Crazy Eddies GUI System
0.7.6
|
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 "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 00092 static const String EventListContentsChanged; 00099 static const String EventSelectionChanged; 00105 static const String EventSortModeChanged; 00111 static const String EventMultiselectModeChanged; 00118 static const String EventVertScrollbarModeChanged; 00125 static const String EventHorzScrollbarModeChanged; 00126 00127 /************************************************************************* 00128 Child Widget name suffix constants 00129 *************************************************************************/ 00130 static const String VertScrollbarNameSuffix; 00131 static const String HorzScrollbarNameSuffix; 00132 00133 /************************************************************************* 00134 Accessor Methods 00135 *************************************************************************/ 00143 size_t getItemCount(void) const {return d_listItems.size();} 00144 00145 00153 size_t getSelectedCount(void) const; 00154 00155 00164 ListboxItem* getFirstSelectedItem(void) const; 00165 00166 00181 ListboxItem* getNextSelected(const ListboxItem* start_item) const; 00182 00183 00196 ListboxItem* getListboxItemFromIndex(size_t index) const; 00197 00198 00211 size_t getItemIndex(const ListboxItem* item) const; 00212 00213 00221 bool isSortEnabled(void) const {return d_sorted;} 00222 00230 bool isMultiselectEnabled(void) const {return d_multiselect;} 00231 00232 bool isItemTooltipsEnabled(void) const {return d_itemTooltips;} 00233 00246 bool isItemSelected(size_t index) const; 00247 00248 00266 ListboxItem* findItemWithText(const String& text, const ListboxItem* start_item); 00267 00268 00276 bool isListboxItemInList(const ListboxItem* item) const; 00277 00278 00287 bool isVertScrollbarAlwaysShown(void) const; 00288 00289 00298 bool isHorzScrollbarAlwaysShown(void) const; 00299 00300 00301 /************************************************************************* 00302 Manipulator Methods 00303 *************************************************************************/ 00314 virtual void initialiseComponents(void); 00315 00316 00323 void resetList(void); 00324 00325 00337 void addItem(ListboxItem* item); 00338 00339 00363 void insertItem(ListboxItem* item, const ListboxItem* position); 00364 00365 00377 void removeItem(const ListboxItem* item); 00378 00379 00387 void clearAllSelections(void); 00388 00389 00400 void setSortingEnabled(bool setting); 00401 00402 00414 void setMultiselectEnabled(bool setting); 00415 00416 00428 void setShowVertScrollbar(bool setting); 00429 00430 00442 void setShowHorzScrollbar(bool setting); 00443 00444 void setItemTooltipsEnabled(bool setting); 00464 void setItemSelectState(ListboxItem* item, bool state); 00465 00466 00486 void setItemSelectState(size_t item_index, bool state); 00487 00488 00501 void handleUpdatedItemData(void); 00502 00503 00515 void ensureItemIsVisible(size_t item_index); 00516 00517 00530 void ensureItemIsVisible(const ListboxItem* item); 00531 00532 00542 virtual Rect getListRenderArea(void) const; 00543 00544 00556 Scrollbar* getVertScrollbar() const; 00557 00569 Scrollbar* getHorzScrollbar() const; 00570 00571 00576 float getTotalItemsHeight(void) const; 00577 00578 00583 float getWidestItemWidth(void) const; 00584 00585 00596 ListboxItem* getItemAtPoint(const Point& pt) const; 00597 00598 00599 /************************************************************************* 00600 Construction and Destruction 00601 *************************************************************************/ 00606 Listbox(const String& type, const String& name); 00607 00608 00613 virtual ~Listbox(void); 00614 00615 00616 protected: 00617 /************************************************************************* 00618 Abstract Implementation Functions (must be provided by derived class) 00619 *************************************************************************/ 00629 //virtual Rect getListRenderArea_impl(void) const = 0; 00630 00631 00632 /************************************************************************* 00633 Implementation Functions 00634 *************************************************************************/ 00639 void configureScrollbars(void); 00640 00646 void selectRange(size_t start, size_t end); 00647 00648 00656 bool clearAllSelections_impl(void); 00657 00658 00670 bool resetList_impl(void); 00671 00672 00683 virtual bool testClassName_impl(const String& class_name) const 00684 { 00685 if (class_name=="Listbox") return true; 00686 return Window::testClassName_impl(class_name); 00687 } 00688 00693 bool handle_scrollChange(const EventArgs& args); 00694 00695 00696 // validate window renderer 00697 virtual bool validateWindowRenderer(const String& name) const 00698 { 00699 return (name == "Listbox"); 00700 } 00701 00706 void resortList(); 00707 00708 /************************************************************************* 00709 New event handlers 00710 *************************************************************************/ 00715 virtual void onListContentsChanged(WindowEventArgs& e); 00716 00717 00722 virtual void onSelectionChanged(WindowEventArgs& e); 00723 00724 00729 virtual void onSortModeChanged(WindowEventArgs& e); 00730 00731 00736 virtual void onMultiselectModeChanged(WindowEventArgs& e); 00737 00738 00743 virtual void onVertScrollbarModeChanged(WindowEventArgs& e); 00744 00745 00750 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e); 00751 00752 00753 /************************************************************************* 00754 Overridden Event handlers 00755 *************************************************************************/ 00756 virtual void onSized(WindowEventArgs& e); 00757 virtual void onMouseButtonDown(MouseEventArgs& e); 00758 virtual void onMouseWheel(MouseEventArgs& e); 00759 virtual void onMouseMove(MouseEventArgs& e); 00760 00761 00762 /************************************************************************* 00763 Implementation Data 00764 *************************************************************************/ 00765 typedef std::vector<ListboxItem*> LBItemList; 00766 bool d_sorted; 00767 bool d_multiselect; 00768 bool d_forceVertScroll; 00769 bool d_forceHorzScroll; 00770 bool d_itemTooltips; 00771 LBItemList d_listItems; 00772 ListboxItem* d_lastSelected; 00773 00774 friend class ListboxWindowRenderer; 00775 00776 private: 00777 /************************************************************************* 00778 Static Properties for this class 00779 *************************************************************************/ 00780 static ListboxProperties::Sort d_sortProperty; 00781 static ListboxProperties::MultiSelect d_multiSelectProperty; 00782 static ListboxProperties::ForceVertScrollbar d_forceVertProperty; 00783 static ListboxProperties::ForceHorzScrollbar d_forceHorzProperty; 00784 static ListboxProperties::ItemTooltips d_itemTooltipsProperty; 00785 00786 /************************************************************************* 00787 Private methods 00788 *************************************************************************/ 00789 void addListboxProperties(void); 00790 }; 00791 00792 00798 bool lbi_less(const ListboxItem* a, const ListboxItem* b); 00799 00800 00806 bool lbi_greater(const ListboxItem* a, const ListboxItem* b); 00807 00808 } // End of CEGUI namespace section 00809 00810 00811 #if defined(_MSC_VER) 00812 # pragma warning(pop) 00813 #endif 00814 00815 #endif // end of guard _CEGUIListbox_h_