Crazy Eddie's GUI System  0.8.4
Tree.h
00001 /***********************************************************************
00002     created:    5-13-07
00003     author:             Jonathan Welch (Based on Code by David Durant)
00004  *************************************************************************/
00005 /***************************************************************************
00006  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00007  *
00008  *   Permission is hereby granted, free of charge, to any person obtaining
00009  *   a copy of this software and associated documentation files (the
00010  *   "Software"), to deal in the Software without restriction, including
00011  *   without limitation the rights to use, copy, modify, merge, publish,
00012  *   distribute, sublicense, and/or sell copies of the Software, and to
00013  *   permit persons to whom the Software is furnished to do so, subject to
00014  *   the following conditions:
00015  *
00016  *   The above copyright notice and this permission notice shall be
00017  *   included in all copies or substantial portions of the Software.
00018  *
00019  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00023  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00024  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  *   OTHER DEALINGS IN THE SOFTWARE.
00026  ***************************************************************************/
00027 #ifndef _CEGUITree_h_
00028 #define _CEGUITree_h_
00029 
00030 #include "../Base.h"
00031 #include "../Window.h"
00032 #include "../WindowManager.h"
00033 #include "./TreeItem.h"
00034 #include "./Scrollbar.h"
00035 #include <vector>
00036 
00037 #if defined(_MSC_VER)
00038 #       pragma warning(push)
00039 #       pragma warning(disable : 4251)
00040 #endif
00041 
00042 // Start of CEGUI namespace section
00043 namespace CEGUI
00044 {
00050 class CEGUIEXPORT TreeEventArgs : public WindowEventArgs
00051 {
00052 public:
00053     TreeEventArgs(Window* wnd) : WindowEventArgs(wnd)
00054         { treeItem = 0; }
00055 
00056     TreeItem *treeItem;
00057 };
00058 
00059 
00074 class CEGUIEXPORT Tree : public Window
00075 {
00076     friend class TreeItem;
00077 
00078     typedef     std::vector<TreeItem*
00079         CEGUI_VECTOR_ALLOC(TreeItem*)> LBItemList;
00080     
00081 public:
00083     static const String EventNamespace;
00084     static const String WidgetTypeName;
00085     
00086     /*************************************************************************
00087         Constants
00088      *************************************************************************/
00089     // event names
00094     static const String EventListContentsChanged;
00101     static const String EventSelectionChanged;
00107     static const String EventSortModeChanged;
00113     static const String EventMultiselectModeChanged;
00120     static const String EventVertScrollbarModeChanged;
00127     static const String EventHorzScrollbarModeChanged;
00134     static const String EventBranchOpened;
00141     static const String EventBranchClosed;
00142 
00143     //Render the actual tree
00144     void doTreeRender()
00145         { populateGeometryBuffer(); }
00146 
00147     //UpdateScrollbars
00148     void doScrollbars()
00149         { configureScrollbars(); }
00150 
00151     /*************************************************************************
00152         Accessor Methods
00153      *************************************************************************/
00161     size_t getItemCount(void) const
00162         { return d_listItems.size(); }
00163 
00171     size_t getSelectedCount(void) const;
00172 
00181     TreeItem* getFirstSelectedItem(void) const;
00182         
00192     TreeItem* getLastSelectedItem(void) const
00193         { return d_lastSelected; }
00194 
00212     TreeItem* getNextSelected(const TreeItem* start_item) const;
00213     
00214     TreeItem* getNextSelectedItemFromList(const LBItemList &itemList,
00215                                           const TreeItem* start_item,
00216                                           bool& foundStartItem) const;
00217 
00226     bool isSortEnabled(void) const
00227         { return d_sorted; }
00228     
00229     void setItemRenderArea(Rectf& r)
00230         { d_itemArea = r; }
00231     
00232     Scrollbar* getVertScrollbar()
00233         { return d_vertScrollbar; }
00234 
00235     Scrollbar* getHorzScrollbar()
00236         { return d_horzScrollbar; }
00237 
00245     bool isMultiselectEnabled(void) const
00246         { return d_multiselect; }
00247     
00248     bool isItemTooltipsEnabled(void) const
00249         { return d_itemTooltips; }
00250 
00270     TreeItem* findFirstItemWithText(const String& text);
00271 
00272     TreeItem* findNextItemWithText(const String& text,
00273                                    const TreeItem* start_item);
00274 
00275     TreeItem* findItemWithTextFromList(const LBItemList &itemList,
00276                                        const String& text,
00277                                        const TreeItem* start_item,
00278                                        bool foundStartItem);
00279 
00299     TreeItem* findFirstItemWithID(uint searchID);
00300     TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item);
00301     TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID,
00302                                      const TreeItem* start_item,
00303                                      bool foundStartItem);
00304 
00313     bool isTreeItemInList(const TreeItem* item) const;
00314 
00323     bool isVertScrollbarAlwaysShown(void) const;
00324 
00333     bool isHorzScrollbarAlwaysShown(void) const;
00334 
00335     /*************************************************************************
00336         Manipulator Methods
00337      *************************************************************************/
00349     virtual void initialise(void);
00350 
00357     void resetList(void);
00358 
00371     void addItem(TreeItem* item);
00372 
00396     void insertItem(TreeItem* item, const TreeItem* position);
00397 
00410     void removeItem(const TreeItem* item);
00411 
00419     void clearAllSelections(void);
00420     bool clearAllSelectionsFromList(const LBItemList &itemList);
00421 
00433     void setSortingEnabled(bool setting);
00434 
00447     void setMultiselectEnabled(bool setting);
00448 
00462     void setShowVertScrollbar(bool setting);
00463 
00477     void setShowHorzScrollbar(bool setting);
00478     
00479     void setItemTooltipsEnabled(bool setting);
00480 
00504     void setItemSelectState(TreeItem* item, bool state);
00505 
00529     void setItemSelectState(size_t item_index, bool state);
00530     
00548     virtual void setLookNFeel(const String& look);
00549     
00563     void handleUpdatedItemData(void);
00564 
00578     void ensureItemIsVisible(const TreeItem* item);
00579     
00580     
00581     /*************************************************************************
00582      Construction and Destruction
00583      *************************************************************************/
00588     Tree(const String& type, const String& name);
00589 
00594     virtual ~Tree(void);
00595 
00596 protected:
00597     /*************************************************************************
00598         Abstract Implementation Functions (must be provided by derived class)
00599      *************************************************************************/
00609     virtual     Rectf getTreeRenderArea(void) const
00610         { return d_itemArea; }
00611     
00623     virtual Scrollbar* createVertScrollbar(const String& name) const
00624         { return static_cast<Scrollbar*>(getChild(name)); }
00625 
00637     virtual Scrollbar* createHorzScrollbar(const String& name) const
00638         { return static_cast<Scrollbar*>(getChild(name)); }
00639 
00650     virtual     void cacheTreeBaseImagery()
00651     {}
00652     
00653     /*************************************************************************
00654         Implementation Functions
00655      *************************************************************************/
00660     bool containsOpenItemRecursive(const LBItemList& itemList, TreeItem* item);
00661 
00666     void addTreeEvents(void);
00667     
00668     
00674     void configureScrollbars(void);
00675     
00681     void selectRange(size_t start, size_t end);
00682     
00687     float getTotalItemsHeight(void) const;
00688     void getTotalItemsInListHeight(const LBItemList &itemList,
00689                                     float *heightSum) const;
00690 
00695     float getWidestItemWidth(void) const;
00696     void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth,
00697                                   float *widest) const;
00698     
00707     bool getHeightToItemInList(const LBItemList &itemList,
00708                                const TreeItem *treeItem,
00709                                int itemDepth,
00710                                float *height) const;
00711 
00720     bool clearAllSelections_impl(void);
00721 
00730     TreeItem* getItemAtPoint(const Vector2f& pt) const;
00731     TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY,
00732                                      const Vector2f& pt) const;
00733 
00745     bool resetList_impl(void);
00746     
00752     bool handle_scrollChange(const EventArgs& args);
00753     
00754     // overridden from Window base class.
00755     virtual void populateGeometryBuffer();
00756     bool handleFontRenderSizeChange(const EventArgs& args);
00757  
00758      void drawItemList(LBItemList& itemList, Rectf& itemsArea, float widest,
00759                        Vector2f& itemPos, GeometryBuffer& geometry, float alpha);
00760     
00761     /*************************************************************************
00762         New event handlers
00763      *************************************************************************/
00768     virtual     void onListContentsChanged(WindowEventArgs& e);
00769 
00775     virtual     void onSelectionChanged(TreeEventArgs& e);
00776 
00781     virtual     void onSortModeChanged(WindowEventArgs& e);
00782 
00787     virtual     void onMultiselectModeChanged(WindowEventArgs& e);
00788 
00794     virtual     void onVertScrollbarModeChanged(WindowEventArgs& e);
00795 
00801     virtual     void onHorzScrollbarModeChanged(WindowEventArgs& e);
00802     
00807     virtual     void onBranchOpened(TreeEventArgs& e);
00808     
00813     virtual     void onBranchClosed(TreeEventArgs& e);
00814     
00815     /*************************************************************************
00816         Overridden Event handlers
00817      *************************************************************************/
00818     virtual void onSized(ElementEventArgs& e);
00819     virtual void onMouseButtonDown(MouseEventArgs& e);
00820     virtual     void onMouseWheel(MouseEventArgs& e);
00821     virtual void onMouseMove(MouseEventArgs& e);
00822 
00823     /*************************************************************************
00824         Implementation Data
00825      *************************************************************************/
00827     bool d_sorted;
00829     bool d_multiselect;
00831     bool d_forceVertScroll;
00833     bool d_forceHorzScroll;
00835     bool d_itemTooltips;
00837     Scrollbar* d_vertScrollbar;
00839     Scrollbar* d_horzScrollbar;
00841     LBItemList d_listItems;
00843     TreeItem* d_lastSelected;
00844     const ImagerySection* d_openButtonImagery;
00845     const ImagerySection* d_closeButtonImagery;
00846 
00847 private:
00848     /*************************************************************************
00849         Private methods
00850      *************************************************************************/
00851     void addTreeProperties(void);
00852     Rectf d_itemArea;
00853 };
00854 
00860 bool lbi_less(const TreeItem* a, const TreeItem* b);
00861 
00862 
00868 bool lbi_greater(const TreeItem* a, const TreeItem* b);
00869 
00870 } // End of  CEGUI namespace section
00871 
00872 
00873 #if defined(_MSC_VER)
00874 #       pragma warning(pop)
00875 #endif
00876 
00877 #endif  // end of guard _CEGUITree_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends