source: GTP/trunk/App/Demos/Geom/OgreStuff/include/CEGUI/elements/CEGUIItemListBase.h @ 1092

Revision 1092, 11.8 KB checked in by gumbau, 18 years ago (diff)

LodStrips? and LODTrees demos

Line 
1/************************************************************************
2        filename:       CEGUIItemListBase.h
3        created:        31/3/2005
4        author:         Tomas Lindquist Olsen (based on original Listbox code by Paul D Turner)
5       
6        purpose:        Interface to base class for ItemListBase widgets
7*************************************************************************/
8/*************************************************************************
9    Crazy Eddie's GUI System (http://www.cegui.org.uk)
10    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
11
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2.1 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25*************************************************************************/
26#ifndef _CEGUIItemListBase_h_
27#define _CEGUIItemListBase_h_
28
29#include "CEGUIBase.h"
30#include "CEGUIWindow.h"
31#include "elements/CEGUIItemListBaseProperties.h"
32#include "elements/CEGUIItemEntry.h"
33
34#include <vector>
35
36
37#if defined(_MSC_VER)
38#       pragma warning(push)
39#       pragma warning(disable : 4251)
40#endif
41
42
43// Start of CEGUI namespace section
44namespace CEGUI
45{
46
47/*!
48\brief
49        Base class for item list widgets.
50*/
51class CEGUIEXPORT ItemListBase : public Window
52{
53public:
54        static const String EventNamespace;                             //!< Namespace for global events
55
56
57        /*************************************************************************
58                Constants
59        *************************************************************************/
60        // event names
61        static const String EventListContentsChanged;                   //!< Event triggered when the contents of the list is changed.
62
63
64        /*************************************************************************
65                Accessor Methods
66        *************************************************************************/
67        /*!
68        \brief
69                Return number of items attached to the list
70
71        \return
72                the number of items currently attached to this list.
73        */
74        size_t  getItemCount(void) const                {return d_listItems.size();}
75
76
77        /*!
78        \brief
79                Return the item at index position \a index.
80
81        \param index
82                Zero based index of the item to be returned.
83
84        \return
85                Pointer to the ItemEntry at index position \a index in the list.
86
87        \exception      InvalidRequestException thrown if \a index is out of range.
88        */
89        ItemEntry*      getItemFromIndex(size_t index) const;
90
91
92        /*!
93        \brief
94                Return the index of ItemEntry \a item
95
96        \param item
97                Pointer to a ItemEntry whos zero based index is to be returned.
98
99        \return
100                Zero based index indicating the position of ItemEntry \a item in the list.
101
102        \exception      InvalidRequestException thrown if \a item is not attached to this list.
103        */
104        size_t  getItemIndex(const ItemEntry* item) const;
105
106
107        /*!
108        \brief
109                Search the list for an item with the specified text
110
111        \param text
112                String object containing the text to be searched for.
113
114        \param start_item
115                ItemEntry where the search is to begin, the search will not include \a item.  If \a item is
116                NULL, the search will begin from the first item in the list.
117
118        \return
119                Pointer to the first ItemEntry in the list after \a item that has text matching \a text.  If
120                no item matches the criteria NULL is returned.
121
122        \exception      InvalidRequestException thrown if \a item is not attached to this list box.
123        */
124        ItemEntry*      findItemWithText(const String& text, const ItemEntry* start_item);
125
126
127        /*!
128        \brief
129                Return whether the specified ItemEntry is in the List
130
131        \return
132                true if ItemEntry \a item is in the list, false if ItemEntry \a item is not in the list.
133        */
134        bool    isItemInList(const ItemEntry* item) const;
135
136
137        /*!
138        \brief
139                Return wheter this window is automatically resized to fit its content.
140
141        \return
142                true if automatic resizing is enabled, false if it is disabled.
143        */
144        bool isAutoResizeEnabled() const                {return d_autoResize;}
145
146
147        /*************************************************************************
148                Manipulator Methods
149        *************************************************************************/
150        /*!
151        \brief
152                Initialise the Window based object ready for use.
153
154        \note
155                This must be called for every window created.  Normally this is handled automatically by the WindowFactory for each Window type.
156
157        \return
158                Nothing
159        */
160        virtual void    initialise(void);
161
162
163        /*!
164        \brief
165                Remove all items from the list.
166
167                Note that this will cause 'AutoDelete' items to be deleted.
168        */
169        void    resetList(void);
170
171
172        /*!
173        \brief
174                Add the given ItemEntry to the list.
175
176        \param item
177                Pointer to the ItemEntry to be added to the list.  Note that it is the passed object that is added to the
178                list, a copy is not made.  If this parameter is NULL, nothing happens.
179
180        \return
181                Nothing.
182        */
183        void    addItem(ItemEntry* item);
184
185
186        /*!
187        \brief
188                Insert an item into the list after a specified item already in the list.
189
190                Note that if the list is sorted, the item may not end up in the requested position.
191
192        \param item
193                Pointer to the ItemEntry to be inserted.  Note that it is the passed object that is added to the
194                list, a copy is not made.  If this parameter is NULL, nothing happens.
195
196        \param position
197                Pointer to a ItemEntry that \a item is to be inserted after.  If this parameter is NULL, the item is
198                inserted at the start of the list.
199
200        \return
201                Nothing.
202        */
203        void    insertItem(ItemEntry* item, const ItemEntry* position);
204
205
206        /*!
207        \brief
208                Removes the given item from the list.  If the item is has the auto delete state set, the item will be deleted.
209
210        \param item
211                Pointer to the ItemEntry that is to be removed.  If \a item is not attached to this list then nothing
212                will happen.
213
214        \return
215                Nothing.
216        */
217        void    removeItem(ItemEntry* item);
218
219
220        /*!
221        \brief
222                Causes the list to update it's internal state after changes have been made to one or more
223                attached ItemEntry objects.
224
225                Client code must call this whenever it has made any changes to ItemEntry objects already attached to the
226                list.  If you are just adding items, or removed items to update them prior to re-adding them, there is
227                no need to call this method.
228
229        \return
230                Nothing.
231        */
232        void    handleUpdatedItemData(void);
233
234
235        /*!
236        \brief
237                Set whether or not this ItemListBase widget should automatically resize to fit its content.
238
239        \param setting
240                Boolean value that if true enables automatic resizing, if false disables automatic resizing.
241
242        \return
243                Nothing.
244        */
245        void setAutoResizeEnabled(bool setting);
246
247
248        /*!
249        \brief
250        Resize the ItemListBase to exactly fit the content that is attached to it.
251        Return a Rect object describing, in un-clipped pixels, the window relative area
252        that is to be used for rendering items.
253
254        \return
255        Nothing
256        */
257        virtual void    sizeToContent(void)             {sizeToContent_impl();}
258
259
260        /*************************************************************************
261                Construction and Destruction
262        *************************************************************************/
263        /*!
264        \brief
265                Constructor for ItemListBase base class.
266        */
267        ItemListBase(const String& type, const String& name);
268
269
270        /*!
271        \brief
272                Destructor for ItemListBase base class.
273        */
274        virtual ~ItemListBase(void);
275
276
277protected:
278        /*************************************************************************
279                Abstract Implementation Functions (must be provided by derived class)
280        *************************************************************************/
281        /*!
282        \brief
283                Resize the ItemListBase to exactly fit the content that is attached to it.
284                Return a Rect object describing, in un-clipped pixels, the window relative area
285                that is to be used for rendering items.
286
287        \return
288                Nothing
289        */
290        virtual void    sizeToContent_impl(void)                = 0;
291
292
293        /*!
294        \brief
295                Returns the Size in unclipped pixels of the content attached to this ItemListBase that is attached to it.
296
297        \return
298                Nothing.
299        */
300        virtual Size getContentSize()           = 0;
301
302
303        /*!
304        \brief
305                Return a Rect object describing, in un-clipped pixels, the window relative area
306                that is to be used for rendering list items.
307
308        \return
309                Rect object describing the window relative area of the that is to be used for rendering
310                the items.
311        */
312        virtual Rect    getItemRenderArea(void) const           = 0;
313
314
315        /*!
316        \brief
317                Setup size and position for the item widgets attached to this ItemListBase
318
319        \return
320                Nothing.
321        */
322        virtual void    layoutItemWidgets()     = 0;
323
324
325        /*!
326        \brief
327                Perform the actual rendering for this Window.
328
329        \param z
330                float value specifying the base Z co-ordinate that should be used when rendering
331
332        \return
333                Nothing
334        */
335        virtual void    drawSelf(float z) = 0;
336
337
338        /*************************************************************************
339                Implementation Functions
340        *************************************************************************/
341        /*!
342        \brief
343                Add list box specific events
344        */
345        void    addItemListBaseEvents(void);
346
347
348        /*!
349        \brief
350                Remove all items from the list.
351
352        \note
353                Note that this will cause 'AutoDelete' items to be deleted.
354
355        \return
356                - true if the list contents were changed.
357                - false if the list contents were not changed (list already empty).
358        */
359        bool    resetList_impl(void);
360
361
362        /*!
363        \brief
364                Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
365
366        \param class_name
367                The class name that is to be checked.
368
369        \return
370                true if this window was inherited from \a class_name. false if not.
371        */
372        virtual bool    testClassName_impl(const String& class_name) const
373        {
374                if (class_name==(const utf8*)"ItemListBase")    return true;
375                return Window::testClassName_impl(class_name);
376        }
377
378        /*************************************************************************
379                New event handlers
380        *************************************************************************/
381        /*!
382        \brief
383                Handler called internally when the list contents are changed
384        */
385        virtual void    onListContentsChanged(WindowEventArgs& e);
386
387
388        /*************************************************************************
389                Overridden Event handlers
390        *************************************************************************/
391        virtual void    onSized(WindowEventArgs& e);
392
393
394        /*************************************************************************
395                Implementation Data
396        *************************************************************************/
397        typedef std::vector<ItemEntry*> ItemEntryList;
398        ItemEntryList   d_listItems;            //!< list of items in the list.
399
400        // boolean telling if this ItemListBase widget should automatically resize to fit its content.
401        bool d_autoResize;
402
403private:
404        /*************************************************************************
405        Static Properties for this class
406        *************************************************************************/
407        static ItemListBaseProperties::AutoResizeEnabled        d_autoResizeEnabledProperty;
408
409
410        /*************************************************************************
411                Private methods
412        *************************************************************************/
413        void    addItemListBaseProperties(void);
414
415
416        /*!
417        \brief
418                Add given window to child list at an appropriate position
419        */
420        virtual void    addChild_impl(Window* wnd);
421};
422
423} // End of  CEGUI namespace section
424
425
426#if defined(_MSC_VER)
427#       pragma warning(pop)
428#endif
429
430#endif  // end of guard _CEGUIItemListBase_h_
Note: See TracBrowser for help on using the repository browser.