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 "elements/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
00109         static const String EventSelectionModeChanged;          
00110         static const String EventNominatedSelectColumnChanged;
00111         static const String EventNominatedSelectRowChanged;     
00112         static const String EventVertScrollbarModeChanged;      
00113         static const String EventHorzScrollbarModeChanged;      
00114         static const String EventSelectionChanged;                      
00115         static const String EventListContentsChanged;                   
00116         static const String EventSortColumnChanged;                     
00117         static const String EventSortDirectionChanged;          
00118         static const String EventListColumnSized;                               
00119         static const String EventListColumnMoved;                               
00120 
00121     /*************************************************************************
00122         Child Widget name suffix constants
00123     *************************************************************************/
00124     static const String VertScrollbarNameSuffix;   
00125     static const String HorzScrollbarNameSuffix;   
00126     static const String ListHeaderNameSuffix;      
00127 
00128         /*************************************************************************
00129                 Enumerations
00130         *************************************************************************/
00135         enum SelectionMode
00136         {
00137                 RowSingle,                                      // Any single row may be selected.  All items in the row are selected.
00138                 RowMultiple,                            // Multiple rows may be selected.  All items in the row are selected.
00139                 CellSingle,                                     // Any single cell may be selected.
00140                 CellMultiple,                           // Multiple cells bay be selected.
00141                 NominatedColumnSingle,          // Any single item in a nominated column may be selected.
00142                 NominatedColumnMultiple,        // Multiple items in a nominated column may be selected.
00143                 ColumnSingle,                           // Any single column may be selected.  All items in the column are selected.
00144                 ColumnMultiple,                         // Multiple columns may be selected.  All items in the column are selected.
00145                 NominatedRowSingle,                     // Any single item in a nominated row may be selected.
00146                 NominatedRowMultiple            // Multiple items in a nominated row may be selected.
00147         };
00148 
00149 
00150         /*************************************************************************
00151                 Accessor Methods
00152         *************************************************************************/
00161         bool    isUserSortControlEnabled(void) const;
00162 
00163 
00171         bool    isUserColumnSizingEnabled(void) const;
00172 
00173 
00181         bool    isUserColumnDraggingEnabled(void) const;
00182 
00183 
00191         uint    getColumnCount(void) const;
00192 
00193 
00201         uint    getRowCount(void) const;
00202 
00203 
00214         uint    getSortColumn(void) const;
00215 
00216         
00229         uint    getColumnWithID(uint col_id) const;
00230 
00231 
00244         uint    getColumnWithHeaderText(const String& text) const;
00245 
00246 
00254         UDim getTotalColumnHeadersWidth(void) const;
00255 
00256 
00269         UDim getColumnHeaderWidth(uint col_idx) const;
00270 
00271 
00279         ListHeaderSegment::SortDirection        getSortDirection(void) const;
00280 
00281 
00294         ListHeaderSegment&      getHeaderSegmentForColumn(uint col_idx) const;
00295 
00296 
00309         uint    getItemRowIndex(const ListboxItem* item) const;
00310 
00311 
00324         uint    getItemColumnIndex(const ListboxItem* item) const;
00325 
00326 
00339         MCLGridRef      getItemGridReference(const ListboxItem* item) const;
00340 
00341         
00354         ListboxItem*    getItemAtGridReference(const MCLGridRef& grid_ref) const;
00355 
00356 
00373         bool    isListboxItemInColumn(const ListboxItem* item, uint col_idx) const;
00374 
00375 
00392         bool    isListboxItemInRow(const ListboxItem* item, uint row_idx) const;
00393 
00394 
00406         bool    isListboxItemInList(const ListboxItem* item) const;
00407 
00408 
00427         ListboxItem*    findColumnItemWithText(const String& text, uint col_idx, const ListboxItem* start_item) const;
00428 
00429 
00448         ListboxItem*    findRowItemWithText(const String& text, uint row_idx, const ListboxItem* start_item) const;
00449 
00450 
00469         ListboxItem*    findListItemWithText(const String& text, const ListboxItem* start_item) const;
00470 
00471 
00482         ListboxItem*    getFirstSelectedItem(void) const;
00483 
00484 
00500         ListboxItem*    getNextSelected(const ListboxItem* start_item) const;
00501 
00502 
00510         uint    getSelectedCount(void) const;
00511 
00512 
00526         bool    isItemSelected(const MCLGridRef& grid_ref) const;
00527 
00528 
00540         uint    getNominatedSelectionColumnID(void) const;
00541 
00542 
00551         uint    getNominatedSelectionColumn(void) const;
00552 
00553 
00562         uint    getNominatedSelectionRow(void) const;
00563 
00564 
00572         MultiColumnList::SelectionMode  getSelectionMode(void) const;
00573 
00574 
00583         bool    isVertScrollbarAlwaysShown(void) const;
00584 
00585 
00594         bool    isHorzScrollbarAlwaysShown(void) const;
00595 
00596 
00609         uint    getColumnID(uint col_idx) const;
00610 
00611 
00624         uint    getRowID(uint row_idx) const;
00625 
00626 
00639         uint    getRowWithID(uint row_id) const;
00640 
00641 
00651     Rect    getListRenderArea(void) const;
00652 
00653 
00665     Scrollbar* getVertScrollbar() const;
00666 
00678     Scrollbar* getHorzScrollbar() const;
00679 
00691     ListHeader* getListHeader() const;
00692 
00697     float   getTotalRowsHeight(void) const;
00698 
00703     float   getWidestColumnItemWidth(uint col_idx) const;
00704 
00709     float   getHighestRowItemHeight(uint row_idx) const;
00710 
00711         /*************************************************************************
00712                 Manipulator Methods
00713         *************************************************************************/
00724         virtual void    initialiseComponents(void);
00725 
00726 
00733         void    resetList(void);
00734 
00735 
00752         void    addColumn(const String& text, uint col_id, const UDim& width);
00753 
00754 
00775         void    insertColumn(const String& text, uint col_id, const UDim& width, uint position);
00776 
00777 
00790         void    removeColumn(uint col_idx);
00791 
00792 
00805         void    removeColumnWithID(uint col_id);
00806 
00807 
00823         void    moveColumn(uint col_idx, uint position);
00824 
00825 
00841         void    moveColumnWithID(uint col_id, uint position);
00842 
00843 
00858         uint    addRow(uint row_id = 0);
00859 
00860 
00883         uint    addRow(ListboxItem* item, uint col_id, uint row_id = 0);
00884 
00885 
00904         uint    insertRow(uint row_idx, uint row_id = 0);
00905 
00906 
00933         uint    insertRow(ListboxItem* item, uint col_id, uint row_idx, uint row_id = 0);
00934 
00935 
00948         void    removeRow(uint row_idx);
00949 
00950 
00966         void    setItem(ListboxItem* item, const MCLGridRef& position);
00967 
00968 
00987         void    setItem(ListboxItem* item, uint col_id, uint row_idx);
00988 
00989 
01002         void    setSelectionMode(MultiColumnList::SelectionMode sel_mode);
01003 
01004 
01017         void    setNominatedSelectionColumnID(uint col_id);
01018 
01019 
01032         void    setNominatedSelectionColumn(uint col_idx);
01033 
01034 
01047         void    setNominatedSelectionRow(uint row_idx);
01048 
01049 
01060         void    setSortDirection(ListHeaderSegment::SortDirection direction);
01061 
01062 
01075         void    setSortColumn(uint col_idx);
01076 
01077 
01090         void    setSortColumnByID(uint col_id);
01091 
01092         
01104         void    setShowVertScrollbar(bool setting);
01105 
01106 
01118         void    setShowHorzScrollbar(bool setting);
01119 
01120         
01128         void    clearAllSelections(void);
01129 
01130 
01151         void    setItemSelectState(ListboxItem* item, bool state);
01152 
01153 
01174         void    setItemSelectState(const MCLGridRef& grid_ref, bool state);
01175 
01176         
01185         void    handleUpdatedItemData(void);
01186 
01187 
01203         void    setColumnHeaderWidth(uint col_idx, const UDim& width);
01204 
01205 
01217         void    setUserSortControlEnabled(bool setting);
01218 
01219 
01231         void    setUserColumnSizingEnabled(bool setting);
01232 
01233 
01242         void    setUserColumnDraggingEnabled(bool setting);
01243 
01244 
01258         void    autoSizeColumnHeader(uint col_idx);
01259 
01260 
01276         void    setRowID(uint row_idx, uint row_id);
01277 
01278 
01279         /*************************************************************************
01280                 Construction and Destruction
01281         *************************************************************************/
01286         MultiColumnList(const String& type, const String& name);
01287 
01288 
01293         virtual ~MultiColumnList(void);
01294 
01295 
01296 protected:
01297         /*************************************************************************
01298                 Implementation Functions (abstract interface)
01299         *************************************************************************/
01309         //virtual       Rect    getListRenderArea_impl(void) const              = 0;
01310 
01311 
01312         /*************************************************************************
01313                 Implementation Functions
01314         *************************************************************************/
01319         void    configureScrollbars(void);
01320 
01321 
01326         bool    selectRange(const MCLGridRef& start, const MCLGridRef& end);
01327 
01328 
01336         bool    clearAllSelections_impl(void);
01337 
01338 
01347         ListboxItem*    getItemAtPoint(const Point& pt) const;
01348 
01349 
01356         bool    setItemSelectState_impl(const MCLGridRef grid_ref, bool state);
01357 
01358 
01363         void    setSelectForItemsInRow(uint row_idx, bool state);
01364 
01365 
01370         void    setSelectForItemsInColumn(uint col_idx, bool state);
01371 
01372 
01380         void    moveColumn_impl(uint col_idx, uint position);
01381 
01382 
01394         bool    resetList_impl(void);
01395 
01396 
01407         virtual bool    testClassName_impl(const String& class_name) const
01408         {
01409                 if (class_name=="MultiColumnList")      return true;
01410                 return Window::testClassName_impl(class_name);
01411         }
01412     
01413 
01414     // overrides function in base class.
01415     virtual bool validateWindowRenderer(const String& name) const
01416     {
01417         return (name == "MultiColumnList");
01418     }
01419 
01420     // overrides function in base class.
01421     int writePropertiesXML(XMLSerializer& xml_stream) const;
01422 
01423         /*************************************************************************
01424                 New event handlers for multi column list
01425         *************************************************************************/
01430         virtual void    onSelectionModeChanged(WindowEventArgs& e);
01431 
01432 
01437         virtual void    onNominatedSelectColumnChanged(WindowEventArgs& e);
01438 
01439 
01444         virtual void    onNominatedSelectRowChanged(WindowEventArgs& e);
01445 
01446 
01451         virtual void    onVertScrollbarModeChanged(WindowEventArgs& e);
01452 
01453 
01458         virtual void    onHorzScrollbarModeChanged(WindowEventArgs& e);
01459 
01460 
01465         virtual void    onSelectionChanged(WindowEventArgs& e);
01466 
01467 
01472         virtual void    onListContentsChanged(WindowEventArgs& e);
01473 
01474 
01479         virtual void    onSortColumnChanged(WindowEventArgs& e);
01480 
01481 
01486         virtual void    onSortDirectionChanged(WindowEventArgs& e);
01487 
01488 
01493         virtual void    onListColumnSized(WindowEventArgs& e);
01494 
01495 
01500         virtual void    onListColumnMoved(WindowEventArgs& e);
01501 
01502 
01503         /*************************************************************************
01504                 Overridden Event handlers
01505         *************************************************************************/
01506         virtual void    onSized(WindowEventArgs& e);
01507         virtual void    onMouseButtonDown(MouseEventArgs& e);
01508         virtual void    onMouseWheel(MouseEventArgs& e);
01509 
01510 
01511         /*************************************************************************
01512                 Handlers for subscribed events
01513         *************************************************************************/
01514         bool    handleHeaderScroll(const EventArgs& e);
01515         bool    handleHeaderSegMove(const EventArgs& e);
01516         bool    handleColumnSizeChange(const EventArgs& e);
01517         bool    handleHorzScrollbar(const EventArgs& e);
01518         bool    handleVertScrollbar(const EventArgs& e);
01519         bool    handleSortColumnChange(const EventArgs& e);
01520         bool    handleSortDirectionChange(const EventArgs& e);
01521         bool    handleHeaderSegDblClick(const EventArgs& e);
01522 
01528         struct ListRow
01529         {
01530                 typedef std::vector<ListboxItem*>       RowItems;
01531                 RowItems        d_items;
01532                 uint            d_sortColumn;
01533                 uint            d_rowID;
01534 
01535                 // operators
01536                 ListboxItem* const& operator[](uint idx) const  {return d_items[idx];}
01537                 ListboxItem*&   operator[](uint idx) {return d_items[idx];}
01538                 bool    operator<(const ListRow& rhs) const;
01539                 bool    operator>(const ListRow& rhs) const;
01540         };
01541 
01542 
01547         static bool pred_descend(const ListRow& a, const ListRow& b);
01548 
01549 
01550         /*************************************************************************
01551                 Implementation Data
01552         *************************************************************************/
01553         // scrollbar settings.
01554         bool    d_forceVertScroll;              
01555         bool    d_forceHorzScroll;              
01556 
01557         // selection abilities.
01558         SelectionMode   d_selectMode;   
01559         uint    d_nominatedSelectCol;   
01560         uint    d_nominatedSelectRow;   
01561         bool    d_multiSelect;                  
01562         bool    d_fullRowSelect;                
01563         bool    d_fullColSelect;                
01564         bool    d_useNominatedRow;              
01565         bool    d_useNominatedCol;              
01566         ListboxItem*    d_lastSelected; 
01567 
01568     uint    d_columnCount;          
01569 
01570         // storage of items in the list box.
01571         typedef std::vector<ListRow>            ListItemGrid;
01572         ListItemGrid    d_grid;                 
01573 
01574     friend class MultiColumnListWindowRenderer;
01575 
01576 
01577 private:
01578         /*************************************************************************
01579                 Static Properties for this class
01580         *************************************************************************/
01581         static MultiColumnListProperties::ColumnsMovable                                d_columnsMovableProperty;
01582         static MultiColumnListProperties::ColumnsSizable                                d_columnsSizableProperty;
01583         static MultiColumnListProperties::ForceHorzScrollbar                    d_forceHorzScrollProperty;
01584         static MultiColumnListProperties::ForceVertScrollbar                    d_forceVertScrollProperty;
01585         static MultiColumnListProperties::NominatedSelectionColumnID    d_nominatedSelectColProperty;
01586         static MultiColumnListProperties::NominatedSelectionRow                 d_nominatedSelectRowProperty;
01587         static MultiColumnListProperties::SelectionMode                                 d_selectModeProperty;
01588         static MultiColumnListProperties::SortColumnID                                  d_sortColumnIDProperty;
01589         static MultiColumnListProperties::SortDirection                                 d_sortDirectionProperty;
01590         static MultiColumnListProperties::SortSettingEnabled                    d_sortSettingProperty;
01591         static MultiColumnListProperties::ColumnHeader                                  d_columnHeaderProperty;
01592         static MultiColumnListProperties::RowCount                                              d_rowCountProperty;
01593 
01594 
01595         /*************************************************************************
01596                 Private methods
01597         *************************************************************************/
01598         void    addMultiColumnListProperties(void);
01599 };
01600 
01601 } // End of  CEGUI namespace section
01602 
01603 #if defined(_MSC_VER)
01604 #       pragma warning(pop)
01605 #endif
01606 
01607 #endif  // end of guard _CEGUIMultiColumnList_h_

Generated on Sun Nov 5 14:35:28 2006 for Crazy Eddies GUI System by  doxygen 1.4.7