ManaPlus
tabbedarea.h
Go to the documentation of this file.
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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 /* _______ __ __ __ ______ __ __ _______ __ __
25  * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
26  * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
27  * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
28  * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
29  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
30  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
31  *
32  * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
33  *
34  *
35  * Per Larsson a.k.a finalman
36  * Olof Naessén a.k.a jansem/yakslem
37  *
38  * Visit: http://guichan.sourceforge.net
39  *
40  * License: (BSD)
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  * 1. Redistributions of source code must retain the above copyright
45  * notice, this list of conditions and the following disclaimer.
46  * 2. Redistributions in binary form must reproduce the above copyright
47  * notice, this list of conditions and the following disclaimer in
48  * the documentation and/or other materials provided with the
49  * distribution.
50  * 3. Neither the name of Guichan nor the names of its contributors may
51  * be used to endorse or promote products derived from this software
52  * without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
60  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
61  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
62  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
63  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65  */
66 
67 #ifndef GUI_WIDGETS_TABBEDAREA_H
68 #define GUI_WIDGETS_TABBEDAREA_H
69 
70 #include "listeners/keylistener.h"
73 
75 
77 
78 class Button;
79 class Image;
80 class Tab;
81 
86  public BasicContainer,
87  public KeyListener,
88  public MouseListener,
89  public WidgetListener
90 {
91  public:
95  explicit TabbedArea(const Widget2 *const widget);
96 
98 
99  ~TabbedArea() override final;
100 
101  void postInit() override final;
102 
106  void draw(Graphics *const graphics) override final A_NONNULL(2);
107 
108  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
109 
113  int getNumberOfTabs() const A_WARN_UNUSED;
114 
118  Tab *getTab(const std::string &name) const A_WARN_UNUSED;
119 
120  Tab *getTabByIndex(const int index) const A_WARN_UNUSED;
121 
122  Widget *getWidgetByIndex(const int index) const A_WARN_UNUSED;
123 
127  Widget *getWidget(const std::string &name) const A_WARN_UNUSED;
128 
133 
140  void addTab(Tab *const tab, Widget *const widget);
141 
142  void addTab(const std::string &caption, Widget *const widget);
143 
144  void addTab(Image *const image, Widget *const widget);
145 
146  bool isTabSelected(const size_t index) const A_WARN_UNUSED;
147 
148  bool isTabSelected(const Tab *const tab) const A_WARN_UNUSED;
149 
150  bool isTabPresent(const Tab *const tab) const A_WARN_UNUSED;
151 
155  void removeTab(Tab *const tab);
156 
157  void removeAll(const bool del);
158 
162  void logic() override final;
163 
165  { return mWidgetContainer->getHeight(); }
166 
167  void setSelectedTab(Tab *const tab);
168 
169  void setSelectedTabDefault();
170 
171  void setSelectedTabByIndex(const size_t index);
172 
174 
176  { return mSelectedTab; }
177 
178  void setOpaque(const Opaque opaque)
179  { mOpaque = opaque; }
180 
182  { return mOpaque == Opaque_true; }
183 
184  void adjustSize();
185 
186  void setSelectedTabByName(const std::string &name);
187 
188  void widgetResized(const Event &event) override final;
189 
190 /*
191  void moveLeft(Tab *tab);
192 
193  void moveRight(Tab *tab);
194 */
195  void adjustTabPositions();
196 
197  void action(const ActionEvent& actionEvent) override final;
198 
199  // Inherited from MouseListener
200 
201  void mousePressed(MouseEvent &event) override final;
202 
203  void enableScrollButtons(const bool enable);
204 
205  void setRightMargin(const int n) noexcept2
206  { mRightMargin = n; }
207 
209  { return mRightMargin; }
210 
211  void setFollowDownScroll(const bool n) noexcept2
212  { mFollowDownScroll = n; }
213 
215  { return mFollowDownScroll; }
216 
217  void keyPressed(KeyEvent& event) override final;
218 
219  void setBlockSwitching(const bool b) noexcept2
220  { mBlockSwitching = b; }
221 
222  void setWidth(int width);
223 
224  void setHeight(int height);
225 
226  void setSize(int width, int height);
227 
228  void setDimension(const Rect &dimension);
229 
230  void death(const Event &event) override final;
231 
233  { mResizeHeight = b; }
234 
235  void adjustWidget(Widget *const widget) const;
236 
237  void selectNextTab();
238 
239  void selectPrevTab();
240 
242  { return mTabContainer; }
243 
245  { return mWidgetContainer; }
246 
247  private:
248  typedef STD_VECTOR <std::pair<Tab*, Widget*> > TabContainer;
249 
252 
254  void updateArrowEnableState();
255 
260  void updateTabsWidth();
261 
265  STD_VECTOR<Tab*> mTabsToDelete;
267 
272 
277  void updateVisibleTabsWidth();
278 
283 
290  unsigned int mTabScrollIndex;
292 
298 };
299 
300 #endif // GUI_WIDGETS_TABBEDAREA_H
Definition: button.h:102
Definition: event.h:79
Definition: rect.h:74
Definition: tab.h:88
bool mFollowDownScroll
Definition: tabbedarea.h:295
void updateVisibleTabsWidth()
Definition: tabbedarea.cpp:557
Widget * getWidgetByIndex(const int index) const
Definition: tabbedarea.cpp:723
int getRightMargin() const
Definition: tabbedarea.h:208
void setFollowDownScroll(const bool n)
Definition: tabbedarea.h:211
int mVisibleTabsWidth
Definition: tabbedarea.h:282
TabContainer mTabs
Definition: tabbedarea.h:266
void postInit()
Definition: tabbedarea.cpp:107
void adjustSize()
Definition: tabbedarea.cpp:569
void setOpaque(const Opaque opaque)
Definition: tabbedarea.h:178
void setWidth(int width)
Definition: tabbedarea.cpp:750
void setResizeHeight(bool b)
Definition: tabbedarea.h:232
TabbedArea(const Widget2 *const widget)
Definition: tabbedarea.cpp:80
bool isTabSelected(const size_t index) const
Definition: tabbedarea.cpp:292
int getContainerHeight() const
Definition: tabbedarea.h:164
bool isTabPresent(const Tab *const tab) const
Definition: tabbedarea.cpp:300
Widget * getCurrentWidget() const
Definition: tabbedarea.cpp:229
void keyPressed(KeyEvent &event)
Definition: tabbedarea.cpp:778
std::vector< Tab * > mTabsToDelete
Definition: tabbedarea.h:265
BasicContainer2 * mWidgetContainer
Definition: tabbedarea.h:264
void removeTab(Tab *const tab)
Definition: tabbedarea.cpp:323
std::vector< std::pair< Tab *, Widget * > > TabContainer
Definition: tabbedarea.h:248
void setSelectedTabDefault()
Definition: tabbedarea.cpp:432
void mousePressed(MouseEvent &event)
Definition: tabbedarea.cpp:387
Opaque mOpaque
Definition: tabbedarea.h:293
void setHeight(int height)
Definition: tabbedarea.cpp:757
unsigned int mTabScrollIndex
Definition: tabbedarea.h:290
void logic()
Definition: tabbedarea.cpp:380
void draw(Graphics *const graphics)
Definition: tabbedarea.cpp:188
void adjustWidget(Widget *const widget) const
Definition: tabbedarea.cpp:265
int mTabsWidth
Definition: tabbedarea.h:271
Widget * getTabContainer() const
Definition: tabbedarea.h:241
int mRightMargin
Definition: tabbedarea.h:291
void updateTabsWidth()
Definition: tabbedarea.cpp:545
void setSelectedTabByName(const std::string &name)
Definition: tabbedarea.cpp:462
void selectPrevTab()
Definition: tabbedarea.cpp:828
Tab * getTab(const std::string &name) const
Definition: tabbedarea.cpp:174
void widgetResized(const Event &event)
Definition: tabbedarea.cpp:474
void safeDraw(Graphics *const graphics)
Definition: tabbedarea.cpp:201
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:407
bool mEnableScrollButtons
Definition: tabbedarea.h:294
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:263
void selectNextTab()
Definition: tabbedarea.cpp:819
void adjustTabPositions()
Definition: tabbedarea.cpp:606
int getNumberOfTabs() const
Definition: tabbedarea.cpp:169
void updateArrowEnableState()
Definition: tabbedarea.cpp:676
void removeAll(const bool del)
Definition: tabbedarea.cpp:730
void setRightMargin(const int n)
Definition: tabbedarea.h:205
void setSize(int width, int height)
Definition: tabbedarea.cpp:764
int getSelectedTabIndex() const
Definition: tabbedarea.cpp:449
bool isOpaque() const
Definition: tabbedarea.h:181
Widget * getWidgetContainer() const
Definition: tabbedarea.h:244
void setBlockSwitching(const bool b)
Definition: tabbedarea.h:219
bool mBlockSwitching
Definition: tabbedarea.h:296
void setDimension(const Rect &dimension)
Definition: tabbedarea.cpp:771
void action(const ActionEvent &actionEvent)
Definition: tabbedarea.cpp:649
Button * mArrowButton[2]
Definition: tabbedarea.h:251
bool mResizeHeight
Definition: tabbedarea.h:297
void addTab(Tab *const tab, Widget *const widget)
Definition: tabbedarea.cpp:238
void setSelectedTabByIndex(const size_t index)
Definition: tabbedarea.cpp:315
void death(const Event &event)
Definition: tabbedarea.cpp:809
Tab * getSelectedTab() const
Definition: tabbedarea.h:175
Widget * getWidget(const std::string &name) const
Definition: tabbedarea.cpp:214
Tab * mSelectedTab
Definition: tabbedarea.h:262
bool getFollowDownScroll() const
Definition: tabbedarea.h:214
Tab * getTabByIndex(const int index) const
Definition: tabbedarea.cpp:716
void enableScrollButtons(const bool enable)
Definition: tabbedarea.cpp:150
Definition: widget.h:99
int getHeight() const
Definition: widget.h:240
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
const bool Opaque_true
Definition: opaque.h:30
bool Opaque
Definition: opaque.h:30