Crazy Eddies GUI System  0.7.6
CEGUIMultiColumnList.h
00001 /***********************************************************************
00002         filename:       CEGUIMultiColumnList.h
00003         created:        13/4/2004
00004         author:         Paul D Turner
00005 
00006         purpose:        Interface to base class for MultiColumnList 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 _CEGUIMultiColumnList_h_
00031 #define _CEGUIMultiColumnList_h_
00032 
00033 #include "../CEGUIBase.h"
00034 #include "../CEGUIWindow.h"
00035 #include "CEGUIListHeader.h"
00036 #include "CEGUIMultiColumnListProperties.h"
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 struct CEGUIEXPORT MCLGridRef
00054 {
00055         MCLGridRef(uint r, uint c) : row(r), column(c) {}
00056 
00057         uint    row;            
00058         uint    column;         
00059 
00060         // operators
00061         MCLGridRef& operator=(const MCLGridRef& rhs);
00062         bool operator<(const MCLGridRef& rhs) const;
00063         bool operator<=(const MCLGridRef& rhs) const;
00064         bool operator>(const MCLGridRef& rhs) const;
00065         bool operator>=(const MCLGridRef& rhs) const;
00066         bool operator==(const MCLGridRef& rhs) const;
00067         bool operator!=(const MCLGridRef& rhs) const;
00068 };
00069 
00074 class CEGUIEXPORT MultiColumnListWindowRenderer : public WindowRenderer
00075 {
00076 public:
00081     MultiColumnListWindowRenderer(const String& name);
00082 
00092     virtual Rect    getListRenderArea(void) const = 0;
00093 };
00094 
00099 class CEGUIEXPORT MultiColumnList : public Window
00100 {
00101 public:
00102         static const String EventNamespace;                             
00103     static const String WidgetTypeName;             
00104 
00105         /*************************************************************************
00106                 Constants
00107         *************************************************************************/
00108         // Event names
00114         static const String EventSelectionModeChanged;
00120         static const String EventNominatedSelectColumnChanged;
00126         static const String EventNominatedSelectRowChanged;
00132         static const String EventVertScrollbarModeChanged;
00138         static const String EventHorzScrollbarModeChanged;
00144         static const String EventSelectionChanged;
00150         static const String EventListContentsChanged;
00156         static const String EventSortColumnChanged;
00162         static const String EventSortDirectionChanged;
00168         static const String EventListColumnSized;
00174         static const String EventListColumnMoved;
00175 
00176     /*************************************************************************
00177         Child Widget name suffix constants
00178     *************************************************************************/
00179     static const String VertScrollbarNameSuffix;   
00180     static const String HorzScrollbarNameSuffix;   
00181     static const String ListHeaderNameSuffix;      
00182 
00183         /*************************************************************************
00184                 Enumerations
00185         *************************************************************************/
00190         enum SelectionMode
00191         {
00192                 RowSingle,                                      // Any single row may be selected.  All items in the row are selected.
00193                 RowMultiple,                            // Multiple rows may be selected.  All items in the row are selected.
00194                 CellSingle,                                     // Any single cell may be selected.
00195                 CellMultiple,                           // Multiple cells bay be selected.
00196                 NominatedColumnSingle,          // Any single item in a nominated column may be selected.
00197                 NominatedColumnMultiple,        // Multiple items in a nominated column may be selected.
00198                 ColumnSingle,                           // Any single column may be selected.  All items in the column are selected.
00199                 ColumnMultiple,                         // Multiple columns may be selected.  All items in the column are selected.
00200                 NominatedRowSingle,                     // Any single item in a nominated row may be selected.
00201                 NominatedRowMultiple            // Multiple items in a nominated row may be selected.
00202         };
00203 
00204 
00205         /*************************************************************************
00206                 Accessor Methods
00207         *************************************************************************/
00216         bool    isUserSortControlEnabled(void) const;
00217 
00218 
00226         bool    isUserColumnSizingEnabled(void) const;
00227 
00228 
00236         bool    isUserColumnDraggingEnabled(void) const;
00237 
00238 
00246         uint    getColumnCount(void) const;
00247 
00248 
00256         uint    getRowCount(void) const;
00257 
00258 
00269         uint    getSortColumn(void) const;
00270 
00271 
00284         uint    getColumnWithID(uint col_id) const;
00285 
00286 
00299         uint    getColumnWithHeaderText(const String& text) const;
00300 
00301 
00309         UDim getTotalColumnHeadersWidth(void) const;
00310 
00311 
00324         UDim getColumnHeaderWidth(uint col_idx) const;
00325 
00326 
00334         ListHeaderSegment::SortDirection        getSortDirection(void) const;
00335 
00336 
00349         ListHeaderSegment&      getHeaderSegmentForColumn(uint col_idx) const;
00350 
00351 
00364         uint    getItemRowIndex(const ListboxItem* item) const;
00365 
00366 
00379         uint    getItemColumnIndex(const ListboxItem* item) const;
00380 
00381 
00394         MCLGridRef      getItemGridReference(const ListboxItem* item) const;
00395 
00396 
00409         ListboxItem*    getItemAtGridReference(const MCLGridRef& grid_ref) const;
00410 
00411 
00428         bool    isListboxItemInColumn(const ListboxItem* item, uint col_idx) const;
00429 
00430 
00447         bool    isListboxItemInRow(const ListboxItem* item, uint row_idx) const;
00448 
00449 
00461         bool    isListboxItemInList(const ListboxItem* item) const;
00462 
00463 
00482         ListboxItem*    findColumnItemWithText(const String& text, uint col_idx, const ListboxItem* start_item) const;
00483 
00484 
00503         ListboxItem*    findRowItemWithText(const String& text, uint row_idx, const ListboxItem* start_item) const;
00504 
00505 
00524         ListboxItem*    findListItemWithText(const String& text, const ListboxItem* start_item) const;
00525 
00526 
00537         ListboxItem*    getFirstSelectedItem(void) const;
00538 
00539 
00555         ListboxItem*    getNextSelected(const ListboxItem* start_item) const;
00556 
00557 
00565         uint    getSelectedCount(void) const;
00566 
00567 
00581         bool    isItemSelected(const MCLGridRef& grid_ref) const;
00582 
00583 
00595         uint    getNominatedSelectionColumnID(void) const;
00596 
00597 
00606         uint    getNominatedSelectionColumn(void) const;
00607 
00608 
00617         uint    getNominatedSelectionRow(void) const;
00618 
00619 
00627         MultiColumnList::SelectionMode  getSelectionMode(void) const;
00628 
00629 
00638         bool    isVertScrollbarAlwaysShown(void) const;
00639 
00640 
00649         bool    isHorzScrollbarAlwaysShown(void) const;
00650 
00651 
00664         uint    getColumnID(uint col_idx) const;
00665 
00666 
00679         uint    getRowID(uint row_idx) const;
00680 
00681 
00694         uint    getRowWithID(uint row_id) const;
00695 
00696 
00706     Rect    getListRenderArea(void) const;
00707 
00708 
00720     Scrollbar* getVertScrollbar() const;
00721 
00733     Scrollbar* getHorzScrollbar() const;
00734 
00746     ListHeader* getListHeader() const;
00747 
00752     float   getTotalRowsHeight(void) const;
00753 
00758     float   getWidestColumnItemWidth(uint col_idx) const;
00759 
00764     float   getHighestRowItemHeight(uint row_idx) const;
00765 
00766         /*************************************************************************
00767                 Manipulator Methods
00768         *************************************************************************/
00779         virtual void    initialiseComponents(void);
00780 
00781 
00788         void    resetList(void);
00789 
00790 
00807         void    addColumn(const String& text, uint col_id, const UDim& width);
00808 
00809 
00830         void    insertColumn(const String& text, uint col_id, const UDim& width, uint position);
00831 
00832 
00845         void    removeColumn(uint col_idx);
00846 
00847 
00860         void    removeColumnWithID(uint col_id);
00861 
00862 
00878         void    moveColumn(uint col_idx, uint position);
00879 
00880 
00896         void    moveColumnWithID(uint col_id, uint position);
00897 
00898 
00913         uint    addRow(uint row_id = 0);
00914 
00915 
00938         uint    addRow(ListboxItem* item, uint col_id, uint row_id = 0);
00939 
00940 
00959         uint    insertRow(uint row_idx, uint row_id = 0);
00960 
00961 
00988         uint    insertRow(ListboxItem* item, uint col_id, uint row_idx, uint row_id = 0);
00989 
00990 
01003         void    removeRow(uint row_idx);
01004 
01005 
01021         void    setItem(ListboxItem* item, const MCLGridRef& position);
01022 
01023 
01042         void    setItem(ListboxItem* item, uint col_id, uint row_idx);
01043 
01044 
01057         void    setSelectionMode(MultiColumnList::SelectionMode sel_mode);
01058 
01059 
01072         void    setNominatedSelectionColumnID(uint col_id);
01073 
01074 
01087         void    setNominatedSelectionColumn(uint col_idx);
01088 
01089 
01102         void    setNominatedSelectionRow(uint row_idx);
01103 
01104 
01115         void    setSortDirection(ListHeaderSegment::SortDirection direction);
01116 
01117 
01130         void    setSortColumn(uint col_idx);
01131 
01132 
01145         void    setSortColumnByID(uint col_id);
01146 
01147 
01159         void    setShowVertScrollbar(bool setting);
01160 
01161 
01173         void    setShowHorzScrollbar(bool setting);
01174 
01175 
01183         void    clearAllSelections(void);
01184 
01185 
01206         void    setItemSelectState(ListboxItem* item, bool state);
01207 
01208 
01229         void    setItemSelectState(const MCLGridRef& grid_ref, bool state);
01230 
01231 
01240         void    handleUpdatedItemData(void);
01241 
01242 
01258         void    setColumnHeaderWidth(uint col_idx, const UDim& width);
01259 
01260 
01272         void    setUserSortControlEnabled(bool setting);
01273 
01274 
01286         void    setUserColumnSizingEnabled(bool setting);
01287 
01288 
01297         void    setUserColumnDraggingEnabled(bool setting);
01298 
01299 
01313         void    autoSizeColumnHeader(uint col_idx);
01314 
01315 
01331         void    setRowID(uint row_idx, uint row_id);
01332 
01333 
01334         /*************************************************************************
01335                 Construction and Destruction
01336         *************************************************************************/
01341         MultiColumnList(const String& type, const String& name);
01342 
01343 
01348         virtual ~MultiColumnList(void);
01349 
01350 
01351 protected:
01352         /*************************************************************************
01353                 Implementation Functions (abstract interface)
01354         *************************************************************************/
01364         //virtual       Rect    getListRenderArea_impl(void) const              = 0;
01365 
01366 
01367         /*************************************************************************
01368                 Implementation Functions
01369         *************************************************************************/
01374         void    configureScrollbars(void);
01375 
01376 
01381         bool    selectRange(const MCLGridRef& start, const MCLGridRef& end);
01382 
01383 
01391         bool    clearAllSelections_impl(void);
01392 
01393 
01402         ListboxItem*    getItemAtPoint(const Point& pt) const;
01403 
01404 
01411         bool    setItemSelectState_impl(const MCLGridRef grid_ref, bool state);
01412 
01413 
01418         void    setSelectForItemsInRow(uint row_idx, bool state);
01419 
01420 
01425         void    setSelectForItemsInColumn(uint col_idx, bool state);
01426 
01427 
01435         void    moveColumn_impl(uint col_idx, uint position);
01436 
01437 
01449         bool    resetList_impl(void);
01450 
01451 
01462         virtual bool    testClassName_impl(const String& class_name) const
01463         {
01464                 if (class_name=="MultiColumnList")      return true;
01465                 return Window::testClassName_impl(class_name);
01466         }
01467 
01468 
01469     // overrides function in base class.
01470     virtual bool validateWindowRenderer(const String& name) const
01471     {
01472         return (name == "MultiColumnList");
01473     }
01474 
01475     // overrides function in base class.
01476     int writePropertiesXML(XMLSerializer& xml_stream) const;
01477 
01482     void resortList();
01483 
01484         /*************************************************************************
01485                 New event handlers for multi column list
01486         *************************************************************************/
01491         virtual void    onSelectionModeChanged(WindowEventArgs& e);
01492 
01493 
01498         virtual void    onNominatedSelectColumnChanged(WindowEventArgs& e);
01499 
01500 
01505         virtual void    onNominatedSelectRowChanged(WindowEventArgs& e);
01506 
01507 
01512         virtual void    onVertScrollbarModeChanged(WindowEventArgs& e);
01513 
01514 
01519         virtual void    onHorzScrollbarModeChanged(WindowEventArgs& e);
01520 
01521 
01526         virtual void    onSelectionChanged(WindowEventArgs& e);
01527 
01528 
01533         virtual void    onListContentsChanged(WindowEventArgs& e);
01534 
01535 
01540         virtual void    onSortColumnChanged(WindowEventArgs& e);
01541 
01542 
01547         virtual void    onSortDirectionChanged(WindowEventArgs& e);
01548 
01549 
01554         virtual void    onListColumnSized(WindowEventArgs& e);
01555 
01556 
01561         virtual void    onListColumnMoved(WindowEventArgs& e);
01562 
01563 
01564         /*************************************************************************
01565                 Overridden Event handlers
01566         *************************************************************************/
01567         virtual void    onFontChanged(WindowEventArgs& e);
01568         virtual void    onSized(WindowEventArgs& e);
01569         virtual void    onMouseButtonDown(MouseEventArgs& e);
01570         virtual void    onMouseWheel(MouseEventArgs& e);
01571 
01572 
01573         /*************************************************************************
01574                 Handlers for subscribed events
01575         *************************************************************************/
01576         bool    handleHeaderScroll(const EventArgs& e);
01577         bool    handleHeaderSegMove(const EventArgs& e);
01578         bool    handleColumnSizeChange(const EventArgs& e);
01579         bool    handleHorzScrollbar(const EventArgs& e);
01580         bool    handleVertScrollbar(const EventArgs& e);
01581         bool    handleSortColumnChange(const EventArgs& e);
01582         bool    handleSortDirectionChange(const EventArgs& e);
01583         bool    handleHeaderSegDblClick(const EventArgs& e);
01584 
01590         struct ListRow
01591         {
01592                 typedef std::vector<ListboxItem*>       RowItems;
01593                 RowItems        d_items;
01594                 uint            d_sortColumn;
01595                 uint            d_rowID;
01596 
01597                 // operators
01598                 ListboxItem* const& operator[](uint idx) const  {return d_items[idx];}
01599                 ListboxItem*&   operator[](uint idx) {return d_items[idx];}
01600                 bool    operator<(const ListRow& rhs) const;
01601                 bool    operator>(const ListRow& rhs) const;
01602         };
01603 
01604 
01609         static bool pred_descend(const ListRow& a, const ListRow& b);
01610 
01611 
01612         /*************************************************************************
01613                 Implementation Data
01614         *************************************************************************/
01615         // scrollbar settings.
01616         bool    d_forceVertScroll;              
01617         bool    d_forceHorzScroll;              
01618 
01619         // selection abilities.
01620         SelectionMode   d_selectMode;   
01621         uint    d_nominatedSelectCol;   
01622         uint    d_nominatedSelectRow;   
01623         bool    d_multiSelect;                  
01624         bool    d_fullRowSelect;                
01625         bool    d_fullColSelect;                
01626         bool    d_useNominatedRow;              
01627         bool    d_useNominatedCol;              
01628         ListboxItem*    d_lastSelected; 
01629 
01630     uint    d_columnCount;          
01631 
01632         // storage of items in the list box.
01633         typedef std::vector<ListRow>            ListItemGrid;
01634         ListItemGrid    d_grid;                 
01635 
01636     friend class MultiColumnListWindowRenderer;
01637 
01638 
01639 private:
01640         /*************************************************************************
01641                 Static Properties for this class
01642         *************************************************************************/
01643         static MultiColumnListProperties::ColumnsMovable                                d_columnsMovableProperty;
01644         static MultiColumnListProperties::ColumnsSizable                                d_columnsSizableProperty;
01645         static MultiColumnListProperties::ForceHorzScrollbar                    d_forceHorzScrollProperty;
01646         static MultiColumnListProperties::ForceVertScrollbar                    d_forceVertScrollProperty;
01647         static MultiColumnListProperties::NominatedSelectionColumnID    d_nominatedSelectColProperty;
01648         static MultiColumnListProperties::NominatedSelectionRow                 d_nominatedSelectRowProperty;
01649         static MultiColumnListProperties::SelectionMode                                 d_selectModeProperty;
01650         static MultiColumnListProperties::SortColumnID                                  d_sortColumnIDProperty;
01651         static MultiColumnListProperties::SortDirection                                 d_sortDirectionProperty;
01652         static MultiColumnListProperties::SortSettingEnabled                    d_sortSettingProperty;
01653         static MultiColumnListProperties::ColumnHeader                                  d_columnHeaderProperty;
01654         static MultiColumnListProperties::RowCount                                              d_rowCountProperty;
01655 
01656 
01657         /*************************************************************************
01658                 Private methods
01659         *************************************************************************/
01660         void    addMultiColumnListProperties(void);
01661 };
01662 
01663 } // End of  CEGUI namespace section
01664 
01665 #if defined(_MSC_VER)
01666 #       pragma warning(pop)
01667 #endif
01668 
01669 #endif  // end of guard _CEGUIMultiColumnList_h_