Mercurial > fife-parpg
comparison ext/guichan-0.8.2/include/guichan/widgets/listbox.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_LISTBOX_HPP | |
45 #define GCN_LISTBOX_HPP | |
46 | |
47 #include <list> | |
48 | |
49 #include "guichan/keylistener.hpp" | |
50 #include "guichan/listmodel.hpp" | |
51 #include "guichan/mouselistener.hpp" | |
52 #include "guichan/platform.hpp" | |
53 #include "guichan/widget.hpp" | |
54 | |
55 namespace gcn | |
56 { | |
57 class SelectionListener; | |
58 | |
59 /** | |
60 * An implementation of a list box where an item can be selected. | |
61 * | |
62 * To be able display a list the list box uses a user provided list model. | |
63 * A list model can be any class that implements the ListModel interface. | |
64 * | |
65 * If an item is selected in the list box a select event will be sent to | |
66 * all selection listeners of the list box. If an item is selected by using | |
67 * a mouse click or by using the enter or space key an action event will be | |
68 * sent to all action listeners of the list box. | |
69 */ | |
70 class GCN_CORE_DECLSPEC ListBox : | |
71 public Widget, | |
72 public MouseListener, | |
73 public KeyListener | |
74 { | |
75 public: | |
76 /** | |
77 * Constructor. | |
78 */ | |
79 ListBox(); | |
80 | |
81 /** | |
82 * Constructor. | |
83 * | |
84 * @param listModel the list model to use. | |
85 */ | |
86 ListBox(ListModel *listModel); | |
87 | |
88 /** | |
89 * Destructor. | |
90 */ | |
91 virtual ~ListBox() { } | |
92 | |
93 /** | |
94 * Gets the selected item as an index in the list model. | |
95 * | |
96 * @return the selected item as an index in the list model. | |
97 * @see setSelected | |
98 */ | |
99 int getSelected() const; | |
100 | |
101 /** | |
102 * Sets the selected item. The selected item is represented by | |
103 * an index from the list model. | |
104 * | |
105 * @param selected the selected item as an index from the list model. | |
106 * @see getSelected | |
107 */ | |
108 void setSelected(int selected); | |
109 | |
110 /** | |
111 * Sets the list model to use. | |
112 * | |
113 * @param listModel the list model to use. | |
114 * @see getListModel | |
115 */ | |
116 void setListModel(ListModel *listModel); | |
117 | |
118 /** | |
119 * Gets the list model used. | |
120 * | |
121 * @return the list model used. | |
122 * @see setListModel | |
123 */ | |
124 ListModel *getListModel(); | |
125 | |
126 /** | |
127 * Adjusts the size of the list box to fit it's list model. | |
128 */ | |
129 void adjustSize(); | |
130 | |
131 /** | |
132 * Checks whether the list box wraps when selecting items with a | |
133 * keyboard. | |
134 * | |
135 * Wrapping means that the selection of items will be wrapped. That is, | |
136 * if the first item is selected and up is pressed, the last item will | |
137 * get selected. If the last item is selected and down is pressed, the | |
138 * first item will get selected. | |
139 * | |
140 * @return true if wrapping is enabled, fasle otherwise. | |
141 * @see setWrappingEnabled | |
142 */ | |
143 bool isWrappingEnabled() const; | |
144 | |
145 /** | |
146 * Sets the list box to wrap or not when selecting items with a | |
147 * keyboard. | |
148 * | |
149 * Wrapping means that the selection of items will be wrapped. That is, | |
150 * if the first item is selected and up is pressed, the last item will | |
151 * get selected. If the last item is selected and down is pressed, the | |
152 * first item will get selected. | |
153 * | |
154 * @see isWrappingEnabled | |
155 */ | |
156 void setWrappingEnabled(bool wrappingEnabled); | |
157 | |
158 /** | |
159 * Adds a selection listener to the list box. When the selection | |
160 * changes an event will be sent to all selection listeners of the | |
161 * list box. | |
162 * | |
163 * If you delete your selection listener, be sure to also remove it | |
164 * using removeSelectionListener(). | |
165 * | |
166 * @param selectionListener The selection listener to add. | |
167 * @since 0.8.0 | |
168 */ | |
169 void addSelectionListener(SelectionListener* selectionListener); | |
170 | |
171 /** | |
172 * Removes a selection listener from the list box. | |
173 * | |
174 * @param selectionListener The selection listener to remove. | |
175 * @since 0.8.0 | |
176 */ | |
177 void removeSelectionListener(SelectionListener* selectionListener); | |
178 | |
179 /** | |
180 * Gets the height of a row. Should be overridden if another row | |
181 * height than the font height is preferred. | |
182 * | |
183 * @return The height of a row. | |
184 * @since 0.8.0 | |
185 */ | |
186 virtual unsigned int getRowHeight() const; | |
187 | |
188 | |
189 // Inherited from Widget | |
190 | |
191 virtual void draw(Graphics* graphics); | |
192 | |
193 virtual void logic(); | |
194 | |
195 | |
196 // Inherited from KeyListener | |
197 | |
198 virtual void keyPressed(KeyEvent& keyEvent); | |
199 | |
200 | |
201 // Inherited from MouseListener | |
202 | |
203 virtual void mousePressed(MouseEvent& mouseEvent); | |
204 | |
205 virtual void mouseWheelMovedUp(MouseEvent& mouseEvent); | |
206 | |
207 virtual void mouseWheelMovedDown(MouseEvent& mouseEvent); | |
208 | |
209 virtual void mouseDragged(MouseEvent& mouseEvent); | |
210 | |
211 | |
212 protected: | |
213 /** | |
214 * Distributes a value changed event to all selection listeners | |
215 * of the list box. | |
216 * | |
217 * @since 0.8.0 | |
218 */ | |
219 void distributeValueChangedEvent(); | |
220 | |
221 /** | |
222 * The selected item as an index in the list model. | |
223 */ | |
224 int mSelected; | |
225 | |
226 /** | |
227 * The list model to use. | |
228 */ | |
229 ListModel *mListModel; | |
230 | |
231 /** | |
232 * True if wrapping is enabled, false otherwise. | |
233 */ | |
234 bool mWrappingEnabled; | |
235 | |
236 /** | |
237 * Typdef. | |
238 */ | |
239 typedef std::list<SelectionListener*> SelectionListenerList; | |
240 | |
241 /** | |
242 * The selection listeners of the list box. | |
243 */ | |
244 SelectionListenerList mSelectionListeners; | |
245 | |
246 /** | |
247 * Typedef. | |
248 */ | |
249 typedef SelectionListenerList::iterator SelectionListenerIterator; | |
250 }; | |
251 } | |
252 | |
253 #endif // end GCN_LISTBOX_HPP |