FifeGUI 0.3.0
A C++ GUI library designed for games.
fcn::FocusHandler Class Reference

#include <focushandler.hpp>

Classes

class  ModalScope
struct  ModalState

Public Types

using InputModalScope = ModalScope

Public Member Functions

virtual void add (Widget *widget)
virtual void clearModal ()
 FocusHandler (FocusHandler &&)=delete
 FocusHandler (FocusHandler const &)=delete
virtual void focusNext ()
virtual void focusNone ()
virtual void focusPrevious ()
virtual WidgetgetDraggedWidget ()
virtual WidgetgetFocused () const
virtual WidgetgetFocusOwner () const
virtual WidgetgetLastWidgetPressed ()
virtual WidgetgetLastWidgetWithModalFocus ()
virtual WidgetgetLastWidgetWithModalMouseInputFocus ()
virtual WidgetgetLastWidgetWithMouse ()
virtual WidgetgetMouseCaptureOwner () const
virtual bool hasModalFocus () const
virtual bool isFocused (Widget const *widget) const
FocusHandler & operator= (FocusHandler &&)=delete
FocusHandler & operator= (FocusHandler const &)=delete
virtual void popModal () noexcept
virtual void pushModal (Widget *focusOwner, Widget *mouseOwner=nullptr)
virtual void releaseFocus (Widget *widget)
virtual void remove (Widget *widget)
virtual void requestFocus (Widget *widget)
virtual void setDraggedWidget (Widget *draggedWidget)
virtual void setFocusedWidget (Widget *widget)
virtual void setLastWidgetPressed (Widget *lastWidgetPressed)
virtual void setLastWidgetWithModalFocus (Widget *lastWidgetWithModalFocus)
virtual void setLastWidgetWithModalMouseInputFocus (Widget *lastWidgetWithModalMouseInputFocus)
virtual void setLastWidgetWithMouse (Widget *lastWidgetWithMouse)
virtual void tabNext ()
virtual void tabPrevious ()
virtual void widgetHidden (Widget *widget)

Protected Types

using WidgetIterator = WidgetVector::iterator
using WidgetVector = std::vector<Widget*>

Protected Member Functions

virtual void distributeFocusGainedEvent (Event const &focusEvent)
virtual void distributeFocusLostEvent (Event const &focusEvent)

Protected Attributes

WidgetmDraggedWidget
WidgetmFocusedWidget
WidgetmLastWidgetPressed
WidgetmLastWidgetWithModalFocus
WidgetmLastWidgetWithModalMouseInputFocus
WidgetmLastWidgetWithMouse
std::vector< ModalStatemModalStack
WidgetVector mWidgets

Detailed Description

Manages focus navigation and assignment among widgets within a Gui instance.

Each Gui has at least one focus handler. You will probably not use the focus handler directly as Widget has functions that automatically uses the active focus handler.

See also
Widget::isFocus, Widget::isModalFocused, Widget::isModalMouseInputFocused, Widget::requestFocus, Widget::isModalFocused, Widget::isModalMouseInputFocused, Widget::setFocusable, Widget::isFocusable, FocusListener

Definition at line 33 of file focushandler.hpp.

Member Typedef Documentation

◆ InputModalScope

Alias for ModalScope to clarify its purpose for input handling.

Deprecated
Use InputModalScope instead.

◆ WidgetIterator

using fcn::FocusHandler::WidgetIterator = WidgetVector::iterator
protected

Iterator for WidgetVector.

Definition at line 392 of file focushandler.hpp.

◆ WidgetVector

using fcn::FocusHandler::WidgetVector = std::vector<Widget*>
protected

Vector of Widget pointers.

Definition at line 389 of file focushandler.hpp.

Constructor & Destructor Documentation

◆ FocusHandler()

fcn::FocusHandler::FocusHandler ( )

Definition at line 26 of file focushandler.cpp.

Member Function Documentation

◆ add()

void fcn::FocusHandler::add ( Widget * widget)
virtual

Adds a widget to by handles by the focus handler.

Parameters
widgetThe widget to add.
See also
remove

Definition at line 283 of file focushandler.cpp.

References add(), and mWidgets.

Referenced by fcn::Widget::_setFocusHandler(), and add().

◆ clearModal()

void fcn::FocusHandler::clearModal ( )
virtual

Clears all modal states from the stack.

Resets all modal focus and mouse input.

See also
pushModal, popModal

Definition at line 114 of file focushandler.cpp.

References clearModal(), and mModalStack.

Referenced by clearModal().

◆ distributeFocusGainedEvent()

void fcn::FocusHandler::distributeFocusGainedEvent ( Event const & focusEvent)
protectedvirtual

Distributes a focus gained event.

Parameters
focusEventthe event to distribute.

Definition at line 469 of file focushandler.cpp.

References fcn::Widget::_getFocusListeners(), distributeFocusGainedEvent(), and fcn::Event::getSource().

Referenced by distributeFocusGainedEvent(), focusNext(), focusPrevious(), requestFocus(), tabNext(), and tabPrevious().

◆ distributeFocusLostEvent()

void fcn::FocusHandler::distributeFocusLostEvent ( Event const & focusEvent)
protectedvirtual

Distributes a focus lost event.

Parameters
focusEventthe event to distribute.

Definition at line 457 of file focushandler.cpp.

References fcn::Widget::_getFocusListeners(), distributeFocusLostEvent(), and fcn::Event::getSource().

Referenced by distributeFocusLostEvent(), focusNext(), focusNone(), focusPrevious(), releaseFocus(), requestFocus(), tabNext(), and tabPrevious().

◆ focusNext()

void fcn::FocusHandler::focusNext ( )
virtual

Focuses the next widget added to a container.

If no widget has focus the first widget gets focus. The order in which the widgets are focused is determined by the order they were added to a container.

See also
focusPrevious

Definition at line 174 of file focushandler.cpp.

References distributeFocusGainedEvent(), distributeFocusLostEvent(), focusNext(), mFocusedWidget, and mWidgets.

Referenced by focusNext().

◆ focusNone()

void fcn::FocusHandler::focusNone ( )
virtual

Focuses nothing.

A focus event will also be sent to the focused widget's focus listeners if a widget has focus.

Definition at line 325 of file focushandler.cpp.

References distributeFocusLostEvent(), focusNone(), and mFocusedWidget.

Referenced by focusNone(), and pushModal().

◆ focusPrevious()

void fcn::FocusHandler::focusPrevious ( )
virtual

Focuses the previous widget added to a container.

If no widget has focus the first widget gets focus. The order in which the widgets are focused is determined by the order they were added to a container.

See also
focusNext

Definition at line 224 of file focushandler.cpp.

References distributeFocusGainedEvent(), distributeFocusLostEvent(), focusPrevious(), mFocusedWidget, and mWidgets.

Referenced by focusPrevious().

◆ getDraggedWidget()

Widget * fcn::FocusHandler::getDraggedWidget ( )
virtual

Gets the widget being dragged.

Used by the GUI class to keep track of the dragged widget.

Returns
the widget being dragged.
See also
setDraggedWidget

Definition at line 481 of file focushandler.cpp.

References getDraggedWidget(), and mDraggedWidget.

Referenced by getDraggedWidget().

◆ getFocused()

Widget * fcn::FocusHandler::getFocused ( ) const
virtual

Gets the widget with focus.

Returns
The widget with focus. Nullptr if no widget has focus.

Definition at line 151 of file focushandler.cpp.

References getFocused(), and mFocusedWidget.

Referenced by getFocused(), and fcn::Gui::getKeyEventSource().

◆ getFocusOwner()

Widget * fcn::FocusHandler::getFocusOwner ( ) const
virtual

Gets the active input root widget for focus routing.

Returns the top of the modal stack for focus, or nullptr if no modal.

Returns
The widget that currently owns modal focus, or nullptr.

Definition at line 156 of file focushandler.cpp.

References getFocusOwner(), and mModalStack.

Referenced by getFocusOwner(), tabNext(), and tabPrevious().

◆ getLastWidgetPressed()

Widget * fcn::FocusHandler::getLastWidgetPressed ( )
virtual

Gets the last widget pressed.

Used by the GUI class to keep track of pressed widgets.

Returns
The last widget pressed.
See also
setLastWidgetPressed

Definition at line 521 of file focushandler.cpp.

References getLastWidgetPressed(), and mLastWidgetPressed.

Referenced by getLastWidgetPressed().

◆ getLastWidgetWithModalFocus()

Widget * fcn::FocusHandler::getLastWidgetWithModalFocus ( )
virtual

Gets the last widget with modal focus.

Returns
The last widget with modal focus.
See also
setLastWidgetWithModalFocus

Definition at line 501 of file focushandler.cpp.

References getLastWidgetWithModalFocus(), and mLastWidgetWithModalFocus.

Referenced by getLastWidgetWithModalFocus().

◆ getLastWidgetWithModalMouseInputFocus()

Widget * fcn::FocusHandler::getLastWidgetWithModalMouseInputFocus ( )
virtual

Gets the last widget with modal mouse input focus.

Returns
The last widget with modal mouse input focus.
See also
setLastWidgetWithModalMouseInputFocus

Definition at line 511 of file focushandler.cpp.

References getLastWidgetWithModalMouseInputFocus(), and mLastWidgetWithModalMouseInputFocus.

Referenced by getLastWidgetWithModalMouseInputFocus().

◆ getLastWidgetWithMouse()

Widget * fcn::FocusHandler::getLastWidgetWithMouse ( )
virtual

Gets the last widget with the mouse.

Used by the GUI class to keep track the last widget with the mouse.

Returns
The last widget with the mouse.
See also
setLastWidgetWithMouse

Definition at line 491 of file focushandler.cpp.

References getLastWidgetWithMouse(), and mLastWidgetWithMouse.

Referenced by getLastWidgetWithMouse().

◆ getMouseCaptureOwner()

Widget * fcn::FocusHandler::getMouseCaptureOwner ( ) const
virtual

Gets the widget with modal mouse input focus.

Returns
The widget with modal mouse input focus. Nullptr if no widget has modal mouse input focus.

Definition at line 165 of file focushandler.cpp.

References getMouseCaptureOwner(), and mModalStack.

Referenced by getMouseCaptureOwner().

◆ hasModalFocus()

bool fcn::FocusHandler::hasModalFocus ( ) const
virtual

Checks if any modal state is active.

Returns
True if modal focus or modal mouse input is active.

Definition at line 63 of file focushandler.cpp.

References hasModalFocus(), and mModalStack.

Referenced by hasModalFocus().

◆ isFocused()

bool fcn::FocusHandler::isFocused ( Widget const * widget) const
virtual

Checks if a widget is focused.

Parameters
widgetThe widget to check.
Returns
True if the widget is focused, false otherwise.
See also
Widget::isFocused

Definition at line 278 of file focushandler.cpp.

References isFocused(), and mFocusedWidget.

Referenced by isFocused(), and remove().

◆ popModal()

void fcn::FocusHandler::popModal ( )
virtualnoexcept

Pops the current modal state from the stack.

Restores focus to the previous modal level if any.

See also
pushModal, clearModal

Definition at line 92 of file focushandler.cpp.

References mModalStack, popModal(), and requestFocus().

Referenced by popModal().

◆ pushModal()

void fcn::FocusHandler::pushModal ( Widget * focusOwner,
Widget * mouseOwner = nullptr )
virtual

Pushes a new modal state onto the stack.

Parameters
focusOwnerThe widget that will have modal focus.
mouseOwnerOptional widget for modal mouse input focus.
See also
popModal, clearModal

Definition at line 68 of file focushandler.cpp.

References focusNone(), fcn::FocusHandler::ModalState::focusOwner, fcn::Widget::getMouseCapture(), fcn::Widget::isDescendantOf(), mFocusedWidget, mModalStack, fcn::FocusHandler::ModalState::mouseOwner, and pushModal().

Referenced by pushModal().

◆ releaseFocus()

void fcn::FocusHandler::releaseFocus ( Widget * widget)
virtual

Releases focus for the specified widget if it is currently focused.

Parameters
widgetThe widget to release focus for.
See also
requestFocus, setFocusedWidget

Definition at line 119 of file focushandler.cpp.

References distributeFocusLostEvent(), mFocusedWidget, and releaseFocus().

Referenced by releaseFocus().

◆ remove()

void fcn::FocusHandler::remove ( Widget * widget)
virtual

Removes a widget from the focus handler.

Parameters
widgetThe widget to remove.
See also
add

Definition at line 288 of file focushandler.cpp.

References isFocused(), mDraggedWidget, mFocusedWidget, mLastWidgetPressed, mLastWidgetWithModalFocus, mLastWidgetWithModalMouseInputFocus, mLastWidgetWithMouse, mWidgets, and remove().

Referenced by remove().

◆ requestFocus()

void fcn::FocusHandler::requestFocus ( Widget * widget)
virtual

Requests focus for a widget.

Focus will only be granted to a widget if it's focusable and if no other widget has modal focus. If a widget receives focus, a focus event will be sent to the focus listeners of the widget.

Parameters
widgetThe widget to request focus for.
See also
isFocused, Widget::requestFocus

Definition at line 36 of file focushandler.cpp.

References distributeFocusGainedEvent(), distributeFocusLostEvent(), mFocusedWidget, mWidgets, requestFocus(), setFocusedWidget(), and fcn::throwException().

Referenced by popModal(), and requestFocus().

◆ setDraggedWidget()

void fcn::FocusHandler::setDraggedWidget ( Widget * draggedWidget)
virtual

Sets the widget being dragged.

Used by the GUI class to keep track of the dragged widget.

Parameters
draggedWidgetThe widget being dragged.
See also
getDraggedWidget

Definition at line 486 of file focushandler.cpp.

References mDraggedWidget, and setDraggedWidget().

Referenced by setDraggedWidget().

◆ setFocusedWidget()

void fcn::FocusHandler::setFocusedWidget ( Widget * widget)
virtual

Sets the focused widget directly.

Parameters
widgetThe widget to focus, or nullptr to clear focus.
See also
requestFocus, releaseFocus

Definition at line 132 of file focushandler.cpp.

References mFocusedWidget, fcn::Widget::setFocused(), and setFocusedWidget().

Referenced by requestFocus(), and setFocusedWidget().

◆ setLastWidgetPressed()

void fcn::FocusHandler::setLastWidgetPressed ( Widget * lastWidgetPressed)
virtual

Sets the last widget pressed.

Used by the GUI class to keep track of pressed widgets.

Parameters
lastWidgetPressedThe last widget pressed.
See also
getLastWidgetPressed

Definition at line 526 of file focushandler.cpp.

References mLastWidgetPressed, and setLastWidgetPressed().

Referenced by setLastWidgetPressed().

◆ setLastWidgetWithModalFocus()

void fcn::FocusHandler::setLastWidgetWithModalFocus ( Widget * lastWidgetWithModalFocus)
virtual

Sets the last widget with modal focus.

Parameters
lastWidgetWithModalFocusThe last widget with modal focus.
See also
getLastWidgetWithModalFocus

Definition at line 506 of file focushandler.cpp.

References mLastWidgetWithModalFocus, and setLastWidgetWithModalFocus().

Referenced by setLastWidgetWithModalFocus().

◆ setLastWidgetWithModalMouseInputFocus()

void fcn::FocusHandler::setLastWidgetWithModalMouseInputFocus ( Widget * lastWidgetWithModalMouseInputFocus)
virtual

Sets the last widget with modal mouse input focus.

Parameters
lastWidgetWithModalMouseInputFocusThe last widget with modal mouse input focus.
See also
getLastWidgetWithModalMouseInputFocus

Definition at line 516 of file focushandler.cpp.

References mLastWidgetWithModalMouseInputFocus, and setLastWidgetWithModalMouseInputFocus().

Referenced by setLastWidgetWithModalMouseInputFocus().

◆ setLastWidgetWithMouse()

void fcn::FocusHandler::setLastWidgetWithMouse ( Widget * lastWidgetWithMouse)
virtual

Sets the last widget with the mouse.

Used by the GUI class to keep track the last widget with the mouse.

Parameters
lastWidgetWithMouseThe last widget with the mouse.
See also
getLastWidgetWithMouse

Definition at line 496 of file focushandler.cpp.

References mLastWidgetWithMouse, and setLastWidgetWithMouse().

Referenced by setLastWidgetWithMouse().

◆ tabNext()

void fcn::FocusHandler::tabNext ( )
virtual

Focuses the next widget which allows tabbing in unless the current focused Widget disallows tabbing out.

See also
tabPrevious

Definition at line 336 of file focushandler.cpp.

References distributeFocusGainedEvent(), distributeFocusLostEvent(), getFocusOwner(), mFocusedWidget, mWidgets, and tabNext().

Referenced by tabNext().

◆ tabPrevious()

void fcn::FocusHandler::tabPrevious ( )
virtual

Focuses the previous widget which allows tabbing in unless current focused Widget disallows tabbing out.

See also
tabNext

Definition at line 397 of file focushandler.cpp.

References distributeFocusGainedEvent(), distributeFocusLostEvent(), getFocusOwner(), mFocusedWidget, mWidgets, and tabPrevious().

Referenced by tabPrevious().

◆ widgetHidden()

void fcn::FocusHandler::widgetHidden ( Widget * widget)
virtual

Informs the focus handler that a widget was hidden.

This is needed because the focus handler must determine which widget has the mouse now.

Parameters
widgetWidget that was hidden

Definition at line 531 of file focushandler.cpp.

References widgetHidden().

Referenced by widgetHidden().

Member Data Documentation

◆ mDraggedWidget

Widget* fcn::FocusHandler::mDraggedWidget
protected

Holds the dragged widget.

Nullptr if no widget is being dragged.

Definition at line 430 of file focushandler.hpp.

Referenced by getDraggedWidget(), remove(), and setDraggedWidget().

◆ mFocusedWidget

Widget* fcn::FocusHandler::mFocusedWidget
protected

Holds the focused widget.

Nullptr if no widget has focus.

Definition at line 423 of file focushandler.hpp.

Referenced by focusNext(), focusNone(), focusPrevious(), getFocused(), isFocused(), pushModal(), releaseFocus(), remove(), requestFocus(), setFocusedWidget(), tabNext(), and tabPrevious().

◆ mLastWidgetPressed

Widget* fcn::FocusHandler::mLastWidgetPressed
protected

Holds the last widget pressed.

Definition at line 450 of file focushandler.hpp.

Referenced by getLastWidgetPressed(), remove(), and setLastWidgetPressed().

◆ mLastWidgetWithModalFocus

Widget* fcn::FocusHandler::mLastWidgetWithModalFocus
protected

Holds the last widget with modal focus.

Definition at line 440 of file focushandler.hpp.

Referenced by getLastWidgetWithModalFocus(), remove(), and setLastWidgetWithModalFocus().

◆ mLastWidgetWithModalMouseInputFocus

Widget* fcn::FocusHandler::mLastWidgetWithModalMouseInputFocus
protected

Holds the last widget with modal mouse input focus.

Definition at line 445 of file focushandler.hpp.

Referenced by getLastWidgetWithModalMouseInputFocus(), remove(), and setLastWidgetWithModalMouseInputFocus().

◆ mLastWidgetWithMouse

Widget* fcn::FocusHandler::mLastWidgetWithMouse
protected

Holds the last widget with the mouse.

Definition at line 435 of file focushandler.hpp.

Referenced by getLastWidgetWithMouse(), remove(), and setLastWidgetWithMouse().

◆ mModalStack

std::vector<ModalState> fcn::FocusHandler::mModalStack
protected

Holds the modal stack for nested modal dialogs.

Definition at line 413 of file focushandler.hpp.

Referenced by clearModal(), getFocusOwner(), getMouseCaptureOwner(), hasModalFocus(), popModal(), and pushModal().

◆ mWidgets

WidgetVector fcn::FocusHandler::mWidgets
protected

Holds the widgets currently being handled by the focus handler.

Definition at line 418 of file focushandler.hpp.

Referenced by add(), focusNext(), focusPrevious(), remove(), requestFocus(), tabNext(), and tabPrevious().


The documentation for this class was generated from the following files: