GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabbedarea.h Lines: 6 7 85.7 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2008-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
/*      _______   __   __   __   ______   __   __   _______   __   __
24
 *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
25
 *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
26
 *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
27
 *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
28
 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
29
 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
30
 *
31
 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
32
 *
33
 *
34
 * Per Larsson a.k.a finalman
35
 * Olof Naessén a.k.a jansem/yakslem
36
 *
37
 * Visit: http://guichan.sourceforge.net
38
 *
39
 * License: (BSD)
40
 * Redistribution and use in source and binary forms, with or without
41
 * modification, are permitted provided that the following conditions
42
 * are met:
43
 * 1. Redistributions of source code must retain the above copyright
44
 *    notice, this list of conditions and the following disclaimer.
45
 * 2. Redistributions in binary form must reproduce the above copyright
46
 *    notice, this list of conditions and the following disclaimer in
47
 *    the documentation and/or other materials provided with the
48
 *    distribution.
49
 * 3. Neither the name of Guichan nor the names of its contributors may
50
 *    be used to endorse or promote products derived from this software
51
 *    without specific prior written permission.
52
 *
53
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
59
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
60
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
61
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
62
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64
 */
65
66
#ifndef GUI_WIDGETS_TABBEDAREA_H
67
#define GUI_WIDGETS_TABBEDAREA_H
68
69
#include "listeners/keylistener.h"
70
#include "listeners/mouselistener.h"
71
#include "listeners/widgetlistener.h"
72
73
#include "gui/widgets/basiccontainer2.h"
74
75
#include "listeners/actionlistener.h"
76
77
class Button;
78
class Image;
79
class Tab;
80
81
/**
82
 * A tabbed area, the same as the guichan tabbed area in 0.8, but extended
83
 */
84
class TabbedArea final : public ActionListener,
85
                         public BasicContainer,
86
                         public KeyListener,
87
                         public MouseListener,
88
                         public WidgetListener
89
{
90
    public:
91
        /**
92
         * Constructor.
93
         */
94
        explicit TabbedArea(const Widget2 *const widget);
95
96
        A_DELETE_COPY(TabbedArea)
97
98
        ~TabbedArea();
99
100
        void postInit() override final;
101
102
        /**
103
         * Draw the tabbed area.
104
         */
105
        void draw(Graphics *const graphics) override final A_NONNULL(2);
106
107
        void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
108
109
        /**
110
         * Return how many tabs have been created.
111
         */
112
        int getNumberOfTabs() const A_WARN_UNUSED;
113
114
        /**
115
         * Return tab with specified name as caption.
116
         */
117
        Tab *getTab(const std::string &name) const A_WARN_UNUSED;
118
119
        Tab *getTabByIndex(const int index) const A_WARN_UNUSED;
120
121
        Widget *getWidgetByIndex(const int index) const A_WARN_UNUSED;
122
123
        /**
124
         * Returns the widget with the tab that has specified caption
125
         */
126
        Widget *getWidget(const std::string &name) const A_WARN_UNUSED;
127
128
        /**
129
         * Returns the widget for the current tab
130
         */
131
        Widget *getCurrentWidget() const A_WARN_UNUSED;
132
133
        /**
134
         * Add a tab. Overridden since it needs to size the widget.
135
         *
136
         * @param tab The tab widget for the tab.
137
         * @param widget The widget to view when the tab is selected.
138
         */
139
        void addTab(Tab *const tab, Widget *const widget);
140
141
        void addTab(const std::string &caption, Widget *const widget);
142
143
        void addTab(Image *const image, Widget *const widget);
144
145
        bool isTabSelected(const size_t index) const A_WARN_UNUSED;
146
147
        bool isTabSelected(const Tab *const tab) const A_WARN_UNUSED;
148
149
        bool isTabPresent(const Tab *const tab) const A_WARN_UNUSED;
150
151
        /**
152
         * Overload the remove tab function as it's broken in guichan 0.8.
153
         */
154
        void removeTab(Tab *const tab);
155
156
        void removeAll(const bool del = true);
157
158
        /**
159
         * Overload the logic function since it's broken in guichan 0.8.
160
         */
161
        void logic() override final;
162
163
        int getContainerHeight() const noexcept2 A_WARN_UNUSED
164
        { return mWidgetContainer->getHeight(); }
165
166
        void setSelectedTab(Tab *const tab);
167
168
        void setSelectedTabDefault();
169
170
        void setSelectedTabByIndex(const size_t index);
171
172
        int getSelectedTabIndex() const A_WARN_UNUSED;
173
174
        Tab* getSelectedTab() const noexcept2 A_WARN_UNUSED
175
510
        { return mSelectedTab; }
176
177
        void setOpaque(const Opaque opaque)
178
        { mOpaque = opaque; }
179
180
        bool isOpaque() const noexcept2 A_WARN_UNUSED
181
        { return mOpaque == Opaque_true; }
182
183
        void adjustSize();
184
185
        void setSelectedTabByName(const std::string &name);
186
187
        void widgetResized(const Event &event) override final;
188
189
/*
190
        void moveLeft(Tab *tab);
191
192
        void moveRight(Tab *tab);
193
*/
194
        void adjustTabPositions();
195
196
        void action(const ActionEvent& actionEvent) override final;
197
198
        // Inherited from MouseListener
199
200
        void mousePressed(MouseEvent &event) override final;
201
202
        void enableScrollButtons(const bool enable);
203
204
        void setRightMargin(const int n) noexcept2
205
8
        { mRightMargin = n; }
206
207
        int getRightMargin() const noexcept2 A_WARN_UNUSED
208
        { return mRightMargin; }
209
210
        void setFollowDownScroll(const bool n) noexcept2
211
4
        { mFollowDownScroll = n; }
212
213
        bool getFollowDownScroll() const noexcept2 A_WARN_UNUSED
214
        { return mFollowDownScroll; }
215
216
        void keyPressed(KeyEvent& event) override final;
217
218
        void setBlockSwitching(const bool b) noexcept2
219
        { mBlockSwitching = b; }
220
221
        void setWidth(int width);
222
223
        void setHeight(int height);
224
225
        void setSize(int width, int height);
226
227
        void setDimension(const Rect &dimension);
228
229
        void death(const Event &event) override final;
230
231
        void setResizeHeight(bool b) noexcept2
232
4
        { mResizeHeight = b; }
233
234
        void adjustWidget(Widget *const widget) const;
235
236
        void selectNextTab();
237
238
        void selectPrevTab();
239
240
        Widget *getTabContainer() const noexcept2 A_WARN_UNUSED
241
14
        { return mTabContainer; }
242
243
        Widget *getWidgetContainer() const noexcept2 A_WARN_UNUSED
244
14
        { return mWidgetContainer; }
245
246
    private:
247
        typedef STD_VECTOR <std::pair<Tab*, Widget*> > TabContainer;
248
249
        /** The tab arrows */
250
        Button *mArrowButton[2] A_NONNULLPOINTER;
251
252
        /** Check whether the arrow should be clickable */
253
        void updateArrowEnableState();
254
255
        /**
256
         * Update the overall width of all tab. Used to know whether the arrows
257
         * have to be drawn or not.
258
         */
259
        void updateTabsWidth();
260
261
        Tab* mSelectedTab;
262
        BasicContainer2* mTabContainer A_NONNULLPOINTER;
263
        BasicContainer2* mWidgetContainer A_NONNULLPOINTER;
264
        STD_VECTOR<Tab*> mTabsToDelete;
265
        TabContainer mTabs;
266
267
        /**
268
         * The overall width of all tab.
269
         */
270
        int mTabsWidth;
271
272
        /**
273
         * Update the overall width of visible tab. Used to know whether
274
         * the arrows have to be enable or not.
275
         */
276
        void updateVisibleTabsWidth();
277
278
        /**
279
         * The overall width of visible tab.
280
         */
281
        int mVisibleTabsWidth;
282
283
        /**
284
         * The tab scroll index. When scrolling with the arrows, the tabs
285
         * must be displayed according to the current index.
286
         * So the first tab displayed may not be the first in the list.
287
         * @note the index must start at 0.
288
         */
289
        unsigned int mTabScrollIndex;
290
        int mRightMargin;
291
292
        Opaque mOpaque;
293
        bool mEnableScrollButtons;
294
        bool mFollowDownScroll;
295
        bool mBlockSwitching;
296
        bool mResizeHeight;
297
};
298
299
#endif  // GUI_WIDGETS_TABBEDAREA_H