ManaPlus
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
FocusHandler Class Reference

#include <focushandler.h>

Public Member Functions

 FocusHandler ()
 
void requestFocus (const Widget *const widget)
 
void requestModalFocus (Widget *const widget)
 
void requestModalMouseInputFocus (Widget *const widget)
 
void releaseModalFocus (Widget *const widget)
 
void releaseModalMouseInputFocus (const Widget *const widget)
 
bool isFocused (const Widget *const widget) const
 
WidgetgetFocused () const
 
WidgetgetModalFocused () const
 
WidgetgetModalMouseInputFocused () const
 
void focusNext ()
 
void focusPrevious ()
 
void add (Widget *const widget)
 
void remove (Widget *const widget)
 
void focusNone ()
 
void tabNext ()
 
void tabPrevious ()
 
WidgetgetDraggedWidget () const
 
void setDraggedWidget (Widget *const draggedWidget)
 
WidgetgetLastWidgetWithMouse () const
 
void setLastWidgetWithMouse (Widget *const lastWidgetWithMouse)
 
WidgetgetLastWidgetWithModalFocus () const
 
void setLastWidgetWithModalFocus (Widget *const widget)
 
WidgetgetLastWidgetWithModalMouseInputFocus () const
 
void setLastWidgetWithModalMouseInputFocus (Widget *const widget)
 
WidgetgetLastWidgetPressed () const
 
void setLastWidgetPressed (Widget *const lastWidgetPressed)
 

Private Types

typedef std::vector< Widget * > WidgetVector
 
typedef WidgetVector::iterator WidgetIterator
 

Private Member Functions

void checkForWindow () const
 

Static Private Member Functions

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

Private Attributes

WidgetVector mWidgets
 
WidgetmFocusedWidget
 
WidgetmModalFocusedWidget
 
WidgetmModalMouseInputFocusedWidget
 
WidgetmDraggedWidget
 
WidgetmLastWidgetWithMouse
 
WidgetmLastWidgetWithModalFocus
 
WidgetmLastWidgetWithModalMouseInputFocus
 
WidgetmLastWidgetPressed
 
std::list< Widget * > mModalStack
 

Detailed Description

The focus handler. This focus handler does exactly the same as the Guichan focus handler, but keeps a stack of modal widgets to be able to handle multiple modal focus requests.

Definition at line 83 of file focushandler.h.

Member Typedef Documentation

◆ WidgetIterator

typedef WidgetVector::iterator FocusHandler::WidgetIterator
private

Typedef.

Definition at line 353 of file focushandler.h.

◆ WidgetVector

typedef std::vector<Widget*> FocusHandler::WidgetVector
private

Typedef.

Definition at line 348 of file focushandler.h.

Constructor & Destructor Documentation

◆ FocusHandler()

FocusHandler::FocusHandler ( )

Definition at line 78 of file focushandler.cpp.

78  :
79  mWidgets(),
80  mFocusedWidget(nullptr),
81  mModalFocusedWidget(nullptr),
83  mDraggedWidget(nullptr),
84  mLastWidgetWithMouse(nullptr),
87  mLastWidgetPressed(nullptr),
88  mModalStack()
89 {
90 }
Widget * mLastWidgetWithModalFocus
Definition: focushandler.h:392
Widget * mFocusedWidget
Definition: focushandler.h:364
Widget * mModalMouseInputFocusedWidget
Definition: focushandler.h:376
Widget * mModalFocusedWidget
Definition: focushandler.h:370
Widget * mDraggedWidget
Definition: focushandler.h:382
Widget * mLastWidgetWithModalMouseInputFocus
Definition: focushandler.h:397
std::list< Widget * > mModalStack
Definition: focushandler.h:407
WidgetVector mWidgets
Definition: focushandler.h:359
Widget * mLastWidgetPressed
Definition: focushandler.h:402
Widget * mLastWidgetWithMouse
Definition: focushandler.h:387

Member Function Documentation

◆ add()

void FocusHandler::add ( Widget *const  widget)

Adds a widget to by handles by the focus handler.

Parameters
widgetThe widget to add.
See also
remove

Definition at line 537 of file focushandler.cpp.

References mWidgets.

Referenced by Widget::setFocusHandler().

538 {
539  mWidgets.push_back(widget);
540 }
WidgetVector mWidgets
Definition: focushandler.h:359

◆ checkForWindow()

void FocusHandler::checkForWindow ( ) const
private

Checks to see if the widget tabbed to is in a window, and if it is, it requests the window be moved to the top.

Definition at line 316 of file focushandler.cpp.

References Widget::getParent(), mFocusedWidget, and Widget::requestMoveToTop().

Referenced by tabNext(), and tabPrevious().

317 {
318  if (mFocusedWidget != nullptr)
319  {
320  Widget *widget = mFocusedWidget->getParent();
321 
322  while (widget != nullptr)
323  {
324  Window *const window = dynamic_cast<Window*>(widget);
325 
326  if (window != nullptr)
327  {
328  window->requestMoveToTop();
329  break;
330  }
331 
332  widget = widget->getParent();
333  }
334  }
335 }
Widget * mFocusedWidget
Definition: focushandler.h:364
virtual void requestMoveToTop()
Definition: widget.cpp:212
Definition: window.h:98
Widget * getParent() const
Definition: widget.h:201
Definition: widget.h:97

◆ distributeFocusGainedEvent()

void FocusHandler::distributeFocusGainedEvent ( const Event focusEvent)
staticprivate

Distributes a focus gained event.

Parameters
focusEventthe event to distribute.

Definition at line 337 of file focushandler.cpp.

References Gui::distributeGlobalFocusGainedEvent(), Widget::getFocusListeners(), Event::getSource(), and gui.

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

338 {
339  if (gui != nullptr)
341 
342  const Widget *const sourceWidget = focusEvent.getSource();
343 
344  if (sourceWidget == nullptr)
345  return;
346  std::list<FocusListener*> focusListeners
347  = sourceWidget->getFocusListeners();
348 
349  // Send the event to all focus listeners of the widget.
350  for (std::list<FocusListener*>::const_iterator
351  it = focusListeners.begin();
352  it != focusListeners.end();
353  ++ it)
354  {
355  (*it)->focusGained(focusEvent);
356  }
357 }
Gui * gui
Definition: gui.cpp:110
void distributeGlobalFocusGainedEvent(const Event &focusEvent)
Definition: gui.cpp:1134
Widget * getSource() const
Definition: event.h:103
Definition: widget.h:97
const std::list< FocusListener * > & getFocusListeners() const A_CONST
Definition: widget.cpp:445

◆ distributeFocusLostEvent()

void FocusHandler::distributeFocusLostEvent ( const Event focusEvent)
staticprivate

Distributes a focus lost event.

Parameters
focusEventthe event to distribute.

Definition at line 554 of file focushandler.cpp.

References Widget::getFocusListeners(), and Event::getSource().

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

555 {
556  const Widget *const sourceWidget = focusEvent.getSource();
557  if (sourceWidget == nullptr)
558  return;
559 
560  std::list<FocusListener*> focusListeners
561  = sourceWidget->getFocusListeners();
562 
563  // Send the event to all focus listeners of the widget.
564  for (std::list<FocusListener*>::const_iterator
565  it = focusListeners.begin();
566  it != focusListeners.end();
567  ++ it)
568  {
569  (*it)->focusLost(focusEvent);
570  }
571 }
Widget * getSource() const
Definition: event.h:103
Definition: widget.h:97
const std::list< FocusListener * > & getFocusListeners() const A_CONST
Definition: widget.cpp:445

◆ focusNext()

void FocusHandler::focusNext ( )

Focuses the next widget added to a conainer. 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 427 of file focushandler.cpp.

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

428 {
429  int i;
430  int focusedWidget = -1;
431  const int sz = CAST_S32(mWidgets.size());
432  for (i = 0; i < sz; ++i)
433  {
434  if (mWidgets[i] == mFocusedWidget)
435  focusedWidget = i;
436  }
437  const int focused = focusedWidget;
438 
439  // i is a counter that ensures that the following loop
440  // won't get stuck in an infinite loop
441  i = sz;
442  do
443  {
444  ++ focusedWidget;
445 
446  if (i == 0)
447  {
448  focusedWidget = -1;
449  break;
450  }
451 
452  -- i;
453 
454  if (focusedWidget >= sz)
455  focusedWidget = 0;
456 
457  if (focusedWidget == focused)
458  return;
459  }
460  while (!mWidgets.at(focusedWidget)->isFocusable());
461 
462  if (focusedWidget >= 0)
463  {
464  mFocusedWidget = mWidgets.at(focusedWidget);
465 
466  Event focusEvent(mFocusedWidget);
467  distributeFocusGainedEvent(focusEvent);
468  }
469 
470  if (focused >= 0)
471  {
472  Event focusEvent(mWidgets.at(focused));
473  distributeFocusLostEvent(focusEvent);
474  }
475 }
Widget * mFocusedWidget
Definition: focushandler.h:364
static void distributeFocusLostEvent(const Event &focusEvent)
#define CAST_S32
Definition: cast.h:29
Definition: event.h:77
WidgetVector mWidgets
Definition: focushandler.h:359
static void distributeFocusGainedEvent(const Event &focusEvent)

◆ focusNone()

void FocusHandler::focusNone ( )

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

Definition at line 542 of file focushandler.cpp.

References distributeFocusLostEvent(), and mFocusedWidget.

Referenced by ChatWindow::action(), Gui::handleKeyInput(), requestModalFocus(), Widget::setFocusable(), Widget::setVisible(), and Window::widgetHidden().

543 {
544  if (mFocusedWidget != nullptr)
545  {
546  Widget *const focused = mFocusedWidget;
547  mFocusedWidget = nullptr;
548 
549  Event focusEvent(focused);
550  distributeFocusLostEvent(focusEvent);
551  }
552 }
Widget * mFocusedWidget
Definition: focushandler.h:364
static void distributeFocusLostEvent(const Event &focusEvent)
Definition: widget.h:97
Definition: event.h:77

◆ focusPrevious()

void FocusHandler::focusPrevious ( )

Focuses the previous widget added to a contaienr. 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 477 of file focushandler.cpp.

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

478 {
479  if (mWidgets.empty())
480  {
481  mFocusedWidget = nullptr;
482  return;
483  }
484 
485  int i;
486  int focusedWidget = -1;
487  const int sz = CAST_S32(mWidgets.size());
488  for (i = 0; i < sz; ++ i)
489  {
490  if (mWidgets[i] == mFocusedWidget)
491  focusedWidget = i;
492  }
493  const int focused = focusedWidget;
494 
495  // i is a counter that ensures that the following loop
496  // won't get stuck in an infinite loop
497  i = sz;
498  do
499  {
500  -- focusedWidget;
501 
502  if (i == 0)
503  {
504  focusedWidget = -1;
505  break;
506  }
507 
508  -- i;
509 
510  if (focusedWidget <= 0)
511  focusedWidget = sz - 1;
512 
513  if (focusedWidget == focused)
514  return;
515  }
516  while (!mWidgets.at(focusedWidget)->isFocusable());
517 
518  if (focusedWidget >= 0)
519  {
520  mFocusedWidget = mWidgets.at(focusedWidget);
521  Event focusEvent(mFocusedWidget);
522  distributeFocusGainedEvent(focusEvent);
523  }
524 
525  if (focused >= 0)
526  {
527  Event focusEvent(mWidgets.at(focused));
528  distributeFocusLostEvent(focusEvent);
529  }
530 }
Widget * mFocusedWidget
Definition: focushandler.h:364
static void distributeFocusLostEvent(const Event &focusEvent)
#define CAST_S32
Definition: cast.h:29
Definition: event.h:77
WidgetVector mWidgets
Definition: focushandler.h:359
static void distributeFocusGainedEvent(const Event &focusEvent)

◆ getDraggedWidget()

Widget * FocusHandler::getDraggedWidget ( ) const

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

References mDraggedWidget.

Referenced by Gui::handleMouseMoved(), Gui::handleMousePressed(), Gui::handleMouseReleased(), Gui::handleMouseWheelMovedDown(), Gui::handleMouseWheelMovedUp(), and Gui::removeDragged().

574 {
575  return mDraggedWidget;
576 }
Widget * mDraggedWidget
Definition: focushandler.h:382

◆ getFocused()

Widget * FocusHandler::getFocused ( ) const

Gets the widget with focus.

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

Definition at line 412 of file focushandler.cpp.

References mFocusedWidget.

Referenced by Gui::getKeyEventSource(), and Gui::handleKeyInput().

413 {
414  return mFocusedWidget;
415 }
Widget * mFocusedWidget
Definition: focushandler.h:364

◆ getLastWidgetPressed()

Widget * FocusHandler::getLastWidgetPressed ( ) const

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

References mLastWidgetPressed.

Referenced by Gui::handleMouseReleased().

614 {
615  return mLastWidgetPressed;
616 }
Widget * mLastWidgetPressed
Definition: focushandler.h:402

◆ getLastWidgetWithModalFocus()

Widget * FocusHandler::getLastWidgetWithModalFocus ( ) const

Gets the last widget with modal focus.

Returns
The last widget with modal focus.
See also
setLastWidgetWithModalFocus

Definition at line 593 of file focushandler.cpp.

References mLastWidgetWithModalFocus.

Referenced by Gui::handleModalFocus().

594 {
596 }
Widget * mLastWidgetWithModalFocus
Definition: focushandler.h:392

◆ getLastWidgetWithModalMouseInputFocus()

Widget * FocusHandler::getLastWidgetWithModalMouseInputFocus ( ) const

Gets the last widget with modal mouse input focus.

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

Definition at line 603 of file focushandler.cpp.

References mLastWidgetWithModalMouseInputFocus.

Referenced by Gui::handleModalMouseInputFocus().

604 {
606 }
Widget * mLastWidgetWithModalMouseInputFocus
Definition: focushandler.h:397

◆ getLastWidgetWithMouse()

Widget * FocusHandler::getLastWidgetWithMouse ( ) const

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

References mLastWidgetWithMouse.

584 {
585  return mLastWidgetWithMouse;
586 }
Widget * mLastWidgetWithMouse
Definition: focushandler.h:387

◆ getModalFocused()

Widget * FocusHandler::getModalFocused ( ) const

Gets the widget with modal focus.

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

Definition at line 417 of file focushandler.cpp.

References mModalFocusedWidget.

Referenced by Gui::distributeKeyEvent(), Gui::distributeMouseEvent(), Gui::handleModalFocus(), Gui::handleMousePressed(), Widget::isModalFocused(), and InputManager::updateConditionMask().

418 {
419  return mModalFocusedWidget;
420 }
Widget * mModalFocusedWidget
Definition: focushandler.h:370

◆ getModalMouseInputFocused()

Widget * FocusHandler::getModalMouseInputFocused ( ) const

Gets the widget with modal mouse input focus.

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

Definition at line 422 of file focushandler.cpp.

References mModalMouseInputFocusedWidget.

Referenced by Gui::distributeKeyEvent(), Gui::distributeMouseEvent(), Gui::getMouseEventSource(), Gui::handleModalFocusGained(), Gui::handleModalMouseInputFocus(), Gui::handleMouseMoved(), and Widget::isModalMouseInputFocused().

423 {
425 }
Widget * mModalMouseInputFocusedWidget
Definition: focushandler.h:376

◆ isFocused()

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

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

References mFocusedWidget.

Referenced by Widget::isFocused(), remove(), and Window::widgetHidden().

533 {
534  return mFocusedWidget == widget;
535 }
Widget * mFocusedWidget
Definition: focushandler.h:364

◆ releaseModalFocus()

void FocusHandler::releaseModalFocus ( Widget *const  widget)

Releases modal focus if the widget has modal focus. If the widget doesn't have modal focus no relase will occur.

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

Definition at line 108 of file focushandler.cpp.

References mModalFocusedWidget, mModalStack, and requestModalFocus().

Referenced by Widget::releaseModalFocus(), and remove().

109 {
110  mModalStack.remove(widget);
111 
112  if (mModalFocusedWidget == widget)
113  {
114  mModalFocusedWidget = nullptr;
115 
116  /* Check if there were any previously modal widgets that'd still like
117  * to regain their modal focus.
118  */
119  if (!mModalStack.empty())
120  {
122  mModalStack.pop_front();
123  }
124  }
125 }
Widget * mModalFocusedWidget
Definition: focushandler.h:370
void requestModalFocus(Widget *const widget)
std::list< Widget * > mModalStack
Definition: focushandler.h:407

◆ releaseModalMouseInputFocus()

void FocusHandler::releaseModalMouseInputFocus ( const Widget *const  widget)

Releases modal mouse input focus if the widget has modal mouse input focus. If the widget doesn't have modal mouse input focus no relase will occur.

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

Definition at line 406 of file focushandler.cpp.

References mModalMouseInputFocusedWidget.

Referenced by Widget::releaseModalMouseInputFocus().

407 {
408  if (mModalMouseInputFocusedWidget == widget)
410 }
Widget * mModalMouseInputFocusedWidget
Definition: focushandler.h:376

◆ remove()

void FocusHandler::remove ( Widget *const  widget)

Removes a widget from the focus handler.

Parameters
widgetThe widget to remove.
See also
add

Definition at line 127 of file focushandler.cpp.

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

Referenced by Widget::setFocusHandler().

128 {
129  releaseModalFocus(widget);
130 
131  if (isFocused(widget))
132  mFocusedWidget = nullptr;
133 
135  {
136  if ((*iter) == widget)
137  {
138  mWidgets.erase(iter);
139  break;
140  }
141  }
142 
143  if (mDraggedWidget == widget)
144  {
145  mDraggedWidget = nullptr;
146  return;
147  }
148 
149  if (mLastWidgetWithMouse == widget)
150  {
151  mLastWidgetWithMouse = nullptr;
152  return;
153  }
154 
155  if (mLastWidgetWithModalFocus == widget)
156  {
157  mLastWidgetWithModalFocus = nullptr;
158  return;
159  }
160 
162  {
164  return;
165  }
166 
167  if (mLastWidgetPressed == widget)
168  {
169  mLastWidgetPressed = nullptr;
170  return;
171  }
172 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Widget * mLastWidgetWithModalFocus
Definition: focushandler.h:392
Widget * mFocusedWidget
Definition: focushandler.h:364
bool isFocused(const Widget *const widget) const
Widget * mDraggedWidget
Definition: focushandler.h:382
Widget * mLastWidgetWithModalMouseInputFocus
Definition: focushandler.h:397
WidgetVector::iterator WidgetIterator
Definition: focushandler.h:353
WidgetVector mWidgets
Definition: focushandler.h:359
Widget * mLastWidgetPressed
Definition: focushandler.h:402
void releaseModalFocus(Widget *const widget)
Widget * mLastWidgetWithMouse
Definition: focushandler.h:387

◆ requestFocus()

void FocusHandler::requestFocus ( const Widget *const  widget)

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

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

Referenced by ListBox::refocus(), and Widget::requestFocus().

360 {
361  if ((widget == nullptr) || widget == mFocusedWidget)
362  return;
363 
364  int toBeFocusedIndex = -1;
365  for (unsigned int i = 0, fsz = CAST_U32(
366  mWidgets.size()); i < fsz; ++i)
367  {
368  if (mWidgets[i] == widget)
369  {
370  toBeFocusedIndex = i;
371  break;
372  }
373  }
374 
375  if (toBeFocusedIndex < 0)
376  return;
377 
378  Widget *const oldFocused = mFocusedWidget;
379 
380  if (oldFocused != widget)
381  {
382  mFocusedWidget = mWidgets.at(toBeFocusedIndex);
383 
384  if (oldFocused != nullptr)
385  {
386  Event focusEvent(oldFocused);
387  distributeFocusLostEvent(focusEvent);
388  }
389 
390  Event focusEvent(mWidgets.at(toBeFocusedIndex));
391  distributeFocusGainedEvent(focusEvent);
392  }
393 }
#define CAST_U32
Definition: cast.h:30
Widget * mFocusedWidget
Definition: focushandler.h:364
static void distributeFocusLostEvent(const Event &focusEvent)
Definition: widget.h:97
Definition: event.h:77
WidgetVector mWidgets
Definition: focushandler.h:359
static void distributeFocusGainedEvent(const Event &focusEvent)

◆ requestModalFocus()

void FocusHandler::requestModalFocus ( Widget *const  widget)

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

References focusNone(), Widget::isModalFocused(), mFocusedWidget, mModalFocusedWidget, and mModalStack.

Referenced by releaseModalFocus(), and Widget::requestModalFocus().

93 {
94  /* If there is another widget with modal focus, remove its modal focus
95  * and put it on the modal widget stack.
96  */
97  if ((mModalFocusedWidget != nullptr) && mModalFocusedWidget != widget)
98  {
99  mModalStack.push_front(mModalFocusedWidget);
100  mModalFocusedWidget = nullptr;
101  }
102 
103  mModalFocusedWidget = widget;
104  if ((mFocusedWidget != nullptr) && !mFocusedWidget->isModalFocused())
105  focusNone();
106 }
Widget * mFocusedWidget
Definition: focushandler.h:364
Widget * mModalFocusedWidget
Definition: focushandler.h:370
virtual bool isModalFocused() const
Definition: widget.cpp:407
std::list< Widget * > mModalStack
Definition: focushandler.h:407

◆ requestModalMouseInputFocus()

void FocusHandler::requestModalMouseInputFocus ( Widget *const  widget)

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

References mModalMouseInputFocusedWidget.

Referenced by Widget::requestModalMouseInputFocus().

396 {
397  if ((mModalMouseInputFocusedWidget != nullptr)
398  && mModalMouseInputFocusedWidget != widget)
399  {
400  return;
401  }
402 
404 }
Widget * mModalMouseInputFocusedWidget
Definition: focushandler.h:376

◆ setDraggedWidget()

void FocusHandler::setDraggedWidget ( Widget *const  draggedWidget)

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

References mDraggedWidget.

Referenced by Gui::handleMousePressed(), Gui::handleMouseReleased(), and Gui::removeDragged().

579 {
580  mDraggedWidget = draggedWidget;
581 }
Widget * mDraggedWidget
Definition: focushandler.h:382

◆ setLastWidgetPressed()

void FocusHandler::setLastWidgetPressed ( Widget *const  lastWidgetPressed)

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

References mLastWidgetPressed.

Referenced by Gui::handleMousePressed(), and Gui::handleMouseReleased().

619 {
620  mLastWidgetPressed = lastWidgetPressed;
621 }
Widget * mLastWidgetPressed
Definition: focushandler.h:402

◆ setLastWidgetWithModalFocus()

void FocusHandler::setLastWidgetWithModalFocus ( Widget *const  widget)

Sets the last widget with modal focus.

Parameters
widgetThe last widget with modal focus.
See also
getLastWidgetWithModalFocus

Definition at line 598 of file focushandler.cpp.

References mLastWidgetWithModalFocus.

Referenced by Gui::handleModalFocus().

599 {
600  mLastWidgetWithModalFocus = widget;
601 }
Widget * mLastWidgetWithModalFocus
Definition: focushandler.h:392

◆ setLastWidgetWithModalMouseInputFocus()

void FocusHandler::setLastWidgetWithModalMouseInputFocus ( Widget *const  widget)

Sets the last widget with modal mouse input focus.

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

Definition at line 608 of file focushandler.cpp.

References mLastWidgetWithModalMouseInputFocus.

Referenced by Gui::handleModalFocusGained(), and Gui::handleModalMouseInputFocus().

609 {
611 }
Widget * mLastWidgetWithModalMouseInputFocus
Definition: focushandler.h:397

◆ setLastWidgetWithMouse()

void FocusHandler::setLastWidgetWithMouse ( Widget *const  lastWidgetWithMouse)

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

References mLastWidgetWithMouse.

589 {
590  mLastWidgetWithMouse = lastWidgetWithMouse;
591 }
Widget * mLastWidgetWithMouse
Definition: focushandler.h:387

◆ tabNext()

void FocusHandler::tabNext ( )

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

See also
tabPrevious

Definition at line 174 of file focushandler.cpp.

References CAST_S32, checkForWindow(), distributeFocusGainedEvent(), distributeFocusLostEvent(), Widget::isFocusable(), Widget::isModalFocused(), Widget::isTabInEnabled(), Widget::isTabOutEnabled(), mFocusedWidget, mModalFocusedWidget, and mWidgets.

Referenced by Gui::handleKeyInput().

175 {
176  if (mFocusedWidget != nullptr)
177  {
179  return;
180  }
181 
182  if (mWidgets.empty())
183  {
184  mFocusedWidget = nullptr;
185  return;
186  }
187 
188  int i;
189  int focusedWidget = -1;
190  const int sz = CAST_S32(mWidgets.size());
191  for (i = 0; i < sz; ++ i)
192  {
193  if (mWidgets[i] == mFocusedWidget)
194  focusedWidget = i;
195  }
196  const int focused = focusedWidget;
197  bool done = false;
198 
199  // i is a counter that ensures that the following loop
200  // won't get stuck in an infinite loop
201  i = sz;
202  do
203  {
204  ++ focusedWidget;
205 
206  if (i == 0)
207  {
208  focusedWidget = -1;
209  break;
210  }
211 
212  -- i;
213 
214  if (focusedWidget >= sz)
215  focusedWidget = 0;
216 
217  if (focusedWidget == focused)
218  return;
219 
220  const Widget *const widget = mWidgets.at(focusedWidget);
221  if (widget->isFocusable() && widget->isTabInEnabled() &&
222  ((mModalFocusedWidget == nullptr) || widget->isModalFocused()))
223  {
224  done = true;
225  }
226  }
227  while (!done);
228 
229  if (focusedWidget >= 0)
230  {
231  mFocusedWidget = mWidgets.at(focusedWidget);
232  Event focusEvent(mFocusedWidget);
233  distributeFocusGainedEvent(focusEvent);
234  }
235 
236  if (focused >= 0)
237  {
238  Event focusEvent(mWidgets.at(focused));
239  distributeFocusLostEvent(focusEvent);
240  }
241 
242  checkForWindow();
243 }
Widget * mFocusedWidget
Definition: focushandler.h:364
static void distributeFocusLostEvent(const Event &focusEvent)
bool isTabInEnabled() const
Definition: widget.h:687
bool isTabOutEnabled() const
Definition: widget.h:711
Widget * mModalFocusedWidget
Definition: focushandler.h:370
virtual bool isModalFocused() const
Definition: widget.cpp:407
#define CAST_S32
Definition: cast.h:29
void checkForWindow() const
Definition: widget.h:97
Definition: event.h:77
bool isFocusable() const
Definition: widget.cpp:198
WidgetVector mWidgets
Definition: focushandler.h:359
static void distributeFocusGainedEvent(const Event &focusEvent)

◆ tabPrevious()

void FocusHandler::tabPrevious ( )

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

See also
tabNext

Definition at line 245 of file focushandler.cpp.

References CAST_S32, checkForWindow(), distributeFocusGainedEvent(), distributeFocusLostEvent(), Widget::isFocusable(), Widget::isModalFocused(), Widget::isTabInEnabled(), Widget::isTabOutEnabled(), mFocusedWidget, mModalFocusedWidget, and mWidgets.

Referenced by Gui::handleKeyInput().

246 {
247  if (mFocusedWidget != nullptr)
248  {
250  return;
251  }
252 
253  if (mWidgets.empty())
254  {
255  mFocusedWidget = nullptr;
256  return;
257  }
258 
259  int i;
260  int focusedWidget = -1;
261  const int sz = CAST_S32(mWidgets.size());
262  for (i = 0; i < sz; ++ i)
263  {
264  if (mWidgets[i] == mFocusedWidget)
265  focusedWidget = i;
266  }
267  const int focused = focusedWidget;
268  bool done = false;
269 
270  // i is a counter that ensures that the following loop
271  // won't get stuck in an infinite loop
272  i = sz;
273  do
274  {
275  -- focusedWidget;
276 
277  if (i == 0)
278  {
279  focusedWidget = -1;
280  break;
281  }
282 
283  -- i;
284 
285  if (focusedWidget <= 0)
286  focusedWidget = sz - 1;
287 
288  if (focusedWidget == focused)
289  return;
290 
291  const Widget *const widget = mWidgets.at(focusedWidget);
292  if (widget->isFocusable() && widget->isTabInEnabled() &&
293  ((mModalFocusedWidget == nullptr) || widget->isModalFocused()))
294  {
295  done = true;
296  }
297  }
298  while (!done);
299 
300  if (focusedWidget >= 0)
301  {
302  mFocusedWidget = mWidgets.at(focusedWidget);
303  Event focusEvent(mFocusedWidget);
304  distributeFocusGainedEvent(focusEvent);
305  }
306 
307  if (focused >= 0)
308  {
309  Event focusEvent(mWidgets.at(focused));
310  distributeFocusLostEvent(focusEvent);
311  }
312 
313  checkForWindow();
314 }
Widget * mFocusedWidget
Definition: focushandler.h:364
static void distributeFocusLostEvent(const Event &focusEvent)
bool isTabInEnabled() const
Definition: widget.h:687
bool isTabOutEnabled() const
Definition: widget.h:711
Widget * mModalFocusedWidget
Definition: focushandler.h:370
virtual bool isModalFocused() const
Definition: widget.cpp:407
#define CAST_S32
Definition: cast.h:29
void checkForWindow() const
Definition: widget.h:97
Definition: event.h:77
bool isFocusable() const
Definition: widget.cpp:198
WidgetVector mWidgets
Definition: focushandler.h:359
static void distributeFocusGainedEvent(const Event &focusEvent)

Field Documentation

◆ mDraggedWidget

Widget* FocusHandler::mDraggedWidget
private

Holds the dragged widget. NULL if no widget is being dragged.

Definition at line 382 of file focushandler.h.

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

◆ mFocusedWidget

Widget* FocusHandler::mFocusedWidget
private

Holds the focused widget. NULL if no widget has focus.

Definition at line 364 of file focushandler.h.

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

◆ mLastWidgetPressed

Widget* FocusHandler::mLastWidgetPressed
private

Holds the last widget pressed.

Definition at line 402 of file focushandler.h.

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

◆ mLastWidgetWithModalFocus

Widget* FocusHandler::mLastWidgetWithModalFocus
private

Holds the last widget with modal focus.

Definition at line 392 of file focushandler.h.

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

◆ mLastWidgetWithModalMouseInputFocus

Widget* FocusHandler::mLastWidgetWithModalMouseInputFocus
private

Holds the last widget with modal mouse input focus.

Definition at line 397 of file focushandler.h.

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

◆ mLastWidgetWithMouse

Widget* FocusHandler::mLastWidgetWithMouse
private

Holds the last widget with the mouse.

Definition at line 387 of file focushandler.h.

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

◆ mModalFocusedWidget

Widget* FocusHandler::mModalFocusedWidget
private

Holds the modal focused widget. NULL if no widget has modal focused.

Definition at line 370 of file focushandler.h.

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

◆ mModalMouseInputFocusedWidget

Widget* FocusHandler::mModalMouseInputFocusedWidget
private

Holds the modal mouse input focused widget. NULL if no widget is being dragged.

Definition at line 376 of file focushandler.h.

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

◆ mModalStack

std::list<Widget*> FocusHandler::mModalStack
private

Stack of widgets that have requested modal forcus.

Definition at line 407 of file focushandler.h.

Referenced by releaseModalFocus(), and requestModalFocus().

◆ mWidgets

WidgetVector FocusHandler::mWidgets
private

Holds the widgets currently being handled by the focus handler.

Definition at line 359 of file focushandler.h.

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


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