comparison ext/guichan-0.8.2/include/guichan/widgets/tabbedarea.hpp @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents
children
comparison
equal deleted inserted replaced
377:fe6fb0e0ed23 378:64738befdf3b
1 /* _______ __ __ __ ______ __ __ _______ __ __
2 * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
3 * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4 * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
5 * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
6 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8 *
9 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
10 *
11 *
12 * Per Larsson a.k.a finalman
13 * Olof Naessén a.k.a jansem/yakslem
14 *
15 * Visit: http://guichan.sourceforge.net
16 *
17 * License: (BSD)
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in
25 * the documentation and/or other materials provided with the
26 * distribution.
27 * 3. Neither the name of Guichan nor the names of its contributors may
28 * be used to endorse or promote products derived from this software
29 * without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
37 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 #ifndef GCN_TABBEDAREA_HPP
45 #define GCN_TABBEDAREA_HPP
46
47 #include <map>
48 #include <string>
49 #include <vector>
50
51 #include "guichan/actionlistener.hpp"
52 #include "guichan/basiccontainer.hpp"
53 #include "guichan/keylistener.hpp"
54 #include "guichan/mouselistener.hpp"
55 #include "guichan/platform.hpp"
56
57 namespace gcn
58 {
59 class Container;
60 class Tab;
61
62 /**
63 * An implementation of a tabbed area where a user can display a widget by
64 * selecting a tab.
65 *
66 * @since 0.8.0
67 */
68 class GCN_CORE_DECLSPEC TabbedArea:
69 public ActionListener,
70 public BasicContainer,
71 public KeyListener,
72 public MouseListener
73 {
74 friend class Tab;
75
76 public:
77 /**
78 * Constructor.
79 */
80 TabbedArea();
81
82 /**
83 * Destructor.
84 */
85 virtual ~TabbedArea();
86
87 /**
88 * Sets the tabbed area to be opaque or not. If the tabbed area is
89 * opaque its background will be drawn, if it's not opaque its
90 * background will not be drawn. By default, a tabbed area is not
91 * opaque.
92 *
93 * The tabbed area's background is normally only visible behind the
94 * tabs, since the container holding the tab contents is opaque by
95 * default.
96 *
97 * @param opaque True if the tabbed area should be opaque, false
98 * otherwise.
99 * @see isOpaque
100 */
101 void setOpaque(bool opaque);
102
103 /**
104 * Checks if the tabbed area is opaque or not.
105 *
106 * @return true if the tabbed area is opaque, false otherwise.
107 * @see setOpaque
108 */
109 bool isOpaque() const;
110
111 /**
112 * Adds a tab to the tabbed area. The newly created tab will be
113 * automatically deleted by the tabbed area when it is removed.
114 *
115 * @param caption The caption of the tab to add.
116 * @param widget The widget to view when the tab is selected.
117 * @see removeTab, removeTabWithIndex
118 */
119 virtual void addTab(const std::string& caption, Widget* widget);
120
121 /**
122 * Adds a tab to the tabbed area. The tab will not be deleted by the
123 * tabbed area when it is removed.
124 *
125 * @param tab The tab widget for the tab.
126 * @param widget The widget to view when the tab is selected.
127 * @see removeTab, removeTabWithIndex
128 */
129 virtual void addTab(Tab* tab, Widget* widget);
130
131 /**
132 * Removes a tab from the tabbed area.
133 *
134 * @param index The index of the tab to remove.
135 * @see addTab
136 */
137 virtual void removeTabWithIndex(unsigned int index);
138
139 /**
140 * Removes a tab from the tabbed area.
141 *
142 * @param index The tab to remove.
143 * @see addTab
144 */
145 virtual void removeTab(Tab* tab);
146
147 /**
148 * Checks if a tab given an index is selected or not.
149 *
150 * @param index The index of the tab to check.
151 * @return True if the tab is selected, false otherwise.
152 * @see setSelectedTab
153 */
154 virtual bool isTabSelected(unsigned int index) const;
155
156 /**
157 * Checks if a tab is selected or not.
158 *
159 * @param index The tab to check.
160 * @return True if the tab is selected, false otherwise.
161 * @see setSelectedTab
162 */
163 virtual bool isTabSelected(Tab* tab);
164
165 /**
166 * Sets a tab given an index to be selected.
167 *
168 * @param index The index of the tab to be selected.
169 * @see isTabSelected, getSelectedTab
170 */
171 virtual void setSelectedTab(unsigned int index);
172
173 /**
174 * Sets a tab to be selected or not.
175 *
176 * @param index The tab to be selected.
177 * @see isTabSelected, getSelectedTab
178 */
179 virtual void setSelectedTab(Tab* tab);
180
181 /**
182 * Gets the index of the selected tab.
183 *
184 * @return The undex of the selected tab.
185 * If no tab is selected -1 will be returned.
186 * @see isTabSelected, setSelectedTab
187 */
188 virtual int getSelectedTabIndex() const;
189
190 /**
191 * Gets the selected tab.
192 *
193 * @return The selected tab.
194 * @see isTabSelected, setSelectedTab
195 */
196 Tab* getSelectedTab();
197
198
199 // Inherited from Widget
200
201 virtual void draw(Graphics *graphics);
202
203 virtual void logic();
204
205 void setWidth(int width);
206
207 void setHeight(int height);
208
209 void setSize(int width, int height);
210
211 void setDimension(const Rectangle& dimension);
212
213
214 // Inherited from ActionListener
215
216 void action(const ActionEvent& actionEvent);
217
218
219 // Inherited from DeathListener
220
221 virtual void death(const Event& event);
222
223
224 // Inherited from KeyListener
225
226 virtual void keyPressed(KeyEvent& keyEvent);
227
228
229 // Inherited from MouseListener
230
231 virtual void mousePressed(MouseEvent& mouseEvent);
232
233
234 protected:
235 /**
236 * Adjusts the size of the tab container and the widget container.
237 */
238 void adjustSize();
239
240 /**
241 * Adjusts the positions of the tabs.
242 */
243 void adjustTabPositions();
244
245 /**
246 * Holds the selected tab.
247 */
248 Tab* mSelectedTab;
249
250 /**
251 * Holds the container for the tabs.
252 */
253 Container* mTabContainer;
254
255 /**
256 * Holds the container for the widgets.
257 */
258 Container* mWidgetContainer;
259
260 /**
261 * Holds a vector of tabs to delete in the destructor.
262 * A tab that is to be deleted is a tab that has been
263 * internally created by the tabbed area.
264 */
265 std::vector<Tab*> mTabsToDelete;
266
267 /**
268 * A map between a tab and a widget to display when the
269 * tab is selected.
270 */
271 std::vector<std::pair<Tab*, Widget*> > mTabs;
272
273 /**
274 * True if the tabbed area is opaque, false otherwise.
275 */
276 bool mOpaque;
277 };
278 }
279
280 #endif // end GCN_TABBEDAREA_HPP