Mana
Loading...
Searching...
No Matches
focushandler.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "focushandler.h"
23
24#include "gui/widgets/window.h"
25
26void FocusHandler::requestModalFocus(gcn::Widget *widget)
27{
28 /* If there is another widget with modal focus, remove its modal focus
29 * and put it on the modal widget stack.
30 */
31 if (mModalFocusedWidget && mModalFocusedWidget != widget)
32 {
33 mModalStack.push_front(mModalFocusedWidget);
34 mModalFocusedWidget = nullptr;
35 }
36
37 gcn::FocusHandler::requestModalFocus(widget);
38}
39
40void FocusHandler::releaseModalFocus(gcn::Widget *widget)
41{
42 mModalStack.remove(widget);
43
44 if (mModalFocusedWidget == widget)
45 {
46 gcn::FocusHandler::releaseModalFocus(widget);
47
48 /* Check if there were any previously modal widgets that'd still like
49 * to regain their modal focus.
50 */
51 if (mModalStack.size() > 0)
52 {
53 gcn::FocusHandler::requestModalFocus(mModalStack.front());
54 mModalStack.pop_front();
55 }
56 }
57}
58
59void FocusHandler::remove(gcn::Widget *widget)
60{
61 releaseModalFocus(widget);
62
63 gcn::FocusHandler::remove(widget);
64}
65
67{
68 gcn::FocusHandler::tabNext();
69
71}
72
74{
75 gcn::FocusHandler::tabPrevious();
76
78}
79
81{
82 if (mFocusedWidget)
83 {
84 gcn::Widget *widget = mFocusedWidget->getParent();
85
86 while (widget)
87 {
88 auto *window = dynamic_cast<Window*>(widget);
89
90 if (window)
91 {
92 window->requestMoveToTop();
93 break;
94 }
95
96 widget = widget->getParent();
97 }
98 }
99}
void checkForWindow()
Checks to see if the widget tabbed to is in a window, and if it is, it requests the window be moved t...
void requestModalFocus(gcn::Widget *widget) override
Sets modal focus to a widget.
void remove(gcn::Widget *widget) override
Removes a widget from the focus handler.
void releaseModalFocus(gcn::Widget *widget) override
Releases modal focus of a widget.
std::list< gcn::Widget * > mModalStack
Stack of widgets that have requested modal forcus.
void tabPrevious() override
void tabNext() override
Overloaded to allow windows to move to the top when one of their widgets is tabbed to when tabbing th...
A window.
Definition window.h:59