From ae1fdecb4092695516875ff504e56ae3d61a0553 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Wed, 18 Nov 2020 22:10:09 +0100 Subject: [PATCH 01/45] The terminal update rate is now limited to 60 Hz --- ChangeLog | 3 +++ examples/transparent.cpp | 2 +- src/fapplication.cpp | 33 ++---------------------- src/fmouse.cpp | 8 +++--- src/fvterm.cpp | 43 ++++++++++++++++---------------- src/include/final/fapplication.h | 3 --- src/include/final/fmouse.h | 4 +-- src/include/final/fvterm.h | 8 +++--- 8 files changed, 38 insertions(+), 66 deletions(-) diff --git a/ChangeLog b/ChangeLog index 117f37a9..864bc31b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2019-11-18 Markus Gans + * The terminal update rate is now limited to 60 Hz + 2019-11-14 Markus Gans * Version 0.7.1 * Bugfix: The cursor position was not changed anymore diff --git a/examples/transparent.cpp b/examples/transparent.cpp index b12392e1..b4cca03b 100644 --- a/examples/transparent.cpp +++ b/examples/transparent.cpp @@ -248,7 +248,7 @@ void MainWindow::onClose (finalcut::FCloseEvent* ev) //---------------------------------------------------------------------- void MainWindow::onShow (finalcut::FShowEvent*) { - addTimer(100); // Call onTimer() every 100 ms + addTimer(90); // Call onTimer() every 90 ms } //---------------------------------------------------------------------- diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 01878a30..f2d93803 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -73,7 +73,6 @@ FMouseControl* FApplication::mouse {nullptr}; // mouse control int FApplication::loop_level {0}; // event loop level int FApplication::quit_code {EXIT_SUCCESS}; bool FApplication::quit_now {false}; -bool FApplication::pending_updates {false}; uInt64 FApplication::next_event_wait {5000}; // 5 ms (200 Hz) struct timeval FApplication::time_last_event {}; @@ -391,9 +390,6 @@ void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev) void FApplication::processExternalUserEvent() { // This method can be overloaded and replaced by own code - - if ( FKeyboard::getReadBlockingTime() < 10000 ) - std::this_thread::sleep_for(std::chrono::milliseconds(5)); } @@ -758,9 +754,6 @@ void FApplication::mouseEvent (const FMouseData& md) unselectMenubarItems (md); sendMouseEvent (md); } - - if ( mouse ) - mouse->drawGpmPointer(); } //---------------------------------------------------------------------- @@ -1231,23 +1224,6 @@ void FApplication::sendWheelEvent ( const FMouseData& md } } -//---------------------------------------------------------------------- -inline void FApplication::flushTerminal() -{ - if ( ! pending_updates ) - return; - - if ( flush_count < 4 ) - { - flush_count++; - return; - } - - flush(); - flush_count = 0; - pending_updates = false; -} - //---------------------------------------------------------------------- FWidget* FApplication::processParameters (const int& argc, char* argv[]) { @@ -1328,11 +1304,8 @@ bool FApplication::processNextEvent() processMouseEvent(); processResizeEvent(); processCloseWidget(); - - if ( processTerminalUpdate() ) // after terminal changes - pending_updates = true; - - flushTerminal(); + processTerminalUpdate(); // after terminal changes + flush(); processLogger(); } @@ -1342,8 +1315,6 @@ bool FApplication::processNextEvent() { sendQueuedEvents(); num_events += processTimerEvent(); - uInt64 wait{next_event_wait / 2}; - std::this_thread::sleep_for(std::chrono::microseconds(wait)); } return ( num_events > 0 ); diff --git a/src/fmouse.cpp b/src/fmouse.cpp index d609959a..5db6a52c 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -510,7 +510,7 @@ bool FMouseGPM::getGpmKeyPressed (bool is_pending) } //---------------------------------------------------------------------- -void FMouseGPM::drawGpmPointer() const +void FMouseGPM::drawPointer() const { if ( isGpmMouseEnabled() && gpm_ev.x != -1 ) GPM_DRAWPOINTER(&gpm_ev); @@ -1605,7 +1605,7 @@ bool FMouseControl::getGpmKeyPressed (bool) //---------------------------------------------------------------------- #ifdef F_HAVE_LIBGPM -void FMouseControl::drawGpmPointer() +void FMouseControl::drawPointer() { if ( mouse_protocol.empty() ) return; @@ -1614,10 +1614,10 @@ void FMouseControl::drawGpmPointer() auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) - gpm_mouse->drawGpmPointer(); + gpm_mouse->drawPointer(); } #else // F_HAVE_LIBGPM -void FMouseControl::drawGpmPointer() +void FMouseControl::drawPointer() { } #endif // F_HAVE_LIBGPM diff --git a/src/fvterm.cpp b/src/fvterm.cpp index ecee8531..a46c1513 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -34,6 +34,7 @@ #include "final/fcolorpair.h" #include "final/fkeyboard.h" #include "final/flog.h" +#include "final/fmouse.h" #include "final/foptiattr.h" #include "final/foptimove.h" #include "final/fstyle.h" @@ -55,13 +56,14 @@ bool FVTerm::draw_completed{false}; bool FVTerm::no_terminal_updates{false}; bool FVTerm::cursor_hideable{false}; bool FVTerm::force_terminal_update{false}; -int FVTerm::skipped_terminal_update{0}; +uInt64 FVTerm::flush_wait{16667}; // 16.6 ms (60 Hz) uInt64 FVTerm::term_size_check_timeout{500000}; // 500 ms uInt FVTerm::erase_char_length{}; uInt FVTerm::repeat_char_length{}; uInt FVTerm::clr_bol_length{}; uInt FVTerm::clr_eol_length{}; uInt FVTerm::cursor_address_length{}; +struct timeval FVTerm::time_last_flush{}; struct timeval FVTerm::last_term_size_check{}; std::vector* FVTerm::output_buffer{nullptr}; FPoint* FVTerm::term_pos{nullptr}; @@ -71,7 +73,7 @@ FTerm* FVTerm::fterm{nullptr}; FVTerm::FTermArea* FVTerm::vterm{nullptr}; FVTerm::FTermArea* FVTerm::vdesktop{nullptr}; FVTerm::FTermArea* FVTerm::active_area{nullptr}; -FKeyboard* FVTerm::keyboard{nullptr}; +FMouseControl* FVTerm::mouse{nullptr}; FChar FVTerm::term_attribute{}; FChar FVTerm::next_attribute{}; FChar FVTerm::s_ch{}; @@ -280,25 +282,14 @@ bool FVTerm::updateTerminal() const } std::size_t changedlines = 0; - static constexpr int check_interval = 5; + for (uInt y{0}; y < uInt(vterm->height); y++) { if ( updateTerminalLine(y) ) changedlines++; - - if ( ! force_terminal_update - && changedlines % check_interval == 0 - && (keyboard->hasUnprocessedInput() || keyboard->isKeyPressed(0) ) - && skipped_terminal_update < max_skip ) - { - // Skipping terminal updates if there is unprocessed inputs - skipped_terminal_update++; - return false; - } } - skipped_terminal_update = 0; vterm->has_changes = false; // sets the new input cursor position @@ -586,7 +577,8 @@ void FVTerm::flush() { // Flush the output buffer - if ( ! output_buffer || output_buffer->empty() ) + if ( ! output_buffer || output_buffer->empty() + || ! (isFlushTimeout() || force_terminal_update) ) return; static const FTerm::defaultPutChar& FTermPutchar = FTerm::putchar(); @@ -599,6 +591,8 @@ void FVTerm::flush() output_buffer->clear(); std::fflush(stdout); + mouse->drawPointer(); + FObject::getCurrentTime (&time_last_flush); } @@ -1259,8 +1253,7 @@ bool FVTerm::processTerminalUpdate() const } // Update data on VTerm - if ( force_terminal_update || skipped_terminal_update == 0 ) - updateVTerm(); + updateVTerm(); // Update the visible terminal return updateTerminal(); @@ -1286,8 +1279,8 @@ void FVTerm::initTerminal() if ( fterm ) fterm->initTerminal(); - // Get FKeyboard object - keyboard = FTerm::getFKeyboard(); + // Get the global FMouseControl object + mouse = FTerm::getFMouseControl(); // Hide the input cursor cursor_hideable = FTerm::isCursorHideable(); @@ -1863,7 +1856,9 @@ void FVTerm::init() vdesktop->visible = true; active_area = vdesktop; - // Initialize the last terminal size check time + // Initialize the flush and last terminal size check time + time_last_flush.tv_sec = 0; + time_last_flush.tv_usec = 0; last_term_size_check.tv_sec = 0; last_term_size_check.tv_usec = 0; } @@ -1902,7 +1897,7 @@ void FVTerm::finish() && FTerm::getFTermData()->isInAlternateScreen() ) clearTerm(); - flush(); + forceTerminalUpdate(); if ( output_buffer ) delete output_buffer; @@ -2866,6 +2861,12 @@ inline bool FVTerm::isTermSizeChanged() const return false; } +//---------------------------------------------------------------------- +inline bool FVTerm::isFlushTimeout() +{ + return FObject::isTimeout (&time_last_flush, flush_wait); +} + //---------------------------------------------------------------------- inline bool FVTerm::isTermSizeCheckTimeout() { diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index bb6dacd2..79ba0bc5 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -222,7 +222,6 @@ class FApplication : public FWidget void sendWheelEvent ( const FMouseData& , const FPoint& , const FPoint& ) const; - void flushTerminal(); static FWidget* processParameters (const int&, char*[]); void processResizeEvent() const; void processCloseWidget(); @@ -240,13 +239,11 @@ class FApplication : public FWidget std::streambuf* default_clog_rdbuf{std::clog.rdbuf()}; FWidget* clicked_widget{}; FEventQueue event_queue{}; - int flush_count{0}; static uInt64 next_event_wait; static timeval time_last_event; static int loop_level; static int quit_code; static bool quit_now; - static bool pending_updates; static FMouseControl* mouse; static FKeyboard* keyboard; static FWidget* keyboard_widget; diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index 28ad2800..e265c9e7 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -279,7 +279,7 @@ class FMouseGPM final : public FMouse void interpretKeyDown(); void interpretKeyUp(); bool getGpmKeyPressed(bool); - void drawGpmPointer() const; + void drawPointer() const; private: // Enumeration @@ -578,7 +578,7 @@ class FMouseControl virtual void processEvent (struct timeval* time); void processQueuedInput(); bool getGpmKeyPressed (bool); - void drawGpmPointer(); + void drawPointer(); private: // Typedef diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index c96a0a22..db0c3a91 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -68,7 +68,6 @@ namespace finalcut // class forward declaration class FColorPair; -class FKeyboard; class FMouseControl; class FPoint; class FRect; @@ -341,7 +340,6 @@ class FVTerm // Constants // Buffer size for character output on the terminal static constexpr uInt TERMINAL_OUTPUT_BUFFER_SIZE = 131072; - static constexpr int max_skip = 2; // Methods void resetTextAreaToDefault ( const FTermArea* @@ -408,6 +406,7 @@ class FVTerm bool updateTerminalCursor() const; bool isInsideTerminal (const FPoint&) const; bool isTermSizeChanged() const; + static bool isFlushTimeout(); static bool isTermSizeCheckTimeout(); static bool hasPendingUpdates (const FTermArea*); static void markAsPrinted (uInt, uInt); @@ -438,12 +437,13 @@ class FVTerm static FChar s_ch; // shadow character static FChar i_ch; // inherit background character static FPoint* term_pos; // terminal cursor position - static FKeyboard* keyboard; + static FMouseControl* mouse; + static timeval time_last_flush; static timeval last_term_size_check; static bool draw_completed; static bool no_terminal_updates; static bool force_terminal_update; - static int skipped_terminal_update; + static uInt64 flush_wait; static uInt64 term_size_check_timeout; static uInt erase_char_length; static uInt repeat_char_length; From 25f2abe175f8bd659c524bf5c8404ad9a9cd67dc Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Wed, 18 Nov 2020 23:57:31 +0100 Subject: [PATCH 02/45] Bug fix for the FMouseControl unit test --- test/fmouse-test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fmouse-test.cpp b/test/fmouse-test.cpp index 01120179..c6002b75 100644 --- a/test/fmouse-test.cpp +++ b/test/fmouse-test.cpp @@ -1260,7 +1260,7 @@ void FMouseTest::mouseControlTest() if ( mouse_control.isGpmMouseEnabled() ) { CPPUNIT_ASSERT ( ! mouse_control.getGpmKeyPressed(false) ); - mouse_control.drawGpmPointer(); + mouse_control.drawPointer(); } // Left mouse button pressed on an X11 mouse From 7868a0dee9227a1f544fb41f93fddd4d09da3fa6 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 24 Nov 2020 21:06:39 +0100 Subject: [PATCH 03/45] Use of default destructors --- examples/7segment.cpp | 5 +- examples/background-color.cpp | 9 +- examples/calculator.cpp | 6 +- examples/checklist.cpp | 6 +- examples/choice.cpp | 4 +- examples/listbox.cpp | 6 +- examples/listview.cpp | 6 +- examples/mandelbrot.cpp | 6 +- examples/menu.cpp | 6 +- examples/mouse.cpp | 18 +- examples/rotozoomer.cpp | 6 +- examples/scrollview.cpp | 12 +- examples/term-attributes.cpp | 9 +- examples/transparent.cpp | 32 ++- examples/treeview.cpp | 303 +++++++++++++++------------- examples/ui.cpp | 12 +- examples/watch.cpp | 6 +- examples/windows.cpp | 67 +++--- src/fbuttongroup.cpp | 4 +- src/fcheckbox.cpp | 4 +- src/fcheckmenuitem.cpp | 3 +- src/fcombobox.cpp | 4 +- src/fdialoglistmenu.cpp | 3 +- src/fevent.cpp | 44 ---- src/fkeyboard.cpp | 3 - src/flistbox.cpp | 8 +- src/flistview.cpp | 54 +---- src/fmessagebox.cpp | 25 +-- src/fmouse.cpp | 145 ++++++------- src/fobject.cpp | 41 ++-- src/foptiattr.cpp | 4 - src/foptimove.cpp | 9 +- src/fpoint.cpp | 19 -- src/fprogressbar.cpp | 3 +- src/fradiobutton.cpp | 3 +- src/fradiomenuitem.cpp | 3 +- src/frect.cpp | 24 --- src/fsize.cpp | 19 -- src/fspinbox.cpp | 3 +- src/fstartoptions.cpp | 26 +-- src/fstatusbar.cpp | 4 +- src/fswitch.cpp | 3 +- src/fsystem.cpp | 9 +- src/fsystemimpl.cpp | 6 +- src/fterm.cpp | 3 +- src/fterm_functions.cpp | 20 +- src/ftermbuffer.cpp | 9 +- src/ftermcapquirks.cpp | 10 - src/ftermios.cpp | 4 - src/ftermopenbsd.cpp | 5 - src/ftermxterminal.cpp | 4 - src/ftextview.cpp | 3 +- src/ftogglebutton.cpp | 2 +- src/fvterm.cpp | 3 +- src/include/final/fbuttongroup.h | 2 +- src/include/final/fcheckbox.h | 2 +- src/include/final/fcheckmenuitem.h | 2 +- src/include/final/fcombobox.h | 2 +- src/include/final/fdialoglistmenu.h | 2 +- src/include/final/fevent.h | 22 +- src/include/final/fkeyboard.h | 2 +- src/include/final/flineedit.h | 4 +- src/include/final/flistbox.h | 4 +- src/include/final/flistview.h | 16 +- src/include/final/fmenubar.h | 11 +- src/include/final/fmessagebox.h | 13 +- src/include/final/fmouse.h | 13 +- src/include/final/fobject.h | 9 +- src/include/final/foptiattr.h | 7 +- src/include/final/foptimove.h | 4 +- src/include/final/fpoint.h | 21 +- src/include/final/fprogressbar.h | 2 +- src/include/final/fradiobutton.h | 2 +- src/include/final/fradiomenuitem.h | 2 +- src/include/final/frect.h | 27 +-- src/include/final/fscrollbar.h | 6 +- src/include/final/fsize.h | 21 +- src/include/final/fspinbox.h | 2 +- src/include/final/fstartoptions.h | 5 +- src/include/final/fstring.h | 4 +- src/include/final/fstyle.h | 15 -- src/include/final/fswitch.h | 2 +- src/include/final/fsystem.h | 4 +- src/include/final/fsystemimpl.h | 4 +- src/include/final/fterm.h | 8 +- src/include/final/ftermbuffer.h | 2 +- src/include/final/ftermcapquirks.h | 4 +- src/include/final/ftermdata.h | 6 +- src/include/final/ftermdetection.h | 5 +- src/include/final/ftermfreebsd.h | 4 +- src/include/final/ftermios.h | 2 +- src/include/final/ftermlinux.h | 13 +- src/include/final/ftermopenbsd.h | 2 +- src/include/final/ftermxterminal.h | 2 +- src/include/final/ftextview.h | 2 +- src/include/final/ftogglebutton.h | 2 +- src/include/final/ftypes.h | 81 ++++---- src/include/final/fvterm.h | 60 ++---- src/include/final/fwidget.h | 14 +- src/include/final/sgr_optimizer.h | 2 +- src/sgr_optimizer.cpp | 4 - 101 files changed, 533 insertions(+), 967 deletions(-) diff --git a/examples/7segment.cpp b/examples/7segment.cpp index 6a16fd6c..b2021d74 100644 --- a/examples/7segment.cpp +++ b/examples/7segment.cpp @@ -44,8 +44,7 @@ class SegmentView final : public finalcut::FDialog explicit SegmentView (finalcut::FWidget* = nullptr); private: - // Typedef - typedef struct + struct sevenSegment { unsigned char a : 1; unsigned char b : 1; @@ -55,7 +54,7 @@ class SegmentView final : public finalcut::FDialog unsigned char f : 1; unsigned char g : 1; unsigned char : 1; // padding bit - } sevenSegment; + }; // Methods void hexEncoding(); diff --git a/examples/background-color.cpp b/examples/background-color.cpp index d52c6a1f..97c49f3a 100644 --- a/examples/background-color.cpp +++ b/examples/background-color.cpp @@ -38,8 +38,8 @@ using finalcut::FSize; class Background final : public finalcut::FDialog { public: - // Typedef - typedef std::tuple RGB; + // Using-declaration + using RGB = std::tuple; // Constructor explicit Background (finalcut::FWidget* = nullptr); @@ -48,7 +48,7 @@ class Background final : public finalcut::FDialog Background (const Background&) = delete; // Destructor - ~Background(); + ~Background() noexcept override; // Disable copy assignment operator (=) Background& operator = (const Background&) = delete; @@ -169,8 +169,7 @@ Background::Background (finalcut::FWidget* parent) } //---------------------------------------------------------------------- -Background::~Background() // destructor -{ } +Background::~Background() noexcept = default; // destructor //---------------------------------------------------------------------- void Background::cb_changed() diff --git a/examples/calculator.cpp b/examples/calculator.cpp index a1e46fa1..c8912c33 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -118,7 +118,7 @@ class Calc final : public finalcut::FDialog explicit Calc (finalcut::FWidget* parent = nullptr); // Destructor - ~Calc() override; + ~Calc() override = default; private: // Typedef and Enumeration @@ -305,10 +305,6 @@ Calc::Calc (FWidget* parent) calculator_buttons[Equals]->addAccelerator(fc::Fkey_enter); } -//---------------------------------------------------------------------- -Calc::~Calc() -{ } - //---------------------------------------------------------------------- void Calc::onKeyPress (finalcut::FKeyEvent* ev) { diff --git a/examples/checklist.cpp b/examples/checklist.cpp index 6469a68e..a6ca7b90 100644 --- a/examples/checklist.cpp +++ b/examples/checklist.cpp @@ -51,7 +51,7 @@ class CheckList final : public finalcut::FDialog CheckList (const CheckList&) = delete; // Destructor - ~CheckList() override; + ~CheckList() override = default; // Disable copy assignment operator (=) CheckList& operator = (const CheckList&) = delete; @@ -115,10 +115,6 @@ CheckList::CheckList (finalcut::FWidget* parent) ); } -//---------------------------------------------------------------------- -CheckList::~CheckList() // destructor -{ } - //---------------------------------------------------------------------- void CheckList::populate() { diff --git a/examples/choice.cpp b/examples/choice.cpp index beec8393..c0c2f4b2 100644 --- a/examples/choice.cpp +++ b/examples/choice.cpp @@ -27,8 +27,8 @@ using finalcut::FPoint; using finalcut::FSize; -// Typedef -typedef std::shared_ptr FRadioButtonPtr; +// Using-declaration +using FRadioButtonPtr = std::shared_ptr; // Function prototypes void cb_quit (finalcut::FDialog&); diff --git a/examples/listbox.cpp b/examples/listbox.cpp index e1af5c0e..f47a937b 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -87,7 +87,7 @@ class Listbox final : public FDialog Listbox (const Listbox&) = delete; // Destructor - ~Listbox() override; + ~Listbox() override = default; // Disable copy assignment operator (=) Listbox& operator = (const Listbox&) = delete; @@ -164,10 +164,6 @@ Listbox::Listbox (FWidget* parent) ); } -//---------------------------------------------------------------------- -Listbox::~Listbox() // destructor -{ } - //---------------------------------------------------------------------- void Listbox::onClose (FCloseEvent* ev) { diff --git a/examples/listview.cpp b/examples/listview.cpp index a0478895..d039a82b 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -47,7 +47,7 @@ class Listview final : public finalcut::FDialog Listview (const Listview&) = delete; // Destructor - ~Listview() override; + ~Listview() override = default; // Disable copy assignment operator (=) Listview& operator = (const Listview&) = delete; @@ -124,10 +124,6 @@ Listview::Listview (finalcut::FWidget* parent) ); } -//---------------------------------------------------------------------- -Listview::~Listview() // destructor -{ } - //---------------------------------------------------------------------- void Listview::populate() { diff --git a/examples/mandelbrot.cpp b/examples/mandelbrot.cpp index e087776a..8c70b9e7 100644 --- a/examples/mandelbrot.cpp +++ b/examples/mandelbrot.cpp @@ -38,7 +38,7 @@ class Mandelbrot final : public finalcut::FDialog explicit Mandelbrot (finalcut::FWidget* = nullptr); // Destructor - ~Mandelbrot() override; + ~Mandelbrot() override = default; // Event handlers void onKeyPress (finalcut::FKeyEvent*) override; @@ -58,10 +58,6 @@ Mandelbrot::Mandelbrot (finalcut::FWidget* parent) FDialog::setText ("Mandelbrot set"); } -//---------------------------------------------------------------------- -Mandelbrot::~Mandelbrot() -{ } - //---------------------------------------------------------------------- void Mandelbrot::draw() { diff --git a/examples/menu.cpp b/examples/menu.cpp index a60dd65e..9b36fcd2 100644 --- a/examples/menu.cpp +++ b/examples/menu.cpp @@ -41,7 +41,7 @@ class Menu final : public finalcut::FDialog Menu (const Menu&) = delete; // Destructor - ~Menu() override; + ~Menu() override = default; // Disable copy assignment operator (=) Menu& operator = (const Menu&) = delete; @@ -157,10 +157,6 @@ Menu::Menu (finalcut::FWidget* parent) Info.setGeometry(FPoint{2, 1}, FSize{36, 5}); } -//---------------------------------------------------------------------- -Menu::~Menu() -{ } - //---------------------------------------------------------------------- void Menu::configureFileMenuItems() { diff --git a/examples/mouse.cpp b/examples/mouse.cpp index 99730553..924fb7a6 100644 --- a/examples/mouse.cpp +++ b/examples/mouse.cpp @@ -43,7 +43,7 @@ class ColorChooser final : public finalcut::FWidget ColorChooser (const ColorChooser&) = delete; // Destructor - ~ColorChooser() override; + ~ColorChooser() override = default; // Disable copy assignment operator (=) ColorChooser& operator = (const ColorChooser&) = delete; @@ -85,10 +85,6 @@ ColorChooser::ColorChooser (finalcut::FWidget* parent) headline << "Color"; } -//---------------------------------------------------------------------- -ColorChooser::~ColorChooser() -{ } - //---------------------------------------------------------------------- inline FColor ColorChooser::getForeground() const { @@ -186,7 +182,7 @@ class Brushes final : public finalcut::FWidget Brushes (const Brushes&) = delete; // Destructor - ~Brushes() override; + ~Brushes() override = default; // Disable copy assignment operator (=) Brushes& operator = (const Brushes&) = delete; @@ -231,10 +227,6 @@ Brushes::Brushes (finalcut::FWidget* parent) headline << "Brush"; } -//---------------------------------------------------------------------- -Brushes::~Brushes() -{ } - //---------------------------------------------------------------------- void Brushes::setSize (const FSize& size, bool adjust) { @@ -328,7 +320,7 @@ class MouseDraw final : public finalcut::FDialog MouseDraw (const MouseDraw&) = delete; // Destructor - ~MouseDraw() override; + ~MouseDraw() override = default; // Disable copy assignment operator (=) MouseDraw& operator = (const MouseDraw&) = delete; @@ -377,10 +369,6 @@ MouseDraw::MouseDraw (finalcut::FWidget* parent) brush.setPos (FPoint{1, 12}); } -//---------------------------------------------------------------------- -MouseDraw::~MouseDraw() -{ } - //---------------------------------------------------------------------- void MouseDraw::setGeometry ( const FPoint& p, const FSize& s, bool adjust) { diff --git a/examples/rotozoomer.cpp b/examples/rotozoomer.cpp index 698ea38e..753631a7 100644 --- a/examples/rotozoomer.cpp +++ b/examples/rotozoomer.cpp @@ -53,7 +53,7 @@ class RotoZoomer final : public finalcut::FDialog explicit RotoZoomer (finalcut::FWidget* = nullptr, bool = false, int = 314); // Destructor - ~RotoZoomer() override; + ~RotoZoomer() override = default; // Accessors finalcut::FString getReport() const; @@ -123,10 +123,6 @@ RotoZoomer::RotoZoomer (finalcut::FWidget* parent, bool b, int l) } } -//---------------------------------------------------------------------- -RotoZoomer::~RotoZoomer() -{ } - //---------------------------------------------------------------------- void RotoZoomer::draw() { diff --git a/examples/scrollview.cpp b/examples/scrollview.cpp index 7453bfbf..0042e9db 100644 --- a/examples/scrollview.cpp +++ b/examples/scrollview.cpp @@ -41,7 +41,7 @@ class Scrollview final : public finalcut::FScrollView Scrollview (const Scrollview&) = delete; // Destructor - ~Scrollview() override; + ~Scrollview() override = default; // Disable copy assignment operator (=) Scrollview& operator = (const Scrollview&) = delete; @@ -110,10 +110,6 @@ Scrollview::Scrollview (finalcut::FWidget* parent) ); } -//---------------------------------------------------------------------- -Scrollview::~Scrollview() -{ } - //---------------------------------------------------------------------- void Scrollview::setScrollSize (const FSize& size) { @@ -197,7 +193,7 @@ class Scrollviewdemo final : public finalcut::FDialog explicit Scrollviewdemo (finalcut::FWidget* = nullptr); // Destructor - ~Scrollviewdemo() override; + ~Scrollviewdemo() override = default; // Event handler void onClose (finalcut::FCloseEvent*) override; @@ -240,10 +236,6 @@ Scrollviewdemo::Scrollviewdemo (finalcut::FWidget* parent) label << L"Use scrollbars to change the viewport position"; } -//---------------------------------------------------------------------- -Scrollviewdemo::~Scrollviewdemo() -{ } - //---------------------------------------------------------------------- void Scrollviewdemo::cb_quit() { diff --git a/examples/term-attributes.cpp b/examples/term-attributes.cpp index f7da8ef3..e26d4a24 100644 --- a/examples/term-attributes.cpp +++ b/examples/term-attributes.cpp @@ -44,7 +44,7 @@ class AttribDlg final : public finalcut::FDialog AttribDlg (const AttribDlg&) = delete; // Destructor - ~AttribDlg() override; + ~AttribDlg() override = default; // Disable copy assignment operator (=) AttribDlg& operator = (const AttribDlg&) = delete; @@ -100,10 +100,6 @@ AttribDlg::AttribDlg (finalcut::FWidget* parent) ); } -//---------------------------------------------------------------------- -AttribDlg::~AttribDlg() -{ } - //---------------------------------------------------------------------- FColor AttribDlg::getBGColor() const { @@ -226,8 +222,7 @@ class AttribDemo final : public finalcut::FWidget explicit AttribDemo (FWidget* = nullptr); // Destructor - ~AttribDemo() override - { } + ~AttribDemo() override = default; // Event handler void onWheel (finalcut::FWheelEvent* ev) override diff --git a/examples/transparent.cpp b/examples/transparent.cpp index b4cca03b..307e5208 100644 --- a/examples/transparent.cpp +++ b/examples/transparent.cpp @@ -36,23 +36,23 @@ using finalcut::FStyle; class Transparent final : public finalcut::FDialog { public: - // Typedef and Enumeration - typedef enum ttype + // Enumeration + enum class Type { transparent = 0, shadow = 1, inherit_background = 2 - } trans_type; + }; // Constructor explicit Transparent ( finalcut::FWidget* = nullptr - , trans_type = transparent ); + , Type = Type::transparent ); // Disable copy constructor Transparent (const Transparent&) = delete; // Destructor - ~Transparent() override; + ~Transparent() override = default; // Disable copy assignment operator (=) Transparent& operator = (const Transparent&) = delete; @@ -65,12 +65,12 @@ class Transparent final : public finalcut::FDialog void onKeyPress (finalcut::FKeyEvent* ev) override; // Data members - trans_type type; + Type type; }; //---------------------------------------------------------------------- Transparent::Transparent ( finalcut::FWidget* parent - , Transparent::trans_type tt ) + , Transparent::Type tt ) : finalcut::FDialog{parent} , type{tt} { @@ -80,10 +80,6 @@ Transparent::Transparent ( finalcut::FWidget* parent FWidget::setStatusbarMessage("Press Q to quit"); } -//---------------------------------------------------------------------- -Transparent::~Transparent() -{ } - //---------------------------------------------------------------------- void Transparent::draw() { @@ -92,13 +88,13 @@ void Transparent::draw() if ( finalcut::FTerm::isMonochron() ) setReverse(true); - if ( type == shadow ) + if ( type == Type::shadow ) { const auto& wc = getColorTheme(); print() << FColorPair {wc->shadow_bg, wc->shadow_fg} << FStyle {fc::ColorOverlay}; } - else if ( type == inherit_background ) + else if ( type == Type::inherit_background ) { if ( finalcut::FTerm::getMaxColor() > 8 ) print() << FColorPair {fc::Blue, fc::Black}; @@ -152,7 +148,7 @@ class MainWindow final : public finalcut::FDialog MainWindow (const MainWindow&) = delete; // Destructor - ~MainWindow() override; + ~MainWindow() override = default; // Disable copy assignment operator (=) MainWindow& operator = (const MainWindow&) = delete; @@ -202,12 +198,12 @@ MainWindow::MainWindow (finalcut::FWidget* parent) transpwin->setGeometry (FPoint{6, 3}, FSize{29, 12}); transpwin->unsetTransparentShadow(); - shadowwin = new Transparent(this, Transparent::shadow); + shadowwin = new Transparent(this, Transparent::Type::shadow); shadowwin->setText("shadow"); shadowwin->setGeometry (FPoint{46, 11}, FSize{29, 12}); shadowwin->unsetTransparentShadow(); - ibg = new Transparent(this, Transparent::inherit_background); + ibg = new Transparent(this, Transparent::Type::inherit_background); ibg->setText("inherit background"); ibg->setGeometry (FPoint{42, 3}, FSize{29, 7}); ibg->unsetTransparentShadow(); @@ -219,10 +215,6 @@ MainWindow::MainWindow (finalcut::FWidget* parent) activateDialog(); } -//---------------------------------------------------------------------- -MainWindow::~MainWindow() -{ } - //---------------------------------------------------------------------- void MainWindow::draw() { diff --git a/examples/treeview.cpp b/examples/treeview.cpp index 3f3d8123..469f265e 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -151,7 +151,7 @@ class Treeview final : public finalcut::FDialog Treeview (const Treeview&) = delete; // Destructor - ~Treeview() override; + ~Treeview() override = default; // Disable copy assignment operator (=) Treeview& operator = (const Treeview&) = delete; @@ -161,6 +161,12 @@ class Treeview final : public finalcut::FDialog struct TreeItem; // forward declaration // Methods + auto initAfrica() -> std::initializer_list; + auto initAsia() -> std::initializer_list; + auto initEurope() -> std::initializer_list; + auto initNorthAmerica() -> std::initializer_list; + auto initSouthAmerica() -> std::initializer_list; + auto initOceania() -> std::initializer_list; void adjustSize() override; // Event handler @@ -170,12 +176,12 @@ class Treeview final : public finalcut::FDialog bool initialized{false}; finalcut::FListView listview{this}; finalcut::FButton quit{this}; - static TreeItem africa[]; - static TreeItem asia[]; - static TreeItem europe[]; - static TreeItem north_america[]; - static TreeItem south_america[]; - static TreeItem oceania[]; + std::vector africa{initAfrica()}; + std::vector asia{initAsia()}; + std::vector europe{initEurope()}; + std::vector north_america{initNorthAmerica()}; + std::vector south_america{initSouthAmerica()}; + std::vector oceania{initOceania()}; }; @@ -195,133 +201,9 @@ struct Treeview::TreeItem const char* name; const char* population; const char* density; - TreeItem* child_element; + std::vector child_element; }; -//---------------------------------------------------------------------- -// class Treeview - array data -//---------------------------------------------------------------------- -Treeview::TreeItem Treeview::africa[] = -{ - { "Algeria", "40,400,000", "15.9", nullptr }, - { "Angola", "25,789,024", "20.69", nullptr }, - { "Botswana", "2,250,260", "3.7", nullptr }, - { "Cameroon", "22,534,532", "39.7", nullptr }, - { "Chad", "13,670,084", "8.6", nullptr }, - { "Egypt", "94,666,000", "87", nullptr }, - { "Ethiopia", "102,374,044", "92.7", nullptr }, - { "Ivory Coast", "23,740,424", "63.9", nullptr }, - { "Libya", "6,541,948", "3.55", nullptr }, - { "Madagascar", "24,430,325", "35.2", nullptr }, - { "Mali", "14,517,176", "11.7", nullptr }, - { "Mauritania", "4,301,018", "3.4", nullptr }, - { "Mozambique", "24,692,144", "28.7", nullptr }, - { "Namibia", "2,113,077", "2.54", nullptr }, - { "Niger", "20,672,987", "12.1", nullptr }, - { "Nigeria", "185,989,640", "197.2", nullptr }, - { "Somalia", "14,317,996", "19.31", nullptr }, - { "South Africa", "54,956,900", "42.4", nullptr }, - { "South Sudan", "12,340,000", "13.33", nullptr }, - { "Sudan", "39,578,828", "21.3", nullptr }, - { "Tanzania", "51,820,00", "47.5", nullptr }, - { "Zambia", "16,212,000", "17.2", nullptr }, - { nullptr, nullptr, nullptr, nullptr } -}; - -Treeview::TreeItem Treeview::asia[] = -{ - { "Afghanistan", "34,656,032", "49.88", nullptr }, - { "China", "1,403,500,365", "145.0", nullptr }, - { "India", "1,324,171,354", "393.9", nullptr }, - { "Indonesia", "261,115,456", "124.66", nullptr }, - { "Iran", "80,829,192", "48.0", nullptr }, - { "Iraq", "37,202,572", "82.7", nullptr }, - { "Japan", "126,740,000", "336.0", nullptr }, - { "Kazakhstan", "17,987,736", "6.49", nullptr }, - { "Mongolia", "3,081,677", "1.97", nullptr }, - { "Myanmar", "51,486,253", "76.0", nullptr }, - { "Pakistan", "207,774,520", "244.4", nullptr }, - { "Russia", "144,463,451", "8.4", nullptr }, - { "Saudi Arabia", "33,000,000", "15.0", nullptr }, - { "Thailand", "68,863,514", "132.1", nullptr }, - { "Turkey", "79,814,871", "102.0", nullptr }, - { "Turkmenistan", "5,662,544", "10.5", nullptr }, - { "Uzbekistan", "32,979,000", "70.5", nullptr }, - { "Vietnam", "94,569,072", "276.03", nullptr }, - { "Yemen", "27,584,213", "44.7", nullptr }, - { nullptr, nullptr, nullptr, nullptr } -}; - -Treeview::TreeItem Treeview::europe[] = -{ - { "Austria", "8,794,267", "104.0", nullptr }, - { "Belarus", "9,498,700", "45.8", nullptr }, - { "Bulgaria", "7,101,859", "64.9", nullptr }, - { "Czech Republic", "10,610,947", "134.0", nullptr }, - { "Finland", "5,506,312", "16.0", nullptr }, - { "France", "66,991,000", "103.0", nullptr }, - { "Germany", "82,175,700", "227.0", nullptr }, - { "Greece", "11,183,716", "82.0", nullptr }, - { "Hungary", "9,797,561", "105.3", nullptr }, - { "Iceland", "332,529", "3.2", nullptr }, - { "Italy", "60,589,445", "201.3", nullptr }, - { "Norway", "5,267,146", "15.8", nullptr }, - { "Poland", "38,634,007", "123.0", nullptr }, - { "Portugal", "10,309,573", "115.0", nullptr }, - { "Romania", "19,638,000", "84.4", nullptr }, - { "Serbia", "7,058,322", "91.1", nullptr }, - { "Spain", "46,468,102", "92.0", nullptr }, - { "Sweden", "10,065,389", "22.0", nullptr }, - { "United Kingdom", "65,648,000", "270.7", nullptr }, - { nullptr, nullptr, nullptr, nullptr } -}; - - -Treeview::TreeItem Treeview::north_america[] = -{ - { "Canada", "35,151,728", "3.92", nullptr }, - { "Cuba", "11,239,224", "102.3", nullptr }, - { "Greenland", "56,483", "0.028", nullptr }, - { "Guatemala", "16,582,469", "129.0", nullptr }, - { "Honduras", "9,112,867", "64.0", nullptr }, - { "Mexico", "119,530,753", "61.0", nullptr }, - { "Nicaragua", "6,167,237", "51.0", nullptr }, - { "USA", "325,365,189", "35.0", nullptr }, - { nullptr, nullptr, nullptr, nullptr } -}; - -Treeview::TreeItem Treeview::south_america[] = -{ - { "Argentina", "43,847,430", "14.4", nullptr }, - { "Bolivia", "11,410,651", "10.4", nullptr }, - { "Brazil", "208,064,000", "24.35", nullptr }, - { "Chile", "18,006,407", "24.0", nullptr }, - { "Colombia", "49,364,592", "40.74", nullptr }, - { "Ecuador", "16,385,068", "58.95", nullptr }, - { "Guyana", "773,303", "3.502", nullptr }, - { "Paraguay", "6,725,308", "17.2", nullptr }, - { "Peru", "31,826,018", "23.0", nullptr }, - { "Venezuela", "31,568,179", "33.75", nullptr }, - { nullptr, nullptr, nullptr, nullptr } -}; - -Treeview::TreeItem Treeview::oceania[] = -{ - { "Australia", "24,675,900", "3.2", nullptr }, - { "Papua New Guinea", "7,059,653", "15.0", nullptr }, - { "Papua", "3,486,432", "11.0", nullptr }, - { "New Zealand", "4,823,090", "17.5", nullptr }, - { "West Papua", "877,437", "6.3", nullptr }, - { "Solomon Islands", "599,419", "18.1", nullptr }, - { "New Caledonia", "268,767", "14.5", nullptr }, - { "Fiji", "898,76", "46.4", nullptr }, - { "Hawaii", "1,428,557", "82.6", nullptr }, - { "Vanuatu", "270,402", "19.7", nullptr }, - { "French Polynesia", "280,208", "76.0", nullptr }, - { "Samoa", "192,342", "68.0", nullptr }, - { "Kiribati", "110,136", "152.0", nullptr }, - { nullptr, nullptr, nullptr, nullptr } -}; // constructors and destructor //---------------------------------------------------------------------- @@ -351,30 +233,28 @@ Treeview::Treeview (finalcut::FWidget* parent) listview.setTreeView(); // Populate FListView with a list of items - static TreeItem continent_list[] = + const std::vector continent_list { { "Africa", "944,000,000", "31.2", africa }, { "Asia", "4,010,000,000", "90.3", asia }, { "Europe", "733,000,000", "69.9", europe }, { "North America", "523,000,000", "21", north_america }, { "South America", "381,000,000", "21.4", south_america }, - { "Antarctica", "1000", "0", nullptr }, + { "Antarctica", "1000", "0", {} }, { "Australia/Oceania", "34,000,000", "4", oceania } }; for (const auto& continent : continent_list) { - const TreeItem* country_list = continent.child_element; finalcut::FStringList continent_line ( continent.begin() , continent.end() ); auto iter = listview.insert (continent_line); - while ( country_list && country_list->name ) + for (const auto& country : continent.child_element) { - finalcut::FStringList country_line ( country_list->begin() - , country_list->end() ); + finalcut::FStringList country_line ( country.begin() + , country.end() ); listview.insert (country_line, iter); - country_list++; } } @@ -395,8 +275,149 @@ Treeview::Treeview (finalcut::FWidget* parent) } //---------------------------------------------------------------------- -Treeview::~Treeview() // destructor -{ } +auto Treeview::initAfrica() -> std::initializer_list +{ + static const auto list = std::initializer_list + { + { "Algeria", "40,400,000", "15.9", {} }, + { "Angola", "25,789,024", "20.69", {} }, + { "Botswana", "2,250,260", "3.7", {} }, + { "Cameroon", "22,534,532", "39.7", {} }, + { "Chad", "13,670,084", "8.6", {} }, + { "Egypt", "94,666,000", "87", {} }, + { "Ethiopia", "102,374,044", "92.7", {} }, + { "Ivory Coast", "23,740,424", "63.9", {} }, + { "Libya", "6,541,948", "3.55", {} }, + { "Madagascar", "24,430,325", "35.2", {} }, + { "Mali", "14,517,176", "11.7", {} }, + { "Mauritania", "4,301,018", "3.4", {} }, + { "Mozambique", "24,692,144", "28.7", {} }, + { "Namibia", "2,113,077", "2.54", {} }, + { "Niger", "20,672,987", "12.1", {} }, + { "Nigeria", "185,989,640", "197.2", {} }, + { "Somalia", "14,317,996", "19.31", {} }, + { "South Africa", "54,956,900", "42.4", {} }, + { "South Sudan", "12,340,000", "13.33", {} }, + { "Sudan", "39,578,828", "21.3", {} }, + { "Tanzania", "51,820,00", "47.5", {} }, + { "Zambia", "16,212,000", "17.2", {} } + }; + return list; +} + +//---------------------------------------------------------------------- +auto Treeview::initAsia() -> std::initializer_list +{ + static const auto list = std::initializer_list + { + { "Afghanistan", "34,656,032", "49.88", {} }, + { "China", "1,403,500,365", "145.0", {} }, + { "India", "1,324,171,354", "393.9", {} }, + { "Indonesia", "261,115,456", "124.66", {} }, + { "Iran", "80,829,192", "48.0", {} }, + { "Iraq", "37,202,572", "82.7", {} }, + { "Japan", "126,740,000", "336.0", {} }, + { "Kazakhstan", "17,987,736", "6.49", {} }, + { "Mongolia", "3,081,677", "1.97", {} }, + { "Myanmar", "51,486,253", "76.0", {} }, + { "Pakistan", "207,774,520", "244.4", {} }, + { "Russia", "144,463,451", "8.4", {} }, + { "Saudi Arabia", "33,000,000", "15.0", {} }, + { "Thailand", "68,863,514", "132.1", {} }, + { "Turkey", "79,814,871", "102.0", {} }, + { "Turkmenistan", "5,662,544", "10.5", {} }, + { "Uzbekistan", "32,979,000", "70.5", {} }, + { "Vietnam", "94,569,072", "276.03", {} }, + { "Yemen", "27,584,213", "44.7", {} } + }; + return list; +} + +//---------------------------------------------------------------------- +auto Treeview::initEurope() -> std::initializer_list +{ + static const auto list = std::initializer_list + { + { "Austria", "8,794,267", "104.0", {} }, + { "Belarus", "9,498,700", "45.8", {} }, + { "Bulgaria", "7,101,859", "64.9", {} }, + { "Czech Republic", "10,610,947", "134.0", {} }, + { "Finland", "5,506,312", "16.0", {} }, + { "France", "66,991,000", "103.0", {} }, + { "Germany", "82,175,700", "227.0", {} }, + { "Greece", "11,183,716", "82.0", {} }, + { "Hungary", "9,797,561", "105.3", {} }, + { "Iceland", "332,529", "3.2", {} }, + { "Italy", "60,589,445", "201.3", {} }, + { "Norway", "5,267,146", "15.8", {} }, + { "Poland", "38,634,007", "123.0", {} }, + { "Portugal", "10,309,573", "115.0", {} }, + { "Romania", "19,638,000", "84.4", {} }, + { "Serbia", "7,058,322", "91.1", {} }, + { "Spain", "46,468,102", "92.0", {} }, + { "Sweden", "10,065,389", "22.0", {} }, + { "United Kingdom", "65,648,000", "270.7", {} } + }; + return list; +} + +//---------------------------------------------------------------------- +auto Treeview::initNorthAmerica() -> std::initializer_list +{ + static const auto list = std::initializer_list + { + { "Canada", "35,151,728", "3.92", {} }, + { "Cuba", "11,239,224", "102.3", {} }, + { "Greenland", "56,483", "0.028", {} }, + { "Guatemala", "16,582,469", "129.0", {} }, + { "Honduras", "9,112,867", "64.0", {} }, + { "Mexico", "119,530,753", "61.0", {} }, + { "Nicaragua", "6,167,237", "51.0", {} }, + { "USA", "325,365,189", "35.0", {} } + }; + return list; +} + +//---------------------------------------------------------------------- +auto Treeview::initSouthAmerica() -> std::initializer_list +{ + static const auto list = std::initializer_list + { + { "Argentina", "43,847,430", "14.4", {} }, + { "Bolivia", "11,410,651", "10.4", {} }, + { "Brazil", "208,064,000", "24.35", {} }, + { "Chile", "18,006,407", "24.0", {} }, + { "Colombia", "49,364,592", "40.74", {} }, + { "Ecuador", "16,385,068", "58.95", {} }, + { "Guyana", "773,303", "3.502", {} }, + { "Paraguay", "6,725,308", "17.2", {} }, + { "Peru", "31,826,018", "23.0", {} }, + { "Venezuela", "31,568,179", "33.75", {} } + }; + return list; +} + +//---------------------------------------------------------------------- +auto Treeview::initOceania() -> std::initializer_list +{ + static const auto list = std::initializer_list + { + { "Australia", "24,675,900", "3.2", {} }, + { "Papua New Guinea", "7,059,653", "15.0", {} }, + { "Papua", "3,486,432", "11.0", {} }, + { "New Zealand", "4,823,090", "17.5", {} }, + { "West Papua", "877,437", "6.3", {} }, + { "Solomon Islands", "599,419", "18.1", {} }, + { "New Caledonia", "268,767", "14.5", {} }, + { "Fiji", "898,76", "46.4", {} }, + { "Hawaii", "1,428,557", "82.6", {} }, + { "Vanuatu", "270,402", "19.7", {} }, + { "French Polynesia", "280,208", "76.0", {} }, + { "Samoa", "192,342", "68.0", {} }, + { "Kiribati", "110,136", "152.0", {} } + }; + return list; +} //---------------------------------------------------------------------- void Treeview::adjustSize() diff --git a/examples/ui.cpp b/examples/ui.cpp index 94f453b3..5f7d128a 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -196,7 +196,7 @@ class TextWindow final : public finalcut::FDialog TextWindow (const TextWindow&) = delete; // Destructor - ~TextWindow() override; + ~TextWindow() override = default; // Disable copy assignment operator (=) TextWindow& operator = (const TextWindow&) = delete; @@ -230,10 +230,6 @@ TextWindow::TextWindow (finalcut::FWidget* parent) scrolltext.deleteRange(3, 4); } -//---------------------------------------------------------------------- -TextWindow::~TextWindow() // destructor -{ } - //---------------------------------------------------------------------- void TextWindow::append (const finalcut::FString& str) { @@ -262,7 +258,7 @@ class MyDialog final : public finalcut::FDialog MyDialog (const MyDialog&) = delete; // Destructor - ~MyDialog() override; + ~MyDialog() override = default; // Disable copy assignment operator (=) MyDialog& operator = (const MyDialog&) = delete; @@ -375,10 +371,6 @@ MyDialog::MyDialog (finalcut::FWidget* parent) init(); } -//---------------------------------------------------------------------- -MyDialog::~MyDialog() // destructor -{ } - //---------------------------------------------------------------------- void MyDialog::init() { diff --git a/examples/watch.cpp b/examples/watch.cpp index 89adc220..130c9450 100644 --- a/examples/watch.cpp +++ b/examples/watch.cpp @@ -41,7 +41,7 @@ class Watch final : public finalcut::FDialog Watch (const Watch&) = delete; // Destructor - ~Watch() override; + ~Watch() override = default; // Disable copy assignment operator (=) Watch& operator = (const Watch&) = delete; @@ -118,10 +118,6 @@ Watch::Watch (FWidget* parent) ); } -//---------------------------------------------------------------------- -Watch::~Watch() -{ } - //---------------------------------------------------------------------- void Watch::printTime() { diff --git a/examples/windows.cpp b/examples/windows.cpp index 3276ac72..5edf2a5f 100644 --- a/examples/windows.cpp +++ b/examples/windows.cpp @@ -44,7 +44,7 @@ class SmallWindow final : public finalcut::FDialog SmallWindow (const SmallWindow&) = delete; // Destructor - ~SmallWindow() override; + ~SmallWindow() override = default; // Disable copy assignment operator (=) SmallWindow& operator = (const SmallWindow&) = delete; @@ -107,10 +107,6 @@ SmallWindow::SmallWindow (finalcut::FWidget* parent) bottom_label.setGeometry (FPoint{13, 3}, FSize{6, 3}); } -//---------------------------------------------------------------------- -SmallWindow::~SmallWindow() -{ } - //---------------------------------------------------------------------- void SmallWindow::adjustSize() { @@ -177,15 +173,22 @@ class Window final : public finalcut::FDialog Window& operator = (const Window&) = delete; private: - struct win_data + struct WinData { // Constructor - win_data() = default; - // Disable copy constructor - win_data (const win_data&) = delete; + WinData() = default; - // Disable copy assignment operator (=) - win_data& operator = (const win_data&) = delete; + // copy constructor + WinData (const WinData&) = default; + + // move constructor + WinData (WinData&&) noexcept = default; + + // copy assignment operator (=) + WinData& operator = (const WinData&) = default; + + // move assignment operator (=) + WinData& operator = (WinData&&) noexcept = default; // Data members bool is_open{false}; @@ -216,10 +219,10 @@ class Window final : public finalcut::FDialog void cb_closeWindows(); void cb_next(); void cb_previous(); - void cb_destroyWindow (win_data*) const; + void cb_destroyWindow (WinData&) const; // Data members - std::vector windows{}; + std::vector windows{}; finalcut::FString drop_down_symbol{fc::BlackDownPointingTriangle}; finalcut::FMenuBar Menubar{this}; finalcut::FMenu File{"&File", &Menubar}; @@ -262,9 +265,9 @@ Window::Window (finalcut::FWidget* parent) // Generate data vector for the windows for (uInt n{1}; n < 7; n++) { - auto win_dat = new win_data; - win_dat->title.sprintf("Window %1u", n); - windows.push_back(win_dat); + WinData win_dat; + win_dat.title.sprintf("Window %1u", n); + windows.emplace_back(std::move(win_dat)); } } @@ -275,13 +278,12 @@ Window::~Window() while ( iter != windows.end() ) { - auto win_dat = *iter; + auto& win_dat = *iter; // Remove all callbacks before Window::cb_destroyWindow() will be called - if ( win_dat->is_open && win_dat->dgl ) - win_dat->dgl->delCallback(); + if ( win_dat.is_open && win_dat.dgl ) + win_dat.dgl->delCallback(); - delete win_dat; iter = windows.erase(iter); } } @@ -366,12 +368,12 @@ void Window::adjustSize() while ( iter != windows.end() ) { - if ( (*iter)->is_open ) + if ( (*iter).is_open ) { const auto n = int(std::distance(first, iter)); const int x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3; const int y = dy + 11 + int(n / 3) * 3; - (*iter)->dgl->setPos (FPoint{x, y}); + (*iter).dgl->setPos (FPoint{x, y}); } ++iter; @@ -459,13 +461,13 @@ void Window::cb_createWindows() while ( iter != windows.end() ) { - if ( ! (*iter)->is_open ) + if ( ! (*iter).is_open ) { - auto win_dat = *iter; + auto& win_dat = *iter; auto win = new SmallWindow(this); - win_dat->dgl = win; - win_dat->is_open = true; - win->setText(win_dat->title); + win_dat.dgl = win; + win_dat.is_open = true; + win->setText(win_dat.title); const auto n = int(std::distance(first, iter)); const int x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3; const int y = dy + 11 + int(n / 3) * 3; @@ -478,7 +480,7 @@ void Window::cb_createWindows() ( "destroy", this, &Window::cb_destroyWindow, - win_dat + std::ref(win_dat) ); } @@ -551,13 +553,10 @@ void Window::cb_previous() } //---------------------------------------------------------------------- -void Window::cb_destroyWindow (win_data* win_dat) const +void Window::cb_destroyWindow (WinData& win_dat) const { - if ( win_dat ) - { - win_dat->is_open = false; - win_dat->dgl = nullptr; - } + win_dat.is_open = false; + win_dat.dgl = nullptr; } diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 41317b3b..9bd22d62 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -374,7 +374,7 @@ void FButtonGroup::drawLabel() else FWidget::setPrintPos (FPoint{0, 1}); - drawText (label_text, hotkeypos); + drawText (std::move(label_text), hotkeypos); setViewportPrint(); } @@ -397,7 +397,7 @@ void FButtonGroup::init() } //---------------------------------------------------------------------- -void FButtonGroup::drawText ( const FString& label_text +void FButtonGroup::drawText ( FString&& label_text , std::size_t hotkeypos ) { const auto& wc = getColorTheme(); diff --git a/src/fcheckbox.cpp b/src/fcheckbox.cpp index f06f3d07..4f464505 100644 --- a/src/fcheckbox.cpp +++ b/src/fcheckbox.cpp @@ -46,9 +46,7 @@ FCheckBox::FCheckBox (const FString& txt, FWidget* parent) } //---------------------------------------------------------------------- -FCheckBox::~FCheckBox() // destructor -{ } - +FCheckBox::~FCheckBox() noexcept = default; // destructor // private methods of FCheckBox //---------------------------------------------------------------------- diff --git a/src/fcheckmenuitem.cpp b/src/fcheckmenuitem.cpp index 4c77f837..89ff8061 100644 --- a/src/fcheckmenuitem.cpp +++ b/src/fcheckmenuitem.cpp @@ -47,8 +47,7 @@ FCheckMenuItem::FCheckMenuItem (const FString& txt, FWidget* parent) } //---------------------------------------------------------------------- -FCheckMenuItem::~FCheckMenuItem() // destructor -{ } +FCheckMenuItem::~FCheckMenuItem() noexcept = default; // destructor // private methods of FCheckMenuItem diff --git a/src/fcombobox.cpp b/src/fcombobox.cpp index be66c27d..e7ec8cf0 100644 --- a/src/fcombobox.cpp +++ b/src/fcombobox.cpp @@ -177,9 +177,7 @@ FComboBox::FComboBox (FWidget* parent) } //---------------------------------------------------------------------- -FComboBox::~FComboBox() // destructor -{ } - +FComboBox::~FComboBox() noexcept = default; // destructor // public methods of FComboBox //---------------------------------------------------------------------- diff --git a/src/fdialoglistmenu.cpp b/src/fdialoglistmenu.cpp index a301b65b..064fa246 100644 --- a/src/fdialoglistmenu.cpp +++ b/src/fdialoglistmenu.cpp @@ -46,8 +46,7 @@ FDialogListMenu::FDialogListMenu (const FString& txt, FWidget* parent) } //---------------------------------------------------------------------- -FDialogListMenu::~FDialogListMenu() -{ } +FDialogListMenu::~FDialogListMenu() noexcept = default; // destructor // private methods of FMenu diff --git a/src/fevent.cpp b/src/fevent.cpp index e3885c76..45888095 100644 --- a/src/fevent.cpp +++ b/src/fevent.cpp @@ -56,10 +56,6 @@ FKeyEvent::FKeyEvent (fc::events ev_type, FKey key_num) // constructor , k{key_num} { } -//---------------------------------------------------------------------- -FKeyEvent::~FKeyEvent() // destructor -{ } - //---------------------------------------------------------------------- FKey FKeyEvent::key() const { return k; } @@ -98,10 +94,6 @@ FMouseEvent::FMouseEvent ( fc::events ev_type // constructor : FMouseEvent{ev_type, pos, FPoint{}, button} { } -//---------------------------------------------------------------------- -FMouseEvent::~FMouseEvent() // destructor -{ } - //---------------------------------------------------------------------- const FPoint& FMouseEvent::getPos() const { return p; } @@ -152,10 +144,6 @@ FWheelEvent::FWheelEvent ( fc::events ev_type // constructor : FWheelEvent{ev_type, pos, FPoint{}, wheel} { } -//---------------------------------------------------------------------- -FWheelEvent::~FWheelEvent() // destructor -{ } - //---------------------------------------------------------------------- const FPoint& FWheelEvent::getPos() const { return p; } @@ -193,10 +181,6 @@ FFocusEvent::FFocusEvent (fc::events ev_type) // constructor : FEvent{ev_type} { } -//---------------------------------------------------------------------- -FFocusEvent::~FFocusEvent() // destructor -{ } - //---------------------------------------------------------------------- bool FFocusEvent::gotFocus() const { @@ -239,10 +223,6 @@ FAccelEvent::FAccelEvent (fc::events ev_type, FWidget* focused) // constructor , focus_widget{focused} { } -//---------------------------------------------------------------------- -FAccelEvent::~FAccelEvent() // destructor -{ } - //---------------------------------------------------------------------- FWidget* FAccelEvent::focusedWidget() const { return focus_widget; } @@ -268,10 +248,6 @@ FResizeEvent::FResizeEvent (fc::events ev_type) // constructor : FEvent{ev_type} { } -//---------------------------------------------------------------------- -FResizeEvent::~FResizeEvent() // destructor -{ } - //---------------------------------------------------------------------- bool FResizeEvent::isAccepted() const { return accpt; } @@ -293,10 +269,6 @@ FShowEvent::FShowEvent (fc::events ev_type) // constructor : FEvent{ev_type} { } -//---------------------------------------------------------------------- -FShowEvent::~FShowEvent() // destructor -{ } - //---------------------------------------------------------------------- // class FHideEvent @@ -306,10 +278,6 @@ FHideEvent::FHideEvent (fc::events ev_type) // constructor : FEvent{ev_type} { } -//---------------------------------------------------------------------- -FHideEvent::~FHideEvent() // destructor -{ } - //---------------------------------------------------------------------- // class FCloseEvent @@ -319,10 +287,6 @@ FCloseEvent::FCloseEvent (fc::events ev_type) // constructor : FEvent{ev_type} { } -//---------------------------------------------------------------------- -FCloseEvent::~FCloseEvent() // destructor -{ } - //---------------------------------------------------------------------- bool FCloseEvent::isAccepted() const { return accpt; } @@ -345,10 +309,6 @@ FTimerEvent::FTimerEvent (fc::events ev_type, int timer_id) // constructor , id{timer_id} { } -//---------------------------------------------------------------------- -FTimerEvent::~FTimerEvent() // destructor -{ } - //---------------------------------------------------------------------- int FTimerEvent::getTimerId() const { return id; } @@ -363,10 +323,6 @@ FUserEvent::FUserEvent (fc::events ev_type, int user_event_id) // constructor , uid{user_event_id} { } -//---------------------------------------------------------------------- -FUserEvent::~FUserEvent() // destructor -{ } - //---------------------------------------------------------------------- int FUserEvent::getUserId() const { return uid; } diff --git a/src/fkeyboard.cpp b/src/fkeyboard.cpp index e6e29016..5e8c0319 100644 --- a/src/fkeyboard.cpp +++ b/src/fkeyboard.cpp @@ -81,9 +81,6 @@ FKeyboard::FKeyboard() term_detection = FTerm::getFTermDetection(); } -//---------------------------------------------------------------------- -FKeyboard::~FKeyboard() // destructor -{ } // public methods of FKeyboard //---------------------------------------------------------------------- diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 496abec2..bfc278c6 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -39,10 +39,6 @@ namespace finalcut //---------------------------------------------------------------------- // constructor and destructor -//---------------------------------------------------------------------- -FListBoxItem::FListBoxItem() -{ } - //---------------------------------------------------------------------- FListBoxItem::FListBoxItem (const FListBoxItem& item) : text{item.text} @@ -52,8 +48,8 @@ FListBoxItem::FListBoxItem (const FListBoxItem& item) { } //---------------------------------------------------------------------- -FListBoxItem::~FListBoxItem() // destructor -{ } +FListBoxItem::~FListBoxItem() noexcept = default; // destructor + // public methods of FListBoxItem //---------------------------------------------------------------------- diff --git a/src/flistview.cpp b/src/flistview.cpp index 7490367f..aeb99961 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -477,52 +477,12 @@ void FListViewItem::resetVisibleLineCounter() //---------------------------------------------------------------------- // constructor and destructor -//---------------------------------------------------------------------- -FListViewIterator::FListViewIterator() -{ } - //---------------------------------------------------------------------- FListViewIterator::FListViewIterator (iterator iter) : node{iter} { } -//---------------------------------------------------------------------- -FListViewIterator::~FListViewIterator() // destructor -{ } - -//---------------------------------------------------------------------- -FListViewIterator::FListViewIterator (const FListViewIterator& i) - : 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)} -{ } - // FListViewIterator operators -//---------------------------------------------------------------------- -FListViewIterator& FListViewIterator::operator = (const FListViewIterator& i) -{ - iter_path = i.iter_path; - node = i.node; - position = i.position; - return *this; -} - -//---------------------------------------------------------------------- -FListViewIterator& FListViewIterator::operator = (FListViewIterator&& i) noexcept -{ - iter_path = std::move(i.iter_path); - node = std::move(i.node); - position = std::move(i.position); - return *this; -} - //---------------------------------------------------------------------- FListViewIterator& FListViewIterator::operator ++ () // prefix { @@ -554,25 +514,19 @@ FListViewIterator FListViewIterator::operator -- (int) // postfix } //---------------------------------------------------------------------- -FListViewIterator& FListViewIterator::operator += (volatile int n) +FListViewIterator& FListViewIterator::operator += (int n) { - while ( n > 0 ) - { + for (int i = n; i > 0 ; i--) nextElement(node); - n--; - } return *this; } //---------------------------------------------------------------------- -FListViewIterator& FListViewIterator::operator -= (volatile int n) +FListViewIterator& FListViewIterator::operator -= (int n) { - while ( n > 0 ) - { + for (int i = n; i > 0 ; i--) prevElement(node); - n--; - } return *this; } diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index d707e89f..16cd26b4 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -92,10 +92,7 @@ FMessageBox::FMessageBox ( const FString& caption } //---------------------------------------------------------------------- -FMessageBox::~FMessageBox() // destructor -{ - deallocation(); -} +FMessageBox::~FMessageBox() noexcept = default; // destructor // public methods of FMessageBox @@ -108,10 +105,6 @@ FMessageBox& FMessageBox::operator = (const FMessageBox& mbox) } else { - for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++) - if ( button[n] ) - delete button[n]; - if ( mbox.getParentWidget() ) mbox.getParentWidget()->addChild (this); @@ -238,7 +231,7 @@ inline void FMessageBox::allocation() { try { - button[0] = new FButton (this); + button[0].reset(new FButton (this)); button[0]->setText(button_text[button_digit[0]]); button[0]->setPos(FPoint{3, int(getHeight()) - 4}, false); button[0]->setWidth(1, false); @@ -247,7 +240,7 @@ inline void FMessageBox::allocation() if ( button_digit[1] > FMessageBox::Reject ) { - button[1] = new FButton(this); + button[1].reset(new FButton(this)); button[1]->setText(button_text[button_digit[1]]); button[1]->setPos(FPoint{17, int(getHeight()) - 4}, false); button[1]->setWidth(0, false); @@ -256,7 +249,7 @@ inline void FMessageBox::allocation() if ( button_digit[2] > FMessageBox::Reject ) { - button[2] = new FButton(this); + button[2].reset(new FButton(this)); button[2]->setText(button_text[button_digit[2]]); button[2]->setPos(FPoint{32, int(getHeight()) - 4}, false); button[2]->setWidth(0, false); @@ -270,14 +263,6 @@ inline void FMessageBox::allocation() } } -//---------------------------------------------------------------------- -inline void FMessageBox::deallocation() -{ - for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++) - if ( button[n] ) - delete button[n]; -} - //---------------------------------------------------------------------- inline void FMessageBox::initCallbacks() { @@ -391,7 +376,7 @@ void FMessageBox::draw() //---------------------------------------------------------------------- void FMessageBox::resizeButtons() const { - std::array len{}; + std::array len{}; std::size_t max_size{}; for (std::size_t n{0}; n < num_buttons && n < MAX_BUTTONS; n++) diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 5db6a52c..6bd4bd6b 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -313,10 +313,6 @@ FMouseGPM::FMouseGPM() gpm_ev.x = -1; } -//---------------------------------------------------------------------- -FMouseGPM::~FMouseGPM() // destructor -{ } - // public methods of FMouseX11 //---------------------------------------------------------------------- @@ -1217,27 +1213,25 @@ void FMouseUrxvt::setButtonState (const int btn, const struct timeval* time) FMouseControl::FMouseControl() { #ifdef F_HAVE_LIBGPM - mouse_protocol[FMouse::gpm] = FMouse::createMouseObject(); + if ( FTerm::isLinuxTerm() ) + mouse_protocol[FMouse::gpm].reset(FMouse::createMouseObject()); #endif - mouse_protocol[FMouse::x11] = FMouse::createMouseObject(); - mouse_protocol[FMouse::sgr] = FMouse::createMouseObject(); - mouse_protocol[FMouse::urxvt] = FMouse::createMouseObject(); + mouse_protocol[FMouse::x11].reset(FMouse::createMouseObject()); + mouse_protocol[FMouse::sgr].reset(FMouse::createMouseObject()); + mouse_protocol[FMouse::urxvt].reset(FMouse::createMouseObject()); } //---------------------------------------------------------------------- -FMouseControl::~FMouseControl() // destructor -{ - for (auto&& m : mouse_protocol) - delete m.second; -} +FMouseControl::~FMouseControl() = default; // destructor // public methods of FMouseControl //---------------------------------------------------------------------- const FPoint& FMouseControl::getPos() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); + const auto& mouse_object = mouse_protocol[mtype].get(); if ( mouse_object ) return mouse_object->getPos(); @@ -1248,17 +1242,23 @@ const FPoint& FMouseControl::getPos() //---------------------------------------------------------------------- void FMouseControl::clearEvent() { - FMouse* mouse_object; + FMouse::mouse_type mtype; - while ( (mouse_object = getMouseWithEvent()) != nullptr ) - mouse_object->clearEvent(); + do + { + mtype = getMouseWithEvent(); + + if ( mouse_protocol[mtype] ) + mouse_protocol[mtype]->clearEvent(); + } + while ( mtype != FMouse::none ); } //---------------------------------------------------------------------- #ifdef F_HAVE_LIBGPM void FMouseControl::setStdinNo (int file_descriptor) { - auto mouse = mouse_protocol[FMouse::gpm]; + auto mouse = mouse_protocol[FMouse::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1304,7 +1304,8 @@ void FMouseControl::useXtermMouse (bool enable) //---------------------------------------------------------------------- bool FMouseControl::hasData() { - const auto& mouse_object = getMouseWithData(); + auto mtype = getMouseWithData(); + const auto& mouse_object = mouse_protocol[mtype].get(); if ( mouse_object ) // with data return true; @@ -1315,9 +1316,9 @@ bool FMouseControl::hasData() //---------------------------------------------------------------------- bool FMouseControl::hasEvent() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) // with event + if ( mouse_protocol[mtype] ) // with event return true; return false; @@ -1326,10 +1327,10 @@ bool FMouseControl::hasEvent() //---------------------------------------------------------------------- bool FMouseControl::isLeftButtonPressed() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isLeftButtonPressed(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isLeftButtonPressed(); return false; } @@ -1337,10 +1338,10 @@ bool FMouseControl::isLeftButtonPressed() //---------------------------------------------------------------------- bool FMouseControl::isLeftButtonReleased() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isLeftButtonReleased(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isLeftButtonReleased(); return false; } @@ -1348,10 +1349,10 @@ bool FMouseControl::isLeftButtonReleased() //---------------------------------------------------------------------- bool FMouseControl::isLeftButtonDoubleClick() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isLeftButtonDoubleClick(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isLeftButtonDoubleClick(); return false; } @@ -1359,10 +1360,10 @@ bool FMouseControl::isLeftButtonDoubleClick() //---------------------------------------------------------------------- bool FMouseControl::isRightButtonPressed() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isRightButtonPressed(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isRightButtonPressed(); return false; } @@ -1370,10 +1371,10 @@ bool FMouseControl::isRightButtonPressed() //---------------------------------------------------------------------- bool FMouseControl::isRightButtonReleased() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isRightButtonReleased(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isRightButtonReleased(); return false; } @@ -1381,10 +1382,10 @@ bool FMouseControl::isRightButtonReleased() //---------------------------------------------------------------------- bool FMouseControl::isMiddleButtonPressed() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isMiddleButtonPressed(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isMiddleButtonPressed(); return false; } @@ -1392,10 +1393,10 @@ bool FMouseControl::isMiddleButtonPressed() //---------------------------------------------------------------------- bool FMouseControl::isMiddleButtonReleased() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isMiddleButtonReleased(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isMiddleButtonReleased(); return false; } @@ -1403,10 +1404,10 @@ bool FMouseControl::isMiddleButtonReleased() //---------------------------------------------------------------------- bool FMouseControl::isShiftKeyPressed() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isShiftKeyPressed(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isShiftKeyPressed(); return false; } @@ -1414,10 +1415,10 @@ bool FMouseControl::isShiftKeyPressed() //---------------------------------------------------------------------- bool FMouseControl::isControlKeyPressed() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isControlKeyPressed(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isControlKeyPressed(); return false; } @@ -1425,10 +1426,10 @@ bool FMouseControl::isControlKeyPressed() //---------------------------------------------------------------------- bool FMouseControl::isMetaKeyPressed() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isMetaKeyPressed(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isMetaKeyPressed(); return false; } @@ -1436,10 +1437,10 @@ bool FMouseControl::isMetaKeyPressed() //---------------------------------------------------------------------- bool FMouseControl::isWheelUp() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isWheelUp(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isWheelUp(); return false; } @@ -1447,10 +1448,10 @@ bool FMouseControl::isWheelUp() //---------------------------------------------------------------------- bool FMouseControl::isWheelDown() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isWheelDown(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isWheelDown(); return false; } @@ -1458,10 +1459,10 @@ bool FMouseControl::isWheelDown() //---------------------------------------------------------------------- bool FMouseControl::isMoved() { - const auto& mouse_object = getMouseWithEvent(); + auto mtype = getMouseWithEvent(); - if ( mouse_object ) - return mouse_object->isMoved(); + if ( mouse_protocol[mtype] ) + return mouse_protocol[mtype]->isMoved(); return false; } @@ -1486,7 +1487,7 @@ bool FMouseControl::isGpmMouseEnabled() if ( mouse_protocol.empty() ) return false; - const auto& mouse = mouse_protocol[FMouse::gpm]; + const auto& mouse = mouse_protocol[FMouse::gpm].get(); const auto& gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1507,7 +1508,7 @@ void FMouseControl::enable() #ifdef F_HAVE_LIBGPM if ( use_gpm_mouse ) { - auto mouse = mouse_protocol[FMouse::gpm]; + auto mouse = mouse_protocol[FMouse::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1525,7 +1526,7 @@ void FMouseControl::disable() #ifdef F_HAVE_LIBGPM if ( use_gpm_mouse ) { - auto mouse = mouse_protocol[FMouse::gpm]; + auto mouse = mouse_protocol[FMouse::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1541,7 +1542,7 @@ void FMouseControl::disable() void FMouseControl::setRawData ( FMouse::mouse_type mt , FKeyboard::keybuffer& fifo_buf) { - auto mouse = mouse_protocol[mt]; + auto mouse = mouse_protocol[mt].get(); if ( mouse ) mouse->setRawData (fifo_buf); @@ -1569,7 +1570,9 @@ void FMouseControl::processQueuedInput() //---------------------------------------------------------------------- void FMouseControl::processEvent (struct timeval* time) { - auto mouse_object = getMouseWithData(); + auto mtype = getMouseWithData(); + auto mouse_object = mouse_protocol[mtype].get(); + // Clear all old mouse events clearEvent(); @@ -1588,7 +1591,7 @@ bool FMouseControl::getGpmKeyPressed (bool pending) if ( mouse_protocol.empty() ) return false; - auto mouse = mouse_protocol[FMouse::gpm]; + auto mouse = mouse_protocol[FMouse::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1610,7 +1613,7 @@ void FMouseControl::drawPointer() if ( mouse_protocol.empty() ) return; - auto mouse = mouse_protocol[FMouse::gpm]; + auto mouse = mouse_protocol[FMouse::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1624,7 +1627,7 @@ void FMouseControl::drawPointer() // private methods of FMouseControl //---------------------------------------------------------------------- -FMouse* FMouseControl::getMouseWithData() +FMouse::mouse_type FMouseControl::getMouseWithData() { const auto& iter = \ std::find_if ( std::begin(mouse_protocol) @@ -1636,11 +1639,11 @@ FMouse* FMouseControl::getMouseWithData() } ); - return ( iter != mouse_protocol.end() ) ? iter->second : nullptr; + return ( iter != mouse_protocol.end() ) ? iter->first : FMouse::none; } //---------------------------------------------------------------------- -FMouse* FMouseControl::getMouseWithEvent() +FMouse::mouse_type FMouseControl::getMouseWithEvent() { const auto& iter = \ std::find_if ( std::begin(mouse_protocol) @@ -1652,7 +1655,7 @@ FMouse* FMouseControl::getMouseWithEvent() } ); - return ( iter != mouse_protocol.end() ) ? iter->second : nullptr; + return ( iter != mouse_protocol.end() ) ? iter->first : FMouse::none; } //---------------------------------------------------------------------- diff --git a/src/fobject.cpp b/src/fobject.cpp index c29ab4e9..db0a8943 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -32,7 +32,6 @@ namespace finalcut // static class attributes bool FObject::timer_modify_lock; -FObject::FTimerList* FObject::timer_list{nullptr}; const FString* fc::emptyFString::empty_string{nullptr}; @@ -45,27 +44,10 @@ const FString* fc::emptyFString::empty_string{nullptr}; FObject::FObject (FObject* parent) : parent_obj{parent} { - if ( parent ) // add object to parent - { + if ( parent ) // add object to parent parent->addChild(this); - } else - { timer_modify_lock = false; - - if ( ! timer_list ) - { - try - { - timer_list = new FTimerList; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTimerList"); - return; - } - } - } } //---------------------------------------------------------------------- @@ -73,12 +55,6 @@ FObject::~FObject() // destructor { delOwnTimers(); // Delete all timers of this object - if ( ! has_parent && timer_list ) - { - delete timer_list; - timer_list = nullptr; - } - if ( ! has_parent && ! fc::emptyFString::isNull() ) fc::emptyFString::clear(); @@ -268,6 +244,7 @@ int FObject::addTimer (int interval) timeval currentTime{}; int id{1}; timer_modify_lock = true; + auto& timer_list = globalTimerList(); // find an unused timer id if ( ! timer_list->empty() ) @@ -317,6 +294,7 @@ bool FObject::delTimer (int id) const return false; timer_modify_lock = true; + auto& timer_list = globalTimerList(); auto iter = timer_list->begin(); const auto& last = timer_list->end(); @@ -339,6 +317,8 @@ bool FObject::delOwnTimers() const { // Deletes all timers of this object + auto& timer_list = globalTimerList(); + if ( ! timer_list ) return false; @@ -365,6 +345,8 @@ bool FObject::delAllTimers() const { // Deletes all timers of all objects + auto& timer_list = globalTimerList(); + if ( ! timer_list ) return false; @@ -405,6 +387,8 @@ uInt FObject::processTimerEvent() if ( isTimerInUpdating() ) return 0; + auto& timer_list = globalTimerList(); + if ( ! timer_list ) return 0; @@ -440,4 +424,11 @@ void FObject::performTimerAction (FObject*, FEvent*) // to process the passed object and timer event } +//---------------------------------------------------------------------- +FObject::FTimerListPtr& FObject::globalTimerList() +{ + static const auto& timer_list = make_unique(); + return timer_list; +} + } // namespace finalcut diff --git a/src/foptiattr.cpp b/src/foptiattr.cpp index caf4d09d..43ad3264 100644 --- a/src/foptiattr.cpp +++ b/src/foptiattr.cpp @@ -47,10 +47,6 @@ FOptiAttr::FOptiAttr() reset_byte_mask.attr.bit.printed = true; } -//---------------------------------------------------------------------- -FOptiAttr::~FOptiAttr() // destructor -{ } - // public methods of FOptiAttr //---------------------------------------------------------------------- diff --git a/src/foptimove.cpp b/src/foptimove.cpp index 38e05c20..54715e79 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -52,10 +52,6 @@ FOptiMove::FOptiMove (int baud) set_cursor_down ("\n"); } -//---------------------------------------------------------------------- -FOptiMove::~FOptiMove() // destructor -{ } - // public methods of FOptiMove //---------------------------------------------------------------------- @@ -608,7 +604,7 @@ int FOptiMove::capDurationToLength (int duration) const //---------------------------------------------------------------------- int FOptiMove::repeatedAppend ( const Capability& o - , volatile int count + , int count , char* dst ) const { const std::size_t src_len = std::strlen(o.cap); @@ -623,8 +619,9 @@ int FOptiMove::repeatedAppend ( const Capability& o { dst += dst_len; std::size_t free = BUF_SIZE - dst_len - 2; + int cnt = count; - while ( count-- > 0 ) + while ( cnt-- > 0 ) { std::strncpy (dst, o.cap, free); dst += src_len; diff --git a/src/fpoint.cpp b/src/fpoint.cpp index 6c6f8efc..f4603e40 100644 --- a/src/fpoint.cpp +++ b/src/fpoint.cpp @@ -31,26 +31,7 @@ namespace finalcut // class FPoint //---------------------------------------------------------------------- -FPoint::~FPoint() // destructor -{ } - // public methods of FPoint -//---------------------------------------------------------------------- -FPoint& FPoint::operator = (const FPoint& p) -{ - xpos = p.xpos; - ypos = p.ypos; - return *this; -} - -//---------------------------------------------------------------------- -FPoint& FPoint::operator = (FPoint&& p) noexcept -{ - xpos = std::move(p.xpos); - ypos = std::move(p.ypos); - return *this; -} - //---------------------------------------------------------------------- FPoint& FPoint::operator += (const FPoint& p) { diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 5c4060ef..867b8c88 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -42,8 +42,7 @@ FProgressbar::FProgressbar(FWidget* parent) } //---------------------------------------------------------------------- -FProgressbar::~FProgressbar() // destructor -{ } +FProgressbar::~FProgressbar() noexcept = default; // destructor // public methods of FProgressbar diff --git a/src/fradiobutton.cpp b/src/fradiobutton.cpp index 8c8e1a16..7ea88571 100644 --- a/src/fradiobutton.cpp +++ b/src/fradiobutton.cpp @@ -46,8 +46,7 @@ FRadioButton::FRadioButton (const FString& txt, FWidget* parent) } //---------------------------------------------------------------------- -FRadioButton::~FRadioButton() // destructor -{ } +FRadioButton::~FRadioButton() noexcept = default; // destructor // private methods of FRadioButton diff --git a/src/fradiomenuitem.cpp b/src/fradiomenuitem.cpp index 8b882c8b..12bedf5f 100644 --- a/src/fradiomenuitem.cpp +++ b/src/fradiomenuitem.cpp @@ -49,8 +49,7 @@ FRadioMenuItem::FRadioMenuItem (const FString& txt, FWidget* parent) } //---------------------------------------------------------------------- -FRadioMenuItem::~FRadioMenuItem() // destructor -{ } +FRadioMenuItem::~FRadioMenuItem() noexcept = default; // destructor // private methods of FRadioMenuItem diff --git a/src/frect.cpp b/src/frect.cpp index e62c8c40..f02337f7 100644 --- a/src/frect.cpp +++ b/src/frect.cpp @@ -51,32 +51,8 @@ FRect::FRect (const FPoint& p1, const FPoint& p2) , Y2{p2.getY()} { } -//---------------------------------------------------------------------- -FRect::~FRect() // destructor -{ } - // public methods of FRect -//---------------------------------------------------------------------- -FRect& FRect::operator = (const FRect& r) -{ - X1 = r.X1; - Y1 = r.Y1; - X2 = r.X2; - Y2 = r.Y2; - return *this; -} - -//---------------------------------------------------------------------- -FRect& FRect::operator = (FRect&& r) noexcept -{ - X1 = std::move(r.X1); - Y1 = std::move(r.Y1); - X2 = std::move(r.X2); - Y2 = std::move(r.Y2); - return *this; -} - //---------------------------------------------------------------------- bool FRect::isEmpty() const { diff --git a/src/fsize.cpp b/src/fsize.cpp index 74ee9f5d..18f88330 100644 --- a/src/fsize.cpp +++ b/src/fsize.cpp @@ -33,26 +33,7 @@ namespace finalcut // class FSize //---------------------------------------------------------------------- -FSize::~FSize() // destructor -{ } - // public methods of FSize -//---------------------------------------------------------------------- -FSize& FSize::operator = (const FSize& s) -{ - width = s.width; - height = s.height; - return *this; -} - -//---------------------------------------------------------------------- -FSize& FSize::operator = (FSize&& s) noexcept -{ - width = std::move(s.width); - height = std::move(s.height); - return *this; -} - //---------------------------------------------------------------------- FSize& FSize::operator += (const FSize& s) { diff --git a/src/fspinbox.cpp b/src/fspinbox.cpp index 09fd46e0..4355d1c7 100644 --- a/src/fspinbox.cpp +++ b/src/fspinbox.cpp @@ -48,8 +48,7 @@ FSpinBox::FSpinBox (FWidget* parent) } //---------------------------------------------------------------------- -FSpinBox::~FSpinBox() // destructor -{ } +FSpinBox::~FSpinBox() noexcept = default; // destructor // public methods of FSpinBox diff --git a/src/fstartoptions.cpp b/src/fstartoptions.cpp index 3250eadb..196e65d3 100644 --- a/src/fstartoptions.cpp +++ b/src/fstartoptions.cpp @@ -54,35 +54,13 @@ FStartOptions::FStartOptions() , dark_theme{false} { } -//---------------------------------------------------------------------- -FStartOptions::~FStartOptions() // destructor -{ } // public methods of FStartOptions //---------------------------------------------------------------------- FStartOptions& FStartOptions::getFStartOptions() { - if ( start_options == nullptr ) - { - try - { - start_options = new FStartOptions; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FStartOptions"); - std::abort(); - } - } - - return *start_options; -} - -//---------------------------------------------------------------------- -void FStartOptions::destroyObject() -{ - if ( start_options ) - delete start_options; + static const auto& start_options = make_unique(); + return *start_options.get(); } //---------------------------------------------------------------------- diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index fac517cf..b226ec4c 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -143,12 +143,12 @@ FStatusBar::~FStatusBar() // destructor while ( iter != key_list.end() ) { (*iter)->setConnectedStatusbar(nullptr); - delAccelerator (*iter); + FWidget::delAccelerator (*iter); iter = key_list.erase(iter); } } - setStatusBar(nullptr); + FWidget::setStatusBar(nullptr); } diff --git a/src/fswitch.cpp b/src/fswitch.cpp index 71a8a61d..1bd5d723 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -49,8 +49,7 @@ FSwitch::FSwitch (const FString& txt, FWidget* parent) } //---------------------------------------------------------------------- -FSwitch::~FSwitch() // destructor -{ } +FSwitch::~FSwitch() noexcept = default; // destructor // public methods of FSwitch diff --git a/src/fsystem.cpp b/src/fsystem.cpp index 2f1dd98e..0193ed0f 100644 --- a/src/fsystem.cpp +++ b/src/fsystem.cpp @@ -3,7 +3,7 @@ * * * This file is part of the FINAL CUT widget toolkit * * * -* Copyright 2019 Markus Gans * +* Copyright 2019-2020 Markus Gans * * * * FINAL CUT is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * @@ -31,12 +31,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- -FSystem::FSystem() -{ } - -//---------------------------------------------------------------------- -FSystem::~FSystem() // destructor -{ } +FSystem::~FSystem() noexcept = default; // destructor } // namespace finalcut diff --git a/src/fsystemimpl.cpp b/src/fsystemimpl.cpp index 498c86c2..dd097ebe 100644 --- a/src/fsystemimpl.cpp +++ b/src/fsystemimpl.cpp @@ -35,12 +35,8 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- -FSystemImpl::FSystemImpl() -{ } +FSystemImpl::~FSystemImpl() noexcept = default; // destructor -//---------------------------------------------------------------------- -FSystemImpl::~FSystemImpl() // destructor -{ } // public methods of FSystemImpl //---------------------------------------------------------------------- diff --git a/src/fterm.cpp b/src/fterm.cpp index ca220c30..e54eaf2f 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -1419,7 +1419,7 @@ void FTerm::init_alt_charset() } } - enum column + enum Column : int { vt100_key = 0, utf8_char = 1 @@ -2272,7 +2272,6 @@ inline void FTerm::deallocationValues() const defaultPutChar* putchar_ptr = &(putchar()); delete putchar_ptr; destroyColorPaletteTheme(); - FStartOptions::destroyObject(); } //---------------------------------------------------------------------- diff --git a/src/fterm_functions.cpp b/src/fterm_functions.cpp index 07dd90c0..22915191 100644 --- a/src/fterm_functions.cpp +++ b/src/fterm_functions.cpp @@ -43,15 +43,15 @@ namespace finalcut { // Enumeration -enum fullWidthSupport +enum class FullWidthSupport { - unknown_fullwidth_support = -1, - supports_fullwidth = 0, - no_fullwidth_support = 1 + unknown = -1, + no = 0, + yes = 1 }; // global state -static fullWidthSupport has_fullwidth_support = unknown_fullwidth_support; +static FullWidthSupport has_fullwidth_support = FullWidthSupport::unknown; // Function prototypes bool hasAmbiguousWidth (wchar_t); @@ -250,7 +250,7 @@ bool hasFullWidthSupports() { // Checks if the terminal has full-width character support - if ( has_fullwidth_support == unknown_fullwidth_support ) + if ( has_fullwidth_support == FullWidthSupport::unknown ) { if ( ! FTerm::isInitialized() ) return true; // Assume that it is a modern terminal with full-width support @@ -262,12 +262,12 @@ bool hasFullWidthSupports() || FTerm::isOpenBSDTerm() || FTerm::isSunTerminal() || FTerm::isAnsiTerminal() ) - has_fullwidth_support = no_fullwidth_support; + has_fullwidth_support = FullWidthSupport::no; else - has_fullwidth_support = supports_fullwidth; + has_fullwidth_support = FullWidthSupport::yes; } - return ( has_fullwidth_support == supports_fullwidth) ? true : false; + return ( has_fullwidth_support == FullWidthSupport::yes) ? true : false; } //---------------------------------------------------------------------- @@ -528,7 +528,7 @@ std::size_t getColumnWidth (const FTermBuffer& tb) , tb.front().attr.bit.char_width , [] (std::size_t s, const FChar& c) { - return std::move(s) + c.attr.bit.char_width; + return s + c.attr.bit.char_width; } ); } diff --git a/src/ftermbuffer.cpp b/src/ftermbuffer.cpp index 9f088dfc..f6cb0c3c 100644 --- a/src/ftermbuffer.cpp +++ b/src/ftermbuffer.cpp @@ -38,8 +38,8 @@ namespace finalcut //---------------------------------------------------------------------- // class FTermBuffer //---------------------------------------------------------------------- -FTermBuffer::~FTermBuffer() // destructor -{ } +FTermBuffer::~FTermBuffer() noexcept = default; // destructor + // public methods of FTermBuffer //---------------------------------------------------------------------- @@ -72,7 +72,7 @@ int FTermBuffer::write (const FString& string) nc.attr.byte[2] = 0; nc.attr.byte[3] = 0; getColumnWidth(nc); // add column width - data.push_back(std::move(nc)); + data.emplace_back(std::move(nc)); } return len; @@ -86,8 +86,7 @@ int FTermBuffer::write (wchar_t ch) getColumnWidth(nc); // add column width nc.attr.bit.no_changes = false; nc.attr.bit.printed = false; - - data.push_back(nc); + data.emplace_back(std::move(nc)); return 1; } diff --git a/src/ftermcapquirks.cpp b/src/ftermcapquirks.cpp index d5fc36e8..30c49b2f 100644 --- a/src/ftermcapquirks.cpp +++ b/src/ftermcapquirks.cpp @@ -43,16 +43,6 @@ FTermDetection* FTermcapQuirks::term_detection {nullptr}; // class FTermcapQuirks //---------------------------------------------------------------------- -// constructors and destructor -//---------------------------------------------------------------------- -FTermcapQuirks::FTermcapQuirks() -{ } - -//---------------------------------------------------------------------- -FTermcapQuirks::~FTermcapQuirks() // destructor -{ } - - // public methods of FTermcapQuirks //---------------------------------------------------------------------- void FTermcapQuirks::terminalFixup() diff --git a/src/ftermios.cpp b/src/ftermios.cpp index 6abb3249..9c8a60d5 100644 --- a/src/ftermios.cpp +++ b/src/ftermios.cpp @@ -52,10 +52,6 @@ FTermios::FTermios() init(); } -//---------------------------------------------------------------------- -FTermios::~FTermios() // destructor -{ } - // public methods of FTermios //---------------------------------------------------------------------- void FTermios::init() diff --git a/src/ftermopenbsd.cpp b/src/ftermopenbsd.cpp index 6b789543..0b2fda5d 100644 --- a/src/ftermopenbsd.cpp +++ b/src/ftermopenbsd.cpp @@ -52,11 +52,6 @@ namespace finalcut // class FTermOpenBSD //---------------------------------------------------------------------- -// constructors and destructor -//---------------------------------------------------------------------- -FTermOpenBSD::~FTermOpenBSD() // destructor -{ } - // public methods of FTermOpenBSD //---------------------------------------------------------------------- #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index d9651dd6..54d67158 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -70,10 +70,6 @@ FTermXTerminal::FTermXTerminal() keyboard = FTerm::getFKeyboard(); } -//---------------------------------------------------------------------- -FTermXTerminal::~FTermXTerminal() // destructor -{ } - // public methods of FTermXTerminal //---------------------------------------------------------------------- diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 8e1ed36b..a7f1c7c2 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -48,8 +48,7 @@ FTextView::FTextView(FWidget* parent) } //---------------------------------------------------------------------- -FTextView::~FTextView() // destructor -{ } +FTextView::~FTextView() noexcept = default; // destructor // public methods of FTextView diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index f90ade84..3d9d56c6 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -485,7 +485,7 @@ void FToggleButton::init() } //---------------------------------------------------------------------- -void FToggleButton::drawText (const FString& label_text, std::size_t hotkeypos) +void FToggleButton::drawText (FString&& label_text, std::size_t hotkeypos) { if ( FTerm::isMonochron() ) setReverse(true); diff --git a/src/fvterm.cpp b/src/fvterm.cpp index a46c1513..e7eddb2a 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -443,8 +443,7 @@ int FVTerm::print (FTermArea* area, const FTermBuffer& term_buffer) //---------------------------------------------------------------------- int FVTerm::print (wchar_t c) { - FChar nc{}; // next character - nc = FVTerm::getAttribute(); + FChar nc{FVTerm::getAttribute()}; // next character nc.ch[0] = c; nc.attr.byte[2] = 0; nc.attr.byte[3] = 0; diff --git a/src/include/final/fbuttongroup.h b/src/include/final/fbuttongroup.h index d2c59f0c..a6731a6b 100644 --- a/src/include/final/fbuttongroup.h +++ b/src/include/final/fbuttongroup.h @@ -126,7 +126,7 @@ class FButtonGroup : public FScrollView // Methods void init(); - void drawText (const FString&, std::size_t); + void drawText (FString&&, std::size_t); bool directFocusCheckedRadioButton (FToggleButton*) const; bool directFocusRadioButton() const; void directFocus(); diff --git a/src/include/final/fcheckbox.h b/src/include/final/fcheckbox.h index 40e74bb7..43cd9f31 100644 --- a/src/include/final/fcheckbox.h +++ b/src/include/final/fcheckbox.h @@ -72,7 +72,7 @@ class FCheckBox : public FToggleButton FCheckBox (const FCheckBox&) = delete; // Destructor - ~FCheckBox() override; + ~FCheckBox() noexcept override; // Disable copy assignment operator (=) FCheckBox& operator = (const FCheckBox&) = delete; diff --git a/src/include/final/fcheckmenuitem.h b/src/include/final/fcheckmenuitem.h index c5ea112b..97883ff0 100644 --- a/src/include/final/fcheckmenuitem.h +++ b/src/include/final/fcheckmenuitem.h @@ -72,7 +72,7 @@ class FCheckMenuItem : public FMenuItem FCheckMenuItem (const FCheckMenuItem&) = delete; // Destructor - ~FCheckMenuItem() override; + ~FCheckMenuItem() noexcept override; // Disable copy assignment operator (=) FCheckMenuItem& operator = (const FCheckMenuItem&) = delete; diff --git a/src/include/final/fcombobox.h b/src/include/final/fcombobox.h index 4c2f6af1..46f122ec 100644 --- a/src/include/final/fcombobox.h +++ b/src/include/final/fcombobox.h @@ -142,7 +142,7 @@ class FComboBox : public FWidget FComboBox (const FComboBox&) = delete; // Destructor - ~FComboBox() override; + ~FComboBox() noexcept override; // Disable copy assignment operator (=) FComboBox& operator = (const FComboBox&) = delete; diff --git a/src/include/final/fdialoglistmenu.h b/src/include/final/fdialoglistmenu.h index f753242e..0ab3ba5b 100644 --- a/src/include/final/fdialoglistmenu.h +++ b/src/include/final/fdialoglistmenu.h @@ -78,7 +78,7 @@ class FDialogListMenu : public FMenu FDialogListMenu (const FDialogListMenu&) = delete; // Destructor - ~FDialogListMenu() override; + ~FDialogListMenu() noexcept override; // Disable copy assignment operator (=) FDialogListMenu& operator = (const FDialogListMenu&) = delete; diff --git a/src/include/final/fevent.h b/src/include/final/fevent.h index d59610ac..82373d54 100644 --- a/src/include/final/fevent.h +++ b/src/include/final/fevent.h @@ -127,7 +127,7 @@ class FKeyEvent : public FEvent // keyboard event public: FKeyEvent() = default; FKeyEvent (fc::events, FKey); - ~FKeyEvent(); + ~FKeyEvent() = default; FKey key() const; bool isAccepted() const; @@ -150,7 +150,7 @@ class FMouseEvent : public FEvent // mouse event FMouseEvent() = default; FMouseEvent (fc::events, const FPoint&, const FPoint&, int); FMouseEvent (fc::events, const FPoint&, int); - ~FMouseEvent(); + ~FMouseEvent() = default; const FPoint& getPos() const; const FPoint& getTermPos() const; @@ -177,7 +177,7 @@ class FWheelEvent : public FEvent // wheel event FWheelEvent() = default; FWheelEvent (fc::events, const FPoint&, int); FWheelEvent (fc::events, const FPoint&, const FPoint&, int); - ~FWheelEvent(); + ~FWheelEvent() = default; const FPoint& getPos() const; const FPoint& getTermPos() const; @@ -203,7 +203,7 @@ class FFocusEvent : public FEvent // focus event public: FFocusEvent() = default; explicit FFocusEvent (fc::events); - ~FFocusEvent(); + ~FFocusEvent() = default; bool gotFocus() const; bool lostFocus() const; @@ -230,7 +230,7 @@ class FAccelEvent : public FEvent // focus event FAccelEvent() = default; FAccelEvent (fc::events, FWidget*); FAccelEvent (const FAccelEvent&) = delete; - ~FAccelEvent(); + ~FAccelEvent() = default; FAccelEvent& operator = (const FAccelEvent&) = delete; FWidget* focusedWidget() const; @@ -253,7 +253,7 @@ class FResizeEvent : public FEvent // resize event public: FResizeEvent() = default; explicit FResizeEvent (fc::events); - ~FResizeEvent(); + ~FResizeEvent() = default; bool isAccepted() const; void accept(); @@ -273,7 +273,7 @@ class FShowEvent : public FEvent // show event public: FShowEvent() = default; explicit FShowEvent (fc::events); - ~FShowEvent(); + ~FShowEvent() = default; }; @@ -286,7 +286,7 @@ class FHideEvent : public FEvent // hide event public: FHideEvent() = default; explicit FHideEvent (fc::events); - ~FHideEvent(); + ~FHideEvent() = default; }; @@ -299,7 +299,7 @@ class FCloseEvent : public FEvent // close event public: FCloseEvent() = default; explicit FCloseEvent(fc::events); - ~FCloseEvent(); + ~FCloseEvent() = default; bool isAccepted() const; void accept(); @@ -319,7 +319,7 @@ class FTimerEvent : public FEvent // timer event public: FTimerEvent() = default; FTimerEvent (fc::events, int); - ~FTimerEvent(); + ~FTimerEvent() = default; int getTimerId() const; @@ -341,7 +341,7 @@ class FUserEvent : public FEvent // user event FUserEvent (const FUserEvent&) = delete; FUserEvent (fc::events, int); - ~FUserEvent(); + ~FUserEvent() = default; // Disable copy assignment operator (=) FUserEvent& operator = (const FUserEvent&) = delete; diff --git a/src/include/final/fkeyboard.h b/src/include/final/fkeyboard.h index 567a7e2c..7ac7b1b5 100644 --- a/src/include/final/fkeyboard.h +++ b/src/include/final/fkeyboard.h @@ -100,7 +100,7 @@ class FKeyboard final FKeyboard (const FKeyboard&) = delete; // Destructor - ~FKeyboard(); + ~FKeyboard() = default; // Disable copy assignment operator (=) FKeyboard& operator = (const FKeyboard&) = delete; diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index 7c28aebe..3ab68976 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -163,8 +163,8 @@ class FLineEdit : public FWidget void adjustSize() override; private: - // Typedef - typedef std::pair offsetPair; + // Using-declaration + using offsetPair = std::pair; // Enumeration enum dragScroll diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index d763a5eb..0d27a1ae 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -73,13 +73,13 @@ class FListBoxItem { public: // Constructors - FListBoxItem (); + FListBoxItem() = default; FListBoxItem (const FListBoxItem&); // copy constructor template explicit FListBoxItem (const FString&, DT&& = DT() ); // Destructor - virtual ~FListBoxItem(); + virtual ~FListBoxItem() noexcept; // copy copy assignment operator (=) FListBoxItem& operator = (const FListBoxItem&); diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index b75c7f0d..fe164f88 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -219,23 +219,16 @@ class FListViewIterator using iterator_stack = std::stack; // Constructor - FListViewIterator (); + FListViewIterator () = default; FListViewIterator (iterator); - FListViewIterator (const FListViewIterator&); // copy constructor - FListViewIterator (FListViewIterator&&) noexcept; // move constructor - - // Destructor - ~FListViewIterator(); // Overloaded operators - FListViewIterator& operator = (const FListViewIterator&); - FListViewIterator& operator = (FListViewIterator&&) noexcept; FListViewIterator& operator ++ (); // prefix FListViewIterator operator ++ (int); // postfix FListViewIterator& operator -- (); // prefix FListViewIterator operator -- (int); // postfix - FListViewIterator& operator += (volatile int); - FListViewIterator& operator -= (volatile int); + FListViewIterator& operator += (int); + FListViewIterator& operator -= (int); FObject*& operator * () const; FObject* operator -> () const; bool operator == (const FListViewIterator&) const; @@ -542,8 +535,7 @@ class FListView : public FWidget struct FListView::Header { public: - Header() - { } + Header () = default; FString name{}; fc::text_alignment alignment{fc::alignLeft}; diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index 4807386b..348b5eb0 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -102,17 +102,16 @@ class FMenuBar : public FWindow, public FMenuList void cb_itemDeactivated (const FMenuItem*) const; private: - // Constants - static constexpr auto NOT_SET = static_cast(-1); - - // Typedef - typedef struct + struct menuText { FString text; std::size_t startpos; std::size_t hotkeypos; bool no_underline; - } menuText; + }; + + // Constants + static constexpr auto NOT_SET = static_cast(-1); // Inquiry bool isMenu (const FMenuItem*) const; diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index 4b79c0c5..d24b2e51 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -59,6 +59,10 @@ #include +#include +#include + +#include "final/fbutton.h" #include "final/fdialog.h" #include "final/fwidgetcolors.h" @@ -95,7 +99,7 @@ class FMessageBox : public FDialog , ButtonType, ButtonType, ButtonType , FWidget* = nullptr ); // Destructor - ~FMessageBox() override; + virtual ~FMessageBox() noexcept override; // copy assignment operator (=) FMessageBox& operator = (const FMessageBox&); @@ -140,10 +144,12 @@ class FMessageBox : public FDialog // Constants static constexpr std::size_t MAX_BUTTONS = 3; + // Using-declaration + using FButtons = std::array, MAX_BUTTONS>; + // Methods void init(); void allocation(); - void deallocation(); void initCallbacks(); void calculateDimensions(); void draw() override; @@ -154,7 +160,8 @@ class FMessageBox : public FDialog FString headline_text{}; FString text{}; FStringList text_components{}; - FButton* button[MAX_BUTTONS]{nullptr}; + + FButtons button; std::size_t max_line_width{0}; FColor emphasis_color{getColorTheme()->dialog_emphasis_fg}; ButtonType button_digit[MAX_BUTTONS]{FMessageBox::Reject}; diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index e265c9e7..a4b6c00a 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -257,7 +257,7 @@ class FMouseGPM final : public FMouse FMouseGPM(); // Destructor - ~FMouseGPM() override; + ~FMouseGPM() override = default; // Accessors FString getClassName() const override; @@ -581,13 +581,14 @@ class FMouseControl void drawPointer(); private: - // Typedef - typedef std::map FMouseProtocol; - typedef std::unique_ptr FMouseDataPtr; + // Using-declaration + using FMousePtr = std::unique_ptr; + using FMouseDataPtr = std::unique_ptr; + using FMouseProtocol = std::map; // Accessor - FMouse* getMouseWithData(); - FMouse* getMouseWithEvent(); + FMouse::mouse_type getMouseWithData(); + FMouse::mouse_type getMouseWithEvent(); void xtermMouse (bool) const; void enableXTermMouse() const; void disableXTermMouse() const; diff --git a/src/include/final/fobject.h b/src/include/final/fobject.h index a5fb8a14..bff7cb6b 100644 --- a/src/include/final/fobject.h +++ b/src/include/final/fobject.h @@ -150,8 +150,9 @@ class FObject FObject* object; }; - // Typedefs - typedef std::vector FTimerList; + // Using-declaration + using FTimerList = std::vector; + using FTimerListPtr = const std::unique_ptr; // Accessor FTimerList* getTimerList() const; @@ -169,6 +170,7 @@ class FObject private: // Method virtual void performTimerAction (FObject*, FEvent*); + static FTimerListPtr& globalTimerList(); // Data members FObject* parent_obj{nullptr}; @@ -177,7 +179,6 @@ class FObject bool has_parent{false}; bool widget_object{false}; static bool timer_modify_lock; - static FTimerList* timer_list; }; @@ -267,7 +268,7 @@ inline bool FObject::isTimerInUpdating() const //---------------------------------------------------------------------- inline FObject::FTimerList* FObject::getTimerList() const -{ return timer_list; } +{ return globalTimerList().get(); } //---------------------------------------------------------------------- inline void FObject::setWidgetProperty (bool property) diff --git a/src/include/final/foptiattr.h b/src/include/final/foptiattr.h index a9103174..cfa48398 100644 --- a/src/include/final/foptiattr.h +++ b/src/include/final/foptiattr.h @@ -51,8 +51,7 @@ namespace finalcut class FOptiAttr final { public: - // Typedef - typedef struct + struct TermEnv { const char* t_enter_bold_mode; const char* t_exit_bold_mode; @@ -92,7 +91,7 @@ class FOptiAttr final int max_color; int attr_without_color; bool ansi_default_color; - } TermEnv; + }; // Constructor FOptiAttr(); @@ -101,7 +100,7 @@ class FOptiAttr final FOptiAttr (const FOptiAttr&) = delete; // Destructor - ~FOptiAttr(); + ~FOptiAttr() noexcept = default; // Disable copy assignment operator (=) FOptiAttr& operator = (const FOptiAttr&) = delete; diff --git a/src/include/final/foptimove.h b/src/include/final/foptimove.h index 1fcea1fb..c9003fee 100644 --- a/src/include/final/foptimove.h +++ b/src/include/final/foptimove.h @@ -89,7 +89,7 @@ class FOptiMove final explicit FOptiMove (int = 0); // Destructor - ~FOptiMove(); + ~FOptiMove() noexcept = default; // Accessors FString getClassName() const; @@ -168,7 +168,7 @@ class FOptiMove final void calculateCharDuration(); int capDuration (const char[], int) const; int capDurationToLength (int) const; - int repeatedAppend (const Capability&, volatile int, char*) const; + int repeatedAppend (const Capability&, int, char*) const; int relativeMove (char[], int, int, int, int) const; int verticalMove (char[], int, int) const; void downMove (char[], int&, int, int) const; diff --git a/src/include/final/fpoint.h b/src/include/final/fpoint.h index 17ba5628..b4019623 100644 --- a/src/include/final/fpoint.h +++ b/src/include/final/fpoint.h @@ -52,21 +52,14 @@ class FPoint public: // Constructors FPoint () = default; - FPoint (const FPoint&); // copy constructor - FPoint (FPoint&&) noexcept; // move constructor FPoint (int, int); - // Destructor - virtual ~FPoint(); - // Overloaded operators - FPoint& operator = (const FPoint&); - FPoint& operator = (FPoint&&) noexcept; FPoint& operator += (const FPoint&); FPoint& operator -= (const FPoint&); // Accessors - virtual FString getClassName(); + FString getClassName(); int getX() const; int getY() const; void setX (int); @@ -102,18 +95,6 @@ class FPoint // FPoint inline functions -//---------------------------------------------------------------------- -inline FPoint::FPoint (const FPoint& p) // copy constructor - : xpos{p.xpos} - , ypos{p.ypos} -{ } - -//---------------------------------------------------------------------- -inline FPoint::FPoint (FPoint&& p) noexcept // move constructor - : xpos{std::move(p.xpos)} - , ypos{std::move(p.ypos)} -{ } - //---------------------------------------------------------------------- inline FPoint::FPoint (int x, int y) : xpos{x} diff --git a/src/include/final/fprogressbar.h b/src/include/final/fprogressbar.h index 05d2005b..c7f89fb6 100644 --- a/src/include/final/fprogressbar.h +++ b/src/include/final/fprogressbar.h @@ -66,7 +66,7 @@ class FProgressbar : public FWidget explicit FProgressbar(FWidget* = nullptr); // Destructor - ~FProgressbar() override; + ~FProgressbar() noexcept override; // Accessors FString getClassName() const override; diff --git a/src/include/final/fradiobutton.h b/src/include/final/fradiobutton.h index 5187017f..6af13e5a 100644 --- a/src/include/final/fradiobutton.h +++ b/src/include/final/fradiobutton.h @@ -72,7 +72,7 @@ class FRadioButton : public FToggleButton FRadioButton (const FRadioButton&) = delete; // Destructor - ~FRadioButton() override; + ~FRadioButton() noexcept override; // Disable copy assignment operator (=) FRadioButton& operator = (const FRadioButton&) = delete; diff --git a/src/include/final/fradiomenuitem.h b/src/include/final/fradiomenuitem.h index 4ba3b0c3..ba306c8f 100644 --- a/src/include/final/fradiomenuitem.h +++ b/src/include/final/fradiomenuitem.h @@ -72,7 +72,7 @@ class FRadioMenuItem : public FMenuItem FRadioMenuItem (const FRadioMenuItem&) = delete; // Destructor - ~FRadioMenuItem() override; + ~FRadioMenuItem() noexcept override; // Disable copy assignment operator (=) FRadioMenuItem& operator = (const FRadioMenuItem&) = delete; diff --git a/src/include/final/frect.h b/src/include/final/frect.h index 15c4a25e..ec588e33 100644 --- a/src/include/final/frect.h +++ b/src/include/final/frect.h @@ -60,21 +60,12 @@ class FRect public: // Constructors FRect () = default; - FRect (const FRect&); // copy constructor - FRect (FRect&&) noexcept; // move constructor FRect (int, int, std::size_t, std::size_t); FRect (const FPoint&, const FSize&); FRect (const FPoint&, const FPoint&); - // Destructor - virtual ~FRect(); - - // Overloaded operators - FRect& operator = (const FRect&); - FRect& operator = (FRect&&) noexcept; - // Accessors - virtual FString getClassName(); + FString getClassName(); int getX1() const; int getY1() const; int getX2() const; @@ -147,22 +138,6 @@ 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} -{ } - -//---------------------------------------------------------------------- -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)} -{ } - //---------------------------------------------------------------------- inline FRect::FRect (int x, int y, std::size_t width, std::size_t height) : X1{x} diff --git a/src/include/final/fscrollbar.h b/src/include/final/fscrollbar.h index f4b7fe95..6e394fb5 100644 --- a/src/include/final/fscrollbar.h +++ b/src/include/final/fscrollbar.h @@ -60,8 +60,8 @@ namespace finalcut // class forward declaration class FScrollbar; -// Global typedef -typedef std::shared_ptr FScrollbarPtr; +// Global using-declaration +using FScrollbarPtr = std::shared_ptr; //---------------------------------------------------------------------- // class FScrollbar @@ -70,7 +70,7 @@ typedef std::shared_ptr FScrollbarPtr; class FScrollbar : public FWidget { public: - // Using-declarations + // Using-declaration using FWidget::setGeometry; // Enumeration diff --git a/src/include/final/fsize.h b/src/include/final/fsize.h index 9de799ef..90c94f4f 100644 --- a/src/include/final/fsize.h +++ b/src/include/final/fsize.h @@ -57,21 +57,14 @@ class FSize public: // Constructors FSize () = default; - FSize (const FSize&); // copy constructor - FSize (FSize&&) noexcept; // move constructor FSize (std::size_t, std::size_t); - // Destructor - virtual ~FSize(); - // Overloaded operators - FSize& operator = (const FSize&); - FSize& operator = (FSize&&) noexcept; FSize& operator += (const FSize&); FSize& operator -= (const FSize&); // Accessors - virtual FString getClassName(); + FString getClassName(); std::size_t getWidth() const; std::size_t getHeight() const; std::size_t getArea() const; @@ -111,18 +104,6 @@ class FSize }; // FSize inline functions -//---------------------------------------------------------------------- -inline FSize::FSize (const FSize& s) // copy constructor - : width{s.width} - , height{s.height} -{ } - -//---------------------------------------------------------------------- -inline FSize::FSize (FSize&& s) noexcept // move constructor - : width{std::move(s.width)} - , height{std::move(s.height)} -{ } - //---------------------------------------------------------------------- inline FSize::FSize (std::size_t w, std::size_t h) : width{w} diff --git a/src/include/final/fspinbox.h b/src/include/final/fspinbox.h index b13c306f..24963f9b 100644 --- a/src/include/final/fspinbox.h +++ b/src/include/final/fspinbox.h @@ -74,7 +74,7 @@ class FSpinBox : public FWidget FSpinBox (const FSpinBox&) = delete; // Destructor - ~FSpinBox() override; + ~FSpinBox() noexcept override; // Disable copy assignment operator (=) FSpinBox& operator = (const FSpinBox&) = delete; diff --git a/src/include/final/fstartoptions.h b/src/include/final/fstartoptions.h index a5430228..715e013e 100644 --- a/src/include/final/fstartoptions.h +++ b/src/include/final/fstartoptions.h @@ -59,7 +59,7 @@ class FStartOptions final FStartOptions (const FStartOptions&) = delete; // Destructor - ~FStartOptions(); + ~FStartOptions() = default; // Disable copy assignment operator (=) FStartOptions& operator = (const FStartOptions&) = delete; @@ -71,9 +71,6 @@ class FStartOptions final // Mutator void setDefault(); - // Method - static void destroyObject(); - // Data members uInt8 cursor_optimisation : 1; uInt8 mouse_support : 1; diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index 8a1bf59d..fda86f79 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -68,8 +68,8 @@ namespace finalcut // class forward declaration class FString; -// Global typedef -typedef std::vector FStringList; +// Global using-declaration +using FStringList = std::vector; //---------------------------------------------------------------------- diff --git a/src/include/final/fstyle.h b/src/include/final/fstyle.h index dbb93162..d6188beb 100644 --- a/src/include/final/fstyle.h +++ b/src/include/final/fstyle.h @@ -54,21 +54,6 @@ class FStyle : attribute{attr} { } - // Copy constructor - FStyle (const FStyle& style) - : attribute{style.attribute} - { } - - // Destructor - ~FStyle() = default; - - // copy assignment operator (=) - FStyle& operator = (const FStyle& style) - { - attribute = style.attribute; - return *this; - } - // Accessor FString getClassName() const { return "FStyle"; } diff --git a/src/include/final/fswitch.h b/src/include/final/fswitch.h index 3978a4db..a450f973 100644 --- a/src/include/final/fswitch.h +++ b/src/include/final/fswitch.h @@ -72,7 +72,7 @@ class FSwitch : public FToggleButton FSwitch (const FSwitch&) = delete; // Destructor - ~FSwitch() override; + ~FSwitch() noexcept override; // Disable copy assignment operator (=) FSwitch& operator = (const FSwitch&) = delete; diff --git a/src/include/final/fsystem.h b/src/include/final/fsystem.h index e07fed7b..8ac8723a 100644 --- a/src/include/final/fsystem.h +++ b/src/include/final/fsystem.h @@ -52,10 +52,10 @@ class FSystem using fn_putc = int (*)(int); // Constructor - FSystem(); + FSystem () = default; // Destructor - virtual ~FSystem(); + virtual ~FSystem() noexcept; // Methods virtual uChar inPortByte (uShort) = 0; diff --git a/src/include/final/fsystemimpl.h b/src/include/final/fsystemimpl.h index 17d56a4b..aa9bad91 100644 --- a/src/include/final/fsystemimpl.h +++ b/src/include/final/fsystemimpl.h @@ -97,10 +97,10 @@ class FSystemImpl : public FSystem { public: // Constructor - FSystemImpl(); + FSystemImpl() = default; // Destructor - ~FSystemImpl() override; + ~FSystemImpl() noexcept override; // Methods #if defined(ISA_SYSCTL_SUPPORT) diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index aefaf4ba..7abd7cf6 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -161,10 +161,10 @@ class FTermXTerminal; class FTerm final { public: - // Typedef - typedef std::function defaultPutChar; - typedef std::shared_ptr FColorPalettePtr; - typedef FColorPalette::FSetPalette FSetPalette; + // Using-declarations + using defaultPutChar = std::function; + using FColorPalettePtr = std::shared_ptr; + using FSetPalette = FColorPalette::FSetPalette; // Constructor FTerm(); diff --git a/src/include/final/ftermbuffer.h b/src/include/final/ftermbuffer.h index 3ef4455e..4d8fc918 100644 --- a/src/include/final/ftermbuffer.h +++ b/src/include/final/ftermbuffer.h @@ -69,7 +69,7 @@ class FTermBuffer FTermBuffer (Iterator, Iterator); // Destructor - virtual ~FTermBuffer(); + virtual ~FTermBuffer() noexcept; // Overloaded operators template diff --git a/src/include/final/ftermcapquirks.h b/src/include/final/ftermcapquirks.h index c73df24b..384918d5 100644 --- a/src/include/final/ftermcapquirks.h +++ b/src/include/final/ftermcapquirks.h @@ -50,10 +50,10 @@ class FTermcapQuirks final { public: // Constructors - FTermcapQuirks(); + FTermcapQuirks() = default; // Destructor - ~FTermcapQuirks(); + ~FTermcapQuirks() noexcept = default; // Accessor FString getClassName() const; diff --git a/src/include/final/ftermdata.h b/src/include/final/ftermdata.h index 5ba213c6..3b77b4fc 100644 --- a/src/include/final/ftermdata.h +++ b/src/include/final/ftermdata.h @@ -57,15 +57,13 @@ class FTermData final typedef std::unordered_map EncodingMap; // Constructors - FTermData() - { } + FTermData () = default; // Disable copy constructor FTermData (const FTermData&) = delete; // Destructor - ~FTermData() - { } + ~FTermData() noexcept = default; // Disable copy assignment operator (=) FTermData& operator = (const FTermData&) = delete; diff --git a/src/include/final/ftermdetection.h b/src/include/final/ftermdetection.h index 89798b87..6935372e 100644 --- a/src/include/final/ftermdetection.h +++ b/src/include/final/ftermdetection.h @@ -50,8 +50,7 @@ namespace finalcut class FTermDetection final { public: - // Typedefs - typedef struct + struct FTerminalType { // byte #0 uInt8 ansi : 1; @@ -77,7 +76,7 @@ class FTermDetection final uInt8 kterm : 1; uInt8 mlterm : 1; uInt8 : 4; // padding bits - } FTerminalType; + }; // Constructors FTermDetection(); diff --git a/src/include/final/ftermfreebsd.h b/src/include/final/ftermfreebsd.h index 93ac5405..23214c59 100644 --- a/src/include/final/ftermfreebsd.h +++ b/src/include/final/ftermfreebsd.h @@ -79,8 +79,8 @@ class FTermData; class FTermFreeBSD final { public: - // Typedef - typedef fc::freebsdConsoleCursorStyle CursorStyle; + // Using-declaration + using CursorStyle = fc::freebsdConsoleCursorStyle; // Constructors FTermFreeBSD() = default; diff --git a/src/include/final/ftermios.h b/src/include/final/ftermios.h index e1a31e35..14178b9c 100644 --- a/src/include/final/ftermios.h +++ b/src/include/final/ftermios.h @@ -55,7 +55,7 @@ class FTermios final FTermios(); // Destructor - ~FTermios(); + ~FTermios() noexcept = default; // Accessors FString getClassName() const; diff --git a/src/include/final/ftermlinux.h b/src/include/final/ftermlinux.h index 84b8b0a0..989b8028 100644 --- a/src/include/final/ftermlinux.h +++ b/src/include/final/ftermlinux.h @@ -77,8 +77,8 @@ class FTermDetection; class FTermLinux final { public: - // Typedef - typedef fc::linuxConsoleCursorStyle CursorStyle; + // Using-declaration + using CursorStyle = fc::linuxConsoleCursorStyle; // Constructors FTermLinux() = default; @@ -123,7 +123,6 @@ class FTermLinux final FKey modifierKeyCorrection (const FKey&); private: - // Typedef struct ModifierKey // bit field { uChar shift : 1; // 0..1 @@ -133,17 +132,17 @@ class FTermLinux final uChar : 4; // padding bits }; - typedef struct + struct RGB { uChar red; uChar green; uChar blue; - } RGB; + }; - typedef struct + struct ColorMap { RGB color[16]; - } ColorMap; + }; // Accessors int getFramebuffer_bpp(); diff --git a/src/include/final/ftermopenbsd.h b/src/include/final/ftermopenbsd.h index 97799dbb..86590cca 100644 --- a/src/include/final/ftermopenbsd.h +++ b/src/include/final/ftermopenbsd.h @@ -81,7 +81,7 @@ class FTermOpenBSD final FTermOpenBSD (const FTermOpenBSD&) = delete; // Destructor - ~FTermOpenBSD(); + ~FTermOpenBSD() noexcept = default; // Disable copy assignment operator (=) FTermOpenBSD& operator = (const FTermOpenBSD&) = delete; diff --git a/src/include/final/ftermxterminal.h b/src/include/final/ftermxterminal.h index 805f58a3..2f53c910 100644 --- a/src/include/final/ftermxterminal.h +++ b/src/include/final/ftermxterminal.h @@ -58,7 +58,7 @@ class FTermXTerminal final FTermXTerminal (const FTermXTerminal&) = delete; // Destructor - ~FTermXTerminal(); + ~FTermXTerminal() noexcept = default; // Disable copy assignment operator (=) FTermXTerminal& operator = (const FTermXTerminal&) = delete; diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index 8fb66e65..6ddd3946 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -77,7 +77,7 @@ class FTextView : public FWidget FTextView (const FTextView&) = delete; // Destructor - ~FTextView() override; + ~FTextView() noexcept override; // Disable copy assignment operator (=) FTextView& operator = (const FTextView&) = delete; diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 35e35565..0780e32f 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -148,7 +148,7 @@ class FToggleButton : public FWidget // Methods void init(); - void drawText (const FString&, std::size_t); + void drawText (FString&&, std::size_t); void correctSize (FSize&) const; // Data members diff --git a/src/include/final/ftypes.h b/src/include/final/ftypes.h index 42e7088b..4bbba54d 100644 --- a/src/include/final/ftypes.h +++ b/src/include/final/ftypes.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -49,29 +50,28 @@ << " in " \ << __func__ << std::endl; -typedef unsigned char uChar; -typedef unsigned short uShort; -typedef unsigned int uInt; -typedef unsigned long uLong; -typedef std::uint8_t uInt8; -typedef std::uint16_t uInt16; -typedef std::uint32_t uInt32; -typedef std::uint64_t uInt64; +using uChar = unsigned char; +using uShort = unsigned short; +using uInt = unsigned int; +using uLong = unsigned long; +using uInt8 = std::uint8_t; +using uInt16 = std::uint16_t; +using uInt32 = std::uint32_t; +using uInt64 = std::uint64_t; -typedef signed int sInt; -typedef signed long sLong; -typedef std::int8_t sInt8; -typedef std::int16_t sInt16; -typedef std::int32_t sInt32; -typedef std::int64_t sInt64; +using sInt = signed int; +using sLong = signed long; +using sInt8 = std::int8_t; +using sInt16 = std::int16_t; +using sInt32 = std::int32_t; +using sInt64 = std::int64_t; -typedef long double lDouble; +using lDouble = long double; -typedef uInt16 FColor; -typedef uInt16 FAttribute; -typedef uInt32 FKey; -typedef void* FDataPtr; -typedef std::function FCall; +using FColor = uInt16; +using FAttribute = uInt16; +using FKey = uInt32; +using FCall = std::function; namespace finalcut { @@ -115,7 +115,13 @@ struct getPrecision } }; -typedef std::unordered_map charSubstitution; +template +std::unique_ptr make_unique (Args&&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} + +using charSubstitution = std::unordered_map; struct FCharAttribute { @@ -155,42 +161,39 @@ union attribute static constexpr uInt UNICODE_MAX = 5; -typedef std::array FUnicode; +using FUnicode = std::array; -typedef struct +struct FChar { - FUnicode ch; // Character code - FUnicode encoded_char; // Encoded output character - FColor fg_color; // Foreground color - FColor bg_color; // Background color - attribute attr; // Attributes -} FChar; + FUnicode ch{}; // Character code + FUnicode encoded_char{}; // Encoded output character + FColor fg_color{}; // Foreground color + FColor bg_color{}; // Background color + attribute attr{}; // Attributes +}; namespace fc { -typedef struct +struct FKeyMap { FKey num; const char* string; char tname[4]; -} -FKeyMap; +}; -typedef struct +struct FMetakeyMap { FKey num; char string[8]; -} -FMetakeyMap; +}; -typedef struct +struct FKeyName { FKey num; char string[25]; -} -FKeyName; +}; } // namespace fc @@ -198,7 +201,7 @@ FKeyName; //---------------------------------------------------------------------- inline bool operator == (const FChar& lhs, const FChar& rhs) { - return operator == (lhs.ch, rhs.ch) + return operator == (lhs.ch, rhs.ch) // Compare FUnicode && lhs.fg_color == rhs.fg_color && lhs.bg_color == rhs.bg_color && lhs.attr.byte[0] == rhs.attr.byte[0] diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index db0c3a91..be265c79 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -87,22 +87,22 @@ class FWidget; class FVTerm { public: - // Typedefs and Enumeration - typedef struct + struct FTermArea; // forward declaration + struct FVTermPreprocessing; // forward declaration + + struct FLineChanges { uInt xmin; // X-position with the first change uInt xmax; // X-position with the last change uInt trans_count; // Number of transparent characters - } FLineChanges; + }; - typedef void (FVTerm::*FPreprocessingHandler)(); - typedef std::function FPreprocessingFunction; - - struct FTermArea; // forward declaration - struct FVTermPreprocessing; // forward declaration - - typedef std::vector FPreprocessing; + // Using-declarations + using FPreprocessingHandler = void (FVTerm::*)(); + using FPreprocessingFunction = std::function ; + using FPreprocessing = std::vector; + // Enumerations enum covered_state { non_covered, @@ -500,50 +500,16 @@ struct FVTerm::FTermArea // define virtual terminal character properties struct FVTerm::FVTermPreprocessing { // Constructor - FVTermPreprocessing() - : instance(nullptr) - , function(nullptr) - { } + FVTermPreprocessing() = default; FVTermPreprocessing (const FVTerm* i, const FPreprocessingFunction& f) : instance(i) , function(f) { } - FVTermPreprocessing (const FVTermPreprocessing& p) // copy constructor - : instance(p.instance) - , function(p.function) - { } - - FVTermPreprocessing (FVTermPreprocessing&& p) noexcept // move constructor - : instance(std::move(p.instance)) - , function(std::move(p.function)) - { } - - // Overloaded operators - FVTermPreprocessing& operator = (const FVTermPreprocessing& p) - { - instance = p.instance; - function = p.function; - return *this; - } - - FVTermPreprocessing& operator = (FVTermPreprocessing&& p) noexcept - { - instance = p.instance; - function = p.function; - p.instance = nullptr; - p.function = nullptr; - return *this; - } - - // Destructor - ~FVTermPreprocessing() - { } - // Data members - const FVTerm* instance{}; - FPreprocessingFunction function{}; + const FVTerm* instance{nullptr}; + FPreprocessingFunction function{nullptr}; }; diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index c482b8ef..187aea0d 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -125,20 +125,18 @@ class FWidgetColors; class FWidget : public FVTerm, public FObject { public: - // Using-declaration - using FVTerm::setColor; - using FVTerm::print; - struct FAccelerator { alignas(8) FKey key; FWidget* object; }; - // Typedefs - typedef std::vector FWidgetList; - typedef std::vector FAcceleratorList; - typedef std::shared_ptr FWidgetColorsPtr; + // Using-declarations + using FVTerm::setColor; + using FVTerm::print; + using FWidgetList = std::vector; + using FAcceleratorList = std::vector; + using FWidgetColorsPtr = std::shared_ptr; struct FWidgetFlags // Properties of a widget ⚑ { diff --git a/src/include/final/sgr_optimizer.h b/src/include/final/sgr_optimizer.h index e67dcdd3..67a604b2 100644 --- a/src/include/final/sgr_optimizer.h +++ b/src/include/final/sgr_optimizer.h @@ -61,7 +61,7 @@ class SGRoptimizer final SGRoptimizer (const SGRoptimizer&) = delete; // Destructor - ~SGRoptimizer(); + ~SGRoptimizer() noexcept = default; // Disable copy assignment operator (=) SGRoptimizer& operator = (const SGRoptimizer&) = delete; diff --git a/src/sgr_optimizer.cpp b/src/sgr_optimizer.cpp index b38ecbf4..a26f7e6f 100644 --- a/src/sgr_optimizer.cpp +++ b/src/sgr_optimizer.cpp @@ -39,10 +39,6 @@ SGRoptimizer::SGRoptimizer (AttributeBuffer& sequence) : seq{sequence} { } -//---------------------------------------------------------------------- -SGRoptimizer::~SGRoptimizer() // destructor -{ } - // public methods of SGRoptimizer //---------------------------------------------------------------------- From 4517038521487417969d3e2c644f38eb955934c6 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 3 Dec 2020 10:43:20 +0100 Subject: [PATCH 04/45] Using smart pointers for global objects --- examples/calculator.cpp | 2 +- examples/event-log.cpp | 10 +- examples/listbox.cpp | 2 +- examples/opti-move.cpp | 11 +- examples/termcap.cpp | 14 +- examples/treeview.cpp | 24 +- src/fapplication.cpp | 132 +++--- src/fbusyindicator.cpp | 3 +- src/fbuttongroup.cpp | 4 +- src/fcallback.cpp | 10 - src/fcolorpalette.cpp | 15 +- src/fdata.cpp | 7 +- src/fdialog.cpp | 4 +- src/ffiledialog.cpp | 21 +- src/fkeyboard.cpp | 32 +- src/flog.cpp | 4 - src/flogger.cpp | 7 +- src/fmenu.cpp | 12 +- src/fmenubar.cpp | 4 +- src/fmouse.cpp | 16 +- src/fobject.cpp | 7 +- src/fstring.cpp | 11 +- src/fstringstream.cpp | 4 +- src/fterm.cpp | 655 +++++++++++------------------ src/ftermbuffer.cpp | 9 +- src/ftermcap.cpp | 19 +- src/ftermcapquirks.cpp | 24 +- src/ftermdebugdata.cpp | 18 +- src/ftermdetection.cpp | 17 +- src/ftermfreebsd.cpp | 50 +-- src/ftermlinux.cpp | 119 +++--- src/ftermopenbsd.cpp | 53 +-- src/ftermxterminal.cpp | 75 +--- src/ftogglebutton.cpp | 4 +- src/fvterm.cpp | 53 +-- src/fwidget.cpp | 6 +- src/fwidgetcolors.cpp | 23 +- src/include/final/emptyfstring.h | 66 +-- src/include/final/fapplication.h | 11 +- src/include/final/fbusyindicator.h | 2 +- src/include/final/fbuttongroup.h | 2 +- src/include/final/fcallback.h | 4 +- src/include/final/fcolorpalette.h | 8 +- src/include/final/fdata.h | 7 +- src/include/final/fdialog.h | 2 +- src/include/final/ffiledialog.h | 4 - src/include/final/fkeyboard.h | 9 - src/include/final/flistview.h | 7 +- src/include/final/flog.h | 2 +- src/include/final/flogger.h | 4 +- src/include/final/fmenu.h | 6 +- src/include/final/fmenubar.h | 2 +- src/include/final/fmessagebox.h | 2 +- src/include/final/fmouse.h | 56 +-- src/include/final/fobject.h | 4 +- src/include/final/fpoint.h | 4 +- src/include/final/frect.h | 4 +- src/include/final/fsize.h | 4 +- src/include/final/fstringstream.h | 4 +- src/include/final/fterm.h | 105 ++--- src/include/final/ftermcap.h | 15 +- src/include/final/ftermcapquirks.h | 8 - src/include/final/ftermdebugdata.h | 10 - src/include/final/ftermdetection.h | 3 - src/include/final/ftermfreebsd.h | 7 - src/include/final/ftermlinux.h | 10 +- src/include/final/ftermopenbsd.h | 8 - src/include/final/ftermxterminal.h | 14 +- src/include/final/ftogglebutton.h | 2 +- src/include/final/fvterm.h | 24 +- src/include/final/fwidgetcolors.h | 12 +- test/conemu.h | 2 +- test/ftermfreebsd-test.cpp | 19 +- test/ftermlinux-test.cpp | 152 ++++--- test/ftermopenbsd-test.cpp | 29 +- 75 files changed, 800 insertions(+), 1315 deletions(-) diff --git a/examples/calculator.cpp b/examples/calculator.cpp index c8912c33..7058f5de 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -122,7 +122,7 @@ class Calc final : public finalcut::FDialog private: // Typedef and Enumeration - typedef std::function keyFunction; // Member function + using keyFunction = std::function; // Member function enum button { diff --git a/examples/event-log.cpp b/examples/event-log.cpp index 2c2aa840..900b3941 100644 --- a/examples/event-log.cpp +++ b/examples/event-log.cpp @@ -51,7 +51,7 @@ class EventDialog final : public finalcut::FDialog EventDialog (const EventDialog&) = delete; // Destructor - ~EventDialog() override; + ~EventDialog() noexcept override; // Disable copy assignment operator (=) EventDialog& operator = (const EventDialog&) = delete; @@ -99,8 +99,7 @@ EventDialog::EventDialog (finalcut::FWidget* parent) } //---------------------------------------------------------------------- -EventDialog::~EventDialog() // destructor -{ } +EventDialog::~EventDialog() noexcept = default; // destructor //---------------------------------------------------------------------- finalcut::FString EventDialog::getMouseButtonName (int btn_state) const @@ -245,7 +244,7 @@ class EventLog final : public finalcut::FDialog, public std::ostringstream EventLog (const EventLog&) = delete; // Destructor - ~EventLog() override; + ~EventLog() noexcept override; // Disable copy assignment operator (=) EventLog& operator = (const EventLog&) = delete; @@ -282,8 +281,7 @@ EventLog::EventLog (finalcut::FWidget* parent) } //---------------------------------------------------------------------- -EventLog::~EventLog() // destructor -{ } +EventLog::~EventLog() noexcept = default; // destructor //---------------------------------------------------------------------- void EventLog::onTimer (finalcut::FTimerEvent*) diff --git a/examples/listbox.cpp b/examples/listbox.cpp index f47a937b..1cfbaf7a 100644 --- a/examples/listbox.cpp +++ b/examples/listbox.cpp @@ -50,7 +50,7 @@ void doubleToItem ( FListBoxItem& item , FDataAccess* container , std::size_t index ) { - typedef std::list DblList; + using DblList = std::list; DblList& dbl_list = flistboxhelper::getContainer(container); std::list::iterator iter = dbl_list.begin(); std::advance (iter, index); diff --git a/examples/opti-move.cpp b/examples/opti-move.cpp index dfeb007c..8973e09a 100644 --- a/examples/opti-move.cpp +++ b/examples/opti-move.cpp @@ -136,10 +136,10 @@ class DirectLogger final : public finalcut::FLog { public: // Constructor - DirectLogger(); + DirectLogger() = default; // Destructor - ~DirectLogger() override; + ~DirectLogger() noexcept override; void info (const std::string& entry) override { @@ -194,12 +194,7 @@ class DirectLogger final : public finalcut::FLog }; //---------------------------------------------------------------------- -DirectLogger::DirectLogger() // constructor -{ } - -//---------------------------------------------------------------------- -DirectLogger::~DirectLogger() // destructor -{ } +DirectLogger::~DirectLogger() noexcept = default; // destructor //---------------------------------------------------------------------- diff --git a/examples/termcap.cpp b/examples/termcap.cpp index 16554f20..333467ce 100644 --- a/examples/termcap.cpp +++ b/examples/termcap.cpp @@ -212,22 +212,22 @@ void tcapString (const std::string& name, const char cap_str[]) void debug (const finalcut::FApplication& TermApp) { const auto& fterm = TermApp.getFTerm(); - auto& debug_data = fterm.getFTermDebugData(); - const finalcut::FString& ab_s = debug_data.getAnswerbackString(); - const finalcut::FString& sec_da = debug_data.getSecDAString(); + const auto& debug_data = fterm.getFTermDebugData(); + const finalcut::FString& ab_s = debug_data->getAnswerbackString(); + const finalcut::FString& sec_da = debug_data->getSecDAString(); std::cout << "\n.------------------- debug -------------------\r\n"; #if defined(__linux__) std::cout << "| Framebuffer bpp: " - << debug_data.getFramebufferBpp() << "\r\n"; + << debug_data->getFramebufferBpp() << "\r\n"; #endif std::cout << "| after init_256colorTerminal(): " - << debug_data.getTermType_256color() << "\r\n"; + << debug_data->getTermType_256color() << "\r\n"; std::cout << "| after parseAnswerbackMsg(): " - << debug_data.getTermType_Answerback() << "\r\n"; + << debug_data->getTermType_Answerback() << "\r\n"; std::cout << "| after parseSecDA(): " - << debug_data.getTermType_SecDA() << "\r\n"; + << debug_data->getTermType_SecDA() << "\r\n"; if ( ! ab_s.isEmpty() ) tcapString ("| The answerback String", ab_s.c_str()); diff --git a/examples/treeview.cpp b/examples/treeview.cpp index 469f265e..340b242c 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -161,12 +161,12 @@ class Treeview final : public finalcut::FDialog struct TreeItem; // forward declaration // Methods - auto initAfrica() -> std::initializer_list; - auto initAsia() -> std::initializer_list; - auto initEurope() -> std::initializer_list; - auto initNorthAmerica() -> std::initializer_list; - auto initSouthAmerica() -> std::initializer_list; - auto initOceania() -> std::initializer_list; + auto initAfrica() -> std::initializer_list const; + auto initAsia() -> std::initializer_list const; + auto initEurope() -> std::initializer_list const; + auto initNorthAmerica() -> std::initializer_list const; + auto initSouthAmerica() -> std::initializer_list const; + auto initOceania() -> std::initializer_list const; void adjustSize() override; // Event handler @@ -275,7 +275,7 @@ Treeview::Treeview (finalcut::FWidget* parent) } //---------------------------------------------------------------------- -auto Treeview::initAfrica() -> std::initializer_list +auto Treeview::initAfrica() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -306,7 +306,7 @@ auto Treeview::initAfrica() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initAsia() -> std::initializer_list +auto Treeview::initAsia() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -334,7 +334,7 @@ auto Treeview::initAsia() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initEurope() -> std::initializer_list +auto Treeview::initEurope() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -362,7 +362,7 @@ auto Treeview::initEurope() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initNorthAmerica() -> std::initializer_list +auto Treeview::initNorthAmerica() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -379,7 +379,7 @@ auto Treeview::initNorthAmerica() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initSouthAmerica() -> std::initializer_list +auto Treeview::initSouthAmerica() -> std::initializer_list const { static const auto list = std::initializer_list { @@ -398,7 +398,7 @@ auto Treeview::initSouthAmerica() -> std::initializer_list } //---------------------------------------------------------------------- -auto Treeview::initOceania() -> std::initializer_list +auto Treeview::initOceania() -> std::initializer_list const { static const auto list = std::initializer_list { diff --git a/src/fapplication.cpp b/src/fapplication.cpp index f2d93803..a1397e7a 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -68,8 +68,6 @@ FWidget* FWidget::clicked_widget {nullptr}; // is focused by click FWidget* FWidget::open_menu {nullptr}; // currently open menu FWidget* FWidget::move_size_widget {nullptr}; // move/size by keyboard FWidget* FApplication::keyboard_widget {nullptr}; // has the keyboard focus -FKeyboard* FApplication::keyboard {nullptr}; // keyboard access -FMouseControl* FApplication::mouse {nullptr}; // mouse control int FApplication::loop_level {0}; // event loop level int FApplication::quit_code {EXIT_SUCCESS}; bool FApplication::quit_now {false}; @@ -93,9 +91,9 @@ FApplication::FApplication (const int& _argc, char* _argv[]) if ( internal::var::app_object ) { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage("FApplication: There should be " - "only one application object"); + const auto& fterm_data = FTerm::getFTermData(); + fterm_data->setExitMessage("FApplication: There should be " + "only one application object"); FApplication::exit(EXIT_FAILURE); return; } @@ -105,7 +103,7 @@ FApplication::FApplication (const int& _argc, char* _argv[]) if ( ! (_argc && _argv) ) { - typedef char* CString; + using CString = char*; static std::array empty{{CString("")}}; app_argc = 0; app_argv = empty.data(); @@ -350,9 +348,9 @@ void FApplication::setLogFile (const FString& filename) } else { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage ( "Could not open log file \"" - + filename + "\"" ); + const auto& fterm_data = FTerm::getFTermData(); + fterm_data->setExitMessage ( "Could not open log file \"" + + filename + "\"" ); exit(EXIT_FAILURE); } } @@ -405,41 +403,32 @@ void FApplication::init() time_last_event.tv_usec = 0; // Initialize keyboard - keyboard = FTerm::getFKeyboard(); - - - if ( keyboard ) - { - auto cmd1 = std::bind(&FApplication::keyPressed, this); - auto cmd2 = std::bind(&FApplication::keyReleased, this); - auto cmd3 = std::bind(&FApplication::escapeKeyPressed, this); - auto cmd4 = std::bind(&FApplication::mouseTracking, this); - FKeyboardCommand key_cmd1 (cmd1); - FKeyboardCommand key_cmd2 (cmd2); - FKeyboardCommand key_cmd3 (cmd3); - FKeyboardCommand key_cmd4 (cmd4); - keyboard->setPressCommand (key_cmd1); - keyboard->setReleaseCommand (key_cmd2); - keyboard->setEscPressedCommand (key_cmd3); - keyboard->setMouseTrackingCommand (key_cmd4); - // Set the keyboard keypress timeout - keyboard->setKeypressTimeout (key_timeout); - } + const auto& keyboard = FTerm::getFKeyboard(); + auto cmd1 = std::bind(&FApplication::keyPressed, this); + auto cmd2 = std::bind(&FApplication::keyReleased, this); + auto cmd3 = std::bind(&FApplication::escapeKeyPressed, this); + auto cmd4 = std::bind(&FApplication::mouseTracking, this); + FKeyboardCommand key_cmd1 (cmd1); + FKeyboardCommand key_cmd2 (cmd2); + FKeyboardCommand key_cmd3 (cmd3); + FKeyboardCommand key_cmd4 (cmd4); + keyboard->setPressCommand (key_cmd1); + keyboard->setReleaseCommand (key_cmd2); + keyboard->setEscPressedCommand (key_cmd3); + keyboard->setMouseTrackingCommand (key_cmd4); + // Set the keyboard keypress timeout + keyboard->setKeypressTimeout (key_timeout); // Initialize mouse control - mouse = FTerm::getFMouseControl(); - - if ( mouse ) - { - using namespace std::placeholders; - auto cmd = std::bind(&FApplication::mouseEvent, this, _1); - FMouseCommand mouse_cmd (cmd); - mouse->setEventCommand (mouse_cmd); - // Set stdin number for a gpm-mouse - mouse->setStdinNo (FTermios::getStdIn()); - // Set the default double click interval - mouse->setDblclickInterval (dblclick_interval); - } + const auto& mouse = FTerm::getFMouseControl(); + using namespace std::placeholders; + auto cmd = std::bind(&FApplication::mouseEvent, this, _1); + FMouseCommand mouse_cmd (cmd); + mouse->setEventCommand (mouse_cmd); + // Set stdin number for a gpm-mouse + mouse->setStdinNo (FTermios::getStdIn()); + // Set the default double click interval + mouse->setDblclickInterval (dblclick_interval); // Initialize logging if ( ! getStartOptions().logfile_stream.is_open() ) @@ -463,10 +452,10 @@ void FApplication::setTerminalEncoding (const FString& enc_str) showParameterUsage(); else { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage ( "Unknown encoding \"" + enc_str - + "\"\n(Valid encodings are utf8, " - + "vt100, pc and ascii)" ); + const auto& fterm_data = FTerm::getFTermData(); + fterm_data->setExitMessage ( "Unknown encoding \"" + enc_str + + "\"\n(Valid encodings are utf8, " + + "vt100, pc and ascii)" ); exit(EXIT_FAILURE); } } @@ -665,7 +654,10 @@ inline void FApplication::findKeyboardWidget() const //---------------------------------------------------------------------- inline bool FApplication::isKeyPressed() const { - if ( mouse && mouse->isGpmMouseEnabled() ) + const auto& mouse = FTerm::getFMouseControl(); + const auto& keyboard = FTerm::getFKeyboard(); + + if ( mouse->isGpmMouseEnabled() ) return mouse->getGpmKeyPressed(keyboard->hasUnprocessedInput()); return (keyboard->isKeyPressed() || keyboard->hasPendingInput()); @@ -698,6 +690,8 @@ void FApplication::mouseTracking() const //---------------------------------------------------------------------- inline void FApplication::performKeyboardAction() { + const auto& keyboard = FTerm::getFKeyboard(); + if ( keyboard->getKey() == fc::Fckey_l ) // Ctrl-L (redraw the screen) { redraw(); @@ -715,9 +709,8 @@ inline void FApplication::performKeyboardAction() //---------------------------------------------------------------------- inline void FApplication::performMouseAction() const { - if ( ! mouse ) - return; - + const auto& mouse = FTerm::getFMouseControl(); + const auto& keyboard = FTerm::getFKeyboard(); auto& buffer = keyboard->getKeyBuffer(); switch ( keyboard->getKey() ) @@ -768,6 +761,7 @@ inline void FApplication::sendEscapeKeyPressEvent() const inline bool FApplication::sendKeyDownEvent (FWidget* widget) const { // Send key down event + const auto& keyboard = FTerm::getFKeyboard(); FKeyEvent k_down_ev (fc::KeyDown_Event, keyboard->getKey()); sendEvent (widget, &k_down_ev); return k_down_ev.isAccepted(); @@ -777,6 +771,7 @@ inline bool FApplication::sendKeyDownEvent (FWidget* widget) const inline bool FApplication::sendKeyPressEvent (FWidget* widget) const { // Send key press event + const auto& keyboard = FTerm::getFKeyboard(); FKeyEvent k_press_ev (fc::KeyPress_Event, keyboard->getKey()); sendEvent (widget, &k_press_ev); return k_press_ev.isAccepted(); @@ -786,6 +781,7 @@ inline bool FApplication::sendKeyPressEvent (FWidget* widget) const inline bool FApplication::sendKeyUpEvent (FWidget* widget) const { // Send key up event + const auto& keyboard = FTerm::getFKeyboard(); FKeyEvent k_up_ev (fc::KeyUp_Event, keyboard->getKey()); sendEvent (widget, &k_up_ev); return k_up_ev.isAccepted(); @@ -822,9 +818,12 @@ inline void FApplication::sendKeyboardAccelerator() //---------------------------------------------------------------------- inline bool FApplication::hasDataInQueue() const { - if ( keyboard && keyboard->hasDataInQueue() ) + const auto& keyboard = FTerm::getFKeyboard(); + const auto& mouse = FTerm::getFMouseControl(); + + if ( keyboard->hasDataInQueue() ) return true; - else if ( mouse && mouse->hasDataInQueue() ) + else if ( mouse->hasDataInQueue() ) return true; return false; @@ -833,10 +832,11 @@ inline bool FApplication::hasDataInQueue() const //---------------------------------------------------------------------- void FApplication::queuingKeyboardInput() const { - if ( quit_now || internal::var::exit_loop || ! keyboard ) + if ( quit_now || internal::var::exit_loop ) return; findKeyboardWidget(); + const auto& keyboard = FTerm::getFKeyboard(); keyboard->escapeKeyHandling(); // special case: Esc key keyboard->clearKeyBufferOnTimeout(); @@ -847,10 +847,12 @@ void FApplication::queuingKeyboardInput() const //---------------------------------------------------------------------- void FApplication::queuingMouseInput() const { - if ( quit_now || internal::var::exit_loop - || ! mouse || ! mouse->hasData() ) + const auto& mouse = FTerm::getFMouseControl(); + + if ( quit_now || internal::var::exit_loop || ! mouse->hasData() ) return; + const auto& keyboard = FTerm::getFKeyboard(); struct timeval* time_keypressed = keyboard->getKeyPressedTime(); mouse->processEvent (time_keypressed); keyboard->hasUnprocessedInput() = mouse->hasUnprocessedInput(); @@ -860,24 +862,27 @@ void FApplication::queuingMouseInput() const //---------------------------------------------------------------------- void FApplication::processKeyboardEvent() const { - if ( quit_now || internal::var::exit_loop || ! keyboard ) + if ( quit_now || internal::var::exit_loop ) return; + const auto& keyboard = FTerm::getFKeyboard(); keyboard->processQueuedInput(); } //---------------------------------------------------------------------- void FApplication::processMouseEvent() const { - if ( quit_now || internal::var::exit_loop || ! mouse ) + if ( quit_now || internal::var::exit_loop ) return; - mouse->processQueuedInput(); + FTerm::getFMouseControl()->processQueuedInput(); } //---------------------------------------------------------------------- bool FApplication::processDialogSwitchAccelerator() const { + const auto& keyboard = FTerm::getFKeyboard(); + if ( keyboard->getKey() >= fc::Fmkey_1 && keyboard->getKey() <= fc::Fmkey_9 ) { @@ -914,7 +919,7 @@ bool FApplication::processAccelerator (const FWidget& widget) const for (auto&& item : widget.getAcceleratorList()) { - if ( item.key == keyboard->getKey() ) + if ( item.key == FTerm::getFKeyboard()->getKey() ) { // unset the move/size mode auto move_size = getMoveSizeWidget(); @@ -1244,12 +1249,9 @@ void FApplication::processResizeEvent() const if ( ! FTerm::hasChangedTermSize() ) return; - if ( mouse ) - { - mouse->setMaxWidth (uInt16(getDesktopWidth())); - mouse->setMaxHeight (uInt16(getDesktopHeight())); - } - + const auto& mouse = FTerm::getFMouseControl(); + mouse->setMaxWidth (uInt16(getDesktopWidth())); + mouse->setMaxHeight (uInt16(getDesktopHeight())); FResizeEvent r_ev(fc::Resize_Event); sendEvent(internal::var::app_object, &r_ev); diff --git a/src/fbusyindicator.cpp b/src/fbusyindicator.cpp index 7ffec3c6..db26eaf7 100644 --- a/src/fbusyindicator.cpp +++ b/src/fbusyindicator.cpp @@ -39,8 +39,7 @@ FBusyIndicator::FBusyIndicator (FWidget* parent) } //---------------------------------------------------------------------- -FBusyIndicator::~FBusyIndicator() // destructor -{ } +FBusyIndicator::~FBusyIndicator() noexcept = default; // destructor // public methods of FBusyIndicator diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 9bd22d62..41317b3b 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -374,7 +374,7 @@ void FButtonGroup::drawLabel() else FWidget::setPrintPos (FPoint{0, 1}); - drawText (std::move(label_text), hotkeypos); + drawText (label_text, hotkeypos); setViewportPrint(); } @@ -397,7 +397,7 @@ void FButtonGroup::init() } //---------------------------------------------------------------------- -void FButtonGroup::drawText ( FString&& label_text +void FButtonGroup::drawText ( const FString& label_text , std::size_t hotkeypos ) { const auto& wc = getColorTheme(); diff --git a/src/fcallback.cpp b/src/fcallback.cpp index adc1d367..1f413d69 100644 --- a/src/fcallback.cpp +++ b/src/fcallback.cpp @@ -29,16 +29,6 @@ namespace finalcut // class FCallback //---------------------------------------------------------------------- -// constructors and destructor -//---------------------------------------------------------------------- -FCallback::FCallback() -{ } - -//---------------------------------------------------------------------- -FCallback::~FCallback() // destructor -{ } - - // public methods of FCallback //---------------------------------------------------------------------- void FCallback::delCallback (const FString& cb_signal) diff --git a/src/fcolorpalette.cpp b/src/fcolorpalette.cpp index 9eb8329c..cee215fe 100644 --- a/src/fcolorpalette.cpp +++ b/src/fcolorpalette.cpp @@ -36,8 +36,7 @@ FColorPalette::FColorPalette (const FSetPalette& f) { } //---------------------------------------------------------------------- -FColorPalette::~FColorPalette() // destructor -{ } +FColorPalette::~FColorPalette() noexcept = default; // destructor // protected methods of FColorPalette @@ -79,8 +78,8 @@ default8ColorPalette::default8ColorPalette (const FSetPalette& f) { } //---------------------------------------------------------------------- -default8ColorPalette::~default8ColorPalette() -{ } +default8ColorPalette::~default8ColorPalette() noexcept = default; // destructor + // public methods of default8ColorPalette //---------------------------------------------------------------------- @@ -123,8 +122,8 @@ default16ColorPalette::default16ColorPalette (const FSetPalette& f) { } //---------------------------------------------------------------------- -default16ColorPalette::~default16ColorPalette() -{ } +default16ColorPalette::~default16ColorPalette() noexcept = default; // destructor + // public methods of default16ColorPalette //---------------------------------------------------------------------- @@ -166,8 +165,8 @@ default16DarkColorPalette::default16DarkColorPalette (const FSetPalette& f) { } //---------------------------------------------------------------------- -default16DarkColorPalette::~default16DarkColorPalette() -{ } +default16DarkColorPalette::~default16DarkColorPalette() noexcept = default; // destructor + // public methods of default16DarkColorPalette //---------------------------------------------------------------------- diff --git a/src/fdata.cpp b/src/fdata.cpp index f39345d9..a3778949 100644 --- a/src/fdata.cpp +++ b/src/fdata.cpp @@ -31,12 +31,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- -FDataAccess::FDataAccess() -{ } - -//---------------------------------------------------------------------- -FDataAccess::~FDataAccess() // destructor -{ } +FDataAccess::~FDataAccess() noexcept = default; // destructor } // namespace finalcut diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 558ed411..de57a594 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -623,7 +623,7 @@ void FDialog::onMouseMove (FMouseEvent* ev) // Mouse event handover to the menu if ( ms.mouse_over_menu ) - passEventToSubMenu (ms, std::move(*ev)); + passEventToSubMenu (ms, *ev); leaveZoomButton(ms); // Check zoom button pressed resizeMouseUpMove(ms); // Resize the dialog @@ -1361,7 +1361,7 @@ inline bool FDialog::isMouseOverMenu (const FPoint& termpos) const //---------------------------------------------------------------------- inline void FDialog::passEventToSubMenu ( const MouseStates& ms - , const FMouseEvent&& ev ) + , const FMouseEvent& ev ) { // Mouse event handover to the dialog menu if ( ! ms.mouse_over_menu diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 0ea6e0de..6b7cf9e7 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -89,9 +89,6 @@ FString fileChooser ( FWidget* parent return ret; } -// static class attributes -FSystem* FFileDialog::fsystem{nullptr}; - //---------------------------------------------------------------------- // class FFileDialog @@ -202,7 +199,9 @@ void FFileDialog::setPath (const FString& dir) return; } - if ( fsystem && fsystem->realpath(dir.c_str(), resolved_path.data()) != nullptr ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->realpath(dir.c_str(), resolved_path.data()) != nullptr ) r_dir.setString(resolved_path.data()); else r_dir.setString(dir); @@ -324,9 +323,6 @@ void FFileDialog::init() int x{}; int y{}; - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - setGeometry(FPoint{1, 1}, FSize{w, h}, false); const auto& parent_widget = getParentWidget(); @@ -600,9 +596,7 @@ void FFileDialog::followSymLink (const char* const dir, FDirEntry& entry) const std::array symLink{}; struct stat sb{}; - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - + const auto& fsystem = FTerm::getFSystem(); std::strncpy (symLink.data(), dir, symLink.size() - 1); symLink[symLink.size() - 1] = '\0'; std::strncat ( symLink.data() @@ -666,9 +660,6 @@ int FFileDialog::changeDir (const FString& dirname) FString lastdir{directory}; FString newdir{dirname}; - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - if ( newdir.includes('~') ) newdir = newdir.replace('~', getHomeDir()); @@ -743,9 +734,7 @@ FString FFileDialog::getHomeDir() struct passwd* pwd_ptr{}; std::array buf{}; - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - + const auto& fsystem = FTerm::getFSystem(); const uid_t euid = fsystem->geteuid(); if ( fsystem->getpwuid_r(euid, &pwd, buf.data(), buf.size(), &pwd_ptr) ) diff --git a/src/fkeyboard.cpp b/src/fkeyboard.cpp index 5e8c0319..13a05b8c 100644 --- a/src/fkeyboard.cpp +++ b/src/fkeyboard.cpp @@ -23,9 +23,7 @@ #include #include -#if defined(__sun) && defined(__SVR4) - #include // need for FIONREAD -#elif defined(__CYGWIN__) +#if defined(__CYGWIN__) #include // need for FD_ZERO, FD_SET, FD_CLR, ... #endif @@ -55,10 +53,6 @@ uInt64 FKeyboard::read_blocking_time_short{5000}; // 5 ms (200 Hz) bool FKeyboard::non_blocking_input_support{true}; struct timeval FKeyboard::time_keypressed{}; -#if defined(__linux__) - FTermLinux* FKeyboard::linux{nullptr}; -#endif - //---------------------------------------------------------------------- // class FKeyboard @@ -77,8 +71,6 @@ FKeyboard::FKeyboard() if ( stdin_status_flags == -1 ) std::abort(); - - term_detection = FTerm::getFTermDetection(); } @@ -136,14 +128,6 @@ bool FKeyboard::setNonBlockingInput (bool enable) return non_blocking_stdin; } -//---------------------------------------------------------------------- -void FKeyboard::init() -{ -#if defined(__linux__) - linux = FTerm::getFTermLinux(); -#endif -} - //---------------------------------------------------------------------- bool& FKeyboard::hasUnprocessedInput() { @@ -465,13 +449,6 @@ FKey FKeyboard::UTF8decode (const char utf8[]) const //---------------------------------------------------------------------- inline ssize_t FKeyboard::readKey() { -#if !defined(__CYGWIN__) - int len{0}; - - if ( ioctl(FTermios::getStdIn(), FIONREAD, &len) < 0 || len == 0 ) - return 0; -#endif - setNonBlockingInput(); const ssize_t bytes = read(FTermios::getStdIn(), &read_character, 1); unsetNonBlockingInput(); @@ -562,8 +539,11 @@ FKey FKeyboard::keyCorrection (const FKey& keycode) const FKey key_correction; #if defined(__linux__) - if ( linux && FTerm::isLinuxTerm() ) - key_correction = linux->modifierKeyCorrection(keycode); + if ( FTerm::isLinuxTerm() ) + { + const auto& linux_console = FTerm::getFTermLinux(); + key_correction = linux_console->modifierKeyCorrection(keycode); + } else key_correction = keycode; #else diff --git a/src/flog.cpp b/src/flog.cpp index c06e1d2c..37567fff 100644 --- a/src/flog.cpp +++ b/src/flog.cpp @@ -30,10 +30,6 @@ namespace finalcut //---------------------------------------------------------------------- // constructors and destructor -//---------------------------------------------------------------------- -FLog::FLog() -{ } - //---------------------------------------------------------------------- FLog::~FLog() // destructor { diff --git a/src/flogger.cpp b/src/flogger.cpp index 6f1bf2a7..216e0b7d 100644 --- a/src/flogger.cpp +++ b/src/flogger.cpp @@ -34,12 +34,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- -FLogger::FLogger() -{ } - -//---------------------------------------------------------------------- -FLogger::~FLogger() // destructor -{ } +FLogger::~FLogger() noexcept = default; // destructor // private methods of FLogger diff --git a/src/fmenu.cpp b/src/fmenu.cpp index d42b51ec..1bca8375 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -279,19 +279,19 @@ void FMenu::onMouseMove (FMouseEvent* ev) if ( ms.mouse_over_submenu ) { - passEventToSubMenu(std::move(*ev)); // Event handover to sub-menu + passEventToSubMenu(*ev); // Event handover to sub-menu return; } if ( ! ms.mouse_over_menu && ms.mouse_over_supermenu ) { - passEventToSuperMenu(std::move(*ev)); // Event handover to super-menu + passEventToSuperMenu(*ev); // Event handover to super-menu return; } if ( ms.mouse_over_menubar ) { - passEventToMenuBar(std::move(*ev)); // Event handover to the menu bar + passEventToMenuBar(*ev); // Event handover to the menu bar return; } @@ -908,7 +908,7 @@ void FMenu::mouseMoveOverBorder (MouseStates& ms) const } //---------------------------------------------------------------------- -void FMenu::passEventToSubMenu (const FMouseEvent&& ev) +void FMenu::passEventToSubMenu (const FMouseEvent& ev) { // Mouse event handover to sub-menu @@ -931,7 +931,7 @@ void FMenu::passEventToSubMenu (const FMouseEvent&& ev) } //---------------------------------------------------------------------- -void FMenu::passEventToSuperMenu (const FMouseEvent&& ev) +void FMenu::passEventToSuperMenu (const FMouseEvent& ev) { // Mouse event handover to super-menu @@ -955,7 +955,7 @@ void FMenu::passEventToSuperMenu (const FMouseEvent&& ev) } //---------------------------------------------------------------------- -void FMenu::passEventToMenuBar (const FMouseEvent&& ev) const +void FMenu::passEventToMenuBar (const FMouseEvent& ev) const { // Mouse event handover to the menu bar diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 843a6a11..50f899e1 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -209,7 +209,7 @@ void FMenuBar::onMouseMove (FMouseEvent* ev) // Handle menu entries if ( mouse_down ) - mouseMoveOverList(std::move(*ev)); + mouseMoveOverList(*ev); } //---------------------------------------------------------------------- @@ -868,7 +868,7 @@ void FMenuBar::mouseUpOverList (const FMouseEvent* ev) } //---------------------------------------------------------------------- -void FMenuBar::mouseMoveOverList (const FMouseEvent&& ev) +void FMenuBar::mouseMoveOverList (const FMouseEvent& ev) { auto list = getItemList(); diff --git a/src/fmouse.cpp b/src/fmouse.cpp index 6bd4bd6b..f4f13951 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -44,14 +44,10 @@ namespace finalcut // class FMouseData //---------------------------------------------------------------------- -// constructors and destructor +// constructor and destructor //---------------------------------------------------------------------- -FMouseData::FMouseData() -{ } +FMouseData::~FMouseData() noexcept = default; // destructor -//---------------------------------------------------------------------- -FMouseData::~FMouseData() -{ } // public methods of FMouseData //---------------------------------------------------------------------- @@ -182,10 +178,6 @@ FMouse::FMouse() clearButtonState(); } -//---------------------------------------------------------------------- -FMouse::~FMouse() // destructor -{ } - // public methods of FMouse //---------------------------------------------------------------------- @@ -1282,7 +1274,7 @@ void FMouseControl::setMaxHeight (uInt16 y_max) } //---------------------------------------------------------------------- -void FMouseControl::setDblclickInterval (const uInt64 timeout) +void FMouseControl::setDblclickInterval (const uInt64 timeout) const { for (auto&& m : mouse_protocol) if ( m.second ) @@ -1580,7 +1572,7 @@ void FMouseControl::processEvent (struct timeval* time) { mouse_object->processEvent(time); auto& md = static_cast(*mouse_object); - fmousedata_queue.emplace(new FMouseData(std::move(md))); + fmousedata_queue.emplace(make_unique(std::move(md))); } } diff --git a/src/fobject.cpp b/src/fobject.cpp index db0a8943..4fa43513 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -22,7 +22,6 @@ #include -#include "final/emptyfstring.h" #include "final/fevent.h" #include "final/fc.h" #include "final/fobject.h" @@ -32,7 +31,6 @@ namespace finalcut // static class attributes bool FObject::timer_modify_lock; -const FString* fc::emptyFString::empty_string{nullptr}; //---------------------------------------------------------------------- @@ -55,9 +53,6 @@ FObject::~FObject() // destructor { delOwnTimers(); // Delete all timers of this object - if ( ! has_parent && ! fc::emptyFString::isNull() ) - fc::emptyFString::clear(); - // Delete children objects if ( hasChildren() ) { @@ -425,7 +420,7 @@ void FObject::performTimerAction (FObject*, FEvent*) } //---------------------------------------------------------------------- -FObject::FTimerListPtr& FObject::globalTimerList() +auto FObject::globalTimerList() -> const FTimerListUniquePtr& { static const auto& timer_list = make_unique(); return timer_list; diff --git a/src/fstring.cpp b/src/fstring.cpp index 2b3234c3..112092c5 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -76,10 +76,10 @@ FString::FString (const FString& s) // copy constructor //---------------------------------------------------------------------- FString::FString (FString&& s) noexcept // move constructor - : string{std::move(s.string)} + : string{s.string} , length{s.length} , bufsize{s.bufsize} - , c_string{std::move(s.c_string)} + , c_string{s.c_string} { s.string = nullptr; s.length = 0; @@ -185,10 +185,10 @@ FString& FString::operator = (FString&& s) noexcept if ( c_string ) delete[](c_string); - string = std::move(s.string); + string = s.string; length = s.length; bufsize = s.bufsize; - c_string = std::move(s.c_string); + c_string = s.c_string; s.string = nullptr; s.length = 0; @@ -1456,6 +1456,9 @@ inline const wchar_t* FString::_to_wcstring (const char s[]) const auto state = std::mbstate_t(); auto size = std::mbsrtowcs(nullptr, &src, 0, &state) + 1; + if ( size == 0 ) // ...malformed UTF-8 string + return nullptr; + try { dest = new wchar_t[size]; diff --git a/src/fstringstream.cpp b/src/fstringstream.cpp index c019b5d1..a8a4159c 100644 --- a/src/fstringstream.cpp +++ b/src/fstringstream.cpp @@ -54,8 +54,8 @@ FStringStream::FStringStream (FStringStream&& sstream) noexcept } //---------------------------------------------------------------------- -FStringStream::~FStringStream() // destructor -{ } +FStringStream::~FStringStream() noexcept = default; + // public methods of FStringStream //---------------------------------------------------------------------- diff --git a/src/fterm.cpp b/src/fterm.cpp index e54eaf2f..8fe5e285 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -79,32 +79,6 @@ uInt var::object_counter{0}; } // namespace internal -// Static class attributes -FTermData* FTerm::data {nullptr}; -FSystem* FTerm::fsys {nullptr}; -FOptiMove* FTerm::opti_move {nullptr}; -FOptiAttr* FTerm::opti_attr {nullptr}; -FTermDetection* FTerm::term_detection{nullptr}; -FTermXTerminal* FTerm::xterm {nullptr}; -FKeyboard* FTerm::keyboard {nullptr}; -FMouseControl* FTerm::mouse {nullptr}; - -#if defined(UNIT_TEST) - FTermLinux* FTerm::linux {nullptr}; - FTermFreeBSD* FTerm::freebsd {nullptr}; - FTermOpenBSD* FTerm::openbsd {nullptr}; -#elif defined(__linux__) - FTermLinux* FTerm::linux {nullptr}; -#elif defined(__FreeBSD__) || defined(__DragonFly__) - FTermFreeBSD* FTerm::freebsd {nullptr}; -#elif defined(__NetBSD__) || defined(__OpenBSD__) - FTermOpenBSD* FTerm::openbsd {nullptr}; -#endif - -#if DEBUG - FTermDebugData* FTerm::debug_data {nullptr}; -#endif - //---------------------------------------------------------------------- // class FTerm @@ -114,9 +88,6 @@ FMouseControl* FTerm::mouse {nullptr}; //---------------------------------------------------------------------- FTerm::FTerm() { - if ( internal::var::object_counter == 0 ) - allocationValues(); // Allocation of global objects - internal::var::object_counter++; } @@ -129,10 +100,7 @@ FTerm::~FTerm() // destructor internal::var::object_counter--; if ( internal::var::object_counter == 0 ) - { printExitMessage(); - deallocationValues(); // Deallocation of global objects - } } @@ -140,9 +108,7 @@ FTerm::~FTerm() // destructor //---------------------------------------------------------------------- std::size_t FTerm::getLineNumber() { - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); const auto& term_geometry = data->getTermGeometry(); if ( term_geometry.getHeight() == 0 ) @@ -154,9 +120,7 @@ std::size_t FTerm::getLineNumber() //---------------------------------------------------------------------- std::size_t FTerm::getColumnNumber() { - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); const auto& term_geometry = data->getTermGeometry(); if ( term_geometry.getWidth() == 0 ) @@ -168,30 +132,35 @@ std::size_t FTerm::getColumnNumber() //---------------------------------------------------------------------- FString FTerm::getKeyName (FKey keynum) { + const auto& keyboard = FTerm::getFKeyboard(); return keyboard->getKeyName (keynum); } //---------------------------------------------------------------------- charSubstitution& FTerm::getCharSubstitutionMap() { + const auto& data = FTerm::getFTermData(); return data->getCharSubstitutionMap(); } //---------------------------------------------------------------------- int FTerm::getTTYFileDescriptor() { - return ( data ) ? data->getTTYFileDescriptor() : 0; + const auto& data = FTerm::getFTermData(); + return data->getTTYFileDescriptor(); } //---------------------------------------------------------------------- const char* FTerm::getTermType() { + const auto& data = FTerm::getFTermData(); return data->getTermType(); } //---------------------------------------------------------------------- const char* FTerm::getTermFileName() { + const auto& data = FTerm::getFTermData(); return data->getTermFileName(); } @@ -208,243 +177,101 @@ int FTerm::getMaxColor() } //---------------------------------------------------------------------- -FTerm::FColorPalettePtr& FTerm::getColorPaletteTheme() +auto FTerm::getColorPaletteTheme() -> std::shared_ptr& { - static auto color_theme = new FColorPalettePtr(); - return *color_theme; + static const auto& color_theme = make_unique>(); + return *color_theme.get(); } //---------------------------------------------------------------------- -FTermData* FTerm::getFTermData() +auto FTerm::getFTermData() -> const std::unique_ptr& { - if ( data == nullptr ) - { - try - { - data = new FTermData; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermData"); - std::abort(); - } - } - + static const auto& data = make_unique(); return data; } //---------------------------------------------------------------------- -FSystem* FTerm::getFSystem() +auto FTerm::getFSystem() -> std::unique_ptr& { - if ( fsys == nullptr ) - { - try - { - fsys = new FSystemImpl; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FSystemImpl"); - std::abort(); - } - } - - return fsys; + static const auto& fsys = make_unique>(make_unique()); + return *fsys.get(); } //---------------------------------------------------------------------- -FOptiMove* FTerm::getFOptiMove() +auto FTerm::getFOptiMove() -> const std::unique_ptr& { - if ( opti_move == nullptr ) - { - try - { - opti_move = new FOptiMove; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FOptiMove"); - std::abort(); - } - } - + static const auto& opti_move = make_unique(); return opti_move; } //---------------------------------------------------------------------- -FOptiAttr* FTerm::getFOptiAttr() +auto FTerm::getFOptiAttr() -> const std::unique_ptr& { - if ( opti_attr == nullptr ) - { - try - { - opti_attr = new FOptiAttr; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FOptiAttr"); - std::abort(); - } - } - + static const auto& opti_attr = make_unique(); return opti_attr; } //---------------------------------------------------------------------- -FTermDetection* FTerm::getFTermDetection() +auto FTerm::getFTermDetection() -> const std::unique_ptr& { - if ( term_detection == nullptr ) - { - try - { - term_detection = new FTermDetection; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermDetection"); - std::abort(); - } - } - + static const auto& term_detection = make_unique(); return term_detection; } //---------------------------------------------------------------------- -FTermXTerminal* FTerm::getFTermXTerminal() +auto FTerm::getFTermXTerminal() -> const std::unique_ptr& { - if ( xterm == nullptr ) - { - try - { - xterm = new FTermXTerminal; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermXTerminal"); - std::abort(); - } - } - + static const auto& xterm = make_unique(); return xterm; } //---------------------------------------------------------------------- -FKeyboard* FTerm::getFKeyboard() +auto FTerm::getFKeyboard() -> const std::unique_ptr& { - if ( keyboard == nullptr ) - { - try - { - keyboard = new FKeyboard; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FKeyboard"); - std::abort(); - } - } - + static const auto& keyboard = make_unique(); return keyboard; } //---------------------------------------------------------------------- -FMouseControl* FTerm::getFMouseControl() +auto FTerm::getFMouseControl() -> const std::unique_ptr& { - if ( mouse == nullptr ) - { - try - { - mouse = new FMouseControl; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FMouseControl"); - std::abort(); - } - } - + static const auto& mouse = make_unique(); return mouse; } -#if defined(__linux__) +#if defined(__linux__) || defined(UNIT_TEST) //---------------------------------------------------------------------- -FTermLinux* FTerm::getFTermLinux() +auto FTerm::getFTermLinux() -> const std::unique_ptr& { - if ( linux == nullptr ) - { - try - { - linux = new FTermLinux; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermLinux"); - std::abort(); - } - } - - return linux; + static const auto& linux_console = make_unique(); + return linux_console; } +#endif -#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) //---------------------------------------------------------------------- -FTermFreeBSD* FTerm::getFTermFreeBSD() +auto FTerm::getFTermFreeBSD() -> const std::unique_ptr& { - if ( freebsd == nullptr ) - { - try - { - freebsd = new FTermFreeBSD; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermFreeBSD"); - std::abort(); - } - } - - return freebsd; + static const auto& freebsd_console = make_unique(); + return freebsd_console; } +#endif -#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) //---------------------------------------------------------------------- -FTermOpenBSD* FTerm::getFTermOpenBSD() +auto FTerm::getFTermOpenBSD() -> const std::unique_ptr& { - if ( openbsd == nullptr ) - { - try - { - openbsd = new FTermOpenBSD; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermOpenBSD"); - std::abort(); - } - } - - return openbsd; + static const auto& openbsd_console = make_unique(); + return openbsd_console; } #endif #if DEBUG //---------------------------------------------------------------------- -FTermDebugData& FTerm::getFTermDebugData() +auto FTerm::getFTermDebugData() -> const std::unique_ptr& { - if ( debug_data == nullptr ) - { - try - { - debug_data = new FTermDebugData; - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FTermDebugData"); - std::abort(); - } - } - - return *debug_data; + static const auto& debug_data = make_unique(); + return debug_data; } #endif // DEBUG @@ -457,138 +284,161 @@ bool FTerm::isNormal (const FChar& ch) //---------------------------------------------------------------------- bool FTerm::hasUTF8() { + const auto& data = FTerm::getFTermData(); return data->hasUTF8Console(); } //---------------------------------------------------------------------- bool FTerm::isMonochron() { + const auto& data = FTerm::getFTermData(); return data->isMonochron(); } //---------------------------------------------------------------------- bool FTerm::isAnsiTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isAnsiTerminal(); } //---------------------------------------------------------------------- bool FTerm::isXTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isXTerminal(); } //---------------------------------------------------------------------- bool FTerm::isRxvtTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isRxvtTerminal(); } //---------------------------------------------------------------------- bool FTerm::isUrxvtTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isUrxvtTerminal(); } //---------------------------------------------------------------------- bool FTerm::isKdeTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isKdeTerminal(); } //---------------------------------------------------------------------- bool FTerm::isGnomeTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isGnomeTerminal(); } //---------------------------------------------------------------------- bool FTerm::isPuttyTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isPuttyTerminal(); } //---------------------------------------------------------------------- bool FTerm::isWindowsTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isWindowsTerminal(); } //---------------------------------------------------------------------- bool FTerm::isTeraTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isTeraTerm(); } //---------------------------------------------------------------------- bool FTerm::isCygwinTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isCygwinTerminal(); } //---------------------------------------------------------------------- bool FTerm::isMinttyTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isMinttyTerm(); } //---------------------------------------------------------------------- bool FTerm::isLinuxTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isLinuxTerm(); } //---------------------------------------------------------------------- bool FTerm::isFreeBSDTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isFreeBSDTerm(); } //---------------------------------------------------------------------- bool FTerm::isNetBSDTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isNetBSDTerm(); } //---------------------------------------------------------------------- bool FTerm::isOpenBSDTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isOpenBSDTerm(); } //---------------------------------------------------------------------- bool FTerm::isSunTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isSunTerminal(); } //---------------------------------------------------------------------- bool FTerm::isScreenTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isScreenTerm(); } //---------------------------------------------------------------------- bool FTerm::isTmuxTerm() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isTmuxTerm(); } //---------------------------------------------------------------------- bool FTerm::isKtermTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isKtermTerminal(); } //---------------------------------------------------------------------- bool FTerm::isMltermTerminal() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->isMltermTerminal(); } //---------------------------------------------------------------------- bool FTerm::isNewFont() { + const auto& data = FTerm::getFTermData(); return data->isNewFont(); } @@ -612,24 +462,28 @@ bool FTerm::isCursorHideable() //---------------------------------------------------------------------- bool FTerm::hasChangedTermSize() { + const auto& data = FTerm::getFTermData(); return data->hasTermResized(); } //---------------------------------------------------------------------- bool FTerm::hasShadowCharacter() { + const auto& data = FTerm::getFTermData(); return data->hasShadowCharacter(); } //---------------------------------------------------------------------- bool FTerm::hasHalfBlockCharacter() { + const auto& data = FTerm::getFTermData(); return data->hasHalfBlockCharacter(); } //---------------------------------------------------------------------- bool FTerm::hasAlternateScreen() { + const auto& data = FTerm::getFTermData(); return data->hasAlternateScreen(); } @@ -652,6 +506,7 @@ bool FTerm::canChangeColorPalette() //---------------------------------------------------------------------- void FTerm::setTermType (const char term_name[]) { + const auto& data = FTerm::getFTermData(); data->setTermType(term_name); } @@ -676,6 +531,7 @@ void FTerm::redefineDefaultColors (bool enable) //---------------------------------------------------------------------- void FTerm::setDblclickInterval (const uInt64 timeout) { + const auto& mouse = FTerm::getFMouseControl(); mouse->setDblclickInterval(timeout); } @@ -690,6 +546,8 @@ void FTerm::useAlternateScreen (bool enable) //---------------------------------------------------------------------- bool FTerm::setUTF8 (bool enable) // UTF-8 (Unicode) { + const auto& data = FTerm::getFTermData(); + if ( data->isUTF8() == enable ) return enable; @@ -699,7 +557,7 @@ bool FTerm::setUTF8 (bool enable) // UTF-8 (Unicode) data->setUTF8(false); #if defined(__linux__) - linux->setUTF8 (enable); + FTerm::getFTermLinux()->setUTF8 (enable); #endif return data->isUTF8(); @@ -708,6 +566,8 @@ bool FTerm::setUTF8 (bool enable) // UTF-8 (Unicode) //---------------------------------------------------------------------- bool FTerm::setVGAFont() { + const auto& data = FTerm::getFTermData(); + if ( data->isVGAFont() ) return data->isVGAFont(); @@ -726,7 +586,8 @@ bool FTerm::setVGAFont() #if defined(__linux__) else if ( isLinuxTerm() ) { - data->setVGAFont(linux->loadVGAFont()); + const auto& linux_console = FTerm::getFTermLinux(); + data->setVGAFont(linux_console->loadVGAFont()); } #endif // defined(__linux__) else @@ -744,6 +605,8 @@ bool FTerm::setVGAFont() //---------------------------------------------------------------------- bool FTerm::setNewFont() { + const auto& data = FTerm::getFTermData(); + if ( isNewFont() ) return true; @@ -760,7 +623,8 @@ bool FTerm::setNewFont() #if defined(__linux__) else if ( isLinuxTerm() ) { - data->setNewFont(linux->loadNewFont()); + const auto& linux_console = FTerm::getFTermLinux(); + data->setNewFont(linux_console->loadNewFont()); } #endif // defined(__linux__) else @@ -779,6 +643,7 @@ bool FTerm::setNewFont() bool FTerm::resetFont() { bool retval{false}; + const auto& data = FTerm::getFTermData(); if ( ! (data->isNewFont() || data->isVGAFont()) ) return false; @@ -807,7 +672,8 @@ bool FTerm::resetFont() #if defined(__linux__) else if ( isLinuxTerm() ) { - retval = linux->loadOldFont(); + const auto& linux_console = FTerm::getFTermLinux(); + retval = linux_console->loadOldFont(); } #endif // defined(__linux__) @@ -823,9 +689,7 @@ bool FTerm::resetFont() //---------------------------------------------------------------------- int FTerm::openConsole() { - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); int fd = data->getTTYFileDescriptor(); const char* termfilename = data->getTermFileName(); @@ -842,11 +706,12 @@ int FTerm::openConsole() if ( fd >= 0 ) // console is already opened return 0; - if ( ! *termfilename || ! fsys ) + if ( ! *termfilename ) return 0; for (auto&& entry : terminal_devices) { + const auto& fsys = FTerm::getFSystem(); fd = fsys->open(entry, O_RDWR, 0); data->setTTYFileDescriptor(fd); @@ -860,20 +725,15 @@ int FTerm::openConsole() //---------------------------------------------------------------------- int FTerm::closeConsole() { - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); const int fd = data->getTTYFileDescriptor(); int ret{-1}; if ( fd < 0 ) // console is already closed return 0; - if ( ! fsys ) - getFSystem(); - + const auto& fsys = FTerm::getFSystem(); ret = fsys->close(fd); // close console - data->setTTYFileDescriptor(-1); if ( ret == 0 ) @@ -887,8 +747,13 @@ const char* FTerm::moveCursorString (int xold, int yold, int xnew, int ynew) { // Returns the cursor move string + const auto& data = FTerm::getFTermData(); + if ( data->hasCursorOptimisation() ) + { + const auto& opti_move = FTerm::getFOptiMove(); return opti_move->moveCursor (xold, yold, xnew, ynew); + } else return FTermcap::encodeMotionParameter(TCAP(fc::t_cursor_address), xnew, ynew); } @@ -899,6 +764,7 @@ const char* FTerm::cursorsVisibilityString (bool enable) // Hides or shows the input cursor on the terminal const char* visibility_str{nullptr}; + const auto& data = FTerm::getFTermData(); if ( data->isCursorHidden() == enable ) return nullptr; @@ -926,9 +792,7 @@ void FTerm::detectTermSize() { // Detect the terminal width and height - if ( ! data ) - data = FTerm::getFTermData(); - + const auto& data = FTerm::getFTermData(); struct winsize win_size{}; auto& term_geometry = data->getTermGeometry(); int ret{}; @@ -936,9 +800,7 @@ void FTerm::detectTermSize() do { - if ( ! fsys ) - getFSystem(); - + const auto& fsys = FTerm::getFSystem(); ret = fsys->ioctl (FTermios::getStdOut(), TIOCGWINSZ, &win_size); } while (errno == EINTR); @@ -958,9 +820,9 @@ void FTerm::detectTermSize() term_geometry.setRect(1, 1, win_size.ws_col, win_size.ws_row); } - if ( opti_move ) - opti_move->setTermSize ( term_geometry.getWidth() - , term_geometry.getHeight() ); + const auto& opti_move = FTerm::getFOptiMove(); + opti_move->setTermSize ( term_geometry.getWidth() + , term_geometry.getHeight() ); } //---------------------------------------------------------------------- @@ -997,7 +859,7 @@ void FTerm::setKDECursor (fc::kdeKonsoleCursorShape style) void FTerm::saveColorMap() { #if defined(__linux__) - linux->saveColorMap(); + FTerm::getFTermLinux()->saveColorMap(); #endif } @@ -1012,7 +874,7 @@ void FTerm::resetColorMap() #if defined(__linux__) else - linux->resetColorMap(); + FTerm::getFTermLinux()->resetColorMap(); #endif if ( op ) @@ -1054,7 +916,7 @@ void FTerm::setPalette (FColor index, int r, int g, int b) #if defined(__linux__) else { - state = linux->setPalette(index, r, g, b); + state = FTerm::getFTermLinux()->setPalette(index, r, g, b); } #endif @@ -1063,27 +925,23 @@ void FTerm::setPalette (FColor index, int r, int g, int b) } //---------------------------------------------------------------------- -#if defined(UNIT_TEST) +#if defined(__linux__) || defined(UNIT_TEST) void FTerm::setBeep (int Hz, int ms) { - linux->setBeep (Hz, ms); - freebsd->setBeep (Hz, ms); - openbsd->setBeep (Hz, ms); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->setBeep (Hz, ms); } -#elif defined(__linux__) +#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) void FTerm::setBeep (int Hz, int ms) { - linux->setBeep (Hz, ms); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->setBeep (Hz, ms); } -#elif defined(__FreeBSD__) || defined(__DragonFly__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) void FTerm::setBeep (int Hz, int ms) { - freebsd->setBeep (Hz, ms); -} -#elif defined(__NetBSD__) || defined(__OpenBSD__) -void FTerm::setBeep (int Hz, int ms) -{ - openbsd->setBeep (Hz, ms); + const auto& openbsd_console = FTerm::getFTermOpenBSD(); + openbsd_console->setBeep (Hz, ms); } #else void FTerm::setBeep (int, int) @@ -1093,16 +951,19 @@ void FTerm::setBeep (int, int) //---------------------------------------------------------------------- void FTerm::resetBeep() { -#if defined(UNIT_TEST) - linux->resetBeep(); - freebsd->resetBeep(); - openbsd->resetBeep(); -#elif defined(__linux__) - linux->resetBeep(); -#elif defined(__FreeBSD__) || defined(__DragonFly__) - freebsd->resetBeep(); -#elif defined(__NetBSD__) || defined(__OpenBSD__) - openbsd->resetBeep(); +#if defined(__linux__) || defined(UNIT_TEST) + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->resetBeep(); +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->resetBeep(); +#endif + +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) + const auto& openbsd_console = FTerm::getFTermOpenBSD(); + openbsd_console->resetBeep(); #endif } @@ -1119,6 +980,7 @@ void FTerm::beep() //---------------------------------------------------------------------- void FTerm::setEncoding (fc::encoding enc) { + const auto& data = FTerm::getFTermData(); data->setTermEncoding (enc); assert ( enc == fc::UTF8 @@ -1151,6 +1013,8 @@ void FTerm::setEncoding (fc::encoding enc) if ( isLinuxTerm() ) { + const auto& opti_move = FTerm::getFOptiMove(); + if ( enc == fc::VT100 || enc == fc::PC ) { const char* empty{nullptr}; @@ -1164,12 +1028,14 @@ void FTerm::setEncoding (fc::encoding enc) //---------------------------------------------------------------------- fc::encoding FTerm::getEncoding() { + const auto& data = FTerm::getFTermData(); return data->getTermEncoding(); } //---------------------------------------------------------------------- std::string FTerm::getEncodingString() { + const auto& data = FTerm::getFTermData(); const auto& term_encoding = data->getTermEncoding(); const auto& encoding_list = data->getEncodingList(); const auto& end = encoding_list.end(); @@ -1191,6 +1057,7 @@ bool FTerm::charEncodable (wchar_t c) //---------------------------------------------------------------------- wchar_t FTerm::charEncode (wchar_t c) { + const auto& data = FTerm::getFTermData(); return charEncode (c, data->getTermEncoding()); } @@ -1243,8 +1110,8 @@ bool FTerm::scrollTermReverse() //---------------------------------------------------------------------- FTerm::defaultPutChar& FTerm::putchar() { - static auto fputchar = new defaultPutChar(); - return *fputchar; + static const auto& fputchar = make_unique(&FTerm::putchar_ASCII); + return *fputchar.get(); } //---------------------------------------------------------------------- @@ -1256,8 +1123,7 @@ void FTerm::putstring (const char str[], int affcnt) //---------------------------------------------------------------------- int FTerm::putchar_ASCII (int c) { - if ( ! fsys ) - getFSystem(); + const auto& fsys = FTerm::getFSystem(); if ( fsys->putchar(char(c)) == EOF ) return 0; @@ -1268,8 +1134,7 @@ int FTerm::putchar_ASCII (int c) //---------------------------------------------------------------------- int FTerm::putchar_UTF8 (int c) { - if ( ! fsys ) - getFSystem(); + const auto& fsys = FTerm::getFSystem(); if ( c < 0x80 ) { @@ -1313,9 +1178,11 @@ void FTerm::initScreenSettings() #if defined(__linux__) // Important: Do not use setNewFont() or setVGAFont() after // the console character mapping has been initialized - linux->initCharMap(); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->initCharMap(); #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - freebsd->initCharMap(); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->initCharMap(); #endif // set xterm underline cursor @@ -1328,12 +1195,14 @@ void FTerm::initScreenSettings() //---------------------------------------------------------------------- const char* FTerm::changeAttribute (FChar& term_attr, FChar& next_attr) { + const auto& opti_attr = FTerm::getFOptiAttr(); return opti_attr->changeAttribute (term_attr, next_attr); } //---------------------------------------------------------------------- void FTerm::changeTermSizeFinished() { + const auto& data = FTerm::getFTermData(); data->setTermResized(false); } @@ -1350,18 +1219,16 @@ void FTerm::init_global_values() { // Initialize global values + const auto& data = FTerm::getFTermData(); + // Preset to false data->setNewFont(false); - // Initialize xterm object - getFTermXTerminal()->init(); - if ( ! getStartOptions().terminal_detection ) + { + const auto& term_detection = FTerm::getFTermDetection(); term_detection->setTerminalDetection (false); - -#if DEBUG - debug_data->init(); -#endif + } } //---------------------------------------------------------------------- @@ -1373,6 +1240,7 @@ void FTerm::init_terminal_device_path() if ( ttyname_r(stdout_no, termfilename.data(), termfilename.size()) ) termfilename[0] = '\0'; + const auto& data = FTerm::getFTermData(); data->setTermFileName(termfilename.data()); } @@ -1451,6 +1319,7 @@ void FTerm::init_alt_charset() void FTerm::init_pc_charset() { bool reinit{false}; + const auto& opti_attr = FTerm::getFOptiAttr(); // rxvt does not support pc charset if ( isRxvtTerminal() || isUrxvtTerminal() ) @@ -1458,6 +1327,8 @@ void FTerm::init_pc_charset() if ( isGnomeTerminal() || isLinuxTerm() ) { + const auto& data = FTerm::getFTermData(); + // Fallback if tcap "S2" is not found if ( ! TCAP(fc::t_enter_pc_charset_mode) ) { @@ -1531,6 +1402,7 @@ void FTerm::init_cygwin_charmap() } // General encoding changes + const auto& data = FTerm::getFTermData(); charSubstitution& sub_map = data->getCharSubstitutionMap(); sub_map[L'•'] = L'*'; sub_map[L'●'] = L'*'; @@ -1569,12 +1441,6 @@ void FTerm::init_teraterm_charmap() entry[fc::PC] = entry[fc::ASCII]; } -//---------------------------------------------------------------------- -void FTerm::init_keyboard() -{ - FKeyboard::init(); -} - //---------------------------------------------------------------------- void FTerm::init_termcap() { @@ -1623,6 +1489,7 @@ void FTerm::init_optiMove() FTermcap::eat_nl_glitch }; + const auto& opti_move = FTerm::getFOptiMove(); opti_move->setTermEnvironment(optimove_env); } @@ -1673,12 +1540,15 @@ void FTerm::init_optiAttr() FTermcap::ansi_default_color }; + const auto& opti_attr = FTerm::getFOptiAttr(); opti_attr->setTermEnvironment(optiattr_env); } //---------------------------------------------------------------------- bool FTerm::init_font() { + const auto& data = FTerm::getFTermData(); + if ( getStartOptions().vgafont && ! setVGAFont() ) { data->setExitMessage("VGAfont is not supported by this terminal"); @@ -1699,6 +1569,7 @@ void FTerm::init_locale() { // Init current locale + const auto& data = FTerm::getFTermData(); const char* termtype = data->getTermType(); const char* locale_name = std::setlocale (LC_ALL, ""); std::setlocale (LC_NUMERIC, ""); @@ -1777,6 +1648,7 @@ inline void FTerm::init_encoding_set() { // Define the encoding set + const auto& data = FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF8"] = fc::UTF8; encoding_list["UTF-8"] = fc::UTF8; @@ -1789,10 +1661,9 @@ inline void FTerm::init_encoding_set() void FTerm::init_term_encoding() { const int stdout_no = FTermios::getStdOut(); + const auto& data = FTerm::getFTermData(); const char* termtype = data->getTermType(); - - if ( ! fsys ) - getFSystem(); + const auto& fsys = FTerm::getFSystem(); if ( fsys->isTTY(stdout_no) && ! std::strcmp(nl_langinfo(CODESET), "UTF-8") ) @@ -1802,6 +1673,7 @@ void FTerm::init_term_encoding() putchar() = &FTerm::putchar_UTF8; // function pointer data->setUTF8(true); setUTF8(true); + const auto& keyboard = FTerm::getFKeyboard(); keyboard->enableUTF8(); } else if ( fsys->isTTY(stdout_no) @@ -1823,6 +1695,8 @@ void FTerm::init_term_encoding() //---------------------------------------------------------------------- void FTerm::init_individual_term_encoding() { + const auto& data = FTerm::getFTermData(); + if ( isNewFont() || (isPuttyTerminal() && ! data->isUTF8()) || (isTeraTerm() && ! data->isUTF8()) ) @@ -1840,6 +1714,7 @@ void FTerm::init_individual_term_encoding() //---------------------------------------------------------------------- void FTerm::init_force_vt100_encoding() { + const auto& data = FTerm::getFTermData(); data->setVT100Console(true); data->setTermEncoding (fc::VT100); putchar() = &FTerm::putchar_ASCII; // function pointer @@ -1851,6 +1726,8 @@ void FTerm::init_utf8_without_alt_charset() // Fall back to ascii for utf-8 terminals that // do not support VT100 line drawings + const auto& data = FTerm::getFTermData(); + if ( FTermcap::no_utf8_acs_chars && data->isUTF8() && data->getTermEncoding() == fc::VT100 ) { @@ -1867,11 +1744,13 @@ void FTerm::init_tab_quirks() // on the terminal and does not move the cursor to the next tab stop // position + const auto& data = FTerm::getFTermData(); const auto& enc = data->getTermEncoding(); if ( enc == fc::VT100 || enc == fc::PC ) { const char* empty{nullptr}; + const auto& opti_move = FTerm::getFOptiMove(); opti_move->set_tabular (empty); } } @@ -1887,6 +1766,7 @@ void FTerm::init_captureFontAndTitle() getFTermXTerminal()->captureFontAndTitle(); const auto& font = getFTermXTerminal()->getFont(); const auto& title = getFTermXTerminal()->getTitle(); + const auto& data = FTerm::getFTermData(); if ( ! font.isEmpty() ) data->setXtermFont(font); @@ -1979,9 +1859,11 @@ void FTerm::setInsertCursorStyle() setKDECursor(fc::UnderlineCursor); #if defined(__linux__) - linux->setCursorStyle (fc::underscore_cursor); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->setCursorStyle (fc::underscore_cursor); #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - freebsd->setCursorStyle (fc::destructive_cursor); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->setCursorStyle (fc::destructive_cursor); #endif if ( isUrxvtTerminal() ) @@ -1995,9 +1877,11 @@ void FTerm::setOverwriteCursorStyle() setKDECursor(fc::BlockCursor); #if defined(__linux__) - linux->setCursorStyle (fc::full_block_cursor); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->setCursorStyle (fc::full_block_cursor); #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - freebsd->setCursorStyle (fc::normal_cursor); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->setCursorStyle (fc::normal_cursor); #endif if ( isUrxvtTerminal() ) @@ -2023,7 +1907,8 @@ const char* FTerm::enableCursorString() if ( isLinuxTerm() ) { // Restore the last used Linux console cursor style - const char* cstyle = linux->getCursorStyleString(); + const auto& linux_console = FTerm::getFTermLinux(); + const char* cstyle = linux_console->getCursorStyleString(); std::size_t length = std::strlen(enable_str.data()); std::strncat (enable_str.data(), cstyle, SIZE - length - 1); } @@ -2035,7 +1920,8 @@ const char* FTerm::enableCursorString() if ( isFreeBSDTerm() ) { // Restore the last used FreeBSD console cursor style - freebsd->setCursorStyle (freebsd->getCursorStyle()); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->setCursorStyle (freebsd_console->getCursorStyle()); } #endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) @@ -2069,7 +1955,7 @@ void FTerm::enableMouse() #if defined(__linux__) if ( isLinuxTerm() && openConsole() == 0 ) { - if ( linux->isLinuxConsole() ) + if ( FTerm::getFTermLinux()->isLinuxConsole() ) gpm_mouse = true; closeConsole(); @@ -2079,7 +1965,9 @@ void FTerm::enableMouse() if ( TCAP(fc::t_key_mouse) && ! isLinuxTerm() ) xterm_mouse = true; + const auto& keyboard = FTerm::getFKeyboard(); keyboard->enableMouseSequences(); + const auto& mouse = FTerm::getFMouseControl(); mouse->setMaxWidth (uInt16(getColumnNumber())); mouse->setMaxHeight (uInt16(getLineNumber())); // Enable the linux general purpose mouse (gpm) server @@ -2094,8 +1982,8 @@ inline void FTerm::disableMouse() { // Disable the terminal mouse support - keyboard->disableMouseSequences(); - mouse->disable(); + FTerm::getFKeyboard()->disableMouseSequences(); + FTerm::getFMouseControl()->disable(); } //---------------------------------------------------------------------- @@ -2200,80 +2088,6 @@ void FTerm::useNormalScreenBuffer() } } -//---------------------------------------------------------------------- -inline void FTerm::allocationValues() const -{ - FStartOptions::getFStartOptions(); - getFTermData(); - getFSystem(); - getFOptiMove(); - getFOptiAttr(); - getFTermDetection(); - getFTermXTerminal(); - getFKeyboard(); - getFMouseControl(); - -#if defined(__linux__) - getFTermLinux(); -#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - getFTermFreeBSD(); -#elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - getFTermOpenBSD(); -#endif - -#if DEBUG - getFTermDebugData(); -#endif -} - -//---------------------------------------------------------------------- -inline void FTerm::deallocationValues() -{ -#if DEBUG - if ( debug_data ) - delete debug_data; -#endif - -#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - if ( openbsd ) - delete openbsd; -#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - if ( freebsd ) - delete freebsd; -#elif defined(__linux__) - if ( linux ) - delete linux; -#endif - - if ( mouse ) - delete mouse; - - if ( keyboard ) - delete keyboard; - - if ( xterm ) - delete xterm; - - if ( term_detection ) - delete term_detection; - - if ( opti_attr ) - delete opti_attr; - - if ( opti_move ) - delete opti_move; - - if ( fsys ) - delete fsys; - - if ( data ) - delete data; - - const defaultPutChar* putchar_ptr = &(putchar()); - delete putchar_ptr; - destroyColorPaletteTheme(); -} - //---------------------------------------------------------------------- void FTerm::init() { @@ -2305,6 +2119,7 @@ void FTerm::init() init_alt_charset(); // Pass the terminal capabilities to the keyboard object + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setTermcapMap (fc::fkey); // Initializes locale information @@ -2313,9 +2128,6 @@ void FTerm::init() // Detect environment and set encoding init_encoding(); - // Initializes keyboard settings - init_keyboard(); - // Enable the terminal mouse support enableMouse(); @@ -2351,7 +2163,9 @@ void FTerm::init() setSignalHandler(); if ( ! getStartOptions().cursor_optimisation ) - data->supportCursorOptimisation(false); + { + FTerm::getFTermData()->supportCursorOptimisation(false); + } // Activate the VGA or the new graphic font // (depending on the initialization values) @@ -2373,6 +2187,8 @@ bool FTerm::init_terminal() const { // Initialize termios FTermios::init(); + const auto& data = FTerm::getFTermData(); + const auto& fsys = FTerm::getFSystem(); // Check if stdin is a tty if ( ! fsys->isTTY(FTermios::getStdIn()) ) @@ -2406,6 +2222,7 @@ bool FTerm::init_terminal() const // Terminal detection FTermDetection::detect(); + const auto& term_detection = FTerm::getFTermDetection(); setTermType (term_detection->getTermType()); return true; } @@ -2414,33 +2231,39 @@ bool FTerm::init_terminal() const void FTerm::initOSspecifics() const { #if defined(__linux__) - linux->init(); // Initialize Linux console + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->init(); // Initialize Linux console #if DEBUG - data->setFramebufferBpp (linux->getFramebufferBpp()); + const auto& data = FTerm::getFTermData(); + data->setFramebufferBpp (linux_console->getFramebufferBpp()); #endif #endif // defined(__linux__) #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + if ( getStartOptions().meta_sends_escape ) - freebsd->enableMetaSendsEscape(); + freebsd_console->enableMetaSendsEscape(); else - freebsd->disableMetaSendsEscape(); + freebsd_console->disableMetaSendsEscape(); if ( getStartOptions().change_cursorstyle ) - freebsd->enableChangeCursorStyle(); + freebsd_console->enableChangeCursorStyle(); else - freebsd->disableChangeCursorStyle(); + freebsd_console->disableChangeCursorStyle(); - freebsd->init(); // Initialize BSD console + freebsd_console->init(); // Initialize BSD console #elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - if ( getStartOptions().meta_sends_escape ) - openbsd->enableMetaSendsEscape(); - else - openbsd->disableMetaSendsEscape(); + const auto& openbsd_console = FTerm::getFTermOpenBSD(); - openbsd->init(); // Initialize wscons console + if ( getStartOptions().meta_sends_escape ) + openbsd_console->enableMetaSendsEscape(); + else + openbsd_console->disableMetaSendsEscape(); + + openbsd_console->init(); // Initialize wscons console #endif } @@ -2462,13 +2285,14 @@ void FTerm::initBaudRate() const { const int stdout_no = FTermios::getStdOut(); const uInt baud = FTermios::getBaudRate(); - data->setBaudrate(baud); - - if ( ! fsys ) - getFSystem(); + FTerm::getFTermData()->setBaudrate(baud); + const auto& fsys = FTerm::getFSystem(); if ( fsys->isTTY(stdout_no) ) + { + const auto& opti_move = FTerm::getFOptiMove(); opti_move->setBaudRate(int(baud)); + } } //---------------------------------------------------------------------- @@ -2531,6 +2355,7 @@ void FTerm::finish() const disableKeypad(); finish_encoding(); + const auto& data = FTerm::getFTermData(); if ( data->isNewFont() || data->isVGAFont() ) resetFont(); @@ -2540,11 +2365,13 @@ void FTerm::finish() const void FTerm::finishOSspecifics() const { #if defined(__linux__) - linux->finish(); + const auto& linux_console = FTerm::getFTermLinux(); + linux_console->finish(); #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - freebsd->finish(); + const auto& freebsd_console = FTerm::getFTermFreeBSD(); + freebsd_console->finish(); #elif defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - openbsd->finish(); + openbsd_console->finish(); #endif } @@ -2552,22 +2379,16 @@ void FTerm::finishOSspecifics() const void FTerm::finish_encoding() const { #if defined(__linux__) - if ( isLinuxTerm() && data->hasUTF8Console() ) + if ( isLinuxTerm() && FTerm::getFTermData()->hasUTF8Console() ) setUTF8(true); #endif } -//---------------------------------------------------------------------- -void FTerm::destroyColorPaletteTheme() -{ - const FColorPalettePtr* theme = &(getColorPaletteTheme()); - delete theme; -} - //---------------------------------------------------------------------- void FTerm::printExitMessage() { // Print exit message + const auto& data = FTerm::getFTermData(); const auto& exit_message = data->getExitMessage(); if ( ! exit_message.isEmpty() ) @@ -2577,8 +2398,7 @@ void FTerm::printExitMessage() //---------------------------------------------------------------------- void FTerm::terminalSizeChange() { - if ( ! data ) - return; + const auto& data = FTerm::getFTermData(); if ( data->hasTermResized() ) return; @@ -2595,19 +2415,12 @@ void FTerm::processTermination (int signum) std::fflush (stderr); std::fflush (stdout); - - if ( data ) - { - FStringStream msg{}; - msg << "Program stopped: signal " << signum - << " (" << strsignal(signum) << ")"; - data->setExitMessage(msg.str()); - printExitMessage(); - } - - if ( internal::var::init_term_object ) - internal::var::init_term_object->deallocationValues(); - + const auto& data = FTerm::getFTermData(); + FStringStream msg{}; + msg << "Program stopped: signal " << signum + << " (" << strsignal(signum) << ")"; + data->setExitMessage(msg.str()); + printExitMessage(); std::terminate(); } diff --git a/src/ftermbuffer.cpp b/src/ftermbuffer.cpp index f6cb0c3c..27df36c0 100644 --- a/src/ftermbuffer.cpp +++ b/src/ftermbuffer.cpp @@ -66,13 +66,12 @@ int FTermBuffer::write (const FString& string) for (auto&& c : string) { - FChar nc; // next character - nc = FVTerm::getAttribute(); + FChar nc{FVTerm::getAttribute()}; // next character nc.ch[0] = c; nc.attr.byte[2] = 0; nc.attr.byte[3] = 0; getColumnWidth(nc); // add column width - data.emplace_back(std::move(nc)); + data.emplace_back(nc); } return len; @@ -81,12 +80,12 @@ int FTermBuffer::write (const FString& string) //---------------------------------------------------------------------- int FTermBuffer::write (wchar_t ch) { - FChar nc = FVTerm::getAttribute(); // next character + FChar nc{FVTerm::getAttribute()}; // next character nc.ch[0] = ch; getColumnWidth(nc); // add column width nc.attr.bit.no_changes = false; nc.attr.bit.printed = false; - data.emplace_back(std::move(nc)); + data.emplace_back(nc); return 1; } diff --git a/src/ftermcap.cpp b/src/ftermcap.cpp index ae2f712e..863a354f 100644 --- a/src/ftermcap.cpp +++ b/src/ftermcap.cpp @@ -38,6 +38,7 @@ namespace finalcut { // static class attributes +bool FTermcap::initialized {false}; bool FTermcap::background_color_erase {false}; bool FTermcap::can_change_color_palette {false}; bool FTermcap::automatic_left_margin {false}; @@ -50,9 +51,6 @@ bool FTermcap::no_utf8_acs_chars {false}; int FTermcap::max_color {1}; int FTermcap::tabstop {8}; int FTermcap::attr_without_color {0}; -FSystem* FTermcap::fsystem {nullptr}; -FTermData* FTermcap::fterm_data {nullptr}; -FTermDetection* FTermcap::term_detection {nullptr}; char FTermcap::string_buf[2048] {}; //---------------------------------------------------------------------- @@ -72,9 +70,6 @@ char FTermcap::string_buf[2048] {}; //---------------------------------------------------------------------- void FTermcap::init() { - fsystem = FTerm::getFSystem(); - fterm_data = FTerm::getFTermData(); - term_detection = FTerm::getFTermDetection(); termcap(); } @@ -82,11 +77,13 @@ void FTermcap::init() //---------------------------------------------------------------------- void FTermcap::termcap() { + const auto& fterm_data = FTerm::getFTermData(); std::vector terminals{}; static constexpr int success = 1; static constexpr int uninitialized = -2; static char term_buffer[BUF_SIZE]{}; int status = uninitialized; + const auto& term_detection = FTerm::getFTermDetection(); const bool color256 = term_detection->canDisplay256Colors(); // Open termcap file @@ -112,6 +109,9 @@ void FTermcap::termcap() // Open the termcap file + load entry for termtype status = tgetent(term_buffer, termtype); + if ( status == success ) + initialized = true; + if ( status == success || ! term_detection->hasTerminalDetection() ) break; @@ -131,6 +131,7 @@ void FTermcap::termcapError (int status) if ( status == no_entry || status == uninitialized ) { + const auto& fterm_data = FTerm::getFTermData(); const char* termtype = fterm_data->getTermType(); std::clog << FLog::Error << "Unknown terminal: \"" << termtype << "\". " @@ -200,6 +201,8 @@ void FTermcap::termcapNumerics() { // Get termcap numerics + const auto& fterm_data = FTerm::getFTermData(); + // Maximum number of colors on screen max_color = std::max(max_color, getNumber("Co")); @@ -252,9 +255,7 @@ void FTermcap::termcapKeys() //---------------------------------------------------------------------- int FTermcap::_tputs (const char* str, int affcnt, fn_putc putc) { - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - + const auto& fsystem = FTerm::getFSystem(); return fsystem->tputs (str, affcnt, putc); } diff --git a/src/ftermcapquirks.cpp b/src/ftermcapquirks.cpp index 30c49b2f..b240ea56 100644 --- a/src/ftermcapquirks.cpp +++ b/src/ftermcapquirks.cpp @@ -34,11 +34,6 @@ namespace finalcut { -// static class attributes -FTermData* FTermcapQuirks::fterm_data {nullptr}; -FTermDetection* FTermcapQuirks::term_detection {nullptr}; - - //---------------------------------------------------------------------- // class FTermcapQuirks //---------------------------------------------------------------------- @@ -47,9 +42,7 @@ FTermDetection* FTermcapQuirks::term_detection {nullptr}; //---------------------------------------------------------------------- void FTermcapQuirks::terminalFixup() { - fterm_data = FTerm::getFTermData(); - term_detection = FTerm::getFTermDetection(); - const auto& td = term_detection; + const auto& td = FTerm::getFTermDetection(); if ( td->isCygwinTerminal() ) { @@ -231,7 +224,9 @@ void FTermcapQuirks::xterm() void FTermcapQuirks::rxvt() { // Set enter/exit alternative charset mode for rxvt terminal + const auto& fterm_data = FTerm::getFTermData(); const char* termtype = fterm_data->getTermType(); + const auto& term_detection = FTerm::getFTermDetection(); if ( std::strncmp(termtype, "rxvt-16color", 12) == 0 ) { @@ -252,12 +247,13 @@ void FTermcapQuirks::rxvt() //---------------------------------------------------------------------- void FTermcapQuirks::vte() { + const auto& term_detection = FTerm::getFTermDetection(); + // gnome-terminal has NC=16 however, it can use the dim attribute FTermcap::attr_without_color = 0; // set exit underline for gnome terminal - TCAP(fc::t_exit_underline_mode) = \ - CSI "24m"; + TCAP(fc::t_exit_underline_mode) = CSI "24m"; if ( term_detection->getGnomeTerminalID() >= 5300 ) // vte >= 0.53.0 { @@ -266,8 +262,7 @@ void FTermcapQuirks::vte() { // Save the cursor position, enter alternate screen buffer // and save xterm icon and window title on stack - TCAP(fc::t_enter_ca_mode) = \ - CSI "?1049h" CSI "22;0;0t"; + TCAP(fc::t_enter_ca_mode) = CSI "?1049h" CSI "22;0;0t"; } if ( TCAP(fc::t_exit_ca_mode) @@ -275,8 +270,7 @@ void FTermcapQuirks::vte() { // Use normal screen buffer, restore the cursor position // and restore xterm icon and window title from stack - TCAP(fc::t_exit_ca_mode) = \ - CSI "?1049l" CSI "23;0;0t"; + TCAP(fc::t_exit_ca_mode) = CSI "?1049l" CSI "23;0;0t"; } } } @@ -457,6 +451,8 @@ void FTermcapQuirks::sunConsole() //---------------------------------------------------------------------- void FTermcapQuirks::screen() { + const auto& term_detection = FTerm::getFTermDetection(); + // Fallback if "Ic" is not found if ( ! TCAP(fc::t_initialize_color) ) { diff --git a/src/ftermdebugdata.cpp b/src/ftermdebugdata.cpp index 8ea81d19..b1c468cc 100644 --- a/src/ftermdebugdata.cpp +++ b/src/ftermdebugdata.cpp @@ -30,49 +30,44 @@ namespace finalcut { #if DEBUG -// static class attributes -FTermData* FTermDebugData::data {nullptr}; -FTermDetection* FTermDebugData::term_detection {nullptr}; //---------------------------------------------------------------------- // class FTermDebugData //---------------------------------------------------------------------- // public methods of FTermDebugData -//---------------------------------------------------------------------- -void FTermDebugData::init() -{ - data = FTerm::getFTermData(); - term_detection = FTerm::getFTermDetection(); -} - //---------------------------------------------------------------------- const FString& FTermDebugData::getAnswerbackString() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getAnswerbackString(); } //---------------------------------------------------------------------- const FString& FTermDebugData::getSecDAString() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getSecDAString(); } //---------------------------------------------------------------------- const char* FTermDebugData::getTermType_256color() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getTermType_256color(); } //---------------------------------------------------------------------- const char* FTermDebugData::getTermType_Answerback() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getTermType_Answerback(); } //---------------------------------------------------------------------- const char* FTermDebugData::getTermType_SecDA() { + const auto& term_detection = FTerm::getFTermDetection(); return term_detection->getTermType_SecDA(); } @@ -80,7 +75,8 @@ const char* FTermDebugData::getTermType_SecDA() #if defined(__linux__) int FTermDebugData::getFramebufferBpp() { - return data->getFramebufferBpp(); + const auto& fterm_data = FTerm::getFTermData(); + return fterm_data->getFramebufferBpp(); } #endif // defined(__linux__) diff --git a/src/ftermdetection.cpp b/src/ftermdetection.cpp index 7044e19b..f153f11f 100644 --- a/src/ftermdetection.cpp +++ b/src/ftermdetection.cpp @@ -54,9 +54,6 @@ namespace finalcut FTermDetection::FTerminalType FTermDetection::terminal_type{}; FTermDetection::colorEnv FTermDetection::color_env{}; FTermDetection::secondaryDA FTermDetection::secondary_da{}; -FTermData* FTermDetection::fterm_data{nullptr}; -FSystem* FTermDetection::fsystem{nullptr}; -FKeyboard* FTermDetection::keyboard{nullptr}; char FTermDetection::termtype[256]{}; char FTermDetection::ttytypename[256]{}; bool FTermDetection::decscusr_support{}; @@ -133,9 +130,6 @@ void FTermDetection::setTtyTypeFileName (const char ttytype_filename[]) //---------------------------------------------------------------------- void FTermDetection::detect() { - fterm_data = FTerm::getFTermData(); - fsystem = FTerm::getFSystem(); - keyboard = FTerm::getFKeyboard(); deallocation(); // Set the variable 'termtype' to the predefined type of the terminal @@ -165,6 +159,7 @@ void FTermDetection::getSystemTermType() { // Import the untrusted environment variable TERM const auto& term_env = std::getenv("TERM"); + const auto& fterm_data = FTerm::getFTermData(); const auto& termfilename = fterm_data->getTermFileName(); if ( term_env ) @@ -203,6 +198,7 @@ bool FTermDetection::getTTYtype() // vt100 ttys0 // Get term basename + const auto& fterm_data = FTerm::getFTermData(); const char* termfilename = fterm_data->getTermFileName(); const char* term_basename = std::strrchr(termfilename, '/'); @@ -213,9 +209,7 @@ bool FTermDetection::getTTYtype() std::FILE* fp{}; std::array str{}; - - if ( ! fsystem ) - return false; + const auto& fsystem = FTerm::getFSystem(); if ( (fp = fsystem->fopen(ttytypename, "r")) == nullptr ) return false; @@ -260,6 +254,7 @@ bool FTermDetection::getTTYSFileEntry() // Analyse /etc/ttys and get the term name // get term basename + const auto& fterm_data = FTerm::getFTermData(); const char* termfilename = fterm_data->getTermFileName(); const char* term_basename = std::strrchr(termfilename, '/'); @@ -364,6 +359,7 @@ void FTermDetection::detectTerminal() if ( terminal_detection ) { FTermios::setCaptureSendCharacters(); + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setNonBlockingInput(); // Initialize 256 colors terminals @@ -408,6 +404,7 @@ void FTermDetection::detectTerminal() } #if defined(__CYGWIN__) + const auto& fterm_data = FTerm::getFTermData(); const auto& termfilename = fterm_data->getTermFileName(); // Fixes problem with mouse input @@ -541,6 +538,7 @@ const char* FTermDetection::determineMaxColor (const char current_termtype[]) // Determine xterm maximum number of colors via OSC 4 const char* new_termtype = current_termtype; + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setNonBlockingInput(); if ( ! color256 @@ -632,6 +630,7 @@ FString FTermDetection::getXTermColorName (FColor color) const char* FTermDetection::parseAnswerbackMsg (const char current_termtype[]) { const char* new_termtype = current_termtype; + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setNonBlockingInput(); // send ENQ and read the answerback message const auto& ans = getAnswerbackMsg(); diff --git a/src/ftermfreebsd.cpp b/src/ftermfreebsd.cpp index ee6a08cc..595cc62c 100644 --- a/src/ftermfreebsd.cpp +++ b/src/ftermfreebsd.cpp @@ -30,28 +30,15 @@ #include "final/ftypes.h" #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) -#define initCheck(ret_value) \ - if ( ! isInitialized() ) \ - { \ - if ( ! FApplication::isQuit() ) \ - warnNotInitialized(); \ - \ - return ret_value; \ - } -#endif namespace finalcut { // static class attributes -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) - uInt FTermFreeBSD::bsd_alt_keymap{0}; - FTermFreeBSD::CursorStyle FTermFreeBSD::cursor_style{fc::normal_cursor}; - bool FTermFreeBSD::change_cursorstyle{true}; - bool FTermFreeBSD::meta_sends_escape{true}; - FSystem* FTermFreeBSD::fsystem{nullptr}; - FTermData* FTermFreeBSD::fterm_data{nullptr}; -#endif +uInt FTermFreeBSD::bsd_alt_keymap{0}; +FTermFreeBSD::CursorStyle FTermFreeBSD::cursor_style{fc::normal_cursor}; +bool FTermFreeBSD::change_cursorstyle{true}; +bool FTermFreeBSD::meta_sends_escape{true}; //---------------------------------------------------------------------- @@ -60,7 +47,6 @@ namespace finalcut // public methods of FTermFreeBSD //---------------------------------------------------------------------- -#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) FTermFreeBSD::CursorStyle FTermFreeBSD::getCursorStyle() { return cursor_style; @@ -71,15 +57,11 @@ bool FTermFreeBSD::setCursorStyle (CursorStyle style) { // Set cursor style in a BSD console - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - - initCheck(false); - - if ( ! fsystem || ! isFreeBSDConsole() || ! change_cursorstyle ) + if ( ! isFreeBSDConsole() || ! change_cursorstyle ) return false; cursor_style = style; + const auto& fterm_data = FTerm::getFTermData(); if ( fterm_data->isCursorHidden() ) return false; @@ -93,11 +75,9 @@ bool FTermFreeBSD::isFreeBSDConsole() // Check if it's a FreeBSD console keymap_t keymap{}; + const auto& fsystem = FTerm::getFSystem(); - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - - if ( fsystem && fsystem->ioctl(0, GIO_KEYMAP, &keymap) == 0 ) + if ( fsystem->ioctl(0, GIO_KEYMAP, &keymap) == 0 ) return true; else return false; @@ -141,9 +121,6 @@ void FTermFreeBSD::init() { // Initialize BSD console - fsystem = FTerm::getFSystem(); - fterm_data = FTerm::getFTermData(); - if ( ! isFreeBSDConsole() ) return; @@ -210,7 +187,7 @@ bool FTermFreeBSD::saveFreeBSDAltKey() static constexpr int left_alt = 0x38; int ret{-1}; keymap_t keymap{}; - initCheck(false); + const auto& fsystem = FTerm::getFSystem(); ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); if ( ret < 0 ) @@ -229,7 +206,7 @@ bool FTermFreeBSD::setFreeBSDAltKey (uInt key) static constexpr int left_alt = 0x38; int ret{-1}; keymap_t keymap{}; - initCheck(false); + const auto& fsystem = FTerm::getFSystem(); ret = fsystem->ioctl (0, GIO_KEYMAP, &keymap); if ( ret < 0 ) @@ -239,7 +216,7 @@ bool FTermFreeBSD::setFreeBSDAltKey (uInt key) keymap.key[left_alt].map[0] = int(key); if ( (keymap.n_keys > 0) - && fsystem && (fsystem->ioctl(0, PIO_KEYMAP, &keymap) < 0) ) + && (fsystem->ioctl(0, PIO_KEYMAP, &keymap) < 0) ) return false; else return true; @@ -264,13 +241,14 @@ bool FTermFreeBSD::resetFreeBSDAlt2Meta() //---------------------------------------------------------------------- bool FTermFreeBSD::setFreeBSDCursorStyle (CursorStyle style) { - initCheck(false); + const auto& fsystem = FTerm::getFSystem(); if ( fsystem->ioctl(0, CONS_CURSORTYPE, &style) == 0 ) return true; else return false; } -#endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) } // namespace finalcut + +#endif // defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index 8667260d..27fbd1e1 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -35,11 +35,12 @@ #include "final/ftypes.h" #if defined(__linux__) - #include // need keyboard modifiers - #include "../fonts/newfont.h" - #include "../fonts/unicodemap.h" - #include "../fonts/vgafont.h" -#endif + +#include // need keyboard modifiers +#include "../fonts/newfont.h" +#include "../fonts/unicodemap.h" +#include "../fonts/vgafont.h" + namespace finalcut { @@ -52,18 +53,15 @@ namespace finalcut //---------------------------------------------------------------------- FTermLinux::~FTermLinux() // destructor { -#if defined(__linux__) if ( screen_font.data ) delete[] screen_font.data; if ( screen_unicode_map.entries ) delete[] screen_unicode_map.entries; -#endif // defined(__linux__) } // public methods of FTermLinux //---------------------------------------------------------------------- -#if defined(__linux__) fc::linuxConsoleCursorStyle FTermLinux::getCursorStyle() const { // Get the current set cursor style @@ -87,8 +85,7 @@ bool FTermLinux::setCursorStyle (fc::linuxConsoleCursorStyle style) { // Set cursor style in linux console - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); + const auto& fterm_data = FTerm::getFTermData(); if ( ! FTerm::isLinuxTerm() ) return false; @@ -137,11 +134,9 @@ bool FTermLinux::isLinuxConsole() { // Check if it's a Linux console - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - char arg{0}; const int fd_tty = FTerm::getTTYFileDescriptor(); + const auto& fsystem = FTerm::getFSystem(); // Get keyboard type an compare return ( fsystem->isTTY(fd_tty) @@ -154,14 +149,8 @@ void FTermLinux::init() { // Initialize Linux console - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - - fsystem = FTerm::getFSystem(); - term_detection = FTerm::getFTermDetection(); + const auto& fterm_data = FTerm::getFTermData(); + const auto& term_detection = FTerm::getFTermDetection(); screen_unicode_map.entries = nullptr; screen_font.data = nullptr; fterm_data->supportShadowCharacter (true); @@ -292,9 +281,7 @@ bool FTermLinux::loadVGAFont() if ( vga_font ) { - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - + const auto& fterm_data = FTerm::getFTermData(); fterm_data->supportShadowCharacter (true); fterm_data->supportHalfBlockCharacter (true); } @@ -342,9 +329,7 @@ bool FTermLinux::loadNewFont() if ( new_font ) { - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - + const auto& fterm_data = FTerm::getFTermData(); fterm_data->supportShadowCharacter (true); fterm_data->supportHalfBlockCharacter (true); } @@ -458,9 +443,6 @@ FKey FTermLinux::modifierKeyCorrection (const FKey& key_id) { // Get the current modifier key state - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - const ModifierKey& m = getModifierKey(); if ( ! (m.shift || m.ctrl || m.alt) ) @@ -508,9 +490,7 @@ int FTermLinux::getFramebuffer_bpp() const char* fb = "/dev/fb/0"; struct fb_var_screeninfo fb_var{}; struct fb_fix_screeninfo fb_fix{}; - - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); if ( (fd = fsystem->open(fb, O_RDWR)) < 0 ) { @@ -569,8 +549,8 @@ bool FTermLinux::getScreenFont() } // Font operation - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, KDFONTOP, &font); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (fd_tty, KDFONTOP, &font); if ( ret != 0 ) { @@ -600,8 +580,8 @@ bool FTermLinux::getUnicodeMap() screen_unicode_map.entries = nullptr; // Get count - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, GIO_UNIMAP, &screen_unicode_map); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (fd_tty, GIO_UNIMAP, &screen_unicode_map); if ( ret != 0 ) { @@ -621,8 +601,7 @@ bool FTermLinux::getUnicodeMap() } // Get unicode-to-font mapping from kernel - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, GIO_UNIMAP, &screen_unicode_map); + ret = fsystem->ioctl (fd_tty, GIO_UNIMAP, &screen_unicode_map); if ( ret != 0 ) return false; @@ -641,8 +620,10 @@ FTermLinux::ModifierKey& FTermLinux::getModifierKey() // Fill bit field with 0 std::memset (&mod_key, 0x00, sizeof(mod_key)); + const auto& fsystem = FTerm::getFSystem(); + // TIOCLINUX, subcode = 6 (TIOCL_GETSHIFTSTATE) - if ( fsystem && fsystem->ioctl(0, TIOCLINUX, &subcode) >= 0 ) + if ( fsystem->ioctl(0, TIOCLINUX, &subcode) >= 0 ) { if ( subcode & (1 << KG_SHIFT) ) mod_key.shift = true; @@ -705,8 +686,8 @@ int FTermLinux::setScreenFont ( const uChar fontdata[], uInt count } // Font operation - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, KDFONTOP, &font); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (fd_tty, KDFONTOP, &font); if ( ret != 0 && errno != ENOSYS && errno != EINVAL ) { @@ -742,15 +723,14 @@ int FTermLinux::setUnicodeMap (struct unimapdesc* unimap) do { // Clear the unicode-to-font table - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, PIO_UNIMAPCLR, &advice); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (fd_tty, PIO_UNIMAPCLR, &advice); if ( ret != 0 ) return -1; // Put the new unicode-to-font mapping in kernel - if ( fsystem ) - ret = fsystem->ioctl (fd_tty, PIO_UNIMAP, unimap); + ret = fsystem->ioctl (fd_tty, PIO_UNIMAP, unimap); if ( ret != 0 ) advice.advised_hashlevel++; @@ -775,8 +755,7 @@ inline uInt16 FTermLinux::getInputStatusRegisterOne() { // Gets the VGA input-status-register-1 - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); // Miscellaneous output (read port) static constexpr uInt16 misc_read = 0x3cc; @@ -792,8 +771,7 @@ uChar FTermLinux::readAttributeController (uChar index) { // Reads a byte from the attribute controller from a given index - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); // Attribute controller (write port) static constexpr uInt16 attrib_cntlr_write = 0x3c0; @@ -819,8 +797,7 @@ void FTermLinux::writeAttributeController (uChar index, uChar data) { // Writes a byte from the attribute controller from a given index - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); // Attribute controller (write port) static constexpr uInt16 attrib_cntlr_write = 0x3c0; @@ -859,8 +836,7 @@ int FTermLinux::setBlinkAsIntensity (bool enable) // Uses blink-bit as background intensity. // That permits 16 colors for background - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); + const auto& fsystem = FTerm::getFSystem(); const int fd_tty = FTerm::getTTYFileDescriptor(); @@ -899,9 +875,7 @@ bool FTermLinux::has9BitCharacters() // 0xc0...0xdf - copying the eighth pixel into the ninth pixel // The rest - the ninth pixel has the background color - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - + const auto& fsystem = FTerm::getFSystem(); const int fd_tty = FTerm::getTTYFileDescriptor(); if ( fsystem->getuid() != 0 ) // Direct hardware access requires root privileges @@ -926,7 +900,9 @@ bool FTermLinux::has9BitCharacters() //---------------------------------------------------------------------- void FTermLinux::getVGAPalette() { - if ( fsystem && fsystem->ioctl(0, GIO_CMAP, &cmap) != 0 ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->ioctl(0, GIO_CMAP, &cmap) != 0 ) setVGADefaultPalette(); // Fallback, if GIO_CMAP does not work } @@ -967,7 +943,9 @@ bool FTermLinux::setVGAPalette (FColor index, int r, int g, int b) cmap.color[index].blue = uChar(b); } - if ( fsystem && fsystem->ioctl(0, PIO_CMAP, &cmap) == 0 ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->ioctl(0, PIO_CMAP, &cmap) == 0 ) return true; else return false; @@ -978,7 +956,9 @@ bool FTermLinux::saveVGAPalette() { // Save the current vga color map - if ( fsystem && fsystem->ioctl(0, GIO_CMAP, &saved_color_map) == 0 ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->ioctl(0, GIO_CMAP, &saved_color_map) == 0 ) has_saved_palette = true; else has_saved_palette = false; @@ -991,16 +971,18 @@ bool FTermLinux::resetVGAPalette() { // Reset the vga color map + const auto& fsystem = FTerm::getFSystem(); + if ( has_saved_palette ) { - if ( fsystem && fsystem->ioctl (0, PIO_CMAP, &saved_color_map) ) + if ( fsystem->ioctl (0, PIO_CMAP, &saved_color_map) ) return false; } else { setVGADefaultPalette(); - if ( fsystem && fsystem->ioctl(0, PIO_CMAP, &cmap) != 0 ) + if ( fsystem->ioctl(0, PIO_CMAP, &cmap) != 0 ) return false; } @@ -1291,13 +1273,11 @@ FKey FTermLinux::shiftCtrlAltKeyCorrection (const FKey& key_id) const //---------------------------------------------------------------------- inline void FTermLinux::initSpecialCharacter() { + const auto& fterm_data = FTerm::getFTermData(); const wchar_t c1 = fc::UpperHalfBlock; 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) ) @@ -1334,10 +1314,7 @@ void FTermLinux::characterFallback ( wchar_t ucs , std::vector fallback ) { constexpr sInt16 NOT_FOUND = -1; - - if ( ! fterm_data ) - fterm_data = FTerm::getFTermData(); - + const auto& fterm_data = FTerm::getFTermData(); charSubstitution& sub_map = fterm_data->getCharSubstitutionMap(); if ( fallback.size() < 2 || ucs != fallback[0] ) @@ -1355,6 +1332,6 @@ void FTermLinux::characterFallback ( wchar_t ucs } } -#endif // defined(__linux__) - } // namespace finalcut + +#endif // defined(__linux__) diff --git a/src/ftermopenbsd.cpp b/src/ftermopenbsd.cpp index 0b2fda5d..d10ed9f6 100644 --- a/src/ftermopenbsd.cpp +++ b/src/ftermopenbsd.cpp @@ -27,25 +27,13 @@ #include "final/ftermopenbsd.h" #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) -#define initCheck(ret_value) \ - if ( ! isInitialized() ) \ - { \ - if ( ! FApplication::isQuit() ) \ - warnNotInitialized(); \ - \ - return ret_value; \ - } -#endif namespace finalcut { // static class attributes -#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) - kbd_t FTermOpenBSD::bsd_keyboard_encoding{0}; - bool FTermOpenBSD::meta_sends_escape{true}; - FSystem* FTermOpenBSD::fsystem{nullptr}; -#endif +kbd_t FTermOpenBSD::bsd_keyboard_encoding{0}; +bool FTermOpenBSD::meta_sends_escape{true}; //---------------------------------------------------------------------- @@ -54,18 +42,14 @@ namespace finalcut // public methods of FTermOpenBSD //---------------------------------------------------------------------- -#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) bool FTermOpenBSD::isBSDConsole() { // Check if it's a NetBSD/OpenBSD workstation console static kbd_t kbdencoding{}; + const auto& fsystem = FTerm::getFSystem(); - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - - if ( fsystem - && fsystem->ioctl(0, WSKBDIO_GETENCODING, &kbdencoding) == 0 ) + if ( fsystem->ioctl(0, WSKBDIO_GETENCODING, &kbdencoding) == 0 ) return true; else return false; @@ -76,8 +60,6 @@ void FTermOpenBSD::init() { // Initialize BSD workstation console - fsystem = FTerm::getFSystem(); - if ( ! isBSDConsole() ) return; @@ -94,8 +76,6 @@ void FTermOpenBSD::init() //---------------------------------------------------------------------- void FTermOpenBSD::finish() { - initCheck(); - if ( ! isBSDConsole() ) return; @@ -106,8 +86,6 @@ void FTermOpenBSD::finish() //---------------------------------------------------------------------- bool FTermOpenBSD::setBeep (int Hz, int ms) { - initCheck(false); - if ( ! isBSDConsole() ) return false; @@ -124,8 +102,9 @@ bool FTermOpenBSD::setBeep (int Hz, int ms) bell.pitch = uInt(Hz); bell.period = uInt(ms); bell.volume = 50; // 50% volume + const auto& fsystem = FTerm::getFSystem(); - if ( fsystem && fsystem->ioctl(0, WSKBDIO_SETBELL, &bell) < 0 ) + if ( fsystem->ioctl(0, WSKBDIO_SETBELL, &bell) < 0 ) return false; else return true; @@ -134,19 +113,17 @@ bool FTermOpenBSD::setBeep (int Hz, int ms) //---------------------------------------------------------------------- bool FTermOpenBSD::resetBeep() { - initCheck(false); wskbd_bell_data default_bell; + const auto& fsystem = FTerm::getFSystem(); // Gets the default setting for the bell - if ( fsystem - && fsystem->ioctl(0, WSKBDIO_GETDEFAULTBELL, &default_bell) < 0 ) + if ( fsystem->ioctl(0, WSKBDIO_GETDEFAULTBELL, &default_bell) < 0 ) return false; default_bell.which = WSKBD_BELL_DOALL; // Sets the bell settings - if ( fsystem - && fsystem->ioctl(0, WSKBDIO_SETBELL, &default_bell) < 0 ) + if ( fsystem->ioctl(0, WSKBDIO_SETBELL, &default_bell) < 0 ) return false; else return true; @@ -170,8 +147,8 @@ bool FTermOpenBSD::saveBSDConsoleEncoding() static kbd_t k_encoding{}; int ret{-1}; - if ( fsystem ) - ret = fsystem->ioctl (0, WSKBDIO_GETENCODING, &k_encoding); + const auto& fsystem = FTerm::getFSystem(); + ret = fsystem->ioctl (0, WSKBDIO_GETENCODING, &k_encoding); if ( ret < 0 ) return false; @@ -184,8 +161,9 @@ bool FTermOpenBSD::saveBSDConsoleEncoding() //---------------------------------------------------------------------- bool FTermOpenBSD::setBSDConsoleEncoding (kbd_t k_encoding) { - if ( fsystem - && fsystem->ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 ) + const auto& fsystem = FTerm::getFSystem(); + + if ( fsystem->ioctl(0, WSKBDIO_SETENCODING, &k_encoding) < 0 ) return false; else return true; @@ -204,6 +182,7 @@ bool FTermOpenBSD::resetBSDConsoleEncoding() { return setBSDConsoleEncoding (bsd_keyboard_encoding); } -#endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) } // namespace finalcut + +#endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index 54d67158..3899fcad 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -39,38 +39,17 @@ #include "final/ftermxterminal.h" #include "final/fsize.h" -#define initCheck(ret_value) \ - if ( ! isInitialized() ) \ - { \ - if ( ! FApplication::isQuit() ) \ - warnNotInitialized(); \ - \ - return ret_value; \ - } - namespace finalcut { // static class attributes bool FTermXTerminal::mouse_support{false}; -FSystem* FTermXTerminal::fsystem{nullptr}; -FKeyboard* FTermXTerminal::keyboard{nullptr}; //---------------------------------------------------------------------- // class FTermXTerminal //---------------------------------------------------------------------- -// constructors and destructor -//---------------------------------------------------------------------- -FTermXTerminal::FTermXTerminal() -{ - // Get FSystem object - fsystem = FTerm::getFSystem(); - keyboard = FTerm::getFKeyboard(); -} - - // public methods of FTermXTerminal //---------------------------------------------------------------------- void FTermXTerminal::setCursorStyle (fc::xtermCursorStyle style) @@ -185,12 +164,6 @@ void FTermXTerminal::metaSendsESC (bool enable) disableXTermMetaSendsESC(); } -//---------------------------------------------------------------------- -void FTermXTerminal::init() -{ - term_detection = FTerm::getFTermDetection(); -} - //---------------------------------------------------------------------- void FTermXTerminal::setDefaults() { @@ -268,7 +241,7 @@ void FTermXTerminal::resetHighlightBackground() //---------------------------------------------------------------------- void FTermXTerminal::resetDefaults() { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isPuttyTerminal() ) return; @@ -301,13 +274,14 @@ void FTermXTerminal::resetTitle() //---------------------------------------------------------------------- void FTermXTerminal::captureFontAndTitle() { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( ( term_detection->isXTerminal() || term_detection->isUrxvtTerminal() ) && ! term_detection->isRxvtTerminal() ) { FTermios::setCaptureSendCharacters(); + const auto& keyboard = FTerm::getFKeyboard(); keyboard->setNonBlockingInput(); xterm_font = captureXTermFont(); xterm_title = captureXTermTitle(); @@ -338,7 +312,7 @@ void FTermXTerminal::setXTermCursorStyle() return; #endif - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isGnomeTerminal() && ! term_detection->hasSetCursorStyleSupport() ) @@ -362,7 +336,7 @@ void FTermXTerminal::setXTermCursorStyle() void FTermXTerminal::setXTermTitle() { // Set the xterm title - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -387,7 +361,7 @@ void FTermXTerminal::setXTermTitle() //---------------------------------------------------------------------- void FTermXTerminal::setXTermSize() const { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() ) { @@ -403,7 +377,7 @@ void FTermXTerminal::setXTermFont() { // Change the XTerm font (needs the allowFontOps resource) - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -421,7 +395,7 @@ void FTermXTerminal::setXTermForeground() { // Set the XTerm text foreground color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -441,7 +415,7 @@ void FTermXTerminal::setXTermBackground() { // Set the XTerm text background color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -461,7 +435,7 @@ void FTermXTerminal::setXTermCursorColor() { // Set the text cursor color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -481,7 +455,7 @@ void FTermXTerminal::setXTermMouseForeground() { // Set the mouse foreground color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -500,7 +474,7 @@ void FTermXTerminal::setXTermMouseBackground() { // Set the mouse background color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -518,7 +492,7 @@ void FTermXTerminal::setXTermHighlightBackground() { // Set the highlight background color - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isXTerminal() || term_detection->isScreenTerm() @@ -538,7 +512,7 @@ void FTermXTerminal::setXTerm8ColorDefaults() // Redefinition of the XTerm default colors // for the final cut 8 color theme - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isPuttyTerminal() ) return; @@ -560,7 +534,7 @@ void FTermXTerminal::setXTerm16ColorDefaults() // Redefinition of the XTerm default colors // for the final cut 16 color theme - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isPuttyTerminal() ) return; @@ -582,7 +556,7 @@ inline void FTermXTerminal::setXTermDefaultsMouseCursor() setMouseBackground("rgb:ffff/ffff/ffff"); // white setMouseForeground ("rgb:0000/0000/0000"); // black - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( ! term_detection->isGnomeTerminal() ) setCursorColor("rgb:ffff/ffff/ffff"); // white @@ -591,7 +565,7 @@ inline void FTermXTerminal::setXTermDefaultsMouseCursor() //---------------------------------------------------------------------- inline bool FTermXTerminal::canSetXTermBackground() const { - initCheck(false); + const auto& term_detection = FTerm::getFTermDetection(); if ( xterm_default_colors && ! (term_detection->isMinttyTerm() @@ -608,7 +582,7 @@ void FTermXTerminal::resetXTermColorMap() const { // Reset the entire color table - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isMinttyTerm() ) { @@ -710,7 +684,7 @@ void FTermXTerminal::resetXTermHighlightBackground() const //---------------------------------------------------------------------- bool FTermXTerminal::canResetColor() const { - initCheck(false); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isGnomeTerminal() && term_detection->getGnomeTerminalID() < 3502 ) @@ -731,7 +705,7 @@ bool FTermXTerminal::canResetColor() const //---------------------------------------------------------------------- void FTermXTerminal::oscPrefix() const { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isTmuxTerm() ) { @@ -748,7 +722,7 @@ void FTermXTerminal::oscPrefix() const //---------------------------------------------------------------------- void FTermXTerminal::oscPostfix() const { - initCheck(); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isScreenTerm() || term_detection->isTmuxTerm() ) @@ -761,7 +735,7 @@ void FTermXTerminal::oscPostfix() const //---------------------------------------------------------------------- FString FTermXTerminal::captureXTermFont() const { - initCheck(FString{}); + const auto& term_detection = FTerm::getFTermDetection(); if ( ! term_detection->isXTerminal() && ! term_detection->isScreenTerm() @@ -823,7 +797,7 @@ FString FTermXTerminal::captureXTermFont() const //---------------------------------------------------------------------- FString FTermXTerminal::captureXTermTitle() const { - initCheck(FString{}); + const auto& term_detection = FTerm::getFTermDetection(); if ( term_detection->isKdeTerminal() ) return FString{}; @@ -887,9 +861,6 @@ void FTermXTerminal::enableXTermMouse() if ( mouse_support ) return; // The mouse is already activated - if ( ! fsystem ) - fsystem = FTerm::getFSystem(); - FTerm::putstring (CSI "?1001s" // save old highlight mouse tracking CSI "?1000;" // enable x11 mouse tracking "1002;" // enable cell motion mouse tracking diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 3d9d56c6..8d997ec0 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -402,7 +402,7 @@ void FToggleButton::drawLabel() FString label_text{}; auto hotkeypos = finalcut::getHotkeyPos(txt, label_text); print() << FPoint{1 + int(label_offset_pos), 1}; - drawText (std::move(label_text), hotkeypos); + drawText (label_text, hotkeypos); } //---------------------------------------------------------------------- @@ -485,7 +485,7 @@ void FToggleButton::init() } //---------------------------------------------------------------------- -void FToggleButton::drawText (FString&& label_text, std::size_t hotkeypos) +void FToggleButton::drawText (const FString& label_text, std::size_t hotkeypos) { if ( FTerm::isMonochron() ) setReverse(true); diff --git a/src/fvterm.cpp b/src/fvterm.cpp index e7eddb2a..a1bafe16 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -68,12 +68,10 @@ struct timeval FVTerm::last_term_size_check{}; std::vector* FVTerm::output_buffer{nullptr}; FPoint* FVTerm::term_pos{nullptr}; const FVTerm* FVTerm::init_object{nullptr}; -FSystem* FVTerm::fsystem{nullptr}; FTerm* FVTerm::fterm{nullptr}; FVTerm::FTermArea* FVTerm::vterm{nullptr}; FVTerm::FTermArea* FVTerm::vdesktop{nullptr}; FVTerm::FTermArea* FVTerm::active_area{nullptr}; -FMouseControl* FVTerm::mouse{nullptr}; FChar FVTerm::term_attribute{}; FChar FVTerm::next_attribute{}; FChar FVTerm::s_ch{}; @@ -276,6 +274,7 @@ bool FVTerm::updateTerminal() const // Check if terminal updates were stopped, application is stopping, // VTerm has no changes, or the drawing is not completed if ( no_terminal_updates || FApplication::isQuit() + || ! isFlushTimeout() || ! (hasPendingUpdates(vterm) && draw_completed) ) { return false; @@ -308,7 +307,7 @@ void FVTerm::addPreprocessingHandler ( const FVTerm* instance { FVTermPreprocessing obj{ instance, function }; delPreprocessingHandler (instance); - print_area->preproc_list.push_back(obj); + print_area->preproc_list.emplace_back(std::move(obj)); } } @@ -325,8 +324,8 @@ void FVTerm::delPreprocessingHandler (const FVTerm* instance) while ( iter != print_area->preproc_list.end() ) { - if ( iter->instance == instance ) - iter = print_area->preproc_list.erase(iter); + if ( iter->instance.get() == instance ) + iter = std::move(print_area->preproc_list.erase(iter)); else ++iter; } @@ -590,6 +589,7 @@ void FVTerm::flush() output_buffer->clear(); std::fflush(stdout); + const auto& mouse = FTerm::getFMouseControl(); mouse->drawPointer(); FObject::getCurrentTime (&time_last_flush); } @@ -1278,15 +1278,12 @@ void FVTerm::initTerminal() if ( fterm ) fterm->initTerminal(); - // Get the global FMouseControl object - mouse = FTerm::getFMouseControl(); - // Hide the input cursor cursor_hideable = FTerm::isCursorHideable(); hideCursor(); // Initialize character lengths - init_characterLengths(FTerm::getFOptiMove()); + init_characterLengths(); } @@ -1812,7 +1809,6 @@ void FVTerm::init() init_object = this; vterm = nullptr; vdesktop = nullptr; - fsystem = FTerm::getFSystem(); try { @@ -1863,24 +1859,29 @@ void FVTerm::init() } //---------------------------------------------------------------------- -void FVTerm::init_characterLengths (const FOptiMove* optimove) +void FVTerm::init_characterLengths() { - if ( optimove ) - { - cursor_address_length = optimove->getCursorAddressLength(); - erase_char_length = optimove->getEraseCharsLength(); - repeat_char_length = optimove->getRepeatCharLength(); - clr_bol_length = optimove->getClrBolLength(); - clr_eol_length = optimove->getClrEolLength(); - } - else - { + const auto& opti_move = FTerm::getFOptiMove(); + cursor_address_length = opti_move->getCursorAddressLength(); + erase_char_length = opti_move->getEraseCharsLength(); + repeat_char_length = opti_move->getRepeatCharLength(); + clr_bol_length = opti_move->getClrBolLength(); + clr_eol_length = opti_move->getClrEolLength(); + + if ( cursor_address_length == 0 ) cursor_address_length = INT_MAX; - erase_char_length = INT_MAX; - repeat_char_length = INT_MAX; - clr_bol_length = INT_MAX; - clr_eol_length = INT_MAX; - } + + if ( erase_char_length == 0 ) + erase_char_length = INT_MAX; + + if ( repeat_char_length == 0 ) + repeat_char_length = INT_MAX; + + if ( clr_bol_length == 0 ) + clr_bol_length = INT_MAX; + + if ( clr_eol_length == 0 ) + clr_eol_length = INT_MAX; } //---------------------------------------------------------------------- diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 82751c01..4317d63b 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -85,9 +85,9 @@ FWidget::FWidget (FWidget* parent) { if ( internal::var::root_widget ) { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage("FWidget: No parent defined! " - "There should be only one root object"); + const auto& fterm_data = FTerm::getFTermData(); + fterm_data->setExitMessage("FWidget: No parent defined! " + "There should be only one root object"); FApplication::exit(EXIT_FAILURE); return; } diff --git a/src/fwidgetcolors.cpp b/src/fwidgetcolors.cpp index 53c75a12..8a55417a 100644 --- a/src/fwidgetcolors.cpp +++ b/src/fwidgetcolors.cpp @@ -33,12 +33,7 @@ namespace finalcut // constructors and destructor //---------------------------------------------------------------------- -FWidgetColors::FWidgetColors() -{ } - -//---------------------------------------------------------------------- -FWidgetColors::~FWidgetColors() -{ } +FWidgetColors::~FWidgetColors() noexcept = default; //---------------------------------------------------------------------- @@ -53,8 +48,8 @@ default8ColorTheme::default8ColorTheme() } //---------------------------------------------------------------------- -default8ColorTheme::~default8ColorTheme() -{ } +default8ColorTheme::~default8ColorTheme() noexcept = default; + // public methods of default8ColorTheme //---------------------------------------------------------------------- @@ -161,8 +156,8 @@ default16ColorTheme::default16ColorTheme() } //---------------------------------------------------------------------- -default16ColorTheme::~default16ColorTheme() -{ } +default16ColorTheme::~default16ColorTheme() noexcept = default; + // public methods of default16ColorTheme //---------------------------------------------------------------------- @@ -271,8 +266,8 @@ default8ColorDarkTheme::default8ColorDarkTheme() } //---------------------------------------------------------------------- -default8ColorDarkTheme::~default8ColorDarkTheme() -{ } +default8ColorDarkTheme::~default8ColorDarkTheme() noexcept = default; + // public methods of default8ColorDarkTheme //---------------------------------------------------------------------- @@ -379,8 +374,8 @@ default16ColorDarkTheme::default16ColorDarkTheme() } //---------------------------------------------------------------------- -default16ColorDarkTheme::~default16ColorDarkTheme() -{ } +default16ColorDarkTheme::~default16ColorDarkTheme() noexcept = default; + // public methods of default16ColorDarkTheme //---------------------------------------------------------------------- diff --git a/src/include/final/emptyfstring.h b/src/include/final/emptyfstring.h index c6ab6f97..33bf5007 100644 --- a/src/include/final/emptyfstring.h +++ b/src/include/final/emptyfstring.h @@ -52,62 +52,28 @@ namespace fc class emptyFString final { -public: - // Constructors - emptyFString() = delete; + public: + // Constructors + emptyFString() = delete; - // Disable copy constructor - emptyFString (const emptyFString&) = delete; + // Disable copy constructor + emptyFString (const emptyFString&) = delete; - // Disable copy assignment operator (=) - emptyFString& operator = (const emptyFString&) = delete; + // Disable copy assignment operator (=) + emptyFString& operator = (const emptyFString&) = delete; - static FString getClassName(); - static bool isNull(); - static const FString& get(); - static void clear(); + static FString getClassName() + { + return "emptyFString"; + } -private: - // Data member - static const FString* empty_string; + static const FString& get() + { + static const auto& empty_string = make_unique(""); + return *empty_string.get(); + } }; -// emptyFString inline functions -//---------------------------------------------------------------------- -inline FString emptyFString::getClassName() -{ return "emptyFString"; } - -//---------------------------------------------------------------------- -inline bool emptyFString::isNull() -{ - return ( empty_string ) ? false : true; -} - -//---------------------------------------------------------------------- -inline const FString& emptyFString::get() -{ - if ( ! empty_string ) - { - try - { - empty_string = new FString(""); - } - catch (const std::bad_alloc&) - { - badAllocOutput ("FString"); - } - } - - return *empty_string; -} - -//---------------------------------------------------------------------- -inline void emptyFString::clear() -{ - delete empty_string; - empty_string = nullptr; -} - } // namespace fc } // namespace finalcut diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index 79ba0bc5..733a7ade 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -86,7 +86,6 @@ class FStartOptions; class FTimerEvent; class FWheelEvent; class FMouseControl; -class FKeyboard; class FPoint; class FObject; @@ -98,7 +97,7 @@ class FApplication : public FWidget { public: // Typedef - typedef std::shared_ptr FLogPtr; + using FLogPtr = std::shared_ptr; // Constructor FApplication (const int&, char*[]); @@ -164,9 +163,9 @@ class FApplication : public FWidget #endif // Typedefs - typedef std::pair EventPair; - typedef std::deque FEventQueue; - typedef std::unordered_map> CmdMap; + using EventPair = std::pair; + using FEventQueue = std::deque; + using CmdMap = std::unordered_map>; // Methods void init(); @@ -244,8 +243,6 @@ class FApplication : public FWidget static int loop_level; static int quit_code; static bool quit_now; - static FMouseControl* mouse; - static FKeyboard* keyboard; static FWidget* keyboard_widget; }; diff --git a/src/include/final/fbusyindicator.h b/src/include/final/fbusyindicator.h index 00babea3..6cc9843a 100644 --- a/src/include/final/fbusyindicator.h +++ b/src/include/final/fbusyindicator.h @@ -76,7 +76,7 @@ class FBusyIndicator : public FToolTip FBusyIndicator (const FBusyIndicator&) = delete; // Destructor - ~FBusyIndicator() override; + ~FBusyIndicator() noexcept override; // Disable copy assignment operator (=) FBusyIndicator& operator = (const FBusyIndicator&) = delete; diff --git a/src/include/final/fbuttongroup.h b/src/include/final/fbuttongroup.h index a6731a6b..d2c59f0c 100644 --- a/src/include/final/fbuttongroup.h +++ b/src/include/final/fbuttongroup.h @@ -126,7 +126,7 @@ class FButtonGroup : public FScrollView // Methods void init(); - void drawText (FString&&, std::size_t); + void drawText (const FString&, std::size_t); bool directFocusCheckedRadioButton (FToggleButton*) const; bool directFocusRadioButton() const; void directFocus(); diff --git a/src/include/final/fcallback.h b/src/include/final/fcallback.h index 32de081b..a493a13b 100644 --- a/src/include/final/fcallback.h +++ b/src/include/final/fcallback.h @@ -135,13 +135,13 @@ class FCallback , std::nullptr_t >; // Constructors - FCallback(); + FCallback() = default; // Disable copy constructor FCallback (const FCallback&) = delete; // Destructor - ~FCallback(); + ~FCallback() noexcept = default; // Disable copy assignment operator (=) FCallback& operator = (const FCallback&) = delete; diff --git a/src/include/final/fcolorpalette.h b/src/include/final/fcolorpalette.h index ed22b4f1..63387705 100644 --- a/src/include/final/fcolorpalette.h +++ b/src/include/final/fcolorpalette.h @@ -56,7 +56,7 @@ class FColorPalette explicit FColorPalette (const FSetPalette&); // Destructor - virtual ~FColorPalette(); + virtual ~FColorPalette() noexcept; // Accessor virtual FString getClassName() const; @@ -104,7 +104,7 @@ class default8ColorPalette final : public FColorPalette explicit default8ColorPalette (const FSetPalette&); // Destructor - ~default8ColorPalette() override; + ~default8ColorPalette() noexcept override; // Accessor FString getClassName() const override; @@ -144,7 +144,7 @@ class default16ColorPalette final : public FColorPalette explicit default16ColorPalette (const FSetPalette&); // Destructor - ~default16ColorPalette() override; + ~default16ColorPalette() noexcept override; // Accessor FString getClassName() const override; @@ -183,7 +183,7 @@ class default16DarkColorPalette final : public FColorPalette explicit default16DarkColorPalette (const FSetPalette&); // Destructor - ~default16DarkColorPalette() override; + ~default16DarkColorPalette() noexcept override; // Accessor FString getClassName() const override; diff --git a/src/include/final/fdata.h b/src/include/final/fdata.h index 9b47169d..15d8a823 100644 --- a/src/include/final/fdata.h +++ b/src/include/final/fdata.h @@ -118,10 +118,10 @@ class FDataAccess { public: // Constructor - FDataAccess(); + FDataAccess() = default; // Destructor - virtual ~FDataAccess(); + virtual ~FDataAccess() noexcept; // Accessors virtual FString getClassName() const @@ -166,8 +166,7 @@ class FData : public FDataAccess { } // Destructor - ~FData() override - { } + ~FData() noexcept override = default; FData (const FData& d) // Copy constructor : value{d.value} diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index fd4ea073..4916ac44 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -195,7 +195,7 @@ class FDialog : public FWindow void pressZoomButton (const MouseStates&); bool isMouseOverMenu (const FPoint&) const; void passEventToSubMenu ( const MouseStates& - , const FMouseEvent&& ); + , const FMouseEvent& ); void moveSizeKey (FKeyEvent*); void raiseActivateDialog(); void lowerActivateDialog(); diff --git a/src/include/final/ffiledialog.h b/src/include/final/ffiledialog.h index 04e366e6..aa6acda5 100644 --- a/src/include/final/ffiledialog.h +++ b/src/include/final/ffiledialog.h @@ -80,9 +80,6 @@ namespace finalcut { -// class forward declaration -class FSystem; - //---------------------------------------------------------------------- // class FFileDialog //---------------------------------------------------------------------- @@ -214,7 +211,6 @@ class FFileDialog : public FDialog void cb_processShowHidden(); // Data members - static FSystem* fsystem; DIR* directory_stream{nullptr}; DirEntries dir_entries{}; FString directory{}; diff --git a/src/include/final/fkeyboard.h b/src/include/final/fkeyboard.h index 7ac7b1b5..bf86002d 100644 --- a/src/include/final/fkeyboard.h +++ b/src/include/final/fkeyboard.h @@ -52,8 +52,6 @@ namespace finalcut // class forward declaration class FApplication; class FString; -class FTermDetection; -class FTermLinux; //---------------------------------------------------------------------- // class FKeyboardCommand @@ -137,7 +135,6 @@ class FKeyboard final bool hasDataInQueue() const; // Methods - static void init(); bool& hasUnprocessedInput(); bool isKeyPressed (uInt64 = read_blocking_time); void clearKeyBuffer(); @@ -182,12 +179,6 @@ class FKeyboard final FKeyboardCommand escape_key_cmd{}; FKeyboardCommand mouse_tracking_cmd{}; -#if defined(__linux__) - #undef linux - static FTermLinux* linux; -#endif - - FTermDetection* term_detection{nullptr}; static timeval time_keypressed; static uInt64 read_blocking_time; static uInt64 read_blocking_time_short; diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index fe164f88..7db08aa4 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -221,8 +221,13 @@ class FListViewIterator // Constructor FListViewIterator () = default; FListViewIterator (iterator); - + FListViewIterator (const FListViewIterator&) = default; + FListViewIterator (FListViewIterator&& ) + noexcept (std::is_nothrow_move_constructible::value) + = default; // Overloaded operators + FListViewIterator& operator = (const FListViewIterator&) = default; + FListViewIterator& operator = (FListViewIterator&&) noexcept = default; FListViewIterator& operator ++ (); // prefix FListViewIterator operator ++ (int); // postfix FListViewIterator& operator -- (); // prefix diff --git a/src/include/final/flog.h b/src/include/final/flog.h index e5d46e0d..61cab79f 100644 --- a/src/include/final/flog.h +++ b/src/include/final/flog.h @@ -75,7 +75,7 @@ class FLog : public std::stringbuf }; // Constructor - FLog(); + FLog() = default; // Destructor ~FLog() override; diff --git a/src/include/final/flogger.h b/src/include/final/flogger.h index d5caff76..cb722877 100644 --- a/src/include/final/flogger.h +++ b/src/include/final/flogger.h @@ -66,10 +66,10 @@ class FLogger : public FLog { public: // Constructor - FLogger(); + FLogger() = default; // Destructor - ~FLogger() override; + ~FLogger() noexcept override; // Methods FString getClassName() const override; diff --git a/src/include/final/fmenu.h b/src/include/final/fmenu.h index ceeeda0e..81bd4cb1 100644 --- a/src/include/final/fmenu.h +++ b/src/include/final/fmenu.h @@ -192,9 +192,9 @@ class FMenu : public FWindow, public FMenuList void mouseMoveDeselection (FMenuItem*, MouseStates&); void mouseUpOverBorder(); void mouseMoveOverBorder (MouseStates&) const; - void passEventToSubMenu (const FMouseEvent&&); - void passEventToSuperMenu (const FMouseEvent&&); - void passEventToMenuBar (const FMouseEvent&&) const; + void passEventToSubMenu (const FMouseEvent&); + void passEventToSuperMenu (const FMouseEvent&); + void passEventToMenuBar (const FMouseEvent&) const; bool containsMenuStructure (const FPoint&); bool containsMenuStructure (int, int); FMenu* superMenuAt (const FPoint&); diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index 348b5eb0..828fa3c3 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -138,7 +138,7 @@ class FMenuBar : public FWindow, public FMenuList void selectMenuItem (FMenuItem*); void mouseDownOverList (const FMouseEvent*); void mouseUpOverList (const FMouseEvent*); - void mouseMoveOverList (const FMouseEvent&&); + void mouseMoveOverList (const FMouseEvent&); void passEventToMenu (const FMouseEvent&&) const; void leaveMenuBar(); diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index d24b2e51..10e6d814 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -99,7 +99,7 @@ class FMessageBox : public FDialog , ButtonType, ButtonType, ButtonType , FWidget* = nullptr ); // Destructor - virtual ~FMessageBox() noexcept override; + ~FMessageBox() noexcept override; // copy assignment operator (=) FMessageBox& operator = (const FMessageBox&); diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index a4b6c00a..b0616c7d 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -90,25 +90,19 @@ namespace finalcut class FMouseData { public: + // Constructor + FMouseData() = default; + + // Copy constructor + FMouseData (const FMouseData&) = default; + + // Destructor + virtual ~FMouseData() noexcept; + // Accessors virtual FString getClassName() const; const FPoint& getPos() const; - // Constructor - FMouseData(); - - // Default copy constructor - FMouseData (const FMouseData&) = default; - // Default move constructor - FMouseData (FMouseData&&) = default; - // Default copy assignment operator (=) - FMouseData& operator = (const FMouseData&) = default; - // Default move assignment operator (=) - FMouseData& operator = (FMouseData&&) = default; - - // Destructor - virtual ~FMouseData(); - // Inquiries bool isLeftButtonPressed() const; bool isLeftButtonReleased() const; @@ -185,9 +179,6 @@ class FMouse : public FMouseData // Constructor FMouse(); - // Destructor - ~FMouse() override; - // Accessors FString getClassName() const override; void clearEvent(); @@ -256,9 +247,6 @@ class FMouseGPM final : public FMouse // Constructor FMouseGPM(); - // Destructor - ~FMouseGPM() override = default; - // Accessors FString getClassName() const override; @@ -321,12 +309,6 @@ inline bool FMouseGPM::isGpmMouseEnabled() const class FMouseX11 final : public FMouse { public: - // Constructor - FMouseX11() = default; - - // Destructor - ~FMouseX11() override = default; - // Accessors FString getClassName() const override; @@ -380,12 +362,6 @@ class FMouseX11 final : public FMouse class FMouseSGR final : public FMouse { public: - // Constructor - FMouseSGR() = default; - - // Destructor - ~FMouseSGR() override = default; - // Accessors FString getClassName() const override; @@ -439,12 +415,6 @@ class FMouseSGR final : public FMouse class FMouseUrxvt final : public FMouse { public: - // Constructor - FMouseUrxvt() = default; - - // Destructor - ~FMouseUrxvt() override = default; - // Accessors FString getClassName() const override; @@ -527,15 +497,9 @@ class FMouseControl // Constructor FMouseControl(); - // Disable copy constructor - FMouseControl (const FMouseControl&) = delete; - // Destructor virtual ~FMouseControl(); - // Disable copy assignment operator (=) - FMouseControl& operator = (const FMouseControl&) = delete; - // Accessors virtual FString getClassName() const; const FPoint& getPos(); @@ -545,7 +509,7 @@ class FMouseControl void setStdinNo (int); void setMaxWidth (uInt16); void setMaxHeight (uInt16); - void setDblclickInterval (const uInt64); + void setDblclickInterval (const uInt64) const; void setEventCommand (const FMouseCommand&); void useGpmMouse (bool = true); void useXtermMouse (bool = true); diff --git a/src/include/final/fobject.h b/src/include/final/fobject.h index bff7cb6b..dec492d8 100644 --- a/src/include/final/fobject.h +++ b/src/include/final/fobject.h @@ -152,7 +152,7 @@ class FObject // Using-declaration using FTimerList = std::vector; - using FTimerListPtr = const std::unique_ptr; + using FTimerListUniquePtr = std::unique_ptr; // Accessor FTimerList* getTimerList() const; @@ -170,7 +170,7 @@ class FObject private: // Method virtual void performTimerAction (FObject*, FEvent*); - static FTimerListPtr& globalTimerList(); + static auto globalTimerList() -> const FTimerListUniquePtr&; // Data members FObject* parent_obj{nullptr}; diff --git a/src/include/final/fpoint.h b/src/include/final/fpoint.h index b4019623..c4b4d417 100644 --- a/src/include/final/fpoint.h +++ b/src/include/final/fpoint.h @@ -59,7 +59,7 @@ class FPoint FPoint& operator -= (const FPoint&); // Accessors - FString getClassName(); + FString getClassName() const; int getX() const; int getY() const; void setX (int); @@ -102,7 +102,7 @@ inline FPoint::FPoint (int x, int y) { } //---------------------------------------------------------------------- -inline FString FPoint::getClassName() +inline FString FPoint::getClassName() const { return "FPoint"; } //---------------------------------------------------------------------- diff --git a/src/include/final/frect.h b/src/include/final/frect.h index ec588e33..5bf1d2a6 100644 --- a/src/include/final/frect.h +++ b/src/include/final/frect.h @@ -65,7 +65,7 @@ class FRect FRect (const FPoint&, const FPoint&); // Accessors - FString getClassName(); + FString getClassName() const; int getX1() const; int getY1() const; int getX2() const; @@ -147,7 +147,7 @@ inline FRect::FRect (int x, int y, std::size_t width, std::size_t height) { } //---------------------------------------------------------------------- -inline FString FRect::getClassName() +inline FString FRect::getClassName() const { return "FRect"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fsize.h b/src/include/final/fsize.h index 90c94f4f..3a9d2cfb 100644 --- a/src/include/final/fsize.h +++ b/src/include/final/fsize.h @@ -64,7 +64,7 @@ class FSize FSize& operator -= (const FSize&); // Accessors - FString getClassName(); + FString getClassName() const; std::size_t getWidth() const; std::size_t getHeight() const; std::size_t getArea() const; @@ -111,7 +111,7 @@ inline FSize::FSize (std::size_t w, std::size_t h) { } //---------------------------------------------------------------------- -inline FString FSize::getClassName() +inline FString FSize::getClassName() const { return "FSize"; } //---------------------------------------------------------------------- diff --git a/src/include/final/fstringstream.h b/src/include/final/fstringstream.h index 2904ce7e..dfd994a6 100644 --- a/src/include/final/fstringstream.h +++ b/src/include/final/fstringstream.h @@ -72,13 +72,13 @@ class FStringStream : public std::wiostream FStringStream (FStringStream&&) noexcept; // Destructor - ~FStringStream(); + ~FStringStream() noexcept; // Disable copy assignment operator (=) FStringStream& operator = (const FStringStream&) = delete; // Move assignment operator (=) - FStringStream& operator = (FStringStream&& sstream) noexcept; + FStringStream& operator = (FStringStream&&) noexcept; virtual FString getClassName() const; void swap (FStringStream&) noexcept; diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index 7abd7cf6..cf1379a1 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -142,15 +142,15 @@ class FTermDebugData; class FTermDetection; class FTermXTerminal; -#if defined(UNIT_TEST) +#if defined(__linux__) || defined(UNIT_TEST) class FTermLinux; +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) class FTermFreeBSD; - class FTermOpenBSD; -#elif defined(__linux__) - class FTermLinux; -#elif defined(__FreeBSD__) || defined(__DragonFly__) - class FTermFreeBSD; -#elif defined(__NetBSD__) || defined(__OpenBSD__) +#endif + +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) class FTermOpenBSD; #endif @@ -163,7 +163,6 @@ class FTerm final public: // Using-declarations using defaultPutChar = std::function; - using FColorPalettePtr = std::shared_ptr; using FSetPalette = FColorPalette::FSetPalette; // Constructor @@ -183,36 +182,36 @@ class FTerm final static std::size_t getLineNumber(); static std::size_t getColumnNumber(); static FString getKeyName (FKey); + charSubstitution& getCharSubstitutionMap(); 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 auto getColorPaletteTheme() -> std::shared_ptr&; + static auto getFTermData() -> const std::unique_ptr&; + static auto getFSystem() -> std::unique_ptr&; + static auto getFOptiMove() -> const std::unique_ptr&; + static auto getFOptiAttr() -> const std::unique_ptr&; + static auto getFTermDetection() -> const std::unique_ptr&; + static auto getFTermXTerminal() -> const std::unique_ptr&; + static auto getFKeyboard() -> const std::unique_ptr&; + static auto getFMouseControl() -> const std::unique_ptr&; -#if defined(UNIT_TEST) - static FTermLinux* getFTermLinux(); - static FTermFreeBSD* getFTermFreeBSD(); - static FTermOpenBSD* getFTermOpenBSD(); -#elif defined(__linux__) - static FTermLinux* getFTermLinux(); -#elif defined(__FreeBSD__) || defined(__DragonFly__) - static FTermFreeBSD* getFTermFreeBSD(); -#elif defined(__NetBSD__) || defined(__OpenBSD__) - static FTermOpenBSD* getFTermOpenBSD(); +#if defined(__linux__) || defined(UNIT_TEST) + static auto getFTermLinux() -> const std::unique_ptr&; +#endif + +#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(UNIT_TEST) + static auto getFTermFreeBSD() -> const std::unique_ptr&; +#endif + +#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) + static auto getFTermOpenBSD() -> const std::unique_ptr&; #endif #if DEBUG - static FTermDebugData& getFTermDebugData(); + static auto getFTermDebugData() -> const std::unique_ptr&; #endif // Inquiries @@ -252,7 +251,7 @@ class FTerm final static bool canChangeColorPalette(); // Mutators - static void setFSystem (FSystem*); + static void setFSystem (std::unique_ptr&&); static void setTermType (const char[]); static void setInsertCursor (bool); static void setInsertCursor(); @@ -319,7 +318,6 @@ class FTerm final 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(); @@ -351,8 +349,6 @@ class FTerm final static void enableAlternateCharset(); static void useAlternateScreenBuffer(); static void useNormalScreenBuffer(); - void allocationValues() const; - void deallocationValues(); void init(); bool init_terminal() const; void initOSspecifics() const; @@ -361,41 +357,12 @@ class FTerm final void finish() const; void finishOSspecifics() const; void finish_encoding() const; - void destroyColorPaletteTheme(); static void printExitMessage(); static void terminalSizeChange(); [[noreturn]] static void processTermination (int); 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; - -#if defined(UNIT_TEST) - #undef linux - static FTermLinux* linux; - static FTermFreeBSD* freebsd; - static FTermOpenBSD* openbsd; -#elif defined(__linux__) - #undef linux - static FTermLinux* linux; -#elif defined(__FreeBSD__) || defined(__DragonFly__) - static FTermFreeBSD* freebsd; -#elif defined(__NetBSD__) || defined(__OpenBSD__) - static FTermOpenBSD* openbsd; -#endif - -#if DEBUG - static FTermDebugData* debug_data; -#endif }; @@ -424,8 +391,10 @@ inline FString FTerm::getClassName() { return "FTerm"; } //---------------------------------------------------------------------- -inline void FTerm::setFSystem (FSystem* fsystem) -{ fsys = fsystem; } +inline void FTerm::setFSystem (std::unique_ptr&& fsystem) +{ + getFSystem().swap(fsystem); +} //---------------------------------------------------------------------- inline void FTerm::setInsertCursor() @@ -460,15 +429,11 @@ inline void FTerm::putstringf (const char format[], Args&&... args) if ( size == -1 ) return; - if ( ! fsys ) - getFSystem(); // Trying to set fsys - const auto count = std::size_t(size); std::vector buf(count); std::snprintf (&buf[0], count, format, std::forward(args)...); - - if ( fsys ) - fsys->tputs (&buf[0], 1, FTerm::putchar_ASCII); + const auto& fsys = FTerm::getFSystem(); + fsys->tputs (&buf[0], 1, FTerm::putchar_ASCII); } //---------------------------------------------------------------------- diff --git a/src/include/final/ftermcap.h b/src/include/final/ftermcap.h index a4ca6d45..dc30ec31 100644 --- a/src/include/final/ftermcap.h +++ b/src/include/final/ftermcap.h @@ -60,17 +60,14 @@ #include #include +#include "final/ftermcap.h" + // FTermcap string macro #define TCAP(...) FTermcap::strings[__VA_ARGS__].string namespace finalcut { -// class forward declaration -class FSystem; -class FTermData; -class FTermDetection; - //---------------------------------------------------------------------- // class FTermcap //---------------------------------------------------------------------- @@ -148,10 +145,8 @@ class FTermcap final static int _tputs (const char*, int, fn_putc); // Data member - static FSystem* fsystem; - static FTermData* fterm_data; - static FTermDetection* term_detection; - static char string_buf[BUF_SIZE]; + static char string_buf[BUF_SIZE]; + static bool initialized; }; @@ -206,7 +201,7 @@ int FTermcap::paddingPrint (const CharT& str, int affcnt, fn_putc putc) //---------------------------------------------------------------------- inline bool FTermcap::isInitialized() { - return bool(fsystem && fterm_data && term_detection); + return initialized; } } // namespace finalcut diff --git a/src/include/final/ftermcapquirks.h b/src/include/final/ftermcapquirks.h index 384918d5..6f27999c 100644 --- a/src/include/final/ftermcapquirks.h +++ b/src/include/final/ftermcapquirks.h @@ -38,10 +38,6 @@ namespace finalcut { -// class forward declaration -class FTermData; -class FTermDetection; - //---------------------------------------------------------------------- // class FTermcapsQuirks //---------------------------------------------------------------------- @@ -77,10 +73,6 @@ class FTermcapQuirks final static void screen(); static void general(); static void ecma48(); - - // Data members - static FTermData* fterm_data; - static FTermDetection* term_detection; }; // FTermcapQuirks inline functions diff --git a/src/include/final/ftermdebugdata.h b/src/include/final/ftermdebugdata.h index 1d76e9da..392d2087 100644 --- a/src/include/final/ftermdebugdata.h +++ b/src/include/final/ftermdebugdata.h @@ -40,8 +40,6 @@ namespace finalcut // class forward declaration class FTerm; -class FTermData; -class FTermDetection; #if DEBUG //---------------------------------------------------------------------- @@ -72,14 +70,6 @@ class FTermDebugData final #if defined(__linux__) int getFramebufferBpp(); #endif - - // Methods - static void init(); - - private: - // Data members - static FTermData* data; - static FTermDetection* term_detection; }; #endif // DEBUG diff --git a/src/include/final/ftermdetection.h b/src/include/final/ftermdetection.h index 6935372e..aa2268df 100644 --- a/src/include/final/ftermdetection.h +++ b/src/include/final/ftermdetection.h @@ -207,9 +207,6 @@ class FTermDetection final static int gnome_terminal_id; static const FString* answer_back; static const FString* sec_da; - static FTermData* fterm_data; - static FSystem* fsystem; - static FKeyboard* keyboard; static FTerminalType terminal_type; static colorEnv color_env; static secondaryDA secondary_da; diff --git a/src/include/final/ftermfreebsd.h b/src/include/final/ftermfreebsd.h index 23214c59..27893b08 100644 --- a/src/include/final/ftermfreebsd.h +++ b/src/include/final/ftermfreebsd.h @@ -69,7 +69,6 @@ namespace finalcut { // class forward declaration -class FSystem; class FTermData; //---------------------------------------------------------------------- @@ -123,15 +122,12 @@ class FTermFreeBSD final static bool setFreeBSDAlt2Meta(); static bool resetFreeBSDAlt2Meta(); static bool setFreeBSDCursorStyle (CursorStyle); - static bool isInitialized(); // Data members static uInt bsd_alt_keymap; static CursorStyle cursor_style; static bool change_cursorstyle; static bool meta_sends_escape; - static FSystem* fsystem; - static FTermData* fterm_data; }; @@ -157,9 +153,6 @@ 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/ftermlinux.h b/src/include/final/ftermlinux.h index 989b8028..efaa0e32 100644 --- a/src/include/final/ftermlinux.h +++ b/src/include/final/ftermlinux.h @@ -65,11 +65,6 @@ namespace finalcut { -// class forward declaration -class FSystem; -class FTermData; -class FTermDetection; - //---------------------------------------------------------------------- // class FTermLinux //---------------------------------------------------------------------- @@ -148,7 +143,7 @@ class FTermLinux final int getFramebuffer_bpp(); bool getScreenFont(); bool getUnicodeMap (); - ModifierKey& getModifierKey(); + ModifierKey& getModifierKey(); // Mutators int setScreenFont ( const uChar[], uInt, uInt, uInt @@ -187,9 +182,6 @@ class FTermLinux final bool vga_font{}; bool new_font{}; bool has_saved_palette{}; - FTermData* fterm_data{nullptr}; - FSystem* fsystem{nullptr}; - FTermDetection* term_detection{nullptr}; CursorStyle linux_console_cursor_style{}; console_font_op screen_font{}; unimapdesc screen_unicode_map{}; diff --git a/src/include/final/ftermopenbsd.h b/src/include/final/ftermopenbsd.h index 86590cca..43dabe28 100644 --- a/src/include/final/ftermopenbsd.h +++ b/src/include/final/ftermopenbsd.h @@ -64,9 +64,6 @@ namespace finalcut { -// class forward declaration -class FSystem; - //---------------------------------------------------------------------- // class FTermOpenBSD //---------------------------------------------------------------------- @@ -110,12 +107,10 @@ class FTermOpenBSD final static bool setBSDConsoleEncoding (kbd_t); static bool setBSDConsoleMetaEsc(); static bool resetBSDConsoleEncoding(); - static bool isInitialized(); // Data members static kbd_t bsd_keyboard_encoding; static bool meta_sends_escape; - static FSystem* fsystem; #endif // defined(__NetBSD__) || defined(__OpenBSD__) || defined(UNIT_TEST) }; @@ -134,9 +129,6 @@ 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 2f53c910..f209d1b5 100644 --- a/src/include/final/ftermxterminal.h +++ b/src/include/final/ftermxterminal.h @@ -40,9 +40,6 @@ namespace finalcut // class forward declaration class FString; -class FSystem; -class FKeyboard; -class FTermDetection; //---------------------------------------------------------------------- // class FTermXTerminal @@ -52,7 +49,7 @@ class FTermXTerminal final { public: // Constructors - FTermXTerminal(); + FTermXTerminal() = default; // Disable copy constructor FTermXTerminal (const FTermXTerminal&) = delete; @@ -97,7 +94,6 @@ class FTermXTerminal final bool hasTitle() const; // Methods - void init(); void setDefaults(); void resetColorMap() const; void resetForeground(); @@ -134,7 +130,6 @@ class FTermXTerminal final void resetXTermMouseForeground() const; void resetXTermMouseBackground() const; void resetXTermHighlightBackground() const; - bool isInitialized() const; bool canResetColor() const; void oscPrefix() const; void oscPostfix() const; @@ -160,9 +155,6 @@ class FTermXTerminal final FString mouse_foreground_color{}; FString mouse_background_color{}; FString highlight_background_color{}; - static FSystem* fsystem; - static FKeyboard* keyboard; - FTermDetection* term_detection{nullptr}; fc::xtermCursorStyle cursor_style{fc::unknown_cursor_style}; }; @@ -228,10 +220,6 @@ inline void FTermXTerminal::setMouseSupport() inline void FTermXTerminal::unsetMouseSupport() { setMouseSupport (false); } -//---------------------------------------------------------------------- -inline bool FTermXTerminal::isInitialized() const -{ return bool(fsystem && term_detection); } - } // namespace finalcut #endif // FTERMXTERMINAL_H diff --git a/src/include/final/ftogglebutton.h b/src/include/final/ftogglebutton.h index 0780e32f..35e35565 100644 --- a/src/include/final/ftogglebutton.h +++ b/src/include/final/ftogglebutton.h @@ -148,7 +148,7 @@ class FToggleButton : public FWidget // Methods void init(); - void drawText (FString&&, std::size_t); + void drawText (const FString&, std::size_t); void correctSize (FSize&) const; // Data members diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index be265c79..6270a1fc 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -68,12 +68,10 @@ namespace finalcut // class forward declaration class FColorPair; -class FMouseControl; class FPoint; class FRect; class FSize; class FString; -class FSystem; class FTerm; class FTermBuffer; class FTermDebugData; @@ -370,7 +368,7 @@ class FVTerm static FChar getCoveredCharacter (const FPoint&, const FTermArea*); static FChar getOverlappedCharacter (const FPoint&, const FTermArea*); void init(); - static void init_characterLengths (const FOptiMove*); + static void init_characterLengths(); void finish(); static void putAreaLine (const FChar&, FChar&, std::size_t); static void putAreaCharacter ( const FPoint&, const FTermArea* @@ -426,7 +424,6 @@ class FVTerm FTermArea* child_print_area{nullptr}; // print area for children FTermArea* vwin{nullptr}; // virtual window static const FVTerm* init_object; // Global FVTerm object - static FSystem* fsystem; static FTerm* fterm; static FTermArea* vterm; // virtual terminal static FTermArea* vdesktop; // virtual desktop @@ -437,7 +434,6 @@ class FVTerm static FChar s_ch; // shadow character static FChar i_ch; // inherit background character static FPoint* term_pos; // terminal cursor position - static FMouseControl* mouse; static timeval time_last_flush; static timeval last_term_size_check; static bool draw_completed; @@ -492,6 +488,11 @@ struct FVTerm::FTermArea // define virtual terminal character properties bool visible{false}; }; +struct D +{ + void operator () (const FVTerm*) const + { } +}; //---------------------------------------------------------------------- // struct FVTerm::FVTermPreprocessing @@ -500,16 +501,19 @@ struct FVTerm::FTermArea // define virtual terminal character properties struct FVTerm::FVTermPreprocessing { // Constructor - FVTermPreprocessing() = default; - FVTermPreprocessing (const FVTerm* i, const FPreprocessingFunction& f) - : instance(i) + : instance(std::unique_ptr(i)) , function(f) { } + FVTermPreprocessing (const FVTermPreprocessing&) = delete; + FVTermPreprocessing (FVTermPreprocessing&&) = default; + FVTermPreprocessing& operator = (const FVTermPreprocessing&) = delete; + FVTermPreprocessing& operator = (FVTermPreprocessing&&) noexcept = default; + // Data members - const FVTerm* instance{nullptr}; - FPreprocessingFunction function{nullptr}; + std::unique_ptr instance{}; + FPreprocessingFunction function{}; }; diff --git a/src/include/final/fwidgetcolors.h b/src/include/final/fwidgetcolors.h index 38fbed1a..60a279cf 100644 --- a/src/include/final/fwidgetcolors.h +++ b/src/include/final/fwidgetcolors.h @@ -48,10 +48,10 @@ class FWidgetColors { public: // Constructor - FWidgetColors(); + FWidgetColors() = default; // Destructor - virtual ~FWidgetColors(); + virtual ~FWidgetColors() noexcept; // Method virtual FString getClassName() const; @@ -176,7 +176,7 @@ class default8ColorTheme final : public FWidgetColors default8ColorTheme(); // Destructor - ~default8ColorTheme() override; + ~default8ColorTheme() noexcept override; // Method FString getClassName() const override; @@ -213,7 +213,7 @@ class default16ColorTheme final : public FWidgetColors default16ColorTheme(); // Destructor - ~default16ColorTheme() override; + ~default16ColorTheme() noexcept override; // Method FString getClassName() const override; @@ -250,7 +250,7 @@ class default8ColorDarkTheme final : public FWidgetColors default8ColorDarkTheme(); // Destructor - ~default8ColorDarkTheme() override; + ~default8ColorDarkTheme() noexcept override; // Method FString getClassName() const override; @@ -287,7 +287,7 @@ class default16ColorDarkTheme final : public FWidgetColors default16ColorDarkTheme(); // Destructor - ~default16ColorDarkTheme() override; + ~default16ColorDarkTheme() noexcept override; // Method FString getClassName() const override; diff --git a/test/conemu.h b/test/conemu.h index 25529b1d..109b2bc4 100644 --- a/test/conemu.h +++ b/test/conemu.h @@ -531,7 +531,7 @@ inline pid_t ConEmu::forkConEmu() #ifdef TIOCSWINSZ // Set slave tty window size - struct winsize size; + struct winsize size{}; size.ws_row = 25; size.ws_col = 80; diff --git a/test/ftermfreebsd-test.cpp b/test/ftermfreebsd-test.cpp index dc0582df..640a2894 100644 --- a/test/ftermfreebsd-test.cpp +++ b/test/ftermfreebsd-test.cpp @@ -573,7 +573,6 @@ struct keymap_t& FSystemTest::getTerminalKeymap() return terminal_keymap; } - } // namespace test @@ -624,11 +623,10 @@ void ftermfreebsdTest::freebsdConsoleTest() setenv ("COLUMNS", "80", 1); setenv ("LINES", "25", 1); - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTermDetection* term_detection{}; - finalcut::FTerm::setFSystem(fsys); + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -655,10 +653,9 @@ void ftermfreebsdTest::freebsdConsoleTest() data->setVGAFont (false); data->setMonochron (false); data->setTermResized (false); - // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); term_detection->setTerminalDetection(true); pid_t pid = forkConEmu(); @@ -666,7 +663,8 @@ void ftermfreebsdTest::freebsdConsoleTest() { static constexpr int left_alt = 0x38; finalcut::FTermFreeBSD freebsd; - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); struct keymap_t& keymap = fsystest->getTerminalKeymap(); setenv ("TERM", "xterm", 1); @@ -760,7 +758,7 @@ void ftermfreebsdTest::freebsdConsoleTest() #if DEBUG const finalcut::FString& sec_da = \ - finalcut::FTerm::getFTermDebugData().getSecDAString(); + finalcut::FTerm::getFTermDebugData()->getSecDAString(); CPPUNIT_ASSERT ( sec_da == "\033[>0;10;0c" ); #endif @@ -773,6 +771,7 @@ void ftermfreebsdTest::freebsdConsoleTest() data->setCursorHidden (false); freebsd.setCursorStyle (finalcut::fc::normal_cursor); + CPPUNIT_ASSERT ( fsystest->getCursorType() == finalcut::fc::normal_cursor ); freebsd.setCursorStyle (finalcut::fc::blink_cursor); @@ -812,8 +811,6 @@ void ftermfreebsdTest::freebsdConsoleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- diff --git a/test/ftermlinux-test.cpp b/test/ftermlinux-test.cpp index 36afea72..de4a49ba 100644 --- a/test/ftermlinux-test.cpp +++ b/test/ftermlinux-test.cpp @@ -994,10 +994,16 @@ FSystemTest::FSystemTest() // constructor FSystemTest::~FSystemTest() // destructor { if ( terminal_font.data ) + { delete[] terminal_font.data; + terminal_font.data = nullptr; + } if ( terminal_unicode_map.entries ) + { delete[] terminal_unicode_map.entries; + terminal_unicode_map.entries = nullptr; + } } @@ -1091,19 +1097,25 @@ int FSystemTest::ioctl (int fd, uLong request, ...) constexpr std::size_t font_data_size = 4 * 32 * 512; struct console_font_op* fn = static_cast(argp); - // Set Default - if ( terminal_font.data && terminal_font.data[219 * 32] == 0 ) - { - terminal_font.width = 8; - terminal_font.height = 16; - terminal_font.charcount = 256; - - if ( fn->data ) - std::memcpy (terminal_font.data, &vga8x16, sizeof(vga8x16)); - } - if ( fn->op == KD_FONT_OP_GET ) { + // If data is empty + if ( ! terminal_font.data ) + { + terminal_font.data = new uChar[font_data_size]{ }; + } + + // Set Default + if ( terminal_font.data[219 * 32] == 0 ) + { + terminal_font.width = 8; + terminal_font.height = 16; + terminal_font.charcount = 256; + + if ( fn->data ) + std::memcpy (terminal_font.data, &vga8x16, sizeof(vga8x16)); + } + fn->flags = terminal_font.flags; fn->width = terminal_font.width; fn->height = terminal_font.height; @@ -1117,11 +1129,17 @@ int FSystemTest::ioctl (int fd, uLong request, ...) if ( fn->op == KD_FONT_OP_SET ) { - terminal_font.flags = fn->flags; - terminal_font.width = fn->width; - terminal_font.height = fn->height; - terminal_font.charcount = fn->charcount; - auto size = fn->width / 8 * fn->height * fn->charcount; + terminal_font.flags = fn->flags; + terminal_font.width = fn->width; + terminal_font.height = fn->height; + terminal_font.charcount = fn->charcount; + constexpr int fix_height = 32; // This value is identical for all fonts + auto size = fn->width / 8 * fix_height * fn->charcount; + + if ( ! terminal_font.data ) // If data is empty on a second run + { + terminal_font.data = new uChar[font_data_size]{ }; + } if ( fn->data && terminal_font.data ) std::memcpy (terminal_font.data, fn->data, size); @@ -1194,7 +1212,7 @@ int FSystemTest::ioctl (int fd, uLong request, ...) std::size_t pairs_size = pairs * sizeof(unipair); // Sets the default unicode map of the terminal on the first call - if ( terminal_unicode_map.entries == 0 ) + if ( ! terminal_unicode_map.entries ) { terminal_unicode_map.entry_ct = pairs; terminal_unicode_map.entries = new unipair[pairs](); @@ -1222,8 +1240,30 @@ int FSystemTest::ioctl (int fd, uLong request, ...) { req_string = "PIO_UNIMAP"; unimapdesc* umap = static_cast(argp); - std::memcpy (&terminal_unicode_map, umap, sizeof(*umap)); - ret_val = 0; + std::size_t pairs = umap->entry_ct; + std::size_t pairs_size = pairs * sizeof(unipair); + terminal_unicode_map.entry_ct = umap->entry_ct; + + if ( terminal_unicode_map.entries ) + { + delete[] terminal_unicode_map.entries; + terminal_unicode_map.entries = nullptr; + } + + terminal_unicode_map.entries = new unipair[pairs](); + + if ( umap->entries && terminal_unicode_map.entries ) + { + std::memcpy (terminal_unicode_map.entries, umap->entries, pairs_size); + errno = 0; + ret_val = 0; + } + else + { + errno = ENOMEM; + ret_val = 0; + } + break; } @@ -1519,11 +1559,10 @@ void FTermLinuxTest::classNameTest() //---------------------------------------------------------------------- void FTermLinuxTest::linuxConsoleTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -1555,7 +1594,7 @@ void FTermLinuxTest::linuxConsoleTest() data->setMonochron (false); data->setTermResized (false); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); finalcut::FTermLinux linux; // setupterm is needed for tputs in ncurses >= 6.1 @@ -1590,7 +1629,8 @@ void FTermLinuxTest::linuxConsoleTest() CPPUNIT_ASSERT ( data->hasHalfBlockCharacter() ); CPPUNIT_ASSERT ( linux.getFramebufferBpp() == 32 ); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); std::string& characters = fsystest->getCharacters(); linux.setUTF8 (false); CPPUNIT_ASSERT ( characters == ESC "%@" ); @@ -1636,18 +1676,15 @@ void FTermLinuxTest::linuxConsoleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void FTermLinuxTest::linuxCursorStyleTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -1681,7 +1718,7 @@ void FTermLinuxTest::linuxCursorStyleTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); finalcut::FTermLinux linux; pid_t pid = forkConEmu(); @@ -1704,7 +1741,8 @@ void FTermLinuxTest::linuxCursorStyleTest() term_detection->detect(); linux.init(); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); std::string& characters = fsystest->getCharacters(); characters.clear(); linux.setCursorStyle (finalcut::fc::default_cursor); @@ -1827,18 +1865,15 @@ void FTermLinuxTest::linuxCursorStyleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void FTermLinuxTest::linuxColorPaletteTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -1872,7 +1907,7 @@ void FTermLinuxTest::linuxColorPaletteTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); finalcut::FTermLinux linux; term_detection->setLinuxTerm(true); @@ -1895,7 +1930,8 @@ void FTermLinuxTest::linuxColorPaletteTest() term_detection->detect(); linux.init(); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); CPPUNIT_ASSERT ( linux.resetColorMap() == true ); CPPUNIT_ASSERT ( linux.saveColorMap() == true ); @@ -2104,18 +2140,15 @@ void FTermLinuxTest::linuxColorPaletteTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void FTermLinuxTest::linuxFontTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -2149,7 +2182,7 @@ void FTermLinuxTest::linuxFontTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); finalcut::FTermLinux linux; pid_t pid = forkConEmu(); @@ -2171,18 +2204,19 @@ void FTermLinuxTest::linuxFontTest() term_detection->detect(); linux.init(); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); console_font_op& font = fsystest->getConsoleFont(); CPPUNIT_ASSERT ( font.op == KD_FONT_OP_GET ); CPPUNIT_ASSERT ( ! linux.isVGAFontUsed() ); CPPUNIT_ASSERT ( ! linux.isNewFontUsed() ); - linux.loadVGAFont(); - /* CPPUNIT_ASSERT ( data->hasShadowCharacter() ); + CPPUNIT_ASSERT ( data->hasShadowCharacter() ); CPPUNIT_ASSERT ( data->hasHalfBlockCharacter() ); CPPUNIT_ASSERT ( font.op == KD_FONT_OP_SET ); CPPUNIT_ASSERT ( linux.isVGAFontUsed() ); CPPUNIT_ASSERT ( ! linux.isNewFontUsed() ); + CPPUNIT_ASSERT ( font.data ); // Full block character test for (std::size_t i = 0; i < 16 ; i++) @@ -2235,7 +2269,7 @@ void FTermLinuxTest::linuxFontTest() CPPUNIT_ASSERT ( font.data[249 * 32 + 13] == 0x00 ); CPPUNIT_ASSERT ( font.data[249 * 32 + 14] == 0x00 ); CPPUNIT_ASSERT ( font.data[249 * 32 + 15] == 0x00 ); -*/ + linux.finish(); closeConEmuStdStreams(); @@ -2249,19 +2283,20 @@ void FTermLinuxTest::linuxFontTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void FTermLinuxTest::modifierKeyTest() { + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); + + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); + test::FSystemTest::ShiftState& mod_key = fsystest->getShiftState(); + finalcut::FTermLinux linux{}; FKey keycode{}; FKey mod_keycode{}; - finalcut::FTermLinux linux{}; - finalcut::FSystem* fsys(new test::FSystemTest()); - test::FSystemTest* fsystest = static_cast(fsys); - test::FSystemTest::ShiftState& mod_key = fsystest->getShiftState(); // Up key keycode = finalcut::fc::Fkey_up; @@ -2721,7 +2756,6 @@ void FTermLinuxTest::modifierKeyTest() mod_key.shift = 1; mod_keycode = linux.modifierKeyCorrection(keycode); CPPUNIT_ASSERT ( mod_keycode == finalcut::fc::Fkey_space ); - delete fsys; } // Put the test suite in the registry diff --git a/test/ftermopenbsd-test.cpp b/test/ftermopenbsd-test.cpp index 1936f2ba..9201aaba 100644 --- a/test/ftermopenbsd-test.cpp +++ b/test/ftermopenbsd-test.cpp @@ -345,11 +345,10 @@ void ftermopenbsdTest::classNameTest() //---------------------------------------------------------------------- void ftermopenbsdTest::netbsdConsoleTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -379,7 +378,7 @@ void ftermopenbsdTest::netbsdConsoleTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); term_detection->setTerminalDetection(true); pid_t pid = forkConEmu(); @@ -407,7 +406,7 @@ void ftermopenbsdTest::netbsdConsoleTest() #if DEBUG const finalcut::FString& sec_da = \ - finalcut::FTerm::getFTermDebugData().getSecDAString(); + finalcut::FTerm::getFTermDebugData()->getSecDAString(); CPPUNIT_ASSERT ( sec_da == "\033[>24;20;0c" ); #endif @@ -445,18 +444,15 @@ void ftermopenbsdTest::netbsdConsoleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } //---------------------------------------------------------------------- void ftermopenbsdTest::openbsdConsoleTest() { - finalcut::FSystem* fsys = new test::FSystemTest(); - finalcut::FTerm::setFSystem(fsys); - finalcut::FTermDetection* term_detection{}; + auto fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(std::move(fsys)); std::cout << "\n"; - finalcut::FTermData* data = finalcut::FTerm::getFTermData(); + const auto& data = finalcut::FTerm::getFTermData(); auto& encoding_list = data->getEncodingList(); encoding_list["UTF-8"] = finalcut::fc::UTF8; @@ -486,7 +482,7 @@ void ftermopenbsdTest::openbsdConsoleTest() // setupterm is needed for tputs in ncurses >= 6.1 setupterm (static_cast(0), 1, static_cast(0)); - term_detection = finalcut::FTerm::getFTermDetection(); + const auto& term_detection = finalcut::FTerm::getFTermDetection(); term_detection->setTerminalDetection(true); pid_t pid = forkConEmu(); @@ -507,7 +503,8 @@ void ftermopenbsdTest::openbsdConsoleTest() unsetenv("KONSOLE_DCOP"); unsetenv("TMUX"); - test::FSystemTest* fsystest = static_cast(fsys); + const auto& fsystem = finalcut::FTerm::getFSystem(); + auto fsystest = static_cast(fsystem.get()); wskbd_bell_data& speaker = fsystest->getBell(); openbsd.disableMetaSendsEscape(); openbsd.init(); @@ -516,7 +513,7 @@ void ftermopenbsdTest::openbsdConsoleTest() #if DEBUG const finalcut::FString& sec_da = \ - finalcut::FTerm::getFTermDebugData().getSecDAString(); + finalcut::FTerm::getFTermDebugData()->getSecDAString(); CPPUNIT_ASSERT ( sec_da == "\033[>24;20;0c" ); #endif @@ -583,8 +580,6 @@ void ftermopenbsdTest::openbsdConsoleTest() if ( waitpid(pid, 0, WUNTRACED) != pid ) std::cerr << "waitpid error" << std::endl; } - - delete fsys; } From 226663889b4deeb2ffd38576fce0e8371482f071 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 3 Dec 2020 23:20:33 +0100 Subject: [PATCH 05/45] Improvement of the move semantics in FVTermPreprocessing --- src/flistview.cpp | 6 ++--- src/ftermlinux.cpp | 12 ++++----- src/fvterm.cpp | 6 ++--- src/fwidget.cpp | 13 ++------- src/include/final/fapplication.h | 2 +- src/include/final/fcallback.h | 4 +-- src/include/final/fcolorpalette.h | 4 +-- src/include/final/fdialog.h | 5 ++-- src/include/final/ffiledialog.h | 3 +-- src/include/final/fkeyboard.h | 4 +-- src/include/final/flistbox.h | 12 ++++----- src/include/final/flistview.h | 45 ++++++++++++++++--------------- src/include/final/fmenu.h | 17 ++++++------ src/include/final/fmouse.h | 6 ++--- src/include/final/foptiattr.h | 11 ++++---- src/include/final/foptimove.h | 16 +++++------ src/include/final/fscrollview.h | 4 +-- src/include/final/fstatusbar.h | 4 +-- src/include/final/fstringstream.h | 2 +- src/include/final/fterm.h | 4 +-- src/include/final/ftermcap.h | 6 ++--- src/include/final/ftermdata.h | 4 +-- src/include/final/ftermlinux.h | 12 ++++----- src/include/final/ftermopenbsd.h | 2 +- src/include/final/ftextview.h | 4 +-- src/include/final/fvterm.h | 12 +++++---- src/include/final/fwidget.h | 10 +++---- src/include/final/sgr_optimizer.h | 4 +-- test/ftermfreebsd-test.cpp | 4 +-- test/ftermlinux-test.cpp | 20 +++++++------- test/ftermopenbsd-test.cpp | 8 +++--- 31 files changed, 125 insertions(+), 141 deletions(-) diff --git a/src/flistview.cpp b/src/flistview.cpp index aeb99961..084f1d00 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -478,7 +478,7 @@ void FListViewItem::resetVisibleLineCounter() // constructor and destructor //---------------------------------------------------------------------- -FListViewIterator::FListViewIterator (iterator iter) +FListViewIterator::FListViewIterator (Iterator iter) : node{iter} { } @@ -533,7 +533,7 @@ FListViewIterator& FListViewIterator::operator -= (int n) // private methods of FListViewIterator //---------------------------------------------------------------------- -void FListViewIterator::nextElement (iterator& iter) +void FListViewIterator::nextElement (Iterator& iter) { const auto& item = static_cast(*iter); @@ -570,7 +570,7 @@ void FListViewIterator::nextElement (iterator& iter) } //---------------------------------------------------------------------- -void FListViewIterator::prevElement (iterator& iter) +void FListViewIterator::prevElement (Iterator& iter) { auto start_iter = iter; diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index 27fbd1e1..b5f09306 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -130,7 +130,7 @@ bool FTermLinux::setPalette (FColor, int, int, int) #endif //---------------------------------------------------------------------- -bool FTermLinux::isLinuxConsole() +bool FTermLinux::isLinuxConsole() const { // Check if it's a Linux console @@ -484,7 +484,7 @@ FKey FTermLinux::modifierKeyCorrection (const FKey& key_id) // private methods of FTermLinux //---------------------------------------------------------------------- -int FTermLinux::getFramebuffer_bpp() +int FTermLinux::getFramebuffer_bpp() const { int fd{-1}; const char* fb = "/dev/fb/0"; @@ -707,7 +707,7 @@ int FTermLinux::setScreenFont ( const uChar fontdata[], uInt count } //---------------------------------------------------------------------- -int FTermLinux::setUnicodeMap (struct unimapdesc* unimap) +int FTermLinux::setUnicodeMap (struct unimapdesc* unimap) const { struct unimapinit advice; const int fd_tty = FTerm::getTTYFileDescriptor(); @@ -751,7 +751,7 @@ void FTermLinux::setLinuxCursorStyle (CursorStyle style) const #if defined(ISA_SYSCTL_SUPPORT) //---------------------------------------------------------------------- -inline uInt16 FTermLinux::getInputStatusRegisterOne() +inline uInt16 FTermLinux::getInputStatusRegisterOne() const { // Gets the VGA input-status-register-1 @@ -1271,7 +1271,7 @@ FKey FTermLinux::shiftCtrlAltKeyCorrection (const FKey& key_id) const } //---------------------------------------------------------------------- -inline void FTermLinux::initSpecialCharacter() +inline void FTermLinux::initSpecialCharacter() const { const auto& fterm_data = FTerm::getFTermData(); const wchar_t c1 = fc::UpperHalfBlock; @@ -1311,7 +1311,7 @@ sInt16 FTermLinux::getFontPos (wchar_t ucs) const //---------------------------------------------------------------------- void FTermLinux::characterFallback ( wchar_t ucs - , std::vector fallback ) + , std::vector fallback ) const { constexpr sInt16 NOT_FOUND = -1; const auto& fterm_data = FTerm::getFTermData(); diff --git a/src/fvterm.cpp b/src/fvterm.cpp index a1bafe16..53577070 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -298,14 +298,14 @@ bool FVTerm::updateTerminal() const //---------------------------------------------------------------------- void FVTerm::addPreprocessingHandler ( const FVTerm* instance - , const FPreprocessingFunction& function ) + , FPreprocessingFunction&& function ) { if ( ! print_area ) FVTerm::getPrintArea(); if ( print_area ) { - FVTermPreprocessing obj{ instance, function }; + FVTermPreprocessing obj{ instance, std::move(function) }; delPreprocessingHandler (instance); print_area->preproc_list.emplace_back(std::move(obj)); } @@ -325,7 +325,7 @@ void FVTerm::delPreprocessingHandler (const FVTerm* instance) while ( iter != print_area->preproc_list.end() ) { if ( iter->instance.get() == instance ) - iter = std::move(print_area->preproc_list.erase(iter)); + iter = print_area->preproc_list.erase(iter); else ++iter; } diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 4317d63b..e117059d 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -1149,12 +1149,12 @@ FVTerm::FTermArea* FWidget::getPrintArea() //---------------------------------------------------------------------- void FWidget::addPreprocessingHandler ( const FVTerm* instance - , const FPreprocessingFunction& function ) + , FPreprocessingFunction&& function ) { if ( ! getCurrentPrintArea() ) FWidget::getPrintArea(); - FVTerm::addPreprocessingHandler (instance, function); + FVTerm::addPreprocessingHandler (instance, std::move(function)); } //---------------------------------------------------------------------- @@ -1781,8 +1781,6 @@ void FWidget::finish() delete window_list; window_list = nullptr; } - - destroyColorTheme(); } //---------------------------------------------------------------------- @@ -2061,13 +2059,6 @@ void FWidget::initColorTheme() } } -//---------------------------------------------------------------------- -void FWidget::destroyColorTheme() -{ - const FWidgetColorsPtr* theme = &(getColorTheme()); - delete theme; -} - //---------------------------------------------------------------------- void FWidget::removeQueuedEvent() const { diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index 733a7ade..d405ccba 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -162,7 +162,7 @@ class FApplication : public FWidget using CmdOption = struct option; #endif - // Typedefs + // Using-declaration using EventPair = std::pair; using FEventQueue = std::deque; using CmdMap = std::unordered_map>; diff --git a/src/include/final/fcallback.h b/src/include/final/fcallback.h index a493a13b..5341c760 100644 --- a/src/include/final/fcallback.h +++ b/src/include/final/fcallback.h @@ -211,8 +211,8 @@ class FCallback void emitCallback (const FString& emit_signal) const; private: - // Typedefs - typedef std::vector FCallbackObjects; + // Using-declaration + using FCallbackObjects = std::vector; // Data members FCallbackObjects callback_objects{}; diff --git a/src/include/final/fcolorpalette.h b/src/include/final/fcolorpalette.h index 63387705..1c5b2a48 100644 --- a/src/include/final/fcolorpalette.h +++ b/src/include/final/fcolorpalette.h @@ -49,8 +49,8 @@ namespace finalcut class FColorPalette { public: - // Typedef - typedef std::function FSetPalette; + // Using-declaration + using FSetPalette = std::function; // Constructor explicit FColorPalette (const FSetPalette&); diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index 4916ac44..26a44ebb 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -155,15 +155,14 @@ class FDialog : public FWindow void onClose (FCloseEvent*) override; private: - // Typedef - typedef struct + struct MouseStates { int mouse_x; int mouse_y; FPoint termPos; std::size_t zoom_btn; bool mouse_over_menu; - } MouseStates; + }; // Constant static constexpr std::size_t MENU_BTN = 3; diff --git a/src/include/final/ffiledialog.h b/src/include/final/ffiledialog.h index aa6acda5..20902290 100644 --- a/src/include/final/ffiledialog.h +++ b/src/include/final/ffiledialog.h @@ -138,7 +138,6 @@ class FFileDialog : public FDialog void adjustSize() override; private: - // Typedef struct FDirEntry { // Constructor @@ -183,7 +182,7 @@ class FFileDialog : public FDialog uChar : 1; // padding bits }; - typedef std::vector DirEntries; + using DirEntries = std::vector; // Methods void init(); diff --git a/src/include/final/fkeyboard.h b/src/include/final/fkeyboard.h index bf86002d..e1e91d8f 100644 --- a/src/include/final/fkeyboard.h +++ b/src/include/final/fkeyboard.h @@ -88,8 +88,8 @@ class FKeyboard final // Constants static constexpr std::size_t FIFO_BUF_SIZE{512}; - // Typedef - typedef char keybuffer[FIFO_BUF_SIZE]; + // Using-declaration + using keybuffer = char[FIFO_BUF_SIZE]; // Constructor FKeyboard(); diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index 0d27a1ae..714a46e5 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -169,9 +169,7 @@ class FListBox : public FWidget public: // Using-declaration using FWidget::setGeometry; - - // Typedef - typedef std::vector FListBoxItems; + using FListBoxItems = std::vector; // Constructor explicit FListBox (FWidget* = nullptr); @@ -276,10 +274,10 @@ class FListBox : public FWidget void adjustSize() override; private: - // Typedefs - typedef std::unordered_map> KeyMap; - typedef std::unordered_map> KeyMapResult; - typedef std::function LazyInsert; + // Using-declaration + using KeyMap = std::unordered_map>; + using KeyMapResult = std::unordered_map>; + using LazyInsert = std::function; // Enumeration enum convert_type diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index 7db08aa4..ccdf926c 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -48,6 +48,7 @@ #endif #include +#include #include #include #include @@ -214,17 +215,20 @@ class FListViewIterator { public: // Using-declarations - using FObjectList = std::list; - using iterator = FObjectList::iterator; - using iterator_stack = std::stack; + using FObjectList = std::list; + using Iterator = FObjectList::iterator; + using IteratorStack = std::stack; // Constructor FListViewIterator () = default; - FListViewIterator (iterator); + FListViewIterator (Iterator); FListViewIterator (const FListViewIterator&) = default; - FListViewIterator (FListViewIterator&& ) - noexcept (std::is_nothrow_move_constructible::value) - = default; + FListViewIterator (FListViewIterator&& i) noexcept + : iter_path{std::move(i.iter_path)} + , node{i.node} + , position{i.position} + { } + // Overloaded operators FListViewIterator& operator = (const FListViewIterator&) = default; FListViewIterator& operator = (FListViewIterator&&) noexcept = default; @@ -248,12 +252,12 @@ class FListViewIterator private: // Methods - void nextElement (iterator&); - void prevElement (iterator&); + void nextElement (Iterator&); + void prevElement (Iterator&); // Data members - iterator_stack iter_path{}; - iterator node{}; + IteratorStack iter_path{}; + Iterator node{}; int position{0}; }; @@ -293,9 +297,7 @@ class FListView : public FWidget public: // Using-declaration using FWidget::setGeometry; - - // Typedef - typedef std::list FListViewItems; + using FListViewItems = std::list; // Constructor explicit FListView (FWidget* = nullptr); @@ -401,18 +403,17 @@ class FListView : public FWidget void adjustSize() override; private: - // Typedefs - typedef std::unordered_map> KeyMap; - typedef std::unordered_map> KeyMapResult; + struct Header; // forward declaration + + // Using-declaration + using KeyMap = std::unordered_map>; + using KeyMapResult = std::unordered_map>; + using HeaderItems = std::vector
; + using SortTypes = std::vector; // Constants static constexpr std::size_t checkbox_space = 4; - // Typedef - struct Header; // forward declaration - typedef std::vector
HeaderItems; - typedef std::vector SortTypes; - // Constants static constexpr int USE_MAX_SIZE = -1; diff --git a/src/include/final/fmenu.h b/src/include/final/fmenu.h index 81bd4cb1..b745b584 100644 --- a/src/include/final/fmenu.h +++ b/src/include/final/fmenu.h @@ -132,12 +132,7 @@ class FMenu : public FWindow, public FMenuList void cb_menuitemToggled (const FMenuItem*) const; private: - // Constants - static constexpr auto NOT_SET = static_cast(-1); - static constexpr bool SELECT_ITEM = true; - - // Typedef - typedef struct + struct MouseStates { uChar focus_changed : 1; uChar hide_sub_menu : 1; @@ -146,14 +141,18 @@ class FMenu : public FWindow, public FMenuList uChar mouse_over_supermenu : 1; uChar mouse_over_menubar : 1; uChar : 2; // padding bits - } MouseStates; + }; - typedef struct + struct MenuText { FString text; std::size_t hotkeypos; bool no_underline; - } MenuText; + }; + + // Constants + static constexpr auto NOT_SET = static_cast(-1); + static constexpr bool SELECT_ITEM = true; // Accessors FWidget* getSuperMenu() const; diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index b0616c7d..1891e13a 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -122,8 +122,7 @@ class FMouseData void clearButtonState(); protected: - // Typedef and Enumerations - typedef struct + struct FMouseButton // bit field { uChar left_button : 2; // 0..3 uChar right_button : 2; // 0..3 @@ -135,8 +134,9 @@ class FMouseData uChar wheel_down : 1; // 0..1 uChar mouse_moved : 1; // 0..1 uChar : 4; // padding bits - } FMouseButton; // bit field + }; + // Enumerations enum states { Undefined = 0, diff --git a/src/include/final/foptiattr.h b/src/include/final/foptiattr.h index cfa48398..18af4e5e 100644 --- a/src/include/final/foptiattr.h +++ b/src/include/final/foptiattr.h @@ -159,15 +159,16 @@ class FOptiAttr final const char* changeAttribute (FChar&, FChar&); private: - // Typedefs and Enumerations - typedef SGRoptimizer::AttributeBuffer AttributeBuffer; - - typedef struct + struct Capability { const char* cap; bool caused_reset; - } Capability; + }; + // Using-declaration + using AttributeBuffer = SGRoptimizer::AttributeBuffer; + + // Enumerations enum init_reset_tests { no_test = 0x00, diff --git a/src/include/final/foptimove.h b/src/include/final/foptimove.h index c9003fee..4dc24953 100644 --- a/src/include/final/foptimove.h +++ b/src/include/final/foptimove.h @@ -57,8 +57,7 @@ namespace finalcut class FOptiMove final { public: - // Typedef - typedef struct + struct TermEnv { const char* t_cursor_home; const char* t_carriage_return; @@ -83,7 +82,7 @@ class FOptiMove final int tabstop; bool automatic_left_margin; bool eat_nl_glitch; - } TermEnv; + }; // Constructor explicit FOptiMove (int = 0); @@ -147,16 +146,15 @@ class FOptiMove final const char* moveCursor (int, int, int, int); private: - // Constant - static constexpr std::size_t BUF_SIZE{512}; - - // Typedef - typedef struct + struct Capability { const char* cap; int duration; int length; - } Capability; + }; + + // Constant + static constexpr std::size_t BUF_SIZE{512}; // Constants static constexpr int LONG_DURATION{INT_MAX}; diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index a019e2f1..23c82fa2 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -149,8 +149,8 @@ class FScrollView : public FWidget void copy2area(); private: - // Typedefs - typedef std::unordered_map> KeyMap; + // Using-declaration + using KeyMap = std::unordered_map>; // Constants static constexpr int vertical_border_spacing = 2; diff --git a/src/include/final/fstatusbar.h b/src/include/final/fstatusbar.h index 7b7cc1c3..4b0f1f95 100644 --- a/src/include/final/fstatusbar.h +++ b/src/include/final/fstatusbar.h @@ -230,8 +230,8 @@ class FStatusBar : public FWindow void cb_statuskey_activated (const FStatusKey*); private: - // Typedef - typedef std::vector FKeyList; + // Using-declaration + using FKeyList = std::vector; // Methods void init(); diff --git a/src/include/final/fstringstream.h b/src/include/final/fstringstream.h index dfd994a6..6635e549 100644 --- a/src/include/final/fstringstream.h +++ b/src/include/final/fstringstream.h @@ -72,7 +72,7 @@ class FStringStream : public std::wiostream FStringStream (FStringStream&&) noexcept; // Destructor - ~FStringStream() noexcept; + ~FStringStream() noexcept override; // Disable copy assignment operator (=) FStringStream& operator = (const FStringStream&) = delete; diff --git a/src/include/final/fterm.h b/src/include/final/fterm.h index cf1379a1..10cabb62 100644 --- a/src/include/final/fterm.h +++ b/src/include/final/fterm.h @@ -251,7 +251,7 @@ class FTerm final static bool canChangeColorPalette(); // Mutators - static void setFSystem (std::unique_ptr&&); + static void setFSystem (std::unique_ptr&); static void setTermType (const char[]); static void setInsertCursor (bool); static void setInsertCursor(); @@ -391,7 +391,7 @@ inline FString FTerm::getClassName() { return "FTerm"; } //---------------------------------------------------------------------- -inline void FTerm::setFSystem (std::unique_ptr&& fsystem) +inline void FTerm::setFSystem (std::unique_ptr& fsystem) { getFSystem().swap(fsystem); } diff --git a/src/include/final/ftermcap.h b/src/include/final/ftermcap.h index dc30ec31..45c77363 100644 --- a/src/include/final/ftermcap.h +++ b/src/include/final/ftermcap.h @@ -75,13 +75,11 @@ namespace finalcut class FTermcap final { public: - // Typedef - typedef struct + struct TCapMap { const char* string; char tname[alignof(char*)]; - } - TCapMap; + }; // Using-declaration using fn_putc = int (*)(int); diff --git a/src/include/final/ftermdata.h b/src/include/final/ftermdata.h index 3b77b4fc..ced0c4ff 100644 --- a/src/include/final/ftermdata.h +++ b/src/include/final/ftermdata.h @@ -53,8 +53,8 @@ namespace finalcut class FTermData final { public: - // Typedefs - typedef std::unordered_map EncodingMap; + // Using-declaration + using EncodingMap = std::unordered_map; // Constructors FTermData () = default; diff --git a/src/include/final/ftermlinux.h b/src/include/final/ftermlinux.h index efaa0e32..386ceb80 100644 --- a/src/include/final/ftermlinux.h +++ b/src/include/final/ftermlinux.h @@ -99,7 +99,7 @@ class FTermLinux final void setUTF8 (bool) const; // Inquiries - bool isLinuxConsole(); + bool isLinuxConsole() const; bool isVGAFontUsed() const; bool isNewFontUsed() const; @@ -140,7 +140,7 @@ class FTermLinux final }; // Accessors - int getFramebuffer_bpp(); + int getFramebuffer_bpp() const; bool getScreenFont(); bool getUnicodeMap (); ModifierKey& getModifierKey(); @@ -148,12 +148,12 @@ class FTermLinux final // Mutators int setScreenFont ( const uChar[], uInt, uInt, uInt , bool = false ); - int setUnicodeMap (struct unimapdesc*); + int setUnicodeMap (struct unimapdesc*) const; void setLinuxCursorStyle (fc::linuxConsoleCursorStyle) const; // Methods #if defined(ISA_SYSCTL_SUPPORT) - uInt16 getInputStatusRegisterOne(); + uInt16 getInputStatusRegisterOne() const; uChar readAttributeController (uChar); void writeAttributeController (uChar, uChar); uChar getAttributeMode(); @@ -174,8 +174,8 @@ class FTermLinux final FKey ctrlAltKeyCorrection (const FKey&) const; FKey shiftCtrlAltKeyCorrection (const FKey&) const; sInt16 getFontPos (wchar_t ucs) const; - void initSpecialCharacter(); - void characterFallback (wchar_t, std::vector); + void initSpecialCharacter() const; + void characterFallback (wchar_t, std::vector) const; // Data members #if defined(__linux__) diff --git a/src/include/final/ftermopenbsd.h b/src/include/final/ftermopenbsd.h index 43dabe28..aa7deb08 100644 --- a/src/include/final/ftermopenbsd.h +++ b/src/include/final/ftermopenbsd.h @@ -47,7 +47,7 @@ #define WSKBD_BELL_DOVOLUME 0x4 // get/set volume #define WSKBD_BELL_DOALL 0x7 // all of the above - typedef uInt32 kbd_t; + using kbd_t = uInt32; struct wskbd_bell_data { diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index 6ddd3946..2be73fc4 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -137,8 +137,8 @@ class FTextView : public FWidget void adjustSize() override; private: - // Typedefs - typedef std::unordered_map> KeyMap; + // Using-declaration + using KeyMap = std::unordered_map>; // Accessors std::size_t getTextHeight() const; diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index 6270a1fc..0a518372 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -97,7 +97,7 @@ class FVTerm // Using-declarations using FPreprocessingHandler = void (FVTerm::*)(); - using FPreprocessingFunction = std::function ; + using FPreprocessingFunction = std::function; using FPreprocessing = std::vector; // Enumerations @@ -253,7 +253,7 @@ class FVTerm void putVTerm() const; bool updateTerminal() const; virtual void addPreprocessingHandler ( const FVTerm* - , const FPreprocessingFunction& ); + , FPreprocessingFunction&& ); virtual void delPreprocessingHandler (const FVTerm*); template int printf (const FString&, Args&&...); @@ -491,7 +491,9 @@ struct FVTerm::FTermArea // define virtual terminal character properties struct D { void operator () (const FVTerm*) const - { } + { + // No deleting of pointer objects when exiting the std::unique_ptr + } }; //---------------------------------------------------------------------- @@ -501,9 +503,9 @@ struct D struct FVTerm::FVTermPreprocessing { // Constructor - FVTermPreprocessing (const FVTerm* i, const FPreprocessingFunction& f) + FVTermPreprocessing (const FVTerm* i, FPreprocessingFunction&& f) : instance(std::unique_ptr(i)) - , function(f) + , function(std::move(f)) { } FVTermPreprocessing (const FVTermPreprocessing&) = delete; diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index 187aea0d..9e1da773 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -136,7 +136,6 @@ class FWidget : public FVTerm, public FObject using FVTerm::print; using FWidgetList = std::vector; using FAcceleratorList = std::vector; - using FWidgetColorsPtr = std::shared_ptr; struct FWidgetFlags // Properties of a widget ⚑ { @@ -187,7 +186,7 @@ class FWidget : public FVTerm, public FObject static FWidgetList*& getWindowList(); static FMenuBar* getMenuBar(); static FStatusBar* getStatusBar(); - static FWidgetColorsPtr& getColorTheme(); + static auto getColorTheme() -> std::shared_ptr&; virtual FWidget* getFirstFocusableWidget (FObjectList); virtual FWidget* getLastFocusableWidget (FObjectList); const FAcceleratorList& getAcceleratorList() const; @@ -338,7 +337,7 @@ class FWidget : public FVTerm, public FObject static FWidgetList*& getAlwaysOnTopList(); static FWidgetList*& getWidgetCloseList(); void addPreprocessingHandler ( const FVTerm* - , const FPreprocessingFunction& ) override; + , FPreprocessingFunction&& ) override; void delPreprocessingHandler (const FVTerm*) override; // Inquiry @@ -443,7 +442,6 @@ class FWidget : public FVTerm, public FObject void drawChildren(); static bool isDefaultTheme(); static void initColorTheme(); - void destroyColorTheme(); void removeQueuedEvent() const; void setStatusbarText (bool) const; @@ -573,9 +571,9 @@ inline FStatusBar* FWidget::getStatusBar() { return statusbar; } //---------------------------------------------------------------------- -inline FWidget::FWidgetColorsPtr& FWidget::getColorTheme() +inline auto FWidget::getColorTheme() -> std::shared_ptr& { - static auto color_theme = new FWidgetColorsPtr(); + static const auto& color_theme = make_unique>(); return *color_theme; } diff --git a/src/include/final/sgr_optimizer.h b/src/include/final/sgr_optimizer.h index 67a604b2..700c7320 100644 --- a/src/include/final/sgr_optimizer.h +++ b/src/include/final/sgr_optimizer.h @@ -51,8 +51,8 @@ class SGRoptimizer final // Constants static constexpr std::size_t ATTR_BUF_SIZE{8192}; - // Typedefs - typedef std::array AttributeBuffer; + // Using-declaration + using AttributeBuffer = std::array; // Constructors explicit SGRoptimizer (AttributeBuffer&); diff --git a/test/ftermfreebsd-test.cpp b/test/ftermfreebsd-test.cpp index 640a2894..0a87ab47 100644 --- a/test/ftermfreebsd-test.cpp +++ b/test/ftermfreebsd-test.cpp @@ -623,8 +623,8 @@ void ftermfreebsdTest::freebsdConsoleTest() setenv ("COLUMNS", "80", 1); setenv ("LINES", "25", 1); - auto fsys = finalcut::make_unique(); - finalcut::FTerm::setFSystem(std::move(fsys)); + std::unique_ptr fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(fsys); std::cout << "\n"; const auto& data = finalcut::FTerm::getFTermData(); diff --git a/test/ftermlinux-test.cpp b/test/ftermlinux-test.cpp index de4a49ba..820eca94 100644 --- a/test/ftermlinux-test.cpp +++ b/test/ftermlinux-test.cpp @@ -1559,8 +1559,8 @@ void FTermLinuxTest::classNameTest() //---------------------------------------------------------------------- void FTermLinuxTest::linuxConsoleTest() { - auto fsys = finalcut::make_unique(); - finalcut::FTerm::setFSystem(std::move(fsys)); + std::unique_ptr fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(fsys); std::cout << "\n"; const auto& data = finalcut::FTerm::getFTermData(); @@ -1681,8 +1681,8 @@ void FTermLinuxTest::linuxConsoleTest() //---------------------------------------------------------------------- void FTermLinuxTest::linuxCursorStyleTest() { - auto fsys = finalcut::make_unique(); - finalcut::FTerm::setFSystem(std::move(fsys)); + std::unique_ptr fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(fsys); std::cout << "\n"; const auto& data = finalcut::FTerm::getFTermData(); @@ -1870,8 +1870,8 @@ void FTermLinuxTest::linuxCursorStyleTest() //---------------------------------------------------------------------- void FTermLinuxTest::linuxColorPaletteTest() { - auto fsys = finalcut::make_unique(); - finalcut::FTerm::setFSystem(std::move(fsys)); + std::unique_ptr fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(fsys); std::cout << "\n"; const auto& data = finalcut::FTerm::getFTermData(); @@ -2145,8 +2145,8 @@ void FTermLinuxTest::linuxColorPaletteTest() //---------------------------------------------------------------------- void FTermLinuxTest::linuxFontTest() { - auto fsys = finalcut::make_unique(); - finalcut::FTerm::setFSystem(std::move(fsys)); + std::unique_ptr fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(fsys); std::cout << "\n"; const auto& data = finalcut::FTerm::getFTermData(); @@ -2288,8 +2288,8 @@ void FTermLinuxTest::linuxFontTest() //---------------------------------------------------------------------- void FTermLinuxTest::modifierKeyTest() { - auto fsys = finalcut::make_unique(); - finalcut::FTerm::setFSystem(std::move(fsys)); + std::unique_ptr fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(fsys); const auto& fsystem = finalcut::FTerm::getFSystem(); auto fsystest = static_cast(fsystem.get()); diff --git a/test/ftermopenbsd-test.cpp b/test/ftermopenbsd-test.cpp index 9201aaba..f190e225 100644 --- a/test/ftermopenbsd-test.cpp +++ b/test/ftermopenbsd-test.cpp @@ -345,8 +345,8 @@ void ftermopenbsdTest::classNameTest() //---------------------------------------------------------------------- void ftermopenbsdTest::netbsdConsoleTest() { - auto fsys = finalcut::make_unique(); - finalcut::FTerm::setFSystem(std::move(fsys)); + std::unique_ptr fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(fsys); std::cout << "\n"; const auto& data = finalcut::FTerm::getFTermData(); @@ -449,8 +449,8 @@ void ftermopenbsdTest::netbsdConsoleTest() //---------------------------------------------------------------------- void ftermopenbsdTest::openbsdConsoleTest() { - auto fsys = finalcut::make_unique(); - finalcut::FTerm::setFSystem(std::move(fsys)); + std::unique_ptr fsys = finalcut::make_unique(); + finalcut::FTerm::setFSystem(fsys); std::cout << "\n"; const auto& data = finalcut::FTerm::getFTermData(); From c4b799d98f29a10572716d7e4abb909a57f9eb16 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 5 Dec 2020 21:24:09 +0100 Subject: [PATCH 06/45] Fixed: build with gcc < 5.5 --- examples/7segment.cpp | 2 +- examples/background-color.cpp | 8 ++-- examples/input-dialog.cpp | 2 +- examples/listview.cpp | 6 +-- examples/ui.cpp | 18 ++++---- src/fapplication.cpp | 18 ++++---- src/fdialog.cpp | 12 ++--- src/ffiledialog.cpp | 18 ++++---- src/flineedit.cpp | 24 +++++----- src/fmenubar.cpp | 12 ++--- src/fmessagebox.cpp | 73 ++++++++++++++----------------- src/frect.cpp | 4 +- src/fstartoptions.cpp | 3 -- src/ftermlinux.cpp | 6 +-- src/fvterm.cpp | 51 ++++++++++----------- src/fwindow.cpp | 4 +- src/include/final/fcombobox.h | 9 ++-- src/include/final/fdata.h | 12 ++--- src/include/final/fdialog.h | 8 ++-- src/include/final/ffiledialog.h | 6 +-- src/include/final/flineedit.h | 54 +++++++++++------------ src/include/final/flistview.h | 1 + src/include/final/fmenubar.h | 2 +- src/include/final/fmessagebox.h | 56 +++++++++++++----------- src/include/final/fpoint.h | 6 +-- src/include/final/frect.h | 10 ++--- src/include/final/fsize.h | 6 +-- src/include/final/fspinbox.h | 9 ++-- src/include/final/fstartoptions.h | 1 - src/include/final/ftermlinux.h | 6 +-- src/include/final/fvterm.h | 18 ++++---- 31 files changed, 234 insertions(+), 231 deletions(-) diff --git a/examples/7segment.cpp b/examples/7segment.cpp index b2021d74..41da4a7d 100644 --- a/examples/7segment.cpp +++ b/examples/7segment.cpp @@ -85,7 +85,7 @@ SegmentView::SegmentView (finalcut::FWidget* parent) input.setGeometry (FPoint(2, 2), FSize{12, 1}); input.setLabelText (L"&Hex value"); input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)"); - input.setLabelOrientation(finalcut::FLineEdit::label_above); + input.setLabelOrientation(finalcut::FLineEdit::LabelOrientation::above); input.setMaxLength(9); input.setInputFilter("[:.hHlLpPuU[:xdigit:]]"); diff --git a/examples/background-color.cpp b/examples/background-color.cpp index 97c49f3a..944f8e22 100644 --- a/examples/background-color.cpp +++ b/examples/background-color.cpp @@ -99,7 +99,7 @@ Background::Background (finalcut::FWidget* parent) // Combobox color_choice.setGeometry (FPoint{2, 2}, FSize{18, 1}); - color_choice.setLabelOrientation (finalcut::FLineEdit::label_above); + color_choice.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above); color_choice.setLabelText ("Color choice"); color_choice.unsetEditable(); @@ -111,19 +111,19 @@ Background::Background (finalcut::FWidget* parent) // Spin boxes red.setGeometry (FPoint{2, 5}, FSize{7, 1}); - red.setLabelOrientation (finalcut::FLineEdit::label_above); + red.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above); red.setLabelText ("Red"); red.setRange (0, 255); red.setValue (0x80); green.setGeometry (FPoint{12, 5}, FSize{7, 1}); - green.setLabelOrientation (finalcut::FLineEdit::label_above); + green.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above); green.setLabelText ("Green"); green.setRange (0, 255); green.setValue (0xa4); blue.setGeometry (FPoint{22, 5}, FSize{7, 1}); - blue.setLabelOrientation (finalcut::FLineEdit::label_above); + blue.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above); blue.setLabelText ("Blue"); blue.setRange (0, 255); blue.setValue (0xec); diff --git a/examples/input-dialog.cpp b/examples/input-dialog.cpp index c4bb2245..0a496060 100644 --- a/examples/input-dialog.cpp +++ b/examples/input-dialog.cpp @@ -76,7 +76,7 @@ int main (int argc, char* argv[]) finalcut::FLineEdit c_field {&dgl}; // Set input type to password - pw_field.setInputType (finalcut::FLineEdit::password); + pw_field.setInputType (finalcut::FLineEdit::InputType::password); name_field.setLabelText (L"&Name"); pw_field.setLabelText (L"&Password"); diff --git a/examples/listview.cpp b/examples/listview.cpp index d039a82b..ca4f80b7 100644 --- a/examples/listview.cpp +++ b/examples/listview.cpp @@ -194,9 +194,9 @@ void Listview::cb_showInMessagebox() "Temperature: " + item->getText(3) + "\n" " Humidity: " + item->getText(4) + "\n" " Pressure: " + item->getText(5) - , finalcut::FMessageBox::Ok - , finalcut::FMessageBox::Reject - , finalcut::FMessageBox::Reject + , finalcut::FMessageBox::ButtonType::Ok + , finalcut::FMessageBox::ButtonType::Reject + , finalcut::FMessageBox::ButtonType::Reject , this ); info.show(); } diff --git a/examples/ui.cpp b/examples/ui.cpp index 5f7d128a..5b9e5094 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -809,9 +809,9 @@ void MyDialog::cb_about() , line + L" FINAL CUT " + line + L"\n\n" L"Version " + libver + L"\n\n" L"(c) 2020 by Markus Gans" - , finalcut::FMessageBox::Ok - , finalcut::FMessageBox::Reject - , finalcut::FMessageBox::Reject + , finalcut::FMessageBox::ButtonType::Ok + , finalcut::FMessageBox::ButtonType::Reject + , finalcut::FMessageBox::ButtonType::Reject , this ); info.setCenterText(); info.show(); @@ -832,9 +832,9 @@ void MyDialog::cb_terminfo() << " Size: " << x << fc::Times << y << "\n" << "Colors: " << finalcut::FTerm::getMaxColor() - , finalcut::FMessageBox::Ok - , finalcut::FMessageBox::Reject - , finalcut::FMessageBox::Reject + , finalcut::FMessageBox::ButtonType::Ok + , finalcut::FMessageBox::ButtonType::Reject + , finalcut::FMessageBox::ButtonType::Reject , this ); info1.setHeadline("Terminal:"); @@ -850,9 +850,9 @@ void MyDialog::cb_drives() , "Generic: \n\n" "Network: \n\n" " CD:" - , finalcut::FMessageBox::Ok - , finalcut::FMessageBox::Reject - , finalcut::FMessageBox::Reject + , finalcut::FMessageBox::ButtonType::Ok + , finalcut::FMessageBox::ButtonType::Reject + , finalcut::FMessageBox::ButtonType::Reject , this ); diff --git a/src/fapplication.cpp b/src/fapplication.cpp index a1397e7a..ee744e0e 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -365,12 +365,14 @@ void FApplication::setKeyboardWidget (FWidget* widget) void FApplication::closeConfirmationDialog (FWidget* w, FCloseEvent* ev) { internal::var::app_object->unsetMoveSizeMode(); - const int ret = FMessageBox::info ( w, "Quit" - , "Do you really want\n" - "to quit the program ?" - , FMessageBox::Yes - , FMessageBox::No ); - if ( ret == FMessageBox::Yes ) + const FMessageBox::ButtonType ret = \ + FMessageBox::info ( w, "Quit" + , "Do you really want\n" + "to quit the program ?" + , FMessageBox::ButtonType::Yes + , FMessageBox::ButtonType::No ); + + if ( ret == FMessageBox::ButtonType::Yes ) ev->accept(); else { @@ -1265,7 +1267,7 @@ void FApplication::processCloseWidget() if ( ! getWidgetCloseList() || getWidgetCloseList()->empty() ) return; - setTerminalUpdates (FVTerm::stop_terminal_updates); + setTerminalUpdates (FVTerm::TerminalUpdate::Stop); auto iter = getWidgetCloseList()->begin(); while ( iter != getWidgetCloseList()->end() && *iter ) @@ -1275,7 +1277,7 @@ void FApplication::processCloseWidget() } getWidgetCloseList()->clear(); - setTerminalUpdates (FVTerm::start_terminal_updates); + setTerminalUpdates (FVTerm::TerminalUpdate::Start); } //---------------------------------------------------------------------- diff --git a/src/fdialog.cpp b/src/fdialog.cpp index de57a594..6f522fb7 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -189,9 +189,9 @@ void FDialog::hide() } //---------------------------------------------------------------------- -int FDialog::exec() +FDialog::ResultCode FDialog::exec() { - result_code = FDialog::Reject; + result_code = ResultCode::Reject; show(); return result_code; } @@ -484,7 +484,7 @@ void FDialog::onKeyPress (FKeyEvent* ev) ev->accept(); if ( isModal() ) - done (FDialog::Reject); + done (ResultCode::Reject); else close(); } @@ -664,7 +664,7 @@ void FDialog::onMouseDoubleClick (FMouseEvent* ev) setClickedWidget(nullptr); if ( isModal() ) - done (FDialog::Reject); + done (ResultCode::Reject); else close(); } @@ -761,7 +761,7 @@ void FDialog::onWindowLowered (FEvent*) // protected methods of FDialog //---------------------------------------------------------------------- -void FDialog::done(int result) +void FDialog::done (ResultCode result) { hide(); result_code = result; @@ -807,7 +807,7 @@ void FDialog::drawDialogShadow() void FDialog::onClose (FCloseEvent* ev) { ev->accept(); - result_code = FDialog::Reject; + result_code = ResultCode::Reject; } diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 6b7cf9e7..4dbc97e2 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -81,7 +81,7 @@ FString fileChooser ( FWidget* parent , type , parent ); - if ( fileopen.exec() == FDialog::Accept ) + if ( fileopen.exec() == FDialog::ResultCode::Accept ) ret = fileopen.getPath() + fileopen.getSelectedFile(); else ret = FString{}; @@ -261,7 +261,7 @@ FString FFileDialog::fileOpenChooser ( FWidget* parent , const FString& dirname , const FString& filter ) { - return fileChooser (parent, dirname, filter, FFileDialog::Open); + return fileChooser (parent, dirname, filter, DialogType::Open); } //---------------------------------------------------------------------- @@ -269,7 +269,7 @@ FString FFileDialog::fileSaveChooser ( FWidget* parent , const FString& dirname , const FString& filter ) { - return fileChooser (parent, dirname, filter, FFileDialog::Save); + return fileChooser (parent, dirname, filter, DialogType::Save); } @@ -334,7 +334,7 @@ void FFileDialog::init() else x = y = 1; - if ( dlg_type == FFileDialog::Save ) + if ( dlg_type == DialogType::Save ) FDialog::setText("Save file"); else FDialog::setText("Open file"); @@ -362,7 +362,7 @@ inline void FFileDialog::widgetSettings (const FPoint& pos) cancel_btn.setText ("&Cancel"); cancel_btn.setGeometry(FPoint{19, 10}, FSize{9, 1}); - if ( dlg_type == FFileDialog::Save ) + if ( dlg_type == DialogType::Save ) open_btn.setText ("&Save"); else open_btn.setText ("&Open"); @@ -788,7 +788,7 @@ void FFileDialog::cb_processActivate() if ( found ) changeDir(input); else - done (FDialog::Accept); + done (ResultCode::Accept); } } @@ -818,19 +818,19 @@ void FFileDialog::cb_processClicked() if ( dir_entries[n].directory ) changeDir(dir_entries[n].name); else - done (FDialog::Accept); + done (ResultCode::Accept); } //---------------------------------------------------------------------- void FFileDialog::cb_processCancel() { - done (FDialog::Reject); + done (ResultCode::Reject); } //---------------------------------------------------------------------- void FFileDialog::cb_processOpen() { - done (FDialog::Accept); + done (ResultCode::Accept); } //---------------------------------------------------------------------- diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 2fc949bf..65d376f6 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -214,7 +214,7 @@ void FLineEdit::setLabelText (const FString& ltxt) } //---------------------------------------------------------------------- -void FLineEdit::setLabelOrientation (const label_o o) +void FLineEdit::setLabelOrientation (const LabelOrientation o) { label_orientation = o; adjustLabel(); @@ -610,15 +610,15 @@ void FLineEdit::adjustLabel() if ( hasHotkey() ) label_width--; - assert ( label_orientation == label_above - || label_orientation == label_left ); + assert ( label_orientation == LabelOrientation::above + || label_orientation == LabelOrientation::left ); - if ( label_orientation == label_above ) + if ( label_orientation == LabelOrientation::above ) { label->setGeometry ( FPoint{w->getX(), w->getY() - 1} , FSize{label_width, 1} ); } - else if ( label_orientation == label_left ) + else if ( label_orientation == LabelOrientation::left ) { label->setGeometry ( FPoint{w->getX() - int(label_width) - 1, w->getY()} , FSize{label_width, 1} ); @@ -710,15 +710,15 @@ void FLineEdit::drawInputField() const std::size_t text_offset_column = [this] () { - assert ( input_type == FLineEdit::textfield - || input_type == FLineEdit::password ); + assert ( input_type == InputType::textfield + || input_type == InputType::password ); switch ( input_type ) { - case FLineEdit::textfield: + case InputType::textfield: return printTextField(); - case FLineEdit::password: + case InputType::password: return printPassword(); } @@ -782,11 +782,11 @@ inline std::size_t FLineEdit::printPassword() //---------------------------------------------------------------------- inline std::size_t FLineEdit::getCursorColumnPos() const { - if ( input_type == FLineEdit::textfield ) + if ( input_type == InputType::textfield ) { return getColumnWidth (print_text, cursor_pos); } - else if ( input_type == FLineEdit::password ) + else if ( input_type == InputType::password ) { return cursor_pos; } @@ -803,7 +803,7 @@ inline FString FLineEdit::getPasswordText() const //---------------------------------------------------------------------- inline bool FLineEdit::isPasswordField() const { - return bool( input_type == FLineEdit::password ); + return bool( input_type == InputType::password ); } //---------------------------------------------------------------------- diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 50f899e1..0ca0f61c 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -312,7 +312,7 @@ bool FMenuBar::selectNextItem() if ( next == *iter ) return false; - setTerminalUpdates (FVTerm::stop_terminal_updates); + setTerminalUpdates (FVTerm::TerminalUpdate::Stop); unselectItem(); next->setSelected(); setSelectedItem(next); @@ -335,7 +335,7 @@ bool FMenuBar::selectNextItem() getStatusBar()->drawMessage(); redraw(); - setTerminalUpdates (FVTerm::start_terminal_updates); + setTerminalUpdates (FVTerm::TerminalUpdate::Start); forceTerminalUpdate(); break; } @@ -377,7 +377,7 @@ bool FMenuBar::selectPrevItem() if ( prev == *iter ) return false; - setTerminalUpdates (FVTerm::stop_terminal_updates); + setTerminalUpdates (FVTerm::TerminalUpdate::Stop); unselectItem(); prev->setSelected(); prev->setFocus(); @@ -400,7 +400,7 @@ bool FMenuBar::selectPrevItem() setSelectedItem(prev); redraw(); - setTerminalUpdates (FVTerm::start_terminal_updates); + setTerminalUpdates (FVTerm::TerminalUpdate::Start); forceTerminalUpdate(); break; } @@ -905,7 +905,7 @@ void FMenuBar::mouseMoveOverList (const FMouseEvent& ev) else { // Event handover to the menu - passEventToMenu(std::move(ev)); + passEventToMenu(ev); } } } @@ -926,7 +926,7 @@ void FMenuBar::mouseMoveOverList (const FMouseEvent& ev) } //---------------------------------------------------------------------- -void FMenuBar::passEventToMenu (const FMouseEvent&& ev) const +void FMenuBar::passEventToMenu (const FMouseEvent& ev) const { if ( ! hasSelectedItem() || ! getSelectedItem()->hasMenu() ) return; diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index 16cd26b4..a55cb3f2 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -51,31 +51,12 @@ constexpr std::array button_text = //---------------------------------------------------------------------- FMessageBox::FMessageBox (FWidget* parent) : FDialog{parent} - , button_digit{FMessageBox::Ok, FMessageBox::Reject, FMessageBox::Reject} + , button_digit{ButtonType::Ok, ButtonType::Reject, ButtonType::Reject} { setTitlebarText("Message for you"); init(); } -//---------------------------------------------------------------------- -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} - , button_digit{mbox.button_digit[0], - mbox.button_digit[1], - mbox.button_digit[2]} - , num_buttons{mbox.num_buttons} - , text_num_lines{mbox.text_num_lines} - , center_text{mbox.center_text} -{ - setTitlebarText (mbox.getTitlebarText()); - init(); -} - //---------------------------------------------------------------------- FMessageBox::FMessageBox ( const FString& caption , const FString& message @@ -151,15 +132,22 @@ void FMessageBox::setText (const FString& txt) if ( button[0] ) button[0]->setY (int(getHeight()) - 4, false); - if ( button[1] && button_digit[1] != FMessageBox::Reject ) + if ( button[1] && button_digit[1] != ButtonType::Reject ) button[1]->setY (int(getHeight()) - 4, false); - if ( button[2] && button_digit[2] != FMessageBox::Reject ) + if ( button[2] && button_digit[2] != ButtonType::Reject ) button[2]->setY (int(getHeight()) - 4, false); adjustButtons(); } +//---------------------------------------------------------------------- +FMessageBox::ButtonType FMessageBox::exec() +{ + result_code = ButtonType::Reject; + show(); + return result_code; +} // protected methods of FMessageBox //---------------------------------------------------------------------- @@ -187,10 +175,17 @@ void FMessageBox::adjustSize() FDialog::adjustSize(); } +//---------------------------------------------------------------------- +void FMessageBox::done (ButtonType result) +{ + hide(); + result_code = result; +} + //---------------------------------------------------------------------- void FMessageBox::cb_processClick (ButtonType reply) { - done(int(reply)); + done(reply); } @@ -200,21 +195,21 @@ void FMessageBox::init() { calculateDimensions(); - if ( (button_digit[2] != Reject && button_digit[1] == Reject) - || (button_digit[1] != Reject && button_digit[0] == Reject) ) + if ( (button_digit[2] != ButtonType::Reject && button_digit[1] == ButtonType::Reject) + || (button_digit[1] != ButtonType::Reject && button_digit[0] == ButtonType::Reject) ) { button_digit[0] = button_digit[1] \ = button_digit[2] \ - = FMessageBox::Reject; + = ButtonType::Reject; } - if ( button_digit[0] == FMessageBox::Reject ) - button_digit[0] = FMessageBox::Ok; + if ( button_digit[0] == ButtonType::Reject ) + button_digit[0] = ButtonType::Ok; - if ( button_digit[1] == FMessageBox::Reject - && button_digit[2] == FMessageBox::Reject ) + if ( button_digit[1] == ButtonType::Reject + && button_digit[2] == ButtonType::Reject ) num_buttons = 1; - else if ( button_digit[2] == FMessageBox::Reject ) + else if ( button_digit[2] == ButtonType::Reject ) num_buttons = 2; else num_buttons = 3; @@ -232,25 +227,25 @@ inline void FMessageBox::allocation() try { button[0].reset(new FButton (this)); - button[0]->setText(button_text[button_digit[0]]); + button[0]->setText(button_text[std::size_t(button_digit[0])]); button[0]->setPos(FPoint{3, int(getHeight()) - 4}, false); button[0]->setWidth(1, false); button[0]->setHeight(1, false); button[0]->setFocus(); - if ( button_digit[1] > FMessageBox::Reject ) + if ( button_digit[1] > ButtonType::Reject ) { button[1].reset(new FButton(this)); - button[1]->setText(button_text[button_digit[1]]); + button[1]->setText(button_text[std::size_t(button_digit[1])]); button[1]->setPos(FPoint{17, int(getHeight()) - 4}, false); button[1]->setWidth(0, false); button[1]->setHeight(1, false); } - if ( button_digit[2] > FMessageBox::Reject ) + if ( button_digit[2] > ButtonType::Reject ) { button[2].reset(new FButton(this)); - button[2]->setText(button_text[button_digit[2]]); + button[2]->setText(button_text[std::size_t(button_digit[2])]); button[2]->setPos(FPoint{32, int(getHeight()) - 4}, false); button[2]->setWidth(0, false); button[2]->setHeight(1, false); @@ -266,7 +261,7 @@ inline void FMessageBox::allocation() //---------------------------------------------------------------------- inline void FMessageBox::initCallbacks() { - if ( button[0] && button_digit[0] != FMessageBox::Reject ) + if ( button[0] && button_digit[0] != ButtonType::Reject ) { button[0]->addCallback ( @@ -276,7 +271,7 @@ inline void FMessageBox::initCallbacks() ); } - if ( button[1] && button_digit[1] != FMessageBox::Reject ) + if ( button[1] && button_digit[1] != ButtonType::Reject ) { button[1]->addCallback ( @@ -286,7 +281,7 @@ inline void FMessageBox::initCallbacks() ); } - if ( button[2] && button_digit[2] != FMessageBox::Reject ) + if ( button[2] && button_digit[2] != ButtonType::Reject ) { button[2]->addCallback ( diff --git a/src/frect.cpp b/src/frect.cpp index f02337f7..960db706 100644 --- a/src/frect.cpp +++ b/src/frect.cpp @@ -36,7 +36,7 @@ namespace finalcut // constructor and destructor //---------------------------------------------------------------------- -FRect::FRect (const FPoint& p, const FSize& s) +FRect::FRect (const FPoint& p, const FSize& s) noexcept : X1{p.getX()} , Y1{p.getY()} , X2{p.getX() + int(s.getWidth()) - 1} @@ -44,7 +44,7 @@ FRect::FRect (const FPoint& p, const FSize& s) { } //---------------------------------------------------------------------- -FRect::FRect (const FPoint& p1, const FPoint& p2) +FRect::FRect (const FPoint& p1, const FPoint& p2) noexcept : X1{p1.getX()} , Y1{p1.getY()} , X2{p2.getX()} diff --git a/src/fstartoptions.cpp b/src/fstartoptions.cpp index 196e65d3..375737db 100644 --- a/src/fstartoptions.cpp +++ b/src/fstartoptions.cpp @@ -27,9 +27,6 @@ namespace finalcut { -// static class attribute -FStartOptions* FStartOptions::start_options{}; - //---------------------------------------------------------------------- // class FStartOptions //---------------------------------------------------------------------- diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index b5f09306..c442fbb5 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -198,7 +198,7 @@ void FTermLinux::init() } //---------------------------------------------------------------------- -void FTermLinux::initCharMap() +void FTermLinux::initCharMap() const { constexpr sInt16 NOT_FOUND = -1; @@ -767,7 +767,7 @@ inline uInt16 FTermLinux::getInputStatusRegisterOne() const } //---------------------------------------------------------------------- -uChar FTermLinux::readAttributeController (uChar index) +uChar FTermLinux::readAttributeController (uChar index) const { // Reads a byte from the attribute controller from a given index @@ -793,7 +793,7 @@ uChar FTermLinux::readAttributeController (uChar index) } //---------------------------------------------------------------------- -void FTermLinux::writeAttributeController (uChar index, uChar data) +void FTermLinux::writeAttributeController (uChar index, uChar data) const { // Writes a byte from the attribute controller from a given index diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 53577070..40b0b57e 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -153,19 +153,19 @@ void FVTerm::setTermXY (int x, int y) const } //---------------------------------------------------------------------- -void FVTerm::setTerminalUpdates (terminal_update refresh_state) const +void FVTerm::setTerminalUpdates (TerminalUpdate refresh_state) const { - if ( refresh_state == stop_terminal_updates ) + if ( refresh_state == TerminalUpdate::Stop ) { no_terminal_updates = true; } - else if ( refresh_state == continue_terminal_updates - || refresh_state == start_terminal_updates ) + else if ( refresh_state == TerminalUpdate::Continue + || refresh_state == TerminalUpdate::Start ) { no_terminal_updates = false; } - if ( refresh_state == start_terminal_updates ) + if ( refresh_state == TerminalUpdate::Start ) updateTerminal(); } @@ -305,8 +305,9 @@ void FVTerm::addPreprocessingHandler ( const FVTerm* instance if ( print_area ) { - FVTermPreprocessing obj{ instance, std::move(function) }; delPreprocessingHandler (instance); + auto obj = make_unique \ + (instance, std::forward(function)); print_area->preproc_list.emplace_back(std::move(obj)); } } @@ -324,7 +325,7 @@ void FVTerm::delPreprocessingHandler (const FVTerm* instance) while ( iter != print_area->preproc_list.end() ) { - if ( iter->instance.get() == instance ) + if ( iter->get()->instance.get() == instance ) iter = print_area->preproc_list.erase(iter); else ++iter; @@ -803,7 +804,7 @@ bool FVTerm::updateVTermCursor (const FTermArea* area) const if ( isInsideArea (FPoint{cx, cy}, area) && isInsideTerminal (FPoint{x, y}) - && isCovered (FPoint{x, y}, area) == non_covered ) + && isCovered (FPoint{x, y}, area) == CoveredState::non_covered ) { vterm->input_cursor_x = x; vterm->input_cursor_y = y; @@ -1362,15 +1363,15 @@ inline bool FVTerm::reallocateTextArea (FTermArea* area, std::size_t size) } //---------------------------------------------------------------------- -FVTerm::covered_state FVTerm::isCovered ( const FPoint& pos - , const FTermArea* area ) +FVTerm::CoveredState FVTerm::isCovered ( const FPoint& pos + , const FTermArea* area ) { // Determines the covered state for the given position if ( ! area ) - return non_covered; + return CoveredState::non_covered; - auto is_covered = non_covered; + auto is_covered = CoveredState::non_covered; if ( FWidget::getWindowList() && ! FWidget::getWindowList()->empty() ) { @@ -1398,11 +1399,11 @@ FVTerm::covered_state FVTerm::isCovered ( const FPoint& pos if ( tmp->attr.bit.color_overlay ) { - is_covered = half_covered; + is_covered = CoveredState::half_covered; } else if ( ! tmp->attr.bit.transparent ) { - is_covered = fully_covered; + is_covered = CoveredState::fully_covered; break; } } @@ -1524,10 +1525,10 @@ bool FVTerm::updateVTermCharacter ( const FTermArea* area // Get covered state const auto is_covered = isCovered(terminal_pos, area); - if ( is_covered == fully_covered ) + if ( is_covered == CoveredState::fully_covered ) return false; - if ( is_covered == half_covered ) + if ( is_covered == CoveredState::half_covered ) { // Overlapped character auto oc = getOverlappedCharacter (terminal_pos, area); @@ -1610,7 +1611,7 @@ void FVTerm::callPreprocessingHandler (const FTermArea* area) for (auto&& pcall : area->preproc_list) { // call the preprocessing handler - auto preprocessingHandler = pcall.function; + auto preprocessingHandler = pcall->function; preprocessingHandler(); } } @@ -1623,11 +1624,11 @@ bool FVTerm::hasChildAreaChanges (FTermArea* area) const return std::any_of ( area->preproc_list.begin() , area->preproc_list.end() - , [] (const FVTermPreprocessing& pcall) + , [] (const std::unique_ptr& pcall) { - return pcall.instance - && pcall.instance->child_print_area - && pcall.instance->child_print_area->has_changes; + return pcall->instance + && pcall->instance->child_print_area + && pcall->instance->child_print_area->has_changes; } ); } @@ -1640,8 +1641,8 @@ void FVTerm::clearChildAreaChanges (const FTermArea* area) const for (auto&& pcall : area->preproc_list) { - if ( pcall.instance && pcall.instance->child_print_area ) - pcall.instance->child_print_area->has_changes = false; + if ( pcall->instance && pcall->instance->child_print_area ) + pcall->instance->child_print_area->has_changes = false; } } @@ -1830,7 +1831,7 @@ void FVTerm::init() output_buffer->reserve(TERMINAL_OUTPUT_BUFFER_SIZE + 256); // term_attribute stores the current state of the terminal - term_attribute.ch = { L'\0' }; + term_attribute.ch = {{ L'\0' }}; term_attribute.fg_color = fc::Default; term_attribute.bg_color = fc::Default; term_attribute.attr.byte[0] = 0; @@ -2718,7 +2719,7 @@ void FVTerm::printPaddingCharacter (FTermArea* area, const FChar& term_char) if ( FTerm::getEncoding() == fc::UTF8 ) { - pc.ch = { L'\0' }; + pc.ch = {{ L'\0' }}; pc.attr.bit.fullwidth_padding = true; pc.attr.bit.char_width = 0; } diff --git a/src/fwindow.cpp b/src/fwindow.cpp index e1012e9a..c522f8aa 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -681,7 +681,7 @@ void FWindow::switchToPrevWindow (const FWidget* widget) // Disable terminal updates to avoid flickering // when redrawing the focused widget if ( widget ) - widget->setTerminalUpdates (FVTerm::stop_terminal_updates); + widget->setTerminalUpdates (FVTerm::TerminalUpdate::Stop); const bool is_activated = activatePrevWindow(); auto active_win = static_cast(getActiveWindow()); @@ -729,7 +729,7 @@ void FWindow::switchToPrevWindow (const FWidget* widget) // Enable terminal updates again if ( widget ) - widget->setTerminalUpdates (FVTerm::continue_terminal_updates); + widget->setTerminalUpdates (FVTerm::TerminalUpdate::Continue); } //---------------------------------------------------------------------- diff --git a/src/include/final/fcombobox.h b/src/include/final/fcombobox.h index 46f122ec..9e2cf70f 100644 --- a/src/include/final/fcombobox.h +++ b/src/include/final/fcombobox.h @@ -134,6 +134,7 @@ class FComboBox : public FWidget public: // Using-declaration using FWidget::setGeometry; + using LabelOrientation = FLineEdit::LabelOrientation; // Constructors explicit FComboBox (FWidget* = nullptr); @@ -155,7 +156,7 @@ class FComboBox : public FWidget FString getText() const; template clean_fdata_t
& getItemData(); - FLineEdit::label_o getLabelOrientation() const; + LabelOrientation getLabelOrientation() const; // Mutators void setSize (const FSize&, bool = true) override; @@ -179,7 +180,7 @@ class FComboBox : public FWidget void setText (const FString&); void clearText(); void setLabelText (const FString&); - void setLabelOrientation (const FLineEdit::label_o); + void setLabelOrientation (const LabelOrientation); // Inquiries bool hasShadow() const; @@ -261,7 +262,7 @@ inline clean_fdata_t
& FComboBox::getItemData() } //---------------------------------------------------------------------- -inline FLineEdit::label_o FComboBox::getLabelOrientation() const +inline FLineEdit::LabelOrientation FComboBox::getLabelOrientation() const { return input_field.getLabelOrientation(); } //---------------------------------------------------------------------- @@ -342,7 +343,7 @@ inline void FComboBox::setLabelText (const FString& s) { input_field.setLabelText(s); } //---------------------------------------------------------------------- -inline void FComboBox::setLabelOrientation (const FLineEdit::label_o o) +inline void FComboBox::setLabelOrientation (const LabelOrientation o) { input_field.setLabelOrientation(o); } } // namespace finalcut diff --git a/src/include/final/fdata.h b/src/include/final/fdata.h index 15d8a823..03c40574 100644 --- a/src/include/final/fdata.h +++ b/src/include/final/fdata.h @@ -65,7 +65,7 @@ template struct cleanCondition { // Leave the type untouched - typedef T type; + using type = T; }; //---------------------------------------------------------------------- @@ -73,7 +73,7 @@ template struct cleanCondition { // Array to pointer - typedef typename std::remove_extent::type* type; + using type = typename std::remove_extent::type*; }; //---------------------------------------------------------------------- @@ -81,7 +81,7 @@ template struct cleanCondition { // Add pointer to function - typedef typename std::add_pointer::type type; + using type = typename std::add_pointer::type; }; } // namespace internal @@ -91,11 +91,11 @@ template class cleanFData { private: - typedef typename std::remove_reference::type remove_ref; + using remove_ref = typename std::remove_reference::type; public: // Similar to std::decay, but keeps const and volatile - typedef typename internal::cleanCondition::type type; + using type = typename internal::cleanCondition::type; }; //---------------------------------------------------------------------- @@ -153,7 +153,7 @@ template class FData : public FDataAccess { public: - typedef typename std::remove_cv::type T_nocv; + using T_nocv = typename std::remove_cv::type; // Constructors explicit FData (T& v) // constructor diff --git a/src/include/final/fdialog.h b/src/include/final/fdialog.h index 26a44ebb..0d21e0fc 100644 --- a/src/include/final/fdialog.h +++ b/src/include/final/fdialog.h @@ -71,7 +71,7 @@ class FDialog : public FWindow using FWindow::setResizeable; // Enumeration - enum DialogCode + enum class ResultCode : int { Reject = 0, Accept = 1 @@ -119,7 +119,7 @@ class FDialog : public FWindow // Methods void show() override; void hide() override; - int exec(); + ResultCode exec(); void setPos (const FPoint&, bool = true) override; void move (const FPoint&) override; bool moveUp (int); @@ -147,7 +147,7 @@ class FDialog : public FWindow protected: // Methods - virtual void done (int); + void done (ResultCode); void draw() override; void drawDialogShadow(); @@ -217,7 +217,7 @@ class FDialog : public FWindow // Data members FString tb_text{}; // title bar text - int result_code{FDialog::Reject}; + ResultCode result_code{ResultCode::Reject}; bool zoom_button_pressed{false}; bool zoom_button_active{false}; bool setPos_error{false}; diff --git a/src/include/final/ffiledialog.h b/src/include/final/ffiledialog.h index 20902290..22d1787b 100644 --- a/src/include/final/ffiledialog.h +++ b/src/include/final/ffiledialog.h @@ -88,7 +88,7 @@ class FFileDialog : public FDialog { public: // Enumeration - enum DialogType + enum class DialogType { Open = 0, Save = 1 @@ -99,7 +99,7 @@ class FFileDialog : public FDialog FFileDialog (const FFileDialog&); // copy constructor FFileDialog ( const FString& , const FString& - , DialogType = FFileDialog::Open + , DialogType = DialogType::Open , FWidget* = nullptr ); // Destructor @@ -219,7 +219,7 @@ class FFileDialog : public FDialog FCheckBox hidden_check{this}; FButton cancel_btn{this}; FButton open_btn{this}; - DialogType dlg_type{FFileDialog::Open}; + DialogType dlg_type{DialogType::Open}; bool show_hidden{false}; // Friend functions diff --git a/src/include/final/flineedit.h b/src/include/final/flineedit.h index 3ab68976..2567cd91 100644 --- a/src/include/final/flineedit.h +++ b/src/include/final/flineedit.h @@ -69,13 +69,13 @@ class FLineEdit : public FWidget using FWidget::setGeometry; // Enumerations - enum label_o + enum class LabelOrientation { - label_above = 0, - label_left = 1 + above = 0, + left = 1 }; - enum inputType + enum class InputType { textfield = 0, password = 1 @@ -108,7 +108,7 @@ class FLineEdit : public FWidget std::size_t getMaxLength() const; std::size_t getCursorPosition() const; FLabel* getLabelObject() const; - label_o getLabelOrientation() const; + LabelOrientation getLabelOrientation() const; // Mutators void setText (const FString&); @@ -117,8 +117,8 @@ class FLineEdit : public FWidget void setMaxLength (std::size_t); void setCursorPosition (std::size_t); void setLabelText (const FString&); - void setInputType (const inputType); - void setLabelOrientation (const label_o); + void setInputType (const InputType); + void setLabelOrientation (const LabelOrientation); void setLabelAssociatedWidget (FWidget*); void resetColors() override; void setSize (const FSize&, bool = true) override; @@ -204,24 +204,24 @@ class FLineEdit : public FWidget void processChanged() const; // Data members - FString text{""}; - FString print_text{""}; - FString label_text{""}; - FLabel* label{}; - FWidget* label_associated_widget{this}; - std::wstring input_filter{}; - dragScroll drag_scroll{FLineEdit::noScroll}; - label_o label_orientation{FLineEdit::label_left}; - inputType input_type{FLineEdit::textfield}; - int scroll_repeat{100}; - bool scroll_timer{false}; - bool insert_mode{true}; - bool read_only{false}; - std::size_t cursor_pos{NOT_SET}; - std::size_t text_offset{0}; - std::size_t char_width_offset{0}; - std::size_t x_pos{0}; - std::size_t max_length{std::numeric_limits::max()}; + FString text{""}; + FString print_text{""}; + FString label_text{""}; + FLabel* label{}; + FWidget* label_associated_widget{this}; + std::wstring input_filter{}; + dragScroll drag_scroll{FLineEdit::noScroll}; + LabelOrientation label_orientation{LabelOrientation::left}; + InputType input_type{InputType::textfield}; + int scroll_repeat{100}; + bool scroll_timer{false}; + bool insert_mode{true}; + bool read_only{false}; + std::size_t cursor_pos{NOT_SET}; + std::size_t text_offset{0}; + std::size_t char_width_offset{0}; + std::size_t x_pos{0}; + std::size_t max_length{std::numeric_limits::max()}; }; @@ -257,7 +257,7 @@ inline FLabel* FLineEdit::getLabelObject() const { return label; } //---------------------------------------------------------------------- -inline FLineEdit::label_o FLineEdit::getLabelOrientation() const +inline FLineEdit::LabelOrientation FLineEdit::getLabelOrientation() const { return label_orientation; } //---------------------------------------------------------------------- @@ -269,7 +269,7 @@ inline void FLineEdit::clearInputFilter() { input_filter.clear(); } //---------------------------------------------------------------------- -inline void FLineEdit::setInputType (const inputType type) +inline void FLineEdit::setInputType (const InputType type) { input_type = type; } //---------------------------------------------------------------------- diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index ccdf926c..ad036621 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -221,6 +221,7 @@ class FListViewIterator // Constructor FListViewIterator () = default; + ~FListViewIterator () = default; FListViewIterator (Iterator); FListViewIterator (const FListViewIterator&) = default; FListViewIterator (FListViewIterator&& i) noexcept diff --git a/src/include/final/fmenubar.h b/src/include/final/fmenubar.h index 828fa3c3..45b8110f 100644 --- a/src/include/final/fmenubar.h +++ b/src/include/final/fmenubar.h @@ -139,7 +139,7 @@ class FMenuBar : public FWindow, public FMenuList void mouseDownOverList (const FMouseEvent*); void mouseUpOverList (const FMouseEvent*); void mouseMoveOverList (const FMouseEvent&); - void passEventToMenu (const FMouseEvent&&) const; + void passEventToMenu (const FMouseEvent&) const; void leaveMenuBar(); // Data members diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index 10e6d814..d44b5553 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -80,7 +80,7 @@ class FMessageBox : public FDialog { public: // Enumeration - enum ButtonType + enum class ButtonType : std::size_t { Reject = 0, Ok = 1, @@ -94,10 +94,13 @@ class FMessageBox : public FDialog // Constructors explicit FMessageBox (FWidget* = nullptr); - FMessageBox (const FMessageBox&); // copy constructor + + FMessageBox (const FMessageBox&) = default; // copy constructor + FMessageBox ( const FString&, const FString& , ButtonType, ButtonType, ButtonType , FWidget* = nullptr ); + // Destructor ~FMessageBox() noexcept override; @@ -119,23 +122,25 @@ class FMessageBox : public FDialog void setText (const FString&) override; // Methods + ButtonType exec(); template - static int info ( FWidget* + static ButtonType info ( FWidget* , const FString& , const messageType& - , ButtonType = FMessageBox::Ok - , ButtonType = FMessageBox::Reject - , ButtonType = FMessageBox::Reject ); + , ButtonType = ButtonType::Ok + , ButtonType = ButtonType::Reject + , ButtonType = ButtonType::Reject ); template - static int error ( FWidget* + static ButtonType error ( FWidget* , const messageType& - , ButtonType = FMessageBox::Ok - , ButtonType = FMessageBox::Reject - , ButtonType = FMessageBox::Reject ); + , ButtonType = ButtonType::Ok + , ButtonType = ButtonType::Reject + , ButtonType = ButtonType::Reject ); protected: // Method void adjustSize() override; + void done (ButtonType); // Callback method void cb_processClick (ButtonType); @@ -161,10 +166,11 @@ class FMessageBox : public FDialog FString text{}; FStringList text_components{}; - FButtons button; + FButtons button{}; std::size_t max_line_width{0}; FColor emphasis_color{getColorTheme()->dialog_emphasis_fg}; - ButtonType button_digit[MAX_BUTTONS]{FMessageBox::Reject}; + ButtonType result_code{ButtonType::Reject}; + ButtonType button_digit[MAX_BUTTONS]{ButtonType::Reject}; std::size_t num_buttons{0}; std::size_t text_num_lines{0}; bool center_text{false}; @@ -209,28 +215,28 @@ inline bool FMessageBox::unsetCenterText() //---------------------------------------------------------------------- template -int FMessageBox::info ( FWidget* parent - , const FString& caption - , const messageType& message - , ButtonType button0 - , ButtonType button1 - , ButtonType button2 ) +FMessageBox::ButtonType FMessageBox::info ( FWidget* parent + , const FString& caption + , const messageType& message + , ButtonType button0 + , ButtonType button1 + , ButtonType button2 ) { FMessageBox mbox ( caption , FString() << message , button0, button1, button2 , parent ); - const int reply = mbox.exec(); + const ButtonType reply = mbox.exec(); return reply; } //---------------------------------------------------------------------- template -int FMessageBox::error ( FWidget* parent - , const messageType& message - , ButtonType button0 - , ButtonType button1 - , ButtonType button2 ) +FMessageBox::ButtonType FMessageBox::error ( FWidget* parent + , const messageType& message + , ButtonType button0 + , ButtonType button1 + , ButtonType button2 ) { const FString caption{"Error message"}; @@ -245,7 +251,7 @@ int FMessageBox::error ( FWidget* parent 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(); + const ButtonType reply = mbox.exec(); return reply; } diff --git a/src/include/final/fpoint.h b/src/include/final/fpoint.h index c4b4d417..fef5efa2 100644 --- a/src/include/final/fpoint.h +++ b/src/include/final/fpoint.h @@ -51,8 +51,8 @@ class FPoint { public: // Constructors - FPoint () = default; - FPoint (int, int); + FPoint () noexcept = default; + FPoint (int, int) noexcept; // Overloaded operators FPoint& operator += (const FPoint&); @@ -96,7 +96,7 @@ class FPoint // FPoint inline functions //---------------------------------------------------------------------- -inline FPoint::FPoint (int x, int y) +inline FPoint::FPoint (int x, int y) noexcept : xpos{x} , ypos{y} { } diff --git a/src/include/final/frect.h b/src/include/final/frect.h index 5bf1d2a6..6bba8e0c 100644 --- a/src/include/final/frect.h +++ b/src/include/final/frect.h @@ -59,10 +59,10 @@ class FRect { public: // Constructors - FRect () = default; - FRect (int, int, std::size_t, std::size_t); - FRect (const FPoint&, const FSize&); - FRect (const FPoint&, const FPoint&); + FRect () noexcept = default; + FRect (int, int, std::size_t, std::size_t) noexcept; + FRect (const FPoint&, const FSize&) noexcept; + FRect (const FPoint&, const FPoint&) noexcept; // Accessors FString getClassName() const; @@ -139,7 +139,7 @@ class FRect // FRect inline functions //---------------------------------------------------------------------- -inline FRect::FRect (int x, int y, std::size_t width, std::size_t height) +inline FRect::FRect (int x, int y, std::size_t width, std::size_t height) noexcept : X1{x} , Y1{y} , X2{x + int(width) - 1} diff --git a/src/include/final/fsize.h b/src/include/final/fsize.h index 3a9d2cfb..a642f08f 100644 --- a/src/include/final/fsize.h +++ b/src/include/final/fsize.h @@ -56,8 +56,8 @@ class FSize { public: // Constructors - FSize () = default; - FSize (std::size_t, std::size_t); + FSize () noexcept = default; + FSize (std::size_t, std::size_t) noexcept; // Overloaded operators FSize& operator += (const FSize&); @@ -105,7 +105,7 @@ class FSize // FSize inline functions //---------------------------------------------------------------------- -inline FSize::FSize (std::size_t w, std::size_t h) +inline FSize::FSize (std::size_t w, std::size_t h) noexcept : width{w} , height{h} { } diff --git a/src/include/final/fspinbox.h b/src/include/final/fspinbox.h index 24963f9b..681f4ccb 100644 --- a/src/include/final/fspinbox.h +++ b/src/include/final/fspinbox.h @@ -66,6 +66,7 @@ class FSpinBox : public FWidget public: // Using-declaration using FWidget::setGeometry; + using LabelOrientation = FLineEdit::LabelOrientation; // Constructors explicit FSpinBox (FWidget* = nullptr); @@ -84,7 +85,7 @@ class FSpinBox : public FWidget sInt64 getValue() const; FString getPrefix() const; FString getSuffix() const; - FLineEdit::label_o getLabelOrientation() const; + LabelOrientation getLabelOrientation() const; // Mutators void setSize (const FSize&, bool = true) override; @@ -107,7 +108,7 @@ class FSpinBox : public FWidget void setPrefix (const FString&); void setSuffix (const FString&); void setLabelText (const FString&); - void setLabelOrientation (const FLineEdit::label_o); + void setLabelOrientation (const LabelOrientation); // Inquiries bool hasShadow() const; @@ -177,7 +178,7 @@ inline FString FSpinBox::getSuffix() const { return sfix; } //---------------------------------------------------------------------- -inline FLineEdit::label_o FSpinBox::getLabelOrientation() const +inline FLineEdit::LabelOrientation FSpinBox::getLabelOrientation() const { return input_field.getLabelOrientation(); } //---------------------------------------------------------------------- @@ -217,7 +218,7 @@ inline void FSpinBox::setLabelText (const FString& s) { input_field.setLabelText(s); } //---------------------------------------------------------------------- -inline void FSpinBox::setLabelOrientation (const FLineEdit::label_o o) +inline void FSpinBox::setLabelOrientation (const LabelOrientation o) { input_field.setLabelOrientation(o); } } // namespace finalcut diff --git a/src/include/final/fstartoptions.h b/src/include/final/fstartoptions.h index 715e013e..f2342018 100644 --- a/src/include/final/fstartoptions.h +++ b/src/include/final/fstartoptions.h @@ -95,7 +95,6 @@ class FStartOptions final fc::encoding encoding{fc::UNKNOWN}; std::ofstream logfile_stream{}; - static FStartOptions* start_options; }; //---------------------------------------------------------------------- diff --git a/src/include/final/ftermlinux.h b/src/include/final/ftermlinux.h index 386ceb80..0eb59ffb 100644 --- a/src/include/final/ftermlinux.h +++ b/src/include/final/ftermlinux.h @@ -105,7 +105,7 @@ class FTermLinux final // Methods void init(); - void initCharMap(); + void initCharMap() const; void finish(); bool loadVGAFont(); bool loadNewFont(); @@ -154,8 +154,8 @@ class FTermLinux final // Methods #if defined(ISA_SYSCTL_SUPPORT) uInt16 getInputStatusRegisterOne() const; - uChar readAttributeController (uChar); - void writeAttributeController (uChar, uChar); + uChar readAttributeController (uChar) const; + void writeAttributeController (uChar, uChar) const; uChar getAttributeMode(); void setAttributeMode (uChar); int setBlinkAsIntensity (bool); diff --git a/src/include/final/fvterm.h b/src/include/final/fvterm.h index 0a518372..7ddb01be 100644 --- a/src/include/final/fvterm.h +++ b/src/include/final/fvterm.h @@ -98,21 +98,21 @@ class FVTerm // Using-declarations using FPreprocessingHandler = void (FVTerm::*)(); using FPreprocessingFunction = std::function; - using FPreprocessing = std::vector; + using FPreprocessing = std::vector>; // Enumerations - enum covered_state + enum class CoveredState { non_covered, half_covered, fully_covered }; - enum terminal_update + enum class TerminalUpdate { - stop_terminal_updates, // No terminal refresh - continue_terminal_updates, // Resuming terminal refresh - start_terminal_updates // Allowing terminal refresh + Stop, // No terminal refresh + Continue, // Resuming terminal refresh + Start // Allowing terminal refresh }; // Constructor @@ -150,7 +150,7 @@ class FVTerm // Mutators void setTermXY (int, int) const; - void setTerminalUpdates (terminal_update) const; + void setTerminalUpdates (TerminalUpdate) const; void hideCursor (bool) const; void hideCursor() const; void showCursor() const; @@ -347,7 +347,7 @@ class FVTerm , std::size_t ); static bool reallocateTextArea ( FTermArea* , std::size_t ); - static covered_state isCovered (const FPoint&, const FTermArea*); + static CoveredState isCovered (const FPoint&, const FTermArea*); static void updateOverlappedColor (const FChar&, const FChar&, FChar&); static void updateOverlappedCharacter (FChar&, FChar&); static void updateShadedCharacter (const FChar&, FChar&, FChar&); @@ -509,7 +509,7 @@ struct FVTerm::FVTermPreprocessing { } FVTermPreprocessing (const FVTermPreprocessing&) = delete; - FVTermPreprocessing (FVTermPreprocessing&&) = default; + FVTermPreprocessing (FVTermPreprocessing&&) noexcept = default; FVTermPreprocessing& operator = (const FVTermPreprocessing&) = delete; FVTermPreprocessing& operator = (FVTermPreprocessing&&) noexcept = default; From 47cb79a7f075174e411d05d9b7d1c50595c38e08 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 5 Dec 2020 23:54:40 +0100 Subject: [PATCH 07/45] Small fixes --- examples/treeview.cpp | 24 ++++++++++----------- src/fcharmap.cpp | 2 +- src/ffiledialog.cpp | 37 --------------------------------- src/fmessagebox.cpp | 30 -------------------------- src/fterm.cpp | 14 +++++-------- src/ftermlinux.cpp | 4 ++-- src/fvterm.cpp | 2 +- src/include/final/fc.h | 7 +++++++ src/include/final/fcallback.h | 3 +-- src/include/final/fcharmap.h | 2 +- src/include/final/ffiledialog.h | 9 +++++--- src/include/final/fmessagebox.h | 11 +++++----- src/include/final/ftermlinux.h | 4 ++-- 13 files changed, 44 insertions(+), 105 deletions(-) diff --git a/examples/treeview.cpp b/examples/treeview.cpp index 340b242c..a1ebf6e6 100644 --- a/examples/treeview.cpp +++ b/examples/treeview.cpp @@ -161,12 +161,12 @@ class Treeview final : public finalcut::FDialog struct TreeItem; // forward declaration // Methods - auto initAfrica() -> std::initializer_list const; - auto initAsia() -> std::initializer_list const; - auto initEurope() -> std::initializer_list const; - auto initNorthAmerica() -> std::initializer_list const; - auto initSouthAmerica() -> std::initializer_list const; - auto initOceania() -> std::initializer_list const; + auto initAfrica() const -> std::initializer_list; + auto initAsia() const -> std::initializer_list; + auto initEurope() const -> std::initializer_list; + auto initNorthAmerica() const -> std::initializer_list; + auto initSouthAmerica() const -> std::initializer_list; + auto initOceania() const -> std::initializer_list; void adjustSize() override; // Event handler @@ -275,7 +275,7 @@ Treeview::Treeview (finalcut::FWidget* parent) } //---------------------------------------------------------------------- -auto Treeview::initAfrica() -> std::initializer_list const +auto Treeview::initAfrica() const -> std::initializer_list { static const auto list = std::initializer_list { @@ -306,7 +306,7 @@ auto Treeview::initAfrica() -> std::initializer_list const } //---------------------------------------------------------------------- -auto Treeview::initAsia() -> std::initializer_list const +auto Treeview::initAsia() const -> std::initializer_list { static const auto list = std::initializer_list { @@ -334,7 +334,7 @@ auto Treeview::initAsia() -> std::initializer_list const } //---------------------------------------------------------------------- -auto Treeview::initEurope() -> std::initializer_list const +auto Treeview::initEurope() const -> std::initializer_list { static const auto list = std::initializer_list { @@ -362,7 +362,7 @@ auto Treeview::initEurope() -> std::initializer_list const } //---------------------------------------------------------------------- -auto Treeview::initNorthAmerica() -> std::initializer_list const +auto Treeview::initNorthAmerica() const -> std::initializer_list { static const auto list = std::initializer_list { @@ -379,7 +379,7 @@ auto Treeview::initNorthAmerica() -> std::initializer_list c } //---------------------------------------------------------------------- -auto Treeview::initSouthAmerica() -> std::initializer_list const +auto Treeview::initSouthAmerica() const -> std::initializer_list { static const auto list = std::initializer_list { @@ -398,7 +398,7 @@ auto Treeview::initSouthAmerica() -> std::initializer_list c } //---------------------------------------------------------------------- -auto Treeview::initOceania() -> std::initializer_list const +auto Treeview::initOceania() const -> std::initializer_list { static const auto list = std::initializer_list { diff --git a/src/fcharmap.cpp b/src/fcharmap.cpp index 7c6c2097..180b9930 100644 --- a/src/fcharmap.cpp +++ b/src/fcharmap.cpp @@ -161,7 +161,7 @@ std::array, 115> character = * (2) Only supported in use with newfont */ -constexpr std::array, 39> vt100_key_to_utf8 = +constexpr std::array, 39> dec_special_graphics = {{ {{fc::vt100_key_rarrow , fc::BlackRightPointingPointer}}, // ► {{fc::vt100_key_larrow , fc::BlackLeftPointingPointer}}, // ◄ diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 4dbc97e2..a37d44a5 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -102,16 +102,6 @@ FFileDialog::FFileDialog (FWidget* parent) init(); } -//---------------------------------------------------------------------- -FFileDialog::FFileDialog (const FFileDialog& fdlg) - : FDialog{fdlg.getParentWidget()} -{ - if ( fdlg.directory ) - setPath(fdlg.directory); - - init(); -} - //---------------------------------------------------------------------- FFileDialog::FFileDialog ( const FString& dirname , const FString& filter @@ -135,33 +125,6 @@ FFileDialog::~FFileDialog() // destructor // public methods of FFileDialog -//---------------------------------------------------------------------- -FFileDialog& FFileDialog::operator = (const FFileDialog& fdlg) -{ - if ( &fdlg == this ) - { - return *this; - } - else - { - clear(); - - if ( fdlg.getParentWidget() ) - fdlg.getParentWidget()->addChild (this); - - directory = fdlg.directory; - filter_pattern = fdlg.filter_pattern; - dlg_type = fdlg.dlg_type; - show_hidden = fdlg.show_hidden; - - if ( directory ) - setPath(directory); - - init(); - return *this; - } -} - //---------------------------------------------------------------------- FString FFileDialog::getSelectedFile() const { diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index a55cb3f2..e030d12b 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -77,36 +77,6 @@ FMessageBox::~FMessageBox() noexcept = default; // destructor // public methods of FMessageBox -//---------------------------------------------------------------------- -FMessageBox& FMessageBox::operator = (const FMessageBox& mbox) -{ - if ( &mbox == this ) - { - return *this; - } - else - { - if ( mbox.getParentWidget() ) - mbox.getParentWidget()->addChild (this); - - setTitlebarText (mbox.getTitlebarText()); - headline_text = mbox.headline_text; - text = mbox.text; - text_components = mbox.text_components; - max_line_width = mbox.max_line_width; - center_text = mbox.center_text; - emphasis_color = mbox.emphasis_color; - num_buttons = mbox.num_buttons; - text_num_lines = mbox.text_num_lines; - button_digit[0] = mbox.button_digit[0]; - button_digit[1] = mbox.button_digit[1]; - button_digit[2] = mbox.button_digit[2]; - init(); - - return *this; - } -} - //---------------------------------------------------------------------- void FMessageBox::setHeadline (const FString& headline) { diff --git a/src/fterm.cpp b/src/fterm.cpp index 8fe5e285..508541f6 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -1287,18 +1287,14 @@ void FTerm::init_alt_charset() } } - enum Column : int - { - vt100_key = 0, - utf8_char = 1 - }; - // Update array 'character' with discovered VT100 pairs - for (auto&& pair : fc::vt100_key_to_utf8) + for (auto&& pair : fc::dec_special_graphics) { - const auto keyChar = uChar(pair[vt100_key]); + const auto vt100 = std::size_t(fc::DECSpecialGraphics::vt100); + const auto utf8 = std::size_t(fc::DECSpecialGraphics::utf8); + const auto keyChar = uChar(pair[vt100]); const auto altChar = uChar(vt100_alt_char[keyChar]); - const auto utf8char = uInt(pair[utf8_char]); + const auto utf8char = uInt(pair[utf8]); const auto p = std::find_if ( fc::character.begin() , fc::character.end() , [&utf8char] (std::array entry) diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index c442fbb5..e36dc4e0 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -815,7 +815,7 @@ void FTermLinux::writeAttributeController (uChar index, uChar data) const } //---------------------------------------------------------------------- -inline uChar FTermLinux::getAttributeMode() +inline uChar FTermLinux::getAttributeMode() const { // Gets the attribute mode value from the vga attribute controller static constexpr uChar attrib_mode = 0x10; @@ -823,7 +823,7 @@ inline uChar FTermLinux::getAttributeMode() } //---------------------------------------------------------------------- -inline void FTermLinux::setAttributeMode (uChar data) +inline void FTermLinux::setAttributeMode (uChar data) const { // Sets the attribute mode value from the vga attribute controller static constexpr uChar attrib_mode = 0x10; diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 40b0b57e..8012c221 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -307,7 +307,7 @@ void FVTerm::addPreprocessingHandler ( const FVTerm* instance { delPreprocessingHandler (instance); auto obj = make_unique \ - (instance, std::forward(function)); + (instance, std::move(function)); print_area->preproc_list.emplace_back(std::move(obj)); } } diff --git a/src/include/final/fc.h b/src/include/final/fc.h index 735b89a0..1978c950 100644 --- a/src/include/final/fc.h +++ b/src/include/final/fc.h @@ -92,6 +92,13 @@ enum encoding UNKNOWN }; +// vt100 <-> utf-8 +enum class DECSpecialGraphics : std::size_t +{ + vt100 = 0, // First column + utf8 = 1 // Second column +}; + // VT100 line graphic keys enum vt100_keys : char { diff --git a/src/include/final/fcallback.h b/src/include/final/fcallback.h index 5341c760..0100afff 100644 --- a/src/include/final/fcallback.h +++ b/src/include/final/fcallback.h @@ -55,8 +55,7 @@ class FWidget; struct FCallbackData { // Constructor - FCallbackData() - { } + FCallbackData() = default; template FCallbackData (const FString& s, FWidget* i, FuncPtr m, const FCall& c) diff --git a/src/include/final/fcharmap.h b/src/include/final/fcharmap.h index 8aafa7e8..033fe16a 100644 --- a/src/include/final/fcharmap.h +++ b/src/include/final/fcharmap.h @@ -39,7 +39,7 @@ namespace fc { extern std::array, 115> character; -extern const std::array, 39> vt100_key_to_utf8; +extern const std::array, 39> dec_special_graphics; extern const std::array, 256> cp437_ucs; extern const std::array, 227> halfwidth_fullwidth; diff --git a/src/include/final/ffiledialog.h b/src/include/final/ffiledialog.h index 22d1787b..8ab7c239 100644 --- a/src/include/final/ffiledialog.h +++ b/src/include/final/ffiledialog.h @@ -96,17 +96,20 @@ class FFileDialog : public FDialog // Constructors explicit FFileDialog (FWidget* = nullptr); - FFileDialog (const FFileDialog&); // copy constructor + FFileDialog ( const FString& , const FString& , DialogType = DialogType::Open , FWidget* = nullptr ); + // Disable copy constructor + FFileDialog (const FFileDialog&) = delete; + // Destructor ~FFileDialog() override; - // copy assignment operator (=) - FFileDialog& operator = (const FFileDialog&); + // Disable copy assignment operator (=) + FFileDialog& operator = (const FFileDialog&) = delete; // Accessors FString getClassName() const override; diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index d44b5553..e199b34e 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -95,7 +95,8 @@ class FMessageBox : public FDialog // Constructors explicit FMessageBox (FWidget* = nullptr); - FMessageBox (const FMessageBox&) = default; // copy constructor + // Disable copy constructor + FMessageBox (const FMessageBox&) = delete; FMessageBox ( const FString&, const FString& , ButtonType, ButtonType, ButtonType @@ -104,8 +105,8 @@ class FMessageBox : public FDialog // Destructor ~FMessageBox() noexcept override; - // copy assignment operator (=) - FMessageBox& operator = (const FMessageBox&); + // Disable copy assignment operator (=) + FMessageBox& operator = (const FMessageBox&) = delete; // Accessor FString getClassName() const override; @@ -151,6 +152,7 @@ class FMessageBox : public FDialog // Using-declaration using FButtons = std::array, MAX_BUTTONS>; + using FButtonsDigit = std::array; // Methods void init(); @@ -165,12 +167,11 @@ class FMessageBox : public FDialog FString headline_text{}; FString text{}; FStringList text_components{}; - FButtons button{}; std::size_t max_line_width{0}; FColor emphasis_color{getColorTheme()->dialog_emphasis_fg}; ButtonType result_code{ButtonType::Reject}; - ButtonType button_digit[MAX_BUTTONS]{ButtonType::Reject}; + FButtonsDigit button_digit{ButtonType::Reject}; std::size_t num_buttons{0}; std::size_t text_num_lines{0}; bool center_text{false}; diff --git a/src/include/final/ftermlinux.h b/src/include/final/ftermlinux.h index 0eb59ffb..3e589c0a 100644 --- a/src/include/final/ftermlinux.h +++ b/src/include/final/ftermlinux.h @@ -156,8 +156,8 @@ class FTermLinux final uInt16 getInputStatusRegisterOne() const; uChar readAttributeController (uChar) const; void writeAttributeController (uChar, uChar) const; - uChar getAttributeMode(); - void setAttributeMode (uChar); + uChar getAttributeMode() const; + void setAttributeMode (uChar) const; int setBlinkAsIntensity (bool); bool has9BitCharacters(); void getVGAPalette(); From 4146b20028981baed9c7ca29a3be2c3afb444824 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 6 Dec 2020 02:11:54 +0100 Subject: [PATCH 08/45] Small fixes --- examples/event-log.cpp | 6 +- src/fapplication.cpp | 10 +-- src/flineedit.cpp | 10 +-- src/flistbox.cpp | 72 ++++++++--------- src/flistview.cpp | 74 ++++++++--------- src/flog.cpp | 8 +- src/flogger.cpp | 14 ++-- src/fmouse.cpp | 139 +++++++++++++++++--------------- src/fscrollbar.cpp | 82 +++++++++---------- src/fscrollview.cpp | 72 ++++++++--------- src/fterm_functions.cpp | 2 +- src/ftermcap.cpp | 2 +- src/ftermfreebsd.cpp | 2 +- src/ftermlinux.cpp | 2 +- src/ftermopenbsd.cpp | 2 +- src/ftermxterminal.cpp | 2 +- src/ftextview.cpp | 72 ++++++++--------- src/include/final/flog.h | 8 +- src/include/final/flogger.h | 8 +- src/include/final/fmessagebox.h | 2 +- src/include/final/fmouse.h | 39 +++++---- src/include/final/fscrollbar.h | 14 ++-- src/include/final/ftypes.h | 2 +- test/flogger-test.cpp | 36 ++++----- test/fmouse-test.cpp | 22 ++--- 25 files changed, 354 insertions(+), 348 deletions(-) diff --git a/examples/event-log.cpp b/examples/event-log.cpp index 900b3941..98bc6a3b 100644 --- a/examples/event-log.cpp +++ b/examples/event-log.cpp @@ -126,7 +126,7 @@ void EventDialog::logMouseEvent ( const finalcut::FString& state const int mouse_x = ev.getX(); const int mouse_y = ev.getY(); - log << finalcut::FLog::Info + log << finalcut::FLog::LogLevel::Info << getMouseButtonName(ev.getButton()) << " mouse button " << state << " at (" << mouse_x << ", " << mouse_y << ")" << std::flush; @@ -162,7 +162,7 @@ void EventDialog::onKeyPress (finalcut::FKeyEvent* ev) key_name = wchar_t(key_id); // std::clog redirects all stream data to FLogger - std::clog << finalcut::FLog::Info + std::clog << finalcut::FLog::LogLevel::Info << "Key " << key_name << " (id " << key_id << ")" << std::flush; @@ -322,7 +322,7 @@ int main (int argc, char* argv[]) finalcut::FLog& log = *finalcut::FApplication::getLog(); // Set the line endings (default = CRLF) - log.setLineEnding (finalcut::FLog::LF); + log.setLineEnding (finalcut::FLog::LineEnding::LF); // Write a timestamp before each output line log.enableTimestamp(); diff --git a/src/fapplication.cpp b/src/fapplication.cpp index ee744e0e..b7db789f 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -344,7 +344,7 @@ void FApplication::setLogFile (const FString& filename) FLog& log = *FApplication::getLog(); log.setOutputStream(log_stream); log.enableTimestamp(); - log.setLineEnding (finalcut::FLog::LF); + log.setLineEnding (FLog::LineEnding::LF); } else { @@ -434,7 +434,7 @@ void FApplication::init() // Initialize logging if ( ! getStartOptions().logfile_stream.is_open() ) - getLog()->setLineEnding(FLog::CRLF); + getLog()->setLineEnding(FLog::LineEnding::CRLF); } //---------------------------------------------------------------------- @@ -718,15 +718,15 @@ inline void FApplication::performMouseAction() const switch ( keyboard->getKey() ) { case fc::Fkey_mouse: - mouse->setRawData (FMouse::x11, buffer); + mouse->setRawData (FMouse::MouseType::x11, buffer); break; case fc::Fkey_extended_mouse: - mouse->setRawData (FMouse::sgr, buffer); + mouse->setRawData (FMouse::MouseType::sgr, buffer); break; case fc::Fkey_urxvt_mouse: - mouse->setRawData (FMouse::urxvt, buffer); + mouse->setRawData (FMouse::MouseType::urxvt, buffer); break; default: diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 65d376f6..4dc72aa1 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -826,7 +826,7 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos) } catch (const std::out_of_range& ex) { - std::clog << FLog::Error + std::clog << FLog::LogLevel::Error << "Out of Range error: " << ex.what() << std::endl; } @@ -850,7 +850,7 @@ inline FLineEdit::offsetPair FLineEdit::endPosToOffset (std::size_t pos) } catch (const std::out_of_range& ex) { - std::clog << FLog::Error + std::clog << FLog::LogLevel::Error << "Out of Range error: " << ex.what() << std::endl; } } @@ -886,7 +886,7 @@ std::size_t FLineEdit::clickPosToCursorPos (std::size_t pos) } catch (const std::out_of_range& ex) { - std::clog << FLog::Error + std::clog << FLog::LogLevel::Error << "Out of Range error: " << ex.what() << std::endl; } @@ -920,7 +920,7 @@ void FLineEdit::adjustTextOffset() } catch (const std::out_of_range& ex) { - std::clog << FLog::Error + std::clog << FLog::LogLevel::Error << "Out of Range error: " << ex.what() << std::endl; } } @@ -933,7 +933,7 @@ void FLineEdit::adjustTextOffset() } catch (const std::out_of_range& ex) { - std::clog << FLog::Error + std::clog << FLog::LogLevel::Error << "Out of Range error: " << ex.what() << std::endl; } } diff --git a/src/flistbox.cpp b/src/flistbox.cpp index bfc278c6..ebd34929 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -1731,49 +1731,49 @@ void FListBox::lazyConvert(FListBoxItems::iterator iter, std::size_t y) //---------------------------------------------------------------------- void FListBox::cb_vbarChange (const FWidget*) { - FScrollbar::sType scrollType; + FScrollbar::SType scrollType; const std::size_t current_before = current; static constexpr int wheel_distance = 4; int distance{1}; const int yoffset_before = yoffset; scrollType = vbar->getScrollType(); - assert ( scrollType == FScrollbar::noScroll - || scrollType == FScrollbar::scrollJump - || scrollType == FScrollbar::scrollStepBackward - || scrollType == FScrollbar::scrollStepForward - || scrollType == FScrollbar::scrollPageBackward - || scrollType == FScrollbar::scrollPageForward - || scrollType == FScrollbar::scrollWheelUp - || scrollType == FScrollbar::scrollWheelDown ); + assert ( scrollType == FScrollbar::SType::noScroll + || scrollType == FScrollbar::SType::scrollJump + || scrollType == FScrollbar::SType::scrollStepBackward + || scrollType == FScrollbar::SType::scrollStepForward + || scrollType == FScrollbar::SType::scrollPageBackward + || scrollType == FScrollbar::SType::scrollPageForward + || scrollType == FScrollbar::SType::scrollWheelUp + || scrollType == FScrollbar::SType::scrollWheelDown ); switch ( scrollType ) { - case FScrollbar::noScroll: + case FScrollbar::SType::noScroll: break; - case FScrollbar::scrollPageBackward: + case FScrollbar::SType::scrollPageBackward: distance = int(getClientHeight()); // fall through - case FScrollbar::scrollStepBackward: + case FScrollbar::SType::scrollStepBackward: prevListItem (distance); break; - case FScrollbar::scrollPageForward: + case FScrollbar::SType::scrollPageForward: distance = int(getClientHeight()); // fall through - case FScrollbar::scrollStepForward: + case FScrollbar::SType::scrollStepForward: nextListItem (distance); break; - case FScrollbar::scrollJump: + case FScrollbar::SType::scrollJump: scrollToY (vbar->getValue()); break; - case FScrollbar::scrollWheelUp: + case FScrollbar::SType::scrollWheelUp: wheelUp (wheel_distance); break; - case FScrollbar::scrollWheelDown: + case FScrollbar::SType::scrollWheelDown: wheelDown (wheel_distance); break; } @@ -1787,7 +1787,7 @@ void FListBox::cb_vbarChange (const FWidget*) if ( isShown() ) drawList(); - if ( scrollType >= FScrollbar::scrollStepBackward ) + if ( scrollType >= FScrollbar::SType::scrollStepBackward ) { vbar->setValue (yoffset); @@ -1803,47 +1803,47 @@ void FListBox::cb_hbarChange (const FWidget*) { static constexpr int padding_space = 2; // 1 leading space + 1 trailing space static constexpr int wheel_distance = 4; - FScrollbar::sType scrollType; + FScrollbar::SType scrollType; int distance{1}; const int xoffset_before = xoffset; scrollType = hbar->getScrollType(); - assert ( scrollType == FScrollbar::noScroll - || scrollType == FScrollbar::scrollJump - || scrollType == FScrollbar::scrollStepBackward - || scrollType == FScrollbar::scrollStepForward - || scrollType == FScrollbar::scrollPageBackward - || scrollType == FScrollbar::scrollPageForward - || scrollType == FScrollbar::scrollWheelUp - || scrollType == FScrollbar::scrollWheelDown ); + assert ( scrollType == FScrollbar::SType::noScroll + || scrollType == FScrollbar::SType::scrollJump + || scrollType == FScrollbar::SType::scrollStepBackward + || scrollType == FScrollbar::SType::scrollStepForward + || scrollType == FScrollbar::SType::scrollPageBackward + || scrollType == FScrollbar::SType::scrollPageForward + || scrollType == FScrollbar::SType::scrollWheelUp + || scrollType == FScrollbar::SType::scrollWheelDown ); switch ( scrollType ) { - case FScrollbar::noScroll: + case FScrollbar::SType::noScroll: break; - case FScrollbar::scrollPageBackward: + case FScrollbar::SType::scrollPageBackward: distance = int(getClientWidth()) - padding_space; // fall through - case FScrollbar::scrollStepBackward: + case FScrollbar::SType::scrollStepBackward: scrollLeft (distance); break; - case FScrollbar::scrollPageForward: + case FScrollbar::SType::scrollPageForward: distance = int(getClientWidth()) - padding_space; // fall through - case FScrollbar::scrollStepForward: + case FScrollbar::SType::scrollStepForward: scrollRight (distance); break; - case FScrollbar::scrollJump: + case FScrollbar::SType::scrollJump: scrollToX (hbar->getValue()); break; - case FScrollbar::scrollWheelUp: + case FScrollbar::SType::scrollWheelUp: scrollLeft (wheel_distance); break; - case FScrollbar::scrollWheelDown: + case FScrollbar::SType::scrollWheelDown: scrollRight (wheel_distance); break; } @@ -1855,7 +1855,7 @@ void FListBox::cb_hbarChange (const FWidget*) drawList(); - if ( scrollType >= FScrollbar::scrollStepBackward ) + if ( scrollType >= FScrollbar::SType::scrollStepBackward ) { hbar->setValue (xoffset); diff --git a/src/flistview.cpp b/src/flistview.cpp index 084f1d00..652a6bb8 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -2765,47 +2765,47 @@ void FListView::scrollBy (int dx, int dy) //---------------------------------------------------------------------- void FListView::cb_vbarChange (const FWidget*) { - FScrollbar::sType scrollType = vbar->getScrollType(); + FScrollbar::SType scrollType = vbar->getScrollType(); static constexpr int wheel_distance = 4; int distance{1}; first_line_position_before = first_visible_line.getPosition(); - assert ( scrollType == FScrollbar::noScroll - || scrollType == FScrollbar::scrollJump - || scrollType == FScrollbar::scrollStepBackward - || scrollType == FScrollbar::scrollStepForward - || scrollType == FScrollbar::scrollPageBackward - || scrollType == FScrollbar::scrollPageForward - || scrollType == FScrollbar::scrollWheelUp - || scrollType == FScrollbar::scrollWheelDown ); + assert ( scrollType == FScrollbar::SType::noScroll + || scrollType == FScrollbar::SType::scrollJump + || scrollType == FScrollbar::SType::scrollStepBackward + || scrollType == FScrollbar::SType::scrollStepForward + || scrollType == FScrollbar::SType::scrollPageBackward + || scrollType == FScrollbar::SType::scrollPageForward + || scrollType == FScrollbar::SType::scrollWheelUp + || scrollType == FScrollbar::SType::scrollWheelDown ); switch ( scrollType ) { - case FScrollbar::noScroll: + case FScrollbar::SType::noScroll: break; - case FScrollbar::scrollPageBackward: + case FScrollbar::SType::scrollPageBackward: distance = int(getClientHeight()); // fall through - case FScrollbar::scrollStepBackward: + case FScrollbar::SType::scrollStepBackward: stepBackward(distance); break; - case FScrollbar::scrollPageForward: + case FScrollbar::SType::scrollPageForward: distance = int(getClientHeight()); // fall through - case FScrollbar::scrollStepForward: + case FScrollbar::SType::scrollStepForward: stepForward(distance); break; - case FScrollbar::scrollJump: + case FScrollbar::SType::scrollJump: scrollToY (vbar->getValue()); break; - case FScrollbar::scrollWheelUp: + case FScrollbar::SType::scrollWheelUp: wheelUp (wheel_distance); break; - case FScrollbar::scrollWheelDown: + case FScrollbar::SType::scrollWheelDown: wheelDown (wheel_distance); break; } @@ -2813,8 +2813,8 @@ void FListView::cb_vbarChange (const FWidget*) if ( isShown() ) drawList(); - if ( scrollType >= FScrollbar::scrollStepBackward - && scrollType <= FScrollbar::scrollPageForward ) + if ( scrollType >= FScrollbar::SType::scrollStepBackward + && scrollType <= FScrollbar::SType::scrollPageForward ) { vbar->setValue (first_visible_line.getPosition()); @@ -2828,47 +2828,47 @@ void FListView::cb_vbarChange (const FWidget*) //---------------------------------------------------------------------- void FListView::cb_hbarChange (const FWidget*) { - FScrollbar::sType scrollType = hbar->getScrollType(); + FScrollbar::SType scrollType = hbar->getScrollType(); static constexpr int wheel_distance = 4; int distance{1}; const int xoffset_before = xoffset; - assert ( scrollType == FScrollbar::noScroll - || scrollType == FScrollbar::scrollJump - || scrollType == FScrollbar::scrollStepBackward - || scrollType == FScrollbar::scrollStepForward - || scrollType == FScrollbar::scrollPageBackward - || scrollType == FScrollbar::scrollPageForward - || scrollType == FScrollbar::scrollWheelUp - || scrollType == FScrollbar::scrollWheelDown ); + assert ( scrollType == FScrollbar::SType::noScroll + || scrollType == FScrollbar::SType::scrollJump + || scrollType == FScrollbar::SType::scrollStepBackward + || scrollType == FScrollbar::SType::scrollStepForward + || scrollType == FScrollbar::SType::scrollPageBackward + || scrollType == FScrollbar::SType::scrollPageForward + || scrollType == FScrollbar::SType::scrollWheelUp + || scrollType == FScrollbar::SType::scrollWheelDown ); switch ( scrollType ) { - case FScrollbar::noScroll: + case FScrollbar::SType::noScroll: break; - case FScrollbar::scrollPageBackward: + case FScrollbar::SType::scrollPageBackward: distance = int(getClientWidth()); // fall through - case FScrollbar::scrollStepBackward: + case FScrollbar::SType::scrollStepBackward: scrollBy (-distance, 0); break; - case FScrollbar::scrollPageForward: + case FScrollbar::SType::scrollPageForward: distance = int(getClientWidth()); // fall through - case FScrollbar::scrollStepForward: + case FScrollbar::SType::scrollStepForward: scrollBy (distance, 0); break; - case FScrollbar::scrollJump: + case FScrollbar::SType::scrollJump: scrollToX (hbar->getValue()); break; - case FScrollbar::scrollWheelUp: + case FScrollbar::SType::scrollWheelUp: scrollBy (-wheel_distance, 0); break; - case FScrollbar::scrollWheelDown: + case FScrollbar::SType::scrollWheelDown: scrollBy (wheel_distance, 0); break; } @@ -2879,7 +2879,7 @@ void FListView::cb_hbarChange (const FWidget*) drawList(); } - if ( scrollType >= FScrollbar::scrollStepBackward ) + if ( scrollType >= FScrollbar::SType::scrollStepBackward ) { hbar->setValue (xoffset); diff --git a/src/flog.cpp b/src/flog.cpp index 37567fff..49c5d08f 100644 --- a/src/flog.cpp +++ b/src/flog.cpp @@ -47,19 +47,19 @@ FLog& FLog::operator << (LogLevel l) switch ( l ) { - case Info: + case LogLevel::Info: current_log = std::bind(&FLog::info, this, _1); break; - case Warn: + case LogLevel::Warn: current_log = std::bind(&FLog::warn, this, _1); break; - case Error: + case LogLevel::Error: current_log = std::bind(&FLog::error, this, _1); break; - case Debug: + case LogLevel::Debug: current_log = std::bind(&FLog::debug, this, _1); break; } diff --git a/src/flogger.cpp b/src/flogger.cpp index 216e0b7d..b71a9c31 100644 --- a/src/flogger.cpp +++ b/src/flogger.cpp @@ -71,11 +71,11 @@ std::string FLogger::getEOL() { std::lock_guard lock_guard(getMutex()); - if ( getEnding() == FLog::LF ) + if ( getEnding() == LineEnding::LF ) return "\n"; - else if ( getEnding() == FLog::CR ) + else if ( getEnding() == LineEnding::CR ) return "\r"; - else if ( getEnding() == FLog::CRLF ) + else if ( getEnding() == LineEnding::CRLF ) return "\r\n"; return ""; @@ -90,16 +90,16 @@ void FLogger::printLogLine (const std::string& msg) switch ( getLevel() ) { - case Info: + case LogLevel::Info: return "INFO"; - case Warn: + case LogLevel::Warn: return "WARNING"; - case Error: + case LogLevel::Error: return "ERROR"; - case Debug: + case LogLevel::Debug: return "DEBUG"; } diff --git a/src/fmouse.cpp b/src/fmouse.cpp index f4f13951..d1d683c5 100644 --- a/src/fmouse.cpp +++ b/src/fmouse.cpp @@ -64,42 +64,42 @@ const FPoint& FMouseData::getPos() const //---------------------------------------------------------------------- bool FMouseData::isLeftButtonPressed() const { - return bool(getButtonState().left_button == Pressed); + return bool(getButtonState().left_button == State::Pressed); } //---------------------------------------------------------------------- bool FMouseData::isLeftButtonReleased() const { - return bool(getButtonState().left_button == Released); + return bool(getButtonState().left_button == State::Released); } //---------------------------------------------------------------------- bool FMouseData::isLeftButtonDoubleClick() const { - return bool(getButtonState().left_button == DoubleClick); + return bool(getButtonState().left_button == State::DoubleClick); } //---------------------------------------------------------------------- bool FMouseData::isRightButtonPressed() const { - return bool(getButtonState().right_button == Pressed); + return bool(getButtonState().right_button == State::Pressed); } //---------------------------------------------------------------------- bool FMouseData::isRightButtonReleased() const { - return bool(getButtonState().right_button == Released); + return bool(getButtonState().right_button == State::Released); } //---------------------------------------------------------------------- bool FMouseData::isMiddleButtonPressed() const { - return bool(getButtonState().middle_button == Pressed); + return bool(getButtonState().middle_button == State::Pressed); } //---------------------------------------------------------------------- bool FMouseData::isMiddleButtonReleased() const { - return bool(getButtonState().middle_button == Released); + return bool(getButtonState().middle_button == State::Released); } //---------------------------------------------------------------------- @@ -141,8 +141,15 @@ bool FMouseData::isMoved() const //---------------------------------------------------------------------- void FMouseData::clearButtonState() { - // Fill bit field with 0 - std::memset(&b_state, 0x00, sizeof(b_state)); + b_state.left_button = State::Undefined; + b_state.right_button = State::Undefined; + b_state.middle_button = State::Undefined; + b_state.shift_button = 0; + b_state.control_button = 0; + b_state.meta_button = 0; + b_state.wheel_up = 0; + b_state.wheel_down = 0; + b_state.mouse_moved = 0; } @@ -433,16 +440,16 @@ void FMouseGPM::interpretKeyDown() if ( gpm_ev.buttons & GPM_B_LEFT ) { if ( gpm_ev.type & GPM_DOUBLE ) - getButtonState().left_button = DoubleClick; + getButtonState().left_button = State::DoubleClick; else - getButtonState().left_button = Pressed; + getButtonState().left_button = State::Pressed; } if ( gpm_ev.buttons & GPM_B_MIDDLE ) - getButtonState().middle_button = Pressed; + getButtonState().middle_button = State::Pressed; if ( gpm_ev.buttons & GPM_B_RIGHT ) - getButtonState().right_button = Pressed; + getButtonState().right_button = State::Pressed; if ( gpm_ev.buttons & GPM_B_UP ) getButtonState().wheel_up = true; @@ -465,13 +472,13 @@ void FMouseGPM::interpretKeyDown() void FMouseGPM::interpretKeyUp() { if ( gpm_ev.buttons & GPM_B_LEFT ) - getButtonState().left_button = Released; + getButtonState().left_button = State::Released; if ( gpm_ev.buttons & GPM_B_MIDDLE ) - getButtonState().middle_button = Released; + getButtonState().middle_button = State::Released; if ( gpm_ev.buttons & GPM_B_RIGHT ) - getButtonState().right_button = Released; + getButtonState().right_button = State::Released; } //---------------------------------------------------------------------- @@ -619,13 +626,13 @@ void FMouseX11::processEvent (struct timeval* time) void FMouseX11::setKeyState (int btn) { if ( (btn & key_shift) == key_shift ) - getButtonState().shift_button = Pressed; + getButtonState().shift_button = true; if ( (btn & key_meta) == key_meta ) - getButtonState().meta_button = Pressed; + getButtonState().meta_button = true; if ( (btn & key_ctrl) == key_ctrl ) - getButtonState().control_button = Pressed; + getButtonState().control_button = true; } //---------------------------------------------------------------------- @@ -655,25 +662,25 @@ void FMouseX11::setButtonState (const int btn, const struct timeval* time) && ! isDblclickTimeout(getMousePressedTime()) ) { resetMousePressedTime(); - getButtonState().left_button = DoubleClick; + getButtonState().left_button = State::DoubleClick; } else { setMousePressedTime (time); // save click time - getButtonState().left_button = Pressed; + getButtonState().left_button = State::Pressed; } break; case button2_pressed: case button2_pressed_move: resetMousePressedTime(); - getButtonState().middle_button = Pressed; + getButtonState().middle_button = State::Pressed; break; case button3_pressed: case button3_pressed_move: resetMousePressedTime(); - getButtonState().right_button = Pressed; + getButtonState().right_button = State::Pressed; break; case all_buttons_released: @@ -681,17 +688,17 @@ void FMouseX11::setButtonState (const int btn, const struct timeval* time) { case button1_pressed: case button1_pressed_move: - getButtonState().left_button = Released; + getButtonState().left_button = State::Released; break; case button2_pressed: case button2_pressed_move: - getButtonState().middle_button = Released; + getButtonState().middle_button = State::Released; break; case button3_pressed: case button3_pressed_move: - getButtonState().right_button = Released; + getButtonState().right_button = State::Released; break; default: @@ -701,12 +708,12 @@ void FMouseX11::setButtonState (const int btn, const struct timeval* time) case button_up: resetMousePressedTime(); - getButtonState().wheel_up = Pressed; + getButtonState().wheel_up = true; break; case button_down: resetMousePressedTime(); - getButtonState().wheel_down = Pressed; + getButtonState().wheel_down = true; break; default: @@ -881,25 +888,25 @@ void FMouseSGR::setPressedButtonState ( const int btn && ! isDblclickTimeout(getMousePressedTime()) ) { resetMousePressedTime(); - getButtonState().left_button = DoubleClick; + getButtonState().left_button = State::DoubleClick; } else { setMousePressedTime (time); // save click time - getButtonState().left_button = Pressed; + getButtonState().left_button = State::Pressed; } break; case button2: case button2_move: resetMousePressedTime(); - getButtonState().middle_button = Pressed; + getButtonState().middle_button = State::Pressed; break; case button3: case button3_move: resetMousePressedTime(); - getButtonState().right_button = Pressed; + getButtonState().right_button = State::Pressed; break; case button_up: @@ -926,17 +933,17 @@ void FMouseSGR::setReleasedButtonState (const int btn) { case button1: case button1_move: - getButtonState().left_button = Released; + getButtonState().left_button = State::Released; break; case button2: case button2_move: - getButtonState().middle_button = Released; + getButtonState().middle_button = State::Released; break; case button3: case button3_move: - getButtonState().right_button = Released; + getButtonState().right_button = State::Released; break; default: @@ -1100,13 +1107,13 @@ void FMouseUrxvt::processEvent (struct timeval* time) void FMouseUrxvt::setKeyState (int btn) { if ( (btn & key_shift) == key_shift ) - getButtonState().shift_button = Pressed; + getButtonState().shift_button = true; if ( (btn & key_meta) == key_meta ) - getButtonState().meta_button = Pressed; + getButtonState().meta_button = true; if ( (btn & key_ctrl) == key_ctrl ) - getButtonState().control_button = Pressed; + getButtonState().control_button = true; } //---------------------------------------------------------------------- @@ -1136,25 +1143,25 @@ void FMouseUrxvt::setButtonState (const int btn, const struct timeval* time) && ! isDblclickTimeout(getMousePressedTime()) ) { resetMousePressedTime(); - getButtonState().left_button = DoubleClick; + getButtonState().left_button = State::DoubleClick; } else { setMousePressedTime (time); // save click time - getButtonState().left_button = Pressed; + getButtonState().left_button = State::Pressed; } break; case button2_pressed: case button2_pressed_move: resetMousePressedTime(); - getButtonState().middle_button = Pressed; + getButtonState().middle_button = State::Pressed; break; case button3_pressed: case button3_pressed_move: resetMousePressedTime(); - getButtonState().right_button = Pressed; + getButtonState().right_button = State::Pressed; break; case all_buttons_released: @@ -1162,17 +1169,17 @@ void FMouseUrxvt::setButtonState (const int btn, const struct timeval* time) { case button1_pressed: case button1_pressed_move: - getButtonState().left_button = Released; + getButtonState().left_button = State::Released; break; case button2_pressed: case button2_pressed_move: - getButtonState().middle_button = Released; + getButtonState().middle_button = State::Released; break; case button3_pressed: case button3_pressed_move: - getButtonState().right_button = Released; + getButtonState().right_button = State::Released; break; default: @@ -1182,12 +1189,12 @@ void FMouseUrxvt::setButtonState (const int btn, const struct timeval* time) case button_up: resetMousePressedTime(); - getButtonState().wheel_up = Pressed; + getButtonState().wheel_up = true; break; case button_down: resetMousePressedTime(); - getButtonState().wheel_down = Pressed; + getButtonState().wheel_down = true; break; default: @@ -1206,12 +1213,12 @@ FMouseControl::FMouseControl() { #ifdef F_HAVE_LIBGPM if ( FTerm::isLinuxTerm() ) - mouse_protocol[FMouse::gpm].reset(FMouse::createMouseObject()); + mouse_protocol[FMouse::MouseType::gpm].reset(FMouse::createMouseObject()); #endif - mouse_protocol[FMouse::x11].reset(FMouse::createMouseObject()); - mouse_protocol[FMouse::sgr].reset(FMouse::createMouseObject()); - mouse_protocol[FMouse::urxvt].reset(FMouse::createMouseObject()); + mouse_protocol[FMouse::MouseType::x11].reset(FMouse::createMouseObject()); + mouse_protocol[FMouse::MouseType::sgr].reset(FMouse::createMouseObject()); + mouse_protocol[FMouse::MouseType::urxvt].reset(FMouse::createMouseObject()); } //---------------------------------------------------------------------- @@ -1234,7 +1241,7 @@ const FPoint& FMouseControl::getPos() //---------------------------------------------------------------------- void FMouseControl::clearEvent() { - FMouse::mouse_type mtype; + FMouse::MouseType mtype; do { @@ -1243,14 +1250,14 @@ void FMouseControl::clearEvent() if ( mouse_protocol[mtype] ) mouse_protocol[mtype]->clearEvent(); } - while ( mtype != FMouse::none ); + while ( mtype != FMouse::MouseType::none ); } //---------------------------------------------------------------------- #ifdef F_HAVE_LIBGPM void FMouseControl::setStdinNo (int file_descriptor) { - auto mouse = mouse_protocol[FMouse::gpm].get(); + auto mouse = mouse_protocol[FMouse::MouseType::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1264,13 +1271,13 @@ void FMouseControl::setStdinNo (int) //---------------------------------------------------------------------- void FMouseControl::setMaxWidth (uInt16 x_max) { - mouse_protocol[FMouse::urxvt]->setMaxWidth(x_max); + mouse_protocol[FMouse::MouseType::urxvt]->setMaxWidth(x_max); } //---------------------------------------------------------------------- void FMouseControl::setMaxHeight (uInt16 y_max) { - mouse_protocol[FMouse::urxvt]->setMaxHeight(y_max); + mouse_protocol[FMouse::MouseType::urxvt]->setMaxHeight(y_max); } //---------------------------------------------------------------------- @@ -1479,7 +1486,7 @@ bool FMouseControl::isGpmMouseEnabled() if ( mouse_protocol.empty() ) return false; - const auto& mouse = mouse_protocol[FMouse::gpm].get(); + const auto& mouse = mouse_protocol[FMouse::MouseType::gpm].get(); const auto& gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1500,7 +1507,7 @@ void FMouseControl::enable() #ifdef F_HAVE_LIBGPM if ( use_gpm_mouse ) { - auto mouse = mouse_protocol[FMouse::gpm].get(); + auto mouse = mouse_protocol[FMouse::MouseType::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1518,7 +1525,7 @@ void FMouseControl::disable() #ifdef F_HAVE_LIBGPM if ( use_gpm_mouse ) { - auto mouse = mouse_protocol[FMouse::gpm].get(); + auto mouse = mouse_protocol[FMouse::MouseType::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1531,7 +1538,7 @@ void FMouseControl::disable() } //---------------------------------------------------------------------- -void FMouseControl::setRawData ( FMouse::mouse_type mt +void FMouseControl::setRawData ( FMouse::MouseType mt , FKeyboard::keybuffer& fifo_buf) { auto mouse = mouse_protocol[mt].get(); @@ -1583,7 +1590,7 @@ bool FMouseControl::getGpmKeyPressed (bool pending) if ( mouse_protocol.empty() ) return false; - auto mouse = mouse_protocol[FMouse::gpm].get(); + auto mouse = mouse_protocol[FMouse::MouseType::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1605,7 +1612,7 @@ void FMouseControl::drawPointer() if ( mouse_protocol.empty() ) return; - auto mouse = mouse_protocol[FMouse::gpm].get(); + auto mouse = mouse_protocol[FMouse::MouseType::gpm].get(); auto gpm_mouse = static_cast(mouse); if ( gpm_mouse ) @@ -1619,7 +1626,7 @@ void FMouseControl::drawPointer() // private methods of FMouseControl //---------------------------------------------------------------------- -FMouse::mouse_type FMouseControl::getMouseWithData() +FMouse::MouseType FMouseControl::getMouseWithData() { const auto& iter = \ std::find_if ( std::begin(mouse_protocol) @@ -1631,11 +1638,11 @@ FMouse::mouse_type FMouseControl::getMouseWithData() } ); - return ( iter != mouse_protocol.end() ) ? iter->first : FMouse::none; + return ( iter != mouse_protocol.end() ) ? iter->first : FMouse::MouseType::none; } //---------------------------------------------------------------------- -FMouse::mouse_type FMouseControl::getMouseWithEvent() +FMouse::MouseType FMouseControl::getMouseWithEvent() { const auto& iter = \ std::find_if ( std::begin(mouse_protocol) @@ -1647,7 +1654,7 @@ FMouse::mouse_type FMouseControl::getMouseWithEvent() } ); - return ( iter != mouse_protocol.end() ) ? iter->first : FMouse::none; + return ( iter != mouse_protocol.end() ) ? iter->first : FMouse::MouseType::none; } //---------------------------------------------------------------------- diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index a6b7f2a6..0dd70e52 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -261,16 +261,16 @@ void FScrollbar::onMouseDown (FMouseEvent* ev) // Process left mouse button scroll_type = getClickedScrollType(mouse_x, mouse_y); - if ( scroll_type == FScrollbar::noScroll ) + if ( scroll_type == SType::noScroll ) { slider_click_pos = getSliderClickPos (mouse_x, mouse_y); if ( slider_click_pos > 0 ) - scroll_type = FScrollbar::scrollJump; + scroll_type = SType::scrollJump; } - if ( scroll_type == FScrollbar::scrollPageBackward - || scroll_type == FScrollbar::scrollPageForward ) + if ( scroll_type == SType::scrollPageBackward + || scroll_type == SType::scrollPageForward ) { if ( bar_orientation == fc::vertical ) slider_click_stop_pos = mouse_y - 2; @@ -285,8 +285,8 @@ void FScrollbar::onMouseDown (FMouseEvent* ev) else slider_click_stop_pos = -1; - if ( scroll_type >= FScrollbar::scrollStepBackward - && scroll_type <= FScrollbar::scrollPageForward ) + if ( scroll_type >= SType::scrollStepBackward + && scroll_type <= SType::scrollPageForward ) { processScroll(); threshold_reached = false; @@ -303,10 +303,10 @@ void FScrollbar::onMouseUp (FMouseEvent* ev) slider_click_pos = -1; - if ( scroll_type != FScrollbar::noScroll ) + if ( scroll_type != SType::noScroll ) { delOwnTimers(); - scroll_type = FScrollbar::noScroll; + scroll_type = SType::noScroll; } } @@ -327,9 +327,9 @@ void FScrollbar::onMouseMove (FMouseEvent* ev) } // Process left mouse button - const int new_scroll_type = getClickedScrollType(mouse_x, mouse_y); + const auto new_scroll_type = getClickedScrollType(mouse_x, mouse_y); - if ( scroll_type == FScrollbar::scrollJump ) + if ( scroll_type == SType::scrollJump ) { int new_val{}; @@ -362,7 +362,7 @@ void FScrollbar::onMouseMove (FMouseEvent* ev) { delOwnTimers(); } - else if ( scroll_type != FScrollbar::scrollJump ) + else if ( scroll_type != SType::scrollJump ) { addTimer(repeat_time); } @@ -378,16 +378,16 @@ void FScrollbar::onWheel (FWheelEvent* ev) { const int wheel = ev->getWheel(); - if ( scroll_type != FScrollbar::noScroll ) + if ( scroll_type != SType::noScroll ) { delOwnTimers(); - scroll_type = FScrollbar::noScroll; + scroll_type = SType::noScroll; } if ( wheel == fc::WheelUp ) - scroll_type = FScrollbar::scrollWheelUp; + scroll_type = SType::scrollWheelUp; else if ( wheel == fc::WheelDown ) - scroll_type = FScrollbar::scrollWheelDown; + scroll_type = SType::scrollWheelDown; processScroll(); } @@ -395,7 +395,7 @@ void FScrollbar::onWheel (FWheelEvent* ev) //---------------------------------------------------------------------- void FScrollbar::onTimer (FTimerEvent*) { - if ( scroll_type == FScrollbar::noScroll ) + if ( scroll_type == SType::noScroll ) return; if ( ! threshold_reached ) @@ -406,20 +406,20 @@ void FScrollbar::onTimer (FTimerEvent*) } // Timer stop condition - if ( ( scroll_type == FScrollbar::scrollPageBackward + if ( ( scroll_type == SType::scrollPageBackward && slider_pos == slider_click_stop_pos ) - || ( scroll_type == FScrollbar::scrollPageForward + || ( scroll_type == SType::scrollPageForward && slider_pos == slider_click_stop_pos ) ) { const auto max_slider_pos = int(bar_length - slider_length); - if ( scroll_type == FScrollbar::scrollPageBackward + if ( scroll_type == SType::scrollPageBackward && slider_pos == 0 ) { jumpToClickPos(0); // Scroll to the start processScroll(); } - else if ( scroll_type == FScrollbar::scrollPageForward + else if ( scroll_type == SType::scrollPageForward && slider_pos == max_slider_pos ) { jumpToClickPos (max_slider_pos); // Scroll to the end @@ -613,7 +613,7 @@ void FScrollbar::drawButtons() } //---------------------------------------------------------------------- -FScrollbar::sType FScrollbar::getClickedScrollType (int x, int y) const +FScrollbar::SType FScrollbar::getClickedScrollType (int x, int y) const { if ( bar_orientation == fc::vertical ) { @@ -626,72 +626,72 @@ FScrollbar::sType FScrollbar::getClickedScrollType (int x, int y) const } //---------------------------------------------------------------------- -FScrollbar::sType FScrollbar::getVerticalClickedScrollType (int y) const +FScrollbar::SType FScrollbar::getVerticalClickedScrollType (int y) const { if ( y == 1 ) { - return FScrollbar::scrollStepBackward; // decrement button + return SType::scrollStepBackward; // decrement button } else if ( y > 1 && y <= slider_pos + 1 ) { - return FScrollbar::scrollPageBackward; // before slider + return SType::scrollPageBackward; // before slider } else if ( y > slider_pos + int(slider_length) + 1 && y < int(getHeight()) ) { - return FScrollbar::scrollPageForward; // after slider + return SType::scrollPageForward; // after slider } else if ( y == int(getHeight()) ) { - return FScrollbar::scrollStepForward; // increment button + return SType::scrollStepForward; // increment button } - return FScrollbar::noScroll; + return SType::noScroll; } //---------------------------------------------------------------------- -FScrollbar::sType FScrollbar::getHorizontalClickedScrollType (int x) const +FScrollbar::SType FScrollbar::getHorizontalClickedScrollType (int x) const { if ( FTerm::isNewFont() ) { if ( x == 1 || x == 2 ) { - return FScrollbar::scrollStepBackward; // decrement button + return SType::scrollStepBackward; // decrement button } else if ( x > 2 && x <= slider_pos + 2 ) { - return FScrollbar::scrollPageBackward; // before slider + return SType::scrollPageBackward; // before slider } else if ( x > slider_pos + int(slider_length) + 2 && x < int(getWidth()) - 1 ) { - return FScrollbar::scrollPageForward; // after slider + return SType::scrollPageForward; // after slider } else if ( x == int(getWidth()) - 1 || x == int(getWidth()) ) { - return FScrollbar::scrollStepForward; // increment button + return SType::scrollStepForward; // increment button } - return FScrollbar::noScroll; + return SType::noScroll; } else { if ( x == 1 ) { - return FScrollbar::scrollStepBackward; // decrement button + return SType::scrollStepBackward; // decrement button } else if ( x > 1 && x <= slider_pos + 1 ) { - return FScrollbar::scrollPageBackward; // before slider + return SType::scrollPageBackward; // before slider } else if ( x > slider_pos + int(slider_length) + 1 && x < int(getWidth()) ) { - return FScrollbar::scrollPageForward; // after slider + return SType::scrollPageForward; // after slider } else if ( x == int(getWidth()) ) { - return FScrollbar::scrollStepForward; // increment button + return SType::scrollStepForward; // increment button } - return FScrollbar::noScroll; + return SType::noScroll; } } @@ -758,7 +758,7 @@ void FScrollbar::jumpToClickPos (int x, int y) setValue(new_val); drawBar(); forceTerminalUpdate(); - scroll_type = FScrollbar::scrollJump; + scroll_type = SType::scrollJump; processScroll(); } } @@ -781,9 +781,9 @@ void FScrollbar::jumpToClickPos (int pos) void FScrollbar::avoidScrollOvershoot() { // Avoid overshoot - if ( ( scroll_type == FScrollbar::scrollPageBackward + if ( ( scroll_type == SType::scrollPageBackward && slider_pos < slider_click_stop_pos ) - || ( scroll_type == FScrollbar::scrollPageForward + || ( scroll_type == SType::scrollPageForward && slider_pos > slider_click_stop_pos ) ) { jumpToClickPos (slider_click_stop_pos); diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 9c10d532..18d58ee6 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -865,19 +865,19 @@ void FScrollView::setViewportCursor() //---------------------------------------------------------------------- void FScrollView::cb_vbarChange (const FWidget*) { - FScrollbar::sType scrollType = vbar->getScrollType(); + FScrollbar::SType scrollType = vbar->getScrollType(); static constexpr int wheel_distance = 4; int distance{1}; - assert ( scrollType == FScrollbar::noScroll - || scrollType == FScrollbar::scrollJump - || scrollType == FScrollbar::scrollStepBackward - || scrollType == FScrollbar::scrollStepForward - || scrollType == FScrollbar::scrollPageBackward - || scrollType == FScrollbar::scrollPageForward - || scrollType == FScrollbar::scrollWheelUp - || scrollType == FScrollbar::scrollWheelDown ); + assert ( scrollType == FScrollbar::SType::noScroll + || scrollType == FScrollbar::SType::scrollJump + || scrollType == FScrollbar::SType::scrollStepBackward + || scrollType == FScrollbar::SType::scrollStepForward + || scrollType == FScrollbar::SType::scrollPageBackward + || scrollType == FScrollbar::SType::scrollPageForward + || scrollType == FScrollbar::SType::scrollWheelUp + || scrollType == FScrollbar::SType::scrollWheelDown ); - if ( scrollType >= FScrollbar::scrollStepBackward ) + if ( scrollType >= FScrollbar::SType::scrollStepBackward ) { update_scrollbar = true; } @@ -888,32 +888,32 @@ void FScrollView::cb_vbarChange (const FWidget*) switch ( scrollType ) { - case FScrollbar::noScroll: + case FScrollbar::SType::noScroll: break; - case FScrollbar::scrollPageBackward: + case FScrollbar::SType::scrollPageBackward: distance = int(getViewportHeight()); // fall through - case FScrollbar::scrollStepBackward: + case FScrollbar::SType::scrollStepBackward: scrollBy (0, -distance); break; - case FScrollbar::scrollPageForward: + case FScrollbar::SType::scrollPageForward: distance = int(getViewportHeight()); // fall through - case FScrollbar::scrollStepForward: + case FScrollbar::SType::scrollStepForward: scrollBy (0, distance); break; - case FScrollbar::scrollJump: + case FScrollbar::SType::scrollJump: scrollToY (1 + int(vbar->getValue())); break; - case FScrollbar::scrollWheelUp: + case FScrollbar::SType::scrollWheelUp: scrollBy (0, -wheel_distance); break; - case FScrollbar::scrollWheelDown: + case FScrollbar::SType::scrollWheelDown: scrollBy (0, wheel_distance); break; } @@ -924,19 +924,19 @@ void FScrollView::cb_vbarChange (const FWidget*) //---------------------------------------------------------------------- void FScrollView::cb_hbarChange (const FWidget*) { - FScrollbar::sType scrollType = hbar->getScrollType(); + FScrollbar::SType scrollType = hbar->getScrollType(); static constexpr int wheel_distance = 4; int distance{1}; - assert ( scrollType == FScrollbar::noScroll - || scrollType == FScrollbar::scrollJump - || scrollType == FScrollbar::scrollStepBackward - || scrollType == FScrollbar::scrollStepForward - || scrollType == FScrollbar::scrollPageBackward - || scrollType == FScrollbar::scrollPageForward - || scrollType == FScrollbar::scrollWheelUp - || scrollType == FScrollbar::scrollWheelDown ); + assert ( scrollType == FScrollbar::SType::noScroll + || scrollType == FScrollbar::SType::scrollJump + || scrollType == FScrollbar::SType::scrollStepBackward + || scrollType == FScrollbar::SType::scrollStepForward + || scrollType == FScrollbar::SType::scrollPageBackward + || scrollType == FScrollbar::SType::scrollPageForward + || scrollType == FScrollbar::SType::scrollWheelUp + || scrollType == FScrollbar::SType::scrollWheelDown ); - if ( scrollType >= FScrollbar::scrollStepBackward ) + if ( scrollType >= FScrollbar::SType::scrollStepBackward ) { update_scrollbar = true; } @@ -947,32 +947,32 @@ void FScrollView::cb_hbarChange (const FWidget*) switch ( scrollType ) { - case FScrollbar::noScroll: + case FScrollbar::SType::noScroll: break; - case FScrollbar::scrollPageBackward: + case FScrollbar::SType::scrollPageBackward: distance = int(getViewportWidth()); // fall through - case FScrollbar::scrollStepBackward: + case FScrollbar::SType::scrollStepBackward: scrollBy (-distance, 0); break; - case FScrollbar::scrollPageForward: + case FScrollbar::SType::scrollPageForward: distance = int(getViewportWidth()); // fall through - case FScrollbar::scrollStepForward: + case FScrollbar::SType::scrollStepForward: scrollBy (distance, 0); break; - case FScrollbar::scrollJump: + case FScrollbar::SType::scrollJump: scrollToX (1 + int(hbar->getValue())); break; - case FScrollbar::scrollWheelUp: + case FScrollbar::SType::scrollWheelUp: scrollBy (-wheel_distance, 0); break; - case FScrollbar::scrollWheelDown: + case FScrollbar::SType::scrollWheelDown: scrollBy (wheel_distance, 0); break; } diff --git a/src/fterm_functions.cpp b/src/fterm_functions.cpp index 22915191..27d521fd 100644 --- a/src/fterm_functions.cpp +++ b/src/fterm_functions.cpp @@ -460,7 +460,7 @@ std::size_t getColumnWidth (const FString& s, std::size_t pos) } catch (const std::out_of_range& ex) { - std::clog << FLog::Error + std::clog << FLog::LogLevel::Error << "Out of Range error: " << ex.what() << std::endl; } } diff --git a/src/ftermcap.cpp b/src/ftermcap.cpp index 863a354f..5d99d544 100644 --- a/src/ftermcap.cpp +++ b/src/ftermcap.cpp @@ -133,7 +133,7 @@ void FTermcap::termcapError (int status) { const auto& fterm_data = FTerm::getFTermData(); const char* termtype = fterm_data->getTermType(); - std::clog << FLog::Error + std::clog << FLog::LogLevel::Error << "Unknown terminal: \"" << termtype << "\". " << "Check the TERM environment variable. " << "Also make sure that the terminal " diff --git a/src/ftermfreebsd.cpp b/src/ftermfreebsd.cpp index 595cc62c..22ff4e85 100644 --- a/src/ftermfreebsd.cpp +++ b/src/ftermfreebsd.cpp @@ -172,7 +172,7 @@ void FTermFreeBSD::finish() //---------------------------------------------------------------------- void FTermFreeBSD::warnNotInitialized() { - std::clog << FLog::Warn + std::clog << FLog::LogLevel::Warn << "The FTermFreeBSD object has " << "not yet been initialized! " << "Please call the init() method first." diff --git a/src/ftermlinux.cpp b/src/ftermlinux.cpp index e36dc4e0..145c1412 100644 --- a/src/ftermlinux.cpp +++ b/src/ftermlinux.cpp @@ -192,7 +192,7 @@ void FTermLinux::init() } else { - std::clog << FLog::Error << "Can not open the console." << std::endl; + std::clog << FLog::LogLevel::Error << "Can not open the console." << std::endl; std::abort(); } } diff --git a/src/ftermopenbsd.cpp b/src/ftermopenbsd.cpp index d10ed9f6..9e4742ff 100644 --- a/src/ftermopenbsd.cpp +++ b/src/ftermopenbsd.cpp @@ -134,7 +134,7 @@ bool FTermOpenBSD::resetBeep() //---------------------------------------------------------------------- void FTermOpenBSD::warnNotInitialized() { - std::clog << FLog::Warn + std::clog << FLog::LogLevel::Warn << "The FTermOpenBSD object has " << "not yet been initialized! " << "Please call the init() method first." diff --git a/src/ftermxterminal.cpp b/src/ftermxterminal.cpp index 3899fcad..45cfc589 100644 --- a/src/ftermxterminal.cpp +++ b/src/ftermxterminal.cpp @@ -295,7 +295,7 @@ void FTermXTerminal::captureFontAndTitle() //---------------------------------------------------------------------- void FTermXTerminal::warnNotInitialized() const { - std::clog << FLog::Warn + std::clog << FLog::LogLevel::Warn << "The FTermXTerminal object has " << "not yet been initialized! " << "Please call the init() method first." diff --git a/src/ftextview.cpp b/src/ftextview.cpp index a7f1c7c2..756d40c6 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -761,51 +761,51 @@ void FTextView::changeOnResize() const //---------------------------------------------------------------------- void FTextView::cb_vbarChange (const FWidget*) { - const FScrollbar::sType scrollType = vbar->getScrollType(); + const FScrollbar::SType scrollType = vbar->getScrollType(); static constexpr int wheel_distance = 4; int distance{1}; - assert ( scrollType == FScrollbar::noScroll - || scrollType == FScrollbar::scrollJump - || scrollType == FScrollbar::scrollStepBackward - || scrollType == FScrollbar::scrollStepForward - || scrollType == FScrollbar::scrollPageBackward - || scrollType == FScrollbar::scrollPageForward - || scrollType == FScrollbar::scrollWheelUp - || scrollType == FScrollbar::scrollWheelDown ); + assert ( scrollType == FScrollbar::SType::noScroll + || scrollType == FScrollbar::SType::scrollJump + || scrollType == FScrollbar::SType::scrollStepBackward + || scrollType == FScrollbar::SType::scrollStepForward + || scrollType == FScrollbar::SType::scrollPageBackward + || scrollType == FScrollbar::SType::scrollPageForward + || scrollType == FScrollbar::SType::scrollWheelUp + || scrollType == FScrollbar::SType::scrollWheelDown ); - if ( scrollType >= FScrollbar::scrollStepBackward ) + if ( scrollType >= FScrollbar::SType::scrollStepBackward ) update_scrollbar = true; else update_scrollbar = false; switch ( scrollType ) { - case FScrollbar::noScroll: + case FScrollbar::SType::noScroll: break; - case FScrollbar::scrollPageBackward: + case FScrollbar::SType::scrollPageBackward: distance = int(getClientHeight()); // fall through - case FScrollbar::scrollStepBackward: + case FScrollbar::SType::scrollStepBackward: scrollBy (0, -distance); break; - case FScrollbar::scrollPageForward: + case FScrollbar::SType::scrollPageForward: distance = int(getClientHeight()); // fall through - case FScrollbar::scrollStepForward: + case FScrollbar::SType::scrollStepForward: scrollBy (0, distance); break; - case FScrollbar::scrollJump: + case FScrollbar::SType::scrollJump: scrollToY (vbar->getValue()); break; - case FScrollbar::scrollWheelUp: + case FScrollbar::SType::scrollWheelUp: scrollBy (0, -wheel_distance); break; - case FScrollbar::scrollWheelDown: + case FScrollbar::SType::scrollWheelDown: scrollBy (0, wheel_distance); break; } @@ -816,51 +816,51 @@ void FTextView::cb_vbarChange (const FWidget*) //---------------------------------------------------------------------- void FTextView::cb_hbarChange (const FWidget*) { - const FScrollbar::sType scrollType = hbar->getScrollType(); + const FScrollbar::SType scrollType = hbar->getScrollType(); static constexpr int wheel_distance = 4; int distance{1}; - assert ( scrollType == FScrollbar::noScroll - || scrollType == FScrollbar::scrollJump - || scrollType == FScrollbar::scrollStepBackward - || scrollType == FScrollbar::scrollStepForward - || scrollType == FScrollbar::scrollPageBackward - || scrollType == FScrollbar::scrollPageForward - || scrollType == FScrollbar::scrollWheelUp - || scrollType == FScrollbar::scrollWheelDown ); + assert ( scrollType == FScrollbar::SType::noScroll + || scrollType == FScrollbar::SType::scrollJump + || scrollType == FScrollbar::SType::scrollStepBackward + || scrollType == FScrollbar::SType::scrollStepForward + || scrollType == FScrollbar::SType::scrollPageBackward + || scrollType == FScrollbar::SType::scrollPageForward + || scrollType == FScrollbar::SType::scrollWheelUp + || scrollType == FScrollbar::SType::scrollWheelDown ); - if ( scrollType >= FScrollbar::scrollStepBackward ) + if ( scrollType >= FScrollbar::SType::scrollStepBackward ) update_scrollbar = true; else update_scrollbar = false; switch ( scrollType ) { - case FScrollbar::noScroll: + case FScrollbar::SType::noScroll: break; - case FScrollbar::scrollPageBackward: + case FScrollbar::SType::scrollPageBackward: distance = int(getClientWidth()); // fall through - case FScrollbar::scrollStepBackward: + case FScrollbar::SType::scrollStepBackward: scrollBy (-distance, 0); break; - case FScrollbar::scrollPageForward: + case FScrollbar::SType::scrollPageForward: distance = int(getClientWidth()); // fall through - case FScrollbar::scrollStepForward: + case FScrollbar::SType::scrollStepForward: scrollBy (distance, 0); break; - case FScrollbar::scrollJump: + case FScrollbar::SType::scrollJump: scrollToX (hbar->getValue()); break; - case FScrollbar::scrollWheelUp: + case FScrollbar::SType::scrollWheelUp: scrollBy (-wheel_distance, 0); break; - case FScrollbar::scrollWheelDown: + case FScrollbar::SType::scrollWheelDown: scrollBy (wheel_distance, 0); break; } diff --git a/src/include/final/flog.h b/src/include/final/flog.h index 61cab79f..b88b8b75 100644 --- a/src/include/final/flog.h +++ b/src/include/final/flog.h @@ -64,12 +64,12 @@ class FLog : public std::stringbuf using IOManip = std::ostream& (*)(std::ostream&); // Enumerations - enum LogLevel + enum class LogLevel { Info, Warn, Error, Debug }; - enum LineEnding + enum class LineEnding { LF, CR, CRLF }; @@ -106,8 +106,8 @@ class FLog : public std::stringbuf private: // Data member - LogLevel level{Info}; - LineEnding end_of_line{CRLF}; + LogLevel level{LogLevel::Info}; + LineEnding end_of_line{LineEnding::CRLF}; std::mutex mut{}; FLogPrint current_log{std::bind(&FLog::info, this, std::placeholders::_1)}; std::ostream stream{this}; diff --git a/src/include/final/flogger.h b/src/include/final/flogger.h index cb722877..a258b232 100644 --- a/src/include/final/flogger.h +++ b/src/include/final/flogger.h @@ -104,7 +104,7 @@ inline FString FLogger::getClassName() const inline void FLogger::info (const std::string& msg) { std::lock_guard lock_guard(getMutex()); - setLevel() = Info; + setLevel() = LogLevel::Info; printLogLine (msg); } @@ -112,7 +112,7 @@ inline void FLogger::info (const std::string& msg) inline void FLogger::warn (const std::string& msg) { std::lock_guard lock_guard(getMutex()); - setLevel() = Warn; + setLevel() = LogLevel::Warn; printLogLine (msg); } @@ -120,7 +120,7 @@ inline void FLogger::warn (const std::string& msg) inline void FLogger::error (const std::string& msg) { std::lock_guard lock_guard(getMutex()); - setLevel() = Error; + setLevel() = LogLevel::Error; printLogLine (msg); } @@ -128,7 +128,7 @@ inline void FLogger::error (const std::string& msg) inline void FLogger::debug (const std::string& msg) { std::lock_guard lock_guard(getMutex()); - setLevel() = Debug; + setLevel() = LogLevel::Debug; printLogLine (msg); } diff --git a/src/include/final/fmessagebox.h b/src/include/final/fmessagebox.h index e199b34e..4ec19543 100644 --- a/src/include/final/fmessagebox.h +++ b/src/include/final/fmessagebox.h @@ -171,7 +171,7 @@ class FMessageBox : public FDialog std::size_t max_line_width{0}; FColor emphasis_color{getColorTheme()->dialog_emphasis_fg}; ButtonType result_code{ButtonType::Reject}; - FButtonsDigit button_digit{ButtonType::Reject}; + FButtonsDigit button_digit{}; std::size_t num_buttons{0}; std::size_t text_num_lines{0}; bool center_text{false}; diff --git a/src/include/final/fmouse.h b/src/include/final/fmouse.h index 1891e13a..48017c13 100644 --- a/src/include/final/fmouse.h +++ b/src/include/final/fmouse.h @@ -122,22 +122,8 @@ class FMouseData void clearButtonState(); protected: - struct FMouseButton // bit field - { - uChar left_button : 2; // 0..3 - uChar right_button : 2; // 0..3 - uChar middle_button : 2; // 0..3 - uChar shift_button : 1; // 0..1 - uChar control_button : 1; // 0..1 - uChar meta_button : 1; // 0..1 - uChar wheel_up : 1; // 0..1 - uChar wheel_down : 1; // 0..1 - uChar mouse_moved : 1; // 0..1 - uChar : 4; // padding bits - }; - // Enumerations - enum states + enum class State : uChar { Undefined = 0, Pressed = 1, @@ -145,6 +131,19 @@ class FMouseData DoubleClick = 3 }; + struct FMouseButton + { + State left_button{}; + State right_button{}; + State middle_button{}; + bool shift_button{}; + bool control_button{}; + bool meta_button{}; + bool wheel_up{}; + bool wheel_down{}; + bool mouse_moved{}; + }; + // Accessors FMouseButton& getButtonState(); const FMouseButton& getButtonState() const; @@ -167,7 +166,7 @@ class FMouse : public FMouseData { public: // Enumeration - enum mouse_type + enum class MouseType { none = 0, gpm = 1, @@ -537,7 +536,7 @@ class FMouseControl // Methods void enable(); void disable(); - virtual void setRawData ( FMouse::mouse_type + virtual void setRawData ( FMouse::MouseType , FKeyboard::keybuffer& ); virtual void processEvent (struct timeval* time); void processQueuedInput(); @@ -548,11 +547,11 @@ class FMouseControl // Using-declaration using FMousePtr = std::unique_ptr; using FMouseDataPtr = std::unique_ptr; - using FMouseProtocol = std::map; + using FMouseProtocol = std::map; // Accessor - FMouse::mouse_type getMouseWithData(); - FMouse::mouse_type getMouseWithEvent(); + FMouse::MouseType getMouseWithData(); + FMouse::MouseType getMouseWithEvent(); void xtermMouse (bool) const; void enableXTermMouse() const; void disableXTermMouse() const; diff --git a/src/include/final/fscrollbar.h b/src/include/final/fscrollbar.h index 6e394fb5..b615ef9a 100644 --- a/src/include/final/fscrollbar.h +++ b/src/include/final/fscrollbar.h @@ -74,7 +74,7 @@ class FScrollbar : public FWidget using FWidget::setGeometry; // Enumeration - enum sType + enum class SType { noScroll = 0, scrollJump = 1, @@ -102,7 +102,7 @@ class FScrollbar : public FWidget // Accessors FString getClassName() const override; int getValue() const; - sType getScrollType() const; + SType getScrollType() const; // Mutators void setMinimum (int); @@ -138,9 +138,9 @@ class FScrollbar : public FWidget void drawHorizontalBar(); void drawHorizontalBackgroundColumn(); void drawButtons(); - sType getClickedScrollType (int, int) const; - sType getVerticalClickedScrollType (int) const; - sType getHorizontalClickedScrollType (int) const; + SType getClickedScrollType (int, int) const; + SType getVerticalClickedScrollType (int) const; + SType getHorizontalClickedScrollType (int) const; int getSliderClickPos (int, int) const; void jumpToClickPos (int, int); void jumpToClickPos (int); @@ -149,7 +149,7 @@ class FScrollbar : public FWidget void changeOnResize(); // Data members - sType scroll_type{FScrollbar::noScroll}; + SType scroll_type{SType::noScroll}; bool threshold_reached{false}; int threshold_time{500}; int repeat_time{80}; @@ -211,7 +211,7 @@ inline int FScrollbar::getValue() const { return val; } //---------------------------------------------------------------------- -inline FScrollbar::sType FScrollbar::getScrollType() const +inline FScrollbar::SType FScrollbar::getScrollType() const { return scroll_type; } } // namespace finalcut diff --git a/src/include/final/ftypes.h b/src/include/final/ftypes.h index 4bbba54d..407e984a 100644 --- a/src/include/final/ftypes.h +++ b/src/include/final/ftypes.h @@ -43,7 +43,7 @@ #define null nullptr #define badAllocOutput(object_name) \ - std::clog << FLog::Error \ + std::clog << FLog::LogLevel::Error \ << __FILE__ << ":" << __LINE__ \ << ": Not enough memory to alloc " \ << (object_name) \ diff --git a/test/flogger-test.cpp b/test/flogger-test.cpp index c3aee10c..33f0e4bd 100644 --- a/test/flogger-test.cpp +++ b/test/flogger-test.cpp @@ -149,11 +149,11 @@ void FLoggerTest::defaultObjectTest() CPPUNIT_ASSERT ( buf.str() == "[INFO] Hello, World!\n\r\n" ); buf.str(""); // Clear buffer - log << finalcut::FLog::Info << "Hello, World!" << std::flush; + log << finalcut::FLog::LogLevel::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; + log << finalcut::FLog::LogLevel::Warn << "Hello, World!" << std::flush; CPPUNIT_ASSERT ( buf.str() == "[WARNING] Hello, World!\r\n" ); buf.str(""); // Clear buffer @@ -161,7 +161,7 @@ void FLoggerTest::defaultObjectTest() CPPUNIT_ASSERT ( buf.str() == "[WARNING] Hello, World!\r\n" ); buf.str(""); // Clear buffer - log << finalcut::FLog::Error << "Hello, World!" << std::flush; + log << finalcut::FLog::LogLevel::Error << "Hello, World!" << std::flush; CPPUNIT_ASSERT ( buf.str() == "[ERROR] Hello, World!\r\n" ); buf.str(""); // Clear buffer @@ -169,7 +169,7 @@ void FLoggerTest::defaultObjectTest() CPPUNIT_ASSERT ( buf.str() == "[ERROR] Hello, World!\r\n" ); buf.str(""); // Clear buffer - log << finalcut::FLog::Debug << "Hello, World!" << std::flush; + log << finalcut::FLog::LogLevel::Debug << "Hello, World!" << std::flush; CPPUNIT_ASSERT ( buf.str() == "[DEBUG] Hello, World!\r\n" ); buf.str(""); // Clear buffer @@ -206,17 +206,17 @@ void FLoggerTest::lineEndingTest() CPPUNIT_ASSERT ( buf.str() == "[INFO] Line endings\r\n" ); buf.str(""); // Clear buffer - log.setLineEnding(finalcut::FLog::LF); + log.setLineEnding(finalcut::FLog::LineEnding::LF); log.warn("Line endings"); CPPUNIT_ASSERT ( buf.str() == "[WARNING] Line endings\n" ); buf.str(""); // Clear buffer - log.setLineEnding(finalcut::FLog::CR); + log.setLineEnding(finalcut::FLog::LineEnding::CR); log.error("Line endings"); CPPUNIT_ASSERT ( buf.str() == "[ERROR] Line endings\r" ); buf.str(""); // Clear buffer - log.setLineEnding(finalcut::FLog::CRLF); + log.setLineEnding(finalcut::FLog::LineEnding::CRLF); log.debug("Line endings"); CPPUNIT_ASSERT ( buf.str() == "[DEBUG] Line endings\r\n" ); buf.str(""); // Clear buffer @@ -258,17 +258,17 @@ void FLoggerTest::fileTest() { finalcut::FLogger log{}; std::ofstream file_stream(filename, std::ofstream::out); - log.setLineEnding (finalcut::FLog::LF); + log.setLineEnding (finalcut::FLog::LineEnding::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; + log << finalcut::FLog::LogLevel::Info << "streaming test1"; + log << finalcut::FLog::LogLevel::Warn << "streaming test2"; + log << finalcut::FLog::LogLevel::Error << "streaming test3"; + log << finalcut::FLog::LogLevel::Debug << "streaming test4" << std::flush; if ( file_stream.is_open() ) file_stream.close(); @@ -308,7 +308,7 @@ void FLoggerTest::fileTest() { finalcut::FLogger log{}; log.setOutputStream(std::cerr); - log.setLineEnding (finalcut::FLog::LF); + log.setLineEnding (finalcut::FLog::LineEnding::LF); log.error("Cannot delete the test.log file"); } } @@ -347,16 +347,16 @@ void FLoggerTest::applicationObjectTest() CPPUNIT_ASSERT ( buf.str() == "[INFO] test5\r\n" ); buf.str(""); // Clear buffer - *log << finalcut::FLog::Error << "test6" << std::flush; + *log << finalcut::FLog::LogLevel::Error << "test6" << std::flush; CPPUNIT_ASSERT ( buf.str() == "[ERROR] test6\r\n" ); buf.str(""); // Clear buffer // Logging to std::clog - std::clog << finalcut::FLog::Info << "test7" << std::flush; + std::clog << finalcut::FLog::LogLevel::Info << "test7" << std::flush; CPPUNIT_ASSERT ( buf.str() == "[INFO] test7\r\n" ); buf.str(""); // Clear buffer - std::clog << finalcut::FLog::Warn << "test8" << std::endl; + std::clog << finalcut::FLog::LogLevel::Warn << "test8" << std::endl; CPPUNIT_ASSERT ( buf.str() == "[WARNING] test8\n\r\n" ); buf.str(""); // Clear buffer @@ -382,11 +382,11 @@ void FLoggerTest::applicationObjectTest() buf.str(""); // Clear buffer // Logging to std::clog with the replaced logger - std::clog << finalcut::FLog::Info << "myLogger 5" << std::flush; + std::clog << finalcut::FLog::LogLevel::Info << "myLogger 5" << std::flush; CPPUNIT_ASSERT ( buf.str() == " Info: myLogger 5\n" ); buf.str(""); // Clear buffer - std::clog << finalcut::FLog::Error << "myLogger 6" << std::endl; + std::clog << finalcut::FLog::LogLevel::Error << "myLogger 6" << std::endl; CPPUNIT_ASSERT ( buf.str() == "Error: myLogger 6\n\n" ); buf.str(""); // Clear buffer diff --git a/test/fmouse-test.cpp b/test/fmouse-test.cpp index c6002b75..00b8254a 100644 --- a/test/fmouse-test.cpp +++ b/test/fmouse-test.cpp @@ -1267,7 +1267,7 @@ void FMouseTest::mouseControlTest() finalcut::FKeyboard::keybuffer rawdata1 = \ { 0x1b, '[', 'M', 0x20, 0x25, 0x28 , 0x1b, '[', 'M', 0x23, 0x25, 0x28 }; - mouse_control.setRawData (finalcut::FMouse::x11, rawdata1); + mouse_control.setRawData (finalcut::FMouse::MouseType::x11, rawdata1); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() ); @@ -1292,7 +1292,7 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() ); - mouse_control.setRawData (finalcut::FMouse::x11, rawdata1); + mouse_control.setRawData (finalcut::FMouse::MouseType::x11, rawdata1); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( ! mouse_control.hasUnprocessedInput() ); CPPUNIT_ASSERT ( ! mouse_control.isLeftButtonPressed() ); @@ -1303,7 +1303,7 @@ void FMouseTest::mouseControlTest() finalcut::FKeyboard::keybuffer rawdata2 = \ { 0x1b, '[', '<', '1', ';', '1', ';', '1', 'M' , 0x1b, '[', '<', '1', ';', '1', ';', '1', 'm' }; - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata2); + mouse_control.setRawData (finalcut::FMouse::MouseType::sgr, rawdata2); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() ); finalcut::FObject::getCurrentTime(&tv); @@ -1325,7 +1325,7 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isWheelDown() ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata2); + mouse_control.setRawData (finalcut::FMouse::MouseType::sgr, rawdata2); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( ! mouse_control.hasUnprocessedInput() ); CPPUNIT_ASSERT ( ! mouse_control.isMiddleButtonPressed() ); @@ -1334,7 +1334,7 @@ void FMouseTest::mouseControlTest() // Right mouse button on a urxvt mouse finalcut::FKeyboard::keybuffer rawdata3 = { 0x1b, '[', '3', '4', ';', '3', ';', '3', 'M' , 0x1b, '[', '3', '5', ';', '3', ';', '4', 'M' }; - mouse_control.setRawData (finalcut::FMouse::urxvt, rawdata3); + mouse_control.setRawData (finalcut::FMouse::MouseType::urxvt, rawdata3); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() ); finalcut::FObject::getCurrentTime(&tv); @@ -1356,7 +1356,7 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isWheelDown() ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::urxvt, rawdata3); + mouse_control.setRawData (finalcut::FMouse::MouseType::urxvt, rawdata3); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(3, 4) ); CPPUNIT_ASSERT ( ! mouse_control.hasUnprocessedInput() ); @@ -1367,7 +1367,7 @@ void FMouseTest::mouseControlTest() finalcut::FKeyboard::keybuffer rawdata4 = \ { 0x1b, '[', 'M', 0x60, 0x70, 0x39 , 0x1b, '[', 'M', 0x61, 0x70, 0x39 }; - mouse_control.setRawData (finalcut::FMouse::x11, rawdata4); + mouse_control.setRawData (finalcut::FMouse::MouseType::x11, rawdata4); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() ); finalcut::FObject::getCurrentTime(&tv); @@ -1389,7 +1389,7 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isWheelDown() ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::x11, rawdata4); + mouse_control.setRawData (finalcut::FMouse::MouseType::x11, rawdata4); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( ! mouse_control.hasUnprocessedInput() ); CPPUNIT_ASSERT ( mouse_control.isWheelDown() ); @@ -1399,7 +1399,7 @@ void FMouseTest::mouseControlTest() { 0x1b, '[', '<', '0', ';', '1', ';', '2', 'M' , 0x1b, '[', '<', '3', '2', ';', '2', ';', '3', 'M' , 0x1b, '[', '<', '0', ';', '3', ';', '4', 'm' }; - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata5); + mouse_control.setRawData (finalcut::FMouse::MouseType::sgr, rawdata5); CPPUNIT_ASSERT ( mouse_control.hasData() ); CPPUNIT_ASSERT ( mouse_control.hasUnprocessedInput() ); finalcut::FObject::getCurrentTime(&tv); @@ -1421,12 +1421,12 @@ void FMouseTest::mouseControlTest() CPPUNIT_ASSERT ( ! mouse_control.isWheelDown() ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata5); + mouse_control.setRawData (finalcut::FMouse::MouseType::sgr, rawdata5); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(2, 3) ); CPPUNIT_ASSERT ( mouse_control.isMoved() ); - mouse_control.setRawData (finalcut::FMouse::sgr, rawdata5); + mouse_control.setRawData (finalcut::FMouse::MouseType::sgr, rawdata5); mouse_control.processEvent (&tv); CPPUNIT_ASSERT ( mouse_control.getPos() == finalcut::FPoint(3, 4) ); CPPUNIT_ASSERT ( ! mouse_control.isMoved() ); From 783f58bc4b5dc3913f2ac3bc3a610ed321f1f30c Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sun, 6 Dec 2020 02:45:21 +0100 Subject: [PATCH 09/45] .travis.yml --- .github/workflows/codeql-analysis.yml | 4 ++-- .travis.yml | 2 +- README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2f58b012..975a12d6 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -7,10 +7,10 @@ name: "CodeQL" on: push: - branches: [master] + branches: [main] pull_request: # The branches below must be a subset of the branches above - branches: [master] + branches: [main] schedule: - cron: '0 7 * * 2' diff --git a/.travis.yml b/.travis.yml index fcabedb0..8c339351 100644 --- a/.travis.yml +++ b/.travis.yml @@ -67,7 +67,7 @@ jobs: notification_email: guru.mail@muenster.de build_command_prepend: "autoreconf -v --install --force && ./configure --prefix=/usr CPPFLAGS='-DDEBUG' CXXFLAGS='-g -O0 -DDEBUG -DUNIT_TEST' --with-unit-test && make clean" build_command: "make V=1 -j10" - branch_pattern: master + branch_pattern: main before_install: - lsb_release -a - uname -a diff --git a/README.md b/README.md index 4958b1a0..6e3742be 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The structure of the Qt framework was originally the inspiration for the C++ cla | *Latest release* | [![Latest Release](https://img.shields.io/github/release/gansm/finalcut.svg)](https://github.com/gansm/finalcut/releases) | | *License* | [![license](https://img.shields.io/github/license/gansm/finalcut.svg?colorA=#333)](COPYING) | | *Class Reference* | [![documented](https://codedocs.xyz/gansm/finalcut.svg)](https://codedocs.xyz/gansm/finalcut/hierarchy.html) | -| *Travis CI* | [![Build Status](https://travis-ci.org/gansm/finalcut.svg?branch=master)](https://travis-ci.org/gansm/finalcut) +| *Travis CI* | [![Build Status](https://travis-ci.org/gansm/finalcut.svg?branch=main)](https://travis-ci.org/gansm/finalcut) | *Coverity Scan* | [![Coverity Scan Status](https://img.shields.io/coverity/scan/6508.svg)](https://scan.coverity.com/projects/6508 )| | *LGTM* | [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/gansm/finalcut.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/gansm/finalcut/context:cpp) | | *SonarCloud* | [![Quality gate](https://sonarcloud.io/api/project_badges/measure?project=gansm_finalcut&metric=alert_status)](https://sonarcloud.io/dashboard?id=gansm_finalcut) | From b2de303cfc4b6f02ef33933283114d07361b5041 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 31 Dec 2020 20:45:10 +0100 Subject: [PATCH 10/45] Refactoring to scaled enumerations --- ChangeLog | 9 +- doc/first-steps.md | 24 +- doc/user-theme.md | 242 ++--- examples/7segment.cpp | 8 +- examples/background-color.cpp | 17 +- examples/calculator.cpp | 342 +++--- examples/checklist.cpp | 14 +- examples/choice.cpp | 2 +- examples/dialog.cpp | 6 +- examples/event-log.cpp | 36 +- examples/fullwidth-character.cpp | 4 +- examples/input-dialog.cpp | 2 +- examples/keyboard.cpp | 14 +- examples/listview.cpp | 18 +- examples/mandelbrot.cpp | 7 +- examples/menu.cpp | 32 +- examples/mouse.cpp | 65 +- examples/rotozoomer.cpp | 9 +- examples/scrollview.cpp | 8 +- examples/term-attributes.cpp | 50 +- examples/termcap.cpp | 171 +-- examples/timer.cpp | 12 +- examples/transparent.cpp | 33 +- examples/treeview.cpp | 10 +- examples/ui.cpp | 59 +- examples/windows.cpp | 16 +- src/fapplication.cpp | 166 +-- src/fbusyindicator.cpp | 4 +- src/fbutton.cpp | 52 +- src/fbuttongroup.cpp | 10 +- src/fcharmap.cpp | 313 +++--- src/fcheckbox.cpp | 2 +- src/fcolorpalette.cpp | 128 +-- src/fcombobox.cpp | 138 +-- src/fdialog.cpp | 157 ++- src/fevent.cpp | 50 +- src/ffiledialog.cpp | 14 +- src/fkey_map.cpp | 1620 ++++++++++++++-------------- src/fkeyboard.cpp | 84 +- src/flabel.cpp | 49 +- src/flineedit.cpp | 184 ++-- src/flistbox.cpp | 260 ++--- src/flistview.cpp | 289 +++-- src/fmenu.cpp | 167 ++- src/fmenubar.cpp | 133 ++- src/fmenuitem.cpp | 83 +- src/fmessagebox.cpp | 4 +- src/fmouse.cpp | 73 +- src/fobject.cpp | 6 +- src/foptiattr.cpp | 58 +- src/fprogressbar.cpp | 10 +- src/fradiobutton.cpp | 2 +- src/fscrollbar.cpp | 156 +-- src/fscrollview.cpp | 162 +-- src/fspinbox.cpp | 118 +- src/fstartoptions.cpp | 2 +- src/fstatusbar.cpp | 14 +- src/fstring.cpp | 16 +- src/fswitch.cpp | 29 +- src/fterm.cpp | 351 +++--- src/fterm_functions.cpp | 80 +- src/ftermbuffer.cpp | 32 +- src/ftermcap.cpp | 4 +- src/ftermcapquirks.cpp | 312 +++--- src/ftermdebugdata.cpp | 7 +- src/ftermdetection.cpp | 14 +- src/ftermfreebsd.cpp | 10 +- src/ftermlinux.cpp | 474 +++----- src/ftermxterminal.cpp | 4 +- src/ftextview.cpp | 164 ++- src/ftogglebutton.cpp | 78 +- src/fvterm.cpp | 226 ++-- src/fwidget.cpp | 253 ++--- src/fwidget_functions.cpp | 130 +-- src/fwidgetcolors.cpp | 690 ++++++------ src/fwindow.cpp | 59 +- src/include/final/fapplication.h | 8 +- src/include/final/fbutton.h | 16 +- src/include/final/fc.h | 1475 +++++++++++++++---------- src/include/final/fcharmap.h | 27 +- src/include/final/fcolorpair.h | 4 +- src/include/final/fdialog.h | 5 + src/include/final/fevent.h | 56 +- src/include/final/fkey_map.h | 27 +- src/include/final/fkeyboard.h | 16 +- src/include/final/flabel.h | 14 +- src/include/final/flineedit.h | 27 +- src/include/final/flistbox.h | 52 +- src/include/final/flistview.h | 34 +- src/include/final/fmenuitem.h | 8 +- src/include/final/fmouse.h | 25 +- src/include/final/fscrollbar.h | 50 +- src/include/final/fscrollview.h | 20 +- src/include/final/fspinbox.h | 14 +- src/include/final/fstartoptions.h | 2 +- src/include/final/fstatusbar.h | 2 +- src/include/final/fstring.h | 15 +- src/include/final/fstyle.h | 8 +- src/include/final/fterm.h | 14 +- src/include/final/ftermbuffer.h | 8 + src/include/final/ftermcap.h | 2 +- src/include/final/ftermcapquirks.h | 3 + src/include/final/ftermdata.h | 12 +- src/include/final/ftermdebugdata.h | 6 +- src/include/final/ftermfreebsd.h | 2 +- src/include/final/ftermlinux.h | 69 +- src/include/final/ftermxterminal.h | 8 +- src/include/final/ftextview.h | 6 +- src/include/final/ftypes.h | 62 +- src/include/final/fvterm.h | 39 +- src/include/final/fwidget.h | 102 +- src/include/final/fwidgetcolors.h | 172 +-- test/fcolorpair-test.cpp | 80 +- test/fkeyboard-test.cpp | 1153 ++++++++++---------- test/fmouse-test.cpp | 22 +- test/fobject-test.cpp | 8 +- test/foptiattr-test.cpp | 360 +++---- test/fstring-test.cpp | 2 +- test/fstyle-test.cpp | 74 +- test/ftermcapquirks-test.cpp | 248 ++--- test/ftermdata-test.cpp | 54 +- test/ftermfreebsd-test.cpp | 86 +- test/ftermlinux-test.cpp | 391 +++---- test/ftermopenbsd-test.cpp | 24 +- 124 files changed, 6823 insertions(+), 6740 deletions(-) diff --git a/ChangeLog b/ChangeLog index 864bc31b..8702f271 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,16 @@ -2019-11-18 Markus Gans +2020-12-31 Markus Gans + * Refactoring to scaled enumerations + +2020-11-18 Markus Gans * The terminal update rate is now limited to 60 Hz -2019-11-14 Markus Gans +2020-11-14 Markus Gans * Version 0.7.1 * Bugfix: The cursor position was not changed anymore if there was no change to the content * Forcing a direct update for faster terminal output -2019-11-07 Markus Gans +2020-11-07 Markus Gans * Version 0.7.0 2020-11-04 Markus Gans diff --git a/doc/first-steps.md b/doc/first-steps.md index 4fb6fd50..67b6c402 100644 --- a/doc/first-steps.md +++ b/doc/first-steps.md @@ -381,7 +381,7 @@ class dialogWidget : public FDialog setText ("Dialog"); setGeometry (FPoint{25, 5}, FSize{23, 4}); label.setGeometry (FPoint{1, 1}, FSize{10, 1}); - label.setAlignment (fc::alignRight); + label.setAlignment (Align::Right); value.setGeometry (FPoint{11, 1}, FSize{10, 1}); id = addTimer(100); } @@ -475,7 +475,7 @@ class extendedApplication : public FApplication || last_avg[1] != load_avg[1] || last_avg[2] != load_avg[2] ) { - FUserEvent user_event(fc::User_Event, 0); + FUserEvent user_event(Event::User, 0); user_event.setData (load_avg); FApplication::sendEvent (getMainWidget(), &user_event); } @@ -958,8 +958,8 @@ class dialogWidget : public FDialog setText ("Emit signal"); const FSize size{5, 1}; label.setGeometry (FPoint{8, 1}, size); - label.setAlignment (fc::alignRight); - label.setForegroundColor (fc::Black); + label.setAlignment (Align::Right); + label.setForegroundColor (FColor::Black); plus.setGeometry (FPoint{3, 3}, size); minus.setGeometry (FPoint{3, 3} + FPoint{10, 0}, size); plus.setNoUnderline(); @@ -1004,17 +1004,17 @@ class dialogWidget : public FDialog void cb_set_blue() { - label.setForegroundColor (fc::Blue); + label.setForegroundColor (FColor::Blue); } void cb_set_black() { - label.setForegroundColor (fc::Black); + label.setForegroundColor (FColor::Black); } void cb_set_red() { - label.setForegroundColor (fc::Red); + label.setForegroundColor (FColor::Red); } void setTemperature() @@ -1291,9 +1291,9 @@ class dialogWidget : public FDialog FDialog::draw(); print() << FPoint{3, 3} - << FColorPair{fc::Black, fc::White} + << FColorPair{FColor::Black, FColor::White} << "Text on " - << FColorPair{fc::Blue, fc::Yellow} + << FColorPair{FColor::Blue, FColor::Yellow} << "top"; } @@ -1383,9 +1383,9 @@ class dialogWidget : public FDialog const auto& wc = getColorTheme(); setColor (wc->label_inactive_fg, wc->dialog_bg); scrollview.clearArea(); - FColorPair red (fc::LightRed, wc->dialog_bg); - FColorPair black (fc::Black, wc->dialog_bg); - FColorPair cyan (fc::Cyan, wc->dialog_bg); + FColorPair red (FColor::LightRed, wc->dialog_bg); + FColorPair black (FColor::Black, wc->dialog_bg); + FColorPair cyan (FColor::Cyan, wc->dialog_bg); static std::vector d { diff --git a/doc/user-theme.md b/doc/user-theme.md index 18156010..0295b3ec 100644 --- a/doc/user-theme.md +++ b/doc/user-theme.md @@ -75,92 +75,92 @@ class BeeColorTheme final : public finalcut::FWidgetColors void setColorTheme() override { - term_fg = finalcut::fc::Black; - term_bg = finalcut::fc::LightBlue; - list_fg = finalcut::fc::Black; - list_bg = finalcut::fc::LightGray; - selected_list_fg = finalcut::fc::LightRed; - selected_list_bg = finalcut::fc::LightGray; - dialog_fg = finalcut::fc::Black; - dialog_resize_fg = finalcut::fc::Red; - dialog_emphasis_fg = finalcut::fc::Blue; - dialog_bg = finalcut::fc::LightGray; - error_box_fg = finalcut::fc::Black; - error_box_emphasis_fg = finalcut::fc::Red; - error_box_bg = finalcut::fc::Yellow; - tooltip_fg = finalcut::fc::Black; - tooltip_bg = finalcut::fc::Yellow; - shadow_fg = finalcut::fc::Black; - shadow_bg = finalcut::fc::LightGray; - current_element_focus_fg = finalcut::fc::White; - current_element_focus_bg = finalcut::fc::Green; - current_element_fg = finalcut::fc::LightGray; - current_element_bg = finalcut::fc::DarkGray; - current_inc_search_element_fg = finalcut::fc::Brown; - selected_current_element_focus_fg = finalcut::fc::LightRed; - selected_current_element_focus_bg = finalcut::fc::Green; - selected_current_element_fg = finalcut::fc::LightRed; - selected_current_element_bg = finalcut::fc::DarkGray; - label_fg = finalcut::fc::Black; - label_bg = finalcut::fc::LightGray; - label_inactive_fg = finalcut::fc::LightGray; - label_inactive_bg = finalcut::fc::DarkGray; - label_hotkey_fg = finalcut::fc::Red; - label_hotkey_bg = finalcut::fc::LightGray; - label_emphasis_fg = finalcut::fc::Blue; - label_ellipsis_fg = finalcut::fc::DarkGray; - inputfield_active_focus_fg = finalcut::fc::LightGray; - inputfield_active_focus_bg = finalcut::fc::Green; - inputfield_active_fg = finalcut::fc::Black; - inputfield_active_bg = finalcut::fc::Cyan ; - inputfield_inactive_fg = finalcut::fc::Black; - inputfield_inactive_bg = finalcut::fc::LightGray; - toggle_button_active_focus_fg = finalcut::fc::White; - toggle_button_active_focus_bg = finalcut::fc::Green; - toggle_button_active_fg = finalcut::fc::Black; - toggle_button_active_bg = finalcut::fc::LightGray; - toggle_button_inactive_fg = finalcut::fc::DarkGray; - toggle_button_inactive_bg = finalcut::fc::LightGray; - button_active_focus_fg = finalcut::fc::White; - button_active_focus_bg = finalcut::fc::Green; - button_active_fg = finalcut::fc::Black; - button_active_bg = finalcut::fc::Cyan; - button_inactive_fg = finalcut::fc::Cyan; - button_inactive_bg = finalcut::fc::LightGray; - button_hotkey_fg = finalcut::fc::Red; - titlebar_active_fg = finalcut::fc::White; - titlebar_active_bg = finalcut::fc::Blue; - titlebar_inactive_fg = finalcut::fc::LightGray; - titlebar_inactive_bg = finalcut::fc::DarkGray; - titlebar_button_fg = finalcut::fc::Black; - titlebar_button_bg = finalcut::fc::LightGray; - titlebar_button_focus_fg = finalcut::fc::LightGray; - titlebar_button_focus_bg = finalcut::fc::Black; - menu_active_focus_fg = finalcut::fc::White; - menu_active_focus_bg = finalcut::fc::Blue; - menu_active_fg = finalcut::fc::Black; - menu_active_bg = finalcut::fc::Yellow; - menu_inactive_fg = finalcut::fc::Cyan; - menu_inactive_bg = finalcut::fc::Yellow; - menu_hotkey_fg = finalcut::fc::Red; - menu_hotkey_bg = finalcut::fc::Yellow; - statusbar_fg = finalcut::fc::White; - statusbar_bg = finalcut::fc::DarkGray; - statusbar_hotkey_fg = finalcut::fc::LightRed; - statusbar_hotkey_bg = finalcut::fc::DarkGray; - statusbar_separator_fg = finalcut::fc::Black; - statusbar_active_fg = finalcut::fc::White; - statusbar_active_bg = finalcut::fc::Green; - statusbar_active_hotkey_fg = finalcut::fc::LightRed; - statusbar_active_hotkey_bg = finalcut::fc::Green; - scrollbar_fg = finalcut::fc::Black; - scrollbar_bg = finalcut::fc::Green; - scrollbar_button_fg = finalcut::fc::Black; - scrollbar_button_bg = finalcut::fc::Green; - scrollbar_button_inactive_fg = finalcut::fc::Cyan; - scrollbar_button_inactive_bg = finalcut::fc::LightGray; - progressbar_fg = finalcut::fc::Green; - progressbar_bg = finalcut::fc::DarkGray; + term_fg = finalcut::FColor::Black; + term_bg = finalcut::FColor::LightBlue; + list_fg = finalcut::FColor::Black; + list_bg = finalcut::FColor::LightGray; + selected_list_fg = finalcut::FColor::LightRed; + selected_list_bg = finalcut::FColor::LightGray; + dialog_fg = finalcut::FColor::Black; + dialog_resize_fg = finalcut::FColor::Red; + dialog_emphasis_fg = finalcut::FColor::Blue; + dialog_bg = finalcut::FColor::LightGray; + error_box_fg = finalcut::FColor::Black; + error_box_emphasis_fg = finalcut::FColor::Red; + error_box_bg = finalcut::FColor::Yellow; + tooltip_fg = finalcut::FColor::Black; + tooltip_bg = finalcut::FColor::Yellow; + shadow_fg = finalcut::FColor::Black; + shadow_bg = finalcut::FColor::LightGray; + current_element_focus_fg = finalcut::FColor::White; + current_element_focus_bg = finalcut::FColor::Green; + current_element_fg = finalcut::FColor::LightGray; + current_element_bg = finalcut::FColor::DarkGray; + current_inc_search_element_fg = finalcut::FColor::Brown; + selected_current_element_focus_fg = finalcut::FColor::LightRed; + selected_current_element_focus_bg = finalcut::FColor::Green; + selected_current_element_fg = finalcut::FColor::LightRed; + selected_current_element_bg = finalcut::FColor::DarkGray; + label_fg = finalcut::FColor::Black; + label_bg = finalcut::FColor::LightGray; + label_inactive_fg = finalcut::FColor::LightGray; + label_inactive_bg = finalcut::FColor::DarkGray; + label_hotkey_fg = finalcut::FColor::Red; + label_hotkey_bg = finalcut::FColor::LightGray; + label_emphasis_fg = finalcut::FColor::Blue; + label_ellipsis_fg = finalcut::FColor::DarkGray; + inputfield_active_focus_fg = finalcut::FColor::LightGray; + inputfield_active_focus_bg = finalcut::FColor::Green; + inputfield_active_fg = finalcut::FColor::Black; + inputfield_active_bg = finalcut::FColor::Cyan ; + inputfield_inactive_fg = finalcut::FColor::Black; + inputfield_inactive_bg = finalcut::FColor::LightGray; + toggle_button_active_focus_fg = finalcut::FColor::White; + toggle_button_active_focus_bg = finalcut::FColor::Green; + toggle_button_active_fg = finalcut::FColor::Black; + toggle_button_active_bg = finalcut::FColor::LightGray; + toggle_button_inactive_fg = finalcut::FColor::DarkGray; + toggle_button_inactive_bg = finalcut::FColor::LightGray; + button_active_focus_fg = finalcut::FColor::White; + button_active_focus_bg = finalcut::FColor::Green; + button_active_fg = finalcut::FColor::Black; + button_active_bg = finalcut::FColor::Cyan; + button_inactive_fg = finalcut::FColor::Cyan; + button_inactive_bg = finalcut::FColor::LightGray; + button_hotkey_fg = finalcut::FColor::Red; + titlebar_active_fg = finalcut::FColor::White; + titlebar_active_bg = finalcut::FColor::Blue; + titlebar_inactive_fg = finalcut::FColor::LightGray; + titlebar_inactive_bg = finalcut::FColor::DarkGray; + titlebar_button_fg = finalcut::FColor::Black; + titlebar_button_bg = finalcut::FColor::LightGray; + titlebar_button_focus_fg = finalcut::FColor::LightGray; + titlebar_button_focus_bg = finalcut::FColor::Black; + menu_active_focus_fg = finalcut::FColor::White; + menu_active_focus_bg = finalcut::FColor::Blue; + menu_active_fg = finalcut::FColor::Black; + menu_active_bg = finalcut::FColor::Yellow; + menu_inactive_fg = finalcut::FColor::Cyan; + menu_inactive_bg = finalcut::FColor::Yellow; + menu_hotkey_fg = finalcut::FColor::Red; + menu_hotkey_bg = finalcut::FColor::Yellow; + statusbar_fg = finalcut::FColor::White; + statusbar_bg = finalcut::FColor::DarkGray; + statusbar_hotkey_fg = finalcut::FColor::LightRed; + statusbar_hotkey_bg = finalcut::FColor::DarkGray; + statusbar_separator_fg = finalcut::FColor::Black; + statusbar_active_fg = finalcut::FColor::White; + statusbar_active_bg = finalcut::FColor::Green; + statusbar_active_hotkey_fg = finalcut::FColor::LightRed; + statusbar_active_hotkey_bg = finalcut::FColor::Green; + scrollbar_fg = finalcut::FColor::Black; + scrollbar_bg = finalcut::FColor::Green; + scrollbar_button_fg = finalcut::FColor::Black; + scrollbar_button_bg = finalcut::FColor::Green; + scrollbar_button_inactive_fg = finalcut::FColor::Cyan; + scrollbar_button_inactive_bg = finalcut::FColor::LightGray; + progressbar_fg = finalcut::FColor::Green; + progressbar_bg = finalcut::FColor::DarkGray; } }; @@ -175,24 +175,24 @@ FINAL CUT has four color tables for the 16 standard colors in the terminal. These are a redefinition of the 16 ANSI colors. You can address the colors via indexes values from 0 to 15. They correspond to the following colors: -| Index | Color name | -|:------:|:---------------------------| -| 0 | finalcut::fc::Black | -| 1 | finalcut::fc::Blue | -| 2 | finalcut::fc::Green | -| 3 | finalcut::fc::Cyan | -| 4 | finalcut::fc::Red | -| 5 | finalcut::fc::Magenta | -| 6 | finalcut::fc::Brown | -| 7 | finalcut::fc::LightGray | -| 8 | finalcut::fc::DarkGray | -| 9 | finalcut::fc::LightBlue | -| 10 | finalcut::fc::LightGreen | -| 11 | finalcut::fc::LightCyan | -| 12 | finalcut::fc::LightRed | -| 13 | finalcut::fc::LightMagenta | -| 14 | finalcut::fc::Yellow | -| 15 | finalcut::fc::White | +| Index | Color name | +|:------:|:-------------------------------| +| 0 | finalcut::FColor::Black | +| 1 | finalcut::FColor::Blue | +| 2 | finalcut::FColor::Green | +| 3 | finalcut::FColor::Cyan | +| 4 | finalcut::FColor::Red | +| 5 | finalcut::FColor::Magenta | +| 6 | finalcut::FColor::Brown | +| 7 | finalcut::FColor::LightGray | +| 8 | finalcut::FColor::DarkGray | +| 9 | finalcut::FColor::LightBlue | +| 10 | finalcut::FColor::LightGreen | +| 11 | finalcut::FColor::LightCyan | +| 12 | finalcut::FColor::LightRed | +| 13 | finalcut::FColor::LightMagenta | +| 14 | finalcut::FColor::Yellow | +| 15 | finalcut::FColor::White | You can define your color as an 8-bit value based on its red, green, and blue components. To create a color palette, create a derived class of @@ -306,22 +306,22 @@ class BeeColorPalette final : public finalcut::FColorPalette void setColorPalette() override { - setPalette (finalcut::fc::Black, 0x00, 0x00, 0x00); - setPalette (finalcut::fc::Blue, 0x23, 0x21, 0x2c); - setPalette (finalcut::fc::Green, 0x26, 0x93, 0x7c); - setPalette (finalcut::fc::Cyan, 0xcf, 0xb3, 0xa8); - setPalette (finalcut::fc::Red, 0xba, 0x1a, 0x1a); - setPalette (finalcut::fc::Magenta, 0xb2, 0x18, 0xb2); - setPalette (finalcut::fc::Brown, 0xe8, 0x87, 0x1f); - setPalette (finalcut::fc::LightGray, 0xff, 0xfb, 0xe4); - setPalette (finalcut::fc::DarkGray, 0x3a, 0x36, 0x37); - setPalette (finalcut::fc::LightBlue, 0xa5, 0xa5, 0xb1); - setPalette (finalcut::fc::LightGreen, 0x5e, 0xeb, 0x5c); - setPalette (finalcut::fc::LightCyan, 0x62, 0xbf, 0xf8); - setPalette (finalcut::fc::LightRed, 0xee, 0x44, 0x44); - setPalette (finalcut::fc::LightMagenta, 0xe9, 0xad, 0xff); - setPalette (finalcut::fc::Yellow, 0xf8, 0xef, 0xa6); - setPalette (finalcut::fc::White, 0xff, 0xff, 0xff); + setPalette (finalcut::FColor::Black, 0x00, 0x00, 0x00); + setPalette (finalcut::FColor::Blue, 0x23, 0x21, 0x2c); + setPalette (finalcut::FColor::Green, 0x26, 0x93, 0x7c); + setPalette (finalcut::FColor::Cyan, 0xcf, 0xb3, 0xa8); + setPalette (finalcut::FColor::Red, 0xba, 0x1a, 0x1a); + setPalette (finalcut::FColor::Magenta, 0xb2, 0x18, 0xb2); + setPalette (finalcut::FColor::Brown, 0xe8, 0x87, 0x1f); + setPalette (finalcut::FColor::LightGray, 0xff, 0xfb, 0xe4); + setPalette (finalcut::FColor::DarkGray, 0x3a, 0x36, 0x37); + setPalette (finalcut::FColor::LightBlue, 0xa5, 0xa5, 0xb1); + setPalette (finalcut::FColor::LightGreen, 0x5e, 0xeb, 0x5c); + setPalette (finalcut::FColor::LightCyan, 0x62, 0xbf, 0xf8); + setPalette (finalcut::FColor::LightRed, 0xee, 0x44, 0x44); + setPalette (finalcut::FColor::LightMagenta, 0xe9, 0xad, 0xff); + setPalette (finalcut::FColor::Yellow, 0xf8, 0xef, 0xa6); + setPalette (finalcut::FColor::White, 0xff, 0xff, 0xff); } void resetColorPalette() override @@ -364,7 +364,7 @@ class dialogWidget final : public FDialog FDialog::setGeometry (FPoint{15, 5}, FSize{50, 9}); Input.setGeometry (FPoint{2, 2}, FSize{39, 1}); Input.setLabelText("File name:"); - Input.setLabelOrientation(FLineEdit::label_above); + Input.setLabelOrientation(FLineEdit::LabelOrientation::Above); Input.setStatusbarMessage("Enter a file name"); Browse.setGeometry (FPoint{43, 2}, FSize{4, 1}); Browse.addCallback diff --git a/examples/7segment.cpp b/examples/7segment.cpp index 41da4a7d..36153294 100644 --- a/examples/7segment.cpp +++ b/examples/7segment.cpp @@ -28,11 +28,11 @@ namespace fc = finalcut::fc; using finalcut::FColorPair; +using finalcut::FColor; using finalcut::FRect; using finalcut::FPoint; using finalcut::FSize; - //---------------------------------------------------------------------- // class SegmentView //---------------------------------------------------------------------- @@ -85,7 +85,7 @@ SegmentView::SegmentView (finalcut::FWidget* parent) input.setGeometry (FPoint(2, 2), FSize{12, 1}); input.setLabelText (L"&Hex value"); input.setLabelText (L"&Hex-digits or (.) (:) (H) (L) (P) (U)"); - input.setLabelOrientation(finalcut::FLineEdit::LabelOrientation::above); + input.setLabelOrientation(finalcut::FLineEdit::LabelOrientation::Above); input.setMaxLength(9); input.setInputFilter("[:.hHlLpPuU[:xdigit:]]"); @@ -199,12 +199,12 @@ void SegmentView::draw() finalcut::FTermBuffer left_space{}; FDialog::draw(); - setColor(fc::LightGray, fc::Black); + setColor(FColor::LightGray, FColor::Black); finalcut::drawBorder(this, FRect(FPoint{3, 6}, FPoint{40, 11})); for (auto&& ch : input.getText().toUpper()) { - const FColorPair color{fc::LightRed, fc::Black}; + const FColorPair color{FColor::LightRed, FColor::Black}; get7Segment(ch); for (std::size_t i{0}; i < 3; i++) diff --git a/examples/background-color.cpp b/examples/background-color.cpp index 944f8e22..41d65433 100644 --- a/examples/background-color.cpp +++ b/examples/background-color.cpp @@ -29,6 +29,7 @@ using finalcut::FPoint; using finalcut::FRect; using finalcut::FSize; +using finalcut::FColor; //---------------------------------------------------------------------- @@ -99,7 +100,7 @@ Background::Background (finalcut::FWidget* parent) // Combobox color_choice.setGeometry (FPoint{2, 2}, FSize{18, 1}); - color_choice.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above); + color_choice.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above); color_choice.setLabelText ("Color choice"); color_choice.unsetEditable(); @@ -111,19 +112,19 @@ Background::Background (finalcut::FWidget* parent) // Spin boxes red.setGeometry (FPoint{2, 5}, FSize{7, 1}); - red.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above); + red.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above); red.setLabelText ("Red"); red.setRange (0, 255); red.setValue (0x80); green.setGeometry (FPoint{12, 5}, FSize{7, 1}); - green.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above); + green.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above); green.setLabelText ("Green"); green.setRange (0, 255); green.setValue (0xa4); blue.setGeometry (FPoint{22, 5}, FSize{7, 1}); - blue.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::above); + blue.setLabelOrientation (finalcut::FLineEdit::LabelOrientation::Above); blue.setLabelText ("Blue"); blue.setRange (0, 255); blue.setValue (0xec); @@ -131,7 +132,7 @@ Background::Background (finalcut::FWidget* parent) // Set the initial palette values if ( finalcut::FTerm::canChangeColorPalette() ) { - finalcut::FTerm::setPalette ( finalcut::fc::LightMagenta + finalcut::FTerm::setPalette ( FColor::LightMagenta , int(red.getValue()) , int(green.getValue()) , int(blue.getValue()) ); @@ -177,7 +178,7 @@ void Background::cb_changed() if ( ! finalcut::FTerm::canChangeColorPalette() ) return; - finalcut::FTerm::setPalette ( finalcut::fc::LightMagenta + finalcut::FTerm::setPalette ( FColor::LightMagenta , int(red.getValue()) , int(green.getValue()) , int(blue.getValue()) ); @@ -198,7 +199,7 @@ void Background::cb_choice() red.setValue(r); green.setValue(g); blue.setValue(b); - finalcut::FTerm::setPalette ( finalcut::fc::LightMagenta + finalcut::FTerm::setPalette ( FColor::LightMagenta , int(red.getValue()) , int(green.getValue()) , int(blue.getValue()) ); @@ -219,7 +220,7 @@ int main (int argc, char* argv[]) // The following lines require an initialized terminal if ( finalcut::FTerm::canChangeColorPalette() ) - app.setBackgroundColor(finalcut::fc::LightMagenta); + app.setBackgroundColor(FColor::LightMagenta); Background dialog(&app); finalcut::FWidget::setMainWidget(&dialog); diff --git a/examples/calculator.cpp b/examples/calculator.cpp index 7058f5de..e04064e1 100644 --- a/examples/calculator.cpp +++ b/examples/calculator.cpp @@ -31,11 +31,12 @@ #include -namespace fc = finalcut::fc; +using FKey = finalcut::FKey; +using finalcut::FColorPair; +using finalcut::FColor; using finalcut::FPoint; using finalcut::FRect; using finalcut::FSize; -using finalcut::FColorPair; constexpr lDouble pi_value{3.141592653589793238L}; @@ -76,9 +77,9 @@ void Button::setChecked (bool enable) if ( checked ) { - setBackgroundColor(fc::Cyan); - setFocusForegroundColor(fc::White); - setFocusBackgroundColor(fc::Cyan); + setBackgroundColor(FColor::Cyan); + setFocusForegroundColor(FColor::White); + setFocusBackgroundColor(FColor::Cyan); } else { @@ -97,7 +98,7 @@ void Button::onKeyPress (finalcut::FKeyEvent* ev) const FKey key = ev->key(); // catch the enter key - if ( key == fc::Fkey_return || key == fc::Fkey_enter ) + if ( key == FKey::Return || key == FKey::Enter ) return; finalcut::FButton::onKeyPress(ev); @@ -124,7 +125,7 @@ class Calc final : public finalcut::FDialog // Typedef and Enumeration using keyFunction = std::function; // Member function - enum button + enum class ButtonName { Sine, Cosine, @@ -201,15 +202,15 @@ class Calc final : public finalcut::FDialog void sine (lDouble&); void cosine (lDouble&); void tangent (lDouble&); - bool isDataEntryKey (int) const; - bool isOperatorKey (int) const; + bool isDataEntryKey (const ButtonName&) const; + bool isOperatorKey (const ButtonName&) const; lDouble& getValue(); void setDisplay (lDouble); void setInfixOperator (char); void clearInfixOperator(); void calcInfixOperator(); void adjustSize() override; - const wchar_t* getButtonText (const std::size_t) const; + const wchar_t* getButtonText (const ButtonName&) const; void mapKeyFunctions(); // Event handlers @@ -218,7 +219,14 @@ class Calc final : public finalcut::FDialog void onClose (finalcut::FCloseEvent*) override; // Callback method - void cb_buttonClicked (Calc::button); + void cb_buttonClicked (ButtonName); + + // Overloaded operators + friend bool operator < (const ButtonName& c, const int n) noexcept; + friend bool operator <= (const ButtonName& c, const int n) noexcept; + friend ButtonName operator + (const ButtonName& c, const int n) noexcept; + friend ButtonName& operator ++ (ButtonName& c) noexcept; // prefix + friend ButtonName operator ++ (ButtonName& c, int) noexcept; // postfix // Data members bool error{false}; @@ -228,11 +236,11 @@ class Calc final : public finalcut::FDialog lDouble b{0.0L}; lDouble infinity{std::numeric_limits::infinity()}; uInt max_char{33}; - int last_key{-1}; + ButtonName last_key{ButtonName(-1)}; char infix_operator{'\0'}; char last_infix_operator{'\0'}; finalcut::FString input{""}; - std::array button_no{}; + std::array button_no{}; struct StackData { @@ -241,8 +249,8 @@ class Calc final : public finalcut::FDialog }; std::stack bracket_stack{}; - std::map > calculator_buttons{}; - std::map key_map{}; + std::map > calculator_buttons{}; + std::map key_map{}; }; //---------------------------------------------------------------------- @@ -258,26 +266,27 @@ Calc::Calc (FWidget* parent) mapKeyFunctions(); clearInfixOperator(); - for (button key{Sine}; key < Calc::NUM_OF_BUTTONS; key = button(key + 1)) + for (ButtonName key{ButtonName::Sine}; key < ButtonName::NUM_OF_BUTTONS; key++) { auto btn = std::make_shared