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     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #ifndef _CEGUIListbox_h_
00027 #define _CEGUIListbox_h_
00028 
00029 #include "CEGUIBase.h"
00030 #include "CEGUIWindow.h"
00031 #include "elements/CEGUIListboxProperties.h"
00032 #include <vector>
00033 
00034 
00035 #if defined(_MSC_VER)
00036 #       pragma warning(push)
00037 #       pragma warning(disable : 4251)
00038 #endif
00039 
00040 
00041 // Start of CEGUI namespace section
00042 namespace CEGUI
00043 {
00044 
00049 class CEGUIEXPORT Listbox : public Window
00050 {
00051 public:
00052         static const String EventNamespace;                             
00053 
00054 
00055         /*************************************************************************
00056                 Constants
00057         *************************************************************************/
00058         // event names
00059         static const String EventListContentsChanged;                   
00060         static const String EventSelectionChanged;                      
00061         static const String EventSortModeChanged;                               
00062         static const String EventMultiselectModeChanged;                
00063         static const String EventVertScrollbarModeChanged;      
00064         static const String EventHorzScrollbarModeChanged;      
00065 
00066 
00067         /*************************************************************************
00068                 Accessor Methods
00069         *************************************************************************/
00077         size_t  getItemCount(void) const                {return d_listItems.size();}
00078 
00079         
00087         size_t  getSelectedCount(void) const;
00088 
00089 
00098         ListboxItem*    getFirstSelectedItem(void) const;
00099 
00100 
00115         ListboxItem*    getNextSelected(const ListboxItem* start_item) const;
00116 
00117 
00130         ListboxItem*    getListboxItemFromIndex(size_t index) const;
00131 
00132 
00145         size_t  getItemIndex(const ListboxItem* item) const;
00146 
00147 
00155         bool    isSortEnabled(void) const               {return d_sorted;}
00156 
00164         bool    isMultiselectEnabled(void) const        {return d_multiselect;}
00165 
00166         bool    isItemTooltipsEnabled(void) const       {return d_itemTooltips;}
00167 
00180         bool    isItemSelected(size_t index) const;
00181 
00182 
00200         ListboxItem*    findItemWithText(const String& text, const ListboxItem* start_item);
00201 
00202 
00210         bool    isListboxItemInList(const ListboxItem* item) const;
00211 
00212 
00221         bool    isVertScrollbarAlwaysShown(void) const;
00222 
00223 
00232         bool    isHorzScrollbarAlwaysShown(void) const;
00233 
00234 
00235         /*************************************************************************
00236                 Manipulator Methods
00237         *************************************************************************/
00248         virtual void    initialise(void);
00249 
00250 
00257         void    resetList(void);
00258 
00259 
00271         void    addItem(ListboxItem* item);
00272 
00273 
00293         void    insertItem(ListboxItem* item, const ListboxItem* position);
00294 
00295 
00307         void    removeItem(const ListboxItem* item);
00308 
00309 
00317         void    clearAllSelections(void);
00318 
00319 
00330         void    setSortingEnabled(bool setting);
00331 
00332         
00344         void    setMultiselectEnabled(bool setting);
00345 
00346 
00358         void    setShowVertScrollbar(bool setting);
00359 
00360 
00372         void    setShowHorzScrollbar(bool setting);
00373 
00374         void    setItemTooltipsEnabled(bool setting);
00394         void    setItemSelectState(ListboxItem* item, bool state);
00395 
00396 
00416         void    setItemSelectState(size_t item_index, bool state);
00417 
00418 
00431         void    handleUpdatedItemData(void);
00432 
00433 
00445         void    ensureItemIsVisible(size_t item_index);
00446 
00447 
00460         void    ensureItemIsVisible(const ListboxItem* item);
00461 
00462 
00463         /*************************************************************************
00464                 Construction and Destruction
00465         *************************************************************************/
00470         Listbox(const String& type, const String& name);
00471 
00472 
00477         virtual ~Listbox(void);
00478 
00479 
00480 protected:
00481         /*************************************************************************
00482                 Abstract Implementation Functions (must be provided by derived class)
00483         *************************************************************************/
00493         virtual Rect    getListRenderArea(void) const           = 0;
00494 
00495 
00506         virtual Scrollbar*      createVertScrollbar(const String& name) const           = 0;
00507  
00508 
00519         virtual Scrollbar*      createHorzScrollbar(const String& name) const           = 0;
00520 
00521 
00532         virtual void cacheListboxBaseImagery() = 0;
00533 
00534 
00535         /*************************************************************************
00536                 Implementation Functions
00537         *************************************************************************/
00542         void    addListboxEvents(void);
00543 
00544 
00549         void    configureScrollbars(void);
00550 
00556         void    selectRange(size_t start, size_t end);
00557 
00558 
00563         float   getTotalItemsHeight(void) const;
00564 
00565 
00570         float   getWidestItemWidth(void) const;
00571 
00572 
00580         bool    clearAllSelections_impl(void);
00581 
00582 
00591         ListboxItem*    getItemAtPoint(const Point& pt) const;
00592 
00593 
00605         bool    resetList_impl(void);
00606 
00607 
00618         virtual bool    testClassName_impl(const String& class_name) const
00619         {
00620                 if (class_name==(const utf8*)"Listbox") return true;
00621                 return Window::testClassName_impl(class_name);
00622         }
00623 
00628     bool handle_scrollChange(const EventArgs& args);
00629 
00630     // overridden from Window base class.
00631     void populateRenderCache();
00632 
00633 
00634         /*************************************************************************
00635                 New event handlers
00636         *************************************************************************/
00641         virtual void    onListContentsChanged(WindowEventArgs& e);
00642 
00643 
00648         virtual void    onSelectionChanged(WindowEventArgs& e);
00649 
00650 
00655         virtual void    onSortModeChanged(WindowEventArgs& e);
00656 
00657 
00662         virtual void    onMultiselectModeChanged(WindowEventArgs& e);
00663 
00664 
00669         virtual void    onVertScrollbarModeChanged(WindowEventArgs& e);
00670 
00671 
00676         virtual void    onHorzScrollbarModeChanged(WindowEventArgs& e);
00677 
00678 
00679         /*************************************************************************
00680                 Overridden Event handlers
00681         *************************************************************************/
00682         virtual void    onSized(WindowEventArgs& e);
00683         virtual void    onMouseButtonDown(MouseEventArgs& e);
00684         virtual void    onMouseWheel(MouseEventArgs& e);
00685         virtual void    onMouseMove(MouseEventArgs& e);
00686 
00687 
00688         /*************************************************************************
00689                 Implementation Data
00690         *************************************************************************/
00691         typedef std::vector<ListboxItem*>       LBItemList;
00692         bool    d_sorted;                               
00693         bool    d_multiselect;                  
00694         bool    d_forceVertScroll;              
00695         bool    d_forceHorzScroll;              
00696         bool    d_itemTooltips;                 
00697         Scrollbar*      d_vertScrollbar;        
00698         Scrollbar*      d_horzScrollbar;        
00699         LBItemList      d_listItems;            
00700         ListboxItem*    d_lastSelected; 
00701 
00702 
00703 private:
00704         /*************************************************************************
00705                 Static Properties for this class
00706         *************************************************************************/
00707         static ListboxProperties::Sort                                  d_sortProperty;
00708         static ListboxProperties::MultiSelect                   d_multiSelectProperty;
00709         static ListboxProperties::ForceVertScrollbar    d_forceVertProperty;
00710         static ListboxProperties::ForceHorzScrollbar    d_forceHorzProperty;
00711         static ListboxProperties::ItemTooltips                  d_itemTooltipsProperty;
00712 
00713         /*************************************************************************
00714                 Private methods
00715         *************************************************************************/
00716         void    addListboxProperties(void);
00717 };
00718 
00719 
00725 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
00726 
00727 
00733 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
00734 
00735 } // End of  CEGUI namespace section
00736 
00737 
00738 #if defined(_MSC_VER)
00739 #       pragma warning(pop)
00740 #endif
00741 
00742 #endif  // end of guard _CEGUIListbox_h_

Generated on Sat Nov 26 09:34:48 2005 for Crazy Eddies GUI System by  doxygen 1.4.5