Merge pull request #58 from gansm/master

merge
This commit is contained in:
Markus Gans 2020-06-03 21:29:52 +02:00 committed by GitHub
commit cd5f7ae16e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
133 changed files with 4750 additions and 2058 deletions

15
.codacy.yml Normal file
View File

@ -0,0 +1,15 @@
---
engines:
duplication:
enabled: true
exclude_paths:
- 'fonts/**'
- 'test/**'
exclude_paths:
- 'debian/**'
- 'doc/**'
- 'icon/**'
- 'logo/**'
- 'm4/**'
- 'scripts/**'

1
.gitignore vendored
View File

@ -38,6 +38,7 @@ examples/.deps/
examples/.libs/ examples/.libs/
examples/calculator examples/calculator
examples/dialog examples/dialog
examples/event-log
examples/string-operations examples/string-operations
examples/background-color examples/background-color
examples/opti-move examples/opti-move

View File

@ -75,12 +75,12 @@ matrix:
- whoami - whoami
- echo -n | openssl s_client -CApath /etc/ssl/certs/ -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt - echo -n | openssl s_client -CApath /etc/ssl/certs/ -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt
script: script:
- cat /home/travis/build/gansm/finalcut/cov-int/scm_log.txt - cat /home/travis/build/gansm/finalcut/cov-int/scm_log.txt || echo
- autoreconf -v --install --force - autoreconf -v --install --force
- ./configure --prefix=/usr CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -DUNIT_TEST" --with-unit-test - ./configure --prefix=/usr CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -DUNIT_TEST" --with-unit-test
- make V=1 -j10 - make V=1 -j10
- make check - make check
- cat test/*.log - cat test/*.log || echo
# #
# Coveralls + Codecov # Coveralls + Codecov

View File

@ -1,3 +1,38 @@
2020-05-30 Markus Gans <guru.mail@muenster.de>
* With the two new methods FApplication::setDarkTheme() and
FApplication::setDefaultTheme() you can now change the theme
within an application. An example can be found in examples/ui
via the menu items "View" -> "Dark mode".
2020-05-29 Markus Gans <guru.mail@muenster.de>
* Adding a dark theme. Can be activated with the --dark-theme parameter.
2020-05-28 Markus Gans <guru.mail@muenster.de>
* FColorPalette now also uses polymorphism, so you can now
easily create your own color palette theme
2020-05-26 Markus Gans <guru.mail@muenster.de>
* FWidgetColors now uses polymorphism, so you can now easily
create your own widget color theme
* FApplication has got the new virtual method processExternalUserEvent()
for user code
2020-05-24 Markus Gans <guru.mail@muenster.de>
* New class FStringStream implements input and output operations
on FString based streams
* Fixed memory leak in FString move assignment operator
2020-05-21 Markus Gans <guru.mail@muenster.de>
* Fixed the event queue in FApplication
2020-05-16 Markus Gans <guru.mail@muenster.de>
* More direct access to the static FTerm functions
2020-05-13 Markus Gans <guru.mail@muenster.de>
* The new class FLogger for logging, which can be redirected
to different I/O channels
* Adding the event-log example to show the logging functionality
2020-05-02 Markus Gans <guru.mail@muenster.de> 2020-05-02 Markus Gans <guru.mail@muenster.de>
* Transfer of all termcap functions into the FTermcap class * Transfer of all termcap functions into the FTermcap class

View File

@ -69,8 +69,8 @@ int main (int argc, char* argv[])
finalcut::FApplication app(argc, argv); finalcut::FApplication app(argc, argv);
finalcut::FDialog dialog(&app); finalcut::FDialog dialog(&app);
dialog.setText ("A dialog"); dialog.setText ("A dialog");
const finalcut::FPoint position(25, 5); const finalcut::FPoint position{25, 5};
const finalcut::FSize size(30, 10); const finalcut::FSize size{30, 10};
dialog.setGeometry (position, size); dialog.setGeometry (position, size);
finalcut::FWidget::setMainWidget(&dialog); finalcut::FWidget::setMainWidget(&dialog);
dialog.show(); dialog.show();
@ -126,8 +126,8 @@ dialog.setText ("A dialog");
The title bar of the dialog box gets the text "A dialog". The title bar of the dialog box gets the text "A dialog".
```cpp ```cpp
finalcut::FPoint position(25, 5); finalcut::FPoint position{25, 5};
finalcut::FSize size(30, 10); finalcut::FSize size{30, 10};
dialog.setGeometry (position, size); dialog.setGeometry (position, size);
``` ```
The dialog window gets a width of 30 and a height of 10 characters. The dialog window gets a width of 30 and a height of 10 characters.
@ -206,11 +206,11 @@ int main (int argc, char* argv[])
// The object dialog is managed by app // The object dialog is managed by app
FDialog* dialog = new FDialog(&app); FDialog* dialog = new FDialog(&app);
dialog->setText ("Window Title"); dialog->setText ("Window Title");
dialog->setGeometry (FPoint(25, 5), FSize(40, 8)); dialog->setGeometry (FPoint{25, 5}, FSize{40, 8});
// The object input is managed by dialog // The object input is managed by dialog
FLineEdit* input = new FLineEdit("predefined text", dialog); FLineEdit* input = new FLineEdit("predefined text", dialog);
input->setGeometry(FPoint(8, 2), FSize(29, 1)); input->setGeometry(FPoint{8, 2}, FSize{29, 1});
input->setLabelText (L"&Input"); input->setLabelText (L"&Input");
// The object label is managed by dialog // The object label is managed by dialog
@ -218,7 +218,7 @@ int main (int argc, char* argv[])
"adipiscing elit, sed do eiusmod tempor " "adipiscing elit, sed do eiusmod tempor "
"incididunt ut labore et dolore magna aliqua." "incididunt ut labore et dolore magna aliqua."
, dialog ); , dialog );
label->setGeometry (FPoint(2, 4), FSize(36, 1)); label->setGeometry (FPoint{2, 4}, FSize{36, 1});
FWidget::setMainWidget(dialog); FWidget::setMainWidget(dialog);
dialog->show(); dialog->show();
return app.exec(); return app.exec();
@ -322,13 +322,13 @@ class dialogWidget : public FDialog
{ {
public: public:
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog(parent) : FDialog{parent}
{ {
setText ("Dialog"); setText ("Dialog");
setGeometry (FPoint(25, 5), FSize(23, 4)); setGeometry (FPoint{25, 5}, FSize{23, 4});
label.setGeometry (FPoint(1, 1), FSize(10, 1)); label.setGeometry (FPoint{1, 1}, FSize{10, 1});
label.setAlignment (fc::alignRight); label.setAlignment (fc::alignRight);
value.setGeometry (FPoint(11, 1), FSize(10, 1)); value.setGeometry (FPoint{11, 1}, FSize{10, 1});
id = addTimer(100); id = addTimer(100);
} }
@ -500,14 +500,14 @@ int main (int argc, char* argv[])
FApplication app(argc, argv); FApplication app(argc, argv);
FDialog dialog(&app); FDialog dialog(&app);
dialog.setText ("A dialog with callback function"); dialog.setText ("A dialog with callback function");
dialog.setGeometry (FRect(25, 5, 45, 9)); dialog.setGeometry (FRect{25, 5, 45, 9});
FLabel label (&dialog); FLabel label (&dialog);
label = "The button has never been pressed before"; label = "The button has never been pressed before";
label.setGeometry (FPoint(2, 2), FSize(41, 1)); label.setGeometry (FPoint{2, 2}, FSize{41, 1});
FButton button (&dialog); FButton button (&dialog);
// Character follows '&' will be used as the accelerator key // Character follows '&' will be used as the accelerator key
button = "&Click me"; button = "&Click me";
button.setGeometry (FPoint(15, 5), FSize(14, 1)); button.setGeometry (FPoint{15, 5}, FSize{14, 1});
// Connect the button signal "clicked" with the callback function // Connect the button signal "clicked" with the callback function
button.addCallback button.addCallback
@ -553,9 +553,9 @@ int main (int argc, char* argv[])
FApplication app(argc, argv); FApplication app(argc, argv);
FDialog dialog(&app); FDialog dialog(&app);
dialog.setText ("Lambda expression as callback"); dialog.setText ("Lambda expression as callback");
dialog.setGeometry (FRect(25, 5, 45, 9)); dialog.setGeometry (FRect{25, 5, 45, 9});
FButton button ("&bottom", &dialog); FButton button ("&bottom", &dialog);
button.setGeometry (FPoint(15, 5), FSize(14, 1)); button.setGeometry (FPoint{15, 5}, FSize{14, 1});
// Connect the button signal "clicked" with the lambda expression // Connect the button signal "clicked" with the lambda expression
button.addCallback button.addCallback
@ -567,12 +567,12 @@ int main (int argc, char* argv[])
if ( button.getY() != 2 ) if ( button.getY() != 2 )
{ {
button.setPos (FPoint(15, 2)); button.setPos (FPoint{15, 2});
button.setText("&top"); button.setText("&top");
} }
else else
{ {
button.setPos (FPoint(15, 5)); button.setPos (FPoint{15, 5});
button.setText("&bottom"); button.setText("&bottom");
} }
@ -616,11 +616,11 @@ class dialogWidget : public FDialog
{ {
public: public:
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog(parent) : FDialog{parent}
{ {
setText ("Callback method"); setText ("Callback method");
setGeometry (FPoint(25, 5), FSize(25, 7)); setGeometry (FPoint{25, 5}, FSize{25, 7});
button.setGeometry (FPoint(7, 3), FSize(10, 1)); button.setGeometry (FPoint{7, 3}, FSize{10, 1});
// Connect the button signal "clicked" with the callback method // Connect the button signal "clicked" with the callback method
button.addCallback button.addCallback
@ -678,16 +678,16 @@ class dialogWidget : public FDialog
{ {
public: public:
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog(parent) : FDialog{parent}
{ {
setGeometry (FPoint(25, 5), FSize(22, 7)); setGeometry (FPoint{25, 5}, FSize{22, 7});
setText ("Emit signal"); setText ("Emit signal");
const FSize size(5, 1); const FSize size{5, 1};
label.setGeometry (FPoint(8, 1), size); label.setGeometry (FPoint{8, 1}, size);
label.setAlignment (fc::alignRight); label.setAlignment (fc::alignRight);
label.setForegroundColor (fc::Black); label.setForegroundColor (fc::Black);
plus.setGeometry (FPoint(3, 3), size); plus.setGeometry (FPoint{3, 3}, size);
minus.setGeometry (FPoint(13, 3), size); minus.setGeometry (FPoint{13, 3}, size);
plus.setNoUnderline(); plus.setNoUnderline();
minus.setNoUnderline(); minus.setNoUnderline();
@ -987,15 +987,15 @@ class dialogWidget : public FDialog
{ {
public: public:
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog(parent) : FDialog{parent}
{ {
setText ("Dialog"); setText ("Dialog");
setResizeable(); setResizeable();
button.setGeometry (FPoint(1, 1), FSize(12, 1), false); button.setGeometry (FPoint{1, 1}, FSize{12, 1}, false);
input.setGeometry (FPoint(2, 3), FSize(12, 1), false); input.setGeometry (FPoint{2, 3}, FSize{12, 1}, false);
// Set dialog geometry and calling adjustSize() // Set dialog geometry and calling adjustSize()
setGeometry (FPoint(25, 5), FSize(40, 12)); setGeometry (FPoint{25, 5}), FSize{40, 12});
setMinimumSize (FSize(25, 9)); setMinimumSize (FSize{25, 9});
} }
private: private:
@ -1011,14 +1011,14 @@ class dialogWidget : public FDialog
auto y = int((getDesktopHeight() - getHeight()) / 2); auto y = int((getDesktopHeight() - getHeight()) / 2);
checkMinValue(x); checkMinValue(x);
checkMinValue(y); checkMinValue(y);
setPos (FPoint(x, y), false); setPos (FPoint{x, y}, false);
} }
void adjustWidgets() void adjustWidgets()
{ {
const auto bx = int(getWidth() - button.getWidth() - 3); const auto bx = int(getWidth() - button.getWidth() - 3);
const auto by = int(getHeight() - 4); const auto by = int(getHeight() - 4);
button.setPos (FPoint(bx, by), false); button.setPos (FPoint{bx, by}, false);
input.setWidth (getWidth() - 4); input.setWidth (getWidth() - 4);
const auto ly = int(getHeight() / 2) - 1; const auto ly = int(getHeight() / 2) - 1;
input.setY (ly, false); input.setY (ly, false);
@ -1046,10 +1046,10 @@ class dialogWidget : public FDialog
// Calling super class method draw() // Calling super class method draw()
FDialog::draw(); FDialog::draw();
print() << FPoint (3, 3) print() << FPoint{3, 3}
<< FColorPair (fc::Black, fc::White) << FColorPair{fc::Black, fc::White}
<< "Text on " << "Text on "
<< FColorPair (fc::Blue, fc::Yellow) << FColorPair{fc::Blue, fc::Yellow}
<< "top"; << "top";
} }
@ -1129,12 +1129,12 @@ class dialogWidget : public FDialog
{ {
public: public:
explicit dialogWidget (FWidget* parent = nullptr) explicit dialogWidget (FWidget* parent = nullptr)
: FDialog(parent) : FDialog{parent}
{ {
setText ("Dialog"); setText ("Dialog");
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(); const auto& wc = getFWidgetColors();
setColor (wc.label_inactive_fg, wc.dialog_bg); setColor (wc.label_inactive_fg, wc.dialog_bg);
scrollview.clearArea(); scrollview.clearArea();
@ -1144,25 +1144,25 @@ class dialogWidget : public FDialog
static std::vector<direction> d static std::vector<direction> d
{ {
{"NW", FPoint(3, 13), FPoint(1, 1), black}, {"NW", FPoint{3, 13}, FPoint{1, 1}, black},
{"N", FPoint(10, 13), FPoint(21, 1), red}, {"N", FPoint{10, 13}, FPoint{21, 1}, red},
{"NE", FPoint(17, 13), FPoint(41, 1), black}, {"NE", FPoint{17, 13}, FPoint{41, 1}, black},
{"W", FPoint(3, 15), FPoint(1, 10), black}, {"W", FPoint{3, 15}, FPoint{1, 10}, black},
{"*", FPoint(10, 15), FPoint(21, 10), black}, {"*", FPoint{10, 15}, FPoint{21, 10}, black},
{"E", FPoint(17, 15), FPoint(41, 10), black}, {"E", FPoint{17, 15}, FPoint{41, 10}, black},
{"SW", FPoint(3, 17), FPoint(1, 19), black}, {"SW", FPoint{3, 17}, FPoint{1, 19}, black},
{"S", FPoint(10, 17), FPoint(21, 19), cyan}, {"S", FPoint{10, 17}, FPoint{21, 19}, cyan},
{"SE", FPoint(17, 17), FPoint(41, 19), black} {"SE", FPoint{17, 17}, FPoint{41, 19}, black}
}; };
for (auto&& b : d) for (auto&& b : d)
{ {
scrollview.print() << std::get<2>(b) + FPoint(10, 5) scrollview.print() << std::get<2>(b) + FPoint{10, 5}
<< std::get<3>(b) << std::get<0>(b); << std::get<3>(b) << std::get<0>(b);
auto edit = new FLineEdit("direction " + std::get<0>(b), &scrollview); auto edit = new FLineEdit("direction " + std::get<0>(b), &scrollview);
edit->setGeometry(std::get<2>(b) + FPoint(1, 1), FSize(17, 1)); edit->setGeometry(std::get<2>(b) + FPoint{1, 1}, FSize{17, 1});
auto btn = new FButton(std::get<0>(b), this); auto btn = new FButton(std::get<0>(b), this);
btn->setGeometry(std::get<1>(b), FSize(4, 1)); btn->setGeometry(std::get<1>(b), FSize{4, 1});
btn->unsetShadow(); btn->unsetShadow();
btn->addCallback btn->addCallback
( (

View File

@ -74,7 +74,7 @@ class SegmentView final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
SegmentView::SegmentView (finalcut::FWidget* parent) SegmentView::SegmentView (finalcut::FWidget* parent)
: FDialog(parent) : FDialog{parent}
{ {
// Dialog settings // Dialog settings
// Avoids calling a virtual function from the constructor // Avoids calling a virtual function from the constructor

View File

@ -11,6 +11,7 @@ noinst_PROGRAMS = \
hello \ hello \
dialog \ dialog \
input-dialog \ input-dialog \
event-log \
fullwidth-character \ fullwidth-character \
7segment \ 7segment \
choice \ choice \
@ -39,6 +40,7 @@ noinst_PROGRAMS = \
hello_SOURCES = hello.cpp hello_SOURCES = hello.cpp
dialog_SOURCES = dialog.cpp dialog_SOURCES = dialog.cpp
input_dialog_SOURCES = input-dialog.cpp input_dialog_SOURCES = input-dialog.cpp
event_log_SOURCES = event-log.cpp
fullwidth_character_SOURCES = fullwidth-character.cpp fullwidth_character_SOURCES = fullwidth-character.cpp
7segment_SOURCES = 7segment.cpp 7segment_SOURCES = 7segment.cpp
choice_SOURCES = choice.cpp choice_SOURCES = choice.cpp

View File

@ -92,7 +92,7 @@ class Background final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Background::Background (finalcut::FWidget* parent) Background::Background (finalcut::FWidget* parent)
: FDialog(parent) : FDialog{parent}
{ {
// Dialog settings // Dialog settings
// Avoids calling a virtual function from the constructor // Avoids calling a virtual function from the constructor
@ -211,7 +211,6 @@ void Background::cb_choice (const finalcut::FWidget*, const FDataPtr)
updateTerminal(); updateTerminal();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// main part // main part
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -62,7 +62,7 @@ class Button final : public finalcut::FButton
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Button::Button (finalcut::FWidget* parent) Button::Button (finalcut::FWidget* parent)
: finalcut::FButton(parent) : finalcut::FButton{parent}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -81,10 +81,10 @@ void Button::setChecked (bool enable)
} }
else else
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
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);
} }
redraw(); redraw();
@ -245,7 +245,7 @@ class Calc final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Calc::Calc (FWidget* parent) Calc::Calc (FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
// Dialog settings // Dialog settings
// Avoids calling a virtual function from the constructor // Avoids calling a virtual function from the constructor
@ -278,7 +278,7 @@ Calc::Calc (FWidget* parent)
btn->setDoubleFlatLine(fc::top); btn->setDoubleFlatLine(fc::top);
btn->setDoubleFlatLine(fc::bottom); btn->setDoubleFlatLine(fc::bottom);
if ( isNewFont() ) if ( finalcut::FTerm::isNewFont() )
btn->unsetClickAnimation(); btn->unsetClickAnimation();
btn->addCallback btn->addCallback
@ -421,18 +421,18 @@ void Calc::drawDispay()
if ( error ) if ( error )
display = " Error "; display = " Error ";
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
setReverse(false); setReverse(false);
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
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};
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
setReverse(true); setReverse(true);
if ( isNewFont() ) if ( finalcut::FTerm::isNewFont() )
{ {
const wchar_t bottom_line {fc::NF_border_line_bottom}; const wchar_t bottom_line {fc::NF_border_line_bottom};
const wchar_t top_bottom_line {fc::NF_border_line_up_and_down}; const wchar_t top_bottom_line {fc::NF_border_line_up_and_down};

View File

@ -73,13 +73,13 @@ class CheckList final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
CheckList::CheckList (finalcut::FWidget* parent) CheckList::CheckList (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
// Dialog settings // Dialog settings
// Avoids calling a virtual function from the constructor // Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP) // (CERT, OOP50-CPP)
FDialog::setText (L"Shopping list"); FDialog::setText (L"Shopping list");
const std::size_t nf_offset = ( isNewFont() ) ? 1 : 0; const std::size_t nf_offset = ( finalcut::FTerm::isNewFont() ) ? 1 : 0;
FDialog::setGeometry ( FPoint{int(1 + (parent->getWidth() - 28) / 2), 5} FDialog::setGeometry ( FPoint{int(1 + (parent->getWidth() - 28) / 2), 5}
, FSize{28 + nf_offset, 13} ); , FSize{28 + nf_offset, 13} );
setShadow(); setShadow();

350
examples/event-log.cpp Normal file
View File

@ -0,0 +1,350 @@
/***********************************************************************
* event-log.cpp - Logs events in a dialog box *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 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 <fstream>
#include <sstream>
#include <tuple>
#include <utility>
#include <vector>
#include <final/final.h>
using finalcut::FPoint;
using finalcut::FRect;
using finalcut::FSize;
class EventLog; // class forward declaration
//----------------------------------------------------------------------
// class EventLog::EventLog
//----------------------------------------------------------------------
class EventDialog final : public finalcut::FDialog
{
public:
// Using-declaration
using FDialog::setGeometry;
// Constructor
explicit EventDialog (finalcut::FWidget* = nullptr);
// Disable copy constructor
EventDialog (const EventDialog&) = delete;
// Destructor
~EventDialog();
// Disable copy assignment operator (=)
EventDialog& operator = (const EventDialog&) = delete;
private:
// Methods
finalcut::FString getMouseButtonName (int);
void logMouseEvent ( const finalcut::FString&
, const finalcut::FMouseEvent& );
// Event handlers
void onClose (finalcut::FCloseEvent*) override;
void onShow (finalcut::FShowEvent*) override;
void onTimer (finalcut::FTimerEvent*) override;
void onKeyPress (finalcut::FKeyEvent*) override;
void onMouseDown (finalcut::FMouseEvent*) override;
void onMouseMove (finalcut::FMouseEvent*) override;
void onMouseUp (finalcut::FMouseEvent*) override;
void onMouseDoubleClick (finalcut::FMouseEvent* ev) override;
void onWindowActive (finalcut::FEvent*) override;
void onWindowInactive (finalcut::FEvent*) override;
void onWindowRaised (finalcut::FEvent*) override;
void onWindowLowered (finalcut::FEvent*) override;
// Data members
finalcut::FLog& log{*finalcut::FApplication::getLog()};
finalcut::FLabel label{this};
};
//----------------------------------------------------------------------
EventDialog::EventDialog (finalcut::FWidget* parent)
: FDialog{parent}
{
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setText ("Event dialog");
FDialog::setGeometry (FPoint{15, 2}, FSize{53, 12});
setShadow();
label.setText("\n\nUse the keyboard or mouse\n"
"in this dialog to create events");
label.setAlignment(finalcut::fc::alignCenter);
label.setGeometry (FPoint(1, 1), getClientSize(), false);
addTimer(60000); // Starts the timer every minute
}
//----------------------------------------------------------------------
EventDialog::~EventDialog() // destructor
{ }
//----------------------------------------------------------------------
finalcut::FString EventDialog::getMouseButtonName (int btn_state)
{
switch ( btn_state )
{
case finalcut::fc::LeftButton:
return "left";
case finalcut::fc::RightButton:
return "right";
case finalcut::fc::MiddleButton:
return "middle";
}
return "unknown";
}
//----------------------------------------------------------------------
void EventDialog::logMouseEvent ( const finalcut::FString& state
, const finalcut::FMouseEvent& ev )
{
const int mouse_x = ev.getX();
const int mouse_y = ev.getY();
log << finalcut::FLog::Info
<< getMouseButtonName(ev.getButton())
<< " mouse button " << state << " at ("
<< mouse_x << ", " << mouse_y << ")" << std::flush;
}
//----------------------------------------------------------------------
void EventDialog::onClose (finalcut::FCloseEvent* ev)
{
log.info("The event dialog was closed");
ev->accept();
}
//----------------------------------------------------------------------
void EventDialog::onShow (finalcut::FShowEvent*)
{
log.info("The event dialog is now displayed");
}
//----------------------------------------------------------------------
void EventDialog::onTimer (finalcut::FTimerEvent*)
{
log.info("-- minute marker --");
}
//----------------------------------------------------------------------
void EventDialog::onKeyPress (finalcut::FKeyEvent* ev)
{
const FKey key_id = ev->key();
finalcut::FString key_name = finalcut::FTerm::getKeyName(key_id);
if ( key_name.isEmpty() )
key_name = wchar_t(key_id);
log << finalcut::FLog::Info
<< "Key " << key_name << " (id " << key_id << ")" << std::flush;
finalcut::FDialog::onKeyPress(ev);
}
//----------------------------------------------------------------------
void EventDialog::onMouseDown (finalcut::FMouseEvent* ev)
{
logMouseEvent("down", *ev);
finalcut::FDialog::onMouseDown(ev);
}
//----------------------------------------------------------------------
void EventDialog::onMouseMove (finalcut::FMouseEvent* ev)
{
logMouseEvent("move", *ev);
finalcut::FDialog::onMouseMove(ev);
}
//----------------------------------------------------------------------
void EventDialog::onMouseUp (finalcut::FMouseEvent* ev)
{
logMouseEvent("up", *ev);
finalcut::FDialog::onMouseUp(ev);
}
//----------------------------------------------------------------------
void EventDialog::onMouseDoubleClick (finalcut::FMouseEvent* ev)
{
logMouseEvent("double click", *ev);
finalcut::FDialog::onMouseDoubleClick(ev);
}
//----------------------------------------------------------------------
void EventDialog::onWindowActive (finalcut::FEvent* ev)
{
log.info("The Event dialog is now active");
finalcut::FDialog::onWindowActive(ev);
}
//----------------------------------------------------------------------
void EventDialog::onWindowInactive (finalcut::FEvent* ev)
{
log.info("The Event dialog is now inactive");
finalcut::FDialog::onWindowInactive(ev);
}
//----------------------------------------------------------------------
void EventDialog::onWindowRaised (finalcut::FEvent* ev)
{
log.info("The dialog was raised");
finalcut::FDialog::onWindowRaised(ev);
}
//----------------------------------------------------------------------
void EventDialog::onWindowLowered (finalcut::FEvent* ev)
{
log.info("The dialog was lowered");
finalcut::FDialog::onWindowLowered(ev);
}
//----------------------------------------------------------------------
// class EventLog
//----------------------------------------------------------------------
class EventLog final : public finalcut::FDialog, public std::ostringstream
{
public:
// Using-declaration
using FDialog::setGeometry;
// Constructor
explicit EventLog (finalcut::FWidget* = nullptr);
// Disable copy constructor
EventLog (const EventLog&) = delete;
// Destructor
~EventLog();
// Disable copy assignment operator (=)
EventLog& operator = (const EventLog&) = delete;
// Event handlers
void onTimer (finalcut::FTimerEvent*) override;
void onClose (finalcut::FCloseEvent*) override;
private:
// Method
void adjustSize() override;
// Data members
finalcut::FTextView scrollText{this};
EventDialog* event_dialog{new EventDialog(this)};
};
//----------------------------------------------------------------------
EventLog::EventLog (finalcut::FWidget* parent)
: FDialog{parent}
{
// Dialog settings
// Avoids calling a virtual function from the constructor
// (CERT, OOP50-CPP)
FDialog::setText ("Event log");
FDialog::setGeometry (FPoint{4, 16}, FSize{75, 8});
FDialog::setResizeable();
setMinimumSize (FSize{75, 5});
setShadow();
scrollText.ignorePadding();
scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
event_dialog->setFocus();
addTimer(250); // Starts the timer every 250 milliseconds
}
//----------------------------------------------------------------------
EventLog::~EventLog() // destructor
{ }
//----------------------------------------------------------------------
void EventLog::onTimer (finalcut::FTimerEvent*)
{
if ( ! str().empty() )
{
scrollText.append(str());
str("");
scrollText.scrollToEnd();
redraw();
updateTerminal();
}
}
//----------------------------------------------------------------------
void EventLog::onClose (finalcut::FCloseEvent* ev)
{
finalcut::FApplication::closeConfirmationDialog (this, ev);
}
//----------------------------------------------------------------------
void EventLog::adjustSize()
{
finalcut::FDialog::adjustSize();
scrollText.setGeometry (FPoint{1, 2}, FSize(getWidth(), getHeight() - 1));
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
finalcut::FApplication app(argc, argv);
EventLog dialog(&app);
// Get the global logger object
finalcut::FLog& log = *finalcut::FApplication::getLog();
// Set the line endings (default = CRLF)
log.setLineEnding (finalcut::FLog::LF);
// Write a timestamp before each output line
log.enableTimestamp();
// Set the dialog object as output stream
log.setOutputStream(dialog);
// ----------------------------------------------
// Remove the comment characters in the following
// two lines to log the output to a file.
// ----------------------------------------------
//std::ofstream file_stream("test.log", std::ofstream::out | std::ofstream::app);
//log.setOutputStream(file_stream);
// Sets the dialog as main widget
finalcut::FWidget::setMainWidget(&dialog);
// Show the dialog
dialog.show();
// Run the application
return app.exec();
}

View File

@ -44,17 +44,17 @@ class Keyboard final : public finalcut::FWidget
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Keyboard::Keyboard (finalcut::FWidget* parent) Keyboard::Keyboard (finalcut::FWidget* parent)
: finalcut::FWidget(parent) : finalcut::FWidget{parent}
{ {
setFWidgetColors().term_fg = finalcut::fc::Default; getColorTheme()->term_fg = finalcut::fc::Default;
setFWidgetColors().term_bg = finalcut::fc::Default; getColorTheme()->term_bg = finalcut::fc::Default;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Keyboard::onKeyPress (finalcut::FKeyEvent* ev) void Keyboard::onKeyPress (finalcut::FKeyEvent* ev)
{ {
const FKey key_id = ev->key(); const FKey key_id = ev->key();
finalcut::FString key_name = getKeyName(key_id); finalcut::FString key_name = finalcut::FTerm::getKeyName(key_id);
bool is_last_line{false}; bool is_last_line{false};
if ( key_name.isEmpty() ) if ( key_name.isEmpty() )

View File

@ -105,7 +105,7 @@ class Listbox final : public FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Listbox::Listbox (FWidget* parent) Listbox::Listbox (FWidget* parent)
: FDialog(parent) : FDialog{parent}
{ {
auto temp = std::make_shared<FString>(); auto temp = std::make_shared<FString>();
temp_str = temp; temp_str = temp;

View File

@ -68,7 +68,7 @@ class Listview final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Listview::Listview (finalcut::FWidget* parent) Listview::Listview (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
// Set FListView geometry // Set FListView geometry
listView.setGeometry(FPoint{2, 1}, FSize{33, 14}); listView.setGeometry(FPoint{2, 1}, FSize{33, 14});

View File

@ -53,7 +53,7 @@ class Mandelbrot final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Mandelbrot::Mandelbrot (finalcut::FWidget* parent) Mandelbrot::Mandelbrot (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
FDialog::setText ("Mandelbrot set"); FDialog::setText ("Mandelbrot set");
} }

View File

@ -117,7 +117,7 @@ class Menu final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Menu::Menu (finalcut::FWidget* parent) Menu::Menu (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
// Menu bar itms // Menu bar itms
File.setStatusbarMessage ("File management commands"); File.setStatusbarMessage ("File management commands");

View File

@ -72,7 +72,7 @@ class ColorChooser final : public finalcut::FWidget
//---------------------------------------------------------------------- //----------------------------------------------------------------------
ColorChooser::ColorChooser (finalcut::FWidget* parent) ColorChooser::ColorChooser (finalcut::FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
FWidget::setSize (FSize{8, 12}); FWidget::setSize (FSize{8, 12});
setFixedSize (FSize{8, 12}); setFixedSize (FSize{8, 12});
@ -226,7 +226,7 @@ class Brushes final : public finalcut::FWidget
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Brushes::Brushes (finalcut::FWidget* parent) Brushes::Brushes (finalcut::FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
FWidget::setSize (FSize{8, 4}); FWidget::setSize (FSize{8, 4});
setFixedSize (FSize{8, 4}); setFixedSize (FSize{8, 4});
@ -379,7 +379,7 @@ class MouseDraw final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
MouseDraw::MouseDraw (finalcut::FWidget* parent) MouseDraw::MouseDraw (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
FDialog::setText ("Drawing with the mouse"); FDialog::setText ("Drawing with the mouse");
c_chooser.setPos (FPoint{1, 1}); c_chooser.setPos (FPoint{1, 1});
@ -447,7 +447,7 @@ void MouseDraw::draw()
finalcut::FDialog::draw(); finalcut::FDialog::draw();
setColor(); setColor();
if ( isNewFont() ) if ( finalcut::FTerm::isNewFont() )
{ {
for (int y{2}; y < y_max; y++) for (int y{2}; y < y_max; y++)
{ {

View File

@ -132,6 +132,40 @@ void move (int xold, int yold, int xnew, int ynew)
<< std::right << std::setw(10) << byte << "\r\n"; << std::right << std::setw(10) << byte << "\r\n";
} }
//----------------------------------------------------------------------
class DirectLogger : public finalcut::FLog
{
public:
void info (const std::string& entry) override
{
output << entry << "\r" << std::endl;
}
void warn (const std::string&) override
{ }
void error (const std::string&) override
{ }
void debug (const std::string&) override
{ }
void setOutputStream (const std::ostream& os) override
{ output.rdbuf(os.rdbuf()); }
void setLineEnding (LineEnding) override
{ }
void enableTimestamp() override
{ }
void disableTimestamp() override
{ }
private:
// Data member
std::ostream output{std::cerr.rdbuf()};
};
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// main part // main part
@ -157,7 +191,7 @@ int main (int argc, char* argv[])
TermApp.clearArea(); TermApp.clearArea();
// Show the determined terminal name and text resolution // Show the determined terminal name and text resolution
std::cout << "Terminal: " << TermApp.getTermType() << "\r\n"; std::cout << "Terminal: " << finalcut::FTerm::getTermType() << "\r\n";
std::cout << " Columns: 0.." << xmax << "\r\n"; std::cout << " Columns: 0.." << xmax << "\r\n";
std::cout << " Lines: 0.." << ymax << "\r\n"; std::cout << " Lines: 0.." << ymax << "\r\n";
@ -189,7 +223,11 @@ int main (int argc, char* argv[])
keyPressed(); keyPressed();
// Show terminal speed and milliseconds for all cursor movement sequence // Show terminal speed and milliseconds for all cursor movement sequence
std::cout << "\r" << line; std::cout << "\r" << line << std::flush;
// Generation of a logger in a shared_ptr via a pointer
finalcut::FApplication::setLog(std::make_shared<DirectLogger>());
// Get the shared_ptr with the base class
std::shared_ptr<finalcut::FLog> log = finalcut::FApplication::getLog();
const finalcut::FOptiMove& opti_move = *finalcut::FTerm::getFOptiMove(); const finalcut::FOptiMove& opti_move = *finalcut::FTerm::getFOptiMove();
finalcut::printDurations(opti_move); finalcut::printDurations(opti_move);

View File

@ -80,9 +80,9 @@ class RotoZoomer final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
RotoZoomer::RotoZoomer (finalcut::FWidget* parent, bool b, int l) RotoZoomer::RotoZoomer (finalcut::FWidget* parent, bool b, int l)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
, benchmark(b) , benchmark{b}
, loops(l) , loops{l}
{ {
FDialog::setText ("Rotozoomer effect"); FDialog::setText ("Rotozoomer effect");
@ -179,11 +179,11 @@ void RotoZoomer::rotozoomer (double cx, double cy, double r, double a)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void RotoZoomer::generateReport() void RotoZoomer::generateReport()
{ {
finalcut::FString term_type = getTermType(); finalcut::FString term_type = finalcut::FTerm::getTermType();
finalcut::FString dimension_str{}; finalcut::FString dimension_str{};
finalcut::FString time_str{}; finalcut::FString time_str{};
finalcut::FString fps_str{}; finalcut::FString fps_str{};
std::wostringstream rep; finalcut::FStringStream rep;
dimension_str << getDesktopWidth() dimension_str << getDesktopWidth()
<< "x" << getDesktopHeight(); << "x" << getDesktopHeight();
int elapsed_ms = int(duration_cast<milliseconds>(end - start).count()); int elapsed_ms = int(duration_cast<milliseconds>(end - start).count());

View File

@ -72,7 +72,7 @@ class Scrollview final : public finalcut::FScrollView
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Scrollview::Scrollview (finalcut::FWidget* parent) Scrollview::Scrollview (finalcut::FWidget* parent)
: finalcut::FScrollView(parent) : finalcut::FScrollView{parent}
{ {
// Sets the navigation button geometry // Sets the navigation button geometry
go_east.setGeometry (FPoint{1, 1}, FSize{5, 1}); go_east.setGeometry (FPoint{1, 1}, FSize{5, 1});
@ -128,11 +128,11 @@ void Scrollview::setScrollSize (const FSize& size)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void Scrollview::draw() void Scrollview::draw()
{ {
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
setReverse(true); setReverse(true);
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.label_inactive_fg, wc.dialog_bg); setColor (wc->label_inactive_fg, wc->dialog_bg);
clearArea(); clearArea();
for (int y{0}; y < int(getScrollHeight()); y++) for (int y{0}; y < int(getScrollHeight()); y++)
@ -143,7 +143,7 @@ void Scrollview::draw()
print (32 + ((x + y) % 0x5f)); print (32 + ((x + y) % 0x5f));
} }
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
setReverse(false); setReverse(false);
FScrollView::draw(); FScrollView::draw();
@ -214,7 +214,7 @@ class Scrollviewdemo final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent) Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
FDialog::setGeometry (FPoint{16, 3}, FSize{50, 19}); FDialog::setGeometry (FPoint{16, 3}, FSize{50, 19});
FDialog::setText ("Scrolling viewport example"); FDialog::setText ("Scrolling viewport example");

View File

@ -224,17 +224,17 @@ void streamToInterger()
finalcut::FString("-321") >> stream_int; finalcut::FString("-321") >> stream_int;
std::cout << "stream out: " << stream_int << std::endl; std::cout << "stream out: " << stream_int << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
std::cerr << "underflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
std::cerr << "overflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
std::cerr << "Arithmetic error: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Arithmetic error");
} }
} }
@ -248,17 +248,17 @@ void streamToUnsignedInterger()
finalcut::FString("123") >> stream_uint; finalcut::FString("123") >> stream_uint;
std::cout << "stream out: " << stream_uint << std::endl; std::cout << "stream out: " << stream_uint << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
std::cerr << "underflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
std::cerr << "overflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
std::cerr << "Arithmetic error: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Arithmetic error");
} }
} }
@ -272,17 +272,17 @@ void streamToDouble()
finalcut::FString("0.123456e+2") >> stream_double; finalcut::FString("0.123456e+2") >> stream_double;
std::cout << "stream out: " << stream_double << std::endl; std::cout << "stream out: " << stream_double << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
std::cerr << "underflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
std::cerr << "overflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
std::cerr << "Arithmetic error: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Arithmetic error");
} }
} }
@ -296,17 +296,17 @@ void streamToFloat()
finalcut::FString("0.123e-3") >> stream_float; finalcut::FString("0.123e-3") >> stream_float;
std::cout << "stream out: " << stream_float << std::endl; std::cout << "stream out: " << stream_float << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
std::cerr << "underflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
std::cerr << "overflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
std::cerr << "Arithmetic error: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Arithmetic error");
} }
} }
@ -496,17 +496,17 @@ void convertToNumberExample()
const uLong ulong_num = finalcut::FString("123456789").toULong(); const uLong ulong_num = finalcut::FString("123456789").toULong();
std::cout << " toULong: " << ulong_num << std::endl; std::cout << " toULong: " << ulong_num << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
std::cerr << "underflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
std::cerr << "overflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
std::cerr << "Arithmetic error: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Arithmetic error");
} }
// Test: convert a string to a signed long interger // Test: convert a string to a signed long interger
@ -515,17 +515,17 @@ void convertToNumberExample()
const long long_num = finalcut::FString("-9876543210").toLong(); const long long_num = finalcut::FString("-9876543210").toLong();
std::cout << " toLong: " << long_num << std::endl; std::cout << " toLong: " << long_num << std::endl;
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
std::cerr << "underflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
std::cerr << "overflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
std::cerr << "Arithmetic error: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Arithmetic error");
} }
// Test: convert a string to a double value // Test: convert a string to a double value
@ -540,17 +540,17 @@ void convertToNumberExample()
<< double_num << std::endl; << double_num << std::endl;
std::cout.flags(save_flags); std::cout.flags(save_flags);
} }
catch (const std::underflow_error& ex) catch (const std::underflow_error&)
{ {
std::cerr << "underflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Underflow");
} }
catch (const std::overflow_error& ex) catch (const std::overflow_error&)
{ {
std::cerr << "overflow: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Overflow");
} }
catch (const std::invalid_argument& ex) catch (const std::invalid_argument&)
{ {
std::cerr << "Arithmetic error: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Arithmetic error");
} }
} }
@ -640,9 +640,9 @@ void insertExample()
std::cout << " insert: " std::cout << " insert: "
<< insert_str.insert("changed ", 7) << std::endl; << insert_str.insert("changed ", 7) << std::endl;
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range&)
{ {
std::cerr << "Out of Range error: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Out of Range");
} }
} }
@ -655,14 +655,14 @@ void indexExample()
try try
{ {
index[0] = L'I'; // write a wide character at position 0 index[0] = L'I'; // Write a wide character at position 0
printf ( " index: [0] = %c ; [4] = %c\n" printf ( " index: [0] = %c ; [4] = %c\n"
, char(index[0]) , char(index[0])
, char(index[4]) ); , char(index[4]) );
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range&)
{ {
std::cerr << "Out of Range error: " << ex.what() << std::endl; finalcut::FApplication::getLog()->error("Out of Range");
} }
} }

View File

@ -66,17 +66,17 @@ class AttribDlg final : public finalcut::FDialog
void adjustSize() override; void adjustSize() override;
// Data members // Data members
FColor bgcolor{getFWidgetColors().label_bg}; FColor bgcolor{getColorTheme()->label_bg};
finalcut::FButton next_button{"&Next >", this}; finalcut::FButton next_button{"&Next >", this};
finalcut::FButton back_button{"< &Back", this}; finalcut::FButton back_button{"< &Back", this};
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------
AttribDlg::AttribDlg (finalcut::FWidget* parent) AttribDlg::AttribDlg (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
FDialog::setText ( "A terminal attributes test (" FDialog::setText ( "A terminal attributes test ("
+ finalcut::FString{getTermType()} + finalcut::FString{finalcut::FTerm::getTermType()}
+ ")"); + ")");
next_button.setGeometry ( FPoint{int(getWidth()) - 13, int(getHeight()) - 4} next_button.setGeometry ( FPoint{int(getWidth()) - 13, int(getHeight()) - 4}
@ -145,10 +145,10 @@ void AttribDlg::onClose (finalcut::FCloseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void AttribDlg::cb_next (const finalcut::FWidget*, const FDataPtr) void AttribDlg::cb_next (const finalcut::FWidget*, const FDataPtr)
{ {
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
return; return;
if ( bgcolor == FColor(getMaxColor() - 1) ) if ( bgcolor == FColor(finalcut::FTerm::getMaxColor() - 1) )
bgcolor = fc::Default; bgcolor = fc::Default;
else if ( bgcolor == fc::Default ) else if ( bgcolor == fc::Default )
bgcolor = 0; bgcolor = 0;
@ -161,13 +161,13 @@ void AttribDlg::cb_next (const finalcut::FWidget*, const FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void AttribDlg::cb_back (const finalcut::FWidget*, const FDataPtr) void AttribDlg::cb_back (const finalcut::FWidget*, const FDataPtr)
{ {
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
return; return;
if ( bgcolor == 0 ) if ( bgcolor == 0 )
bgcolor = fc::Default; bgcolor = fc::Default;
else if ( bgcolor == fc::Default ) else if ( bgcolor == fc::Default )
bgcolor = FColor(getMaxColor() - 1); bgcolor = FColor(finalcut::FTerm::getMaxColor() - 1);
else else
bgcolor--; bgcolor--;
@ -238,14 +238,14 @@ class AttribDemo final : public finalcut::FWidget
void draw() override; void draw() override;
// Data member // Data member
FColor last_color{FColor(getMaxColor())}; FColor last_color{FColor(finalcut::FTerm::getMaxColor())};
}; };
//---------------------------------------------------------------------- //----------------------------------------------------------------------
AttribDemo::AttribDemo (finalcut::FWidget* parent) AttribDemo::AttribDemo (finalcut::FWidget* parent)
: finalcut::FWidget(parent) : finalcut::FWidget{parent}
{ {
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
last_color = 1; last_color = 1;
else if ( last_color > 16 ) else if ( last_color > 16 )
last_color = 16; last_color = 16;
@ -267,11 +267,11 @@ void AttribDemo::printColorLine()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void AttribDemo::printAltCharset() void AttribDemo::printAltCharset()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
const auto& parent = static_cast<AttribDlg*>(getParent()); const auto& parent = static_cast<AttribDlg*>(getParent());
if ( ! isMonochron() ) if ( ! finalcut::FTerm::isMonochron() )
setColor (wc.label_fg, wc.label_bg); setColor (wc->label_fg, wc->label_bg);
print() << FPoint{1, 1} << "alternate charset: "; print() << FPoint{1, 1} << "alternate charset: ";
@ -418,7 +418,7 @@ void AttribDemo::printProtected()
void AttribDemo::draw() void AttribDemo::draw()
{ {
// test alternate character set // test alternate character set
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
printAltCharset(); printAltCharset();
const std::vector<std::function<void()> > effect const std::vector<std::function<void()> > effect
@ -441,15 +441,15 @@ void AttribDemo::draw()
{ {
print() << FPoint{1, 2 + int(y)}; print() << FPoint{1, 2 + int(y)};
if ( ! isMonochron() ) if ( ! finalcut::FTerm::isMonochron() )
setColor (wc.label_fg, wc.label_bg); setColor (wc->label_fg, wc->label_bg);
if ( y < effect.size() ) if ( y < effect.size() )
effect[y](); effect[y]();
} }
if ( ! isMonochron() ) if ( ! finalcut::FTerm::isMonochron() )
setColor(wc.label_fg, wc.label_bg); setColor(wc->label_fg, wc->label_bg);
print() << FPoint{1, 15}; print() << FPoint{1, 15};
const FColor bg = static_cast<AttribDlg*>(getParent())->getBGColor(); const FColor bg = static_cast<AttribDlg*>(getParent())->getBGColor();

View File

@ -300,7 +300,7 @@ int main (int argc, char* argv[])
finalcut::FApplication TermApp {argc, argv, disable_alt_screen}; finalcut::FApplication TermApp {argc, argv, disable_alt_screen};
std::cout << "--------\r\nFTermcap\r\n--------\r\n\n"; std::cout << "--------\r\nFTermcap\r\n--------\r\n\n";
std::cout << "Terminal: " << TermApp.getTermType() << "\r\n"; std::cout << "Terminal: " << finalcut::FTerm::getTermType() << "\r\n";
debug (TermApp); debug (TermApp);

View File

@ -46,7 +46,7 @@ class Timer final : public finalcut::FWidget
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Timer::Timer (finalcut::FWidget* parent) Timer::Timer (finalcut::FWidget* parent)
: finalcut::FWidget(parent) : finalcut::FWidget{parent}
{ {
addTimer (60000); // 1-minute timer addTimer (60000); // 1-minute timer
const int id = addTimer (50); // 50-millisecond timer const int id = addTimer (50); // 50-millisecond timer
@ -54,8 +54,8 @@ Timer::Timer (finalcut::FWidget* parent)
delTimer (id); delTimer (id);
addTimer (250); // 250-millisecond timer addTimer (250); // 250-millisecond timer
setFWidgetColors().term_fg = fc::Default; getColorTheme()->term_fg = fc::Default;
setFWidgetColors().term_bg = fc::Default; getColorTheme()->term_bg = fc::Default;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -71,8 +71,8 @@ class Transparent final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Transparent::Transparent ( finalcut::FWidget* parent Transparent::Transparent ( finalcut::FWidget* parent
, Transparent::trans_type tt ) , Transparent::trans_type tt )
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
, type(tt) , type{tt}
{ {
// Set statusbar text for this window // Set statusbar text for this window
// Avoids calling a virtual function from the constructor // Avoids calling a virtual function from the constructor
@ -89,18 +89,18 @@ void Transparent::draw()
{ {
finalcut::FDialog::draw(); finalcut::FDialog::draw();
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
setReverse(true); setReverse(true);
if ( type == shadow ) if ( type == shadow )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
print() << FColorPair {wc.shadow_bg, wc.shadow_fg} print() << FColorPair {wc->shadow_bg, wc->shadow_fg}
<< FStyle {fc::ColorOverlay}; << FStyle {fc::ColorOverlay};
} }
else if ( type == inherit_background ) else if ( type == inherit_background )
{ {
if ( getMaxColor() > 8 ) if ( finalcut::FTerm::getMaxColor() > 8 )
print() << FColorPair {fc::Blue, fc::Black}; print() << FColorPair {fc::Blue, fc::Black};
else else
print() << FColorPair {fc::Green, fc::Black}; print() << FColorPair {fc::Green, fc::Black};
@ -191,7 +191,7 @@ class MainWindow final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
MainWindow::MainWindow (finalcut::FWidget* parent) MainWindow::MainWindow (finalcut::FWidget* parent)
: FDialog(parent) : FDialog{parent}
{ {
// The memory allocation for the following three sub windows occurs // The memory allocation for the following three sub windows occurs
// with the operator new. The lifetime of the generated widget // with the operator new. The lifetime of the generated widget
@ -228,14 +228,14 @@ void MainWindow::draw()
{ {
finalcut::FDialog::draw(); finalcut::FDialog::draw();
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
setReverse(true); setReverse(true);
setColor(); setColor();
print() << FPoint{2, 4} << line1; print() << FPoint{2, 4} << line1;
print() << FPoint{2, 5} << line2; print() << FPoint{2, 5} << line2;
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
setReverse(false); setReverse(false);
updateTerminal(); updateTerminal();

View File

@ -326,7 +326,7 @@ Treeview::TreeItem Treeview::oceania[] =
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Treeview::Treeview (finalcut::FWidget* parent) Treeview::Treeview (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
// Set FListView geometry // Set FListView geometry
listView.setGeometry(FPoint{2, 1}, FSize{53, 14}); listView.setGeometry(FPoint{2, 1}, FSize{53, 14});

View File

@ -76,7 +76,7 @@ class ProgressDialog final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
ProgressDialog::ProgressDialog (finalcut::FWidget* parent) ProgressDialog::ProgressDialog (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
// Dialog settings // Dialog settings
// Avoids calling a virtual function from the constructor // Avoids calling a virtual function from the constructor
@ -218,7 +218,7 @@ class TextWindow final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
TextWindow::TextWindow (finalcut::FWidget* parent) TextWindow::TextWindow (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
scrollText.ignorePadding(); scrollText.ignorePadding();
scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1}); scrollText.setGeometry (FPoint{1, 2}, FSize{getWidth(), getHeight() - 1});
@ -301,6 +301,7 @@ class MyDialog final : public finalcut::FDialog
void cb_copyClipboard (const finalcut::FWidget*, const FDataPtr); void cb_copyClipboard (const finalcut::FWidget*, const FDataPtr);
void cb_pasteClipboard (const finalcut::FWidget*, const FDataPtr); void cb_pasteClipboard (const finalcut::FWidget*, const FDataPtr);
void cb_clearInput (const finalcut::FWidget*, const FDataPtr); void cb_clearInput (const finalcut::FWidget*, const FDataPtr);
void cb_switchTheme (const finalcut::FWidget*, const FDataPtr);
void cb_input2buttonText (finalcut::FWidget*, FDataPtr); void cb_input2buttonText (finalcut::FWidget*, FDataPtr);
void cb_setTitlebar (finalcut::FWidget*, const FDataPtr); void cb_setTitlebar (finalcut::FWidget*, const FDataPtr);
void cb_showProgressBar (const finalcut::FWidget*, const FDataPtr); void cb_showProgressBar (const finalcut::FWidget*, const FDataPtr);
@ -339,6 +340,8 @@ class MyDialog final : public finalcut::FDialog
// "View" menu items // "View" menu items
finalcut::FMenuItem Env{"&Terminal...", &View}; finalcut::FMenuItem Env{"&Terminal...", &View};
finalcut::FMenuItem Drive{"&Drive symbols...", &View}; finalcut::FMenuItem Drive{"&Drive symbols...", &View};
finalcut::FMenuItem Line3{&View};
finalcut::FCheckMenuItem Theme{"Dark &mode", &View};
// Statusbar // Statusbar
finalcut::FStatusBar Statusbar{this}; finalcut::FStatusBar Statusbar{this};
finalcut::FStatusKey key_F1{fc::Fkey_f1, "About", &Statusbar}; finalcut::FStatusKey key_F1{fc::Fkey_f1, "About", &Statusbar};
@ -369,7 +372,7 @@ class MyDialog final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
MyDialog::MyDialog (finalcut::FWidget* parent) MyDialog::MyDialog (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
init(); init();
} }
@ -422,6 +425,10 @@ void MyDialog::initMenu()
// "View" menu items // "View" menu items
Env.setStatusbarMessage ("Informations about this terminal"); Env.setStatusbarMessage ("Informations about this terminal");
Drive.setStatusbarMessage ("Show drive symbols"); Drive.setStatusbarMessage ("Show drive symbols");
Line3.setSeparator();
if ( finalcut::FStartOptions::getFStartOptions().dark_theme )
Theme.setChecked();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -517,6 +524,12 @@ void MyDialog::initViewMenuCallbacks()
"clicked", "clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_drives) F_METHOD_CALLBACK (this, &MyDialog::cb_drives)
); );
Theme.addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &MyDialog::cb_switchTheme)
);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -810,12 +823,12 @@ void MyDialog::cb_terminfo (const finalcut::FWidget*, const FDataPtr)
( (
"Environment" "Environment"
, finalcut::FString{} , finalcut::FString{}
<< " Type: " << getTermType() << "\n" << " Type: " << finalcut::FTerm::getTermType() << "\n"
<< " Name: " << getTermFileName() << "\n" << " Name: " << finalcut::FTerm::getTermFileName() << "\n"
<< " Mode: " << getEncodingString() << "\n" << " Mode: " << finalcut::FTerm::getEncodingString() << "\n"
<< " Size: " << x << fc::Times << " Size: " << x << fc::Times
<< y << "\n" << y << "\n"
<< "Colors: " << getMaxColor() << "Colors: " << finalcut::FTerm::getMaxColor()
, finalcut::FMessageBox::Ok, 0, 0, this , finalcut::FMessageBox::Ok, 0, 0, this
); );
info1.setHeadline("Terminal:"); info1.setHeadline("Terminal:");
@ -834,7 +847,7 @@ void MyDialog::cb_drives (const finalcut::FWidget*, const FDataPtr)
, finalcut::FMessageBox::Ok, 0, 0, this , finalcut::FMessageBox::Ok, 0, 0, this
); );
if ( isNewFont() ) if ( finalcut::FTerm::isNewFont() )
{ {
finalcut::FLabel drive {finalcut::NF_Drive, &info2}; finalcut::FLabel drive {finalcut::NF_Drive, &info2};
drive.setGeometry (FPoint{11, 2}, FSize{4, 1}); drive.setGeometry (FPoint{11, 2}, FSize{4, 1});
@ -853,7 +866,7 @@ void MyDialog::cb_drives (const finalcut::FWidget*, const FDataPtr)
finalcut::FLabel cd {" CD ", &info2}; finalcut::FLabel cd {" CD ", &info2};
cd.setGeometry (FPoint{11, 6}, FSize{4, 1}); cd.setGeometry (FPoint{11, 6}, FSize{4, 1});
if ( isMonochron() ) if ( finalcut::FTerm::isMonochron() )
{ {
net.setReverseMode(); net.setReverseMode();
drive.setReverseMode(); drive.setReverseMode();
@ -902,6 +915,21 @@ void MyDialog::cb_clearInput (const finalcut::FWidget*, const FDataPtr)
myLineEdit.redraw(); myLineEdit.redraw();
} }
//----------------------------------------------------------------------
void MyDialog::cb_switchTheme (const finalcut::FWidget* widget, const FDataPtr)
{
const auto& check_menu = *(static_cast<const finalcut::FCheckMenuItem*>(widget));
if ( check_menu.isChecked() )
finalcut::FApplication::setDarkTheme();
else
finalcut::FApplication::setDefaultTheme();
auto root_widget = getRootWidget();
root_widget->resetColors();
root_widget->redraw();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void MyDialog::cb_input2buttonText (finalcut::FWidget* widget, FDataPtr data) void MyDialog::cb_input2buttonText (finalcut::FWidget* widget, FDataPtr data)
{ {
@ -917,7 +945,7 @@ void MyDialog::cb_setTitlebar (finalcut::FWidget* widget, const FDataPtr)
auto& lineedit = *(static_cast<finalcut::FLineEdit*>(widget)); auto& lineedit = *(static_cast<finalcut::FLineEdit*>(widget));
finalcut::FString title{}; finalcut::FString title{};
lineedit >> title; lineedit >> title;
setTermTitle (title); finalcut::FTerm::setTermTitle (title);
setText (title); setText (title);
redraw(); redraw();
} }
@ -981,7 +1009,7 @@ void MyDialog::cb_view (const finalcut::FWidget*, FDataPtr data)
int(getRootWidget()->getHeight() / 6) } int(getRootWidget()->getHeight() / 6) }
, FSize{60, getRootWidget()->getHeight() * 3 / 4} ); , FSize{60, getRootWidget()->getHeight() * 3 / 4} );
view->setResizeable(); view->setResizeable();
std::string line = ""; std::string line{""};
std::ifstream infile; std::ifstream infile;
infile.open(file); infile.open(file);
@ -1021,17 +1049,17 @@ int main (int argc, char* argv[])
// Create the application object app // Create the application object app
finalcut::FApplication app{argc, argv}; finalcut::FApplication app{argc, argv};
app.setNonBlockingRead(); app.setNonBlockingRead();
app.redefineDefaultColors(true); finalcut::FTerm::redefineDefaultColors(true);
app.setTermTitle (title); finalcut::FTerm::setTermTitle (title);
// Force vt100 encoding // Force vt100 encoding
//app.setEncoding(finalcut::fc::VT100); //finalcut::FTerm::setEncoding(finalcut::fc::VT100);
// Sets the terminal size to 94×30 // Sets the terminal size to 94×30
//app.setTermSize(94,30); //finalcut::FTerm::setTermSize(FSize{94, 30});
// Enable the final cut graphical font // Enable the final cut graphical font
//app.setNewFont(); //finalcut::FTerm::setNewFont();
// Create main dialog object d // Create main dialog object d
MyDialog d{&app}; MyDialog d{&app};

View File

@ -73,7 +73,7 @@ class Watch final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Watch::Watch (FWidget* parent) Watch::Watch (FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
// Dialog settings // Dialog settings
// Avoids calling a virtual function from the constructor // Avoids calling a virtual function from the constructor

View File

@ -66,32 +66,32 @@ class SmallWindow final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
SmallWindow::SmallWindow (finalcut::FWidget* parent) SmallWindow::SmallWindow (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
const wchar_t arrow_up = fc::BlackUpPointingTriangle; const wchar_t arrow_up = fc::BlackUpPointingTriangle;
const wchar_t arrow_down = fc::BlackDownPointingTriangle; const wchar_t arrow_down = fc::BlackDownPointingTriangle;
left_arrow = arrow_up; left_arrow = arrow_up;
left_arrow.setForegroundColor (wc.label_inactive_fg); left_arrow.setForegroundColor (wc->label_inactive_fg);
left_arrow.setEmphasis(); left_arrow.setEmphasis();
left_arrow.ignorePadding(); left_arrow.ignorePadding();
left_arrow.setGeometry (FPoint{2, 2}, FSize{1, 1}); left_arrow.setGeometry (FPoint{2, 2}, FSize{1, 1});
right_arrow = arrow_up; right_arrow = arrow_up;
right_arrow.setForegroundColor (wc.label_inactive_fg); right_arrow.setForegroundColor (wc->label_inactive_fg);
right_arrow.setEmphasis(); right_arrow.setEmphasis();
right_arrow.ignorePadding(); right_arrow.ignorePadding();
right_arrow.setGeometry (FPoint{int(getWidth()) - 1, 2}, FSize{1, 1}); right_arrow.setGeometry (FPoint{int(getWidth()) - 1, 2}, FSize{1, 1});
top_left_label = "menu"; top_left_label = "menu";
top_left_label.setForegroundColor (wc.label_inactive_fg); top_left_label.setForegroundColor (wc->label_inactive_fg);
top_left_label.setEmphasis(); top_left_label.setEmphasis();
top_left_label.setGeometry (FPoint{1, 1}, FSize{6, 1}); top_left_label.setGeometry (FPoint{1, 1}, FSize{6, 1});
top_right_label = "zoom"; top_right_label = "zoom";
top_right_label.setAlignment (fc::alignRight); top_right_label.setAlignment (fc::alignRight);
top_right_label.setForegroundColor (wc.label_inactive_fg); top_right_label.setForegroundColor (wc->label_inactive_fg);
top_right_label.setEmphasis(); top_right_label.setEmphasis();
top_right_label.setGeometry (FPoint{int(getClientWidth()) - 5, 1}, FSize{6, 1}); top_right_label.setGeometry (FPoint{int(getClientWidth()) - 5, 1}, FSize{6, 1});
@ -100,7 +100,7 @@ SmallWindow::SmallWindow (finalcut::FWidget* parent)
bottom_label_text += arrow_down; bottom_label_text += arrow_down;
bottom_label = bottom_label_text; bottom_label = bottom_label_text;
bottom_label.setAlignment (fc::alignRight); bottom_label.setAlignment (fc::alignRight);
bottom_label.setForegroundColor (wc.label_inactive_fg); bottom_label.setForegroundColor (wc->label_inactive_fg);
bottom_label.setEmphasis(); bottom_label.setEmphasis();
bottom_label.setGeometry (FPoint{13, 3}, FSize{6, 3}); bottom_label.setGeometry (FPoint{13, 3}, FSize{6, 3});
} }
@ -240,7 +240,7 @@ class Window final : public finalcut::FDialog
//---------------------------------------------------------------------- //----------------------------------------------------------------------
Window::Window (finalcut::FWidget* parent) Window::Window (finalcut::FWidget* parent)
: finalcut::FDialog(parent) : finalcut::FDialog{parent}
{ {
// Menu bar item // Menu bar item
File.setStatusbarMessage ("File management commands"); File.setStatusbarMessage ("File management commands");

View File

@ -10,6 +10,7 @@ lib_LTLIBRARIES = libfinal.la
libfinal_la_SOURCES = \ libfinal_la_SOURCES = \
fstring.cpp \ fstring.cpp \
fstringstream.cpp \
fpoint.cpp \ fpoint.cpp \
fsize.cpp \ fsize.cpp \
frect.cpp \ frect.cpp \
@ -25,6 +26,8 @@ libfinal_la_SOURCES = \
flabel.cpp \ flabel.cpp \
flistbox.cpp \ flistbox.cpp \
flistview.cpp \ flistview.cpp \
flog.cpp \
flogger.cpp \
fmenu.cpp \ fmenu.cpp \
fmouse.cpp \ fmouse.cpp \
fsystem.cpp \ fsystem.cpp \
@ -67,6 +70,7 @@ libfinal_la_SOURCES = \
foptimove.cpp \ foptimove.cpp \
ftermbuffer.cpp \ ftermbuffer.cpp \
fapplication.cpp \ fapplication.cpp \
fcolorpalette.cpp \
fwidgetcolors.cpp \ fwidgetcolors.cpp \
fwidget.cpp \ fwidget.cpp \
fwidget_functions.cpp \ fwidget_functions.cpp \
@ -98,6 +102,8 @@ finalcutinclude_HEADERS = \
include/final/flineedit.h \ include/final/flineedit.h \
include/final/flistbox.h \ include/final/flistbox.h \
include/final/flistview.h \ include/final/flistview.h \
include/final/flog.h \
include/final/flogger.h \
include/final/fmenu.h \ include/final/fmenu.h \
include/final/fmouse.h \ include/final/fmouse.h \
include/final/fkeyboard.h \ include/final/fkeyboard.h \
@ -126,6 +132,7 @@ finalcutinclude_HEADERS = \
include/final/fstartoptions.h \ include/final/fstartoptions.h \
include/final/fstatusbar.h \ include/final/fstatusbar.h \
include/final/fstring.h \ include/final/fstring.h \
include/final/fstringstream.h \
include/final/fsystem.h \ include/final/fsystem.h \
include/final/fsystemimpl.h \ include/final/fsystemimpl.h \
include/final/ftermcap.h \ include/final/ftermcap.h \

View File

@ -25,6 +25,8 @@ INCLUDE_HEADERS = \
flineedit.h \ flineedit.h \
flistbox.h \ flistbox.h \
flistview.h \ flistview.h \
flog.h \
flogger.h \
fmenu.h \ fmenu.h \
fdialoglistmenu.h \ fdialoglistmenu.h \
fmenubar.h \ fmenubar.h \
@ -49,6 +51,7 @@ INCLUDE_HEADERS = \
fcombobox.h \ fcombobox.h \
fstatusbar.h \ fstatusbar.h \
fstring.h \ fstring.h \
fstringstream.h \
fmouse.h \ fmouse.h \
fkeyboard.h \ fkeyboard.h \
fstartoptions.h \ fstartoptions.h \
@ -83,6 +86,7 @@ RM = rm -f
LIB = libfinal.so LIB = libfinal.so
OBJS = \ OBJS = \
fstring.o \ fstring.o \
fstringstream.o \
fpoint.o \ fpoint.o \
fsize.o \ fsize.o \
frect.o \ frect.o \
@ -98,6 +102,8 @@ OBJS = \
flabel.o \ flabel.o \
flistbox.o \ flistbox.o \
flistview.o \ flistview.o \
flog.o \
flogger.o \
fmenu.o \ fmenu.o \
fdialoglistmenu.o \ fdialoglistmenu.o \
fmenubar.o \ fmenubar.o \
@ -139,6 +145,7 @@ OBJS = \
foptimove.o \ foptimove.o \
ftermbuffer.o \ ftermbuffer.o \
fapplication.o \ fapplication.o \
fcolorpalette.o \
fwidgetcolors.o \ fwidgetcolors.o \
fwidget.o \ fwidget.o \
fwidget_functions.o \ fwidget_functions.o \

View File

@ -25,6 +25,8 @@ INCLUDE_HEADERS = \
flineedit.h \ flineedit.h \
flistbox.h \ flistbox.h \
flistview.h \ flistview.h \
flog.h \
flogger.h \
fmenu.h \ fmenu.h \
fdialoglistmenu.h \ fdialoglistmenu.h \
fmenubar.h \ fmenubar.h \
@ -49,6 +51,7 @@ INCLUDE_HEADERS = \
fcombobox.h \ fcombobox.h \
fstatusbar.h \ fstatusbar.h \
fstring.h \ fstring.h \
fstringstream.h \
fmouse.h \ fmouse.h \
fkeyboard.h \ fkeyboard.h \
fstartoptions.h \ fstartoptions.h \
@ -83,6 +86,7 @@ RM = rm -f
LIB = libfinal.so LIB = libfinal.so
OBJS = \ OBJS = \
fstring.o \ fstring.o \
fstringstream.o \
fpoint.o \ fpoint.o \
fsize.o \ fsize.o \
frect.o \ frect.o \
@ -98,6 +102,8 @@ OBJS = \
flabel.o \ flabel.o \
flistbox.o \ flistbox.o \
flistview.o \ flistview.o \
flog.o \
flogger.o \
fmenu.o \ fmenu.o \
fdialoglistmenu.o \ fdialoglistmenu.o \
fmenubar.o \ fmenubar.o \
@ -139,6 +145,7 @@ OBJS = \
foptimove.o \ foptimove.o \
ftermbuffer.o \ ftermbuffer.o \
fapplication.o \ fapplication.o \
fcolorpalette.o \
fwidgetcolors.o \ fwidgetcolors.o \
fwidget.o \ fwidget.o \
fwidget_functions.o \ fwidget_functions.o \

View File

@ -25,6 +25,8 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flog.h"
#include "final/flogger.h"
#include "final/fmenu.h" #include "final/fmenu.h"
#include "final/fmenubar.h" #include "final/fmenubar.h"
#include "final/fmessagebox.h" #include "final/fmessagebox.h"
@ -69,7 +71,7 @@ bool FApplication::quit_now {false};
FApplication::FApplication ( const int& _argc FApplication::FApplication ( const int& _argc
, char* _argv[] , char* _argv[]
, bool disable_alt_screen ) , bool disable_alt_screen )
: FWidget(processParameters(_argc, _argv), disable_alt_screen) : FWidget{processParameters(_argc, _argv), disable_alt_screen}
, app_argc{_argc} , app_argc{_argc}
, app_argv{_argv} , app_argv{_argv}
{ {
@ -98,6 +100,11 @@ FApplication::FApplication ( const int& _argc
FApplication::~FApplication() // destructor FApplication::~FApplication() // destructor
{ {
app_object = nullptr; app_object = nullptr;
if ( eventInQueue() )
event_queue.clear();
destroyLog();
} }
@ -108,6 +115,24 @@ FApplication* FApplication::getApplicationObject()
return app_object; return app_object;
} }
//----------------------------------------------------------------------
FApplication::FLogPtr& FApplication::getLog()
{
// Global logger object
static FLogPtr* logger = new FLogPtr();
if ( logger && logger->get() == nullptr )
*logger = std::make_shared<FLogger>();
return *logger;
}
//----------------------------------------------------------------------
void FApplication::setLog (const FLogPtr& logger)
{
getLog() = logger;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FApplication::isQuit() bool FApplication::isQuit()
{ {
@ -167,25 +192,27 @@ void FApplication::quit()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FApplication::sendEvent (FObject* receiver, FEvent* event ) bool FApplication::sendEvent (FObject* receiver, FEvent* event )
{ {
if ( quit_now || app_exit_loop || ! receiver ) if ( quit_now || app_exit_loop || ! (bool(receiver) && bool(event)) )
return false; return false;
if ( ! isEventProcessable (receiver, event) ) if ( ! isEventProcessable (receiver, event) )
return false; return false;
// Sends the event event directly to receiver // Sends the event event directly to receiver
return receiver->event(event); bool ret = receiver->event(event);
event->send = true;
return ret;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FApplication::queueEvent (FObject* receiver, FEvent* event) void FApplication::queueEvent (FObject* receiver, FEvent* event)
{ {
if ( ! receiver ) if ( ! (bool(receiver) && bool(event)) )
return; return;
// queue this event // queue this event
eventPair send_event (receiver, std::make_shared<FEvent>(*event)); event->queued = true;
event_queue.push_back(send_event); event_queue.emplace_back (receiver, event);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -193,8 +220,9 @@ void FApplication::sendQueuedEvents()
{ {
while ( eventInQueue() ) while ( eventInQueue() )
{ {
sendEvent( event_queue.front().first, const EventPair& event_pair = event_queue.front();
event_queue.front().second.get() ); event_pair.second->queued = false;
sendEvent(event_pair.first, event_pair.second);
event_queue.pop_front(); event_queue.pop_front();
} }
} }
@ -234,6 +262,12 @@ bool FApplication::removeQueuedEvent (const FObject* receiver)
return retval; return retval;
} }
//----------------------------------------------------------------------
void FApplication::processExternalUserEvent()
{
// This method can be overloaded and replaced by own code
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FWidget* FApplication::processParameters (const int& argc, char* argv[]) FWidget* FApplication::processParameters (const int& argc, char* argv[])
{ {
@ -248,6 +282,37 @@ FWidget* FApplication::processParameters (const int& argc, char* argv[])
return nullptr; return nullptr;
} }
//----------------------------------------------------------------------
void FApplication::setDefaultTheme()
{
if ( FTerm::getMaxColor() < 16 ) // for 8 color mode
{
if ( getStartOptions().color_change )
FTerm::setColorPaletteTheme<default8ColorPalette>(&FTerm::setPalette);
setColorTheme<default8ColorTheme>();
}
else
{
if ( getStartOptions().color_change )
FTerm::setColorPaletteTheme<default16ColorPalette>(&FTerm::setPalette);
setColorTheme<default16ColorTheme>();
}
}
//----------------------------------------------------------------------
void FApplication::setDarkTheme()
{
if ( getStartOptions().color_change )
FTerm::setColorPaletteTheme<default16DarkColorPalette>(&FTerm::setPalette);
if ( FTerm::getMaxColor() < 16 ) // for 8 color mode
setColorTheme<default8ColorDarkTheme>();
else
setColorTheme<default16ColorDarkTheme>();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FApplication::showParameterUsage() void FApplication::showParameterUsage()
{ {
@ -277,6 +342,8 @@ void FApplication::showParameterUsage()
<< " Set the standard vga 8x16 font\n" << " Set the standard vga 8x16 font\n"
<< " --newfont " << " --newfont "
<< " Enables the graphical font\n" << " Enables the graphical font\n"
<< " --dark-theme "
<< " Enables the dark theme\n"
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
<< "\n" << "\n"
@ -322,7 +389,7 @@ void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev)
void FApplication::init (uInt64 key_time, uInt64 dblclick_time) void FApplication::init (uInt64 key_time, uInt64 dblclick_time)
{ {
// Initialize keyboard // Initialize keyboard
keyboard = FVTerm::getFKeyboard(); keyboard = FTerm::getFKeyboard();
// Set the keyboard keypress timeout // Set the keyboard keypress timeout
if ( keyboard ) if ( keyboard )
@ -340,7 +407,7 @@ void FApplication::init (uInt64 key_time, uInt64 dblclick_time)
} }
// Initialize mouse control // Initialize mouse control
mouse = FVTerm::getFMouseControl(); mouse = FTerm::getFMouseControl();
// Set stdin number for a gpm-mouse // Set stdin number for a gpm-mouse
if ( mouse ) if ( mouse )
@ -349,6 +416,9 @@ void FApplication::init (uInt64 key_time, uInt64 dblclick_time)
// Set the default double click interval // Set the default double click interval
if ( mouse ) if ( mouse )
mouse->setDblclickInterval (dblclick_time); mouse->setDblclickInterval (dblclick_time);
// Initialize logging
getLog()->setLineEnding(FLog::CRLF);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -369,6 +439,7 @@ void FApplication::cmd_options (const int& argc, char* argv[])
{"no-sgr-optimizer", no_argument, nullptr, 0 }, {"no-sgr-optimizer", no_argument, nullptr, 0 },
{"vgafont", no_argument, nullptr, 0 }, {"vgafont", no_argument, nullptr, 0 },
{"newfont", no_argument, nullptr, 0 }, {"newfont", no_argument, nullptr, 0 },
{"dark-theme", no_argument, nullptr, 0 },
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
{"no-esc-for-alt-meta", no_argument, nullptr, 0 }, {"no-esc-for-alt-meta", no_argument, nullptr, 0 },
@ -405,7 +476,7 @@ void FApplication::cmd_options (const int& argc, char* argv[])
else if ( encoding.includes("help") ) else if ( encoding.includes("help") )
showParameterUsage(); showParameterUsage();
else else
exitWithMessage ( "Unknown encoding " FTerm::exitWithMessage ( "Unknown encoding "
+ std::string(encoding.c_str()) ); + std::string(encoding.c_str()) );
} }
@ -433,6 +504,9 @@ void FApplication::cmd_options (const int& argc, char* argv[])
if ( std::strcmp(long_options[idx].name, "newfont") == 0 ) if ( std::strcmp(long_options[idx].name, "newfont") == 0 )
getStartOptions().newfont = true; getStartOptions().newfont = true;
if ( std::strcmp(long_options[idx].name, "dark-theme") == 0 )
getStartOptions().dark_theme = true;
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)
if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 ) if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 )
getStartOptions().meta_sends_escape = false; getStartOptions().meta_sends_escape = false;
@ -453,6 +527,13 @@ inline FStartOptions& FApplication::getStartOptions()
return FStartOptions::getFStartOptions(); return FStartOptions::getFStartOptions();
} }
//----------------------------------------------------------------------
inline void FApplication::destroyLog()
{
const FLogPtr* logger = &(getLog());
delete logger;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FApplication::findKeyboardWidget() inline void FApplication::findKeyboardWidget()
{ {
@ -985,7 +1066,7 @@ void FApplication::sendMouseMiddleClickEvent ( const FPoint& widgetMousePos
sendEvent (clicked, &m_down_ev); sendEvent (clicked, &m_down_ev);
// gnome-terminal sends no released on middle click // gnome-terminal sends no released on middle click
if ( isGnomeTerminal() ) if ( FTerm::isGnomeTerminal() )
setClickedWidget(nullptr); setClickedWidget(nullptr);
} }
else if ( mouse->isMiddleButtonReleased() ) else if ( mouse->isMiddleButtonReleased() )
@ -1057,7 +1138,7 @@ void FApplication::processMouseEvent()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FApplication::processResizeEvent() void FApplication::processResizeEvent()
{ {
if ( ! hasChangedTermSize() ) if ( ! FTerm::hasChangedTermSize() )
return; return;
if ( mouse ) if ( mouse )
@ -1070,7 +1151,7 @@ void FApplication::processResizeEvent()
sendEvent(app_object, &r_ev); sendEvent(app_object, &r_ev);
if ( r_ev.isAccepted() ) if ( r_ev.isAccepted() )
changeTermSizeFinished(); FTerm::changeTermSizeFinished();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1094,6 +1175,17 @@ void FApplication::processCloseWidget()
setTerminalUpdates (FVTerm::start_terminal_updates); setTerminalUpdates (FVTerm::start_terminal_updates);
} }
//----------------------------------------------------------------------
void FApplication::processLogger()
{
// Synchronizing the stream buffer with the logging output
auto logger = getLog();
if ( ! logger->str().empty() )
logger->pubsync();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FApplication::processNextEvent() bool FApplication::processNextEvent()
{ {
@ -1104,6 +1196,8 @@ bool FApplication::processNextEvent()
processResizeEvent(); processResizeEvent();
processTerminalUpdate(); processTerminalUpdate();
processCloseWidget(); processCloseWidget();
processLogger();
processExternalUserEvent();
sendQueuedEvents(); sendQueuedEvents();
num_events += processTimerEvent(); num_events += processTimerEvent();
@ -1118,7 +1212,8 @@ void FApplication::performTimerAction (FObject* receiver, FEvent* event)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FApplication::isEventProcessable (const FObject* receiver, const FEvent* event ) bool FApplication::isEventProcessable ( const FObject* receiver
, const FEvent* event )
{ {
if ( ! receiver->isWidget() ) // No restrictions for non-widgets if ( ! receiver->isWidget() ) // No restrictions for non-widgets
return true; return true;
@ -1139,7 +1234,7 @@ bool FApplication::isEventProcessable (const FObject* receiver, const FEvent* ev
&& ! window->getFlags().modal && ! window->getFlags().modal
&& ! window->isMenuWidget() ) && ! window->isMenuWidget() )
{ {
switch ( uInt(event->type()) ) switch ( uInt(event->getType()) )
{ {
case fc::KeyPress_Event: case fc::KeyPress_Event:
case fc::KeyUp_Event: case fc::KeyUp_Event:
@ -1163,8 +1258,8 @@ bool FApplication::isEventProcessable (const FObject* receiver, const FEvent* ev
} }
// Throw away mouse events for disabled widgets // Throw away mouse events for disabled widgets
if ( event->type() >= fc::MouseDown_Event if ( event->getType() >= fc::MouseDown_Event
&& event->type() <= fc::MouseMove_Event && event->getType() <= fc::MouseMove_Event
&& ! widget->isEnabled() ) && ! widget->isEnabled() )
return false; return false;

View File

@ -36,14 +36,14 @@ namespace finalcut
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FButton::FButton(FWidget* parent) FButton::FButton(FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FButton::FButton (const FString& txt, FWidget* parent) FButton::FButton (const FString& txt, FWidget* parent)
: FWidget(parent) : FWidget{parent}
, text{txt} , text{txt}
{ {
init(); init();
@ -127,6 +127,20 @@ void FButton::setInactiveBackgroundColor (FColor color)
updateButtonColor(); updateButtonColor();
} }
//----------------------------------------------------------------------
void FButton::resetColors()
{
const auto& wc = getColorTheme();
setForegroundColor (wc->button_active_fg);
setBackgroundColor (wc->button_active_bg);
setHotkeyForegroundColor (wc->button_hotkey_fg);
setFocusForegroundColor (wc->button_active_focus_fg);
setFocusBackgroundColor (wc->button_active_focus_bg);
setInactiveForegroundColor (wc->button_inactive_fg);
setInactiveBackgroundColor (wc->button_inactive_bg);
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FButton::setNoUnderline (bool enable) bool FButton::setNoUnderline (bool enable)
{ {
@ -165,8 +179,8 @@ bool FButton::setFlat (bool enable)
bool FButton::setShadow (bool enable) bool FButton::setShadow (bool enable)
{ {
if ( enable if ( enable
&& getEncoding() != fc::VT100 && FTerm::getEncoding() != fc::VT100
&& getEncoding() != fc::ASCII ) && FTerm::getEncoding() != fc::ASCII )
{ {
setFlags().shadow = true; setFlags().shadow = true;
setShadowSize(FSize{1, 1}); setShadowSize(FSize{1, 1});
@ -218,9 +232,9 @@ void FButton::hide()
} }
else else
{ {
auto wc = getFWidgetColors(); const auto& wc = getColorTheme();
fg = wc.dialog_fg; fg = wc->dialog_fg;
bg = wc.dialog_bg; bg = wc->dialog_bg;
} }
setColor (fg, bg); setColor (fg, bg);
@ -387,9 +401,9 @@ void FButton::onFocusOut (FFocusEvent*)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButton::init() void FButton::init()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setForegroundColor (wc.button_active_fg); setForegroundColor (wc->button_active_fg);
setBackgroundColor (wc.button_active_bg); setBackgroundColor (wc->button_active_bg);
setShadow(); setShadow();
if ( ! text.isEmpty() ) if ( ! text.isEmpty() )
@ -439,7 +453,7 @@ inline std::size_t FButton::clickAnimationIndent (const FWidget* parent_widget)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FButton::clearRightMargin (const FWidget* parent_widget) inline void FButton::clearRightMargin (const FWidget* parent_widget)
{ {
if ( button_down || isNewFont() ) if ( button_down || FTerm::isNewFont() )
return; return;
// Restore the right background after button down // Restore the right background after button down
@ -449,12 +463,12 @@ inline void FButton::clearRightMargin (const FWidget* parent_widget)
for (int y{1}; y <= int(getHeight()); y++) for (int y{1}; y <= int(getHeight()); y++)
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); // Light background setReverse(true); // Light background
print() << FPoint{1 + int(getWidth()), y} << ' '; // clear right print() << FPoint{1 + int(getWidth()), y} << ' '; // clear right
if ( getFlags().active && isMonochron() ) if ( getFlags().active && FTerm::isMonochron() )
setReverse(false); // Dark background setReverse(false); // Dark background
} }
} }
@ -470,7 +484,7 @@ inline void FButton::drawMarginLeft()
{ {
print() << FPoint{1 + int(indent), 1 + int(y)}; print() << FPoint{1 + int(indent), 1 + int(y)};
if ( isMonochron() && active_focus && y == vcenter_offset ) if ( FTerm::isMonochron() && active_focus && y == vcenter_offset )
print (fc::BlackRightPointingPointer); // ► print (fc::BlackRightPointingPointer); // ►
else else
print (space_char); // full block █ print (space_char); // full block █
@ -486,7 +500,7 @@ inline void FButton::drawMarginRight()
{ {
print() << FPoint{int(getWidth() + indent), 1 + int(y)}; print() << FPoint{int(getWidth() + indent), 1 + int(y)};
if ( isMonochron() && active_focus && y == vcenter_offset ) if ( FTerm::isMonochron() && active_focus && y == vcenter_offset )
print (fc::BlackLeftPointingPointer); // ◄ print (fc::BlackLeftPointingPointer); // ◄
else else
print (space_char); // full block █ print (space_char); // full block █
@ -543,10 +557,10 @@ inline void FButton::drawButtonTextLine (const FString& button_text)
setCursorPos ({ 2 + int(center_offset + hotkeypos) setCursorPos ({ 2 + int(center_offset + hotkeypos)
, 1 + int(vcenter_offset) }); // hotkey , 1 + int(vcenter_offset) }); // hotkey
if ( ! getFlags().active && isMonochron() ) if ( ! getFlags().active && FTerm::isMonochron() )
setReverse(true); // Light background setReverse(true); // Light background
if ( active_focus && (isMonochron() || getMaxColor() < 16) ) if ( active_focus && (FTerm::isMonochron() || FTerm::getMaxColor() < 16) )
setBold(); setBold();
while ( pos < center_offset + column_width && columns + 2 < getWidth() ) while ( pos < center_offset + column_width && columns + 2 < getWidth() )
@ -555,7 +569,7 @@ inline void FButton::drawButtonTextLine (const FString& button_text)
{ {
setColor (button_hotkey_fg, button_bg); setColor (button_hotkey_fg, button_bg);
if ( ! active_focus && getMaxColor() < 16 ) if ( ! active_focus && FTerm::getMaxColor() < 16 )
setBold(); setBold();
if ( ! getFlags().no_underline ) if ( ! getFlags().no_underline )
@ -563,7 +577,7 @@ inline void FButton::drawButtonTextLine (const FString& button_text)
print (button_text[z]); print (button_text[z]);
if ( ! active_focus && getMaxColor() < 16 ) if ( ! active_focus && FTerm::getMaxColor() < 16 )
unsetBold(); unsetBold();
if ( ! getFlags().no_underline ) if ( ! getFlags().no_underline )
@ -588,7 +602,7 @@ inline void FButton::drawButtonTextLine (const FString& button_text)
print() << FPoint{int(getWidth() + indent) - 2, 1} << ".."; print() << FPoint{int(getWidth() + indent) - 2, 1} << "..";
} }
if ( active_focus && (isMonochron() || getMaxColor() < 16) ) if ( active_focus && (FTerm::isMonochron() || FTerm::getMaxColor() < 16) )
unsetBold(); unsetBold();
for (pos = center_offset + column_width; pos < getWidth() - 2; pos++) for (pos = center_offset + column_width; pos < getWidth() - 2; pos++)
@ -604,7 +618,7 @@ void FButton::draw()
space_char = int(' '); space_char = int(' ');
active_focus = getFlags().active && getFlags().focus; active_focus = getFlags().active && getFlags().focus;
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); // Light background setReverse(true); // Light background
// Click animation preprocessing // Click animation preprocessing
@ -613,10 +627,10 @@ void FButton::draw()
// Clear right margin after animation // Clear right margin after animation
clearRightMargin (parent_widget); clearRightMargin (parent_widget);
if ( ! getFlags().active && isMonochron() ) if ( ! getFlags().active && FTerm::isMonochron() )
space_char = fc::MediumShade; // ▒ simulates greyed out at Monochron space_char = fc::MediumShade; // ▒ simulates greyed out at Monochron
if ( isMonochron() && (getFlags().active || getFlags().focus) ) if ( FTerm::isMonochron() && (getFlags().active || getFlags().focus) )
setReverse(false); // Dark background setReverse(false); // Dark background
if ( getFlags().flat && ! button_down ) if ( getFlags().flat && ! button_down )
@ -648,7 +662,7 @@ void FButton::draw()
if ( ! getFlags().flat && getFlags().shadow && ! button_down ) if ( ! getFlags().flat && getFlags().shadow && ! button_down )
drawShadow(this); drawShadow(this);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); // Dark background setReverse(false); // Dark background
updateStatusBar(); updateStatusBar();

View File

@ -39,14 +39,14 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FButtonGroup::FButtonGroup(FWidget* parent) FButtonGroup::FButtonGroup(FWidget* parent)
: FScrollView(parent) : FScrollView{parent}
{ {
init(); init();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FButtonGroup::FButtonGroup (const FString& txt, FWidget* parent) FButtonGroup::FButtonGroup (const FString& txt, FWidget* parent)
: FScrollView(parent) : FScrollView{parent}
, text{txt} , text{txt}
{ {
init(); init();
@ -196,9 +196,9 @@ void FButtonGroup::hide()
} }
else else
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
fg = wc.dialog_fg; fg = wc->dialog_fg;
bg = wc.dialog_bg; bg = wc->dialog_bg;
} }
setColor (fg, bg); setColor (fg, bg);
@ -380,13 +380,13 @@ void FButtonGroup::setHotkeyAccelerator()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButtonGroup::draw() void FButtonGroup::draw()
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
setColor(); useParentWidgetColor();
clearArea(); clearArea();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
FScrollView::draw(); FScrollView::draw();
@ -427,9 +427,6 @@ bool FButtonGroup::isRadioButton (const FToggleButton* button) const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FButtonGroup::init() void FButtonGroup::init()
{ {
const auto& wc = getFWidgetColors();
setForegroundColor (wc.label_fg);
setBackgroundColor (wc.label_bg);
setMinimumSize (FSize{7, 3}); setMinimumSize (FSize{7, 3});
buttonlist.clear(); // no buttons yet buttonlist.clear(); // no buttons yet
} }
@ -438,7 +435,7 @@ void FButtonGroup::init()
void FButtonGroup::drawText ( const FString& label_text void FButtonGroup::drawText ( const FString& label_text
, std::size_t hotkeypos ) , std::size_t hotkeypos )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
const std::size_t column_width = getColumnWidth(label_text); const std::size_t column_width = getColumnWidth(label_text);
std::size_t length = label_text.getLength(); std::size_t length = label_text.getLength();
bool ellipsis{false}; bool ellipsis{false};
@ -451,19 +448,19 @@ void FButtonGroup::drawText ( const FString& label_text
ellipsis = true; ellipsis = true;
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
if ( isEnabled() ) if ( isEnabled() )
setColor(wc.label_emphasis_fg, wc.label_bg); setColor(wc->label_emphasis_fg, wc->label_bg);
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 < length; z++)
{ {
if ( (z == hotkeypos) && getFlags().active ) if ( (z == hotkeypos) && getFlags().active )
{ {
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg); setColor (wc->label_hotkey_fg, wc->label_hotkey_bg);
if ( ! getFlags().no_underline ) if ( ! getFlags().no_underline )
setUnderline(); setUnderline();
@ -473,16 +470,16 @@ void FButtonGroup::drawText ( const FString& label_text
if ( ! getFlags().no_underline ) if ( ! getFlags().no_underline )
unsetUnderline(); unsetUnderline();
setColor (wc.label_emphasis_fg, wc.label_bg); setColor (wc->label_emphasis_fg, wc->label_bg);
} }
else else
print (label_text[z]); print (label_text[z]);
} }
if ( ellipsis ) // Print ellipsis if ( ellipsis ) // Print ellipsis
print() << FColorPair {wc.label_ellipsis_fg, wc.label_bg} << ".."; print() << FColorPair {wc->label_ellipsis_fg, wc->label_bg} << "..";
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
} }

View File

@ -33,14 +33,14 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FCheckBox::FCheckBox(FWidget* parent) FCheckBox::FCheckBox(FWidget* parent)
: FToggleButton(parent) : FToggleButton{parent}
{ {
init(); init();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FCheckBox::FCheckBox (const FString& txt, FWidget* parent) FCheckBox::FCheckBox (const FString& txt, FWidget* parent)
: FToggleButton(txt, parent) : FToggleButton{txt, parent}
{ {
init(); init();
} }
@ -74,9 +74,9 @@ void FCheckBox::draw()
void FCheckBox::drawCheckButton() void FCheckBox::drawCheckButton()
{ {
print() << FPoint{1, 1}; print() << FPoint{1, 1};
setColor(); useParentWidgetColor();
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
if ( hasFocus() ) if ( hasFocus() )
setReverse(false); setReverse(false);
@ -89,14 +89,14 @@ void FCheckBox::drawCheckButton()
else else
drawUnchecked(); drawUnchecked();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FCheckBox::drawChecked() inline void FCheckBox::drawChecked()
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
print (CHECKBOX_ON); print (CHECKBOX_ON);
else else
{ {
@ -109,7 +109,7 @@ inline void FCheckBox::drawChecked()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FCheckBox::drawUnchecked() inline void FCheckBox::drawUnchecked()
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
print (CHECKBOX); print (CHECKBOX);
else else
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2015-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -34,14 +34,14 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FCheckMenuItem::FCheckMenuItem (FWidget* parent) FCheckMenuItem::FCheckMenuItem (FWidget* parent)
: FMenuItem(parent) : FMenuItem{parent}
{ {
init (parent); init (parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FCheckMenuItem::FCheckMenuItem (const FString& txt, FWidget* parent) FCheckMenuItem::FCheckMenuItem (const FString& txt, FWidget* parent)
: FMenuItem(txt, parent) : FMenuItem{txt, parent}
{ {
init (parent); init (parent);
} }

201
src/fcolorpalette.cpp Normal file
View File

@ -0,0 +1,201 @@
/***********************************************************************
* fcolorpalette.cpp - Define RGB color value for a palette entry *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 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/fcolorpalette.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FColorPalette
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FColorPalette::FColorPalette (const FSetPalette& f)
: set_palette{f}
{ }
//----------------------------------------------------------------------
FColorPalette::~FColorPalette() // destructor
{ }
// protected methods of FColorPalette
//----------------------------------------------------------------------
void FColorPalette::setPalette (FColor index, int r, int g, int b)
{
set_palette (index, r, g, b);
}
//----------------------------------------------------------------------
void FColorPalette::setVGAdefaultPalette()
{
setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x00, 0x00, 0xaa);
setPalette (fc::Green, 0x00, 0xaa, 0x00);
setPalette (fc::Cyan, 0x00, 0x55, 0xaa);
setPalette (fc::Red, 0xaa, 0x00, 0x00);
setPalette (fc::Magenta, 0xaa, 0x00, 0xaa);
setPalette (fc::Brown, 0xaa, 0xaa, 0x00);
setPalette (fc::LightGray, 0xaa, 0xaa, 0xaa);
setPalette (fc::DarkGray, 0x55, 0x55, 0x55);
setPalette (fc::LightBlue, 0x55, 0x55, 0xff);
setPalette (fc::LightGreen, 0x55, 0xff, 0x55);
setPalette (fc::LightCyan, 0x55, 0xff, 0xff);
setPalette (fc::LightRed, 0xff, 0x55, 0x55);
setPalette (fc::LightMagenta, 0xff, 0x55, 0xff);
setPalette (fc::Yellow, 0xff, 0xff, 0x55);
setPalette (fc::White, 0xff, 0xff, 0xff);
}
//----------------------------------------------------------------------
// class default8ColorPalette
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default8ColorPalette::default8ColorPalette (const FSetPalette& f)
: FColorPalette(f)
{ }
//----------------------------------------------------------------------
default8ColorPalette::~default8ColorPalette()
{ }
// public methods of default8ColorPalette
//----------------------------------------------------------------------
void default8ColorPalette::setColorPalette()
{
setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x10, 0x3b, 0x9e);
setPalette (fc::Green, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0xa0, 0xb2, 0xb2);
setPalette (fc::Red, 0xb2, 0x18, 0x18);
setPalette (fc::Magenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Brown, 0xe8, 0x87, 0x1f);
setPalette (fc::LightGray, 0xe0, 0xe0, 0xe0);
// The same colors again...
setPalette (fc::DarkGray, 0x00, 0x00, 0x00);
setPalette (fc::LightBlue, 0x10, 0x3b, 0x9e);
setPalette (fc::LightGreen, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0xa0, 0xb2, 0xb2);
setPalette (fc::LightRed, 0xb2, 0x18, 0x18);
setPalette (fc::LightMagenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Yellow, 0xe8, 0x87, 0x1f);
setPalette (fc::White, 0xe0, 0xe0, 0xe0);
}
//----------------------------------------------------------------------
void default8ColorPalette::resetColorPalette()
{
setVGAdefaultPalette();
}
//----------------------------------------------------------------------
// class default16ColorPalette
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default16ColorPalette::default16ColorPalette (const FSetPalette& f)
: FColorPalette(f)
{ }
//----------------------------------------------------------------------
default16ColorPalette::~default16ColorPalette()
{ }
// public methods of default8ColorPalette
//----------------------------------------------------------------------
void default16ColorPalette::setColorPalette()
{
setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x10, 0x3b, 0x9e);
setPalette (fc::Green, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0x55, 0x6a, 0xcf);
setPalette (fc::Red, 0xba, 0x1a, 0x1a);
setPalette (fc::Magenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Brown, 0xe8, 0x87, 0x1f);
setPalette (fc::LightGray, 0xbc, 0xbc, 0xbc);
setPalette (fc::DarkGray, 0x50, 0x50, 0x50);
setPalette (fc::LightBlue, 0x80, 0xa4, 0xec);
setPalette (fc::LightGreen, 0x5e, 0xeb, 0x5c);
setPalette (fc::LightCyan, 0x62, 0xbf, 0xf8);
setPalette (fc::LightRed, 0xee, 0x44, 0x44);
setPalette (fc::LightMagenta, 0xe9, 0xad, 0xff);
setPalette (fc::Yellow, 0xfb, 0xe8, 0x67);
setPalette (fc::White, 0xff, 0xff, 0xff);
}
//----------------------------------------------------------------------
void default16ColorPalette::resetColorPalette()
{
setVGAdefaultPalette();
}
//----------------------------------------------------------------------
// class default16DarkColorPalette
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default16DarkColorPalette::default16DarkColorPalette (const FSetPalette& f)
: FColorPalette(f)
{ }
//----------------------------------------------------------------------
default16DarkColorPalette::~default16DarkColorPalette()
{ }
// public methods of default8ColorPalette
//----------------------------------------------------------------------
void default16DarkColorPalette::setColorPalette()
{
setPalette (fc::Black, 0x00, 0x00, 0x00);
setPalette (fc::Blue, 0x41, 0x58, 0xb3);
setPalette (fc::Green, 0x18, 0x78, 0x18);
setPalette (fc::Cyan, 0x4e, 0x66, 0x72);
setPalette (fc::Red, 0xa5, 0x40, 0x40);
setPalette (fc::Magenta, 0xb2, 0x18, 0xb2);
setPalette (fc::Brown, 0xe8, 0x87, 0x1f);
setPalette (fc::LightGray, 0xd2, 0xd2, 0xd2);
setPalette (fc::DarkGray, 0x27, 0x33, 0x39);
setPalette (fc::LightBlue, 0xb0, 0xb0, 0xb8);
setPalette (fc::LightGreen, 0x5e, 0xeb, 0x5c);
setPalette (fc::LightCyan, 0x62, 0xbf, 0xf8);
setPalette (fc::LightRed, 0xdd, 0x51, 0x45);
setPalette (fc::LightMagenta, 0xe9, 0xad, 0xff);
setPalette (fc::Yellow, 0xfb, 0xe8, 0x67);
setPalette (fc::White, 0xff, 0xff, 0xff);
}
//----------------------------------------------------------------------
void default16DarkColorPalette::resetColorPalette()
{
setVGAdefaultPalette();
}
} // namespace finalcut

View File

@ -27,6 +27,7 @@
#include "final/flabel.h" #include "final/flabel.h"
#include "final/flineedit.h" #include "final/flineedit.h"
#include "final/flistbox.h" #include "final/flistbox.h"
#include "final/flog.h"
#include "final/fmouse.h" #include "final/fmouse.h"
#include "final/fpoint.h" #include "final/fpoint.h"
#include "final/fsize.h" #include "final/fsize.h"
@ -43,7 +44,7 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FDropDownListBox::FDropDownListBox (FWidget* parent) FDropDownListBox::FDropDownListBox (FWidget* parent)
: FWindow(parent) : FWindow{parent}
{ {
init(); init();
} }
@ -71,7 +72,7 @@ void FDropDownListBox::setGeometry ( const FPoint& pos, const FSize& size
{ {
FWindow::setGeometry (pos, size, adjust); FWindow::setGeometry (pos, size, adjust);
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
FSize new_size{size}; FSize new_size{size};
new_size.scaleBy(-1, 0); new_size.scaleBy(-1, 0);
@ -123,25 +124,25 @@ void FDropDownListBox::init()
void FDropDownListBox::draw() void FDropDownListBox::draw()
{ {
// Fill the background // Fill the background
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.menu_active_fg, wc.menu_active_bg); setColor (wc->menu_active_fg, wc->menu_active_bg);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
clearArea(); clearArea();
drawShadow(); drawShadow();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDropDownListBox::drawShadow() void FDropDownListBox::drawShadow()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
finalcut::drawShadow(this); finalcut::drawShadow(this);
setColor (wc.shadow_fg, wc.shadow_bg); setColor (wc->shadow_fg, wc->shadow_bg);
print() << FPoint{int(getWidth()) + 1, 1} << fc::FullBlock; // █ print() << FPoint{int(getWidth()) + 1, 1} << fc::FullBlock; // █
} }
@ -168,7 +169,7 @@ bool FDropDownListBox::containsWidget (const FPoint& p)
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FComboBox::FComboBox (FWidget* parent) FComboBox::FComboBox (FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
} }
@ -218,8 +219,8 @@ bool FComboBox::setFocus (bool enable)
bool FComboBox::setShadow (bool enable) bool FComboBox::setShadow (bool enable)
{ {
if ( enable if ( enable
&& getEncoding() != fc::VT100 && FTerm::getEncoding() != fc::VT100
&& getEncoding() != fc::ASCII ) && FTerm::getEncoding() != fc::ASCII )
{ {
setFlags().shadow = true; setFlags().shadow = true;
setShadowSize(FSize{1, 1}); setShadowSize(FSize{1, 1});
@ -494,7 +495,7 @@ void FComboBox::init()
adjustSize(); adjustSize();
initCallbacks(); initCallbacks();
if ( isNewFont() ) if ( FTerm::isNewFont() )
nf = 1; nf = 1;
} }
@ -532,22 +533,22 @@ void FComboBox::initCallbacks()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FComboBox::draw() void FComboBox::draw()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
const FColorPair button_color = [this, &wc] () const FColorPair button_color = [this, &wc] ()
{ {
if ( list_window.isEmpty() ) if ( list_window.isEmpty() )
return FColorPair { wc.scrollbar_button_inactive_fg return FColorPair { wc->scrollbar_button_inactive_fg
, wc.scrollbar_button_inactive_bg }; , wc->scrollbar_button_inactive_bg };
else else
return FColorPair { wc.scrollbar_button_fg return FColorPair { wc->scrollbar_button_fg
, wc.scrollbar_button_bg }; , wc->scrollbar_button_bg };
}(); }();
print() << FPoint{int(getWidth()) - nf, 1} print() << FPoint{int(getWidth()) - nf, 1}
<< button_color; << button_color;
if ( isNewFont() ) if ( FTerm::isNewFont() )
print() << NF_button_arrow_down; print() << NF_button_arrow_down;
else else
print() << fc::BlackDownPointingTriangle; // ▼ print() << fc::BlackDownPointingTriangle; // ▼
@ -605,9 +606,9 @@ void FComboBox::passEventToListWindow (FMouseEvent* const& ev)
list_window.list.setFocus(); list_window.list.setFocus();
list_window.list.onMouseMove(_ev.get()); list_window.list.onMouseMove(_ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
} }
} }
@ -643,7 +644,7 @@ void FComboBox::cb_closeComboBox (const FWidget*, const FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FComboBox::cb_inputFieldSwitch (const FWidget*, const FDataPtr) void FComboBox::cb_inputFieldSwitch (const FWidget*, const FDataPtr)
{ {
const auto& mouse = getFMouseControl(); const auto& mouse = FTerm::getFMouseControl();
if ( mouse && ! mouse->isLeftButtonPressed() ) if ( mouse && ! mouse->isLeftButtonPressed() )
return; return;
@ -675,7 +676,7 @@ void FComboBox::cb_inputFieldSwitch (const FWidget*, const FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FComboBox::cb_inputFieldHandOver (const FWidget*, const FDataPtr) void FComboBox::cb_inputFieldHandOver (const FWidget*, const FDataPtr)
{ {
const auto& mouse = getFMouseControl(); const auto& mouse = FTerm::getFMouseControl();
if ( ! mouse || list_window.isHidden() ) if ( ! mouse || list_window.isHidden() )
return; return;
@ -692,9 +693,9 @@ void FComboBox::cb_inputFieldHandOver (const FWidget*, const FDataPtr)
list_window.list.setFocus(); list_window.list.setFocus();
list_window.list.onMouseMove(_ev.get()); list_window.list.onMouseMove(_ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
} }
} }

View File

@ -42,15 +42,15 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FDialog::FDialog (FWidget* parent) FDialog::FDialog (FWidget* parent)
: FWindow(parent) : FWindow{parent}
{ {
init(); init();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FDialog::FDialog (const FString& txt, FWidget* parent) FDialog::FDialog (const FString& txt, FWidget* parent)
: FWindow(parent) : FWindow{parent}
, tb_text(txt) , tb_text{txt}
{ {
init(); init();
} }
@ -99,7 +99,7 @@ bool FDialog::setModal (bool enable)
if ( enable ) if ( enable )
{ {
setModalDialogCounter()++; setModalDialogCounter()++;
getFKeyboard()->clearKeyBuffer(); FTerm::getFKeyboard()->clearKeyBuffer();
} }
else else
setModalDialogCounter()--; setModalDialogCounter()--;
@ -136,6 +136,15 @@ bool FDialog::setBorder (bool enable)
return (setFlags().no_border = ! enable); return (setFlags().no_border = ! enable);
} }
//----------------------------------------------------------------------
void FDialog::resetColors()
{
const auto& wc = getColorTheme();
setForegroundColor (wc->dialog_fg);
setBackgroundColor (wc->dialog_bg);
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FDialog::setResizeable (bool enable) bool FDialog::setResizeable (bool enable)
{ {
@ -752,7 +761,7 @@ void FDialog::draw()
// Fill the background // Fill the background
setColor(); setColor();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
clearArea(); clearArea();
@ -763,14 +772,14 @@ void FDialog::draw()
if ( getFlags().shadow ) if ( getFlags().shadow )
drawDialogShadow(); drawDialogShadow();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::drawDialogShadow() void FDialog::drawDialogShadow()
{ {
if ( isMonochron() && ! getFlags().trans_shadow ) if ( FTerm::isMonochron() && ! getFlags().trans_shadow )
return; return;
drawShadow(this); drawShadow(this);
@ -800,9 +809,7 @@ void FDialog::init()
addDialog(this); addDialog(this);
setActiveWindow(this); setActiveWindow(this);
setTransparentShadow(); setTransparentShadow();
const auto& wc = getFWidgetColors(); resetColors();
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
auto old_focus = FWidget::getFocusWidget(); auto old_focus = FWidget::getFocusWidget();
if ( old_focus ) if ( old_focus )
@ -824,9 +831,9 @@ void FDialog::initDialogMenu()
{ {
dialog_menu = new FMenu ("-", this); dialog_menu = new FMenu ("-", this);
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMenu");
return; return;
} }
@ -854,9 +861,9 @@ void FDialog::initMoveSizeMenuItem (FMenu* menu)
{ {
move_size_item = new FMenuItem (menu); move_size_item = new FMenuItem (menu);
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMenuItem");
return; return;
} }
@ -877,9 +884,9 @@ void FDialog::initZoomMenuItem (FMenu* menu)
{ {
zoom_item = new FMenuItem (menu); zoom_item = new FMenuItem (menu);
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMenuItem");
return; return;
} }
@ -900,9 +907,9 @@ void FDialog::initCloseMenuItem (FMenu* menu)
{ {
close_item = new FMenuItem ("&Close", menu); close_item = new FMenuItem ("&Close", menu);
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMenuItem");
return; return;
} }
@ -924,13 +931,13 @@ void FDialog::drawBorder()
if ( (getMoveSizeWidget() == this || ! resize_click_pos.isOrigin() ) if ( (getMoveSizeWidget() == this || ! resize_click_pos.isOrigin() )
&& ! isZoomed() ) && ! isZoomed() )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.dialog_resize_fg, getBackgroundColor()); setColor (wc->dialog_resize_fg, getBackgroundColor());
} }
else else
setColor(); setColor();
if ( isNewFont() ) // Draw a newfont U-shaped frame if ( FTerm::isNewFont() ) // Draw a newfont U-shaped frame
{ {
const FRect r{FPoint{1, 1}, getSize()}; const FRect r{FPoint{1, 1}, getSize()};
@ -965,7 +972,7 @@ void FDialog::drawTitleBar()
// Draw the zoom/unzoom button // Draw the zoom/unzoom button
drawZoomButton(); drawZoomButton();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
#if DEBUG #if DEBUG
@ -983,14 +990,14 @@ void FDialog::drawBarButton()
{ {
// Print the title button // Print the title button
print() << FPoint{1, 1}; print() << FPoint{1, 1};
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( dialog_menu && dialog_menu->isShown() ) if ( dialog_menu && dialog_menu->isShown() )
setColor (wc.titlebar_button_focus_fg, wc.titlebar_button_focus_bg); setColor (wc->titlebar_button_focus_fg, wc->titlebar_button_focus_bg);
else else
setColor (wc.titlebar_button_fg, wc.titlebar_button_bg); setColor (wc->titlebar_button_fg, wc->titlebar_button_bg);
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
if ( isWindowActive() ) if ( isWindowActive() )
setReverse(false); setReverse(false);
@ -998,11 +1005,11 @@ void FDialog::drawBarButton()
setReverse(true); setReverse(true);
} }
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
print (finalcut::NF_menu_button); print (finalcut::NF_menu_button);
} }
else if ( isMonochron() ) else if ( FTerm::isMonochron() )
{ {
print ('['); print ('[');
@ -1034,12 +1041,12 @@ void FDialog::drawZoomButton()
if ( ! isResizeable() ) if ( ! isResizeable() )
return; return;
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( zoom_button_pressed ) if ( zoom_button_pressed )
setColor (wc.titlebar_button_focus_fg, wc.titlebar_button_focus_bg); setColor (wc->titlebar_button_focus_fg, wc->titlebar_button_focus_bg);
else else
setColor (wc.titlebar_button_fg, wc.titlebar_button_bg); setColor (wc->titlebar_button_fg, wc->titlebar_button_bg);
if ( isZoomed() ) if ( isZoomed() )
drawRestoreSizeButton(); drawRestoreSizeButton();
@ -1050,13 +1057,13 @@ void FDialog::drawZoomButton()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FDialog::drawRestoreSizeButton() inline void FDialog::drawRestoreSizeButton()
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
print (finalcut::NF_button_down); print (finalcut::NF_button_down);
} }
else else
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
print ('['); print ('[');
print (fc::BlackDownPointingTriangle); // ▼ print (fc::BlackDownPointingTriangle); // ▼
@ -1074,13 +1081,13 @@ inline void FDialog::drawRestoreSizeButton()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FDialog::drawZoomedButton() inline void FDialog::drawZoomedButton()
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
print (finalcut::NF_button_up); print (finalcut::NF_button_up);
} }
else else
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
print ('['); print ('[');
print (fc::BlackUpPointingTriangle); // ▲ print (fc::BlackUpPointingTriangle); // ▲
@ -1101,15 +1108,15 @@ void FDialog::drawTextBar()
// Fill with spaces (left of the title) // Fill with spaces (left of the title)
std::size_t center_offset{0}; std::size_t center_offset{0};
std::size_t x{1}; std::size_t x{1};
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( getMaxColor() < 16 ) if ( FTerm::getMaxColor() < 16 )
setBold(); setBold();
if ( isWindowActive() || (dialog_menu && dialog_menu->isShown()) ) if ( isWindowActive() || (dialog_menu && dialog_menu->isShown()) )
setColor (wc.titlebar_active_fg, wc.titlebar_active_bg); setColor (wc->titlebar_active_fg, wc->titlebar_active_bg);
else else
setColor (wc.titlebar_inactive_fg, wc.titlebar_inactive_bg); setColor (wc->titlebar_inactive_fg, wc->titlebar_inactive_bg);
const auto width = getWidth(); const auto width = getWidth();
const auto zoom_btn = getZoomButtonWidth(); const auto zoom_btn = getZoomButtonWidth();
@ -1138,7 +1145,7 @@ void FDialog::drawTextBar()
for ( ; x + 1 + length < width - zoom_btn - 1; x++) for ( ; x + 1 + length < width - zoom_btn - 1; x++)
print (' '); print (' ');
if ( getMaxColor() < 16 ) if ( FTerm::getMaxColor() < 16 )
unsetBold(); unsetBold();
} }
@ -1267,7 +1274,7 @@ inline std::size_t FDialog::getZoomButtonWidth()
{ {
if ( ! isResizeable() ) if ( ! isResizeable() )
return 0; return 0;
else if ( isNewFont() ) else if ( FTerm::isNewFont() )
return 2; return 2;
else else
return 3; return 3;
@ -1358,9 +1365,9 @@ inline void FDialog::passEventToSubMenu ( const mouseStates& ms
setClickedWidget(dialog_menu); setClickedWidget(dialog_menu);
dialog_menu->onMouseMove(_ev.get()); dialog_menu->onMouseMove(_ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
return; return;
} }
} }
@ -1632,12 +1639,12 @@ void FDialog::cb_move (const FWidget*, const FDataPtr)
setMoveSizeWidget(this); setMoveSizeWidget(this);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
drawBorder(); drawBorder();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
save_geometry = getGeometry(); save_geometry = getGeometry();
@ -1646,15 +1653,15 @@ void FDialog::cb_move (const FWidget*, const FDataPtr)
{ {
tooltip = new FToolTip(this); tooltip = new FToolTip(this);
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FToolTip");
return; return;
} }
if ( isResizeable() ) if ( isResizeable() )
{ {
if ( isLinuxTerm() ) if ( FTerm::isLinuxTerm() )
tooltip->setText ( " Arrow keys: Move\n" tooltip->setText ( " Arrow keys: Move\n"
"Shift + Arrow keys: Resize\n" "Shift + Arrow keys: Resize\n"
" Enter: Done\n" " Enter: Done\n"

View File

@ -33,14 +33,14 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FDialogListMenu::FDialogListMenu(FWidget* parent) FDialogListMenu::FDialogListMenu(FWidget* parent)
: FMenu(parent) : FMenu{parent}
{ {
init(); init();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FDialogListMenu::FDialogListMenu (const FString& txt, FWidget* parent) FDialogListMenu::FDialogListMenu (const FString& txt, FWidget* parent)
: FMenu(txt, parent) : FMenu{txt, parent}
{ {
init(); init();
} }

View File

@ -36,16 +36,24 @@ FEvent::FEvent (fc::events ev_type) // constructor
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
fc::events FEvent::type() const fc::events FEvent::getType() const
{ return t; } { return t; }
//----------------------------------------------------------------------
bool FEvent::isQueued() const
{ return queued; }
//----------------------------------------------------------------------
bool FEvent::wasSent() const
{ return send; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FKeyEvent // class FKeyEvent
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FKeyEvent::FKeyEvent (fc::events ev_type, FKey key_num) // constructor FKeyEvent::FKeyEvent (fc::events ev_type, FKey key_num) // constructor
: FEvent(ev_type) : FEvent{ev_type}
, k{key_num} , k{key_num}
{ } { }
@ -78,7 +86,7 @@ FMouseEvent::FMouseEvent ( fc::events ev_type // constructor
, const FPoint& pos , const FPoint& pos
, const FPoint& termPos , const FPoint& termPos
, int button ) , int button )
: FEvent(ev_type) : FEvent{ev_type}
, p{pos} , p{pos}
, tp{termPos} , tp{termPos}
, b{button} , b{button}
@ -88,7 +96,7 @@ FMouseEvent::FMouseEvent ( fc::events ev_type // constructor
FMouseEvent::FMouseEvent ( fc::events ev_type // constructor FMouseEvent::FMouseEvent ( fc::events ev_type // constructor
, const FPoint& pos , const FPoint& pos
, int button ) , int button )
: FMouseEvent(ev_type, pos, FPoint{}, button) : FMouseEvent{ev_type, pos, FPoint{}, button}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -132,7 +140,7 @@ FWheelEvent::FWheelEvent ( fc::events ev_type // constructor
, const FPoint& pos , const FPoint& pos
, const FPoint& termPos , const FPoint& termPos
, int wheel ) , int wheel )
: FEvent(ev_type) : FEvent{ev_type}
, p{pos} , p{pos}
, tp{termPos} , tp{termPos}
, w{wheel} , w{wheel}
@ -142,7 +150,7 @@ FWheelEvent::FWheelEvent ( fc::events ev_type // constructor
FWheelEvent::FWheelEvent ( fc::events ev_type // constructor FWheelEvent::FWheelEvent ( fc::events ev_type // constructor
, const FPoint& pos , const FPoint& pos
, int wheel ) , int wheel )
: FWheelEvent(ev_type, pos, FPoint{}, wheel) : FWheelEvent{ev_type, pos, FPoint{}, wheel}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -183,7 +191,7 @@ int FWheelEvent::getWheel() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FFocusEvent::FFocusEvent (fc::events ev_type) // constructor FFocusEvent::FFocusEvent (fc::events ev_type) // constructor
: FEvent(ev_type) : FEvent{ev_type}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -193,13 +201,13 @@ FFocusEvent::~FFocusEvent() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FFocusEvent::gotFocus() const bool FFocusEvent::gotFocus() const
{ {
return ( type() == fc::FocusIn_Event ); return ( getType() == fc::FocusIn_Event );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FFocusEvent::lostFocus() const bool FFocusEvent::lostFocus() const
{ {
return ( type() == fc::FocusOut_Event ); return ( getType() == fc::FocusOut_Event );
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -228,7 +236,7 @@ void FFocusEvent::ignore()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FAccelEvent::FAccelEvent (fc::events ev_type, void* focused) // constructor FAccelEvent::FAccelEvent (fc::events ev_type, void* focused) // constructor
: FEvent(ev_type) : FEvent{ev_type}
, focus_widget{focused} , focus_widget{focused}
{ } { }
@ -258,7 +266,7 @@ void FAccelEvent::ignore()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FResizeEvent::FResizeEvent (fc::events ev_type) // constructor FResizeEvent::FResizeEvent (fc::events ev_type) // constructor
: FEvent(ev_type) : FEvent{ev_type}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -283,7 +291,7 @@ void FResizeEvent::ignore()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FShowEvent::FShowEvent (fc::events ev_type) // constructor FShowEvent::FShowEvent (fc::events ev_type) // constructor
: FEvent(ev_type) : FEvent{ev_type}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -296,7 +304,7 @@ FShowEvent::~FShowEvent() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FHideEvent::FHideEvent (fc::events ev_type) // constructor FHideEvent::FHideEvent (fc::events ev_type) // constructor
: FEvent(ev_type) : FEvent{ev_type}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -309,7 +317,7 @@ FHideEvent::~FHideEvent() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FCloseEvent::FCloseEvent (fc::events ev_type) // constructor FCloseEvent::FCloseEvent (fc::events ev_type) // constructor
: FEvent(ev_type) : FEvent{ev_type}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -334,7 +342,7 @@ void FCloseEvent::ignore()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FTimerEvent::FTimerEvent (fc::events ev_type, int timer_id) // constructor FTimerEvent::FTimerEvent (fc::events ev_type, int timer_id) // constructor
: FEvent(ev_type) : FEvent{ev_type}
, id{timer_id} , id{timer_id}
{ } { }
@ -352,7 +360,7 @@ int FTimerEvent::getTimerId() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FUserEvent::FUserEvent (fc::events ev_type, int user_event_id) // constructor FUserEvent::FUserEvent (fc::events ev_type, int user_event_id) // constructor
: FEvent(ev_type) : FEvent{ev_type}
, uid{user_event_id} , uid{user_event_id}
{ } { }

View File

@ -99,14 +99,14 @@ FSystem* FFileDialog::fsystem{nullptr};
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FFileDialog::FFileDialog (FWidget* parent) FFileDialog::FFileDialog (FWidget* parent)
: FDialog(parent) : FDialog{parent}
{ {
init(); init();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FFileDialog::FFileDialog (const FFileDialog& fdlg) FFileDialog::FFileDialog (const FFileDialog& fdlg)
: FDialog(fdlg.getParentWidget()) : FDialog{fdlg.getParentWidget()}
{ {
if ( fdlg.directory ) if ( fdlg.directory )
setPath(fdlg.directory); setPath(fdlg.directory);
@ -119,9 +119,9 @@ FFileDialog::FFileDialog ( const FString& dirname
, const FString& filter , const FString& filter
, DialogType type , DialogType type
, FWidget* parent ) , FWidget* parent )
: FDialog(parent) : FDialog{parent}
, filter_pattern(filter) , filter_pattern{filter}
, dlg_type(type) , dlg_type{type}
{ {
if ( ! dirname.isNull() ) if ( ! dirname.isNull() )
setPath(dirname); setPath(dirname);

View File

@ -27,6 +27,7 @@
#include "final/fcolorpair.h" #include "final/fcolorpair.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flabel.h" #include "final/flabel.h"
#include "final/flog.h"
#include "final/fstatusbar.h" #include "final/fstatusbar.h"
namespace finalcut namespace finalcut
@ -39,15 +40,15 @@ namespace finalcut
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FLabel::FLabel(FWidget* parent) FLabel::FLabel(FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FLabel::FLabel (const FString& txt, FWidget* parent) FLabel::FLabel (const FString& txt, FWidget* parent)
: FWidget(parent) : FWidget{parent}
, text(txt) , text{txt}
{ {
init(); init();
setText(txt); setText(txt);
@ -173,9 +174,9 @@ void FLabel::onMouseDown (FMouseEvent* ev)
std::make_shared<FMouseEvent>(fc::MouseDown_Event, p, tp, b); std::make_shared<FMouseEvent>(fc::MouseDown_Event, p, tp, b);
FApplication::sendEvent (parent, _ev.get()); FApplication::sendEvent (parent, _ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
return; return;
} }
} }
@ -245,20 +246,7 @@ void FLabel::cb_accelWidgetDestroyed (const FWidget*, const FDataPtr)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLabel::init() void FLabel::init()
{ {
const auto& parent_widget = getParentWidget();
unsetFocusable(); unsetFocusable();
if ( parent_widget )
{
setForegroundColor (parent_widget->getForegroundColor());
setBackgroundColor (parent_widget->getBackgroundColor());
}
else
{
const auto& wc = getFWidgetColors();
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -302,7 +290,9 @@ void FLabel::draw()
if ( text.isEmpty() ) if ( text.isEmpty() )
return; return;
if ( isMonochron() ) useParentWidgetColor();
if ( FTerm::isMonochron() )
{ {
setReverse(true); setReverse(true);
@ -321,7 +311,7 @@ void FLabel::draw()
else else
drawSingleLine(); drawSingleLine();
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
setReverse(false); setReverse(false);
@ -406,7 +396,7 @@ void FLabel::printLine (FString& line)
for (std::size_t z{0}; z < to_char; z++) for (std::size_t z{0}; z < to_char; z++)
{ {
if ( ! std::iswprint(std::wint_t(line[z])) if ( ! std::iswprint(std::wint_t(line[z]))
&& ! isNewFont() && ! FTerm::isNewFont()
&& ( line[z] < fc::NF_rev_left_arrow2 && ( line[z] < fc::NF_rev_left_arrow2
|| line[z] > fc::NF_check_mark ) ) || line[z] > fc::NF_check_mark ) )
{ {
@ -415,8 +405,8 @@ void FLabel::printLine (FString& line)
if ( z == hotkeypos && getFlags().active ) if ( z == hotkeypos && getFlags().active )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg); setColor (wc->label_hotkey_fg, wc->label_hotkey_bg);
if ( ! getFlags().no_underline ) if ( ! getFlags().no_underline )
setUnderline(); setUnderline();

View File

@ -25,6 +25,7 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flabel.h" #include "final/flabel.h"
#include "final/flog.h"
#include "final/flineedit.h" #include "final/flineedit.h"
#include "final/fpoint.h" #include "final/fpoint.h"
#include "final/fsize.h" #include "final/fsize.h"
@ -41,7 +42,7 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FLineEdit::FLineEdit (FWidget* parent) FLineEdit::FLineEdit (FWidget* parent)
: FWidget(parent) : FWidget{parent}
, label{new FLabel("", parent)} , label{new FLabel("", parent)}
{ {
init(); init();
@ -49,8 +50,8 @@ FLineEdit::FLineEdit (FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FLineEdit::FLineEdit (const FString& txt, FWidget* parent) FLineEdit::FLineEdit (const FString& txt, FWidget* parent)
: FWidget(parent) : FWidget{parent}
, text(txt) , text{txt}
, label{new FLabel("", parent)} , label{new FLabel("", parent)}
{ {
init(); init();
@ -61,7 +62,7 @@ FLineEdit::FLineEdit (const FString& txt, FWidget* parent)
FLineEdit::~FLineEdit() // destructor FLineEdit::~FLineEdit() // destructor
{ {
if ( ! insert_mode ) if ( ! insert_mode )
setInsertCursor(); FTerm::setInsertCursor();
} }
// FLineEdit operators // FLineEdit operators
@ -98,28 +99,8 @@ const FLineEdit& FLineEdit::operator >> (FString& s)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FLineEdit::setEnable (bool enable) bool FLineEdit::setEnable (bool enable)
{ {
const auto& wc = getFWidgetColors();
FWidget::setEnable(enable); FWidget::setEnable(enable);
resetColors();
if ( enable )
{
if ( hasFocus() )
{
setForegroundColor (wc.inputfield_active_focus_fg);
setBackgroundColor (wc.inputfield_active_focus_bg);
}
else
{
setForegroundColor (wc.inputfield_active_fg);
setBackgroundColor (wc.inputfield_active_bg);
}
}
else
{
setForegroundColor (wc.inputfield_inactive_fg);
setBackgroundColor (wc.inputfield_inactive_bg);
}
return enable; return enable;
} }
@ -127,23 +108,7 @@ bool FLineEdit::setEnable (bool enable)
bool FLineEdit::setFocus (bool enable) bool FLineEdit::setFocus (bool enable)
{ {
FWidget::setFocus(enable); FWidget::setFocus(enable);
resetColors();
if ( isEnabled() )
{
const auto& wc = getFWidgetColors();
if ( enable )
{
setForegroundColor (wc.inputfield_active_focus_fg);
setBackgroundColor (wc.inputfield_active_focus_bg);
}
else
{
setForegroundColor (wc.inputfield_active_fg);
setBackgroundColor (wc.inputfield_active_bg);
}
}
return enable; return enable;
} }
@ -151,8 +116,8 @@ bool FLineEdit::setFocus (bool enable)
bool FLineEdit::setShadow (bool enable) bool FLineEdit::setShadow (bool enable)
{ {
if ( enable if ( enable
&& getEncoding() != fc::VT100 && FTerm::getEncoding() != fc::VT100
&& getEncoding() != fc::ASCII ) && FTerm::getEncoding() != fc::ASCII )
{ {
setFlags().shadow = true; setFlags().shadow = true;
setShadowSize(FSize{1, 1}); setShadowSize(FSize{1, 1});
@ -254,6 +219,34 @@ void FLineEdit::setLabelOrientation (const label_o o)
adjustLabel(); adjustLabel();
} }
//----------------------------------------------------------------------
void FLineEdit::resetColors()
{
const auto& wc = getColorTheme();
if ( isEnabled() ) // active
{
if ( hasFocus() )
{
setForegroundColor (wc->inputfield_active_focus_fg);
setBackgroundColor (wc->inputfield_active_focus_bg);
}
else
{
setForegroundColor (wc->inputfield_active_fg);
setBackgroundColor (wc->inputfield_active_bg);
}
}
else // inactive
{
setForegroundColor (wc->inputfield_inactive_fg);
setBackgroundColor (wc->inputfield_inactive_bg);
}
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::setSize (const FSize& size, bool adjust) void FLineEdit::setSize (const FSize& size, bool adjust)
{ {
@ -575,7 +568,7 @@ void FLineEdit::onAccel (FAccelEvent* ev)
void FLineEdit::onHide (FHideEvent*) void FLineEdit::onHide (FHideEvent*)
{ {
if ( ! insert_mode && ! isReadOnly() ) if ( ! insert_mode && ! isReadOnly() )
setInsertCursor(); FTerm::setInsertCursor();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -584,9 +577,9 @@ void FLineEdit::onFocusIn (FFocusEvent*)
if ( ! isReadOnly() ) if ( ! isReadOnly() )
{ {
if ( insert_mode ) if ( insert_mode )
setInsertCursor(); FTerm::setInsertCursor();
else else
unsetInsertCursor(); FTerm::unsetInsertCursor();
} }
if ( getStatusBar() ) if ( getStatusBar() )
@ -607,7 +600,7 @@ void FLineEdit::onFocusOut (FFocusEvent*)
} }
if ( ! insert_mode && ! isReadOnly() ) if ( ! insert_mode && ! isReadOnly() )
setInsertCursor(); FTerm::setInsertCursor();
} }
@ -654,34 +647,14 @@ void FLineEdit::adjustSize()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::init() void FLineEdit::init()
{ {
const auto& wc = getFWidgetColors();
label->setAccelWidget(this); label->setAccelWidget(this);
setShadow();
resetColors();
if ( isReadOnly() ) if ( isReadOnly() )
unsetVisibleCursor(); unsetVisibleCursor();
else else
setVisibleCursor(); setVisibleCursor();
setShadow();
if ( isEnabled() )
{
if ( hasFocus() )
{
setForegroundColor (wc.inputfield_active_focus_fg);
setBackgroundColor (wc.inputfield_active_focus_bg);
}
else
{
setForegroundColor (wc.inputfield_active_fg);
setBackgroundColor (wc.inputfield_active_bg);
}
}
else // inactive
{
setForegroundColor (wc.inputfield_inactive_fg);
setBackgroundColor (wc.inputfield_inactive_bg);
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -723,7 +696,7 @@ void FLineEdit::drawInputField()
const bool isActiveFocus = getFlags().active && getFlags().focus; const bool isActiveFocus = getFlags().active && getFlags().focus;
print() << FPoint{1, 1}; print() << FPoint{1, 1};
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
setReverse(true); setReverse(true);
print (' '); print (' ');
@ -739,7 +712,7 @@ void FLineEdit::drawInputField()
print (' '); print (' ');
} }
if ( isActiveFocus && getMaxColor() < 16 ) if ( isActiveFocus && FTerm::getMaxColor() < 16 )
setBold(); setBold();
const std::size_t text_offset_column = [this] () const std::size_t text_offset_column = [this] ()
@ -765,10 +738,10 @@ void FLineEdit::drawInputField()
x_pos++; x_pos++;
} }
if ( isActiveFocus && getMaxColor() < 16 ) if ( isActiveFocus && FTerm::getMaxColor() < 16 )
unsetBold(); unsetBold();
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
setReverse(false); setReverse(false);
setUnderline(false); setUnderline(false);
@ -860,7 +833,8 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos)
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
std::cerr << "Out of Range error: " << ex.what() << std::endl; *FApplication::getLog() << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl;
} }
if ( input_width >= char_width ) if ( input_width >= char_width )
@ -883,7 +857,8 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos)
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
std::cerr << "Out of Range error: " << ex.what() << std::endl; *FApplication::getLog() << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl;
} }
} }
@ -918,7 +893,8 @@ std::size_t FLineEdit::clickPosToCursorPos (std::size_t pos)
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
std::cerr << "Out of Range error: " << ex.what() << std::endl; *FApplication::getLog() << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl;
} }
idx++; idx++;
@ -951,7 +927,8 @@ void FLineEdit::adjustTextOffset()
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
std::cerr << "Out of Range error: " << ex.what() << std::endl; *FApplication::getLog() << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl;
} }
} }
@ -963,7 +940,8 @@ void FLineEdit::adjustTextOffset()
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
std::cerr << "Out of Range error: " << ex.what() << std::endl; *FApplication::getLog() << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl;
} }
} }
@ -1076,9 +1054,9 @@ inline void FLineEdit::switchInsertMode()
insert_mode = ! insert_mode; insert_mode = ! insert_mode;
if ( insert_mode ) if ( insert_mode )
setInsertCursor(); // Insert mode FTerm::setInsertCursor(); // Insert mode
else else
unsetInsertCursor(); // Overtype mode FTerm::unsetInsertCursor(); // Overtype mode
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1092,7 +1070,7 @@ inline bool FLineEdit::keyInput (FKey key)
{ {
if ( text.getLength() >= max_length ) if ( text.getLength() >= max_length )
{ {
beep(); FTerm::beep();
return true; return true;
} }

View File

@ -45,16 +45,16 @@ FListBoxItem::FListBoxItem()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListBoxItem::FListBoxItem (const FListBoxItem& item) FListBoxItem::FListBoxItem (const FListBoxItem& item)
: text(item.text) : text{item.text}
, data_pointer(item.data_pointer) , data_pointer{item.data_pointer}
, brackets(item.brackets) , brackets{item.brackets}
, selected(item.selected) , selected{item.selected}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListBoxItem::FListBoxItem (const FString& txt, FDataPtr data) FListBoxItem::FListBoxItem (const FString& txt, FDataPtr data)
: text(txt) : text{txt}
, data_pointer(data) , data_pointer{data}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -87,7 +87,7 @@ FListBoxItem& FListBoxItem::operator = (const FListBoxItem& item)
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListBox::FListBox (FWidget* parent) FListBox::FListBox (FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
} }
@ -274,8 +274,8 @@ void FListBox::clear()
hbar->hide(); hbar->hide();
// clear list from screen // clear list from screen
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.list_fg, wc.list_bg); setColor (wc->list_fg, wc->list_bg);
const std::size_t size = getWidth() - 2; const std::size_t size = getWidth() - 2;
drawBorder(); drawBorder();
drawHeadline(); drawHeadline();
@ -655,10 +655,7 @@ void FListBox::init()
initScrollbar (vbar, fc::vertical, this, &FListBox::cb_vbarChange); initScrollbar (vbar, fc::vertical, this, &FListBox::cb_vbarChange);
initScrollbar (hbar, fc::horizontal, this, &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(); nf_offset = FTerm::isNewFont() ? 1 : 0;
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
nf_offset = isNewFont() ? 1 : 0;
setTopPadding(1); setTopPadding(1);
setLeftPadding(1); setLeftPadding(1);
setBottomPadding(1); setBottomPadding(1);
@ -722,14 +719,15 @@ void FListBox::draw()
if ( current < 1 ) if ( current < 1 )
current = 1; current = 1;
setColor(); useParentWidgetColor();
if ( isMonochron() )
if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
drawBorder(); drawBorder();
if ( isNewFont() && ! vbar->isShown() ) if ( FTerm::isNewFont() && ! vbar->isShown() )
{ {
setColor(); setColor();
@ -742,7 +740,7 @@ void FListBox::draw()
drawHeadline(); drawHeadline();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
drawScrollbars(); drawScrollbars();
@ -792,12 +790,12 @@ void FListBox::drawHeadline()
const FString txt{" " + text + " "}; const FString txt{" " + text + " "};
const auto column_width = getColumnWidth(txt); const auto column_width = getColumnWidth(txt);
print() << FPoint{2, 1}; print() << FPoint{2, 1};
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( isEnabled() ) if ( isEnabled() )
setColor(wc.label_emphasis_fg, wc.label_bg); setColor(wc->label_emphasis_fg, wc->label_bg);
else else
setColor(wc.label_inactive_fg, wc.label_inactive_bg); setColor(wc->label_inactive_fg, wc->label_inactive_bg);
if ( column_width <= getClientWidth() ) if ( column_width <= getClientWidth() )
print (txt); print (txt);
@ -805,7 +803,7 @@ void FListBox::drawHeadline()
{ {
// Print ellipsis // Print ellipsis
print() << getColumnSubString (text, 1, getClientWidth() - 2) print() << getColumnSubString (text, 1, getClientWidth() - 2)
<< FColorPair {wc.label_ellipsis_fg, wc.label_bg} << ".."; << FColorPair {wc->label_ellipsis_fg, wc->label_bg} << "..";
} }
} }
@ -870,32 +868,32 @@ inline void FListBox::drawListLine ( int y
, bool serach_mark ) , bool serach_mark )
{ {
const std::size_t inc_len = inc_search.getLength(); const std::size_t inc_len = inc_search.getLength();
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
const bool isCurrentLine( y + yoffset + 1 == int(current) ); const bool isCurrentLine( y + yoffset + 1 == int(current) );
const std::size_t first = std::size_t(xoffset) + 1; const std::size_t first = std::size_t(xoffset) + 1;
const std::size_t max_width = getWidth() - nf_offset - 4; const std::size_t max_width = getWidth() - nf_offset - 4;
const FString element(getColumnSubString (getString(iter), first, max_width)); const FString element(getColumnSubString (getString(iter), first, max_width));
std::size_t column_width = getColumnWidth(element); std::size_t column_width = getColumnWidth(element);
if ( isMonochron() && isCurrentLine && getFlags().focus ) if ( FTerm::isMonochron() && isCurrentLine && getFlags().focus )
print (fc::BlackRightPointingPointer); // ► print (fc::BlackRightPointingPointer); // ►
else else
print (' '); print (' ');
if ( serach_mark ) if ( serach_mark )
setColor ( wc.current_inc_search_element_fg setColor ( wc->current_inc_search_element_fg
, wc.current_element_focus_bg ); , wc->current_element_focus_bg );
for (std::size_t i{0}; i < element.getLength(); i++) for (std::size_t i{0}; i < element.getLength(); i++)
{ {
if ( serach_mark && i == inc_len && getFlags().focus ) if ( serach_mark && i == inc_len && getFlags().focus )
setColor ( wc.current_element_focus_fg setColor ( wc->current_element_focus_fg
, wc.current_element_focus_bg ); , wc->current_element_focus_bg );
print (element[i]); print (element[i]);
} }
if ( isMonochron() && isCurrentLine && getFlags().focus ) if ( FTerm::isMonochron() && isCurrentLine && getFlags().focus )
{ {
print (fc::BlackLeftPointingPointer); // ◄ print (fc::BlackLeftPointingPointer); // ◄
column_width++; column_width++;
@ -928,7 +926,7 @@ inline void FListBox::drawListBracketsLine ( int y
const std::size_t inc_len = inc_search.getLength(); const std::size_t inc_len = inc_search.getLength();
const bool isCurrentLine( y + yoffset + 1 == int(current) ); const bool isCurrentLine( y + yoffset + 1 == int(current) );
if ( isMonochron() && isCurrentLine && getFlags().focus ) if ( FTerm::isMonochron() && isCurrentLine && getFlags().focus )
print (fc::BlackRightPointingPointer); // ► print (fc::BlackRightPointingPointer); // ►
else else
print (' '); print (' ');
@ -945,17 +943,17 @@ inline void FListBox::drawListBracketsLine ( int y
std::size_t column_width = getColumnWidth(element); std::size_t column_width = getColumnWidth(element);
const std::size_t text_width = getColumnWidth(getString(iter)); const std::size_t text_width = getColumnWidth(getString(iter));
std::size_t i{0}; std::size_t i{0};
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
for (; i < element.getLength(); i++) for (; i < element.getLength(); i++)
{ {
if ( serach_mark && i == 0 ) if ( serach_mark && i == 0 )
setColor ( wc.current_inc_search_element_fg setColor ( wc->current_inc_search_element_fg
, wc.current_element_focus_bg ); , wc->current_element_focus_bg );
if ( serach_mark && i == inc_len ) if ( serach_mark && i == inc_len )
setColor ( wc.current_element_focus_fg setColor ( wc->current_element_focus_fg
, wc.current_element_focus_bg ); , wc->current_element_focus_bg );
print (element[i]); print (element[i]);
} }
@ -964,14 +962,14 @@ inline void FListBox::drawListBracketsLine ( int y
&& std::size_t(xoffset) <= text_width ) && std::size_t(xoffset) <= text_width )
{ {
if ( serach_mark && i == inc_len ) if ( serach_mark && i == inc_len )
setColor ( wc.current_element_focus_fg setColor ( wc->current_element_focus_fg
, wc.current_element_focus_bg ); , wc->current_element_focus_bg );
printRightBracket (iter->brackets); printRightBracket (iter->brackets);
column_width++; column_width++;
} }
if ( isMonochron() && isCurrentLine && getFlags().focus ) if ( FTerm::isMonochron() && isCurrentLine && getFlags().focus )
{ {
print (fc::BlackLeftPointingPointer); // ◄ print (fc::BlackLeftPointingPointer); // ◄
column_width++; column_width++;
@ -990,51 +988,51 @@ inline void FListBox::setLineAttributes ( int y
const bool isCurrentLine( y + yoffset + 1 == int(current) ); const bool isCurrentLine( y + yoffset + 1 == int(current) );
const std::size_t inc_len = inc_search.getLength(); const std::size_t inc_len = inc_search.getLength();
const std::size_t inc_width = getColumnWidth(inc_search); const std::size_t inc_width = getColumnWidth(inc_search);
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
print() << FPoint{2, 2 + int(y)}; print() << FPoint{2, 2 + int(y)};
if ( isLineSelected ) if ( isLineSelected )
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setBold(); setBold();
else else
setColor (wc.selected_list_fg, wc.selected_list_bg); setColor (wc->selected_list_fg, wc->selected_list_bg);
} }
else else
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
unsetBold(); unsetBold();
else else
setColor (wc.list_fg, wc.list_bg); setColor (wc->list_fg, wc->list_bg);
} }
if ( isCurrentLine ) if ( isCurrentLine )
{ {
if ( getFlags().focus && getMaxColor() < 16 ) if ( getFlags().focus && FTerm::getMaxColor() < 16 )
setBold(); setBold();
if ( isLineSelected ) if ( isLineSelected )
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setBold(); setBold();
else if ( getFlags().focus ) else if ( getFlags().focus )
setColor ( wc.selected_current_element_focus_fg setColor ( wc->selected_current_element_focus_fg
, wc.selected_current_element_focus_bg ); , wc->selected_current_element_focus_bg );
else else
setColor ( wc.selected_current_element_fg setColor ( wc->selected_current_element_fg
, wc.selected_current_element_bg ); , wc->selected_current_element_bg );
setCursorPos ({3, 2 + int(y)}); // first character setCursorPos ({3, 2 + int(y)}); // first character
} }
else else
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
unsetBold(); unsetBold();
if ( getFlags().focus ) if ( getFlags().focus )
{ {
setColor ( wc.current_element_focus_fg setColor ( wc->current_element_focus_fg
, wc.current_element_focus_bg ); , wc->current_element_focus_bg );
const int b = ( lineHasBrackets ) ? 1: 0; const int b = ( lineHasBrackets ) ? 1: 0;
if ( inc_len > 0 ) // incremental search if ( inc_len > 0 ) // incremental search
@ -1047,18 +1045,18 @@ inline void FListBox::setLineAttributes ( int y
setCursorPos ({3 + b, 2 + int(y)}); // first character setCursorPos ({3 + b, 2 + int(y)}); // first character
} }
else else
setColor ( wc.current_element_fg setColor ( wc->current_element_fg
, wc.current_element_bg ); , wc->current_element_bg );
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
else else
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
else if ( getFlags().focus && getMaxColor() < 16 ) else if ( getFlags().focus && FTerm::getMaxColor() < 16 )
unsetBold(); unsetBold();
} }
} }
@ -1066,7 +1064,7 @@ inline void FListBox::setLineAttributes ( int y
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListBox::unsetAttributes() inline void FListBox::unsetAttributes()
{ {
if ( isMonochron() ) // unset for the last element if ( FTerm::isMonochron() ) // unset for the last element
setReverse(false); setReverse(false);
unsetBold(); unsetBold();
@ -1719,7 +1717,7 @@ void FListBox::processChanged()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::changeOnResize() void FListBox::changeOnResize()
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
vbar->setGeometry (FPoint{int(getWidth()), 2}, FSize{2, getHeight() - 2}); vbar->setGeometry (FPoint{int(getWidth()), 2}, FSize{2, getHeight() - 2});
hbar->setGeometry (FPoint{1, int(getHeight())}, FSize{getWidth() - 2, 1}); hbar->setGeometry (FPoint{1, int(getHeight())}, FSize{getWidth() - 2, 1});

View File

@ -170,9 +170,9 @@ bool sortDescendingByNumber (const FObject* lhs, const FObject* rhs)
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListViewItem::FListViewItem (const FListViewItem& item) FListViewItem::FListViewItem (const FListViewItem& item)
: FObject(item.getParent()) : FObject{item.getParent()}
, column_list(item.column_list) , column_list{item.column_list}
, data_pointer(item.data_pointer) , data_pointer{item.data_pointer}
{ {
auto parent = getParent(); auto parent = getParent();
@ -191,7 +191,7 @@ FListViewItem::FListViewItem (const FListViewItem& item)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListViewItem::FListViewItem (iterator parent_iter) FListViewItem::FListViewItem (iterator parent_iter)
: FObject((*parent_iter)->getParent()) : FObject{(*parent_iter)->getParent()}
{ {
insert (this, parent_iter); insert (this, parent_iter);
} }
@ -200,9 +200,9 @@ FListViewItem::FListViewItem (iterator parent_iter)
FListViewItem::FListViewItem ( const FStringList& cols FListViewItem::FListViewItem ( const FStringList& cols
, FDataPtr data , FDataPtr data
, iterator parent_iter ) , iterator parent_iter )
: FObject(nullptr) : FObject{nullptr}
, column_list(cols) , column_list{cols}
, data_pointer(data) , data_pointer{data}
{ {
if ( cols.empty() ) if ( cols.empty() )
return; return;
@ -496,7 +496,7 @@ FListViewIterator::FListViewIterator()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListViewIterator::FListViewIterator (iterator iter) FListViewIterator::FListViewIterator (iterator iter)
: node(iter) : node{iter}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -505,16 +505,16 @@ FListViewIterator::~FListViewIterator() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListViewIterator::FListViewIterator (const FListViewIterator& i) FListViewIterator::FListViewIterator (const FListViewIterator& i)
: iter_path(i.iter_path) // copy constructor : iter_path{i.iter_path} // copy constructor
, node(i.node) , node{i.node}
, position(i.position) , position{i.position}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListViewIterator::FListViewIterator (FListViewIterator&& i) noexcept FListViewIterator::FListViewIterator (FListViewIterator&& i) noexcept
: iter_path(std::move(i.iter_path)) // move constructor : iter_path{std::move(i.iter_path)} // move constructor
, node(std::move(i.node)) , node{std::move(i.node)}
, position(std::move(i.position)) , position{std::move(i.position)}
{ } { }
// FListViewIterator operators // FListViewIterator operators
@ -683,7 +683,7 @@ void FListViewIterator::parentElement()
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FListView::FListView (FWidget* parent) FListView::FListView (FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
} }
@ -910,9 +910,9 @@ FObject::iterator FListView::insert ( const FStringList& cols
{ {
item = new FListViewItem (cols, d, getNullIterator()); item = new FListViewItem (cols, d, getNullIterator());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FListViewItem");
return getNullIterator(); return getNullIterator();
} }
@ -1523,10 +1523,7 @@ void FListView::init()
root = selflist.begin(); root = selflist.begin();
getNullIterator() = selflist.end(); getNullIterator() = selflist.end();
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(); nf_offset = FTerm::isNewFont() ? 1 : 0;
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
nf_offset = isNewFont() ? 1 : 0;
setTopPadding(1); setTopPadding(1);
setLeftPadding(1); setLeftPadding(1);
setBottomPadding(1); setBottomPadding(1);
@ -1637,14 +1634,14 @@ void FListView::draw()
if ( current_iter.getPosition() < 1 ) if ( current_iter.getPosition() < 1 )
current_iter = itemlist.begin(); current_iter = itemlist.begin();
setColor(); useParentWidgetColor();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
drawBorder(); drawBorder();
if ( isNewFont() && ! vbar->isShown() ) if ( FTerm::isNewFont() && ! vbar->isShown() )
{ {
setColor(); setColor();
@ -1657,7 +1654,7 @@ void FListView::draw()
drawHeadlines(); drawHeadlines();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
drawScrollbars(); drawScrollbars();
@ -1773,7 +1770,7 @@ void FListView::drawList()
// Reset color // Reset color
setColor(); setColor();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
// Clean empty space after last element // Clean empty space after last element
@ -1876,8 +1873,8 @@ void FListView::clearList()
{ {
// Clear list from terminal screen // Clear list from terminal screen
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.list_fg, wc.list_bg); setColor (wc->list_fg, wc->list_bg);
const std::size_t size = getWidth() - 2; const std::size_t size = getWidth() - 2;
drawBorder(); drawBorder();
drawHeadlines(); drawHeadlines();
@ -1897,34 +1894,34 @@ void FListView::clearList()
inline void FListView::setLineAttributes ( bool is_current inline void FListView::setLineAttributes ( bool is_current
, bool is_focus ) , bool is_focus )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.list_fg, wc.list_bg); setColor (wc->list_fg, wc->list_bg);
if ( is_current ) if ( is_current )
{ {
if ( is_focus && getMaxColor() < 16 ) if ( is_focus && FTerm::getMaxColor() < 16 )
setBold(); setBold();
if ( isMonochron() ) if ( FTerm::isMonochron() )
unsetBold(); unsetBold();
if ( is_focus ) if ( is_focus )
{ {
setColor ( wc.current_element_focus_fg setColor ( wc->current_element_focus_fg
, wc.current_element_focus_bg ); , wc->current_element_focus_bg );
} }
else else
setColor ( wc.current_element_fg setColor ( wc->current_element_fg
, wc.current_element_bg ); , wc->current_element_bg );
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
else else
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
else if ( is_focus && getMaxColor() < 16 ) else if ( is_focus && FTerm::getMaxColor() < 16 )
unsetBold(); unsetBold();
} }
} }
@ -1934,7 +1931,7 @@ inline FString FListView::getCheckBox (const FListViewItem* item)
{ {
FString checkbox{""}; FString checkbox{""};
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
checkbox = ( item->isChecked() ) ? CHECKBOX_ON : CHECKBOX; checkbox = ( item->isChecked() ) ? CHECKBOX_ON : CHECKBOX;
checkbox += L' '; checkbox += L' ';
@ -2039,12 +2036,12 @@ void FListView::drawHeadlineLabel (const headerItems::const_iterator& iter)
const headerItems::const_iterator first = header.begin(); const headerItems::const_iterator first = header.begin();
const int column = int(std::distance(first, iter)) + 1; const int column = int(std::distance(first, iter)) + 1;
const bool has_sort_indicator( sort_column == column && ! hide_sort_indicator ); const bool has_sort_indicator( sort_column == column && ! hide_sort_indicator );
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( isEnabled() ) if ( isEnabled() )
setColor (wc.label_emphasis_fg, wc.label_bg); setColor (wc->label_emphasis_fg, wc->label_bg);
else else
setColor (wc.label_inactive_fg, wc.label_inactive_bg); setColor (wc->label_inactive_fg, wc->label_inactive_bg);
if ( has_sort_indicator && column_width >= column_max - 1 && column_width > 1 ) if ( has_sort_indicator && column_width >= column_max - 1 && column_width > 1 )
{ {
@ -2169,11 +2166,11 @@ void FListView::drawColumnEllipsis ( const headerItems::const_iterator& iter
// Print label ellipsis // Print label ellipsis
static constexpr int ellipsis_length = 2; static constexpr int ellipsis_length = 2;
const int width = iter->width; const int width = iter->width;
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
headerline << ' ' headerline << ' '
<< getColumnSubString (text, 1, uInt(width - ellipsis_length)) << getColumnSubString (text, 1, uInt(width - ellipsis_length))
<< FColorPair {wc.label_ellipsis_fg, wc.label_bg} << FColorPair {wc->label_ellipsis_fg, wc->label_bg}
<< ".."; << "..";
if ( iter == header.end() - 1 ) // Last element if ( iter == header.end() - 1 ) // Last element
@ -2516,7 +2513,7 @@ void FListView::processChanged()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::changeOnResize() void FListView::changeOnResize()
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
vbar->setGeometry (FPoint{int(getWidth()), 2}, FSize{2, getHeight() - 2}); vbar->setGeometry (FPoint{int(getWidth()), 2}, FSize{2, getHeight() - 2});
hbar->setGeometry (FPoint{1, int(getHeight())}, FSize{getWidth() - 2, 1}); hbar->setGeometry (FPoint{1, int(getHeight())}, FSize{getWidth() - 2, 1});

88
src/flog.cpp Normal file
View File

@ -0,0 +1,88 @@
/***********************************************************************
* flog.cpp - Interface of the FINAL CUT logger *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 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/flog.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FLog
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FLog::FLog()
{ }
//----------------------------------------------------------------------
FLog::~FLog() // destructor
{
FLog::sync();
}
// public methods of FLog
//----------------------------------------------------------------------
FLog& FLog::operator << (LogLevel l)
{
using namespace std::placeholders;
sync();
switch ( l )
{
case Info:
current_log = std::bind(&FLog::info, this, _1);
break;
case Warn:
current_log = std::bind(&FLog::warn, this, _1);
break;
case Error:
current_log = std::bind(&FLog::error, this, _1);
break;
case Debug:
current_log = std::bind(&FLog::debug, this, _1);
break;
}
return *this;
}
// protected methods of FLog
//----------------------------------------------------------------------
int FLog::sync()
{
if ( ! str().empty() )
{
current_log (str());
str("");
}
return 0;
}
} // namespace finalcut

124
src/flogger.cpp Normal file
View File

@ -0,0 +1,124 @@
/***********************************************************************
* flogger.cpp - The FINAL CUT text logger *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 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/flogger.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FLogger
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FLogger::FLogger()
{ }
//----------------------------------------------------------------------
FLogger::~FLogger() // destructor
{ }
// private methods of FLogger
//----------------------------------------------------------------------
void FLogger::newlineReplace ( std::string& str
, const std::string& replace_str )
{
std::size_t pos{0};
std::size_t npos{std::string::npos};
while ( (pos = str.find("\n", pos)) != npos
&& pos + 1 < str.length() )
{
str.replace(pos, 1, replace_str);
pos += replace_str.length();
}
}
//----------------------------------------------------------------------
const std::string FLogger::getTimeString()
{
char str[100];
const auto& now = std::chrono::system_clock::now();
const auto& t = std::chrono::system_clock::to_time_t(now);
// Print RFC 2822 date
struct tm time{};
localtime_r (&t, &time);
std::strftime (str, sizeof(str), "%a, %d %b %Y %T %z", &time);
return std::string(str);
}
//----------------------------------------------------------------------
const std::string FLogger::getEOL()
{
if ( getEnding() == FLog::LF )
return "\n";
else if ( getEnding() == FLog::CR )
return "\r";
else if ( getEnding() == FLog::CRLF )
return "\r\n";
return "";
}
//----------------------------------------------------------------------
void FLogger::printLogLine (const std::string& msg)
{
const std::string& log_level = [this] ()
{
switch ( getLevel() )
{
case Info:
return "INFO";
case Warn:
return "WARNING";
case Error:
return "ERROR";
case Debug:
return "DEBUG";
}
return "";
}();
const std::string prefix = [this, &log_level] ()
{
if ( timestamp )
return getTimeString() + " [" + log_level + "] ";
else
return "[" + log_level + "] ";
}();
std::string message{msg};
const std::string& eol = getEOL();
const std::string replace_str = eol + prefix;
newlineReplace (message, replace_str);
output << prefix << message << eol;
}
} // namespace finalcut

View File

@ -28,6 +28,7 @@
#include "final/fcolorpair.h" #include "final/fcolorpair.h"
#include "final/fdialog.h" #include "final/fdialog.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flog.h"
#include "final/fmenu.h" #include "final/fmenu.h"
#include "final/fmenubar.h" #include "final/fmenubar.h"
#include "final/fmenuitem.h" #include "final/fmenuitem.h"
@ -44,15 +45,15 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenu::FMenu(FWidget* parent) FMenu::FMenu(FWidget* parent)
: FWindow(parent) : FWindow{parent}
{ {
init(parent); init(parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenu::FMenu (const FString& txt, FWidget* parent) FMenu::FMenu (const FString& txt, FWidget* parent)
: FWindow(parent) : FWindow{parent}
, menuitem(txt, parent) , menuitem{txt, parent}
{ {
init(parent); init(parent);
} }
@ -82,6 +83,15 @@ void FMenu::setStatusbarMessage (const FString& msg)
menuitem.setStatusbarMessage(msg); menuitem.setStatusbarMessage(msg);
} }
//----------------------------------------------------------------------
void FMenu::resetColors()
{
const auto& wc = getColorTheme();
setForegroundColor (wc->menu_active_fg);
setBackgroundColor (wc->menu_active_bg);
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenu::show() void FMenu::show()
{ {
@ -457,10 +467,7 @@ void FMenu::init(FWidget* parent)
setTransparentShadow(); setTransparentShadow();
setMenuWidget(); setMenuWidget();
hide(); hide();
resetColors();
const auto& wc = getFWidgetColors();
setForegroundColor (wc.menu_active_fg);
setBackgroundColor (wc.menu_active_bg);
menuitem.setMenu(this); menuitem.setMenu(this);
if ( parent ) if ( parent )
@ -517,7 +524,7 @@ void FMenu::calculateDimensions()
} }
else if ( accel_key ) else if ( accel_key )
{ {
const std::size_t accel_len = getKeyName(accel_key).getLength(); const std::size_t accel_len = FTerm::getKeyName(accel_key).getLength();
item_width += accel_len + 2; item_width += accel_len + 2;
} }
@ -941,9 +948,9 @@ void FMenu::passEventToSubMenu (FMouseEvent* const& ev)
setClickedWidget(opened_sub_menu); setClickedWidget(opened_sub_menu);
opened_sub_menu->onMouseMove(_ev.get()); opened_sub_menu->onMouseMove(_ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
} }
} }
@ -965,9 +972,9 @@ void FMenu::passEventToSuperMenu (FMouseEvent* const& ev)
setClickedWidget(smenu); setClickedWidget(smenu);
smenu->onMouseMove(_ev.get()); smenu->onMouseMove(_ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
} }
} }
@ -990,9 +997,9 @@ void FMenu::passEventToMenuBar (FMouseEvent* const& ev)
mbar.mouse_down = true; mbar.mouse_down = true;
mbar.onMouseMove(_ev.get()); mbar.onMouseMove(_ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
} }
} }
@ -1208,10 +1215,10 @@ bool FMenu::hotkeyMenu (FKeyEvent* ev)
void FMenu::draw() void FMenu::draw()
{ {
// Fill the background // Fill the background
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.menu_active_fg, wc.menu_active_bg); setColor (wc->menu_active_fg, wc->menu_active_bg);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
clearArea(); clearArea();
@ -1219,7 +1226,7 @@ void FMenu::draw()
drawItems(); drawItems();
drawShadow(this); drawShadow(this);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
@ -1242,14 +1249,14 @@ void FMenu::drawItems()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenu::drawSeparator (int y) inline void FMenu::drawSeparator (int y)
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
print() << FPoint{1, 2 + y} print() << FPoint{1, 2 + y}
<< FColorPair{wc.menu_active_fg, wc.menu_active_bg}; << FColorPair{wc->menu_active_fg, wc->menu_active_bg};
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
print (fc::NF_border_line_vertical_right); print (fc::NF_border_line_vertical_right);
FString line { std::size_t(getWidth()) - 2 FString line { std::size_t(getWidth()) - 2
@ -1266,7 +1273,7 @@ inline void FMenu::drawSeparator (int y)
print (fc::BoxDrawingsVerticalAndLeft); print (fc::BoxDrawingsVerticalAndLeft);
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
@ -1313,7 +1320,7 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y)
if ( is_selected ) if ( is_selected )
drawTrailingSpaces (column_width); drawTrailingSpaces (column_width);
if ( isMonochron() && is_enabled && is_selected ) if ( FTerm::isMonochron() && is_enabled && is_selected )
setReverse(true); setReverse(true);
} }
@ -1333,14 +1340,14 @@ inline void FMenu::drawCheckMarkPrefix (const FMenuItem* m_item)
{ {
if ( is_radio_btn ) if ( is_radio_btn )
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
print (fc::NF_Bullet); // NF_Bullet ● print (fc::NF_Bullet); // NF_Bullet ●
else else
print (fc::BlackCircle); // BlackCircle ● print (fc::BlackCircle); // BlackCircle ●
} }
else else
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
print (fc::NF_check_mark); // NF_check_mark ✓ print (fc::NF_check_mark); // NF_check_mark ✓
else else
print (fc::SquareRoot); // SquareRoot √ print (fc::SquareRoot); // SquareRoot √
@ -1348,10 +1355,10 @@ inline void FMenu::drawCheckMarkPrefix (const FMenuItem* m_item)
} }
else else
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.menu_inactive_fg, getBackgroundColor()); setColor (wc->menu_inactive_fg, getBackgroundColor());
if ( getEncoding() == fc::ASCII ) if ( FTerm::getEncoding() == fc::ASCII )
print ('-'); print ('-');
else else
print (fc::SmallBullet); // · print (fc::SmallBullet); // ·
@ -1371,18 +1378,18 @@ inline void FMenu::drawMenuText (menuText& data)
for (std::size_t z{0}; z < data.text.getLength(); 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]))
&& ! isNewFont() && ! FTerm::isNewFont()
&& ( data.text[z] < fc::NF_rev_left_arrow2 && ( data.text[z] < fc::NF_rev_left_arrow2
|| data.text[z] > fc::NF_check_mark ) || data.text[z] > fc::NF_check_mark )
&& ! charEncodable(wchar_t(data.text[z])) ) && ! FTerm::charEncodable(wchar_t(data.text[z])) )
{ {
data.text[z] = L' '; data.text[z] = L' ';
} }
if ( z == data.hotkeypos ) if ( z == data.hotkeypos )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg); setColor (wc->menu_hotkey_fg, wc->menu_hotkey_bg);
if ( ! data.no_underline ) if ( ! data.no_underline )
setUnderline(); setUnderline();
@ -1418,7 +1425,7 @@ inline void FMenu::drawSubMenuIndicator (std::size_t& startpos)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FMenu::drawAcceleratorKey (std::size_t& startpos, FKey accel_key) inline void FMenu::drawAcceleratorKey (std::size_t& startpos, FKey accel_key)
{ {
const FString accel_name {getKeyName(accel_key)}; const FString accel_name {FTerm::getKeyName(accel_key)};
const std::size_t c = ( has_checkable_items ) ? 1 : 0; const std::size_t c = ( has_checkable_items ) ? 1 : 0;
const std::size_t accel_len = accel_name.getLength(); const std::size_t accel_len = accel_name.getLength();
const std::size_t len = max_item_width - (startpos + accel_len + c + 2); const std::size_t len = max_item_width - (startpos + accel_len + c + 2);
@ -1447,33 +1454,33 @@ inline void FMenu::setLineAttributes (const FMenuItem* m_item, int y)
{ {
const bool is_enabled = m_item->isEnabled(); const bool is_enabled = m_item->isEnabled();
const bool is_selected = m_item->isSelected(); const bool is_selected = m_item->isSelected();
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( is_enabled ) if ( is_enabled )
{ {
if ( is_selected ) if ( is_selected )
{ {
setForegroundColor (wc.menu_active_focus_fg); setForegroundColor (wc->menu_active_focus_fg);
setBackgroundColor (wc.menu_active_focus_bg); setBackgroundColor (wc->menu_active_focus_bg);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
else else
{ {
setForegroundColor (wc.menu_active_fg); setForegroundColor (wc->menu_active_fg);
setBackgroundColor (wc.menu_active_bg); setBackgroundColor (wc->menu_active_bg);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
} }
} }
else else
{ {
setForegroundColor (wc.menu_inactive_fg); setForegroundColor (wc->menu_inactive_fg);
setBackgroundColor (wc.menu_inactive_bg); setBackgroundColor (wc->menu_inactive_bg);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
} }

View File

@ -25,6 +25,7 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flog.h"
#include "final/fmenu.h" #include "final/fmenu.h"
#include "final/fmenubar.h" #include "final/fmenubar.h"
#include "final/fmenuitem.h" #include "final/fmenuitem.h"
@ -41,7 +42,7 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenuBar::FMenuBar(FWidget* parent) FMenuBar::FMenuBar(FWidget* parent)
: FWindow(parent) : FWindow{parent}
{ {
init(); init();
} }
@ -54,6 +55,15 @@ FMenuBar::~FMenuBar() // destructor
// public methods of FMenuBar // public methods of FMenuBar
//----------------------------------------------------------------------
void FMenuBar::resetColors()
{
const auto& wc = getColorTheme();
setForegroundColor (wc->menu_active_fg);
setBackgroundColor (wc->menu_active_bg);
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuBar::resetMenu() void FMenuBar::resetMenu()
{ {
@ -64,9 +74,9 @@ void FMenuBar::resetMenu()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuBar::hide() void FMenuBar::hide()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
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);
print() << FPoint{1, 1} << FString{getDesktopWidth(), L' '}; print() << FPoint{1, 1} << FString{getDesktopWidth(), L' '};
updateTerminal(); updateTerminal();
@ -248,9 +258,7 @@ void FMenuBar::init()
addAccelerator (fc::Fkey_f10); addAccelerator (fc::Fkey_f10);
addAccelerator (fc::Fckey_space); addAccelerator (fc::Fckey_space);
const auto& wc = getFWidgetColors(); resetColors();
setForegroundColor (wc.menu_active_fg);
setBackgroundColor (wc.menu_active_bg);
unsetFocusable(); unsetFocusable();
} }
@ -477,7 +485,7 @@ void FMenuBar::drawItems()
print() << FPoint{1, 1}; print() << FPoint{1, 1};
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
std::size_t x{1}; std::size_t x{1};
@ -489,7 +497,7 @@ void FMenuBar::drawItems()
for (; x <= getDesktopWidth(); x++) for (; x <= getDesktopWidth(); x++)
print (' '); print (' ');
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
@ -528,10 +536,10 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x)
drawEllipsis (txtdata, x); drawEllipsis (txtdata, x);
drawTrailingSpace (x); drawTrailingSpace (x);
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.menu_active_fg, wc.menu_active_bg); setColor (wc->menu_active_fg, wc->menu_active_bg);
if ( isMonochron() && is_enabled && is_selected ) if ( FTerm::isMonochron() && is_enabled && is_selected )
setReverse(true); setReverse(true);
} }
@ -540,28 +548,28 @@ inline void FMenuBar::setLineAttributes (const FMenuItem* menuitem)
{ {
bool is_enabled = menuitem->isEnabled(); bool is_enabled = menuitem->isEnabled();
bool is_selected = menuitem->isSelected(); bool is_selected = menuitem->isSelected();
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( is_enabled ) if ( is_enabled )
{ {
if ( is_selected ) if ( is_selected )
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
setForegroundColor (wc.menu_active_focus_fg); setForegroundColor (wc->menu_active_focus_fg);
setBackgroundColor (wc.menu_active_focus_bg); setBackgroundColor (wc->menu_active_focus_bg);
} }
else else
{ {
setForegroundColor (wc.menu_active_fg); setForegroundColor (wc->menu_active_fg);
setBackgroundColor (wc.menu_active_bg); setBackgroundColor (wc->menu_active_bg);
} }
} }
else else
{ {
setForegroundColor (wc.menu_inactive_fg); setForegroundColor (wc->menu_inactive_fg);
setBackgroundColor (wc.menu_inactive_bg); setBackgroundColor (wc->menu_inactive_bg);
} }
setColor(); setColor();
@ -597,7 +605,7 @@ inline void FMenuBar::drawMenuText (menuText& data)
break; break;
if ( ! std::iswprint(std::wint_t(data.text[z])) if ( ! std::iswprint(std::wint_t(data.text[z]))
&& ! isNewFont() && ! FTerm::isNewFont()
&& ( data.text[z] < fc::NF_rev_left_arrow2 && ( data.text[z] < fc::NF_rev_left_arrow2
|| data.text[z] > fc::NF_check_mark ) ) || data.text[z] > fc::NF_check_mark ) )
{ {
@ -606,8 +614,8 @@ inline void FMenuBar::drawMenuText (menuText& data)
if ( z == data.hotkeypos ) if ( z == data.hotkeypos )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg); setColor (wc->menu_hotkey_fg, wc->menu_hotkey_bg);
if ( ! data.no_underline ) if ( ! data.no_underline )
setUnderline(); setUnderline();
@ -944,9 +952,9 @@ void FMenuBar::passEventToMenu (const FMouseEvent* const& ev)
setClickedWidget(menu); setClickedWidget(menu);
menu->onMouseMove(_ev.get()); menu->onMouseMove(_ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
} }
} }
} }

View File

@ -25,6 +25,7 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fdialog.h" #include "final/fdialog.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flog.h"
#include "final/fmenu.h" #include "final/fmenu.h"
#include "final/fmenubar.h" #include "final/fmenubar.h"
#include "final/fmenulist.h" #include "final/fmenulist.h"
@ -41,24 +42,24 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenuItem::FMenuItem (FWidget* parent) FMenuItem::FMenuItem (FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init (parent); init (parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenuItem::FMenuItem (const FString& txt, FWidget* parent) FMenuItem::FMenuItem (const FString& txt, FWidget* parent)
: FWidget(parent) : FWidget{parent}
, text(txt) , text{txt}
{ {
init (parent); init (parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMenuItem::FMenuItem (FKey k, const FString& txt, FWidget* parent) FMenuItem::FMenuItem (FKey k, const FString& txt, FWidget* parent)
: FWidget(parent) : FWidget{parent}
, text(txt) , text{txt}
, accel_key(k) , accel_key{k}
{ {
init (parent); init (parent);
} }
@ -614,9 +615,9 @@ void FMenuItem::createDialogList (FMenu* winmenu)
// create a new dialog list item // create a new dialog list item
win_item = new FMenuItem (name, winmenu); win_item = new FMenuItem (name, winmenu);
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMenuItem");
return; return;
} }
@ -663,9 +664,9 @@ void FMenuItem::passMouseEvent ( T widget, const FMouseEvent* ev
{ {
_ev = std::make_shared<FMouseEvent>(ev_type, p2, t, b); _ev = std::make_shared<FMouseEvent>(ev_type, p2, t, b);
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
return; return;
} }

View File

@ -24,6 +24,7 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fbutton.h" #include "final/fbutton.h"
#include "final/flog.h"
#include "final/fmessagebox.h" #include "final/fmessagebox.h"
namespace finalcut namespace finalcut
@ -49,7 +50,7 @@ static const char* const button_text[] =
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMessageBox::FMessageBox (FWidget* parent) FMessageBox::FMessageBox (FWidget* parent)
: FDialog(parent) : FDialog{parent}
{ {
setTitlebarText("Message for you"); setTitlebarText("Message for you");
init(FMessageBox::Ok, 0, 0); init(FMessageBox::Ok, 0, 0);
@ -57,15 +58,15 @@ FMessageBox::FMessageBox (FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMessageBox::FMessageBox (const FMessageBox& mbox) FMessageBox::FMessageBox (const FMessageBox& mbox)
: FDialog(mbox.getParentWidget()) : FDialog{mbox.getParentWidget()}
, headline_text(mbox.headline_text) , headline_text{mbox.headline_text}
, text(mbox.text) , text{mbox.text}
, text_components(mbox.text_components) , text_components{mbox.text_components}
, max_line_width(mbox.max_line_width) , max_line_width{mbox.max_line_width}
, emphasis_color(mbox.emphasis_color) , emphasis_color{mbox.emphasis_color}
, num_buttons(mbox.num_buttons) , num_buttons{mbox.num_buttons}
, text_num_lines(mbox.text_num_lines) , text_num_lines{mbox.text_num_lines}
, center_text(mbox.center_text) , center_text{mbox.center_text}
{ {
setTitlebarText (mbox.getTitlebarText()); setTitlebarText (mbox.getTitlebarText());
init ( mbox.button_digit[0] init ( mbox.button_digit[0]
@ -80,8 +81,8 @@ FMessageBox::FMessageBox ( const FString& caption
, int button1 , int button1
, int button2 , int button2
, FWidget* parent ) , FWidget* parent )
: FDialog(parent) : FDialog{parent}
, text(message) , text{message}
{ {
setTitlebarText(caption); setTitlebarText(caption);
init(button0, button1, button2); init(button0, button1, button2);
@ -256,9 +257,9 @@ inline void FMessageBox::allocation (int button0, int button1, int button2)
button[2]->setHeight(1, false); button[2]->setHeight(1, false);
} }
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FButton");
return; return;
} }
} }
@ -347,7 +348,7 @@ void FMessageBox::draw()
// center the whole block // center the whole block
const int msg_x = int((getWidth() - max_line_width) / 2); const int msg_x = int((getWidth() - max_line_width) / 2);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
if ( ! headline_text.isEmpty() ) if ( ! headline_text.isEmpty() )
@ -376,7 +377,7 @@ void FMessageBox::draw()
y++; y++;
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }

View File

@ -308,7 +308,7 @@ bool FMouse::isDblclickTimeout (const timeval* time)
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FMouseGPM::FMouseGPM() FMouseGPM::FMouseGPM()
: FMouse() : FMouse{}
{ {
gpm_ev.x = -1; gpm_ev.x = -1;
} }

View File

@ -43,7 +43,7 @@ const FString* fc::emptyFString::empty_string{nullptr};
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FObject::FObject (FObject* parent) FObject::FObject (FObject* parent)
: parent_obj(parent) : parent_obj{parent}
{ {
if ( parent ) // add object to parent if ( parent ) // add object to parent
{ {
@ -60,9 +60,9 @@ FObject::FObject (FObject* parent)
{ {
timer_list = new FTimerList; timer_list = new FTimerList;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTimerList");
return; return;
} }
} }
@ -191,19 +191,18 @@ bool FObject::event (FEvent* ev)
{ {
// Receives events on this object // Receives events on this object
if ( ev->type() == fc::Timer_Event ) if ( ev->getType() == fc::Timer_Event )
{ {
onTimer ( static_cast<FTimerEvent*>(ev) ); onTimer ( static_cast<FTimerEvent*>(ev) );
return true;
} }
else if ( ev->getType() == fc::User_Event )
if ( ev->type() == fc::User_Event )
{ {
onUserEvent ( static_cast<FUserEvent*>(ev) ); onUserEvent ( static_cast<FUserEvent*>(ev) );
return true;
} }
else
return false; return false;
return true;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -22,7 +22,9 @@
#include <cstring> #include <cstring>
#include "final/fapplication.h"
#include "final/fc.h" #include "final/fc.h"
#include "final/flog.h"
#include "final/foptimove.h" #include "final/foptimove.h"
#include "final/ftermcap.h" #include "final/ftermcap.h"
@ -36,7 +38,7 @@ namespace finalcut
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FOptiMove::FOptiMove (int baud) FOptiMove::FOptiMove (int baud)
: baudrate(baud) : baudrate{baud}
{ {
assert ( baud >= 0 ); assert ( baud >= 0 );
@ -1105,42 +1107,43 @@ void FOptiMove::moveByMethod ( int method
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void printDurations (const FOptiMove& om) void printDurations (const FOptiMove& om)
{ {
std::cout << " speed: " finalcut::FLog& log = *FApplication::getLog();
<< om.baudrate << " baud\r\n"; log << " speed: "
std::cout << " char_duration: " << om.baudrate << " baud" << std::flush;
<< om.char_duration << " ms\r\n"; log << " char_duration: "
std::cout << " cursor_home: " << om.char_duration << " ms" << std::flush;
<< om.F_cursor_home.duration << " ms\r\n"; log << " cursor_home: "
std::cout << " cursor_to_ll: " << om.F_cursor_home.duration << " ms" << std::flush;
<< om.F_cursor_to_ll.duration << " ms\r\n"; log << " cursor_to_ll: "
std::cout << " carriage_return: " << om.F_cursor_to_ll.duration << " ms" << std::flush;
<< om.F_carriage_return.duration << " ms\r\n"; log << " carriage_return: "
std::cout << " tab: " << om.F_carriage_return.duration << " ms" << std::flush;
<< om.F_tab.duration << " ms\r\n"; log << " tab: "
std::cout << " back_tab: " << om.F_tab.duration << " ms" << std::flush;
<< om.F_back_tab.duration << " ms\r\n"; log << " back_tab: "
std::cout << " cursor_up: " << om.F_back_tab.duration << " ms" << std::flush;
<< om.F_cursor_up.duration << " ms\r\n"; log << " cursor_up: "
std::cout << " cursor_down: " << om.F_cursor_up.duration << " ms" << std::flush;
<< om.F_cursor_down.duration << " ms\r\n"; log << " cursor_down: "
std::cout << " cursor_left: " << om.F_cursor_down.duration << " ms" << std::flush;
<< om.F_cursor_left.duration << " ms\r\n"; log << " cursor_left: "
std::cout << " cursor_right: " << om.F_cursor_left.duration << " ms" << std::flush;
<< om.F_cursor_right.duration << " ms\r\n"; log << " cursor_right: "
std::cout << " cursor_address: " << om.F_cursor_right.duration << " ms" << std::flush;
<< om.F_cursor_address.duration << " ms\r\n"; log << " cursor_address: "
std::cout << " column_address: " << om.F_cursor_address.duration << " ms" << std::flush;
<< om.F_column_address.duration << " ms\r\n"; log << " column_address: "
std::cout << " row_address: " << om.F_column_address.duration << " ms" << std::flush;
<< om.F_row_address.duration << " ms\r\n"; log << " row_address: "
std::cout << " parm_up_cursor: " << om.F_row_address.duration << " ms" << std::flush;
<< om.F_parm_up_cursor.duration << " ms\r\n"; log << " parm_up_cursor: "
std::cout << " parm_down_cursor: " << om.F_parm_up_cursor.duration << " ms" << std::flush;
<< om.F_parm_down_cursor.duration << " ms\r\n"; log << " parm_down_cursor: "
std::cout << " parm_left_cursor: " << om.F_parm_down_cursor.duration << " ms" << std::flush;
<< om.F_parm_left_cursor.duration << " ms\r\n"; log << " parm_left_cursor: "
std::cout << "parm_right_cursor: " << om.F_parm_left_cursor.duration << " ms" << std::flush;
<< om.F_parm_right_cursor.duration << " ms\r\n"; log << "parm_right_cursor: "
<< om.F_parm_right_cursor.duration << " ms" << std::flush;
} }
} // namespace finalcut } // namespace finalcut

View File

@ -36,7 +36,7 @@ namespace finalcut
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FProgressbar::FProgressbar(FWidget* parent) FProgressbar::FProgressbar(FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
unsetFocusable(); unsetFocusable();
setShadow(); setShadow();
@ -92,8 +92,8 @@ void FProgressbar::setGeometry ( const FPoint& pos, const FSize& size
bool FProgressbar::setShadow (bool enable) bool FProgressbar::setShadow (bool enable)
{ {
if ( enable if ( enable
&& getEncoding() != fc::VT100 && FTerm::getEncoding() != fc::VT100
&& getEncoding() != fc::ASCII ) && FTerm::getEncoding() != fc::ASCII )
{ {
setFlags().shadow = true; setFlags().shadow = true;
setShadowSize(FSize{1, 1}); setShadowSize(FSize{1, 1});
@ -148,20 +148,10 @@ void FProgressbar::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FProgressbar::drawProgressLabel() void FProgressbar::drawProgressLabel()
{ {
const auto& parent_widget = getParentWidget(); if ( FTerm::isMonochron() )
if ( parent_widget )
setColor ( parent_widget->getForegroundColor()
, parent_widget->getBackgroundColor() );
else
{
const auto& wc = getFWidgetColors();
setColor (wc.dialog_fg, wc.dialog_bg);
}
if ( isMonochron() )
setReverse(true); setReverse(true);
useParentWidgetColor();
print() << FPoint{int(getWidth()) - 3, 0}; print() << FPoint{int(getWidth()) - 3, 0};
if ( percentage > 100 ) if ( percentage > 100 )
@ -169,7 +159,7 @@ void FProgressbar::drawProgressLabel()
else else
printf ("%3zu %%", percentage); printf ("%3zu %%", percentage);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
@ -184,7 +174,7 @@ void FProgressbar::drawProgressBar()
drawProgressBackground(len); drawProgressBackground(len);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
updateTerminal(); updateTerminal();
@ -196,31 +186,31 @@ std::size_t FProgressbar::drawProgressIndicator()
{ {
// Draw the progress indicator // Draw the progress indicator
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
const double length = double(bar_length * percentage) / 100; const double length = double(bar_length * percentage) / 100;
auto len = std::size_t(trunc(length)); auto len = std::size_t(trunc(length));
print() << FColorPair {wc.progressbar_fg, wc.progressbar_fg} print() << FColorPair {wc->progressbar_fg, wc->progressbar_fg}
<< FString {len, fc::FullBlock}; // █ << FString {len, fc::FullBlock}; // █
if ( len >= bar_length ) if ( len >= bar_length )
return len; return len;
if ( round(length) > len || getMaxColor() < 16 ) if ( round(length) > len || FTerm::getMaxColor() < 16 )
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
print(' '); print(' ');
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
} }
else else
{ {
print() << FColorPair{wc.progressbar_fg, wc.progressbar_bg} print() << FColorPair{wc->progressbar_fg, wc->progressbar_bg}
<< fc::LeftHalfBlock; // ▌ << fc::LeftHalfBlock; // ▌
} }
@ -234,10 +224,10 @@ void FProgressbar::drawProgressBackground (std::size_t len)
// Draw the progress background // Draw the progress background
const std::size_t bg_len = bar_length - len; const std::size_t bg_len = bar_length - len;
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.progressbar_fg, wc.progressbar_bg); setColor (wc->progressbar_fg, wc->progressbar_bg);
if ( getMaxColor() < 16 ) if ( FTerm::getMaxColor() < 16 )
print() << FString {bg_len, fc::MediumShade}; // ▒ print() << FString {bg_len, fc::MediumShade}; // ▒
else else
print() << FString {bg_len, L' '}; print() << FString {bg_len, L' '};

View File

@ -33,14 +33,14 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FRadioButton::FRadioButton(FWidget* parent) FRadioButton::FRadioButton(FWidget* parent)
: FToggleButton(parent) : FToggleButton{parent}
{ {
init(); init();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FRadioButton::FRadioButton (const FString& txt, FWidget* parent) FRadioButton::FRadioButton (const FString& txt, FWidget* parent)
: FToggleButton(txt, parent) : FToggleButton{txt, parent}
{ {
init(); init();
} }
@ -74,9 +74,9 @@ void FRadioButton::draw()
void FRadioButton::drawRadioButton() void FRadioButton::drawRadioButton()
{ {
print() << FPoint{1, 1}; print() << FPoint{1, 1};
setColor(); useParentWidgetColor();
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
if ( hasFocus() ) if ( hasFocus() )
setReverse(false); setReverse(false);
@ -89,14 +89,14 @@ void FRadioButton::drawRadioButton()
else else
drawUnchecked(); drawUnchecked();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FRadioButton::drawChecked() inline void FRadioButton::drawChecked()
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
print (CHECKED_RADIO_BUTTON); print (CHECKED_RADIO_BUTTON);
else else
{ {
@ -109,7 +109,7 @@ inline void FRadioButton::drawChecked()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FRadioButton::drawUnchecked() inline void FRadioButton::drawUnchecked()
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
print (RADIO_BUTTON); print (RADIO_BUTTON);
else else
{ {

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2015-2019 Markus Gans * * Copyright 2015-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -34,14 +34,14 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FRadioMenuItem::FRadioMenuItem (FWidget* parent) FRadioMenuItem::FRadioMenuItem (FWidget* parent)
: FMenuItem(parent) : FMenuItem{parent}
{ {
init (parent); init (parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FRadioMenuItem::FRadioMenuItem (const FString& txt, FWidget* parent) FRadioMenuItem::FRadioMenuItem (const FString& txt, FWidget* parent)
: FMenuItem(txt, parent) : FMenuItem{txt, parent}
{ {
init (parent); init (parent);
} }

View File

@ -36,18 +36,18 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FRect::FRect (const FPoint& p, const FSize& s) FRect::FRect (const FPoint& p, const FSize& s)
: X1(p.getX()) : X1{p.getX()}
, Y1(p.getY()) , Y1{p.getY()}
, X2(p.getX() + int(s.getWidth()) - 1) , X2{p.getX() + int(s.getWidth()) - 1}
, Y2(p.getY() + int(s.getHeight()) - 1) , Y2{p.getY() + int(s.getHeight()) - 1}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FRect::FRect (const FPoint& p1, const FPoint& p2) FRect::FRect (const FPoint& p1, const FPoint& p2)
: X1(p1.getX()) : X1{p1.getX()}
, Y1(p1.getY()) , Y1{p1.getY()}
, X2(p2.getX()) , X2{p2.getX()}
, Y2(p2.getY()) , Y2{p2.getY()}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -37,7 +37,7 @@ namespace finalcut
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FScrollbar::FScrollbar(FWidget* parent) FScrollbar::FScrollbar(FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
// The default scrollbar orientation is vertical // The default scrollbar orientation is vertical
setGeometry(FPoint{1, 1}, FSize{1, length}, false); setGeometry(FPoint{1, 1}, FSize{1, length}, false);
@ -46,7 +46,7 @@ FScrollbar::FScrollbar(FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FScrollbar::FScrollbar(fc::orientation o, FWidget* parent) FScrollbar::FScrollbar(fc::orientation o, FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
setOrientation (o); setOrientation (o);
init(); init();
@ -184,7 +184,7 @@ void FScrollbar::redraw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollbar::calculateSliderValues() void FScrollbar::calculateSliderValues()
{ {
if ( isNewFont() && bar_orientation == fc::horizontal ) if ( FTerm::isNewFont() && bar_orientation == fc::horizontal )
bar_length = ( length > 2 ) ? length - 4 : 1; bar_length = ( length > 2 ) ? length - 4 : 1;
else else
bar_length = ( length > 2 ) ? length - 2 : 1; bar_length = ( length > 2 ) ? length - 2 : 1;
@ -276,7 +276,7 @@ void FScrollbar::onMouseDown (FMouseEvent* ev)
slider_click_stop_pos = mouse_y - 2; slider_click_stop_pos = mouse_y - 2;
else else
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
slider_click_stop_pos = mouse_x - 3; slider_click_stop_pos = mouse_x - 3;
else else
slider_click_stop_pos = mouse_x - 2; slider_click_stop_pos = mouse_x - 2;
@ -459,8 +459,8 @@ void FScrollbar::draw()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollbar::drawVerticalBar() void FScrollbar::drawVerticalBar()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.scrollbar_fg, wc.scrollbar_bg); setColor (wc->scrollbar_fg, wc->scrollbar_bg);
for (int z{1}; z <= slider_pos; z++) for (int z{1}; z <= slider_pos; z++)
{ {
@ -468,25 +468,25 @@ void FScrollbar::drawVerticalBar()
drawVerticalBackgroundLine(); drawVerticalBackgroundLine();
} }
setColor (wc.scrollbar_bg, wc.scrollbar_fg); setColor (wc->scrollbar_bg, wc->scrollbar_fg);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
for (int z{1}; z <= int(slider_length); z++) // Draw slider for (int z{1}; z <= int(slider_length); z++) // Draw slider
{ {
print() << FPoint{1, 1 + slider_pos + z}; print() << FPoint{1, 1 + slider_pos + z};
if ( isNewFont() ) if ( FTerm::isNewFont() )
print (' '); print (' ');
print (' '); print (' ');
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
setColor (wc.scrollbar_fg, wc.scrollbar_bg); setColor (wc->scrollbar_fg, wc->scrollbar_bg);
for (int z = slider_pos + int(slider_length) + 1; z <= int(bar_length); z++) for (int z = slider_pos + int(slider_length) + 1; z <= int(bar_length); z++)
{ {
@ -494,24 +494,24 @@ void FScrollbar::drawVerticalBar()
drawVerticalBackgroundLine(); drawVerticalBackgroundLine();
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FScrollbar::drawVerticalBackgroundLine() inline void FScrollbar::drawVerticalBackgroundLine()
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
if ( isMonochron() || max_color < 16 ) if ( FTerm::isMonochron() || max_color < 16 )
print (fc::MediumShade); // ▒ print (fc::MediumShade); // ▒
else else
print (fc::NF_border_line_left); // ⎸ print (fc::NF_border_line_left); // ⎸
} }
if ( isMonochron() || max_color < 16 ) if ( FTerm::isMonochron() || max_color < 16 )
print (fc::MediumShade); // ▒ print (fc::MediumShade); // ▒
else if ( isNewFont() ) else if ( FTerm::isNewFont() )
print (fc::NF_rev_border_line_right); //⎹ print (fc::NF_rev_border_line_right); //⎹
else else
print (' '); print (' ');
@ -520,10 +520,10 @@ inline void FScrollbar::drawVerticalBackgroundLine()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollbar::drawHorizontalBar() void FScrollbar::drawHorizontalBar()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.scrollbar_fg, wc.scrollbar_bg); setColor (wc->scrollbar_fg, wc->scrollbar_bg);
if ( isNewFont() ) if ( FTerm::isNewFont() )
print() << FPoint{3, 1}; print() << FPoint{3, 1};
else else
print() << FPoint{2, 1}; print() << FPoint{2, 1};
@ -531,33 +531,33 @@ void FScrollbar::drawHorizontalBar()
for (int z{0}; z < slider_pos; z++) for (int z{0}; z < slider_pos; z++)
drawHorizontalBackgroundColumn(); drawHorizontalBackgroundColumn();
setColor (wc.scrollbar_bg, wc.scrollbar_fg); setColor (wc->scrollbar_bg, wc->scrollbar_fg);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
for (int z{0}; z < int(slider_length); z++) // Draw slider for (int z{0}; z < int(slider_length); z++) // Draw slider
print (' '); print (' ');
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
setColor (wc.scrollbar_fg, wc.scrollbar_bg); setColor (wc->scrollbar_fg, wc->scrollbar_bg);
int z = slider_pos + int(slider_length) + 1; int z = slider_pos + int(slider_length) + 1;
for (; z <= int(bar_length); z++) for (; z <= int(bar_length); z++)
drawHorizontalBackgroundColumn(); drawHorizontalBackgroundColumn();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FScrollbar::drawHorizontalBackgroundColumn() inline void FScrollbar::drawHorizontalBackgroundColumn()
{ {
if ( isNewFont() && max_color > 8 ) if ( FTerm::isNewFont() && max_color > 8 )
print (fc::NF_border_line_up_and_down); // ニ print (fc::NF_border_line_up_and_down); // ニ
else if ( isMonochron() || max_color < 16 ) else if ( FTerm::isMonochron() || max_color < 16 )
print (fc::MediumShade); // ▒ print (fc::MediumShade); // ▒
else else
print (' '); print (' ');
@ -566,10 +566,10 @@ inline void FScrollbar::drawHorizontalBackgroundColumn()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollbar::drawButtons() void FScrollbar::drawButtons()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.scrollbar_button_fg, wc.scrollbar_button_bg); setColor (wc->scrollbar_button_fg, wc->scrollbar_button_bg);
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
print() << FPoint{1, 1}; print() << FPoint{1, 1};
@ -590,7 +590,7 @@ void FScrollbar::drawButtons()
{ {
print() << FPoint{1, 1}; print() << FPoint{1, 1};
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
if ( bar_orientation == fc::vertical ) if ( bar_orientation == fc::vertical )
@ -606,7 +606,7 @@ void FScrollbar::drawButtons()
<< fc::BlackRightPointingPointer; // ► << fc::BlackRightPointingPointer; // ►
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
} }
@ -650,7 +650,7 @@ FScrollbar::sType FScrollbar::getVerticalClickedScrollType (int y)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FScrollbar::sType FScrollbar::getHorizontalClickedScrollType (int x) FScrollbar::sType FScrollbar::getHorizontalClickedScrollType (int x)
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
if ( x == 1 || x == 2 ) if ( x == 1 || x == 2 )
{ {
@ -707,7 +707,7 @@ int FScrollbar::getSliderClickPos (int mouse_x, int mouse_y)
} }
else // horizontal bar orientation else // horizontal bar orientation
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
if ( mouse_x > slider_pos + 2 if ( mouse_x > slider_pos + 2
&& mouse_x <= slider_pos + int(slider_length) + 2 ) && mouse_x <= slider_pos + int(slider_length) + 2 )
@ -741,7 +741,7 @@ void FScrollbar::jumpToClickPos (int x, int y)
} }
else // horizontal else // horizontal
{ {
const int nf = isNewFont() ? 1 : 0; const int nf = FTerm::isNewFont() ? 1 : 0;
if ( x > 1 + nf && x < int(getWidth()) - nf ) if ( x > 1 + nf && x < int(getWidth()) - nf )
{ {
@ -769,7 +769,7 @@ void FScrollbar::jumpToClickPos (int pos)
jumpToClickPos (0, pos + 2); jumpToClickPos (0, pos + 2);
else else
{ {
if ( isNewFont() ) if ( FTerm::isNewFont() )
jumpToClickPos (pos + 3, 0); jumpToClickPos (pos + 3, 0);
else else
jumpToClickPos (pos + 2, 0); jumpToClickPos (pos + 2, 0);
@ -807,7 +807,7 @@ void FScrollbar::changeOnResize()
if ( bar_orientation == fc::vertical ) if ( bar_orientation == fc::vertical )
{ {
setWidth(isNewFont() ? 2 : 1); setWidth(FTerm::isNewFont() ? 2 : 1);
setHeight(length); setHeight(length);
} }
else // horizontal else // horizontal

View File

@ -38,7 +38,7 @@ namespace finalcut
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FScrollView::FScrollView (FWidget* parent) FScrollView::FScrollView (FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init(parent); init(parent);
} }
@ -293,6 +293,15 @@ bool FScrollView::setViewportPrint (bool enable)
return (use_own_print_area = ! enable); return (use_own_print_area = ! enable);
} }
//----------------------------------------------------------------------
void FScrollView::resetColors()
{
const auto& wc = getColorTheme();
setForegroundColor (wc->dialog_fg);
setBackgroundColor (wc->dialog_bg);
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FScrollView::setBorder (bool enable) bool FScrollView::setBorder (bool enable)
{ {
@ -416,7 +425,7 @@ void FScrollView::draw()
{ {
unsetViewportPrint(); unsetViewportPrint();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
if ( const auto& p = getParentWidget() ) if ( const auto& p = getParentWidget() )
@ -427,7 +436,7 @@ void FScrollView::draw()
if ( hasBorder() ) if ( hasBorder() )
drawBorder(); drawBorder();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
setViewportPrint(); setViewportPrint();
@ -712,14 +721,12 @@ void FScrollView::init (const 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(); mapKeyFunctions();
const auto& wc = getFWidgetColors(); resetColors();
setForegroundColor (wc.dialog_fg);
setBackgroundColor (wc.dialog_bg);
setGeometry (FPoint{1, 1}, FSize{4, 4}); setGeometry (FPoint{1, 1}, FSize{4, 4});
setMinimumSize (FSize{4, 4}); setMinimumSize (FSize{4, 4});
const int xoffset_end = int(getScrollWidth() - getViewportWidth()); const int xoffset_end = int(getScrollWidth() - getViewportWidth());
const int yoffset_end = int(getScrollHeight() - getViewportHeight()); const int yoffset_end = int(getScrollHeight() - getViewportHeight());
nf_offset = isNewFont() ? 1 : 0; nf_offset = FTerm::isNewFont() ? 1 : 0;
setTopPadding (1 - getScrollY()); setTopPadding (1 - getScrollY());
setLeftPadding (1 - getScrollX()); setLeftPadding (1 - getScrollX());
setBottomPadding (1 - (yoffset_end - getScrollY())); setBottomPadding (1 - (yoffset_end - getScrollY()));
@ -769,7 +776,7 @@ void FScrollView::calculateScrollbarPos()
const std::size_t width = getWidth(); const std::size_t width = getWidth();
const std::size_t height = getHeight(); const std::size_t height = getHeight();
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
vbar->setGeometry (FPoint{int(width), 2}, FSize{2, height - 2}); vbar->setGeometry (FPoint{int(width), 2}, FSize{2, height - 2});
hbar->setGeometry (FPoint{1, int(height)}, FSize{width - 2, 1}); hbar->setGeometry (FPoint{1, int(height)}, FSize{width - 2, 1});

View File

@ -42,7 +42,7 @@ namespace finalcut
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FSpinBox::FSpinBox (FWidget* parent) FSpinBox::FSpinBox (FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
} }
@ -92,8 +92,8 @@ bool FSpinBox::setFocus (bool enable)
bool FSpinBox::setShadow (bool enable) bool FSpinBox::setShadow (bool enable)
{ {
if ( enable if ( enable
&& getEncoding() != fc::VT100 && FTerm::getEncoding() != fc::VT100
&& getEncoding() != fc::ASCII ) && FTerm::getEncoding() != fc::ASCII )
{ {
setFlags().shadow = true; setFlags().shadow = true;
setShadowSize(FSize{1, 1}); setShadowSize(FSize{1, 1});
@ -326,26 +326,26 @@ void FSpinBox::init()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FSpinBox::draw() void FSpinBox::draw()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
const FColorPair inc_button_color = [this, &wc] () const FColorPair inc_button_color = [this, &wc] ()
{ {
if ( value == max ) if ( value == max )
return FColorPair { wc.scrollbar_button_inactive_fg return FColorPair { wc->scrollbar_button_inactive_fg
, wc.scrollbar_button_inactive_bg }; , wc->scrollbar_button_inactive_bg };
else else
return FColorPair { wc.scrollbar_button_fg return FColorPair { wc->scrollbar_button_fg
, wc.scrollbar_button_bg }; , wc->scrollbar_button_bg };
}(); }();
const FColorPair dec_button_color = [this, &wc] () const FColorPair dec_button_color = [this, &wc] ()
{ {
if ( value == min ) if ( value == min )
return FColorPair { wc.scrollbar_button_inactive_fg return FColorPair { wc->scrollbar_button_inactive_fg
, wc.scrollbar_button_inactive_bg }; , wc->scrollbar_button_inactive_bg };
else else
return FColorPair { wc.scrollbar_button_fg return FColorPair { wc->scrollbar_button_fg
, wc.scrollbar_button_bg }; , wc->scrollbar_button_bg };
}(); }();
print() << FPoint{int(getWidth()) - 1, 1} print() << FPoint{int(getWidth()) - 1, 1}

View File

@ -20,6 +20,8 @@
* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***********************************************************************/ ***********************************************************************/
#include "final/fapplication.h"
#include "final/flog.h"
#include "final/fstartoptions.h" #include "final/fstartoptions.h"
namespace finalcut namespace finalcut
@ -49,6 +51,7 @@ FStartOptions::FStartOptions()
#elif defined(__NetBSD__) || defined(__OpenBSD__) #elif defined(__NetBSD__) || defined(__OpenBSD__)
, meta_sends_escape{true} , meta_sends_escape{true}
#endif #endif
, dark_theme{false}
{ } { }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -65,9 +68,9 @@ FStartOptions& FStartOptions::getFStartOptions()
{ {
start_options = new FStartOptions; start_options = new FStartOptions;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FStartOptions");
std::abort(); std::abort();
} }
} }

View File

@ -36,16 +36,16 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FStatusKey::FStatusKey(FWidget* parent) FStatusKey::FStatusKey(FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init (parent); init (parent);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FStatusKey::FStatusKey (FKey k, const FString& txt, FWidget* parent) FStatusKey::FStatusKey (FKey k, const FString& txt, FWidget* parent)
: FWidget(parent) : FWidget{parent}
, text(txt) , text{txt}
, key(k) , key{k}
{ {
init (parent); init (parent);
} }
@ -126,7 +126,7 @@ void FStatusKey::processActivate()
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FStatusBar::FStatusBar(FWidget* parent) FStatusBar::FStatusBar(FWidget* parent)
: FWindow(parent) : FWindow{parent}
{ {
init(); init();
} }
@ -158,6 +158,15 @@ void FStatusBar::setMessage (const FString& mgs)
text.setString(mgs); text.setString(mgs);
} }
//----------------------------------------------------------------------
void FStatusBar::resetColors()
{
const auto& wc = getColorTheme();
setForegroundColor (wc->statusbar_fg);
setBackgroundColor (wc->statusbar_bg);
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FStatusBar::hasActivatedKey() const bool FStatusBar::hasActivatedKey() const
{ {
@ -174,9 +183,9 @@ bool FStatusBar::hasActivatedKey() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FStatusBar::hide() void FStatusBar::hide()
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
const FColor fg = wc.term_fg; const FColor fg = wc->term_fg;
const FColor bg = wc.term_bg; const FColor bg = wc->term_bg;
setColor (fg, bg); setColor (fg, bg);
print() << FPoint{1, 1} << FString{getDesktopWidth(), L' '}; print() << FPoint{1, 1} << FString{getDesktopWidth(), L' '};
updateTerminal(); updateTerminal();
@ -210,11 +219,11 @@ void FStatusBar::drawMessage()
if ( isLastActiveFocus ) if ( isLastActiveFocus )
space_offset = 0; space_offset = 0;
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.statusbar_fg, wc.statusbar_bg); setColor (wc->statusbar_fg, wc->statusbar_bg);
setPrintPos ({x, 1}); setPrintPos ({x, 1});
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
if ( x + space_offset + 3 < int(termWidth) && text ) if ( x + space_offset + 3 < int(termWidth) && text )
@ -249,7 +258,7 @@ void FStatusBar::drawMessage()
for (int i = x; i <= int(termWidth); i++) for (int i = x; i <= int(termWidth); i++)
print (' '); print (' ');
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
@ -513,16 +522,14 @@ void FStatusBar::init()
if ( getRootWidget() ) if ( getRootWidget() )
getRootWidget()->setBottomPadding(1, true); getRootWidget()->setBottomPadding(1, true);
const auto& wc = getFWidgetColors(); resetColors();
setForegroundColor (wc.statusbar_fg);
setBackgroundColor (wc.statusbar_bg);
unsetFocusable(); unsetFocusable();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FStatusBar::getKeyNameWidth (const FStatusKey* key) int FStatusBar::getKeyNameWidth (const FStatusKey* key)
{ {
const FString& key_name = getKeyName(key->getKey()); const FString& key_name = FTerm::getKeyName(key->getKey());
return int(getColumnWidth(key_name)); return int(getColumnWidth(key_name));
} }
@ -554,7 +561,7 @@ void FStatusBar::drawKeys()
print() << FPoint{1, 1}; print() << FPoint{1, 1};
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
auto iter = key_list.begin(); auto iter = key_list.begin();
@ -573,8 +580,8 @@ void FStatusBar::drawKeys()
} }
else else
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.statusbar_fg, wc.statusbar_bg); setColor (wc->statusbar_fg, wc->statusbar_bg);
for (; x <= int(screenWidth); x++) for (; x <= int(screenWidth); x++)
print (' '); print (' ');
@ -583,7 +590,7 @@ void FStatusBar::drawKeys()
++iter; ++iter;
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
x_msg = x; x_msg = x;
@ -595,13 +602,13 @@ void FStatusBar::drawKey (keyList::const_iterator iter)
// Draw not active key // Draw not active key
const auto item = *iter; const auto item = *iter;
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.statusbar_hotkey_fg, wc.statusbar_hotkey_bg); setColor (wc->statusbar_hotkey_fg, wc->statusbar_hotkey_bg);
x++; x++;
print (' '); print (' ');
x += keyname_len; x += keyname_len;
print (getKeyName(item->getKey())); print (FTerm::getKeyName(item->getKey()));
setColor (wc.statusbar_fg, wc.statusbar_bg); setColor (wc->statusbar_fg, wc->statusbar_bg);
x++; x++;
print ('-'); print ('-');
const auto column_width = getColumnWidth (item->getText()); const auto column_width = getColumnWidth (item->getText());
@ -622,12 +629,12 @@ void FStatusBar::drawKey (keyList::const_iterator iter)
&& x + getKeyNameWidth(*(iter + 1)) + 3 < int(screenWidth) ) && x + getKeyNameWidth(*(iter + 1)) + 3 < int(screenWidth) )
{ {
// Next element is active // Next element is active
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
if ( hasHalfBlockCharacter() ) if ( FTerm::hasHalfBlockCharacter() )
{ {
setColor (wc.statusbar_active_fg, wc.statusbar_active_bg); setColor (wc->statusbar_bg, wc->statusbar_active_hotkey_bg);
print (fc::LeftHalfBlock); // ▐ print (fc::LeftHalfBlock); // ▐
} }
else else
@ -635,13 +642,13 @@ void FStatusBar::drawKey (keyList::const_iterator iter)
x++; x++;
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
} }
else if ( iter + 1 != key_list.end() && x < int(screenWidth) ) else if ( iter + 1 != key_list.end() && x < int(screenWidth) )
{ {
// Not the last element // Not the last element
setColor (wc.statusbar_separator_fg, wc.statusbar_bg); setColor (wc->statusbar_separator_fg, wc->statusbar_bg);
x++; x++;
print (fc::BoxDrawingsVertical); // │ print (fc::BoxDrawingsVertical); // │
} }
@ -654,17 +661,17 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter)
const auto& item = *iter; const auto& item = *iter;
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor ( wc.statusbar_active_hotkey_fg setColor ( wc->statusbar_active_hotkey_fg
, wc.statusbar_active_hotkey_bg ); , wc->statusbar_active_hotkey_bg );
x++; x++;
print (' '); print (' ');
x += keyname_len; x += keyname_len;
print (getKeyName(item->getKey())); print (FTerm::getKeyName(item->getKey()));
setColor (wc.statusbar_active_fg, wc.statusbar_active_bg); setColor (wc->statusbar_active_fg, wc->statusbar_active_bg);
x++; x++;
print ('-'); print ('-');
const auto column_width = getColumnWidth (item->getText()); const auto column_width = getColumnWidth (item->getText());
@ -674,6 +681,7 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter)
{ {
print (item->getText()); print (item->getText());
x++; x++;
setColor (wc->statusbar_bg, wc->statusbar_active_hotkey_bg);
print (fc::RightHalfBlock); // ▌ print (fc::RightHalfBlock); // ▌
} }
else else
@ -684,7 +692,7 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter)
<< ".."; << "..";
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
} }

View File

@ -25,6 +25,8 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "final/fapplication.h"
#include "final/flog.h"
#include "final/fstring.h" #include "final/fstring.h"
namespace finalcut namespace finalcut
@ -43,21 +45,21 @@ const wchar_t FString::const_null_char{L'\0'};
FString::FString (int len) FString::FString (int len)
{ {
if ( len > 0 ) if ( len > 0 )
initLength(std::size_t(len)); _initLength(std::size_t(len));
else else
initLength(0); _initLength(0);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString::FString (std::size_t len) FString::FString (std::size_t len)
{ {
initLength(len); _initLength(len);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString::FString (std::size_t len, wchar_t c) FString::FString (std::size_t len, wchar_t c)
{ {
initLength(len); _initLength(len);
const wchar_t* ps = string; const wchar_t* ps = string;
wchar_t* pe = string + len; wchar_t* pe = string + len;
@ -74,12 +76,12 @@ FString::FString (const FString& s) // copy constructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString::FString (FString&& s) noexcept // move constructor FString::FString (FString&& s) noexcept // move constructor
: string{std::move(s.string)}
, length{s.length}
, bufsize{s.bufsize}
, c_string{std::move(s.c_string)}
{ {
if ( ! s.isNull() )
_assign (std::move(s.string));
else
s.string = nullptr; s.string = nullptr;
s.length = 0; s.length = 0;
s.bufsize = 0; s.bufsize = 0;
s.c_string = nullptr; s.c_string = nullptr;
@ -104,7 +106,7 @@ FString::FString (const std::string& s)
{ {
if ( ! s.empty() ) if ( ! s.empty() )
{ {
const wchar_t* wc_string = c_to_wc_str(s.c_str()); const wchar_t* wc_string = _to_wcstring(s.c_str());
_assign(wc_string); _assign(wc_string);
delete[] wc_string; delete[] wc_string;
} }
@ -115,7 +117,7 @@ FString::FString (const char s[])
{ {
if ( s ) if ( s )
{ {
const wchar_t* wc_string = c_to_wc_str(s); const wchar_t* wc_string = _to_wcstring(s);
_assign( wc_string ); _assign( wc_string );
delete[] wc_string; delete[] wc_string;
} }
@ -172,14 +174,34 @@ FString::~FString() // destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::operator = (const FString& s) FString& FString::operator = (const FString& s)
{ {
if ( &s != this )
_assign (s.string); _assign (s.string);
return *this; return *this;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::operator = (FString&& s) noexcept FString& FString::operator = (FString&& s) noexcept
{ {
_assign (std::move(s.string)); if ( &s != this )
{
if ( string )
delete[](string);
if ( c_string )
delete[](c_string);
string = std::move(s.string);
length = s.length;
bufsize = s.bufsize;
c_string = std::move(s.c_string);
s.string = nullptr;
s.length = 0;
s.bufsize = 0;
s.c_string = nullptr;
}
return *this; return *this;
} }
@ -399,9 +421,9 @@ const char* FString::c_str() const
// Returns a constant c-string // Returns a constant c-string
if ( length > 0 ) if ( length > 0 )
return wc_to_c_str (string); return _to_cstring(string);
else if ( string ) else if ( string )
return const_cast<const char*>(""); return "";
else else
return nullptr; return nullptr;
} }
@ -412,7 +434,7 @@ char* FString::c_str()
// Returns a c-string // Returns a c-string
if ( length > 0 ) if ( length > 0 )
return wc_to_c_str (string); return const_cast<char*>(_to_cstring(string));
else if ( string ) else if ( string )
return const_cast<char*>(""); return const_cast<char*>("");
else else
@ -759,12 +781,12 @@ FStringList FString::split (const FString& delimiter)
return string_list; return string_list;
wchar_t* rest{nullptr}; wchar_t* rest{nullptr};
const wchar_t* token = extractToken(&rest, s.string, delimiter.wc_str()); const wchar_t* token = _extractToken(&rest, s.string, delimiter.wc_str());
while ( token ) while ( token )
{ {
string_list.push_back (FString{token}); string_list.push_back (FString{token});
token = extractToken (&rest, nullptr, delimiter.wc_str()); token = _extractToken (&rest, nullptr, delimiter.wc_str());
} }
return string_list; return string_list;
@ -1219,7 +1241,7 @@ bool FString::includes (const FString& s) const
// private methods of FString // private methods of FString
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FString::initLength (std::size_t len) inline void FString::_initLength (std::size_t len)
{ {
if ( len == 0 ) if ( len == 0 )
return; return;
@ -1232,9 +1254,9 @@ inline void FString::initLength (std::size_t len)
string = new wchar_t[bufsize](); string = new wchar_t[bufsize]();
std::wmemset (string, L'\0', bufsize); std::wmemset (string, L'\0', bufsize);
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("wchar_t[bufsize]");
} }
} }
@ -1263,9 +1285,9 @@ void FString::_assign (const wchar_t s[])
{ {
string = new wchar_t[bufsize](); string = new wchar_t[bufsize]();
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("wchar_t[bufsize]");
return; return;
} }
} }
@ -1291,9 +1313,9 @@ void FString::_insert (std::size_t len, const wchar_t s[])
{ {
string = new wchar_t[bufsize](); string = new wchar_t[bufsize]();
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << " " << ex.what() << std::endl; badAllocOutput ("wchar_t[bufsize]");
return; return;
} }
@ -1338,9 +1360,9 @@ void FString::_insert ( std::size_t pos
{ {
sptr = new wchar_t[bufsize](); // generate new string sptr = new wchar_t[bufsize](); // generate new string
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << " " << ex.what() << std::endl; badAllocOutput ("wchar_t[bufsize]");
return; return;
} }
@ -1382,9 +1404,9 @@ void FString::_remove (std::size_t pos, std::size_t len)
{ {
sptr = new wchar_t[bufsize](); // generate new string sptr = new wchar_t[bufsize](); // generate new string
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << " " << ex.what() << std::endl; badAllocOutput ("wchar_t[bufsize]");
return; return;
} }
@ -1404,7 +1426,7 @@ void FString::_remove (std::size_t pos, std::size_t len)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline char* FString::wc_to_c_str (const wchar_t s[]) const inline const char* FString::_to_cstring (const wchar_t s[]) const
{ {
if ( ! s ) // handle NULL string if ( ! s ) // handle NULL string
return nullptr; return nullptr;
@ -1416,9 +1438,9 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const
// Generate a empty string ("") // Generate a empty string ("")
c_string = new char[1](); c_string = new char[1]();
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << " " << ex.what() << std::endl; badAllocOutput ("char[1]");
return nullptr; return nullptr;
} }
@ -1441,9 +1463,9 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const
// pre-initialiaze the whole string with '\0' // pre-initialiaze the whole string with '\0'
std::memset (c_string, '\0', std::size_t(dest_size)); std::memset (c_string, '\0', std::size_t(dest_size));
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << " " << ex.what() << std::endl; badAllocOutput ("char[std::size_t(dest_size)]");
return nullptr; return nullptr;
} }
@ -1454,14 +1476,14 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const
{ {
delete[](c_string); delete[](c_string);
c_string = nullptr; c_string = nullptr;
return const_cast<char*>(""); return "";
} }
return c_string; return c_string;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline wchar_t* FString::c_to_wc_str (const char s[]) const inline const wchar_t* FString::_to_wcstring (const char s[]) const
{ {
if ( ! s ) // handle NULL string if ( ! s ) // handle NULL string
return nullptr; return nullptr;
@ -1473,9 +1495,9 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const
// Generate a empty wide string (L"") // Generate a empty wide string (L"")
return new wchar_t[1](); return new wchar_t[1]();
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << " " << ex.what() << std::endl; badAllocOutput ("wchar_t[1]");
return nullptr; return nullptr;
} }
} }
@ -1493,9 +1515,9 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const
// pre-initialiaze the whole string with '\0' // pre-initialiaze the whole string with '\0'
std::wmemset (dest, L'\0', std::size_t(size)); std::wmemset (dest, L'\0', std::size_t(size));
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << " " << ex.what() << std::endl; badAllocOutput ("wchar_t[std::size_t(size)]");
return nullptr; return nullptr;
} }
@ -1526,7 +1548,7 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline wchar_t* FString::extractToken ( wchar_t* rest[] inline const wchar_t* FString::_extractToken ( wchar_t* rest[]
, const wchar_t s[] , const wchar_t s[]
, const wchar_t delim[] ) , const wchar_t delim[] )
{ {
@ -1641,12 +1663,12 @@ std::ostream& operator << (std::ostream& outstr, const FString& s)
if ( s.length > 0 ) if ( s.length > 0 )
{ {
outstr << s.wc_to_c_str(s.string); outstr << s._to_cstring(s.string);
} }
else if ( width > 0 ) else if ( width > 0 )
{ {
const FString fill_str{width, wchar_t(outstr.fill())}; const FString fill_str{width, wchar_t(outstr.fill())};
outstr << s.wc_to_c_str(fill_str.string); outstr << s._to_cstring(fill_str.string);
} }
return outstr; return outstr;
@ -1657,7 +1679,7 @@ std::istream& operator >> (std::istream& instr, FString& s)
{ {
char buf[FString::INPBUFFER + 1]{}; char buf[FString::INPBUFFER + 1]{};
instr.getline (buf, FString::INPBUFFER); instr.getline (buf, FString::INPBUFFER);
const wchar_t* wc_str = s.c_to_wc_str(buf); const wchar_t* wc_str = s._to_wcstring(buf);
if ( wc_str ) if ( wc_str )
{ {

75
src/fstringstream.cpp Normal file
View File

@ -0,0 +1,75 @@
/***********************************************************************
* fstringstream.cpp - I/O operations on FString based streams *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 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/fstring.h"
#include "final/fstringstream.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FStringStream
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FStringStream::FStringStream (openmode mode)
: std::wiostream{&buffer}
, buffer{mode}
{ }
//----------------------------------------------------------------------
FStringStream::FStringStream (const FString& str, openmode mode)
: std::wiostream{&buffer}
, buffer{str.wc_str(), mode}
{ }
//----------------------------------------------------------------------
FStringStream::FStringStream (FStringStream&& sstream) noexcept
: std::wiostream{std::move(sstream)}
, buffer{std::move(sstream.buffer)}
{
std::wiostream::set_rdbuf(&buffer);
}
//----------------------------------------------------------------------
FStringStream::~FStringStream() // destructor
{ }
// public methods of FStringStream
//----------------------------------------------------------------------
FStringStream& FStringStream::operator = (FStringStream&& sstream) noexcept
{
std::wiostream::operator = (std::move(sstream));
buffer = std::move(sstream.buffer);
return *this;
}
//----------------------------------------------------------------------
void FStringStream::swap (FStringStream& sstream) noexcept
{
std::wiostream::swap(sstream);
buffer.swap(sstream.buffer);
}
} // namespace finalcut

View File

@ -35,14 +35,14 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FSwitch::FSwitch(FWidget* parent) FSwitch::FSwitch(FWidget* parent)
: FToggleButton(parent) : FToggleButton{parent}
{ {
setButtonWidth(11); setButtonWidth(11);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FSwitch::FSwitch (const FString& txt, FWidget* parent) FSwitch::FSwitch (const FString& txt, FWidget* parent)
: FToggleButton(txt, parent) : FToggleButton{txt, parent}
, switch_offset_pos(txt.getLength() + 1) , switch_offset_pos(txt.getLength() + 1)
{ {
setButtonWidth(11); setButtonWidth(11);
@ -143,46 +143,46 @@ inline void FSwitch::drawChecked()
{ {
wchar_t on[6]{L" On "}; wchar_t on[6]{L" On "};
const wchar_t off[6]{L" Off "}; const wchar_t off[6]{L" Off "};
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( hasFocus() && ! button_pressed ) if ( hasFocus() && ! button_pressed )
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
std::wcsncpy (on, L" <On>", 6); std::wcsncpy (on, L" <On>", 6);
setBold(true); setBold(true);
} }
else if ( getMaxColor() < 16 ) else if ( FTerm::getMaxColor() < 16 )
{ {
setBold(true); setBold(true);
setColor (wc.button_active_focus_fg, wc.button_active_focus_bg); setColor (wc->button_active_focus_fg, wc->button_active_focus_bg);
} }
else else
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg); setColor (wc->button_hotkey_fg, wc->button_active_focus_bg);
} }
else else
{ {
if ( isMonochron() || getMaxColor() < 16 ) if ( FTerm::isMonochron() || FTerm::getMaxColor() < 16 )
setColor (wc.button_active_focus_fg, wc.button_active_bg); setColor (wc->button_active_focus_fg, wc->button_active_bg);
else else
setColor (wc.button_hotkey_fg, wc.button_active_bg); setColor (wc->button_hotkey_fg, wc->button_active_bg);
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
print (on); print (on);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
if ( isMonochron() || getMaxColor() < 16 ) if ( FTerm::isMonochron() || FTerm::getMaxColor() < 16 )
setBold(false); setBold(false);
print() << FColorPair{wc.button_inactive_fg, wc.button_inactive_bg} print() << FColorPair{wc->button_inactive_fg, wc->button_inactive_bg}
<< off; << off;
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
setCursorPos ({3 + int(switch_offset_pos), 1}); setCursorPos ({3 + int(switch_offset_pos), 1});
@ -194,43 +194,43 @@ inline void FSwitch::drawUnchecked()
const wchar_t on[6]{L" On "}; const wchar_t on[6]{L" On "};
wchar_t off[6]{L" Off "}; wchar_t off[6]{L" Off "};
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
setColor (wc.button_inactive_fg, wc.button_inactive_bg); setColor (wc->button_inactive_fg, wc->button_inactive_bg);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
print (on); print (on);
if ( hasFocus() && ! button_pressed ) if ( hasFocus() && ! button_pressed )
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
{ {
std::wcsncpy (off, L"<Off>", 6); std::wcsncpy (off, L"<Off>", 6);
setBold(true); setBold(true);
} }
else if ( getMaxColor() < 16 ) else if ( FTerm::getMaxColor() < 16 )
{ {
setBold(true); setBold(true);
setColor (wc.button_active_focus_fg, wc.button_active_focus_bg); setColor (wc->button_active_focus_fg, wc->button_active_focus_bg);
} }
else else
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg); setColor (wc->button_hotkey_fg, wc->button_active_focus_bg);
} }
else else
{ {
if ( isMonochron() || getMaxColor() < 16 ) if ( FTerm::isMonochron() || FTerm::getMaxColor() < 16 )
setColor (wc.button_active_focus_fg, wc.button_active_bg); setColor (wc->button_active_focus_fg, wc->button_active_bg);
else else
setColor (wc.button_hotkey_fg, wc.button_active_bg); setColor (wc->button_hotkey_fg, wc->button_active_bg);
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
print (off); print (off);
if ( isMonochron() || getMaxColor() < 16 ) if ( FTerm::isMonochron() || FTerm::getMaxColor() < 16 )
setBold(false); setBold(false);
setCursorPos ({7 + int(switch_offset_pos), 1}); setCursorPos ({7 + int(switch_offset_pos), 1});

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2019 Markus Gans * * Copyright 2019-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -42,6 +42,7 @@ FSystemImpl::FSystemImpl()
FSystemImpl::~FSystemImpl() // destructor FSystemImpl::~FSystemImpl() // destructor
{ } { }
// public methods of FSystemImpl
//---------------------------------------------------------------------- //----------------------------------------------------------------------
int FSystemImpl::getpwuid_r ( uid_t uid, struct passwd* pwd int FSystemImpl::getpwuid_r ( uid_t uid, struct passwd* pwd
, char* buf, size_t buflen , char* buf, size_t buflen

View File

@ -28,9 +28,9 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fc.h" #include "final/fc.h"
#include "final/fcharmap.h" #include "final/fcharmap.h"
#include "final/fcolorpalette.h"
#include "final/fkey_map.h" #include "final/fkey_map.h"
#include "final/fkeyboard.h" #include "final/fkeyboard.h"
#include "final/flog.h"
#include "final/fmouse.h" #include "final/fmouse.h"
#include "final/foptiattr.h" #include "final/foptiattr.h"
#include "final/foptimove.h" #include "final/foptimove.h"
@ -180,6 +180,13 @@ int FTerm::getMaxColor()
return FTermcap::max_color; return FTermcap::max_color;
} }
//----------------------------------------------------------------------
FTerm::FColorPalettePtr& FTerm::getColorPaletteTheme()
{
static FColorPalettePtr* color_theme = new FColorPalettePtr();
return *color_theme;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FTermData* FTerm::getFTermData() FTermData* FTerm::getFTermData()
{ {
@ -189,9 +196,9 @@ FTermData* FTerm::getFTermData()
{ {
data = new FTermData; data = new FTermData;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTermData");
std::abort(); std::abort();
} }
} }
@ -208,9 +215,9 @@ FSystem* FTerm::getFSystem()
{ {
fsys = new FSystemImpl; fsys = new FSystemImpl;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTermData");
std::abort(); std::abort();
} }
} }
@ -227,9 +234,9 @@ FOptiMove* FTerm::getFOptiMove()
{ {
opti_move = new FOptiMove; opti_move = new FOptiMove;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FOptiMove");
std::abort(); std::abort();
} }
} }
@ -246,9 +253,9 @@ FOptiAttr* FTerm::getFOptiAttr()
{ {
opti_attr = new FOptiAttr; opti_attr = new FOptiAttr;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FOptiAttr");
std::abort(); std::abort();
} }
} }
@ -265,9 +272,9 @@ FTermDetection* FTerm::getFTermDetection()
{ {
term_detection = new FTermDetection; term_detection = new FTermDetection;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTermDetection");
std::abort(); std::abort();
} }
} }
@ -284,9 +291,9 @@ FTermXTerminal* FTerm::getFTermXTerminal()
{ {
xterm = new FTermXTerminal; xterm = new FTermXTerminal;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTermXTerminal");
std::abort(); std::abort();
} }
} }
@ -303,9 +310,9 @@ FKeyboard* FTerm::getFKeyboard()
{ {
keyboard = new FKeyboard; keyboard = new FKeyboard;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FKeyboard");
std::abort(); std::abort();
} }
} }
@ -322,9 +329,9 @@ FMouseControl* FTerm::getFMouseControl()
{ {
mouse = new FMouseControl; mouse = new FMouseControl;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseControl");
std::abort(); std::abort();
} }
} }
@ -342,9 +349,9 @@ FTermLinux* FTerm::getFTermLinux()
{ {
linux = new FTermLinux; linux = new FTermLinux;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTermLinux");
std::abort(); std::abort();
} }
} }
@ -362,9 +369,9 @@ FTermFreeBSD* FTerm::getFTermFreeBSD()
{ {
freebsd = new FTermFreeBSD; freebsd = new FTermFreeBSD;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTermFreeBSD");
std::abort(); std::abort();
} }
} }
@ -382,9 +389,9 @@ FTermOpenBSD* FTerm::getFTermOpenBSD()
{ {
openbsd = new FTermOpenBSD; openbsd = new FTermOpenBSD;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTermOpenBSD");
std::abort(); std::abort();
} }
} }
@ -403,9 +410,9 @@ FTermDebugData& FTerm::getFTermDebugData()
{ {
debug_data = new FTermDebugData; debug_data = new FTermDebugData;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTermDebugData");
std::abort(); std::abort();
} }
} }
@ -624,7 +631,7 @@ void FTerm::redefineDefaultColors (bool enable)
if ( isNewFont() ) // NewFont need the reverse-video attribute if ( isNewFont() ) // NewFont need the reverse-video attribute
return; return;
xterm->redefineDefaultColors (enable); getFTermXTerminal()->redefineDefaultColors (enable);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -665,7 +672,7 @@ bool FTerm::setVGAFont()
{ {
data->setVGAFont(true); data->setVGAFont(true);
// Set font in xterm to vga // Set font in xterm to vga
xterm->setFont("vga"); getFTermXTerminal()->setFont("vga");
data->setNewFont(false); data->setNewFont(false);
} }
#if defined(__linux__) #if defined(__linux__)
@ -700,7 +707,7 @@ bool FTerm::setNewFont()
{ {
data->setNewFont(true); data->setNewFont(true);
// Set font in xterm to 8x16graph // Set font in xterm to 8x16graph
xterm->setFont("8x16graph"); getFTermXTerminal()->setFont("8x16graph");
} }
#if defined(__linux__) #if defined(__linux__)
else if ( isLinuxTerm() ) else if ( isLinuxTerm() )
@ -739,12 +746,12 @@ bool FTerm::setOldFont()
if ( font.getLength() > 2 ) if ( font.getLength() > 2 )
{ {
// restore saved xterm font // restore saved xterm font
xterm->setFont(font); getFTermXTerminal()->setFont(font);
} }
else else
{ {
// Set font in xterm to vga // Set font in xterm to vga
xterm->setFont("vga"); getFTermXTerminal()->setFont("vga");
} }
retval = true; retval = true;
@ -914,7 +921,7 @@ void FTerm::setTermSize (const FSize& size)
{ {
// Set xterm size // Set xterm size
xterm->setTermSize (size); getFTermXTerminal()->setTermSize (size);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -922,7 +929,7 @@ void FTerm::setTermTitle (const FString& title)
{ {
// Set the xterm window title // Set the xterm window title
xterm->setTitle (title); getFTermXTerminal()->setTitle (title);
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1268,10 +1275,10 @@ void FTerm::initScreenSettings()
#endif #endif
// set xterm underline cursor // set xterm underline cursor
xterm->setCursorStyle (fc::blinking_underline); getFTermXTerminal()->setCursorStyle (fc::blinking_underline);
// set xterm color settings to defaults // set xterm color settings to defaults
xterm->setDefaults(); getFTermXTerminal()->setDefaults();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1297,7 +1304,7 @@ void FTerm::exitWithMessage (const FString& message)
std::fflush (stdout); std::fflush (stdout);
if ( ! message.isEmpty() ) if ( ! message.isEmpty() )
std::cerr << "Warning: " << message << std::endl; FApplication::getLog()->warn(message.c_str());
std::exit (EXIT_FAILURE); std::exit (EXIT_FAILURE);
} }
@ -1322,7 +1329,7 @@ void FTerm::init_global_values (bool disable_alt_screen)
data->useAlternateScreen(! disable_alt_screen); data->useAlternateScreen(! disable_alt_screen);
// Initialize xterm object // Initialize xterm object
xterm->init(); getFTermXTerminal()->init();
if ( ! getStartOptions().terminal_detection ) if ( ! getStartOptions().terminal_detection )
term_detection->setTerminalDetection (false); term_detection->setTerminalDetection (false);
@ -1845,9 +1852,9 @@ void FTerm::init_captureFontAndTitle()
if ( ! FStartOptions::getFStartOptions().terminal_data_request ) if ( ! FStartOptions::getFStartOptions().terminal_data_request )
return; return;
xterm->captureFontAndTitle(); getFTermXTerminal()->captureFontAndTitle();
const auto& font = xterm->getFont(); const auto& font = getFTermXTerminal()->getFont();
const auto& title = xterm->getTitle(); const auto& title = getFTermXTerminal()->getTitle();
if ( ! font.isEmpty() ) if ( ! font.isEmpty() )
data->setXtermFont(font); data->setXtermFont(font);
@ -1875,38 +1882,41 @@ void FTerm::redefineColorPalette()
{ {
// Redefine the color palette // Redefine the color palette
if ( ! canChangeColorPalette() ) if ( ! (canChangeColorPalette() && getStartOptions().color_change) )
return; return;
resetColorMap(); resetColorMap();
saveColorMap(); saveColorMap();
if ( getStartOptions().dark_theme )
{
setColorPaletteTheme<default16DarkColorPalette>(&FTerm::setPalette);
}
else
{
if ( getMaxColor() >= 16 ) if ( getMaxColor() >= 16 )
FColorPalette::set16ColorPalette (FTerm::setPalette); setColorPaletteTheme<default16ColorPalette>(&FTerm::setPalette);
else // 8 colors else // 8 colors
FColorPalette::set8ColorPalette (FTerm::setPalette); setColorPaletteTheme<default8ColorPalette>(&FTerm::setPalette);
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::restoreColorPalette() void FTerm::restoreColorPalette()
{ {
if ( ! canChangeColorPalette() ) if ( ! (canChangeColorPalette() && getStartOptions().color_change) )
return; return;
// Reset screen settings // Reset screen settings
if ( getMaxColor() >= 16 ) getColorPaletteTheme()->resetColorPalette();
FColorPalette::reset16ColorPalette (FTerm::setPalette); getFTermXTerminal()->resetColorMap();
else // 8 colors
FColorPalette::reset8ColorPalette (FTerm::setPalette);
xterm->resetColorMap();
resetColorMap(); resetColorMap();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::setInsertCursorStyle() void FTerm::setInsertCursorStyle()
{ {
xterm->setCursorStyle (fc::blinking_underline); getFTermXTerminal()->setCursorStyle (fc::blinking_underline);
setKDECursor(fc::UnderlineCursor); setKDECursor(fc::UnderlineCursor);
#if defined(__linux__) #if defined(__linux__)
@ -1916,13 +1926,13 @@ void FTerm::setInsertCursorStyle()
#endif #endif
if ( isUrxvtTerminal() ) if ( isUrxvtTerminal() )
xterm->setCursorColor ("rgb:ffff/ffff/ffff"); getFTermXTerminal()->setCursorColor ("rgb:ffff/ffff/ffff");
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::setOverwriteCursorStyle() void FTerm::setOverwriteCursorStyle()
{ {
xterm->setCursorStyle (fc::steady_block); getFTermXTerminal()->setCursorStyle (fc::steady_block);
setKDECursor(fc::BlockCursor); setKDECursor(fc::BlockCursor);
#if defined(__linux__) #if defined(__linux__)
@ -1932,7 +1942,7 @@ void FTerm::setOverwriteCursorStyle()
#endif #endif
if ( isUrxvtTerminal() ) if ( isUrxvtTerminal() )
xterm->setCursorColor ("rgb:eeee/0000/0000"); getFTermXTerminal()->setCursorColor ("rgb:eeee/0000/0000");
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -2250,7 +2260,7 @@ void FTerm::init (bool disable_alt_screen)
// Activate meta key sends escape // Activate meta key sends escape
if ( isXTerminal() ) if ( isXTerminal() )
xterm->metaSendsESC(true); getFTermXTerminal()->metaSendsESC(true);
// switch to application escape key mode // switch to application escape key mode
enableApplicationEscKey(); enableApplicationEscKey();
@ -2271,7 +2281,6 @@ void FTerm::init (bool disable_alt_screen)
initTermspecifics(); initTermspecifics();
// Redefine the color palette // Redefine the color palette
if ( getStartOptions().color_change )
redefineColorPalette(); redefineColorPalette();
// Set 220 Hz beep (100 ms) // Set 220 Hz beep (100 ms)
@ -2429,13 +2438,12 @@ void FTerm::finish()
} }
// Reset xterm color settings to default values // Reset xterm color settings to default values
xterm->resetDefaults(); getFTermXTerminal()->resetDefaults();
// Set xterm full block cursor // Set xterm full block cursor
xterm->setCursorStyle (fc::steady_block); getFTermXTerminal()->setCursorStyle (fc::steady_block);
// Restore the color palette // Restore the color palette
if ( getStartOptions().color_change )
restoreColorPalette(); restoreColorPalette();
// Switch to normal escape key mode // Switch to normal escape key mode
@ -2454,7 +2462,7 @@ void FTerm::finish()
// Deactivate meta key sends escape // Deactivate meta key sends escape
if ( isXTerminal() ) if ( isXTerminal() )
xterm->metaSendsESC(false); getFTermXTerminal()->metaSendsESC(false);
// Switch to the normal screen // Switch to the normal screen
useNormalScreenBuffer(); useNormalScreenBuffer();
@ -2471,7 +2479,7 @@ void FTerm::finish()
const auto& exit_message = data->getExitMessage(); const auto& exit_message = data->getExitMessage();
if ( ! exit_message.isEmpty() ) if ( ! exit_message.isEmpty() )
std::cerr << exit_message << std::endl; FApplication::getLog()->info(exit_message.c_str());
deallocationValues(); deallocationValues();
} }
@ -2497,6 +2505,13 @@ void FTerm::finish_encoding()
#endif #endif
} }
//----------------------------------------------------------------------
void FTerm::destroyColorPaletteTheme()
{
const FColorPalettePtr* theme = &(getColorPaletteTheme());
delete theme;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::setSignalHandler() void FTerm::setSignalHandler()
{ {
@ -2546,9 +2561,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::cerr << "\nProgram stopped: signal " *FApplication::getLog() << FLog::Error
<< "\nProgram stopped: signal "
<< signum << signum
<< " (" << strsignal(signum) << ")" << std::endl; << " (" << strsignal(signum) << ")"
<< std::endl;
std::terminate(); std::terminate();
default: default:

View File

@ -27,7 +27,9 @@
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
#include "final/fapplication.h"
#include "final/fcharmap.h" #include "final/fcharmap.h"
#include "final/flog.h"
#include "final/fterm.h" #include "final/fterm.h"
#include "final/ftermbuffer.h" #include "final/ftermbuffer.h"
@ -451,7 +453,8 @@ std::size_t getColumnWidth (const FString& s, std::size_t pos)
} }
catch (const std::out_of_range& ex) catch (const std::out_of_range& ex)
{ {
std::cerr << "Out of Range error: " << ex.what() << std::endl; *FApplication::getLog() << FLog::Error
<< "Out of Range error: " << ex.what() << std::endl;
} }
} }

View File

@ -83,7 +83,7 @@ void FTermcap::termcap()
std::vector<std::string> terminals{}; std::vector<std::string> terminals{};
static constexpr int success = 1; static constexpr int success = 1;
static constexpr int uninitialized = -2; static constexpr int uninitialized = -2;
static char term_buffer[2048]{}; static char term_buffer[BUF_SIZE]{};
int status = uninitialized; int status = uninitialized;
const bool color256 = term_detection->canDisplay256Colors(); const bool color256 = term_detection->canDisplay256Colors();
@ -116,9 +116,6 @@ void FTermcap::termcap()
++iter; ++iter;
} }
if ( std::strncmp(termtype, "ansi", 4) == 0 )
term_detection->setAnsiTerminal (true);
termcapError (status); termcapError (status);
termcapVariables(); termcapVariables();
} }
@ -129,19 +126,23 @@ void FTermcap::termcapError (int status)
static constexpr int no_entry = 0; static constexpr int no_entry = 0;
static constexpr int db_not_found = -1; static constexpr int db_not_found = -1;
static constexpr int uninitialized = -2; static constexpr int uninitialized = -2;
finalcut::FLog& log = *FApplication::getLog();
if ( status == no_entry || status == uninitialized ) if ( status == no_entry || status == uninitialized )
{ {
const char* termtype = fterm_data->getTermType(); const char* termtype = fterm_data->getTermType();
std::cerr << "Unknown terminal: " << termtype << "\n" log << FLog::Error
<< "Check the TERM environment variable\n" << "Unknown terminal: \"" << termtype << "\". "
<< "Also make sure that the terminal\n" << "Check the TERM environment variable. "
<< "is defined in the termcap/terminfo database.\n"; << "Also make sure that the terminal "
<< "is defined in the termcap/terminfo database."
<< std::endl;
std::abort(); std::abort();
} }
else if ( status == db_not_found ) else if ( status == db_not_found )
{ {
std::cerr << "The termcap/terminfo database could not be found.\n"; log << "The termcap/terminfo database could not be found."
<< std::endl;
std::abort(); std::abort();
} }
} }

View File

@ -25,7 +25,9 @@
#endif #endif
#include "final/emptyfstring.h" #include "final/emptyfstring.h"
#include "final/fapplication.h"
#include "final/fc.h" #include "final/fc.h"
#include "final/flog.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"
@ -377,6 +379,8 @@ void FTermDetection::detectTerminal()
if ( ! new_termtype && std::strlen(termtype) == 5 ) if ( ! new_termtype && std::strlen(termtype) == 5 )
new_termtype = "xterm-16color"; new_termtype = "xterm-16color";
} }
else if ( std::strncmp(termtype, "ansi", 4) == 0 ) // ANSI detection
terminal_type.ansi = true;
// set the new environment variable TERM // set the new environment variable TERM
if ( new_termtype ) if ( new_termtype )
@ -587,9 +591,9 @@ const char* FTermDetection::parseAnswerbackMsg (const char current_termtype[])
{ {
answer_back = new FString(getAnswerbackMsg()); answer_back = new FString(getAnswerbackMsg());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FString");
return nullptr; return nullptr;
} }
@ -657,9 +661,9 @@ const char* FTermDetection::parseSecDA (const char current_termtype[])
// Secondary device attributes (SEC_DA) <- decTerminalID string // Secondary device attributes (SEC_DA) <- decTerminalID string
sec_da = new FString(getSecDA()); sec_da = new FString(getSecDA());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FString");
return current_termtype; return current_termtype;
} }

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -20,13 +20,24 @@
* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***********************************************************************/ ***********************************************************************/
#include "final/fapplication.h"
#include "final/fcharmap.h" #include "final/fcharmap.h"
#include "final/flog.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"
#include "final/ftermfreebsd.h" #include "final/ftermfreebsd.h"
#include "final/ftypes.h" #include "final/ftypes.h"
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST)
#define initCheck(ret_value) \
if ( ! isInitialized() ) \
{ \
warnNotInitialized(); \
return ret_value; \
}
#endif
namespace finalcut namespace finalcut
{ {
@ -58,12 +69,14 @@ bool FTermFreeBSD::setCursorStyle (CursorStyle style)
{ {
// Set cursor style in a BSD console // Set cursor style in a BSD console
if ( ! fsystem || ! isFreeBSDConsole() || ! change_cursorstyle )
return false;
if ( ! fterm_data ) if ( ! fterm_data )
fterm_data = FTerm::getFTermData(); fterm_data = FTerm::getFTermData();
initCheck(false);
if ( ! fsystem || ! isFreeBSDConsole() || ! change_cursorstyle )
return false;
cursor_style = style; cursor_style = style;
if ( fterm_data->isCursorHidden() ) if ( fterm_data->isCursorHidden() )
@ -177,6 +190,16 @@ void FTermFreeBSD::finish()
// private methods of FTermFreeBSD // private methods of FTermFreeBSD
//----------------------------------------------------------------------
void FTermFreeBSD::warnNotInitialized()
{
*FApplication::getLog() << FLog::Warn
<< "The FTermFreeBSD object has "
<< "not yet been initialized! "
<< "Please call the init() method first."
<< std::endl;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermFreeBSD::saveFreeBSDAltKey() bool FTermFreeBSD::saveFreeBSDAltKey()
{ {
@ -185,8 +208,7 @@ bool FTermFreeBSD::saveFreeBSDAltKey()
static constexpr int left_alt = 0x38; static constexpr int left_alt = 0x38;
int ret{-1}; int ret{-1};
keymap_t keymap{}; keymap_t keymap{};
initCheck(false);
if ( fsystem )
ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap);
if ( ret < 0 ) if ( ret < 0 )
@ -205,8 +227,7 @@ bool FTermFreeBSD::setFreeBSDAltKey (uInt key)
static constexpr int left_alt = 0x38; static constexpr int left_alt = 0x38;
int ret{-1}; int ret{-1};
keymap_t keymap{}; keymap_t keymap{};
initCheck(false);
if ( fsystem )
ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap);
if ( ret < 0 ) if ( ret < 0 )
@ -241,6 +262,8 @@ bool FTermFreeBSD::resetFreeBSDAlt2Meta()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermFreeBSD::setFreeBSDCursorStyle (CursorStyle style) bool FTermFreeBSD::setFreeBSDCursorStyle (CursorStyle style)
{ {
initCheck(false);
if ( fsystem->ioctl(0, CONS_CURSORTYPE, &style) == 0 ) if ( fsystem->ioctl(0, CONS_CURSORTYPE, &style) == 0 )
return true; return true;
else else

View File

@ -22,8 +22,10 @@
#include <vector> #include <vector>
#include "final/fapplication.h"
#include "final/fc.h" #include "final/fc.h"
#include "final/fcharmap.h" #include "final/fcharmap.h"
#include "final/flog.h"
#include "final/fsystem.h" #include "final/fsystem.h"
#include "final/fterm.h" #include "final/fterm.h"
#include "final/ftermcap.h" #include "final/ftermcap.h"
@ -200,7 +202,7 @@ void FTermLinux::init()
} }
else else
{ {
std::cerr << "can not open the console.\n"; FApplication::getLog()->error("Can not open the console.");
std::abort(); std::abort();
} }
} }
@ -290,6 +292,9 @@ bool FTermLinux::loadVGAFont()
if ( vga_font ) if ( vga_font )
{ {
if ( ! fterm_data )
fterm_data = FTerm::getFTermData();
fterm_data->supportShadowCharacter (true); fterm_data->supportShadowCharacter (true);
fterm_data->supportHalfBlockCharacter (true); fterm_data->supportHalfBlockCharacter (true);
} }
@ -336,6 +341,9 @@ bool FTermLinux::loadNewFont()
if ( new_font ) if ( new_font )
{ {
if ( ! fterm_data )
fterm_data = FTerm::getFTermData();
fterm_data->supportShadowCharacter (true); fterm_data->supportShadowCharacter (true);
fterm_data->supportHalfBlockCharacter (true); fterm_data->supportHalfBlockCharacter (true);
} }
@ -553,9 +561,9 @@ bool FTermLinux::getScreenFont()
static constexpr std::size_t data_size = 4 * 32 * 512; static constexpr std::size_t data_size = 4 * 32 * 512;
font.data = new uChar[data_size](); font.data = new uChar[data_size]();
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FString");
return false; return false;
} }
@ -605,9 +613,9 @@ bool FTermLinux::getUnicodeMap()
{ {
screen_unicode_map.entries = new struct unipair[count](); screen_unicode_map.entries = new struct unipair[count]();
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("unipair[count]");
return false; return false;
} }
@ -683,9 +691,9 @@ int FTermLinux::setScreenFont ( uChar fontdata[], uInt count
{ {
font.data = new uChar[data_size](); // Initialize with 0 font.data = new uChar[data_size](); // Initialize with 0
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("uChar[data_size]");
return -1; return -1;
} }
@ -1286,6 +1294,9 @@ inline void FTermLinux::initSpecialCharacter()
const wchar_t c2 = fc::LowerHalfBlock; const wchar_t c2 = fc::LowerHalfBlock;
const wchar_t c3 = fc::FullBlock; const wchar_t c3 = fc::FullBlock;
if ( ! fterm_data )
fterm_data = FTerm::getFTermData();
if ( FTerm::charEncode(c1, fc::PC) == FTerm::charEncode(c1, fc::ASCII) if ( FTerm::charEncode(c1, fc::PC) == FTerm::charEncode(c1, fc::ASCII)
|| FTerm::charEncode(c2, fc::PC) == FTerm::charEncode(c2, fc::ASCII) || FTerm::charEncode(c2, fc::PC) == FTerm::charEncode(c2, fc::ASCII)
|| FTerm::charEncode(c3, fc::PC) == FTerm::charEncode(c3, fc::ASCII) ) || FTerm::charEncode(c3, fc::PC) == FTerm::charEncode(c3, fc::ASCII) )
@ -1322,6 +1333,10 @@ void FTermLinux::characterFallback ( wchar_t ucs
, std::vector<wchar_t> fallback ) , std::vector<wchar_t> fallback )
{ {
constexpr sInt16 NOT_FOUND = -1; constexpr sInt16 NOT_FOUND = -1;
if ( ! fterm_data )
fterm_data = FTerm::getFTermData();
charSubstitution& sub_map = fterm_data->getCharSubstitutionMap(); charSubstitution& sub_map = fterm_data->getCharSubstitutionMap();
if ( fallback.size() < 2 || ucs != fallback[0] ) if ( fallback.size() < 2 || ucs != fallback[0] )

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -20,10 +20,21 @@
* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***********************************************************************/ ***********************************************************************/
#include "final/fapplication.h"
#include "final/flog.h"
#include "final/fsystem.h" #include "final/fsystem.h"
#include "final/fterm.h" #include "final/fterm.h"
#include "final/ftermopenbsd.h" #include "final/ftermopenbsd.h"
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST)
#define initCheck(ret_value) \
if ( ! isInitialized() ) \
{ \
warnNotInitialized(); \
return ret_value; \
}
#endif
namespace finalcut namespace finalcut
{ {
@ -86,6 +97,8 @@ void FTermOpenBSD::init()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermOpenBSD::finish() void FTermOpenBSD::finish()
{ {
initCheck();
if ( ! isBSDConsole() ) if ( ! isBSDConsole() )
return; return;
@ -96,6 +109,8 @@ void FTermOpenBSD::finish()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermOpenBSD::setBeep (int Hz, int ms) bool FTermOpenBSD::setBeep (int Hz, int ms)
{ {
initCheck(false);
if ( ! isBSDConsole() ) if ( ! isBSDConsole() )
return false; return false;
@ -122,6 +137,7 @@ bool FTermOpenBSD::setBeep (int Hz, int ms)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermOpenBSD::resetBeep() bool FTermOpenBSD::resetBeep()
{ {
initCheck(false);
wskbd_bell_data default_bell; wskbd_bell_data default_bell;
// Gets the default setting for the bell // Gets the default setting for the bell
@ -141,6 +157,16 @@ bool FTermOpenBSD::resetBeep()
// private methods of FTermOpenBSD // private methods of FTermOpenBSD
//----------------------------------------------------------------------
void FTermOpenBSD::warnNotInitialized()
{
*FApplication::getLog() << FLog::Warn
<< "The FTermOpenBSD object has "
<< "not yet been initialized! "
<< "Please call the init() method first."
<< std::endl;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermOpenBSD::saveBSDConsoleEncoding() bool FTermOpenBSD::saveBSDConsoleEncoding()
{ {

View File

@ -24,7 +24,9 @@
#include "final/fconfig.h" // includes _GNU_SOURCE for fd_set #include "final/fconfig.h" // includes _GNU_SOURCE for fd_set
#endif #endif
#include "final/fapplication.h"
#include "final/fc.h" #include "final/fc.h"
#include "final/flog.h"
#include "final/fstring.h" #include "final/fstring.h"
#include "final/fterm.h" #include "final/fterm.h"
#include "final/ftermcap.h" #include "final/ftermcap.h"
@ -34,6 +36,13 @@
#include "final/ftermxterminal.h" #include "final/ftermxterminal.h"
#include "final/fsize.h" #include "final/fsize.h"
#define initCheck(ret_value) \
if ( ! isInitialized() ) \
{ \
warnNotInitialized(); \
return ret_value; \
}
namespace finalcut namespace finalcut
{ {
@ -256,6 +265,8 @@ void FTermXTerminal::resetHighlightBackground()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermXTerminal::resetDefaults() void FTermXTerminal::resetDefaults()
{ {
initCheck();
if ( term_detection->isPuttyTerminal() ) if ( term_detection->isPuttyTerminal() )
return; return;
@ -280,6 +291,8 @@ void FTermXTerminal::resetDefaults()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermXTerminal::captureFontAndTitle() void FTermXTerminal::captureFontAndTitle()
{ {
initCheck();
if ( ( term_detection->isXTerminal() if ( ( term_detection->isXTerminal()
|| term_detection->isUrxvtTerminal() ) || term_detection->isUrxvtTerminal() )
&& ! term_detection->isRxvtTerminal() ) && ! term_detection->isRxvtTerminal() )
@ -293,6 +306,16 @@ void FTermXTerminal::captureFontAndTitle()
// private methods of FTermXTerminal // private methods of FTermXTerminal
//----------------------------------------------------------------------
void FTermXTerminal::warnNotInitialized()
{
*FApplication::getLog() << FLog::Warn
<< "The FTermXTerminal object has "
<< "not yet been initialized! "
<< "Please call the init() method first."
<< std::endl;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermXTerminal::setXTermCursorStyle() void FTermXTerminal::setXTermCursorStyle()
{ {
@ -303,6 +326,8 @@ void FTermXTerminal::setXTermCursorStyle()
return; return;
#endif #endif
initCheck();
if ( term_detection->isGnomeTerminal() if ( term_detection->isGnomeTerminal()
&& ! term_detection->hasSetCursorStyleSupport() ) && ! term_detection->hasSetCursorStyleSupport() )
return; return;
@ -325,6 +350,7 @@ void FTermXTerminal::setXTermCursorStyle()
void FTermXTerminal::setXTermTitle() void FTermXTerminal::setXTermTitle()
{ {
// Set the xterm title // Set the xterm title
initCheck();
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
@ -343,6 +369,8 @@ void FTermXTerminal::setXTermTitle()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermXTerminal::setXTermSize() void FTermXTerminal::setXTermSize()
{ {
initCheck();
if ( term_detection->isXTerminal() ) if ( term_detection->isXTerminal() )
{ {
FTerm::putstringf ( CSI "8;%lu;%lut" FTerm::putstringf ( CSI "8;%lu;%lut"
@ -357,6 +385,8 @@ void FTermXTerminal::setXTermFont()
{ {
// Change the XTerm font (needs the allowFontOps resource) // Change the XTerm font (needs the allowFontOps resource)
initCheck();
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
|| term_detection->isUrxvtTerminal() || term_detection->isUrxvtTerminal()
@ -373,6 +403,8 @@ void FTermXTerminal::setXTermForeground()
{ {
// Set the XTerm text foreground color // Set the XTerm text foreground color
initCheck();
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
|| term_detection->isMinttyTerm() || term_detection->isMinttyTerm()
@ -391,6 +423,8 @@ void FTermXTerminal::setXTermBackground()
{ {
// Set the XTerm text background color // Set the XTerm text background color
initCheck();
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
|| term_detection->isMinttyTerm() || term_detection->isMinttyTerm()
@ -409,6 +443,8 @@ void FTermXTerminal::setXTermCursorColor()
{ {
// Set the text cursor color // Set the text cursor color
initCheck();
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
|| term_detection->isMinttyTerm() || term_detection->isMinttyTerm()
@ -427,6 +463,8 @@ void FTermXTerminal::setXTermMouseForeground()
{ {
// Set the mouse foreground color // Set the mouse foreground color
initCheck();
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
|| term_detection->isUrxvtTerminal() || term_detection->isUrxvtTerminal()
@ -444,6 +482,8 @@ void FTermXTerminal::setXTermMouseBackground()
{ {
// Set the mouse background color // Set the mouse background color
initCheck();
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
|| FTermcap::osc_support ) || FTermcap::osc_support )
@ -460,6 +500,8 @@ void FTermXTerminal::setXTermHighlightBackground()
{ {
// Set the highlight background color // Set the highlight background color
initCheck();
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
|| term_detection->isUrxvtTerminal() || term_detection->isUrxvtTerminal()
@ -478,6 +520,8 @@ void FTermXTerminal::setXTerm8ColorDefaults()
// Redefinition of the XTerm default colors // Redefinition of the XTerm default colors
// for the final cut 8 color theme // for the final cut 8 color theme
initCheck();
if ( term_detection->isPuttyTerminal() ) if ( term_detection->isPuttyTerminal() )
return; return;
@ -498,6 +542,8 @@ void FTermXTerminal::setXTerm16ColorDefaults()
// Redefinition of the XTerm default colors // Redefinition of the XTerm default colors
// for the final cut 16 color theme // for the final cut 16 color theme
initCheck();
if ( term_detection->isPuttyTerminal() ) if ( term_detection->isPuttyTerminal() )
return; return;
@ -518,6 +564,8 @@ inline void FTermXTerminal::setXTermDefaultsMouseCursor()
setMouseBackground("rgb:ffff/ffff/ffff"); // white setMouseBackground("rgb:ffff/ffff/ffff"); // white
setMouseForeground ("rgb:0000/0000/0000"); // black setMouseForeground ("rgb:0000/0000/0000"); // black
initCheck();
if ( ! term_detection->isGnomeTerminal() ) if ( ! term_detection->isGnomeTerminal() )
setCursorColor("rgb:ffff/ffff/ffff"); // white setCursorColor("rgb:ffff/ffff/ffff"); // white
} }
@ -525,6 +573,8 @@ inline void FTermXTerminal::setXTermDefaultsMouseCursor()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FTermXTerminal::canSetXTermBackground() inline bool FTermXTerminal::canSetXTermBackground()
{ {
initCheck(false);
if ( xterm_default_colors if ( xterm_default_colors
&& ! (term_detection->isMinttyTerm() && ! (term_detection->isMinttyTerm()
|| term_detection->isMltermTerminal() || term_detection->isMltermTerminal()
@ -540,6 +590,8 @@ void FTermXTerminal::resetXTermColorMap()
{ {
// Reset the entire color table // Reset the entire color table
initCheck();
if ( term_detection->isMinttyTerm() ) if ( term_detection->isMinttyTerm() )
{ {
FTerm::putstring (ESC "c"); // Full Reset (RIS) FTerm::putstring (ESC "c"); // Full Reset (RIS)
@ -640,6 +692,8 @@ void FTermXTerminal::resetXTermHighlightBackground()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FTermXTerminal::canResetColor() bool FTermXTerminal::canResetColor()
{ {
initCheck(false);
if ( term_detection->isGnomeTerminal() if ( term_detection->isGnomeTerminal()
&& term_detection->getGnomeTerminalID() < 3502 ) && term_detection->getGnomeTerminalID() < 3502 )
return false; return false;
@ -659,6 +713,8 @@ bool FTermXTerminal::canResetColor()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermXTerminal::oscPrefix() void FTermXTerminal::oscPrefix()
{ {
initCheck();
if ( term_detection->isTmuxTerm() ) if ( term_detection->isTmuxTerm() )
{ {
// tmux device control string // tmux device control string
@ -674,6 +730,8 @@ void FTermXTerminal::oscPrefix()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTermXTerminal::oscPostfix() void FTermXTerminal::oscPostfix()
{ {
initCheck();
if ( term_detection->isScreenTerm() if ( term_detection->isScreenTerm()
|| term_detection->isTmuxTerm() ) || term_detection->isTmuxTerm() )
{ {
@ -685,6 +743,8 @@ void FTermXTerminal::oscPostfix()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString FTermXTerminal::captureXTermFont() const FString FTermXTerminal::captureXTermFont()
{ {
initCheck(FString{});
if ( term_detection->isXTerminal() if ( term_detection->isXTerminal()
|| term_detection->isScreenTerm() || term_detection->isScreenTerm()
|| FTermcap::osc_support ) || FTermcap::osc_support )
@ -727,6 +787,8 @@ const FString FTermXTerminal::captureXTermFont()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
const FString FTermXTerminal::captureXTermTitle() const FString FTermXTerminal::captureXTermTitle()
{ {
initCheck(FString{});
if ( term_detection->isKdeTerminal() ) if ( term_detection->isKdeTerminal() )
return FString{}; return FString{};

View File

@ -42,7 +42,7 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FTextView::FTextView(FWidget* parent) FTextView::FTextView(FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
} }
@ -104,6 +104,15 @@ void FTextView::setGeometry ( const FPoint& pos, const FSize& size
changeOnResize(); changeOnResize();
} }
//----------------------------------------------------------------------
void FTextView::resetColors()
{
const auto& wc = getColorTheme();
setForegroundColor (wc->dialog_fg);
setBackgroundColor (wc->dialog_bg);
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::setText (const FString& str) void FTextView::setText (const FString& str)
{ {
@ -178,6 +187,18 @@ void FTextView::scrollTo (int x, int y)
updateTerminal(); updateTerminal();
} }
//----------------------------------------------------------------------
void FTextView::scrollToBegin()
{
scrollToY (0);
}
//----------------------------------------------------------------------
void FTextView::scrollToEnd()
{
scrollToY (int(getRows() - getTextHeight()));
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTextView::hide() void FTextView::hide()
{ {
@ -202,7 +223,7 @@ void FTextView::insert (const FString& str, int pos)
if ( str.isEmpty() ) if ( str.isEmpty() )
s = "\n"; s = "\n";
else else
s = FString{str}.rtrim().expandTabs(getTabstop()); s = FString{str}.rtrim().expandTabs(FTerm::getTabstop());
auto text_split = s.split("\r\n"); auto text_split = s.split("\r\n");
@ -363,9 +384,9 @@ void FTextView::onMouseDown (FMouseEvent* ev)
std::make_shared<FMouseEvent>(fc::MouseDown_Event, p, tp, b); std::make_shared<FMouseEvent>(fc::MouseDown_Event, p, tp, b);
FApplication::sendEvent (parent, _ev.get()); FApplication::sendEvent (parent, _ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
} }
} }
} }
@ -392,9 +413,9 @@ void FTextView::onMouseUp (FMouseEvent* ev)
std::make_shared<FMouseEvent>(fc::MouseUp_Event, p, tp, b); std::make_shared<FMouseEvent>(fc::MouseUp_Event, p, tp, b);
FApplication::sendEvent (parent, _ev.get()); FApplication::sendEvent (parent, _ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
} }
} }
} }
@ -425,9 +446,9 @@ void FTextView::onMouseMove (FMouseEvent* ev)
std::make_shared<FMouseEvent>(fc::MouseMove_Event, p, tp, b); std::make_shared<FMouseEvent>(fc::MouseMove_Event, p, tp, b);
FApplication::sendEvent (parent, _ev.get()); FApplication::sendEvent (parent, _ev.get());
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FMouseEvent");
} }
} }
} }
@ -557,10 +578,8 @@ void FTextView::init()
{ {
initScrollbar (vbar, fc::vertical, this, &FTextView::cb_vbarChange); initScrollbar (vbar, fc::vertical, this, &FTextView::cb_vbarChange);
initScrollbar (hbar, fc::horizontal, this, &FTextView::cb_hbarChange); initScrollbar (hbar, fc::horizontal, this, &FTextView::cb_hbarChange);
const auto& wc = getFWidgetColors(); resetColors();
setForegroundColor (wc.dialog_fg); nf_offset = FTerm::isNewFont() ? 1 : 0;
setBackgroundColor (wc.dialog_bg);
nf_offset = isNewFont() ? 1 : 0;
setTopPadding(1); setTopPadding(1);
setLeftPadding(1); setLeftPadding(1);
setBottomPadding(1); setBottomPadding(1);
@ -577,8 +596,8 @@ inline void FTextView::mapKeyFunctions()
key_map[fc::Fkey_right] = [this] { scrollBy (1, 0); }; key_map[fc::Fkey_right] = [this] { scrollBy (1, 0); };
key_map[fc::Fkey_ppage] = [this] { scrollBy (0, -int(getTextHeight())); }; key_map[fc::Fkey_ppage] = [this] { scrollBy (0, -int(getTextHeight())); };
key_map[fc::Fkey_npage] = [this] { scrollBy (0, int(getTextHeight())); }; key_map[fc::Fkey_npage] = [this] { scrollBy (0, int(getTextHeight())); };
key_map[fc::Fkey_home] = [this] { scrollToY (0); }; key_map[fc::Fkey_home] = [this] { scrollToBegin(); };
key_map[fc::Fkey_end] = [this] { scrollToY (int(getRows() - getTextHeight())); }; key_map[fc::Fkey_end] = [this] { scrollToEnd(); };
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -611,13 +630,13 @@ void FTextView::drawBorder()
{ {
if ( ! useFDialogBorder() ) if ( ! useFDialogBorder() )
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
const FRect box{FPoint{1, 1}, getSize()}; const FRect box{FPoint{1, 1}, getSize()};
finalcut::drawListBorder (this, box); finalcut::drawListBorder (this, box);
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
} }
@ -649,7 +668,7 @@ void FTextView::drawText()
setColor(); setColor();
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
for (std::size_t y{0}; y < num; y++) // Line loop for (std::size_t y{0}; y < num; y++) // Line loop
@ -678,7 +697,7 @@ void FTextView::drawText()
print() << FString{trailing_whitespace, L' '}; print() << FString{trailing_whitespace, L' '};
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }
@ -707,7 +726,7 @@ inline bool FTextView::isPrintable (wchar_t ch)
{ {
// Check for printable characters // Check for printable characters
const bool utf8 = ( getEncoding() == fc::UTF8 ) ? true : false; const bool utf8 = ( FTerm::getEncoding() == fc::UTF8 ) ? true : false;
if ( (utf8 && std::iswprint(std::wint_t(ch))) if ( (utf8 && std::iswprint(std::wint_t(ch)))
|| (!utf8 && std::isprint(ch)) ) || (!utf8 && std::isprint(ch)) )
@ -728,7 +747,7 @@ void FTextView::changeOnResize()
const std::size_t width = getWidth(); const std::size_t width = getWidth();
const std::size_t height = getHeight(); const std::size_t height = getHeight();
if ( isNewFont() ) if ( FTerm::isNewFont() )
{ {
vbar->setGeometry (FPoint{int(width), 1}, FSize{2, height - 1}); vbar->setGeometry (FPoint{int(width), 1}, FSize{2, height - 1});
hbar->setGeometry (FPoint{1, int(height)}, FSize{width - 2, 1}); hbar->setGeometry (FPoint{1, int(height)}, FSize{width - 2, 1});

View File

@ -40,7 +40,7 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FToggleButton::FToggleButton (FWidget* parent) FToggleButton::FToggleButton (FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
@ -55,7 +55,7 @@ FToggleButton::FToggleButton (FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FToggleButton::FToggleButton (const FString& txt, FWidget* parent) FToggleButton::FToggleButton (const FString& txt, FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
FToggleButton::setText(txt); // call own method FToggleButton::setText(txt); // call own method
init(); init();
@ -111,6 +111,33 @@ void FToggleButton::setGeometry ( const FPoint& pos, const FSize& s
FWidget::setGeometry (pos, size, adjust); FWidget::setGeometry (pos, size, adjust);
} }
//----------------------------------------------------------------------
void FToggleButton::resetColors()
{
const auto& wc = getColorTheme();
if ( isEnabled() ) // active
{
if ( hasFocus() )
{
setForegroundColor (wc->toggle_button_active_focus_fg);
setBackgroundColor (wc->toggle_button_active_focus_bg);
}
else
{
setForegroundColor (wc->toggle_button_active_fg);
setBackgroundColor (wc->toggle_button_active_bg);
}
}
else // inactive
{
setForegroundColor (wc->label_inactive_fg);
setBackgroundColor (wc->label_inactive_bg);
}
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FToggleButton::setNoUnderline (bool enable) bool FToggleButton::setNoUnderline (bool enable)
{ {
@ -121,7 +148,7 @@ bool FToggleButton::setNoUnderline (bool enable)
bool FToggleButton::setEnable (bool enable) bool FToggleButton::setEnable (bool enable)
{ {
FWidget::setEnable(enable); FWidget::setEnable(enable);
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( enable ) if ( enable )
{ {
@ -129,20 +156,20 @@ bool FToggleButton::setEnable (bool enable)
if ( hasFocus() ) if ( hasFocus() )
{ {
setForegroundColor (wc.toggle_button_active_focus_fg); setForegroundColor (wc->toggle_button_active_focus_fg);
setBackgroundColor (wc.toggle_button_active_focus_bg); setBackgroundColor (wc->toggle_button_active_focus_bg);
} }
else else
{ {
setForegroundColor (wc.toggle_button_active_fg); setForegroundColor (wc->toggle_button_active_fg);
setBackgroundColor (wc.toggle_button_active_bg); setBackgroundColor (wc->toggle_button_active_bg);
} }
} }
else else
{ {
delAccelerator(); delAccelerator();
setForegroundColor (wc.toggle_button_inactive_fg); setForegroundColor (wc->toggle_button_inactive_fg);
setBackgroundColor (wc.toggle_button_inactive_bg); setBackgroundColor (wc->toggle_button_inactive_bg);
} }
return enable; return enable;
@ -155,20 +182,20 @@ bool FToggleButton::setFocus (bool enable)
if ( isEnabled() ) if ( isEnabled() )
{ {
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( enable ) if ( enable )
{ {
if ( isRadioButton() ) if ( isRadioButton() )
focus_inside_group = false; focus_inside_group = false;
setForegroundColor (wc.toggle_button_active_focus_fg); setForegroundColor (wc->toggle_button_active_focus_fg);
setBackgroundColor (wc.toggle_button_active_focus_bg); setBackgroundColor (wc->toggle_button_active_focus_bg);
} }
else else
{ {
setForegroundColor (wc.toggle_button_active_fg); setForegroundColor (wc->toggle_button_active_fg);
setBackgroundColor (wc.toggle_button_active_bg); setBackgroundColor (wc->toggle_button_active_bg);
} }
} }
@ -497,46 +524,27 @@ void FToggleButton::setGroup (FButtonGroup* btngroup)
void FToggleButton::init() void FToggleButton::init()
{ {
setGeometry (FPoint{1, 1}, FSize{4, 1}, false); // initialize geometry values setGeometry (FPoint{1, 1}, FSize{4, 1}, false); // initialize geometry values
const auto& wc = getFWidgetColors(); resetColors();
if ( isEnabled() )
{
if ( hasFocus() )
{
setForegroundColor (wc.toggle_button_active_focus_fg);
setBackgroundColor (wc.toggle_button_active_focus_bg);
}
else
{
setForegroundColor (wc.toggle_button_active_fg);
setBackgroundColor (wc.toggle_button_active_bg);
}
}
else // inactive
{
setForegroundColor (wc.label_inactive_fg);
setBackgroundColor (wc.label_inactive_bg);
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FToggleButton::drawText (const FString& label_text, std::size_t hotkeypos) void FToggleButton::drawText (const FString& label_text, std::size_t hotkeypos)
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(true); setReverse(true);
const auto& wc = getFWidgetColors(); const auto& wc = getColorTheme();
if ( isEnabled() ) if ( isEnabled() )
setColor (wc.label_fg, wc.label_bg); setColor (wc->label_fg, wc->label_bg);
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 < label_text.getLength(); z++) for (std::size_t z{0}; z < label_text.getLength(); z++)
{ {
if ( (z == hotkeypos) && flags.active ) if ( (z == hotkeypos) && flags.active )
{ {
setColor (wc.label_hotkey_fg, wc.label_hotkey_bg); setColor (wc->label_hotkey_fg, wc->label_hotkey_bg);
if ( ! flags.no_underline ) if ( ! flags.no_underline )
setUnderline(); setUnderline();
@ -546,13 +554,13 @@ void FToggleButton::drawText (const FString& label_text, std::size_t hotkeypos)
if ( ! flags.no_underline ) if ( ! flags.no_underline )
unsetUnderline(); unsetUnderline();
setColor (wc.label_fg, wc.label_bg); setColor (wc->label_fg, wc->label_bg);
} }
else else
print (label_text[z]); print (label_text[z]);
} }
if ( isMonochron() ) if ( FTerm::isMonochron() )
setReverse(false); setReverse(false);
} }

View File

@ -34,15 +34,15 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FToolTip::FToolTip (FWidget* parent) FToolTip::FToolTip (FWidget* parent)
: FWindow(parent) : FWindow{parent}
{ {
init(); init();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FToolTip::FToolTip (const FString& txt, FWidget* parent) FToolTip::FToolTip (const FString& txt, FWidget* parent)
: FWindow(parent) : FWindow{parent}
, text(txt) , text{txt}
{ {
init(); init();
} }
@ -73,6 +73,15 @@ void FToolTip::setText (const FString& txt)
calculateDimensions(); calculateDimensions();
} }
//----------------------------------------------------------------------
void FToolTip::resetColors()
{
const auto& wc = getColorTheme();
setForegroundColor (wc->tooltip_fg);
setBackgroundColor (wc->tooltip_bg);
FWidget::resetColors();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FToolTip::setBorder (bool enable) bool FToolTip::setBorder (bool enable)
{ {
@ -107,9 +116,7 @@ void FToolTip::init()
// initialize geometry values // initialize geometry values
setGeometry (FPoint{1, 1}, FSize{3, 3}, false); setGeometry (FPoint{1, 1}, FSize{3, 3}, false);
setMinimumSize (FSize{3, 3}); setMinimumSize (FSize{3, 3});
const auto& wc = getFWidgetColors(); resetColors();
setForegroundColor (wc.tooltip_fg);
setBackgroundColor (wc.tooltip_bg);
calculateDimensions(); calculateDimensions();
} }

View File

@ -29,6 +29,7 @@
#include "final/fcharmap.h" #include "final/fcharmap.h"
#include "final/fcolorpair.h" #include "final/fcolorpair.h"
#include "final/fkeyboard.h" #include "final/fkeyboard.h"
#include "final/flog.h"
#include "final/foptiattr.h" #include "final/foptiattr.h"
#include "final/foptimove.h" #include "final/foptimove.h"
#include "final/fstyle.h" #include "final/fstyle.h"
@ -122,8 +123,8 @@ void FVTerm::setTermXY (int x, int y)
if ( term_pos->getX() == x && term_pos->getY() == y ) if ( term_pos->getX() == x && term_pos->getY() == y )
return; return;
const int term_width = int(getColumnNumber()); const int term_width = int(FTerm::getColumnNumber());
const int term_height = int(getLineNumber()); const int term_height = int(FTerm::getLineNumber());
if ( x >= term_width && term_width > 0 ) if ( x >= term_width && term_width > 0 )
{ {
@ -412,7 +413,7 @@ int FVTerm::print (const std::vector<FChar>& term_string)
int FVTerm::print (FTermArea* area, const std::vector<FChar>& term_string) int FVTerm::print (FTermArea* area, const std::vector<FChar>& term_string)
{ {
int len{0}; int len{0};
const uInt tabstop = uInt(getTabstop()); const uInt tabstop = uInt(FTerm::getTabstop());
if ( ! area ) if ( ! area )
return -1; return -1;
@ -446,7 +447,7 @@ int FVTerm::print (FTermArea* area, const std::vector<FChar>& term_string)
break; break;
case '\a': case '\a':
beep(); FTerm::beep();
break; break;
default: default:
@ -690,9 +691,9 @@ void FVTerm::createArea ( const FRect& box
{ {
area = new FTermArea; area = new FTermArea;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTermArea");
return; return;
} }
@ -1383,9 +1384,9 @@ inline bool FVTerm::reallocateTextArea ( FTermArea* area
area->changes = new FLineChanges[height]; area->changes = new FLineChanges[height];
area->data = new FChar[size]; area->data = new FChar[size];
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FLineChanges[height] or FChar[size]");
return false; return false;
} }
@ -1404,9 +1405,9 @@ inline bool FVTerm::reallocateTextArea (FTermArea* area, std::size_t size)
{ {
area->data = new FChar[size]; area->data = new FChar[size];
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FChar[size]");
return false; return false;
} }
@ -1909,9 +1910,9 @@ void FVTerm::init (bool disable_alt_screen)
term_pos = new FPoint(-1, -1); term_pos = new FPoint(-1, -1);
output_buffer = new std::queue<int>; output_buffer = new std::queue<int>;
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FTerm, FPoint, or std::queue<int>");
std::abort(); std::abort();
} }
@ -1928,7 +1929,7 @@ void FVTerm::init (bool disable_alt_screen)
std::memcpy (&next_attribute, &term_attribute, sizeof(next_attribute)); std::memcpy (&next_attribute, &term_attribute, sizeof(next_attribute));
// Create virtual terminal // Create virtual terminal
FRect term_geometry {0, 0, getColumnNumber(), getLineNumber()}; FRect term_geometry {0, 0, FTerm::getColumnNumber(), FTerm::getLineNumber()};
createVTerm (term_geometry.getSize()); createVTerm (term_geometry.getSize());
// Create virtual desktop area // Create virtual desktop area
@ -2120,7 +2121,7 @@ bool FVTerm::clearTerm (int fillchar)
{ {
term_pos->setPoint(-1, -1); term_pos->setPoint(-1, -1);
for (int i{0}; i < int(getLineNumber()); i++) for (int i{0}; i < int(FTerm::getLineNumber()); i++)
{ {
setTermXY (0, i); setTermXY (0, i);
appendOutputBuffer (cb); appendOutputBuffer (cb);
@ -2753,7 +2754,7 @@ void FVTerm::printPaddingCharacter (FTermArea* area, const FChar& term_char)
// Copy character to padding character // Copy character to padding character
std::memcpy (&pc, &term_char, sizeof(pc)); std::memcpy (&pc, &term_char, sizeof(pc));
if ( getEncoding() == fc::UTF8 ) if ( FTerm::getEncoding() == fc::UTF8 )
{ {
pc.ch = 0; pc.ch = 0;
pc.attr.bit.fullwidth_padding = true; pc.attr.bit.fullwidth_padding = true;
@ -2862,7 +2863,7 @@ bool FVTerm::isInsideTerminal (const FPoint& pos)
{ {
// Check whether the coordinates are within the virtual terminal // Check whether the coordinates are within the virtual terminal
const FRect term_geometry {0, 0, getColumnNumber(), getLineNumber()}; const FRect term_geometry {0, 0, FTerm::getColumnNumber(), FTerm::getLineNumber()};
if ( term_geometry.contains(pos) ) if ( term_geometry.contains(pos) )
return true; return true;
@ -2910,7 +2911,7 @@ inline void FVTerm::markAsPrinted (uInt from, uInt to, uInt line)
inline void FVTerm::newFontChanges (FChar*& next_char) inline void FVTerm::newFontChanges (FChar*& next_char)
{ {
// NewFont special cases // NewFont special cases
if ( ! isNewFont() ) if ( ! FTerm::isNewFont() )
return; return;
if ( next_char->ch == fc::LowerHalfBlock ) if ( next_char->ch == fc::LowerHalfBlock )
@ -2928,7 +2929,7 @@ inline void FVTerm::charsetChanges (FChar*& next_char)
const wchar_t& ch = next_char->ch; const wchar_t& ch = next_char->ch;
next_char->encoded_char = ch; next_char->encoded_char = ch;
if ( getEncoding() == fc::UTF8 ) if ( FTerm::getEncoding() == fc::UTF8 )
return; return;
const wchar_t ch_enc = FTerm::charEncode(ch); const wchar_t ch_enc = FTerm::charEncode(ch);
@ -2944,18 +2945,18 @@ inline void FVTerm::charsetChanges (FChar*& next_char)
next_char->encoded_char = ch_enc; next_char->encoded_char = ch_enc;
if ( getEncoding() == fc::VT100 ) if ( FTerm::getEncoding() == fc::VT100 )
next_char->attr.bit.alt_charset = true; next_char->attr.bit.alt_charset = true;
else if ( getEncoding() == fc::PC ) else if ( FTerm::getEncoding() == fc::PC )
{ {
next_char->attr.bit.pc_charset = true; next_char->attr.bit.pc_charset = true;
if ( isPuttyTerminal() ) if ( FTerm::isPuttyTerminal() )
return; return;
if ( isXTerminal() && ch_enc < 0x20 ) // Character 0x00..0x1f if ( FTerm::isXTerminal() && ch_enc < 0x20 ) // Character 0x00..0x1f
{ {
if ( hasUTF8() ) if ( FTerm::hasUTF8() )
next_char->encoded_char = int(FTerm::charEncode(ch, fc::ASCII)); next_char->encoded_char = int(FTerm::charEncode(ch, fc::ASCII));
else else
{ {
@ -3027,8 +3028,8 @@ int FVTerm::appendLowerRight (FChar*& screen_char)
const auto& ip = TCAP(fc::t_insert_padding); const auto& ip = TCAP(fc::t_insert_padding);
const auto& ic = TCAP(fc::t_insert_character); const auto& ic = TCAP(fc::t_insert_character);
const int x = int(getColumnNumber()) - 2; const int x = int(FTerm::getColumnNumber()) - 2;
const int y = int(getLineNumber()) - 1; const int y = int(FTerm::getLineNumber()) - 1;
setTermXY (x, y); setTermXY (x, y);
appendChar (screen_char); appendChar (screen_char);
term_pos->x_ref()++; term_pos->x_ref()++;

View File

@ -24,7 +24,9 @@
#include "final/fapplication.h" #include "final/fapplication.h"
#include "final/fevent.h" #include "final/fevent.h"
#include "final/flog.h"
#include "final/fmenubar.h" #include "final/fmenubar.h"
#include "final/fstartoptions.h"
#include "final/fstatusbar.h" #include "final/fstatusbar.h"
#include "final/fstring.h" #include "final/fstring.h"
#include "final/ftermdata.h" #include "final/ftermdata.h"
@ -47,7 +49,6 @@ FWidget::FWidgetList* FWidget::window_list{nullptr};
FWidget::FWidgetList* FWidget::dialog_list{nullptr}; FWidget::FWidgetList* FWidget::dialog_list{nullptr};
FWidget::FWidgetList* FWidget::always_on_top_list{nullptr}; FWidget::FWidgetList* FWidget::always_on_top_list{nullptr};
FWidget::FWidgetList* FWidget::close_widget{nullptr}; FWidget::FWidgetList* FWidget::close_widget{nullptr};
FWidgetColors FWidget::wcolors{};
bool FWidget::init_desktop{false}; bool FWidget::init_desktop{false};
bool FWidget::hideable{false}; bool FWidget::hideable{false};
uInt FWidget::modal_dialog_counter{}; uInt FWidget::modal_dialog_counter{};
@ -59,8 +60,8 @@ uInt FWidget::modal_dialog_counter{};
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FWidget::FWidget (FWidget* parent, bool disable_alt_screen) FWidget::FWidget (FWidget* parent, bool disable_alt_screen)
: FVTerm( ! (bool(parent) || root_widget), disable_alt_screen) : FVTerm{ ! (bool(parent) || root_widget), disable_alt_screen}
, FObject(parent) , FObject{parent}
{ {
// init bit field with 0 // init bit field with 0
memset (&flags, 0, sizeof(flags)); memset (&flags, 0, sizeof(flags));
@ -304,6 +305,42 @@ bool FWidget::setFocus (bool enable)
return (flags.focus = enable); return (flags.focus = enable);
} }
//----------------------------------------------------------------------
void FWidget::resetColors()
{
if ( ! hasChildren() )
return;
for (auto&& child : getChildren())
{
if ( child->isWidget() )
{
auto widget = static_cast<FWidget*>(child);
widget->resetColors();
}
}
}
//----------------------------------------------------------------------
void FWidget::useParentWidgetColor()
{
const auto& parent_widget = getParentWidget();
if ( parent_widget )
{
setForegroundColor (parent_widget->getForegroundColor());
setBackgroundColor (parent_widget->getBackgroundColor());
}
else // Fallback
{
const auto& wc = getColorTheme();
setForegroundColor (wc->dialog_fg);
setBackgroundColor (wc->dialog_bg);
}
setColor();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::setColor() void FWidget::setColor()
{ {
@ -537,7 +574,7 @@ void FWidget::setTermSize (const FSize& size)
{ {
// Set xterm size to width x height // Set xterm size to width x height
if ( isXTerminal() ) if ( FTerm::isXTerminal() )
{ {
root_widget->wsize.setRect(FPoint{1, 1}, size); root_widget->wsize.setRect(FPoint{1, 1}, size);
root_widget->adjust_wsize = root_widget->wsize; root_widget->adjust_wsize = root_widget->wsize;
@ -938,7 +975,8 @@ void FWidget::redraw()
{ {
startTerminalUpdate(); startTerminalUpdate();
// clean desktop // clean desktop
setColor (wcolors.term_fg, wcolors.term_bg); auto color_theme = getColorTheme();
setColor (color_theme->term_fg, color_theme->term_bg);
clearArea (getVirtualDesktop()); clearArea (getVirtualDesktop());
} }
else if ( ! isShown() ) else if ( ! isShown() )
@ -1000,7 +1038,7 @@ void FWidget::show()
if ( ! init_desktop ) if ( ! init_desktop )
{ {
// Sets the initial screen settings // Sets the initial screen settings
initScreenSettings(); FTerm::initScreenSettings();
// Initializing vdesktop // Initializing vdesktop
const auto& r = getRootWidget(); const auto& r = getRootWidget();
setColor(r->getForegroundColor(), r->getBackgroundColor()); setColor(r->getForegroundColor(), r->getBackgroundColor());
@ -1369,8 +1407,9 @@ void FWidget::hideArea (const FSize& size)
} }
else else
{ {
fg = wcolors.dialog_fg; auto color_theme = getColorTheme();
bg = wcolors.dialog_bg; fg = color_theme->dialog_fg;
bg = color_theme->dialog_bg;
} }
setColor (fg, bg); setColor (fg, bg);
@ -1514,7 +1553,7 @@ bool FWidget::focusPrevChild()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWidget::event (FEvent* ev) bool FWidget::event (FEvent* ev)
{ {
switch ( uInt(ev->type()) ) switch ( uInt(ev->getType()) )
{ {
case fc::KeyPress_Event: case fc::KeyPress_Event:
KeyPressEvent (static_cast<FKeyEvent*>(ev)); KeyPressEvent (static_cast<FKeyEvent*>(ev));
@ -1590,12 +1629,8 @@ bool FWidget::event (FEvent* ev)
onClose (static_cast<FCloseEvent*>(ev)); onClose (static_cast<FCloseEvent*>(ev));
break; break;
case fc::Timer_Event:
onTimer (static_cast<FTimerEvent*>(ev));
break;
default: default:
return false; return FObject::event(ev);
} }
return true; return true;
@ -1689,13 +1724,13 @@ void FWidget::initRootWidget()
always_on_top_list = new FWidgetList(); always_on_top_list = new FWidgetList();
close_widget = new FWidgetList(); close_widget = new FWidgetList();
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FWidgetList");
return; return;
} }
hideable = isCursorHideable(); hideable = FTerm::isCursorHideable();
flags.visible_cursor = ! hideable; flags.visible_cursor = ! hideable;
// Determine width and height of the terminal // Determine width and height of the terminal
@ -1711,11 +1746,12 @@ void FWidget::initRootWidget()
double_flatline_mask.left.resize (getHeight(), false); double_flatline_mask.left.resize (getHeight(), false);
// Initialize default widget colors // Initialize default widget colors
setColorTheme(); initColorTheme();
// Default foreground and background color of the desktop/terminal // Default foreground and background color of the desktop/terminal
foreground_color = wcolors.term_fg; auto color_theme = getColorTheme();
background_color = wcolors.term_bg; foreground_color = color_theme->term_fg;
background_color = color_theme->term_bg;
init_desktop = false; init_desktop = false;
} }
@ -1745,6 +1781,8 @@ void FWidget::finish()
delete window_list; delete window_list;
window_list = nullptr; window_list = nullptr;
} }
destroyColorTheme();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -1987,14 +2025,31 @@ void FWidget::drawChildren()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::setColorTheme() void FWidget::initColorTheme()
{ {
// Sets the default color theme // Sets the default color theme
if ( getMaxColor() < 16 ) // for 8 color mode if ( FStartOptions::getFStartOptions().dark_theme )
wcolors.set8ColorTheme(); {
if ( FTerm::getMaxColor() < 16 ) // for 8 color mode
setColorTheme<default8ColorDarkTheme>();
else else
wcolors.set16ColorTheme(); setColorTheme<default16ColorDarkTheme>();
}
else
{
if ( FTerm::getMaxColor() < 16 ) // for 8 color mode
setColorTheme<default8ColorTheme>();
else
setColorTheme<default16ColorTheme>();
}
}
//----------------------------------------------------------------------
void FWidget::destroyColorTheme()
{
const FWidgetColorsPtr* theme = &(getColorTheme());
delete theme;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -138,11 +138,11 @@ void setHotkeyViaString (FWidget* w, const FString& text)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void drawShadow (FWidget* w) void drawShadow (FWidget* w)
{ {
if ( w->isMonochron() && ! w->flags.trans_shadow ) if ( FTerm::isMonochron() && ! w->flags.trans_shadow )
return; return;
if ( (w->getEncoding() == fc::VT100 && ! w->flags.trans_shadow) if ( (FTerm::getEncoding() == fc::VT100 && ! w->flags.trans_shadow)
|| (w->getEncoding() == fc::ASCII && ! w->flags.trans_shadow) ) || (FTerm::getEncoding() == fc::ASCII && ! w->flags.trans_shadow) )
{ {
clearShadow(w); clearShadow(w);
return; return;
@ -161,12 +161,12 @@ void drawTransparentShadow (FWidget* w)
const std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
const std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
const auto& wcolors = FWidget::wcolors; const auto& wc = FWidget::getColorTheme();
w->print() << FStyle {fc::Transparent} w->print() << FStyle {fc::Transparent}
<< FPoint {int(width) + 1, 1} << FPoint {int(width) + 1, 1}
<< " " << " "
<< FStyle {fc::Reset} << FStyle {fc::Reset}
<< FColorPair {wcolors.shadow_bg, wcolors.shadow_fg} << FColorPair {wc->shadow_bg, wc->shadow_fg}
<< FStyle {fc::ColorOverlay}; << FStyle {fc::ColorOverlay};
for (std::size_t y{1}; y < height; y++) for (std::size_t y{1}; y < height; y++)
@ -178,12 +178,12 @@ void drawTransparentShadow (FWidget* w)
<< FPoint {1, int(height) + 1} << FPoint {1, int(height) + 1}
<< " " << " "
<< FStyle {fc::Reset} << FStyle {fc::Reset}
<< FColorPair {wcolors.shadow_bg, wcolors.shadow_fg} << FColorPair {wc->shadow_bg, wc->shadow_fg}
<< FStyle {fc::ColorOverlay} << FStyle {fc::ColorOverlay}
<< FString {width, L' '} << FString {width, L' '}
<< FStyle {fc::Reset}; << FStyle {fc::Reset};
if ( w->isMonochron() ) if ( FTerm::isMonochron() )
w->setReverse(false); w->setReverse(false);
} }
@ -192,21 +192,21 @@ void drawBlockShadow (FWidget* w)
{ {
// non-transparent shadow // non-transparent shadow
if ( ! w->hasShadowCharacter() ) if ( ! FTerm::hasShadowCharacter() )
return; return;
const std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
const std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
const auto& wcolors = FWidget::wcolors; const auto& wc = FWidget::getColorTheme();
w->print() << FPoint {int(width) + 1, 1}; w->print() << FPoint {int(width) + 1, 1};
if ( w->isWindowWidget() ) if ( w->isWindowWidget() )
{ {
w->print() << FColorPair {wcolors.shadow_fg, wcolors.shadow_bg} w->print() << FColorPair {wc->shadow_fg, wc->shadow_bg}
<< FStyle {fc::InheritBackground}; // current background color will be ignored << FStyle {fc::InheritBackground}; // current background color will be ignored
} }
else if ( auto p = w->getParentWidget() ) else if ( auto p = w->getParentWidget() )
w->print() << FColorPair {wcolors.shadow_fg, p->getBackgroundColor()}; w->print() << FColorPair {wc->shadow_fg, p->getBackgroundColor()};
w->print (fc::LowerHalfBlock); // ▄ w->print (fc::LowerHalfBlock); // ▄
@ -233,20 +233,20 @@ void drawBlockShadow (FWidget* w)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void clearShadow (FWidget* w) void clearShadow (FWidget* w)
{ {
if ( w->isMonochron() ) if ( FTerm::isMonochron() )
return; return;
const std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
const std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
const auto& wcolors = FWidget::wcolors; const auto& wc = FWidget::getColorTheme();
if ( w->isWindowWidget() ) if ( w->isWindowWidget() )
{ {
w->print() << FColorPair {wcolors.shadow_fg, wcolors.shadow_bg} w->print() << FColorPair {wc->shadow_fg, wc->shadow_bg}
<< FStyle {fc::InheritBackground}; // current background color will be ignored << FStyle {fc::InheritBackground}; // current background color will be ignored
} }
else if ( auto p = w->getParentWidget() ) else if ( auto p = w->getParentWidget() )
w->print() << FColorPair {wcolors.shadow_fg, p->getBackgroundColor()}; w->print() << FColorPair {wc->shadow_fg, p->getBackgroundColor()};
if ( int(width) <= w->woffset.getX2() ) if ( int(width) <= w->woffset.getX2() )
{ {
@ -270,17 +270,17 @@ void clearShadow (FWidget* w)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void drawFlatBorder (FWidget* w) void drawFlatBorder (FWidget* w)
{ {
if ( ! w->isNewFont() ) if ( ! FTerm::isNewFont() )
return; return;
const std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
const std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
const auto& wcolors = FWidget::wcolors; const auto& wc = FWidget::getColorTheme();
if ( auto p = w->getParentWidget() ) if ( auto p = w->getParentWidget() )
w->setColor (wcolors.dialog_fg, p->getBackgroundColor()); w->setColor (wc->dialog_fg, p->getBackgroundColor());
else else
w->setColor (wcolors.dialog_fg, wcolors.dialog_bg); w->setColor (wc->dialog_fg, wc->dialog_bg);
for (std::size_t y{0}; y < height; y++) for (std::size_t y{0}; y < height; y++)
{ {
@ -331,17 +331,17 @@ void drawFlatBorder (FWidget* w)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void clearFlatBorder (FWidget* w) void clearFlatBorder (FWidget* w)
{ {
if ( ! w->isNewFont() ) if ( ! FTerm::isNewFont() )
return; return;
const std::size_t width = w->getWidth(); const std::size_t width = w->getWidth();
const std::size_t height = w->getHeight(); const std::size_t height = w->getHeight();
const auto& wcolors = FWidget::wcolors; const auto& wc = FWidget::getColorTheme();
if ( auto p = w->getParentWidget() ) if ( auto p = w->getParentWidget() )
w->setColor (wcolors.dialog_fg, p->getBackgroundColor()); w->setColor (wc->dialog_fg, p->getBackgroundColor());
else else
w->setColor (wcolors.dialog_fg, wcolors.dialog_bg); w->setColor (wc->dialog_fg, wc->dialog_bg);
for (std::size_t y{0}; y < height; y++) for (std::size_t y{0}; y < height; y++)
{ {
@ -413,7 +413,7 @@ void drawBorder (FWidget* w, const FRect& r)
FRect rect = r; FRect rect = r;
checkBorder (w, rect); checkBorder (w, rect);
if ( w->isNewFont() ) if ( FTerm::isNewFont() )
drawNewFontBox (w, rect); drawNewFontBox (w, rect);
else else
drawBox (w, rect); drawBox (w, rect);
@ -425,7 +425,7 @@ void drawListBorder (FWidget* w, const FRect& r)
FRect rect = r; FRect rect = r;
checkBorder (w, rect); checkBorder (w, rect);
if ( w->isNewFont() ) if ( FTerm::isNewFont() )
drawNewFontListBox (w, rect); drawNewFontListBox (w, rect);
else else
drawBox (w, rect); drawBox (w, rect);

View File

@ -3,7 +3,7 @@
* * * *
* This file is part of the Final Cut widget toolkit * * This file is part of the Final Cut widget toolkit *
* * * *
* Copyright 2018-2019 Markus Gans * * Copyright 2018-2020 Markus Gans *
* * * *
* The Final Cut is free software; you can redistribute it and/or * * The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License * * modify it under the terms of the GNU Lesser General Public License *
@ -31,9 +31,34 @@ namespace finalcut
// class FWidgetColors // class FWidgetColors
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// public methods of FWidgetColors // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidgetColors::set8ColorTheme() FWidgetColors::FWidgetColors()
{ }
//----------------------------------------------------------------------
FWidgetColors::~FWidgetColors()
{ }
//----------------------------------------------------------------------
// class default8ColorTheme
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default8ColorTheme::default8ColorTheme()
{
default8ColorTheme::setColorTheme();
}
//----------------------------------------------------------------------
default8ColorTheme::~default8ColorTheme()
{ }
// public methods of default8ColorTheme
//----------------------------------------------------------------------
void default8ColorTheme::setColorTheme()
{ {
term_fg = fc::Black; term_fg = fc::Black;
term_bg = fc::Blue; term_bg = fc::Blue;
@ -123,8 +148,25 @@ void FWidgetColors::set8ColorTheme()
progressbar_bg = fc::LightGray; progressbar_bg = fc::LightGray;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidgetColors::set16ColorTheme() // class default16ColorTheme
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default16ColorTheme::default16ColorTheme()
{
default16ColorTheme::setColorTheme();
}
//----------------------------------------------------------------------
default16ColorTheme::~default16ColorTheme()
{ }
// public methods of default16ColorTheme
//----------------------------------------------------------------------
void default16ColorTheme::setColorTheme()
{ {
term_fg = fc::Black; term_fg = fc::Black;
term_bg = fc::LightBlue; term_bg = fc::LightBlue;
@ -217,4 +259,219 @@ void FWidgetColors::set16ColorTheme()
term_bg = fc::SkyBlue2; term_bg = fc::SkyBlue2;
} }
//----------------------------------------------------------------------
// class default8ColorDarkTheme
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default8ColorDarkTheme::default8ColorDarkTheme()
{
default8ColorDarkTheme::setColorTheme();
}
//----------------------------------------------------------------------
default8ColorDarkTheme::~default8ColorDarkTheme()
{ }
// public methods of default8ColorDarkTheme
//----------------------------------------------------------------------
void default8ColorDarkTheme::setColorTheme()
{
term_fg = fc::LightGray;
term_bg = fc::Cyan;
list_fg = fc::Black;
list_bg = fc::LightGray;
selected_list_fg = fc::Cyan;
selected_list_bg = fc::LightGray;
dialog_fg = fc::Black;
dialog_resize_fg = fc::Blue;
dialog_emphasis_fg = fc::Blue;
dialog_bg = fc::LightGray;
error_box_fg = fc::LightGray;
error_box_emphasis_fg = fc::Black;
error_box_bg = fc::Red;
tooltip_fg = fc::LightGray;
tooltip_bg = fc::Black;
shadow_fg = fc::Black;
shadow_bg = fc::LightGray; // only for transparent shadow
current_element_focus_fg = fc::LightGray;
current_element_focus_bg = fc::Cyan;
current_element_fg = fc::Black;
current_element_bg = fc::Cyan;
current_inc_search_element_fg = fc::Red;
selected_current_element_focus_fg = fc::Cyan;
selected_current_element_focus_bg = fc::Cyan;
selected_current_element_fg = fc::Blue;
selected_current_element_bg = fc::Cyan;
label_fg = fc::Black;
label_bg = fc::LightGray;
label_inactive_fg = fc::Cyan;
label_inactive_bg = fc::LightGray;
label_hotkey_fg = fc::Red;
label_hotkey_bg = fc::LightGray;
label_emphasis_fg = fc::Blue;
label_ellipsis_fg = fc::Cyan;
inputfield_active_focus_fg = fc::LightGray;
inputfield_active_focus_bg = fc::Cyan;
inputfield_active_fg = fc::LightGray;
inputfield_active_bg = fc::Cyan;
inputfield_inactive_fg = fc::Cyan;
inputfield_inactive_bg = fc::LightGray;
toggle_button_active_focus_fg = fc::LightGray;
toggle_button_active_focus_bg = fc::Cyan;
toggle_button_active_fg = fc::Black;
toggle_button_active_bg = fc::LightGray;
toggle_button_inactive_fg = fc::Cyan;
toggle_button_inactive_bg = fc::LightGray;
button_active_focus_fg = fc::LightGray;
button_active_focus_bg = fc::Cyan;
button_active_fg = fc::LightGray;
button_active_bg = fc::Black;
button_inactive_fg = fc::Black;
button_inactive_bg = fc::Cyan;
button_hotkey_fg = fc::LightGray;
titlebar_active_fg = fc::LightGray;
titlebar_active_bg = fc::Black;
titlebar_inactive_fg = fc::Black;
titlebar_inactive_bg = fc::LightGray;
titlebar_button_fg = fc::Black;
titlebar_button_bg = fc::LightGray;
titlebar_button_focus_fg = fc::LightGray;
titlebar_button_focus_bg = fc::Black;
menu_active_focus_fg = fc::LightGray;
menu_active_focus_bg = fc::Blue;
menu_active_fg = fc::LightGray;
menu_active_bg = fc::Black;
menu_inactive_fg = fc::LightGray;
menu_inactive_bg = fc::Black;
menu_hotkey_fg = fc::Red;
menu_hotkey_bg = fc::Black;
statusbar_fg = fc::LightGray;
statusbar_bg = fc::Black;
statusbar_hotkey_fg = fc::Red;
statusbar_hotkey_bg = fc::Black;
statusbar_separator_fg = fc::LightGray;
statusbar_active_fg = fc::LightGray;
statusbar_active_bg = fc::Blue;
statusbar_active_hotkey_fg = fc::Red;
statusbar_active_hotkey_bg = fc::Blue;
scrollbar_fg = fc::Cyan;
scrollbar_bg = fc::LightGray;
scrollbar_button_fg = fc::Black;
scrollbar_button_bg = fc::LightGray;
scrollbar_button_inactive_fg = fc::Cyan;
scrollbar_button_inactive_bg = fc::LightGray;
progressbar_fg = fc::Cyan;
progressbar_bg = fc::LightGray;
}
//----------------------------------------------------------------------
// class default16ColorDarkTheme
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
default16ColorDarkTheme::default16ColorDarkTheme()
{
default16ColorDarkTheme::setColorTheme();
}
//----------------------------------------------------------------------
default16ColorDarkTheme::~default16ColorDarkTheme()
{ }
// public methods of default16ColorDarkTheme
//----------------------------------------------------------------------
void default16ColorDarkTheme::setColorTheme()
{
term_fg = fc::White;
term_bg = fc::Cyan;
list_fg = fc::Black;
list_bg = fc::LightGray;
selected_list_fg = fc::Red;
selected_list_bg = fc::LightGray;
dialog_fg = fc::Black;
dialog_resize_fg = fc::LightBlue;
dialog_emphasis_fg = fc::Blue;
dialog_bg = fc::LightGray;
error_box_fg = fc::White;
error_box_emphasis_fg = fc::Yellow;
error_box_bg = fc::Red;
tooltip_fg = fc::White;
tooltip_bg = fc::Black;
shadow_fg = fc::Black;
shadow_bg = fc::LightGray; // only for transparent shadow
current_element_focus_fg = fc::White;
current_element_focus_bg = fc::Cyan;
current_element_fg = fc::LightBlue;
current_element_bg = fc::Cyan;
current_inc_search_element_fg = fc::LightRed;
selected_current_element_focus_fg = fc::LightRed;
selected_current_element_focus_bg = fc::Cyan;
selected_current_element_fg = fc::Red;
selected_current_element_bg = fc::Cyan;
label_fg = fc::Black;
label_bg = fc::LightGray;
label_inactive_fg = fc::DarkGray;
label_inactive_bg = fc::LightGray;
label_hotkey_fg = fc::Red;
label_hotkey_bg = fc::LightGray;
label_emphasis_fg = fc::Blue;
label_ellipsis_fg = fc::DarkGray;
inputfield_active_focus_fg = fc::White;
inputfield_active_focus_bg = fc::Cyan;
inputfield_active_fg = fc::White;
inputfield_active_bg = fc::DarkGray;
inputfield_inactive_fg = fc::DarkGray;
inputfield_inactive_bg = fc::LightGray;
toggle_button_active_focus_fg = fc::White;
toggle_button_active_focus_bg = fc::Cyan;
toggle_button_active_fg = fc::Black;
toggle_button_active_bg = fc::LightGray;
toggle_button_inactive_fg = fc::DarkGray;
toggle_button_inactive_bg = fc::LightGray;
button_active_focus_fg = fc::LightGray;
button_active_focus_bg = fc::Cyan;
button_active_fg = fc::LightGray;
button_active_bg = fc::DarkGray;
button_inactive_fg = fc::DarkGray;
button_inactive_bg = fc::LightBlue;
button_hotkey_fg = fc::White;
titlebar_active_fg = fc::White;
titlebar_active_bg = fc::DarkGray;
titlebar_inactive_fg = fc::DarkGray;
titlebar_inactive_bg = fc::LightBlue;
titlebar_button_fg = fc::DarkGray;
titlebar_button_bg = fc::LightBlue;
titlebar_button_focus_fg = fc::LightGray;
titlebar_button_focus_bg = fc::Black;
menu_active_focus_fg = fc::White;
menu_active_focus_bg = fc::Blue;
menu_active_fg = fc::White;
menu_active_bg = fc::DarkGray;
menu_inactive_fg = fc::LightGray;
menu_inactive_bg = fc::DarkGray;
menu_hotkey_fg = fc::LightRed;
menu_hotkey_bg = fc::DarkGray;
statusbar_fg = fc::White;
statusbar_bg = fc::DarkGray;
statusbar_hotkey_fg = fc::LightRed;
statusbar_hotkey_bg = fc::DarkGray;
statusbar_separator_fg = fc::LightGray;
statusbar_active_fg = fc::White;
statusbar_active_bg = fc::Blue;
statusbar_active_hotkey_fg = fc::LightRed;
statusbar_active_hotkey_bg = fc::Blue;
scrollbar_fg = fc::DarkGray;
scrollbar_bg = fc::LightBlue;
scrollbar_button_fg = fc::Black;
scrollbar_button_bg = fc::LightBlue;
scrollbar_button_inactive_fg = fc::DarkGray;
scrollbar_button_inactive_bg = fc::LightGray;
progressbar_fg = fc::DarkGray;
progressbar_bg = fc::LightBlue;
}
} // namespace finalcut } // namespace finalcut

View File

@ -44,7 +44,7 @@ FWindow* FWindow::previous_window{nullptr};
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FWindow::FWindow(FWidget* parent) FWindow::FWindow(FWidget* parent)
: FWidget(parent) : FWidget{parent}
{ {
setWindowWidget(); setWindowWidget();
FRect geometry {getTermGeometry()}; FRect geometry {getTermGeometry()};
@ -184,7 +184,7 @@ bool FWindow::setTransparentShadow (bool enable)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWindow::setShadow (bool enable) bool FWindow::setShadow (bool enable)
{ {
if ( isMonochron() ) if ( FTerm::isMonochron() )
return false; return false;
if ( enable ) if ( enable )
@ -239,7 +239,7 @@ bool FWindow::isWindowHidden() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWindow::drawBorder() void FWindow::drawBorder()
{ {
if ( isNewFont() ) // Draw a newfont outer frame if ( FTerm::isNewFont() ) // Draw a newfont outer frame
{ {
const FRect r{FPoint{1, 1}, getSize()}; const FRect r{FPoint{1, 1}, getSize()};
print() << r.getUpperLeftPos() print() << r.getUpperLeftPos()
@ -786,7 +786,7 @@ void FWindow::adjustSize()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWindow::event (FEvent* ev) bool FWindow::event (FEvent* ev)
{ {
switch ( uInt(ev->type()) ) switch ( uInt(ev->getType()) )
{ {
case fc::WindowActive_Event: case fc::WindowActive_Event:
onWindowActive (ev); onWindowActive (ev);
@ -882,7 +882,8 @@ void closeDropDown (FWidget* widget, const FPoint& mouse_position)
if ( ! openmenu ) if ( ! openmenu )
return; return;
if ( openmenu->isInstanceOf("FMenu") ) if ( openmenu->isInstanceOf("FMenu")
|| openmenu->isInstanceOf("FDialogListMenu") )
{ {
bool contains_menu_structure; bool contains_menu_structure;
auto menu = static_cast<FMenu*>(openmenu); auto menu = static_cast<FMenu*>(openmenu);

View File

@ -20,6 +20,14 @@
* <http://www.gnu.org/licenses/>. * * <http://www.gnu.org/licenses/>. *
***********************************************************************/ ***********************************************************************/
/* Standalone class
*
*
*
* emptyFString
*
*/
#ifndef EMPTYFSTRING_H #ifndef EMPTYFSTRING_H
#define EMPTYFSTRING_H #define EMPTYFSTRING_H
@ -27,6 +35,8 @@
#error "Only <final/final.h> can be included directly." #error "Only <final/final.h> can be included directly."
#endif #endif
#include "final/fapplication.h"
#include "final/flog.h"
#include "final/fstring.h" #include "final/fstring.h"
namespace finalcut namespace finalcut
@ -51,6 +61,7 @@ public:
// Disable copy assignment operator (=) // Disable copy assignment operator (=)
emptyFString& operator = (const emptyFString&) = delete; emptyFString& operator = (const emptyFString&) = delete;
static const FString getClassName();
static bool isNull(); static bool isNull();
static const FString& get(); static const FString& get();
static void clear(); static void clear();
@ -61,6 +72,10 @@ private:
}; };
// emptyFString inline functions // emptyFString inline functions
//----------------------------------------------------------------------
inline const FString emptyFString::getClassName()
{ return "emptyFString"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool emptyFString::isNull() inline bool emptyFString::isNull()
{ {
@ -76,9 +91,9 @@ inline const FString& emptyFString::get()
{ {
empty_string = new FString(""); empty_string = new FString("");
} }
catch (const std::bad_alloc& ex) catch (const std::bad_alloc&)
{ {
std::cerr << bad_alloc_str << ex.what() << std::endl; badAllocOutput ("FString");
} }
} }

View File

@ -68,11 +68,12 @@ namespace finalcut
{ {
// class forward declaration // class forward declaration
class FEvent;
class FAccelEvent; class FAccelEvent;
class FCloseEvent; class FCloseEvent;
class FEvent;
class FFocusEvent; class FFocusEvent;
class FKeyEvent; class FKeyEvent;
class FLog;
class FMouseEvent; class FMouseEvent;
class FStartOptions; class FStartOptions;
class FTimerEvent; class FTimerEvent;
@ -89,6 +90,9 @@ class FObject;
class FApplication : public FWidget class FApplication : public FWidget
{ {
public: public:
// Typedef
typedef std::shared_ptr<FLog> FLogPtr;
// Constructor // Constructor
FApplication (const int&, char*[], bool = false); FApplication (const int&, char*[], bool = false);
@ -106,6 +110,10 @@ class FApplication : public FWidget
int getArgc() const; int getArgc() const;
char** getArgv() const; char** getArgv() const;
static FApplication* getApplicationObject(); static FApplication* getApplicationObject();
static FLogPtr& getLog();
// Mutator
static void setLog (const FLogPtr&);
// Inquiry // Inquiry
static bool isQuit(); static bool isQuit();
@ -121,7 +129,10 @@ class FApplication : public FWidget
void sendQueuedEvents(); void sendQueuedEvents();
bool eventInQueue(); bool eventInQueue();
bool removeQueuedEvent (const FObject*); bool removeQueuedEvent (const FObject*);
virtual void processExternalUserEvent();
static FWidget* processParameters (const int&, char*[]); static FWidget* processParameters (const int&, char*[]);
static void setDefaultTheme();
static void setDarkTheme();
static void showParameterUsage () static void showParameterUsage ()
#if defined(__clang__) || defined(__GNUC__) #if defined(__clang__) || defined(__GNUC__)
__attribute__((noreturn)) __attribute__((noreturn))
@ -134,13 +145,14 @@ class FApplication : public FWidget
private: private:
// Typedefs // Typedefs
typedef std::pair<FObject*, std::shared_ptr<FEvent> > eventPair; typedef std::pair<FObject*, FEvent*> EventPair;
typedef std::deque<eventPair> FEventQueue; typedef std::deque<EventPair> FEventQueue;
// Methods // Methods
void init (uInt64, uInt64); void init (uInt64, uInt64);
static void cmd_options (const int&, char*[]); static void cmd_options (const int&, char*[]);
static FStartOptions& getStartOptions(); static FStartOptions& getStartOptions();
void destroyLog();
void findKeyboardWidget(); void findKeyboardWidget();
bool isKeyPressed() const; bool isKeyPressed() const;
void keyPressed(); void keyPressed();
@ -177,6 +189,7 @@ class FApplication : public FWidget
void processMouseEvent(); void processMouseEvent();
void processResizeEvent(); void processResizeEvent();
void processCloseWidget(); void processCloseWidget();
void processLogger();
bool processNextEvent(); bool processNextEvent();
void performTimerAction (FObject*, FEvent*) override; void performTimerAction (FObject*, FEvent*) override;
static bool isEventProcessable (const FObject*, const FEvent*); static bool isEventProcessable (const FObject*, const FEvent*);

View File

@ -88,6 +88,7 @@ class FButton : public FWidget
void setFocusBackgroundColor (FColor); void setFocusBackgroundColor (FColor);
void setInactiveForegroundColor (FColor); void setInactiveForegroundColor (FColor);
void setInactiveBackgroundColor (FColor); void setInactiveBackgroundColor (FColor);
void resetColors() override;
bool setNoUnderline(bool); bool setNoUnderline(bool);
bool setNoUnderline(); bool setNoUnderline();
bool unsetNoUnderline(); bool unsetNoUnderline();
@ -157,13 +158,13 @@ class FButton : public FWidget
bool click_animation{true}; bool click_animation{true};
int click_time{150}; int click_time{150};
int space_char{int(' ')}; int space_char{int(' ')};
FColor button_fg{getFWidgetColors().button_active_fg}; FColor button_fg{getColorTheme()->button_active_fg};
FColor button_bg{getFWidgetColors().button_active_bg}; FColor button_bg{getColorTheme()->button_active_bg};
FColor button_hotkey_fg{getFWidgetColors().button_hotkey_fg}; FColor button_hotkey_fg{getColorTheme()->button_hotkey_fg};
FColor button_focus_fg{getFWidgetColors().button_active_focus_fg}; FColor button_focus_fg{getColorTheme()->button_active_focus_fg};
FColor button_focus_bg{getFWidgetColors().button_active_focus_bg}; FColor button_focus_bg{getColorTheme()->button_active_focus_bg};
FColor button_inactive_fg{getFWidgetColors().button_inactive_fg}; FColor button_inactive_fg{getColorTheme()->button_inactive_fg};
FColor button_inactive_bg{getFWidgetColors().button_inactive_bg}; FColor button_inactive_bg{getColorTheme()->button_inactive_bg};
std::size_t hotkeypos{NOT_SET}; std::size_t hotkeypos{NOT_SET};
std::size_t indent{0}; std::size_t indent{0};
std::size_t center_offset{0}; std::size_t center_offset{0};

View File

@ -46,27 +46,32 @@ namespace finalcut
// class FColorPalette // class FColorPalette
//---------------------------------------------------------------------- //----------------------------------------------------------------------
class FColorPalette final class FColorPalette
{ {
public: public:
// Typedef
typedef std::function<void(FColor, int, int, int)> FSetPalette;
// Constructor // Constructor
FColorPalette() = default; explicit FColorPalette (const FSetPalette&);
// Destructor // Destructor
~FColorPalette(); virtual ~FColorPalette();
// Accessor // Accessor
const FString getClassName() const; virtual const FString getClassName() const;
// Methods // Methods
template<typename funcT> virtual void setColorPalette() = 0;
static void set8ColorPalette (funcT); virtual void resetColorPalette() = 0;
template<typename funcT>
static void set16ColorPalette (funcT); protected:
template<typename funcT> void setPalette (FColor, int, int, int);
static void reset8ColorPalette (funcT); void setVGAdefaultPalette();
template<typename funcT>
static void reset16ColorPalette (funcT); private:
// Data members
FSetPalette set_palette;
}; };
// FColorPalette inline functions // FColorPalette inline functions
@ -74,85 +79,112 @@ class FColorPalette final
inline const FString FColorPalette::getClassName() const inline const FString FColorPalette::getClassName() const
{ return "FColorPalette"; } { return "FColorPalette"; }
// constructors and destructor
//----------------------------------------------------------------------
inline FColorPalette::~FColorPalette() // destructor
{ }
// public methods of FColorPalette /* Inheritance diagram
//---------------------------------------------------------------------- *
template<typename funcT> *
void FColorPalette::set8ColorPalette (funcT set_palette) *
{ * FColorPalette
set_palette (fc::Black, 0x00, 0x00, 0x00); *
set_palette (fc::Blue, 0x10, 0x3b, 0x9e); *
set_palette (fc::Green, 0x18, 0x78, 0x18); *
set_palette (fc::Cyan, 0xa0, 0xb2, 0xb2); *
set_palette (fc::Red, 0xb2, 0x18, 0x18); * default8ColorPalette
set_palette (fc::Magenta, 0xb2, 0x18, 0xb2); *
set_palette (fc::Brown, 0xe8, 0x87, 0x1f); */
set_palette (fc::LightGray, 0xe0, 0xe0, 0xe0);
// The same colors again...
set_palette (fc::DarkGray, 0x00, 0x00, 0x00);
set_palette (fc::LightBlue, 0x10, 0x3b, 0x9e);
set_palette (fc::LightGreen, 0x18, 0x78, 0x18);
set_palette (fc::Cyan, 0xa0, 0xb2, 0xb2);
set_palette (fc::LightRed, 0xb2, 0x18, 0x18);
set_palette (fc::LightMagenta, 0xb2, 0x18, 0xb2);
set_palette (fc::Yellow, 0xe8, 0x87, 0x1f);
set_palette (fc::White, 0xe0, 0xe0, 0xe0);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template<typename funcT> // class default8ColorPalette
void FColorPalette::set16ColorPalette (funcT set_palette) //----------------------------------------------------------------------
class default8ColorPalette final : public FColorPalette
{ {
set_palette (fc::Black, 0x00, 0x00, 0x00); public:
set_palette (fc::Blue, 0x10, 0x3b, 0x9e); // Constructor
set_palette (fc::Green, 0x18, 0x78, 0x18); explicit default8ColorPalette (const FSetPalette&);
set_palette (fc::Cyan, 0x55, 0x6a, 0xcf);
set_palette (fc::Red, 0xba, 0x1a, 0x1a); // Destructor
set_palette (fc::Magenta, 0xb2, 0x18, 0xb2); ~default8ColorPalette();
set_palette (fc::Brown, 0xe8, 0x87, 0x1f);
set_palette (fc::LightGray, 0xbc, 0xbc, 0xbc); // Accessor
set_palette (fc::DarkGray, 0x50, 0x50, 0x50); const FString getClassName() const override;
set_palette (fc::LightBlue, 0x80, 0xa4, 0xec);
set_palette (fc::LightGreen, 0x5e, 0xeb, 0x5c); // Methods
set_palette (fc::LightCyan, 0x62, 0xbf, 0xf8); void setColorPalette() override;
set_palette (fc::LightRed, 0xee, 0x44, 0x44); void resetColorPalette() override;
set_palette (fc::LightMagenta, 0xe9, 0xad, 0xff); };
set_palette (fc::Yellow, 0xfb, 0xe8, 0x67);
set_palette (fc::White, 0xff, 0xff, 0xff); // default8ColorPalette inline functions
} //----------------------------------------------------------------------
inline const FString default8ColorPalette::getClassName() const
{ return "default8ColorPalette"; }
/* Inheritance diagram
*
*
*
* FColorPalette
*
*
*
*
* default16ColorPalette
*
*/
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template<typename funcT> // class default16ColorPalette
void FColorPalette::reset8ColorPalette (funcT set_palette) //----------------------------------------------------------------------
class default16ColorPalette final : public FColorPalette
{ {
reset16ColorPalette(set_palette); public:
} // Constructor
explicit default16ColorPalette (const FSetPalette&);
// Destructor
~default16ColorPalette();
// Accessor
const FString getClassName() const override;
// Methods
void setColorPalette() override;
void resetColorPalette() override;
};
// default16ColorPalette inline functions
//----------------------------------------------------------------------
inline const FString default16ColorPalette::getClassName() const
{ return "default16ColorPalette"; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
template<typename funcT> // class default16DarkColorPalette
void FColorPalette::reset16ColorPalette (funcT set_palette) //----------------------------------------------------------------------
class default16DarkColorPalette final : public FColorPalette
{ {
set_palette (fc::Black, 0x00, 0x00, 0x00); public:
set_palette (fc::Blue, 0x00, 0x00, 0xaa); // Constructor
set_palette (fc::Green, 0x00, 0xaa, 0x00); explicit default16DarkColorPalette (const FSetPalette&);
set_palette (fc::Cyan, 0x00, 0x55, 0xaa);
set_palette (fc::Red, 0xaa, 0x00, 0x00); // Destructor
set_palette (fc::Magenta, 0xaa, 0x00, 0xaa); ~default16DarkColorPalette();
set_palette (fc::Brown, 0xaa, 0xaa, 0x00);
set_palette (fc::LightGray, 0xaa, 0xaa, 0xaa); // Accessor
set_palette (fc::DarkGray, 0x55, 0x55, 0x55); const FString getClassName() const override;
set_palette (fc::LightBlue, 0x55, 0x55, 0xff);
set_palette (fc::LightGreen, 0x55, 0xff, 0x55); // Methods
set_palette (fc::LightCyan, 0x55, 0xff, 0xff); void setColorPalette() override;
set_palette (fc::LightRed, 0xff, 0x55, 0x55); void resetColorPalette() override;
set_palette (fc::LightMagenta, 0xff, 0x55, 0xff); };
set_palette (fc::Yellow, 0xff, 0xff, 0x55);
set_palette (fc::White, 0xff, 0xff, 0xff); // default16ColorPalette inline functions
} //----------------------------------------------------------------------
inline const FString default16DarkColorPalette::getClassName() const
{ return "default16DarkColorPalette"; }
} // namespace finalcut } // namespace finalcut

View File

@ -108,6 +108,7 @@ class FDialog : public FWindow
bool setBorder (bool); bool setBorder (bool);
bool setBorder(); bool setBorder();
bool unsetBorder(); bool unsetBorder();
void resetColors() override;
virtual void setText (const FString&); virtual void setText (const FString&);
// Inquiries // Inquiries

View File

@ -99,10 +99,18 @@ class FEvent // event base class
public: public:
FEvent() = default; FEvent() = default;
explicit FEvent(fc::events); explicit FEvent(fc::events);
fc::events type() const; fc::events getType() const;
bool isQueued() const;
bool wasSent() const;
private: private:
// Data members
fc::events t{fc::None_Event}; fc::events t{fc::None_Event};
bool queued{false};
bool send{false};
// Friend class
friend class FApplication;
}; };

View File

@ -49,6 +49,8 @@
#include <final/flineedit.h> #include <final/flineedit.h>
#include <final/flistbox.h> #include <final/flistbox.h>
#include <final/flistview.h> #include <final/flistview.h>
#include <final/flog.h>
#include <final/flogger.h>
#include <final/fmenubar.h> #include <final/fmenubar.h>
#include <final/fmenu.h> #include <final/fmenu.h>
#include <final/fmenuitem.h> #include <final/fmenuitem.h>

View File

@ -145,8 +145,8 @@ class FLabel : public FWidget
std::size_t align_offset{0}; std::size_t align_offset{0};
std::size_t hotkeypos{NOT_SET}; std::size_t hotkeypos{NOT_SET};
std::size_t column_width{0}; std::size_t column_width{0};
FColor emphasis_color{getFWidgetColors().label_emphasis_fg}; FColor emphasis_color{getColorTheme()->label_emphasis_fg};
FColor ellipsis_color{getFWidgetColors().label_ellipsis_fg}; FColor ellipsis_color{getColorTheme()->label_ellipsis_fg};
bool multiline{false}; bool multiline{false};
bool emphasis{false}; bool emphasis{false};
bool reverse_mode{false}; bool reverse_mode{false};

View File

@ -120,6 +120,7 @@ class FLineEdit : public FWidget
void setInputType (const inputType); void setInputType (const inputType);
void setLabelOrientation (const label_o); void setLabelOrientation (const label_o);
void setLabelAssociatedWidget (FWidget*); void setLabelAssociatedWidget (FWidget*);
void resetColors() override;
void setSize (const FSize&, bool = true) override; void setSize (const FSize&, bool = true) override;
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;

View File

@ -350,7 +350,7 @@ inline FListBox::FListBox ( Iterator first
, Iterator last , Iterator last
, InsertConverter convert , InsertConverter convert
, FWidget* parent ) , FWidget* parent )
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
@ -366,7 +366,7 @@ template <typename Container, typename LazyConverter>
inline FListBox::FListBox ( Container container inline FListBox::FListBox ( Container container
, LazyConverter convert , LazyConverter convert
, FWidget* parent ) , FWidget* parent )
: FWidget(parent) : FWidget{parent}
{ {
init(); init();
insert (container, convert); insert (container, convert);

151
src/include/final/flog.h Normal file
View File

@ -0,0 +1,151 @@
/***********************************************************************
* flog.h - Interface of the FINAL CUT logger *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 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/>. *
***********************************************************************/
/* Inheritance diagram
*
*
*
* std::stringbuf
*
*
*
*
* FLog
*
*/
#ifndef FLOG_H
#define FLOG_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include <functional>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#include <final/fstring.h>
namespace finalcut
{
//----------------------------------------------------------------------
// class FLog
//----------------------------------------------------------------------
class FLog : public std::stringbuf
{
public:
// Using-declaration
using FLogPrint = std::function<void(const std::string&)>;
using IOManip = std::ostream& (*)(std::ostream&);
// Enumerations
enum LogLevel
{
Info, Warn, Error, Debug
};
enum LineEnding
{
LF, CR, CRLF
};
// Constructor
FLog();
// Destructor
~FLog() override;
template <typename T>
FLog& operator << (const T& s);
FLog& operator << (IOManip);
FLog& operator << (LogLevel);
virtual const FString getClassName() const;
virtual void info (const std::string&) = 0;
virtual void warn (const std::string&) = 0;
virtual void error (const std::string&) = 0;
virtual void debug (const std::string&) = 0;
virtual void setOutputStream (const std::ostream&) = 0;
virtual void setLineEnding (LineEnding) = 0;
virtual void enableTimestamp() = 0;
virtual void disableTimestamp() = 0;
protected:
int sync() override;
const LogLevel& getLevel();
LogLevel& setLevel();
const LineEnding& getEnding();
LineEnding& setEnding();
private:
// Data member
LogLevel level{Info};
LineEnding end_of_line{CRLF};
FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)};
std::ostream stream{this};
};
// FLog inline functions
//----------------------------------------------------------------------
template <typename T>
inline FLog& FLog::operator << (const T& s)
{
stream << s;
return *this;
}
//----------------------------------------------------------------------
inline FLog& FLog::operator << (IOManip pf)
{
pf(stream);
return *this;
}
//----------------------------------------------------------------------
inline const FString FLog::getClassName() const
{ return "FLog"; }
//----------------------------------------------------------------------
inline const FLog::LogLevel& FLog::getLevel()
{ return level; }
//----------------------------------------------------------------------
inline FLog::LogLevel& FLog::setLevel()
{ return level; }
//----------------------------------------------------------------------
inline const FLog::LineEnding& FLog::getEnding()
{ return end_of_line; }
//----------------------------------------------------------------------
inline FLog::LineEnding& FLog::setEnding()
{ return end_of_line; }
} // namespace finalcut
#endif // FLOG_H

148
src/include/final/flogger.h Normal file
View File

@ -0,0 +1,148 @@
/***********************************************************************
* flogger.h - The FINAL CUT text logger *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2020 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/>. *
***********************************************************************/
/* Inheritance diagram
*
*
*
* std::stringbuf
*
*
*
*
* FLog
*
*
*
*
* FLogger
*
*/
#ifndef FLOGGER_H
#define FLOGGER_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <chrono>
#include <iomanip>
#include "final/flog.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FLogger
//----------------------------------------------------------------------
class FLogger : public FLog
{
public:
// Constructor
FLogger();
// Destructor
~FLogger() override;
// Methods
const FString getClassName() const override;
void info (const std::string&) override;
void warn (const std::string&) override;
void error (const std::string&) override;
void debug (const std::string&) override;
void setOutputStream (const std::ostream&) override;
void setLineEnding (LineEnding) override;
void enableTimestamp() override;
void disableTimestamp() override;
private:
// Methods
void newlineReplace (std::string&, const std::string&);
const std::string getTimeString();
const std::string getEOL();
void printLogLine (const std::string&);
// Data member
bool timestamp{false};
std::ostream output{std::cerr.rdbuf()};
};
// FLogger inline functions
//----------------------------------------------------------------------
inline const FString FLogger::getClassName() const
{ return "FLogger"; }
//----------------------------------------------------------------------
inline void FLogger::info (const std::string& msg)
{
setLevel() = Info;
printLogLine (msg);
}
//----------------------------------------------------------------------
inline void FLogger::warn (const std::string& msg)
{
setLevel() = Warn;
printLogLine (msg);
}
//----------------------------------------------------------------------
inline void FLogger::error (const std::string& msg)
{
setLevel() = Error;
printLogLine (msg);
}
//----------------------------------------------------------------------
inline void FLogger::debug (const std::string& msg)
{
setLevel() = Debug;
printLogLine (msg);
}
//----------------------------------------------------------------------
inline void FLogger::setOutputStream (const std::ostream& os)
{ output.rdbuf(os.rdbuf()); }
//----------------------------------------------------------------------
inline void FLogger::setLineEnding (LineEnding eol)
{ setEnding() = eol; }
//----------------------------------------------------------------------
inline void FLogger::enableTimestamp()
{ timestamp = true; }
//----------------------------------------------------------------------
inline void FLogger::disableTimestamp()
{ timestamp = false; }
} // namespace finalcut
#endif // FLOGGER_H

View File

@ -106,6 +106,7 @@ class FMenu : public FWindow, public FMenuList
void setStatusbarMessage (const FString&) override; void setStatusbarMessage (const FString&) override;
void setMenu (FMenu*); void setMenu (FMenu*);
void setText (const FString&); void setText (const FString&);
void resetColors() override;
// Inquiries // Inquiries
bool isSelected() const; bool isSelected() const;

View File

@ -86,6 +86,7 @@ class FMenuBar : public FWindow, public FMenuList
const FString getClassName() const override; const FString getClassName() const override;
// Methods // Methods
void resetColors() override;
void resetMenu(); void resetMenu();
void hide() override; void hide() override;
void adjustSize() override; void adjustSize() override;

View File

@ -153,7 +153,7 @@ class FMessageBox : public FDialog
FStringList text_components{}; FStringList text_components{};
FButton* button[3]{nullptr}; FButton* button[3]{nullptr};
std::size_t max_line_width{0}; std::size_t max_line_width{0};
FColor emphasis_color{getFWidgetColors().dialog_emphasis_fg}; FColor emphasis_color{getColorTheme()->dialog_emphasis_fg};
int button_digit[3]{0}; int button_digit[3]{0};
uInt num_buttons{0}; uInt num_buttons{0};
std::size_t text_num_lines{0}; std::size_t text_num_lines{0};
@ -169,8 +169,8 @@ inline const FString FMessageBox::getClassName() const
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline const FString FMessageBox::getTitlebarText() const inline const FString FMessageBox::getTitlebarText() const
{ {
const FString& tb_text = FDialog::getText(); // initialize text const FString& title = FDialog::getText(); // initialize text
return tb_text; return title;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -228,13 +228,13 @@ int FMessageBox::error ( FWidget* parent
, FString() << message , FString() << message
, button0, button1, button2 , button0, button1, button2
, parent ); , parent );
mbox.beep(); FTerm::beep();
mbox.setHeadline("Warning:"); mbox.setHeadline("Warning:");
mbox.setCenterText(); mbox.setCenterText();
const auto& wc = mbox.getFWidgetColors(); const auto& wc = getColorTheme();
mbox.setForegroundColor(wc.error_box_fg); mbox.setForegroundColor(wc->error_box_fg);
mbox.setBackgroundColor(wc.error_box_bg); mbox.setBackgroundColor(wc->error_box_bg);
mbox.emphasis_color = wc.error_box_emphasis_fg; mbox.emphasis_color = wc->error_box_emphasis_fg;
const int reply = mbox.exec(); const int reply = mbox.exec();
return reply; return reply;
} }

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