Mercurial > fife-parpg
comparison ext/guichan-0.8.2/include/guichan/widgets/dropdown.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_DROPDOWN_HPP | |
45 #define GCN_DROPDOWN_HPP | |
46 | |
47 #include "guichan/actionlistener.hpp" | |
48 #include "guichan/basiccontainer.hpp" | |
49 #include "guichan/deathlistener.hpp" | |
50 #include "guichan/focushandler.hpp" | |
51 #include "guichan/focuslistener.hpp" | |
52 #include "guichan/keylistener.hpp" | |
53 #include "guichan/listmodel.hpp" | |
54 #include "guichan/mouselistener.hpp" | |
55 #include "guichan/platform.hpp" | |
56 #include "guichan/selectionlistener.hpp" | |
57 #include "guichan/widgets/listbox.hpp" | |
58 #include "guichan/widgets/scrollarea.hpp" | |
59 | |
60 namespace gcn { | |
61 /** | |
62 * An implementation of a drop downable list from which an item can be | |
63 * selected. The drop down consists of an internal ScrollArea and an | |
64 * internal ListBox. The drop down also uses an internal FocusHandler to | |
65 * handle the focus of the internal ScollArea and the internal ListBox. The | |
66 * scroll area and the list box can be passed to the drop down if a custom | |
67 * scroll area and or a custom list box is preferable. | |
68 * | |
69 * To be able display a list the drop down uses a user provided list model. | |
70 * A list model can be any class that implements the ListModel interface. | |
71 * | |
72 * If an item is selected in the drop down a select event will be sent to | |
73 * all selection listeners of the drop down. If an item is selected by | |
74 * using a mouse click or by using the enter or space key an action event | |
75 * will be sent to all action listeners of the drop down. | |
76 */ | |
77 class GCN_CORE_DECLSPEC DropDown : | |
78 public ActionListener, | |
79 public BasicContainer, | |
80 public KeyListener, | |
81 public MouseListener, | |
82 public FocusListener, | |
83 public SelectionListener | |
84 { | |
85 public: | |
86 /** | |
87 * Contructor. | |
88 * | |
89 * @param listModel the ListModel to use. | |
90 * @param scrollArea the ScrollArea to use. | |
91 * @param listBox the listBox to use. | |
92 * @see ListModel, ScrollArea, ListBox. | |
93 */ | |
94 DropDown(ListModel *listModel = NULL, | |
95 ScrollArea *scrollArea = NULL, | |
96 ListBox *listBox = NULL); | |
97 | |
98 /** | |
99 * Destructor. | |
100 */ | |
101 virtual ~DropDown(); | |
102 | |
103 /** | |
104 * Gets the selected item as an index in the list model. | |
105 * | |
106 * @return the selected item as an index in the list model. | |
107 * @see setSelected | |
108 */ | |
109 int getSelected() const; | |
110 | |
111 /** | |
112 * Sets the selected item. The selected item is represented by | |
113 * an index from the list model. | |
114 * | |
115 * @param selected the selected item as an index from the list model. | |
116 * @see getSelected | |
117 */ | |
118 void setSelected(int selected); | |
119 | |
120 /** | |
121 * Sets the list model to use when displaying the list. | |
122 * | |
123 * @param listModel the list model to use. | |
124 * @see getListModel | |
125 */ | |
126 void setListModel(ListModel *listModel); | |
127 | |
128 /** | |
129 * Gets the list model used. | |
130 * | |
131 * @return the ListModel used. | |
132 * @see setListModel | |
133 */ | |
134 ListModel *getListModel(); | |
135 | |
136 /** | |
137 * Adjusts the height of the drop down to fit the height of the | |
138 * drop down's parent's height. It's used to not make the drop down | |
139 * draw itself outside of it's parent if folded down. | |
140 */ | |
141 void adjustHeight(); | |
142 | |
143 /** | |
144 * Adds a selection listener to the drop down. When the selection | |
145 * changes an event will be sent to all selection listeners of the | |
146 * drop down. | |
147 * | |
148 * If you delete your selection listener, be sure to also remove it | |
149 * using removeSelectionListener(). | |
150 * | |
151 * @param selectionListener the selection listener to add. | |
152 * @since 0.8.0 | |
153 */ | |
154 void addSelectionListener(SelectionListener* selectionListener); | |
155 | |
156 /** | |
157 * Removes a selection listener from the drop down. | |
158 * | |
159 * @param selectionListener the selection listener to remove. | |
160 * @since 0.8.0 | |
161 */ | |
162 void removeSelectionListener(SelectionListener* selectionListener); | |
163 | |
164 | |
165 // Inherited from Widget | |
166 | |
167 virtual void draw(Graphics* graphics); | |
168 | |
169 void setBaseColor(const Color& color); | |
170 | |
171 void setBackgroundColor(const Color& color); | |
172 | |
173 void setForegroundColor(const Color& color); | |
174 | |
175 void setFont(Font *font); | |
176 | |
177 void setSelectionColor(const Color& color); | |
178 | |
179 | |
180 // Inherited from BasicContainer | |
181 | |
182 virtual Rectangle getChildrenArea(); | |
183 | |
184 | |
185 // Inherited from FocusListener | |
186 | |
187 virtual void focusLost(const Event& event); | |
188 | |
189 | |
190 // Inherited from ActionListener | |
191 | |
192 virtual void action(const ActionEvent& actionEvent); | |
193 | |
194 | |
195 // Inherited from DeathListener | |
196 | |
197 virtual void death(const Event& event); | |
198 | |
199 | |
200 // Inherited from KeyListener | |
201 | |
202 virtual void keyPressed(KeyEvent& keyEvent); | |
203 | |
204 | |
205 // Inherited from MouseListener | |
206 | |
207 virtual void mousePressed(MouseEvent& mouseEvent); | |
208 | |
209 virtual void mouseReleased(MouseEvent& mouseEvent); | |
210 | |
211 virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); | |
212 | |
213 virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); | |
214 | |
215 virtual void mouseDragged(MouseEvent& mouseEvent); | |
216 | |
217 | |
218 // Inherited from SelectionListener | |
219 | |
220 virtual void valueChanged(const SelectionEvent& event); | |
221 | |
222 protected: | |
223 /** | |
224 * Draws the button of the drop down. | |
225 * | |
226 * @param graphics a Graphics object to draw with. | |
227 */ | |
228 virtual void drawButton(Graphics *graphics); | |
229 | |
230 /** | |
231 * Sets the drop down to be dropped down. | |
232 */ | |
233 virtual void dropDown(); | |
234 | |
235 /** | |
236 * Sets the drop down to be folded up. | |
237 */ | |
238 virtual void foldUp(); | |
239 | |
240 /** | |
241 * Distributes a value changed event to all selection listeners | |
242 * of the drop down. | |
243 * | |
244 * @since 0.8.0 | |
245 */ | |
246 void distributeValueChangedEvent(); | |
247 | |
248 /** | |
249 * True if the drop down is dropped down, false otherwise. | |
250 */ | |
251 bool mDroppedDown; | |
252 | |
253 /** | |
254 * True if the drop down has been pushed with the mouse, false | |
255 * otherwise. | |
256 */ | |
257 bool mPushed; | |
258 | |
259 /** | |
260 * Holds what the height is if the drop down is folded up. Used when | |
261 * checking if the list of the drop down was clicked or if the upper | |
262 * part of the drop down was clicked on a mouse click. | |
263 */ | |
264 int mFoldedUpHeight; | |
265 | |
266 /** | |
267 * The scroll area used. | |
268 */ | |
269 ScrollArea* mScrollArea; | |
270 | |
271 /** | |
272 * The list box used. | |
273 */ | |
274 ListBox* mListBox; | |
275 | |
276 /** | |
277 * The internal focus handler used to keep track of focus for the | |
278 * internal list box. | |
279 */ | |
280 FocusHandler mInternalFocusHandler; | |
281 | |
282 /** | |
283 * True if an internal scroll area is used, false if a scroll area | |
284 * has been passed to the drop down which the drop down should not | |
285 * deleted in it's destructor. | |
286 */ | |
287 bool mInternalScrollArea; | |
288 | |
289 /** | |
290 * True if an internal list box is used, false if a list box | |
291 * has been passed to the drop down which the drop down should not | |
292 * deleted in it's destructor. | |
293 */ | |
294 bool mInternalListBox; | |
295 | |
296 /** | |
297 * True if the drop down is dragged. | |
298 */ | |
299 bool mIsDragged; | |
300 | |
301 /** | |
302 * Typedef. | |
303 */ | |
304 typedef std::list<SelectionListener*> SelectionListenerList; | |
305 | |
306 /** | |
307 * The selection listener's of the drop down. | |
308 */ | |
309 SelectionListenerList mSelectionListeners; | |
310 | |
311 /** | |
312 * Typedef. | |
313 */ | |
314 typedef SelectionListenerList::iterator SelectionListenerIterator; | |
315 }; | |
316 } | |
317 | |
318 #endif // end GCN_DROPDOWN_HPP |