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 
00331         void    insertItem(ListboxItem* item, const ListboxItem* position);
00332 
00333 
00345         void    removeItem(const ListboxItem* item);
00346 
00347 
00355         void    clearAllSelections(void);
00356 
00357 
00368         void    setSortingEnabled(bool setting);
00369 
00370 
00382         void    setMultiselectEnabled(bool setting);
00383 
00384 
00396         void    setShowVertScrollbar(bool setting);
00397 
00398 
00410         void    setShowHorzScrollbar(bool setting);
00411 
00412         void    setItemTooltipsEnabled(bool setting);
00432         void    setItemSelectState(ListboxItem* item, bool state);
00433 
00434 
00454         void    setItemSelectState(size_t item_index, bool state);
00455 
00456 
00469         void    handleUpdatedItemData(void);
00470 
00471 
00483         void    ensureItemIsVisible(size_t item_index);
00484 
00485 
00498         void    ensureItemIsVisible(const ListboxItem* item);
00499 
00500 
00510     virtual Rect    getListRenderArea(void) const;
00511 
00512 
00524     Scrollbar* getVertScrollbar() const;
00525 
00537     Scrollbar* getHorzScrollbar() const;
00538 
00539 
00544     float   getTotalItemsHeight(void) const;
00545 
00546 
00551     float   getWidestItemWidth(void) const;
00552 
00553 
00554         /*************************************************************************
00555                 Construction and Destruction
00556         *************************************************************************/
00561         Listbox(const String& type, const String& name);
00562 
00563 
00568         virtual ~Listbox(void);
00569 
00570 
00571 protected:
00572         /*************************************************************************
00573                 Abstract Implementation Functions (must be provided by derived class)
00574         *************************************************************************/
00584         //virtual       Rect    getListRenderArea_impl(void) const = 0;
00585 
00586 
00587         /*************************************************************************
00588                 Implementation Functions
00589         *************************************************************************/
00594         void    configureScrollbars(void);
00595 
00601         void    selectRange(size_t start, size_t end);
00602 
00603 
00611         bool    clearAllSelections_impl(void);
00612 
00613 
00622         ListboxItem*    getItemAtPoint(const Point& pt) const;
00623 
00624 
00636         bool    resetList_impl(void);
00637 
00638 
00649         virtual bool    testClassName_impl(const String& class_name) const
00650         {
00651                 if (class_name=="Listbox")      return true;
00652                 return Window::testClassName_impl(class_name);
00653         }
00654 
00659     bool handle_scrollChange(const EventArgs& args);
00660 
00661 
00662     // validate window renderer
00663     virtual bool validateWindowRenderer(const String& name) const
00664     {
00665         return (name == "Listbox");
00666     }
00667 
00672     void resortList();
00673 
00674         /*************************************************************************
00675                 New event handlers
00676         *************************************************************************/
00681         virtual void    onListContentsChanged(WindowEventArgs& e);
00682 
00683 
00688         virtual void    onSelectionChanged(WindowEventArgs& e);
00689 
00690 
00695         virtual void    onSortModeChanged(WindowEventArgs& e);
00696 
00697 
00702         virtual void    onMultiselectModeChanged(WindowEventArgs& e);
00703 
00704 
00709         virtual void    onVertScrollbarModeChanged(WindowEventArgs& e);
00710 
00711 
00716         virtual void    onHorzScrollbarModeChanged(WindowEventArgs& e);
00717 
00718 
00719         /*************************************************************************
00720                 Overridden Event handlers
00721         *************************************************************************/
00722         virtual void    onSized(WindowEventArgs& e);
00723         virtual void    onMouseButtonDown(MouseEventArgs& e);
00724         virtual void    onMouseWheel(MouseEventArgs& e);
00725         virtual void    onMouseMove(MouseEventArgs& e);
00726 
00727 
00728         /*************************************************************************
00729                 Implementation Data
00730         *************************************************************************/
00731         typedef std::vector<ListboxItem*>       LBItemList;
00732         bool    d_sorted;                               
00733         bool    d_multiselect;                  
00734         bool    d_forceVertScroll;              
00735         bool    d_forceHorzScroll;              
00736         bool    d_itemTooltips;                 
00737         LBItemList      d_listItems;            
00738         ListboxItem*    d_lastSelected; 
00739 
00740     friend class ListboxWindowRenderer;
00741 
00742 private:
00743         /*************************************************************************
00744                 Static Properties for this class
00745         *************************************************************************/
00746         static ListboxProperties::Sort                                  d_sortProperty;
00747         static ListboxProperties::MultiSelect                   d_multiSelectProperty;
00748         static ListboxProperties::ForceVertScrollbar    d_forceVertProperty;
00749         static ListboxProperties::ForceHorzScrollbar    d_forceHorzProperty;
00750         static ListboxProperties::ItemTooltips                  d_itemTooltipsProperty;
00751 
00752         /*************************************************************************
00753                 Private methods
00754         *************************************************************************/
00755         void    addListboxProperties(void);
00756 };
00757 
00758 
00764 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
00765 
00766 
00772 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
00773 
00774 } // End of  CEGUI namespace section
00775 
00776 
00777 #if defined(_MSC_VER)
00778 #       pragma warning(pop)
00779 #endif
00780 
00781 #endif  // end of guard _CEGUIListbox_h_

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