diff --git a/ChangeLog b/ChangeLog index 3e96cba6..92b31674 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-06-11 Markus Gans + * New method FObject::isWidget() + * Non-widget objects inherit from FObjects will no longer + affect the widget lists + 2017-06-05 Markus Gans * The focus and active flag is set centrally in FWidget @@ -45,7 +50,7 @@ * Replace non-printable characters for Tera Term and Cygwin terminal directly at start-up. Special cases in the code are no longer necessary. - * New Method setInsertCursorStyle() to change the appearance + * New method setInsertCursorStyle() to change the appearance of a cursor 2017-04-02 Markus Gans diff --git a/src/fapp.cpp b/src/fapp.cpp index fe2f952e..72260ec5 100644 --- a/src/fapp.cpp +++ b/src/fapp.cpp @@ -167,6 +167,9 @@ bool FApplication::sendEvent(FObject* receiver, FEvent* event) if ( ! receiver ) return false; + if ( ! receiver->isWidget() ) + return false; + widget = static_cast(receiver); if ( modal_dialogs > 0 ) diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 5aea9e98..e9bced76 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -372,20 +372,24 @@ void FButton::onAccel (FAccelEvent* ev) if ( ! hasFocus() ) { FWidget* focused_widget = static_cast(ev->focusedWidget()); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - setFocus(); - if ( focused_widget ) - focused_widget->redraw(); + if ( focused_widget->isWidget() ) + { + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + setFocus(); - if ( click_animation ) - setDown(); - else - redraw(); + if ( focused_widget ) + focused_widget->redraw(); - if ( getStatusBar() ) - getStatusBar()->drawMessage(); + if ( click_animation ) + setDown(); + else + redraw(); + + if ( getStatusBar() ) + getStatusBar()->drawMessage(); + } } else if ( click_animation ) setDown(); diff --git a/src/flabel.cpp b/src/flabel.cpp index 5f74f166..67adeb3d 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -219,23 +219,26 @@ void FLabel::onAccel (FAccelEvent* ev) if ( ! accel_widget->hasFocus() ) { FWidget* focused_widget = static_cast(ev->focusedWidget()); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - accel_widget->setFocus(); - - if ( focused_widget ) - focused_widget->redraw(); - - accel_widget->redraw(); - FFocusEvent in (fc::FocusIn_Event); - FApplication::sendEvent(accel_widget, &in); - - if ( getStatusBar() ) + if ( focused_widget->isWidget() ) { - accel_widget->getStatusBar()->drawMessage(); - updateTerminal(); - flush_out(); + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + accel_widget->setFocus(); + + if ( focused_widget ) + focused_widget->redraw(); + + accel_widget->redraw(); + FFocusEvent in (fc::FocusIn_Event); + FApplication::sendEvent(accel_widget, &in); + + if ( getStatusBar() ) + { + accel_widget->getStatusBar()->drawMessage(); + updateTerminal(); + flush_out(); + } } } diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 4e732431..3f2fb7e5 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -541,20 +541,24 @@ void FLineEdit::onAccel (FAccelEvent* ev) if ( ! hasFocus() ) { FWidget* focused_widget = static_cast(ev->focusedWidget()); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - setFocus(); - if ( focused_widget ) - focused_widget->redraw(); - - redraw(); - - if ( getStatusBar() ) + if ( focused_widget->isWidget() ) { - getStatusBar()->drawMessage(); - updateTerminal(); - flush_out(); + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + setFocus(); + + if ( focused_widget ) + focused_widget->redraw(); + + redraw(); + + if ( getStatusBar() ) + { + getStatusBar()->drawMessage(); + updateTerminal(); + flush_out(); + } } } diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index bc68f793..e680d1ba 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -542,24 +542,28 @@ void FMenuItem::onAccel (FAccelEvent* ev) openMenu(); focused_widget = static_cast(ev->focusedWidget()); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - menu->unselectItem(); - menu->selectFirstItem(); - if ( menu->getSelectedItem() ) - menu->getSelectedItem()->setFocus(); + if ( focused_widget->isWidget() ) + { + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + menu->unselectItem(); + menu->selectFirstItem(); - if ( focused_widget ) - focused_widget->redraw(); + if ( menu->getSelectedItem() ) + menu->getSelectedItem()->setFocus(); - menu->redraw(); + if ( focused_widget ) + focused_widget->redraw(); - if ( getStatusBar() ) - getStatusBar()->drawMessage(); + menu->redraw(); - mbar->redraw(); - mbar->drop_down = true; + if ( getStatusBar() ) + getStatusBar()->drawMessage(); + + mbar->redraw(); + mbar->drop_down = true; + } } else { diff --git a/src/fobject.cpp b/src/fobject.cpp index 71eb5855..b6b24adf 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -15,7 +15,8 @@ FObject::TimerList* FObject::timer_list = 0; // constructors and destructor //---------------------------------------------------------------------- FObject::FObject (FObject* parent) - : parent_obj(parent) + : widget_object(false) + , parent_obj(parent) , children_list() , has_parent(false) { diff --git a/src/fobject.h b/src/fobject.h index 07c9c7c3..90ebd71a 100644 --- a/src/fobject.h +++ b/src/fobject.h @@ -70,6 +70,7 @@ class FObject bool hasChildren() const; bool isChild (FObject*) const; bool isDirectChild (FObject*) const; + bool isWidget() const; bool isTimerInUpdating() const; // Methods @@ -102,6 +103,7 @@ class FObject // Data Members static TimerList* timer_list; + bool widget_object; private: // Disable copy constructor @@ -147,6 +149,10 @@ inline bool FObject::hasChildren() const inline bool FObject::isDirectChild (FObject* obj) const { return bool( obj->getParent() == this ); } +//---------------------------------------------------------------------- +inline bool FObject::isWidget() const +{ return widget_object; } + //---------------------------------------------------------------------- inline bool FObject::isTimerInUpdating() const { return timer_modify_lock; } diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index c4d75432..475b2317 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -297,12 +297,16 @@ void FToggleButton::onAccel (FAccelEvent* ev) if ( ! hasFocus() ) { FWidget* focused_widget = static_cast(ev->focusedWidget()); - FFocusEvent out (fc::FocusOut_Event); - FApplication::queueEvent(focused_widget, &out); - setFocus(); - if ( focused_widget ) - focused_widget->redraw(); + if ( focused_widget->isWidget() ) + { + FFocusEvent out (fc::FocusOut_Event); + FApplication::queueEvent(focused_widget, &out); + setFocus(); + + if ( focused_widget ) + focused_widget->redraw(); + } } if ( isRadioButton() ) diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 73ef6e0d..234e2390 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -64,6 +64,8 @@ FWidget::FWidget (FWidget* parent, bool disable_alt_screen) if ( isEnabled() ) flags |= fc::active; + widget_object = true; + if ( ! parent ) { assert ( ! rootObject @@ -137,6 +139,17 @@ FWidget* FWidget::getRootWidget() const return obj; } +//---------------------------------------------------------------------- +inline FWidget* FWidget::getParentWidget() const +{ + FObject* p_obj = getParent(); + + if ( p_obj && p_obj->isWidget() ) + return static_cast(p_obj); + else + return 0; +} + //---------------------------------------------------------------------- FWidget* FWidget::getMainWidget() { @@ -163,10 +176,13 @@ FWidget* FWidget::getFirstFocusableWidget (FObjectList children) while ( iter != end ) { - FWidget* child = static_cast(*iter); + if ( (*iter)->isWidget() ) + { + FWidget* child = static_cast(*iter); - if ( child->isEnabled() && child->acceptFocus() ) - return child; + if ( child->isEnabled() && child->acceptFocus() ) + return child; + } ++iter; } @@ -187,6 +203,10 @@ FWidget* FWidget::getLastFocusableWidget (FObjectList children) do { --iter; + + if ( ! (*iter)->isWidget() ) + continue; + FWidget* child = static_cast(*iter); if ( child->isEnabled() && child->acceptFocus() ) @@ -311,7 +331,7 @@ void FWidget::setStatusbarMessage (const FString& msg) //---------------------------------------------------------------------- bool FWidget::setEnable (bool on) -{ +{ if ( on ) flags |= fc::active; else @@ -824,6 +844,12 @@ FWidget* FWidget::childWidgetAt (FWidget* p, int x, int y) while ( iter != end ) { + if ( ! (*iter)->isWidget() ) + { + ++iter; + continue; + } + FWidget* widget = static_cast(*iter); if ( widget->isEnabled() @@ -858,10 +884,13 @@ int FWidget::numOfFocusableChildren() while ( iter != end ) { - FWidget* widget = static_cast(*iter); + if ( (*iter)->isWidget() ) + { + FWidget* widget = static_cast(*iter); - if ( widget->acceptFocus() ) - num++; + if ( widget->acceptFocus() ) + num++; + } ++iter; } @@ -1124,10 +1153,13 @@ void FWidget::redraw() while ( iter != end ) { - FWidget* widget = static_cast(*iter); + if ( (*iter)->isWidget() ) + { + FWidget* widget = static_cast(*iter); - if ( widget->isVisible() && ! widget->isWindowWidget() ) - widget->redraw(); + if ( widget->isVisible() && ! widget->isWindowWidget() ) + widget->redraw(); + } ++iter; } @@ -1219,8 +1251,12 @@ void FWidget::show() while ( iter != end ) { - FWidget* widget = static_cast(*iter); - widget->show(); + if ( (*iter)->isWidget() ) + { + FWidget* widget = static_cast(*iter); + widget->show(); + } + ++iter; } } @@ -1275,6 +1311,12 @@ bool FWidget::focusFirstChild() while ( iter != end ) { + if ( ! (*iter)->isWidget() ) + { + ++iter; + continue; + } + FWidget* widget = static_cast(*iter); if ( widget->isEnabled() @@ -1295,8 +1337,6 @@ bool FWidget::focusFirstChild() return true; } - // prefix increment (++) is faster - // than postfix for non primitive type ++iter; } return false; @@ -1318,6 +1358,10 @@ bool FWidget::focusLastChild() do { --iter; + + if ( ! (*iter)->isWidget() ) + continue; + FWidget* widget = static_cast(*iter); if ( widget->isEnabled() @@ -1793,11 +1837,13 @@ void FWidget::adjustSize() while ( iter != end ) { - FWidget* widget = static_cast(*iter); - - if ( ! widget->isWindowWidget() ) - widget->adjustSize(); + if ( (*iter)->isWidget() ) + { + FWidget* widget = static_cast(*iter); + if ( ! widget->isWindowWidget() ) + widget->adjustSize(); + } ++iter; } } @@ -1847,6 +1893,12 @@ bool FWidget::focusNextChild() while ( iter != end ) { + if ( ! (*iter)->isWidget() ) + { + ++iter; + continue; + } + FWidget* w = static_cast(*iter); if ( w == this ) @@ -1859,6 +1911,9 @@ bool FWidget::focusNextChild() { ++next_element; + if ( ! (*next_element)->isWidget() ) + continue; + if ( next_element == children.end() ) next_element = children.begin(); @@ -1932,6 +1987,10 @@ bool FWidget::focusPrevChild() do { --iter; + + if ( ! (*iter)->isWidget() ) + continue; + FWidget* w = static_cast(*iter); if ( w == this ) @@ -1942,6 +2001,12 @@ bool FWidget::focusPrevChild() do { + if ( ! (*prev_element)->isWidget() ) + { + --prev_element; + continue; + } + if ( prev_element == children.begin() ) prev_element = children.end(); diff --git a/src/fwidget.h b/src/fwidget.h index f3f33d0a..b8057752 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -546,10 +546,6 @@ class FWidget : public FVTerm inline const char* FWidget::getClassName() const { return "FWidget"; } -//---------------------------------------------------------------------- -inline FWidget* FWidget::getParentWidget() const -{ return static_cast(getParent()); } - //---------------------------------------------------------------------- inline FString FWidget::getStatusbarMessage() const { return statusbar_message; }