New method FObject::isWidget()

This commit is contained in:
Markus Gans 2017-06-11 17:47:50 +02:00
parent 526e193fb7
commit b1d323ef76
11 changed files with 175 additions and 80 deletions

View File

@ -1,3 +1,8 @@
2017-06-11 Markus Gans <guru.mail@muenster.de>
* New method FObject::isWidget()
* Non-widget objects inherit from FObjects will no longer
affect the widget lists
2017-06-05 Markus Gans <guru.mail@muenster.de> 2017-06-05 Markus Gans <guru.mail@muenster.de>
* The focus and active flag is set centrally in FWidget * The focus and active flag is set centrally in FWidget
@ -45,7 +50,7 @@
* Replace non-printable characters for Tera Term and * Replace non-printable characters for Tera Term and
Cygwin terminal directly at start-up. Special cases Cygwin terminal directly at start-up. Special cases
in the code are no longer necessary. in the code are no longer necessary.
* New Method setInsertCursorStyle() to change the appearance * New method setInsertCursorStyle() to change the appearance
of a cursor of a cursor
2017-04-02 Markus Gans <guru.mail@muenster.de> 2017-04-02 Markus Gans <guru.mail@muenster.de>

View File

@ -167,6 +167,9 @@ bool FApplication::sendEvent(FObject* receiver, FEvent* event)
if ( ! receiver ) if ( ! receiver )
return false; return false;
if ( ! receiver->isWidget() )
return false;
widget = static_cast<FWidget*>(receiver); widget = static_cast<FWidget*>(receiver);
if ( modal_dialogs > 0 ) if ( modal_dialogs > 0 )

View File

@ -372,6 +372,9 @@ void FButton::onAccel (FAccelEvent* ev)
if ( ! hasFocus() ) if ( ! hasFocus() )
{ {
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget()); FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
if ( focused_widget->isWidget() )
{
FFocusEvent out (fc::FocusOut_Event); FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out); FApplication::queueEvent(focused_widget, &out);
setFocus(); setFocus();
@ -387,6 +390,7 @@ void FButton::onAccel (FAccelEvent* ev)
if ( getStatusBar() ) if ( getStatusBar() )
getStatusBar()->drawMessage(); getStatusBar()->drawMessage();
} }
}
else if ( click_animation ) else if ( click_animation )
setDown(); setDown();

View File

@ -219,11 +219,13 @@ void FLabel::onAccel (FAccelEvent* ev)
if ( ! accel_widget->hasFocus() ) if ( ! accel_widget->hasFocus() )
{ {
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget()); FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
if ( focused_widget->isWidget() )
{
FFocusEvent out (fc::FocusOut_Event); FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out); FApplication::queueEvent(focused_widget, &out);
accel_widget->setFocus(); accel_widget->setFocus();
if ( focused_widget ) if ( focused_widget )
focused_widget->redraw(); focused_widget->redraw();
@ -238,6 +240,7 @@ void FLabel::onAccel (FAccelEvent* ev)
flush_out(); flush_out();
} }
} }
}
ev->accept(); ev->accept();
} }

View File

@ -541,6 +541,9 @@ void FLineEdit::onAccel (FAccelEvent* ev)
if ( ! hasFocus() ) if ( ! hasFocus() )
{ {
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget()); FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
if ( focused_widget->isWidget() )
{
FFocusEvent out (fc::FocusOut_Event); FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out); FApplication::queueEvent(focused_widget, &out);
setFocus(); setFocus();
@ -557,6 +560,7 @@ void FLineEdit::onAccel (FAccelEvent* ev)
flush_out(); flush_out();
} }
} }
}
ev->accept(); ev->accept();
} }

View File

@ -542,6 +542,9 @@ void FMenuItem::onAccel (FAccelEvent* ev)
openMenu(); openMenu();
focused_widget = static_cast<FWidget*>(ev->focusedWidget()); focused_widget = static_cast<FWidget*>(ev->focusedWidget());
if ( focused_widget->isWidget() )
{
FFocusEvent out (fc::FocusOut_Event); FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out); FApplication::queueEvent(focused_widget, &out);
menu->unselectItem(); menu->unselectItem();
@ -561,6 +564,7 @@ void FMenuItem::onAccel (FAccelEvent* ev)
mbar->redraw(); mbar->redraw();
mbar->drop_down = true; mbar->drop_down = true;
} }
}
else else
{ {
unsetSelected(); unsetSelected();

View File

@ -15,7 +15,8 @@ FObject::TimerList* FObject::timer_list = 0;
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FObject::FObject (FObject* parent) FObject::FObject (FObject* parent)
: parent_obj(parent) : widget_object(false)
, parent_obj(parent)
, children_list() , children_list()
, has_parent(false) , has_parent(false)
{ {

View File

@ -70,6 +70,7 @@ class FObject
bool hasChildren() const; bool hasChildren() const;
bool isChild (FObject*) const; bool isChild (FObject*) const;
bool isDirectChild (FObject*) const; bool isDirectChild (FObject*) const;
bool isWidget() const;
bool isTimerInUpdating() const; bool isTimerInUpdating() const;
// Methods // Methods
@ -102,6 +103,7 @@ class FObject
// Data Members // Data Members
static TimerList* timer_list; static TimerList* timer_list;
bool widget_object;
private: private:
// Disable copy constructor // Disable copy constructor
@ -147,6 +149,10 @@ inline bool FObject::hasChildren() const
inline bool FObject::isDirectChild (FObject* obj) const inline bool FObject::isDirectChild (FObject* obj) const
{ return bool( obj->getParent() == this ); } { return bool( obj->getParent() == this ); }
//----------------------------------------------------------------------
inline bool FObject::isWidget() const
{ return widget_object; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FObject::isTimerInUpdating() const inline bool FObject::isTimerInUpdating() const
{ return timer_modify_lock; } { return timer_modify_lock; }

View File

@ -297,6 +297,9 @@ void FToggleButton::onAccel (FAccelEvent* ev)
if ( ! hasFocus() ) if ( ! hasFocus() )
{ {
FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget()); FWidget* focused_widget = static_cast<FWidget*>(ev->focusedWidget());
if ( focused_widget->isWidget() )
{
FFocusEvent out (fc::FocusOut_Event); FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out); FApplication::queueEvent(focused_widget, &out);
setFocus(); setFocus();
@ -304,6 +307,7 @@ void FToggleButton::onAccel (FAccelEvent* ev)
if ( focused_widget ) if ( focused_widget )
focused_widget->redraw(); focused_widget->redraw();
} }
}
if ( isRadioButton() ) if ( isRadioButton() )
{ {

View File

@ -64,6 +64,8 @@ FWidget::FWidget (FWidget* parent, bool disable_alt_screen)
if ( isEnabled() ) if ( isEnabled() )
flags |= fc::active; flags |= fc::active;
widget_object = true;
if ( ! parent ) if ( ! parent )
{ {
assert ( ! rootObject assert ( ! rootObject
@ -137,6 +139,17 @@ FWidget* FWidget::getRootWidget() const
return obj; return obj;
} }
//----------------------------------------------------------------------
inline FWidget* FWidget::getParentWidget() const
{
FObject* p_obj = getParent();
if ( p_obj && p_obj->isWidget() )
return static_cast<FWidget*>(p_obj);
else
return 0;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FWidget* FWidget::getMainWidget() FWidget* FWidget::getMainWidget()
{ {
@ -162,11 +175,14 @@ FWidget* FWidget::getFirstFocusableWidget (FObjectList children)
end = children.end(); end = children.end();
while ( iter != end ) while ( iter != end )
{
if ( (*iter)->isWidget() )
{ {
FWidget* child = static_cast<FWidget*>(*iter); FWidget* child = static_cast<FWidget*>(*iter);
if ( child->isEnabled() && child->acceptFocus() ) if ( child->isEnabled() && child->acceptFocus() )
return child; return child;
}
++iter; ++iter;
} }
@ -187,6 +203,10 @@ FWidget* FWidget::getLastFocusableWidget (FObjectList children)
do do
{ {
--iter; --iter;
if ( ! (*iter)->isWidget() )
continue;
FWidget* child = static_cast<FWidget*>(*iter); FWidget* child = static_cast<FWidget*>(*iter);
if ( child->isEnabled() && child->acceptFocus() ) if ( child->isEnabled() && child->acceptFocus() )
@ -824,6 +844,12 @@ FWidget* FWidget::childWidgetAt (FWidget* p, int x, int y)
while ( iter != end ) while ( iter != end )
{ {
if ( ! (*iter)->isWidget() )
{
++iter;
continue;
}
FWidget* widget = static_cast<FWidget*>(*iter); FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->isEnabled() if ( widget->isEnabled()
@ -857,11 +883,14 @@ int FWidget::numOfFocusableChildren()
end = children.end(); end = children.end();
while ( iter != end ) while ( iter != end )
{
if ( (*iter)->isWidget() )
{ {
FWidget* widget = static_cast<FWidget*>(*iter); FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->acceptFocus() ) if ( widget->acceptFocus() )
num++; num++;
}
++iter; ++iter;
} }
@ -1123,11 +1152,14 @@ void FWidget::redraw()
end = children.end(); end = children.end();
while ( iter != end ) while ( iter != end )
{
if ( (*iter)->isWidget() )
{ {
FWidget* widget = static_cast<FWidget*>(*iter); FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->isVisible() && ! widget->isWindowWidget() ) if ( widget->isVisible() && ! widget->isWindowWidget() )
widget->redraw(); widget->redraw();
}
++iter; ++iter;
} }
@ -1218,9 +1250,13 @@ void FWidget::show()
end = children.end(); end = children.end();
while ( iter != end ) while ( iter != end )
{
if ( (*iter)->isWidget() )
{ {
FWidget* widget = static_cast<FWidget*>(*iter); FWidget* widget = static_cast<FWidget*>(*iter);
widget->show(); widget->show();
}
++iter; ++iter;
} }
} }
@ -1275,6 +1311,12 @@ bool FWidget::focusFirstChild()
while ( iter != end ) while ( iter != end )
{ {
if ( ! (*iter)->isWidget() )
{
++iter;
continue;
}
FWidget* widget = static_cast<FWidget*>(*iter); FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->isEnabled() if ( widget->isEnabled()
@ -1295,8 +1337,6 @@ bool FWidget::focusFirstChild()
return true; return true;
} }
// prefix increment (++) is faster
// than postfix for non primitive type
++iter; ++iter;
} }
return false; return false;
@ -1318,6 +1358,10 @@ bool FWidget::focusLastChild()
do do
{ {
--iter; --iter;
if ( ! (*iter)->isWidget() )
continue;
FWidget* widget = static_cast<FWidget*>(*iter); FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->isEnabled() if ( widget->isEnabled()
@ -1792,12 +1836,14 @@ void FWidget::adjustSize()
end = children.end(); end = children.end();
while ( iter != end ) while ( iter != end )
{
if ( (*iter)->isWidget() )
{ {
FWidget* widget = static_cast<FWidget*>(*iter); FWidget* widget = static_cast<FWidget*>(*iter);
if ( ! widget->isWindowWidget() ) if ( ! widget->isWindowWidget() )
widget->adjustSize(); widget->adjustSize();
}
++iter; ++iter;
} }
} }
@ -1847,6 +1893,12 @@ bool FWidget::focusNextChild()
while ( iter != end ) while ( iter != end )
{ {
if ( ! (*iter)->isWidget() )
{
++iter;
continue;
}
FWidget* w = static_cast<FWidget*>(*iter); FWidget* w = static_cast<FWidget*>(*iter);
if ( w == this ) if ( w == this )
@ -1859,6 +1911,9 @@ bool FWidget::focusNextChild()
{ {
++next_element; ++next_element;
if ( ! (*next_element)->isWidget() )
continue;
if ( next_element == children.end() ) if ( next_element == children.end() )
next_element = children.begin(); next_element = children.begin();
@ -1932,6 +1987,10 @@ bool FWidget::focusPrevChild()
do do
{ {
--iter; --iter;
if ( ! (*iter)->isWidget() )
continue;
FWidget* w = static_cast<FWidget*>(*iter); FWidget* w = static_cast<FWidget*>(*iter);
if ( w == this ) if ( w == this )
@ -1942,6 +2001,12 @@ bool FWidget::focusPrevChild()
do do
{ {
if ( ! (*prev_element)->isWidget() )
{
--prev_element;
continue;
}
if ( prev_element == children.begin() ) if ( prev_element == children.begin() )
prev_element = children.end(); prev_element = children.end();

View File

@ -546,10 +546,6 @@ class FWidget : public FVTerm
inline const char* FWidget::getClassName() const inline const char* FWidget::getClassName() const
{ return "FWidget"; } { return "FWidget"; }
//----------------------------------------------------------------------
inline FWidget* FWidget::getParentWidget() const
{ return static_cast<FWidget*>(getParent()); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline FString FWidget::getStatusbarMessage() const inline FString FWidget::getStatusbarMessage() const
{ return statusbar_message; } { return statusbar_message; }