CEGUIListbox.h

00001 /***********************************************************************
00002         filename:       CEGUIListbox.h
00003         created:        13/4/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Interface to base class for Listbox widget
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 _CEGUIListbox_h_
00031 #define _CEGUIListbox_h_
00032 
00033 #include "CEGUIBase.h"
00034 #include "CEGUIWindow.h"
00035 #include "elements/CEGUIListboxProperties.h"
00036 #include <vector>
00037 
00038 
00039 #if defined(_MSC_VER)
00040 #       pragma warning(push)
00041 #       pragma warning(disable : 4251)
00042 #endif
00043 
00044 
00045 // Start of CEGUI namespace section
00046 namespace CEGUI
00047 {
00048 
00053 class CEGUIEXPORT ListboxWindowRenderer : public WindowRenderer
00054 {
00055 public:
00060     ListboxWindowRenderer(const String& name);
00061 
00071     virtual Rect getListRenderArea(void) const = 0;
00072 };
00073 
00078 class CEGUIEXPORT Listbox : public Window
00079 {
00080 public:
00081         static const String EventNamespace;                             
00082     static const String WidgetTypeName;             
00083 
00084         /*************************************************************************
00085                 Constants
00086         *************************************************************************/
00087         // event names
00088         static const String EventListContentsChanged;                   
00089         static const String EventSelectionChanged;                      
00090         static const String EventSortModeChanged;                               
00091         static const String EventMultiselectModeChanged;                
00092         static const String EventVertScrollbarModeChanged;      
00093         static const String EventHorzScrollbarModeChanged;      
00094 
00095     /*************************************************************************
00096         Child Widget name suffix constants
00097     *************************************************************************/
00098     static const String VertScrollbarNameSuffix;   
00099     static const String HorzScrollbarNameSuffix;   
00100 
00101         /*************************************************************************
00102                 Accessor Methods
00103         *************************************************************************/
00111         size_t  getItemCount(void) const                {return d_listItems.size();}
00112 
00113         
00121         size_t  getSelectedCount(void) const;
00122 
00123 
00132         ListboxItem*    getFirstSelectedItem(void) const;
00133 
00134 
00149         ListboxItem*    getNextSelected(const ListboxItem* start_item) const;
00150 
00151 
00164         ListboxItem*    getListboxItemFromIndex(size_t index) const;
00165 
00166 
00179         size_t  getItemIndex(const ListboxItem* item) const;
00180 
00181 
00189         bool    isSortEnabled(void) const               {return d_sorted;}
00190 
00198         bool    isMultiselectEnabled(void) const        {return d_multiselect;}
00199 
00200         bool    isItemTooltipsEnabled(void) const       {return d_itemTooltips;}
00201 
00214         bool    isItemSelected(size_t index) const;
00215 
00216 
00234         ListboxItem*    findItemWithText(const String& text, const ListboxItem* start_item);
00235 
00236 
00244         bool    isListboxItemInList(const ListboxItem* item) const;
00245 
00246 
00255         bool    isVertScrollbarAlwaysShown(void) const;
00256 
00257 
00266         bool    isHorzScrollbarAlwaysShown(void) const;
00267 
00268 
00269         /*************************************************************************
00270                 Manipulator Methods
00271         *************************************************************************/
00282         virtual void    initialiseComponents(void);
00283 
00284 
00291         void    resetList(void);
00292 
00293 
00305         void    addItem(ListboxItem* item);
00306 
00307 
00327         void    insertItem(ListboxItem* item, const ListboxItem* position);
00328 
00329 
00341         void    removeItem(const ListboxItem* item);
00342 
00343 
00351         void    clearAllSelections(void);
00352 
00353 
00364         void    setSortingEnabled(bool setting);
00365 
00366         
00378         void    setMultiselectEnabled(bool setting);
00379 
00380 
00392         void    setShowVertScrollbar(bool setting);
00393 
00394 
00406         void    setShowHorzScrollbar(bool setting);
00407 
00408         void    setItemTooltipsEnabled(bool setting);
00428         void    setItemSelectState(ListboxItem* item, bool state);
00429 
00430 
00450         void    setItemSelectState(size_t item_index, bool state);
00451 
00452 
00465         void    handleUpdatedItemData(void);
00466 
00467 
00479         void    ensureItemIsVisible(size_t item_index);
00480 
00481 
00494         void    ensureItemIsVisible(const ListboxItem* item);
00495 
00496 
00506     virtual Rect    getListRenderArea(void) const;
00507 
00508 
00520     Scrollbar* getVertScrollbar() const;
00521 
00533     Scrollbar* getHorzScrollbar() const;
00534 
00535 
00540     float   getTotalItemsHeight(void) const;
00541 
00542 
00547     float   getWidestItemWidth(void) const;
00548 
00549 
00550         /*************************************************************************
00551                 Construction and Destruction
00552         *************************************************************************/
00557         Listbox(const String& type, const String& name);
00558 
00559 
00564         virtual ~Listbox(void);
00565 
00566 
00567 protected:
00568         /*************************************************************************
00569                 Abstract Implementation Functions (must be provided by derived class)
00570         *************************************************************************/
00580         //virtual       Rect    getListRenderArea_impl(void) const = 0;
00581 
00582 
00583         /*************************************************************************
00584                 Implementation Functions
00585         *************************************************************************/
00590         void    configureScrollbars(void);
00591 
00597         void    selectRange(size_t start, size_t end);
00598 
00599 
00607         bool    clearAllSelections_impl(void);
00608 
00609 
00618         ListboxItem*    getItemAtPoint(const Point& pt) const;
00619 
00620 
00632         bool    resetList_impl(void);
00633 
00634 
00645         virtual bool    testClassName_impl(const String& class_name) const
00646         {
00647                 if (class_name=="Listbox")      return true;
00648                 return Window::testClassName_impl(class_name);
00649         }
00650 
00655     bool handle_scrollChange(const EventArgs& args);
00656 
00657 
00658     // validate window renderer
00659     virtual bool validateWindowRenderer(const String& name) const
00660     {
00661         return (name == "Listbox");
00662     }
00663 
00664 
00665         /*************************************************************************
00666                 New event handlers
00667         *************************************************************************/
00672         virtual void    onListContentsChanged(WindowEventArgs& e);
00673 
00674 
00679         virtual void    onSelectionChanged(WindowEventArgs& e);
00680 
00681 
00686         virtual void    onSortModeChanged(WindowEventArgs& e);
00687 
00688 
00693         virtual void    onMultiselectModeChanged(WindowEventArgs& e);
00694 
00695 
00700         virtual void    onVertScrollbarModeChanged(WindowEventArgs& e);
00701 
00702 
00707         virtual void    onHorzScrollbarModeChanged(WindowEventArgs& e);
00708 
00709 
00710         /*************************************************************************
00711                 Overridden Event handlers
00712         *************************************************************************/
00713         virtual void    onSized(WindowEventArgs& e);
00714         virtual void    onMouseButtonDown(MouseEventArgs& e);
00715         virtual void    onMouseWheel(MouseEventArgs& e);
00716         virtual void    onMouseMove(MouseEventArgs& e);
00717 
00718 
00719         /*************************************************************************
00720                 Implementation Data
00721         *************************************************************************/
00722         typedef std::vector<ListboxItem*>       LBItemList;
00723         bool    d_sorted;                               
00724         bool    d_multiselect;                  
00725         bool    d_forceVertScroll;              
00726         bool    d_forceHorzScroll;              
00727         bool    d_itemTooltips;                 
00728         LBItemList      d_listItems;            
00729         ListboxItem*    d_lastSelected; 
00730 
00731     friend class ListboxWindowRenderer;
00732 
00733 private:
00734         /*************************************************************************
00735                 Static Properties for this class
00736         *************************************************************************/
00737         static ListboxProperties::Sort                                  d_sortProperty;
00738         static ListboxProperties::MultiSelect                   d_multiSelectProperty;
00739         static ListboxProperties::ForceVertScrollbar    d_forceVertProperty;
00740         static ListboxProperties::ForceHorzScrollbar    d_forceHorzProperty;
00741         static ListboxProperties::ItemTooltips                  d_itemTooltipsProperty;
00742 
00743         /*************************************************************************
00744                 Private methods
00745         *************************************************************************/
00746         void    addListboxProperties(void);
00747 };
00748 
00749 
00755 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
00756 
00757 
00763 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
00764 
00765 } // End of  CEGUI namespace section
00766 
00767 
00768 #if defined(_MSC_VER)
00769 #       pragma warning(pop)
00770 #endif
00771 
00772 #endif  // end of guard _CEGUIListbox_h_

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