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>
* 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 <guru.mail@muenster.de>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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)
{

View File

@ -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; }

View File

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

View File

@ -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<FWidget*>(p_obj);
else
return 0;
}
//----------------------------------------------------------------------
FWidget* FWidget::getMainWidget()
{
@ -162,11 +175,14 @@ FWidget* FWidget::getFirstFocusableWidget (FObjectList children)
end = children.end();
while ( iter != end )
{
if ( (*iter)->isWidget() )
{
FWidget* child = static_cast<FWidget*>(*iter);
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<FWidget*>(*iter);
if ( child->isEnabled() && child->acceptFocus() )
@ -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<FWidget*>(*iter);
if ( widget->isEnabled()
@ -857,11 +883,14 @@ int FWidget::numOfFocusableChildren()
end = children.end();
while ( iter != end )
{
if ( (*iter)->isWidget() )
{
FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->acceptFocus() )
num++;
}
++iter;
}
@ -1123,11 +1152,14 @@ void FWidget::redraw()
end = children.end();
while ( iter != end )
{
if ( (*iter)->isWidget() )
{
FWidget* widget = static_cast<FWidget*>(*iter);
if ( widget->isVisible() && ! widget->isWindowWidget() )
widget->redraw();
}
++iter;
}
@ -1218,9 +1250,13 @@ void FWidget::show()
end = children.end();
while ( iter != end )
{
if ( (*iter)->isWidget() )
{
FWidget* widget = static_cast<FWidget*>(*iter);
widget->show();
}
++iter;
}
}
@ -1275,6 +1311,12 @@ bool FWidget::focusFirstChild()
while ( iter != end )
{
if ( ! (*iter)->isWidget() )
{
++iter;
continue;
}
FWidget* widget = static_cast<FWidget*>(*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<FWidget*>(*iter);
if ( widget->isEnabled()
@ -1792,12 +1836,14 @@ void FWidget::adjustSize()
end = children.end();
while ( iter != end )
{
if ( (*iter)->isWidget() )
{
FWidget* widget = static_cast<FWidget*>(*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<FWidget*>(*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<FWidget*>(*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();

View File

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