Allow to change the focus out from FScrollView
This commit is contained in:
parent
d2ba29d842
commit
36bba82e9f
|
@ -1,3 +1,6 @@
|
||||||
|
2017-01-28 Markus Gans <guru.mail@muenster.de>
|
||||||
|
* Allow to change the focus out from FScrollView to another widget
|
||||||
|
|
||||||
2017-01-26 Markus Gans <guru.mail@muenster.de>
|
2017-01-26 Markus Gans <guru.mail@muenster.de>
|
||||||
* FScrollView now scrolls automatically to the focused widget
|
* FScrollView now scrolls automatically to the focused widget
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ FButtonGroup::FButtonGroup (const FString& txt, FWidget* parent)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FButtonGroup::~FButtonGroup() // destructor
|
FButtonGroup::~FButtonGroup() // destructor
|
||||||
{
|
{
|
||||||
FButtonList::iterator iter;
|
FObjectList::iterator iter;
|
||||||
|
|
||||||
if ( buttonlist.empty() )
|
if ( buttonlist.empty() )
|
||||||
return;
|
return;
|
||||||
|
@ -45,7 +45,8 @@ FButtonGroup::~FButtonGroup() // destructor
|
||||||
|
|
||||||
while ( iter != buttonlist.end() )
|
while ( iter != buttonlist.end() )
|
||||||
{
|
{
|
||||||
(*iter)->setGroup(0);
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
||||||
|
toggle_button->setGroup(0);
|
||||||
iter = buttonlist.erase(iter);
|
iter = buttonlist.erase(iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,44 +56,17 @@ FButtonGroup::~FButtonGroup() // destructor
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FToggleButton* FButtonGroup::getFirstButton()
|
FToggleButton* FButtonGroup::getFirstButton()
|
||||||
{
|
{
|
||||||
if ( buttonlist.empty() )
|
FWidget* widget = FWidget::getFirstFocusableWidget(buttonlist);
|
||||||
return 0;
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(widget);
|
||||||
|
return toggle_button;
|
||||||
FButtonList::const_iterator iter, end;
|
|
||||||
iter = buttonlist.begin();
|
|
||||||
end = buttonlist.end();
|
|
||||||
|
|
||||||
while ( iter != end )
|
|
||||||
{
|
|
||||||
if ( (*iter)->isEnabled() && (*iter)->acceptFocus() )
|
|
||||||
return (*iter);
|
|
||||||
|
|
||||||
++iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FToggleButton* FButtonGroup::getLastButton()
|
FToggleButton* FButtonGroup::getLastButton()
|
||||||
{
|
{
|
||||||
if ( buttonlist.empty() )
|
FWidget* widget = FWidget::getLastFocusableWidget(buttonlist);
|
||||||
return 0;
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(widget);
|
||||||
|
return toggle_button;
|
||||||
FButtonList::const_iterator iter, begin;
|
|
||||||
begin = buttonlist.begin();
|
|
||||||
iter = buttonlist.end();
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
--iter;
|
|
||||||
|
|
||||||
if ( (*iter)->isEnabled() && (*iter)->acceptFocus() )
|
|
||||||
return (*iter);
|
|
||||||
}
|
|
||||||
while ( iter != begin );
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
@ -143,13 +117,15 @@ bool FButtonGroup::hasFocusedButton()
|
||||||
if ( buttonlist.empty() )
|
if ( buttonlist.empty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FButtonList::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
iter = buttonlist.begin();
|
iter = buttonlist.begin();
|
||||||
end = buttonlist.end();
|
end = buttonlist.end();
|
||||||
|
|
||||||
while ( iter != end )
|
while ( iter != end )
|
||||||
{
|
{
|
||||||
if ( (*iter)->hasFocus() )
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
||||||
|
|
||||||
|
if ( toggle_button->hasFocus() )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -164,13 +140,15 @@ bool FButtonGroup::hasCheckedButton()
|
||||||
if ( buttonlist.empty() )
|
if ( buttonlist.empty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FButtonList::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
iter = buttonlist.begin();
|
iter = buttonlist.begin();
|
||||||
end = buttonlist.end();
|
end = buttonlist.end();
|
||||||
|
|
||||||
while ( iter != end )
|
while ( iter != end )
|
||||||
{
|
{
|
||||||
if ( (*iter)->isChecked() )
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
||||||
|
|
||||||
|
if ( toggle_button->isChecked() )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -190,13 +168,14 @@ void FButtonGroup::hide()
|
||||||
|
|
||||||
if ( ! buttonlist.empty() )
|
if ( ! buttonlist.empty() )
|
||||||
{
|
{
|
||||||
FButtonList::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
iter = buttonlist.begin();
|
iter = buttonlist.begin();
|
||||||
end = buttonlist.end();
|
end = buttonlist.end();
|
||||||
|
|
||||||
while ( iter != end )
|
while ( iter != end )
|
||||||
{
|
{
|
||||||
(*iter)->hide();
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
||||||
|
toggle_button->hide();
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,8 +220,13 @@ void FButtonGroup::insert (FToggleButton* button)
|
||||||
button->getGroup()->remove(button);
|
button->getGroup()->remove(button);
|
||||||
|
|
||||||
// setChecked the first FRadioButton
|
// setChecked the first FRadioButton
|
||||||
if ( buttonlist.size() == 1 && isRadioButton(*buttonlist.begin()) )
|
if ( buttonlist.size() == 1 )
|
||||||
(*buttonlist.begin())->setChecked();
|
{
|
||||||
|
FToggleButton* first_button = static_cast<FToggleButton*>(*buttonlist.begin());
|
||||||
|
|
||||||
|
if ( isRadioButton(first_button) )
|
||||||
|
first_button->setChecked();
|
||||||
|
}
|
||||||
|
|
||||||
button->setGroup(this);
|
button->setGroup(this);
|
||||||
buttonlist.push_back(button);
|
buttonlist.push_back(button);
|
||||||
|
@ -257,7 +241,7 @@ void FButtonGroup::insert (FToggleButton* button)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FButtonGroup::remove (FToggleButton* button)
|
void FButtonGroup::remove (FToggleButton* button)
|
||||||
{
|
{
|
||||||
FButtonList::iterator iter;
|
FObjectList::iterator iter;
|
||||||
|
|
||||||
if ( ! button || buttonlist.empty() )
|
if ( ! button || buttonlist.empty() )
|
||||||
return;
|
return;
|
||||||
|
@ -266,7 +250,9 @@ void FButtonGroup::remove (FToggleButton* button)
|
||||||
|
|
||||||
while ( iter != buttonlist.end() )
|
while ( iter != buttonlist.end() )
|
||||||
{
|
{
|
||||||
if ( (*iter) == button )
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
||||||
|
|
||||||
|
if ( toggle_button == button )
|
||||||
{
|
{
|
||||||
iter = buttonlist.erase(iter);
|
iter = buttonlist.erase(iter);
|
||||||
button->setGroup(0);
|
button->setGroup(0);
|
||||||
|
@ -298,24 +284,26 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
|
||||||
{
|
{
|
||||||
if ( hasCheckedButton() && ! buttonlist.empty() )
|
if ( hasCheckedButton() && ! buttonlist.empty() )
|
||||||
{
|
{
|
||||||
FButtonList::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
iter = buttonlist.begin();
|
iter = buttonlist.begin();
|
||||||
end = buttonlist.end();
|
end = buttonlist.end();
|
||||||
|
|
||||||
while ( iter != end )
|
while ( iter != end )
|
||||||
{
|
{
|
||||||
if ( (*iter)->isChecked() )
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
||||||
|
|
||||||
|
if ( toggle_button->isChecked() )
|
||||||
{
|
{
|
||||||
if ( isRadioButton(*iter) )
|
if ( isRadioButton(toggle_button) )
|
||||||
{
|
{
|
||||||
in_ev->ignore();
|
in_ev->ignore();
|
||||||
FWidget* prev_element = getFocusWidget();
|
FWidget* prev_element = getFocusWidget();
|
||||||
(*iter)->setFocus();
|
toggle_button->setFocus();
|
||||||
|
|
||||||
if ( prev_element )
|
if ( prev_element )
|
||||||
prev_element->redraw();
|
prev_element->redraw();
|
||||||
|
|
||||||
(*iter)->redraw();
|
toggle_button->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -327,22 +315,12 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
|
||||||
|
|
||||||
if ( in_ev->isAccepted() )
|
if ( in_ev->isAccepted() )
|
||||||
{
|
{
|
||||||
|
in_ev->ignore();
|
||||||
|
FWidget* prev_element = getFocusWidget();
|
||||||
|
|
||||||
if ( in_ev->getFocusType() == fc::FocusNextWidget )
|
if ( in_ev->getFocusType() == fc::FocusNextWidget )
|
||||||
{
|
|
||||||
in_ev->ignore();
|
|
||||||
FWidget* prev_element = getFocusWidget();
|
|
||||||
focusFirstChild();
|
focusFirstChild();
|
||||||
|
|
||||||
if ( prev_element )
|
|
||||||
prev_element->redraw();
|
|
||||||
|
|
||||||
if ( getFocusWidget() )
|
|
||||||
getFocusWidget()->redraw();
|
|
||||||
}
|
|
||||||
else if ( in_ev->getFocusType() == fc::FocusPreviousWidget )
|
else if ( in_ev->getFocusType() == fc::FocusPreviousWidget )
|
||||||
{
|
|
||||||
in_ev->ignore();
|
|
||||||
FWidget* prev_element = getFocusWidget();
|
|
||||||
focusLastChild();
|
focusLastChild();
|
||||||
|
|
||||||
if ( prev_element )
|
if ( prev_element )
|
||||||
|
@ -351,7 +329,6 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
|
||||||
if ( getFocusWidget() )
|
if ( getFocusWidget() )
|
||||||
getFocusWidget()->redraw();
|
getFocusWidget()->redraw();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( getStatusBar() )
|
if ( getStatusBar() )
|
||||||
{
|
{
|
||||||
|
@ -361,15 +338,11 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
void FButtonGroup::onFocusOut (FFocusEvent*)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FButtonGroup::cb_buttonToggled (FWidget* widget, void*)
|
void FButtonGroup::cb_buttonToggled (FWidget* widget, void*)
|
||||||
{
|
{
|
||||||
FToggleButton* button = static_cast<FToggleButton*>(widget);
|
FToggleButton* button = static_cast<FToggleButton*>(widget);
|
||||||
FButtonList::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
|
|
||||||
if ( ! button->isChecked() )
|
if ( ! button->isChecked() )
|
||||||
return;
|
return;
|
||||||
|
@ -382,14 +355,16 @@ void FButtonGroup::cb_buttonToggled (FWidget* widget, void*)
|
||||||
|
|
||||||
while ( iter != end )
|
while ( iter != end )
|
||||||
{
|
{
|
||||||
if ( (*iter) != button
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
||||||
&& (*iter)->isChecked()
|
|
||||||
&& isRadioButton(*iter) )
|
|
||||||
{
|
|
||||||
(*iter)->unsetChecked();
|
|
||||||
|
|
||||||
if ( (*iter)->isVisible() && (*iter)->isShown() )
|
if ( toggle_button != button
|
||||||
(*iter)->redraw();
|
&& toggle_button->isChecked()
|
||||||
|
&& isRadioButton(toggle_button) )
|
||||||
|
{
|
||||||
|
toggle_button->unsetChecked();
|
||||||
|
|
||||||
|
if ( toggle_button->isVisible() && toggle_button->isShown() )
|
||||||
|
toggle_button->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -571,21 +546,23 @@ void FButtonGroup::directFocus()
|
||||||
|
|
||||||
if ( hasCheckedButton() && ! buttonlist.empty() )
|
if ( hasCheckedButton() && ! buttonlist.empty() )
|
||||||
{
|
{
|
||||||
FButtonList::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
iter = buttonlist.begin();
|
iter = buttonlist.begin();
|
||||||
end = buttonlist.end();
|
end = buttonlist.end();
|
||||||
|
|
||||||
while ( iter != end )
|
while ( iter != end )
|
||||||
{
|
{
|
||||||
if ( (*iter)->isChecked() )
|
FToggleButton* toggle_button = static_cast<FToggleButton*>(*iter);
|
||||||
|
|
||||||
|
if ( toggle_button->isChecked() )
|
||||||
{
|
{
|
||||||
if ( isRadioButton(*iter) )
|
if ( isRadioButton(toggle_button) )
|
||||||
{
|
{
|
||||||
found_checked = true;
|
found_checked = true;
|
||||||
FWidget* focused_widget = getFocusWidget();
|
FWidget* focused_widget = getFocusWidget();
|
||||||
FFocusEvent out (fc::FocusOut_Event);
|
FFocusEvent out (fc::FocusOut_Event);
|
||||||
FApplication::queueEvent(focused_widget, &out);
|
FApplication::queueEvent(focused_widget, &out);
|
||||||
(*iter)->setFocus();
|
toggle_button->setFocus();
|
||||||
|
|
||||||
if ( focused_widget )
|
if ( focused_widget )
|
||||||
focused_widget->redraw();
|
focused_widget->redraw();
|
||||||
|
|
|
@ -80,7 +80,6 @@ class FButtonGroup : public FWidget
|
||||||
void onMouseDown (FMouseEvent*);
|
void onMouseDown (FMouseEvent*);
|
||||||
void onAccel (FAccelEvent*);
|
void onAccel (FAccelEvent*);
|
||||||
void onFocusIn (FFocusEvent*);
|
void onFocusIn (FFocusEvent*);
|
||||||
void onFocusOut (FFocusEvent*);
|
|
||||||
|
|
||||||
// Callback method
|
// Callback method
|
||||||
void cb_buttonToggled (FWidget*, void*);
|
void cb_buttonToggled (FWidget*, void*);
|
||||||
|
@ -97,9 +96,6 @@ class FButtonGroup : public FWidget
|
||||||
void drawLabel();
|
void drawLabel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Typedef
|
|
||||||
typedef std::vector<FToggleButton*> FButtonList;
|
|
||||||
|
|
||||||
// Disable copy constructor
|
// Disable copy constructor
|
||||||
FButtonGroup (const FButtonGroup&);
|
FButtonGroup (const FButtonGroup&);
|
||||||
|
|
||||||
|
@ -116,7 +112,7 @@ class FButtonGroup : public FWidget
|
||||||
// Data Members
|
// Data Members
|
||||||
FString text;
|
FString text;
|
||||||
bool border;
|
bool border;
|
||||||
FButtonList buttonlist;
|
FObjectList buttonlist;
|
||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
|
3
src/fc.h
3
src/fc.h
|
@ -36,7 +36,8 @@ class fc
|
||||||
MouseMove_Event, // mouse move
|
MouseMove_Event, // mouse move
|
||||||
FocusIn_Event, // focus in
|
FocusIn_Event, // focus in
|
||||||
FocusOut_Event, // focus out
|
FocusOut_Event, // focus out
|
||||||
ChildFocusChanged_Event, // child focus changed
|
ChildFocusIn_Event, // child focus in
|
||||||
|
ChildFocusOut_Event, // child focus out
|
||||||
WindowActive_Event, // activate window
|
WindowActive_Event, // activate window
|
||||||
WindowInactive_Event, // deactivate window
|
WindowInactive_Event, // deactivate window
|
||||||
WindowRaised_Event, // raise window
|
WindowRaised_Event, // raise window
|
||||||
|
|
|
@ -49,11 +49,11 @@ FObject::~FObject() // destructor
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete children objects
|
// delete children objects
|
||||||
FObject::object_list children = this->getChildren();
|
FObjectList children = this->getChildren();
|
||||||
|
|
||||||
if ( ! children.empty() )
|
if ( ! children.empty() )
|
||||||
{
|
{
|
||||||
FObject::object_list::const_iterator iter;
|
FObjectList::const_iterator iter;
|
||||||
iter = children.begin();
|
iter = children.begin();
|
||||||
|
|
||||||
while ( iter != children.end() )
|
while ( iter != children.end() )
|
||||||
|
|
|
@ -57,7 +57,7 @@ class FObject
|
||||||
};
|
};
|
||||||
|
|
||||||
// Typedef
|
// Typedef
|
||||||
typedef std::list<FObject*> object_list;
|
typedef std::list<FObject*> FObjectList;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
explicit FObject (FObject* = 0);
|
explicit FObject (FObject* = 0);
|
||||||
|
@ -68,7 +68,7 @@ class FObject
|
||||||
// Accessors
|
// Accessors
|
||||||
virtual const char* getClassName() const;
|
virtual const char* getClassName() const;
|
||||||
FObject* getParent() const;
|
FObject* getParent() const;
|
||||||
object_list getChildren() const;
|
FObjectList getChildren() const;
|
||||||
int numOfChildren() const;
|
int numOfChildren() const;
|
||||||
|
|
||||||
// Inquiries
|
// Inquiries
|
||||||
|
@ -108,7 +108,7 @@ class FObject
|
||||||
|
|
||||||
// Data Members
|
// Data Members
|
||||||
FObject* parent_obj;
|
FObject* parent_obj;
|
||||||
object_list children_list;
|
FObjectList children_list;
|
||||||
bool has_parent;
|
bool has_parent;
|
||||||
static bool timer_modify_lock;
|
static bool timer_modify_lock;
|
||||||
};
|
};
|
||||||
|
@ -124,7 +124,7 @@ inline FObject* FObject::getParent() const
|
||||||
{ return parent_obj; }
|
{ return parent_obj; }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
inline FObject::object_list FObject::getChildren() const
|
inline FObject::FObjectList FObject::getChildren() const
|
||||||
{ return children_list; }
|
{ return children_list; }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
|
@ -498,7 +498,32 @@ void FScrollView::onWheel (FWheelEvent* ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FScrollView::onChildFocusChanged (FFocusEvent*)
|
void FScrollView::onFocusIn (FFocusEvent* in_ev)
|
||||||
|
{
|
||||||
|
// Sets the focus to a child widget if it exists
|
||||||
|
|
||||||
|
if ( hasChildren() )
|
||||||
|
{
|
||||||
|
FWidget* prev_element = getFocusWidget();
|
||||||
|
|
||||||
|
if ( in_ev->getFocusType() == fc::FocusNextWidget )
|
||||||
|
focusFirstChild();
|
||||||
|
else if ( in_ev->getFocusType() == fc::FocusPreviousWidget )
|
||||||
|
focusLastChild();
|
||||||
|
|
||||||
|
if ( prev_element )
|
||||||
|
prev_element->redraw();
|
||||||
|
|
||||||
|
if ( getFocusWidget() )
|
||||||
|
getFocusWidget()->redraw();
|
||||||
|
|
||||||
|
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
||||||
|
onChildFocusIn(&cfi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FScrollView::onChildFocusIn (FFocusEvent*)
|
||||||
{
|
{
|
||||||
// Scrolls the viewport so that the focused widget is visible
|
// Scrolls the viewport so that the focused widget is visible
|
||||||
|
|
||||||
|
@ -532,6 +557,35 @@ void FScrollView::onChildFocusChanged (FFocusEvent*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FScrollView::onChildFocusOut (FFocusEvent* out_ev)
|
||||||
|
{
|
||||||
|
// Change the focus away from FScrollView to another widget
|
||||||
|
|
||||||
|
FWidget* focus_widget = FWidget::getFocusWidget();
|
||||||
|
|
||||||
|
if ( out_ev->getFocusType() == fc::FocusNextWidget )
|
||||||
|
{
|
||||||
|
FWidget* last_widget = getLastFocusableWidget(getChildren());
|
||||||
|
|
||||||
|
if ( focus_widget == last_widget )
|
||||||
|
{
|
||||||
|
out_ev->accept();
|
||||||
|
focusNextChild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ( out_ev->getFocusType() == fc::FocusPreviousWidget )
|
||||||
|
{
|
||||||
|
FWidget* first_widget = getFirstFocusableWidget(getChildren());
|
||||||
|
|
||||||
|
if ( focus_widget == first_widget )
|
||||||
|
{
|
||||||
|
out_ev->accept();
|
||||||
|
focusPrevChild();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// protected methods of FScrollView
|
// protected methods of FScrollView
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
|
@ -91,7 +91,9 @@ class FScrollView : public FWidget
|
||||||
// Event handlers
|
// Event handlers
|
||||||
void onKeyPress (FKeyEvent*);
|
void onKeyPress (FKeyEvent*);
|
||||||
void onWheel (FWheelEvent*);
|
void onWheel (FWheelEvent*);
|
||||||
void onChildFocusChanged (FFocusEvent*);
|
void onFocusIn (FFocusEvent*);
|
||||||
|
void onChildFocusIn (FFocusEvent*);
|
||||||
|
void onChildFocusOut (FFocusEvent*);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Using-declaration
|
// Using-declaration
|
||||||
|
|
|
@ -797,6 +797,7 @@ void FVTerm::resizeArea ( int offset_top, int offset_left
|
||||||
default_char.trans_shadow = 0;
|
default_char.trans_shadow = 0;
|
||||||
default_char.inherit_bg = 0;
|
default_char.inherit_bg = 0;
|
||||||
default_char.no_changes = 0;
|
default_char.no_changes = 0;
|
||||||
|
default_char.printed = 0;
|
||||||
|
|
||||||
std::fill_n (area->text, area_size, default_char);
|
std::fill_n (area->text, area_size, default_char);
|
||||||
|
|
||||||
|
|
140
src/fwidget.cpp
140
src/fwidget.cpp
|
@ -148,6 +148,52 @@ FWidget* FWidget::getFocusWidget() const
|
||||||
return focus_widget;
|
return focus_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
FWidget* FWidget::getFirstFocusableWidget (FObjectList children)
|
||||||
|
{
|
||||||
|
if ( children.empty() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
FObjectList::const_iterator iter, end;
|
||||||
|
iter = children.begin();
|
||||||
|
end = children.end();
|
||||||
|
|
||||||
|
while ( iter != end )
|
||||||
|
{
|
||||||
|
FWidget* child = static_cast<FWidget*>(*iter);
|
||||||
|
|
||||||
|
if ( child->isEnabled() && child->acceptFocus() )
|
||||||
|
return child;
|
||||||
|
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
FWidget* FWidget::getLastFocusableWidget (FObjectList children)
|
||||||
|
{
|
||||||
|
if ( children.empty() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
FObjectList::const_iterator iter, begin;
|
||||||
|
begin = children.begin();
|
||||||
|
iter = children.end();
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
--iter;
|
||||||
|
FWidget* child = static_cast<FWidget*>(*iter);
|
||||||
|
|
||||||
|
if ( child->isEnabled() && child->acceptFocus() )
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
while ( iter != begin );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
FWidget* FWidget::getClickedWidget()
|
FWidget* FWidget::getClickedWidget()
|
||||||
{
|
{
|
||||||
|
@ -305,12 +351,6 @@ bool FWidget::setFocus (bool on)
|
||||||
window->setWindowFocusWidget(this);
|
window->setWindowFocusWidget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( hasParent() && last_focus != FWidget::getFocusWidget() )
|
|
||||||
{
|
|
||||||
FFocusEvent cfc (fc::ChildFocusChanged_Event);
|
|
||||||
FApplication::sendEvent(getParentWidget(), &cfc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return focus = (on) ? true : false;
|
return focus = (on) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -746,8 +786,8 @@ FWidget* FWidget::childWidgetAt (FWidget* p, int x, int y)
|
||||||
{
|
{
|
||||||
if ( p && p->hasChildren() )
|
if ( p && p->hasChildren() )
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObjectList children;
|
||||||
FObject::object_list::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
|
|
||||||
children = p->getChildren();
|
children = p->getChildren();
|
||||||
iter = children.begin();
|
iter = children.begin();
|
||||||
|
@ -776,8 +816,8 @@ FWidget* FWidget::childWidgetAt (FWidget* p, int x, int y)
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
int FWidget::numOfFocusableChildren()
|
int FWidget::numOfFocusableChildren()
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObjectList children;
|
||||||
FObject::object_list::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
|
|
||||||
if ( ! this->hasChildren() )
|
if ( ! this->hasChildren() )
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1044,8 +1084,8 @@ void FWidget::redraw()
|
||||||
// draw child elements
|
// draw child elements
|
||||||
if ( this->hasChildren() )
|
if ( this->hasChildren() )
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObjectList children;
|
||||||
FObject::object_list::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
|
|
||||||
children = this->getChildren();
|
children = this->getChildren();
|
||||||
iter = children.begin();
|
iter = children.begin();
|
||||||
|
@ -1133,8 +1173,8 @@ void FWidget::show()
|
||||||
|
|
||||||
if ( this->hasChildren() )
|
if ( this->hasChildren() )
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObjectList children;
|
||||||
FObject::object_list::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
|
|
||||||
children = this->getChildren();
|
children = this->getChildren();
|
||||||
iter = children.begin();
|
iter = children.begin();
|
||||||
|
@ -1186,8 +1226,8 @@ void FWidget::hide()
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
bool FWidget::focusFirstChild()
|
bool FWidget::focusFirstChild()
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObjectList children;
|
||||||
FObject::object_list::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
|
|
||||||
if ( ! this->hasChildren() )
|
if ( ! this->hasChildren() )
|
||||||
return false;
|
return false;
|
||||||
|
@ -1228,8 +1268,8 @@ bool FWidget::focusFirstChild()
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
bool FWidget::focusLastChild()
|
bool FWidget::focusLastChild()
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObjectList children;
|
||||||
FObject::object_list::const_iterator iter, begin;
|
FObjectList::const_iterator iter, begin;
|
||||||
|
|
||||||
if ( ! this->hasChildren() )
|
if ( ! this->hasChildren() )
|
||||||
return false;
|
return false;
|
||||||
|
@ -1720,8 +1760,8 @@ void FWidget::adjustSize()
|
||||||
|
|
||||||
if ( this->hasChildren() )
|
if ( this->hasChildren() )
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObjectList children;
|
||||||
FObject::object_list::const_iterator iter, end;
|
FObjectList::const_iterator iter, end;
|
||||||
|
|
||||||
children = this->getChildren();
|
children = this->getChildren();
|
||||||
iter = children.begin();
|
iter = children.begin();
|
||||||
|
@ -1770,12 +1810,12 @@ bool FWidget::focusNextChild()
|
||||||
|
|
||||||
if ( hasParent() )
|
if ( hasParent() )
|
||||||
{
|
{
|
||||||
FWidget* parent = static_cast<FWidget*>(getParent());
|
FWidget* parent = getParentWidget();
|
||||||
|
|
||||||
if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 )
|
if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 )
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObjectList children;
|
||||||
FObject::object_list::iterator iter, end;
|
FObjectList::iterator iter, end;
|
||||||
|
|
||||||
children = parent->getChildren();
|
children = parent->getChildren();
|
||||||
iter = children.begin();
|
iter = children.begin();
|
||||||
|
@ -1788,7 +1828,7 @@ bool FWidget::focusNextChild()
|
||||||
if ( w == this )
|
if ( w == this )
|
||||||
{
|
{
|
||||||
FWidget* next;
|
FWidget* next;
|
||||||
FObject::object_list::const_iterator next_element;
|
FObjectList::const_iterator next_element;
|
||||||
next_element = iter;
|
next_element = iter;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -1808,20 +1848,31 @@ bool FWidget::focusNextChild()
|
||||||
out.setFocusType(fc::FocusNextWidget);
|
out.setFocusType(fc::FocusNextWidget);
|
||||||
FApplication::sendEvent(this, &out);
|
FApplication::sendEvent(this, &out);
|
||||||
|
|
||||||
|
FFocusEvent cfo (fc::ChildFocusOut_Event);
|
||||||
|
cfo.setFocusType(fc::FocusNextWidget);
|
||||||
|
cfo.ignore();
|
||||||
|
FApplication::sendEvent(parent, &cfo);
|
||||||
|
|
||||||
|
if ( cfo.isAccepted() )
|
||||||
|
out.ignore();
|
||||||
|
|
||||||
if ( out.isAccepted() )
|
if ( out.isAccepted() )
|
||||||
{
|
{
|
||||||
if ( next == this )
|
if ( next == this )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
next->setFocus();
|
next->setFocus();
|
||||||
|
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
||||||
|
FApplication::sendEvent(parent, &cfi);
|
||||||
|
|
||||||
FFocusEvent in (fc::FocusIn_Event);
|
FFocusEvent in (fc::FocusIn_Event);
|
||||||
in.setFocusType(fc::FocusNextWidget);
|
in.setFocusType(fc::FocusNextWidget);
|
||||||
FApplication::sendEvent(next, &in);
|
FApplication::sendEvent(next, &in);
|
||||||
|
|
||||||
if ( in.isAccepted() )
|
if ( in.isAccepted() )
|
||||||
{
|
{
|
||||||
this->draw();
|
this->redraw();
|
||||||
next->draw();
|
next->redraw();
|
||||||
updateTerminal();
|
updateTerminal();
|
||||||
flush_out();
|
flush_out();
|
||||||
}
|
}
|
||||||
|
@ -1843,12 +1894,12 @@ bool FWidget::focusPrevChild()
|
||||||
|
|
||||||
if ( hasParent() )
|
if ( hasParent() )
|
||||||
{
|
{
|
||||||
FWidget* parent = static_cast<FWidget*>(getParent());
|
FWidget* parent = getParentWidget();
|
||||||
|
|
||||||
if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 )
|
if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 )
|
||||||
{
|
{
|
||||||
FObject::object_list children;
|
FObjectList children;
|
||||||
FObject::object_list::iterator iter, begin;
|
FObjectList::iterator iter, begin;
|
||||||
|
|
||||||
children = parent->getChildren();
|
children = parent->getChildren();
|
||||||
iter = children.end();
|
iter = children.end();
|
||||||
|
@ -1862,7 +1913,7 @@ bool FWidget::focusPrevChild()
|
||||||
if ( w == this )
|
if ( w == this )
|
||||||
{
|
{
|
||||||
FWidget* prev;
|
FWidget* prev;
|
||||||
FObject::object_list::const_iterator prev_element;
|
FObjectList::const_iterator prev_element;
|
||||||
prev_element = iter;
|
prev_element = iter;
|
||||||
|
|
||||||
do
|
do
|
||||||
|
@ -1881,20 +1932,31 @@ bool FWidget::focusPrevChild()
|
||||||
out.setFocusType(fc::FocusPreviousWidget);
|
out.setFocusType(fc::FocusPreviousWidget);
|
||||||
FApplication::sendEvent(this, &out);
|
FApplication::sendEvent(this, &out);
|
||||||
|
|
||||||
|
FFocusEvent cfo (fc::ChildFocusOut_Event);
|
||||||
|
cfo.setFocusType(fc::FocusPreviousWidget);
|
||||||
|
cfo.ignore();
|
||||||
|
FApplication::sendEvent(parent, &cfo);
|
||||||
|
|
||||||
|
if ( cfo.isAccepted() )
|
||||||
|
out.ignore();
|
||||||
|
|
||||||
if ( out.isAccepted() )
|
if ( out.isAccepted() )
|
||||||
{
|
{
|
||||||
if ( prev == this )
|
if ( prev == this )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
prev->setFocus();
|
prev->setFocus();
|
||||||
|
FFocusEvent cfi (fc::ChildFocusIn_Event);
|
||||||
|
FApplication::sendEvent(parent, &cfi);
|
||||||
|
|
||||||
FFocusEvent in (fc::FocusIn_Event);
|
FFocusEvent in (fc::FocusIn_Event);
|
||||||
in.setFocusType(fc::FocusPreviousWidget);
|
in.setFocusType(fc::FocusPreviousWidget);
|
||||||
FApplication::sendEvent(prev, &in);
|
FApplication::sendEvent(prev, &in);
|
||||||
|
|
||||||
if ( in.isAccepted() )
|
if ( in.isAccepted() )
|
||||||
{
|
{
|
||||||
this->draw();
|
this->redraw();
|
||||||
prev->draw();
|
prev->redraw();
|
||||||
updateTerminal();
|
updateTerminal();
|
||||||
flush_out();
|
flush_out();
|
||||||
}
|
}
|
||||||
|
@ -2004,8 +2066,12 @@ bool FWidget::event (FEvent* ev)
|
||||||
onFocusOut ( static_cast<FFocusEvent*>(ev) );
|
onFocusOut ( static_cast<FFocusEvent*>(ev) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case fc::ChildFocusChanged_Event:
|
case fc::ChildFocusIn_Event:
|
||||||
onChildFocusChanged ( static_cast<FFocusEvent*>(ev) );
|
onChildFocusIn ( static_cast<FFocusEvent*>(ev) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case fc::ChildFocusOut_Event:
|
||||||
|
onChildFocusOut ( static_cast<FFocusEvent*>(ev) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case fc::Accelerator_Event:
|
case fc::Accelerator_Event:
|
||||||
|
@ -2079,7 +2145,11 @@ void FWidget::onFocusOut (FFocusEvent*)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void FWidget::onChildFocusChanged (FFocusEvent*)
|
void FWidget::onChildFocusIn (FFocusEvent*)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
void FWidget::onChildFocusOut (FFocusEvent*)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
|
@ -124,6 +124,8 @@ class FWidget : public FVTerm
|
||||||
FWidget* getParentWidget() const;
|
FWidget* getParentWidget() const;
|
||||||
static FWidget* getMainWidget();
|
static FWidget* getMainWidget();
|
||||||
virtual FWidget* getFocusWidget() const;
|
virtual FWidget* getFocusWidget() const;
|
||||||
|
virtual FWidget* getFirstFocusableWidget (FObjectList);
|
||||||
|
virtual FWidget* getLastFocusableWidget (FObjectList);
|
||||||
static FWidget* getClickedWidget();
|
static FWidget* getClickedWidget();
|
||||||
static FWidget* getMoveSizeWidget();
|
static FWidget* getMoveSizeWidget();
|
||||||
static FWidget* getOpenMenu();
|
static FWidget* getOpenMenu();
|
||||||
|
@ -313,7 +315,8 @@ class FWidget : public FVTerm
|
||||||
virtual void onMouseMove (FMouseEvent*);
|
virtual void onMouseMove (FMouseEvent*);
|
||||||
virtual void onFocusIn (FFocusEvent*);
|
virtual void onFocusIn (FFocusEvent*);
|
||||||
virtual void onFocusOut (FFocusEvent*);
|
virtual void onFocusOut (FFocusEvent*);
|
||||||
virtual void onChildFocusChanged (FFocusEvent*);
|
virtual void onChildFocusIn (FFocusEvent*);
|
||||||
|
virtual void onChildFocusOut (FFocusEvent*);
|
||||||
virtual void onAccel (FAccelEvent*);
|
virtual void onAccel (FAccelEvent*);
|
||||||
virtual void onResize (FResizeEvent*);
|
virtual void onResize (FResizeEvent*);
|
||||||
virtual void onShow (FShowEvent*);
|
virtual void onShow (FShowEvent*);
|
||||||
|
@ -521,6 +524,7 @@ class FWidget : public FVTerm
|
||||||
|
|
||||||
// Friend class
|
// Friend class
|
||||||
friend class FToggleButton;
|
friend class FToggleButton;
|
||||||
|
friend class FScrollView;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
|
@ -145,7 +145,8 @@ void scrollview::cb_go_west (FWidget*, void*)
|
||||||
scrollToX (1);
|
scrollToX (1);
|
||||||
go_north->setFocus();
|
go_north->setFocus();
|
||||||
go_west->redraw();
|
go_west->redraw();
|
||||||
go_north->redraw();}
|
go_north->redraw();
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
void scrollview::cb_go_north (FWidget*, void*)
|
void scrollview::cb_go_north (FWidget*, void*)
|
||||||
|
|
Loading…
Reference in New Issue