From d10e2888accf2a05e2650dad26aa3ec8ee97f240 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Tue, 22 Sep 2020 01:04:36 +0200 Subject: [PATCH] Bugfix in FDialog::setSize() --- ChangeLog | 4 +++ doc/first-steps.md | 11 ++------ src/fapplication.cpp | 46 ++++++++++++++++---------------- src/fdialog.cpp | 9 ++++--- src/fwidget.cpp | 2 +- src/include/final/fapplication.h | 2 +- src/include/final/fwidget.h | 2 +- test/fdata-test.cpp | 2 +- test/fobject-test.cpp | 13 +++++++++ 9 files changed, 52 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index b41173c1..287dd6bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2020-09-22 Markus Gans + * Bugfix in FDialog::setSize(): Automatic size adjustment and + simultaneous widget movement are now possible. + 2020-09-18 Markus Gans * The generic data type FDataPtr is now deprecated and was completely replaced by the template class FData diff --git a/doc/first-steps.md b/doc/first-steps.md index 6b5b158f..473cd941 100644 --- a/doc/first-steps.md +++ b/doc/first-steps.md @@ -1236,19 +1236,12 @@ class dialogWidget : public FDialog FDialog::adjustSize(); // Centers the dialog in the terminal centerDialog(); - } - - void setSize (const FSize& size, bool) override - { - // Calling super class methods setSize() + adjustSize() - FDialog::setSize (size, false); - FDialog::adjustSize(); + // Adjust widgets before drawing + adjustWidgets(); } void draw() override { - adjustWidgets(); // Adjust widgets before drawing - // Calling super class method draw() FDialog::draw(); diff --git a/src/fapplication.cpp b/src/fapplication.cpp index 70e5b008..ec644f0c 100644 --- a/src/fapplication.cpp +++ b/src/fapplication.cpp @@ -312,6 +312,29 @@ void FApplication::setDarkTheme() setColorTheme(); } +//---------------------------------------------------------------------- +void FApplication::setLogFile (const FString& filename) +{ + auto& log_stream = getStartOptions().logfile_stream; + log_stream.open(filename, std::ofstream::out); + + if ( log_stream.is_open() ) + { + // Get the global logger object + FLog& log = *FApplication::getLog(); + log.setOutputStream(log_stream); + log.enableTimestamp(); + log.setLineEnding (finalcut::FLog::LF); + } + else + { + auto ftermdata = FTerm::getFTermData(); + ftermdata->setExitMessage ( "Could not open log file \"" + + filename + "\"" ); + exit(EXIT_FAILURE); + } +} + //---------------------------------------------------------------------- void FApplication::setKeyboardWidget (FWidget* widget) { @@ -416,29 +439,6 @@ void FApplication::setTerminalEncoding (const FString& enc_str) } } -//---------------------------------------------------------------------- -void FApplication::setLogFile (const FString& filename) -{ - auto& log_stream = getStartOptions().logfile_stream; - log_stream.open(filename, std::ofstream::out); - - if ( log_stream.is_open() ) - { - // Get the global logger object - FLog& log = *FApplication::getLog(); - log.setOutputStream(log_stream); - log.enableTimestamp(); - log.setLineEnding (finalcut::FLog::LF); - } - else - { - auto ftermdata = FTerm::getFTermData(); - ftermdata->setExitMessage ( "Could not open log file \"" - + filename + "\"" ); - exit(EXIT_FAILURE); - } -} - //---------------------------------------------------------------------- void FApplication::cmd_options (const int& argc, char* argv[]) { diff --git a/src/fdialog.cpp b/src/fdialog.cpp index d87708cb..1a300d1c 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -323,7 +323,7 @@ void FDialog::setSize (const FSize& size, bool adjust) const int dw = int(getWidth()) - int(size.getWidth()); const int dh = int(getHeight()) - int(size.getHeight()); const auto& shadow = getShadow(); - FWindow::setSize (size, adjust); + FWindow::setSize (size, false); // get adjust width and height const std::size_t w = getWidth() + shadow.getWidth(); @@ -346,6 +346,9 @@ void FDialog::setSize (const FSize& size, bool adjust) if ( dh > 0 ) restoreVTerm ({x, y + int(h), w + d_width, d_height}); // restore bottom + if ( adjust ) // Adjust the size after restoreVTerm(), + adjustSize(); // because adjustSize() can also change x and y + redraw(); // handle overlaid windows @@ -1069,13 +1072,13 @@ inline void FDialog::drawRestoreSizeButton() if ( FTerm::isMonochron() ) { print ('['); - print (fc::BlackDownPointingTriangle); // ▼ + print (fc::BlackDiamondSuit); // ◆ print (']'); } else { print (' '); - print (fc::BlackDownPointingTriangle); // ▼ + print (fc::BlackDiamondSuit); // ◆ print (' '); } } diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 216423a3..a1843529 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -2015,7 +2015,7 @@ void FWidget::destroyColorTheme() } //---------------------------------------------------------------------- -void FWidget::removeQueuedEvent() +void FWidget::removeQueuedEvent() const { auto app_object = FApplication::getApplicationObject(); diff --git a/src/include/final/fapplication.h b/src/include/final/fapplication.h index d67f2e71..db7efbdb 100644 --- a/src/include/final/fapplication.h +++ b/src/include/final/fapplication.h @@ -137,6 +137,7 @@ class FApplication : public FWidget void initTerminal() override; static void setDefaultTheme(); static void setDarkTheme(); + static void setLogFile (const FString&); static void setKeyboardWidget (FWidget*); static void closeConfirmationDialog (FWidget*, FCloseEvent*); @@ -154,7 +155,6 @@ class FApplication : public FWidget // Methods void init(); static void setTerminalEncoding (const FString&); - static void setLogFile (const FString&); static void cmd_options (const int&, char*[]); static FStartOptions& getStartOptions(); static void showParameterUsage(); diff --git a/src/include/final/fwidget.h b/src/include/final/fwidget.h index 1af03bfe..1a54c839 100644 --- a/src/include/final/fwidget.h +++ b/src/include/final/fwidget.h @@ -452,7 +452,7 @@ class FWidget : public FVTerm, public FObject static bool isDefaultTheme(); static void initColorTheme(); void destroyColorTheme(); - void removeQueuedEvent(); + void removeQueuedEvent() const; void setStatusbarText (bool) const; // Data members diff --git a/test/fdata-test.cpp b/test/fdata-test.cpp index 8ca52d6e..206cdc14 100644 --- a/test/fdata-test.cpp +++ b/test/fdata-test.cpp @@ -1,5 +1,5 @@ /*********************************************************************** -* fdata-test.cpp - FCallback unit tests * +* fdata-test.cpp - FData unit tests * * * * This file is part of the FINAL CUT widget toolkit * * * diff --git a/test/fobject-test.cpp b/test/fobject-test.cpp index 28d74480..60d48637 100644 --- a/test/fobject-test.cpp +++ b/test/fobject-test.cpp @@ -394,6 +394,19 @@ void FObjectTest::addTest() CPPUNIT_ASSERT ( child->hasParent() ); CPPUNIT_ASSERT ( child->getParent() == obj ); + // Switch of the parent by a second addChild + auto obj2 = new finalcut::FObject(); + obj2->addChild(child); + CPPUNIT_ASSERT ( child->hasParent() ); + CPPUNIT_ASSERT ( ! obj->hasChildren() ); + CPPUNIT_ASSERT ( obj->numOfChildren() == 0 ); + CPPUNIT_ASSERT ( ! obj->isChild(child) ); + CPPUNIT_ASSERT ( child->getParent() != obj ); + CPPUNIT_ASSERT ( obj2->hasChildren() ); + CPPUNIT_ASSERT ( obj2->numOfChildren() == 1 ); + CPPUNIT_ASSERT ( obj2->isChild(child) ); + CPPUNIT_ASSERT ( child->getParent() == obj2 ); + delete obj; // also deletes the child object }