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 84 of file focushandler.h.

Member Typedef Documentation

◆ WidgetIterator

typedef WidgetVector::iterator FocusHandler::WidgetIterator
private

Typedef.

Definition at line 354 of file focushandler.h.

◆ WidgetVector

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

Typedef.

Definition at line 349 of file focushandler.h.

Constructor & Destructor Documentation

◆ FocusHandler()

FocusHandler::FocusHandler ( )

Definition at line 79 of file focushandler.cpp.

79  :
80  mWidgets(),
81  mFocusedWidget(nullptr),
82  mModalFocusedWidget(nullptr),
84  mDraggedWidget(nullptr),
85  mLastWidgetWithMouse(nullptr),
88  mLastWidgetPressed(nullptr),
89  mModalStack()
90 {
91 }
Widget * mLastWidgetWithMouse
Definition: focushandler.h:388
Widget * mLastWidgetWithModalFocus
Definition: focushandler.h:393
Widget * mFocusedWidget
Definition: focushandler.h:365
Widget * mModalMouseInputFocusedWidget
Definition: focushandler.h:377
Widget * mModalFocusedWidget
Definition: focushandler.h:371
Widget * mLastWidgetPressed
Definition: focushandler.h:403
std::list< Widget * > mModalStack
Definition: focushandler.h:408
Widget * mDraggedWidget
Definition: focushandler.h:383
Widget * mLastWidgetWithModalMouseInputFocus
Definition: focushandler.h:398
WidgetVector mWidgets
Definition: focushandler.h:360

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

539 {
540  mWidgets.push_back(widget);
541 }

References mWidgets.

Referenced by Widget::setFocusHandler().

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

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

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

Referenced by tabNext(), and tabPrevious().

◆ distributeFocusGainedEvent()

void FocusHandler::distributeFocusGainedEvent ( const Event focusEvent)
staticprivate

Distributes a focus gained event.

Parameters
focusEventthe event to distribute.

Definition at line 338 of file focushandler.cpp.

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

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

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

◆ distributeFocusLostEvent()

void FocusHandler::distributeFocusLostEvent ( const Event focusEvent)
staticprivate

Distributes a focus lost event.

Parameters
focusEventthe event to distribute.

Definition at line 555 of file focushandler.cpp.

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

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

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

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

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

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

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

544 {
545  if (mFocusedWidget != nullptr)
546  {
547  Widget *const focused = mFocusedWidget;
548  mFocusedWidget = nullptr;
549 
550  Event focusEvent(focused);
551  distributeFocusLostEvent(focusEvent);
552  }
553 }

References distributeFocusLostEvent(), and mFocusedWidget.

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

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

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

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

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

575 {
576  return mDraggedWidget;
577 }

References mDraggedWidget.

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

◆ getFocused()

Widget * FocusHandler::getFocused ( ) const

Gets the widget with focus.

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

Definition at line 413 of file focushandler.cpp.

414 {
415  return mFocusedWidget;
416 }

References mFocusedWidget.

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

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

615 {
616  return mLastWidgetPressed;
617 }

References mLastWidgetPressed.

Referenced by Gui::handleMouseReleased().

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

595 {
597 }

References mLastWidgetWithModalFocus.

Referenced by Gui::handleModalFocus().

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

605 {
607 }

References mLastWidgetWithModalMouseInputFocus.

Referenced by Gui::handleModalMouseInputFocus().

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

585 {
586  return mLastWidgetWithMouse;
587 }

References mLastWidgetWithMouse.

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

419 {
420  return mModalFocusedWidget;
421 }

References mModalFocusedWidget.

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

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

424 {
426 }

References mModalMouseInputFocusedWidget.

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

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

534 {
535  return mFocusedWidget == widget;
536 }

References mFocusedWidget.

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

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

110 {
111  mModalStack.remove(widget);
112 
113  if (mModalFocusedWidget == widget)
114  {
115  mModalFocusedWidget = nullptr;
116 
117  /* Check if there were any previously modal widgets that'd still like
118  * to regain their modal focus.
119  */
120  if (!mModalStack.empty())
121  {
123  mModalStack.pop_front();
124  }
125  }
126 }
void requestModalFocus(Widget *const widget)

References mModalFocusedWidget, mModalStack, and requestModalFocus().

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

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

408 {
409  if (mModalMouseInputFocusedWidget == widget)
411 }

References mModalMouseInputFocusedWidget.

Referenced by Widget::releaseModalMouseInputFocus().

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

129 {
130  releaseModalFocus(widget);
131 
132  if (isFocused(widget))
133  mFocusedWidget = nullptr;
134 
136  {
137  if ((*iter) == widget)
138  {
139  mWidgets.erase(iter);
140  break;
141  }
142  }
143 
144  if (mDraggedWidget == widget)
145  {
146  mDraggedWidget = nullptr;
147  return;
148  }
149 
150  if (mLastWidgetWithMouse == widget)
151  {
152  mLastWidgetWithMouse = nullptr;
153  return;
154  }
155 
156  if (mLastWidgetWithModalFocus == widget)
157  {
158  mLastWidgetWithModalFocus = nullptr;
159  return;
160  }
161 
163  {
165  return;
166  }
167 
168  if (mLastWidgetPressed == widget)
169  {
170  mLastWidgetPressed = nullptr;
171  return;
172  }
173 }
WidgetVector::iterator WidgetIterator
Definition: focushandler.h:354
void releaseModalFocus(Widget *const widget)
bool isFocused(const Widget *const widget) const
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

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

Referenced by Widget::setFocusHandler().

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

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

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

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

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

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

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

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

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

397 {
398  if ((mModalMouseInputFocusedWidget != nullptr)
399  && mModalMouseInputFocusedWidget != widget)
400  {
401  return;
402  }
403 
405 }

References mModalMouseInputFocusedWidget.

Referenced by Widget::requestModalMouseInputFocus().

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

580 {
581  mDraggedWidget = draggedWidget;
582 }

References mDraggedWidget.

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

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

620 {
621  mLastWidgetPressed = lastWidgetPressed;
622 }

References mLastWidgetPressed.

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

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

600 {
601  mLastWidgetWithModalFocus = widget;
602 }

References mLastWidgetWithModalFocus.

Referenced by Gui::handleModalFocus().

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

610 {
612 }

References mLastWidgetWithModalMouseInputFocus.

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

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

590 {
591  mLastWidgetWithMouse = lastWidgetWithMouse;
592 }

References mLastWidgetWithMouse.

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

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

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

Referenced by Gui::handleKeyInput().

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

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

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

Referenced by Gui::handleKeyInput().

Field Documentation

◆ mDraggedWidget

Widget* FocusHandler::mDraggedWidget
private

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

Definition at line 383 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 365 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 403 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 393 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 398 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 388 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 371 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 377 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 408 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 360 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: