File: focusgroup.h

package info (click to toggle)
yapet 2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,920 kB
  • sloc: cpp: 32,397; sh: 5,032; makefile: 880; ansic: 36; sed: 16
file content (162 lines) | stat: -rw-r--r-- 4,100 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// -*- mode: c++ -*-
//
// This file is part of libyacurs.
// Copyright (C) 2013  Rafael Ostertag
//
// This program is free software: you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see
// <http://www.gnu.org/licenses/>.
//
//
// $Id$

#ifndef FOCUSGROUP_H
#define FOCUSGROUP_H 1

#include <list>

namespace YACURS {
class WidgetBase;

/**
 * @ingroup Focus
 *
 * Focus Group
 *
 * A Focus Group is comprised of Widgets with one Widget having the
 * focus, if the Group is active (or the Current Focus Group with
 * regards to the Focus Manager).
 *
 * Widgets should emit @c EVT_FOCUS_NEXT or @c EVT_FOCUS_PREVIOUS if
 * they voluntarely give up focus. The focus will then go to the next
 * (or previous) Widget in the Focus Group, by calling
 * WidgetBase::focus().
 *
 * The FocusManager is intended to be the only interface to
 * FocusGroups for other objects.
 *
 * @sa FocusManager
 */
class FocusGroup {
   private:
    /**
     * Indicates the state of the Focus Group.
     *
     * @c true means the Focus Group is active, @c false it is
     * inactive.
     */
    bool _active;

    /**
     * All the widgets belonging to the Focus Group.
     */
    std::list<WidgetBase*> _widgets;

    /**
     * The Widget having the focus in the group if active.
     */
    std::list<WidgetBase*>::iterator _focus;

   public:
    /**
     * Constructor.
     *
     * Upon construction, FocusGroup is not active. In order to
     * activate the FocusGroup, call FocusGroup::activate.
     */
    FocusGroup();

    FocusGroup(const FocusGroup& f);
    FocusGroup& operator=(const FocusGroup& f);
    FocusGroup(FocusGroup&& f);
    FocusGroup& operator=(FocusGroup&& f);
    ~FocusGroup();

    /**
     * Activate Focus Group
     *
     * When activating a FocusGroup, Widgets won't be focused by
     * calling focus(). An explicit call to FocusGroup::refocus()
     * is necessary. This is in order to prevent refresh issues
     * with overlapping Windows during a screen resize.
     */
    void activate();

    /**
     * Deactivate Focus Group.
     *
     * The Widget having the Focus will loose it, and any calls to
     * focus_next() or focus_previous() will be ignored.
     */
    void deactivate();

    /**
     * Query whether or not the Focus Group is active.
     *
     * @return @c true if the Focus Group is active, @c false
     * otherwise.
     */
    bool active() const;

    /**
     * Add Widget to Focus Group.
     *
     * Add Widget to Focus Group. The pointer to the Widget
     * has to be valid for the entire life time of the Focus
     * Group.
     *
     * @param w pointer to the Widget.
     */
    void add(WidgetBase* w);

    /**
     * Remove Widget from Focus Group.
     *
     * Remove Widget from Focus Group.
     *
     * @param w pointer to Widget to be removed.
     */
    void remove(WidgetBase* w);

    /**
     * Focus next Widget.
     *
     * Focus next Widget in the list and refreshes both, the
     * Widget having had the focus and the newly focused Widget.
     */
    void focus_next();

    /**
     * Focus previous Widget.
     *
     * Focus previous Widget in the list and refreshes both, the
     * Widget having had the focus and the newly focused Widget.
     */
    void focus_previous();

    /**
     * Re-focus the Widget having the focus.
     */
    void refocus() const;

    /**
     * Reset the focus.
     *
     * Resetting focus will result in first widget in the focus
     * list receiving focus.
     */
    void reset();
};
}  // namespace YACURS

#endif  // FOCUSGROUP_H