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

#include <focushandler.hpp>

Public Member Functions

virtual void add (Widget *widget)
 FocusHandler (FocusHandler &&)=delete
 FocusHandler (FocusHandler const &)=delete
virtual void focusNext ()
virtual void focusNone ()
virtual void focusPrevious ()
virtual WidgetgetDraggedWidget ()
virtual WidgetgetFocused () const
virtual WidgetgetLastWidgetPressed ()
virtual WidgetgetLastWidgetWithModalFocus ()
virtual WidgetgetLastWidgetWithModalMouseInputFocus ()
virtual WidgetgetLastWidgetWithMouse ()
virtual WidgetgetModalFocused () const
virtual WidgetgetModalMouseInputFocused () const
virtual bool isFocused (Widget const *widget) const
FocusHandler & operator= (FocusHandler &&)=delete
FocusHandler & operator= (FocusHandler const &)=delete
virtual void releaseModalFocus (Widget *widget)
virtual void releaseModalMouseInputFocus (Widget *widget)
virtual void remove (Widget *widget)
virtual void requestFocus (Widget *widget)
virtual void requestModalFocus (Widget *widget)
virtual void requestModalMouseInputFocus (Widget *widget)
virtual void setDraggedWidget (Widget *draggedWidget)
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
WidgetmModalFocusedWidget
WidgetmModalMouseInputFocusedWidget
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::requestModalFocus, Widget::requestModalMouseInputFocus, Widget::releaseModalFocus, Widget::releaseModalMouseInputFocus, Widget::setFocusable, Widget::isFocusable, FocusListener

Definition at line 32 of file focushandler.hpp.

Member Typedef Documentation

◆ WidgetIterator

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

Typedef.

Definition at line 309 of file focushandler.hpp.

◆ WidgetVector

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

Typedef.

Definition at line 304 of file focushandler.hpp.

Constructor & Destructor Documentation

◆ FocusHandler()

fcn::FocusHandler::FocusHandler ( )

Definition at line 19 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 225 of file focushandler.cpp.

References add(), and mWidgets.

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

◆ distributeFocusGainedEvent()

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

Distributes a focus gained event.

Parameters
focusEventthe event to distribute.

Definition at line 410 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 398 of file focushandler.cpp.

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

Referenced by distributeFocusLostEvent(), focusNext(), focusNone(), focusPrevious(), 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 116 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 267 of file focushandler.cpp.

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

Referenced by focusNone(), and requestModalFocus().

◆ 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 166 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 422 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 101 of file focushandler.cpp.

References getFocused(), and mFocusedWidget.

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

◆ 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 462 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 442 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 452 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 432 of file focushandler.cpp.

References getLastWidgetWithMouse(), and mLastWidgetWithMouse.

Referenced by getLastWidgetWithMouse().

◆ getModalFocused()

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

Gets the widget with modal focus.

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

Definition at line 106 of file focushandler.cpp.

References getModalFocused(), and mModalFocusedWidget.

Referenced by getModalFocused().

◆ getModalMouseInputFocused()

Widget * fcn::FocusHandler::getModalMouseInputFocused ( ) 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 111 of file focushandler.cpp.

References getModalMouseInputFocused(), and mModalMouseInputFocusedWidget.

Referenced by getModalMouseInputFocused().

◆ 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 220 of file focushandler.cpp.

References isFocused(), and mFocusedWidget.

Referenced by isFocused(), and remove().

◆ releaseModalFocus()

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

Releases modal focus if the widget has modal focus.

If the widget doesn't have modal focus no release will occur.

Parameters
widgetThe widget to release modal focus for.
See also
requestModalFocus, Widget::releaseModalFocus

Definition at line 87 of file focushandler.cpp.

References mModalFocusedWidget, and releaseModalFocus().

Referenced by releaseModalFocus().

◆ releaseModalMouseInputFocus()

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

Releases modal mouse input focus if the widget has modal mouse input focus.

If the widget doesn't have modal mouse input focus no release will occur.

Parameters
widgetthe widget to release modal mouse input focus for.
See also
requestModalMouseInputFocus, Widget::releaseModalMouseInputFocus

Definition at line 94 of file focushandler.cpp.

References mModalMouseInputFocusedWidget, and releaseModalMouseInputFocus().

Referenced by releaseModalMouseInputFocus().

◆ 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 230 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 31 of file focushandler.cpp.

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

Referenced by requestFocus().

◆ requestModalFocus()

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

Requests modal focus for a widget.

Focus will only be granted to a widget if it's focusable and if no other widget has modal focus.

Parameters
widgetThe widget to request modal focus for.
Exceptions
Exceptionwhen another widget already has modal focus.
See also
releaseModalFocus, Widget::requestModalFocus

Definition at line 65 of file focushandler.cpp.

References focusNone(), mFocusedWidget, mModalFocusedWidget, and requestModalFocus().

Referenced by requestModalFocus().

◆ requestModalMouseInputFocus()

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

Requests modal mouse input focus for a widget.

Focus will only be granted to a widget if it's focusable and if no other widget has modal mouse input focus.

Modal mouse input focus means no other widget then the widget with modal mouse input focus will receive mouse input. The widget with modal mouse input focus will also receive mouse input no matter what the mouse input is or where the mouse input occurs.

Parameters
widgetThe widget to focus for modal mouse input focus.
Exceptions
Exceptionwhen another widget already has modal mouse input focus.
See also
releaseModalMouseInputFocus, Widget::requestModalMouseInputFocus

Definition at line 78 of file focushandler.cpp.

References mModalMouseInputFocusedWidget, and requestModalMouseInputFocus().

Referenced by requestModalMouseInputFocus().

◆ 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 427 of file focushandler.cpp.

References mDraggedWidget, and setDraggedWidget().

Referenced by setDraggedWidget().

◆ 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 467 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 447 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 457 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 437 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 278 of file focushandler.cpp.

References distributeFocusGainedEvent(), distributeFocusLostEvent(), mFocusedWidget, mModalFocusedWidget, 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 338 of file focushandler.cpp.

References distributeFocusGainedEvent(), distributeFocusLostEvent(), mFocusedWidget, mModalFocusedWidget, 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 472 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 338 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 320 of file focushandler.hpp.

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

◆ mLastWidgetPressed

Widget* fcn::FocusHandler::mLastWidgetPressed
protected

Holds the last widget pressed.

Definition at line 358 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 348 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 353 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 343 of file focushandler.hpp.

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

◆ mModalFocusedWidget

Widget* fcn::FocusHandler::mModalFocusedWidget
protected

Holds the modal focused widget.

Nullptr if no widget has modal focused.

Definition at line 326 of file focushandler.hpp.

Referenced by getModalFocused(), releaseModalFocus(), requestModalFocus(), tabNext(), and tabPrevious().

◆ mModalMouseInputFocusedWidget

Widget* fcn::FocusHandler::mModalMouseInputFocusedWidget
protected

Holds the modal mouse input focused widget.

Nullptr if no widget is being dragged.

Definition at line 332 of file focushandler.hpp.

Referenced by getModalMouseInputFocused(), releaseModalMouseInputFocus(), and requestModalMouseInputFocus().

◆ mWidgets

WidgetVector fcn::FocusHandler::mWidgets
protected

Holds the widgets currently being handled by the focus handler.

Definition at line 315 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: