Merge pull request #41 from gansm/master

merge
This commit is contained in:
Markus Gans 2019-10-17 02:01:36 +02:00 committed by GitHub
commit 58c775c252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
169 changed files with 10277 additions and 9331 deletions

View File

@ -1,3 +1,28 @@
2019-10-15 Markus Gans <guru.mail@muenster.de>
* Version 0.6.0
2019-10-13 Markus Gans <guru.mail@muenster.de>
* Compile fix for Cygwin and Linux on arm architectures
* A small color palette optimization
* Corrected east asian ambiguous character width for OpenBSD, NetBSD,
FreeBSD and Solaris
2019-10-05 Markus Gans <guru.mail@muenster.de>
* Internal redesign of the callback call
* Mapping of key functions in an associative container to simplify
onKeyPress() in FListBox, FListView, FTextView and FScrollView
2019-10-01 Markus Gans <guru.mail@muenster.de>
* Replacing null-terminated wide strings with FString objects
* Fix for getColumnWidth() with newfont character
2019-09-29 Markus Gans <guru.mail@muenster.de>
* Streaming into an FTextView() object
* Fixes the streaming of empty FString objects into a stream with
a width > 0
* The FString operator [] now returns a null character ('\0')
if the position is equal to the string length
2019-09-28 Markus Gans <guru.mail@muenster.de> 2019-09-28 Markus Gans <guru.mail@muenster.de>
* Support for displaying full-width characters (2 columns wide) * Support for displaying full-width characters (2 columns wide)
on the terminal. This is particularly important for the correct on the terminal. This is particularly important for the correct

View File

@ -1,5 +1,4 @@
![FINAL CUT](logo/svg/finalcut-logo.svg) ![FINAL CUT](logo/svg/finalcut-logo.svg)
============================================
# Library for creating terminal applications with text-based widgets # Library for creating terminal applications with text-based widgets
The FINAL CUT is a C++ class library and widget toolkit with full mouse support for creating a [text-based user interface](https://en.wikipedia.org/wiki/Text-based_user_interface). The library supports the programmer to develop an application for the text console. It allows the simultaneous handling of multiple text windows on the screen. The FINAL CUT is a C++ class library and widget toolkit with full mouse support for creating a [text-based user interface](https://en.wikipedia.org/wiki/Text-based_user_interface). The library supports the programmer to develop an application for the text console. It allows the simultaneous handling of multiple text windows on the screen.
@ -7,18 +6,15 @@ The FINAL CUT is a C++ class library and widget toolkit with full mouse support
The structure of the Qt framework was originally the inspiration for the C++ class design of FINAL CUT. It provides common controls like dialog boxes, push buttons, check boxes, radio buttons, input lines, list boxes, status bars and so on. The structure of the Qt framework was originally the inspiration for the C++ class design of FINAL CUT. It provides common controls like dialog boxes, push buttons, check boxes, radio buttons, input lines, list boxes, status bars and so on.
## Building and code analysis ## Building and code analysis
*Latest release:*<br /> | | Badge |
&#160;&#160;&#160;&#160;&#160;[![Latest Release](https://img.shields.io/github/release/gansm/finalcut.svg)](https://github.com/gansm/finalcut/releases) <br /> |-------------------:|:------|
*License:*<br /> | *Latest release* | [![Latest Release](https://img.shields.io/github/release/gansm/finalcut.svg)](https://github.com/gansm/finalcut/releases) |
&#160;&#160;&#160;&#160;&#160;[![license](https://img.shields.io/github/license/gansm/finalcut.svg?colorA=#333)](COPYING) <br /> | *License* | [![license](https://img.shields.io/github/license/gansm/finalcut.svg?colorA=#333)](COPYING) |
*Travis CI:*<br /> | *Class Reference* | [![documented](https://codedocs.xyz/gansm/finalcut.svg)](https://codedocs.xyz/gansm/finalcut/hierarchy.html) |
&#160;&#160;&#160;&#160;&#160;[![Build Status](https://travis-ci.org/gansm/finalcut.svg?branch=master)](https://travis-ci.org/gansm/finalcut) <br /> | *Travis CI* | [![Build Status](https://travis-ci.org/gansm/finalcut.svg?branch=master)](https://travis-ci.org/gansm/finalcut)
*Coverity Scan:*<br /> |*Coverity Scan* | [![Coverity Scan Status](https://img.shields.io/coverity/scan/6508.svg)](https://scan.coverity.com/projects/6508 )|
&#160;&#160;&#160;&#160;&#160;[![Coverity Scan Status](https://img.shields.io/coverity/scan/6508.svg)](https://scan.coverity.com/projects/6508) <br /> | *LGTM* | [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/gansm/finalcut.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/gansm/finalcut/context:cpp) |
*LGTM:*<br /> | *CodeFactor* | [![CodeFactor](https://www.codefactor.io/repository/github/gansm/finalcut/badge)](https://www.codefactor.io/repository/github/gansm/finalcut) |
&#160;&#160;&#160;&#160;&#160;[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/gansm/finalcut.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/gansm/finalcut/context:cpp) <br />
*Class Reference:*<br />
&#160;&#160;&#160;&#160;&#160;[![documented](https://codedocs.xyz/gansm/finalcut.svg)](https://codedocs.xyz/gansm/finalcut/hierarchy.html)
## Installation ## Installation
```bash ```bash
@ -40,7 +36,7 @@ The structure of the Qt framework was originally the inspiration for the C++ cla
* Solaris * Solaris
## First steps ## First steps
Read here [how to use the library](doc/first-steps.md#first-steps-with-the-final-cut-widget-toolkit) See the [first steps](doc/first-steps.md#first-steps-with-the-final-cut-widget-toolkit) documentation for information on how to use the library.
## Some screenshots ## Some screenshots
@ -56,12 +52,12 @@ The Final Cut FProgressbar widget:
Scrollable text in the FTextView widget: Scrollable text in the FTextView widget:
![FTextView](doc/textview.png) ![FTextView](doc/textview.png)
The Mandelbrot set example: The Mandelbrot set example:
![Mandelbrot set](doc/Mandelbrot.png) ![Mandelbrot set](doc/Mandelbrot.png)
newfont newfont
@ -83,41 +79,34 @@ The calculator example in newfont mode:
Virtual terminal Virtual terminal
---------------- ----------------
It uses a virtual terminal to print the character via an update method on the screen. FINAL CUT uses a virtual terminal to print character via an update method on the screen. It provides (as an overlying layer) virtual windows for the realization of window movements. The update methods only transfer differences to the virtual terminal or physical screen.
The virtual windows are an overlying layer to realizing window movements.
The update method transmits only the changes to the virtual terminal or the screen.
<pre style="line-height: 1 !important;"> <pre style="line-height: 1 !important;">
print(...) print(...)
printf(...) printf(...)
════════════════════════[ vterm ]════════════════════════╗ │ ╔════════════════════════[ vterm ]════════════════════════╗
│ ║createVTerm() ║ │ ║createVTerm() ║
│ ║ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ║ │ ║ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ║
│ ║ ║ │ ║ ║
│ ║ │ restoreVTerm(x,y,w,h) │ ║ │ ║ │ restoreVTerm(x,y,w,h) │ ║
│ ║ ║ │ ┌───────╨────[ vwin ]────────────┐ ║
│ ║ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ ║ │ │createArea(area) │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ ║
│ ║ ║
│ ┌───────╨─────[ vwin ]─────────────┐ ║
│ │createArea(area) │ ║
│ │ │ ║ │ │ │ ║
│ │ │ ║ │ │ │ ║
└───┼─────────────► ──────► updateVTerm(area) ────► ║ └──┼────────► putArea(area) ────► ║
│ │ ║
│ putArea(x,y,area) ────► ║
│ │ ║
│ ◄──── getArea(x,y,area) ║
│ │ ║ │ │ ║
│ putArea(x,y,area) ║
│ ────────────────────► ║
│ getArea(x,y,area) ║
│ ◄──────────────────── ║
│ │ ║ │ │ ║
│ │ ║ │ │ ║
│ resizeArea(area)│ ║ │ resizeArea(area)│ ║
└───────╥──────────────────────────┘ ║ └───────╥────────────────────────┘ ║
║ ║
║ ║
║ ║ ║ ║
║ │ resizeVTerm()║ ║ │ resizeVTerm()║
═══▼═══════════════════════════════════════════════════════╝ ╚═══════▼═════════════════════════════════════════════════╝
│ putVTerm() │ putVTerm()
└──────────────────► updateTerminalLine(y) └──────────────────► updateTerminalLine(y)
@ -127,10 +116,8 @@ printf(...)
│ output_buffer │ │ output_buffer │
└───────────────┘ └───────────────┘
│ flush_out() │ flushOutputBuffer()
│ + │ and putchar(char)
│ Fputchar(char)
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▌ ▐ ▌ ▐
@ -261,9 +248,7 @@ GNU Lesser General Public License Version 3
Frequently Asked Questions Frequently Asked Questions
-------------------------- --------------------------
If you have any problems, please read the For general questions about FINAL CUT, likely the answer is already included in the [FAQ](doc/faq.md#frequently-asked-questions).
[FAQ](doc/faq.md#frequently-asked-questions)
before you give up.
Please send bug reports to Please send bug reports to
-------------------------- --------------------------

View File

@ -4,7 +4,7 @@
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
AC_INIT([finalcut], [0.5.1]) AC_INIT([finalcut], [0.6.0])
AC_CONFIG_HEADER([config.h]) AC_CONFIG_HEADER([config.h])
AX_PREFIX_CONFIG_H([src/include/final/fconfig.h], [F]) AX_PREFIX_CONFIG_H([src/include/final/fconfig.h], [F])
AC_CONFIG_SRCDIR([src/fobject.cpp]) AC_CONFIG_SRCDIR([src/fobject.cpp])
@ -61,7 +61,7 @@ LT_OUTPUT
### This defines the version number of the installed .so files ### This defines the version number of the installed .so files
### Update this value for every release! (A:B:C will map to foo.so.(A-C).C.B) ### Update this value for every release! (A:B:C will map to foo.so.(A-C).C.B)
### using libtool's versioning system. ### using libtool's versioning system.
AC_SUBST(SO_VERSION, ["5:1:5"]) AC_SUBST(SO_VERSION, ["6:0:6"])
AC_SUBST([LIBTOOL_DEPS]) AC_SUBST([LIBTOOL_DEPS])

11
debian/40-finalcut-newfont.conf vendored Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<selectfont>
<acceptfont>
<pattern>
<patelt name="family"><string>8x16graph</string></patelt>
</pattern>
</acceptfont>
</selectfont>
</fontconfig>

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
finalcut (0.6.0) unstable; urgency=low
* Release (version 0.6.0)
-- Markus Gans <guru.mail@muenster.de> Mon, 14 Oct 2019 01:49:57 +0100
finalcut (0.5.0) unstable; urgency=low finalcut (0.5.0) unstable; urgency=low
* Release (version 0.5.0) * Release (version 0.5.0)

3
debian/control vendored
View File

@ -19,7 +19,8 @@ Architecture: any
Pre-Depends: ${misc:Pre-Depends} Pre-Depends: ${misc:Pre-Depends}
Multi-Arch: same Multi-Arch: same
Depends: Depends:
${shlibs:Depends} xfonts-utils
, ${shlibs:Depends}
, ${misc:Depends} , ${misc:Depends}
Suggests: Suggests:
coreutils coreutils

View File

@ -30,3 +30,4 @@ doc/vt100_line_drawing_graphics.png
doc/virtual-terminal.txt doc/virtual-terminal.txt
doc/xterm.txt doc/xterm.txt
doc/xgraphics doc/xgraphics
fonts/newfont.txt

View File

@ -1,4 +1,5 @@
examples/.libs/* usr/share/doc/libfinal-examples/examples doc/readme.txt usr/lib/libfinal/examples
examples/*.cpp usr/share/doc/libfinal-examples/examples examples/.libs/* usr/lib/libfinal/examples
examples/Makefile.clang usr/share/doc/libfinal-examples/examples examples/*.cpp usr/lib/libfinal/examples
examples/Makefile.gcc usr/share/doc/libfinal-examples/examples examples/Makefile.clang usr/lib/libfinal/examples
examples/Makefile.gcc usr/lib/libfinal/examples

View File

@ -1 +1,2 @@
usr/share/doc/libfinal-examples/examples/Makefile.gcc usr/share/doc/libfinal-examples/examples/Makefile usr/lib/libfinal/examples usr/share/doc/libfinal-examples/examples
usr/lib/libfinal/examples/Makefile.gcc usr/lib/libfinal/examples/Makefile

6
debian/libfinal0.docs vendored Normal file
View File

@ -0,0 +1,6 @@
AUTHORS
COPYING
COPYING.LESSER
ChangeLog
doc/readme.txt
fonts/newfont.txt

View File

@ -1,3 +1,5 @@
usr/lib/*/lib*.so usr/lib/*/lib*.so
usr/lib/*/lib*.so.* usr/lib/*/lib*.so.*
fonts/8x16graph.pcf.gz /usr/share/fonts/X11/misc/
fonts/xfonts-finalcut-newfont.alias /etc/X11/fonts/misc/
debian/40-finalcut-newfont.conf etc/fonts/conf.avail

1
debian/libfinal0.links vendored Normal file
View File

@ -0,0 +1 @@
etc/fonts/conf.avail/40-finalcut-newfont.conf etc/fonts/conf.d/40-finalcut-newfont.conf

View File

@ -1 +1 @@
libfinal 0 libfinal0 (>= 0.5.1) libfinal 0 libfinal0 (>= 0.6.0)

10313
debian/libfinal0.symbols vendored

File diff suppressed because it is too large Load Diff

2
debian/rules vendored
View File

@ -19,6 +19,8 @@ include /usr/share/dpkg/default.mk
# main packaging script based on dh7 syntax # main packaging script based on dh7 syntax
%: %:
sed -i 's/doc\///g' README.md
test -f fonts/fonts.alias && cp fonts/fonts.alias fonts/xfonts-finalcut-newfont.alias || true
dh $@ --with autotools-dev dh $@ --with autotools-dev
# debmake generated override targets # debmake generated override targets

View File

@ -5,6 +5,8 @@
docdir = ${datadir}/doc/${PACKAGE} docdir = ${datadir}/doc/${PACKAGE}
EXTRA_DIST = \ EXTRA_DIST = \
build_openbsd.txt \
build_solaris.txt \
calendar-draft.png \ calendar-draft.png \
calculator.png \ calculator.png \
class-diagram.txt \ class-diagram.txt \
@ -34,6 +36,8 @@ EXTRA_DIST = \
xgraphics xgraphics
doc_DATA = \ doc_DATA = \
build_openbsd.txt \
build_solaris.txt \
calendar-draft.png \ calendar-draft.png \
calculator.png \ calculator.png \
class-diagram.txt \ class-diagram.txt \

View File

@ -116,7 +116,6 @@ class FClassName
// Data members // Data members
// Friend class // Friend class
}; };

View File

@ -900,6 +900,7 @@ class dialogWidget : public FDialog
setGeometry (FPoint(28, 2), FSize(24, 21)); setGeometry (FPoint(28, 2), FSize(24, 21));
scrollview.setGeometry(FPoint(1, 1), FSize(22, 11)); scrollview.setGeometry(FPoint(1, 1), FSize(22, 11));
scrollview.setScrollSize(FSize(60, 27)); scrollview.setScrollSize(FSize(60, 27));
const auto& wc = getFWidgetColors();
setColor (wc.label_inactive_fg, wc.dialog_bg); setColor (wc.label_inactive_fg, wc.dialog_bg);
scrollview.clearArea(); scrollview.clearArea();
FColorPair red (fc::LightRed, wc.dialog_bg); FColorPair red (fc::LightRed, wc.dialog_bg);

View File

@ -1,8 +1,8 @@
---------------------------------------------------------------------- ----------------------------------------------------------------------
The Final Cut FINAL CUT
---------------------------------------------------------------------- ----------------------------------------------------------------------
The Final Cut is a C++ class library and widget toolkit with full mouse The FINAL CUT is a C++ class library and widget toolkit with full mouse
support for creating a text-based user interface. The library supports support for creating a text-based user interface. The library supports
the programmer to develop an application for the text console. It allows the programmer to develop an application for the text console. It allows
the simultaneous handling of multiple text windows on the screen. the simultaneous handling of multiple text windows on the screen.
@ -12,3 +12,50 @@ the C++ class design of FINAL CUT. It provides common controls like
dialog boxes, push buttons, check boxes, radio buttons, input lines, dialog boxes, push buttons, check boxes, radio buttons, input lines,
list boxes, status bars and so on. list boxes, status bars and so on.
Installation
------------
> git clone git://github.com/gansm/finalcut.git
> cd finalcut
> autoreconf --install --force
> ./configure --prefix=/usr
> make
> su -c "make install"
Supported platforms
-------------------
* Linux
* FreeBSD
* NetBSD
* OpenBSD
* macOS
* Cygwin
* Solaris
First steps
-----------
See the first-steps.md documentation for information on how to use
the library.
License
-------
GNU Lesser General Public License Version 3
Frequently Asked Questions
--------------------------
For general questions about FINAL CUT, likely the answer is already included in the faq.md.
Download
--------
You can find the latest version at https://github.com/gansm/finalcut
Please send bug reports to
--------------------------
https://github.com/gansm/finalcut/issues

View File

@ -1,36 +1,38 @@
The virtual terminal (vterm) The virtual terminal (vterm)
---------------------------- ----------------------------
FINAL CUT uses a virtual terminal to print character via an update method
on the screen. It provides (as an overlying layer) virtual windows for
the realization of window movements. The update methods only transfer
differences to the virtual terminal or physical screen.
print(...) print(...)
printf(...) printf(...)
│ ╔═════════════════════════[ vterm ]═════════════════════════╗ │ ╔════════════════════════[ vterm ]════════════════════════╗
│ ║createVTerm() ║ │ ║createVTerm() ║
│ ║ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ║ │ ║ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ║
│ ║ ║ │ ║ ║
│ ║ │ restoreVTerm(x,y,w,h) │ ║ │ ║ │ restoreVTerm(x,y,w,h) │ ║
│ ║ ║ │ ┌───────╨────[ vwin ]────────────┐ ║
│ ║ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ ║ │ │createArea(area) │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ ║
│ ║ ║
│ ┌───────╨─────[ vwin ]─────────────┐ ║
│ │createArea(area) │ ║
│ │ │ ║ │ │ │ ║
│ │ │ ║ │ │ │ ║
└───┼─────────────► ──────► updateVTerm(area) ────► ║ └──┼────────► putArea(area) ────► ║
│ │ ║
│ putArea(x,y,area) ────► ║
│ │ ║
│ ◄──── getArea(x,y,area) ║
│ │ ║ │ │ ║
│ putArea(x,y,area) ║
│ ────────────────────► ║
│ getArea(x,y,area) ║
│ ◄──────────────────── ║
│ │ ║ │ │ ║
│ │ ║ │ │ ║
│ resizeArea(area)│ ║ │ resizeArea(area)│ ║
└───────╥──────────────────────────┘ ║ └───────╥────────────────────────┘ ║
║ ║
║ ║
║ ║ ║ ║
║ │ resizeVTerm()║ ║ │ resizeVTerm()║
═══▼═══════════════════════════════════════════════════════╝ ╚═══════▼═════════════════════════════════════════════════╝
│ putVTerm() │ putVTerm()
└──────────────────► updateTerminalLine(y) └──────────────────► updateTerminalLine(y)
@ -40,10 +42,8 @@ printf(...)
│ output_buffer │ │ output_buffer │
└───────────────┘ └───────────────┘
│ flush_out() │ flushOutputBuffer()
│ + │ and putchar(char)
│ Fputchar(char)
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▌ ▐ ▌ ▐
@ -54,4 +54,3 @@ printf(...)
▀▀▀▀▀▀▀███▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀███▀▀▀▀▀▀▀
███ ███
▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀

View File

@ -16,7 +16,7 @@ INCLUDES = -I../src/include -I/usr/include/final
RM = rm -f RM = rm -f
ifdef DEBUG ifdef DEBUG
OPTIMIZE = -O0 -fsanitize=bool,bounds,enum,float-cast-overflow,function,null OPTIMIZE = -O0 -fsanitize=undefined
else else
OPTIMIZE = -O2 OPTIMIZE = -O2
endif endif

View File

@ -80,7 +80,7 @@ void Button::setChecked (bool enable)
} }
else else
{ {
const finalcut::FWidgetColors& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setBackgroundColor(wc.button_active_bg); setBackgroundColor(wc.button_active_bg);
setFocusForegroundColor(wc.button_active_focus_fg); setFocusForegroundColor(wc.button_active_focus_fg);
setFocusBackgroundColor(wc.button_active_focus_bg); setFocusBackgroundColor(wc.button_active_focus_bg);
@ -328,7 +328,7 @@ void Calc::drawDispay()
if ( isMonochron() ) if ( isMonochron() )
setReverse(false); setReverse(false);
const finalcut::FWidgetColors& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
print() << FColorPair(fc::Black, fc::LightGray) print() << FColorPair(fc::Black, fc::LightGray)
<< FPoint(3, 3) << display << ' ' << FPoint(3, 3) << display << ' '
<< FColorPair(wc.dialog_fg, wc.dialog_bg); << FColorPair(wc.dialog_fg, wc.dialog_bg);
@ -898,9 +898,7 @@ lDouble& Calc::getValue()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Calc::setDisplay (lDouble d) void Calc::setDisplay (lDouble d)
{ {
char buffer[33]{}; input.sprintf("%32.11Lg", d);
snprintf (buffer, sizeof(buffer), "%32.11Lg", d);
input = buffer;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -126,12 +126,10 @@ void CheckList::populate()
{ "Lemons", "Low" } { "Lemons", "Low" }
}; };
constexpr int lastItem = int(sizeof(list) / sizeof(list[0])) - 1; for (const auto& line : list)
for (int i{0}; i <= lastItem; i++)
{ {
const finalcut::FStringList line (&list[i][0], &list[i][0] + 2); const finalcut::FStringList string_line (&line[0], &line[0] + 2);
auto iter = listView.insert (line); auto iter = listView.insert (string_line);
auto item = static_cast<finalcut::FListViewItem*>(*iter); auto item = static_cast<finalcut::FListViewItem*>(*iter);
item->setCheckable(true); item->setCheckable(true);
} }

View File

@ -140,7 +140,7 @@ int main (int argc, char* argv[])
ok.addCallback ok.addCallback
( (
"clicked", "clicked",
F_FUNCTION_CALLBACK (&cb_quit), &cb_quit,
&dgl &dgl
); );

View File

@ -76,7 +76,7 @@ int main (int argc, char* argv[])
btn.addCallback btn.addCallback
( (
"clicked", "clicked",
F_FUNCTION_CALLBACK (&cb_quit), &cb_quit,
&app &app
); );

View File

@ -74,9 +74,9 @@ int main (int argc, char* argv[])
scroll_text.setGeometry (FPoint(2, 8), FSize(32, 3)); scroll_text.setGeometry (FPoint(2, 8), FSize(32, 3));
finalcut::FString text_line{"FINAL CUT supports " finalcut::FString text_line{"FINAL CUT supports "
"full-width characters."}; "full-width characters."};
scroll_text << full(text_line);
scroll_text.setStatusbarMessage ("You can scroll right and " scroll_text.setStatusbarMessage ("You can scroll right and "
"left with the arrow keys"); "left with the arrow keys");
scroll_text.append(full(text_line));
// Create a OK button // Create a OK button
finalcut::FButton btn("&", &dgl); finalcut::FButton btn("&", &dgl);
@ -126,7 +126,7 @@ int main (int argc, char* argv[])
btn.addCallback ("clicked", cb_exit, &app); btn.addCallback ("clicked", cb_exit, &app);
Exit.addCallback ("clicked", cb_exit, &app); Exit.addCallback ("clicked", cb_exit, &app);
Quit.addCallback ("clicked", cb_exit, &app); Quit.addCallback ("clicked", cb_exit, &app);
key_F1.addCallback ("activate",cb_tooltip, &app); key_F1.addCallback ("activate", cb_tooltip, &app);
// Set dialog object as main widget // Set dialog object as main widget
app.setMainWidget(&dgl); app.setMainWidget(&dgl);

View File

@ -120,7 +120,7 @@ int main (int argc, char* argv[])
check1.addCallback check1.addCallback
( (
"clicked", "clicked",
F_FUNCTION_CALLBACK (&cb_publish), &cb_publish,
&check2 &check2
); );
@ -128,7 +128,7 @@ int main (int argc, char* argv[])
btn.addCallback btn.addCallback
( (
"clicked", "clicked",
F_FUNCTION_CALLBACK (&cb_quit), &cb_quit,
&app &app
); );

View File

@ -45,7 +45,7 @@ FString& mapToString ( std::map<FString
, FString>::const_iterator iter ); , FString>::const_iterator iter );
// Lazy conversion import function // Lazy conversion insert function
void doubleToItem ( FListBoxItem& item void doubleToItem ( FListBoxItem& item
, FDataPtr container, int index) , FDataPtr container, int index)
{ {
@ -57,7 +57,7 @@ void doubleToItem ( FListBoxItem& item
item.setData (FDataPtr(&(*iter))); item.setData (FDataPtr(&(*iter)));
} }
// Import converter functions // Insert converter functions
FString& doubleToString (std::list<double>::const_iterator iter) FString& doubleToString (std::list<double>::const_iterator iter)
{ {
auto temp = temp_str.lock(); auto temp = temp_str.lock();
@ -127,12 +127,12 @@ Listbox::Listbox (FWidget* parent)
list2.setText ("double"); list2.setText ("double");
// //
// Import via lazy conversion on print // Insert via lazy conversion on print
// //
list2.insert (&double_list, doubleToItem); list2.insert (&double_list, doubleToItem);
// //
// Direct import of the complete list // Direct insert of the complete list
// //
//list2.insert (double_list.begin(), double_list.end(), doubleToString); //list2.insert (double_list.begin(), double_list.end(), doubleToString);

View File

@ -173,11 +173,9 @@ void Listview::populate()
{ "Zurich", "Mostly Cloudy", "23°C", "44%", "1023.7 mb" } { "Zurich", "Mostly Cloudy", "23°C", "44%", "1023.7 mb" }
}; };
constexpr int lastItem = int(sizeof(weather) / sizeof(weather[0])) - 1; for (const auto& place : weather)
for (int i{0}; i <= lastItem; i++)
{ {
finalcut::FStringList line (&weather[i][0], &weather[i][0] + 5); finalcut::FStringList line (&place[0], &place[0] + 5);
listView.insert (line); listView.insert (line);
} }
} }

View File

@ -350,7 +350,7 @@ class MouseDraw : public finalcut::FDialog
void cb_colorChanged (finalcut::FWidget*, FDataPtr); void cb_colorChanged (finalcut::FWidget*, FDataPtr);
// Data members // Data members
term_area* canvas{nullptr}; FTermArea* canvas{nullptr};
ColorChooser c_chooser{this}; ColorChooser c_chooser{this};
Brushes brush{this}; Brushes brush{this};
}; };
@ -495,13 +495,13 @@ void MouseDraw::drawCanvas()
for (int y{0}; y < y_end; y++) // line loop for (int y{0}; y < y_end; y++) // line loop
{ {
finalcut::charData* canvaschar{}; // canvas character finalcut::FChar* canvaschar{}; // canvas character
finalcut::charData* winchar{}; // window character finalcut::FChar* winchar{}; // window character
canvaschar = &canvas->text[y * x_end]; canvaschar = &canvas->data[y * x_end];
winchar = &printarea->text[(ay + y) * w_line_len + ax]; winchar = &printarea->data[(ay + y) * w_line_len + ax];
std::memcpy ( winchar std::memcpy ( winchar
, canvaschar , canvaschar
, sizeof(finalcut::charData) * unsigned(x_end) ); , sizeof(finalcut::FChar) * unsigned(x_end) );
if ( int(printarea->changes[ay + y].xmin) > ax ) if ( int(printarea->changes[ay + y].xmin) > ax )
printarea->changes[ay + y].xmin = uInt(ax); printarea->changes[ay + y].xmin = uInt(ax);

View File

@ -87,8 +87,7 @@ void term_boundaries (int& x, int& y)
void move (int xold, int yold, int xnew, int ynew) void move (int xold, int yold, int xnew, int ynew)
{ {
// prints the cursor move escape sequence // prints the cursor move escape sequence
std::string sequence{}; finalcut::FString buffer{}, sequence{}, from{}, to{}, byte{};
char from[26]{}, to[26]{}, byte[20]{};
const std::string ctrl_character[] = const std::string ctrl_character[] =
{ {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
@ -100,36 +99,33 @@ void move (int xold, int yold, int xnew, int ynew)
term_boundaries(xold, yold); term_boundaries(xold, yold);
term_boundaries(xnew, ynew); term_boundaries(xnew, ynew);
snprintf (from, sizeof(from), "(%3d;%3d)", xold, yold);
snprintf (to, sizeof(to), "(%3d;%3d)", xnew, ynew);
std::cout << std::right << std::setw(10) << from
<< " -> "
<< std::left << std::setw(10) << to
<< " ";
// get the move string // get the move string
char* buffer = finalcut::FTerm::moveCursorString (xold, yold, xnew, ynew); buffer = finalcut::FTerm::moveCursorString (xold, yold, xnew, ynew);
uInt len = uInt(std::strlen(buffer));
for (uInt i = 0; i < len; i++) for (auto&& ch : buffer)
{ {
char ch = buffer[i];
if ( ch < 0x21 ) if ( ch < 0x21 )
sequence += ctrl_character[uInt(ch)]; sequence += ctrl_character[std::size_t(ch)];
else else
sequence += ch; sequence += ch;
sequence += ' '; sequence += ' ';
} }
std::cout << std::setw(21) << sequence << " "; from.sprintf ("(%3d;%3d)", xold, yold);
to.sprintf ("(%3d;%3d)", xnew, ynew);
std::size_t len = buffer.getLength();
if ( len <= 1 ) if ( len <= 1 )
snprintf (byte, sizeof(byte), "%d byte ", len); byte.sprintf ("%d byte ", len);
else else
snprintf (byte, sizeof(byte), "%d bytes", len); byte.sprintf ("%d bytes", len);
std::cout << std::right << std::setw(10) << byte << "\r\n"; std::cout << std::right << std::setw(10) << from << " -> "
<< std::left << std::setw(10) << to << " "
<< std::setw(21) << sequence << " "
<< std::right << std::setw(10) << byte << "\r\n";
} }

View File

@ -131,7 +131,7 @@ void Scrollview::draw()
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
const finalcut::FWidgetColors& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setColor (wc.label_inactive_fg, wc.dialog_bg); setColor (wc.label_inactive_fg, wc.dialog_bg);
clearArea(); clearArea();
@ -141,7 +141,6 @@ void Scrollview::draw()
for (int x{0}; x < int(getScrollWidth()); x++) for (int x{0}; x < int(getScrollWidth()); x++)
print (32 + ((x + y) % 0x5f)); print (32 + ((x + y) % 0x5f));
} }
if ( isMonochron() ) if ( isMonochron() )

View File

@ -262,7 +262,7 @@ void AttribDemo::printColorLine()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void AttribDemo::printAltCharset() void AttribDemo::printAltCharset()
{ {
const finalcut::FWidgetColors& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
auto parent = static_cast<AttribDlg*>(getParent()); auto parent = static_cast<AttribDlg*>(getParent());
if ( ! isMonochron() ) if ( ! isMonochron() )
@ -413,7 +413,7 @@ void AttribDemo::printProtected()
void AttribDemo::draw() void AttribDemo::draw()
{ {
// test alternate character set // test alternate character set
const finalcut::FWidgetColors& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
printAltCharset(); printAltCharset();
std::vector<std::function<void()> > effect std::vector<std::function<void()> > effect

View File

@ -44,8 +44,6 @@ void string();
struct data struct data
{ {
static int getNumberOfItems();
struct alignas(alignof(std::string)) termcap_string struct alignas(alignof(std::string)) termcap_string
{ {
const std::string name; const std::string name;
@ -144,13 +142,6 @@ data::termcap_string data::strings[] =
{ "t_key_mouse", fc::t_key_mouse } { "t_key_mouse", fc::t_key_mouse }
}; };
// data inline functions
//----------------------------------------------------------------------
inline int data::getNumberOfItems()
{
return int ( sizeof(strings) / sizeof(strings[0]) ) - 1;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Functions // Functions
@ -290,10 +281,10 @@ void string()
finalcut::FTermcap::tcap_map (&tcap_strings)[] \ finalcut::FTermcap::tcap_map (&tcap_strings)[] \
= finalcut::FTermcap::strings; = finalcut::FTermcap::strings;
for (int n{0}; n <= data::getNumberOfItems(); n++ ) for (const auto& entry : data::strings)
{ {
const std::string name = data::strings[n].name; const std::string name = entry.name;
const fc::termcaps cap = data::strings[n].cap; const fc::termcaps cap = entry.cap;
tcapString (name, tcap_strings[cap].string); tcapString (name, tcap_strings[cap].string);
} }
} }

View File

@ -89,7 +89,7 @@ void Transparent::draw()
if ( type == shadow ) if ( type == shadow )
{ {
const finalcut::FWidgetColors& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setColor(wc.shadow_bg, wc.shadow_fg); setColor(wc.shadow_bg, wc.shadow_fg);
setTransShadow(); setTransShadow();
} }
@ -267,7 +267,7 @@ void MainWindow::onTimer (finalcut::FTimerEvent*)
line1 = line1.right(length - 1) + first_Char[0]; line1 = line1.right(length - 1) + first_Char[0];
line2 = line2.right(length - 1) + first_Char[1]; line2 = line2.right(length - 1) + first_Char[1];
redraw(); redraw();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -322,7 +322,7 @@ Treeview::Treeview (finalcut::FWidget* parent)
listView.setTreeView(); listView.setTreeView();
// Populate FListView with a list of items // Populate FListView with a list of items
static TreeItem continent[] = static TreeItem continent_list[] =
{ {
{ "Africa", "944,000,000", "31.2", africa }, { "Africa", "944,000,000", "31.2", africa },
{ "Asia", "4,010,000,000", "90.3", asia }, { "Asia", "4,010,000,000", "90.3", asia },
@ -330,17 +330,14 @@ Treeview::Treeview (finalcut::FWidget* parent)
{ "North America", "523,000,000", "21", north_america }, { "North America", "523,000,000", "21", north_america },
{ "South America", "381,000,000", "21.4", south_america }, { "South America", "381,000,000", "21.4", south_america },
{ "Antarctica", "1000", "0", 0 }, { "Antarctica", "1000", "0", 0 },
{ "Australia/Oceania", "34,000,000", "4", oceania }, { "Australia/Oceania", "34,000,000", "4", oceania }
{ 0, 0, 0, 0 }
}; };
auto continent_list = continent; for (const auto& continent : continent_list)
while ( continent_list->name )
{ {
auto& country_list = continent_list->child_element; TreeItem* country_list = continent.child_element;
finalcut::FStringList continent_line ( continent_list->begin() finalcut::FStringList continent_line ( continent.begin()
, continent_list->end() ); , continent.end() );
const auto& iter = listView.insert (continent_line); const auto& iter = listView.insert (continent_line);
while ( country_list && country_list->name ) while ( country_list && country_list->name )
@ -350,8 +347,6 @@ Treeview::Treeview (finalcut::FWidget* parent)
listView.insert (country_line, iter); listView.insert (country_line, iter);
country_list++; country_list++;
} }
continent_list++;
} }
// Quit button // Quit button

View File

@ -21,6 +21,7 @@
***********************************************************************/ ***********************************************************************/
#include <fstream> #include <fstream>
#include <functional>
#include <map> #include <map>
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -95,6 +96,7 @@ ProgressDialog::ProgressDialog (finalcut::FWidget* parent)
progressBar.setGeometry(FPoint(2, 3), FSize(34, 1), false); progressBar.setGeometry(FPoint(2, 3), FSize(34, 1), false);
//progressBar.setPercentage(78); //progressBar.setPercentage(78);
using namespace std::placeholders;
reset.addCallback reset.addCallback
( (
"clicked", "clicked",
@ -134,7 +136,7 @@ void ProgressDialog::onTimer (finalcut::FTimerEvent*)
{ {
auto p = progressBar.getPercentage(); auto p = progressBar.getPercentage();
progressBar.setPercentage(++p); progressBar.setPercentage(++p);
flush_out(); flushOutputBuffer();
if ( p != 100 ) if ( p != 100 )
return; return;
@ -152,7 +154,7 @@ void ProgressDialog::onTimer (finalcut::FTimerEvent*)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -68,7 +68,7 @@ class SmallWindow : public finalcut::FDialog
SmallWindow::SmallWindow (finalcut::FWidget* parent) SmallWindow::SmallWindow (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog(parent)
{ {
const finalcut::FWidgetColors& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
wchar_t arrow_up, arrow_down; wchar_t arrow_up, arrow_down;
arrow_up = fc::BlackUpPointingTriangle; arrow_up = fc::BlackUpPointingTriangle;
arrow_down = fc::BlackDownPointingTriangle; arrow_down = fc::BlackDownPointingTriangle;
@ -377,7 +377,7 @@ void Window::addClickedCallback ( finalcut::FWidget* widget
, WindowCallback call ) , WindowCallback call )
{ {
FMemberCallback callback FMemberCallback callback
= reinterpret_cast<finalcut::FWidget::FMemberCallback>(call); = reinterpret_cast<FMemberCallback>(call);
widget->addCallback widget->addCallback
( (
@ -391,7 +391,7 @@ void Window::addClickedCallback ( finalcut::FWidget* widget
, FAppCallback call ) , FAppCallback call )
{ {
FMemberCallback callback FMemberCallback callback
= reinterpret_cast<finalcut::FWidget::FMemberCallback>(call); = reinterpret_cast<FMemberCallback>(call);
widget->addCallback widget->addCallback
( (

View File

@ -1,3 +1,24 @@
-------------------------------------------------------------------
Mon Oct 14 23:49:57 UTC 2019 - Markus Gans <guru.mail@muenster.de>
- Release (version 0.6.0)
-------------------------------------------------------------------
Sat Dec 01 21:28:25 UTC 2018 - Markus Gans <guru.mail@muenster.de>
- Release (version 0.5.1)
-------------------------------------------------------------------
Thu Nov 28 23:36:24 UTC 2018 - Markus Gans <guru.mail@muenster.de>
- Package name adjustment
-------------------------------------------------------------------
Mon Nov 26 11:22:27 UTC 2018 - mvetter@suse.com
- Prepare to push to devel project
- Remove old tarball: finalcut-0.3.0.tar.gz
- Remove old tarball: finalcut-0.4.0.tar.gz
- Clean spec with spec-cleaner
- Add changes file
------------------------------------------------------------------- -------------------------------------------------------------------
Sun Nov 25 00:03:36 UTC 2018 - Markus Gans <guru.mail@muenster.de> Sun Nov 25 00:03:36 UTC 2018 - Markus Gans <guru.mail@muenster.de>
- Release (version 0.5.0) - Release (version 0.5.0)
@ -17,3 +38,4 @@ Sat Dec 19 21:01:48 UTC 2015 - Markus Gans <guru.mail@muenster.de>
------------------------------------------------------------------- -------------------------------------------------------------------
Fri Sep 18 22:35:57 UTC 2015 - Markus Gans <guru.mail@muenster.de> Fri Sep 18 22:35:57 UTC 2015 - Markus Gans <guru.mail@muenster.de>
- Initial Release (version 0.1.1) - Initial Release (version 0.1.1)

View File

@ -15,3 +15,13 @@ EXTRA_DIST = \
newfont.h \ newfont.h \
unicodemap.h \ unicodemap.h \
vgafont.h vgafont.h
docdir = ${datadir}/doc/${PACKAGE}
doc_DATA = \
newfont.txt
fontdir = ${datadir}/fonts/X11/misc/${PACKAGE}
font_DATA = \
8x16graph.pcf.gz \
fonts.alias \
fonts.dir

View File

@ -1,3 +1,7 @@
# The FINAL CUT newfont
## *A graphical text font for X11 and the Linux console*
### How can I use the new graphical font under the Linux text console? ### How can I use the new graphical font under the Linux text console?
Simply start your program with the parameter `--newfont`. Simply start your program with the parameter `--newfont`.

View File

@ -1,3 +1,9 @@
----------------------------------------------------------------------
The FINAL CUT newfont
A graphical text font for X11 and the Linux console
----------------------------------------------------------------------
How can I use the new graphical font under the Linux text console? How can I use the new graphical font under the Linux text console?
------------------------------------------------------------------ ------------------------------------------------------------------

View File

@ -9,7 +9,7 @@ else
fi fi
# Is the file executable? # Is the file executable?
test ! -x "$PROG" && echo "No executable file not found" && exit -1 test ! -x "$PROG" && echo "No executable file not found" && exit 1
LD_LIBRARY_PATH=../src/.libs/ valgrind --tool=callgrind -v "$PROG" 2>/dev/null LD_LIBRARY_PATH=../src/.libs/ valgrind --tool=callgrind -v "$PROG" 2>/dev/null

View File

@ -11,12 +11,12 @@ else
fi fi
# Is the file executable? # Is the file executable?
test ! -x "$PROG" && echo "No executable file not found" && exit -1 test ! -x "$PROG" && echo "No executable file not found" && exit 1
# ELF executable file? # ELF executable file?
ELFMAGIC="$(echo -e "\\x7fELF")" ELFMAGIC="$(echo -e "\\x7fELF")"
MAGIC="$(dd bs=1 count=4 if="$PROG" 2>/dev/null)" MAGIC="$(dd bs=1 count=4 if="$PROG" 2>/dev/null)"
test "$MAGIC" != "$ELFMAGIC" && echo "No ELF executable file" && exit -2 test "$MAGIC" != "$ELFMAGIC" && echo "No ELF executable file" && exit 2
LD_LIBRARY_PATH=../src/.libs/ valgrind --tool=memcheck --suppressions=../doc/ncurses.supp --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes --track-origins=yes --log-file=./valgrind.txt "$PROG" "$@" LD_LIBRARY_PATH=../src/.libs/ valgrind --tool=memcheck --suppressions=../doc/ncurses.supp --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes --track-origins=yes --log-file=./valgrind.txt "$PROG" "$@"

View File

@ -57,6 +57,7 @@ libfinal_la_SOURCES = \
ftermdetection.cpp \ ftermdetection.cpp \
ftermios.cpp \ ftermios.cpp \
fterm.cpp \ fterm.cpp \
fterm_functions.cpp \
fvterm.cpp \ fvterm.cpp \
fevent.cpp \ fevent.cpp \
foptiattr.cpp \ foptiattr.cpp \
@ -66,6 +67,7 @@ libfinal_la_SOURCES = \
fcolorpalette.cpp \ fcolorpalette.cpp \
fwidgetcolors.cpp \ fwidgetcolors.cpp \
fwidget.cpp \ fwidget.cpp \
fwidget_functions.cpp \
fobject.cpp fobject.cpp
libfinal_la_LDFLAGS = -version-info @SO_VERSION@ libfinal_la_LDFLAGS = -version-info @SO_VERSION@

View File

@ -3,7 +3,7 @@
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# This is where make install will install the library # This is where make install will install the library
VERSION = "0.5.1" VERSION = "0.6.0"
MAJOR := $(shell echo ${VERSION} | cut -d. -f1) MAJOR := $(shell echo ${VERSION} | cut -d. -f1)
LIBDIR = /usr/local/lib LIBDIR = /usr/local/lib
INCLUDEDIR1 = include/final INCLUDEDIR1 = include/final
@ -118,6 +118,7 @@ OBJS = \
fstartoptions.o \ fstartoptions.o \
ftermcap.o \ ftermcap.o \
fterm.o \ fterm.o \
fterm_functions.o \
ftermdebugdata.o \ ftermdebugdata.o \
ftermios.o \ ftermios.o \
ftermdetection.o \ ftermdetection.o \
@ -134,14 +135,14 @@ OBJS = \
fcolorpalette.o \ fcolorpalette.o \
fwidgetcolors.o \ fwidgetcolors.o \
fwidget.o \ fwidget.o \
fwidget_functions.o \
fevent.o \ fevent.o \
fobject.o fobject.o
TERMCAP := $(shell test -n "$$(ldd {/usr,}/lib64/libncursesw.so.5 2>/dev/null | grep libtinfo)" && echo "-ltinfo" || echo "-lncurses") TERMCAP := $(shell test -n "$$(ldd {/usr,}/lib64/libncursesw.so.5 2>/dev/null | grep libtinfo)" && echo "-ltinfo" || echo "-lncurses")
ifdef DEBUG ifdef DEBUG
OPTIMIZE = -O0 -fsanitize=bool,bounds,enum,float-cast-overflow,function,null OPTIMIZE = -O0 -fsanitize=undefined
# OPTIMIZE = -O0 -fsanitize=undefined
else else
OPTIMIZE = -O2 OPTIMIZE = -O2
endif endif

View File

@ -3,7 +3,7 @@
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# This is where make install will install the library # This is where make install will install the library
VERSION = "0.5.1" VERSION = "0.6.0"
MAJOR := $(shell echo ${VERSION} | cut -d. -f1) MAJOR := $(shell echo ${VERSION} | cut -d. -f1)
LIBDIR = /usr/local/lib LIBDIR = /usr/local/lib
INCLUDEDIR1 = include/final INCLUDEDIR1 = include/final
@ -118,6 +118,7 @@ OBJS = \
ftermcap.o \ ftermcap.o \
fstartoptions.o \ fstartoptions.o \
fterm.o \ fterm.o \
fterm_functions.o \
ftermdebugdata.o \ ftermdebugdata.o \
ftermios.o \ ftermios.o \
ftermdetection.o \ ftermdetection.o \
@ -134,6 +135,7 @@ OBJS = \
fcolorpalette.o \ fcolorpalette.o \
fwidgetcolors.o \ fwidgetcolors.o \
fwidget.o \ fwidget.o \
fwidget_functions.o \
fevent.o \ fevent.o \
fobject.o fobject.o

View File

@ -122,12 +122,12 @@ int FApplication::exec() // run
quit_now = false; quit_now = false;
quit_code = 0; quit_code = 0;
enter_loop(); enterLoop();
return quit_code; return quit_code;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FApplication::enter_loop() // event loop int FApplication::enterLoop() // event loop
{ {
loop_level++; loop_level++;
quit_now = false; quit_now = false;
@ -144,7 +144,7 @@ int FApplication::enter_loop() // event loop
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FApplication::exit_loop() void FApplication::exitLoop()
{ {
app_exit_loop = true; app_exit_loop = true;
} }
@ -172,10 +172,7 @@ void FApplication::quit()
bool FApplication::sendEvent ( const FObject* receiver bool FApplication::sendEvent ( const FObject* receiver
, const FEvent* event ) , const FEvent* event )
{ {
if ( quit_now || app_exit_loop ) if ( quit_now || app_exit_loop || ! receiver )
return false;
if ( ! receiver )
return false; return false;
if ( receiver->isWidget() ) if ( receiver->isWidget() )
@ -370,9 +367,12 @@ void FApplication::init (uInt64 key_time, uInt64 dblclick_time)
// Set the keyboard keypress timeout // Set the keyboard keypress timeout
if ( keyboard ) if ( keyboard )
{ {
FKeyboardCommand key_cmd1 (this, &FApplication::keyPressed); auto cmd1 = std::bind(&FApplication::keyPressed, this);
FKeyboardCommand key_cmd2 (this, &FApplication::keyReleased); auto cmd2 = std::bind(&FApplication::keyReleased, this);
FKeyboardCommand key_cmd3 (this, &FApplication::escapeKeyPressed); auto cmd3 = std::bind(&FApplication::escapeKeyPressed, this);
FKeyboardCommand key_cmd1 (cmd1);
FKeyboardCommand key_cmd2 (cmd2);
FKeyboardCommand key_cmd3 (cmd3);
keyboard->setPressCommand (key_cmd1); keyboard->setPressCommand (key_cmd1);
keyboard->setReleaseCommand (key_cmd2); keyboard->setReleaseCommand (key_cmd2);
keyboard->setEscPressedCommand (key_cmd3); keyboard->setEscPressedCommand (key_cmd3);
@ -425,7 +425,7 @@ void FApplication::cmd_options (const int& argc, char* argv[])
{C_STR("no-esc-for-alt-meta"), no_argument, 0, 0 }, {C_STR("no-esc-for-alt-meta"), no_argument, 0, 0 },
#endif #endif
{0, 0, 0, 0 } {nullptr, 0, nullptr, 0 }
}; };
opterr = 0; opterr = 0;
@ -669,7 +669,7 @@ void FApplication::processKeyboardEvent()
return; return;
findKeyboardWidget(); findKeyboardWidget();
flush_out(); flushOutputBuffer();
keyboard->clearKeyBufferOnTimeout(); keyboard->clearKeyBufferOnTimeout();
if ( isKeyPressed() ) if ( isKeyPressed() )
@ -773,10 +773,7 @@ FWidget*& FApplication::determineClickedWidget()
{ {
FWidget*& clicked = FWidget::getClickedWidget(); FWidget*& clicked = FWidget::getClickedWidget();
if ( clicked ) if ( clicked || ! mouse )
return clicked;
if ( ! mouse )
return clicked; return clicked;
if ( ! mouse->isLeftButtonPressed() if ( ! mouse->isLeftButtonPressed()
@ -795,7 +792,7 @@ FWidget*& FApplication::determineClickedWidget()
if ( window ) if ( window )
{ {
// Determine the widget at the current click position // Determine the widget at the current click position
auto child = childWidgetAt (window, mouse_position); auto child = window->childWidgetAt (mouse_position);
clicked = ( child != 0 ) ? child : window; clicked = ( child != 0 ) ? child : window;
setClickedWidget (clicked); setClickedWidget (clicked);
} }
@ -858,7 +855,7 @@ void FApplication::closeOpenMenu()
FWidget::getStatusBar()->drawMessage(); FWidget::getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -872,13 +869,7 @@ void FApplication::unselectMenubarItems()
if ( openmenu || (mouse && mouse->isMoved()) ) if ( openmenu || (mouse && mouse->isMoved()) )
return; return;
if ( ! menu_bar ) if ( ! (menu_bar && menu_bar->hasSelectedItem() && mouse) )
return;
if ( ! menu_bar->hasSelectedItem() )
return;
if ( ! mouse )
return; return;
const auto& mouse_position = mouse->getPos(); const auto& mouse_position = mouse->getPos();
@ -899,7 +890,7 @@ void FApplication::unselectMenubarItems()
FWidget::getStatusBar()->drawMessage(); FWidget::getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -908,10 +899,7 @@ void FApplication::sendMouseEvent()
{ {
auto clicked = FWidget::getClickedWidget(); auto clicked = FWidget::getClickedWidget();
if ( ! clicked ) if ( ! (clicked && mouse) )
return;
if ( ! mouse )
return; return;
const auto& mouse_position = mouse->getPos(); const auto& mouse_position = mouse->getPos();

View File

@ -251,14 +251,11 @@ void FButton::hide()
if ( size == 0 ) if ( size == 0 )
return; return;
char* blank = createBlankArray(size + 1);
for (std::size_t y{0}; y < getHeight() + s + (f << 1); y++) for (std::size_t y{0}; y < getHeight() + s + (f << 1); y++)
{ {
print() << FPoint(1 - int(f), 1 + int(y - f)) << blank; print() << FPoint(1 - int(f), 1 + int(y - f))
<< FString(size, L' ');
} }
destroyBlankArray (blank);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -422,25 +419,7 @@ void FButton::init()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::setHotkeyAccelerator() void FButton::setHotkeyAccelerator()
{ {
FKey hotkey = getHotkey(text); setHotkeyViaString (this, text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (hotkey);
}
else
delAccelerator();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -461,9 +440,9 @@ inline std::size_t FButton::clickAnimationIndent (FWidget* parent_widget)
// noshadow + indent one character to the right // noshadow + indent one character to the right
if ( getFlags().flat ) if ( getFlags().flat )
clearFlatBorder(); clearFlatBorder(this);
else if ( hasShadow() ) else if ( hasShadow() )
clearShadow(); clearShadow(this);
if ( parent_widget ) if ( parent_widget )
setColor ( parent_widget->getForegroundColor() setColor ( parent_widget->getForegroundColor()
@ -560,7 +539,7 @@ inline void FButton::drawTopBottomBackground()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FButton::drawButtonTextLine (wchar_t button_text[]) inline void FButton::drawButtonTextLine (const FString& button_text)
{ {
std::size_t pos{}; std::size_t pos{};
print() << FPoint(2 + int(indent), 1 + int(vcenter_offset)) print() << FPoint(2 + int(indent), 1 + int(vcenter_offset))
@ -638,23 +617,12 @@ inline void FButton::drawButtonTextLine (wchar_t button_text[])
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::draw() void FButton::draw()
{ {
wchar_t* button_text{}; FString button_text{};
auto parent_widget = getParentWidget(); auto parent_widget = getParentWidget();
auto txtlength = text.getLength();
column_width = getColumnWidth(text); column_width = getColumnWidth(text);
space_char = int(' '); space_char = int(' ');
active_focus = getFlags().active && getFlags().focus; active_focus = getFlags().active && getFlags().focus;
try
{
button_text = new wchar_t[txtlength + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); // Light background setReverse(true); // Light background
@ -671,9 +639,9 @@ void FButton::draw()
setReverse(false); // Dark background setReverse(false); // Dark background
if ( getFlags().flat && ! button_down ) if ( getFlags().flat && ! button_down )
drawFlatBorder(); drawFlatBorder(this);
hotkeypos = finalcut::getHotkeyPos(text.wc_str(), button_text, uInt(txtlength)); hotkeypos = finalcut::getHotkeyPos(text, button_text);
if ( hotkeypos != NOT_SET ) if ( hotkeypos != NOT_SET )
column_width--; column_width--;
@ -697,12 +665,11 @@ void FButton::draw()
// Draw button shadow // Draw button shadow
if ( ! getFlags().flat && getFlags().shadow && ! button_down ) if ( ! getFlags().flat && getFlags().shadow && ! button_down )
drawShadow(); drawShadow(this);
if ( isMonochron() ) if ( isMonochron() )
setReverse(false); // Dark background setReverse(false); // Dark background
delete[] button_text;
updateStatusBar(); updateStatusBar();
} }

View File

@ -182,6 +182,7 @@ void FButtonGroup::hide()
{ {
for (auto&& item : buttonlist) for (auto&& item : buttonlist)
{ {
// Hide items
auto toggle_button = static_cast<FToggleButton*>(item); auto toggle_button = static_cast<FToggleButton*>(item);
toggle_button->hide(); toggle_button->hide();
} }
@ -205,15 +206,13 @@ void FButtonGroup::hide()
if ( size == 0 ) if ( size == 0 )
return; return;
char* blank = createBlankArray(size + 1); // Hide border
unsetViewportPrint();
for (int y{0}; y < int(getHeight()); y++) for (int y{0}; y < int(getHeight()); y++)
{ print() << FPoint(1, 1 + y) << FString(size, L' ');
FWidget::setPrintPos (FPoint(1, 1 + y));
print (blank);
}
destroyBlankArray (blank); setViewportPrint();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -308,10 +307,10 @@ void FButtonGroup::onAccel (FAccelEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButtonGroup::onFocusIn (FFocusEvent* in_ev) void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
{ {
in_ev->ignore(); // Change default value to ignore
if ( hasCheckedButton() && ! buttonlist.empty() ) if ( hasCheckedButton() && ! buttonlist.empty() )
{ {
in_ev->ignore();
for (auto&& item : buttonlist) for (auto&& item : buttonlist)
{ {
auto toggle_button = static_cast<FToggleButton*>(item); auto toggle_button = static_cast<FToggleButton*>(item);
@ -365,7 +364,7 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
{ {
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -374,25 +373,7 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButtonGroup::setHotkeyAccelerator() void FButtonGroup::setHotkeyAccelerator()
{ {
FKey hotkey = getHotkey(text); setHotkeyViaString (this, text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (hotkey);
}
else
delAccelerator();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -417,36 +398,18 @@ void FButtonGroup::drawLabel()
if ( text.isNull() || text.isEmpty() ) if ( text.isNull() || text.isEmpty() )
return; return;
wchar_t* LabelText{}; FString label_text{};
FString txt{" " + text + " "}; FString txt{" " + text + " "};
std::size_t length = txt.getLength();
try
{
LabelText = new wchar_t[length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
wchar_t* src = const_cast<wchar_t*>(txt.wc_str());
wchar_t* dest = const_cast<wchar_t*>(LabelText);
unsetViewportPrint(); unsetViewportPrint();
auto hotkeypos = finalcut::getHotkeyPos(src, dest, length); auto hotkeypos = finalcut::getHotkeyPos(txt, label_text);
if ( hotkeypos != NOT_SET )
length--;
if ( hasBorder() ) if ( hasBorder() )
FWidget::setPrintPos (FPoint(2, 1)); FWidget::setPrintPos (FPoint(2, 1));
else else
FWidget::setPrintPos (FPoint(0, 1)); FWidget::setPrintPos (FPoint(0, 1));
drawText (LabelText, hotkeypos, length); drawText (label_text, hotkeypos);
setViewportPrint(); setViewportPrint();
delete[] LabelText;
} }
@ -457,8 +420,7 @@ bool FButtonGroup::isRadioButton (const FToggleButton* button) const
if ( ! button ) if ( ! button )
return false; return false;
return bool ( std::strcmp ( button->getClassName() return bool( button->getClassName() == "FRadioButton" );
, C_STR("FRadioButton") ) == 0 );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -472,18 +434,18 @@ void FButtonGroup::init()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButtonGroup::drawText ( wchar_t LabelText[] void FButtonGroup::drawText ( const FString& label_text
, std::size_t hotkeypos , std::size_t hotkeypos )
, std::size_t length )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
std::size_t column_width = getColumnWidth(LabelText); std::size_t column_width = getColumnWidth(label_text);
std::size_t length = label_text.getLength();
bool ellipsis{false}; bool ellipsis{false};
if ( column_width > getClientWidth() ) if ( column_width > getClientWidth() )
{ {
std::size_t len = getClientWidth() - 3; std::size_t len = getClientWidth() - 3;
FString s = finalcut::getColumnSubString (LabelText, 1, len); FString s = finalcut::getColumnSubString (label_text, 1, len);
length = s.getLength(); length = s.getLength();
ellipsis = true; ellipsis = true;
} }
@ -505,7 +467,7 @@ void FButtonGroup::drawText ( wchar_t LabelText[]
if ( ! getFlags().no_underline ) if ( ! getFlags().no_underline )
setUnderline(); setUnderline();
print (LabelText[z]); print (label_text[z]);
if ( ! getFlags().no_underline ) if ( ! getFlags().no_underline )
unsetUnderline(); unsetUnderline();
@ -513,7 +475,7 @@ void FButtonGroup::drawText ( wchar_t LabelText[]
setColor (wc.label_emphasis_fg, wc.label_bg); setColor (wc.label_emphasis_fg, wc.label_bg);
} }
else else
print (LabelText[z]); print (label_text[z]);
} }
if ( ellipsis ) // Print ellipsis if ( ellipsis ) // Print ellipsis
@ -577,7 +539,7 @@ void FButtonGroup::directFocus()
{ {
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }

View File

@ -144,8 +144,7 @@ uInt character[][fc::NUM_OF_ENCODINGS] =
{0x1af4, 0, 0xf4, 0}, // ] - NF_rev_menu_button3 (2) {0x1af4, 0, 0xf4, 0}, // ] - NF_rev_menu_button3 (2)
{0x1af5, 0, 0xf5, 0}, // ] - NF_shadow_box_right (2) {0x1af5, 0, 0xf5, 0}, // ] - NF_shadow_box_right (2)
{0x1afb, 0, 0xfb, 0}, // ✓ - NF_check_mark (2) {0x1afb, 0, 0xfb, 0}, // ✓ - NF_check_mark (2)
{0x221a, 0, 0xfb, 'x'}, // √ - square root {0x221a, 0, 0xfb, 'x'} // √ - square root
{0x25cf, '`', 0x04, '*'} // ● - black circle
}; };
/* /*
@ -204,7 +203,7 @@ const std::size_t lastKeyItem = \
std::size_t((sizeof(vt100_key_to_utf8) / sizeof(vt100_key_to_utf8[0])) - 1); std::size_t((sizeof(vt100_key_to_utf8) / sizeof(vt100_key_to_utf8[0])) - 1);
wchar_t cp437_to_ucs[][2] = wchar_t cp437_ucs[][2] =
{ {
{0x00, 0x0000}, // null {0x00, 0x0000}, // null
{0x01, 0x263a}, // white smiling face {0x01, 0x263a}, // white smiling face
@ -465,10 +464,10 @@ wchar_t cp437_to_ucs[][2] =
}; };
const std::size_t lastCP437Item = \ const std::size_t lastCP437Item = \
std::size_t((sizeof(cp437_to_ucs) / sizeof(cp437_to_ucs[0])) - 1); std::size_t((sizeof(cp437_ucs) / sizeof(cp437_ucs[0])) - 1);
// Based on http://www.unicode.org/charts/PDF/UFF00.pdf // Based on http://www.unicode.org/charts/PDF/UFF00.pdf
wchar_t halfWidth_fullWidth[][2] = const wchar_t halfWidth_fullWidth[][2] =
{ {
// Fullwidth ASCII variants // Fullwidth ASCII variants
{0x0020, 0x3000}, // ' ' -> ' ' {0x0020, 0x3000}, // ' ' -> ' '

View File

@ -37,18 +37,18 @@ FColorPalette::~FColorPalette() // destructor
void FColorPalette::set8ColorPalette (funcp setPalette) void FColorPalette::set8ColorPalette (funcp setPalette)
{ {
setPalette (fc::Black, 0x00, 0x00, 0x00); setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x22, 0x22, 0xb2); setPalette (fc::Blue, 0x10, 0x3b, 0x9e);
setPalette (fc::Green, 0x18, 0x78, 0x18); setPalette (fc::Green, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0x66, 0x66, 0xff); setPalette (fc::Cyan, 0xa0, 0xb2, 0xb2);
setPalette (fc::Red, 0xb2, 0x18, 0x18); setPalette (fc::Red, 0xb2, 0x18, 0x18);
setPalette (fc::Magenta, 0xb2, 0x18, 0xb2); setPalette (fc::Magenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Brown, 0xe8, 0x87, 0x1f); setPalette (fc::Brown, 0xe8, 0x87, 0x1f);
setPalette (fc::LightGray, 0xe0, 0xe0, 0xe0); setPalette (fc::LightGray, 0xe0, 0xe0, 0xe0);
// The same colors again... // The same colors again...
setPalette (fc::DarkGray, 0x00, 0x00, 0x00); setPalette (fc::DarkGray, 0x00, 0x00, 0x00);
setPalette (fc::LightBlue, 0x22, 0x22, 0xb2); setPalette (fc::LightBlue, 0x10, 0x3b, 0x9e);
setPalette (fc::LightGreen, 0x18, 0x78, 0x18); setPalette (fc::LightGreen, 0x18, 0x78, 0x18);
setPalette (fc::LightCyan, 0x66, 0x66, 0xff); setPalette (fc::Cyan, 0xa0, 0xb2, 0xb2);
setPalette (fc::LightRed, 0xb2, 0x18, 0x18); setPalette (fc::LightRed, 0xb2, 0x18, 0x18);
setPalette (fc::LightMagenta, 0xb2, 0x18, 0xb2); setPalette (fc::LightMagenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Yellow, 0xe8, 0x87, 0x1f); setPalette (fc::Yellow, 0xe8, 0x87, 0x1f);
@ -59,9 +59,9 @@ void FColorPalette::set8ColorPalette (funcp setPalette)
void FColorPalette::set16ColorPalette (funcp setPalette) void FColorPalette::set16ColorPalette (funcp setPalette)
{ {
setPalette (fc::Black, 0x00, 0x00, 0x00); setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x22, 0x22, 0xb2); setPalette (fc::Blue, 0x10, 0x3b, 0x9e);
setPalette (fc::Green, 0x18, 0x78, 0x18); setPalette (fc::Green, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0x4a, 0x4a, 0xe4); setPalette (fc::Cyan, 0x55, 0x6a, 0xcf);
setPalette (fc::Red, 0xba, 0x1a, 0x1a); setPalette (fc::Red, 0xba, 0x1a, 0x1a);
setPalette (fc::Magenta, 0xb2, 0x18, 0xb2); setPalette (fc::Magenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Brown, 0xe8, 0x87, 0x1f); setPalette (fc::Brown, 0xe8, 0x87, 0x1f);

View File

@ -135,7 +135,7 @@ void FDialog::show()
if ( isModal() ) if ( isModal() )
{ {
auto fapp = FApplication::getApplicationObject(); auto fapp = FApplication::getApplicationObject();
fapp->enter_loop(); fapp->enterLoop();
if ( this == getMainWidget() ) if ( this == getMainWidget() )
fapp->quit(); fapp->quit();
@ -150,7 +150,7 @@ void FDialog::hide()
if ( isModal() ) if ( isModal() )
{ {
auto fapp = FApplication::getApplicationObject(); auto fapp = FApplication::getApplicationObject();
fapp->exit_loop(); fapp->exitLoop();
} }
} }
@ -165,7 +165,6 @@ int FDialog::exec()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::setPos (const FPoint& pos, bool) void FDialog::setPos (const FPoint& pos, bool)
{ {
setPos_error = false; setPos_error = false;
// Avoid to move widget completely outside the terminal // Avoid to move widget completely outside the terminal
@ -749,7 +748,7 @@ void FDialog::drawDialogShadow()
if ( isMonochron() && ! getFlags().trans_shadow ) if ( isMonochron() && ! getFlags().trans_shadow )
return; return;
drawShadow(); drawShadow(this);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -926,14 +925,10 @@ void FDialog::drawBorder()
<< fc::NF_rev_border_line_right; // border right⎹ << fc::NF_rev_border_line_right; // border right⎹
} }
print() << r.getLowerLeftPos() // lower left corner border ⎣ print() << r.getLowerLeftPos()
<< fc::NF_border_corner_lower_left; << fc::NF_border_corner_lower_left // ⎣
<< FString(r.getWidth() - 2, fc::NF_border_line_bottom) // _
for (int x = r.getX1() + 1; x < r.getX2(); x++) << fc::NF_rev_border_corner_lower_right; // ⎦
print (fc::NF_border_line_bottom); // low line _
// lower right corner border ⎦
print (fc::NF_rev_border_corner_lower_right);
} }
else else
{ {
@ -1188,7 +1183,7 @@ void FDialog::leaveMenu()
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1233,7 +1228,7 @@ void FDialog::selectFirstMenuItem()
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -25,7 +25,6 @@
#include <strings.h> // need for strcasecmp #include <strings.h> // need for strcasecmp
#endif #endif
#include <pwd.h>
#include <vector> #include <vector>
#include "final/fevent.h" #include "final/fevent.h"
@ -92,6 +91,7 @@ const FString fileChooser ( FWidget* parent
// static class attributes // static class attributes
FSystem* FFileDialog::fsystem{nullptr}; FSystem* FFileDialog::fsystem{nullptr};
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FFileDialog // class FFileDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -453,12 +453,12 @@ void FFileDialog::clear()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
long FFileDialog::numOfDirs() sInt64 FFileDialog::numOfDirs()
{ {
if ( dir_entries.empty() ) if ( dir_entries.empty() )
return 0; return 0;
long n = std::count_if ( std::begin(dir_entries) sInt64 n = std::count_if ( std::begin(dir_entries)
, std::end(dir_entries) , std::end(dir_entries)
, [] (dir_entry& entry) , [] (dir_entry& entry)
{ {
@ -472,14 +472,14 @@ long FFileDialog::numOfDirs()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FFileDialog::sortDir() void FFileDialog::sortDir()
{ {
long start{}; sInt64 start{};
if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 ) if ( std::strcmp((*dir_entries.begin()).name, "..") == 0 )
start = 1; start = 1;
else else
start = 0; start = 0;
long dir_num = numOfDirs(); sInt64 dir_num = numOfDirs();
// directories first // directories first
std::sort ( dir_entries.begin() + start std::sort ( dir_entries.begin() + start
, dir_entries.end() , dir_entries.end()

View File

@ -30,7 +30,7 @@ namespace finalcut
namespace fc namespace fc
{ {
fkeymap Fkey[] = FKeyMap fkey[] =
{ {
{ fc::Fkey_backspace , 0, "kb" }, // backspace key { fc::Fkey_backspace , 0, "kb" }, // backspace key
{ fc::Fkey_catab , 0, "ka" }, // clear-all-tabs key { fc::Fkey_catab , 0, "ka" }, // clear-all-tabs key
@ -205,7 +205,7 @@ fkeymap Fkey[] =
{ 0 , 0, "\0" } { 0 , 0, "\0" }
}; };
fmetakeymap Fmetakey[] = FMetakeyMap fmetakey[] =
{ {
{ fc::Fmkey_ic , "\033[2;3~" }, // M-insert { fc::Fmkey_ic , "\033[2;3~" }, // M-insert
{ fc::Fmkey_ic , "\033\033[2~" }, // M-insert { fc::Fmkey_ic , "\033\033[2~" }, // M-insert
@ -438,7 +438,7 @@ fmetakeymap Fmetakey[] =
{ 0 , "\0" } { 0 , "\0" }
}; };
keyname FkeyName[] = FKeyName fkeyname[] =
{ {
{ fc::Fckey_a , "Ctrl+A" }, { fc::Fckey_a , "Ctrl+A" },
{ fc::Fckey_b , "Ctrl+B" }, { fc::Fckey_b , "Ctrl+B" },

View File

@ -49,25 +49,6 @@ struct timeval FKeyboard::time_keypressed{};
FTermLinux* FKeyboard::linux{nullptr}; FTermLinux* FKeyboard::linux{nullptr};
#endif #endif
//----------------------------------------------------------------------
// class FKeyboardCommand
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FKeyboardCommand::FKeyboardCommand ( FApplication* object
, void(FApplication::*method)() )
: instance(object)
, handler(method)
{ }
// public methods of FKeyboardCommand
//----------------------------------------------------------------------
void FKeyboardCommand::execute()
{
(instance->*handler)();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FKeyboard // class FKeyboard
@ -102,9 +83,9 @@ void FKeyboard::fetchKeyCode()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString FKeyboard::getKeyName (FKey keynum) const FString FKeyboard::getKeyName (FKey keynum)
{ {
for (std::size_t i{0}; fc::FkeyName[i].string[0] != 0; i++) for (std::size_t i{0}; fc::fkeyname[i].string[0] != 0; i++)
if ( fc::FkeyName[i].num && fc::FkeyName[i].num == keynum ) if ( fc::fkeyname[i].num && fc::fkeyname[i].num == keynum )
return FString(fc::FkeyName[i].string); return FString(fc::fkeyname[i].string);
if ( keynum > 32 && keynum < 127 ) if ( keynum > 32 && keynum < 127 )
return FString(char(keynum)); return FString(char(keynum));
@ -113,7 +94,7 @@ const FString FKeyboard::getKeyName (FKey keynum)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FKeyboard::setTermcapMap (fc::fkeymap* keymap) void FKeyboard::setTermcapMap (fc::FKeyMap* keymap)
{ {
key_map = keymap; key_map = keymap;
} }
@ -250,7 +231,7 @@ inline FKey FKeyboard::getTermcapKey()
fifo_buf[n] = '\0'; fifo_buf[n] = '\0';
input_data_pending = bool(fifo_buf[0] != '\0'); input_data_pending = bool(fifo_buf[0] != '\0');
return fc::Fkey[i].num; return fc::fkey[i].num;
} }
} }
@ -264,9 +245,9 @@ inline FKey FKeyboard::getMetaKey()
assert ( FIFO_BUF_SIZE > 0 ); assert ( FIFO_BUF_SIZE > 0 );
for (std::size_t i{0}; fc::Fmetakey[i].string[0] != 0; i++) for (std::size_t i{0}; fc::fmetakey[i].string[0] != 0; i++)
{ {
char* kmeta = fc::Fmetakey[i].string; // The string is never null char* kmeta = fc::fmetakey[i].string; // The string is never null
std::size_t len = std::strlen(kmeta); std::size_t len = std::strlen(kmeta);
if ( std::strncmp(kmeta, fifo_buf, len) == 0 ) // found if ( std::strncmp(kmeta, fifo_buf, len) == 0 ) // found
@ -288,7 +269,7 @@ inline FKey FKeyboard::getMetaKey()
fifo_buf[n] = '\0'; fifo_buf[n] = '\0';
input_data_pending = bool(fifo_buf[0] != '\0'); input_data_pending = bool(fifo_buf[0] != '\0');
return fc::Fmetakey[i].num; return fc::fmetakey[i].num;
} }
} }

View File

@ -21,6 +21,7 @@
***********************************************************************/ ***********************************************************************/
#include <memory> #include <memory>
#include <utility>
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fcolorpair.h" #include "final/fcolorpair.h"
@ -267,7 +268,7 @@ void FLabel::onMouseDown (FMouseEvent* ev)
{ {
accel_widget->getStatusBar()->drawMessage(); accel_widget->getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
} }
@ -294,7 +295,7 @@ void FLabel::onAccel (FAccelEvent* ev)
{ {
accel_widget->getStatusBar()->drawMessage(); accel_widget->getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
} }
@ -333,25 +334,7 @@ void FLabel::init()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLabel::setHotkeyAccelerator() void FLabel::setHotkeyAccelerator()
{ {
FKey hotkey = getHotkey(text); setHotkeyViaString (this, text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (hotkey);
}
else
delAccelerator();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -423,87 +406,48 @@ void FLabel::drawMultiLine()
while ( y < text_lines && y < std::size_t(getHeight()) ) while ( y < text_lines && y < std::size_t(getHeight()) )
{ {
wchar_t* label_text{}; FString label_text{};
std::size_t hotkeypos{NOT_SET}; hotkeypos = NOT_SET;
std::size_t align_offset{};
auto length = multiline_text[y].getLength(); auto length = multiline_text[y].getLength();
auto column_width = getColumnWidth(multiline_text[y]); column_width = getColumnWidth(multiline_text[y]);
try
{
label_text = new wchar_t[length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
auto src = const_cast<wchar_t*>(multiline_text[y].wc_str());
auto dest = const_cast<wchar_t*>(label_text);
if ( ! hotkey_printed ) if ( ! hotkey_printed )
hotkeypos = finalcut::getHotkeyPos(src, dest, length); hotkeypos = finalcut::getHotkeyPos (multiline_text[y], label_text);
else else
std::wcsncpy(dest, src, length); label_text = multiline_text[y];
print() << FPoint(1, 1 + int(y)); print() << FPoint(1, 1 + int(y));
if ( hotkeypos != NOT_SET ) if ( hotkeypos != NOT_SET )
{ {
align_offset = getAlignOffset(length - 1); align_offset = getAlignOffset(length - 1);
printLine (label_text, length - 1, column_width, hotkeypos, align_offset);
hotkey_printed = true; hotkey_printed = true;
} }
else else
{
align_offset = getAlignOffset(length); align_offset = getAlignOffset(length);
printLine (label_text, length, column_width, NOT_SET, align_offset);
}
printLine (std::move(label_text));
y++; y++;
delete[] label_text;
} }
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLabel::drawSingleLine() void FLabel::drawSingleLine()
{ {
wchar_t* label_text{}; FString label_text{};
std::size_t hotkeypos{NOT_SET}; column_width = getColumnWidth(text);
auto length = text.getLength(); hotkeypos = finalcut::getHotkeyPos (text, label_text);
auto column_width = getColumnWidth(text);
try
{
label_text = new wchar_t[length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
hotkeypos = finalcut::getHotkeyPos (text.wc_str(), label_text, length);
if ( hotkeypos != NOT_SET ) if ( hotkeypos != NOT_SET )
{
length--;
column_width--; column_width--;
}
print() << FPoint(1, 1); print() << FPoint(1, 1);
auto align_offset = getAlignOffset(column_width); align_offset = getAlignOffset(column_width);
printLine (label_text, length, column_width, hotkeypos, align_offset); printLine (std::move(label_text));
delete[] label_text;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLabel::printLine ( wchar_t line[] void FLabel::printLine (FString&& line)
, std::size_t length
, std::size_t column_width
, std::size_t hotkeypos
, std::size_t align_offset )
{ {
std::size_t to_char{}; std::size_t to_char{};
std::size_t to_column{}; std::size_t to_column{};
@ -514,13 +458,13 @@ void FLabel::printLine ( wchar_t line[]
if ( column_width <= width ) if ( column_width <= width )
{ {
to_char = length; to_char = line.getLength();
to_column = column_width; to_column = column_width;
} }
else else
{ {
to_column = width - 2; to_column = width - 2;
to_char = getColumnWidthToLength(line, to_column); to_char = getLengthFromColumnWidth(line, to_column);
} }
if ( hasReverseMode() ) if ( hasReverseMode() )
@ -530,8 +474,8 @@ void FLabel::printLine ( wchar_t line[]
{ {
if ( ! std::iswprint(std::wint_t(line[z])) ) if ( ! std::iswprint(std::wint_t(line[z])) )
{ {
if ( ! isNewFont() && ( int(line[z]) < fc::NF_rev_left_arrow2 if ( ! isNewFont() && ( line[z] < fc::NF_rev_left_arrow2
|| int(line[z]) > fc::NF_check_mark ) ) || line[z] > fc::NF_check_mark ) )
{ {
line[z] = L' '; line[z] = L' ';
} }

View File

@ -596,7 +596,7 @@ void FLineEdit::onAccel (FAccelEvent* ev)
{ {
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
} }
@ -623,7 +623,7 @@ void FLineEdit::onFocusIn (FFocusEvent*)
{ {
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -791,7 +791,7 @@ void FLineEdit::drawInputField()
} }
if ( getFlags().shadow ) if ( getFlags().shadow )
drawShadow (); drawShadow(this);
// set the cursor to the insert pos. // set the cursor to the insert pos.
auto cursor_pos_column = getColumnWidth (text, cursor_pos); auto cursor_pos_column = getColumnWidth (text, cursor_pos);
@ -825,7 +825,7 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos)
{ {
if ( char_width == 1 ) if ( char_width == 1 )
{ {
if ( pos > 0 && getColumnWidth(text[pos - 1]) == 2 ) if ( getColumnWidth(text[pos - 1]) == 2 ) // pos is always > 0
{ {
fullwidth_char_offset = 1; fullwidth_char_offset = 1;
break; break;

View File

@ -27,7 +27,6 @@
#include "final/fcolorpair.h" #include "final/fcolorpair.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flistbox.h" #include "final/flistbox.h"
#include "final/fscrollbar.h"
#include "final/fstring.h" #include "final/fstring.h"
#include "final/fstatusbar.h" #include "final/fstatusbar.h"
#include "final/fwidgetcolors.h" #include "final/fwidgetcolors.h"
@ -305,21 +304,16 @@ void FListBox::clear()
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setColor (wc.list_fg, wc.list_bg); setColor (wc.list_fg, wc.list_bg);
std::size_t size = getWidth() - 2; std::size_t size = getWidth() - 2;
drawBorder();
drawHeadline();
if ( size == 0 ) if ( size == 0 )
return; return;
char* blank = createBlankArray(size + 1);
std::memset (blank, ' ', size);
blank[size] = '\0';
for (int y{0}; y < int(getHeight()) - 2; y++) for (int y{0}; y < int(getHeight()) - 2; y++)
{ {
print() << FPoint(2, 2 + y) << blank; print() << FPoint(2, 2 + y) << FString(size, L' ');
} }
destroyBlankArray (blank);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -328,82 +322,7 @@ void FListBox::onKeyPress (FKeyEvent* ev)
std::size_t current_before = current; std::size_t current_before = current;
int xoffset_before = xoffset; int xoffset_before = xoffset;
int yoffset_before = yoffset; int yoffset_before = yoffset;
FKey key = ev->key(); processKeyAction(ev); // Process the keystrokes
switch ( key )
{
case fc::Fkey_return:
case fc::Fkey_enter:
acceptSelection();
ev->accept();
break;
case fc::Fkey_up:
onePosUp();
ev->accept();
break;
case fc::Fkey_down:
onePosDown();
ev->accept();
break;
case fc::Fkey_left:
scrollLeft();
ev->accept();
break;
case fc::Fkey_right:
scrollRight();
ev->accept();
break;
case fc::Fkey_ppage:
onePageUp();
ev->accept();
break;
case fc::Fkey_npage:
onePageDown();
ev->accept();
break;
case fc::Fkey_home:
firstPos();
ev->accept();
break;
case fc::Fkey_end:
lastPos();
ev->accept();
break;
case fc::Fkey_ic: // insert key
if ( changeSelectionAndPosition() )
ev->accept();
break;
case fc::Fkey_space:
if ( spacebarProcessing() )
ev->accept();
break;
case fc::Fkey_erase:
case fc::Fkey_backspace:
if ( deletePreviousCharacter() )
ev->accept();
break;
case fc::Fkey_escape:
case fc::Fkey_escape_mintty:
if ( skipIncrementalSearch() )
ev->accept();
break;
default:
if ( keyIncSearchInput(key) )
ev->accept();
}
if ( current_before != current ) if ( current_before != current )
{ {
@ -462,7 +381,7 @@ void FListBox::onMouseDown (FMouseEvent* ev)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -530,7 +449,7 @@ void FListBox::onMouseMove (FMouseEvent* ev)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
// Auto-scrolling when dragging mouse outside the widget // Auto-scrolling when dragging mouse outside the widget
@ -607,7 +526,7 @@ void FListBox::onTimer (FTimerEvent*)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -653,7 +572,7 @@ void FListBox::onWheel (FWheelEvent* ev)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -754,8 +673,8 @@ inline FString& FListBox::getString (listBoxItems::iterator iter)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::init() void FListBox::init()
{ {
initScrollbar (vbar, fc::vertical, &FListBox::cb_VBarChange); initScrollbar (vbar, fc::vertical, this, &FListBox::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, &FListBox::cb_HBarChange); initScrollbar (hbar, fc::horizontal, this, &FListBox::cb_HBarChange);
setGeometry (FPoint(1, 1), FSize(5, 4), false); // initialize geometry values setGeometry (FPoint(1, 1), FSize(5, 4), false); // initialize geometry values
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
@ -765,32 +684,57 @@ void FListBox::init()
setLeftPadding(1); setLeftPadding(1);
setBottomPadding(1); setBottomPadding(1);
setRightPadding(1 + int(nf_offset)); setRightPadding(1 + int(nf_offset));
mapKeyFunctions();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::initScrollbar ( FScrollbarPtr& bar inline void FListBox::mapKeyFunctions()
, fc::orientation o
, FListBoxCallback callback )
{ {
try key_map[fc::Fkey_return] = std::bind(&FListBox::acceptSelection, this);
{ key_map[fc::Fkey_enter] = std::bind(&FListBox::acceptSelection, this);
bar = std::make_shared<FScrollbar>(o, this); key_map[fc::Fkey_up] = std::bind(&FListBox::onePosUp, this);
} key_map[fc::Fkey_down] = std::bind(&FListBox::onePosDown, this);
catch (const std::bad_alloc& ex) auto left = static_cast<void(FListBox::*)()>(&FListBox::scrollLeft);
{ key_map[fc::Fkey_left] = std::bind(left, this);
std::cerr << bad_alloc_str << ex.what() << std::endl; auto right = static_cast<void(FListBox::*)()>(&FListBox::scrollRight);
return; key_map[fc::Fkey_right] = std::bind(right, this);
} key_map[fc::Fkey_ppage] = std::bind(&FListBox::onePageUp, this);
key_map[fc::Fkey_npage] = std::bind(&FListBox::onePageDown, this);
key_map[fc::Fkey_home] = std::bind(&FListBox::firstPos, this);
key_map[fc::Fkey_end] = std::bind(&FListBox::lastPos, this);
key_map_result[fc::Fkey_ic] = \
std::bind(&FListBox::changeSelectionAndPosition, this);
key_map_result[fc::Fkey_space] = \
std::bind(&FListBox::spacebarProcessing, this);
key_map_result[fc::Fkey_erase] = \
std::bind(&FListBox::deletePreviousCharacter, this);
key_map_result[fc::Fkey_backspace] = \
std::bind(&FListBox::deletePreviousCharacter, this);
key_map_result[fc::Fkey_escape] = \
std::bind(&FListBox::skipIncrementalSearch, this);
key_map_result[fc::Fkey_escape_mintty] = \
std::bind(&FListBox::skipIncrementalSearch, this);
}
bar->setMinimum(0); //----------------------------------------------------------------------
bar->setValue(0); void FListBox::processKeyAction (FKeyEvent* ev)
bar->hide(); {
int idx = int(ev->key());
bar->addCallback if ( key_map.find(idx) != key_map.end() )
( {
"change-value", key_map[idx]();
F_METHOD_CALLBACK (this, callback) ev->accept();
); }
else if ( key_map_result.find(idx) != key_map_result.end() )
{
if ( key_map_result[idx]() )
ev->accept();
}
else if ( keyIncSearchInput(ev->key()) )
{
ev->accept();
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1172,7 +1116,7 @@ inline void FListBox::updateDrawing (bool draw_vbar, bool draw_hbar)
hbar->drawBar(); hbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1802,7 +1746,7 @@ void FListBox::lazyConvert(listBoxItems::iterator iter, int y)
if ( conv_type != lazy_convert || ! iter->getText().isNull() ) if ( conv_type != lazy_convert || ! iter->getText().isNull() )
return; return;
convertToItem (*iter, source_container, y + yoffset); lazy_inserter (*iter, source_container, y + yoffset);
std::size_t column_width = getColumnWidth(iter->text); std::size_t column_width = getColumnWidth(iter->text);
recalculateHorizontalBar (column_width, hasBrackets(iter)); recalculateHorizontalBar (column_width, hasBrackets(iter));
@ -1872,7 +1816,7 @@ void FListBox::cb_VBarChange (FWidget*, FDataPtr)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -1925,7 +1869,7 @@ void FListBox::cb_HBarChange (FWidget*, FDataPtr)
{ {
drawList(); drawList();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
if ( scrollType >= FScrollbar::scrollStepBackward ) if ( scrollType >= FScrollbar::scrollStepBackward )
@ -1936,7 +1880,7 @@ void FListBox::cb_HBarChange (FWidget*, FDataPtr)
hbar->drawBar(); hbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }

View File

@ -25,6 +25,7 @@
#endif #endif
#include <memory> #include <memory>
#include <unordered_map>
#include <vector> #include <vector>
#include "final/emptyfstring.h" #include "final/emptyfstring.h"
@ -32,7 +33,6 @@
#include "final/fcolorpair.h" #include "final/fcolorpair.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flistview.h" #include "final/flistview.h"
#include "final/fscrollbar.h"
#include "final/fstatusbar.h" #include "final/fstatusbar.h"
#include "final/fstring.h" #include "final/fstring.h"
#include "final/ftermbuffer.h" #include "final/ftermbuffer.h"
@ -42,7 +42,7 @@ namespace finalcut
{ {
// Static class attribute // Static class attribute
FObject::FObjectIterator FListView::null_iter; FObject::iterator FListView::null_iter;
// Function prototypes // Function prototypes
uInt64 firstNumberFromString (const FString&); uInt64 firstNumberFromString (const FString&);
@ -55,14 +55,13 @@ bool sortDescendingByNumber (const FObject*, const FObject*);
//---------------------------------------------------------------------- //----------------------------------------------------------------------
uInt64 firstNumberFromString (const FString& str) uInt64 firstNumberFromString (const FString& str)
{ {
auto last = str.end();
auto iter = str.begin(); auto iter = str.begin();
while ( iter != last ) while ( iter != str.end() )
{ {
if ( wchar_t(*iter) >= L'0' && wchar_t(*iter) <= L'9' ) if ( wchar_t(*iter) >= L'0' && wchar_t(*iter) <= L'9' )
{ {
if ( wchar_t(*(iter - 1)) == L'-' ) if ( iter != str.begin() && wchar_t(*(iter - 1)) == L'-' )
--iter; --iter;
break; break;
@ -73,10 +72,10 @@ uInt64 firstNumberFromString (const FString& str)
auto first_pos = iter; auto first_pos = iter;
if ( first_pos == last ) if ( first_pos == str.end() )
return 0; return 0;
while ( iter != last ) while ( iter != str.end() )
{ {
if ( wchar_t(*iter) < L'0' || wchar_t(*iter) > L'9' ) if ( wchar_t(*iter) < L'0' || wchar_t(*iter) > L'9' )
break; break;
@ -86,7 +85,7 @@ uInt64 firstNumberFromString (const FString& str)
auto last_pos = iter; auto last_pos = iter;
if ( last_pos == last ) if ( last_pos == str.end() )
return 0; return 0;
uInt64 number; uInt64 number;
@ -186,7 +185,7 @@ FListViewItem::FListViewItem (const FListViewItem& item)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListViewItem::FListViewItem (FObjectIterator parent_iter) FListViewItem::FListViewItem (iterator parent_iter)
: FObject((*parent_iter)->getParent()) : FObject((*parent_iter)->getParent())
{ {
insert (this, parent_iter); insert (this, parent_iter);
@ -195,7 +194,7 @@ FListViewItem::FListViewItem (FObjectIterator parent_iter)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListViewItem::FListViewItem ( const FStringList& cols FListViewItem::FListViewItem ( const FStringList& cols
, FDataPtr data , FDataPtr data
, FObjectIterator parent_iter ) , iterator parent_iter )
: FObject(nullptr) : FObject(nullptr)
, column_list(cols) , column_list(cols)
, data_pointer(data) , data_pointer(data)
@ -279,7 +278,7 @@ void FListViewItem::setText (int column, const FString& text)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FObject::FObjectIterator FListViewItem::insert (FListViewItem* child) FObject::iterator FListViewItem::insert (FListViewItem* child)
{ {
// Add a FListViewItem as child element // Add a FListViewItem as child element
if ( ! child ) if ( ! child )
@ -289,8 +288,8 @@ FObject::FObjectIterator FListViewItem::insert (FListViewItem* child)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FObject::FObjectIterator FListViewItem::insert ( FListViewItem* child FObject::iterator FListViewItem::insert ( FListViewItem* child
, FObjectIterator parent_iter ) , iterator parent_iter )
{ {
if ( parent_iter == FListView::null_iter ) if ( parent_iter == FListView::null_iter )
return FListView::null_iter; return FListView::null_iter;
@ -353,7 +352,7 @@ void FListViewItem::sort (Compare cmp)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FObject::FObjectIterator FListViewItem::appendItem (FListViewItem* child) FObject::iterator FListViewItem::appendItem (FListViewItem* child)
{ {
expandable = true; expandable = true;
resetVisibleLineCounter(); resetVisibleLineCounter();
@ -434,7 +433,7 @@ void FListViewItem::resetVisibleLineCounter()
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListViewIterator::FListViewIterator (FObjectIterator iter) FListViewIterator::FListViewIterator (iterator iter)
: node(iter) : node(iter)
{ } { }
@ -496,7 +495,7 @@ FListViewIterator& FListViewIterator::operator -= (volatile int n)
// private methods of FListViewIterator // private methods of FListViewIterator
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListViewIterator::nextElement (FObjectIterator& iter) void FListViewIterator::nextElement (iterator& iter)
{ {
auto item = static_cast<FListViewItem*>(*iter); auto item = static_cast<FListViewItem*>(*iter);
@ -526,7 +525,7 @@ void FListViewIterator::nextElement (FObjectIterator& iter)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListViewIterator::prevElement (FObjectIterator& iter) void FListViewIterator::prevElement (iterator& iter)
{ {
auto start_iter = iter; auto start_iter = iter;
@ -713,7 +712,7 @@ void FListView::setColumnSortType (int column, fc::sorting_type type)
if ( column < 1 || header.empty() || column > int(header.size()) ) if ( column < 1 || header.empty() || column > int(header.size()) )
return; return;
std::size_t size = std::size_t(column + 1); std::size_t size = std::size_t(column) + 1;
if ( sort_type.empty() || sort_type.size() < size ) if ( sort_type.empty() || sort_type.size() < size )
sort_type.resize(size); sort_type.resize(size);
@ -760,10 +759,10 @@ void FListView::hide()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FObject::FObjectIterator FListView::insert ( FListViewItem* item FObject::iterator FListView::insert ( FListViewItem* item
, FObjectIterator parent_iter ) , iterator parent_iter )
{ {
FObjectIterator item_iter; iterator item_iter;
if ( parent_iter == FListView::null_iter ) if ( parent_iter == FListView::null_iter )
return FListView::null_iter; return FListView::null_iter;
@ -799,9 +798,9 @@ FObject::FObjectIterator FListView::insert ( FListViewItem* item
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FObject::FObjectIterator FListView::insert ( const FStringList& cols FObject::iterator FListView::insert ( const FStringList& cols
, FDataPtr d , FDataPtr d
, FObjectIterator parent_iter ) , iterator parent_iter )
{ {
FListViewItem* item; FListViewItem* item;
@ -877,79 +876,11 @@ void FListView::sort()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::onKeyPress (FKeyEvent* ev) void FListView::onKeyPress (FKeyEvent* ev)
{ {
int position_before = current_iter.getPosition() int position_before = current_iter.getPosition();
, xoffset_before = xoffset int xoffset_before = xoffset;
, first_line_position_before = first_visible_line.getPosition() first_line_position_before = first_visible_line.getPosition();
, pagesize = int(getClientHeight()) - 1;
FKey key = ev->key();
clicked_expander_pos.setPoint(-1, -1); clicked_expander_pos.setPoint(-1, -1);
processKeyAction(ev); // Process the keystrokes
switch ( key )
{
case fc::Fkey_return:
case fc::Fkey_enter:
processClick();
ev->accept();
break;
case fc::Fkey_space:
toggleCheckbox();
ev->accept();
break;
case fc::Fkey_up:
stepBackward();
ev->accept();
break;
case fc::Fkey_down:
stepForward();
ev->accept();
break;
case fc::Fkey_left:
collapseAndScrollLeft (first_line_position_before);
ev->accept();
break;
case fc::Fkey_right:
expandAndScrollRight (first_line_position_before);
ev->accept();
break;
case fc::Fkey_ppage:
stepBackward(pagesize);
ev->accept();
break;
case fc::Fkey_npage:
stepForward(pagesize);
ev->accept();
break;
case fc::Fkey_home:
firstPos();
ev->accept();
break;
case fc::Fkey_end:
lastPos();
ev->accept();
break;
case int('+'):
if ( expandSubtree() )
ev->accept();
break;
case int('-'):
if ( collapseSubtree() )
ev->accept();
break;
default:
ev->ignore();
}
if ( position_before != current_iter.getPosition() ) if ( position_before != current_iter.getPosition() )
processChanged(); processChanged();
@ -984,9 +915,9 @@ void FListView::onMouseDown (FMouseEvent* ev)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
} }
int first_line_position_before = first_visible_line.getPosition() int mouse_x = ev->getX();
, mouse_x = ev->getX() int mouse_y = ev->getY();
, mouse_y = ev->getY(); first_line_position_before = first_visible_line.getPosition();
if ( mouse_x > 1 && mouse_x < int(getWidth()) ) if ( mouse_x > 1 && mouse_x < int(getWidth()) )
{ {
@ -1037,7 +968,7 @@ void FListView::onMouseDown (FMouseEvent* ev)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
} }
@ -1121,9 +1052,9 @@ void FListView::onMouseMove (FMouseEvent* ev)
return; return;
} }
int first_line_position_before = first_visible_line.getPosition() int mouse_x = ev->getX();
, mouse_x = ev->getX() int mouse_y = ev->getY();
, mouse_y = ev->getY(); first_line_position_before = first_visible_line.getPosition();
if ( mouse_x > 1 && mouse_x < int(getWidth()) if ( mouse_x > 1 && mouse_x < int(getWidth())
&& mouse_y > 1 && mouse_y < int(getHeight()) ) && mouse_y > 1 && mouse_y < int(getHeight()) )
@ -1142,7 +1073,7 @@ void FListView::onMouseMove (FMouseEvent* ev)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
// auto-scrolling when dragging mouse outside the widget // auto-scrolling when dragging mouse outside the widget
@ -1196,8 +1127,8 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::onTimer (FTimerEvent*) void FListView::onTimer (FTimerEvent*)
{ {
int position_before = current_iter.getPosition() int position_before = current_iter.getPosition();
, first_line_position_before = first_visible_line.getPosition(); first_line_position_before = first_visible_line.getPosition();
switch ( int(drag_scroll) ) switch ( int(drag_scroll) )
{ {
@ -1229,15 +1160,15 @@ void FListView::onTimer (FTimerEvent*)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::onWheel (FWheelEvent* ev) void FListView::onWheel (FWheelEvent* ev)
{ {
int position_before = current_iter.getPosition() int position_before = current_iter.getPosition();
, first_line_position_before = first_visible_line.getPosition() int pagesize{4};
, pagesize{4}; first_line_position_before = first_visible_line.getPosition();
if ( drag_scroll != fc::noScroll ) if ( drag_scroll != fc::noScroll )
stopDragScroll(); stopDragScroll();
@ -1268,7 +1199,7 @@ void FListView::onWheel (FWheelEvent* ev)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1379,8 +1310,8 @@ void FListView::adjustSize()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::init() void FListView::init()
{ {
initScrollbar (vbar, fc::vertical, &FListView::cb_VBarChange); initScrollbar (vbar, fc::vertical, this, &FListView::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, &FListView::cb_HBarChange); initScrollbar (hbar, fc::horizontal, this, &FListView::cb_HBarChange);
selflist.push_back(this); selflist.push_back(this);
root = selflist.begin(); root = selflist.begin();
null_iter = selflist.end(); null_iter = selflist.end();
@ -1393,32 +1324,46 @@ void FListView::init()
setLeftPadding(1); setLeftPadding(1);
setBottomPadding(1); setBottomPadding(1);
setRightPadding(1 + int(nf_offset)); setRightPadding(1 + int(nf_offset));
mapKeyFunctions();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::initScrollbar ( FScrollbarPtr& bar inline void FListView::mapKeyFunctions()
, fc::orientation o
, FListViewCallback callback )
{ {
try key_map[fc::Fkey_return] = std::bind(&FListView::processClick, this);
{ key_map[fc::Fkey_enter] = std::bind(&FListView::processClick, this);
bar = std::make_shared<FScrollbar>(o, this); key_map[fc::Fkey_space] = std::bind(&FListView::toggleCheckbox, this);
} key_map[fc::Fkey_up] = [&] { stepBackward(); };
catch (const std::bad_alloc& ex) key_map[fc::Fkey_down] = [&] { stepForward(); };
{ key_map[fc::Fkey_left] = std::bind(&FListView::collapseAndScrollLeft, this);
std::cerr << bad_alloc_str << ex.what() << std::endl; key_map[fc::Fkey_right] = std::bind(&FListView::expandAndScrollRight, this);
return; key_map[fc::Fkey_ppage] = [&] { stepBackward(int(getClientHeight()) - 1); };
} key_map[fc::Fkey_npage] = [&] { stepForward(int(getClientHeight()) - 1); };
key_map[fc::Fkey_home] = std::bind(&FListView::firstPos, this);
key_map[fc::Fkey_end] = std::bind(&FListView::lastPos, this);
key_map_result[FKey('+')] = std::bind(&FListView::expandSubtree, this);
key_map_result[FKey('-')] = std::bind(&FListView::collapseSubtree, this);
}
bar->setMinimum(0); //----------------------------------------------------------------------
bar->setValue(0); void FListView::processKeyAction (FKeyEvent* ev)
bar->hide(); {
int idx = int(ev->key());
bar->addCallback if ( key_map.find(idx) != key_map.end() )
( {
"change-value", key_map[idx]();
F_METHOD_CALLBACK (this, callback) ev->accept();
); }
else if ( key_map_result.find(idx) != key_map_result.end() )
{
if ( key_map_result[idx]() )
ev->accept();
}
else
{
ev->ignore();
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1648,11 +1593,8 @@ void FListView::drawListLine ( const FListViewItem* item
width -= (indent + 1); width -= (indent + 1);
if ( item->isCheckable() ) if ( item->isCheckable() )
{
static constexpr std::size_t checkbox_space = 4;
width -= checkbox_space; width -= checkbox_space;
} }
}
// Insert alignment spaces // Insert alignment spaces
if ( align_offset > 0 ) if ( align_offset > 0 )
@ -1881,7 +1823,7 @@ void FListView::drawBufferedHeadline()
std::size_t offset{0}; std::size_t offset{0};
bool left_truncated_fullwidth{false}; bool left_truncated_fullwidth{false};
bool right_truncated_fullwidth{false}; bool right_truncated_fullwidth{false};
std::vector<charData>::const_iterator first{}, last{}; std::vector<FChar>::const_iterator first{}, last{};
last = headerline.end(); last = headerline.end();
// Search for the start position // Search for the start position
@ -1992,14 +1934,13 @@ void FListView::updateDrawing (bool draw_vbar, bool draw_hbar)
hbar->drawBar(); hbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::size_t FListView::determineLineWidth (FListViewItem* item) std::size_t FListView::determineLineWidth (FListViewItem* item)
{ {
static constexpr std::size_t padding_space = 1; static constexpr std::size_t padding_space = 1;
static constexpr std::size_t checkbox_space = 4;
std::size_t line_width = padding_space; // leading space std::size_t line_width = padding_space; // leading space
std::size_t column_idx{0}; std::size_t column_idx{0};
std::size_t entries = std::size_t(item->column_list.size()); std::size_t entries = std::size_t(item->column_list.size());
@ -2109,7 +2050,7 @@ void FListView::recalculateVerticalBar (std::size_t element_count)
void FListView::mouseHeaderClicked() void FListView::mouseHeaderClicked()
{ {
int column{1}; int column{1};
int checkbox_offset = ( hasCheckableItems() ) ? 4 : 0; int checkbox_offset = ( hasCheckableItems() ) ? checkbox_space : 0;
int header_start = 2 + checkbox_offset; int header_start = 2 + checkbox_offset;
int header_pos = clicked_header_pos.getX() + xoffset; int header_pos = clicked_header_pos.getX() + xoffset;
@ -2287,7 +2228,7 @@ void FListView::stopDragScroll()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FObject::FObjectIterator FListView::appendItem (FListViewItem* item) FObject::iterator FListView::appendItem (FListViewItem* item)
{ {
item->root = root; item->root = root;
addChild (item); addChild (item);
@ -2323,7 +2264,7 @@ inline void FListView::toggleCheckbox()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListView::collapseAndScrollLeft (int& first_line_position_before) inline void FListView::collapseAndScrollLeft()
{ {
if ( itemlist.empty() ) if ( itemlist.empty() )
return; return;
@ -2380,7 +2321,7 @@ inline void FListView::collapseAndScrollLeft (int& first_line_position_before)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListView::expandAndScrollRight (int& first_line_position_before) inline void FListView::expandAndScrollRight()
{ {
if ( itemlist.empty() ) if ( itemlist.empty() )
return; return;
@ -2650,9 +2591,9 @@ void FListView::scrollBy (int dx, int dy)
void FListView::cb_VBarChange (FWidget*, FDataPtr) void FListView::cb_VBarChange (FWidget*, FDataPtr)
{ {
FScrollbar::sType scrollType = vbar->getScrollType(); FScrollbar::sType scrollType = vbar->getScrollType();
int distance{1} int distance{1};
, pagesize{4} int pagesize{4};
, first_line_position_before = first_visible_line.getPosition(); first_line_position_before = first_visible_line.getPosition();
switch ( scrollType ) switch ( scrollType )
{ {
@ -2701,7 +2642,7 @@ void FListView::cb_VBarChange (FWidget*, FDataPtr)
vbar->drawBar(); vbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -2753,7 +2694,7 @@ void FListView::cb_HBarChange (FWidget*, FDataPtr)
drawHeadlines(); drawHeadlines();
drawList(); drawList();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
if ( scrollType >= FScrollbar::scrollStepBackward ) if ( scrollType >= FScrollbar::scrollStepBackward )
@ -2764,7 +2705,7 @@ void FListView::cb_HBarChange (FWidget*, FDataPtr)
hbar->drawBar(); hbar->drawBar();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }

View File

@ -102,7 +102,7 @@ void FMenu::hide()
const auto& t_geometry = getTermGeometryWithShadow(); const auto& t_geometry = getTermGeometryWithShadow();
restoreVTerm (t_geometry); restoreVTerm (t_geometry);
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
if ( ! isSubMenu() ) if ( ! isSubMenu() )
{ {
@ -204,7 +204,7 @@ void FMenu::onMouseDown (FMouseEvent* ev)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
return; return;
@ -313,7 +313,7 @@ void FMenu::onMouseMove (FMouseEvent* ev)
{ {
closeOpenedSubMenu(); closeOpenedSubMenu();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -584,7 +584,7 @@ void FMenu::openSubMenu (FMenu* sub_menu, bool select)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -696,7 +696,7 @@ void FMenu::mouseDownSubmenu (FMenuItem* m_item)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -764,7 +764,7 @@ bool FMenu::mouseUpOverList (FPoint mouse_pos)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
return true; return true;
@ -1038,7 +1038,7 @@ bool FMenu::selectNextItem()
redraw(); redraw();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
break; break;
} }
@ -1088,7 +1088,7 @@ bool FMenu::selectPrevItem()
redraw(); redraw();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
break; break;
} }
} }
@ -1151,7 +1151,7 @@ bool FMenu::hotkeyMenu (FKeyEvent* ev)
hide(); hide();
hideSuperMenus(); hideSuperMenus();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
ev->accept(); ev->accept();
item->processClicked(); item->processClicked();
} }
@ -1178,7 +1178,7 @@ void FMenu::draw()
clearArea(); clearArea();
drawBorder(); drawBorder();
drawItems(); drawItems();
drawShadow(); drawShadow(this);
if ( isMonochron() ) if ( isMonochron() )
setReverse(false); setReverse(false);
@ -1236,8 +1236,6 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y)
{ {
FString txt(m_item->getText()); FString txt(m_item->getText());
menuText txtdata{}; menuText txtdata{};
std::size_t txt_length = txt.getLength();
std::size_t to_char = txt_length;
std::size_t column_width = getColumnWidth(txt); std::size_t column_width = getColumnWidth(txt);
FKey accel_key = m_item->accel_key; FKey accel_key = m_item->accel_key;
bool is_enabled = m_item->isEnabled(); bool is_enabled = m_item->isEnabled();
@ -1252,25 +1250,11 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y)
// Print leading blank space // Print leading blank space
print (' '); print (' ');
try hotkeypos = finalcut::getHotkeyPos(txt, txtdata.text);
{
txtdata.text = new wchar_t[txt_length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
hotkeypos = finalcut::getHotkeyPos(txt.wc_str(), txtdata.text, txt_length);
if ( hotkeypos != NOT_SET ) if ( hotkeypos != NOT_SET )
{
to_char--;
column_width--; column_width--;
}
txtdata.length = to_char;
txtdata.no_underline = m_item->getFlags().no_underline; txtdata.no_underline = m_item->getFlags().no_underline;
setCursorToHotkeyPosition (m_item); setCursorToHotkeyPosition (m_item);
@ -1292,8 +1276,6 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y)
if ( isMonochron() && is_enabled && is_selected ) if ( isMonochron() && is_enabled && is_selected )
setReverse(true); setReverse(true);
delete[] txtdata.text;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1347,13 +1329,13 @@ inline void FMenu::drawMenuText (menuText& data)
{ {
// Print menu text // Print menu text
for (std::size_t z{0}; z < data.length; z++) for (std::size_t z{0}; z < data.text.getLength(); z++)
{ {
if ( ! std::iswprint(std::wint_t(data.text[z])) ) if ( ! std::iswprint(std::wint_t(data.text[z])) )
{ {
if ( ! isNewFont() if ( ! isNewFont()
&& ( int(data.text[z]) < fc::NF_rev_left_arrow2 && ( data.text[z] < fc::NF_rev_left_arrow2
|| int(data.text[z]) > fc::NF_check_mark ) || data.text[z] > fc::NF_check_mark )
&& ! charEncodable(wchar_t(data.text[z])) ) && ! charEncodable(wchar_t(data.text[z])) )
{ {
data.text[z] = L' '; data.text[z] = L' ';
@ -1512,7 +1494,7 @@ inline void FMenu::selectPrevMenu (FKeyEvent* ev)
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
else else
keypressMenuBar(ev); // select previous menu keypressMenuBar(ev); // select previous menu
@ -1585,7 +1567,7 @@ inline void FMenu::closeMenu()
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -64,15 +64,13 @@ void FMenuBar::resetMenu()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuBar::hide() void FMenuBar::hide()
{ {
FWindow::hide();
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
FColor fg = wc.term_fg; FColor fg = wc.term_fg;
FColor bg = wc.term_bg; FColor bg = wc.term_bg;
setColor (fg, bg); setColor (fg, bg);
screenWidth = getDesktopWidth(); print() << FPoint(1, 1) << FString(getDesktopWidth(), L' ');
char* blank = createBlankArray (screenWidth + 1); updateTerminal();
print() << FPoint(1, 1) << blank; FWindow::hide();
destroyBlankArray (blank);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -482,14 +480,13 @@ void FMenuBar::drawItems()
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
screenWidth = getDesktopWidth();
std::size_t x{1}; std::size_t x{1};
for (auto&& item : list) for (auto&& item : list)
drawItem (item, x); drawItem (item, x);
// Print spaces to end of line // Print spaces to end of line
for (; x <= screenWidth; x++) for (; x <= getDesktopWidth(); x++)
print (' '); print (' ');
if ( isMonochron() ) if ( isMonochron() )
@ -503,8 +500,6 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x)
txtdata.startpos = x + 1; txtdata.startpos = x + 1;
txtdata.no_underline = menuitem->getFlags().no_underline; txtdata.no_underline = menuitem->getFlags().no_underline;
FString txt(menuitem->getText()); FString txt(menuitem->getText());
std::size_t to_char{};
std::size_t txt_length = txt.getLength();
std::size_t column_width = getColumnWidth(txt); std::size_t column_width = getColumnWidth(txt);
bool is_enabled = menuitem->isEnabled(); bool is_enabled = menuitem->isEnabled();
bool is_selected = menuitem->isSelected(); bool is_selected = menuitem->isSelected();
@ -513,33 +508,14 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x)
setLineAttributes (menuitem); setLineAttributes (menuitem);
drawLeadingSpace (x); drawLeadingSpace (x);
try if ( x - 1 > screenWidth )
{ txt = txt.left(getColumnWidth(txt) - screenWidth - x - 1);
txtdata.text = new wchar_t[txt_length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
if ( x - 1 <= screenWidth ) std::size_t hotkeypos = finalcut::getHotkeyPos(txt, txtdata.text);
to_char = txt_length;
else
to_char = txt_length - screenWidth - x - 1;
std::size_t hotkeypos = finalcut::getHotkeyPos ( txt.wc_str()
, txtdata.text
, txt_length );
if ( hotkeypos != NOT_SET ) if ( hotkeypos != NOT_SET )
{
txt_length--;
column_width--; column_width--;
to_char--;
}
txtdata.length = to_char;
x += column_width; x += column_width;
if ( ! is_enabled || is_selected ) if ( ! is_enabled || is_selected )
@ -557,8 +533,6 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x)
if ( isMonochron() && is_enabled && is_selected ) if ( isMonochron() && is_enabled && is_selected )
setReverse(true); setReverse(true);
delete[] txtdata.text;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -617,7 +591,7 @@ inline void FMenuBar::drawMenuText (menuText& data)
{ {
// Print menu text // Print menu text
for (std::size_t z{0}; z < data.length; z++) for (std::size_t z{0}; z < data.text.getLength(); z++)
{ {
if ( data.startpos > screenWidth - z ) if ( data.startpos > screenWidth - z )
break; break;
@ -625,8 +599,8 @@ inline void FMenuBar::drawMenuText (menuText& data)
if ( ! std::iswprint(std::wint_t(data.text[z])) ) if ( ! std::iswprint(std::wint_t(data.text[z])) )
{ {
if ( ! isNewFont() if ( ! isNewFont()
&& ( int(data.text[z]) < fc::NF_rev_left_arrow2 && ( data.text[z] < fc::NF_rev_left_arrow2
|| int(data.text[z]) > fc::NF_check_mark ) ) || data.text[z] > fc::NF_check_mark ) )
{ {
data.text[z] = L' '; data.text[z] = L' ';
} }
@ -997,7 +971,7 @@ void FMenuBar::leaveMenuBar()
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
mouse_down = false; mouse_down = false;
} }

View File

@ -206,7 +206,7 @@ void FMenuItem::setText (const FString& txt)
void FMenuItem::addAccelerator (FKey key, FWidget* obj) void FMenuItem::addAccelerator (FKey key, FWidget* obj)
{ {
auto root = getRootWidget(); auto root = getRootWidget();
accelerator accel = { key, obj }; FAccelerator accel = { key, obj };
if ( root && root->getAcceleratorList() ) if ( root && root->getAcceleratorList() )
{ {
@ -270,7 +270,7 @@ void FMenuItem::openMenu()
dd_menu->raiseWindow(); dd_menu->raiseWindow();
dd_menu->redraw(); dd_menu->redraw();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -567,7 +567,7 @@ void FMenuItem::init (FWidget* parent)
addCallback // for this element addCallback // for this element
( (
"deactivate", "deactivate",
F_METHOD_CALLBACK (parent, &FMenuBar::cb_item_deactivated) F_METHOD_CALLBACK (menubar_ptr, &FMenuBar::cb_item_deactivated)
); );
} }
else if ( isMenu(parent) ) // Parent is menu else if ( isMenu(parent) ) // Parent is menu

View File

@ -53,7 +53,7 @@ FMouse::FMouse()
// public methods of FMouse // public methods of FMouse
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const char* FMouse::getClassName() const const FString FMouse::getClassName() const
{ {
return "FMouse"; return "FMouse";
} }
@ -215,7 +215,7 @@ void FMouse::clearButtonState()
// protected methods of FMouse // protected methods of FMouse
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FMouse::button& FMouse::getButtonState() inline FMouse::FMouseButton& FMouse::getButtonState()
{ {
return b_state; return b_state;
} }
@ -314,7 +314,7 @@ FMouseGPM::~FMouseGPM() // destructor
// public methods of FMouseX11 // public methods of FMouseX11
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const char* FMouseGPM::getClassName() const const FString FMouseGPM::getClassName() const
{ {
return "FMouseGPM"; return "FMouseGPM";
} }
@ -555,7 +555,7 @@ int FMouseGPM::gpmEvent (bool clear)
// public methods of FMouseX11 // public methods of FMouseX11
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const char* FMouseX11::getClassName() const const FString FMouseX11::getClassName() const
{ {
return "FMouseX11"; return "FMouseX11";
} }
@ -733,7 +733,7 @@ void FMouseX11::setButtonState (int btn, struct timeval* time)
// public methods of FMouseSGR // public methods of FMouseSGR
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const char* FMouseSGR::getClassName() const const FString FMouseSGR::getClassName() const
{ {
return "FMouseSGR"; return "FMouseSGR";
} }
@ -962,7 +962,7 @@ void FMouseSGR::setReleasedButtonState (int btn)
// public methods of FMouseUrxvt // public methods of FMouseUrxvt
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const char* FMouseUrxvt::getClassName() const const FString FMouseUrxvt::getClassName() const
{ {
return "FMouseUrxvt"; return "FMouseUrxvt";
} }

View File

@ -32,7 +32,7 @@ namespace finalcut
// static class attributes // static class attributes
bool FObject::timer_modify_lock; bool FObject::timer_modify_lock;
FObject::TimerList* FObject::timer_list{nullptr}; FObject::FTimerList* FObject::timer_list{nullptr};
const FString* fc::emptyFString::empty_string{nullptr}; const FString* fc::emptyFString::empty_string{nullptr};
@ -58,7 +58,7 @@ FObject::FObject (FObject* parent)
{ {
try try
{ {
timer_list = new TimerList; timer_list = new FTimerList;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc& ex)
{ {
@ -281,7 +281,7 @@ int FObject::addTimer (int interval)
time_interval.tv_usec = (interval % 1000) * 1000; time_interval.tv_usec = (interval % 1000) * 1000;
getCurrentTime (&currentTime); getCurrentTime (&currentTime);
timeval timeout = currentTime + time_interval; timeval timeout = currentTime + time_interval;
timer_data t{ id, time_interval, timeout, this }; FTimerData t{ id, time_interval, timeout, this };
// insert in list sorted by timeout // insert in list sorted by timeout
auto iter = timer_list->begin(); auto iter = timer_list->begin();

View File

@ -450,7 +450,7 @@ void FOptiAttr::set_orig_orig_colors (char cap[])
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FOptiAttr::isNormal (charData*& ch) bool FOptiAttr::isNormal (FChar*& ch)
{ {
return hasNoAttribute(ch) && ! hasColor(ch); return hasNoAttribute(ch) && ! hasColor(ch);
} }
@ -542,7 +542,7 @@ FColor FOptiAttr::vga2ansi (FColor color)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
char* FOptiAttr::changeAttribute (charData*& term, charData*& next) char* FOptiAttr::changeAttribute (FChar*& term, FChar*& next)
{ {
const bool next_has_color = hasColor(next); const bool next_has_color = hasColor(next);
fake_reverse = false; fake_reverse = false;
@ -558,7 +558,7 @@ char* FOptiAttr::changeAttribute (charData*& term, charData*& next)
// Simulate invisible characters // Simulate invisible characters
if ( ! F_enter_secure_mode.cap && next->attr.bit.invisible ) if ( ! F_enter_secure_mode.cap && next->attr.bit.invisible )
next->encoded_code = ' '; next->encoded_char = ' ';
// Look for no changes // Look for no changes
if ( ! (switchOn() || switchOff() || hasColorChanged(term, next)) ) if ( ! (switchOn() || switchOff() || hasColorChanged(term, next)) )
@ -584,7 +584,7 @@ char* FOptiAttr::changeAttribute (charData*& term, charData*& next)
// private methods of FOptiAttr // private methods of FOptiAttr
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermBold (charData*& term) inline bool FOptiAttr::setTermBold (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -598,7 +598,7 @@ inline bool FOptiAttr::setTermBold (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermBold (charData*& term) inline bool FOptiAttr::unsetTermBold (FChar*& term)
{ {
// Back to normal intensity (turns off bold + dim) // Back to normal intensity (turns off bold + dim)
@ -620,7 +620,7 @@ inline bool FOptiAttr::unsetTermBold (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermDim (charData*& term) inline bool FOptiAttr::setTermDim (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -634,7 +634,7 @@ inline bool FOptiAttr::setTermDim (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermDim (charData*& term) inline bool FOptiAttr::unsetTermDim (FChar*& term)
{ {
// Back to normal intensity (turns off bold + dim) // Back to normal intensity (turns off bold + dim)
@ -656,7 +656,7 @@ inline bool FOptiAttr::unsetTermDim (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermItalic (charData*& term) inline bool FOptiAttr::setTermItalic (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -670,7 +670,7 @@ inline bool FOptiAttr::setTermItalic (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermItalic (charData*& term) inline bool FOptiAttr::unsetTermItalic (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -687,7 +687,7 @@ inline bool FOptiAttr::unsetTermItalic (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermUnderline (charData*& term) inline bool FOptiAttr::setTermUnderline (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -701,7 +701,7 @@ inline bool FOptiAttr::setTermUnderline (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermUnderline (charData*& term) inline bool FOptiAttr::unsetTermUnderline (FChar*& term)
{ {
// Turns off every underlining // Turns off every underlining
@ -723,7 +723,7 @@ inline bool FOptiAttr::unsetTermUnderline (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermBlink (charData*& term) inline bool FOptiAttr::setTermBlink (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -737,7 +737,7 @@ inline bool FOptiAttr::setTermBlink (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermBlink (charData*& term) inline bool FOptiAttr::unsetTermBlink (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -754,7 +754,7 @@ inline bool FOptiAttr::unsetTermBlink (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermReverse (charData*& term) inline bool FOptiAttr::setTermReverse (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -768,7 +768,7 @@ inline bool FOptiAttr::setTermReverse (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermReverse (charData*& term) inline bool FOptiAttr::unsetTermReverse (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -785,7 +785,7 @@ inline bool FOptiAttr::unsetTermReverse (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermStandout (charData*& term) inline bool FOptiAttr::setTermStandout (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -799,7 +799,7 @@ inline bool FOptiAttr::setTermStandout (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermStandout (charData*& term) inline bool FOptiAttr::unsetTermStandout (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -816,7 +816,7 @@ inline bool FOptiAttr::unsetTermStandout (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermInvisible (charData*& term) inline bool FOptiAttr::setTermInvisible (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -830,7 +830,7 @@ inline bool FOptiAttr::setTermInvisible (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermInvisible (charData*& term) inline bool FOptiAttr::unsetTermInvisible (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -847,7 +847,7 @@ inline bool FOptiAttr::unsetTermInvisible (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermProtected (charData*& term) inline bool FOptiAttr::setTermProtected (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -861,7 +861,7 @@ inline bool FOptiAttr::setTermProtected (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermProtected (charData*& term) inline bool FOptiAttr::unsetTermProtected (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -878,7 +878,7 @@ inline bool FOptiAttr::unsetTermProtected (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermCrossedOut (charData*& term) inline bool FOptiAttr::setTermCrossedOut (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -892,7 +892,7 @@ inline bool FOptiAttr::setTermCrossedOut (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermCrossedOut (charData*& term) inline bool FOptiAttr::unsetTermCrossedOut (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -909,7 +909,7 @@ inline bool FOptiAttr::unsetTermCrossedOut (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermDoubleUnderline (charData*& term) inline bool FOptiAttr::setTermDoubleUnderline (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -923,7 +923,7 @@ inline bool FOptiAttr::setTermDoubleUnderline (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermDoubleUnderline (charData*& term) inline bool FOptiAttr::unsetTermDoubleUnderline (FChar*& term)
{ {
// Turns off every underlining // Turns off every underlining
@ -945,7 +945,7 @@ inline bool FOptiAttr::unsetTermDoubleUnderline (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FOptiAttr::setTermAttributes ( charData*& term bool FOptiAttr::setTermAttributes ( FChar*& term
, bool p1, bool p2, bool p3 , bool p1, bool p2, bool p3
, bool p4, bool p5, bool p6 , bool p4, bool p5, bool p6
, bool p7, bool p8, bool p9 ) , bool p7, bool p8, bool p9 )
@ -985,7 +985,7 @@ bool FOptiAttr::setTermAttributes ( charData*& term
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermAttributes (charData*& term) inline bool FOptiAttr::unsetTermAttributes (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -999,7 +999,7 @@ inline bool FOptiAttr::unsetTermAttributes (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermAltCharset (charData*& term) inline bool FOptiAttr::setTermAltCharset (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -1016,7 +1016,7 @@ inline bool FOptiAttr::setTermAltCharset (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermAltCharset (charData*& term) inline bool FOptiAttr::unsetTermAltCharset (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -1033,7 +1033,7 @@ inline bool FOptiAttr::unsetTermAltCharset (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::setTermPCcharset (charData*& term) inline bool FOptiAttr::setTermPCcharset (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -1050,7 +1050,7 @@ inline bool FOptiAttr::setTermPCcharset (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::unsetTermPCcharset (charData*& term) inline bool FOptiAttr::unsetTermPCcharset (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -1067,7 +1067,7 @@ inline bool FOptiAttr::unsetTermPCcharset (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FOptiAttr::setTermDefaultColor (charData*& term) bool FOptiAttr::setTermDefaultColor (FChar*& term)
{ {
if ( ! term ) if ( ! term )
return false; return false;
@ -1090,7 +1090,7 @@ bool FOptiAttr::setTermDefaultColor (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FOptiAttr::setAttributesOn (charData*& term) void FOptiAttr::setAttributesOn (FChar*& term)
{ {
if ( on.attr.bit.alt_charset ) if ( on.attr.bit.alt_charset )
setTermAltCharset(term); setTermAltCharset(term);
@ -1133,7 +1133,7 @@ void FOptiAttr::setAttributesOn (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FOptiAttr::setAttributesOff (charData*& term) void FOptiAttr::setAttributesOff (FChar*& term)
{ {
if ( off.attr.bit.pc_charset ) if ( off.attr.bit.pc_charset )
unsetTermPCcharset(term); unsetTermPCcharset(term);
@ -1176,7 +1176,7 @@ void FOptiAttr::setAttributesOff (charData*& term)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FOptiAttr::hasColor (charData*& attr) bool FOptiAttr::hasColor (FChar*& attr)
{ {
if ( attr if ( attr
&& attr->fg_color == fc::Default && attr->fg_color == fc::Default
@ -1187,7 +1187,7 @@ bool FOptiAttr::hasColor (charData*& attr)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FOptiAttr::hasAttribute (charData*& attr) bool FOptiAttr::hasAttribute (FChar*& attr)
{ {
if ( attr ) if ( attr )
{ {
@ -1210,13 +1210,13 @@ bool FOptiAttr::hasAttribute (charData*& attr)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FOptiAttr::hasNoAttribute (charData*& attr) bool FOptiAttr::hasNoAttribute (FChar*& attr)
{ {
return ! hasAttribute(attr); return ! hasAttribute(attr);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FOptiAttr::hasColorChanged (charData*& term, charData*& next) inline bool FOptiAttr::hasColorChanged (FChar*& term, FChar*& next)
{ {
if ( term && next ) if ( term && next )
{ {
@ -1233,7 +1233,7 @@ inline bool FOptiAttr::hasColorChanged (charData*& term, charData*& next)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::resetColor (charData*& attr) inline void FOptiAttr::resetColor (FChar*& attr)
{ {
if ( attr ) if ( attr )
{ {
@ -1243,7 +1243,7 @@ inline void FOptiAttr::resetColor (charData*& attr)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::prevent_no_color_video_attributes ( charData*& attr inline void FOptiAttr::prevent_no_color_video_attributes ( FChar*& attr
, bool next_has_color ) , bool next_has_color )
{ {
// Ignore attributes which can not combined with a color // Ignore attributes which can not combined with a color
@ -1304,8 +1304,8 @@ inline void FOptiAttr::prevent_no_color_video_attributes ( charData*& attr
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::deactivateAttributes ( charData*& term inline void FOptiAttr::deactivateAttributes ( FChar*& term
, charData*& next ) , FChar*& next )
{ {
if ( hasAttribute(term) ) if ( hasAttribute(term) )
{ {
@ -1328,8 +1328,8 @@ inline void FOptiAttr::deactivateAttributes ( charData*& term
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::changeAttributeSGR ( charData*& term inline void FOptiAttr::changeAttributeSGR ( FChar*& term
, charData*& next ) , FChar*& next )
{ {
bool pc_charset_usable{true}; bool pc_charset_usable{true};
@ -1378,8 +1378,8 @@ inline void FOptiAttr::changeAttributeSGR ( charData*& term
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::changeAttributeSeparately ( charData*& term inline void FOptiAttr::changeAttributeSeparately ( FChar*& term
, charData*& next ) , FChar*& next )
{ {
setAttributesOff(term); setAttributesOff(term);
@ -1391,7 +1391,7 @@ inline void FOptiAttr::changeAttributeSeparately ( charData*& term
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FOptiAttr::change_color (charData*& term, charData*& next) void FOptiAttr::change_color (FChar*& term, FChar*& next)
{ {
if ( ! (term && next) ) if ( ! (term && next) )
return; return;
@ -1434,8 +1434,8 @@ void FOptiAttr::change_color (charData*& term, charData*& next)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::change_to_default_color ( charData*& term inline void FOptiAttr::change_to_default_color ( FChar*& term
, charData*& next , FChar*& next
, FColor& fg, FColor& bg ) , FColor& fg, FColor& bg )
{ {
if ( ansi_default_color ) if ( ansi_default_color )
@ -1474,7 +1474,7 @@ inline void FOptiAttr::change_to_default_color ( charData*& term
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::change_current_color ( charData*& term inline void FOptiAttr::change_current_color ( FChar*& term
, FColor fg, FColor bg ) , FColor fg, FColor bg )
{ {
char* color_str{}; char* color_str{};
@ -1522,7 +1522,7 @@ inline void FOptiAttr::change_current_color ( charData*& term
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::resetAttribute (charData*& attr) inline void FOptiAttr::resetAttribute (FChar*& attr)
{ {
if ( attr ) if ( attr )
{ {
@ -1532,7 +1532,7 @@ inline void FOptiAttr::resetAttribute (charData*& attr)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::reset (charData*& attr) inline void FOptiAttr::reset (FChar*& attr)
{ {
if ( attr ) if ( attr )
{ {
@ -1593,7 +1593,7 @@ inline bool FOptiAttr::hasCharsetEquivalence()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::detectSwitchOn (charData*& term, charData*& next) inline void FOptiAttr::detectSwitchOn (FChar*& term, FChar*& next)
{ {
if ( ! (term && next) ) if ( ! (term && next) )
return; return;
@ -1614,7 +1614,7 @@ inline void FOptiAttr::detectSwitchOn (charData*& term, charData*& next)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FOptiAttr::detectSwitchOff (charData*& term, charData*& next) inline void FOptiAttr::detectSwitchOff (FChar*& term, FChar*& next)
{ {
if ( ! (term && next) ) if ( ! (term && next) )
return; return;

View File

@ -101,7 +101,7 @@ std::ostream& operator << (std::ostream& outstr, const FPoint& p)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FPoint& p) std::istream& operator >> (std::istream& instr, FPoint& p)
{ {
int x, y; int x{}, y{};
instr >> x; instr >> x;
instr >> y; instr >> y;
p.setPoint (x, y); p.setPoint (x, y);

View File

@ -131,9 +131,9 @@ void FProgressbar::draw()
drawProgressBar(); drawProgressBar();
if ( getFlags().shadow ) if ( getFlags().shadow )
drawShadow (); drawShadow(this);
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -179,7 +179,7 @@ void FProgressbar::drawProgressBar()
setReverse(false); setReverse(false);
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -69,7 +69,7 @@ void FRadioMenuItem::init (FWidget* parent)
addCallback // for this element addCallback // for this element
( (
"toggled", "toggled",
F_METHOD_CALLBACK (parent, &FMenu::cb_menuitem_toggled) F_METHOD_CALLBACK (menu_ptr, &FMenu::cb_menuitem_toggled)
); );
} }
} }

View File

@ -381,7 +381,7 @@ std::ostream& operator << (std::ostream& outstr, const FRect& r)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::istream& operator >> (std::istream& instr, FRect& r) std::istream& operator >> (std::istream& instr, FRect& r)
{ {
int x1, y1, x2, y2; int x1{}, y1{}, x2{}, y2{};
instr >> x1; instr >> x1;
instr >> y1; instr >> y1;
instr >> x2; instr >> x2;

View File

@ -346,7 +346,7 @@ void FScrollbar::onMouseMove (FMouseEvent* ev)
if ( scroll_type == FScrollbar::scrollJump ) if ( scroll_type == FScrollbar::scrollJump )
{ {
int new_val; int new_val{};
if ( bar_orientation == fc::vertical ) if ( bar_orientation == fc::vertical )
{ {

View File

@ -464,52 +464,12 @@ void FScrollView::drawBorder()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::onKeyPress (FKeyEvent* ev) void FScrollView::onKeyPress (FKeyEvent* ev)
{ {
int yoffset_end = int(getScrollHeight() - getViewportHeight()); int idx = int(ev->key());
switch ( ev->key() ) if ( key_map.find(idx) != key_map.end() )
{ {
case fc::Fkey_up: key_map[idx]();
scrollBy (0, -1);
ev->accept(); ev->accept();
break;
case fc::Fkey_down:
scrollBy (0, 1);
ev->accept();
break;
case fc::Fkey_left:
scrollBy (-1, 0);
ev->accept();
break;
case fc::Fkey_right:
scrollBy (1, 0);
ev->accept();
break;
case fc::Fkey_ppage:
scrollBy (0, int(-getViewportHeight()));
ev->accept();
break;
case fc::Fkey_npage:
scrollBy (0, int(getViewportHeight()));
ev->accept();
break;
case fc::Fkey_home:
scrollToY (1);
ev->accept();
break;
case fc::Fkey_end:
scrollToY (1 + yoffset_end);
ev->accept();
break;
default:
break;
} }
} }
@ -629,7 +589,7 @@ void FScrollView::onChildFocusOut (FFocusEvent* out_ev)
// protected methods of FScrollView // protected methods of FScrollView
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FVTerm::term_area* FScrollView::getPrintArea() FVTerm::FTermArea* FScrollView::getPrintArea()
{ {
// returns print area or viewport // returns print area or viewport
@ -715,13 +675,13 @@ void FScrollView::copy2area()
for (int y{0}; y < y_end; y++) // line loop for (int y{0}; y < y_end; y++) // line loop
{ {
charData* vc{}; // viewport character FChar* vc{}; // viewport character
charData* ac{}; // area character FChar* ac{}; // area character
int v_line_len = viewport->width; int v_line_len = viewport->width;
int a_line_len = printarea->width + printarea->right_shadow; int a_line_len = printarea->width + printarea->right_shadow;
vc = &viewport->text[(dy + y) * v_line_len + dx]; vc = &viewport->data[(dy + y) * v_line_len + dx];
ac = &printarea->text[(ay + y) * a_line_len + ax]; ac = &printarea->data[(ay + y) * a_line_len + ax];
std::memcpy (ac, vc, sizeof(charData) * unsigned(x_end)); std::memcpy (ac, vc, sizeof(FChar) * unsigned(x_end));
if ( int(printarea->changes[ay + y].xmin) > ax ) if ( int(printarea->changes[ay + y].xmin) > ax )
printarea->changes[ay + y].xmin = uInt(ax); printarea->changes[ay + y].xmin = uInt(ax);
@ -764,6 +724,7 @@ void FScrollView::init (FWidget* parent)
initScrollbar (vbar, fc::vertical, &FScrollView::cb_VBarChange); initScrollbar (vbar, fc::vertical, &FScrollView::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, &FScrollView::cb_HBarChange); initScrollbar (hbar, fc::horizontal, &FScrollView::cb_HBarChange);
mapKeyFunctions();
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
@ -798,31 +759,21 @@ void FScrollView::init (FWidget* parent)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollView::initScrollbar ( FScrollbarPtr& bar inline void FScrollView::mapKeyFunctions()
, fc::orientation o
, FScrollViewCallback callback )
{ {
try key_map[fc::Fkey_up] = [&] { scrollBy (0, -1); };
key_map[fc::Fkey_down] = [&] { scrollBy (0, 1); };
key_map[fc::Fkey_left] = [&] { scrollBy (-1, 0); };
key_map[fc::Fkey_right] = [&] { scrollBy (1, 0); };
key_map[fc::Fkey_ppage] = [&] { scrollBy (0, int(-getViewportHeight())); };
key_map[fc::Fkey_npage] = [&] { scrollBy (0, int(getViewportHeight())); };
key_map[fc::Fkey_home] = [&] { scrollToY (1); };
key_map[fc::Fkey_end] = \
[&] ()
{ {
bar = std::make_shared<FScrollbar>(o, this); int yoffset_end = int(getScrollHeight() - getViewportHeight());
} scrollToY (1 + yoffset_end);
catch (const std::bad_alloc& ex) };
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
term_area* area = getPrintArea();
bar->setPrintArea(area);
bar->setMinimum(0);
bar->setValue(0);
bar->hide();
bar->addCallback
(
"change-value",
F_METHOD_CALLBACK (this, callback)
);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -52,10 +52,7 @@ FStartOptions::FStartOptions()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FStartOptions::~FStartOptions() // destructor FStartOptions::~FStartOptions() // destructor
{ { }
if ( start_options )
delete start_options;
}
// public methods of FStartOptions // public methods of FStartOptions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -77,6 +74,13 @@ FStartOptions& FStartOptions::getFStartOptions()
return *start_options; return *start_options;
} }
//----------------------------------------------------------------------
void FStartOptions::destroyObject()
{
if ( start_options )
delete start_options;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStartOptions::setDefault() void FStartOptions::setDefault()
{ {

View File

@ -174,15 +174,13 @@ bool FStatusBar::hasActivatedKey()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStatusBar::hide() void FStatusBar::hide()
{ {
FWindow::hide();
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
FColor fg = wc.term_fg; FColor fg = wc.term_fg;
FColor bg = wc.term_bg; FColor bg = wc.term_bg;
setColor (fg, bg); setColor (fg, bg);
screenWidth = getDesktopWidth(); print() << FPoint(1, 1) << FString(getDesktopWidth(), L' ');
char* blank = createBlankArray(screenWidth + 1); updateTerminal();
print() << FPoint(1, 1) << blank; FWindow::hide();
destroyBlankArray (blank);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -408,10 +406,9 @@ void FStatusBar::onMouseUp (FMouseEvent* ev)
if ( (*iter)->hasMouseFocus() ) if ( (*iter)->hasMouseFocus() )
{ {
int mouse_x, mouse_y;
(*iter)->unsetMouseFocus(); (*iter)->unsetMouseFocus();
mouse_x = ev->getX(); int mouse_x = ev->getX();
mouse_y = ev->getY(); int mouse_y = ev->getY();
if ( mouse_x >= x1 && mouse_x <= x2 && mouse_y == 1 ) if ( mouse_x >= x1 && mouse_x <= x2 && mouse_y == 1 )
(*iter)->setActive(); (*iter)->setActive();

View File

@ -30,6 +30,10 @@
namespace finalcut namespace finalcut
{ {
// static class attributes
wchar_t FString::null_char{L'\0'};
const wchar_t FString::const_null_char{L'\0'};
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FString // class FString
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -843,7 +847,7 @@ FString& FString::setString (const FString& s)
FString& FString::setNumber (sInt64 num) FString& FString::setNumber (sInt64 num)
{ {
bool neg{false}; bool neg{false};
wchar_t buf[30]; wchar_t buf[30]{};
wchar_t* s = &buf[29]; wchar_t* s = &buf[29];
if ( num < 0 ) if ( num < 0 )
@ -875,7 +879,7 @@ FString& FString::setNumber (sInt64 num)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::setNumber (uInt64 num) FString& FString::setNumber (uInt64 num)
{ {
wchar_t buf[30]; wchar_t buf[30]{};
wchar_t* s = &buf[29]; wchar_t* s = &buf[29];
*s = '\0'; *s = '\0';
@ -893,7 +897,7 @@ FString& FString::setNumber (uInt64 num)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::setNumber (lDouble f_num, int precision) FString& FString::setNumber (lDouble f_num, int precision)
{ {
wchar_t format[20]; // = "%.<precision>Lg" wchar_t format[20]{}; // = "%.<precision>Lg"
wchar_t* s = &format[0]; wchar_t* s = &format[0];
*s++ = L'%'; *s++ = L'%';
*s++ = L'.'; *s++ = L'.';
@ -926,7 +930,7 @@ FString& FString::setFormatedNumber (sInt64 num, char separator)
{ {
bool neg{false}; bool neg{false};
int n{0}; int n{0};
wchar_t buf[30]; wchar_t buf[30]{};
wchar_t* s = &buf[29]; wchar_t* s = &buf[29];
if ( separator == 0 ) if ( separator == 0 )
@ -965,7 +969,7 @@ FString& FString::setFormatedNumber (sInt64 num, char separator)
FString& FString::setFormatedNumber (uInt64 num, char separator) FString& FString::setFormatedNumber (uInt64 num, char separator)
{ {
int n{0}; int n{0};
wchar_t buf[30]; wchar_t buf[30]{};
wchar_t* s = &buf[29]; wchar_t* s = &buf[29];
*s = L'\0'; *s = L'\0';
@ -1324,7 +1328,7 @@ void FString::_assign (const wchar_t s[])
if ( string && std::wcscmp(string, s) == 0 ) if ( string && std::wcscmp(string, s) == 0 )
return; // string == s return; // string == s
uInt new_length= uInt(std::wcslen(s)); uInt new_length = uInt(std::wcslen(s));
if ( ! string || new_length > capacity() ) if ( ! string || new_length > capacity() )
{ {
@ -1710,8 +1714,17 @@ const FString operator + (const FString& s, const char c)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::ostream& operator << (std::ostream& outstr, const FString& s) std::ostream& operator << (std::ostream& outstr, const FString& s)
{ {
const std::size_t width = std::size_t(outstr.width());
if ( s.length > 0 ) if ( s.length > 0 )
outstr << s.wc_to_c_str( s.string ); {
outstr << s.wc_to_c_str(s.string);
}
else if ( width > 0 )
{
FString fill_str(width, outstr.fill());
outstr << s.wc_to_c_str(fill_str.string);
}
return outstr; return outstr;
} }
@ -1735,8 +1748,17 @@ std::istream& operator >> (std::istream& instr, FString& s)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::wostream& operator << (std::wostream& outstr, const FString& s) std::wostream& operator << (std::wostream& outstr, const FString& s)
{ {
const std::size_t width = std::size_t(outstr.width());
if ( s.length > 0 ) if ( s.length > 0 )
{
outstr << s.string; outstr << s.string;
}
else if ( width > 0 )
{
FString fill_str(width, outstr.fill());
outstr << fill_str.string;
}
return outstr; return outstr;
} }

View File

@ -124,7 +124,7 @@ void FSwitch::draw()
drawCheckButton(); drawCheckButton();
FToggleButton::draw(); FToggleButton::draw();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -20,6 +20,10 @@
* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***********************************************************************/ ***********************************************************************/
#if defined(__CYGWIN__)
#include "final/fconfig.h" // need for getpwuid_r and realpath
#endif
#include "final/fsystemimpl.h" #include "final/fsystemimpl.h"
namespace finalcut namespace finalcut
@ -38,5 +42,19 @@ FSystemImpl::FSystemImpl()
FSystemImpl::~FSystemImpl() // destructor FSystemImpl::~FSystemImpl() // destructor
{ } { }
//----------------------------------------------------------------------
int FSystemImpl::getpwuid_r ( uid_t uid, struct passwd* pwd
, char* buf, size_t buflen
, struct passwd** result )
{
return ::getpwuid_r (uid, pwd, buf, buflen, result);
}
//----------------------------------------------------------------------
char* FSystemImpl::realpath (const char* path, char* resolved_path)
{
return ::realpath(path, resolved_path);
}
} // namespace finalcut } // namespace finalcut

View File

@ -67,9 +67,6 @@ static FTerm* init_term_object{nullptr};
// global init state // global init state
static bool term_initialized{false}; static bool term_initialized{false};
// function pointer
int (*FTerm::Fputchar)(int);
// static class attributes // static class attributes
FTermData* FTerm::data {nullptr}; FTermData* FTerm::data {nullptr};
FSystem* FTerm::fsys {nullptr}; FSystem* FTerm::fsys {nullptr};
@ -96,8 +93,6 @@ FMouseControl* FTerm::mouse {nullptr};
FTermDebugData* FTerm::debug_data {nullptr}; FTermDebugData* FTerm::debug_data {nullptr};
#endif #endif
// function prototypes
uInt env2uint (const char*);
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FTerm // class FTerm
@ -419,7 +414,7 @@ FTermDebugData& FTerm::getFTermDebugData()
#endif // DEBUG #endif // DEBUG
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTerm::isNormal (charData*& ch) bool FTerm::isNormal (FChar*& ch)
{ {
return opti_attr->isNormal(ch); return opti_attr->isNormal(ch);
} }
@ -674,16 +669,16 @@ bool FTerm::setVGAFont()
data->setTermEncoding (fc::PC); data->setTermEncoding (fc::PC);
if ( isXTerminal() && data->hasUTF8Console() ) if ( isXTerminal() && data->hasUTF8Console() )
Fputchar = &FTerm::putchar_UTF8; putchar() = &FTerm::putchar_UTF8;
else else
Fputchar = &FTerm::putchar_ASCII; putchar() = &FTerm::putchar_ASCII;
} }
#if defined(__linux__) #if defined(__linux__)
else if ( isLinuxTerm() ) else if ( isLinuxTerm() )
{ {
data->setVGAFont(linux->loadVGAFont()); data->setVGAFont(linux->loadVGAFont());
data->setTermEncoding (fc::PC); data->setTermEncoding (fc::PC);
Fputchar = &FTerm::putchar_ASCII; putchar() = &FTerm::putchar_ASCII;
} }
#endif // defined(__linux__) #endif // defined(__linux__)
else else
@ -716,16 +711,16 @@ bool FTerm::setNewFont()
data->setTermEncoding (fc::PC); data->setTermEncoding (fc::PC);
if ( isXTerminal() && data->hasUTF8Console() ) if ( isXTerminal() && data->hasUTF8Console() )
Fputchar = &FTerm::putchar_UTF8; putchar() = &FTerm::putchar_UTF8;
else else
Fputchar = &FTerm::putchar_ASCII; putchar() = &FTerm::putchar_ASCII;
} }
#if defined(__linux__) #if defined(__linux__)
else if ( isLinuxTerm() ) else if ( isLinuxTerm() )
{ {
data->setNewFont(linux->loadNewFont()); data->setNewFont(linux->loadNewFont());
data->setTermEncoding (fc::PC); data->setTermEncoding (fc::PC);
Fputchar = &FTerm::putchar_ASCII; // function pointer putchar() = &FTerm::putchar_ASCII; // function pointer
} }
#endif // defined(__linux__) #endif // defined(__linux__)
else else
@ -759,7 +754,7 @@ bool FTerm::setOldFont()
if ( font.getLength() > 2 ) if ( font.getLength() > 2 )
{ {
// restore saved xterm font // restore saved xterm font
xterm->setFont (font); xterm->setFont(font);
} }
else else
{ {
@ -835,7 +830,9 @@ int FTerm::closeConsole()
if ( fd < 0 ) // console is already closed if ( fd < 0 ) // console is already closed
return 0; return 0;
if ( fsys ) if ( ! fsys )
getFSystem();
ret = fsys->close(fd); // close console ret = fsys->close(fd); // close console
data->setTTYFileDescriptor(-1); data->setTTYFileDescriptor(-1);
@ -900,10 +897,10 @@ void FTerm::detectTermSize()
do do
{ {
if ( fsys ) if ( ! fsys )
getFSystem();
ret = fsys->ioctl (FTermios::getStdOut(), TIOCGWINSZ, &win_size); ret = fsys->ioctl (FTermios::getStdOut(), TIOCGWINSZ, &win_size);
else
ret = -1;
} }
while (errno == EINTR); while (errno == EINTR);
@ -992,12 +989,13 @@ void FTerm::setPalette (FColor index, int r, int g, int b)
const auto& Ic = TCAP(fc::t_initialize_color); const auto& Ic = TCAP(fc::t_initialize_color);
const auto& Ip = TCAP(fc::t_initialize_pair); const auto& Ip = TCAP(fc::t_initialize_pair);
bool state{false};
index = FOptiAttr::vga2ansi(index); index = FOptiAttr::vga2ansi(index);
if ( Ic || Ip ) if ( Ic || Ip )
{ {
const char* color_str = ""; const char* color_str{};
int rr = (r * 1001) / 256 int rr = (r * 1001) / 256
, gg = (g * 1001) / 256 , gg = (g * 1001) / 256
@ -1008,15 +1006,20 @@ void FTerm::setPalette (FColor index, int r, int g, int b)
else if ( Ip ) else if ( Ip )
color_str = tparm(Ip, index, 0, 0, 0, rr, gg, bb, 0, 0); color_str = tparm(Ip, index, 0, 0, 0, rr, gg, bb, 0, 0);
if ( color_str )
{
putstring (color_str); putstring (color_str);
state = true;
}
} }
#if defined(__linux__) #if defined(__linux__)
else else
{ {
linux->setPalette(index, r, g, b); state = linux->setPalette(index, r, g, b);
} }
#endif #endif
if ( state )
std::fflush(stdout); std::fflush(stdout);
} }
@ -1084,25 +1087,25 @@ void FTerm::setEncoding (fc::encoding enc)
|| enc == fc::PC // CP-437 || enc == fc::PC // CP-437
|| enc == fc::ASCII ); || enc == fc::ASCII );
// Set the new Fputchar function pointer // Set the new putchar() function pointer
switch ( enc ) switch ( enc )
{ {
case fc::UTF8: case fc::UTF8:
Fputchar = &FTerm::putchar_UTF8; putchar() = &FTerm::putchar_UTF8;
break; break;
case fc::VT100: case fc::VT100:
case fc::PC: case fc::PC:
if ( isXTerminal() && data->hasUTF8Console() ) if ( isXTerminal() && data->hasUTF8Console() )
Fputchar = &FTerm::putchar_UTF8; putchar() = &FTerm::putchar_UTF8;
else else
Fputchar = &FTerm::putchar_ASCII; putchar() = &FTerm::putchar_ASCII;
break; break;
case fc::ASCII: case fc::ASCII:
case fc::UNKNOWN: case fc::UNKNOWN:
case fc::NUM_OF_ENCODINGS: case fc::NUM_OF_ENCODINGS:
Fputchar = &FTerm::putchar_ASCII; putchar() = &FTerm::putchar_ASCII;
} }
if ( isLinuxTerm() ) if ( isLinuxTerm() )
@ -1196,15 +1199,28 @@ bool FTerm::scrollTermReverse()
return false; return false;
} }
//----------------------------------------------------------------------
FTerm::defaultPutChar& FTerm::putchar()
{
static defaultPutChar* fputchar = new defaultPutChar();
return *fputchar;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::putstring (const char str[], int affcnt) void FTerm::putstring (const char str[], int affcnt)
{ {
if ( ! fsys )
getFSystem();
fsys->tputs (str, affcnt, FTerm::putchar_ASCII); fsys->tputs (str, affcnt, FTerm::putchar_ASCII);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FTerm::putchar_ASCII (int c) int FTerm::putchar_ASCII (int c)
{ {
if ( ! fsys )
getFSystem();
if ( fsys->putchar(char(c)) == EOF ) if ( fsys->putchar(char(c)) == EOF )
return 0; return 0;
else else
@ -1214,6 +1230,9 @@ int FTerm::putchar_ASCII (int c)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FTerm::putchar_UTF8 (int c) int FTerm::putchar_UTF8 (int c)
{ {
if ( ! fsys )
getFSystem();
if ( c < 0x80 ) if ( c < 0x80 )
{ {
// 1 Byte (7-bit): 0xxxxxxx // 1 Byte (7-bit): 0xxxxxxx
@ -1269,8 +1288,8 @@ void FTerm::initScreenSettings()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
char* FTerm::changeAttribute ( charData*& term_attr char* FTerm::changeAttribute ( FChar*& term_attr
, charData*& next_attr ) , FChar*& next_attr )
{ {
return opti_attr->changeAttribute (term_attr, next_attr); return opti_attr->changeAttribute (term_attr, next_attr);
} }
@ -1708,7 +1727,7 @@ void FTerm::init_locale()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::init_encoding() void FTerm::init_encoding()
{ {
// detect encoding and set the Fputchar function pointer // detect encoding and set the putchar() function pointer
bool force_vt100{false}; // VT100 line drawing (G1 character set) bool force_vt100{false}; // VT100 line drawing (G1 character set)
init_encoding_set(); init_encoding_set();
@ -1752,12 +1771,15 @@ void FTerm::init_term_encoding()
int stdout_no = FTermios::getStdOut(); int stdout_no = FTermios::getStdOut();
const char* termtype = data->getTermType(); const char* termtype = data->getTermType();
if ( ! fsys )
getFSystem();
if ( fsys->isTTY(stdout_no) if ( fsys->isTTY(stdout_no)
&& ! std::strcmp(nl_langinfo(CODESET), "UTF-8") ) && ! std::strcmp(nl_langinfo(CODESET), "UTF-8") )
{ {
data->setUTF8Console(true); data->setUTF8Console(true);
data->setTermEncoding (fc::UTF8); data->setTermEncoding (fc::UTF8);
Fputchar = &FTerm::putchar_UTF8; // function pointer putchar() = &FTerm::putchar_UTF8; // function pointer
data->setUTF8(true); data->setUTF8(true);
setUTF8(true); setUTF8(true);
keyboard->enableUTF8(); keyboard->enableUTF8();
@ -1768,13 +1790,13 @@ void FTerm::init_term_encoding()
{ {
data->setVT100Console (true); data->setVT100Console (true);
data->setTermEncoding (fc::VT100); data->setTermEncoding (fc::VT100);
Fputchar = &FTerm::putchar_ASCII; // function pointer putchar() = &FTerm::putchar_ASCII; // function pointer
} }
else else
{ {
data->setASCIIConsole (true); data->setASCIIConsole (true);
data->setTermEncoding (fc::ASCII); data->setTermEncoding (fc::ASCII);
Fputchar = &FTerm::putchar_ASCII; // function pointer putchar() = &FTerm::putchar_ASCII; // function pointer
} }
} }
@ -1786,12 +1808,12 @@ void FTerm::init_individual_term_encoding()
|| (isTeraTerm() && ! data->isUTF8()) ) || (isTeraTerm() && ! data->isUTF8()) )
{ {
data->setTermEncoding (fc::PC); data->setTermEncoding (fc::PC);
Fputchar = &FTerm::putchar_ASCII; // function pointer putchar() = &FTerm::putchar_ASCII; // function pointer
if ( hasUTF8() && getStartOptions().encoding == fc::UNKNOWN ) if ( hasUTF8() && getStartOptions().encoding == fc::UNKNOWN )
{ {
if ( isXTerminal() ) if ( isXTerminal() )
Fputchar = &FTerm::putchar_UTF8; // function pointer putchar() = &FTerm::putchar_UTF8; // function pointer
} }
} }
} }
@ -1801,7 +1823,7 @@ void FTerm::init_force_vt100_encoding()
{ {
data->setVT100Console(true); data->setVT100Console(true);
data->setTermEncoding (fc::VT100); data->setTermEncoding (fc::VT100);
Fputchar = &FTerm::putchar_ASCII; // function pointer putchar() = &FTerm::putchar_ASCII; // function pointer
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1815,7 +1837,7 @@ void FTerm::init_utf8_without_alt_charset()
{ {
data->setASCIIConsole(true); data->setASCIIConsole(true);
data->setTermEncoding (fc::ASCII); data->setTermEncoding (fc::ASCII);
Fputchar = &FTerm::putchar_ASCII; // function pointer putchar() = &FTerm::putchar_ASCII; // function pointer
} }
} }
@ -1841,14 +1863,14 @@ void FTerm::init_captureFontAndTitle()
// Save the used xterm font and window title // Save the used xterm font and window title
xterm->captureFontAndTitle(); xterm->captureFontAndTitle();
const auto font = xterm->getFont(); const auto& font = xterm->getFont();
const auto title = xterm->getTitle(); const auto& title = xterm->getTitle();
if ( font ) if ( ! font.isEmpty() )
data->setXtermFont(*font); data->setXtermFont(font);
if ( title ) if ( ! title.isEmpty() )
data->setXtermTitle(*title); data->setXtermTitle(title);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -2126,6 +2148,7 @@ void FTerm::useNormalScreenBuffer()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FTerm::allocationValues() inline void FTerm::allocationValues()
{ {
FStartOptions::getFStartOptions();
getFTermData(); getFTermData();
getFSystem(); getFSystem();
getFOptiMove(); getFOptiMove();
@ -2146,7 +2169,6 @@ inline void FTerm::allocationValues()
#if DEBUG #if DEBUG
getFTermDebugData(); getFTermDebugData();
#endif #endif
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -2191,6 +2213,10 @@ inline void FTerm::deallocationValues()
if ( data ) if ( data )
delete data; delete data;
defaultPutChar* putchar_ptr = &(putchar());
delete putchar_ptr;
FStartOptions::destroyObject();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -2240,7 +2266,7 @@ void FTerm::init (bool disable_alt_screen)
init_alt_charset(); init_alt_charset();
// Pass the terminal capabilities to the keyboard object // Pass the terminal capabilities to the keyboard object
keyboard->setTermcapMap (fc::Fkey); keyboard->setTermcapMap (fc::fkey);
// Initializes locale information // Initializes locale information
init_locale(); init_locale();
@ -2357,6 +2383,9 @@ void FTerm::initBaudRate()
uInt baud = FTermios::getBaudRate(); uInt baud = FTermios::getBaudRate();
data->setBaudrate(baud); data->setBaudrate(baud);
if ( ! fsys )
getFSystem();
if ( fsys->isTTY(stdout_no) ) if ( fsys->isTTY(stdout_no) )
opti_move->setBaudRate(int(baud)); opti_move->setBaudRate(int(baud));
} }
@ -2501,259 +2530,11 @@ void FTerm::signal_handler (int signum)
init_term_object->finish(); init_term_object->finish();
std::fflush (stderr); std::fflush (stderr);
std::fflush (stdout); std::fflush (stdout);
std::fprintf ( stderr std::cerr << "\nProgram stopped: signal "
, "\nProgram stopped: signal %d (%s)\n" << signum
, signum << " (" << strsignal(signum) << ")" << std::endl;
, strsignal(signum) );
std::terminate(); std::terminate();
} }
} }
// FTerm non-member functions
//----------------------------------------------------------------------
uInt env2uint (const char* env)
{
FString str(getenv(env));
if ( str.isEmpty() )
return 0;
try
{
return str.toUInt();
}
catch (const std::exception&)
{
return 0;
}
}
//----------------------------------------------------------------------
wchar_t cp437_to_unicode (uChar c)
{
constexpr std::size_t CP437 = 0;
constexpr std::size_t UNICODE = 1;
wchar_t ucs(c);
for (std::size_t i{0}; i <= fc::lastCP437Item; i++)
{
if ( fc::cp437_to_ucs[i][CP437] == c ) // found
{
ucs = fc::cp437_to_ucs[i][UNICODE];
break;
}
}
return ucs;
}
//----------------------------------------------------------------------
uChar unicode_to_cp437 (wchar_t ucs)
{
constexpr std::size_t CP437 = 0;
constexpr std::size_t UNICODE = 1;
uChar c{'?'};
for (std::size_t i{0}; i <= fc::lastCP437Item; i++)
{
if ( fc::cp437_to_ucs[i][UNICODE] == ucs ) // found
{
c = uChar(fc::cp437_to_ucs[i][CP437]);
break;
}
}
return c;
}
//----------------------------------------------------------------------
FString getFullWidth (const FString& str)
{
// Converts half-width to full-width characters
FString s(str);
constexpr std::size_t HALF = 0;
constexpr std::size_t FULL = 1;
for (auto&& c : s)
{
if ( c > L'\x20' && c < L'\x7f' ) // half-width ASCII
{
c += 0xfee0;
}
else for (std::size_t i{0}; i <= fc::lastHalfWidthItem; i++)
{
if ( fc::halfWidth_fullWidth[i][HALF] == c ) // found
{
c = fc::halfWidth_fullWidth[i][FULL];
}
}
}
return s;
}
//----------------------------------------------------------------------
FString getHalfWidth (const FString& str)
{
// Converts full-width to half-width characters
FString s(str);
constexpr std::size_t HALF = 0;
constexpr std::size_t FULL = 1;
for (auto&& c : s)
{
if ( c > L'\xff00' && c < L'\xff5f' ) // full-width ASCII
{
c -= 0xfee0;
}
else for (std::size_t i{0}; i <= fc::lastHalfWidthItem; i++)
{
if ( fc::halfWidth_fullWidth[i][FULL] == c ) // found
{
c = fc::halfWidth_fullWidth[i][HALF];
}
}
}
return s;
}
//----------------------------------------------------------------------
std::size_t getColumnWidthToLength ( const FString& str
, std::size_t col_len )
{
std::size_t column_width{0}, length{0};
for (auto&& ch : str)
{
if ( column_width < col_len )
{
column_width += getColumnWidth(ch);
length++;
}
}
return length;
}
//----------------------------------------------------------------------
FString getColumnSubString ( const FString& str
, std::size_t col_pos, std::size_t col_len )
{
FString s(str);
std::size_t col_first{1}, col_num{0}, first{1}, num{0};
if ( col_len == 0 || s.isEmpty() )
return FString(L"");
if ( col_pos == 0 )
col_pos = 1;
for (auto&& ch : s)
{
std::size_t width = getColumnWidth(ch);
if ( col_first < col_pos )
{
if ( col_first + width <= col_pos )
{
col_first += width;
first++;
}
else
{
ch = fc::SingleLeftAngleQuotationMark; //
num = col_num = 1;
col_pos = col_first;
}
}
else
{
if ( col_num + width <= col_len )
{
col_num += width;
num++;
}
else if ( col_num < col_len )
{
ch = fc::SingleRightAngleQuotationMark; //
num++;
break;
}
}
}
if ( col_first < col_pos ) // String length < col_pos
return FString(L"");
return s.mid(first, num);
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (const FString& s, std::size_t pos)
{
if ( s.isEmpty() )
return 0;
std::size_t column_width{0};
auto length = s.getLength();
if ( pos > length )
pos = length;
for (std::size_t i{0}; i < pos; i++)
column_width += getColumnWidth(s[i]);
return column_width;
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (const FString& s)
{
if ( s.isEmpty() )
return 0;
const wchar_t* str = s.wc_str();
size_t len = std::wcslen(str);
int column_width = wcswidth (str, len);
return ( column_width == -1 ) ? 0 : std::size_t(column_width);
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (const wchar_t wchar)
{
int column_width = wcwidth (wchar);
return ( column_width == -1 ) ? 0 : std::size_t(column_width);
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (charData& term_char)
{
int column_width = wcwidth (term_char.code);
std::size_t char_width = ( column_width == -1 ) ? 0 : std::size_t(column_width);
if ( char_width == 2 && FTerm::getEncoding() != fc::UTF8 )
{
term_char.code = '.';
term_char.attr.bit.char_width = 1;
}
else
term_char.attr.bit.char_width = char_width & 0x03;
return char_width;
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (const FTermBuffer& termbuffer)
{
std::size_t column_width{0};
for (auto&& tc : termbuffer)
column_width += tc.attr.bit.char_width;
return column_width;
}
} // namespace finalcut } // namespace finalcut

430
src/fterm_functions.cpp Normal file
View File

@ -0,0 +1,430 @@
/***********************************************************************
* fterm_functions.cpp - FTerm helper functions *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#if defined(__CYGWIN__)
#include "final/fconfig.h" // includes _GNU_SOURCE for wcwidth()
#endif
#include <algorithm>
#include "final/fcharmap.h"
#include "final/fterm.h"
#include "final/ftermbuffer.h"
namespace finalcut
{
// Function prototypes
bool hasAmbiguousWidth (wchar_t);
// Data array
const wchar_t ambiguous_width_list[] =
{
0x00a1, 0x00a4, 0x00a7, 0x00a8, 0x00aa, 0x00ad, 0x00ae, 0x00b0,
0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b6, 0x00b7, 0x00b8, 0x00b9,
0x00ba, 0x00bc, 0x00bd, 0x00be, 0x00bf, 0x00c6, 0x00d0, 0x00d7,
0x00d8, 0x00de, 0x00df, 0x00e0, 0x00e1, 0x00e6, 0x00e8, 0x00e9,
0x00ea, 0x00ec, 0x00ed, 0x00f0, 0x00f2, 0x00f3, 0x00f7, 0x00f8,
0x00f9, 0x00fa, 0x00fc, 0x00fe, 0x0101, 0x0111, 0x0113, 0x011b,
0x0126, 0x0127, 0x012b, 0x0131, 0x0132, 0x0133, 0x0138, 0x013f,
0x0140, 0x0141, 0x0142, 0x0144, 0x0148, 0x0149, 0x014a, 0x014b,
0x014d, 0x0152, 0x0153, 0x0166, 0x0167, 0x016b, 0x01ce, 0x01d0,
0x01d2, 0x01d4, 0x01d6, 0x01d8, 0x01da, 0x01dc, 0x0251, 0x0261,
0x02c4, 0x02c7, 0x02c9, 0x02ca, 0x02cb, 0x02cd, 0x02d0, 0x02d8,
0x02d9, 0x02da, 0x02db, 0x02dd, 0x02df, 0x0300, 0x0301, 0x0302,
0x0303, 0x0304, 0x0305, 0x0306, 0x0307, 0x0308, 0x0309, 0x030a,
0x030b, 0x030c, 0x030d, 0x030f, 0x0310, 0x0311, 0x0312, 0x0313,
0x0314, 0x0315, 0x0316, 0x0317, 0x0318, 0x0319, 0x031a, 0x031b,
0x031c, 0x031d, 0x031e, 0x031f, 0x0320, 0x0321, 0x0322, 0x0323,
0x0324, 0x0325, 0x0326, 0x0327, 0x0328, 0x0329, 0x032a, 0x032b,
0x032c, 0x032d, 0x032e, 0x032f, 0x0330, 0x0331, 0x0332, 0x0333,
0x0334, 0x0335, 0x0336, 0x0337, 0x0338, 0x0339, 0x033a, 0x033b,
0x033c, 0x033d, 0x033e, 0x033f, 0x0340, 0x0341, 0x0342, 0x0343,
0x0344, 0x0345, 0x0346, 0x0347, 0x0348, 0x0349, 0x034a, 0x034b,
0x034c, 0x034d, 0x034e, 0x034f, 0x0350, 0x0351, 0x0352, 0x0353,
0x0354, 0x0355, 0x0356, 0x0357, 0x0358, 0x0359, 0x035a, 0x035b,
0x035c, 0x035d, 0x035e, 0x035f, 0x0360, 0x0361, 0x0362, 0x0363,
0x0364, 0x0365, 0x0366, 0x0367, 0x0368, 0x0369, 0x036a, 0x036b,
0x036c, 0x036d, 0x036e, 0x036f, 0x0391, 0x0392, 0x0393, 0x0394,
0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c,
0x039d, 0x039e, 0x039f, 0x03a0, 0x03a1, 0x03a3, 0x03a4, 0x03a5,
0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x03b1, 0x03b2, 0x03b3, 0x03b4,
0x03b5, 0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc,
0x03bd, 0x03be, 0x03bf, 0x03c0, 0x03c1, 0x03c3, 0x03c4, 0x03c5,
0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x0401, 0x0410, 0x0411, 0x0412,
0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041a,
0x041b, 0x041c, 0x041d, 0x041e, 0x041f, 0x0420, 0x0421, 0x0422,
0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042a,
0x042b, 0x042c, 0x042d, 0x042e, 0x042f, 0x0430, 0x0431, 0x0432,
0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a,
0x043b, 0x043c, 0x043d, 0x043e, 0x043f, 0x0440, 0x0441, 0x0442,
0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a,
0x044b, 0x044c, 0x044d, 0x044e, 0x044f, 0x0451, 0x2010, 0x2013,
0x2014, 0x2015, 0x2016, 0x2018, 0x2019, 0x201c, 0x201d, 0x2020,
0x2021, 0x2022, 0x2024, 0x2025, 0x2026, 0x2027, 0x2030, 0x2032,
0x2033, 0x2035, 0x203b, 0x203e, 0x2074, 0x207f, 0x2081, 0x2082,
0x2083, 0x2084, 0x20ac, 0x2103, 0x2105, 0x2109, 0x2113, 0x2116,
0x2121, 0x2122, 0x2126, 0x212b, 0x2153, 0x2154, 0x215b, 0x215c,
0x215d, 0x215e, 0x2160, 0x2162, 0x2162, 0x2163, 0x2164, 0x2165,
0x2166, 0x2167, 0x2168, 0x2169, 0x216a, 0x216b, 0x2170, 0x2171,
0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177, 0x2178, 0x2179,
0x2190, 0x2191, 0x2192, 0x2193, 0x2194, 0x2195, 0x2196, 0x2197,
0x2198, 0x2199, 0x21b8, 0x21b9, 0x21d2, 0x21d4, 0x21e7, 0x2200,
0x2202, 0x2203, 0x2207, 0x2208, 0x220b, 0x220f, 0x2211, 0x2215,
0x221a, 0x221d, 0x221e, 0x221f, 0x2220, 0x2223, 0x2225, 0x2227,
0x2228, 0x2229, 0x222a, 0x222b, 0x222c, 0x222e, 0x2234, 0x2235,
0x2236, 0x2237, 0x223c, 0x223d, 0x2248, 0x224c, 0x2252, 0x2260,
0x2261, 0x2264, 0x2265, 0x2266, 0x2267, 0x226a, 0x226b, 0x226e,
0x226f, 0x2282, 0x2283, 0x2286, 0x2287, 0x2295, 0x2299, 0x22a5,
0x22bf, 0x2312, 0x2460, 0x2461, 0x2462, 0x2463, 0x2464, 0x2465,
0x2466, 0x2467, 0x2468, 0x2469, 0x246a, 0x246b, 0x246c, 0x246d,
0x246e, 0x246f, 0x2470, 0x2471, 0x2472, 0x2473, 0x2474, 0x2475,
0x2476, 0x2477, 0x2478, 0x2479, 0x247a, 0x247b, 0x247c, 0x247d,
0x247e, 0x247f, 0x2480, 0x2481, 0x2482, 0x2483, 0x2484, 0x2485,
0x2486, 0x2487, 0x2488, 0x2489, 0x248a, 0x248b, 0x248c, 0x248d,
0x248e, 0x248f, 0x2490, 0x2491, 0x2492, 0x2493, 0x2494, 0x2495,
0x2496, 0x2497, 0x2498, 0x2499, 0x249a, 0x249b, 0x249c, 0x249d,
0x249e, 0x249f, 0x24a0, 0x24a1, 0x24a2, 0x24a3, 0x24a4, 0x24a5,
0x24a6, 0x24a7, 0x24a8, 0x24a9, 0x24aa, 0x24ab, 0x24ac, 0x24ad,
0x24ae, 0x24af, 0x24b0, 0x24b1, 0x24b2, 0x24b3, 0x24b4, 0x24b5,
0x24b6, 0x24b7, 0x24b8, 0x24b9, 0x24ba, 0x24bb, 0x24bc, 0x24bd,
0x24be, 0x24bf, 0x24c0, 0x24c1, 0x24c2, 0x24c3, 0x24c4, 0x24c5,
0x24c6, 0x24c7, 0x24c8, 0x24c9, 0x24ca, 0x24cb, 0x24cc, 0x24cd,
0x24ce, 0x24cf, 0x24d0, 0x24d1, 0x24d2, 0x24d3, 0x24d4, 0x24d5,
0x24d6, 0x24d7, 0x24d8, 0x24d9, 0x24da, 0x24db, 0x24dc, 0x24dd,
0x24de, 0x24df, 0x24e0, 0x24e1, 0x24e2, 0x24e3, 0x24e4, 0x24e5,
0x24e6, 0x24e7, 0x24e8, 0x24e9, 0x24eb, 0x24ec, 0x24ed, 0x24ee,
0x24ef, 0x24f0, 0x24f1, 0x24f2, 0x24f3, 0x24f4, 0x24f5, 0x24f6,
0x24f7, 0x24f8, 0x24f9, 0x24fa, 0x24fb, 0x24fc, 0x24fd, 0x24fe,
0x2500, 0x2501, 0x2502, 0x2503, 0x2504, 0x2505, 0x2506, 0x2507,
0x2508, 0x2509, 0x250a, 0x250b, 0x250c, 0x250d, 0x250e, 0x250f,
0x2510, 0x2511, 0x2512, 0x2513, 0x2514, 0x2515, 0x2516, 0x2517,
0x2518, 0x2519, 0x251a, 0x251b, 0x251c, 0x251d, 0x251e, 0x251f,
0x2520, 0x2521, 0x2522, 0x2523, 0x2524, 0x2525, 0x2526, 0x2527,
0x2528, 0x2529, 0x252a, 0x252b, 0x252c, 0x252d, 0x252e, 0x252f,
0x2530, 0x2531, 0x2532, 0x2533, 0x2534, 0x2535, 0x2536, 0x2537,
0x2538, 0x2539, 0x253a, 0x253b, 0x253c, 0x253d, 0x253e, 0x253f,
0x2540, 0x2541, 0x2542, 0x2543, 0x2544, 0x2545, 0x2546, 0x2547,
0x2548, 0x2549, 0x254a, 0x254b, 0x2550, 0x2551, 0x2552, 0x2553,
0x2554, 0x2555, 0x2556, 0x2557, 0x2558, 0x2559, 0x255a, 0x255b,
0x255c, 0x255d, 0x255e, 0x255f, 0x2560, 0x2561, 0x2562, 0x2563,
0x2564, 0x2565, 0x2566, 0x2567, 0x2568, 0x2569, 0x256a, 0x256b,
0x256c, 0x256d, 0x256e, 0x256f, 0x2570, 0x2571, 0x2572, 0x2573,
0x2580, 0x2581, 0x2582, 0x2583, 0x2584, 0x2585, 0x2586, 0x2587,
0x2588, 0x2589, 0x258a, 0x258b, 0x258c, 0x258d, 0x258e, 0x258f,
0x2590, 0x2592, 0x2593, 0x2594, 0x2595, 0x25a0, 0x25a1, 0x25a3,
0x25a4, 0x25a5, 0x25a6, 0x25a7, 0x25a8, 0x25a9, 0x25ac, 0x25ae,
0x25b2, 0x25b3, 0x25b6, 0x25b7, 0x25ba, 0x25bc, 0x25bd, 0x25c0,
0x25c1, 0x25c4, 0x25c6, 0x25c7, 0x25c8, 0x25cb, 0x25ce, 0x25cf,
0x25d0, 0x25d1, 0x25d8, 0x25d9, 0x25e2, 0x25e3, 0x25e4, 0x25e5,
0x25ef, 0x2605, 0x2606, 0x2609, 0x260e, 0x260f, 0x2614, 0x2615,
0x261c, 0x261e, 0x2640, 0x2642, 0x2660, 0x2661, 0x2663, 0x2664,
0x2665, 0x2667, 0x2668, 0x2669, 0x266a, 0x266c, 0x266d, 0x266f,
0x273d, 0x2776, 0x2777, 0x2778, 0x2779, 0x277a, 0x277b, 0x277c,
0x277d, 0x277e, 0x277f, 0xfe00, 0xfe01, 0xfe02, 0xfe03, 0xfe04,
0xfe05, 0xfe07, 0xfe09, 0xfe0a, 0xfe0b, 0xfe0c, 0xfe0d, 0xfe0e,
0xfe0f, 0xfffd
#if !defined(__CYGWIN__)
, 0xe0100, 0xe0101, 0xe0102, 0xe0103, 0xe0104, 0xe0105, 0xe0106,
0xe0107, 0xe0108, 0xe0109, 0xe010a, 0xe01ef
#endif
};
// FTerm non-member functions
//----------------------------------------------------------------------
uInt env2uint (const char* env)
{
FString str(getenv(env));
if ( str.isEmpty() )
return 0;
try
{
return str.toUInt();
}
catch (const std::exception&)
{
return 0;
}
}
//----------------------------------------------------------------------
inline bool hasAmbiguousWidth (wchar_t wchar)
{
const auto& begin = std::begin(ambiguous_width_list);
const auto& end = std::end(ambiguous_width_list);
if ( std::find(begin, end, wchar) != end ) // found
return true;
return false;
}
//----------------------------------------------------------------------
wchar_t cp437_to_unicode (uChar c)
{
constexpr std::size_t CP437 = 0;
constexpr std::size_t UNICODE = 1;
wchar_t ucs = c;
for (std::size_t i{0}; i <= fc::lastCP437Item; i++)
{
if ( fc::cp437_ucs[i][CP437] == c ) // found
{
ucs = fc::cp437_ucs[i][UNICODE];
break;
}
}
return ucs;
}
//----------------------------------------------------------------------
uChar unicode_to_cp437 (wchar_t ucs)
{
constexpr std::size_t CP437 = 0;
constexpr std::size_t UNICODE = 1;
uChar c{'?'};
for (std::size_t i{0}; i <= fc::lastCP437Item; i++)
{
if ( fc::cp437_ucs[i][UNICODE] == ucs ) // found
{
c = uChar(fc::cp437_ucs[i][CP437]);
break;
}
}
return c;
}
//----------------------------------------------------------------------
FString getFullWidth (const FString& str)
{
// Converts half-width to full-width characters
FString s(str);
constexpr std::size_t HALF = 0;
constexpr std::size_t FULL = 1;
for (auto&& c : s)
{
if ( c > L'\x20' && c < L'\x7f' ) // half-width ASCII
{
c += 0xfee0;
}
else
{
for (std::size_t i{0}; i <= fc::lastHalfWidthItem; i++)
{
if ( fc::halfWidth_fullWidth[i][HALF] == c ) // found
c = fc::halfWidth_fullWidth[i][FULL];
}
}
}
return s;
}
//----------------------------------------------------------------------
FString getHalfWidth (const FString& str)
{
// Converts full-width to half-width characters
FString s(str);
constexpr std::size_t HALF = 0;
constexpr std::size_t FULL = 1;
for (auto&& c : s)
{
if ( c > L'\xff00' && c < L'\xff5f' ) // full-width ASCII
{
c -= 0xfee0;
}
else
{
for (std::size_t i{0}; i <= fc::lastHalfWidthItem; i++)
{
if ( fc::halfWidth_fullWidth[i][FULL] == c ) // found
c = fc::halfWidth_fullWidth[i][HALF];
}
}
}
return s;
}
//----------------------------------------------------------------------
FString getColumnSubString ( const FString& str
, std::size_t col_pos, std::size_t col_len )
{
FString s(str);
std::size_t col_first{1}, col_num{0}, first{1}, num{0};
if ( col_len == 0 || s.isEmpty() )
return FString(L"");
if ( col_pos == 0 )
col_pos = 1;
for (auto&& ch : s)
{
std::size_t width = getColumnWidth(ch);
if ( col_first < col_pos )
{
if ( col_first + width <= col_pos )
{
col_first += width;
first++;
}
else
{
ch = fc::SingleLeftAngleQuotationMark; //
num = col_num = 1;
col_pos = col_first;
}
}
else
{
if ( col_num + width <= col_len )
{
col_num += width;
num++;
}
else if ( col_num < col_len )
{
ch = fc::SingleRightAngleQuotationMark; //
num++;
break;
}
}
}
if ( col_first < col_pos ) // String length < col_pos
return FString(L"");
return s.mid(first, num);
}
//----------------------------------------------------------------------
std::size_t getLengthFromColumnWidth ( const FString& str
, std::size_t col_len )
{
std::size_t column_width{0}, length{0};
for (auto&& ch : str)
{
if ( column_width < col_len )
{
column_width += getColumnWidth(ch);
length++;
}
}
return length;
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (const FString& s, std::size_t pos)
{
if ( s.isEmpty() )
return 0;
std::size_t column_width{0};
auto length = s.getLength();
if ( pos > length )
pos = length;
for (std::size_t i{0}; i < pos; i++)
column_width += getColumnWidth(s[i]);
return column_width;
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (const FString& s)
{
int column_width{0};
if ( s.isEmpty() )
return 0;
for (const auto& wchar : s)
column_width += getColumnWidth(wchar);
return ( column_width == -1 ) ? 0 : std::size_t(column_width);
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (const wchar_t wchar)
{
int column_width{};
#if defined(__NetBSD__) || defined(__OpenBSD__) \
|| defined(__FreeBSD__) || defined(__DragonFly__) \
|| defined(__sun) && defined(__SVR4)
if ( hasAmbiguousWidth(wchar) )
column_width = 1;
else
#endif
if ( wchar >= fc::NF_rev_left_arrow2 && wchar <= fc::NF_check_mark )
column_width = 1;
else
column_width = wcwidth(wchar);
return ( column_width == -1 ) ? 0 : std::size_t(column_width);
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (FChar& term_char)
{
std::size_t char_width = getColumnWidth(term_char.ch);
if ( char_width == 2 && FTerm::getEncoding() != fc::UTF8 )
{
term_char.ch = '.';
term_char.attr.bit.char_width = 1;
}
else
term_char.attr.bit.char_width = char_width & 0x03;
return char_width;
}
//----------------------------------------------------------------------
std::size_t getColumnWidth (const FTermBuffer& termbuffer)
{
std::size_t column_width{0};
for (auto&& tc : termbuffer)
column_width += tc.attr.bit.char_width;
return column_width;
}
} // namespace finalcut

View File

@ -46,8 +46,8 @@ const FString FTermBuffer::toString() const
std::wstring wide_string{}; std::wstring wide_string{};
wide_string.reserve(data.size()); wide_string.reserve(data.size());
for (auto&& tc : data) for (auto&& fchar : data)
wide_string.push_back(tc.code); wide_string.push_back(fchar.ch);
return FString(wide_string); return FString(wide_string);
} }
@ -60,9 +60,9 @@ int FTermBuffer::write (const FString& string)
for (auto&& c : string) for (auto&& c : string)
{ {
charData nc; // next character FChar nc; // next character
nc = FVTerm::getAttribute(); nc = FVTerm::getAttribute();
nc.code = c; nc.ch = c;
getColumnWidth(nc); // add column width getColumnWidth(nc); // add column width
nc.attr.bit.no_changes = false; nc.attr.bit.no_changes = false;
nc.attr.bit.printed = false; nc.attr.bit.printed = false;
@ -75,8 +75,8 @@ int FTermBuffer::write (const FString& string)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FTermBuffer::write (wchar_t ch) int FTermBuffer::write (wchar_t ch)
{ {
charData nc = FVTerm::getAttribute(); // next character FChar nc = FVTerm::getAttribute(); // next character
nc.code = ch; nc.ch = ch;
getColumnWidth(nc); // add column width getColumnWidth(nc); // add column width
nc.attr.bit.no_changes = false; nc.attr.bit.no_changes = false;
nc.attr.bit.printed = false; nc.attr.bit.printed = false;
@ -94,7 +94,7 @@ void FTermBuffer::write (const FColorPair& pair)
// FTermBuffer non-member operators // FTermBuffer non-member operators
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FTermBuffer::charDataVector& operator << ( FTermBuffer::charDataVector& termString FTermBuffer::FCharVector& operator << ( FTermBuffer::FCharVector& termString
, const FTermBuffer& buf ) , const FTermBuffer& buf )
{ {
if ( ! buf.data.empty() ) if ( ! buf.data.empty() )

View File

@ -230,48 +230,48 @@ void FTermcap::termcapKeys (char*& buffer)
{ {
// Read termcap key strings // Read termcap key strings
for (std::size_t i{0}; fc::Fkey[i].tname[0] != 0; i++) for (std::size_t i{0}; fc::fkey[i].tname[0] != 0; i++)
{ {
fc::Fkey[i].string = tgetstr(fc::Fkey[i].tname, &buffer); fc::fkey[i].string = tgetstr(fc::fkey[i].tname, &buffer);
// Fallback for rxvt with TERM=xterm // Fallback for rxvt with TERM=xterm
if ( std::strncmp(fc::Fkey[i].tname, "khx", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "khx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "7~"); // Home key fc::fkey[i].string = C_STR(CSI "7~"); // Home key
if ( std::strncmp(fc::Fkey[i].tname, "@7x", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "@7x", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "8~"); // End key fc::fkey[i].string = C_STR(CSI "8~"); // End key
if ( std::strncmp(fc::Fkey[i].tname, "k1x", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "k1x", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "11~"); // F1 fc::fkey[i].string = C_STR(CSI "11~"); // F1
if ( std::strncmp(fc::Fkey[i].tname, "k2x", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "k2x", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "12~"); // F2 fc::fkey[i].string = C_STR(CSI "12~"); // F2
if ( std::strncmp(fc::Fkey[i].tname, "k3x", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "k3x", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "13~"); // F3 fc::fkey[i].string = C_STR(CSI "13~"); // F3
if ( std::strncmp(fc::Fkey[i].tname, "k4x", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "k4x", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "14~"); // F4 fc::fkey[i].string = C_STR(CSI "14~"); // F4
// Fallback for TERM=ansi // Fallback for TERM=ansi
if ( std::strncmp(fc::Fkey[i].tname, "@7X", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "@7X", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "K"); // End key fc::fkey[i].string = C_STR(CSI "K"); // End key
// Keypad keys // Keypad keys
if ( std::strncmp(fc::Fkey[i].tname, "@8x", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "@8x", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OM"); // Enter key fc::fkey[i].string = C_STR(ESC "OM"); // Enter key
if ( std::strncmp(fc::Fkey[i].tname, "KP1", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "KP1", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "Oo"); // Keypad slash fc::fkey[i].string = C_STR(ESC "Oo"); // Keypad slash
if ( std::strncmp(fc::Fkey[i].tname, "KP2", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "KP2", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "Oj"); // Keypad asterisk fc::fkey[i].string = C_STR(ESC "Oj"); // Keypad asterisk
if ( std::strncmp(fc::Fkey[i].tname, "KP3", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "KP3", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "Om"); // Keypad minus sign fc::fkey[i].string = C_STR(ESC "Om"); // Keypad minus sign
if ( std::strncmp(fc::Fkey[i].tname, "KP4", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "KP4", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "Ok"); // Keypad plus sign fc::fkey[i].string = C_STR(ESC "Ok"); // Keypad plus sign
} }
// VT100 key codes for the arrow and function keys // VT100 key codes for the arrow and function keys
@ -290,31 +290,31 @@ void FTermcap::termcapKeysVt100 (char*& buffer)
|| ( TCAP(fc::t_cursor_up) || ( TCAP(fc::t_cursor_up)
&& (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) ) && (std::strcmp(TCAP(fc::t_cursor_up), CSI "A") == 0) ) )
{ {
for (std::size_t i{0}; fc::Fkey[i].tname[0] != 0; i++) for (std::size_t i{0}; fc::fkey[i].tname[0] != 0; i++)
{ {
if ( std::strncmp(fc::Fkey[i].tname, "kux", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "kux", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "A"); // Key up fc::fkey[i].string = C_STR(CSI "A"); // Key up
if ( std::strncmp(fc::Fkey[i].tname, "kdx", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "kdx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "B"); // Key down fc::fkey[i].string = C_STR(CSI "B"); // Key down
if ( std::strncmp(fc::Fkey[i].tname, "krx", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "krx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "C"); // Key right fc::fkey[i].string = C_STR(CSI "C"); // Key right
if ( std::strncmp(fc::Fkey[i].tname, "klx", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "klx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "D"); // Key left fc::fkey[i].string = C_STR(CSI "D"); // Key left
if ( std::strncmp(fc::Fkey[i].tname, "k1X", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "k1X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OP"); // PF1 fc::fkey[i].string = C_STR(ESC "OP"); // PF1
if ( std::strncmp(fc::Fkey[i].tname, "k2X", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "k2X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OQ"); // PF2 fc::fkey[i].string = C_STR(ESC "OQ"); // PF2
if ( std::strncmp(fc::Fkey[i].tname, "k3X", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "k3X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OR"); // PF3 fc::fkey[i].string = C_STR(ESC "OR"); // PF3
if ( std::strncmp(fc::Fkey[i].tname, "k4X", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "k4X", 3) == 0 )
fc::Fkey[i].string = C_STR(ESC "OS"); // PF4 fc::fkey[i].string = C_STR(ESC "OS"); // PF4
} }
} }
} }

View File

@ -402,71 +402,71 @@ void FTermcapQuirks::sunConsole()
C_STR(CSI "%p1%dD"); C_STR(CSI "%p1%dD");
// Sun Microsystems workstation console keys // Sun Microsystems workstation console keys
for (std::size_t i{0}; fc::Fkey[i].tname[0] != 0; i++) for (std::size_t i{0}; fc::fkey[i].tname[0] != 0; i++)
{ {
if ( std::strncmp(fc::Fkey[i].tname, "K2", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "K2", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "218z"); // center of keypad fc::fkey[i].string = C_STR(CSI "218z"); // center of keypad
if ( std::strncmp(fc::Fkey[i].tname, "kb", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "kb", 2) == 0 )
fc::Fkey[i].string = C_STR("\b"); // backspace key fc::fkey[i].string = C_STR("\b"); // backspace key
if ( std::strncmp(fc::Fkey[i].tname, "kD", 2) == 0 if ( std::strncmp(fc::fkey[i].tname, "kD", 2) == 0
&& std::strlen(fc::Fkey[i].tname) == 2 ) && std::strlen(fc::fkey[i].tname) == 2 )
fc::Fkey[i].string = C_STR("\177"); // delete-character key fc::fkey[i].string = C_STR("\177"); // delete-character key
if ( std::strncmp(fc::Fkey[i].tname, "@7", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "@7", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "220z"); // end key fc::fkey[i].string = C_STR(CSI "220z"); // end key
if ( std::strncmp(fc::Fkey[i].tname, "k;", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "k;", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "233z"); // F10 function key fc::fkey[i].string = C_STR(CSI "233z"); // F10 function key
if ( std::strncmp(fc::Fkey[i].tname, "F1", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "F1", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "234z"); // F11 function key fc::fkey[i].string = C_STR(CSI "234z"); // F11 function key
if ( std::strncmp(fc::Fkey[i].tname, "F2", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "F2", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "235z"); // F12 function key fc::fkey[i].string = C_STR(CSI "235z"); // F12 function key
if ( std::strncmp(fc::Fkey[i].tname, "kh", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "kh", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "214z"); // home key fc::fkey[i].string = C_STR(CSI "214z"); // home key
if ( std::strncmp(fc::Fkey[i].tname, "kI", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "kI", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "247z"); // insert-character key fc::fkey[i].string = C_STR(CSI "247z"); // insert-character key
if ( std::strncmp(fc::Fkey[i].tname, "kN", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "kN", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "222z"); // next-page key fc::fkey[i].string = C_STR(CSI "222z"); // next-page key
if ( std::strncmp(fc::Fkey[i].tname, "%7", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "%7", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "194z"); // options key fc::fkey[i].string = C_STR(CSI "194z"); // options key
if ( std::strncmp(fc::Fkey[i].tname, "kP", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "kP", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "216z"); // prev-page key fc::fkey[i].string = C_STR(CSI "216z"); // prev-page key
if ( std::strncmp(fc::Fkey[i].tname, "&5", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "&5", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "193z"); // resume key fc::fkey[i].string = C_STR(CSI "193z"); // resume key
if ( std::strncmp(fc::Fkey[i].tname, "&8", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "&8", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "195z"); // undo key fc::fkey[i].string = C_STR(CSI "195z"); // undo key
if ( std::strncmp(fc::Fkey[i].tname, "K2", 2) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "K2", 2) == 0 )
fc::Fkey[i].string = C_STR(CSI "218z"); // center of keypad fc::fkey[i].string = C_STR(CSI "218z"); // center of keypad
if ( std::strncmp(fc::Fkey[i].tname, "kDx", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "kDx", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "249z"); // keypad delete fc::fkey[i].string = C_STR(CSI "249z"); // keypad delete
if ( std::strncmp(fc::Fkey[i].tname, "@8x", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "@8x", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "250z"); // enter/send key fc::fkey[i].string = C_STR(CSI "250z"); // enter/send key
if ( std::strncmp(fc::Fkey[i].tname, "KP1", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "KP1", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "212z"); // keypad slash fc::fkey[i].string = C_STR(CSI "212z"); // keypad slash
if ( std::strncmp(fc::Fkey[i].tname, "KP2", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "KP2", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "213z"); // keypad asterisk fc::fkey[i].string = C_STR(CSI "213z"); // keypad asterisk
if ( std::strncmp(fc::Fkey[i].tname, "KP3", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "KP3", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "254z"); // keypad minus sign fc::fkey[i].string = C_STR(CSI "254z"); // keypad minus sign
if ( std::strncmp(fc::Fkey[i].tname, "KP4", 3) == 0 ) if ( std::strncmp(fc::fkey[i].tname, "KP4", 3) == 0 )
fc::Fkey[i].string = C_STR(CSI "253z"); // keypad plus sign fc::fkey[i].string = C_STR(CSI "253z"); // keypad plus sign
} }
} }

View File

@ -26,7 +26,6 @@
#include "final/emptyfstring.h" #include "final/emptyfstring.h"
#include "final/fc.h" #include "final/fc.h"
#include "final/fconfig.h"
#include "final/fsystem.h" #include "final/fsystem.h"
#include "final/fterm.h" #include "final/fterm.h"
#include "final/ftermdata.h" #include "final/ftermdata.h"
@ -46,7 +45,7 @@ namespace finalcut
{ {
// static class attributes // static class attributes
FTermDetection::terminalType FTermDetection::terminal_type{}; FTermDetection::FTerminalType FTermDetection::terminal_type{};
FTermDetection::colorEnv FTermDetection::color_env{}; FTermDetection::colorEnv FTermDetection::color_env{};
FTermDetection::secondaryDA FTermDetection::secondary_da{}; FTermDetection::secondaryDA FTermDetection::secondary_da{};
FTermData* FTermDetection::fterm_data{nullptr}; FTermData* FTermDetection::fterm_data{nullptr};
@ -546,10 +545,11 @@ const FString FTermDetection::getXTermColorName (FColor color)
struct timeval tv{}; struct timeval tv{};
int stdin_no = FTermios::getStdIn(); int stdin_no = FTermios::getStdIn();
char temp[512]{}; // get color
std::fprintf (stdout, OSC "4;%hu;?" BEL, color); // get color std::fprintf (stdout, OSC "4;%hu;?" BEL, color);
std::fflush(stdout); std::fflush (stdout);
char temp[512]{};
FD_ZERO(&ifds); FD_ZERO(&ifds);
FD_SET(stdin_no, &ifds); FD_SET(stdin_no, &ifds);
tv.tv_sec = 0; tv.tv_sec = 0;

View File

@ -41,26 +41,6 @@
namespace finalcut namespace finalcut
{ {
// static class attributes
#if defined(__linux__)
FTermLinux::modifier_key FTermLinux::mod_key{};
console_font_op FTermLinux::screen_font{};
unimapdesc FTermLinux::screen_unicode_map{};
bool FTermLinux::new_font{false};
bool FTermLinux::vga_font{false};
bool FTermLinux::has_saved_palette{false};
FTermData* FTermLinux::fterm_data{nullptr};
FSystem* FTermLinux::fsystem{nullptr};
FTermDetection* FTermLinux::term_detection{nullptr};
fc::linuxConsoleCursorStyle FTermLinux::linux_console_cursor_style{};
FTermLinux::ColorMap FTermLinux::saved_color_map{};
FTermLinux::ColorMap FTermLinux::cmap{};
int FTermLinux::framebuffer_bpp{-1};
#endif // defined(__linux__)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FTermLinux // class FTermLinux
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -134,7 +114,7 @@ void FTermLinux::setUTF8 (bool enable)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#if defined(__x86_64__) || defined(__i386) || defined(__arm__) #if defined(ISA_SYSCTL_SUPPORT)
bool FTermLinux::setPalette (FColor index, int r, int g, int b) bool FTermLinux::setPalette (FColor index, int r, int g, int b)
{ {
if ( ! FTerm::isLinuxTerm() ) if ( ! FTerm::isLinuxTerm() )
@ -183,7 +163,10 @@ void FTermLinux::init()
screen_font.data = nullptr; screen_font.data = nullptr;
fterm_data->supportShadowCharacter (true); fterm_data->supportShadowCharacter (true);
fterm_data->supportHalfBlockCharacter (true); fterm_data->supportHalfBlockCharacter (true);
#if defined(ISA_SYSCTL_SUPPORT)
getVGAPalette(); getVGAPalette();
#endif
if ( FTerm::openConsole() == 0 ) if ( FTerm::openConsole() == 0 )
{ {
@ -194,7 +177,7 @@ void FTermLinux::init()
getUnicodeMap(); getUnicodeMap();
getScreenFont(); getScreenFont();
#if defined(__x86_64__) || defined(__i386) || defined(__arm__) #if defined(ISA_SYSCTL_SUPPORT)
// Enable 16 background colors // Enable 16 background colors
if ( setBlinkAsIntensity(true) == 0 ) if ( setBlinkAsIntensity(true) == 0 )
FTermcap::max_color = 16; FTermcap::max_color = 16;
@ -266,7 +249,7 @@ void FTermLinux::finish()
{ {
if ( FTerm::isLinuxTerm() ) if ( FTerm::isLinuxTerm() )
{ {
#if defined(__x86_64__) || defined(__i386) || defined(__arm__) #if defined(ISA_SYSCTL_SUPPORT)
setBlinkAsIntensity (false); setBlinkAsIntensity (false);
#endif #endif
setLinuxCursorStyle (fc::default_cursor); setLinuxCursorStyle (fc::default_cursor);
@ -403,7 +386,7 @@ bool FTermLinux::saveColorMap()
if ( ! FTerm::isLinuxTerm() ) if ( ! FTerm::isLinuxTerm() )
return false; return false;
#if defined(__x86_64__) || defined(__i386) || defined(__arm__) #if defined(ISA_SYSCTL_SUPPORT)
return saveVGAPalette(); return saveVGAPalette();
#else #else
return false; return false;
@ -416,7 +399,7 @@ bool FTermLinux::resetColorMap()
if ( ! FTerm::isLinuxTerm() ) if ( ! FTerm::isLinuxTerm() )
return false; return false;
#if defined(__x86_64__) || defined(__i386) || defined(__arm__) #if defined(ISA_SYSCTL_SUPPORT)
return resetVGAPalette(); return resetVGAPalette();
#else #else
return false; return false;
@ -772,7 +755,7 @@ void FTermLinux::setLinuxCursorStyle (CursorStyle style)
FTerm::putstringf (CSI "?%dc", style); FTerm::putstringf (CSI "?%dc", style);
} }
#if defined(__x86_64__) || defined(__i386) || defined(__arm__) #if defined(ISA_SYSCTL_SUPPORT)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline uInt16 FTermLinux::getInputStatusRegisterOne() inline uInt16 FTermLinux::getInputStatusRegisterOne()
{ {
@ -976,7 +959,7 @@ bool FTermLinux::resetVGAPalette()
return true; return true;
} }
#endif // defined(__x86_64__) || defined(__i386) || defined(__arm__) #endif // defined(ISA_SYSCTL_SUPPORT)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FKey FTermLinux::shiftKeyCorrection (const FKey& key_id) FKey FTermLinux::shiftKeyCorrection (const FKey& key_id)

View File

@ -39,6 +39,11 @@ namespace finalcut
// class FTermOpenBSD // class FTermOpenBSD
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FTermOpenBSD::~FTermOpenBSD() // destructor
{ }
// public methods of FTermOpenBSD // public methods of FTermOpenBSD
//---------------------------------------------------------------------- //----------------------------------------------------------------------
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)

View File

@ -39,21 +39,7 @@ namespace finalcut
// static class attributes // static class attributes
bool FTermXTerminal::mouse_support{false}; bool FTermXTerminal::mouse_support{false};
bool FTermXTerminal::meta_sends_esc{false};
bool FTermXTerminal::xterm_default_colors{false};
std::size_t FTermXTerminal::term_width{80};
std::size_t FTermXTerminal::term_height{24};
const FString* FTermXTerminal::xterm_font{nullptr};
const FString* FTermXTerminal::xterm_title{nullptr};
const FString* FTermXTerminal::foreground_color{nullptr};
const FString* FTermXTerminal::background_color{nullptr};
const FString* FTermXTerminal::cursor_color{nullptr};
const FString* FTermXTerminal::mouse_foreground_color{nullptr};
const FString* FTermXTerminal::mouse_background_color{nullptr};
const FString* FTermXTerminal::highlight_background_color{nullptr};
FSystem* FTermXTerminal::fsystem{nullptr}; FSystem* FTermXTerminal::fsystem{nullptr};
FTermDetection* FTermXTerminal::term_detection{nullptr};
fc::xtermCursorStyle FTermXTerminal::cursor_style{fc::unknown_cursor_style};
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -70,31 +56,7 @@ FTermXTerminal::FTermXTerminal()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FTermXTerminal::~FTermXTerminal() // destructor FTermXTerminal::~FTermXTerminal() // destructor
{ { }
if ( highlight_background_color )
delete highlight_background_color;
if ( mouse_background_color )
delete mouse_background_color;
if ( mouse_foreground_color )
delete mouse_foreground_color;
if ( cursor_color )
delete cursor_color;
if ( background_color )
delete background_color;
if ( foreground_color )
delete foreground_color;
if ( xterm_title )
delete xterm_title;
if ( xterm_font )
delete xterm_font;
}
// public methods of FTermXTerminal // public methods of FTermXTerminal
@ -112,10 +74,7 @@ void FTermXTerminal::setFont (const FString& fontname)
{ {
// Change the XTerm font (needs the allowFontOps resource) // Change the XTerm font (needs the allowFontOps resource)
if ( xterm_font ) xterm_font = fontname;
delete xterm_font;
xterm_font = new FString(fontname);
setXTermFont(); setXTermFont();
} }
@ -124,10 +83,7 @@ void FTermXTerminal::setTitle (const FString& title)
{ {
// Set the xterm title // Set the xterm title
if ( xterm_title ) xterm_title = title;
delete xterm_title;
xterm_title = new FString(title);
setXTermTitle(); setXTermTitle();
} }
@ -146,10 +102,7 @@ void FTermXTerminal::setForeground (const FString& fg)
{ {
// Set the XTerm text foreground color // Set the XTerm text foreground color
if ( foreground_color ) foreground_color = fg;
delete foreground_color;
foreground_color = new FString(fg);
setXTermForeground(); setXTermForeground();
} }
@ -158,10 +111,7 @@ void FTermXTerminal::setBackground (const FString& bg)
{ {
// Set the XTerm text background color // Set the XTerm text background color
if ( background_color ) background_color = bg;
delete background_color;
background_color = new FString(bg);
setXTermBackground(); setXTermBackground();
} }
@ -170,10 +120,7 @@ void FTermXTerminal::setCursorColor (const FString& cc)
{ {
// Set the text cursor color // Set the text cursor color
if ( cursor_color ) cursor_color = cc;
delete cursor_color;
cursor_color = new FString(cc);
setXTermCursorColor(); setXTermCursorColor();
} }
@ -182,10 +129,7 @@ void FTermXTerminal::setMouseForeground (const FString& mfg)
{ {
// Set the mouse foreground color // Set the mouse foreground color
if ( mouse_foreground_color ) mouse_foreground_color = mfg;
delete mouse_foreground_color;
mouse_foreground_color = new FString(mfg);
setXTermMouseForeground(); setXTermMouseForeground();
} }
@ -194,10 +138,7 @@ void FTermXTerminal::setMouseBackground (const FString& mbg)
{ {
// Set the mouse background color // Set the mouse background color
if ( mouse_background_color ) mouse_background_color = mbg;
delete mouse_background_color;
mouse_background_color = new FString(mbg);
setXTermMouseBackground(); setXTermMouseBackground();
} }
@ -206,10 +147,7 @@ void FTermXTerminal::setHighlightBackground (const FString& hbg)
{ {
// Set the highlight background color // Set the highlight background color
if ( highlight_background_color ) highlight_background_color = hbg;
delete highlight_background_color;
highlight_background_color = new FString(hbg);
setXTermHighlightBackground(); setXTermHighlightBackground();
} }
@ -266,10 +204,7 @@ void FTermXTerminal::resetForeground()
{ {
// Reset the XTerm text foreground color // Reset the XTerm text foreground color
if ( foreground_color ) foreground_color.clear();
delete foreground_color;
foreground_color = nullptr;
resetXTermForeground(); resetXTermForeground();
} }
@ -278,10 +213,7 @@ void FTermXTerminal::resetBackground()
{ {
// Reset the XTerm text background color // Reset the XTerm text background color
if ( background_color ) background_color.clear();
delete background_color;
background_color = nullptr;
resetXTermBackground(); resetXTermBackground();
} }
@ -290,10 +222,7 @@ void FTermXTerminal::resetCursorColor()
{ {
// Reset the text cursor color // Reset the text cursor color
if ( cursor_color ) cursor_color.clear();
delete cursor_color;
cursor_color = nullptr;
resetXTermCursorColor(); resetXTermCursorColor();
} }
@ -302,10 +231,7 @@ void FTermXTerminal::resetMouseForeground()
{ {
// Reset the mouse foreground color // Reset the mouse foreground color
if ( mouse_foreground_color ) mouse_foreground_color.clear();
delete mouse_foreground_color;
mouse_foreground_color = nullptr;
resetXTermMouseForeground(); resetXTermMouseForeground();
} }
@ -314,10 +240,7 @@ void FTermXTerminal::resetMouseBackground()
{ {
// Reset the mouse background color // Reset the mouse background color
if ( mouse_background_color ) mouse_background_color.clear();
delete mouse_background_color;
mouse_background_color = nullptr;
resetXTermMouseBackground(); resetXTermMouseBackground();
} }
@ -326,10 +249,7 @@ void FTermXTerminal::resetHighlightBackground()
{ {
// Reset the highlight background color // Reset the highlight background color
if ( highlight_background_color ) highlight_background_color.clear();
delete highlight_background_color;
highlight_background_color = nullptr;
resetXTermHighlightBackground(); resetXTermHighlightBackground();
} }
@ -364,12 +284,6 @@ void FTermXTerminal::captureFontAndTitle()
|| term_detection->isUrxvtTerminal() ) || term_detection->isUrxvtTerminal() )
&& ! term_detection->isRxvtTerminal() ) && ! term_detection->isRxvtTerminal() )
{ {
if ( xterm_font )
delete xterm_font;
if ( xterm_title )
delete xterm_title;
FTermios::setCaptureSendCharacters(); FTermios::setCaptureSendCharacters();
xterm_font = captureXTermFont(); xterm_font = captureXTermFont();
xterm_title = captureXTermTitle(); xterm_title = captureXTermTitle();
@ -420,7 +334,7 @@ void FTermXTerminal::setXTermTitle()
|| FTermcap::osc_support ) || FTermcap::osc_support )
{ {
oscPrefix(); oscPrefix();
FTerm::putstringf (OSC "0;%s" BEL, xterm_title->c_str()); FTerm::putstringf (OSC "0;%s" BEL, xterm_title.c_str());
oscPostfix(); oscPostfix();
std::fflush(stdout); std::fflush(stdout);
} }
@ -449,7 +363,7 @@ void FTermXTerminal::setXTermFont()
|| FTermcap::osc_support ) || FTermcap::osc_support )
{ {
oscPrefix(); oscPrefix();
FTerm::putstringf (OSC "50;%s" BEL, xterm_font->c_str() ); FTerm::putstringf (OSC "50;%s" BEL, xterm_font.c_str() );
oscPostfix(); oscPostfix();
} }
} }
@ -466,7 +380,7 @@ void FTermXTerminal::setXTermForeground()
|| FTermcap::osc_support ) || FTermcap::osc_support )
{ {
oscPrefix(); oscPrefix();
FTerm::putstringf (OSC "10;%s" BEL, foreground_color->c_str()); FTerm::putstringf (OSC "10;%s" BEL, foreground_color.c_str());
oscPostfix(); oscPostfix();
std::fflush(stdout); std::fflush(stdout);
} }
@ -484,7 +398,7 @@ void FTermXTerminal::setXTermBackground()
|| FTermcap::osc_support ) || FTermcap::osc_support )
{ {
oscPrefix(); oscPrefix();
FTerm::putstringf (OSC "11;%s" BEL, background_color->c_str()); FTerm::putstringf (OSC "11;%s" BEL, background_color.c_str());
oscPostfix(); oscPostfix();
std::fflush(stdout); std::fflush(stdout);
} }
@ -502,7 +416,7 @@ void FTermXTerminal::setXTermCursorColor()
|| FTermcap::osc_support ) || FTermcap::osc_support )
{ {
oscPrefix(); oscPrefix();
FTerm::putstringf (OSC "12;%s" BEL, cursor_color->c_str()); FTerm::putstringf (OSC "12;%s" BEL, cursor_color.c_str());
oscPostfix(); oscPostfix();
std::fflush(stdout); std::fflush(stdout);
} }
@ -519,7 +433,7 @@ void FTermXTerminal::setXTermMouseForeground()
|| FTermcap::osc_support ) || FTermcap::osc_support )
{ {
oscPrefix(); oscPrefix();
FTerm::putstringf (OSC "13;%s" BEL, mouse_foreground_color->c_str()); FTerm::putstringf (OSC "13;%s" BEL, mouse_foreground_color.c_str());
oscPostfix(); oscPostfix();
std::fflush(stdout); std::fflush(stdout);
} }
@ -535,7 +449,7 @@ void FTermXTerminal::setXTermMouseBackground()
|| FTermcap::osc_support ) || FTermcap::osc_support )
{ {
oscPrefix(); oscPrefix();
FTerm::putstringf (OSC "14;%s" BEL, mouse_background_color->c_str()); FTerm::putstringf (OSC "14;%s" BEL, mouse_background_color.c_str());
oscPostfix(); oscPostfix();
std::fflush(stdout); std::fflush(stdout);
} }
@ -552,7 +466,7 @@ void FTermXTerminal::setXTermHighlightBackground()
|| FTermcap::osc_support ) || FTermcap::osc_support )
{ {
oscPrefix(); oscPrefix();
FTerm::putstringf (OSC "17;%s" BEL, highlight_background_color->c_str()); FTerm::putstringf (OSC "17;%s" BEL, highlight_background_color.c_str());
oscPostfix(); oscPostfix();
std::fflush(stdout); std::fflush(stdout);
} }
@ -769,7 +683,7 @@ void FTermXTerminal::oscPostfix()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString* FTermXTerminal::captureXTermFont() const FString FTermXTerminal::captureXTermFont()
{ {
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
@ -796,36 +710,25 @@ const FString* FTermXTerminal::captureXTermFont()
if ( std::scanf("\033]50;%148[^\n]s", temp) == 1 ) if ( std::scanf("\033]50;%148[^\n]s", temp) == 1 )
{ {
FString* xtermfont;
std::size_t n = std::strlen(temp); std::size_t n = std::strlen(temp);
// BEL + '\0' = string terminator // BEL + '\0' = string terminator
if ( n >= 5 && temp[n - 1] == BEL[0] && temp[n] == '\0' ) if ( n >= 5 && temp[n - 1] == BEL[0] && temp[n] == '\0' )
temp[n - 1] = '\0'; temp[n - 1] = '\0';
try return FString(temp);
{
xtermfont = new FString(temp);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return 0;
}
return xtermfont;
} }
} }
} }
return 0; return FString{};
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString* FTermXTerminal::captureXTermTitle() const FString FTermXTerminal::captureXTermTitle()
{ {
if ( term_detection->isKdeTerminal() ) if ( term_detection->isKdeTerminal() )
return 0; return FString{};
fd_set ifds{}; fd_set ifds{};
struct timeval tv{}; struct timeval tv{};
@ -851,29 +754,16 @@ const FString* FTermXTerminal::captureXTermTitle()
// Esc + \ = OSC string terminator // Esc + \ = OSC string terminator
if ( n >= 2 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' ) if ( n >= 2 && temp[n - 2] == ESC[0] && temp[n - 1] == '\\' )
{ {
FString* xtermtitle;
if ( n < 4 ) if ( n < 4 )
return 0; return FString{};
temp[n - 2] = '\0'; temp[n - 2] = '\0';
return FString{temp};
try
{
xtermtitle = new FString(temp);
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return 0;
}
return xtermtitle;
} }
} }
} }
return 0; return FString{};
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -882,7 +772,7 @@ void FTermXTerminal::enableXTermMouse()
// Activate the xterm mouse support // Activate the xterm mouse support
if ( mouse_support ) if ( mouse_support )
return; return; // The mouse is already activated
if ( ! fsystem ) if ( ! fsystem )
fsystem = FTerm::getFSystem(); fsystem = FTerm::getFSystem();
@ -902,7 +792,7 @@ void FTermXTerminal::disableXTermMouse()
// Deactivate the xterm mouse support // Deactivate the xterm mouse support
if ( ! mouse_support ) if ( ! mouse_support )
return; return; // The mouse was already deactivated
FTerm::putstring (CSI "?1006l" // disable SGR mouse mode FTerm::putstring (CSI "?1006l" // disable SGR mouse mode
CSI "?1015l" // disable urxvt mouse mode CSI "?1015l" // disable urxvt mouse mode

View File

@ -20,11 +20,6 @@
* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***********************************************************************/ ***********************************************************************/
#if defined(__CYGWIN__)
#include "final/fconfig.h" // includes _GNU_SOURCE for wcwidth()
#endif
#include <wchar.h>
#include <memory> #include <memory>
#include "final/fapplication.h" #include "final/fapplication.h"
@ -65,30 +60,28 @@ const FString FTextView::getText() const
return FString(""); return FString("");
std::size_t len{0}; std::size_t len{0};
std::size_t rows = getRows();
for (std::size_t i{0} ; i < rows; i++) for (auto&& line : data)
len += data[i].getLength() + 1; len += line.getLength() + 1; // String length + '\n'
FString s(len + 1); FString s(len); // Reserves storage
std::size_t idx{0}; auto iter = s.begin();
for (std::size_t i{0}; i < rows; i++) for (auto&& line : data)
{ {
const wchar_t* p = data[i].wc_str(); if ( ! line.isEmpty() )
if ( p )
{ {
while ( (s[idx++] = *p++) != 0 ); if ( iter != s.begin() )
s[idx - 1] = '\n'; {
*iter = '\n';
++iter;
} }
else
{ std::copy (line.begin(), line.end(), iter);
s[idx++] = '\n'; iter += std::distance(line.begin(), line.end());
} }
} }
s[idx - 1] = 0;
return s; return s;
} }
@ -241,7 +234,7 @@ void FTextView::insert (const FString& str, int pos)
hbar->setPageSize (int(maxLineWidth), int(getTextWidth())); hbar->setPageSize (int(maxLineWidth), int(getTextWidth()));
hbar->calculateSliderValues(); hbar->calculateSliderValues();
if ( isShown() && ! hbar->isShown() ) if ( isShown() && isHorizontallyScrollable() )
hbar->show(); hbar->show();
} }
} }
@ -256,10 +249,10 @@ void FTextView::insert (const FString& str, int pos)
vbar->setPageSize (int(getRows()), int(getTextHeight())); vbar->setPageSize (int(getRows()), int(getTextHeight()));
vbar->calculateSliderValues(); vbar->calculateSliderValues();
if ( isShown() && ! vbar->isShown() && getRows() > getTextHeight() ) if ( isShown() && ! vbar->isShown() && isVerticallyScrollable() )
vbar->show(); vbar->show();
if ( isShown() && vbar->isShown() && getRows() <= getTextHeight() ) if ( isShown() && vbar->isShown() && ! isVerticallyScrollable() )
vbar->hide(); vbar->hide();
processChanged(); processChanged();
@ -297,69 +290,42 @@ void FTextView::clear()
// clear list from screen // clear list from screen
setColor(); setColor();
if ( useFDialogBorder() )
{
auto parent = getParentWidget();
if ( parent )
static_cast<FDialog*>(parent)->redraw();
}
else
drawBorder();
std::size_t size = getWidth() - 2; std::size_t size = getWidth() - 2;
if ( size == 0 ) if ( size == 0 )
return; return;
char* blank = createBlankArray(size + 1);
for (int y{0}; y < int(getTextHeight()); y++) for (int y{0}; y < int(getTextHeight()); y++)
{ {
print() << FPoint(2, 2 - nf_offset + y) << blank; print() << FPoint(2, 2 - nf_offset + y)
<< FString(size, L' ');
} }
destroyBlankArray (blank); updateTerminal();
processChanged(); processChanged();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::onKeyPress (FKeyEvent* ev) void FTextView::onKeyPress (FKeyEvent* ev)
{ {
switch ( ev->key() ) int idx = int(ev->key());
if ( key_map.find(idx) != key_map.end() )
{ {
case fc::Fkey_up: key_map[idx]();
scrollBy (0, -1);
ev->accept(); ev->accept();
break;
case fc::Fkey_down:
scrollBy (0, 1);
ev->accept();
break;
case fc::Fkey_left:
scrollBy (-1, 0);
ev->accept();
break;
case fc::Fkey_right:
scrollBy (1, 0);
ev->accept();
break;
case fc::Fkey_ppage:
scrollBy (0, int(-getTextHeight()));
ev->accept();
break;
case fc::Fkey_npage:
scrollBy (0, int(getTextHeight()));
ev->accept();
break;
case fc::Fkey_home:
scrollToY (0);
ev->accept();
break;
case fc::Fkey_end:
scrollToY (int(getRows() - getTextHeight()));
ev->accept();
break;
default:
break;
} }
} }
@ -566,15 +532,15 @@ void FTextView::adjustSize()
if ( isShown() ) if ( isShown() )
{ {
if ( last_line < int(height) + nf_offset - 1 ) if ( isHorizontallyScrollable() )
vbar->hide();
else
vbar->show();
if ( max_width < int(width) - nf_offset - 1 )
hbar->hide();
else
hbar->show(); hbar->show();
else
hbar->hide();
if ( isVerticallyScrollable() )
vbar->show();
else
vbar->hide();
} }
} }
@ -595,8 +561,8 @@ std::size_t FTextView::getTextWidth()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::init() void FTextView::init()
{ {
initScrollbar (vbar, fc::vertical, &FTextView::cb_VBarChange); initScrollbar (vbar, fc::vertical, this, &FTextView::cb_VBarChange);
initScrollbar (hbar, fc::horizontal, &FTextView::cb_HBarChange); initScrollbar (hbar, fc::horizontal, this, &FTextView::cb_HBarChange);
const auto& wc = getFWidgetColors(); const auto& wc = getFWidgetColors();
setForegroundColor (wc.dialog_fg); setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg); setBackgroundColor (wc.dialog_bg);
@ -605,75 +571,28 @@ void FTextView::init()
setLeftPadding(1); setLeftPadding(1);
setBottomPadding(1); setBottomPadding(1);
setRightPadding(1 + nf_offset); setRightPadding(1 + nf_offset);
mapKeyFunctions();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::initScrollbar ( FScrollbarPtr& bar inline void FTextView::mapKeyFunctions()
, fc::orientation o
, FTextViewCallback callback )
{ {
try key_map[fc::Fkey_up] = [&] { scrollBy (0, -1); };
{ key_map[fc::Fkey_down] = [&] { scrollBy (0, 1); };
bar = std::make_shared<FScrollbar>(o, this); key_map[fc::Fkey_left] = [&] { scrollBy (-1, 0); };
} key_map[fc::Fkey_right] = [&] { scrollBy (1, 0); };
catch (const std::bad_alloc& ex) key_map[fc::Fkey_ppage] = [&] { scrollBy (0, int(-getTextHeight())); };
{ key_map[fc::Fkey_npage] = [&] { scrollBy (0, int(getTextHeight())); };
std::cerr << bad_alloc_str << ex.what() << std::endl; key_map[fc::Fkey_home] = [&] { scrollToY (0); };
return; key_map[fc::Fkey_end] = [&] { scrollToY (int(getRows() - getTextHeight())); };
}
bar->setMinimum(0);
bar->setValue(0);
bar->hide();
bar->addCallback
(
"change-value",
F_METHOD_CALLBACK (this, callback)
);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::draw() void FTextView::draw()
{ {
auto parent = getParentWidget();
bool is_text_dialog;
setColor(); setColor();
if ( isMonochron() )
setReverse(true);
if ( parent
&& parent->isDialogWidget()
&& isPaddingIgnored()
&& getGeometry() == FRect ( 1
, 2
, parent->getWidth()
, parent->getHeight() - 1) )
{
is_text_dialog = true;
}
else
is_text_dialog = false;
if ( ! (is_text_dialog || isNewFont()) )
drawBorder(); drawBorder();
drawScrollbars();
if ( isMonochron() )
setReverse(false);
if ( ! isShown() ) // first drawing
{
vbar->show();
hbar->show();
}
if ( vbar->isShown() )
vbar->redraw();
if ( hbar->isShown() )
hbar->redraw();
drawText(); drawText();
if ( hasFocus() && getStatusBar() ) if ( hasFocus() && getStatusBar() )
@ -690,7 +609,36 @@ void FTextView::draw()
setCursorPos (FPoint(int(getWidth()), int(getHeight()))); setCursorPos (FPoint(int(getWidth()), int(getHeight())));
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
}
//----------------------------------------------------------------------
void FTextView::drawBorder()
{
if ( ! useFDialogBorder() )
{
if ( isMonochron() )
setReverse(true);
FWidget::drawBorder();
if ( isMonochron() )
setReverse(false);
}
}
//----------------------------------------------------------------------
void FTextView::drawScrollbars()
{
if ( ! hbar->isShown() && isHorizontallyScrollable() )
hbar->show();
else
vbar->redraw();
if ( ! vbar->isShown() && isVerticallyScrollable() )
vbar->show();
else
hbar->redraw();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -721,7 +669,9 @@ void FTextView::drawText()
for (auto&& ch : line) // Column loop for (auto&& ch : line) // Column loop
{ {
if ( isPrintable(ch) ) if ( getColumnWidth(ch) == 0 )
continue;
else if ( isPrintable(ch) )
print (ch); print (ch);
else else
print ('.'); print ('.');
@ -737,6 +687,26 @@ void FTextView::drawText()
setReverse(false); setReverse(false);
} }
//----------------------------------------------------------------------
inline bool FTextView::useFDialogBorder()
{
auto parent = getParentWidget();
bool use_fdialog_border{false};
if ( parent
&& parent->isDialogWidget()
&& isPaddingIgnored()
&& getGeometry() == FRect ( 1
, 2
, parent->getWidth()
, parent->getHeight() - 1) )
{
use_fdialog_border = true;
}
return use_fdialog_border;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTextView::isPrintable (wchar_t ch) inline bool FTextView::isPrintable (wchar_t ch)
{ {

View File

@ -20,6 +20,8 @@
* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***********************************************************************/ ***********************************************************************/
#include <utility>
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fbuttongroup.h" #include "final/fbuttongroup.h"
#include "final/fevent.h" #include "final/fevent.h"
@ -233,7 +235,7 @@ void FToggleButton::onMouseDown (FMouseEvent* ev)
{ {
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -310,7 +312,7 @@ void FToggleButton::onAccel (FAccelEvent* ev)
{ {
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
processClick(); processClick();
@ -370,25 +372,7 @@ void FToggleButton::onFocusOut (FFocusEvent* out_ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::setHotkeyAccelerator() void FToggleButton::setHotkeyAccelerator()
{ {
FKey hotkey = getHotkey(text); setHotkeyViaString (this, text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
addAccelerator (FKey(std::tolower(int(hotkey))));
addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
addAccelerator (hotkey);
}
else
delAccelerator();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -429,34 +413,14 @@ void FToggleButton::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::drawLabel() void FToggleButton::drawLabel()
{ {
wchar_t* LabelText;
if ( text.isNull() || text.isEmpty() ) if ( text.isNull() || text.isEmpty() )
return; return;
std::size_t length = text.getLength();
try
{
LabelText = new wchar_t[length + 1]();
}
catch (const std::bad_alloc& ex)
{
std::cerr << bad_alloc_str << ex.what() << std::endl;
return;
}
FString txt(text); FString txt(text);
wchar_t* src = const_cast<wchar_t*>(txt.wc_str()); FString label_text{};
wchar_t* dest = const_cast<wchar_t*>(LabelText); auto hotkeypos = finalcut::getHotkeyPos(txt, label_text);
auto hotkeypos = finalcut::getHotkeyPos(src, dest, length);
if ( hotkeypos != NOT_SET )
length--;
print() << FPoint(1 + int(label_offset_pos), 1); print() << FPoint(1 + int(label_offset_pos), 1);
drawText (LabelText, hotkeypos, length); drawText (std::move(label_text), hotkeypos);
delete[] LabelText;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -561,9 +525,7 @@ void FToggleButton::init()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::drawText ( wchar_t LabelText[] void FToggleButton::drawText (FString&& label_text, std::size_t hotkeypos)
, std::size_t hotkeypos
, std::size_t length )
{ {
if ( isMonochron() ) if ( isMonochron() )
setReverse(true); setReverse(true);
@ -575,7 +537,7 @@ void FToggleButton::drawText ( wchar_t LabelText[]
else else
setColor (wc.label_inactive_fg, wc.label_inactive_bg); setColor (wc.label_inactive_fg, wc.label_inactive_bg);
for (std::size_t z{0}; z < length; z++) for (std::size_t z{0}; z < label_text.getLength(); z++)
{ {
if ( (z == hotkeypos) && flags.active ) if ( (z == hotkeypos) && flags.active )
{ {
@ -584,7 +546,7 @@ void FToggleButton::drawText ( wchar_t LabelText[]
if ( ! flags.no_underline ) if ( ! flags.no_underline )
setUnderline(); setUnderline();
print ( LabelText[z] ); print ( label_text[z] );
if ( ! flags.no_underline ) if ( ! flags.no_underline )
unsetUnderline(); unsetUnderline();
@ -592,7 +554,7 @@ void FToggleButton::drawText ( wchar_t LabelText[]
setColor (wc.label_fg, wc.label_bg); setColor (wc.label_fg, wc.label_bg);
} }
else else
print (LabelText[z]); print (label_text[z]);
} }
if ( isMonochron() ) if ( isMonochron() )

View File

@ -80,10 +80,6 @@ void FToolTip::draw()
{ {
int y{0}; int y{0};
setColor(); setColor();
if ( getMaxColor() < 16 )
setBold();
clearArea(); clearArea();
drawBorder(); drawBorder();
@ -92,8 +88,6 @@ void FToolTip::draw()
print() << FPoint(3, 2 + y) << line; print() << FPoint(3, 2 + y) << line;
y++; y++;
} }
unsetBold();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

View File

@ -43,10 +43,10 @@ FStatusBar* FWidget::statusbar{nullptr};
FMenuBar* FWidget::menubar{nullptr}; FMenuBar* FWidget::menubar{nullptr};
FWidget* FWidget::show_root_widget{nullptr}; FWidget* FWidget::show_root_widget{nullptr};
FWidget* FWidget::redraw_root_widget{nullptr}; FWidget* FWidget::redraw_root_widget{nullptr};
FWidget::widgetList* FWidget::window_list{nullptr}; FWidget::FWidgetList* FWidget::window_list{nullptr};
FWidget::widgetList* FWidget::dialog_list{nullptr}; FWidget::FWidgetList* FWidget::dialog_list{nullptr};
FWidget::widgetList* FWidget::always_on_top_list{nullptr}; FWidget::FWidgetList* FWidget::always_on_top_list{nullptr};
FWidget::widgetList* FWidget::close_widget{nullptr}; FWidget::FWidgetList* FWidget::close_widget{nullptr};
FWidgetColors FWidget::wcolors{}; FWidgetColors FWidget::wcolors{};
bool FWidget::init_desktop{false}; bool FWidget::init_desktop{false};
bool FWidget::hideable{false}; bool FWidget::hideable{false};
@ -170,9 +170,8 @@ FWidget* FWidget::getFirstFocusableWidget (FObjectList list)
return 0; return 0;
auto iter = list.begin(); auto iter = list.begin();
auto last = list.end();
while ( iter != last ) while ( iter != list.end() )
{ {
if ( (*iter)->isWidget() ) if ( (*iter)->isWidget() )
{ {
@ -194,7 +193,6 @@ FWidget* FWidget::getLastFocusableWidget (FObjectList list)
if ( list.empty() ) if ( list.empty() )
return 0; return 0;
auto first = list.begin();
auto iter = list.end(); auto iter = list.end();
do do
@ -209,19 +207,11 @@ FWidget* FWidget::getLastFocusableWidget (FObjectList list)
if ( child->isEnabled() && child->acceptFocus() ) if ( child->isEnabled() && child->acceptFocus() )
return child; return child;
} }
while ( iter != first ); while ( iter != list.begin() );
return 0; return 0;
} }
//----------------------------------------------------------------------
FPoint FWidget::getPrintPos()
{
const auto cur = getPrintCursor();
return FPoint ( cur.getX() - woffset.getX1() - getX() + 1
, cur.getY() - woffset.getY1() - getY() + 1 );
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::vector<bool>& FWidget::doubleFlatLine_ref (fc::sides side) std::vector<bool>& FWidget::doubleFlatLine_ref (fc::sides side)
{ {
@ -248,6 +238,14 @@ std::vector<bool>& FWidget::doubleFlatLine_ref (fc::sides side)
return double_flatline_mask.left; return double_flatline_mask.left;
} }
//----------------------------------------------------------------------
FPoint FWidget::getPrintPos()
{
const auto cur = getPrintCursor();
return FPoint ( cur.getX() - woffset.getX1() - getX() + 1
, cur.getY() - woffset.getY1() - getY() + 1 );
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::setMainWidget (FWidget* obj) void FWidget::setMainWidget (FWidget* obj)
{ {
@ -757,33 +755,25 @@ void FWidget::setDoubleFlatLine (fc::sides side, int pos, bool bit)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FWidget* FWidget::childWidgetAt (FWidget* p, const FPoint& pos) FWidget* FWidget::childWidgetAt (const FPoint& pos)
{ {
if ( p && p->hasChildren() ) if ( ! hasChildren() )
{ return 0;
auto iter = p->begin();
auto last = p->end();
while ( iter != last ) for (auto&& child : getChildren())
{ {
if ( ! (*iter)->isWidget() ) if ( ! child->isWidget() )
{
++iter;
continue; continue;
}
auto widget = static_cast<FWidget*>(*iter); auto widget = static_cast<FWidget*>(child);
if ( widget->isEnabled() if ( widget->isEnabled()
&& widget->isShown() && widget->isShown()
&& ! widget->isWindowWidget() && ! widget->isWindowWidget()
&& widget->getTermGeometry().contains(pos) ) && widget->getTermGeometry().contains(pos) )
{ {
auto child = childWidgetAt(widget, pos); auto sub_child = widget->childWidgetAt(pos);
return ( child != 0 ) ? child : widget; return ( sub_child != 0 ) ? sub_child : widget;
}
++iter;
} }
} }
@ -797,22 +787,18 @@ int FWidget::numOfFocusableChildren()
return 0; return 0;
int num{0}; int num{0};
auto iter = FObject::begin();
auto last = FObject::end();
while ( iter != last ) for (auto&& child : getChildren())
{ {
if ( (*iter)->isWidget() ) if ( child->isWidget() )
{ {
auto widget = static_cast<FWidget*>(*iter); auto widget = static_cast<FWidget*>(child);
if ( widget->isShown() if ( widget->isShown()
&& widget->acceptFocus() && widget->acceptFocus()
&& ! widget->isWindowWidget() ) && ! widget->isWindowWidget() )
num++; num++;
} }
++iter;
} }
return num; return num;
@ -821,6 +807,8 @@ int FWidget::numOfFocusableChildren()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWidget::close() bool FWidget::close()
{ {
// Sends a close event and quits the application on acceptance
FCloseEvent ev(fc::Close_Event); FCloseEvent ev(fc::Close_Event);
FApplication::sendEvent(this, &ev); FApplication::sendEvent(this, &ev);
@ -844,29 +832,31 @@ bool FWidget::close()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::addCallback ( const FString& cb_signal void FWidget::addCallback ( const FString& cb_signal
, FCallback cb_handler , FCallback cb_function
, FDataPtr data ) , FDataPtr data )
{ {
// add a (normal) function pointer as callback // Add a (normal) function pointer as callback
callback_data obj{ cb_signal, cb_handler, data };
FCallbackData obj{ cb_signal, nullptr, cb_function, data };
callback_objects.push_back(obj); callback_objects.push_back(obj);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::addCallback ( const FString& cb_signal void FWidget::addCallback ( const FString& cb_signal
, FWidget* cb_instance , FWidget* cb_instance
, FMemberCallback cb_handler , FCallback cb_function
, FDataPtr data ) , FDataPtr data )
{ {
// add a member function pointer as callback // Add a member function pointer as callback
member_callback_data obj{ cb_signal, cb_instance, cb_handler, data };
member_callback_objects.push_back(obj); FCallbackData obj{ cb_signal, cb_instance, cb_function, data };
callback_objects.push_back(obj);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::delCallback (FCallback cb_handler) void FWidget::delCallback (FCallback cb_function)
{ {
// delete a cb_handler function pointer // Delete cb_function form callback list
if ( callback_objects.empty() ) if ( callback_objects.empty() )
return; return;
@ -875,7 +865,7 @@ void FWidget::delCallback (FCallback cb_handler)
while ( iter != callback_objects.end() ) while ( iter != callback_objects.end() )
{ {
if ( iter->cb_handler == cb_handler ) if ( getCallbackPtr(iter->cb_function) == getCallbackPtr(cb_function) )
iter = callback_objects.erase(iter); iter = callback_objects.erase(iter);
else else
++iter; ++iter;
@ -885,17 +875,17 @@ void FWidget::delCallback (FCallback cb_handler)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::delCallback (FWidget* cb_instance) void FWidget::delCallback (FWidget* cb_instance)
{ {
// delete all member function pointer from cb_instance // Delete all member function pointer from cb_instance
if ( member_callback_objects.empty() ) if ( callback_objects.empty() )
return; return;
auto iter = member_callback_objects.begin(); auto iter = callback_objects.begin();
while ( iter != member_callback_objects.end() ) while ( iter != callback_objects.end() )
{ {
if ( iter->cb_instance == cb_instance ) if ( iter->cb_instance == cb_instance )
iter = member_callback_objects.erase(iter); iter = callback_objects.erase(iter);
else else
++iter; ++iter;
} }
@ -904,51 +894,26 @@ void FWidget::delCallback (FWidget* cb_instance)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::delCallbacks() void FWidget::delCallbacks()
{ {
// delete all callbacks from this widget // Delete all callbacks from this widget
member_callback_objects.clear(); // member function pointer
callback_objects.clear(); // function pointer callback_objects.clear(); // function pointer
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::emitCallback (const FString& emit_signal) void FWidget::emitCallback (const FString& emit_signal)
{ {
// member function pointer // Initiate callback for the given signal
if ( ! member_callback_objects.empty() ) if ( callback_objects.empty() )
{ return;
auto m_iter = member_callback_objects.begin();
auto m_end = member_callback_objects.end();
while ( m_iter != m_end ) for (auto&& cback : callback_objects)
{ {
if ( m_iter->cb_signal == emit_signal ) if ( cback.cb_signal == emit_signal )
{ {
auto callback = m_iter->cb_handler; // Calling the stored function pointer
// call the member function pointer auto callback = cback.cb_function;
(m_iter->cb_instance->*callback) (this, m_iter->data); callback (this, cback.data);
}
++m_iter;
}
}
// function pointer
if ( ! callback_objects.empty() )
{
auto iter = callback_objects.begin();
auto last = callback_objects.end();
while ( iter != last )
{
if ( iter->cb_signal == emit_signal )
{
auto callback = iter->cb_handler;
// call the function pointer
callback (this, iter->data);
}
++iter;
} }
} }
} }
@ -956,8 +921,10 @@ void FWidget::emitCallback (const FString& emit_signal)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::addAccelerator (FKey key, FWidget* obj) void FWidget::addAccelerator (FKey key, FWidget* obj)
{ {
// Adding a keyboard accelerator for the given widget
auto widget = static_cast<FWidget*>(FWindow::getWindowWidget(obj)); auto widget = static_cast<FWidget*>(FWindow::getWindowWidget(obj));
accelerator accel = { key, obj }; FAccelerator accel = { key, obj };
if ( ! widget || widget == statusbar || widget == menubar ) if ( ! widget || widget == statusbar || widget == menubar )
widget = getRootWidget(); widget = getRootWidget();
@ -969,6 +936,8 @@ void FWidget::addAccelerator (FKey key, FWidget* obj)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::delAccelerator (FWidget* obj) void FWidget::delAccelerator (FWidget* obj)
{ {
// Deletes all accelerators of the given widget
auto widget = static_cast<FWidget*>(FWindow::getWindowWidget(this)); auto widget = static_cast<FWidget*>(FWindow::getWindowWidget(this));
if ( ! widget || widget == statusbar || widget == menubar ) if ( ! widget || widget == statusbar || widget == menubar )
@ -993,6 +962,8 @@ void FWidget::delAccelerator (FWidget* obj)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::redraw() void FWidget::redraw()
{ {
// Redraw the widget immediately unless it is hidden.
if ( ! redraw_root_widget ) if ( ! redraw_root_widget )
redraw_root_widget = this; redraw_root_widget = this;
@ -1019,7 +990,7 @@ void FWidget::redraw()
if ( redraw_root_widget == this ) if ( redraw_root_widget == this )
{ {
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
redraw_root_widget = nullptr; redraw_root_widget = nullptr;
} }
} }
@ -1054,6 +1025,8 @@ void FWidget::resize()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::show() void FWidget::show()
{ {
// Make the widget visible and draw it
if ( ! isVisible() ) if ( ! isVisible() )
return; return;
@ -1081,20 +1054,15 @@ void FWidget::show()
if ( hasChildren() ) if ( hasChildren() )
{ {
auto iter = FObject::begin(); for (auto&& child : getChildren())
auto last = FObject::end();
while ( iter != last )
{ {
if ( (*iter)->isWidget() ) if ( child->isWidget() )
{ {
auto widget = static_cast<FWidget*>(*iter); auto widget = static_cast<FWidget*>(child);
if ( ! widget->flags.hidden ) if ( ! widget->flags.hidden )
widget->show(); widget->show();
} }
++iter;
} }
} }
@ -1102,7 +1070,7 @@ void FWidget::show()
{ {
finishTerminalUpdate(); finishTerminalUpdate();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
show_root_widget = nullptr; show_root_widget = nullptr;
} }
@ -1113,6 +1081,8 @@ void FWidget::show()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::hide() void FWidget::hide()
{ {
// Hide the widget
flags.hidden = true; flags.hidden = true;
if ( isVisible() ) if ( isVisible() )
@ -1214,22 +1184,6 @@ bool FWidget::focusLastChild()
return false; return false;
} }
//----------------------------------------------------------------------
void FWidget::detectTermSize()
{
auto r = rootObject;
FTerm::detectTermSize();
r->adjust_wsize.setRect (1, 1, getDesktopWidth(), getDesktopHeight());
r->woffset.setRect (0, 0, getDesktopWidth(), getDesktopHeight());
r->wclient_offset.setCoordinates
(
r->padding.left,
r->padding.top,
int(getDesktopWidth()) - 1 - r->padding.right,
int(getDesktopHeight()) - 1 - r->padding.bottom
);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::move (const FPoint& pos) void FWidget::move (const FPoint& pos)
{ {
@ -1237,201 +1191,6 @@ void FWidget::move (const FPoint& pos)
adjust_wsize.move(pos); adjust_wsize.move(pos);
} }
//----------------------------------------------------------------------
void FWidget::drawShadow()
{
if ( isMonochron() && ! flags.trans_shadow )
return;
if ( (getEncoding() == fc::VT100 && ! flags.trans_shadow)
|| (getEncoding() == fc::ASCII && ! flags.trans_shadow) )
{
clearShadow();
return;
}
int x1 = 1;
int x2 = int(getWidth());
int y1 = 1;
int y2 = int(getHeight());
if ( flags.trans_shadow )
{
// transparent shadow
drawTransparentShadow (x1, y1, x2, y2);
}
else
{
// non-transparent shadow
drawBlockShadow (x1, y1, x2, y2);
}
}
//----------------------------------------------------------------------
void FWidget::clearShadow()
{
if ( isMonochron() )
return;
int w = int(getWidth());
int h = int(getHeight());
if ( isWindowWidget() )
{
setColor (wcolors.shadow_fg, wcolors.shadow_bg);
setInheritBackground(); // current background color will be ignored
}
else if ( auto p = getParentWidget() )
setColor (wcolors.shadow_fg, p->getBackgroundColor());
if ( w <= woffset.getX2() )
{
for (std::size_t y{1}; y <= getHeight(); y++)
{
print() << FPoint(w + 1, int(y)) << ' '; // clear █
}
}
if ( h <= woffset.getY2() )
{
print() << FPoint(2, h + 1);
for (std::size_t i{1}; i <= getWidth(); i++)
print (' '); // clear ▀
}
if ( isWindowWidget() )
unsetInheritBackground();
}
//----------------------------------------------------------------------
void FWidget::drawFlatBorder()
{
if ( ! isNewFont() )
return;
int x1 = 1;
int x2 = int(getWidth() + 1);
int y1 = 0;
int y2 = int(getHeight() + 1);
if ( auto p = getParentWidget() )
setColor (wcolors.dialog_fg, p->getBackgroundColor());
else
setColor (wcolors.dialog_fg, wcolors.dialog_bg);
for (std::size_t y{0}; y < getHeight(); y++)
{
print() << FPoint(x1 - 1, y1 + int(y) + 1);
if ( double_flatline_mask.left[uLong(y)] )
// left+right line (on left side)
print (fc::NF_rev_border_line_right_and_left);
else
// right line (on left side)
print (fc::NF_rev_border_line_right);
}
print() << FPoint(x2, y1 + 1);
for (std::size_t y{0}; y < getHeight(); y++)
{
if ( double_flatline_mask.right[y] )
// left+right line (on right side)
print (fc::NF_rev_border_line_right_and_left);
else
// left line (on right side)
print (fc::NF_border_line_left);
print() << FPoint(x2, y1 + int(y) + 2);
}
print() << FPoint(x1, y1);
for (std::size_t x{0}; x < getWidth(); x++)
{
if ( double_flatline_mask.top[x] )
// top+bottom line (at top)
print (fc::NF_border_line_up_and_down);
else
// bottom line (at top)
print (fc::NF_border_line_bottom);
}
print() << FPoint(x1, y2);
for (std::size_t x{0}; x < getWidth(); x++)
{
if ( double_flatline_mask.bottom[x] )
// top+bottom line (at bottom)
print (fc::NF_border_line_up_and_down);
else
// top line (at bottom)
print (fc::NF_border_line_upper);
}
}
//----------------------------------------------------------------------
void FWidget::clearFlatBorder()
{
if ( ! isNewFont() )
return;
int x1 = 1;
int x2 = int(getWidth() + 1);
int y1 = 0;
int y2 = int(getHeight() + 1);
if ( auto p = getParentWidget() )
setColor (wcolors.dialog_fg, p->getBackgroundColor());
else
setColor (wcolors.dialog_fg, wcolors.dialog_bg);
// clear on left side
for (std::size_t y{0}; y < getHeight(); y++)
{
print() << FPoint(x1 - 1, y1 + int(y) + 1);
if ( double_flatline_mask.left[y] )
print (fc::NF_border_line_left);
else
print (' ');
}
// clear on right side
for (std::size_t y{0}; y < getHeight(); y++)
{
print() << FPoint(x2, y1 + int(y) + 1);
if ( double_flatline_mask.right[y] )
print (fc::NF_rev_border_line_right);
else
print (' ');
}
// clear at top
print() << FPoint(x1, y1);
for (std::size_t x{0}; x < getWidth(); x++)
{
if ( double_flatline_mask.top[x] )
print (fc::NF_border_line_upper);
else
print (' ');
}
// clear at bottom
print() << FPoint(x1, y2);
for (std::size_t x{0}; x < getWidth(); x++)
{
if ( double_flatline_mask.bottom[x] )
print (fc::NF_border_line_bottom);
else
print (' ');
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::quit() void FWidget::quit()
{ {
@ -1442,7 +1201,7 @@ void FWidget::quit()
// protected methods of FWidget // protected methods of FWidget
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FVTerm::term_area* FWidget::getPrintArea() FVTerm::FTermArea* FWidget::getPrintArea()
{ {
// returns the print area of this object // returns the print area of this object
@ -1477,12 +1236,12 @@ FVTerm::term_area* FWidget::getPrintArea()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::addPreprocessingHandler ( FVTerm* instance void FWidget::addPreprocessingHandler ( FVTerm* instance
, FPreprocessingHandler handler ) , FPreprocessingFunction function )
{ {
if ( ! getCurrentPrintArea() ) if ( ! getCurrentPrintArea() )
FWidget::getPrintArea(); FWidget::getPrintArea();
FVTerm::addPreprocessingHandler (instance, handler); FVTerm::addPreprocessingHandler (instance, function);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1572,19 +1331,15 @@ void FWidget::adjustSize()
if ( hasChildren() ) if ( hasChildren() )
{ {
auto iter = FObject::begin(); for (auto&& child : getChildren())
auto last = FObject::end();
while ( iter != last )
{ {
if ( (*iter)->isWidget() ) if ( child->isWidget() )
{ {
auto widget = static_cast<FWidget*>(*iter); auto widget = static_cast<FWidget*>(child);
if ( ! widget->isWindowWidget() ) if ( ! widget->isWindowWidget() )
widget->adjustSize(); widget->adjustSize();
} }
++iter;
} }
} }
} }
@ -1626,18 +1381,16 @@ void FWidget::hideArea (const FSize& size)
} }
setColor (fg, bg); setColor (fg, bg);
char* blank = createBlankArray(size.getWidth());
if ( blank == 0 ) if ( size.getWidth() == 0 )
return; return;
for (int y{0}; y < int(size.getHeight()); y++) for (int y{0}; y < int(size.getHeight()); y++)
{ {
print() << FPoint(1, 1 + y) << blank; print() << FPoint(1, 1 + y) << FString(size.getWidth(), L' ');
} }
destroyBlankArray (blank); flushOutputBuffer();
flush_out();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1647,7 +1400,7 @@ void FWidget::createWidgetAcceleratorList()
{ {
try try
{ {
accelerator_list = new Accelerators(); accelerator_list = new FAcceleratorList();
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc& ex)
{ {
@ -1948,10 +1701,10 @@ void FWidget::init()
try try
{ {
// Initialize widget lists // Initialize widget lists
window_list = new widgetList(); window_list = new FWidgetList();
dialog_list = new widgetList(); dialog_list = new FWidgetList();
always_on_top_list = new widgetList(); always_on_top_list = new FWidgetList();
close_widget = new widgetList(); close_widget = new FWidgetList();
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc& ex)
{ {
@ -2118,6 +1871,12 @@ void FWidget::KeyDownEvent (FKeyEvent* kev)
} }
} }
//----------------------------------------------------------------------
FWidget::FCallbackPtr FWidget::getCallbackPtr (FCallback cb_function)
{
return *cb_function.template target<FCallbackPtr>();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWidget::changeFocus ( FWidget* follower, FWidget* parent bool FWidget::changeFocus ( FWidget* follower, FWidget* parent
, fc::FocusTypes ft ) , fc::FocusTypes ft )
@ -2152,7 +1911,7 @@ bool FWidget::changeFocus ( FWidget* follower, FWidget* parent
redraw(); redraw();
follower->redraw(); follower->redraw();
updateTerminal(); updateTerminal();
flush_out(); flushOutputBuffer();
} }
} }
@ -2167,8 +1926,8 @@ void FWidget::draw()
void FWidget::drawWindows() void FWidget::drawWindows()
{ {
// redraw windows // redraw windows
charData default_char{}; FChar default_char{};
default_char.code = ' '; default_char.ch = ' ';
default_char.fg_color = fc::Black; default_char.fg_color = fc::Black;
default_char.bg_color = fc::Black; default_char.bg_color = fc::Black;
default_char.attr.byte[0] = 0; default_char.attr.byte[0] = 0;
@ -2177,22 +1936,16 @@ void FWidget::drawWindows()
if ( ! window_list || window_list->empty() ) if ( ! window_list || window_list->empty() )
return; return;
auto iter = window_list->begin(); for (auto&& window : *window_list)
auto last = window_list->end();
while ( iter != last )
{ {
if ( (*iter)->isShown() ) if ( window->isShown() )
{ {
auto win = (*iter)->getVWin(); auto v_win = window->getVWin();
int w = win->width + win->right_shadow; int w = v_win->width + v_win->right_shadow;
int h = win->height + win->bottom_shadow; int h = v_win->height + v_win->bottom_shadow;
std::fill_n (win->text, w * h, default_char); std::fill_n (v_win->data, w * h, default_char);
window->redraw();
(*iter)->redraw();
} }
++iter;
} }
} }
@ -2203,99 +1956,18 @@ void FWidget::drawChildren()
if ( ! hasChildren() ) if ( ! hasChildren() )
return; return;
auto iter = FObject::begin(); for (auto&& child : getChildren())
auto last = FObject::end();
while ( iter != last )
{ {
if ( (*iter)->isWidget() ) if ( child->isWidget() )
{ {
auto widget = static_cast<FWidget*>(*iter); auto widget = static_cast<FWidget*>(child);
if ( widget->isShown() && ! widget->isWindowWidget() ) if ( widget->isShown() && ! widget->isWindowWidget() )
widget->redraw(); widget->redraw();
} }
++iter;
} }
} }
//----------------------------------------------------------------------
void FWidget::drawTransparentShadow (int x1, int y1, int x2, int y2)
{
// transparent shadow
setTransparent();
print() << FPoint(x2 + 1, y1) << " ";
unsetTransparent();
setColor (wcolors.shadow_bg, wcolors.shadow_fg);
setTransShadow();
for (std::size_t y{1}; y < getHeight(); y++)
{
print() << FPoint(x2 + 1, y1 + int(y)) << " ";
}
unsetTransShadow();
setTransparent();
print() << FPoint(x1, y2 + 1) << " ";
unsetTransparent();
setColor (wcolors.shadow_bg, wcolors.shadow_fg);
setTransShadow();
for (std::size_t x{2}; x <= getWidth() + 1; x++)
print (' ');
unsetTransShadow();
if ( isMonochron() )
setReverse(false);
}
//----------------------------------------------------------------------
void FWidget::drawBlockShadow (int x1, int y1, int x2, int y2)
{
// non-transparent shadow
wchar_t block;
if ( ! hasShadowCharacter() )
return;
print() << FPoint(x2 + 1, y1);
if ( isWindowWidget() )
{
setColor (wcolors.shadow_fg, wcolors.shadow_bg);
setInheritBackground(); // current background color will be ignored
}
else if ( auto p = getParentWidget() )
setColor (wcolors.shadow_fg, p->getBackgroundColor());
block = fc::FullBlock; // █
print (fc::LowerHalfBlock); // ▄
if ( isWindowWidget() )
unsetInheritBackground();
for (std::size_t y{1}; y < getHeight(); y++)
{
print() << FPoint(x2 + 1, y1 + int(y)) << block; // █
}
print() << FPoint(x1 + 1, y2 + 1);
if ( isWindowWidget() )
setInheritBackground();
for (std::size_t x{1}; x <= getWidth(); x++)
print (fc::UpperHalfBlock); // ▀
if ( isWindowWidget() )
unsetInheritBackground();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::setColorTheme() void FWidget::setColorTheme()
{ {
@ -2310,163 +1982,19 @@ void FWidget::setColorTheme()
// non-member functions // non-member functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
char* createBlankArray (std::size_t size) void detectTermSize()
{ {
char* blank; auto r = rootObject;
FTerm::detectTermSize();
if ( size == 0 ) r->adjust_wsize.setRect (1, 1, r->getDesktopWidth(), r->getDesktopHeight());
return 0; r->woffset.setRect (0, 0, r->getDesktopWidth(), r->getDesktopHeight());
r->wclient_offset.setCoordinates
try (
{ r->padding.left,
blank = new char[size + 1]; r->padding.top,
} int(r->getDesktopWidth()) - 1 - r->padding.right,
catch (const std::bad_alloc& ex) int(r->getDesktopHeight()) - 1 - r->padding.bottom
{ );
std::cerr << bad_alloc_str << ex.what() << std::endl;
return 0;
}
std::memset(blank, ' ', size);
blank[size] = '\0';
return blank;
}
//----------------------------------------------------------------------
void destroyBlankArray (char blank[])
{
delete[] blank;
}
//----------------------------------------------------------------------
FKey getHotkey (const FString& text)
{
if ( text.isEmpty() )
return 0;
std::size_t length = text.getLength();
for (std::size_t i{0}; i < length; i++)
{
try
{
if ( i + 1 < length && text[i] == '&' )
return FKey(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;
}
}
return 0;
}
//----------------------------------------------------------------------
std::size_t getHotkeyPos (wchar_t src[], wchar_t dest[], std::size_t length)
{
// Find hotkey position in string
// + generate a new string without the '&'-sign
const wchar_t* txt = src;
constexpr std::size_t NOT_SET = static_cast<std::size_t>(-1);
std::size_t hotkeypos{NOT_SET};
for (std::size_t i{0}; i < length; i++)
{
if ( txt[i] == L'&' && hotkeypos == NOT_SET )
{
hotkeypos = i;
i++;
src++;
}
*dest++ = *src++;
}
return hotkeypos;
}
//----------------------------------------------------------------------
inline void drawBox (FWidget* w, const FRect& r)
{
// Use box-drawing characters to draw a border
w->print() << r.getUpperLeftPos() << fc::BoxDrawingsDownAndRight; // ┌
for (int x = r.getX1() + 1; x < r.getX2(); x++)
w->print (fc::BoxDrawingsHorizontal); // ─
w->print (fc::BoxDrawingsDownAndLeft); // ┐
for (int y = r.getY1() + 1; y < r.getY2(); y++)
{
w->print() << FPoint(r.getX1(), y)
<< fc::BoxDrawingsVertical // │
<< FPoint(r.getX2(), y)
<< fc::BoxDrawingsVertical; // │
}
w->print() << r.getLowerLeftPos() << fc::BoxDrawingsUpAndRight; // └
for (int x = r.getX1() + 1; x < r.getX2(); x++)
w->print (fc::BoxDrawingsHorizontal); // ─
w->print (fc::BoxDrawingsUpAndLeft); // ┘
}
//----------------------------------------------------------------------
inline void drawNewFontBox (FWidget* w, const FRect& r)
{
// Use new graphical font characters to draw a border
w->print() << r.getUpperLeftPos()
<< fc::NF_border_corner_middle_upper_left; // ┌
for (int x = r.getX1() + 1; x < r.getX2(); x++)
w->print (fc::BoxDrawingsHorizontal); // ─
w->print (fc::NF_border_corner_middle_upper_right); // ┐
for (int y = r.getY1() + 1; y < r.getY2(); y++)
{
w->print() << FPoint(r.getX1(), y)
<< fc::NF_border_line_left // border left ⎸
<< FPoint(r.getX2(), y)
<< fc::NF_rev_border_line_right; // border right⎹
}
w->print() << r.getLowerLeftPos()
<< fc::NF_border_corner_middle_lower_left; // └
for (int x = r.getX1() + 1; x < r.getX2(); x++)
w->print (fc::BoxDrawingsHorizontal); // ─
w->print (fc::NF_border_corner_middle_lower_right); // ┘
}
//----------------------------------------------------------------------
void drawBorder (FWidget* w, FRect r)
{
if ( r.x1_ref() > r.x2_ref() )
std::swap (r.x1_ref(), r.x2_ref());
if ( r.y1_ref() > r.y2_ref() )
std::swap (r.y1_ref(), r.y2_ref());
if ( r.x1_ref() < 1 )
r.x1_ref() = 1;
if ( r.y1_ref() < 1 )
r.y1_ref() = 1;
if ( r.x2_ref() > int(w->getWidth()) )
r.x2_ref() = int(w->getWidth());
if ( r.y2_ref() > int(w->getHeight()) )
r.y2_ref() = int(w->getHeight());
if ( w->isNewFont() )
drawNewFontBox (w, r);
else
drawBox (w, r);
} }
} // namespace finalcut } // namespace finalcut

428
src/fwidget_functions.cpp Normal file
View File

@ -0,0 +1,428 @@
/***********************************************************************
* fwidget_functions.cpp - FWidget helper functions *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include "final/fwidget.h"
#include "final/fwidgetcolors.h"
namespace finalcut
{
// FWidget non-member functions
//----------------------------------------------------------------------
FKey getHotkey (const FString& text)
{
// Returns the hotkey character from a string
// e.g. "E&xit" returns 'x'
if ( text.isEmpty() )
return 0;
std::size_t length = text.getLength();
for (std::size_t i{0}; i < length; i++)
{
try
{
if ( i + 1 < length && text[i] == '&' )
return FKey(text[++i]);
}
catch (const std::out_of_range&)
{
return 0;
}
}
return 0;
}
//----------------------------------------------------------------------
std::size_t getHotkeyPos (const FString& src, FString& dest)
{
// Find hotkey position in string
// + generate a new string without the '&'-sign
constexpr std::size_t NOT_SET = static_cast<std::size_t>(-1);
std::size_t hotkeypos{NOT_SET};
std::size_t i{0};
for (auto&& ch : src)
{
if ( ch == L'&' && hotkeypos == NOT_SET && src.getLength() != i + 1 )
hotkeypos = i;
else
dest += ch;
i++;
}
return hotkeypos;
}
//----------------------------------------------------------------------
void setHotkeyViaString (FWidget* w, const FString& text)
{
// Set hotkey accelerator via string
if ( ! w )
return;
FKey hotkey = getHotkey(text);
if ( hotkey > 0xff00 && hotkey < 0xff5f ) // full-width character
hotkey -= 0xfee0;
if ( hotkey )
{
if ( std::isalpha(int(hotkey)) || std::isdigit(int(hotkey)) )
{
w->addAccelerator (FKey(std::tolower(int(hotkey))));
w->addAccelerator (FKey(std::toupper(int(hotkey))));
// Meta + hotkey
w->addAccelerator (fc::Fmkey_meta + FKey(std::tolower(int(hotkey))));
}
else
w->addAccelerator (hotkey);
}
else
w->delAccelerator();
}
//----------------------------------------------------------------------
void drawShadow (FWidget* w)
{
if ( w->isMonochron() && ! w->flags.trans_shadow )
return;
if ( (w->getEncoding() == fc::VT100 && ! w->flags.trans_shadow)
|| (w->getEncoding() == fc::ASCII && ! w->flags.trans_shadow) )
{
clearShadow(w);
return;
}
if ( w->flags.trans_shadow )
drawTransparentShadow (w); // transparent shadow
else
drawBlockShadow (w); // non-transparent shadow
}
//----------------------------------------------------------------------
void drawTransparentShadow (FWidget* w)
{
// transparent shadow
std::size_t width = w->getWidth();
std::size_t height = w->getHeight();
w->setTransparent();
w->print() << FPoint(int(width) + 1, 1) << " ";
w->unsetTransparent();
w->setColor (w->wcolors.shadow_bg, w->wcolors.shadow_fg);
w->setTransShadow();
for (std::size_t y{1}; y < height; y++)
{
w->print() << FPoint(int(width) + 1, int(y) + 1) << " ";
}
w->unsetTransShadow();
w->setTransparent();
w->print() << FPoint(1, int(height) + 1) << " ";
w->unsetTransparent();
w->setColor (w->wcolors.shadow_bg, w->wcolors.shadow_fg);
w->setTransShadow();
w->print() << FString(width, L' ');
w->unsetTransShadow();
if ( w->isMonochron() )
w->setReverse(false);
}
//----------------------------------------------------------------------
void drawBlockShadow (FWidget* w)
{
// non-transparent shadow
if ( ! w->hasShadowCharacter() )
return;
std::size_t width = w->getWidth();
std::size_t height = w->getHeight();
w->print() << FPoint(int(width) + 1, 1);
if ( w->isWindowWidget() )
{
w->setColor (w->wcolors.shadow_fg, w->wcolors.shadow_bg);
w->setInheritBackground(); // current background color will be ignored
}
else if ( auto p = w->getParentWidget() )
w->setColor (w->wcolors.shadow_fg, p->getBackgroundColor());
w->print (fc::LowerHalfBlock); // ▄
if ( w->isWindowWidget() )
w->unsetInheritBackground();
for (std::size_t y{1}; y < height; y++)
{
w->print() << FPoint(int(width) + 1, int(y) + 1) << fc::FullBlock; // █
}
w->print() << FPoint(2, int(height) + 1);
if ( w->isWindowWidget() )
w->setInheritBackground();
w->print() << FString(width, fc::UpperHalfBlock); // ▀
if ( w->isWindowWidget() )
w->unsetInheritBackground();
}
//----------------------------------------------------------------------
void clearShadow (FWidget* w)
{
if ( w->isMonochron() )
return;
std::size_t width = w->getWidth();
std::size_t height = w->getHeight();
if ( w->isWindowWidget() )
{
w->setColor (w->wcolors.shadow_fg, w->wcolors.shadow_bg);
w->setInheritBackground(); // current background color will be ignored
}
else if ( auto p = w->getParentWidget() )
w->setColor (w->wcolors.shadow_fg, p->getBackgroundColor());
if ( int(width) <= w->woffset.getX2() )
{
for (std::size_t y{1}; y <= height; y++)
{
w->print() << FPoint(int(width) + 1, int(y)) << ' '; // clear █
}
}
if ( int(height) <= w->woffset.getY2() )
{
w->print() << FPoint(2, int(height) + 1)
<< FString(width, L' '); // clear ▀
}
if ( w->isWindowWidget() )
w->unsetInheritBackground();
}
//----------------------------------------------------------------------
void drawFlatBorder (FWidget* w)
{
if ( ! w->isNewFont() )
return;
if ( auto p = w->getParentWidget() )
w->setColor (w->wcolors.dialog_fg, p->getBackgroundColor());
else
w->setColor (w->wcolors.dialog_fg, w->wcolors.dialog_bg);
std::size_t width = w->getWidth();
std::size_t height = w->getHeight();
for (std::size_t y{0}; y < height; y++)
{
w->print() << FPoint(0, int(y) + 1);
if ( w->double_flatline_mask.left[uLong(y)] )
// left+right line (on left side)
w->print (fc::NF_rev_border_line_right_and_left);
else
// right line (on left side)
w->print (fc::NF_rev_border_line_right);
w->print() << FPoint(int(width) + 1, int(y) + 1);
if ( w->double_flatline_mask.right[y] )
// left+right line (on right side)
w->print (fc::NF_rev_border_line_right_and_left);
else
// left line (on right side)
w->print (fc::NF_border_line_left);
}
w->print() << FPoint(1, 0);
for (std::size_t x{0}; x < width; x++)
{
if ( w->double_flatline_mask.top[x] )
// top+bottom line (at top)
w->print (fc::NF_border_line_up_and_down);
else
// bottom line (at top)
w->print (fc::NF_border_line_bottom);
}
w->print() << FPoint(1, int(height) + 1);
for (std::size_t x{0}; x < width; x++)
{
if ( w->double_flatline_mask.bottom[x] )
// top+bottom line (at bottom)
w->print (fc::NF_border_line_up_and_down);
else
// top line (at bottom)
w->print (fc::NF_border_line_upper);
}
}
//----------------------------------------------------------------------
void clearFlatBorder (FWidget* w)
{
if ( ! w->isNewFont() )
return;
if ( auto p = w->getParentWidget() )
w->setColor (w->wcolors.dialog_fg, p->getBackgroundColor());
else
w->setColor (w->wcolors.dialog_fg, w->wcolors.dialog_bg);
std::size_t width = w->getWidth();
std::size_t height = w->getHeight();
for (std::size_t y{0}; y < height; y++)
{
// clear on left side
w->print() << FPoint(0, int(y) + 1);
if ( w->double_flatline_mask.left[y] )
w->print (fc::NF_border_line_left);
else
w->print (' ');
// clear on right side
w->print() << FPoint(int(width) + 1, int(y) + 1);
if ( w->double_flatline_mask.right[y] )
w->print (fc::NF_rev_border_line_right);
else
w->print (' ');
}
// clear at top
w->print() << FPoint(1, 0);
for (std::size_t x{0}; x < width; x++)
{
if ( w->double_flatline_mask.top[x] )
w->print (fc::NF_border_line_upper);
else
w->print (' ');
}
// clear at bottom
w->print() << FPoint(1, int(height) + 1);
for (std::size_t x{0}; x < width; x++)
{
if ( w->double_flatline_mask.bottom[x] )
w->print (fc::NF_border_line_bottom);
else
w->print (' ');
}
}
//----------------------------------------------------------------------
void drawBorder (FWidget* w, FRect r)
{
if ( r.x1_ref() > r.x2_ref() )
std::swap (r.x1_ref(), r.x2_ref());
if ( r.y1_ref() > r.y2_ref() )
std::swap (r.y1_ref(), r.y2_ref());
if ( r.x1_ref() < 1 )
r.x1_ref() = 1;
if ( r.y1_ref() < 1 )
r.y1_ref() = 1;
if ( r.x2_ref() > int(w->getWidth()) )
r.x2_ref() = int(w->getWidth());
if ( r.y2_ref() > int(w->getHeight()) )
r.y2_ref() = int(w->getHeight());
if ( w->isNewFont() )
drawNewFontBox (w, r);
else
drawBox (w, r);
}
//----------------------------------------------------------------------
inline void drawBox (FWidget* w, const FRect& r)
{
// Use box-drawing characters to draw a border
if ( ! w )
return;
w->print() << r.getUpperLeftPos()
<< fc::BoxDrawingsDownAndRight // ┌
<< FString(r.getWidth() - 2, fc::BoxDrawingsHorizontal) // ─
<< fc::BoxDrawingsDownAndLeft; // ┐
for (int y = r.getY1() + 1; y < r.getY2(); y++)
{
w->print() << FPoint(r.getX1(), y)
<< fc::BoxDrawingsVertical // │
<< FPoint(r.getX2(), y)
<< fc::BoxDrawingsVertical; // │
}
w->print() << r.getLowerLeftPos()
<< fc::BoxDrawingsUpAndRight // └
<< FString(r.getWidth() - 2, fc::BoxDrawingsHorizontal) // ─
<< fc::BoxDrawingsUpAndLeft; // ┘
}
//----------------------------------------------------------------------
inline void drawNewFontBox (FWidget* w, const FRect& r)
{
// Use new graphical font characters to draw a border
w->print() << r.getUpperLeftPos()
<< fc::NF_border_corner_middle_upper_left // ┌
<< FString(r.getWidth() - 2, fc::BoxDrawingsHorizontal) // ─
<< fc::NF_border_corner_middle_upper_right; // ┐
for (int y = r.getY1() + 1; y < r.getY2(); y++)
{
w->print() << FPoint(r.getX1(), y)
<< fc::NF_border_line_left // border left ⎸
<< FPoint(r.getX2(), y)
<< fc::NF_rev_border_line_right; // border right⎹
}
w->print() << r.getLowerLeftPos()
<< fc::NF_border_corner_middle_lower_left // └
<< FString(r.getWidth() - 2, fc::BoxDrawingsHorizontal) // ─
<< fc::NF_border_corner_middle_lower_right; // ┘
}
} // namespace finalcut

View File

@ -48,7 +48,7 @@ void FWidgetColors::set8ColorTheme()
error_box_fg = fc::Black; error_box_fg = fc::Black;
error_box_emphasis_fg = fc::Red; error_box_emphasis_fg = fc::Red;
error_box_bg = fc::LightGray; error_box_bg = fc::LightGray;
tooltip_fg = fc::LightGray; tooltip_fg = fc::Black;
tooltip_bg = fc::Cyan; tooltip_bg = fc::Cyan;
shadow_fg = fc::Black; shadow_fg = fc::Black;
shadow_bg = fc::LightGray; // only for transparent shadow shadow_bg = fc::LightGray; // only for transparent shadow
@ -75,8 +75,8 @@ void FWidgetColors::set8ColorTheme()
inputfield_active_bg = fc::Cyan; inputfield_active_bg = fc::Cyan;
inputfield_inactive_fg = fc::Black; inputfield_inactive_fg = fc::Black;
inputfield_inactive_bg = fc::LightGray; inputfield_inactive_bg = fc::LightGray;
toggle_button_active_focus_fg = fc::LightGray; toggle_button_active_focus_fg = fc::Black;
toggle_button_active_focus_bg = fc::Red; toggle_button_active_focus_bg = fc::Cyan;
toggle_button_active_fg = fc::Black; toggle_button_active_fg = fc::Black;
toggle_button_active_bg = fc::LightGray; toggle_button_active_bg = fc::LightGray;
toggle_button_inactive_fg = fc::Cyan; toggle_button_inactive_fg = fc::Cyan;

View File

@ -107,18 +107,12 @@ void FWindow::setActiveWindow (FWindow* window)
{ {
// activate FWindow object window // activate FWindow object window
if ( ! getWindowList() ) if ( ! getWindowList() || getWindowList()->empty() )
return; return;
if ( getWindowList()->empty() ) for (auto&& win : *getWindowList())
return;
auto iter = getWindowList()->begin();
auto end = getWindowList()->end();
while ( iter != end )
{ {
if ( *iter == window ) if ( win == window )
{ {
if ( ! window->isWindowActive() ) if ( ! window->isWindowActive() )
{ {
@ -129,17 +123,15 @@ void FWindow::setActiveWindow (FWindow* window)
} }
else else
{ {
auto w = static_cast<FWindow*>(*iter); auto w = static_cast<FWindow*>(win);
if ( w->isWindowActive() ) if ( w->isWindowActive() )
{ {
w->deactivateWindow(); w->deactivateWindow();
FEvent ev(fc::WindowInactive_Event); FEvent ev(fc::WindowInactive_Event);
FApplication::sendEvent(*iter, &ev); FApplication::sendEvent(win, &ev);
} }
} }
++iter;
} }
} }
@ -251,11 +243,9 @@ void FWindow::drawBorder()
{ {
FRect r(FPoint(1, 1), getSize()); FRect r(FPoint(1, 1), getSize());
print() << r.getUpperLeftPos() print() << r.getUpperLeftPos()
<< fc::NF_border_corner_upper_left; // ⎡ << fc::NF_border_corner_upper_left // ⎡
for (int x = r.getX1() + 1; x < r.getX2(); x++) << FString(r.getWidth() - 2, fc::NF_border_line_upper) // ¯
print (fc::NF_border_line_upper); // ¯ << fc::NF_rev_border_corner_upper_right; // ⎤
print (fc::NF_rev_border_corner_upper_right); // ⎤
for (int y = r.getY1() + 1; y < r.getY2(); y++) for (int y = r.getY1() + 1; y < r.getY2(); y++)
{ {
@ -265,14 +255,10 @@ void FWindow::drawBorder()
<< fc::NF_rev_border_line_right; // border right⎹ << fc::NF_rev_border_line_right; // border right⎹
} }
print() << r.getLowerLeftPos() // lower left corner border ⎣ print() << r.getLowerLeftPos()
<< fc::NF_border_corner_lower_left; << fc::NF_border_corner_lower_left // ⎣
<< FString(r.getWidth() - 2, fc::NF_border_line_bottom) // _
for (int x = r.getX1() + 1; x < r.getX2(); x++) << fc::NF_rev_border_corner_lower_right; // ⎦
print (fc::NF_border_line_bottom); // low line _
// lower right corner border ⎦
print (fc::NF_rev_border_corner_lower_right);
} }
else else
{ {
@ -478,7 +464,7 @@ void FWindow::delWindow (FWidget* obj)
{ {
if ( (*iter) == obj ) if ( (*iter) == obj )
{ {
getWindowList()->erase (iter); getWindowList()->erase(iter);
return; return;
} }

View File

@ -107,7 +107,7 @@ class FApplication : public FWidget
FApplication& operator = (const FApplication&) = delete; FApplication& operator = (const FApplication&) = delete;
// Accessors // Accessors
const char* getClassName() const override; const FString getClassName() const override;
int getArgc() const; int getArgc() const;
char** getArgv() const; char** getArgv() const;
static FApplication* getApplicationObject(); static FApplication* getApplicationObject();
@ -117,8 +117,8 @@ class FApplication : public FWidget
// Methods // Methods
int exec(); // run int exec(); // run
int enter_loop(); int enterLoop();
void exit_loop(); void exitLoop();
static void exit (int = 0); static void exit (int = 0);
void quit(); void quit();
static bool sendEvent (const FObject*, const FEvent*); static bool sendEvent (const FObject*, const FEvent*);
@ -203,7 +203,7 @@ class FApplication : public FWidget
// FApplication inline functions // FApplication inline functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FApplication::getClassName() const inline const FString FApplication::getClassName() const
{ return "FApplication"; } { return "FApplication"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -82,7 +82,7 @@ class FButton : public FWidget
FButton& operator = (const FString&); FButton& operator = (const FString&);
// Accessors // Accessors
const char* getClassName() const override; const FString getClassName() const override;
FString& getText(); FString& getText();
// Mutators // Mutators
@ -149,7 +149,7 @@ class FButton : public FWidget
void drawMarginLeft(); void drawMarginLeft();
void drawMarginRight(); void drawMarginRight();
void drawTopBottomBackground(); void drawTopBottomBackground();
void drawButtonTextLine (wchar_t[]); void drawButtonTextLine (const FString&);
void draw() override; void draw() override;
void updateStatusBar(); void updateStatusBar();
void updateButtonColor(); void updateButtonColor();
@ -178,7 +178,7 @@ class FButton : public FWidget
// FButton inline functions // FButton inline functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FButton::getClassName() const inline const FString FButton::getClassName() const
{ return "FButton"; } { return "FButton"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -83,7 +83,7 @@ class FButtonGroup : public FScrollView
FButtonGroup& operator = (const FButtonGroup&) = delete; FButtonGroup& operator = (const FButtonGroup&) = delete;
// Accessor // Accessor
const char* getClassName() const override; const FString getClassName() const override;
FToggleButton* getFirstButton(); FToggleButton* getFirstButton();
FToggleButton* getLastButton(); FToggleButton* getLastButton();
FToggleButton* getButton (int) const; FToggleButton* getButton (int) const;
@ -131,7 +131,7 @@ class FButtonGroup : public FScrollView
// Methods // Methods
void init(); void init();
void drawText (wchar_t[], std::size_t, std::size_t); void drawText (const FString&, std::size_t);
void directFocus(); void directFocus();
// Callback method // Callback method
@ -144,7 +144,7 @@ class FButtonGroup : public FScrollView
// FButtonGroup inline functions // FButtonGroup inline functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FButtonGroup::getClassName() const inline const FString FButtonGroup::getClassName() const
{ return "FButtonGroup"; } { return "FButtonGroup"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -42,10 +42,10 @@ extern const std::size_t lastCharItem;
extern int vt100_key_to_utf8[][2]; extern int vt100_key_to_utf8[][2];
extern const std::size_t lastKeyItem; extern const std::size_t lastKeyItem;
extern wchar_t cp437_to_ucs[][2]; extern wchar_t cp437_ucs[][2];
extern const std::size_t lastCP437Item; extern const std::size_t lastCP437Item;
extern wchar_t halfWidth_fullWidth[][2]; extern const wchar_t halfWidth_fullWidth[][2];
extern const std::size_t lastHalfWidthItem; extern const std::size_t lastHalfWidthItem;
} // namespace fc } // namespace fc

View File

@ -83,7 +83,7 @@ class FCheckBox : public FToggleButton
FCheckBox& operator = (const FCheckBox&) = delete; FCheckBox& operator = (const FCheckBox&) = delete;
// Accessor // Accessor
const char* getClassName() const override; const FString getClassName() const override;
private: private:
// Methods // Methods
@ -96,7 +96,7 @@ class FCheckBox : public FToggleButton
// FCheckBox inline functions // FCheckBox inline functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FCheckBox::getClassName() const inline const FString FCheckBox::getClassName() const
{ return "FCheckBox"; } { return "FCheckBox"; }
} // namespace finalcut } // namespace finalcut

View File

@ -83,7 +83,7 @@ class FCheckMenuItem : public FMenuItem
FCheckMenuItem& operator = (const FCheckMenuItem&) = delete; FCheckMenuItem& operator = (const FCheckMenuItem&) = delete;
// Accessor // Accessor
const char* getClassName() const override; const FString getClassName() const override;
private: private:
// Methods // Methods
@ -94,7 +94,7 @@ class FCheckMenuItem : public FMenuItem
// FCheckMenuItem inline functions // FCheckMenuItem inline functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const char* FCheckMenuItem::getClassName() const inline const FString FCheckMenuItem::getClassName() const
{ return "FCheckMenuItem"; } { return "FCheckMenuItem"; }
} // namespace finalcut } // namespace finalcut

Some files were not shown because too many files have changed in this diff Show More