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 
00268         void    insertItem(ItemEntry* item, const ItemEntry* position);
00269 
00270 
00282         void    removeItem(ItemEntry* item);
00283 
00284 
00300         void    handleUpdatedItemData(bool resort=false);
00301 
00302 
00313         void setAutoResizeEnabled(bool setting);
00314 
00315 
00325         virtual void    sizeToContent(void)             {sizeToContent_impl();}
00326 
00327 
00333     virtual void endInitialisation(void);
00334 
00335 
00346     virtual void performChildWindowLayout(void);
00347 
00348 
00358     Rect getItemRenderArea(void) const;
00359 
00368     Window* getContentPane(void) const  {return d_pane;}
00369 
00375     virtual void notifyItemClicked(ItemEntry* li) {}
00376 
00382     virtual void notifyItemSelectState(ItemEntry* li, bool state) {}
00383 
00388     void setSortEnabled(bool setting);
00389 
00396     void setSortMode(SortMode mode);
00397 
00405     void setSortCallback(SortCallback cb);
00406 
00418     void sortList(bool relayout=true);
00419 
00420         /*************************************************************************
00421                 Construction and Destruction
00422         *************************************************************************/
00427         ItemListBase(const String& type, const String& name);
00428 
00429 
00434         virtual ~ItemListBase(void);
00435 
00436 
00437 protected:
00438         /*************************************************************************
00439                 Abstract Implementation Functions (must be provided by derived class)
00440         *************************************************************************/
00450         virtual void    sizeToContent_impl(void);
00451 
00452 
00460         virtual Size getContentSize() const             = 0;
00461 
00462 
00472         //virtual       Rect    getItemRenderArea_impl(void) const              = 0;
00473 
00474 
00482         virtual void    layoutItemWidgets()     = 0;
00483 
00484 
00485         /*************************************************************************
00486                 Implementation Functions
00487         *************************************************************************/
00499         bool    resetList_impl(void);
00500 
00511         virtual bool    testClassName_impl(const String& class_name) const
00512         {
00513                 if (class_name=="ItemListBase") return true;
00514                 return Window::testClassName_impl(class_name);
00515         }
00516 
00517     // validate window renderer
00518     virtual bool    validateWindowRenderer(const String& name) const
00519     {
00520         return (name == EventNamespace);
00521     }
00522 
00527     SortCallback getRealSortCallback(void) const;
00528 
00529         /*************************************************************************
00530                 New event handlers
00531         *************************************************************************/
00536         virtual void    onListContentsChanged(WindowEventArgs& e);
00537 
00542     virtual void onSortEnabledChanged(WindowEventArgs& e);
00543 
00548     virtual void onSortModeChanged(WindowEventArgs& e);
00549 
00550         /*************************************************************************
00551                 Overridden Event handlers
00552         *************************************************************************/
00553         //virtual void    onChildRemoved(WindowEventArgs& e);
00554     //virtual void    onDestructionStarted(WindowEventArgs& e);
00555 
00556 
00557         /*************************************************************************
00558                 Implementation Data
00559         *************************************************************************/
00560         typedef std::vector<ItemEntry*> ItemEntryList;
00561         ItemEntryList   d_listItems;            
00562 
00564         bool d_autoResize;
00565 
00567     Window* d_pane;
00568 
00570     bool d_sortEnabled;
00572     SortMode d_sortMode;
00574     SortCallback d_sortCallback;
00576     bool d_resort;
00577 
00578 private:
00579         /*************************************************************************
00580         Static Properties for this class
00581         *************************************************************************/
00582         static ItemListBaseProperties::AutoResizeEnabled        d_autoResizeEnabledProperty;
00583     static ItemListBaseProperties::SortEnabled d_sortEnabledProperty;
00584     static ItemListBaseProperties::SortMode d_sortModeProperty;
00585 
00586         /*************************************************************************
00587                 Private methods
00588         *************************************************************************/
00589         void    addItemListBaseProperties(void);
00590 
00591 
00596         virtual void    addChild_impl(Window* wnd);
00597 
00603     bool handle_PaneChildRemoved(const EventArgs& e);
00604 };
00605 
00606 } // End of  CEGUI namespace section
00607 
00608 
00609 #if defined(_MSC_VER)
00610 #       pragma warning(pop)
00611 #endif
00612 
00613 #endif  // end of guard _CEGUIItemListBase_h_

Generated on Sat Jun 28 14:35:44 2008 for Crazy Eddies GUI System by  doxygen 1.5.4