Crazy Eddie's GUI System  0.8.4
Listbox.h
00001 /***********************************************************************
00002         created:        13/4/2004
00003         author:         Paul D Turner
00004 
00005         purpose:        Interface to base class for Listbox widget
00006 *************************************************************************/
00007 /***************************************************************************
00008  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00009  *
00010  *   Permission is hereby granted, free of charge, to any person obtaining
00011  *   a copy of this software and associated documentation files (the
00012  *   "Software"), to deal in the Software without restriction, including
00013  *   without limitation the rights to use, copy, modify, merge, publish,
00014  *   distribute, sublicense, and/or sell copies of the Software, and to
00015  *   permit persons to whom the Software is furnished to do so, subject to
00016  *   the following conditions:
00017  *
00018  *   The above copyright notice and this permission notice shall be
00019  *   included in all copies or substantial portions of the Software.
00020  *
00021  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00022  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00023  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00024  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00025  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00026  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00027  *   OTHER DEALINGS IN THE SOFTWARE.
00028  ***************************************************************************/
00029 #ifndef _CEGUIListbox_h_
00030 #define _CEGUIListbox_h_
00031 
00032 #include "../Base.h"
00033 #include "../Window.h"
00034 #include <vector>
00035 
00036 
00037 #if defined(_MSC_VER)
00038 #       pragma warning(push)
00039 #       pragma warning(disable : 4251)
00040 #endif
00041 
00042 
00043 // Start of CEGUI namespace section
00044 namespace CEGUI
00045 {
00046 
00051 class CEGUIEXPORT ListboxWindowRenderer : public WindowRenderer
00052 {
00053 public:
00058     ListboxWindowRenderer(const String& name);
00059 
00065     virtual Rectf getListRenderArea(void) const = 0;
00066 
00073     virtual void resizeListToContent(bool fit_width,
00074                                      bool fit_height) const = 0;
00075 };
00076 
00081 class CEGUIEXPORT Listbox : public Window
00082 {
00083 public:
00084         static const String EventNamespace;                             
00085     static const String WidgetTypeName;             
00086 
00087         /*************************************************************************
00088                 Constants
00089         *************************************************************************/
00090         // event names
00095         static const String EventListContentsChanged;
00102         static const String EventSelectionChanged;
00108         static const String EventSortModeChanged;
00114         static const String EventMultiselectModeChanged;
00121         static const String EventVertScrollbarModeChanged;
00128         static const String EventHorzScrollbarModeChanged;
00129 
00130     /*************************************************************************
00131         Child Widget name constants
00132     *************************************************************************/
00133     static const String VertScrollbarName;   
00134     static const String HorzScrollbarName;   
00135 
00136         /*************************************************************************
00137                 Accessor Methods
00138         *************************************************************************/
00146         size_t  getItemCount(void) const                {return d_listItems.size();}
00147 
00148 
00156         size_t  getSelectedCount(void) const;
00157 
00158 
00167         ListboxItem*    getFirstSelectedItem(void) const;
00168 
00169 
00184         ListboxItem*    getNextSelected(const ListboxItem* start_item) const;
00185 
00186 
00199         ListboxItem*    getListboxItemFromIndex(size_t index) const;
00200 
00201 
00214         size_t  getItemIndex(const ListboxItem* item) const;
00215 
00216 
00224         bool    isSortEnabled(void) const               {return d_sorted;}
00225 
00233         bool    isMultiselectEnabled(void) const        {return d_multiselect;}
00234 
00235         bool    isItemTooltipsEnabled(void) const       {return d_itemTooltips;}
00236 
00249         bool    isItemSelected(size_t index) const;
00250 
00251 
00269         ListboxItem*    findItemWithText(const String& text, const ListboxItem* start_item);
00270 
00271 
00279         bool    isListboxItemInList(const ListboxItem* item) const;
00280 
00281 
00290         bool    isVertScrollbarAlwaysShown(void) const;
00291 
00292 
00301         bool    isHorzScrollbarAlwaysShown(void) const;
00302 
00303 
00304         /*************************************************************************
00305                 Manipulator Methods
00306         *************************************************************************/
00317         virtual void    initialiseComponents(void);
00318 
00319 
00326         void    resetList(void);
00327 
00328 
00340         void    addItem(ListboxItem* item);
00341 
00342 
00366         void    insertItem(ListboxItem* item, const ListboxItem* position);
00367 
00368 
00380         void    removeItem(const ListboxItem* item);
00381 
00382 
00390         void    clearAllSelections(void);
00391 
00392 
00403         void    setSortingEnabled(bool setting);
00404 
00405 
00417         void    setMultiselectEnabled(bool setting);
00418 
00419 
00431         void    setShowVertScrollbar(bool setting);
00432 
00433 
00445         void    setShowHorzScrollbar(bool setting);
00446 
00447         void    setItemTooltipsEnabled(bool setting);
00467         void    setItemSelectState(ListboxItem* item, bool state);
00468 
00469 
00489         void    setItemSelectState(size_t item_index, bool state);
00490 
00491 
00504         void    handleUpdatedItemData(void);
00505 
00506 
00518         void    ensureItemIsVisible(size_t item_index);
00519 
00520 
00533         void    ensureItemIsVisible(const ListboxItem* item);
00534 
00535 
00545     virtual Rectf getListRenderArea(void) const;
00546 
00547 
00559     Scrollbar* getVertScrollbar() const;
00560 
00572     Scrollbar* getHorzScrollbar() const;
00573 
00574 
00579     float   getTotalItemsHeight(void) const;
00580 
00581 
00586     float   getWidestItemWidth(void) const;
00587 
00588 
00599     ListboxItem* getItemAtPoint(const Vector2f& pt) const;
00600 
00601 
00602         /*************************************************************************
00603                 Construction and Destruction
00604         *************************************************************************/
00609         Listbox(const String& type, const String& name);
00610 
00611 
00616         virtual ~Listbox(void);
00617 
00618 
00619 protected:
00620         /*************************************************************************
00621                 Abstract Implementation Functions (must be provided by derived class)
00622         *************************************************************************/
00632         //virtual       Rect    getListRenderArea_impl(void) const = 0;
00633 
00634 
00635         /*************************************************************************
00636                 Implementation Functions
00637         *************************************************************************/
00642         void    configureScrollbars(void);
00643 
00649         void    selectRange(size_t start, size_t end);
00650 
00651 
00659         bool    clearAllSelections_impl(void);
00660 
00661 
00673         bool    resetList_impl(void);
00674 
00679     bool handle_scrollChange(const EventArgs& args);
00680 
00681 
00682     // validate window renderer
00683     virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
00684 
00689     void resortList();
00690 
00691         /*************************************************************************
00692                 New event handlers
00693         *************************************************************************/
00698         virtual void    onListContentsChanged(WindowEventArgs& e);
00699 
00700 
00705         virtual void    onSelectionChanged(WindowEventArgs& e);
00706 
00707 
00712         virtual void    onSortModeChanged(WindowEventArgs& e);
00713 
00714 
00719         virtual void    onMultiselectModeChanged(WindowEventArgs& e);
00720 
00721 
00726         virtual void    onVertScrollbarModeChanged(WindowEventArgs& e);
00727 
00728 
00733         virtual void    onHorzScrollbarModeChanged(WindowEventArgs& e);
00734 
00735 
00736         /*************************************************************************
00737                 Overridden Event handlers
00738         *************************************************************************/
00739         virtual void    onSized(ElementEventArgs& e);
00740         virtual void    onMouseButtonDown(MouseEventArgs& e);
00741         virtual void    onMouseWheel(MouseEventArgs& e);
00742         virtual void    onMouseMove(MouseEventArgs& e);
00743 
00744 
00745         /*************************************************************************
00746                 Implementation Data
00747         *************************************************************************/
00748         typedef std::vector<ListboxItem*
00749         CEGUI_VECTOR_ALLOC(ListboxItem*)> LBItemList;
00750         bool    d_sorted;                               
00751         bool    d_multiselect;                  
00752         bool    d_forceVertScroll;              
00753         bool    d_forceHorzScroll;              
00754         bool    d_itemTooltips;                 
00755         LBItemList      d_listItems;            
00756         ListboxItem*    d_lastSelected; 
00757 
00758     friend class ListboxWindowRenderer;
00759 
00760 private:
00761 
00762         /*************************************************************************
00763                 Private methods
00764         *************************************************************************/
00765         void    addListboxProperties(void);
00766 };
00767 
00768 
00774 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
00775 
00776 
00782 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
00783 
00784 } // End of  CEGUI namespace section
00785 
00786 
00787 #if defined(_MSC_VER)
00788 #       pragma warning(pop)
00789 #endif
00790 
00791 #endif  // end of guard _CEGUIListbox_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends