Crazy Eddies GUI System
0.7.6
|
00001 /*********************************************************************** 00002 filename: CEGUITree.h 00003 created: 5-13-07 00004 author: Jonathan Welch (Based on Code by David Durant) 00005 *************************************************************************/ 00006 /*************************************************************************** 00007 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00008 * 00009 * Permission is hereby granted, free of charge, to any person obtaining 00010 * a copy of this software and associated documentation files (the 00011 * "Software"), to deal in the Software without restriction, including 00012 * without limitation the rights to use, copy, modify, merge, publish, 00013 * distribute, sublicense, and/or sell copies of the Software, and to 00014 * permit persons to whom the Software is furnished to do so, subject to 00015 * the following conditions: 00016 * 00017 * The above copyright notice and this permission notice shall be 00018 * included in all copies or substantial portions of the Software. 00019 * 00020 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00021 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00022 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00023 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00024 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00025 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00026 * OTHER DEALINGS IN THE SOFTWARE. 00027 ***************************************************************************/ 00028 #ifndef _CEGUITree_h_ 00029 #define _CEGUITree_h_ 00030 00031 #include "../CEGUIBase.h" 00032 #include "../CEGUIWindow.h" 00033 #include "../CEGUIWindowManager.h" 00034 #include "CEGUITreeItem.h" 00035 #include "CEGUITreeProperties.h" 00036 #include <vector> 00037 00038 #if defined(_MSC_VER) 00039 # pragma warning(push) 00040 # pragma warning(disable : 4251) 00041 #endif 00042 00043 // Start of CEGUI namespace section 00044 namespace CEGUI 00045 { 00051 class CEGUIEXPORT TreeEventArgs : public WindowEventArgs 00052 { 00053 public: 00054 TreeEventArgs(Window* wnd) : WindowEventArgs(wnd) 00055 { treeItem = 0; } 00056 00057 TreeItem *treeItem; 00058 }; 00059 00060 00075 class CEGUIEXPORT Tree : public Window 00076 { 00077 friend class TreeItem; 00078 typedef std::vector<TreeItem*> LBItemList; 00079 00080 public: 00082 static const String EventNamespace; 00083 static const String WidgetTypeName; 00084 00085 /************************************************************************* 00086 Constants 00087 *************************************************************************/ 00088 // event names 00093 static const String EventListContentsChanged; 00100 static const String EventSelectionChanged; 00106 static const String EventSortModeChanged; 00112 static const String EventMultiselectModeChanged; 00119 static const String EventVertScrollbarModeChanged; 00126 static const String EventHorzScrollbarModeChanged; 00133 static const String EventBranchOpened; 00140 static const String EventBranchClosed; 00141 00142 //Render the actual tree 00143 void doTreeRender() 00144 { populateGeometryBuffer(); } 00145 00146 //UpdateScrollbars 00147 void doScrollbars() 00148 { configureScrollbars(); } 00149 00150 /************************************************************************* 00151 Accessor Methods 00152 *************************************************************************/ 00160 size_t getItemCount(void) const 00161 { return d_listItems.size(); } 00162 00170 size_t getSelectedCount(void) const; 00171 00180 TreeItem* getFirstSelectedItem(void) const; 00181 00191 TreeItem* getLastSelectedItem(void) const 00192 { return d_lastSelected; } 00193 00211 TreeItem* getNextSelected(const TreeItem* start_item) const; 00212 00213 TreeItem* getNextSelectedItemFromList(const LBItemList &itemList, 00214 const TreeItem* start_item, 00215 bool& foundStartItem) const; 00216 00225 bool isSortEnabled(void) const 00226 { return d_sorted; } 00227 00228 void setItemRenderArea(Rect& r) 00229 { d_itemArea = r; } 00230 00231 Scrollbar* getVertScrollbar() 00232 { return d_vertScrollbar; } 00233 00234 Scrollbar* getHorzScrollbar() 00235 { return d_horzScrollbar; } 00236 00244 bool isMultiselectEnabled(void) const 00245 { return d_multiselect; } 00246 00247 bool isItemTooltipsEnabled(void) const 00248 { return d_itemTooltips; } 00249 00269 TreeItem* findFirstItemWithText(const String& text); 00270 00271 TreeItem* findNextItemWithText(const String& text, 00272 const TreeItem* start_item); 00273 00274 TreeItem* findItemWithTextFromList(const LBItemList &itemList, 00275 const String& text, 00276 const TreeItem* start_item, 00277 bool foundStartItem); 00278 00298 TreeItem* findFirstItemWithID(uint searchID); 00299 TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item); 00300 TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID, 00301 const TreeItem* start_item, 00302 bool foundStartItem); 00303 00312 bool isTreeItemInList(const TreeItem* item) const; 00313 00322 bool isVertScrollbarAlwaysShown(void) const; 00323 00332 bool isHorzScrollbarAlwaysShown(void) const; 00333 00334 /************************************************************************* 00335 Manipulator Methods 00336 *************************************************************************/ 00348 virtual void initialise(void); 00349 00356 void resetList(void); 00357 00370 void addItem(TreeItem* item); 00371 00395 void insertItem(TreeItem* item, const TreeItem* position); 00396 00409 void removeItem(const TreeItem* item); 00410 00418 void clearAllSelections(void); 00419 bool clearAllSelectionsFromList(const LBItemList &itemList); 00420 00432 void setSortingEnabled(bool setting); 00433 00446 void setMultiselectEnabled(bool setting); 00447 00461 void setShowVertScrollbar(bool setting); 00462 00476 void setShowHorzScrollbar(bool setting); 00477 00478 void setItemTooltipsEnabled(bool setting); 00479 00503 void setItemSelectState(TreeItem* item, bool state); 00504 00528 void setItemSelectState(size_t item_index, bool state); 00529 00547 virtual void setLookNFeel(const String& look); 00548 00562 void handleUpdatedItemData(void); 00563 00577 void ensureItemIsVisible(const TreeItem* item); 00578 00579 00580 /************************************************************************* 00581 Construction and Destruction 00582 *************************************************************************/ 00587 Tree(const String& type, const String& name); 00588 00593 virtual ~Tree(void); 00594 00595 protected: 00596 /************************************************************************* 00597 Abstract Implementation Functions (must be provided by derived class) 00598 *************************************************************************/ 00608 virtual Rect getTreeRenderArea(void) const 00609 { return d_itemArea; } 00610 00622 virtual Scrollbar* createVertScrollbar(const String& name) const 00623 { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); } 00624 00636 virtual Scrollbar* createHorzScrollbar(const String& name) const 00637 { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); } 00638 00649 virtual void cacheTreeBaseImagery() 00650 {} 00651 00652 /************************************************************************* 00653 Implementation Functions 00654 *************************************************************************/ 00659 bool containsOpenItemRecursive(const LBItemList& itemList, TreeItem* item); 00660 00665 void addTreeEvents(void); 00666 00667 00673 void configureScrollbars(void); 00674 00680 void selectRange(size_t start, size_t end); 00681 00686 float getTotalItemsHeight(void) const; 00687 void getTotalItemsInListHeight(const LBItemList &itemList, 00688 float *heightSum) const; 00689 00694 float getWidestItemWidth(void) const; 00695 void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth, 00696 float *widest) const; 00697 00706 bool getHeightToItemInList(const LBItemList &itemList, 00707 const TreeItem *treeItem, 00708 int itemDepth, 00709 float *height) const; 00710 00719 bool clearAllSelections_impl(void); 00720 00729 TreeItem* getItemAtPoint(const Point& pt) const; 00730 TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY, 00731 const Point& pt) const; 00732 00744 bool resetList_impl(void); 00745 00757 virtual bool testClassName_impl(const String& class_name) const 00758 { 00759 if (class_name==(const utf8*)"Tree") 00760 return true; 00761 00762 return Window::testClassName_impl(class_name); 00763 } 00764 00770 bool handle_scrollChange(const EventArgs& args); 00771 00772 // overridden from Window base class. 00773 virtual void populateGeometryBuffer(); 00774 00775 void drawItemList(LBItemList& itemList, Rect& itemsArea, float widest, 00776 Vector2& itemPos, GeometryBuffer& geometry, float alpha); 00777 00778 /************************************************************************* 00779 New event handlers 00780 *************************************************************************/ 00785 virtual void onListContentsChanged(WindowEventArgs& e); 00786 00792 virtual void onSelectionChanged(TreeEventArgs& e); 00793 00798 virtual void onSortModeChanged(WindowEventArgs& e); 00799 00804 virtual void onMultiselectModeChanged(WindowEventArgs& e); 00805 00811 virtual void onVertScrollbarModeChanged(WindowEventArgs& e); 00812 00818 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e); 00819 00824 virtual void onBranchOpened(TreeEventArgs& e); 00825 00830 virtual void onBranchClosed(TreeEventArgs& e); 00831 00832 /************************************************************************* 00833 Overridden Event handlers 00834 *************************************************************************/ 00835 virtual void onSized(WindowEventArgs& e); 00836 virtual void onMouseButtonDown(MouseEventArgs& e); 00837 virtual void onMouseWheel(MouseEventArgs& e); 00838 virtual void onMouseMove(MouseEventArgs& e); 00839 00840 /************************************************************************* 00841 Implementation Data 00842 *************************************************************************/ 00844 bool d_sorted; 00846 bool d_multiselect; 00848 bool d_forceVertScroll; 00850 bool d_forceHorzScroll; 00852 bool d_itemTooltips; 00854 Scrollbar* d_vertScrollbar; 00856 Scrollbar* d_horzScrollbar; 00858 LBItemList d_listItems; 00860 TreeItem* d_lastSelected; 00861 ImagerySection* d_openButtonImagery; 00862 ImagerySection* d_closeButtonImagery; 00863 00864 private: 00865 /************************************************************************* 00866 Static Properties for this class 00867 *************************************************************************/ 00868 static TreeProperties::Sort d_sortProperty; 00869 static TreeProperties::MultiSelect d_multiSelectProperty; 00870 static TreeProperties::ForceVertScrollbar d_forceVertProperty; 00871 static TreeProperties::ForceHorzScrollbar d_forceHorzProperty; 00872 static TreeProperties::ItemTooltips d_itemTooltipsProperty; 00873 00874 /************************************************************************* 00875 Private methods 00876 *************************************************************************/ 00877 void addTreeProperties(void); 00878 Rect d_itemArea; 00879 }; 00880 00886 bool lbi_less(const TreeItem* a, const TreeItem* b); 00887 00888 00894 bool lbi_greater(const TreeItem* a, const TreeItem* b); 00895 00896 } // End of CEGUI namespace section 00897 00898 00899 #if defined(_MSC_VER) 00900 # pragma warning(pop) 00901 #endif 00902 00903 #endif // end of guard _CEGUITree_h_