CEGUIItemListBase.h

00001 /***********************************************************************
00002         filename:       CEGUIItemListBase.h
00003         created:        31/3/2005
00004         author:         Tomas Lindquist Olsen (based on original Listbox code by Paul D Turner)
00005         
00006         purpose:        Interface to base class for ItemListBase widgets
00007 *************************************************************************/
00008 /***************************************************************************
00009  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00010  *
00011  *   Permission is hereby granted, free of charge, to any person obtaining
00012  *   a copy of this software and associated documentation files (the
00013  *   "Software"), to deal in the Software without restriction, including
00014  *   without limitation the rights to use, copy, modify, merge, publish,
00015  *   distribute, sublicense, and/or sell copies of the Software, and to
00016  *   permit persons to whom the Software is furnished to do so, subject to
00017  *   the following conditions:
00018  *
00019  *   The above copyright notice and this permission notice shall be
00020  *   included in all copies or substantial portions of the Software.
00021  *
00022  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00023  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00024  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00025  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00026  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00027  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00028  *   OTHER DEALINGS IN THE SOFTWARE.
00029  ***************************************************************************/
00030 #ifndef _CEGUIItemListBase_h_
00031 #define _CEGUIItemListBase_h_
00032 
00033 #include "CEGUIBase.h"
00034 #include "CEGUIWindow.h"
00035 #include "elements/CEGUIItemListBaseProperties.h"
00036 #include "elements/CEGUIItemEntry.h"
00037 
00038 #include <vector>
00039 
00040 
00041 #if defined(_MSC_VER)
00042 #       pragma warning(push)
00043 #       pragma warning(disable : 4251)
00044 #endif
00045 
00046 
00047 // Start of CEGUI namespace section
00048 namespace CEGUI
00049 {
00050 
00055 class CEGUIEXPORT ItemListBaseWindowRenderer : public WindowRenderer
00056 {
00057 public:
00062     ItemListBaseWindowRenderer(const String& name);
00063 
00073     virtual Rect getItemRenderArea(void) const = 0;
00074 };
00075 
00080 class CEGUIEXPORT ItemListBase : public Window
00081 {
00082 public:
00083         static const String EventNamespace;                             
00084 
00089     enum SortMode
00090     {
00091         Ascending,
00092         Descending,
00093         UserSort
00094     };
00095     
00097     typedef bool (*SortCallback)(const ItemEntry* a, const ItemEntry* b);
00098 
00099         /*************************************************************************
00100                 Constants
00101         *************************************************************************/
00102         // event names
00103         static const String EventListContentsChanged;                   
00104     static const String EventSortEnabledChanged; 
00105     static const String EventSortModeChanged; 
00106 
00107         /*************************************************************************
00108                 Accessor Methods
00109         *************************************************************************/
00117         size_t  getItemCount(void) const                {return d_listItems.size();}
00118 
00119 
00132         ItemEntry*      getItemFromIndex(size_t index) const;
00133 
00134 
00147         size_t  getItemIndex(const ItemEntry* item) const;
00148 
00149 
00167         ItemEntry*      findItemWithText(const String& text, const ItemEntry* start_item);
00168 
00169 
00177         bool    isItemInList(const ItemEntry* item) const;
00178 
00179 
00187         bool isAutoResizeEnabled() const                {return d_autoResize;}
00188 
00189 
00194     bool isSortEnabled(void) const          {return d_sortEnabled;}
00195 
00196 
00201     SortMode getSortMode(void) const        {return d_sortMode;}
00202 
00203 
00208     SortCallback getSortCallback(void) const {return d_sortCallback;}
00209 
00210         /*************************************************************************
00211                 Manipulator Methods
00212         *************************************************************************/
00223     virtual void initialiseComponents(void);
00224 
00225 
00232         void    resetList(void);
00233 
00234 
00246         void    addItem(ItemEntry* item);
00247 
00248 
00266         void    insertItem(ItemEntry* item, const ItemEntry* position);
00267 
00268 
00280         void    removeItem(ItemEntry* item);
00281 
00282 
00298         void    handleUpdatedItemData(bool resort=false);
00299 
00300 
00311         void setAutoResizeEnabled(bool setting);
00312 
00313 
00323         virtual void    sizeToContent(void)             {sizeToContent_impl();}
00324 
00325 
00331     virtual void endInitialisation(void);
00332 
00333 
00344     virtual void performChildWindowLayout(void);
00345 
00346 
00356     Rect getItemRenderArea(void) const;
00357 
00366     Window* getContentPane(void) const  {return d_pane;}
00367 
00373     virtual void notifyItemClicked(ItemEntry* li) {}
00374 
00380     virtual void notifyItemSelectState(ItemEntry* li, bool state) {}
00381 
00386     void setSortEnabled(bool setting);
00387 
00394     void setSortMode(SortMode mode);
00395 
00403     void setSortCallback(SortCallback cb);
00404 
00416     void sortList(bool relayout=true);
00417 
00418         /*************************************************************************
00419                 Construction and Destruction
00420         *************************************************************************/
00425         ItemListBase(const String& type, const String& name);
00426 
00427 
00432         virtual ~ItemListBase(void);
00433 
00434 
00435 protected:
00436         /*************************************************************************
00437                 Abstract Implementation Functions (must be provided by derived class)
00438         *************************************************************************/
00448         virtual void    sizeToContent_impl(void);
00449 
00450 
00458         virtual Size getContentSize() const             = 0;
00459 
00460 
00470         //virtual       Rect    getItemRenderArea_impl(void) const              = 0;
00471 
00472 
00480         virtual void    layoutItemWidgets()     = 0;
00481 
00482 
00483         /*************************************************************************
00484                 Implementation Functions
00485         *************************************************************************/
00497         bool    resetList_impl(void);
00498 
00509         virtual bool    testClassName_impl(const String& class_name) const
00510         {
00511                 if (class_name=="ItemListBase") return true;
00512                 return Window::testClassName_impl(class_name);
00513         }
00514 
00515     // validate window renderer
00516     virtual bool    validateWindowRenderer(const String& name) const
00517     {
00518         return (name == EventNamespace);
00519     }
00520 
00525     SortCallback getRealSortCallback(void) const;
00526 
00527         /*************************************************************************
00528                 New event handlers
00529         *************************************************************************/
00534         virtual void    onListContentsChanged(WindowEventArgs& e);
00535 
00540     virtual void onSortEnabledChanged(WindowEventArgs& e);
00541 
00546     virtual void onSortModeChanged(WindowEventArgs& e);
00547 
00548         /*************************************************************************
00549                 Overridden Event handlers
00550         *************************************************************************/
00551         //virtual void    onChildRemoved(WindowEventArgs& e);
00552     //virtual void    onDestructionStarted(WindowEventArgs& e);
00553 
00554 
00555         /*************************************************************************
00556                 Implementation Data
00557         *************************************************************************/
00558         typedef std::vector<ItemEntry*> ItemEntryList;
00559         ItemEntryList   d_listItems;            
00560 
00562         bool d_autoResize;
00563 
00565     Window* d_pane;
00566 
00568     bool d_sortEnabled;
00570     SortMode d_sortMode;
00572     SortCallback d_sortCallback;
00574     bool d_resort;
00575 
00576 private:
00577         /*************************************************************************
00578         Static Properties for this class
00579         *************************************************************************/
00580         static ItemListBaseProperties::AutoResizeEnabled        d_autoResizeEnabledProperty;
00581     static ItemListBaseProperties::SortEnabled d_sortEnabledProperty;
00582     static ItemListBaseProperties::SortMode d_sortModeProperty;
00583 
00584         /*************************************************************************
00585                 Private methods
00586         *************************************************************************/
00587         void    addItemListBaseProperties(void);
00588 
00589 
00594         virtual void    addChild_impl(Window* wnd);
00595 
00601     bool handle_PaneChildRemoved(const EventArgs& e);
00602 };
00603 
00604 } // End of  CEGUI namespace section
00605 
00606 
00607 #if defined(_MSC_VER)
00608 #       pragma warning(pop)
00609 #endif
00610 
00611 #endif  // end of guard _CEGUIItemListBase_h_

Generated on Sun Nov 5 14:35:28 2006 for Crazy Eddies GUI System by  doxygen 1.4.7