Crazy Eddie's GUI System  0.8.4
MultiColumnList.h
00001 /***********************************************************************
00002         created:        13/4/2004
00003         author:         Paul D Turner
00004 
00005         purpose:        Interface to base class for MultiColumnList widget
00006 *************************************************************************/
00007 /***************************************************************************
00008  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00009  *
00010  *   Permission is hereby granted, free of charge, to any person obtaining
00011  *   a copy of this software and associated documentation files (the
00012  *   "Software"), to deal in the Software without restriction, including
00013  *   without limitation the rights to use, copy, modify, merge, publish,
00014  *   distribute, sublicense, and/or sell copies of the Software, and to
00015  *   permit persons to whom the Software is furnished to do so, subject to
00016  *   the following conditions:
00017  *
00018  *   The above copyright notice and this permission notice shall be
00019  *   included in all copies or substantial portions of the Software.
00020  *
00021  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00022  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00023  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00024  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00025  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00026  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00027  *   OTHER DEALINGS IN THE SOFTWARE.
00028  ***************************************************************************/
00029 #ifndef _CEGUIMultiColumnList_h_
00030 #define _CEGUIMultiColumnList_h_
00031 
00032 #include "../Base.h"
00033 #include "../Window.h"
00034 #include "./ListHeader.h"
00035 
00036 #if defined(_MSC_VER)
00037 #       pragma warning(push)
00038 #       pragma warning(disable : 4251)
00039 #endif
00040 
00041 
00042 // Start of CEGUI namespace section
00043 namespace CEGUI
00044 {
00045 
00050 struct CEGUIEXPORT MCLGridRef
00051 {
00052         MCLGridRef(uint r, uint c) : row(r), column(c) {}
00053 
00054         uint    row;            
00055         uint    column;         
00056 
00057         // operators
00058         MCLGridRef& operator=(const MCLGridRef& rhs);
00059         bool operator<(const MCLGridRef& rhs) const;
00060         bool operator<=(const MCLGridRef& rhs) const;
00061         bool operator>(const MCLGridRef& rhs) const;
00062         bool operator>=(const MCLGridRef& rhs) const;
00063         bool operator==(const MCLGridRef& rhs) const;
00064         bool operator!=(const MCLGridRef& rhs) const;
00065 };
00066 
00071 class CEGUIEXPORT MultiColumnListWindowRenderer : public WindowRenderer
00072 {
00073 public:
00078     MultiColumnListWindowRenderer(const String& name);
00079 
00089     virtual Rectf getListRenderArea(void) const = 0;
00090 };
00091 
00096 class CEGUIEXPORT MultiColumnList : public Window
00097 {
00098 public:
00099         static const String EventNamespace;                             
00100     static const String WidgetTypeName;             
00101 
00102         /*************************************************************************
00103                 Constants
00104         *************************************************************************/
00105         // Event names
00111         static const String EventSelectionModeChanged;
00117         static const String EventNominatedSelectColumnChanged;
00123         static const String EventNominatedSelectRowChanged;
00129         static const String EventVertScrollbarModeChanged;
00135         static const String EventHorzScrollbarModeChanged;
00141         static const String EventSelectionChanged;
00147         static const String EventListContentsChanged;
00153         static const String EventSortColumnChanged;
00159         static const String EventSortDirectionChanged;
00165         static const String EventListColumnSized;
00171         static const String EventListColumnMoved;
00172 
00173     /*************************************************************************
00174         Child Widget name constants
00175     *************************************************************************/
00176     static const String VertScrollbarName;   
00177     static const String HorzScrollbarName;   
00178     static const String ListHeaderName;      
00179 
00180         /*************************************************************************
00181                 Enumerations
00182         *************************************************************************/
00187         enum SelectionMode
00188         {
00189                 RowSingle,                                      // Any single row may be selected.  All items in the row are selected.
00190                 RowMultiple,                            // Multiple rows may be selected.  All items in the row are selected.
00191                 CellSingle,                                     // Any single cell may be selected.
00192                 CellMultiple,                           // Multiple cells bay be selected.
00193                 NominatedColumnSingle,          // Any single item in a nominated column may be selected.
00194                 NominatedColumnMultiple,        // Multiple items in a nominated column may be selected.
00195                 ColumnSingle,                           // Any single column may be selected.  All items in the column are selected.
00196                 ColumnMultiple,                         // Multiple columns may be selected.  All items in the column are selected.
00197                 NominatedRowSingle,                     // Any single item in a nominated row may be selected.
00198                 NominatedRowMultiple            // Multiple items in a nominated row may be selected.
00199         };
00200 
00201 
00202         /*************************************************************************
00203                 Accessor Methods
00204         *************************************************************************/
00213         bool    isUserSortControlEnabled(void) const;
00214 
00215 
00223         bool    isUserColumnSizingEnabled(void) const;
00224 
00225 
00233         bool    isUserColumnDraggingEnabled(void) const;
00234 
00235 
00243         uint    getColumnCount(void) const;
00244 
00245 
00253         uint    getRowCount(void) const;
00254 
00255 
00266         uint    getSortColumn(void) const;
00267         uint    getSortColumnID(void) const;
00268 
00281         uint    getColumnWithID(uint col_id) const;
00282 
00283 
00296         uint    getColumnWithHeaderText(const String& text) const;
00297 
00298 
00306         UDim getTotalColumnHeadersWidth(void) const;
00307 
00308 
00321         UDim getColumnHeaderWidth(uint col_idx) const;
00322 
00323 
00331         ListHeaderSegment::SortDirection        getSortDirection(void) const;
00332 
00333 
00346         ListHeaderSegment&      getHeaderSegmentForColumn(uint col_idx) const;
00347 
00348 
00361         uint    getItemRowIndex(const ListboxItem* item) const;
00362 
00363 
00376         uint    getItemColumnIndex(const ListboxItem* item) const;
00377 
00378 
00391         MCLGridRef      getItemGridReference(const ListboxItem* item) const;
00392 
00393 
00406         ListboxItem*    getItemAtGridReference(const MCLGridRef& grid_ref) const;
00407 
00408 
00425         bool    isListboxItemInColumn(const ListboxItem* item, uint col_idx) const;
00426 
00427 
00444         bool    isListboxItemInRow(const ListboxItem* item, uint row_idx) const;
00445 
00446 
00458         bool    isListboxItemInList(const ListboxItem* item) const;
00459 
00460 
00479         ListboxItem*    findColumnItemWithText(const String& text, uint col_idx, const ListboxItem* start_item) const;
00480 
00481 
00500         ListboxItem*    findRowItemWithText(const String& text, uint row_idx, const ListboxItem* start_item) const;
00501 
00502 
00521         ListboxItem*    findListItemWithText(const String& text, const ListboxItem* start_item) const;
00522 
00523 
00534         ListboxItem*    getFirstSelectedItem(void) const;
00535 
00536 
00552         ListboxItem*    getNextSelected(const ListboxItem* start_item) const;
00553 
00554 
00562         uint    getSelectedCount(void) const;
00563 
00564 
00578         bool    isItemSelected(const MCLGridRef& grid_ref) const;
00579 
00580 
00592         uint    getNominatedSelectionColumnID(void) const;
00593 
00594 
00603         uint    getNominatedSelectionColumn(void) const;
00604 
00605 
00614         uint    getNominatedSelectionRow(void) const;
00615 
00616 
00624         MultiColumnList::SelectionMode  getSelectionMode(void) const;
00625 
00626 
00635         bool    isVertScrollbarAlwaysShown(void) const;
00636 
00637 
00646         bool    isHorzScrollbarAlwaysShown(void) const;
00647 
00648 
00661         uint    getColumnID(uint col_idx) const;
00662 
00663 
00676         uint    getRowID(uint row_idx) const;
00677 
00678 
00691         uint    getRowWithID(uint row_id) const;
00692 
00693 
00703     Rectf getListRenderArea(void) const;
00704 
00705 
00717     Scrollbar* getVertScrollbar() const;
00718 
00730     Scrollbar* getHorzScrollbar() const;
00731 
00743     ListHeader* getListHeader() const;
00744 
00749     float   getTotalRowsHeight(void) const;
00750 
00755     float   getWidestColumnItemWidth(uint col_idx) const;
00756 
00761     float   getHighestRowItemHeight(uint row_idx) const;
00762 
00772     bool getAutoSizeColumnUsesHeader() const;
00773 
00774         /*************************************************************************
00775                 Manipulator Methods
00776         *************************************************************************/
00787         virtual void    initialiseComponents(void);
00788 
00789 
00796         void    resetList(void);
00797 
00798 
00815         void    addColumn(const String& text, uint col_id, const UDim& width);
00816         void    addColumn(const String& value);
00817 
00838         void    insertColumn(const String& text, uint col_id, const UDim& width, uint position);
00839 
00840 
00853         void    removeColumn(uint col_idx);
00854 
00855 
00868         void    removeColumnWithID(uint col_id);
00869 
00870 
00886         void    moveColumn(uint col_idx, uint position);
00887 
00888 
00904         void    moveColumnWithID(uint col_id, uint position);
00905 
00906 
00921         uint    addRow(uint row_id = 0);
00922 
00923 
00946         uint    addRow(ListboxItem* item, uint col_id, uint row_id = 0);
00947 
00948 
00967         uint    insertRow(uint row_idx, uint row_id = 0);
00968 
00969 
00996         uint    insertRow(ListboxItem* item, uint col_id, uint row_idx, uint row_id = 0);
00997 
00998 
01011         void    removeRow(uint row_idx);
01012 
01013 
01029         void    setItem(ListboxItem* item, const MCLGridRef& position);
01030 
01031 
01050         void    setItem(ListboxItem* item, uint col_id, uint row_idx);
01051 
01052 
01065         void    setSelectionMode(MultiColumnList::SelectionMode sel_mode);
01066 
01067 
01080         void    setNominatedSelectionColumnID(uint col_id);
01081 
01082 
01095         void    setNominatedSelectionColumn(uint col_idx);
01096 
01097 
01110         void    setNominatedSelectionRow(uint row_idx);
01111 
01112 
01123         void    setSortDirection(ListHeaderSegment::SortDirection direction);
01124 
01125 
01138         void    setSortColumn(uint col_idx);
01139 
01140 
01153         void    setSortColumnByID(uint col_id);
01154 
01155 
01167         void    setShowVertScrollbar(bool setting);
01168 
01169 
01181         void    setShowHorzScrollbar(bool setting);
01182 
01183 
01191         void    clearAllSelections(void);
01192 
01193 
01214         void    setItemSelectState(ListboxItem* item, bool state);
01215 
01216 
01237         void    setItemSelectState(const MCLGridRef& grid_ref, bool state);
01238 
01239 
01248         void    handleUpdatedItemData(void);
01249 
01250 
01266         void    setColumnHeaderWidth(uint col_idx, const UDim& width);
01267 
01268 
01280         void    setUserSortControlEnabled(bool setting);
01281 
01282 
01294         void    setUserColumnSizingEnabled(bool setting);
01295 
01296 
01305         void    setUserColumnDraggingEnabled(bool setting);
01306 
01307 
01321         void    autoSizeColumnHeader(uint col_idx);
01322 
01323 
01339         void    setRowID(uint row_idx, uint row_id);
01340 
01356     void ensureItemIsVisible(const ListboxItem* item);
01357 
01370     void ensureItemIsVisible(const MCLGridRef& grid_ref);
01371 
01387     void ensureItemRowIsVisible(const ListboxItem* item);
01388 
01404     void ensureItemColumnIsVisible(const ListboxItem* item);
01405 
01417     void ensureRowIsVisible(uint row_idx);
01418 
01430     void ensureColumnIsVisible(uint column_idx);
01431 
01444     void setAutoSizeColumnUsesHeader(bool include_header);
01445 
01446 
01447         /*************************************************************************
01448                 Construction and Destruction
01449         *************************************************************************/
01454         MultiColumnList(const String& type, const String& name);
01455 
01456 
01461         virtual ~MultiColumnList(void);
01462 
01463 
01464 protected:
01465         /*************************************************************************
01466                 Implementation Functions (abstract interface)
01467         *************************************************************************/
01477         //virtual       Rect    getListRenderArea_impl(void) const              = 0;
01478 
01479 
01480         /*************************************************************************
01481                 Implementation Functions
01482         *************************************************************************/
01487         void    configureScrollbars(void);
01488 
01489 
01494         bool    selectRange(const MCLGridRef& start, const MCLGridRef& end);
01495 
01496 
01504         bool    clearAllSelections_impl(void);
01505 
01506 
01515         ListboxItem*    getItemAtPoint(const Vector2f& pt) const;
01516 
01517 
01524         bool    setItemSelectState_impl(const MCLGridRef grid_ref, bool state);
01525 
01526 
01531         void    setSelectForItemsInRow(uint row_idx, bool state);
01532 
01533 
01538         void    setSelectForItemsInColumn(uint col_idx, bool state);
01539 
01540 
01548         void    moveColumn_impl(uint col_idx, uint position);
01549 
01550 
01562         bool    resetList_impl(void);
01563 
01564     // overrides function in base class.
01565     virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
01566 
01567     // overrides function in base class.
01568     int writePropertiesXML(XMLSerializer& xml_stream) const;
01569 
01574     void resortList();
01575 
01576         /*************************************************************************
01577                 New event handlers for multi column list
01578         *************************************************************************/
01583         virtual void    onSelectionModeChanged(WindowEventArgs& e);
01584 
01585 
01590         virtual void    onNominatedSelectColumnChanged(WindowEventArgs& e);
01591 
01592 
01597         virtual void    onNominatedSelectRowChanged(WindowEventArgs& e);
01598 
01599 
01604         virtual void    onVertScrollbarModeChanged(WindowEventArgs& e);
01605 
01606 
01611         virtual void    onHorzScrollbarModeChanged(WindowEventArgs& e);
01612 
01613 
01618         virtual void    onSelectionChanged(WindowEventArgs& e);
01619 
01620 
01625         virtual void    onListContentsChanged(WindowEventArgs& e);
01626 
01627 
01632         virtual void    onSortColumnChanged(WindowEventArgs& e);
01633 
01634 
01639         virtual void    onSortDirectionChanged(WindowEventArgs& e);
01640 
01641 
01646         virtual void    onListColumnSized(WindowEventArgs& e);
01647 
01648 
01653         virtual void    onListColumnMoved(WindowEventArgs& e);
01654 
01655 
01656         /*************************************************************************
01657                 Overridden Event handlers
01658         *************************************************************************/
01659         virtual void    onFontChanged(WindowEventArgs& e);
01660         virtual void    onSized(ElementEventArgs& e);
01661         virtual void    onMouseButtonDown(MouseEventArgs& e);
01662         virtual void    onMouseWheel(MouseEventArgs& e);
01663 
01664 
01665         /*************************************************************************
01666                 Handlers for subscribed events
01667         *************************************************************************/
01668         bool    handleHeaderScroll(const EventArgs& e);
01669         bool    handleHeaderSegMove(const EventArgs& e);
01670         bool    handleColumnSizeChange(const EventArgs& e);
01671         bool    handleHorzScrollbar(const EventArgs& e);
01672         bool    handleVertScrollbar(const EventArgs& e);
01673         bool    handleSortColumnChange(const EventArgs& e);
01674         bool    handleSortDirectionChange(const EventArgs& e);
01675         bool    handleHeaderSegDblClick(const EventArgs& e);
01676 
01682         struct ListRow
01683         {
01684                 typedef std::vector<ListboxItem*
01685             CEGUI_VECTOR_ALLOC(ListboxItem*)> RowItems;
01686                 RowItems        d_items;
01687                 uint            d_sortColumn;
01688                 uint            d_rowID;
01689 
01690                 // operators
01691                 ListboxItem* const& operator[](uint idx) const  {return d_items[idx];}
01692                 ListboxItem*&   operator[](uint idx) {return d_items[idx];}
01693                 bool    operator<(const ListRow& rhs) const;
01694                 bool    operator>(const ListRow& rhs) const;
01695         };
01696 
01697 
01702         static bool pred_descend(const ListRow& a, const ListRow& b);
01703 
01704 
01705         /*************************************************************************
01706                 Implementation Data
01707         *************************************************************************/
01708         // scrollbar settings.
01709         bool    d_forceVertScroll;              
01710         bool    d_forceHorzScroll;              
01711 
01712         // selection abilities.
01713         SelectionMode   d_selectMode;   
01714         uint    d_nominatedSelectCol;   
01715         uint    d_nominatedSelectRow;   
01716         bool    d_multiSelect;                  
01717         bool    d_fullRowSelect;                
01718         bool    d_fullColSelect;                
01719         bool    d_useNominatedRow;              
01720         bool    d_useNominatedCol;              
01721         ListboxItem*    d_lastSelected; 
01722 
01723     uint    d_columnCount;          
01724 
01725         // storage of items in the list box.
01726         typedef std::vector<ListRow
01727         CEGUI_VECTOR_ALLOC(ListRow)> ListItemGrid;
01728         ListItemGrid    d_grid;                 
01729 
01731     bool d_autoSizeColumnUsesHeader;
01732 
01733     friend class MultiColumnListWindowRenderer;
01734 
01735 
01736 private:
01737         /*************************************************************************
01738                 Private methods
01739         *************************************************************************/
01740         void    addMultiColumnListProperties(void);
01741 };
01742 
01743 
01744 template<>
01745 class PropertyHelper<MultiColumnList::SelectionMode>
01746 {
01747 public:
01748     typedef MultiColumnList::SelectionMode return_type;
01749     typedef return_type safe_method_return_type;
01750     typedef MultiColumnList::SelectionMode pass_type;
01751     typedef String string_return_type;
01752 
01753     static const String& getDataTypeName()
01754     {
01755         static String type("SelectionMode");
01756 
01757         return type;
01758     }
01759 
01760     static return_type fromString(const String& str)
01761     {
01762         MultiColumnList::SelectionMode mode;
01763 
01764         if (str == "RowMultiple")
01765         {
01766             mode = MultiColumnList::RowMultiple;
01767         }
01768         else if (str == "ColumnSingle")
01769         {
01770             mode = MultiColumnList::ColumnSingle;
01771         }
01772         else if (str == "ColumnMultiple")
01773         {
01774             mode = MultiColumnList::ColumnMultiple;
01775         }
01776         else if (str == "CellSingle")
01777         {
01778             mode = MultiColumnList::CellSingle;
01779         }
01780         else if (str == "CellMultiple")
01781         {
01782             mode = MultiColumnList::CellMultiple;
01783         }
01784         else if (str == "NominatedColumnSingle")
01785         {
01786             mode = MultiColumnList::NominatedColumnSingle;
01787         }
01788         else if (str == "NominatedColumnMultiple")
01789         {
01790             mode = MultiColumnList::NominatedColumnMultiple;
01791         }
01792         else if (str == "NominatedRowSingle")
01793         {
01794             mode = MultiColumnList::NominatedRowSingle;
01795         }
01796         else if (str == "NominatedRowMultiple")
01797         {
01798             mode = MultiColumnList::NominatedRowMultiple;
01799         }
01800         else
01801         {
01802             mode = MultiColumnList::RowSingle;
01803         }
01804         return mode;
01805     }
01806 
01807     static string_return_type toString(pass_type val)
01808     {
01809         switch(val)
01810         {
01811         case MultiColumnList::RowMultiple:
01812             return String("RowMultiple");
01813             break;
01814 
01815         case MultiColumnList::ColumnSingle:
01816             return String("ColumnSingle");
01817             break;
01818 
01819         case MultiColumnList::ColumnMultiple:
01820             return String("ColumnMultiple");
01821             break;
01822 
01823         case MultiColumnList::CellSingle:
01824             return String("CellSingle");
01825             break;
01826 
01827         case MultiColumnList::CellMultiple:
01828             return String("CellMultiple");
01829             break;
01830 
01831         case MultiColumnList::NominatedColumnSingle:
01832             return String("NominatedColumnSingle");
01833             break;
01834 
01835         case MultiColumnList::NominatedColumnMultiple:
01836             return String("NominatedColumnMultiple");
01837             break;
01838 
01839         case MultiColumnList::NominatedRowSingle:
01840             return String("NominatedRowSingle");
01841             break;
01842 
01843         case MultiColumnList::NominatedRowMultiple:
01844             return String("NominatedRowMultiple");
01845             break;
01846 
01847         default:
01848             return String("RowSingle");
01849             break;
01850         }
01851     }
01852 };
01853 
01854 
01855 } // End of  CEGUI namespace section
01856 
01857 #if defined(_MSC_VER)
01858 #       pragma warning(pop)
01859 #endif
01860 
01861 #endif  // end of guard _CEGUIMultiColumnList_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends