diff --git a/.codacy.yml b/.codacy.yml new file mode 100644 index 00000000..cb0b05bd --- /dev/null +++ b/.codacy.yml @@ -0,0 +1,15 @@ +--- +engines: + duplication: + enabled: true + exclude_paths: + - 'fonts/**' + - 'test/**' +exclude_paths: + - 'debian/**' + - 'doc/**' + - 'icon/**' + - 'logo/**' + - 'm4/**' + - 'scripts/**' + diff --git a/.gitignore b/.gitignore index 65cc6f2e..b8aa0e2a 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ examples/.deps/ examples/.libs/ examples/calculator examples/dialog +examples/event-log examples/string-operations examples/background-color examples/opti-move diff --git a/.travis.yml b/.travis.yml index f7b5d2a0..dfeb55a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,12 +75,12 @@ matrix: - 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 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 - ./configure --prefix=/usr CPPFLAGS="-DDEBUG" CXXFLAGS="-g -O0 -DDEBUG -DUNIT_TEST" --with-unit-test - make V=1 -j10 - make check - - cat test/*.log + - cat test/*.log || echo # # Coveralls + Codecov diff --git a/ChangeLog b/ChangeLog index 8d9b16e8..f0701d49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2020-05-30 Markus Gans + * 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 + * Adding a dark theme. Can be activated with the --dark-theme parameter. + +2020-05-28 Markus Gans + * FColorPalette now also uses polymorphism, so you can now + easily create your own color palette theme + +2020-05-26 Markus Gans + * 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 + * 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 + * Fixed the event queue in FApplication + +2020-05-16 Markus Gans + * More direct access to the static FTerm functions + +2020-05-13 Markus Gans + * 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 * Transfer of all termcap functions into the FTermcap class diff --git a/doc/first-steps.md b/doc/first-steps.md index f419157e..f184b0dd 100644 --- a/doc/first-steps.md +++ b/doc/first-steps.md @@ -13,10 +13,10 @@ Table of Contents - [Event handler reimplementation](#event-handler-reimplementation) - [Signals and Callbacks](#signals-and-callbacks) - [Default signals](#the-final-cut-widgets-emit-the-following-default-signals) -- [Callback function](#example-of-a-callback-function) -- [Callback lambda expression](#example-of-an-lambda-expression-callback) -- [Callback method](#example-of-a-callback-function) -- [Custom signals](#send-custom-signals) + - [Callback function](#example-of-a-callback-function) + - [Callback lambda expression](#example-of-an-lambda-expression-callback) + - [Callback method](#example-of-a-callback-function) + - [Custom signals](#send-custom-signals) - [Widget layout](#widget-layout) - [Coordinates](#coordinates) - [Lengths](#lengths) @@ -69,8 +69,8 @@ int main (int argc, char* argv[]) finalcut::FApplication app(argc, argv); finalcut::FDialog dialog(&app); dialog.setText ("A dialog"); - const finalcut::FPoint position(25, 5); - const finalcut::FSize size(30, 10); + const finalcut::FPoint position{25, 5}; + const finalcut::FSize size{30, 10}; dialog.setGeometry (position, size); finalcut::FWidget::setMainWidget(&dialog); dialog.show(); @@ -126,8 +126,8 @@ dialog.setText ("A dialog"); The title bar of the dialog box gets the text "A dialog". ```cpp -finalcut::FPoint position(25, 5); -finalcut::FSize size(30, 10); +finalcut::FPoint position{25, 5}; +finalcut::FSize size{30, 10}; dialog.setGeometry (position, size); ``` 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 FDialog* dialog = new FDialog(&app); 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 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"); // The object label is managed by dialog @@ -218,7 +218,7 @@ int main (int argc, char* argv[]) "adipiscing elit, sed do eiusmod tempor " "incididunt ut labore et dolore magna aliqua." , dialog ); - label->setGeometry (FPoint(2, 4), FSize(36, 1)); + label->setGeometry (FPoint{2, 4}, FSize{36, 1}); FWidget::setMainWidget(dialog); dialog->show(); return app.exec(); @@ -322,13 +322,13 @@ class dialogWidget : public FDialog { public: explicit dialogWidget (FWidget* parent = nullptr) - : FDialog(parent) + : FDialog{parent} { setText ("Dialog"); - setGeometry (FPoint(25, 5), FSize(23, 4)); - label.setGeometry (FPoint(1, 1), FSize(10, 1)); + setGeometry (FPoint{25, 5}, FSize{23, 4}); + label.setGeometry (FPoint{1, 1}, FSize{10, 1}); label.setAlignment (fc::alignRight); - value.setGeometry (FPoint(11, 1), FSize(10, 1)); + value.setGeometry (FPoint{11, 1}, FSize{10, 1}); id = addTimer(100); } @@ -500,14 +500,14 @@ int main (int argc, char* argv[]) FApplication app(argc, argv); FDialog dialog(&app); dialog.setText ("A dialog with callback function"); - dialog.setGeometry (FRect(25, 5, 45, 9)); + dialog.setGeometry (FRect{25, 5, 45, 9}); FLabel label (&dialog); 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); // Character follows '&' will be used as the accelerator key 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 button.addCallback @@ -553,9 +553,9 @@ int main (int argc, char* argv[]) FApplication app(argc, argv); FDialog dialog(&app); dialog.setText ("Lambda expression as callback"); - dialog.setGeometry (FRect(25, 5, 45, 9)); + dialog.setGeometry (FRect{25, 5, 45, 9}); 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 button.addCallback @@ -567,12 +567,12 @@ int main (int argc, char* argv[]) if ( button.getY() != 2 ) { - button.setPos (FPoint(15, 2)); + button.setPos (FPoint{15, 2}); button.setText("&top"); } else { - button.setPos (FPoint(15, 5)); + button.setPos (FPoint{15, 5}); button.setText("&bottom"); } @@ -616,11 +616,11 @@ class dialogWidget : public FDialog { public: explicit dialogWidget (FWidget* parent = nullptr) - : FDialog(parent) + : FDialog{parent} { setText ("Callback method"); - setGeometry (FPoint(25, 5), FSize(25, 7)); - button.setGeometry (FPoint(7, 3), FSize(10, 1)); + setGeometry (FPoint{25, 5}, FSize{25, 7}); + button.setGeometry (FPoint{7, 3}, FSize{10, 1}); // Connect the button signal "clicked" with the callback method button.addCallback @@ -678,16 +678,16 @@ class dialogWidget : public FDialog { public: 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"); - const FSize size(5, 1); - label.setGeometry (FPoint(8, 1), size); + const FSize size{5, 1}; + label.setGeometry (FPoint{8, 1}, size); label.setAlignment (fc::alignRight); label.setForegroundColor (fc::Black); - plus.setGeometry (FPoint(3, 3), size); - minus.setGeometry (FPoint(13, 3), size); + plus.setGeometry (FPoint{3, 3}, size); + minus.setGeometry (FPoint{13, 3}, size); plus.setNoUnderline(); minus.setNoUnderline(); @@ -987,15 +987,15 @@ class dialogWidget : public FDialog { public: explicit dialogWidget (FWidget* parent = nullptr) - : FDialog(parent) + : FDialog{parent} { setText ("Dialog"); setResizeable(); - button.setGeometry (FPoint(1, 1), FSize(12, 1), false); - input.setGeometry (FPoint(2, 3), FSize(12, 1), false); + button.setGeometry (FPoint{1, 1}, FSize{12, 1}, false); + input.setGeometry (FPoint{2, 3}, FSize{12, 1}, false); // Set dialog geometry and calling adjustSize() - setGeometry (FPoint(25, 5), FSize(40, 12)); - setMinimumSize (FSize(25, 9)); + setGeometry (FPoint{25, 5}), FSize{40, 12}); + setMinimumSize (FSize{25, 9}); } private: @@ -1011,14 +1011,14 @@ class dialogWidget : public FDialog auto y = int((getDesktopHeight() - getHeight()) / 2); checkMinValue(x); checkMinValue(y); - setPos (FPoint(x, y), false); + setPos (FPoint{x, y}, false); } void adjustWidgets() { const auto bx = int(getWidth() - button.getWidth() - 3); const auto by = int(getHeight() - 4); - button.setPos (FPoint(bx, by), false); + button.setPos (FPoint{bx, by}, false); input.setWidth (getWidth() - 4); const auto ly = int(getHeight() / 2) - 1; input.setY (ly, false); @@ -1046,10 +1046,10 @@ class dialogWidget : public FDialog // Calling super class method draw() FDialog::draw(); - print() << FPoint (3, 3) - << FColorPair (fc::Black, fc::White) + print() << FPoint{3, 3} + << FColorPair{fc::Black, fc::White} << "Text on " - << FColorPair (fc::Blue, fc::Yellow) + << FColorPair{fc::Blue, fc::Yellow} << "top"; } @@ -1129,12 +1129,12 @@ class dialogWidget : public FDialog { public: explicit dialogWidget (FWidget* parent = nullptr) - : FDialog(parent) + : FDialog{parent} { setText ("Dialog"); - setGeometry (FPoint(28, 2), FSize(24, 21)); - scrollview.setGeometry(FPoint(1, 1), FSize(22, 11)); - scrollview.setScrollSize(FSize(60, 27)); + setGeometry (FPoint{28, 2}, FSize{24, 21}); + scrollview.setGeometry(FPoint{1, 1}, FSize{22, 11}); + scrollview.setScrollSize(FSize{60, 27}); const auto& wc = getFWidgetColors(); setColor (wc.label_inactive_fg, wc.dialog_bg); scrollview.clearArea(); @@ -1144,25 +1144,25 @@ class dialogWidget : public FDialog static std::vector d { - {"NW", FPoint(3, 13), FPoint(1, 1), black}, - {"N", FPoint(10, 13), FPoint(21, 1), red}, - {"NE", FPoint(17, 13), FPoint(41, 1), black}, - {"W", FPoint(3, 15), FPoint(1, 10), black}, - {"*", FPoint(10, 15), FPoint(21, 10), black}, - {"E", FPoint(17, 15), FPoint(41, 10), black}, - {"SW", FPoint(3, 17), FPoint(1, 19), black}, - {"S", FPoint(10, 17), FPoint(21, 19), cyan}, - {"SE", FPoint(17, 17), FPoint(41, 19), black} + {"NW", FPoint{3, 13}, FPoint{1, 1}, black}, + {"N", FPoint{10, 13}, FPoint{21, 1}, red}, + {"NE", FPoint{17, 13}, FPoint{41, 1}, black}, + {"W", FPoint{3, 15}, FPoint{1, 10}, black}, + {"*", FPoint{10, 15}, FPoint{21, 10}, black}, + {"E", FPoint{17, 15}, FPoint{41, 10}, black}, + {"SW", FPoint{3, 17}, FPoint{1, 19}, black}, + {"S", FPoint{10, 17}, FPoint{21, 19}, cyan}, + {"SE", FPoint{17, 17}, FPoint{41, 19}, black} }; 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); 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); - btn->setGeometry(std::get<1>(b), FSize(4, 1)); + btn->setGeometry(std::get<1>(b), FSize{4, 1}); btn->unsetShadow(); btn->addCallback ( diff --git a/examples/7segment.cpp b/examples/7segment.cpp index 9ae83058..8cf9cdbb 100644 --- a/examples/7segment.cpp +++ b/examples/7segment.cpp @@ -74,7 +74,7 @@ class SegmentView final : public finalcut::FDialog //---------------------------------------------------------------------- SegmentView::SegmentView (finalcut::FWidget* parent) - : FDialog(parent) + : FDialog{parent} { // Dialog settings // Avoids calling a virtual function from the constructor diff --git a/examples/Makefile.am b/examples/Makefile.am index 8de96be7..9514ec2b 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -11,6 +11,7 @@ noinst_PROGRAMS = \ hello \ dialog \ input-dialog \ + event-log \ fullwidth-character \ 7segment \ choice \ @@ -39,6 +40,7 @@ noinst_PROGRAMS = \ hello_SOURCES = hello.cpp dialog_SOURCES = dialog.cpp input_dialog_SOURCES = input-dialog.cpp +event_log_SOURCES = event-log.cpp fullwidth_character_SOURCES = fullwidth-character.cpp 7segment_SOURCES = 7segment.cpp choice_SOURCES = choice.cpp diff --git a/examples/background-color.cpp b/examples/background-color.cpp index 8cf6f0bd..60938a7e 100644 --- a/examples/background-color.cpp +++ b/examples/background-color.cpp @@ -92,7 +92,7 @@ class Background final : public finalcut::FDialog //---------------------------------------------------------------------- Background::Background (finalcut::FWidget* parent) - : FDialog(parent) + : FDialog{parent} { // Dialog settings // Avoids calling a virtual function from the constructor @@ -211,7 +211,6 @@ void Background::cb_choice (const finalcut::FWidget*, const FDataPtr) updateTerminal(); } - //---------------------------------------------------------------------- // main part //---------------------------------------------------------------------- diff --git a/examples/calculator.cpp b/examples/calculator.cpp index ea9f0aa5..aff63430 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -62,7 +62,7 @@ class Button final : public finalcut::FButton //---------------------------------------------------------------------- Button::Button (finalcut::FWidget* parent) - : finalcut::FButton(parent) + : finalcut::FButton{parent} { } //---------------------------------------------------------------------- @@ -81,10 +81,10 @@ void Button::setChecked (bool enable) } else { - const auto& wc = getFWidgetColors(); - setBackgroundColor(wc.button_active_bg); - setFocusForegroundColor(wc.button_active_focus_fg); - setFocusBackgroundColor(wc.button_active_focus_bg); + const auto& wc = getColorTheme(); + setBackgroundColor(wc->button_active_bg); + setFocusForegroundColor(wc->button_active_focus_fg); + setFocusBackgroundColor(wc->button_active_focus_bg); } redraw(); @@ -245,7 +245,7 @@ class Calc final : public finalcut::FDialog //---------------------------------------------------------------------- Calc::Calc (FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { // Dialog settings // Avoids calling a virtual function from the constructor @@ -278,7 +278,7 @@ Calc::Calc (FWidget* parent) btn->setDoubleFlatLine(fc::top); btn->setDoubleFlatLine(fc::bottom); - if ( isNewFont() ) + if ( finalcut::FTerm::isNewFont() ) btn->unsetClickAnimation(); btn->addCallback @@ -421,18 +421,18 @@ void Calc::drawDispay() if ( error ) display = " Error "; - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) setReverse(false); - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); print() << FColorPair{fc::Black, fc::LightGray} << 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); - if ( isNewFont() ) + if ( finalcut::FTerm::isNewFont() ) { const wchar_t bottom_line {fc::NF_border_line_bottom}; const wchar_t top_bottom_line {fc::NF_border_line_up_and_down}; diff --git a/examples/checklist.cpp b/examples/checklist.cpp index 97b476b0..33ce1e60 100644 --- a/examples/checklist.cpp +++ b/examples/checklist.cpp @@ -73,13 +73,13 @@ class CheckList final : public finalcut::FDialog //---------------------------------------------------------------------- CheckList::CheckList (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { // Dialog settings // Avoids calling a virtual function from the constructor // (CERT, OOP50-CPP) 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} , FSize{28 + nf_offset, 13} ); setShadow(); diff --git a/examples/event-log.cpp b/examples/event-log.cpp new file mode 100644 index 00000000..6d0991a7 --- /dev/null +++ b/examples/event-log.cpp @@ -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 * +* . * +***********************************************************************/ + +#include +#include +#include +#include +#include + +#include + +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(); +} + diff --git a/examples/keyboard.cpp b/examples/keyboard.cpp index 33cd25a8..a92330fc 100644 --- a/examples/keyboard.cpp +++ b/examples/keyboard.cpp @@ -44,17 +44,17 @@ class Keyboard final : public finalcut::FWidget //---------------------------------------------------------------------- Keyboard::Keyboard (finalcut::FWidget* parent) - : finalcut::FWidget(parent) + : finalcut::FWidget{parent} { - setFWidgetColors().term_fg = finalcut::fc::Default; - setFWidgetColors().term_bg = finalcut::fc::Default; + getColorTheme()->term_fg = finalcut::fc::Default; + getColorTheme()->term_bg = finalcut::fc::Default; } //---------------------------------------------------------------------- void Keyboard::onKeyPress (finalcut::FKeyEvent* ev) { 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}; if ( key_name.isEmpty() ) diff --git a/examples/listbox.cpp b/examples/listbox.cpp index 72480b6a..0a6c60cc 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -105,7 +105,7 @@ class Listbox final : public FDialog //---------------------------------------------------------------------- Listbox::Listbox (FWidget* parent) - : FDialog(parent) + : FDialog{parent} { auto temp = std::make_shared(); temp_str = temp; diff --git a/examples/listview.cpp b/examples/listview.cpp index 39cf8c71..0ec35148 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -68,7 +68,7 @@ class Listview final : public finalcut::FDialog //---------------------------------------------------------------------- Listview::Listview (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { // Set FListView geometry listView.setGeometry(FPoint{2, 1}, FSize{33, 14}); diff --git a/examples/mandelbrot.cpp b/examples/mandelbrot.cpp index 4c1a91ea..1ec4935e 100644 --- a/examples/mandelbrot.cpp +++ b/examples/mandelbrot.cpp @@ -53,7 +53,7 @@ class Mandelbrot final : public finalcut::FDialog //---------------------------------------------------------------------- Mandelbrot::Mandelbrot (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { FDialog::setText ("Mandelbrot set"); } diff --git a/examples/menu.cpp b/examples/menu.cpp index f8a21add..978114f0 100644 --- a/examples/menu.cpp +++ b/examples/menu.cpp @@ -117,7 +117,7 @@ class Menu final : public finalcut::FDialog //---------------------------------------------------------------------- Menu::Menu (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { // Menu bar itms File.setStatusbarMessage ("File management commands"); diff --git a/examples/mouse.cpp b/examples/mouse.cpp index 708005f8..f9dc68f2 100644 --- a/examples/mouse.cpp +++ b/examples/mouse.cpp @@ -72,7 +72,7 @@ class ColorChooser final : public finalcut::FWidget //---------------------------------------------------------------------- ColorChooser::ColorChooser (finalcut::FWidget* parent) - : FWidget(parent) + : FWidget{parent} { FWidget::setSize (FSize{8, 12}); setFixedSize (FSize{8, 12}); @@ -226,7 +226,7 @@ class Brushes final : public finalcut::FWidget //---------------------------------------------------------------------- Brushes::Brushes (finalcut::FWidget* parent) - : FWidget(parent) + : FWidget{parent} { FWidget::setSize (FSize{8, 4}); setFixedSize (FSize{8, 4}); @@ -379,7 +379,7 @@ class MouseDraw final : public finalcut::FDialog //---------------------------------------------------------------------- MouseDraw::MouseDraw (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { FDialog::setText ("Drawing with the mouse"); c_chooser.setPos (FPoint{1, 1}); @@ -447,7 +447,7 @@ void MouseDraw::draw() finalcut::FDialog::draw(); setColor(); - if ( isNewFont() ) + if ( finalcut::FTerm::isNewFont() ) { for (int y{2}; y < y_max; y++) { diff --git a/examples/opti-move.cpp b/examples/opti-move.cpp index ebc78933..ed6061a1 100644 --- a/examples/opti-move.cpp +++ b/examples/opti-move.cpp @@ -132,6 +132,40 @@ void move (int xold, int yold, int xnew, int ynew) << 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 @@ -157,7 +191,7 @@ int main (int argc, char* argv[]) TermApp.clearArea(); // 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 << " Lines: 0.." << ymax << "\r\n"; @@ -189,7 +223,11 @@ int main (int argc, char* argv[]) keyPressed(); // 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()); + // Get the shared_ptr with the base class + std::shared_ptr log = finalcut::FApplication::getLog(); const finalcut::FOptiMove& opti_move = *finalcut::FTerm::getFOptiMove(); finalcut::printDurations(opti_move); diff --git a/examples/rotozoomer.cpp b/examples/rotozoomer.cpp index c342f22c..a1bf1399 100644 --- a/examples/rotozoomer.cpp +++ b/examples/rotozoomer.cpp @@ -80,9 +80,9 @@ class RotoZoomer final : public finalcut::FDialog //---------------------------------------------------------------------- RotoZoomer::RotoZoomer (finalcut::FWidget* parent, bool b, int l) - : finalcut::FDialog(parent) - , benchmark(b) - , loops(l) + : finalcut::FDialog{parent} + , benchmark{b} + , loops{l} { FDialog::setText ("Rotozoomer effect"); @@ -179,11 +179,11 @@ void RotoZoomer::rotozoomer (double cx, double cy, double r, double a) //---------------------------------------------------------------------- void RotoZoomer::generateReport() { - finalcut::FString term_type = getTermType(); + finalcut::FString term_type = finalcut::FTerm::getTermType(); finalcut::FString dimension_str{}; finalcut::FString time_str{}; finalcut::FString fps_str{}; - std::wostringstream rep; + finalcut::FStringStream rep; dimension_str << getDesktopWidth() << "x" << getDesktopHeight(); int elapsed_ms = int(duration_cast(end - start).count()); diff --git a/examples/scrollview.cpp b/examples/scrollview.cpp index 9ad2c02e..bb3a9eb2 100644 --- a/examples/scrollview.cpp +++ b/examples/scrollview.cpp @@ -72,7 +72,7 @@ class Scrollview final : public finalcut::FScrollView //---------------------------------------------------------------------- Scrollview::Scrollview (finalcut::FWidget* parent) - : finalcut::FScrollView(parent) + : finalcut::FScrollView{parent} { // Sets the navigation button geometry go_east.setGeometry (FPoint{1, 1}, FSize{5, 1}); @@ -128,11 +128,11 @@ void Scrollview::setScrollSize (const FSize& size) //---------------------------------------------------------------------- void Scrollview::draw() { - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) setReverse(true); - const auto& wc = getFWidgetColors(); - setColor (wc.label_inactive_fg, wc.dialog_bg); + const auto& wc = getColorTheme(); + setColor (wc->label_inactive_fg, wc->dialog_bg); clearArea(); for (int y{0}; y < int(getScrollHeight()); y++) @@ -143,7 +143,7 @@ void Scrollview::draw() print (32 + ((x + y) % 0x5f)); } - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) setReverse(false); FScrollView::draw(); @@ -214,7 +214,7 @@ class Scrollviewdemo final : public finalcut::FDialog //---------------------------------------------------------------------- Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { FDialog::setGeometry (FPoint{16, 3}, FSize{50, 19}); FDialog::setText ("Scrolling viewport example"); diff --git a/examples/string-operations.cpp b/examples/string-operations.cpp index 2ef0b14f..cd92192d 100644 --- a/examples/string-operations.cpp +++ b/examples/string-operations.cpp @@ -224,17 +224,17 @@ void streamToInterger() finalcut::FString("-321") >> stream_int; 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; 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; 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; 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(); 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 @@ -515,17 +515,17 @@ void convertToNumberExample() const long long_num = finalcut::FString("-9876543210").toLong(); 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 @@ -540,17 +540,17 @@ void convertToNumberExample() << double_num << std::endl; 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: " << 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 { - 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" , char(index[0]) , 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"); } } diff --git a/examples/term-attributes.cpp b/examples/term-attributes.cpp index 5e0bb7c1..c8528bba 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -66,17 +66,17 @@ class AttribDlg final : public finalcut::FDialog void adjustSize() override; // Data members - FColor bgcolor{getFWidgetColors().label_bg}; + FColor bgcolor{getColorTheme()->label_bg}; finalcut::FButton next_button{"&Next >", this}; finalcut::FButton back_button{"< &Back", this}; }; //---------------------------------------------------------------------- AttribDlg::AttribDlg (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { FDialog::setText ( "A terminal attributes test (" - + finalcut::FString{getTermType()} + + finalcut::FString{finalcut::FTerm::getTermType()} + ")"); 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) { - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) return; - if ( bgcolor == FColor(getMaxColor() - 1) ) + if ( bgcolor == FColor(finalcut::FTerm::getMaxColor() - 1) ) bgcolor = fc::Default; else if ( bgcolor == fc::Default ) bgcolor = 0; @@ -161,13 +161,13 @@ void AttribDlg::cb_next (const finalcut::FWidget*, const FDataPtr) //---------------------------------------------------------------------- void AttribDlg::cb_back (const finalcut::FWidget*, const FDataPtr) { - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) return; if ( bgcolor == 0 ) bgcolor = fc::Default; else if ( bgcolor == fc::Default ) - bgcolor = FColor(getMaxColor() - 1); + bgcolor = FColor(finalcut::FTerm::getMaxColor() - 1); else bgcolor--; @@ -238,14 +238,14 @@ class AttribDemo final : public finalcut::FWidget void draw() override; // Data member - FColor last_color{FColor(getMaxColor())}; + FColor last_color{FColor(finalcut::FTerm::getMaxColor())}; }; //---------------------------------------------------------------------- AttribDemo::AttribDemo (finalcut::FWidget* parent) - : finalcut::FWidget(parent) + : finalcut::FWidget{parent} { - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) last_color = 1; else if ( last_color > 16 ) last_color = 16; @@ -267,11 +267,11 @@ void AttribDemo::printColorLine() //---------------------------------------------------------------------- void AttribDemo::printAltCharset() { - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); const auto& parent = static_cast(getParent()); - if ( ! isMonochron() ) - setColor (wc.label_fg, wc.label_bg); + if ( ! finalcut::FTerm::isMonochron() ) + setColor (wc->label_fg, wc->label_bg); print() << FPoint{1, 1} << "alternate charset: "; @@ -418,7 +418,7 @@ void AttribDemo::printProtected() void AttribDemo::draw() { // test alternate character set - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); printAltCharset(); const std::vector > effect @@ -441,15 +441,15 @@ void AttribDemo::draw() { print() << FPoint{1, 2 + int(y)}; - if ( ! isMonochron() ) - setColor (wc.label_fg, wc.label_bg); + if ( ! finalcut::FTerm::isMonochron() ) + setColor (wc->label_fg, wc->label_bg); if ( y < effect.size() ) effect[y](); } - if ( ! isMonochron() ) - setColor(wc.label_fg, wc.label_bg); + if ( ! finalcut::FTerm::isMonochron() ) + setColor(wc->label_fg, wc->label_bg); print() << FPoint{1, 15}; const FColor bg = static_cast(getParent())->getBGColor(); diff --git a/examples/termcap.cpp b/examples/termcap.cpp index d01dcfbd..f7532212 100644 --- a/examples/termcap.cpp +++ b/examples/termcap.cpp @@ -300,7 +300,7 @@ int main (int argc, char* argv[]) finalcut::FApplication TermApp {argc, argv, disable_alt_screen}; 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); diff --git a/examples/timer.cpp b/examples/timer.cpp index 5c162394..81a94fbf 100644 --- a/examples/timer.cpp +++ b/examples/timer.cpp @@ -46,7 +46,7 @@ class Timer final : public finalcut::FWidget //---------------------------------------------------------------------- Timer::Timer (finalcut::FWidget* parent) - : finalcut::FWidget(parent) + : finalcut::FWidget{parent} { addTimer (60000); // 1-minute timer const int id = addTimer (50); // 50-millisecond timer @@ -54,8 +54,8 @@ Timer::Timer (finalcut::FWidget* parent) delTimer (id); addTimer (250); // 250-millisecond timer - setFWidgetColors().term_fg = fc::Default; - setFWidgetColors().term_bg = fc::Default; + getColorTheme()->term_fg = fc::Default; + getColorTheme()->term_bg = fc::Default; } //---------------------------------------------------------------------- diff --git a/examples/transparent.cpp b/examples/transparent.cpp index bec51c3e..67ef2fd1 100644 --- a/examples/transparent.cpp +++ b/examples/transparent.cpp @@ -71,8 +71,8 @@ class Transparent final : public finalcut::FDialog //---------------------------------------------------------------------- Transparent::Transparent ( finalcut::FWidget* parent , Transparent::trans_type tt ) - : finalcut::FDialog(parent) - , type(tt) + : finalcut::FDialog{parent} + , type{tt} { // Set statusbar text for this window // Avoids calling a virtual function from the constructor @@ -89,18 +89,18 @@ void Transparent::draw() { finalcut::FDialog::draw(); - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) setReverse(true); if ( type == shadow ) { - const auto& wc = getFWidgetColors(); - print() << FColorPair {wc.shadow_bg, wc.shadow_fg} + const auto& wc = getColorTheme(); + print() << FColorPair {wc->shadow_bg, wc->shadow_fg} << FStyle {fc::ColorOverlay}; } else if ( type == inherit_background ) { - if ( getMaxColor() > 8 ) + if ( finalcut::FTerm::getMaxColor() > 8 ) print() << FColorPair {fc::Blue, fc::Black}; else print() << FColorPair {fc::Green, fc::Black}; @@ -191,7 +191,7 @@ class MainWindow final : public finalcut::FDialog //---------------------------------------------------------------------- MainWindow::MainWindow (finalcut::FWidget* parent) - : FDialog(parent) + : FDialog{parent} { // The memory allocation for the following three sub windows occurs // with the operator new. The lifetime of the generated widget @@ -228,14 +228,14 @@ void MainWindow::draw() { finalcut::FDialog::draw(); - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) setReverse(true); setColor(); print() << FPoint{2, 4} << line1; print() << FPoint{2, 5} << line2; - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) setReverse(false); updateTerminal(); diff --git a/examples/treeview.cpp b/examples/treeview.cpp index c0ec19bc..8d36e5af 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -326,7 +326,7 @@ Treeview::TreeItem Treeview::oceania[] = // constructors and destructor //---------------------------------------------------------------------- Treeview::Treeview (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { // Set FListView geometry listView.setGeometry(FPoint{2, 1}, FSize{53, 14}); diff --git a/examples/ui.cpp b/examples/ui.cpp index 4565e4f0..9e696d09 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -76,7 +76,7 @@ class ProgressDialog final : public finalcut::FDialog //---------------------------------------------------------------------- ProgressDialog::ProgressDialog (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { // Dialog settings // Avoids calling a virtual function from the constructor @@ -218,7 +218,7 @@ class TextWindow final : public finalcut::FDialog //---------------------------------------------------------------------- TextWindow::TextWindow (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { scrollText.ignorePadding(); 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_pasteClipboard (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_setTitlebar (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 finalcut::FMenuItem Env{"&Terminal...", &View}; finalcut::FMenuItem Drive{"&Drive symbols...", &View}; + finalcut::FMenuItem Line3{&View}; + finalcut::FCheckMenuItem Theme{"Dark &mode", &View}; // Statusbar finalcut::FStatusBar Statusbar{this}; finalcut::FStatusKey key_F1{fc::Fkey_f1, "About", &Statusbar}; @@ -369,7 +372,7 @@ class MyDialog final : public finalcut::FDialog //---------------------------------------------------------------------- MyDialog::MyDialog (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { init(); } @@ -422,6 +425,10 @@ void MyDialog::initMenu() // "View" menu items Env.setStatusbarMessage ("Informations about this terminal"); Drive.setStatusbarMessage ("Show drive symbols"); + Line3.setSeparator(); + + if ( finalcut::FStartOptions::getFStartOptions().dark_theme ) + Theme.setChecked(); } //---------------------------------------------------------------------- @@ -517,6 +524,12 @@ void MyDialog::initViewMenuCallbacks() "clicked", 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" , finalcut::FString{} - << " Type: " << getTermType() << "\n" - << " Name: " << getTermFileName() << "\n" - << " Mode: " << getEncodingString() << "\n" + << " Type: " << finalcut::FTerm::getTermType() << "\n" + << " Name: " << finalcut::FTerm::getTermFileName() << "\n" + << " Mode: " << finalcut::FTerm::getEncodingString() << "\n" << " Size: " << x << fc::Times << y << "\n" - << "Colors: " << getMaxColor() + << "Colors: " << finalcut::FTerm::getMaxColor() , finalcut::FMessageBox::Ok, 0, 0, this ); info1.setHeadline("Terminal:"); @@ -834,7 +847,7 @@ void MyDialog::cb_drives (const finalcut::FWidget*, const FDataPtr) , finalcut::FMessageBox::Ok, 0, 0, this ); - if ( isNewFont() ) + if ( finalcut::FTerm::isNewFont() ) { finalcut::FLabel drive {finalcut::NF_Drive, &info2}; 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}; cd.setGeometry (FPoint{11, 6}, FSize{4, 1}); - if ( isMonochron() ) + if ( finalcut::FTerm::isMonochron() ) { net.setReverseMode(); drive.setReverseMode(); @@ -902,6 +915,21 @@ void MyDialog::cb_clearInput (const finalcut::FWidget*, const FDataPtr) myLineEdit.redraw(); } +//---------------------------------------------------------------------- +void MyDialog::cb_switchTheme (const finalcut::FWidget* widget, const FDataPtr) +{ + const auto& check_menu = *(static_cast(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) { @@ -917,7 +945,7 @@ void MyDialog::cb_setTitlebar (finalcut::FWidget* widget, const FDataPtr) auto& lineedit = *(static_cast(widget)); finalcut::FString title{}; lineedit >> title; - setTermTitle (title); + finalcut::FTerm::setTermTitle (title); setText (title); redraw(); } @@ -981,7 +1009,7 @@ void MyDialog::cb_view (const finalcut::FWidget*, FDataPtr data) int(getRootWidget()->getHeight() / 6) } , FSize{60, getRootWidget()->getHeight() * 3 / 4} ); view->setResizeable(); - std::string line = ""; + std::string line{""}; std::ifstream infile; infile.open(file); @@ -1021,17 +1049,17 @@ int main (int argc, char* argv[]) // Create the application object app finalcut::FApplication app{argc, argv}; app.setNonBlockingRead(); - app.redefineDefaultColors(true); - app.setTermTitle (title); + finalcut::FTerm::redefineDefaultColors(true); + finalcut::FTerm::setTermTitle (title); // Force vt100 encoding - //app.setEncoding(finalcut::fc::VT100); + //finalcut::FTerm::setEncoding(finalcut::fc::VT100); // Sets the terminal size to 94×30 - //app.setTermSize(94,30); + //finalcut::FTerm::setTermSize(FSize{94, 30}); // Enable the final cut graphical font - //app.setNewFont(); + //finalcut::FTerm::setNewFont(); // Create main dialog object d MyDialog d{&app}; diff --git a/examples/watch.cpp b/examples/watch.cpp index fdce0bc5..9b03b31f 100644 --- a/examples/watch.cpp +++ b/examples/watch.cpp @@ -73,7 +73,7 @@ class Watch final : public finalcut::FDialog //---------------------------------------------------------------------- Watch::Watch (FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { // Dialog settings // Avoids calling a virtual function from the constructor diff --git a/examples/windows.cpp b/examples/windows.cpp index f761f065..f53a7f77 100644 --- a/examples/windows.cpp +++ b/examples/windows.cpp @@ -66,32 +66,32 @@ class SmallWindow final : public finalcut::FDialog //---------------------------------------------------------------------- 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_down = fc::BlackDownPointingTriangle; left_arrow = arrow_up; - left_arrow.setForegroundColor (wc.label_inactive_fg); + left_arrow.setForegroundColor (wc->label_inactive_fg); left_arrow.setEmphasis(); left_arrow.ignorePadding(); left_arrow.setGeometry (FPoint{2, 2}, FSize{1, 1}); right_arrow = arrow_up; - right_arrow.setForegroundColor (wc.label_inactive_fg); + right_arrow.setForegroundColor (wc->label_inactive_fg); right_arrow.setEmphasis(); right_arrow.ignorePadding(); right_arrow.setGeometry (FPoint{int(getWidth()) - 1, 2}, FSize{1, 1}); 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.setGeometry (FPoint{1, 1}, FSize{6, 1}); top_right_label = "zoom"; 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.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 = bottom_label_text; bottom_label.setAlignment (fc::alignRight); - bottom_label.setForegroundColor (wc.label_inactive_fg); + bottom_label.setForegroundColor (wc->label_inactive_fg); bottom_label.setEmphasis(); bottom_label.setGeometry (FPoint{13, 3}, FSize{6, 3}); } @@ -240,7 +240,7 @@ class Window final : public finalcut::FDialog //---------------------------------------------------------------------- Window::Window (finalcut::FWidget* parent) - : finalcut::FDialog(parent) + : finalcut::FDialog{parent} { // Menu bar item File.setStatusbarMessage ("File management commands"); diff --git a/src/Makefile.am b/src/Makefile.am index 846b28be..098d9dbf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,6 +10,7 @@ lib_LTLIBRARIES = libfinal.la libfinal_la_SOURCES = \ fstring.cpp \ + fstringstream.cpp \ fpoint.cpp \ fsize.cpp \ frect.cpp \ @@ -25,6 +26,8 @@ libfinal_la_SOURCES = \ flabel.cpp \ flistbox.cpp \ flistview.cpp \ + flog.cpp \ + flogger.cpp \ fmenu.cpp \ fmouse.cpp \ fsystem.cpp \ @@ -67,6 +70,7 @@ libfinal_la_SOURCES = \ foptimove.cpp \ ftermbuffer.cpp \ fapplication.cpp \ + fcolorpalette.cpp \ fwidgetcolors.cpp \ fwidget.cpp \ fwidget_functions.cpp \ @@ -98,6 +102,8 @@ finalcutinclude_HEADERS = \ include/final/flineedit.h \ include/final/flistbox.h \ include/final/flistview.h \ + include/final/flog.h \ + include/final/flogger.h \ include/final/fmenu.h \ include/final/fmouse.h \ include/final/fkeyboard.h \ @@ -126,6 +132,7 @@ finalcutinclude_HEADERS = \ include/final/fstartoptions.h \ include/final/fstatusbar.h \ include/final/fstring.h \ + include/final/fstringstream.h \ include/final/fsystem.h \ include/final/fsystemimpl.h \ include/final/ftermcap.h \ diff --git a/src/Makefile.clang b/src/Makefile.clang index 0429f70d..e5ce296d 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -25,6 +25,8 @@ INCLUDE_HEADERS = \ flineedit.h \ flistbox.h \ flistview.h \ + flog.h \ + flogger.h \ fmenu.h \ fdialoglistmenu.h \ fmenubar.h \ @@ -49,6 +51,7 @@ INCLUDE_HEADERS = \ fcombobox.h \ fstatusbar.h \ fstring.h \ + fstringstream.h \ fmouse.h \ fkeyboard.h \ fstartoptions.h \ @@ -83,6 +86,7 @@ RM = rm -f LIB = libfinal.so OBJS = \ fstring.o \ + fstringstream.o \ fpoint.o \ fsize.o \ frect.o \ @@ -98,6 +102,8 @@ OBJS = \ flabel.o \ flistbox.o \ flistview.o \ + flog.o \ + flogger.o \ fmenu.o \ fdialoglistmenu.o \ fmenubar.o \ @@ -139,6 +145,7 @@ OBJS = \ foptimove.o \ ftermbuffer.o \ fapplication.o \ + fcolorpalette.o \ fwidgetcolors.o \ fwidget.o \ fwidget_functions.o \ diff --git a/src/Makefile.gcc b/src/Makefile.gcc index d3c5c420..e40bad84 100644 --- a/src/Makefile.gcc +++ b/src/Makefile.gcc @@ -25,6 +25,8 @@ INCLUDE_HEADERS = \ flineedit.h \ flistbox.h \ flistview.h \ + flog.h \ + flogger.h \ fmenu.h \ fdialoglistmenu.h \ fmenubar.h \ @@ -49,6 +51,7 @@ INCLUDE_HEADERS = \ fcombobox.h \ fstatusbar.h \ fstring.h \ + fstringstream.h \ fmouse.h \ fkeyboard.h \ fstartoptions.h \ @@ -83,6 +86,7 @@ RM = rm -f LIB = libfinal.so OBJS = \ fstring.o \ + fstringstream.o \ fpoint.o \ fsize.o \ frect.o \ @@ -98,6 +102,8 @@ OBJS = \ flabel.o \ flistbox.o \ flistview.o \ + flog.o \ + flogger.o \ fmenu.o \ fdialoglistmenu.o \ fmenubar.o \ @@ -139,6 +145,7 @@ OBJS = \ foptimove.o \ ftermbuffer.o \ fapplication.o \ + fcolorpalette.o \ fwidgetcolors.o \ fwidget.o \ fwidget_functions.o \ diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 8d8b6294..1278b856 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -25,6 +25,8 @@ #include "final/fapplication.h" #include "final/fevent.h" +#include "final/flog.h" +#include "final/flogger.h" #include "final/fmenu.h" #include "final/fmenubar.h" #include "final/fmessagebox.h" @@ -69,7 +71,7 @@ bool FApplication::quit_now {false}; FApplication::FApplication ( const int& _argc , char* _argv[] , bool disable_alt_screen ) - : FWidget(processParameters(_argc, _argv), disable_alt_screen) + : FWidget{processParameters(_argc, _argv), disable_alt_screen} , app_argc{_argc} , app_argv{_argv} { @@ -98,6 +100,11 @@ FApplication::FApplication ( const int& _argc FApplication::~FApplication() // destructor { app_object = nullptr; + + if ( eventInQueue() ) + event_queue.clear(); + + destroyLog(); } @@ -108,6 +115,24 @@ FApplication* FApplication::getApplicationObject() return app_object; } +//---------------------------------------------------------------------- +FApplication::FLogPtr& FApplication::getLog() +{ + // Global logger object + static FLogPtr* logger = new FLogPtr(); + + if ( logger && logger->get() == nullptr ) + *logger = std::make_shared(); + + return *logger; +} + +//---------------------------------------------------------------------- +void FApplication::setLog (const FLogPtr& logger) +{ + getLog() = logger; +} + //---------------------------------------------------------------------- bool FApplication::isQuit() { @@ -167,25 +192,27 @@ void FApplication::quit() //---------------------------------------------------------------------- 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; if ( ! isEventProcessable (receiver, event) ) return false; // 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) { - if ( ! receiver ) + if ( ! (bool(receiver) && bool(event)) ) return; // queue this event - eventPair send_event (receiver, std::make_shared(*event)); - event_queue.push_back(send_event); + event->queued = true; + event_queue.emplace_back (receiver, event); } //---------------------------------------------------------------------- @@ -193,8 +220,9 @@ void FApplication::sendQueuedEvents() { while ( eventInQueue() ) { - sendEvent( event_queue.front().first, - event_queue.front().second.get() ); + const EventPair& event_pair = event_queue.front(); + event_pair.second->queued = false; + sendEvent(event_pair.first, event_pair.second); event_queue.pop_front(); } } @@ -234,6 +262,12 @@ bool FApplication::removeQueuedEvent (const FObject* receiver) return retval; } +//---------------------------------------------------------------------- +void FApplication::processExternalUserEvent() +{ + // This method can be overloaded and replaced by own code +} + //---------------------------------------------------------------------- FWidget* FApplication::processParameters (const int& argc, char* argv[]) { @@ -248,6 +282,37 @@ FWidget* FApplication::processParameters (const int& argc, char* argv[]) return nullptr; } +//---------------------------------------------------------------------- +void FApplication::setDefaultTheme() +{ + if ( FTerm::getMaxColor() < 16 ) // for 8 color mode + { + if ( getStartOptions().color_change ) + FTerm::setColorPaletteTheme(&FTerm::setPalette); + + setColorTheme(); + } + else + { + if ( getStartOptions().color_change ) + FTerm::setColorPaletteTheme(&FTerm::setPalette); + + setColorTheme(); + } +} + +//---------------------------------------------------------------------- +void FApplication::setDarkTheme() +{ + if ( getStartOptions().color_change ) + FTerm::setColorPaletteTheme(&FTerm::setPalette); + + if ( FTerm::getMaxColor() < 16 ) // for 8 color mode + setColorTheme(); + else + setColorTheme(); +} + //---------------------------------------------------------------------- void FApplication::showParameterUsage() { @@ -277,6 +342,8 @@ void FApplication::showParameterUsage() << " Set the standard vga 8x16 font\n" << " --newfont " << " Enables the graphical font\n" + << " --dark-theme " + << " Enables the dark theme\n" #if defined(__FreeBSD__) || defined(__DragonFly__) << "\n" @@ -322,7 +389,7 @@ void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev) void FApplication::init (uInt64 key_time, uInt64 dblclick_time) { // Initialize keyboard - keyboard = FVTerm::getFKeyboard(); + keyboard = FTerm::getFKeyboard(); // Set the keyboard keypress timeout if ( keyboard ) @@ -340,7 +407,7 @@ void FApplication::init (uInt64 key_time, uInt64 dblclick_time) } // Initialize mouse control - mouse = FVTerm::getFMouseControl(); + mouse = FTerm::getFMouseControl(); // Set stdin number for a gpm-mouse if ( mouse ) @@ -349,6 +416,9 @@ void FApplication::init (uInt64 key_time, uInt64 dblclick_time) // Set the default double click interval if ( mouse ) 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 }, {"vgafont", no_argument, nullptr, 0 }, {"newfont", no_argument, nullptr, 0 }, + {"dark-theme", no_argument, nullptr, 0 }, #if defined(__FreeBSD__) || defined(__DragonFly__) {"no-esc-for-alt-meta", no_argument, nullptr, 0 }, @@ -405,8 +476,8 @@ void FApplication::cmd_options (const int& argc, char* argv[]) else if ( encoding.includes("help") ) showParameterUsage(); else - exitWithMessage ( "Unknown encoding " - + std::string(encoding.c_str()) ); + FTerm::exitWithMessage ( "Unknown encoding " + + std::string(encoding.c_str()) ); } if ( std::strcmp(long_options[idx].name, "no-mouse") == 0 ) @@ -433,6 +504,9 @@ void FApplication::cmd_options (const int& argc, char* argv[]) if ( std::strcmp(long_options[idx].name, "newfont") == 0 ) getStartOptions().newfont = true; + if ( std::strcmp(long_options[idx].name, "dark-theme") == 0 ) + getStartOptions().dark_theme = true; + #if defined(__FreeBSD__) || defined(__DragonFly__) if ( std::strcmp(long_options[idx].name, "no-esc-for-alt-meta") == 0 ) getStartOptions().meta_sends_escape = false; @@ -453,6 +527,13 @@ inline FStartOptions& FApplication::getStartOptions() return FStartOptions::getFStartOptions(); } +//---------------------------------------------------------------------- +inline void FApplication::destroyLog() +{ + const FLogPtr* logger = &(getLog()); + delete logger; +} + //---------------------------------------------------------------------- inline void FApplication::findKeyboardWidget() { @@ -985,7 +1066,7 @@ void FApplication::sendMouseMiddleClickEvent ( const FPoint& widgetMousePos sendEvent (clicked, &m_down_ev); // gnome-terminal sends no released on middle click - if ( isGnomeTerminal() ) + if ( FTerm::isGnomeTerminal() ) setClickedWidget(nullptr); } else if ( mouse->isMiddleButtonReleased() ) @@ -1057,7 +1138,7 @@ void FApplication::processMouseEvent() //---------------------------------------------------------------------- void FApplication::processResizeEvent() { - if ( ! hasChangedTermSize() ) + if ( ! FTerm::hasChangedTermSize() ) return; if ( mouse ) @@ -1070,7 +1151,7 @@ void FApplication::processResizeEvent() sendEvent(app_object, &r_ev); if ( r_ev.isAccepted() ) - changeTermSizeFinished(); + FTerm::changeTermSizeFinished(); } //---------------------------------------------------------------------- @@ -1094,6 +1175,17 @@ void FApplication::processCloseWidget() 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() { @@ -1104,6 +1196,8 @@ bool FApplication::processNextEvent() processResizeEvent(); processTerminalUpdate(); processCloseWidget(); + processLogger(); + processExternalUserEvent(); sendQueuedEvents(); 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 return true; @@ -1139,7 +1234,7 @@ bool FApplication::isEventProcessable (const FObject* receiver, const FEvent* ev && ! window->getFlags().modal && ! window->isMenuWidget() ) { - switch ( uInt(event->type()) ) + switch ( uInt(event->getType()) ) { case fc::KeyPress_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 - if ( event->type() >= fc::MouseDown_Event - && event->type() <= fc::MouseMove_Event + if ( event->getType() >= fc::MouseDown_Event + && event->getType() <= fc::MouseMove_Event && ! widget->isEnabled() ) return false; diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 0e110d02..f970fa0a 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -36,14 +36,14 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- FButton::FButton(FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init(); } //---------------------------------------------------------------------- FButton::FButton (const FString& txt, FWidget* parent) - : FWidget(parent) + : FWidget{parent} , text{txt} { init(); @@ -127,6 +127,20 @@ void FButton::setInactiveBackgroundColor (FColor color) 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) { @@ -165,8 +179,8 @@ bool FButton::setFlat (bool enable) bool FButton::setShadow (bool enable) { if ( enable - && getEncoding() != fc::VT100 - && getEncoding() != fc::ASCII ) + && FTerm::getEncoding() != fc::VT100 + && FTerm::getEncoding() != fc::ASCII ) { setFlags().shadow = true; setShadowSize(FSize{1, 1}); @@ -218,9 +232,9 @@ void FButton::hide() } else { - auto wc = getFWidgetColors(); - fg = wc.dialog_fg; - bg = wc.dialog_bg; + const auto& wc = getColorTheme(); + fg = wc->dialog_fg; + bg = wc->dialog_bg; } setColor (fg, bg); @@ -387,9 +401,9 @@ void FButton::onFocusOut (FFocusEvent*) //---------------------------------------------------------------------- void FButton::init() { - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.button_active_fg); - setBackgroundColor (wc.button_active_bg); + const auto& wc = getColorTheme(); + setForegroundColor (wc->button_active_fg); + setBackgroundColor (wc->button_active_bg); setShadow(); 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) { - if ( button_down || isNewFont() ) + if ( button_down || FTerm::isNewFont() ) return; // 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++) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); // Light background print() << FPoint{1 + int(getWidth()), y} << ' '; // clear right - if ( getFlags().active && isMonochron() ) + if ( getFlags().active && FTerm::isMonochron() ) setReverse(false); // Dark background } } @@ -470,7 +484,7 @@ inline void FButton::drawMarginLeft() { 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); // ► else print (space_char); // full block █ @@ -486,7 +500,7 @@ inline void FButton::drawMarginRight() { 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); // ◄ else print (space_char); // full block █ @@ -543,10 +557,10 @@ inline void FButton::drawButtonTextLine (const FString& button_text) setCursorPos ({ 2 + int(center_offset + hotkeypos) , 1 + int(vcenter_offset) }); // hotkey - if ( ! getFlags().active && isMonochron() ) + if ( ! getFlags().active && FTerm::isMonochron() ) setReverse(true); // Light background - if ( active_focus && (isMonochron() || getMaxColor() < 16) ) + if ( active_focus && (FTerm::isMonochron() || FTerm::getMaxColor() < 16) ) setBold(); 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); - if ( ! active_focus && getMaxColor() < 16 ) + if ( ! active_focus && FTerm::getMaxColor() < 16 ) setBold(); if ( ! getFlags().no_underline ) @@ -563,7 +577,7 @@ inline void FButton::drawButtonTextLine (const FString& button_text) print (button_text[z]); - if ( ! active_focus && getMaxColor() < 16 ) + if ( ! active_focus && FTerm::getMaxColor() < 16 ) unsetBold(); if ( ! getFlags().no_underline ) @@ -588,7 +602,7 @@ inline void FButton::drawButtonTextLine (const FString& button_text) print() << FPoint{int(getWidth() + indent) - 2, 1} << ".."; } - if ( active_focus && (isMonochron() || getMaxColor() < 16) ) + if ( active_focus && (FTerm::isMonochron() || FTerm::getMaxColor() < 16) ) unsetBold(); for (pos = center_offset + column_width; pos < getWidth() - 2; pos++) @@ -604,7 +618,7 @@ void FButton::draw() space_char = int(' '); active_focus = getFlags().active && getFlags().focus; - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); // Light background // Click animation preprocessing @@ -613,10 +627,10 @@ void FButton::draw() // Clear right margin after animation clearRightMargin (parent_widget); - if ( ! getFlags().active && isMonochron() ) + if ( ! getFlags().active && FTerm::isMonochron() ) 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 if ( getFlags().flat && ! button_down ) @@ -648,7 +662,7 @@ void FButton::draw() if ( ! getFlags().flat && getFlags().shadow && ! button_down ) drawShadow(this); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); // Dark background updateStatusBar(); diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 219fedbb..85943373 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -39,14 +39,14 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FButtonGroup::FButtonGroup(FWidget* parent) - : FScrollView(parent) + : FScrollView{parent} { init(); } //---------------------------------------------------------------------- FButtonGroup::FButtonGroup (const FString& txt, FWidget* parent) - : FScrollView(parent) + : FScrollView{parent} , text{txt} { init(); @@ -196,9 +196,9 @@ void FButtonGroup::hide() } else { - const auto& wc = getFWidgetColors(); - fg = wc.dialog_fg; - bg = wc.dialog_bg; + const auto& wc = getColorTheme(); + fg = wc->dialog_fg; + bg = wc->dialog_bg; } setColor (fg, bg); @@ -380,13 +380,13 @@ void FButtonGroup::setHotkeyAccelerator() //---------------------------------------------------------------------- void FButtonGroup::draw() { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); - setColor(); + useParentWidgetColor(); clearArea(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); FScrollView::draw(); @@ -427,9 +427,6 @@ bool FButtonGroup::isRadioButton (const FToggleButton* button) const //---------------------------------------------------------------------- void FButtonGroup::init() { - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.label_fg); - setBackgroundColor (wc.label_bg); setMinimumSize (FSize{7, 3}); buttonlist.clear(); // no buttons yet } @@ -438,7 +435,7 @@ void FButtonGroup::init() void FButtonGroup::drawText ( const FString& label_text , std::size_t hotkeypos ) { - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); const std::size_t column_width = getColumnWidth(label_text); std::size_t length = label_text.getLength(); bool ellipsis{false}; @@ -451,19 +448,19 @@ void FButtonGroup::drawText ( const FString& label_text ellipsis = true; } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); if ( isEnabled() ) - setColor(wc.label_emphasis_fg, wc.label_bg); + setColor(wc->label_emphasis_fg, wc->label_bg); 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++) { 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 ) setUnderline(); @@ -473,16 +470,16 @@ void FButtonGroup::drawText ( const FString& label_text if ( ! getFlags().no_underline ) unsetUnderline(); - setColor (wc.label_emphasis_fg, wc.label_bg); + setColor (wc->label_emphasis_fg, wc->label_bg); } else print (label_text[z]); } 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); } diff --git a/src/fcheckbox.cpp b/src/fcheckbox.cpp index e719bcc5..1e6f6c27 100644 --- a/src/fcheckbox.cpp +++ b/src/fcheckbox.cpp @@ -33,14 +33,14 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FCheckBox::FCheckBox(FWidget* parent) - : FToggleButton(parent) + : FToggleButton{parent} { init(); } //---------------------------------------------------------------------- FCheckBox::FCheckBox (const FString& txt, FWidget* parent) - : FToggleButton(txt, parent) + : FToggleButton{txt, parent} { init(); } @@ -74,9 +74,9 @@ void FCheckBox::draw() void FCheckBox::drawCheckButton() { print() << FPoint{1, 1}; - setColor(); + useParentWidgetColor(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) { if ( hasFocus() ) setReverse(false); @@ -89,14 +89,14 @@ void FCheckBox::drawCheckButton() else drawUnchecked(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } //---------------------------------------------------------------------- inline void FCheckBox::drawChecked() { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) print (CHECKBOX_ON); else { @@ -109,7 +109,7 @@ inline void FCheckBox::drawChecked() //---------------------------------------------------------------------- inline void FCheckBox::drawUnchecked() { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) print (CHECKBOX); else { diff --git a/src/fcheckmenuitem.cpp b/src/fcheckmenuitem.cpp index fcfdbf1f..201d4e05 100644 --- a/src/fcheckmenuitem.cpp +++ b/src/fcheckmenuitem.cpp @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -34,14 +34,14 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FCheckMenuItem::FCheckMenuItem (FWidget* parent) - : FMenuItem(parent) + : FMenuItem{parent} { init (parent); } //---------------------------------------------------------------------- FCheckMenuItem::FCheckMenuItem (const FString& txt, FWidget* parent) - : FMenuItem(txt, parent) + : FMenuItem{txt, parent} { init (parent); } diff --git a/src/fcolorpalette.cpp b/src/fcolorpalette.cpp new file mode 100644 index 00000000..ab003a40 --- /dev/null +++ b/src/fcolorpalette.cpp @@ -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 * +* . * +***********************************************************************/ + +#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 + diff --git a/src/fcombobox.cpp b/src/fcombobox.cpp index c4f3930a..c3471847 100644 --- a/src/fcombobox.cpp +++ b/src/fcombobox.cpp @@ -27,6 +27,7 @@ #include "final/flabel.h" #include "final/flineedit.h" #include "final/flistbox.h" +#include "final/flog.h" #include "final/fmouse.h" #include "final/fpoint.h" #include "final/fsize.h" @@ -43,7 +44,7 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FDropDownListBox::FDropDownListBox (FWidget* parent) - : FWindow(parent) + : FWindow{parent} { init(); } @@ -71,7 +72,7 @@ void FDropDownListBox::setGeometry ( const FPoint& pos, const FSize& size { FWindow::setGeometry (pos, size, adjust); - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { FSize new_size{size}; new_size.scaleBy(-1, 0); @@ -123,25 +124,25 @@ void FDropDownListBox::init() void FDropDownListBox::draw() { // Fill the background - const auto& wc = getFWidgetColors(); - setColor (wc.menu_active_fg, wc.menu_active_bg); + const auto& wc = getColorTheme(); + setColor (wc->menu_active_fg, wc->menu_active_bg); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); clearArea(); drawShadow(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } //---------------------------------------------------------------------- void FDropDownListBox::drawShadow() { - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); 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; // █ } @@ -168,7 +169,7 @@ bool FDropDownListBox::containsWidget (const FPoint& p) // constructors and destructor //---------------------------------------------------------------------- FComboBox::FComboBox (FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init(); } @@ -218,8 +219,8 @@ bool FComboBox::setFocus (bool enable) bool FComboBox::setShadow (bool enable) { if ( enable - && getEncoding() != fc::VT100 - && getEncoding() != fc::ASCII ) + && FTerm::getEncoding() != fc::VT100 + && FTerm::getEncoding() != fc::ASCII ) { setFlags().shadow = true; setShadowSize(FSize{1, 1}); @@ -494,7 +495,7 @@ void FComboBox::init() adjustSize(); initCallbacks(); - if ( isNewFont() ) + if ( FTerm::isNewFont() ) nf = 1; } @@ -532,22 +533,22 @@ void FComboBox::initCallbacks() //---------------------------------------------------------------------- void FComboBox::draw() { - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); const FColorPair button_color = [this, &wc] () { if ( list_window.isEmpty() ) - return FColorPair { wc.scrollbar_button_inactive_fg - , wc.scrollbar_button_inactive_bg }; + return FColorPair { wc->scrollbar_button_inactive_fg + , wc->scrollbar_button_inactive_bg }; else - return FColorPair { wc.scrollbar_button_fg - , wc.scrollbar_button_bg }; + return FColorPair { wc->scrollbar_button_fg + , wc->scrollbar_button_bg }; }(); print() << FPoint{int(getWidth()) - nf, 1} << button_color; - if ( isNewFont() ) + if ( FTerm::isNewFont() ) print() << NF_button_arrow_down; else print() << fc::BlackDownPointingTriangle; // ▼ @@ -605,9 +606,9 @@ void FComboBox::passEventToListWindow (FMouseEvent* const& ev) list_window.list.setFocus(); 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) { - const auto& mouse = getFMouseControl(); + const auto& mouse = FTerm::getFMouseControl(); if ( mouse && ! mouse->isLeftButtonPressed() ) return; @@ -675,7 +676,7 @@ void FComboBox::cb_inputFieldSwitch (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() ) return; @@ -692,9 +693,9 @@ void FComboBox::cb_inputFieldHandOver (const FWidget*, const FDataPtr) list_window.list.setFocus(); 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"); } } diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 8ea0335e..c34a3d5c 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -42,15 +42,15 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FDialog::FDialog (FWidget* parent) - : FWindow(parent) + : FWindow{parent} { init(); } //---------------------------------------------------------------------- FDialog::FDialog (const FString& txt, FWidget* parent) - : FWindow(parent) - , tb_text(txt) + : FWindow{parent} + , tb_text{txt} { init(); } @@ -99,7 +99,7 @@ bool FDialog::setModal (bool enable) if ( enable ) { setModalDialogCounter()++; - getFKeyboard()->clearKeyBuffer(); + FTerm::getFKeyboard()->clearKeyBuffer(); } else setModalDialogCounter()--; @@ -136,6 +136,15 @@ bool FDialog::setBorder (bool 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) { @@ -752,7 +761,7 @@ void FDialog::draw() // Fill the background setColor(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); clearArea(); @@ -763,14 +772,14 @@ void FDialog::draw() if ( getFlags().shadow ) drawDialogShadow(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } //---------------------------------------------------------------------- void FDialog::drawDialogShadow() { - if ( isMonochron() && ! getFlags().trans_shadow ) + if ( FTerm::isMonochron() && ! getFlags().trans_shadow ) return; drawShadow(this); @@ -800,9 +809,7 @@ void FDialog::init() addDialog(this); setActiveWindow(this); setTransparentShadow(); - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.dialog_fg); - setBackgroundColor (wc.dialog_bg); + resetColors(); auto old_focus = FWidget::getFocusWidget(); if ( old_focus ) @@ -824,9 +831,9 @@ void FDialog::initDialogMenu() { 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; } @@ -854,9 +861,9 @@ void FDialog::initMoveSizeMenuItem (FMenu* 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; } @@ -877,9 +884,9 @@ void FDialog::initZoomMenuItem (FMenu* 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; } @@ -900,9 +907,9 @@ void FDialog::initCloseMenuItem (FMenu* 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; } @@ -924,13 +931,13 @@ void FDialog::drawBorder() if ( (getMoveSizeWidget() == this || ! resize_click_pos.isOrigin() ) && ! isZoomed() ) { - const auto& wc = getFWidgetColors(); - setColor (wc.dialog_resize_fg, getBackgroundColor()); + const auto& wc = getColorTheme(); + setColor (wc->dialog_resize_fg, getBackgroundColor()); } else 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()}; @@ -965,7 +972,7 @@ void FDialog::drawTitleBar() // Draw the zoom/unzoom button drawZoomButton(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); #if DEBUG @@ -983,14 +990,14 @@ void FDialog::drawBarButton() { // Print the title button print() << FPoint{1, 1}; - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); 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 - 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() ) setReverse(false); @@ -998,11 +1005,11 @@ void FDialog::drawBarButton() setReverse(true); } - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { print (finalcut::NF_menu_button); } - else if ( isMonochron() ) + else if ( FTerm::isMonochron() ) { print ('['); @@ -1034,12 +1041,12 @@ void FDialog::drawZoomButton() if ( ! isResizeable() ) return; - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); 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 - setColor (wc.titlebar_button_fg, wc.titlebar_button_bg); + setColor (wc->titlebar_button_fg, wc->titlebar_button_bg); if ( isZoomed() ) drawRestoreSizeButton(); @@ -1050,13 +1057,13 @@ void FDialog::drawZoomButton() //---------------------------------------------------------------------- inline void FDialog::drawRestoreSizeButton() { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { print (finalcut::NF_button_down); } else { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) { print ('['); print (fc::BlackDownPointingTriangle); // ▼ @@ -1074,13 +1081,13 @@ inline void FDialog::drawRestoreSizeButton() //---------------------------------------------------------------------- inline void FDialog::drawZoomedButton() { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { print (finalcut::NF_button_up); } else { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) { print ('['); print (fc::BlackUpPointingTriangle); // ▲ @@ -1101,15 +1108,15 @@ void FDialog::drawTextBar() // Fill with spaces (left of the title) std::size_t center_offset{0}; std::size_t x{1}; - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); - if ( getMaxColor() < 16 ) + if ( FTerm::getMaxColor() < 16 ) setBold(); 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 - setColor (wc.titlebar_inactive_fg, wc.titlebar_inactive_bg); + setColor (wc->titlebar_inactive_fg, wc->titlebar_inactive_bg); const auto width = getWidth(); const auto zoom_btn = getZoomButtonWidth(); @@ -1138,7 +1145,7 @@ void FDialog::drawTextBar() for ( ; x + 1 + length < width - zoom_btn - 1; x++) print (' '); - if ( getMaxColor() < 16 ) + if ( FTerm::getMaxColor() < 16 ) unsetBold(); } @@ -1267,7 +1274,7 @@ inline std::size_t FDialog::getZoomButtonWidth() { if ( ! isResizeable() ) return 0; - else if ( isNewFont() ) + else if ( FTerm::isNewFont() ) return 2; else return 3; @@ -1358,9 +1365,9 @@ inline void FDialog::passEventToSubMenu ( const mouseStates& ms setClickedWidget(dialog_menu); 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; } } @@ -1632,12 +1639,12 @@ void FDialog::cb_move (const FWidget*, const FDataPtr) setMoveSizeWidget(this); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); drawBorder(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); save_geometry = getGeometry(); @@ -1646,15 +1653,15 @@ void FDialog::cb_move (const FWidget*, const FDataPtr) { 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; } if ( isResizeable() ) { - if ( isLinuxTerm() ) + if ( FTerm::isLinuxTerm() ) tooltip->setText ( " Arrow keys: Move\n" "Shift + Arrow keys: Resize\n" " Enter: Done\n" diff --git a/src/fdialoglistmenu.cpp b/src/fdialoglistmenu.cpp index 4c6cd4e0..3567b8ad 100644 --- a/src/fdialoglistmenu.cpp +++ b/src/fdialoglistmenu.cpp @@ -33,14 +33,14 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FDialogListMenu::FDialogListMenu(FWidget* parent) - : FMenu(parent) + : FMenu{parent} { init(); } //---------------------------------------------------------------------- FDialogListMenu::FDialogListMenu (const FString& txt, FWidget* parent) - : FMenu(txt, parent) + : FMenu{txt, parent} { init(); } diff --git a/src/fevent.cpp b/src/fevent.cpp index 8c85e612..964cf440 100644 --- a/src/fevent.cpp +++ b/src/fevent.cpp @@ -36,16 +36,24 @@ FEvent::FEvent (fc::events ev_type) // constructor { } //---------------------------------------------------------------------- -fc::events FEvent::type() const +fc::events FEvent::getType() const { return t; } +//---------------------------------------------------------------------- +bool FEvent::isQueued() const +{ return queued; } + +//---------------------------------------------------------------------- +bool FEvent::wasSent() const +{ return send; } + //---------------------------------------------------------------------- // class FKeyEvent //---------------------------------------------------------------------- FKeyEvent::FKeyEvent (fc::events ev_type, FKey key_num) // constructor - : FEvent(ev_type) + : FEvent{ev_type} , k{key_num} { } @@ -78,7 +86,7 @@ FMouseEvent::FMouseEvent ( fc::events ev_type // constructor , const FPoint& pos , const FPoint& termPos , int button ) - : FEvent(ev_type) + : FEvent{ev_type} , p{pos} , tp{termPos} , b{button} @@ -88,7 +96,7 @@ FMouseEvent::FMouseEvent ( fc::events ev_type // constructor FMouseEvent::FMouseEvent ( fc::events ev_type // constructor , const FPoint& pos , 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& termPos , int wheel ) - : FEvent(ev_type) + : FEvent{ev_type} , p{pos} , tp{termPos} , w{wheel} @@ -142,7 +150,7 @@ FWheelEvent::FWheelEvent ( fc::events ev_type // constructor FWheelEvent::FWheelEvent ( fc::events ev_type // constructor , const FPoint& pos , 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 - : FEvent(ev_type) + : FEvent{ev_type} { } //---------------------------------------------------------------------- @@ -193,13 +201,13 @@ FFocusEvent::~FFocusEvent() // destructor //---------------------------------------------------------------------- bool FFocusEvent::gotFocus() const { - return ( type() == fc::FocusIn_Event ); + return ( getType() == fc::FocusIn_Event ); } //---------------------------------------------------------------------- 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 - : FEvent(ev_type) + : FEvent{ev_type} , focus_widget{focused} { } @@ -258,7 +266,7 @@ void FAccelEvent::ignore() //---------------------------------------------------------------------- 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 - : FEvent(ev_type) + : FEvent{ev_type} { } //---------------------------------------------------------------------- @@ -296,7 +304,7 @@ FShowEvent::~FShowEvent() // destructor //---------------------------------------------------------------------- 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 - : FEvent(ev_type) + : FEvent{ev_type} { } //---------------------------------------------------------------------- @@ -334,7 +342,7 @@ void FCloseEvent::ignore() //---------------------------------------------------------------------- FTimerEvent::FTimerEvent (fc::events ev_type, int timer_id) // constructor - : FEvent(ev_type) + : FEvent{ev_type} , id{timer_id} { } @@ -352,7 +360,7 @@ int FTimerEvent::getTimerId() const //---------------------------------------------------------------------- FUserEvent::FUserEvent (fc::events ev_type, int user_event_id) // constructor - : FEvent(ev_type) + : FEvent{ev_type} , uid{user_event_id} { } diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 2363d853..7087e6ed 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -99,14 +99,14 @@ FSystem* FFileDialog::fsystem{nullptr}; // constructors and destructor //---------------------------------------------------------------------- FFileDialog::FFileDialog (FWidget* parent) - : FDialog(parent) + : FDialog{parent} { init(); } //---------------------------------------------------------------------- FFileDialog::FFileDialog (const FFileDialog& fdlg) - : FDialog(fdlg.getParentWidget()) + : FDialog{fdlg.getParentWidget()} { if ( fdlg.directory ) setPath(fdlg.directory); @@ -119,9 +119,9 @@ FFileDialog::FFileDialog ( const FString& dirname , const FString& filter , DialogType type , FWidget* parent ) - : FDialog(parent) - , filter_pattern(filter) - , dlg_type(type) + : FDialog{parent} + , filter_pattern{filter} + , dlg_type{type} { if ( ! dirname.isNull() ) setPath(dirname); diff --git a/src/flabel.cpp b/src/flabel.cpp index a527fb57..51d5881a 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -27,6 +27,7 @@ #include "final/fcolorpair.h" #include "final/fevent.h" #include "final/flabel.h" +#include "final/flog.h" #include "final/fstatusbar.h" namespace finalcut @@ -39,15 +40,15 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- FLabel::FLabel(FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init(); } //---------------------------------------------------------------------- FLabel::FLabel (const FString& txt, FWidget* parent) - : FWidget(parent) - , text(txt) + : FWidget{parent} + , text{txt} { init(); setText(txt); @@ -173,9 +174,9 @@ void FLabel::onMouseDown (FMouseEvent* ev) std::make_shared(fc::MouseDown_Event, p, tp, b); 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; } } @@ -245,20 +246,7 @@ void FLabel::cb_accelWidgetDestroyed (const FWidget*, const FDataPtr) //---------------------------------------------------------------------- void FLabel::init() { - const auto& parent_widget = getParentWidget(); 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() ) return; - if ( isMonochron() ) + useParentWidgetColor(); + + if ( FTerm::isMonochron() ) { setReverse(true); @@ -321,7 +311,7 @@ void FLabel::draw() else drawSingleLine(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) { setReverse(false); @@ -406,7 +396,7 @@ void FLabel::printLine (FString& line) for (std::size_t z{0}; z < to_char; z++) { if ( ! std::iswprint(std::wint_t(line[z])) - && ! isNewFont() + && ! FTerm::isNewFont() && ( line[z] < fc::NF_rev_left_arrow2 || line[z] > fc::NF_check_mark ) ) { @@ -415,8 +405,8 @@ void FLabel::printLine (FString& line) if ( z == hotkeypos && getFlags().active ) { - const auto& wc = getFWidgetColors(); - setColor (wc.label_hotkey_fg, wc.label_hotkey_bg); + const auto& wc = getColorTheme(); + setColor (wc->label_hotkey_fg, wc->label_hotkey_bg); if ( ! getFlags().no_underline ) setUnderline(); diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 6a4bf64a..47d05fc7 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -25,6 +25,7 @@ #include "final/fapplication.h" #include "final/fevent.h" #include "final/flabel.h" +#include "final/flog.h" #include "final/flineedit.h" #include "final/fpoint.h" #include "final/fsize.h" @@ -41,7 +42,7 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FLineEdit::FLineEdit (FWidget* parent) - : FWidget(parent) + : FWidget{parent} , label{new FLabel("", parent)} { init(); @@ -49,8 +50,8 @@ FLineEdit::FLineEdit (FWidget* parent) //---------------------------------------------------------------------- FLineEdit::FLineEdit (const FString& txt, FWidget* parent) - : FWidget(parent) - , text(txt) + : FWidget{parent} + , text{txt} , label{new FLabel("", parent)} { init(); @@ -61,7 +62,7 @@ FLineEdit::FLineEdit (const FString& txt, FWidget* parent) FLineEdit::~FLineEdit() // destructor { if ( ! insert_mode ) - setInsertCursor(); + FTerm::setInsertCursor(); } // FLineEdit operators @@ -98,28 +99,8 @@ const FLineEdit& FLineEdit::operator >> (FString& s) //---------------------------------------------------------------------- bool FLineEdit::setEnable (bool enable) { - const auto& wc = getFWidgetColors(); FWidget::setEnable(enable); - - 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); - } - + resetColors(); return enable; } @@ -127,23 +108,7 @@ bool FLineEdit::setEnable (bool enable) bool FLineEdit::setFocus (bool enable) { FWidget::setFocus(enable); - - 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); - } - } - + resetColors(); return enable; } @@ -151,8 +116,8 @@ bool FLineEdit::setFocus (bool enable) bool FLineEdit::setShadow (bool enable) { if ( enable - && getEncoding() != fc::VT100 - && getEncoding() != fc::ASCII ) + && FTerm::getEncoding() != fc::VT100 + && FTerm::getEncoding() != fc::ASCII ) { setFlags().shadow = true; setShadowSize(FSize{1, 1}); @@ -254,6 +219,34 @@ void FLineEdit::setLabelOrientation (const label_o o) 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) { @@ -575,7 +568,7 @@ void FLineEdit::onAccel (FAccelEvent* ev) void FLineEdit::onHide (FHideEvent*) { if ( ! insert_mode && ! isReadOnly() ) - setInsertCursor(); + FTerm::setInsertCursor(); } //---------------------------------------------------------------------- @@ -584,9 +577,9 @@ void FLineEdit::onFocusIn (FFocusEvent*) if ( ! isReadOnly() ) { if ( insert_mode ) - setInsertCursor(); + FTerm::setInsertCursor(); else - unsetInsertCursor(); + FTerm::unsetInsertCursor(); } if ( getStatusBar() ) @@ -607,7 +600,7 @@ void FLineEdit::onFocusOut (FFocusEvent*) } if ( ! insert_mode && ! isReadOnly() ) - setInsertCursor(); + FTerm::setInsertCursor(); } @@ -654,34 +647,14 @@ void FLineEdit::adjustSize() //---------------------------------------------------------------------- void FLineEdit::init() { - const auto& wc = getFWidgetColors(); label->setAccelWidget(this); + setShadow(); + resetColors(); if ( isReadOnly() ) unsetVisibleCursor(); else 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; print() << FPoint{1, 1}; - if ( isMonochron() ) + if ( FTerm::isMonochron() ) { setReverse(true); print (' '); @@ -739,7 +712,7 @@ void FLineEdit::drawInputField() print (' '); } - if ( isActiveFocus && getMaxColor() < 16 ) + if ( isActiveFocus && FTerm::getMaxColor() < 16 ) setBold(); const std::size_t text_offset_column = [this] () @@ -765,10 +738,10 @@ void FLineEdit::drawInputField() x_pos++; } - if ( isActiveFocus && getMaxColor() < 16 ) + if ( isActiveFocus && FTerm::getMaxColor() < 16 ) unsetBold(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) { setReverse(false); setUnderline(false); @@ -860,7 +833,8 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos) } 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 ) @@ -883,7 +857,8 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos) } 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) { - std::cerr << "Out of Range error: " << ex.what() << std::endl; + *FApplication::getLog() << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } idx++; @@ -951,7 +927,8 @@ void FLineEdit::adjustTextOffset() } 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) { - 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; if ( insert_mode ) - setInsertCursor(); // Insert mode + FTerm::setInsertCursor(); // Insert mode else - unsetInsertCursor(); // Overtype mode + FTerm::unsetInsertCursor(); // Overtype mode } //---------------------------------------------------------------------- @@ -1092,7 +1070,7 @@ inline bool FLineEdit::keyInput (FKey key) { if ( text.getLength() >= max_length ) { - beep(); + FTerm::beep(); return true; } diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 0fbf783f..8211a6a1 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -45,16 +45,16 @@ FListBoxItem::FListBoxItem() //---------------------------------------------------------------------- FListBoxItem::FListBoxItem (const FListBoxItem& item) - : text(item.text) - , data_pointer(item.data_pointer) - , brackets(item.brackets) - , selected(item.selected) + : text{item.text} + , data_pointer{item.data_pointer} + , brackets{item.brackets} + , selected{item.selected} { } //---------------------------------------------------------------------- FListBoxItem::FListBoxItem (const FString& txt, FDataPtr data) - : text(txt) - , data_pointer(data) + : text{txt} + , data_pointer{data} { } //---------------------------------------------------------------------- @@ -87,7 +87,7 @@ FListBoxItem& FListBoxItem::operator = (const FListBoxItem& item) // constructor and destructor //---------------------------------------------------------------------- FListBox::FListBox (FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init(); } @@ -274,8 +274,8 @@ void FListBox::clear() hbar->hide(); // clear list from screen - const auto& wc = getFWidgetColors(); - setColor (wc.list_fg, wc.list_bg); + const auto& wc = getColorTheme(); + setColor (wc->list_fg, wc->list_bg); const std::size_t size = getWidth() - 2; drawBorder(); drawHeadline(); @@ -655,10 +655,7 @@ void FListBox::init() initScrollbar (vbar, fc::vertical, this, &FListBox::cb_vbarChange); initScrollbar (hbar, fc::horizontal, this, &FListBox::cb_hbarChange); setGeometry (FPoint{1, 1}, FSize{5, 4}, false); // initialize geometry values - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.dialog_fg); - setBackgroundColor (wc.dialog_bg); - nf_offset = isNewFont() ? 1 : 0; + nf_offset = FTerm::isNewFont() ? 1 : 0; setTopPadding(1); setLeftPadding(1); setBottomPadding(1); @@ -722,14 +719,15 @@ void FListBox::draw() if ( current < 1 ) current = 1; - setColor(); + useParentWidgetColor(); - if ( isMonochron() ) + + if ( FTerm::isMonochron() ) setReverse(true); drawBorder(); - if ( isNewFont() && ! vbar->isShown() ) + if ( FTerm::isNewFont() && ! vbar->isShown() ) { setColor(); @@ -742,7 +740,7 @@ void FListBox::draw() drawHeadline(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); drawScrollbars(); @@ -792,12 +790,12 @@ void FListBox::drawHeadline() const FString txt{" " + text + " "}; const auto column_width = getColumnWidth(txt); print() << FPoint{2, 1}; - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); if ( isEnabled() ) - setColor(wc.label_emphasis_fg, wc.label_bg); + setColor(wc->label_emphasis_fg, wc->label_bg); else - setColor(wc.label_inactive_fg, wc.label_inactive_bg); + setColor(wc->label_inactive_fg, wc->label_inactive_bg); if ( column_width <= getClientWidth() ) print (txt); @@ -805,7 +803,7 @@ void FListBox::drawHeadline() { // Print ellipsis 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 ) { 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 std::size_t first = std::size_t(xoffset) + 1; const std::size_t max_width = getWidth() - nf_offset - 4; const FString element(getColumnSubString (getString(iter), first, max_width)); std::size_t column_width = getColumnWidth(element); - if ( isMonochron() && isCurrentLine && getFlags().focus ) + if ( FTerm::isMonochron() && isCurrentLine && getFlags().focus ) print (fc::BlackRightPointingPointer); // ► else print (' '); if ( serach_mark ) - setColor ( wc.current_inc_search_element_fg - , wc.current_element_focus_bg ); + setColor ( wc->current_inc_search_element_fg + , wc->current_element_focus_bg ); for (std::size_t i{0}; i < element.getLength(); i++) { if ( serach_mark && i == inc_len && getFlags().focus ) - setColor ( wc.current_element_focus_fg - , wc.current_element_focus_bg ); + setColor ( wc->current_element_focus_fg + , wc->current_element_focus_bg ); print (element[i]); } - if ( isMonochron() && isCurrentLine && getFlags().focus ) + if ( FTerm::isMonochron() && isCurrentLine && getFlags().focus ) { print (fc::BlackLeftPointingPointer); // ◄ column_width++; @@ -928,7 +926,7 @@ inline void FListBox::drawListBracketsLine ( int y const std::size_t inc_len = inc_search.getLength(); const bool isCurrentLine( y + yoffset + 1 == int(current) ); - if ( isMonochron() && isCurrentLine && getFlags().focus ) + if ( FTerm::isMonochron() && isCurrentLine && getFlags().focus ) print (fc::BlackRightPointingPointer); // ► else print (' '); @@ -945,17 +943,17 @@ inline void FListBox::drawListBracketsLine ( int y std::size_t column_width = getColumnWidth(element); const std::size_t text_width = getColumnWidth(getString(iter)); std::size_t i{0}; - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); for (; i < element.getLength(); i++) { if ( serach_mark && i == 0 ) - setColor ( wc.current_inc_search_element_fg - , wc.current_element_focus_bg ); + setColor ( wc->current_inc_search_element_fg + , wc->current_element_focus_bg ); if ( serach_mark && i == inc_len ) - setColor ( wc.current_element_focus_fg - , wc.current_element_focus_bg ); + setColor ( wc->current_element_focus_fg + , wc->current_element_focus_bg ); print (element[i]); } @@ -964,14 +962,14 @@ inline void FListBox::drawListBracketsLine ( int y && std::size_t(xoffset) <= text_width ) { if ( serach_mark && i == inc_len ) - setColor ( wc.current_element_focus_fg - , wc.current_element_focus_bg ); + setColor ( wc->current_element_focus_fg + , wc->current_element_focus_bg ); printRightBracket (iter->brackets); column_width++; } - if ( isMonochron() && isCurrentLine && getFlags().focus ) + if ( FTerm::isMonochron() && isCurrentLine && getFlags().focus ) { print (fc::BlackLeftPointingPointer); // ◄ column_width++; @@ -990,51 +988,51 @@ inline void FListBox::setLineAttributes ( int y const bool isCurrentLine( y + yoffset + 1 == int(current) ); const std::size_t inc_len = inc_search.getLength(); const std::size_t inc_width = getColumnWidth(inc_search); - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); print() << FPoint{2, 2 + int(y)}; if ( isLineSelected ) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setBold(); else - setColor (wc.selected_list_fg, wc.selected_list_bg); + setColor (wc->selected_list_fg, wc->selected_list_bg); } else { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) unsetBold(); else - setColor (wc.list_fg, wc.list_bg); + setColor (wc->list_fg, wc->list_bg); } if ( isCurrentLine ) { - if ( getFlags().focus && getMaxColor() < 16 ) + if ( getFlags().focus && FTerm::getMaxColor() < 16 ) setBold(); if ( isLineSelected ) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setBold(); else if ( getFlags().focus ) - setColor ( wc.selected_current_element_focus_fg - , wc.selected_current_element_focus_bg ); + setColor ( wc->selected_current_element_focus_fg + , wc->selected_current_element_focus_bg ); else - setColor ( wc.selected_current_element_fg - , wc.selected_current_element_bg ); + setColor ( wc->selected_current_element_fg + , wc->selected_current_element_bg ); setCursorPos ({3, 2 + int(y)}); // first character } else { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) unsetBold(); if ( getFlags().focus ) { - setColor ( wc.current_element_focus_fg - , wc.current_element_focus_bg ); + setColor ( wc->current_element_focus_fg + , wc->current_element_focus_bg ); const int b = ( lineHasBrackets ) ? 1: 0; if ( inc_len > 0 ) // incremental search @@ -1047,18 +1045,18 @@ inline void FListBox::setLineAttributes ( int y setCursorPos ({3 + b, 2 + int(y)}); // first character } else - setColor ( wc.current_element_fg - , wc.current_element_bg ); + setColor ( wc->current_element_fg + , wc->current_element_bg ); } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } else { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); - else if ( getFlags().focus && getMaxColor() < 16 ) + else if ( getFlags().focus && FTerm::getMaxColor() < 16 ) unsetBold(); } } @@ -1066,7 +1064,7 @@ inline void FListBox::setLineAttributes ( int y //---------------------------------------------------------------------- inline void FListBox::unsetAttributes() { - if ( isMonochron() ) // unset for the last element + if ( FTerm::isMonochron() ) // unset for the last element setReverse(false); unsetBold(); @@ -1719,7 +1717,7 @@ void FListBox::processChanged() //---------------------------------------------------------------------- void FListBox::changeOnResize() { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { vbar->setGeometry (FPoint{int(getWidth()), 2}, FSize{2, getHeight() - 2}); hbar->setGeometry (FPoint{1, int(getHeight())}, FSize{getWidth() - 2, 1}); diff --git a/src/flistview.cpp b/src/flistview.cpp index 9d769553..a4226a0c 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -170,9 +170,9 @@ bool sortDescendingByNumber (const FObject* lhs, const FObject* rhs) // constructor and destructor //---------------------------------------------------------------------- FListViewItem::FListViewItem (const FListViewItem& item) - : FObject(item.getParent()) - , column_list(item.column_list) - , data_pointer(item.data_pointer) + : FObject{item.getParent()} + , column_list{item.column_list} + , data_pointer{item.data_pointer} { auto parent = getParent(); @@ -191,7 +191,7 @@ FListViewItem::FListViewItem (const FListViewItem& item) //---------------------------------------------------------------------- FListViewItem::FListViewItem (iterator parent_iter) - : FObject((*parent_iter)->getParent()) + : FObject{(*parent_iter)->getParent()} { insert (this, parent_iter); } @@ -200,9 +200,9 @@ FListViewItem::FListViewItem (iterator parent_iter) FListViewItem::FListViewItem ( const FStringList& cols , FDataPtr data , iterator parent_iter ) - : FObject(nullptr) - , column_list(cols) - , data_pointer(data) + : FObject{nullptr} + , column_list{cols} + , data_pointer{data} { if ( cols.empty() ) return; @@ -496,7 +496,7 @@ FListViewIterator::FListViewIterator() //---------------------------------------------------------------------- FListViewIterator::FListViewIterator (iterator iter) - : node(iter) + : node{iter} { } //---------------------------------------------------------------------- @@ -505,16 +505,16 @@ FListViewIterator::~FListViewIterator() // destructor //---------------------------------------------------------------------- FListViewIterator::FListViewIterator (const FListViewIterator& i) - : iter_path(i.iter_path) // copy constructor - , node(i.node) - , position(i.position) + : iter_path{i.iter_path} // copy constructor + , node{i.node} + , position{i.position} { } //---------------------------------------------------------------------- FListViewIterator::FListViewIterator (FListViewIterator&& i) noexcept - : iter_path(std::move(i.iter_path)) // move constructor - , node(std::move(i.node)) - , position(std::move(i.position)) + : iter_path{std::move(i.iter_path)} // move constructor + , node{std::move(i.node)} + , position{std::move(i.position)} { } // FListViewIterator operators @@ -683,7 +683,7 @@ void FListViewIterator::parentElement() // constructor and destructor //---------------------------------------------------------------------- FListView::FListView (FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init(); } @@ -910,9 +910,9 @@ FObject::iterator FListView::insert ( const FStringList& cols { 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(); } @@ -1523,10 +1523,7 @@ void FListView::init() root = selflist.begin(); getNullIterator() = selflist.end(); setGeometry (FPoint{1, 1}, FSize{5, 4}, false); // initialize geometry values - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.dialog_fg); - setBackgroundColor (wc.dialog_bg); - nf_offset = isNewFont() ? 1 : 0; + nf_offset = FTerm::isNewFont() ? 1 : 0; setTopPadding(1); setLeftPadding(1); setBottomPadding(1); @@ -1637,14 +1634,14 @@ void FListView::draw() if ( current_iter.getPosition() < 1 ) current_iter = itemlist.begin(); - setColor(); + useParentWidgetColor(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); drawBorder(); - if ( isNewFont() && ! vbar->isShown() ) + if ( FTerm::isNewFont() && ! vbar->isShown() ) { setColor(); @@ -1657,7 +1654,7 @@ void FListView::draw() drawHeadlines(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); drawScrollbars(); @@ -1773,7 +1770,7 @@ void FListView::drawList() // Reset color setColor(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); // Clean empty space after last element @@ -1876,8 +1873,8 @@ void FListView::clearList() { // Clear list from terminal screen - const auto& wc = getFWidgetColors(); - setColor (wc.list_fg, wc.list_bg); + const auto& wc = getColorTheme(); + setColor (wc->list_fg, wc->list_bg); const std::size_t size = getWidth() - 2; drawBorder(); drawHeadlines(); @@ -1897,34 +1894,34 @@ void FListView::clearList() inline void FListView::setLineAttributes ( bool is_current , bool is_focus ) { - const auto& wc = getFWidgetColors(); - setColor (wc.list_fg, wc.list_bg); + const auto& wc = getColorTheme(); + setColor (wc->list_fg, wc->list_bg); if ( is_current ) { - if ( is_focus && getMaxColor() < 16 ) + if ( is_focus && FTerm::getMaxColor() < 16 ) setBold(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) unsetBold(); if ( is_focus ) { - setColor ( wc.current_element_focus_fg - , wc.current_element_focus_bg ); + setColor ( wc->current_element_focus_fg + , wc->current_element_focus_bg ); } else - setColor ( wc.current_element_fg - , wc.current_element_bg ); + setColor ( wc->current_element_fg + , wc->current_element_bg ); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } else { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); - else if ( is_focus && getMaxColor() < 16 ) + else if ( is_focus && FTerm::getMaxColor() < 16 ) unsetBold(); } } @@ -1934,7 +1931,7 @@ inline FString FListView::getCheckBox (const FListViewItem* item) { FString checkbox{""}; - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { checkbox = ( item->isChecked() ) ? CHECKBOX_ON : CHECKBOX; checkbox += L' '; @@ -2039,12 +2036,12 @@ void FListView::drawHeadlineLabel (const headerItems::const_iterator& iter) const headerItems::const_iterator first = header.begin(); const int column = int(std::distance(first, iter)) + 1; const bool has_sort_indicator( sort_column == column && ! hide_sort_indicator ); - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); if ( isEnabled() ) - setColor (wc.label_emphasis_fg, wc.label_bg); + setColor (wc->label_emphasis_fg, wc->label_bg); 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 ) { @@ -2169,11 +2166,11 @@ void FListView::drawColumnEllipsis ( const headerItems::const_iterator& iter // Print label ellipsis static constexpr int ellipsis_length = 2; const int width = iter->width; - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); headerline << ' ' << 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 @@ -2516,7 +2513,7 @@ void FListView::processChanged() //---------------------------------------------------------------------- void FListView::changeOnResize() { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { vbar->setGeometry (FPoint{int(getWidth()), 2}, FSize{2, getHeight() - 2}); hbar->setGeometry (FPoint{1, int(getHeight())}, FSize{getWidth() - 2, 1}); diff --git a/src/flog.cpp b/src/flog.cpp new file mode 100644 index 00000000..2a527412 --- /dev/null +++ b/src/flog.cpp @@ -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 * +* . * +***********************************************************************/ + +#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 + diff --git a/src/flogger.cpp b/src/flogger.cpp new file mode 100644 index 00000000..68720d68 --- /dev/null +++ b/src/flogger.cpp @@ -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 * +* . * +***********************************************************************/ + +#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 + + diff --git a/src/fmenu.cpp b/src/fmenu.cpp index c6b24c01..060bc3d1 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -28,6 +28,7 @@ #include "final/fcolorpair.h" #include "final/fdialog.h" #include "final/fevent.h" +#include "final/flog.h" #include "final/fmenu.h" #include "final/fmenubar.h" #include "final/fmenuitem.h" @@ -44,15 +45,15 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FMenu::FMenu(FWidget* parent) - : FWindow(parent) + : FWindow{parent} { init(parent); } //---------------------------------------------------------------------- FMenu::FMenu (const FString& txt, FWidget* parent) - : FWindow(parent) - , menuitem(txt, parent) + : FWindow{parent} + , menuitem{txt, parent} { init(parent); } @@ -82,6 +83,15 @@ void FMenu::setStatusbarMessage (const FString& 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() { @@ -457,10 +467,7 @@ void FMenu::init(FWidget* parent) setTransparentShadow(); setMenuWidget(); hide(); - - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.menu_active_fg); - setBackgroundColor (wc.menu_active_bg); + resetColors(); menuitem.setMenu(this); if ( parent ) @@ -517,7 +524,7 @@ void FMenu::calculateDimensions() } 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; } @@ -941,9 +948,9 @@ void FMenu::passEventToSubMenu (FMouseEvent* const& ev) setClickedWidget(opened_sub_menu); 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); 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.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() { // Fill the background - const auto& wc = getFWidgetColors(); - setColor (wc.menu_active_fg, wc.menu_active_bg); + const auto& wc = getColorTheme(); + setColor (wc->menu_active_fg, wc->menu_active_bg); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); clearArea(); @@ -1219,7 +1226,7 @@ void FMenu::draw() drawItems(); drawShadow(this); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } @@ -1242,14 +1249,14 @@ void FMenu::drawItems() //---------------------------------------------------------------------- inline void FMenu::drawSeparator (int y) { - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); 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); - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { print (fc::NF_border_line_vertical_right); FString line { std::size_t(getWidth()) - 2 @@ -1266,7 +1273,7 @@ inline void FMenu::drawSeparator (int y) print (fc::BoxDrawingsVerticalAndLeft); } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } @@ -1313,7 +1320,7 @@ inline void FMenu::drawMenuLine (FMenuItem* m_item, int y) if ( is_selected ) drawTrailingSpaces (column_width); - if ( isMonochron() && is_enabled && is_selected ) + if ( FTerm::isMonochron() && is_enabled && is_selected ) setReverse(true); } @@ -1333,14 +1340,14 @@ inline void FMenu::drawCheckMarkPrefix (const FMenuItem* m_item) { if ( is_radio_btn ) { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) print (fc::NF_Bullet); // NF_Bullet ● else print (fc::BlackCircle); // BlackCircle ● } else { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) print (fc::NF_check_mark); // NF_check_mark ✓ else print (fc::SquareRoot); // SquareRoot √ @@ -1348,10 +1355,10 @@ inline void FMenu::drawCheckMarkPrefix (const FMenuItem* m_item) } else { - const auto& wc = getFWidgetColors(); - setColor (wc.menu_inactive_fg, getBackgroundColor()); + const auto& wc = getColorTheme(); + setColor (wc->menu_inactive_fg, getBackgroundColor()); - if ( getEncoding() == fc::ASCII ) + if ( FTerm::getEncoding() == fc::ASCII ) print ('-'); else print (fc::SmallBullet); // · @@ -1371,18 +1378,18 @@ inline void FMenu::drawMenuText (menuText& data) for (std::size_t z{0}; z < data.text.getLength(); 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_check_mark ) - && ! charEncodable(wchar_t(data.text[z])) ) + && ! FTerm::charEncodable(wchar_t(data.text[z])) ) { data.text[z] = L' '; } if ( z == data.hotkeypos ) { - const auto& wc = getFWidgetColors(); - setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg); + const auto& wc = getColorTheme(); + setColor (wc->menu_hotkey_fg, wc->menu_hotkey_bg); if ( ! data.no_underline ) setUnderline(); @@ -1418,7 +1425,7 @@ inline void FMenu::drawSubMenuIndicator (std::size_t& startpos) //---------------------------------------------------------------------- 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 accel_len = accel_name.getLength(); 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_selected = m_item->isSelected(); - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); if ( is_enabled ) { if ( is_selected ) { - setForegroundColor (wc.menu_active_focus_fg); - setBackgroundColor (wc.menu_active_focus_bg); + setForegroundColor (wc->menu_active_focus_fg); + setBackgroundColor (wc->menu_active_focus_bg); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } else { - setForegroundColor (wc.menu_active_fg); - setBackgroundColor (wc.menu_active_bg); + setForegroundColor (wc->menu_active_fg); + setBackgroundColor (wc->menu_active_bg); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); } } else { - setForegroundColor (wc.menu_inactive_fg); - setBackgroundColor (wc.menu_inactive_bg); + setForegroundColor (wc->menu_inactive_fg); + setBackgroundColor (wc->menu_inactive_bg); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); } diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 02fa0ce4..5923248a 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -25,6 +25,7 @@ #include "final/fapplication.h" #include "final/fevent.h" +#include "final/flog.h" #include "final/fmenu.h" #include "final/fmenubar.h" #include "final/fmenuitem.h" @@ -41,7 +42,7 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FMenuBar::FMenuBar(FWidget* parent) - : FWindow(parent) + : FWindow{parent} { init(); } @@ -54,6 +55,15 @@ FMenuBar::~FMenuBar() // destructor // 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() { @@ -64,9 +74,9 @@ void FMenuBar::resetMenu() //---------------------------------------------------------------------- void FMenuBar::hide() { - const auto& wc = getFWidgetColors(); - FColor fg = wc.term_fg; - FColor bg = wc.term_bg; + const auto& wc = getColorTheme(); + FColor fg = wc->term_fg; + FColor bg = wc->term_bg; setColor (fg, bg); print() << FPoint{1, 1} << FString{getDesktopWidth(), L' '}; updateTerminal(); @@ -248,9 +258,7 @@ void FMenuBar::init() addAccelerator (fc::Fkey_f10); addAccelerator (fc::Fckey_space); - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.menu_active_fg); - setBackgroundColor (wc.menu_active_bg); + resetColors(); unsetFocusable(); } @@ -477,7 +485,7 @@ void FMenuBar::drawItems() print() << FPoint{1, 1}; - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); std::size_t x{1}; @@ -489,7 +497,7 @@ void FMenuBar::drawItems() for (; x <= getDesktopWidth(); x++) print (' '); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } @@ -528,10 +536,10 @@ inline void FMenuBar::drawItem (FMenuItem* menuitem, std::size_t& x) drawEllipsis (txtdata, x); drawTrailingSpace (x); - const auto& wc = getFWidgetColors(); - setColor (wc.menu_active_fg, wc.menu_active_bg); + const auto& wc = getColorTheme(); + setColor (wc->menu_active_fg, wc->menu_active_bg); - if ( isMonochron() && is_enabled && is_selected ) + if ( FTerm::isMonochron() && is_enabled && is_selected ) setReverse(true); } @@ -540,28 +548,28 @@ inline void FMenuBar::setLineAttributes (const FMenuItem* menuitem) { bool is_enabled = menuitem->isEnabled(); bool is_selected = menuitem->isSelected(); - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); if ( is_enabled ) { if ( is_selected ) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); - setForegroundColor (wc.menu_active_focus_fg); - setBackgroundColor (wc.menu_active_focus_bg); + setForegroundColor (wc->menu_active_focus_fg); + setBackgroundColor (wc->menu_active_focus_bg); } else { - setForegroundColor (wc.menu_active_fg); - setBackgroundColor (wc.menu_active_bg); + setForegroundColor (wc->menu_active_fg); + setBackgroundColor (wc->menu_active_bg); } } else { - setForegroundColor (wc.menu_inactive_fg); - setBackgroundColor (wc.menu_inactive_bg); + setForegroundColor (wc->menu_inactive_fg); + setBackgroundColor (wc->menu_inactive_bg); } setColor(); @@ -597,7 +605,7 @@ inline void FMenuBar::drawMenuText (menuText& data) break; 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_check_mark ) ) { @@ -606,8 +614,8 @@ inline void FMenuBar::drawMenuText (menuText& data) if ( z == data.hotkeypos ) { - const auto& wc = getFWidgetColors(); - setColor (wc.menu_hotkey_fg, wc.menu_hotkey_bg); + const auto& wc = getColorTheme(); + setColor (wc->menu_hotkey_fg, wc->menu_hotkey_bg); if ( ! data.no_underline ) setUnderline(); @@ -944,9 +952,9 @@ void FMenuBar::passEventToMenu (const FMouseEvent* const& ev) setClickedWidget(menu); 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"); } } } diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index fbd174b5..2bbc12db 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -25,6 +25,7 @@ #include "final/fapplication.h" #include "final/fdialog.h" #include "final/fevent.h" +#include "final/flog.h" #include "final/fmenu.h" #include "final/fmenubar.h" #include "final/fmenulist.h" @@ -41,24 +42,24 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FMenuItem::FMenuItem (FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init (parent); } //---------------------------------------------------------------------- FMenuItem::FMenuItem (const FString& txt, FWidget* parent) - : FWidget(parent) - , text(txt) + : FWidget{parent} + , text{txt} { init (parent); } //---------------------------------------------------------------------- FMenuItem::FMenuItem (FKey k, const FString& txt, FWidget* parent) - : FWidget(parent) - , text(txt) - , accel_key(k) + : FWidget{parent} + , text{txt} + , accel_key{k} { init (parent); } @@ -614,9 +615,9 @@ void FMenuItem::createDialogList (FMenu* winmenu) // create a new dialog list item 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; } @@ -663,9 +664,9 @@ void FMenuItem::passMouseEvent ( T widget, const FMouseEvent* ev { _ev = std::make_shared(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; } diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index 58174342..d47b1e4d 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -24,6 +24,7 @@ #include "final/fapplication.h" #include "final/fbutton.h" +#include "final/flog.h" #include "final/fmessagebox.h" namespace finalcut @@ -49,7 +50,7 @@ static const char* const button_text[] = // constructors and destructor //---------------------------------------------------------------------- FMessageBox::FMessageBox (FWidget* parent) - : FDialog(parent) + : FDialog{parent} { setTitlebarText("Message for you"); init(FMessageBox::Ok, 0, 0); @@ -57,15 +58,15 @@ FMessageBox::FMessageBox (FWidget* parent) //---------------------------------------------------------------------- FMessageBox::FMessageBox (const FMessageBox& mbox) - : FDialog(mbox.getParentWidget()) - , headline_text(mbox.headline_text) - , text(mbox.text) - , text_components(mbox.text_components) - , max_line_width(mbox.max_line_width) - , emphasis_color(mbox.emphasis_color) - , num_buttons(mbox.num_buttons) - , text_num_lines(mbox.text_num_lines) - , center_text(mbox.center_text) + : FDialog{mbox.getParentWidget()} + , headline_text{mbox.headline_text} + , text{mbox.text} + , text_components{mbox.text_components} + , max_line_width{mbox.max_line_width} + , emphasis_color{mbox.emphasis_color} + , num_buttons{mbox.num_buttons} + , text_num_lines{mbox.text_num_lines} + , center_text{mbox.center_text} { setTitlebarText (mbox.getTitlebarText()); init ( mbox.button_digit[0] @@ -80,8 +81,8 @@ FMessageBox::FMessageBox ( const FString& caption , int button1 , int button2 , FWidget* parent ) - : FDialog(parent) - , text(message) + : FDialog{parent} + , text{message} { setTitlebarText(caption); init(button0, button1, button2); @@ -256,9 +257,9 @@ inline void FMessageBox::allocation (int button0, int button1, int button2) 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; } } @@ -347,7 +348,7 @@ void FMessageBox::draw() // center the whole block const int msg_x = int((getWidth() - max_line_width) / 2); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); if ( ! headline_text.isEmpty() ) @@ -376,7 +377,7 @@ void FMessageBox::draw() y++; } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 767ac819..3cd8f6f2 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -308,7 +308,7 @@ bool FMouse::isDblclickTimeout (const timeval* time) // constructors and destructor //---------------------------------------------------------------------- FMouseGPM::FMouseGPM() - : FMouse() + : FMouse{} { gpm_ev.x = -1; } diff --git a/src/fobject.cpp b/src/fobject.cpp index 64eeec48..77fdf11a 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -43,7 +43,7 @@ const FString* fc::emptyFString::empty_string{nullptr}; // constructors and destructor //---------------------------------------------------------------------- FObject::FObject (FObject* parent) - : parent_obj(parent) + : parent_obj{parent} { if ( parent ) // add object to parent { @@ -60,9 +60,9 @@ FObject::FObject (FObject* parent) { 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; } } @@ -191,19 +191,18 @@ bool FObject::event (FEvent* ev) { // Receives events on this object - if ( ev->type() == fc::Timer_Event ) + if ( ev->getType() == fc::Timer_Event ) { onTimer ( static_cast(ev) ); - return true; } - - if ( ev->type() == fc::User_Event ) + else if ( ev->getType() == fc::User_Event ) { onUserEvent ( static_cast(ev) ); - return true; } + else + return false; - return false; + return true; } //---------------------------------------------------------------------- diff --git a/src/foptimove.cpp b/src/foptimove.cpp index f3ee03be..dcafbcf0 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -22,7 +22,9 @@ #include +#include "final/fapplication.h" #include "final/fc.h" +#include "final/flog.h" #include "final/foptimove.h" #include "final/ftermcap.h" @@ -36,7 +38,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- FOptiMove::FOptiMove (int baud) - : baudrate(baud) + : baudrate{baud} { assert ( baud >= 0 ); @@ -1105,42 +1107,43 @@ void FOptiMove::moveByMethod ( int method //---------------------------------------------------------------------- void printDurations (const FOptiMove& om) { - std::cout << " speed: " - << om.baudrate << " baud\r\n"; - std::cout << " char_duration: " - << om.char_duration << " ms\r\n"; - std::cout << " cursor_home: " - << om.F_cursor_home.duration << " ms\r\n"; - std::cout << " cursor_to_ll: " - << om.F_cursor_to_ll.duration << " ms\r\n"; - std::cout << " carriage_return: " - << om.F_carriage_return.duration << " ms\r\n"; - std::cout << " tab: " - << om.F_tab.duration << " ms\r\n"; - std::cout << " back_tab: " - << om.F_back_tab.duration << " ms\r\n"; - std::cout << " cursor_up: " - << om.F_cursor_up.duration << " ms\r\n"; - std::cout << " cursor_down: " - << om.F_cursor_down.duration << " ms\r\n"; - std::cout << " cursor_left: " - << om.F_cursor_left.duration << " ms\r\n"; - std::cout << " cursor_right: " - << om.F_cursor_right.duration << " ms\r\n"; - std::cout << " cursor_address: " - << om.F_cursor_address.duration << " ms\r\n"; - std::cout << " column_address: " - << om.F_column_address.duration << " ms\r\n"; - std::cout << " row_address: " - << om.F_row_address.duration << " ms\r\n"; - std::cout << " parm_up_cursor: " - << om.F_parm_up_cursor.duration << " ms\r\n"; - std::cout << " parm_down_cursor: " - << om.F_parm_down_cursor.duration << " ms\r\n"; - std::cout << " parm_left_cursor: " - << om.F_parm_left_cursor.duration << " ms\r\n"; - std::cout << "parm_right_cursor: " - << om.F_parm_right_cursor.duration << " ms\r\n"; + finalcut::FLog& log = *FApplication::getLog(); + log << " speed: " + << om.baudrate << " baud" << std::flush; + log << " char_duration: " + << om.char_duration << " ms" << std::flush; + log << " cursor_home: " + << om.F_cursor_home.duration << " ms" << std::flush; + log << " cursor_to_ll: " + << om.F_cursor_to_ll.duration << " ms" << std::flush; + log << " carriage_return: " + << om.F_carriage_return.duration << " ms" << std::flush; + log << " tab: " + << om.F_tab.duration << " ms" << std::flush; + log << " back_tab: " + << om.F_back_tab.duration << " ms" << std::flush; + log << " cursor_up: " + << om.F_cursor_up.duration << " ms" << std::flush; + log << " cursor_down: " + << om.F_cursor_down.duration << " ms" << std::flush; + log << " cursor_left: " + << om.F_cursor_left.duration << " ms" << std::flush; + log << " cursor_right: " + << om.F_cursor_right.duration << " ms" << std::flush; + log << " cursor_address: " + << om.F_cursor_address.duration << " ms" << std::flush; + log << " column_address: " + << om.F_column_address.duration << " ms" << std::flush; + log << " row_address: " + << om.F_row_address.duration << " ms" << std::flush; + log << " parm_up_cursor: " + << om.F_parm_up_cursor.duration << " ms" << std::flush; + log << " parm_down_cursor: " + << om.F_parm_down_cursor.duration << " ms" << std::flush; + log << " parm_left_cursor: " + << om.F_parm_left_cursor.duration << " ms" << std::flush; + log << "parm_right_cursor: " + << om.F_parm_right_cursor.duration << " ms" << std::flush; } } // namespace finalcut diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 89e42df9..b006546a 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -36,7 +36,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- FProgressbar::FProgressbar(FWidget* parent) - : FWidget(parent) + : FWidget{parent} { unsetFocusable(); setShadow(); @@ -92,8 +92,8 @@ void FProgressbar::setGeometry ( const FPoint& pos, const FSize& size bool FProgressbar::setShadow (bool enable) { if ( enable - && getEncoding() != fc::VT100 - && getEncoding() != fc::ASCII ) + && FTerm::getEncoding() != fc::VT100 + && FTerm::getEncoding() != fc::ASCII ) { setFlags().shadow = true; setShadowSize(FSize{1, 1}); @@ -148,20 +148,10 @@ void FProgressbar::draw() //---------------------------------------------------------------------- void FProgressbar::drawProgressLabel() { - const auto& parent_widget = getParentWidget(); - - if ( parent_widget ) - setColor ( parent_widget->getForegroundColor() - , parent_widget->getBackgroundColor() ); - else - { - const auto& wc = getFWidgetColors(); - setColor (wc.dialog_fg, wc.dialog_bg); - } - - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); + useParentWidgetColor(); print() << FPoint{int(getWidth()) - 3, 0}; if ( percentage > 100 ) @@ -169,7 +159,7 @@ void FProgressbar::drawProgressLabel() else printf ("%3zu %%", percentage); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } @@ -184,7 +174,7 @@ void FProgressbar::drawProgressBar() drawProgressBackground(len); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); updateTerminal(); @@ -196,31 +186,31 @@ std::size_t FProgressbar::drawProgressIndicator() { // Draw the progress indicator - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); const double length = double(bar_length * percentage) / 100; 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}; // █ if ( len >= bar_length ) return len; - if ( round(length) > len || getMaxColor() < 16 ) + if ( round(length) > len || FTerm::getMaxColor() < 16 ) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); print(' '); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); } else { - print() << FColorPair{wc.progressbar_fg, wc.progressbar_bg} + print() << FColorPair{wc->progressbar_fg, wc->progressbar_bg} << fc::LeftHalfBlock; // ▌ } @@ -234,10 +224,10 @@ void FProgressbar::drawProgressBackground (std::size_t len) // Draw the progress background const std::size_t bg_len = bar_length - len; - const auto& wc = getFWidgetColors(); - setColor (wc.progressbar_fg, wc.progressbar_bg); + const auto& wc = getColorTheme(); + setColor (wc->progressbar_fg, wc->progressbar_bg); - if ( getMaxColor() < 16 ) + if ( FTerm::getMaxColor() < 16 ) print() << FString {bg_len, fc::MediumShade}; // ▒ else print() << FString {bg_len, L' '}; diff --git a/src/fradiobutton.cpp b/src/fradiobutton.cpp index 45d17657..08707354 100644 --- a/src/fradiobutton.cpp +++ b/src/fradiobutton.cpp @@ -33,14 +33,14 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FRadioButton::FRadioButton(FWidget* parent) - : FToggleButton(parent) + : FToggleButton{parent} { init(); } //---------------------------------------------------------------------- FRadioButton::FRadioButton (const FString& txt, FWidget* parent) - : FToggleButton(txt, parent) + : FToggleButton{txt, parent} { init(); } @@ -74,9 +74,9 @@ void FRadioButton::draw() void FRadioButton::drawRadioButton() { print() << FPoint{1, 1}; - setColor(); + useParentWidgetColor(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) { if ( hasFocus() ) setReverse(false); @@ -89,14 +89,14 @@ void FRadioButton::drawRadioButton() else drawUnchecked(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } //---------------------------------------------------------------------- inline void FRadioButton::drawChecked() { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) print (CHECKED_RADIO_BUTTON); else { @@ -109,7 +109,7 @@ inline void FRadioButton::drawChecked() //---------------------------------------------------------------------- inline void FRadioButton::drawUnchecked() { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) print (RADIO_BUTTON); else { diff --git a/src/fradiomenuitem.cpp b/src/fradiomenuitem.cpp index f34667dc..b3be0246 100644 --- a/src/fradiomenuitem.cpp +++ b/src/fradiomenuitem.cpp @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -34,14 +34,14 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FRadioMenuItem::FRadioMenuItem (FWidget* parent) - : FMenuItem(parent) + : FMenuItem{parent} { init (parent); } //---------------------------------------------------------------------- FRadioMenuItem::FRadioMenuItem (const FString& txt, FWidget* parent) - : FMenuItem(txt, parent) + : FMenuItem{txt, parent} { init (parent); } diff --git a/src/frect.cpp b/src/frect.cpp index 9376703f..2d88eb6e 100644 --- a/src/frect.cpp +++ b/src/frect.cpp @@ -36,18 +36,18 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FRect::FRect (const FPoint& p, const FSize& s) - : X1(p.getX()) - , Y1(p.getY()) - , X2(p.getX() + int(s.getWidth()) - 1) - , Y2(p.getY() + int(s.getHeight()) - 1) + : X1{p.getX()} + , Y1{p.getY()} + , X2{p.getX() + int(s.getWidth()) - 1} + , Y2{p.getY() + int(s.getHeight()) - 1} { } //---------------------------------------------------------------------- FRect::FRect (const FPoint& p1, const FPoint& p2) - : X1(p1.getX()) - , Y1(p1.getY()) - , X2(p2.getX()) - , Y2(p2.getY()) + : X1{p1.getX()} + , Y1{p1.getY()} + , X2{p2.getX()} + , Y2{p2.getY()} { } //---------------------------------------------------------------------- diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index e51dfaaf..c8e6c7e8 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -37,7 +37,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- FScrollbar::FScrollbar(FWidget* parent) - : FWidget(parent) + : FWidget{parent} { // The default scrollbar orientation is vertical setGeometry(FPoint{1, 1}, FSize{1, length}, false); @@ -46,7 +46,7 @@ FScrollbar::FScrollbar(FWidget* parent) //---------------------------------------------------------------------- FScrollbar::FScrollbar(fc::orientation o, FWidget* parent) - : FWidget(parent) + : FWidget{parent} { setOrientation (o); init(); @@ -184,7 +184,7 @@ void FScrollbar::redraw() //---------------------------------------------------------------------- void FScrollbar::calculateSliderValues() { - if ( isNewFont() && bar_orientation == fc::horizontal ) + if ( FTerm::isNewFont() && bar_orientation == fc::horizontal ) bar_length = ( length > 2 ) ? length - 4 : 1; else bar_length = ( length > 2 ) ? length - 2 : 1; @@ -276,7 +276,7 @@ void FScrollbar::onMouseDown (FMouseEvent* ev) slider_click_stop_pos = mouse_y - 2; else { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) slider_click_stop_pos = mouse_x - 3; else slider_click_stop_pos = mouse_x - 2; @@ -459,8 +459,8 @@ void FScrollbar::draw() //---------------------------------------------------------------------- void FScrollbar::drawVerticalBar() { - const auto& wc = getFWidgetColors(); - setColor (wc.scrollbar_fg, wc.scrollbar_bg); + const auto& wc = getColorTheme(); + setColor (wc->scrollbar_fg, wc->scrollbar_bg); for (int z{1}; z <= slider_pos; z++) { @@ -468,25 +468,25 @@ void FScrollbar::drawVerticalBar() drawVerticalBackgroundLine(); } - setColor (wc.scrollbar_bg, wc.scrollbar_fg); + setColor (wc->scrollbar_bg, wc->scrollbar_fg); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); for (int z{1}; z <= int(slider_length); z++) // Draw slider { print() << FPoint{1, 1 + slider_pos + z}; - if ( isNewFont() ) + if ( FTerm::isNewFont() ) print (' '); print (' '); } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) 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++) { @@ -494,25 +494,25 @@ void FScrollbar::drawVerticalBar() drawVerticalBackgroundLine(); } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } //---------------------------------------------------------------------- inline void FScrollbar::drawVerticalBackgroundLine() { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { - if ( isMonochron() || max_color < 16 ) + if ( FTerm::isMonochron() || max_color < 16 ) print (fc::MediumShade); // ▒ else print (fc::NF_border_line_left); // ⎸ } - if ( isMonochron() || max_color < 16 ) + if ( FTerm::isMonochron() || max_color < 16 ) print (fc::MediumShade); // ▒ - else if ( isNewFont() ) - print (fc::NF_rev_border_line_right); // ⎹ + else if ( FTerm::isNewFont() ) + print (fc::NF_rev_border_line_right); //⎹ else print (' '); } @@ -520,10 +520,10 @@ inline void FScrollbar::drawVerticalBackgroundLine() //---------------------------------------------------------------------- void FScrollbar::drawHorizontalBar() { - const auto& wc = getFWidgetColors(); - setColor (wc.scrollbar_fg, wc.scrollbar_bg); + const auto& wc = getColorTheme(); + setColor (wc->scrollbar_fg, wc->scrollbar_bg); - if ( isNewFont() ) + if ( FTerm::isNewFont() ) print() << FPoint{3, 1}; else print() << FPoint{2, 1}; @@ -531,33 +531,33 @@ void FScrollbar::drawHorizontalBar() for (int z{0}; z < slider_pos; z++) drawHorizontalBackgroundColumn(); - setColor (wc.scrollbar_bg, wc.scrollbar_fg); + setColor (wc->scrollbar_bg, wc->scrollbar_fg); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); for (int z{0}; z < int(slider_length); z++) // Draw slider print (' '); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); - setColor (wc.scrollbar_fg, wc.scrollbar_bg); + setColor (wc->scrollbar_fg, wc->scrollbar_bg); int z = slider_pos + int(slider_length) + 1; for (; z <= int(bar_length); z++) drawHorizontalBackgroundColumn(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } //---------------------------------------------------------------------- inline void FScrollbar::drawHorizontalBackgroundColumn() { - if ( isNewFont() && max_color > 8 ) + if ( FTerm::isNewFont() && max_color > 8 ) print (fc::NF_border_line_up_and_down); // ニ - else if ( isMonochron() || max_color < 16 ) + else if ( FTerm::isMonochron() || max_color < 16 ) print (fc::MediumShade); // ▒ else print (' '); @@ -566,10 +566,10 @@ inline void FScrollbar::drawHorizontalBackgroundColumn() //---------------------------------------------------------------------- void FScrollbar::drawButtons() { - const auto& wc = getFWidgetColors(); - setColor (wc.scrollbar_button_fg, wc.scrollbar_button_bg); + const auto& wc = getColorTheme(); + setColor (wc->scrollbar_button_fg, wc->scrollbar_button_bg); - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { print() << FPoint{1, 1}; @@ -590,7 +590,7 @@ void FScrollbar::drawButtons() { print() << FPoint{1, 1}; - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); if ( bar_orientation == fc::vertical ) @@ -606,7 +606,7 @@ void FScrollbar::drawButtons() << fc::BlackRightPointingPointer; // ► } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } } @@ -650,7 +650,7 @@ FScrollbar::sType FScrollbar::getVerticalClickedScrollType (int y) //---------------------------------------------------------------------- FScrollbar::sType FScrollbar::getHorizontalClickedScrollType (int x) { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { if ( x == 1 || x == 2 ) { @@ -707,7 +707,7 @@ int FScrollbar::getSliderClickPos (int mouse_x, int mouse_y) } else // horizontal bar orientation { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { if ( mouse_x > slider_pos + 2 && mouse_x <= slider_pos + int(slider_length) + 2 ) @@ -741,7 +741,7 @@ void FScrollbar::jumpToClickPos (int x, int y) } else // horizontal { - const int nf = isNewFont() ? 1 : 0; + const int nf = FTerm::isNewFont() ? 1 : 0; if ( x > 1 + nf && x < int(getWidth()) - nf ) { @@ -769,7 +769,7 @@ void FScrollbar::jumpToClickPos (int pos) jumpToClickPos (0, pos + 2); else { - if ( isNewFont() ) + if ( FTerm::isNewFont() ) jumpToClickPos (pos + 3, 0); else jumpToClickPos (pos + 2, 0); @@ -807,7 +807,7 @@ void FScrollbar::changeOnResize() if ( bar_orientation == fc::vertical ) { - setWidth(isNewFont() ? 2 : 1); + setWidth(FTerm::isNewFont() ? 2 : 1); setHeight(length); } else // horizontal diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 7f4c5d1f..cbc11031 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -38,7 +38,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- FScrollView::FScrollView (FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init(parent); } @@ -293,6 +293,15 @@ bool FScrollView::setViewportPrint (bool 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) { @@ -416,7 +425,7 @@ void FScrollView::draw() { unsetViewportPrint(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); if ( const auto& p = getParentWidget() ) @@ -427,7 +436,7 @@ void FScrollView::draw() if ( hasBorder() ) drawBorder(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); setViewportPrint(); @@ -712,14 +721,12 @@ void FScrollView::init (const FWidget* parent) initScrollbar (vbar, fc::vertical, &FScrollView::cb_vbarChange); initScrollbar (hbar, fc::horizontal, &FScrollView::cb_hbarChange); mapKeyFunctions(); - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.dialog_fg); - setBackgroundColor (wc.dialog_bg); + resetColors(); setGeometry (FPoint{1, 1}, FSize{4, 4}); setMinimumSize (FSize{4, 4}); const int xoffset_end = int(getScrollWidth() - getViewportWidth()); const int yoffset_end = int(getScrollHeight() - getViewportHeight()); - nf_offset = isNewFont() ? 1 : 0; + nf_offset = FTerm::isNewFont() ? 1 : 0; setTopPadding (1 - getScrollY()); setLeftPadding (1 - getScrollX()); setBottomPadding (1 - (yoffset_end - getScrollY())); @@ -769,7 +776,7 @@ void FScrollView::calculateScrollbarPos() const std::size_t width = getWidth(); const std::size_t height = getHeight(); - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { vbar->setGeometry (FPoint{int(width), 2}, FSize{2, height - 2}); hbar->setGeometry (FPoint{1, int(height)}, FSize{width - 2, 1}); diff --git a/src/fspinbox.cpp b/src/fspinbox.cpp index c52e605d..6b12e0c8 100644 --- a/src/fspinbox.cpp +++ b/src/fspinbox.cpp @@ -42,7 +42,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- FSpinBox::FSpinBox (FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init(); } @@ -92,8 +92,8 @@ bool FSpinBox::setFocus (bool enable) bool FSpinBox::setShadow (bool enable) { if ( enable - && getEncoding() != fc::VT100 - && getEncoding() != fc::ASCII ) + && FTerm::getEncoding() != fc::VT100 + && FTerm::getEncoding() != fc::ASCII ) { setFlags().shadow = true; setShadowSize(FSize{1, 1}); @@ -326,26 +326,26 @@ void FSpinBox::init() //---------------------------------------------------------------------- void FSpinBox::draw() { - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); const FColorPair inc_button_color = [this, &wc] () { if ( value == max ) - return FColorPair { wc.scrollbar_button_inactive_fg - , wc.scrollbar_button_inactive_bg }; + return FColorPair { wc->scrollbar_button_inactive_fg + , wc->scrollbar_button_inactive_bg }; else - return FColorPair { wc.scrollbar_button_fg - , wc.scrollbar_button_bg }; + return FColorPair { wc->scrollbar_button_fg + , wc->scrollbar_button_bg }; }(); const FColorPair dec_button_color = [this, &wc] () { if ( value == min ) - return FColorPair { wc.scrollbar_button_inactive_fg - , wc.scrollbar_button_inactive_bg }; + return FColorPair { wc->scrollbar_button_inactive_fg + , wc->scrollbar_button_inactive_bg }; else - return FColorPair { wc.scrollbar_button_fg - , wc.scrollbar_button_bg }; + return FColorPair { wc->scrollbar_button_fg + , wc->scrollbar_button_bg }; }(); print() << FPoint{int(getWidth()) - 1, 1} diff --git a/src/fstartoptions.cpp b/src/fstartoptions.cpp index 4093f980..864b5033 100644 --- a/src/fstartoptions.cpp +++ b/src/fstartoptions.cpp @@ -20,6 +20,8 @@ * . * ***********************************************************************/ +#include "final/fapplication.h" +#include "final/flog.h" #include "final/fstartoptions.h" namespace finalcut @@ -49,6 +51,7 @@ FStartOptions::FStartOptions() #elif defined(__NetBSD__) || defined(__OpenBSD__) , meta_sends_escape{true} #endif + , dark_theme{false} { } //---------------------------------------------------------------------- @@ -65,9 +68,9 @@ FStartOptions& FStartOptions::getFStartOptions() { 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(); } } diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 2d7d17b9..a2ec6983 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -36,16 +36,16 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FStatusKey::FStatusKey(FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init (parent); } //---------------------------------------------------------------------- FStatusKey::FStatusKey (FKey k, const FString& txt, FWidget* parent) - : FWidget(parent) - , text(txt) - , key(k) + : FWidget{parent} + , text{txt} + , key{k} { init (parent); } @@ -126,7 +126,7 @@ void FStatusKey::processActivate() // constructor and destructor //---------------------------------------------------------------------- FStatusBar::FStatusBar(FWidget* parent) - : FWindow(parent) + : FWindow{parent} { init(); } @@ -158,6 +158,15 @@ void FStatusBar::setMessage (const FString& 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 { @@ -174,9 +183,9 @@ bool FStatusBar::hasActivatedKey() const //---------------------------------------------------------------------- void FStatusBar::hide() { - const auto& wc = getFWidgetColors(); - const FColor fg = wc.term_fg; - const FColor bg = wc.term_bg; + const auto& wc = getColorTheme(); + const FColor fg = wc->term_fg; + const FColor bg = wc->term_bg; setColor (fg, bg); print() << FPoint{1, 1} << FString{getDesktopWidth(), L' '}; updateTerminal(); @@ -210,11 +219,11 @@ void FStatusBar::drawMessage() if ( isLastActiveFocus ) space_offset = 0; - const auto& wc = getFWidgetColors(); - setColor (wc.statusbar_fg, wc.statusbar_bg); + const auto& wc = getColorTheme(); + setColor (wc->statusbar_fg, wc->statusbar_bg); setPrintPos ({x, 1}); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); if ( x + space_offset + 3 < int(termWidth) && text ) @@ -249,7 +258,7 @@ void FStatusBar::drawMessage() for (int i = x; i <= int(termWidth); i++) print (' '); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } @@ -513,16 +522,14 @@ void FStatusBar::init() if ( getRootWidget() ) getRootWidget()->setBottomPadding(1, true); - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.statusbar_fg); - setBackgroundColor (wc.statusbar_bg); + resetColors(); unsetFocusable(); } //---------------------------------------------------------------------- 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)); } @@ -554,7 +561,7 @@ void FStatusBar::drawKeys() print() << FPoint{1, 1}; - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); auto iter = key_list.begin(); @@ -573,8 +580,8 @@ void FStatusBar::drawKeys() } else { - const auto& wc = getFWidgetColors(); - setColor (wc.statusbar_fg, wc.statusbar_bg); + const auto& wc = getColorTheme(); + setColor (wc->statusbar_fg, wc->statusbar_bg); for (; x <= int(screenWidth); x++) print (' '); @@ -583,7 +590,7 @@ void FStatusBar::drawKeys() ++iter; } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); x_msg = x; @@ -595,13 +602,13 @@ void FStatusBar::drawKey (keyList::const_iterator iter) // Draw not active key const auto item = *iter; - const auto& wc = getFWidgetColors(); - setColor (wc.statusbar_hotkey_fg, wc.statusbar_hotkey_bg); + const auto& wc = getColorTheme(); + setColor (wc->statusbar_hotkey_fg, wc->statusbar_hotkey_bg); x++; print (' '); x += keyname_len; - print (getKeyName(item->getKey())); - setColor (wc.statusbar_fg, wc.statusbar_bg); + print (FTerm::getKeyName(item->getKey())); + setColor (wc->statusbar_fg, wc->statusbar_bg); x++; print ('-'); 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) ) { // Next element is active - if ( isMonochron() ) + if ( FTerm::isMonochron() ) 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); // ▐ } else @@ -635,13 +642,13 @@ void FStatusBar::drawKey (keyList::const_iterator iter) x++; - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); } else if ( iter + 1 != key_list.end() && x < int(screenWidth) ) { // Not the last element - setColor (wc.statusbar_separator_fg, wc.statusbar_bg); + setColor (wc->statusbar_separator_fg, wc->statusbar_bg); x++; print (fc::BoxDrawingsVertical); // │ } @@ -654,17 +661,17 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter) const auto& item = *iter; - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); - const auto& wc = getFWidgetColors(); - setColor ( wc.statusbar_active_hotkey_fg - , wc.statusbar_active_hotkey_bg ); + const auto& wc = getColorTheme(); + setColor ( wc->statusbar_active_hotkey_fg + , wc->statusbar_active_hotkey_bg ); x++; print (' '); x += keyname_len; - print (getKeyName(item->getKey())); - setColor (wc.statusbar_active_fg, wc.statusbar_active_bg); + print (FTerm::getKeyName(item->getKey())); + setColor (wc->statusbar_active_fg, wc->statusbar_active_bg); x++; print ('-'); const auto column_width = getColumnWidth (item->getText()); @@ -674,6 +681,7 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter) { print (item->getText()); x++; + setColor (wc->statusbar_bg, wc->statusbar_active_hotkey_bg); print (fc::RightHalfBlock); // ▌ } else @@ -684,7 +692,7 @@ void FStatusBar::drawActiveKey (keyList::const_iterator iter) << ".."; } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); } diff --git a/src/fstring.cpp b/src/fstring.cpp index ab3e51c8..a2e9ffe7 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -25,6 +25,8 @@ #include #include +#include "final/fapplication.h" +#include "final/flog.h" #include "final/fstring.h" namespace finalcut @@ -43,21 +45,21 @@ const wchar_t FString::const_null_char{L'\0'}; FString::FString (int len) { if ( len > 0 ) - initLength(std::size_t(len)); + _initLength(std::size_t(len)); else - initLength(0); + _initLength(0); } //---------------------------------------------------------------------- FString::FString (std::size_t len) { - initLength(len); + _initLength(len); } //---------------------------------------------------------------------- FString::FString (std::size_t len, wchar_t c) { - initLength(len); + _initLength(len); const wchar_t* ps = string; wchar_t* pe = string + len; @@ -74,12 +76,12 @@ FString::FString (const FString& s) // copy 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.bufsize = 0; s.c_string = nullptr; @@ -104,7 +106,7 @@ FString::FString (const std::string& s) { 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); delete[] wc_string; } @@ -115,7 +117,7 @@ FString::FString (const char s[]) { if ( s ) { - const wchar_t* wc_string = c_to_wc_str(s); + const wchar_t* wc_string = _to_wcstring(s); _assign( wc_string ); delete[] wc_string; } @@ -172,14 +174,34 @@ FString::~FString() // destructor //---------------------------------------------------------------------- FString& FString::operator = (const FString& s) { - _assign (s.string); + if ( &s != this ) + _assign (s.string); + return *this; } //---------------------------------------------------------------------- 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; } @@ -399,9 +421,9 @@ const char* FString::c_str() const // Returns a constant c-string if ( length > 0 ) - return wc_to_c_str (string); + return _to_cstring(string); else if ( string ) - return const_cast(""); + return ""; else return nullptr; } @@ -412,7 +434,7 @@ char* FString::c_str() // Returns a c-string if ( length > 0 ) - return wc_to_c_str (string); + return const_cast(_to_cstring(string)); else if ( string ) return const_cast(""); else @@ -759,12 +781,12 @@ FStringList FString::split (const FString& delimiter) return string_list; 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 ) { string_list.push_back (FString{token}); - token = extractToken (&rest, nullptr, delimiter.wc_str()); + token = _extractToken (&rest, nullptr, delimiter.wc_str()); } return string_list; @@ -1219,7 +1241,7 @@ bool FString::includes (const FString& s) const // private methods of FString //---------------------------------------------------------------------- -inline void FString::initLength (std::size_t len) +inline void FString::_initLength (std::size_t len) { if ( len == 0 ) return; @@ -1232,9 +1254,9 @@ inline void FString::initLength (std::size_t len) string = new wchar_t[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](); } - 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; } } @@ -1291,9 +1313,9 @@ void FString::_insert (std::size_t len, const wchar_t s[]) { 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; } @@ -1338,9 +1360,9 @@ void FString::_insert ( std::size_t pos { 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; } @@ -1382,9 +1404,9 @@ void FString::_remove (std::size_t pos, std::size_t len) { 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; } @@ -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 return nullptr; @@ -1416,9 +1438,9 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const // Generate a empty string ("") 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; } @@ -1441,9 +1463,9 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const // pre-initialiaze the whole string with '\0' 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; } @@ -1454,14 +1476,14 @@ inline char* FString::wc_to_c_str (const wchar_t s[]) const { delete[](c_string); c_string = nullptr; - return const_cast(""); + return ""; } 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 return nullptr; @@ -1473,9 +1495,9 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const // Generate a empty wide string (L"") 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; } } @@ -1493,9 +1515,9 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const // pre-initialiaze the whole string with '\0' 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; } @@ -1526,9 +1548,9 @@ inline wchar_t* FString::c_to_wc_str (const char s[]) const } //---------------------------------------------------------------------- -inline wchar_t* FString::extractToken ( wchar_t* rest[] - , const wchar_t s[] - , const wchar_t delim[] ) +inline const wchar_t* FString::_extractToken ( wchar_t* rest[] + , const wchar_t s[] + , const wchar_t delim[] ) { wchar_t* token = ( s ) ? const_cast(s) : *rest; @@ -1641,12 +1663,12 @@ std::ostream& operator << (std::ostream& outstr, const FString& s) if ( s.length > 0 ) { - outstr << s.wc_to_c_str(s.string); + outstr << s._to_cstring(s.string); } else if ( width > 0 ) { 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; @@ -1657,7 +1679,7 @@ std::istream& operator >> (std::istream& instr, FString& s) { char buf[FString::INPBUFFER + 1]{}; 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 ) { diff --git a/src/fstringstream.cpp b/src/fstringstream.cpp new file mode 100644 index 00000000..31a3523d --- /dev/null +++ b/src/fstringstream.cpp @@ -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 * +* . * +***********************************************************************/ + +#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 + diff --git a/src/fswitch.cpp b/src/fswitch.cpp index 826619ea..1db06e7d 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -35,14 +35,14 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FSwitch::FSwitch(FWidget* parent) - : FToggleButton(parent) + : FToggleButton{parent} { setButtonWidth(11); } //---------------------------------------------------------------------- FSwitch::FSwitch (const FString& txt, FWidget* parent) - : FToggleButton(txt, parent) + : FToggleButton{txt, parent} , switch_offset_pos(txt.getLength() + 1) { setButtonWidth(11); @@ -143,46 +143,46 @@ inline void FSwitch::drawChecked() { wchar_t on[6]{L" On "}; const wchar_t off[6]{L" Off "}; - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); if ( hasFocus() && ! button_pressed ) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) { std::wcsncpy (on, L" ", 6); setBold(true); } - else if ( getMaxColor() < 16 ) + else if ( FTerm::getMaxColor() < 16 ) { 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 - setColor (wc.button_hotkey_fg, wc.button_active_focus_bg); + setColor (wc->button_hotkey_fg, wc->button_active_focus_bg); } else { - if ( isMonochron() || getMaxColor() < 16 ) - setColor (wc.button_active_focus_fg, wc.button_active_bg); + if ( FTerm::isMonochron() || FTerm::getMaxColor() < 16 ) + setColor (wc->button_active_focus_fg, wc->button_active_bg); 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); print (on); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); - if ( isMonochron() || getMaxColor() < 16 ) + if ( FTerm::isMonochron() || FTerm::getMaxColor() < 16 ) setBold(false); - print() << FColorPair{wc.button_inactive_fg, wc.button_inactive_bg} + print() << FColorPair{wc->button_inactive_fg, wc->button_inactive_bg} << off; - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); setCursorPos ({3 + int(switch_offset_pos), 1}); @@ -194,43 +194,43 @@ inline void FSwitch::drawUnchecked() const wchar_t on[6]{L" On "}; wchar_t off[6]{L" Off "}; - const auto& wc = getFWidgetColors(); - setColor (wc.button_inactive_fg, wc.button_inactive_bg); + const auto& wc = getColorTheme(); + setColor (wc->button_inactive_fg, wc->button_inactive_bg); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); print (on); if ( hasFocus() && ! button_pressed ) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) { std::wcsncpy (off, L"", 6); setBold(true); } - else if ( getMaxColor() < 16 ) + else if ( FTerm::getMaxColor() < 16 ) { 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 - setColor (wc.button_hotkey_fg, wc.button_active_focus_bg); + setColor (wc->button_hotkey_fg, wc->button_active_focus_bg); } else { - if ( isMonochron() || getMaxColor() < 16 ) - setColor (wc.button_active_focus_fg, wc.button_active_bg); + if ( FTerm::isMonochron() || FTerm::getMaxColor() < 16 ) + setColor (wc->button_active_focus_fg, wc->button_active_bg); 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); print (off); - if ( isMonochron() || getMaxColor() < 16 ) + if ( FTerm::isMonochron() || FTerm::getMaxColor() < 16 ) setBold(false); setCursorPos ({7 + int(switch_offset_pos), 1}); diff --git a/src/fsystemimpl.cpp b/src/fsystemimpl.cpp index 31f8b38d..3f8fdef3 100644 --- a/src/fsystemimpl.cpp +++ b/src/fsystemimpl.cpp @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -42,6 +42,7 @@ FSystemImpl::FSystemImpl() FSystemImpl::~FSystemImpl() // destructor { } +// public methods of FSystemImpl //---------------------------------------------------------------------- int FSystemImpl::getpwuid_r ( uid_t uid, struct passwd* pwd , char* buf, size_t buflen diff --git a/src/fterm.cpp b/src/fterm.cpp index 04ab4292..663a5dad 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -28,9 +28,9 @@ #include "final/fapplication.h" #include "final/fc.h" #include "final/fcharmap.h" -#include "final/fcolorpalette.h" #include "final/fkey_map.h" #include "final/fkeyboard.h" +#include "final/flog.h" #include "final/fmouse.h" #include "final/foptiattr.h" #include "final/foptimove.h" @@ -180,6 +180,13 @@ int FTerm::getMaxColor() return FTermcap::max_color; } +//---------------------------------------------------------------------- +FTerm::FColorPalettePtr& FTerm::getColorPaletteTheme() +{ + static FColorPalettePtr* color_theme = new FColorPalettePtr(); + return *color_theme; +} + //---------------------------------------------------------------------- FTermData* FTerm::getFTermData() { @@ -189,9 +196,9 @@ FTermData* FTerm::getFTermData() { 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(); } } @@ -208,9 +215,9 @@ FSystem* FTerm::getFSystem() { 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(); } } @@ -227,9 +234,9 @@ FOptiMove* FTerm::getFOptiMove() { 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(); } } @@ -246,9 +253,9 @@ FOptiAttr* FTerm::getFOptiAttr() { 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(); } } @@ -265,9 +272,9 @@ FTermDetection* FTerm::getFTermDetection() { 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(); } } @@ -284,9 +291,9 @@ FTermXTerminal* FTerm::getFTermXTerminal() { 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(); } } @@ -303,9 +310,9 @@ FKeyboard* FTerm::getFKeyboard() { 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(); } } @@ -322,9 +329,9 @@ FMouseControl* FTerm::getFMouseControl() { 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(); } } @@ -342,9 +349,9 @@ FTermLinux* FTerm::getFTermLinux() { 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(); } } @@ -362,9 +369,9 @@ FTermFreeBSD* FTerm::getFTermFreeBSD() { 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(); } } @@ -382,9 +389,9 @@ FTermOpenBSD* FTerm::getFTermOpenBSD() { 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(); } } @@ -403,9 +410,9 @@ FTermDebugData& FTerm::getFTermDebugData() { 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(); } } @@ -624,7 +631,7 @@ void FTerm::redefineDefaultColors (bool enable) if ( isNewFont() ) // NewFont need the reverse-video attribute return; - xterm->redefineDefaultColors (enable); + getFTermXTerminal()->redefineDefaultColors (enable); } //---------------------------------------------------------------------- @@ -665,7 +672,7 @@ bool FTerm::setVGAFont() { data->setVGAFont(true); // Set font in xterm to vga - xterm->setFont("vga"); + getFTermXTerminal()->setFont("vga"); data->setNewFont(false); } #if defined(__linux__) @@ -700,7 +707,7 @@ bool FTerm::setNewFont() { data->setNewFont(true); // Set font in xterm to 8x16graph - xterm->setFont("8x16graph"); + getFTermXTerminal()->setFont("8x16graph"); } #if defined(__linux__) else if ( isLinuxTerm() ) @@ -739,12 +746,12 @@ bool FTerm::setOldFont() if ( font.getLength() > 2 ) { // restore saved xterm font - xterm->setFont(font); + getFTermXTerminal()->setFont(font); } else { // Set font in xterm to vga - xterm->setFont("vga"); + getFTermXTerminal()->setFont("vga"); } retval = true; @@ -914,7 +921,7 @@ void FTerm::setTermSize (const FSize& 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 - xterm->setTitle (title); + getFTermXTerminal()->setTitle (title); } //---------------------------------------------------------------------- @@ -1268,10 +1275,10 @@ void FTerm::initScreenSettings() #endif // set xterm underline cursor - xterm->setCursorStyle (fc::blinking_underline); + getFTermXTerminal()->setCursorStyle (fc::blinking_underline); // set xterm color settings to defaults - xterm->setDefaults(); + getFTermXTerminal()->setDefaults(); } //---------------------------------------------------------------------- @@ -1297,7 +1304,7 @@ void FTerm::exitWithMessage (const FString& message) std::fflush (stdout); if ( ! message.isEmpty() ) - std::cerr << "Warning: " << message << std::endl; + FApplication::getLog()->warn(message.c_str()); std::exit (EXIT_FAILURE); } @@ -1322,7 +1329,7 @@ void FTerm::init_global_values (bool disable_alt_screen) data->useAlternateScreen(! disable_alt_screen); // Initialize xterm object - xterm->init(); + getFTermXTerminal()->init(); if ( ! getStartOptions().terminal_detection ) term_detection->setTerminalDetection (false); @@ -1845,9 +1852,9 @@ void FTerm::init_captureFontAndTitle() if ( ! FStartOptions::getFStartOptions().terminal_data_request ) return; - xterm->captureFontAndTitle(); - const auto& font = xterm->getFont(); - const auto& title = xterm->getTitle(); + getFTermXTerminal()->captureFontAndTitle(); + const auto& font = getFTermXTerminal()->getFont(); + const auto& title = getFTermXTerminal()->getTitle(); if ( ! font.isEmpty() ) data->setXtermFont(font); @@ -1875,38 +1882,41 @@ void FTerm::redefineColorPalette() { // Redefine the color palette - if ( ! canChangeColorPalette() ) + if ( ! (canChangeColorPalette() && getStartOptions().color_change) ) return; resetColorMap(); saveColorMap(); - if ( getMaxColor() >= 16 ) - FColorPalette::set16ColorPalette (FTerm::setPalette); - else // 8 colors - FColorPalette::set8ColorPalette (FTerm::setPalette); + if ( getStartOptions().dark_theme ) + { + setColorPaletteTheme(&FTerm::setPalette); + } + else + { + if ( getMaxColor() >= 16 ) + setColorPaletteTheme(&FTerm::setPalette); + else // 8 colors + setColorPaletteTheme(&FTerm::setPalette); + } } //---------------------------------------------------------------------- void FTerm::restoreColorPalette() { - if ( ! canChangeColorPalette() ) + if ( ! (canChangeColorPalette() && getStartOptions().color_change) ) return; // Reset screen settings - if ( getMaxColor() >= 16 ) - FColorPalette::reset16ColorPalette (FTerm::setPalette); - else // 8 colors - FColorPalette::reset8ColorPalette (FTerm::setPalette); - - xterm->resetColorMap(); + getColorPaletteTheme()->resetColorPalette(); + getFTermXTerminal()->resetColorMap(); resetColorMap(); } //---------------------------------------------------------------------- void FTerm::setInsertCursorStyle() { - xterm->setCursorStyle (fc::blinking_underline); + getFTermXTerminal()->setCursorStyle (fc::blinking_underline); setKDECursor(fc::UnderlineCursor); #if defined(__linux__) @@ -1916,13 +1926,13 @@ void FTerm::setInsertCursorStyle() #endif if ( isUrxvtTerminal() ) - xterm->setCursorColor ("rgb:ffff/ffff/ffff"); + getFTermXTerminal()->setCursorColor ("rgb:ffff/ffff/ffff"); } //---------------------------------------------------------------------- void FTerm::setOverwriteCursorStyle() { - xterm->setCursorStyle (fc::steady_block); + getFTermXTerminal()->setCursorStyle (fc::steady_block); setKDECursor(fc::BlockCursor); #if defined(__linux__) @@ -1932,7 +1942,7 @@ void FTerm::setOverwriteCursorStyle() #endif 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 if ( isXTerminal() ) - xterm->metaSendsESC(true); + getFTermXTerminal()->metaSendsESC(true); // switch to application escape key mode enableApplicationEscKey(); @@ -2271,8 +2281,7 @@ void FTerm::init (bool disable_alt_screen) initTermspecifics(); // Redefine the color palette - if ( getStartOptions().color_change ) - redefineColorPalette(); + redefineColorPalette(); // Set 220 Hz beep (100 ms) setBeep(220, 100); @@ -2429,14 +2438,13 @@ void FTerm::finish() } // Reset xterm color settings to default values - xterm->resetDefaults(); + getFTermXTerminal()->resetDefaults(); // Set xterm full block cursor - xterm->setCursorStyle (fc::steady_block); + getFTermXTerminal()->setCursorStyle (fc::steady_block); // Restore the color palette - if ( getStartOptions().color_change ) - restoreColorPalette(); + restoreColorPalette(); // Switch to normal escape key mode disableApplicationEscKey(); @@ -2454,7 +2462,7 @@ void FTerm::finish() // Deactivate meta key sends escape if ( isXTerminal() ) - xterm->metaSendsESC(false); + getFTermXTerminal()->metaSendsESC(false); // Switch to the normal screen useNormalScreenBuffer(); @@ -2471,7 +2479,7 @@ void FTerm::finish() const auto& exit_message = data->getExitMessage(); if ( ! exit_message.isEmpty() ) - std::cerr << exit_message << std::endl; + FApplication::getLog()->info(exit_message.c_str()); deallocationValues(); } @@ -2497,6 +2505,13 @@ void FTerm::finish_encoding() #endif } +//---------------------------------------------------------------------- +void FTerm::destroyColorPaletteTheme() +{ + const FColorPalettePtr* theme = &(getColorPaletteTheme()); + delete theme; +} + //---------------------------------------------------------------------- void FTerm::setSignalHandler() { @@ -2546,9 +2561,11 @@ void FTerm::signal_handler (int signum) init_term_object->finish(); std::fflush (stderr); std::fflush (stdout); - std::cerr << "\nProgram stopped: signal " - << signum - << " (" << strsignal(signum) << ")" << std::endl; + *FApplication::getLog() << FLog::Error + << "\nProgram stopped: signal " + << signum + << " (" << strsignal(signum) << ")" + << std::endl; std::terminate(); default: diff --git a/src/fterm_functions.cpp b/src/fterm_functions.cpp index a28bde33..d90f226c 100644 --- a/src/fterm_functions.cpp +++ b/src/fterm_functions.cpp @@ -27,7 +27,9 @@ #include #include +#include "final/fapplication.h" #include "final/fcharmap.h" +#include "final/flog.h" #include "final/fterm.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) { - std::cerr << "Out of Range error: " << ex.what() << std::endl; + *FApplication::getLog() << FLog::Error + << "Out of Range error: " << ex.what() << std::endl; } } diff --git a/src/ftermcap.cpp b/src/ftermcap.cpp index 251a42ec..a1e4ff2a 100644 --- a/src/ftermcap.cpp +++ b/src/ftermcap.cpp @@ -83,7 +83,7 @@ void FTermcap::termcap() std::vector terminals{}; static constexpr int success = 1; static constexpr int uninitialized = -2; - static char term_buffer[2048]{}; + static char term_buffer[BUF_SIZE]{}; int status = uninitialized; const bool color256 = term_detection->canDisplay256Colors(); @@ -116,9 +116,6 @@ void FTermcap::termcap() ++iter; } - if ( std::strncmp(termtype, "ansi", 4) == 0 ) - term_detection->setAnsiTerminal (true); - termcapError (status); termcapVariables(); } @@ -129,19 +126,23 @@ void FTermcap::termcapError (int status) static constexpr int no_entry = 0; static constexpr int db_not_found = -1; static constexpr int uninitialized = -2; + finalcut::FLog& log = *FApplication::getLog(); if ( status == no_entry || status == uninitialized ) { const char* termtype = fterm_data->getTermType(); - std::cerr << "Unknown terminal: " << termtype << "\n" - << "Check the TERM environment variable\n" - << "Also make sure that the terminal\n" - << "is defined in the termcap/terminfo database.\n"; + log << FLog::Error + << "Unknown terminal: \"" << termtype << "\". " + << "Check the TERM environment variable. " + << "Also make sure that the terminal " + << "is defined in the termcap/terminfo database." + << std::endl; std::abort(); } 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(); } } diff --git a/src/ftermdetection.cpp b/src/ftermdetection.cpp index cc536aa0..4554f85f 100644 --- a/src/ftermdetection.cpp +++ b/src/ftermdetection.cpp @@ -25,7 +25,9 @@ #endif #include "final/emptyfstring.h" +#include "final/fapplication.h" #include "final/fc.h" +#include "final/flog.h" #include "final/fsystem.h" #include "final/fterm.h" #include "final/ftermdata.h" @@ -377,6 +379,8 @@ void FTermDetection::detectTerminal() if ( ! new_termtype && std::strlen(termtype) == 5 ) new_termtype = "xterm-16color"; } + else if ( std::strncmp(termtype, "ansi", 4) == 0 ) // ANSI detection + terminal_type.ansi = true; // set the new environment variable TERM if ( new_termtype ) @@ -587,9 +591,9 @@ const char* FTermDetection::parseAnswerbackMsg (const char current_termtype[]) { 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; } @@ -657,9 +661,9 @@ const char* FTermDetection::parseSecDA (const char current_termtype[]) // Secondary device attributes (SEC_DA) <- decTerminalID string 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; } diff --git a/src/ftermfreebsd.cpp b/src/ftermfreebsd.cpp index 00acd0e8..324af019 100644 --- a/src/ftermfreebsd.cpp +++ b/src/ftermfreebsd.cpp @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -20,13 +20,24 @@ * . * ***********************************************************************/ +#include "final/fapplication.h" #include "final/fcharmap.h" +#include "final/flog.h" #include "final/fsystem.h" #include "final/fterm.h" #include "final/ftermdata.h" #include "final/ftermfreebsd.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 { @@ -58,12 +69,14 @@ bool FTermFreeBSD::setCursorStyle (CursorStyle style) { // Set cursor style in a BSD console - if ( ! fsystem || ! isFreeBSDConsole() || ! change_cursorstyle ) - return false; - if ( ! fterm_data ) fterm_data = FTerm::getFTermData(); + initCheck(false); + + if ( ! fsystem || ! isFreeBSDConsole() || ! change_cursorstyle ) + return false; + cursor_style = style; if ( fterm_data->isCursorHidden() ) @@ -177,6 +190,16 @@ void FTermFreeBSD::finish() // 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() { @@ -185,9 +208,8 @@ bool FTermFreeBSD::saveFreeBSDAltKey() static constexpr int left_alt = 0x38; int ret{-1}; keymap_t keymap{}; - - if ( fsystem ) - ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); + initCheck(false); + ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); if ( ret < 0 ) return false; @@ -205,9 +227,8 @@ bool FTermFreeBSD::setFreeBSDAltKey (uInt key) static constexpr int left_alt = 0x38; int ret{-1}; keymap_t keymap{}; - - if ( fsystem ) - ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); + initCheck(false); + ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); if ( ret < 0 ) return false; @@ -241,6 +262,8 @@ bool FTermFreeBSD::resetFreeBSDAlt2Meta() //---------------------------------------------------------------------- bool FTermFreeBSD::setFreeBSDCursorStyle (CursorStyle style) { + initCheck(false); + if ( fsystem->ioctl(0, CONS_CURSORTYPE, &style) == 0 ) return true; else diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index 566cadc8..4537cc83 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -22,8 +22,10 @@ #include +#include "final/fapplication.h" #include "final/fc.h" #include "final/fcharmap.h" +#include "final/flog.h" #include "final/fsystem.h" #include "final/fterm.h" #include "final/ftermcap.h" @@ -200,7 +202,7 @@ void FTermLinux::init() } else { - std::cerr << "can not open the console.\n"; + FApplication::getLog()->error("Can not open the console."); std::abort(); } } @@ -290,6 +292,9 @@ bool FTermLinux::loadVGAFont() if ( vga_font ) { + if ( ! fterm_data ) + fterm_data = FTerm::getFTermData(); + fterm_data->supportShadowCharacter (true); fterm_data->supportHalfBlockCharacter (true); } @@ -336,6 +341,9 @@ bool FTermLinux::loadNewFont() if ( new_font ) { + if ( ! fterm_data ) + fterm_data = FTerm::getFTermData(); + fterm_data->supportShadowCharacter (true); fterm_data->supportHalfBlockCharacter (true); } @@ -553,9 +561,9 @@ bool FTermLinux::getScreenFont() static constexpr std::size_t data_size = 4 * 32 * 512; 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; } @@ -605,9 +613,9 @@ bool FTermLinux::getUnicodeMap() { 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; } @@ -683,9 +691,9 @@ int FTermLinux::setScreenFont ( uChar fontdata[], uInt count { 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; } @@ -1286,6 +1294,9 @@ inline void FTermLinux::initSpecialCharacter() const wchar_t c2 = fc::LowerHalfBlock; const wchar_t c3 = fc::FullBlock; + if ( ! fterm_data ) + fterm_data = FTerm::getFTermData(); + if ( FTerm::charEncode(c1, fc::PC) == FTerm::charEncode(c1, fc::ASCII) || FTerm::charEncode(c2, fc::PC) == FTerm::charEncode(c2, fc::ASCII) || FTerm::charEncode(c3, fc::PC) == FTerm::charEncode(c3, fc::ASCII) ) @@ -1322,6 +1333,10 @@ void FTermLinux::characterFallback ( wchar_t ucs , std::vector fallback ) { constexpr sInt16 NOT_FOUND = -1; + + if ( ! fterm_data ) + fterm_data = FTerm::getFTermData(); + charSubstitution& sub_map = fterm_data->getCharSubstitutionMap(); if ( fallback.size() < 2 || ucs != fallback[0] ) diff --git a/src/ftermopenbsd.cpp b/src/ftermopenbsd.cpp index 662f00db..e8e2499a 100644 --- a/src/ftermopenbsd.cpp +++ b/src/ftermopenbsd.cpp @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -20,10 +20,21 @@ * . * ***********************************************************************/ +#include "final/fapplication.h" +#include "final/flog.h" #include "final/fsystem.h" #include "final/fterm.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 { @@ -86,6 +97,8 @@ void FTermOpenBSD::init() //---------------------------------------------------------------------- void FTermOpenBSD::finish() { + initCheck(); + if ( ! isBSDConsole() ) return; @@ -96,6 +109,8 @@ void FTermOpenBSD::finish() //---------------------------------------------------------------------- bool FTermOpenBSD::setBeep (int Hz, int ms) { + initCheck(false); + if ( ! isBSDConsole() ) return false; @@ -122,6 +137,7 @@ bool FTermOpenBSD::setBeep (int Hz, int ms) //---------------------------------------------------------------------- bool FTermOpenBSD::resetBeep() { + initCheck(false); wskbd_bell_data default_bell; // Gets the default setting for the bell @@ -141,6 +157,16 @@ bool FTermOpenBSD::resetBeep() // 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() { diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index ea700a4e..14569b33 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -24,7 +24,9 @@ #include "final/fconfig.h" // includes _GNU_SOURCE for fd_set #endif +#include "final/fapplication.h" #include "final/fc.h" +#include "final/flog.h" #include "final/fstring.h" #include "final/fterm.h" #include "final/ftermcap.h" @@ -34,6 +36,13 @@ #include "final/ftermxterminal.h" #include "final/fsize.h" +#define initCheck(ret_value) \ + if ( ! isInitialized() ) \ + { \ + warnNotInitialized(); \ + return ret_value; \ + } + namespace finalcut { @@ -256,6 +265,8 @@ void FTermXTerminal::resetHighlightBackground() //---------------------------------------------------------------------- void FTermXTerminal::resetDefaults() { + initCheck(); + if ( term_detection->isPuttyTerminal() ) return; @@ -280,6 +291,8 @@ void FTermXTerminal::resetDefaults() //---------------------------------------------------------------------- void FTermXTerminal::captureFontAndTitle() { + initCheck(); + if ( ( term_detection->isXTerminal() || term_detection->isUrxvtTerminal() ) && ! term_detection->isRxvtTerminal() ) @@ -293,6 +306,16 @@ void FTermXTerminal::captureFontAndTitle() // 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() { @@ -303,6 +326,8 @@ void FTermXTerminal::setXTermCursorStyle() return; #endif + initCheck(); + if ( term_detection->isGnomeTerminal() && ! term_detection->hasSetCursorStyleSupport() ) return; @@ -325,6 +350,7 @@ void FTermXTerminal::setXTermCursorStyle() void FTermXTerminal::setXTermTitle() { // Set the xterm title + initCheck(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -343,6 +369,8 @@ void FTermXTerminal::setXTermTitle() //---------------------------------------------------------------------- void FTermXTerminal::setXTermSize() { + initCheck(); + if ( term_detection->isXTerminal() ) { FTerm::putstringf ( CSI "8;%lu;%lut" @@ -357,6 +385,8 @@ void FTermXTerminal::setXTermFont() { // Change the XTerm font (needs the allowFontOps resource) + initCheck(); + if ( term_detection->isXTerminal() || term_detection->isScreenTerm() || term_detection->isUrxvtTerminal() @@ -373,6 +403,8 @@ void FTermXTerminal::setXTermForeground() { // Set the XTerm text foreground color + initCheck(); + if ( term_detection->isXTerminal() || term_detection->isScreenTerm() || term_detection->isMinttyTerm() @@ -391,6 +423,8 @@ void FTermXTerminal::setXTermBackground() { // Set the XTerm text background color + initCheck(); + if ( term_detection->isXTerminal() || term_detection->isScreenTerm() || term_detection->isMinttyTerm() @@ -409,6 +443,8 @@ void FTermXTerminal::setXTermCursorColor() { // Set the text cursor color + initCheck(); + if ( term_detection->isXTerminal() || term_detection->isScreenTerm() || term_detection->isMinttyTerm() @@ -427,6 +463,8 @@ void FTermXTerminal::setXTermMouseForeground() { // Set the mouse foreground color + initCheck(); + if ( term_detection->isXTerminal() || term_detection->isScreenTerm() || term_detection->isUrxvtTerminal() @@ -444,6 +482,8 @@ void FTermXTerminal::setXTermMouseBackground() { // Set the mouse background color + initCheck(); + if ( term_detection->isXTerminal() || term_detection->isScreenTerm() || FTermcap::osc_support ) @@ -460,6 +500,8 @@ void FTermXTerminal::setXTermHighlightBackground() { // Set the highlight background color + initCheck(); + if ( term_detection->isXTerminal() || term_detection->isScreenTerm() || term_detection->isUrxvtTerminal() @@ -478,6 +520,8 @@ void FTermXTerminal::setXTerm8ColorDefaults() // Redefinition of the XTerm default colors // for the final cut 8 color theme + initCheck(); + if ( term_detection->isPuttyTerminal() ) return; @@ -498,6 +542,8 @@ void FTermXTerminal::setXTerm16ColorDefaults() // Redefinition of the XTerm default colors // for the final cut 16 color theme + initCheck(); + if ( term_detection->isPuttyTerminal() ) return; @@ -518,6 +564,8 @@ inline void FTermXTerminal::setXTermDefaultsMouseCursor() setMouseBackground("rgb:ffff/ffff/ffff"); // white setMouseForeground ("rgb:0000/0000/0000"); // black + initCheck(); + if ( ! term_detection->isGnomeTerminal() ) setCursorColor("rgb:ffff/ffff/ffff"); // white } @@ -525,6 +573,8 @@ inline void FTermXTerminal::setXTermDefaultsMouseCursor() //---------------------------------------------------------------------- inline bool FTermXTerminal::canSetXTermBackground() { + initCheck(false); + if ( xterm_default_colors && ! (term_detection->isMinttyTerm() || term_detection->isMltermTerminal() @@ -540,6 +590,8 @@ void FTermXTerminal::resetXTermColorMap() { // Reset the entire color table + initCheck(); + if ( term_detection->isMinttyTerm() ) { FTerm::putstring (ESC "c"); // Full Reset (RIS) @@ -640,6 +692,8 @@ void FTermXTerminal::resetXTermHighlightBackground() //---------------------------------------------------------------------- bool FTermXTerminal::canResetColor() { + initCheck(false); + if ( term_detection->isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) return false; @@ -659,6 +713,8 @@ bool FTermXTerminal::canResetColor() //---------------------------------------------------------------------- void FTermXTerminal::oscPrefix() { + initCheck(); + if ( term_detection->isTmuxTerm() ) { // tmux device control string @@ -674,6 +730,8 @@ void FTermXTerminal::oscPrefix() //---------------------------------------------------------------------- void FTermXTerminal::oscPostfix() { + initCheck(); + if ( term_detection->isScreenTerm() || term_detection->isTmuxTerm() ) { @@ -685,6 +743,8 @@ void FTermXTerminal::oscPostfix() //---------------------------------------------------------------------- const FString FTermXTerminal::captureXTermFont() { + initCheck(FString{}); + if ( term_detection->isXTerminal() || term_detection->isScreenTerm() || FTermcap::osc_support ) @@ -727,6 +787,8 @@ const FString FTermXTerminal::captureXTermFont() //---------------------------------------------------------------------- const FString FTermXTerminal::captureXTermTitle() { + initCheck(FString{}); + if ( term_detection->isKdeTerminal() ) return FString{}; diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 35839b15..15ce3574 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -42,7 +42,7 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FTextView::FTextView(FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init(); } @@ -104,6 +104,15 @@ void FTextView::setGeometry ( const FPoint& pos, const FSize& size changeOnResize(); } +//---------------------------------------------------------------------- +void FTextView::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->dialog_fg); + setBackgroundColor (wc->dialog_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- void FTextView::setText (const FString& str) { @@ -178,6 +187,18 @@ void FTextView::scrollTo (int x, int y) updateTerminal(); } +//---------------------------------------------------------------------- +void FTextView::scrollToBegin() +{ + scrollToY (0); +} + +//---------------------------------------------------------------------- +void FTextView::scrollToEnd() +{ + scrollToY (int(getRows() - getTextHeight())); +} + //---------------------------------------------------------------------- void FTextView::hide() { @@ -202,7 +223,7 @@ void FTextView::insert (const FString& str, int pos) if ( str.isEmpty() ) s = "\n"; else - s = FString{str}.rtrim().expandTabs(getTabstop()); + s = FString{str}.rtrim().expandTabs(FTerm::getTabstop()); auto text_split = s.split("\r\n"); @@ -363,9 +384,9 @@ void FTextView::onMouseDown (FMouseEvent* ev) std::make_shared(fc::MouseDown_Event, p, tp, b); 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(fc::MouseUp_Event, p, tp, b); 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(fc::MouseMove_Event, p, tp, b); 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 (hbar, fc::horizontal, this, &FTextView::cb_hbarChange); - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.dialog_fg); - setBackgroundColor (wc.dialog_bg); - nf_offset = isNewFont() ? 1 : 0; + resetColors(); + nf_offset = FTerm::isNewFont() ? 1 : 0; setTopPadding(1); setLeftPadding(1); setBottomPadding(1); @@ -577,8 +596,8 @@ inline void FTextView::mapKeyFunctions() key_map[fc::Fkey_right] = [this] { scrollBy (1, 0); }; key_map[fc::Fkey_ppage] = [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_end] = [this] { scrollToY (int(getRows() - getTextHeight())); }; + key_map[fc::Fkey_home] = [this] { scrollToBegin(); }; + key_map[fc::Fkey_end] = [this] { scrollToEnd(); }; } //---------------------------------------------------------------------- @@ -611,13 +630,13 @@ void FTextView::drawBorder() { if ( ! useFDialogBorder() ) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); const FRect box{FPoint{1, 1}, getSize()}; finalcut::drawListBorder (this, box); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } } @@ -649,7 +668,7 @@ void FTextView::drawText() setColor(); - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); for (std::size_t y{0}; y < num; y++) // Line loop @@ -678,7 +697,7 @@ void FTextView::drawText() print() << FString{trailing_whitespace, L' '}; } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } @@ -707,7 +726,7 @@ inline bool FTextView::isPrintable (wchar_t ch) { // 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))) || (!utf8 && std::isprint(ch)) ) @@ -728,7 +747,7 @@ void FTextView::changeOnResize() const std::size_t width = getWidth(); const std::size_t height = getHeight(); - if ( isNewFont() ) + if ( FTerm::isNewFont() ) { vbar->setGeometry (FPoint{int(width), 1}, FSize{2, height - 1}); hbar->setGeometry (FPoint{1, int(height)}, FSize{width - 2, 1}); diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 4e702110..6f665eb4 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -40,7 +40,7 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FToggleButton::FToggleButton (FWidget* parent) - : FWidget(parent) + : FWidget{parent} { init(); @@ -55,7 +55,7 @@ FToggleButton::FToggleButton (FWidget* parent) //---------------------------------------------------------------------- FToggleButton::FToggleButton (const FString& txt, FWidget* parent) - : FWidget(parent) + : FWidget{parent} { FToggleButton::setText(txt); // call own method init(); @@ -111,6 +111,33 @@ void FToggleButton::setGeometry ( const FPoint& pos, const FSize& s 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) { @@ -121,7 +148,7 @@ bool FToggleButton::setNoUnderline (bool enable) bool FToggleButton::setEnable (bool enable) { FWidget::setEnable(enable); - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); if ( enable ) { @@ -129,20 +156,20 @@ bool FToggleButton::setEnable (bool enable) if ( hasFocus() ) { - setForegroundColor (wc.toggle_button_active_focus_fg); - setBackgroundColor (wc.toggle_button_active_focus_bg); + 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); + setForegroundColor (wc->toggle_button_active_fg); + setBackgroundColor (wc->toggle_button_active_bg); } } else { delAccelerator(); - setForegroundColor (wc.toggle_button_inactive_fg); - setBackgroundColor (wc.toggle_button_inactive_bg); + setForegroundColor (wc->toggle_button_inactive_fg); + setBackgroundColor (wc->toggle_button_inactive_bg); } return enable; @@ -155,20 +182,20 @@ bool FToggleButton::setFocus (bool enable) if ( isEnabled() ) { - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); if ( enable ) { if ( isRadioButton() ) focus_inside_group = false; - setForegroundColor (wc.toggle_button_active_focus_fg); - setBackgroundColor (wc.toggle_button_active_focus_bg); + 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); + setForegroundColor (wc->toggle_button_active_fg); + setBackgroundColor (wc->toggle_button_active_bg); } } @@ -497,46 +524,27 @@ void FToggleButton::setGroup (FButtonGroup* btngroup) void FToggleButton::init() { setGeometry (FPoint{1, 1}, FSize{4, 1}, false); // initialize geometry values - const auto& wc = getFWidgetColors(); - - 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); - } + resetColors(); } //---------------------------------------------------------------------- void FToggleButton::drawText (const FString& label_text, std::size_t hotkeypos) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(true); - const auto& wc = getFWidgetColors(); + const auto& wc = getColorTheme(); if ( isEnabled() ) - setColor (wc.label_fg, wc.label_bg); + setColor (wc->label_fg, wc->label_bg); 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++) { 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 ) setUnderline(); @@ -546,13 +554,13 @@ void FToggleButton::drawText (const FString& label_text, std::size_t hotkeypos) if ( ! flags.no_underline ) unsetUnderline(); - setColor (wc.label_fg, wc.label_bg); + setColor (wc->label_fg, wc->label_bg); } else print (label_text[z]); } - if ( isMonochron() ) + if ( FTerm::isMonochron() ) setReverse(false); } diff --git a/src/ftooltip.cpp b/src/ftooltip.cpp index 31cfbf13..ca26b639 100644 --- a/src/ftooltip.cpp +++ b/src/ftooltip.cpp @@ -34,15 +34,15 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- FToolTip::FToolTip (FWidget* parent) - : FWindow(parent) + : FWindow{parent} { init(); } //---------------------------------------------------------------------- FToolTip::FToolTip (const FString& txt, FWidget* parent) - : FWindow(parent) - , text(txt) + : FWindow{parent} + , text{txt} { init(); } @@ -73,6 +73,15 @@ void FToolTip::setText (const FString& txt) calculateDimensions(); } +//---------------------------------------------------------------------- +void FToolTip::resetColors() +{ + const auto& wc = getColorTheme(); + setForegroundColor (wc->tooltip_fg); + setBackgroundColor (wc->tooltip_bg); + FWidget::resetColors(); +} + //---------------------------------------------------------------------- bool FToolTip::setBorder (bool enable) { @@ -107,9 +116,7 @@ void FToolTip::init() // initialize geometry values setGeometry (FPoint{1, 1}, FSize{3, 3}, false); setMinimumSize (FSize{3, 3}); - const auto& wc = getFWidgetColors(); - setForegroundColor (wc.tooltip_fg); - setBackgroundColor (wc.tooltip_bg); + resetColors(); calculateDimensions(); } diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 71ba9303..b5ea316e 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -29,6 +29,7 @@ #include "final/fcharmap.h" #include "final/fcolorpair.h" #include "final/fkeyboard.h" +#include "final/flog.h" #include "final/foptiattr.h" #include "final/foptimove.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 ) return; - const int term_width = int(getColumnNumber()); - const int term_height = int(getLineNumber()); + const int term_width = int(FTerm::getColumnNumber()); + const int term_height = int(FTerm::getLineNumber()); if ( x >= term_width && term_width > 0 ) { @@ -412,7 +413,7 @@ int FVTerm::print (const std::vector& term_string) int FVTerm::print (FTermArea* area, const std::vector& term_string) { int len{0}; - const uInt tabstop = uInt(getTabstop()); + const uInt tabstop = uInt(FTerm::getTabstop()); if ( ! area ) return -1; @@ -446,7 +447,7 @@ int FVTerm::print (FTermArea* area, const std::vector& term_string) break; case '\a': - beep(); + FTerm::beep(); break; default: @@ -690,9 +691,9 @@ void FVTerm::createArea ( const FRect& box { 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; } @@ -1383,9 +1384,9 @@ inline bool FVTerm::reallocateTextArea ( FTermArea* area area->changes = new FLineChanges[height]; 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; } @@ -1404,9 +1405,9 @@ inline bool FVTerm::reallocateTextArea (FTermArea* area, std::size_t 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; } @@ -1909,9 +1910,9 @@ void FVTerm::init (bool disable_alt_screen) term_pos = new FPoint(-1, -1); output_buffer = new std::queue; } - 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"); std::abort(); } @@ -1928,7 +1929,7 @@ void FVTerm::init (bool disable_alt_screen) std::memcpy (&next_attribute, &term_attribute, sizeof(next_attribute)); // Create virtual terminal - FRect term_geometry {0, 0, getColumnNumber(), getLineNumber()}; + FRect term_geometry {0, 0, FTerm::getColumnNumber(), FTerm::getLineNumber()}; createVTerm (term_geometry.getSize()); // Create virtual desktop area @@ -2120,7 +2121,7 @@ bool FVTerm::clearTerm (int fillchar) { 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); appendOutputBuffer (cb); @@ -2753,7 +2754,7 @@ void FVTerm::printPaddingCharacter (FTermArea* area, const FChar& term_char) // Copy character to padding character std::memcpy (&pc, &term_char, sizeof(pc)); - if ( getEncoding() == fc::UTF8 ) + if ( FTerm::getEncoding() == fc::UTF8 ) { pc.ch = 0; 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 - const FRect term_geometry {0, 0, getColumnNumber(), getLineNumber()}; + const FRect term_geometry {0, 0, FTerm::getColumnNumber(), FTerm::getLineNumber()}; if ( term_geometry.contains(pos) ) return true; @@ -2910,7 +2911,7 @@ inline void FVTerm::markAsPrinted (uInt from, uInt to, uInt line) inline void FVTerm::newFontChanges (FChar*& next_char) { // NewFont special cases - if ( ! isNewFont() ) + if ( ! FTerm::isNewFont() ) return; if ( next_char->ch == fc::LowerHalfBlock ) @@ -2928,7 +2929,7 @@ inline void FVTerm::charsetChanges (FChar*& next_char) const wchar_t& ch = next_char->ch; next_char->encoded_char = ch; - if ( getEncoding() == fc::UTF8 ) + if ( FTerm::getEncoding() == fc::UTF8 ) return; 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; - if ( getEncoding() == fc::VT100 ) + if ( FTerm::getEncoding() == fc::VT100 ) 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; - if ( isPuttyTerminal() ) + if ( FTerm::isPuttyTerminal() ) 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)); else { @@ -3027,8 +3028,8 @@ int FVTerm::appendLowerRight (FChar*& screen_char) const auto& ip = TCAP(fc::t_insert_padding); const auto& ic = TCAP(fc::t_insert_character); - const int x = int(getColumnNumber()) - 2; - const int y = int(getLineNumber()) - 1; + const int x = int(FTerm::getColumnNumber()) - 2; + const int y = int(FTerm::getLineNumber()) - 1; setTermXY (x, y); appendChar (screen_char); term_pos->x_ref()++; diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 38999673..22bbf124 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -24,7 +24,9 @@ #include "final/fapplication.h" #include "final/fevent.h" +#include "final/flog.h" #include "final/fmenubar.h" +#include "final/fstartoptions.h" #include "final/fstatusbar.h" #include "final/fstring.h" #include "final/ftermdata.h" @@ -47,7 +49,6 @@ FWidget::FWidgetList* FWidget::window_list{nullptr}; FWidget::FWidgetList* FWidget::dialog_list{nullptr}; FWidget::FWidgetList* FWidget::always_on_top_list{nullptr}; FWidget::FWidgetList* FWidget::close_widget{nullptr}; -FWidgetColors FWidget::wcolors{}; bool FWidget::init_desktop{false}; bool FWidget::hideable{false}; uInt FWidget::modal_dialog_counter{}; @@ -59,8 +60,8 @@ uInt FWidget::modal_dialog_counter{}; // constructors and destructor //---------------------------------------------------------------------- FWidget::FWidget (FWidget* parent, bool disable_alt_screen) - : FVTerm( ! (bool(parent) || root_widget), disable_alt_screen) - , FObject(parent) + : FVTerm{ ! (bool(parent) || root_widget), disable_alt_screen} + , FObject{parent} { // init bit field with 0 memset (&flags, 0, sizeof(flags)); @@ -304,6 +305,42 @@ bool FWidget::setFocus (bool enable) return (flags.focus = enable); } +//---------------------------------------------------------------------- +void FWidget::resetColors() +{ + if ( ! hasChildren() ) + return; + + for (auto&& child : getChildren()) + { + if ( child->isWidget() ) + { + auto widget = static_cast(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() { @@ -537,7 +574,7 @@ void FWidget::setTermSize (const FSize& size) { // Set xterm size to width x height - if ( isXTerminal() ) + if ( FTerm::isXTerminal() ) { root_widget->wsize.setRect(FPoint{1, 1}, size); root_widget->adjust_wsize = root_widget->wsize; @@ -938,7 +975,8 @@ void FWidget::redraw() { startTerminalUpdate(); // clean desktop - setColor (wcolors.term_fg, wcolors.term_bg); + auto color_theme = getColorTheme(); + setColor (color_theme->term_fg, color_theme->term_bg); clearArea (getVirtualDesktop()); } else if ( ! isShown() ) @@ -1000,7 +1038,7 @@ void FWidget::show() if ( ! init_desktop ) { // Sets the initial screen settings - initScreenSettings(); + FTerm::initScreenSettings(); // Initializing vdesktop const auto& r = getRootWidget(); setColor(r->getForegroundColor(), r->getBackgroundColor()); @@ -1369,8 +1407,9 @@ void FWidget::hideArea (const FSize& size) } else { - fg = wcolors.dialog_fg; - bg = wcolors.dialog_bg; + auto color_theme = getColorTheme(); + fg = color_theme->dialog_fg; + bg = color_theme->dialog_bg; } setColor (fg, bg); @@ -1514,7 +1553,7 @@ bool FWidget::focusPrevChild() //---------------------------------------------------------------------- bool FWidget::event (FEvent* ev) { - switch ( uInt(ev->type()) ) + switch ( uInt(ev->getType()) ) { case fc::KeyPress_Event: KeyPressEvent (static_cast(ev)); @@ -1590,12 +1629,8 @@ bool FWidget::event (FEvent* ev) onClose (static_cast(ev)); break; - case fc::Timer_Event: - onTimer (static_cast(ev)); - break; - default: - return false; + return FObject::event(ev); } return true; @@ -1689,13 +1724,13 @@ void FWidget::initRootWidget() always_on_top_list = 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; } - hideable = isCursorHideable(); + hideable = FTerm::isCursorHideable(); flags.visible_cursor = ! hideable; // Determine width and height of the terminal @@ -1711,11 +1746,12 @@ void FWidget::initRootWidget() double_flatline_mask.left.resize (getHeight(), false); // Initialize default widget colors - setColorTheme(); + initColorTheme(); // Default foreground and background color of the desktop/terminal - foreground_color = wcolors.term_fg; - background_color = wcolors.term_bg; + auto color_theme = getColorTheme(); + foreground_color = color_theme->term_fg; + background_color = color_theme->term_bg; init_desktop = false; } @@ -1745,6 +1781,8 @@ void FWidget::finish() delete window_list; window_list = nullptr; } + + destroyColorTheme(); } //---------------------------------------------------------------------- @@ -1987,14 +2025,31 @@ void FWidget::drawChildren() } //---------------------------------------------------------------------- -void FWidget::setColorTheme() +void FWidget::initColorTheme() { // Sets the default color theme - if ( getMaxColor() < 16 ) // for 8 color mode - wcolors.set8ColorTheme(); + if ( FStartOptions::getFStartOptions().dark_theme ) + { + if ( FTerm::getMaxColor() < 16 ) // for 8 color mode + setColorTheme(); + else + setColorTheme(); + } else - wcolors.set16ColorTheme(); + { + if ( FTerm::getMaxColor() < 16 ) // for 8 color mode + setColorTheme(); + else + setColorTheme(); + } +} + +//---------------------------------------------------------------------- +void FWidget::destroyColorTheme() +{ + const FWidgetColorsPtr* theme = &(getColorTheme()); + delete theme; } //---------------------------------------------------------------------- diff --git a/src/fwidget_functions.cpp b/src/fwidget_functions.cpp index db50c947..d97426d7 100644 --- a/src/fwidget_functions.cpp +++ b/src/fwidget_functions.cpp @@ -138,11 +138,11 @@ void setHotkeyViaString (FWidget* w, const FString& text) //---------------------------------------------------------------------- void drawShadow (FWidget* w) { - if ( w->isMonochron() && ! w->flags.trans_shadow ) + if ( FTerm::isMonochron() && ! w->flags.trans_shadow ) return; - if ( (w->getEncoding() == fc::VT100 && ! w->flags.trans_shadow) - || (w->getEncoding() == fc::ASCII && ! w->flags.trans_shadow) ) + if ( (FTerm::getEncoding() == fc::VT100 && ! w->flags.trans_shadow) + || (FTerm::getEncoding() == fc::ASCII && ! w->flags.trans_shadow) ) { clearShadow(w); return; @@ -161,12 +161,12 @@ void drawTransparentShadow (FWidget* w) const std::size_t width = w->getWidth(); const std::size_t height = w->getHeight(); - const auto& wcolors = FWidget::wcolors; + const auto& wc = FWidget::getColorTheme(); w->print() << FStyle {fc::Transparent} << FPoint {int(width) + 1, 1} << " " << FStyle {fc::Reset} - << FColorPair {wcolors.shadow_bg, wcolors.shadow_fg} + << FColorPair {wc->shadow_bg, wc->shadow_fg} << FStyle {fc::ColorOverlay}; for (std::size_t y{1}; y < height; y++) @@ -178,12 +178,12 @@ void drawTransparentShadow (FWidget* w) << FPoint {1, int(height) + 1} << " " << FStyle {fc::Reset} - << FColorPair {wcolors.shadow_bg, wcolors.shadow_fg} + << FColorPair {wc->shadow_bg, wc->shadow_fg} << FStyle {fc::ColorOverlay} << FString {width, L' '} << FStyle {fc::Reset}; - if ( w->isMonochron() ) + if ( FTerm::isMonochron() ) w->setReverse(false); } @@ -192,21 +192,21 @@ void drawBlockShadow (FWidget* w) { // non-transparent shadow - if ( ! w->hasShadowCharacter() ) + if ( ! FTerm::hasShadowCharacter() ) return; const std::size_t width = w->getWidth(); const std::size_t height = w->getHeight(); - const auto& wcolors = FWidget::wcolors; + const auto& wc = FWidget::getColorTheme(); w->print() << FPoint {int(width) + 1, 1}; 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 } 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); // ▄ @@ -233,20 +233,20 @@ void drawBlockShadow (FWidget* w) //---------------------------------------------------------------------- void clearShadow (FWidget* w) { - if ( w->isMonochron() ) + if ( FTerm::isMonochron() ) return; const std::size_t width = w->getWidth(); const std::size_t height = w->getHeight(); - const auto& wcolors = FWidget::wcolors; + const auto& wc = FWidget::getColorTheme(); 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 } 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() ) { @@ -270,17 +270,17 @@ void clearShadow (FWidget* w) //---------------------------------------------------------------------- void drawFlatBorder (FWidget* w) { - if ( ! w->isNewFont() ) + if ( ! FTerm::isNewFont() ) return; const std::size_t width = w->getWidth(); const std::size_t height = w->getHeight(); - const auto& wcolors = FWidget::wcolors; + const auto& wc = FWidget::getColorTheme(); if ( auto p = w->getParentWidget() ) - w->setColor (wcolors.dialog_fg, p->getBackgroundColor()); + w->setColor (wc->dialog_fg, p->getBackgroundColor()); 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++) { @@ -331,17 +331,17 @@ void drawFlatBorder (FWidget* w) //---------------------------------------------------------------------- void clearFlatBorder (FWidget* w) { - if ( ! w->isNewFont() ) + if ( ! FTerm::isNewFont() ) return; const std::size_t width = w->getWidth(); const std::size_t height = w->getHeight(); - const auto& wcolors = FWidget::wcolors; + const auto& wc = FWidget::getColorTheme(); if ( auto p = w->getParentWidget() ) - w->setColor (wcolors.dialog_fg, p->getBackgroundColor()); + w->setColor (wc->dialog_fg, p->getBackgroundColor()); 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++) { @@ -413,7 +413,7 @@ void drawBorder (FWidget* w, const FRect& r) FRect rect = r; checkBorder (w, rect); - if ( w->isNewFont() ) + if ( FTerm::isNewFont() ) drawNewFontBox (w, rect); else drawBox (w, rect); @@ -425,7 +425,7 @@ void drawListBorder (FWidget* w, const FRect& r) FRect rect = r; checkBorder (w, rect); - if ( w->isNewFont() ) + if ( FTerm::isNewFont() ) drawNewFontListBox (w, rect); else drawBox (w, rect); diff --git a/src/fwidgetcolors.cpp b/src/fwidgetcolors.cpp index 6c3d3474..e54d4541 100644 --- a/src/fwidgetcolors.cpp +++ b/src/fwidgetcolors.cpp @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -31,9 +31,34 @@ namespace finalcut // 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_bg = fc::Blue; @@ -123,8 +148,25 @@ void FWidgetColors::set8ColorTheme() 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_bg = fc::LightBlue; @@ -217,4 +259,219 @@ void FWidgetColors::set16ColorTheme() 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 diff --git a/src/fwindow.cpp b/src/fwindow.cpp index cfa0db00..3d01dfe0 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -44,7 +44,7 @@ FWindow* FWindow::previous_window{nullptr}; // constructor and destructor //---------------------------------------------------------------------- FWindow::FWindow(FWidget* parent) - : FWidget(parent) + : FWidget{parent} { setWindowWidget(); FRect geometry {getTermGeometry()}; @@ -184,7 +184,7 @@ bool FWindow::setTransparentShadow (bool enable) //---------------------------------------------------------------------- bool FWindow::setShadow (bool enable) { - if ( isMonochron() ) + if ( FTerm::isMonochron() ) return false; if ( enable ) @@ -239,7 +239,7 @@ bool FWindow::isWindowHidden() const //---------------------------------------------------------------------- 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()}; print() << r.getUpperLeftPos() @@ -786,7 +786,7 @@ void FWindow::adjustSize() //---------------------------------------------------------------------- bool FWindow::event (FEvent* ev) { - switch ( uInt(ev->type()) ) + switch ( uInt(ev->getType()) ) { case fc::WindowActive_Event: onWindowActive (ev); @@ -882,7 +882,8 @@ void closeDropDown (FWidget* widget, const FPoint& mouse_position) if ( ! openmenu ) return; - if ( openmenu->isInstanceOf("FMenu") ) + if ( openmenu->isInstanceOf("FMenu") + || openmenu->isInstanceOf("FDialogListMenu") ) { bool contains_menu_structure; auto menu = static_cast(openmenu); diff --git a/src/include/final/emptyfstring.h b/src/include/final/emptyfstring.h index 6d2beb0f..46174f1f 100644 --- a/src/include/final/emptyfstring.h +++ b/src/include/final/emptyfstring.h @@ -20,6 +20,14 @@ * . * ***********************************************************************/ +/* Standalone class + * ════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ emptyFString ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ + #ifndef EMPTYFSTRING_H #define EMPTYFSTRING_H @@ -27,6 +35,8 @@ #error "Only can be included directly." #endif +#include "final/fapplication.h" +#include "final/flog.h" #include "final/fstring.h" namespace finalcut @@ -51,6 +61,7 @@ public: // Disable copy assignment operator (=) emptyFString& operator = (const emptyFString&) = delete; + static const FString getClassName(); static bool isNull(); static const FString& get(); static void clear(); @@ -61,6 +72,10 @@ private: }; // emptyFString inline functions +//---------------------------------------------------------------------- +inline const FString emptyFString::getClassName() +{ return "emptyFString"; } + //---------------------------------------------------------------------- inline bool emptyFString::isNull() { @@ -76,9 +91,9 @@ inline const FString& emptyFString::get() { 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"); } } diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index 52f7a8e7..aeeadb68 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -68,11 +68,12 @@ namespace finalcut { // class forward declaration -class FEvent; class FAccelEvent; class FCloseEvent; +class FEvent; class FFocusEvent; class FKeyEvent; +class FLog; class FMouseEvent; class FStartOptions; class FTimerEvent; @@ -89,6 +90,9 @@ class FObject; class FApplication : public FWidget { public: + // Typedef + typedef std::shared_ptr FLogPtr; + // Constructor FApplication (const int&, char*[], bool = false); @@ -106,6 +110,10 @@ class FApplication : public FWidget int getArgc() const; char** getArgv() const; static FApplication* getApplicationObject(); + static FLogPtr& getLog(); + + // Mutator + static void setLog (const FLogPtr&); // Inquiry static bool isQuit(); @@ -118,10 +126,13 @@ class FApplication : public FWidget void quit(); static bool sendEvent (FObject*, FEvent*); void queueEvent (FObject*, FEvent*); - void sendQueuedEvents (); + void sendQueuedEvents(); bool eventInQueue(); bool removeQueuedEvent (const FObject*); + virtual void processExternalUserEvent(); static FWidget* processParameters (const int&, char*[]); + static void setDefaultTheme(); + static void setDarkTheme(); static void showParameterUsage () #if defined(__clang__) || defined(__GNUC__) __attribute__((noreturn)) @@ -134,13 +145,14 @@ class FApplication : public FWidget private: // Typedefs - typedef std::pair > eventPair; - typedef std::deque FEventQueue; + typedef std::pair EventPair; + typedef std::deque FEventQueue; // Methods void init (uInt64, uInt64); static void cmd_options (const int&, char*[]); static FStartOptions& getStartOptions(); + void destroyLog(); void findKeyboardWidget(); bool isKeyPressed() const; void keyPressed(); @@ -177,6 +189,7 @@ class FApplication : public FWidget void processMouseEvent(); void processResizeEvent(); void processCloseWidget(); + void processLogger(); bool processNextEvent(); void performTimerAction (FObject*, FEvent*) override; static bool isEventProcessable (const FObject*, const FEvent*); diff --git a/src/include/final/fbutton.h b/src/include/final/fbutton.h index d06821ba..16d60716 100644 --- a/src/include/final/fbutton.h +++ b/src/include/final/fbutton.h @@ -88,6 +88,7 @@ class FButton : public FWidget void setFocusBackgroundColor (FColor); void setInactiveForegroundColor (FColor); void setInactiveBackgroundColor (FColor); + void resetColors() override; bool setNoUnderline(bool); bool setNoUnderline(); bool unsetNoUnderline(); @@ -157,13 +158,13 @@ class FButton : public FWidget bool click_animation{true}; int click_time{150}; int space_char{int(' ')}; - FColor button_fg{getFWidgetColors().button_active_fg}; - FColor button_bg{getFWidgetColors().button_active_bg}; - FColor button_hotkey_fg{getFWidgetColors().button_hotkey_fg}; - FColor button_focus_fg{getFWidgetColors().button_active_focus_fg}; - FColor button_focus_bg{getFWidgetColors().button_active_focus_bg}; - FColor button_inactive_fg{getFWidgetColors().button_inactive_fg}; - FColor button_inactive_bg{getFWidgetColors().button_inactive_bg}; + FColor button_fg{getColorTheme()->button_active_fg}; + FColor button_bg{getColorTheme()->button_active_bg}; + FColor button_hotkey_fg{getColorTheme()->button_hotkey_fg}; + FColor button_focus_fg{getColorTheme()->button_active_focus_fg}; + FColor button_focus_bg{getColorTheme()->button_active_focus_bg}; + FColor button_inactive_fg{getColorTheme()->button_inactive_fg}; + FColor button_inactive_bg{getColorTheme()->button_inactive_bg}; std::size_t hotkeypos{NOT_SET}; std::size_t indent{0}; std::size_t center_offset{0}; diff --git a/src/include/final/fcolorpalette.h b/src/include/final/fcolorpalette.h index 1f519f40..c9940841 100644 --- a/src/include/final/fcolorpalette.h +++ b/src/include/final/fcolorpalette.h @@ -46,27 +46,32 @@ namespace finalcut // class FColorPalette //---------------------------------------------------------------------- -class FColorPalette final +class FColorPalette { public: + // Typedef + typedef std::function FSetPalette; + // Constructor - FColorPalette() = default; + explicit FColorPalette (const FSetPalette&); // Destructor - ~FColorPalette(); + virtual ~FColorPalette(); // Accessor - const FString getClassName() const; + virtual const FString getClassName() const; // Methods - template - static void set8ColorPalette (funcT); - template - static void set16ColorPalette (funcT); - template - static void reset8ColorPalette (funcT); - template - static void reset16ColorPalette (funcT); + virtual void setColorPalette() = 0; + virtual void resetColorPalette() = 0; + + protected: + void setPalette (FColor, int, int, int); + void setVGAdefaultPalette(); + + private: + // Data members + FSetPalette set_palette; }; // FColorPalette inline functions @@ -74,85 +79,112 @@ class FColorPalette final inline const FString FColorPalette::getClassName() const { return "FColorPalette"; } -// constructors and destructor -//---------------------------------------------------------------------- -inline FColorPalette::~FColorPalette() // destructor -{ } -// public methods of FColorPalette -//---------------------------------------------------------------------- -template -void FColorPalette::set8ColorPalette (funcT set_palette) -{ - 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); - 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); -} +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FColorPalette ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ default8ColorPalette ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ //---------------------------------------------------------------------- -template -void FColorPalette::set16ColorPalette (funcT set_palette) +// class default8ColorPalette +//---------------------------------------------------------------------- + +class default8ColorPalette final : public 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, 0x55, 0x6a, 0xcf); - set_palette (fc::Red, 0xba, 0x1a, 0x1a); - set_palette (fc::Magenta, 0xb2, 0x18, 0xb2); - set_palette (fc::Brown, 0xe8, 0x87, 0x1f); - set_palette (fc::LightGray, 0xbc, 0xbc, 0xbc); - set_palette (fc::DarkGray, 0x50, 0x50, 0x50); - set_palette (fc::LightBlue, 0x80, 0xa4, 0xec); - set_palette (fc::LightGreen, 0x5e, 0xeb, 0x5c); - set_palette (fc::LightCyan, 0x62, 0xbf, 0xf8); - set_palette (fc::LightRed, 0xee, 0x44, 0x44); - set_palette (fc::LightMagenta, 0xe9, 0xad, 0xff); - set_palette (fc::Yellow, 0xfb, 0xe8, 0x67); - set_palette (fc::White, 0xff, 0xff, 0xff); -} + public: + // Constructor + explicit default8ColorPalette (const FSetPalette&); + + // Destructor + ~default8ColorPalette(); + + // Accessor + const FString getClassName() const override; + + // Methods + void setColorPalette() override; + void resetColorPalette() override; +}; + +// default8ColorPalette inline functions +//---------------------------------------------------------------------- +inline const FString default8ColorPalette::getClassName() const +{ return "default8ColorPalette"; } + + +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FColorPalette ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ default16ColorPalette ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ //---------------------------------------------------------------------- -template -void FColorPalette::reset8ColorPalette (funcT set_palette) +// class default16ColorPalette +//---------------------------------------------------------------------- + +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 -void FColorPalette::reset16ColorPalette (funcT set_palette) +// class default16DarkColorPalette +//---------------------------------------------------------------------- + +class default16DarkColorPalette final : public FColorPalette { - set_palette (fc::Black, 0x00, 0x00, 0x00); - set_palette (fc::Blue, 0x00, 0x00, 0xaa); - set_palette (fc::Green, 0x00, 0xaa, 0x00); - set_palette (fc::Cyan, 0x00, 0x55, 0xaa); - set_palette (fc::Red, 0xaa, 0x00, 0x00); - set_palette (fc::Magenta, 0xaa, 0x00, 0xaa); - set_palette (fc::Brown, 0xaa, 0xaa, 0x00); - set_palette (fc::LightGray, 0xaa, 0xaa, 0xaa); - set_palette (fc::DarkGray, 0x55, 0x55, 0x55); - set_palette (fc::LightBlue, 0x55, 0x55, 0xff); - set_palette (fc::LightGreen, 0x55, 0xff, 0x55); - set_palette (fc::LightCyan, 0x55, 0xff, 0xff); - set_palette (fc::LightRed, 0xff, 0x55, 0x55); - set_palette (fc::LightMagenta, 0xff, 0x55, 0xff); - set_palette (fc::Yellow, 0xff, 0xff, 0x55); - set_palette (fc::White, 0xff, 0xff, 0xff); -} + public: + // Constructor + explicit default16DarkColorPalette (const FSetPalette&); + + // Destructor + ~default16DarkColorPalette(); + + // Accessor + const FString getClassName() const override; + + // Methods + void setColorPalette() override; + void resetColorPalette() override; +}; + +// default16ColorPalette inline functions +//---------------------------------------------------------------------- +inline const FString default16DarkColorPalette::getClassName() const +{ return "default16DarkColorPalette"; } } // namespace finalcut diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index 424b8d02..71208971 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -108,6 +108,7 @@ class FDialog : public FWindow bool setBorder (bool); bool setBorder(); bool unsetBorder(); + void resetColors() override; virtual void setText (const FString&); // Inquiries diff --git a/src/include/final/fevent.h b/src/include/final/fevent.h index eeb0acca..0e33d66a 100644 --- a/src/include/final/fevent.h +++ b/src/include/final/fevent.h @@ -99,10 +99,18 @@ class FEvent // event base class public: FEvent() = default; explicit FEvent(fc::events); - fc::events type() const; + fc::events getType() const; + bool isQueued() const; + bool wasSent() const; private: + // Data members fc::events t{fc::None_Event}; + bool queued{false}; + bool send{false}; + + // Friend class + friend class FApplication; }; diff --git a/src/include/final/final.h b/src/include/final/final.h index e829a454..fe235835 100644 --- a/src/include/final/final.h +++ b/src/include/final/final.h @@ -49,6 +49,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/src/include/final/flabel.h b/src/include/final/flabel.h index a0a8fc97..20d55bbc 100644 --- a/src/include/final/flabel.h +++ b/src/include/final/flabel.h @@ -145,8 +145,8 @@ class FLabel : public FWidget std::size_t align_offset{0}; std::size_t hotkeypos{NOT_SET}; std::size_t column_width{0}; - FColor emphasis_color{getFWidgetColors().label_emphasis_fg}; - FColor ellipsis_color{getFWidgetColors().label_ellipsis_fg}; + FColor emphasis_color{getColorTheme()->label_emphasis_fg}; + FColor ellipsis_color{getColorTheme()->label_ellipsis_fg}; bool multiline{false}; bool emphasis{false}; bool reverse_mode{false}; diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index dacd50e8..b2cc6e14 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -120,6 +120,7 @@ class FLineEdit : public FWidget void setInputType (const inputType); void setLabelOrientation (const label_o); void setLabelAssociatedWidget (FWidget*); + void resetColors() override; void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index 5ae4058e..85742216 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -350,7 +350,7 @@ inline FListBox::FListBox ( Iterator first , Iterator last , InsertConverter convert , FWidget* parent ) - : FWidget(parent) + : FWidget{parent} { init(); @@ -366,7 +366,7 @@ template inline FListBox::FListBox ( Container container , LazyConverter convert , FWidget* parent ) - : FWidget(parent) + : FWidget{parent} { init(); insert (container, convert); diff --git a/src/include/final/flog.h b/src/include/final/flog.h new file mode 100644 index 00000000..ef5d372c --- /dev/null +++ b/src/include/final/flog.h @@ -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 * +* . * +***********************************************************************/ + +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ std::stringbuf ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▏ + * ▕ FLog ▏ + * ▕▁▁▁▁▁▁▏ + */ + +#ifndef FLOG_H +#define FLOG_H + +#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) + #error "Only can be included directly." +#endif + +#include +#include +#include +#include +#include + +#include + +namespace finalcut +{ + +//---------------------------------------------------------------------- +// class FLog +//---------------------------------------------------------------------- + +class FLog : public std::stringbuf +{ + public: + // Using-declaration + using FLogPrint = std::function; + using IOManip = std::ostream& (*)(std::ostream&); + + // Enumerations + enum LogLevel + { + Info, Warn, Error, Debug + }; + + enum LineEnding + { + LF, CR, CRLF + }; + + // Constructor + FLog(); + + // Destructor + ~FLog() override; + + template + 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 +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 diff --git a/src/include/final/flogger.h b/src/include/final/flogger.h new file mode 100644 index 00000000..cdba1192 --- /dev/null +++ b/src/include/final/flogger.h @@ -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 * +* . * +***********************************************************************/ + +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ std::stringbuf ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▏ + * ▕ FLog ▏ + * ▕▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▔▔▏ + * ▕ FLogger ▏ + * ▕▁▁▁▁▁▁▁▁▁▏ + */ + +#ifndef FLOGGER_H +#define FLOGGER_H + +#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) + #error "Only can be included directly." +#endif + +#include +#include +#include +#include + +#include +#include + +#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 diff --git a/src/include/final/fmenu.h b/src/include/final/fmenu.h index af04b2f6..282143cf 100644 --- a/src/include/final/fmenu.h +++ b/src/include/final/fmenu.h @@ -106,6 +106,7 @@ class FMenu : public FWindow, public FMenuList void setStatusbarMessage (const FString&) override; void setMenu (FMenu*); void setText (const FString&); + void resetColors() override; // Inquiries bool isSelected() const; diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index bf1e81d5..5ad7d7f1 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -86,6 +86,7 @@ class FMenuBar : public FWindow, public FMenuList const FString getClassName() const override; // Methods + void resetColors() override; void resetMenu(); void hide() override; void adjustSize() override; diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index de13ce09..7ee09d56 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -153,7 +153,7 @@ class FMessageBox : public FDialog FStringList text_components{}; FButton* button[3]{nullptr}; 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}; uInt num_buttons{0}; std::size_t text_num_lines{0}; @@ -169,8 +169,8 @@ inline const FString FMessageBox::getClassName() const //---------------------------------------------------------------------- inline const FString FMessageBox::getTitlebarText() const { - const FString& tb_text = FDialog::getText(); // initialize text - return tb_text; + const FString& title = FDialog::getText(); // initialize text + return title; } //---------------------------------------------------------------------- @@ -228,13 +228,13 @@ int FMessageBox::error ( FWidget* parent , FString() << message , button0, button1, button2 , parent ); - mbox.beep(); + FTerm::beep(); mbox.setHeadline("Warning:"); mbox.setCenterText(); - const auto& wc = mbox.getFWidgetColors(); - mbox.setForegroundColor(wc.error_box_fg); - mbox.setBackgroundColor(wc.error_box_bg); - mbox.emphasis_color = wc.error_box_emphasis_fg; + const auto& wc = getColorTheme(); + mbox.setForegroundColor(wc->error_box_fg); + mbox.setBackgroundColor(wc->error_box_bg); + mbox.emphasis_color = wc->error_box_emphasis_fg; const int reply = mbox.exec(); return reply; } diff --git a/src/include/final/fobject.h b/src/include/final/fobject.h index 2bab65e4..0e68c500 100644 --- a/src/include/final/fobject.h +++ b/src/include/final/fobject.h @@ -48,6 +48,8 @@ #include #include +#include "final/fstring.h" + namespace finalcut { diff --git a/src/include/final/fpoint.h b/src/include/final/fpoint.h index 20cb59fd..a3ae4b22 100644 --- a/src/include/final/fpoint.h +++ b/src/include/final/fpoint.h @@ -103,20 +103,20 @@ class FPoint // FPoint inline functions //---------------------------------------------------------------------- inline FPoint::FPoint (const FPoint& p) // copy constructor - : xpos(p.xpos) - , ypos(p.ypos) + : xpos{p.xpos} + , ypos{p.ypos} { } //---------------------------------------------------------------------- inline FPoint::FPoint (FPoint&& p) noexcept // move constructor - : xpos(std::move(p.xpos)) - , ypos(std::move(p.ypos)) + : xpos{std::move(p.xpos)} + , ypos{std::move(p.ypos)} { } //---------------------------------------------------------------------- inline FPoint::FPoint (int x, int y) - : xpos(x) - , ypos(y) + : xpos{x} + , ypos{y} { } //---------------------------------------------------------------------- diff --git a/src/include/final/frect.h b/src/include/final/frect.h index b874a58e..1e538437 100644 --- a/src/include/final/frect.h +++ b/src/include/final/frect.h @@ -148,26 +148,26 @@ class FRect // FRect inline functions //---------------------------------------------------------------------- inline FRect::FRect (const FRect& r) // copy constructor - : X1(r.X1) - , Y1(r.Y1) - , X2(r.X2) - , Y2(r.Y2) + : X1{r.X1} + , Y1{r.Y1} + , X2{r.X2} + , Y2{r.Y2} { } //---------------------------------------------------------------------- inline FRect::FRect (FRect&& r) noexcept // move constructor - : X1(std::move(r.X1)) - , Y1(std::move(r.Y1)) - , X2(std::move(r.X2)) - , Y2(std::move(r.Y2)) + : X1{std::move(r.X1)} + , Y1{std::move(r.Y1)} + , X2{std::move(r.X2)} + , Y2{std::move(r.Y2)} { } //---------------------------------------------------------------------- inline FRect::FRect (int x, int y, std::size_t width, std::size_t height) - : X1(x) - , Y1(y) - , X2(x + int(width) - 1) - , Y2(y + int(height) - 1) + : X1{x} + , Y1{y} + , X2{x + int(width) - 1} + , Y2{y + int(height) - 1} { } //---------------------------------------------------------------------- diff --git a/src/include/final/fscrollbar.h b/src/include/final/fscrollbar.h index 61eb4635..164afe8f 100644 --- a/src/include/final/fscrollbar.h +++ b/src/include/final/fscrollbar.h @@ -50,6 +50,8 @@ #include #include +#include "final/fapplication.h" +#include "final/flog.h" #include "final/fwidget.h" namespace finalcut @@ -150,7 +152,7 @@ class FScrollbar : public FWidget sType scroll_type{FScrollbar::noScroll}; bool threshold_reached{false}; int threshold_time{500}; - int repeat_time{10}; + int repeat_time{80}; int slider_click_pos{-1}; int slider_click_stop_pos{-1}; int current_slider_pos{-1}; @@ -164,7 +166,7 @@ class FScrollbar : public FWidget double steps{1}; std::size_t length{20}; fc::orientation bar_orientation{fc::vertical}; - int max_color{getMaxColor()}; + int max_color{FTerm::getMaxColor()}; }; @@ -180,9 +182,9 @@ void initScrollbar ( FScrollbarPtr& bar { bar = std::make_shared(o, cb_instance); } - catch (const std::bad_alloc& ex) + catch (const std::bad_alloc&) { - std::cerr << bad_alloc_str << ex.what() << std::endl; + badAllocOutput ("FScrollbar"); return; } diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index 12bffba8..83cef868 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -108,6 +108,7 @@ class FScrollView : public FWidget bool setViewportPrint (bool); bool setViewportPrint(); bool unsetViewportPrint(); + void resetColors() override; bool setBorder (bool); bool setBorder(); bool unsetBorder(); diff --git a/src/include/final/fsize.h b/src/include/final/fsize.h index 596435e1..fe6373b7 100644 --- a/src/include/final/fsize.h +++ b/src/include/final/fsize.h @@ -112,20 +112,20 @@ class FSize // FSize inline functions //---------------------------------------------------------------------- inline FSize::FSize (const FSize& s) // copy constructor - : width(s.width) - , height(s.height) + : width{s.width} + , height{s.height} { } //---------------------------------------------------------------------- inline FSize::FSize (FSize&& s) noexcept // move constructor - : width(std::move(s.width)) - , height(std::move(s.height)) + : width{std::move(s.width)} + , height{std::move(s.height)} { } //---------------------------------------------------------------------- inline FSize::FSize (std::size_t w, std::size_t h) - : width(w) - , height(h) + : width{w} + , height{h} { } //---------------------------------------------------------------------- diff --git a/src/include/final/fspinbox.h b/src/include/final/fspinbox.h index ed6a4b4f..58d26506 100644 --- a/src/include/final/fspinbox.h +++ b/src/include/final/fspinbox.h @@ -151,7 +151,7 @@ class FSpinBox : public FWidget spiningState spining_state{FSpinBox::noSpin}; bool threshold_reached{false}; int threshold_time{500}; - int repeat_time{10}; + int repeat_time{80}; }; diff --git a/src/include/final/fstartoptions.h b/src/include/final/fstartoptions.h index b9e7bac1..c541559e 100644 --- a/src/include/final/fstartoptions.h +++ b/src/include/final/fstartoptions.h @@ -64,7 +64,7 @@ class FStartOptions final FStartOptions& operator = (const FStartOptions&) = delete; // Accessors - const FString getClassName(); + static const FString getClassName(); static FStartOptions& getFStartOptions(); // Mutator @@ -93,6 +93,8 @@ class FStartOptions final uInt8 : 7; // padding bits #endif + uInt16 dark_theme : 1; + uInt16 : 15; // padding bits static FStartOptions* start_options; }; diff --git a/src/include/final/fstatusbar.h b/src/include/final/fstatusbar.h index 2a86d383..f9b3f961 100644 --- a/src/include/final/fstatusbar.h +++ b/src/include/final/fstatusbar.h @@ -205,6 +205,7 @@ class FStatusBar : public FWindow void activateKey (int); void deactivateKey (int); void setMessage (const FString&); + void resetColors() override; // Inquiries bool isActivated (int) const; diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index 91c520ad..ae8c7ef6 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -87,8 +87,8 @@ class FString explicit FString (int); explicit FString (std::size_t); FString (std::size_t, wchar_t); - FString (const FString&); // implicit conversion copy constructor - FString (FString&&) noexcept; // implicit conversion move constructor + FString (const FString&); // copy constructor + FString (FString&&) noexcept; // move constructor FString (const std::wstring&); // implicit conversion constructor FString (const wchar_t[]); // implicit conversion constructor FString (const std::string&); // implicit conversion constructor @@ -162,7 +162,7 @@ class FString operator const char* () const { return c_str(); } // Accessor - virtual const FString getClassName(); + virtual const FString getClassName() const; // inquiries bool isNull() const; @@ -247,14 +247,14 @@ class FString static constexpr uInt CHAR_SIZE = sizeof(wchar_t); // bytes per character // Methods - void initLength (std::size_t); - void _assign (const wchar_t[]); - void _insert (std::size_t, const wchar_t[]); - void _insert (std::size_t, std::size_t, const wchar_t[]); - void _remove (std::size_t, std::size_t); - char* wc_to_c_str (const wchar_t[]) const; - wchar_t* c_to_wc_str (const char[]) const; - wchar_t* extractToken (wchar_t*[], const wchar_t[], const wchar_t[]); + void _initLength (std::size_t); + void _assign (const wchar_t[]); + void _insert (std::size_t, const wchar_t[]); + void _insert (std::size_t, std::size_t, const wchar_t[]); + void _remove (std::size_t, std::size_t); + const char* _to_cstring (const wchar_t[]) const; + const wchar_t* _to_wcstring (const char[]) const; + const wchar_t* _extractToken (wchar_t*[], const wchar_t[], const wchar_t[]); // Data members wchar_t* string{nullptr}; @@ -370,16 +370,16 @@ inline bool FString::operator > (const CharT& s) const } //---------------------------------------------------------------------- -inline const FString FString::getClassName() +inline const FString FString::getClassName() const { return "FString"; } //---------------------------------------------------------------------- inline bool FString::isNull() const -{ return ! string; } +{ return ( bufsize == 0 || (bufsize > 0 && ! string) ); } //---------------------------------------------------------------------- inline bool FString::isEmpty() const -{ return ( ! string ) || ( ! *string ); } +{ return ( length == 0 || (length > 0 && string[0] == L'\0') ); } //---------------------------------------------------------------------- inline std::size_t FString::getLength() const diff --git a/src/include/final/fstringstream.h b/src/include/final/fstringstream.h new file mode 100644 index 00000000..e0c111c8 --- /dev/null +++ b/src/include/final/fstringstream.h @@ -0,0 +1,120 @@ +/*********************************************************************** +* fstringstream.h - 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 * +* . * +***********************************************************************/ + +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ std::wiostream ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FStringStream ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ + +#ifndef FSTRINGSTREAM_H +#define FSTRINGSTREAM_H + +#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) + #error "Only can be included directly." +#endif + +#include +#include +#include + +namespace finalcut +{ + +// class forward declaration +class FString; + +//---------------------------------------------------------------------- +// class FStringStream +//---------------------------------------------------------------------- + +class FStringStream : public std::wiostream +{ + public: + using std::ios_base::openmode; + static constexpr openmode in_out = std::ios_base::out + | std::ios_base::in; + + // Constructors + explicit FStringStream (openmode = in_out); + explicit FStringStream (const FString&, openmode = in_out); + + // Disable copy constructor + FStringStream (const FStringStream&) = delete; + + // Move constructor + FStringStream (FStringStream&&) noexcept; + + // Destructor + ~FStringStream(); + + // Disable copy assignment operator (=) + FStringStream& operator = (const FStringStream&) = delete; + + // Move assignment operator (=) + FStringStream& operator = (FStringStream&& sstream) noexcept; + + virtual const FString getClassName() const; + void swap (FStringStream&) noexcept; + void clear(); + std::wstringbuf* rdbuf() const; + FString str() const; + + private: + std::wstringbuf buffer{in_out}; +}; + + +// FStringStream inline functions +//---------------------------------------------------------------------- +inline const FString FStringStream::getClassName() const +{ return "FStringStream"; } + +//---------------------------------------------------------------------- +inline void FStringStream::clear() +{ buffer.str(L""); } + +//---------------------------------------------------------------------- +inline std::wstringbuf* FStringStream::rdbuf() const +{ return const_cast(&buffer); } + +//---------------------------------------------------------------------- +inline FString FStringStream::str() const +{ return buffer.str(); } + + +// FStringStream non-member function +//---------------------------------------------------------------------- +inline void swap (FStringStream& a, FStringStream& b) noexcept +{ a.swap(b); } + + +} // namespace finalcut + +#endif // FSTRINGSTREAM_H diff --git a/src/include/final/fsystem.h b/src/include/final/fsystem.h index 483decb3..38b98868 100644 --- a/src/include/final/fsystem.h +++ b/src/include/final/fsystem.h @@ -78,5 +78,3 @@ class FSystem } // namespace finalcut #endif // FSYSTEM_H - - diff --git a/src/include/final/fsystemimpl.h b/src/include/final/fsystemimpl.h index 4fda025a..44d8c687 100644 --- a/src/include/final/fsystemimpl.h +++ b/src/include/final/fsystemimpl.h @@ -20,12 +20,17 @@ * . * ***********************************************************************/ -/* Standalone class - * ════════════════ +/* Inheritance diagram + * ═══════════════════ * - * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏ - * ▕ FSystemImpl ▏ - * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▕▔▔▔▔▔▔▔▔▔▏ + * ▕ FSystem ▏ + * ▕▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FSystemImpl ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏ */ #ifndef FSYSTEMIMPL_H diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 7f3f2e8f..ff8fd129 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -112,12 +112,14 @@ #include #include #include +#include #include #include #include #include #include "final/fc.h" +#include "final/fcolorpalette.h" #include "final/fstring.h" #include "final/fsystem.h" @@ -125,6 +127,7 @@ namespace finalcut { // class forward declaration +class FColorPalette; class FKeyboard; class FMouseControl; class FOptiAttr; @@ -159,6 +162,8 @@ class FTerm final public: // Typedef typedef std::function defaultPutChar; + typedef std::shared_ptr FColorPalettePtr; + typedef FColorPalette::FSetPalette FSetPalette; // Constructor explicit FTerm (bool = false); @@ -173,213 +178,219 @@ class FTerm final FTerm& operator = (const FTerm&) = delete; // Accessors - const FString getClassName() const; - static std::size_t getLineNumber(); - static std::size_t getColumnNumber(); - static const FString getKeyName (FKey); - static int getTTYFileDescriptor(); - static const char* getTermType(); - static const char* getTermFileName(); - static int getTabstop(); - static int getMaxColor(); - charSubstitution& getCharSubstitutionMap(); + static const FString getClassName(); + static std::size_t getLineNumber(); + static std::size_t getColumnNumber(); + static const FString getKeyName (FKey); + static int getTTYFileDescriptor(); + static const char* getTermType(); + static const char* getTermFileName(); + static int getTabstop(); + static int getMaxColor(); + static FColorPalettePtr& getColorPaletteTheme(); + charSubstitution& getCharSubstitutionMap(); - static FTermData* getFTermData(); - static FSystem* getFSystem(); - static FOptiMove* getFOptiMove(); - static FOptiAttr* getFOptiAttr(); - static FTermDetection* getFTermDetection(); - static FTermXTerminal* getFTermXTerminal(); - static FKeyboard* getFKeyboard(); - static FMouseControl* getFMouseControl(); + static FTermData* getFTermData(); + static FSystem* getFSystem(); + static FOptiMove* getFOptiMove(); + static FOptiAttr* getFOptiAttr(); + static FTermDetection* getFTermDetection(); + static FTermXTerminal* getFTermXTerminal(); + static FKeyboard* getFKeyboard(); + static FMouseControl* getFMouseControl(); #if defined(UNIT_TEST) - static FTermLinux* getFTermLinux(); - static FTermFreeBSD* getFTermFreeBSD(); - static FTermOpenBSD* getFTermOpenBSD(); + static FTermLinux* getFTermLinux(); + static FTermFreeBSD* getFTermFreeBSD(); + static FTermOpenBSD* getFTermOpenBSD(); #elif defined(__linux__) - static FTermLinux* getFTermLinux(); + static FTermLinux* getFTermLinux(); #elif defined(__FreeBSD__) || defined(__DragonFly__) - static FTermFreeBSD* getFTermFreeBSD(); + static FTermFreeBSD* getFTermFreeBSD(); #elif defined(__NetBSD__) || defined(__OpenBSD__) - static FTermOpenBSD* getFTermOpenBSD(); + static FTermOpenBSD* getFTermOpenBSD(); #endif #if DEBUG - static FTermDebugData& getFTermDebugData(); + static FTermDebugData& getFTermDebugData(); #endif // Inquiries - static bool isNormal (const FChar* const&); - static bool isRaw(); - static bool hasUTF8(); - static bool hasVT100(); - static bool hasASCII(); - static bool isMonochron(); - static bool isXTerminal(); - static bool isAnsiTerminal(); - static bool isRxvtTerminal(); - static bool isUrxvtTerminal(); - static bool isMltermTerminal(); - static bool isPuttyTerminal(); - static bool isKdeTerminal(); - static bool isGnomeTerminal(); - static bool isKtermTerminal(); - static bool isTeraTerm(); - static bool isSunTerminal(); - static bool isCygwinTerminal(); - static bool isMinttyTerm(); - static bool isLinuxTerm(); - static bool isFreeBSDTerm(); - static bool isNetBSDTerm(); - static bool isOpenBSDTerm(); - static bool isScreenTerm(); - static bool isTmuxTerm(); - static bool isNewFont(); - static bool isCursorHideable(); - static bool hasChangedTermSize(); - static bool hasShadowCharacter(); - static bool hasHalfBlockCharacter(); - static bool hasAlternateScreen(); - static bool canChangeColorPalette(); + static bool isNormal (const FChar* const&); + static bool isRaw(); + static bool hasUTF8(); + static bool hasVT100(); + static bool hasASCII(); + static bool isMonochron(); + static bool isXTerminal(); + static bool isAnsiTerminal(); + static bool isRxvtTerminal(); + static bool isUrxvtTerminal(); + static bool isMltermTerminal(); + static bool isPuttyTerminal(); + static bool isKdeTerminal(); + static bool isGnomeTerminal(); + static bool isKtermTerminal(); + static bool isTeraTerm(); + static bool isSunTerminal(); + static bool isCygwinTerminal(); + static bool isMinttyTerm(); + static bool isLinuxTerm(); + static bool isFreeBSDTerm(); + static bool isNetBSDTerm(); + static bool isOpenBSDTerm(); + static bool isScreenTerm(); + static bool isTmuxTerm(); + static bool isNewFont(); + static bool isCursorHideable(); + static bool hasChangedTermSize(); + static bool hasShadowCharacter(); + static bool hasHalfBlockCharacter(); + static bool hasAlternateScreen(); + static bool canChangeColorPalette(); // Mutators - static void setFSystem (FSystem*); - static void setTermType (const char[]); - static void setInsertCursor (bool); - static void redefineDefaultColors (bool); - static void setDblclickInterval (const uInt64); - static bool setUTF8 (bool); - static bool setUTF8(); - static bool unsetUTF8(); + static void setFSystem (FSystem*); + static void setTermType (const char[]); + static void setInsertCursor (bool); + static void setInsertCursor(); + static void unsetInsertCursor(); + static void redefineDefaultColors (bool); + static void setDblclickInterval (const uInt64); + static bool setUTF8 (bool); + static bool setUTF8(); + static bool unsetUTF8(); // Methods - static bool setVGAFont(); - static bool setNewFont(); - static bool setOldFont(); - static int openConsole(); - static int closeConsole(); - static const char* moveCursorString (int, int, int, int); - static const char* cursorsVisibilityString (bool); - static void detectTermSize(); - static void setTermSize (const FSize&); - static void setTermTitle (const FString&); - static void setKDECursor (fc::kdeKonsoleCursorShape); - static void saveColorMap(); - static void resetColorMap(); - static void setPalette (FColor, int, int, int); - static void setBeep (int, int); - static void resetBeep(); - static void beep(); + static bool setVGAFont(); + static bool setNewFont(); + static bool setOldFont(); + static int openConsole(); + static int closeConsole(); + static const char* moveCursorString (int, int, int, int); + static const char* cursorsVisibilityString (bool); + static void detectTermSize(); + static void setTermSize (const FSize&); + static void setTermTitle (const FString&); + static void setKDECursor (fc::kdeKonsoleCursorShape); + static void saveColorMap(); + static void resetColorMap(); + static void setPalette (FColor, int, int, int); + template + static void setColorPaletteTheme (const FSetPalette&); + static void setBeep (int, int); + static void resetBeep(); + static void beep(); - static void setEncoding (fc::encoding); - static fc::encoding getEncoding(); - static std::string getEncodingString(); - static bool charEncodable (wchar_t); - static wchar_t charEncode (wchar_t); - static wchar_t charEncode (wchar_t, fc::encoding); + static void setEncoding (fc::encoding); + static fc::encoding getEncoding(); + static std::string getEncodingString(); + static bool charEncodable (wchar_t); + static wchar_t charEncode (wchar_t); + static wchar_t charEncode (wchar_t, fc::encoding); - static bool scrollTermForward(); - static bool scrollTermReverse(); + static bool scrollTermForward(); + static bool scrollTermReverse(); - static defaultPutChar& putchar(); // function pointer + static defaultPutChar& putchar(); // function pointer template - static void putstringf (const char[], Args&&...); - static void putstring (const char[], int = 1); - static int putchar_ASCII (int); - static int putchar_UTF8 (int); + static void putstringf (const char[], Args&&...); + static void putstring (const char[], int = 1); + static int putchar_ASCII (int); + static int putchar_UTF8 (int); - static void initScreenSettings(); - static const char* changeAttribute (FChar*&, FChar*&); - static void changeTermSizeFinished(); - static void exitWithMessage (const FString&) + static void initScreenSettings(); + static const char* changeAttribute (FChar*&, FChar*&); + static void changeTermSizeFinished(); + static void exitWithMessage (const FString&) #if defined(__clang__) || defined(__GNUC__) __attribute__((noreturn)) #endif - ; + ; private: // Methods - static FStartOptions& getStartOptions(); - static void init_global_values (bool); - static void init_terminal_device_path(); - static void oscPrefix(); - static void oscPostfix(); - static void init_alt_charset(); - static void init_pc_charset(); - static void init_cygwin_charmap(); - static void init_teraterm_charmap(); - static void init_fixed_max_color(); - static void init_keyboard(); - static void init_termcap(); - static void init_quirks(); - static void init_optiMove(); - static void init_optiAttr(); - static void init_font(); - static void init_locale(); - static void init_encoding(); - static void init_encoding_set(); - static void init_term_encoding(); - static void init_individual_term_encoding(); - static void init_force_vt100_encoding(); - static void init_utf8_without_alt_charset(); - static void init_tab_quirks(); - static void init_captureFontAndTitle(); - static bool hasNoFontSettingOption(); - static void redefineColorPalette(); - static void restoreColorPalette(); - static void setInsertCursorStyle(); - static void setOverwriteCursorStyle(); - static const char* enableCursorString(); - static const char* disableCursorString(); - static void enableMouse(); - static void disableMouse(); - static void enableApplicationEscKey(); - static void disableApplicationEscKey(); - static void enableKeypad(); - static void disableKeypad(); - static void enableAlternateCharset(); - static void useAlternateScreenBuffer(); - static void useNormalScreenBuffer(); - void allocationValues(); - void deallocationValues(); - void init (bool); - bool init_terminal(); - void initOSspecifics(); - void initTermspecifics(); - void initBaudRate(); - void finish(); - void finishOSspecifics1(); - void finish_encoding(); - static void setSignalHandler(); - static void resetSignalHandler(); - static void signal_handler (int); + static FStartOptions& getStartOptions(); + static void init_global_values (bool); + static void init_terminal_device_path(); + static void oscPrefix(); + static void oscPostfix(); + static void init_alt_charset(); + static void init_pc_charset(); + static void init_cygwin_charmap(); + static void init_teraterm_charmap(); + static void init_fixed_max_color(); + static void init_keyboard(); + static void init_termcap(); + static void init_quirks(); + static void init_optiMove(); + static void init_optiAttr(); + static void init_font(); + static void init_locale(); + static void init_encoding(); + static void init_encoding_set(); + static void init_term_encoding(); + static void init_individual_term_encoding(); + static void init_force_vt100_encoding(); + static void init_utf8_without_alt_charset(); + static void init_tab_quirks(); + static void init_captureFontAndTitle(); + static bool hasNoFontSettingOption(); + static void redefineColorPalette(); + static void restoreColorPalette(); + static void setInsertCursorStyle(); + static void setOverwriteCursorStyle(); + static const char* enableCursorString(); + static const char* disableCursorString(); + static void enableMouse(); + static void disableMouse(); + static void enableApplicationEscKey(); + static void disableApplicationEscKey(); + static void enableKeypad(); + static void disableKeypad(); + static void enableAlternateCharset(); + static void useAlternateScreenBuffer(); + static void useNormalScreenBuffer(); + void allocationValues(); + void deallocationValues(); + void init (bool); + bool init_terminal(); + void initOSspecifics(); + void initTermspecifics(); + void initBaudRate(); + void finish(); + void finishOSspecifics1(); + void finish_encoding(); + void destroyColorPaletteTheme(); + static void setSignalHandler(); + static void resetSignalHandler(); + static void signal_handler (int); // Data members - static FTermData* data; - static FSystem* fsys; - static FOptiMove* opti_move; - static FOptiAttr* opti_attr; - static FTermDetection* term_detection; - static FTermXTerminal* xterm; - static FKeyboard* keyboard; - static FMouseControl* mouse; + static FTermData* data; + static FSystem* fsys; + static FOptiMove* opti_move; + static FOptiAttr* opti_attr; + static FTermDetection* term_detection; + static FTermXTerminal* xterm; + static FKeyboard* keyboard; + static FMouseControl* mouse; #if defined(UNIT_TEST) #undef linux - static FTermLinux* linux; - static FTermFreeBSD* freebsd; - static FTermOpenBSD* openbsd; + static FTermLinux* linux; + static FTermFreeBSD* freebsd; + static FTermOpenBSD* openbsd; #elif defined(__linux__) #undef linux - static FTermLinux* linux; + static FTermLinux* linux; #elif defined(__FreeBSD__) || defined(__DragonFly__) - static FTermFreeBSD* freebsd; + static FTermFreeBSD* freebsd; #elif defined(__NetBSD__) || defined(__OpenBSD__) - static FTermOpenBSD* openbsd; + static FTermOpenBSD* openbsd; #endif #if DEBUG - static FTermDebugData* debug_data; + static FTermDebugData* debug_data; #endif }; @@ -405,13 +416,21 @@ std::size_t getColumnWidth (const FTermBuffer&); // FTerm inline functions //---------------------------------------------------------------------- -inline const FString FTerm::getClassName() const +inline const FString FTerm::getClassName() { return "FTerm"; } //---------------------------------------------------------------------- inline void FTerm::setFSystem (FSystem* fsystem) { fsys = fsystem; } +//---------------------------------------------------------------------- +inline void FTerm::setInsertCursor() +{ return setInsertCursor(true); } + +//---------------------------------------------------------------------- +inline void FTerm::unsetInsertCursor() +{ return setInsertCursor(false); } + //---------------------------------------------------------------------- inline bool FTerm::setUTF8() { return setUTF8(true); } @@ -420,6 +439,14 @@ inline bool FTerm::setUTF8() inline bool FTerm::unsetUTF8() { return setUTF8(false); } +//---------------------------------------------------------------------- +template +inline void FTerm::setColorPaletteTheme (const FSetPalette& f) +{ + getColorPaletteTheme() = std::make_shared(f); + getColorPaletteTheme()->setColorPalette(); +} + //---------------------------------------------------------------------- template inline void FTerm::putstringf (const char format[], Args&&... args) diff --git a/src/include/final/ftermbuffer.h b/src/include/final/ftermbuffer.h index 6f55a5d2..84fa4a0e 100644 --- a/src/include/final/ftermbuffer.h +++ b/src/include/final/ftermbuffer.h @@ -35,11 +35,12 @@ #error "Only can be included directly." #endif -#include // std::stringstream #include #include #include +#include "final/fstringstream.h" + namespace finalcut { @@ -122,10 +123,10 @@ inline FTermBuffer::FTermBuffer(Iterator first, Iterator last) template inline FTermBuffer& FTermBuffer::operator << (const typeT& s) { - std::wostringstream outstream; + FStringStream outstream{std::ios_base::out}; outstream << s; - if ( ! outstream.str().empty() ) + if ( ! outstream.str().isEmpty() ) write (outstream.str()); return *this; diff --git a/src/include/final/ftermcap.h b/src/include/final/ftermcap.h index 1a8c3cb9..3d26e3ac 100644 --- a/src/include/final/ftermcap.h +++ b/src/include/final/ftermcap.h @@ -126,6 +126,9 @@ class FTermcap final static tcap_map strings[]; private: + // Constant + static constexpr std::size_t BUF_SIZE{2048}; + // Methods static void termcap(); static void termcapError (int); @@ -140,7 +143,7 @@ class FTermcap final static FSystem* fsystem; static FTermData* fterm_data; static FTermDetection* term_detection; - static char string_buf[2048]; + static char string_buf[BUF_SIZE]; }; @@ -153,35 +156,35 @@ inline const FString FTermcap::getClassName() const template bool FTermcap::getFlag (const CharT& cap) { - return tgetflag(C_STR(cap)); + return ::tgetflag(C_STR(cap)); } //---------------------------------------------------------------------- template int FTermcap::getNumber (const CharT& cap) { - return tgetnum(C_STR(cap)); + return ::tgetnum(C_STR(cap)); } //---------------------------------------------------------------------- template char* FTermcap::getString (const CharT& cap) { - return tgetstr(C_STR(cap), reinterpret_cast(&string_buf)); + return ::tgetstr(C_STR(cap), reinterpret_cast(&string_buf)); } //---------------------------------------------------------------------- template char* FTermcap::encodeMotionParameter (const CharT& cap, int col, int row) { - return tgoto(C_STR(cap), col, row); + return ::tgoto(C_STR(cap), col, row); } //---------------------------------------------------------------------- template inline char* FTermcap::encodeParameter (const CharT& cap, Args&&... args) { - return tparm (C_STR(cap), std::forward(args)...); + return ::tparm (C_STR(cap), std::forward(args)...); } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermdata.h b/src/include/final/ftermdata.h index 93b0b3e4..d14e3d52 100644 --- a/src/include/final/ftermdata.h +++ b/src/include/final/ftermdata.h @@ -373,5 +373,3 @@ inline void FTermData::setFramebufferBpp (int bpp) } // namespace finalcut #endif // FTERMDATA_H - - diff --git a/src/include/final/ftermdetection.h b/src/include/final/ftermdetection.h index d68ca07c..f17786d3 100644 --- a/src/include/final/ftermdetection.h +++ b/src/include/final/ftermdetection.h @@ -91,7 +91,7 @@ class FTermDetection final FTermDetection& operator = (const FTermDetection&) = delete; // Accessor - const FString getClassName() const; + static const FString getClassName(); static const char* getTermType(); static int getGnomeTerminalID(); FTerminalType& getTermTypeStruct(); @@ -240,7 +240,7 @@ struct FTermDetection::secondaryDA // FTermDetection inline functions //---------------------------------------------------------------------- -inline const FString FTermDetection::getClassName() const +inline const FString FTermDetection::getClassName() { return "FTermDetection"; } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermfreebsd.h b/src/include/final/ftermfreebsd.h index da7aaf08..130f980a 100644 --- a/src/include/final/ftermfreebsd.h +++ b/src/include/final/ftermfreebsd.h @@ -117,11 +117,13 @@ class FTermFreeBSD final private: // Methods + static void warnNotInitialized(); static bool saveFreeBSDAltKey(); static bool setFreeBSDAltKey (uInt); static bool setFreeBSDAlt2Meta(); static bool resetFreeBSDAlt2Meta(); static bool setFreeBSDCursorStyle (CursorStyle); + static bool isInitialized(); // Data members static uInt bsd_alt_keymap; @@ -154,6 +156,10 @@ inline void FTermFreeBSD::enableMetaSendsEscape() //---------------------------------------------------------------------- inline void FTermFreeBSD::disableMetaSendsEscape() { meta_sends_escape = false; } + +//---------------------------------------------------------------------- +inline bool FTermFreeBSD::isInitialized() +{ return bool(fsystem && fterm_data); } #endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) } // namespace finalcut diff --git a/src/include/final/ftermopenbsd.h b/src/include/final/ftermopenbsd.h index 051fa1e2..00843e3f 100644 --- a/src/include/final/ftermopenbsd.h +++ b/src/include/final/ftermopenbsd.h @@ -105,10 +105,12 @@ class FTermOpenBSD final #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) private: // Methods + static void warnNotInitialized(); static bool saveBSDConsoleEncoding(); static bool setBSDConsoleEncoding (kbd_t); static bool setBSDConsoleMetaEsc(); static bool resetBSDConsoleEncoding(); + static bool isInitialized(); // Data members static kbd_t bsd_keyboard_encoding; @@ -131,6 +133,10 @@ inline void FTermOpenBSD::enableMetaSendsEscape() //---------------------------------------------------------------------- inline void FTermOpenBSD::disableMetaSendsEscape() { meta_sends_escape = false; } + +//---------------------------------------------------------------------- +inline bool FTermOpenBSD::isInitialized() +{ return bool(fsystem); } #endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) } // namespace finalcut diff --git a/src/include/final/ftermxterminal.h b/src/include/final/ftermxterminal.h index b7ed001e..17058d0b 100644 --- a/src/include/final/ftermxterminal.h +++ b/src/include/final/ftermxterminal.h @@ -110,6 +110,7 @@ class FTermXTerminal final private: // Methods + void warnNotInitialized(); void setXTermCursorStyle(); void setXTermFont(); void setXTermTitle(); @@ -131,6 +132,7 @@ class FTermXTerminal final void resetXTermMouseForeground(); void resetXTermMouseBackground(); void resetXTermHighlightBackground(); + bool isInitialized(); bool canResetColor(); void oscPrefix(); void oscPostfix(); @@ -222,6 +224,10 @@ inline void FTermXTerminal::setMouseSupport() inline void FTermXTerminal::unsetMouseSupport() { setMouseSupport (false); } +//---------------------------------------------------------------------- +inline bool FTermXTerminal::isInitialized() +{ return bool(fsystem && term_detection); } + } // namespace finalcut #endif // FTERMXTERMINAL_H diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index d968a8d4..6443bb1a 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -51,6 +51,7 @@ #include #include +#include "final/fstringstream.h" #include "final/fwidget.h" namespace finalcut @@ -99,11 +100,14 @@ class FTextView : public FWidget void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; + void resetColors() override; void setText (const FString&); void scrollToX (int); void scrollToY (int); void scrollTo (const FPoint&); void scrollTo (int, int); + void scrollToBegin(); + void scrollToEnd(); void scrollBy (int, int); // Methods @@ -184,10 +188,10 @@ inline FTextView& FTextView::operator = (const FString& s) template inline FTextView& FTextView::operator << (const typeT& s) { - std::wostringstream outstream; + FStringStream outstream{std::ios_base::out}; outstream << s; - if ( ! outstream.str().empty() ) + if ( ! outstream.str().isEmpty() ) append (outstream.str()); return *this; diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 60f10601..d00080d4 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -86,6 +86,7 @@ class FToggleButton : public FWidget void setSize (const FSize&, bool = true) override; void setGeometry ( const FPoint&, const FSize& , bool = true ) override; + void resetColors() override; bool setNoUnderline (bool); bool setNoUnderline(); bool unsetNoUnderline(); diff --git a/src/include/final/ftooltip.h b/src/include/final/ftooltip.h index 16769727..605f0a7a 100644 --- a/src/include/final/ftooltip.h +++ b/src/include/final/ftooltip.h @@ -85,6 +85,7 @@ class FToolTip : public FWindow // Mutators void setText (const FString&); + void resetColors() override; bool setBorder (bool); bool setBorder(); bool unsetBorder(); diff --git a/src/include/final/ftypes.h b/src/include/final/ftypes.h index 395a8bd5..ff35a9ec 100644 --- a/src/include/final/ftypes.h +++ b/src/include/final/ftypes.h @@ -37,6 +37,14 @@ #define null nullptr +#define badAllocOutput(object_name) \ + *FApplication::getLog() << FLog::Error \ + << __FILE__ << ":" << __LINE__ \ + << ": Not enough memory to alloc " \ + << (object_name) \ + << " in " \ + << __func__ << std::endl; + namespace { @@ -69,9 +77,6 @@ typedef void* FDataPtr; namespace finalcut { -const char* const bad_alloc_str = \ - "not enough memory to alloc "; - template struct is_negative { diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index f888217f..497d3d11 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -49,12 +49,12 @@ #endif #include -#include // std::stringstream #include #include #include #include "final/fc.h" +#include "final/fstringstream.h" #include "final/fterm.h" #define F_PREPROC_HANDLER(i,h) \ @@ -148,13 +148,6 @@ class FVTerm const FTermArea* getVWin() const; const FPoint getPrintCursor(); static const FChar getAttribute(); - static int getMaxColor(); - static int getTabstop(); - static fc::encoding getEncoding(); - static std::string getEncodingString(); - static const FString getKeyName (FKey); - static const char* getTermType(); - static const char* getTermFileName(); FTerm& getFTerm(); // Mutators @@ -237,12 +230,6 @@ class FVTerm static void setNonBlockingRead(); static void unsetNonBlockingRead(); - static void setTermTitle (const FString&); - static void setEncoding (fc::encoding); - static bool setVGAFont(); - static bool setNewFont(); - static bool setOldFont(); - // Inquiries static bool isBold(); static bool isDim(); @@ -260,30 +247,6 @@ class FVTerm static bool isTransparent(); static bool isTransShadow(); static bool isInheritBackground(); - static bool isMonochron(); - static bool isXTerminal(); - static bool isAnsiTerminal(); - static bool isRxvtTerminal(); - static bool isUrxvtTerminal(); - static bool isMltermTerminal(); - static bool isPuttyTerminal(); - static bool isKdeTerminal(); - static bool isGnomeTerminal(); - static bool isKtermTerminal(); - static bool isTeraTerm(); - static bool isSunTerminal(); - static bool isCygwinTerminal(); - static bool isMinttyTerm(); - static bool isLinuxTerm(); - static bool isFreeBSDTerm(); - static bool isNetBSDTerm(); - static bool isOpenBSDTerm(); - static bool isScreenTerm(); - static bool isTmuxTerm(); - static bool isNewFont(); - static bool isCursorHideable(); - static bool hasChangedTermSize(); - static bool hasUTF8(); // Methods virtual void clearArea (int = ' '); @@ -312,8 +275,6 @@ class FVTerm virtual void print (const FColorPair&); virtual FVTerm& print(); static void flush(); - static void beep(); - static void redefineDefaultColors (bool); protected: // Accessor @@ -322,26 +283,16 @@ class FVTerm FTermArea* getCurrentPrintArea() const; FTermArea* getVirtualDesktop() const; FTermArea* getVirtualTerminal() const; - std::size_t getLineNumber(); - std::size_t getColumnNumber(); - static bool charEncodable (wchar_t); - static FKeyboard* getFKeyboard(); - static FMouseControl* getFMouseControl(); // Mutators void setPrintArea (FTermArea*); void setChildPrintArea (FTermArea*); void setActiveArea (FTermArea*); - static void setInsertCursor (bool); - static void setInsertCursor(); - static void unsetInsertCursor(); // Inquiries bool hasPrintArea() const; bool hasChildPrintArea() const; bool isVirtualWindow() const; - static bool hasHalfBlockCharacter(); - static bool hasShadowCharacter(); // Methods @@ -366,13 +317,7 @@ class FVTerm void processTerminalUpdate(); static void startTerminalUpdate(); static void finishTerminalUpdate(); - static void initScreenSettings(); - static void changeTermSizeFinished(); - static void exitWithMessage (const FString&) - #if defined(__clang__) || defined(__GNUC__) - __attribute__((noreturn)) - #endif - ; + private: // Enumerations enum character_type @@ -601,10 +546,10 @@ struct FVTerm::FVTermPreprocessing template inline FVTerm& FVTerm::operator << (const typeT& s) { - std::wostringstream outstream; + FStringStream outstream{std::ios_base::out}; outstream << s; - if ( ! outstream.str().empty() ) + if ( ! outstream.str().isEmpty() ) print (outstream.str()); return *this; @@ -677,40 +622,6 @@ inline const FVTerm::FTermArea* FVTerm::getVWin() const inline const FChar FVTerm::getAttribute() { return next_attribute; } -//---------------------------------------------------------------------- -inline int FVTerm::getMaxColor() -{ return FTerm::getMaxColor(); } - -//---------------------------------------------------------------------- -inline int FVTerm::getTabstop() -{ return FTerm::getTabstop(); } - -//---------------------------------------------------------------------- -inline fc::encoding FVTerm::getEncoding() -{ return FTerm::getEncoding(); } - -//---------------------------------------------------------------------- -inline std::string FVTerm::getEncodingString() -{ - const std::string& enc_str = FTerm::getEncodingString(); // init enc_str - return enc_str; -} - -//---------------------------------------------------------------------- -inline const FString FVTerm::getKeyName (FKey keynum) -{ - const FString& name = FTerm::getKeyName(keynum); // initialize name - return name; -} - -//---------------------------------------------------------------------- -inline const char* FVTerm::getTermType() -{ return FTerm::getTermType(); } - -//---------------------------------------------------------------------- -inline const char* FVTerm::getTermFileName() -{ return FTerm::getTermFileName(); } - //---------------------------------------------------------------------- inline FTerm& FVTerm::getFTerm() { return *fterm; } @@ -942,26 +853,6 @@ inline void FVTerm::setNonBlockingRead() inline void FVTerm::unsetNonBlockingRead() { setNonBlockingRead(false); } -//---------------------------------------------------------------------- -inline void FVTerm::setTermTitle (const FString& title) -{ FTerm::setTermTitle(title); } - -//---------------------------------------------------------------------- -inline void FVTerm::setEncoding (fc::encoding enc) -{ FTerm::setEncoding(enc); } - -//---------------------------------------------------------------------- -inline bool FVTerm::setVGAFont() -{ return FTerm::setVGAFont(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::setNewFont() -{ return FTerm::setNewFont(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::setOldFont() -{ return FTerm::setOldFont(); } - //---------------------------------------------------------------------- inline bool FVTerm::isBold() { return next_attribute.attr.bit.bold; } @@ -1026,102 +917,6 @@ inline bool FVTerm::isTransShadow() inline bool FVTerm::isInheritBackground() { return next_attribute.attr.bit.inherit_background; } -//---------------------------------------------------------------------- -inline bool FVTerm::isMonochron() -{ return FTerm::isMonochron(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isXTerminal() -{ return FTerm::isXTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isAnsiTerminal() -{ return FTerm::isAnsiTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isRxvtTerminal() -{ return FTerm::isRxvtTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isUrxvtTerminal() -{ return FTerm::isUrxvtTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isMltermTerminal() -{ return FTerm::isMltermTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isPuttyTerminal() -{ return FTerm::isPuttyTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isKdeTerminal() -{ return FTerm::isKdeTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isGnomeTerminal() -{ return FTerm::isGnomeTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isKtermTerminal() -{ return FTerm::isKtermTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isTeraTerm() -{ return FTerm::isTeraTerm(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isSunTerminal() -{ return FTerm::isSunTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isCygwinTerminal() -{ return FTerm::isCygwinTerminal(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isMinttyTerm() -{ return FTerm::isMinttyTerm(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isLinuxTerm() -{ return FTerm::isLinuxTerm(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isFreeBSDTerm() -{ return FTerm::isFreeBSDTerm(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isNetBSDTerm() -{ return FTerm::isNetBSDTerm(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isOpenBSDTerm() -{ return FTerm::isOpenBSDTerm(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isScreenTerm() -{ return FTerm::isScreenTerm(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isTmuxTerm() -{ return FTerm::isTmuxTerm(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isNewFont() -{ return FTerm::isNewFont(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::isCursorHideable() -{ return FTerm::isCursorHideable(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::hasChangedTermSize() -{ return FTerm::hasChangedTermSize(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::hasUTF8() -{ return FTerm::hasUTF8(); } - //---------------------------------------------------------------------- template inline int FVTerm::printf (const FString& format, Args&&... args) @@ -1135,14 +930,6 @@ inline int FVTerm::printf (const FString& format, Args&&... args) inline FVTerm& FVTerm::print() { return *this; } -//---------------------------------------------------------------------- -inline void FVTerm::beep() -{ FTerm::beep(); } - -//---------------------------------------------------------------------- -inline void FVTerm::redefineDefaultColors (bool enable) -{ FTerm::redefineDefaultColors(enable); } - //---------------------------------------------------------------------- inline FVTerm::FTermArea* FVTerm::getChildPrintArea() const { return child_print_area; } @@ -1159,26 +946,6 @@ inline FVTerm::FTermArea* FVTerm::getVirtualDesktop() const inline FVTerm::FTermArea* FVTerm::getVirtualTerminal() const { return vterm; } -//---------------------------------------------------------------------- -inline std::size_t FVTerm::getLineNumber() -{ return FTerm::getLineNumber(); } - -//---------------------------------------------------------------------- -inline std::size_t FVTerm::getColumnNumber() -{ return FTerm::getColumnNumber(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::charEncodable (wchar_t c) -{ return FTerm::charEncodable(c); } - -//---------------------------------------------------------------------- -inline FKeyboard* FVTerm::getFKeyboard() -{ return FTerm::getFKeyboard(); } - -//---------------------------------------------------------------------- -inline FMouseControl* FVTerm::getFMouseControl() -{ return FTerm::getFMouseControl(); } - //---------------------------------------------------------------------- inline void FVTerm::setPrintArea (FTermArea* area) { print_area = area; } @@ -1191,18 +958,6 @@ inline void FVTerm::setChildPrintArea (FTermArea* area) inline void FVTerm::setActiveArea (FTermArea* area) { active_area = area; } -//---------------------------------------------------------------------- -inline void FVTerm::setInsertCursor (bool enable) -{ return FTerm::setInsertCursor(enable); } - -//---------------------------------------------------------------------- -inline void FVTerm::setInsertCursor() -{ return FTerm::setInsertCursor(true); } - -//---------------------------------------------------------------------- -inline void FVTerm::unsetInsertCursor() -{ return FTerm::setInsertCursor(false); } - //---------------------------------------------------------------------- inline bool FVTerm::hasPrintArea() const { return print_area; } @@ -1215,25 +970,6 @@ inline bool FVTerm::hasChildPrintArea() const inline bool FVTerm::isVirtualWindow() const { return vwin; } -//---------------------------------------------------------------------- -inline bool FVTerm::hasHalfBlockCharacter() -{ return FTerm::hasHalfBlockCharacter(); } - -//---------------------------------------------------------------------- -inline bool FVTerm::hasShadowCharacter() -{ return FTerm::hasShadowCharacter(); } - -//---------------------------------------------------------------------- -inline void FVTerm::initScreenSettings() -{ FTerm::initScreenSettings(); } - -//---------------------------------------------------------------------- -inline void FVTerm::changeTermSizeFinished() -{ FTerm::changeTermSizeFinished(); } - -//---------------------------------------------------------------------- -inline void FVTerm::exitWithMessage (const FString& message) -{ FTerm::exitWithMessage(message); } } // namespace finalcut diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index 348ec09a..fcc6fdfd 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -94,12 +94,12 @@ #include #include -#include "final/fvterm.h" #include "final/fobject.h" #include "final/fpoint.h" #include "final/frect.h" #include "final/fsize.h" #include "final/ftypes.h" +#include "final/fvterm.h" // Callback macros #define F_FUNCTION_CALLBACK(h) \ @@ -146,6 +146,7 @@ class FWidget : public FVTerm, public FObject typedef void (*FCallbackPtr)(FWidget*, FDataPtr); typedef void (FWidget::*FMemberCallback)(FWidget*, FDataPtr); typedef std::function FCallback; + typedef std::shared_ptr FWidgetColorsPtr; struct FWidgetFlags // Properties of a widget ⚑ { @@ -184,161 +185,166 @@ class FWidget : public FVTerm, public FObject FWidget& operator = (const FWidget&) = delete; // Accessors - const FString getClassName() const override; - FWidget* getRootWidget() const; - FWidget* getParentWidget() const; - static FWidget*& getMainWidget(); - static FWidget*& getActiveWindow(); - static FWidget*& getFocusWidget(); - static FWidget*& getClickedWidget(); - static FWidget*& getOpenMenu(); - static FWidget*& getMoveSizeWidget(); - static FWidgetList*& getWindowList(); - static FMenuBar* getMenuBar(); - static FStatusBar* getStatusBar(); - virtual FWidget* getFirstFocusableWidget (FObjectList); - virtual FWidget* getLastFocusableWidget (FObjectList); - const FAcceleratorList& getAcceleratorList() const; - FAcceleratorList& setAcceleratorList(); - FString getStatusbarMessage() const; - FColor getForegroundColor() const; // get the primary - FColor getBackgroundColor() const; // widget colors - std::vector& doubleFlatLine_ref (fc::sides); + const FString getClassName() const override; + FWidget* getRootWidget() const; + FWidget* getParentWidget() const; + static FWidget*& getMainWidget(); + static FWidget*& getActiveWindow(); + static FWidget*& getFocusWidget(); + static FWidget*& getClickedWidget(); + static FWidget*& getOpenMenu(); + static FWidget*& getMoveSizeWidget(); + static FWidgetList*& getWindowList(); + static FMenuBar* getMenuBar(); + static FStatusBar* getStatusBar(); + static FWidgetColorsPtr& getColorTheme(); + virtual FWidget* getFirstFocusableWidget (FObjectList); + virtual FWidget* getLastFocusableWidget (FObjectList); + const FAcceleratorList& getAcceleratorList() const; + FString getStatusbarMessage() const; + FColor getForegroundColor() const; // get the primary + FColor getBackgroundColor() const; // widget colors + std::vector& doubleFlatLine_ref (fc::sides); // Positioning and sizes accessors... - int getX() const; - int getY() const; - const FPoint getPos() const; - int getTermX() const; - int getTermY() const; - const FPoint getTermPos() const; - std::size_t getWidth() const; - std::size_t getHeight() const; - const FSize getSize() const; - int getTopPadding() const; - int getLeftPadding() const; - int getBottomPadding() const; - int getRightPadding() const; - std::size_t getClientWidth() const; - std::size_t getClientHeight() const; - const FSize getClientSize() const; - std::size_t getMaxWidth() const; - std::size_t getMaxHeight() const; - const FSize& getShadow() const; - const FRect& getGeometry() const; - const FRect& getGeometryWithShadow(); - const FRect& getTermGeometry(); - const FRect& getTermGeometryWithShadow(); - std::size_t getDesktopWidth(); - std::size_t getDesktopHeight(); - const FWidgetFlags& getFlags() const; - const FPoint getCursorPos(); - const FPoint getPrintPos(); + int getX() const; + int getY() const; + const FPoint getPos() const; + int getTermX() const; + int getTermY() const; + const FPoint getTermPos() const; + std::size_t getWidth() const; + std::size_t getHeight() const; + const FSize getSize() const; + int getTopPadding() const; + int getLeftPadding() const; + int getBottomPadding() const; + int getRightPadding() const; + std::size_t getClientWidth() const; + std::size_t getClientHeight() const; + const FSize getClientSize() const; + std::size_t getMaxWidth() const; + std::size_t getMaxHeight() const; + const FSize& getShadow() const; + const FRect& getGeometry() const; + const FRect& getGeometryWithShadow(); + const FRect& getTermGeometry(); + const FRect& getTermGeometryWithShadow(); + std::size_t getDesktopWidth(); + std::size_t getDesktopHeight(); + const FWidgetFlags& getFlags() const; + const FPoint getCursorPos(); + const FPoint getPrintPos(); // Mutators - static void setMainWidget (FWidget*); - static void setFocusWidget (FWidget*); - static void setClickedWidget (FWidget*); - static void setMoveSizeWidget (FWidget*); - static void setActiveWindow (FWidget*); - static void setOpenMenu (FWidget*); - virtual void setStatusbarMessage (const FString&); - bool setVisible (bool); - bool setVisible(); - bool unsetVisible(); - virtual bool setEnable (bool); - virtual bool setEnable(); - virtual bool unsetEnable(); - virtual bool setDisable(); - virtual bool setVisibleCursor (bool); // input cursor visibility - virtual bool setVisibleCursor(); // for the widget - virtual bool unsetVisibleCursor(); - virtual bool setFocus (bool); - virtual bool setFocus(); - virtual bool unsetFocus(); - void setFocusable(); - void unsetFocusable(); - bool ignorePadding (bool); // ignore padding from - bool ignorePadding(); // the parent widget - bool acceptPadding(); - virtual void setForegroundColor (FColor); - virtual void setBackgroundColor (FColor); - void setColor(); - FWidgetFlags& setFlags(); + static void setMainWidget (FWidget*); + static void setFocusWidget (FWidget*); + static void setClickedWidget (FWidget*); + static void setMoveSizeWidget (FWidget*); + static void setActiveWindow (FWidget*); + static void setOpenMenu (FWidget*); + template + static void setColorTheme(); + FAcceleratorList& setAcceleratorList(); + virtual void setStatusbarMessage (const FString&); + bool setVisible (bool); + bool setVisible(); + bool unsetVisible(); + virtual bool setEnable (bool); + virtual bool setEnable(); + virtual bool unsetEnable(); + virtual bool setDisable(); + virtual bool setVisibleCursor (bool); // input cursor visibility + virtual bool setVisibleCursor(); // for the widget + virtual bool unsetVisibleCursor(); + virtual bool setFocus (bool); + virtual bool setFocus(); + virtual bool unsetFocus(); + void setFocusable(); + void unsetFocusable(); + bool ignorePadding (bool); // ignore padding from + bool ignorePadding(); // the parent widget + bool acceptPadding(); + virtual void setForegroundColor (FColor); + virtual void setBackgroundColor (FColor); + virtual void resetColors(); + void useParentWidgetColor(); + void setColor(); + FWidgetFlags& setFlags(); // Positioning and sizes mutators... - virtual void setX (int, bool = true); - virtual void setY (int, bool = true); - virtual void setPos (const FPoint&, bool = true); - virtual void setWidth (std::size_t, bool = true); - virtual void setHeight (std::size_t, bool = true); - virtual void setSize (const FSize&, bool = true); - void setTopPadding (int, bool = true); - void setLeftPadding (int, bool = true); - void setBottomPadding (int, bool = true); - void setRightPadding (int, bool = true); - void setTermSize (const FSize&); - virtual void setGeometry (const FRect&, bool = true); - virtual void setGeometry (const FPoint&, const FSize&, bool = true); - virtual void setShadowSize (const FSize&); - void setMinimumWidth (std::size_t); - void setMinimumHeight (std::size_t); - void setMinimumSize (const FSize&); - void setMaximumWidth (std::size_t); - void setMaximumHeight (std::size_t); - void setMaximumSize (const FSize&); - void setFixedSize (const FSize&); - virtual bool setCursorPos (const FPoint&); - void unsetCursorPos(); - virtual void setPrintPos (const FPoint&); - void setDoubleFlatLine (fc::sides, bool = true); - void unsetDoubleFlatLine (fc::sides); - void setDoubleFlatLine (fc::sides, int, bool = true); - void unsetDoubleFlatLine (fc::sides, int); + virtual void setX (int, bool = true); + virtual void setY (int, bool = true); + virtual void setPos (const FPoint&, bool = true); + virtual void setWidth (std::size_t, bool = true); + virtual void setHeight (std::size_t, bool = true); + virtual void setSize (const FSize&, bool = true); + void setTopPadding (int, bool = true); + void setLeftPadding (int, bool = true); + void setBottomPadding (int, bool = true); + void setRightPadding (int, bool = true); + void setTermSize (const FSize&); + virtual void setGeometry (const FRect&, bool = true); + virtual void setGeometry (const FPoint&, const FSize&, bool = true); + virtual void setShadowSize (const FSize&); + void setMinimumWidth (std::size_t); + void setMinimumHeight (std::size_t); + void setMinimumSize (const FSize&); + void setMaximumWidth (std::size_t); + void setMaximumHeight (std::size_t); + void setMaximumSize (const FSize&); + void setFixedSize (const FSize&); + virtual bool setCursorPos (const FPoint&); + void unsetCursorPos(); + virtual void setPrintPos (const FPoint&); + void setDoubleFlatLine (fc::sides, bool = true); + void unsetDoubleFlatLine (fc::sides); + void setDoubleFlatLine (fc::sides, int, bool = true); + void unsetDoubleFlatLine (fc::sides, int); // Inquiries - bool isRootWidget() const; - bool isWindowWidget() const; - bool isDialogWidget() const; - bool isMenuWidget() const; - bool isVisible() const; - bool isShown() const; - bool isHidden() const; - bool isEnabled() const; - bool hasVisibleCursor() const; - bool hasFocus() const; - bool acceptFocus() const; // is focusable - bool isPaddingIgnored() const; + bool isRootWidget() const; + bool isWindowWidget() const; + bool isDialogWidget() const; + bool isMenuWidget() const; + bool isVisible() const; + bool isShown() const; + bool isHidden() const; + bool isEnabled() const; + bool hasVisibleCursor() const; + bool hasFocus() const; + bool acceptFocus() const; // is focusable + bool isPaddingIgnored() const; // Methods - FWidget* childWidgetAt (const FPoint&); - int numOfFocusableChildren(); - virtual bool close(); - void clearStatusbarMessage(); - void addCallback ( const FString& - , const FCallback& - , FDataPtr = nullptr ); - void addCallback ( const FString& - , FWidget* - , const FCallback& - , FDataPtr = nullptr ); - void delCallback (const FCallback&); - void delCallback (const FWidget*); - void delCallbacks(); - void emitCallback (const FString&); - void addAccelerator (FKey); - virtual void addAccelerator (FKey, FWidget*); - void delAccelerator (); - virtual void delAccelerator (FWidget*); - virtual void redraw(); - virtual void resize(); - virtual void show(); - virtual void hide(); - virtual bool focusFirstChild(); // widget focusing - virtual bool focusLastChild(); - const FPoint termToWidgetPos (const FPoint&); - void print (const FPoint&) override; - virtual void move (const FPoint&); - virtual void drawBorder(); - static void quit(); + FWidget* childWidgetAt (const FPoint&); + int numOfFocusableChildren(); + virtual bool close(); + void clearStatusbarMessage(); + void addCallback ( const FString& + , const FCallback& + , FDataPtr = nullptr ); + void addCallback ( const FString& + , FWidget* + , const FCallback& + , FDataPtr = nullptr ); + void delCallback (const FCallback&); + void delCallback (const FWidget*); + void delCallbacks(); + void emitCallback (const FString&); + void addAccelerator (FKey); + virtual void addAccelerator (FKey, FWidget*); + void delAccelerator (); + virtual void delAccelerator (FWidget*); + virtual void redraw(); + virtual void resize(); + virtual void show(); + virtual void hide(); + virtual bool focusFirstChild(); // widget focusing + virtual bool focusLastChild(); + const FPoint termToWidgetPos (const FPoint&); + void print (const FPoint&) override; + virtual void move (const FPoint&); + virtual void drawBorder(); + static void quit(); protected: struct FCallbackData; // forward declaration @@ -347,54 +353,52 @@ class FWidget : public FVTerm, public FObject typedef std::vector FCallbackObjects; // Accessor - FTermArea* getPrintArea() override; - const FWidgetColors& getFWidgetColors() const; - static uInt getModalDialogCounter(); - static FWidgetList*& getDialogList(); - static FWidgetList*& getAlwaysOnTopList(); - static FWidgetList*& getWidgetCloseList(); - void addPreprocessingHandler ( const FVTerm* - , const FPreprocessingFunction& ) override; - void delPreprocessingHandler (const FVTerm*) override; + FTermArea* getPrintArea() override; + static uInt getModalDialogCounter(); + static FWidgetList*& getDialogList(); + static FWidgetList*& getAlwaysOnTopList(); + static FWidgetList*& getWidgetCloseList(); + void addPreprocessingHandler ( const FVTerm* + , const FPreprocessingFunction& ) override; + void delPreprocessingHandler (const FVTerm*) override; // Inquiry - bool isChildPrintArea() const; + bool isChildPrintArea() const; // Mutators - virtual void setStatusBar (FStatusBar*); - virtual void setMenuBar (FMenuBar*); - FWidgetColors& setFWidgetColors(); - static uInt& setModalDialogCounter(); - void setParentOffset(); - void setTermOffset(); - void setTermOffsetWithPadding(); + virtual void setStatusBar (FStatusBar*); + virtual void setMenuBar (FMenuBar*); + static uInt& setModalDialogCounter(); + void setParentOffset(); + void setTermOffset(); + void setTermOffsetWithPadding(); // Methods - virtual void adjustSize(); - void adjustSizeGlobal(); - void hideArea (const FSize&); - virtual bool focusNextChild(); // Change child... - virtual bool focusPrevChild(); // ...focus + virtual void adjustSize(); + void adjustSizeGlobal(); + void hideArea (const FSize&); + virtual bool focusNextChild(); // Change child... + virtual bool focusPrevChild(); // ...focus // Event handlers - bool event (FEvent*) override; - virtual void onKeyPress (FKeyEvent*); - virtual void onKeyUp (FKeyEvent*); - virtual void onKeyDown (FKeyEvent*); - virtual void onMouseDown (FMouseEvent*); - virtual void onMouseUp (FMouseEvent*); - virtual void onMouseDoubleClick (FMouseEvent*); - virtual void onWheel (FWheelEvent*); - virtual void onMouseMove (FMouseEvent*); - virtual void onFocusIn (FFocusEvent*); - virtual void onFocusOut (FFocusEvent*); - virtual void onChildFocusIn (FFocusEvent*); - virtual void onChildFocusOut (FFocusEvent*); - virtual void onAccel (FAccelEvent*); - virtual void onResize (FResizeEvent*); - virtual void onShow (FShowEvent*); - virtual void onHide (FHideEvent*); - virtual void onClose (FCloseEvent*); + bool event (FEvent*) override; + virtual void onKeyPress (FKeyEvent*); + virtual void onKeyUp (FKeyEvent*); + virtual void onKeyDown (FKeyEvent*); + virtual void onMouseDown (FMouseEvent*); + virtual void onMouseUp (FMouseEvent*); + virtual void onMouseDoubleClick (FMouseEvent*); + virtual void onWheel (FWheelEvent*); + virtual void onMouseMove (FMouseEvent*); + virtual void onFocusIn (FFocusEvent*); + virtual void onFocusOut (FFocusEvent*); + virtual void onChildFocusIn (FFocusEvent*); + virtual void onChildFocusOut (FFocusEvent*); + virtual void onAccel (FAccelEvent*); + virtual void onResize (FResizeEvent*); + virtual void onShow (FShowEvent*); + virtual void onHide (FHideEvent*); + virtual void onClose (FCloseEvent*); private: struct widget_size_hints @@ -443,68 +447,68 @@ class FWidget : public FVTerm, public FObject }; // Methods - void initRootWidget(); - void finish(); - void insufficientSpaceAdjust(); - void KeyPressEvent (FKeyEvent*); - void KeyDownEvent (FKeyEvent*); - void emitWheelCallback (const FWheelEvent*); - void setWindowFocus (bool); - FCallbackPtr getCallbackPtr (const FCallback&); - bool changeFocus (FWidget*, FWidget*, fc::FocusTypes); - void processDestroy(); - virtual void draw(); - void drawWindows(); - void drawChildren(); - static void setColorTheme(); - void setStatusbarText (bool); + void initRootWidget(); + void finish(); + void insufficientSpaceAdjust(); + void KeyPressEvent (FKeyEvent*); + void KeyDownEvent (FKeyEvent*); + void emitWheelCallback (const FWheelEvent*); + void setWindowFocus (bool); + FCallbackPtr getCallbackPtr (const FCallback&); + bool changeFocus (FWidget*, FWidget*, fc::FocusTypes); + void processDestroy(); + virtual void draw(); + void drawWindows(); + void drawChildren(); + static void initColorTheme(); + void destroyColorTheme(); + void setStatusbarText (bool); // Data members - struct FWidgetFlags flags{}; - FPoint widget_cursor_position{-1, -1}; - widget_size_hints size_hints{}; - dbl_line_mask double_flatline_mask{}; - widget_padding padding{}; - bool ignore_padding{false}; + struct FWidgetFlags flags{}; + FPoint widget_cursor_position{-1, -1}; + widget_size_hints size_hints{}; + dbl_line_mask double_flatline_mask{}; + widget_padding padding{}; + bool ignore_padding{false}; // widget size - FRect wsize{1, 1, 1, 1}; - FRect adjust_wsize{1, 1, 1, 1}; - FRect adjust_wsize_term{}; - FRect adjust_wsize_shadow{}; - FRect adjust_wsize_term_shadow{}; + FRect wsize{1, 1, 1, 1}; + FRect adjust_wsize{1, 1, 1, 1}; + FRect adjust_wsize_term{}; + FRect adjust_wsize_shadow{}; + FRect adjust_wsize_term_shadow{}; // widget offset - FRect woffset{}; + FRect woffset{}; // offset of the widget client area - FRect wclient_offset{}; + FRect wclient_offset{}; // widget shadow size (on the right and bottom side) - FSize wshadow{0, 0}; + FSize wshadow{0, 0}; // default widget foreground and background color - FColor foreground_color{fc::Default}; - FColor background_color{fc::Default}; - FString statusbar_message{}; - FAcceleratorList accelerator_list{}; - FCallbackObjects callback_objects{}; + FColor foreground_color{fc::Default}; + FColor background_color{fc::Default}; + FString statusbar_message{}; + FAcceleratorList accelerator_list{}; + FCallbackObjects callback_objects{}; - static FStatusBar* statusbar; - static FMenuBar* menubar; - static FWidget* main_widget; - static FWidget* active_window; - static FWidget* focus_widget; - static FWidget* clicked_widget; - static FWidget* open_menu; - static FWidget* move_size_widget; - static FWidget* show_root_widget; - static FWidget* redraw_root_widget; - static FWidgetList* window_list; - static FWidgetList* dialog_list; - static FWidgetList* always_on_top_list; - static FWidgetList* close_widget; - static FWidgetColors wcolors; - static uInt modal_dialog_counter; - static bool init_desktop; - static bool hideable; + static FStatusBar* statusbar; + static FMenuBar* menubar; + static FWidget* main_widget; + static FWidget* active_window; + static FWidget* focus_widget; + static FWidget* clicked_widget; + static FWidget* open_menu; + static FWidget* move_size_widget; + static FWidget* show_root_widget; + static FWidget* redraw_root_widget; + static FWidgetList* window_list; + static FWidgetList* dialog_list; + static FWidgetList* always_on_top_list; + static FWidgetList* close_widget; + static uInt modal_dialog_counter; + static bool init_desktop; + static bool hideable; // Friend classes friend class FToggleButton; @@ -645,6 +649,13 @@ inline FMenuBar* FWidget::getMenuBar() inline FStatusBar* FWidget::getStatusBar() { return statusbar; } +//---------------------------------------------------------------------- +inline FWidget::FWidgetColorsPtr& FWidget::getColorTheme() +{ + static FWidgetColorsPtr* color_theme = new FWidgetColorsPtr(); + return *color_theme; +} + //---------------------------------------------------------------------- inline const FWidget::FAcceleratorList& FWidget::getAcceleratorList() const { return accelerator_list; } @@ -798,11 +809,11 @@ inline const FRect& FWidget::getTermGeometryWithShadow() //---------------------------------------------------------------------- inline std::size_t FWidget::getDesktopWidth() -{ return getColumnNumber(); } +{ return FTerm::getColumnNumber(); } //---------------------------------------------------------------------- inline std::size_t FWidget::getDesktopHeight() -{ return getLineNumber(); } +{ return FTerm::getLineNumber(); } //---------------------------------------------------------------------- inline const FWidget::FWidgetFlags& FWidget::getFlags() const @@ -828,6 +839,13 @@ inline void FWidget::setClickedWidget (FWidget* obj) inline void FWidget::setOpenMenu (FWidget* obj) { open_menu = obj; } +//---------------------------------------------------------------------- +template +inline void FWidget::setColorTheme() +{ + getColorTheme() = std::make_shared(); +} + //---------------------------------------------------------------------- inline void FWidget::setMoveSizeWidget (FWidget* obj) { move_size_widget = obj; } @@ -1069,10 +1087,6 @@ inline void FWidget::drawBorder() finalcut::drawBorder (this, FRect(FPoint{1, 1}, getSize())); } -//---------------------------------------------------------------------- -inline const FWidgetColors& FWidget::getFWidgetColors() const -{ return wcolors; } - //---------------------------------------------------------------------- inline uInt FWidget::getModalDialogCounter() { return modal_dialog_counter; } @@ -1089,10 +1103,6 @@ inline FWidget::FWidgetList*& FWidget::getAlwaysOnTopList() inline FWidget::FWidgetList*& FWidget::getWidgetCloseList() { return close_widget; } -//---------------------------------------------------------------------- -inline FWidgetColors& FWidget::setFWidgetColors() -{ return wcolors; } - //---------------------------------------------------------------------- inline uInt& FWidget::setModalDialogCounter() { return modal_dialog_counter; } diff --git a/src/include/final/fwidgetcolors.h b/src/include/final/fwidgetcolors.h index 53815492..425cffa9 100644 --- a/src/include/final/fwidgetcolors.h +++ b/src/include/final/fwidgetcolors.h @@ -3,7 +3,7 @@ * * * 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 * * modify it under the terms of the GNU Lesser General Public License * @@ -44,12 +44,17 @@ namespace finalcut // class FWidgetColors //---------------------------------------------------------------------- -class FWidgetColors final +class FWidgetColors { public: - // Methods - void set8ColorTheme(); - void set16ColorTheme(); + // Constructor + FWidgetColors(); + + // Destructor + virtual ~FWidgetColors(); + + // Method + virtual void setColorTheme() = 0; // Data members FColor term_fg{fc::Default}; @@ -140,6 +145,130 @@ class FWidgetColors final FColor progressbar_bg{fc::Default}; }; + +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FWidgetColors ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ default8ColorTheme ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ + +//---------------------------------------------------------------------- +// class default8ColorTheme +//---------------------------------------------------------------------- + +class default8ColorTheme final : public FWidgetColors +{ + public: + // Constructor + default8ColorTheme(); + + // Destructor + ~default8ColorTheme() override; + + // Method + void setColorTheme() override; +}; + + +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FWidgetColors ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ default16ColorTheme ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ + +//---------------------------------------------------------------------- +// class default16ColorTheme +//---------------------------------------------------------------------- + +class default16ColorTheme final : public FWidgetColors +{ + public: + // Constructor + default16ColorTheme(); + + // Destructor + ~default16ColorTheme() override; + + // Method + void setColorTheme() override; +}; + + +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FWidgetColors ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ default8ColorDarkTheme ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ + +//---------------------------------------------------------------------- +// class default8ColorDarkTheme +//---------------------------------------------------------------------- + +class default8ColorDarkTheme final : public FWidgetColors +{ + public: + // Constructor + default8ColorDarkTheme(); + + // Destructor + ~default8ColorDarkTheme() override; + + // Method + void setColorTheme() override; +}; + + +/* Inheritance diagram + * ═══════════════════ + * + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ FWidgetColors ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + * ▲ + * │ + * ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏ + * ▕ default16ColorDarkTheme ▏ + * ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏ + */ + +//---------------------------------------------------------------------- +// class default16ColorDarkTheme +//---------------------------------------------------------------------- + +class default16ColorDarkTheme final : public FWidgetColors +{ + public: + // Constructor + default16ColorDarkTheme(); + + // Destructor + ~default16ColorDarkTheme() override; + + // Method + void setColorTheme() override; +}; + } // namespace finalcut #endif // FWIDGETCOLORS_H diff --git a/src/sgr_optimizer.cpp b/src/sgr_optimizer.cpp index 87eba5b4..74cc3c57 100644 --- a/src/sgr_optimizer.cpp +++ b/src/sgr_optimizer.cpp @@ -35,7 +35,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- SGRoptimizer::SGRoptimizer (attributebuffer& sequence) - : seq(sequence) + : seq{sequence} { } //---------------------------------------------------------------------- diff --git a/test/Makefile.am b/test/Makefile.am index a2ff0559..6c0f8bfa 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -21,6 +21,8 @@ noinst_PROGRAMS = \ fcolorpair_test \ fstyle_test \ fstring_test \ + fstringstream_test \ + flogger_test \ fsize_test \ fpoint_test \ frect_test @@ -39,6 +41,8 @@ foptiattr_test_SOURCES = foptiattr-test.cpp fcolorpair_test_SOURCES = fcolorpair-test.cpp fstyle_test_SOURCES = fstyle-test.cpp fstring_test_SOURCES = fstring-test.cpp +fstringstream_test_SOURCES = fstringstream-test.cpp +flogger_test_SOURCES = flogger-test.cpp fsize_test_SOURCES = fsize-test.cpp fpoint_test_SOURCES = fpoint-test.cpp frect_test_SOURCES = frect-test.cpp @@ -57,6 +61,8 @@ TESTS = fobject_test \ fcolorpair_test \ fstyle_test \ fstring_test \ + fstringstream_test \ + flogger_test \ fsize_test \ fpoint_test \ frect_test diff --git a/test/flogger-test.cpp b/test/flogger-test.cpp new file mode 100644 index 00000000..176f6e89 --- /dev/null +++ b/test/flogger-test.cpp @@ -0,0 +1,369 @@ +/*********************************************************************** +* flogger-test.cpp - FLogger unit tests * +* * +* 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 * +* . * +***********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +//---------------------------------------------------------------------- +// class FLoggerTest +//---------------------------------------------------------------------- + +class myLogger : public finalcut::FLog +{ + public: + void info (const std::string& entry) override + { + output << " Info: " << entry << std::endl; + } + + void warn (const std::string& entry) override + { + output << " Warn: " << entry << std::endl; + } + + void error (const std::string& entry) override + { + output << "Error: " << entry << std::endl; + } + + void debug (const std::string& entry) override + { + output << "Debug: " << entry << std::endl; + } + + 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()}; +}; + +//---------------------------------------------------------------------- +// class FLoggerTest +//---------------------------------------------------------------------- + +class FLoggerTest : public CPPUNIT_NS::TestFixture +{ + public: + FLoggerTest() + { } + + protected: + void classNameTest(); + void defaultObjectTest(); + void lineEndingTest(); + void timestampTest(); + void fileTest(); + void applicationObjectTest(); + + private: + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE (FLoggerTest); + + // Add a methods to the test suite + CPPUNIT_TEST (classNameTest); + CPPUNIT_TEST (defaultObjectTest); + CPPUNIT_TEST (lineEndingTest); + CPPUNIT_TEST (timestampTest); + CPPUNIT_TEST (fileTest); + CPPUNIT_TEST (applicationObjectTest); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); +}; + +//---------------------------------------------------------------------- +void FLoggerTest::classNameTest() +{ + finalcut::FLogger log; + const finalcut::FString& classname = log.getClassName(); + CPPUNIT_ASSERT ( classname == "FLogger" ); +} + +//---------------------------------------------------------------------- +void FLoggerTest::defaultObjectTest() +{ + finalcut::FLogger log{}; + std::ostringstream buf{}; + log.setOutputStream(buf); + log << "Hello, World!" << std::flush; // Default level is "Info" + CPPUNIT_ASSERT ( buf.str() == "[INFO] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log << "Hel" << "lo," << " Wor" << "ld!" << std::flush; // Several parts + CPPUNIT_ASSERT ( buf.str() == "[INFO] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log << "Hello, World!" << std::endl; // std::endl + CPPUNIT_ASSERT ( buf.str() == "[INFO] Hello, World!\n\r\n" ); + buf.str(""); // Clear buffer + + log << finalcut::FLog::Info << "Hello, World!" << std::flush; + CPPUNIT_ASSERT ( buf.str() == "[INFO] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log << finalcut::FLog::Warn << "Hello, World!" << std::flush; + CPPUNIT_ASSERT ( buf.str() == "[WARNING] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log << "Hello, World!" << std::flush; // Last level was "Warn" + CPPUNIT_ASSERT ( buf.str() == "[WARNING] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log << finalcut::FLog::Error << "Hello, World!" << std::flush; + CPPUNIT_ASSERT ( buf.str() == "[ERROR] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log << "Hello, World!" << std::flush; // Last level was "Error" + CPPUNIT_ASSERT ( buf.str() == "[ERROR] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log << finalcut::FLog::Debug << "Hello, World!" << std::flush; + CPPUNIT_ASSERT ( buf.str() == "[DEBUG] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log << "Hello, World!" << std::flush; // Last level was "Debug" + CPPUNIT_ASSERT ( buf.str() == "[DEBUG] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + // Without stream + log.info("Hello, World!"); + CPPUNIT_ASSERT ( buf.str() == "[INFO] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log.warn("Hello, World!"); + CPPUNIT_ASSERT ( buf.str() == "[WARNING] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log.error("Hello, World!"); + CPPUNIT_ASSERT ( buf.str() == "[ERROR] Hello, World!\r\n" ); + buf.str(""); // Clear buffer + + log.debug("Hello, World!"); + CPPUNIT_ASSERT ( buf.str() == "[DEBUG] Hello, World!\r\n" ); + buf.str(""); // Clear buffer +} + +//---------------------------------------------------------------------- +void FLoggerTest::lineEndingTest() +{ + finalcut::FLogger log{}; + std::ostringstream buf{}; + log.setOutputStream(buf); + + log.info("Line endings"); // Default = CRLF + CPPUNIT_ASSERT ( buf.str() == "[INFO] Line endings\r\n" ); + buf.str(""); // Clear buffer + + log.setLineEnding(finalcut::FLog::LF); + log.warn("Line endings"); + CPPUNIT_ASSERT ( buf.str() == "[WARNING] Line endings\n" ); + buf.str(""); // Clear buffer + + log.setLineEnding(finalcut::FLog::CR); + log.error("Line endings"); + CPPUNIT_ASSERT ( buf.str() == "[ERROR] Line endings\r" ); + buf.str(""); // Clear buffer + + log.setLineEnding(finalcut::FLog::CRLF); + log.debug("Line endings"); + CPPUNIT_ASSERT ( buf.str() == "[DEBUG] Line endings\r\n" ); + buf.str(""); // Clear buffer +} + +//---------------------------------------------------------------------- +void FLoggerTest::timestampTest() +{ + finalcut::FLogger log{}; + std::ostringstream buf{}; + log.setOutputStream(buf); + + log.info("Timestamp"); + std::size_t length = buf.str().length(); + CPPUNIT_ASSERT ( buf.str() == "[INFO] Timestamp\r\n" ); + CPPUNIT_ASSERT ( length == 18 ); + buf.str(""); // Clear buffer + + log.enableTimestamp(); + log.info("Timestamp"); + length = buf.str().length(); + CPPUNIT_ASSERT ( buf.str().substr(length - 18) == "[INFO] Timestamp\r\n" ); + CPPUNIT_ASSERT ( length > 40 ); + buf.str(""); // Clear buffer + + log.disableTimestamp(); + log.info("Timestamp"); + length = buf.str().length(); + CPPUNIT_ASSERT ( buf.str() == "[INFO] Timestamp\r\n" ); + CPPUNIT_ASSERT ( length == 18 ); + buf.str(""); // Clear buffer +} + +//---------------------------------------------------------------------- +void FLoggerTest::fileTest() +{ + std::string filename = "test.log"; + + { + finalcut::FLogger log{}; + std::ofstream file_stream(filename, std::ofstream::out); + log.setLineEnding (finalcut::FLog::LF); + log.setOutputStream(file_stream); + + log.info("test1"); + log.warn("test2"); + log.error("test3"); + log.debug("test4"); + log << finalcut::FLog::Info << "streaming test1"; + log << finalcut::FLog::Warn << "streaming test2"; + log << finalcut::FLog::Error << "streaming test3"; + log << finalcut::FLog::Debug << "streaming test4" << std::flush; + + if ( file_stream.is_open() ) + file_stream.close(); + } // End of logging + + + std::string strings[] = + { + "[INFO] test1", + "[WARNING] test2", + "[ERROR] test3", + "[DEBUG] test4", + "[INFO] streaming test1", + "[WARNING] streaming test2", + "[ERROR] streaming test3", + "[DEBUG] streaming test4", + "" + }; + + std::string line{}; + std::ifstream file_stream{filename}; + std::size_t i{0}; + + while ( ! file_stream.eof() && file_stream.good() ) + { + getline(file_stream, line); + CPPUNIT_ASSERT ( line == strings[i] ); + i++; + } + + if ( file_stream.is_open() ) + file_stream.close(); + + int ret = remove(filename.c_str()); // Delete file + + if ( ret == -1 ) + { + finalcut::FLogger log{}; + log.setOutputStream(std::cerr); + log.setLineEnding (finalcut::FLog::LF); + log.error("Cannot delete the test.log file"); + } +} + +//---------------------------------------------------------------------- +void FLoggerTest::applicationObjectTest() +{ + // Generation of a logger in a shared_ptr via a pointer + finalcut::FApplication::setLog (std::make_shared()); + // Get the shared_ptr with the base class + std::shared_ptr log = finalcut::FApplication::getLog(); + + std::ostringstream buf{}; + log->setOutputStream(buf); + + log->info("test1"); + CPPUNIT_ASSERT ( buf.str() == "[INFO] test1\r\n" ); + buf.str(""); // Clear buffer + + log->warn("test2"); + CPPUNIT_ASSERT ( buf.str() == "[WARNING] test2\r\n" ); + buf.str(""); // Clear buffer + + log->error("test3"); + CPPUNIT_ASSERT ( buf.str() == "[ERROR] test3\r\n" ); + buf.str(""); // Clear buffer + + log->debug("test4"); + CPPUNIT_ASSERT ( buf.str() == "[DEBUG] test4\r\n" ); + buf.str(""); // Clear buffer + + *log << "test5" << std::flush; + CPPUNIT_ASSERT ( buf.str() == "[INFO] test5\r\n" ); + buf.str(""); // Clear buffer + + *log << finalcut::FLog::Error << "test6" << std::flush; + CPPUNIT_ASSERT ( buf.str() == "[ERROR] test6\r\n" ); + buf.str(""); // Clear buffer + + // Replace the logger with another one + finalcut::FApplication::setLog(std::make_shared()); + log = finalcut::FApplication::getLog(); + log->setOutputStream(buf); + + log->info("myLogger 1"); + CPPUNIT_ASSERT ( buf.str() == " Info: myLogger 1\n" ); + buf.str(""); // Clear buffer + + log->warn("myLogger 2"); + CPPUNIT_ASSERT ( buf.str() == " Warn: myLogger 2\n" ); + buf.str(""); // Clear buffer + + log->error("myLogger 3"); + CPPUNIT_ASSERT ( buf.str() == "Error: myLogger 3\n" ); + buf.str(""); // Clear buffer + + log->debug("myLogger 4"); + CPPUNIT_ASSERT ( buf.str() == "Debug: myLogger 4\n" ); + buf.str(""); // Clear buffer + + std::shared_ptr* logger = &(finalcut::FApplication::getLog()); + delete logger; +} + + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION (FLoggerTest); + +// The general unit test main part +#include + diff --git a/test/fstring-test.cpp b/test/fstring-test.cpp index 74cf4647..8e7c9d28 100644 --- a/test/fstring-test.cpp +++ b/test/fstring-test.cpp @@ -58,6 +58,7 @@ class FStringTest : public CPPUNIT_NS::TestFixture void noArgumentTest(); void initLengthTest(); void copyConstructorTest(); + void moveConstructorTest(); void assignmentTest(); void additionAssignmentTest(); void additionTest(); @@ -97,6 +98,7 @@ class FStringTest : public CPPUNIT_NS::TestFixture CPPUNIT_TEST (noArgumentTest); CPPUNIT_TEST (initLengthTest); CPPUNIT_TEST (copyConstructorTest); + CPPUNIT_TEST (moveConstructorTest); CPPUNIT_TEST (assignmentTest); CPPUNIT_TEST (additionAssignmentTest); CPPUNIT_TEST (additionTest); @@ -291,6 +293,20 @@ void FStringTest::copyConstructorTest() CPPUNIT_ASSERT ( s2.capacity() == 18 ); } +//---------------------------------------------------------------------- +void FStringTest::moveConstructorTest() +{ + finalcut::FString s1("abc"); + const finalcut::FString s2{std::move(s1)}; + CPPUNIT_ASSERT ( s2 == L"abc" ); + CPPUNIT_ASSERT ( s2.getLength() == 3 ); + CPPUNIT_ASSERT ( s2.capacity() == 18 ); + CPPUNIT_ASSERT ( s1.isNull() ); + CPPUNIT_ASSERT ( s1.isEmpty() ); + CPPUNIT_ASSERT ( s1.getLength() == 0 ); + CPPUNIT_ASSERT ( s1.capacity() == 0 ); +} + //---------------------------------------------------------------------- void FStringTest::assignmentTest() { @@ -370,14 +386,14 @@ void FStringTest::assignmentTest() CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 == L"#" ); CPPUNIT_ASSERT ( s1.getLength() == 1 ); - CPPUNIT_ASSERT ( s1.capacity() == 18 ); + CPPUNIT_ASSERT ( s1.capacity() == 16 ); constexpr char s8 = '%'; s1 = s8; CPPUNIT_ASSERT ( s1 ); CPPUNIT_ASSERT ( s1 == L"%" ); CPPUNIT_ASSERT ( s1.getLength() == 1 ); - CPPUNIT_ASSERT ( s1.capacity() == 18 ); + CPPUNIT_ASSERT ( s1.capacity() == 16 ); s1.setString("A character string"); CPPUNIT_ASSERT ( s1 ); @@ -425,6 +441,23 @@ void FStringTest::assignmentTest() CPPUNIT_ASSERT ( s1.isEmpty() ); CPPUNIT_ASSERT ( s1.isNull() ); CPPUNIT_ASSERT ( ! s1 ); + + // Move assignment operator + const finalcut::FString s9 = std::move(finalcut::FString(0)); + CPPUNIT_ASSERT ( ! s9 ); + CPPUNIT_ASSERT ( s9.isNull() ); + CPPUNIT_ASSERT ( s9.isEmpty() ); + + finalcut::FString s10("abc"); + const finalcut::FString s11 = std::move(s10); + CPPUNIT_ASSERT ( s11 ); + CPPUNIT_ASSERT ( s11 == L"abc" ); + CPPUNIT_ASSERT ( s11.getLength() == 3 ); + CPPUNIT_ASSERT ( s11.capacity() == 18 ); + CPPUNIT_ASSERT ( s10.isNull() ); + CPPUNIT_ASSERT ( s10.isEmpty() ); + CPPUNIT_ASSERT ( s10.getLength() == 0 ); + CPPUNIT_ASSERT ( s10.capacity() == 0 ); } //---------------------------------------------------------------------- diff --git a/test/fstringstream-test.cpp b/test/fstringstream-test.cpp new file mode 100644 index 00000000..4b12156e --- /dev/null +++ b/test/fstringstream-test.cpp @@ -0,0 +1,235 @@ +/*********************************************************************** +* fstringstream-test.cpp - FStringStream unit tests * +* * +* 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 * +* . * +***********************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +//---------------------------------------------------------------------- +// class FStringStreamTest +//---------------------------------------------------------------------- + +class FStringStreamTest : public CPPUNIT_NS::TestFixture +{ + public: + FStringStreamTest() + { } + + protected: + void classNameTest(); + void defaultObjectTest(); + void moveConstructorTest(); + void assignmentTest(); + void swapTest(); + void rdbufTest(); + void fileTest(); + + + private: + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE (FStringStreamTest); + + // Add a methods to the test suite + CPPUNIT_TEST (classNameTest); + CPPUNIT_TEST (defaultObjectTest); + CPPUNIT_TEST (moveConstructorTest); + CPPUNIT_TEST (assignmentTest); + CPPUNIT_TEST (swapTest); + CPPUNIT_TEST (rdbufTest); + CPPUNIT_TEST (fileTest); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); +}; + +//---------------------------------------------------------------------- +void FStringStreamTest::classNameTest() +{ + finalcut::FStringStream string_stream; + const finalcut::FString& classname = string_stream.getClassName(); + CPPUNIT_ASSERT ( classname == "FStringStream" ); +} + +//---------------------------------------------------------------------- +void FStringStreamTest::defaultObjectTest() +{ + finalcut::FStringStream ss{std::ios_base::out}; + CPPUNIT_ASSERT ( ss.str().isNull() ); + CPPUNIT_ASSERT ( ss.str().isEmpty() ); + CPPUNIT_ASSERT ( ss.str() != "" ); + + ss << "Hello"; + CPPUNIT_ASSERT ( ! ss.str().isNull() ); + CPPUNIT_ASSERT ( ! ss.str().isEmpty() ); + CPPUNIT_ASSERT ( ss.str() = "Hello" ); + + ss << ", World!"; + CPPUNIT_ASSERT ( ss.str() == "Hello, World!" ); + CPPUNIT_ASSERT ( ss.str() == L"Hello, World!" ); + + ss.clear(); + CPPUNIT_ASSERT ( ss.str().isNull() ); + CPPUNIT_ASSERT ( ss.str().isEmpty() ); + CPPUNIT_ASSERT ( ss.str() != "" ); + ss.clear(); + + ss << "Three" << " " << "parts"; + CPPUNIT_ASSERT ( ss.str() == L"Three parts" ); + ss.clear(); + + finalcut::FStringStream in{"21 45 45", std::ios_base::in}; + int n1{0}; + int n2{0}; + int n3{0}; + in >> std::hex >> n1 >> n2 + >> std::oct >> n3; + CPPUNIT_ASSERT ( n1 == 33 ); + CPPUNIT_ASSERT ( n2 == 69 ); + CPPUNIT_ASSERT ( n3 == 37 ); + + ss << "Line break at the end" << std::endl; + CPPUNIT_ASSERT ( ss.str() == "Line break at the end\n" ); + ss.clear(); + + ss << std::resetiosflags(std::ios_base::basefield) + << 20 << " " << std::showbase << std::hex + << 20 << " " << std::noshowbase << std::oct + << 20 << " " << std::boolalpha + << bool(20) << " " << std::dec + << 20; + CPPUNIT_ASSERT ( ss.str() == "20 0x14 24 true 20" ); + ss.clear(); + + ss << "|" << std::setfill(L'-') << std::setw(6) << "|"; + CPPUNIT_ASSERT ( ss.str() == "|-----|" ); +} + +//---------------------------------------------------------------------- +void FStringStreamTest::moveConstructorTest() +{ + finalcut::FStringStream ss1{"abc"}; + const finalcut::FStringStream ss2{std::move(ss1)}; + CPPUNIT_ASSERT ( ss2.str() == L"abc" ); + CPPUNIT_ASSERT ( ss2.str().getLength() == 3 ); + CPPUNIT_ASSERT ( ss1.str().isNull() ); + CPPUNIT_ASSERT ( ss1.str().isEmpty() ); + CPPUNIT_ASSERT ( ss1.str().getLength() == 0 ); +} + +//---------------------------------------------------------------------- +void FStringStreamTest::assignmentTest() +{ + finalcut::FStringStream ss1{"xyz"}; + finalcut::FStringStream ss2{}; + ss2 = std::move(ss1); + CPPUNIT_ASSERT ( ss2.str() == L"xyz" ); + CPPUNIT_ASSERT ( ss2.str().getLength() == 3 ); + CPPUNIT_ASSERT ( ss1.str().isNull() ); + CPPUNIT_ASSERT ( ss1.str().isEmpty() ); + CPPUNIT_ASSERT ( ss1.str().getLength() == 0 ); +} + +//---------------------------------------------------------------------- +void FStringStreamTest::swapTest() +{ + finalcut::FStringStream ss1{"FStringStream"}; + finalcut::FStringStream ss2{"FINAL CUT"}; + CPPUNIT_ASSERT ( ss1.str() == "FStringStream" ); + CPPUNIT_ASSERT ( ss2.str() == "FINAL CUT" ); + ss1.swap(ss2); + CPPUNIT_ASSERT ( ss1.str() == "FINAL CUT" ); + CPPUNIT_ASSERT ( ss2.str() == "FStringStream" ); + + finalcut::FStringStream ss3{"dog"}; + finalcut::FStringStream ss4{"cat"}; + CPPUNIT_ASSERT ( ss3.str() == "dog" ); + CPPUNIT_ASSERT ( ss4.str() == "cat" ); + finalcut::swap (ss3, ss4); + CPPUNIT_ASSERT ( ss3.str() == "cat" ); + CPPUNIT_ASSERT ( ss4.str() == "dog" ); +} + +//---------------------------------------------------------------------- +void FStringStreamTest::rdbufTest() +{ + finalcut::FStringStream ss{}; + std::wostream os (ss.rdbuf()); // Associate stream buffer to stream + ss.rdbuf()->sputn (L"0x", 2); + os << std::hex << 255; + CPPUNIT_ASSERT ( ss.str() == "0xff" ); + CPPUNIT_ASSERT ( ss.str().getLength() == 4 ); + + ss.rdbuf()->str(L""); + CPPUNIT_ASSERT ( ss.str().isNull() ); + CPPUNIT_ASSERT ( ss.str().isEmpty() ); + CPPUNIT_ASSERT ( ss.str().getLength() == 0 ); +} + +//---------------------------------------------------------------------- +void FStringStreamTest::fileTest() +{ + std::string filename = "test.log"; + finalcut::FStringStream ss{}; + + { + std::ofstream file_stream(filename, std::ofstream::out); + ss << "FStringStream file test\n"; + file_stream << ss.str(); + + if ( file_stream.is_open() ) + file_stream.close(); + } + + std::string line{}; + std::ifstream file_stream{filename}; + + if ( ! file_stream.eof() && file_stream.good() ) + { + getline(file_stream, line); + CPPUNIT_ASSERT ( line == "FStringStream file test" ); + } + + if ( file_stream.is_open() ) + file_stream.close(); + + int ret = remove(filename.c_str()); // Delete file + + if ( ret == -1 ) + { + std::cerr << "Cannot delete the " << filename << " file"; + } +} + +// Put the test suite in the registry +CPPUNIT_TEST_SUITE_REGISTRATION (FStringStreamTest); + +// The general unit test main part +#include +