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,20 +372,24 @@ 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());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget ) if ( focused_widget->isWidget() )
focused_widget->redraw(); {
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( click_animation ) if ( focused_widget )
setDown(); focused_widget->redraw();
else
redraw();
if ( getStatusBar() ) if ( click_animation )
getStatusBar()->drawMessage(); setDown();
else
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
} }
else if ( click_animation ) else if ( click_animation )
setDown(); setDown();

View File

@ -219,23 +219,26 @@ 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());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
accel_widget->setFocus();
if ( focused_widget->isWidget() )
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(); FFocusEvent out (fc::FocusOut_Event);
updateTerminal(); FApplication::queueEvent(focused_widget, &out);
flush_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();
}
} }
} }

View File

@ -541,20 +541,24 @@ 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());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget ) if ( focused_widget->isWidget() )
focused_widget->redraw();
redraw();
if ( getStatusBar() )
{ {
getStatusBar()->drawMessage(); FFocusEvent out (fc::FocusOut_Event);
updateTerminal(); FApplication::queueEvent(focused_widget, &out);
flush_out(); setFocus();
if ( focused_widget )
focused_widget->redraw();
redraw();
if ( getStatusBar() )
{
getStatusBar()->drawMessage();
updateTerminal();
flush_out();
}
} }
} }

View File

@ -542,24 +542,28 @@ void FMenuItem::onAccel (FAccelEvent* ev)
openMenu(); openMenu();
focused_widget = static_cast<FWidget*>(ev->focusedWidget()); focused_widget = static_cast<FWidget*>(ev->focusedWidget());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
menu->unselectItem();
menu->selectFirstItem();
if ( menu->getSelectedItem() ) if ( focused_widget->isWidget() )
menu->getSelectedItem()->setFocus(); {
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
menu->unselectItem();
menu->selectFirstItem();
if ( focused_widget ) if ( menu->getSelectedItem() )
focused_widget->redraw(); menu->getSelectedItem()->setFocus();
menu->redraw(); if ( focused_widget )
focused_widget->redraw();
if ( getStatusBar() ) menu->redraw();
getStatusBar()->drawMessage();
mbar->redraw(); if ( getStatusBar() )
mbar->drop_down = true; getStatusBar()->drawMessage();
mbar->redraw();
mbar->drop_down = true;
}
} }
else else
{ {

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,12 +297,16 @@ 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());
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget ) if ( focused_widget->isWidget() )
focused_widget->redraw(); {
FFocusEvent out (fc::FocusOut_Event);
FApplication::queueEvent(focused_widget, &out);
setFocus();
if ( focused_widget )
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()
{ {
@ -163,10 +176,13 @@ FWidget* FWidget::getFirstFocusableWidget (FObjectList children)
while ( iter != end ) while ( iter != end )
{ {
FWidget* child = static_cast<FWidget*>(*iter); if ( (*iter)->isWidget() )
{
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() )
@ -311,7 +331,7 @@ void FWidget::setStatusbarMessage (const FString& msg)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FWidget::setEnable (bool on) bool FWidget::setEnable (bool on)
{ {
if ( on ) if ( on )
flags |= fc::active; flags |= fc::active;
else else
@ -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()
@ -858,10 +884,13 @@ int FWidget::numOfFocusableChildren()
while ( iter != end ) while ( iter != end )
{ {
FWidget* widget = static_cast<FWidget*>(*iter); if ( (*iter)->isWidget() )
{
FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->acceptFocus() ) if ( widget->acceptFocus() )
num++; num++;
}
++iter; ++iter;
} }
@ -1124,10 +1153,13 @@ void FWidget::redraw()
while ( iter != end ) while ( iter != end )
{ {
FWidget* widget = static_cast<FWidget*>(*iter); if ( (*iter)->isWidget() )
{
FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->isVisible() && ! widget->isWindowWidget() ) if ( widget->isVisible() && ! widget->isWindowWidget() )
widget->redraw(); widget->redraw();
}
++iter; ++iter;
} }
@ -1219,8 +1251,12 @@ void FWidget::show()
while ( iter != end ) while ( iter != end )
{ {
FWidget* widget = static_cast<FWidget*>(*iter); if ( (*iter)->isWidget() )
widget->show(); {
FWidget* widget = static_cast<FWidget*>(*iter);
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()
@ -1793,11 +1837,13 @@ void FWidget::adjustSize()
while ( iter != end ) while ( iter != end )
{ {
FWidget* widget = static_cast<FWidget*>(*iter); if ( (*iter)->isWidget() )
{
if ( ! widget->isWindowWidget() ) FWidget* widget = static_cast<FWidget*>(*iter);
widget->adjustSize();
if ( ! widget->isWindowWidget() )
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; }