Crazy Eddies GUI System  0.7.8
CEGUIMultiColumnList.h
1 /***********************************************************************
2  filename: CEGUIMultiColumnList.h
3  created: 13/4/2004
4  author: Paul D Turner
5 
6  purpose: Interface to base class for MultiColumnList widget
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIMultiColumnList_h_
31 #define _CEGUIMultiColumnList_h_
32 
33 #include "../CEGUIBase.h"
34 #include "../CEGUIWindow.h"
35 #include "CEGUIListHeader.h"
36 #include "CEGUIMultiColumnListProperties.h"
37 
38 
39 #if defined(_MSC_VER)
40 # pragma warning(push)
41 # pragma warning(disable : 4251)
42 #endif
43 
44 
45 // Start of CEGUI namespace section
46 namespace CEGUI
47 {
48 
53 struct CEGUIEXPORT MCLGridRef
54 {
55  MCLGridRef(uint r, uint c) : row(r), column(c) {}
56 
57  uint row;
58  uint column;
59 
60  // operators
61  MCLGridRef& operator=(const MCLGridRef& rhs);
62  bool operator<(const MCLGridRef& rhs) const;
63  bool operator<=(const MCLGridRef& rhs) const;
64  bool operator>(const MCLGridRef& rhs) const;
65  bool operator>=(const MCLGridRef& rhs) const;
66  bool operator==(const MCLGridRef& rhs) const;
67  bool operator!=(const MCLGridRef& rhs) const;
68 };
69 
75 {
76 public:
82 
92  virtual Rect getListRenderArea(void) const = 0;
93 };
94 
99 class CEGUIEXPORT MultiColumnList : public Window
100 {
101 public:
102  static const String EventNamespace;
103  static const String WidgetTypeName;
104 
105  /*************************************************************************
106  Constants
107  *************************************************************************/
108  // Event names
175 
176  /*************************************************************************
177  Child Widget name suffix constants
178  *************************************************************************/
182 
183  /*************************************************************************
184  Enumerations
185  *************************************************************************/
191  {
192  RowSingle, // Any single row may be selected. All items in the row are selected.
193  RowMultiple, // Multiple rows may be selected. All items in the row are selected.
194  CellSingle, // Any single cell may be selected.
195  CellMultiple, // Multiple cells bay be selected.
196  NominatedColumnSingle, // Any single item in a nominated column may be selected.
197  NominatedColumnMultiple, // Multiple items in a nominated column may be selected.
198  ColumnSingle, // Any single column may be selected. All items in the column are selected.
199  ColumnMultiple, // Multiple columns may be selected. All items in the column are selected.
200  NominatedRowSingle, // Any single item in a nominated row may be selected.
201  NominatedRowMultiple // Multiple items in a nominated row may be selected.
202  };
203 
204 
205  /*************************************************************************
206  Accessor Methods
207  *************************************************************************/
216  bool isUserSortControlEnabled(void) const;
217 
218 
226  bool isUserColumnSizingEnabled(void) const;
227 
228 
236  bool isUserColumnDraggingEnabled(void) const;
237 
238 
246  uint getColumnCount(void) const;
247 
248 
256  uint getRowCount(void) const;
257 
258 
269  uint getSortColumn(void) const;
270 
271 
284  uint getColumnWithID(uint col_id) const;
285 
286 
299  uint getColumnWithHeaderText(const String& text) const;
300 
301 
309  UDim getTotalColumnHeadersWidth(void) const;
310 
311 
324  UDim getColumnHeaderWidth(uint col_idx) const;
325 
326 
334  ListHeaderSegment::SortDirection getSortDirection(void) const;
335 
336 
349  ListHeaderSegment& getHeaderSegmentForColumn(uint col_idx) const;
350 
351 
364  uint getItemRowIndex(const ListboxItem* item) const;
365 
366 
379  uint getItemColumnIndex(const ListboxItem* item) const;
380 
381 
394  MCLGridRef getItemGridReference(const ListboxItem* item) const;
395 
396 
409  ListboxItem* getItemAtGridReference(const MCLGridRef& grid_ref) const;
410 
411 
428  bool isListboxItemInColumn(const ListboxItem* item, uint col_idx) const;
429 
430 
447  bool isListboxItemInRow(const ListboxItem* item, uint row_idx) const;
448 
449 
461  bool isListboxItemInList(const ListboxItem* item) const;
462 
463 
482  ListboxItem* findColumnItemWithText(const String& text, uint col_idx, const ListboxItem* start_item) const;
483 
484 
503  ListboxItem* findRowItemWithText(const String& text, uint row_idx, const ListboxItem* start_item) const;
504 
505 
524  ListboxItem* findListItemWithText(const String& text, const ListboxItem* start_item) const;
525 
526 
537  ListboxItem* getFirstSelectedItem(void) const;
538 
539 
555  ListboxItem* getNextSelected(const ListboxItem* start_item) const;
556 
557 
565  uint getSelectedCount(void) const;
566 
567 
581  bool isItemSelected(const MCLGridRef& grid_ref) const;
582 
583 
595  uint getNominatedSelectionColumnID(void) const;
596 
597 
606  uint getNominatedSelectionColumn(void) const;
607 
608 
617  uint getNominatedSelectionRow(void) const;
618 
619 
627  MultiColumnList::SelectionMode getSelectionMode(void) const;
628 
629 
638  bool isVertScrollbarAlwaysShown(void) const;
639 
640 
649  bool isHorzScrollbarAlwaysShown(void) const;
650 
651 
664  uint getColumnID(uint col_idx) const;
665 
666 
679  uint getRowID(uint row_idx) const;
680 
681 
694  uint getRowWithID(uint row_id) const;
695 
696 
706  Rect getListRenderArea(void) const;
707 
708 
720  Scrollbar* getVertScrollbar() const;
721 
733  Scrollbar* getHorzScrollbar() const;
734 
746  ListHeader* getListHeader() const;
747 
752  float getTotalRowsHeight(void) const;
753 
758  float getWidestColumnItemWidth(uint col_idx) const;
759 
764  float getHighestRowItemHeight(uint row_idx) const;
765 
775  bool getAutoSizeColumnUsesHeader() const;
776 
777  /*************************************************************************
778  Manipulator Methods
779  *************************************************************************/
790  virtual void initialiseComponents(void);
791 
792 
799  void resetList(void);
800 
801 
818  void addColumn(const String& text, uint col_id, const UDim& width);
819 
820 
841  void insertColumn(const String& text, uint col_id, const UDim& width, uint position);
842 
843 
856  void removeColumn(uint col_idx);
857 
858 
871  void removeColumnWithID(uint col_id);
872 
873 
889  void moveColumn(uint col_idx, uint position);
890 
891 
907  void moveColumnWithID(uint col_id, uint position);
908 
909 
924  uint addRow(uint row_id = 0);
925 
926 
949  uint addRow(ListboxItem* item, uint col_id, uint row_id = 0);
950 
951 
970  uint insertRow(uint row_idx, uint row_id = 0);
971 
972 
999  uint insertRow(ListboxItem* item, uint col_id, uint row_idx, uint row_id = 0);
1000 
1001 
1014  void removeRow(uint row_idx);
1015 
1016 
1032  void setItem(ListboxItem* item, const MCLGridRef& position);
1033 
1034 
1053  void setItem(ListboxItem* item, uint col_id, uint row_idx);
1054 
1055 
1068  void setSelectionMode(MultiColumnList::SelectionMode sel_mode);
1069 
1070 
1083  void setNominatedSelectionColumnID(uint col_id);
1084 
1085 
1098  void setNominatedSelectionColumn(uint col_idx);
1099 
1100 
1113  void setNominatedSelectionRow(uint row_idx);
1114 
1115 
1126  void setSortDirection(ListHeaderSegment::SortDirection direction);
1127 
1128 
1141  void setSortColumn(uint col_idx);
1142 
1143 
1156  void setSortColumnByID(uint col_id);
1157 
1158 
1170  void setShowVertScrollbar(bool setting);
1171 
1172 
1184  void setShowHorzScrollbar(bool setting);
1185 
1186 
1194  void clearAllSelections(void);
1195 
1196 
1217  void setItemSelectState(ListboxItem* item, bool state);
1218 
1219 
1240  void setItemSelectState(const MCLGridRef& grid_ref, bool state);
1241 
1242 
1251  void handleUpdatedItemData(void);
1252 
1253 
1269  void setColumnHeaderWidth(uint col_idx, const UDim& width);
1270 
1271 
1283  void setUserSortControlEnabled(bool setting);
1284 
1285 
1297  void setUserColumnSizingEnabled(bool setting);
1298 
1299 
1308  void setUserColumnDraggingEnabled(bool setting);
1309 
1310 
1324  void autoSizeColumnHeader(uint col_idx);
1325 
1326 
1342  void setRowID(uint row_idx, uint row_id);
1343 
1359  void ensureItemIsVisible(const ListboxItem* item);
1360 
1373  void ensureItemIsVisible(const MCLGridRef& grid_ref);
1374 
1390  void ensureItemRowIsVisible(const ListboxItem* item);
1391 
1407  void ensureItemColumnIsVisible(const ListboxItem* item);
1408 
1420  void ensureRowIsVisible(uint row_idx);
1421 
1433  void ensureColumnIsVisible(uint column_idx);
1434 
1447  void setAutoSizeColumnUsesHeader(bool include_header);
1448 
1449 
1450  /*************************************************************************
1451  Construction and Destruction
1452  *************************************************************************/
1457  MultiColumnList(const String& type, const String& name);
1458 
1459 
1464  virtual ~MultiColumnList(void);
1465 
1466 
1467 protected:
1468  /*************************************************************************
1469  Implementation Functions (abstract interface)
1470  *************************************************************************/
1480  //virtual Rect getListRenderArea_impl(void) const = 0;
1481 
1482 
1483  /*************************************************************************
1484  Implementation Functions
1485  *************************************************************************/
1490  void configureScrollbars(void);
1491 
1492 
1497  bool selectRange(const MCLGridRef& start, const MCLGridRef& end);
1498 
1499 
1507  bool clearAllSelections_impl(void);
1508 
1509 
1518  ListboxItem* getItemAtPoint(const Point& pt) const;
1519 
1520 
1527  bool setItemSelectState_impl(const MCLGridRef grid_ref, bool state);
1528 
1529 
1534  void setSelectForItemsInRow(uint row_idx, bool state);
1535 
1536 
1541  void setSelectForItemsInColumn(uint col_idx, bool state);
1542 
1543 
1551  void moveColumn_impl(uint col_idx, uint position);
1552 
1553 
1565  bool resetList_impl(void);
1566 
1567 
1578  virtual bool testClassName_impl(const String& class_name) const
1579  {
1580  if (class_name=="MultiColumnList") return true;
1581  return Window::testClassName_impl(class_name);
1582  }
1583 
1584 
1585  // overrides function in base class.
1586  virtual bool validateWindowRenderer(const String& name) const
1587  {
1588  return (name == "MultiColumnList");
1589  }
1590 
1591  // overrides function in base class.
1592  int writePropertiesXML(XMLSerializer& xml_stream) const;
1593 
1598  void resortList();
1599 
1600  /*************************************************************************
1601  New event handlers for multi column list
1602  *************************************************************************/
1607  virtual void onSelectionModeChanged(WindowEventArgs& e);
1608 
1609 
1614  virtual void onNominatedSelectColumnChanged(WindowEventArgs& e);
1615 
1616 
1621  virtual void onNominatedSelectRowChanged(WindowEventArgs& e);
1622 
1623 
1628  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
1629 
1630 
1635  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
1636 
1637 
1642  virtual void onSelectionChanged(WindowEventArgs& e);
1643 
1644 
1649  virtual void onListContentsChanged(WindowEventArgs& e);
1650 
1651 
1656  virtual void onSortColumnChanged(WindowEventArgs& e);
1657 
1658 
1663  virtual void onSortDirectionChanged(WindowEventArgs& e);
1664 
1665 
1670  virtual void onListColumnSized(WindowEventArgs& e);
1671 
1672 
1677  virtual void onListColumnMoved(WindowEventArgs& e);
1678 
1679 
1680  /*************************************************************************
1681  Overridden Event handlers
1682  *************************************************************************/
1683  virtual void onFontChanged(WindowEventArgs& e);
1684  virtual void onSized(WindowEventArgs& e);
1685  virtual void onMouseButtonDown(MouseEventArgs& e);
1686  virtual void onMouseWheel(MouseEventArgs& e);
1687 
1688 
1689  /*************************************************************************
1690  Handlers for subscribed events
1691  *************************************************************************/
1692  bool handleHeaderScroll(const EventArgs& e);
1693  bool handleHeaderSegMove(const EventArgs& e);
1694  bool handleColumnSizeChange(const EventArgs& e);
1695  bool handleHorzScrollbar(const EventArgs& e);
1696  bool handleVertScrollbar(const EventArgs& e);
1697  bool handleSortColumnChange(const EventArgs& e);
1698  bool handleSortDirectionChange(const EventArgs& e);
1699  bool handleHeaderSegDblClick(const EventArgs& e);
1700 
1706  struct ListRow
1707  {
1708  typedef std::vector<ListboxItem*> RowItems;
1709  RowItems d_items;
1710  uint d_sortColumn;
1711  uint d_rowID;
1712 
1713  // operators
1714  ListboxItem* const& operator[](uint idx) const {return d_items[idx];}
1715  ListboxItem*& operator[](uint idx) {return d_items[idx];}
1716  bool operator<(const ListRow& rhs) const;
1717  bool operator>(const ListRow& rhs) const;
1718  };
1719 
1720 
1725  static bool pred_descend(const ListRow& a, const ListRow& b);
1726 
1727 
1728  /*************************************************************************
1729  Implementation Data
1730  *************************************************************************/
1731  // scrollbar settings.
1734 
1735  // selection abilities.
1745 
1747 
1748  // storage of items in the list box.
1749  typedef std::vector<ListRow> ListItemGrid;
1750  ListItemGrid d_grid;
1751 
1754 
1755  friend class MultiColumnListWindowRenderer;
1756 
1757 
1758 private:
1759  /*************************************************************************
1760  Static Properties for this class
1761  *************************************************************************/
1762  static MultiColumnListProperties::ColumnsMovable d_columnsMovableProperty;
1763  static MultiColumnListProperties::ColumnsSizable d_columnsSizableProperty;
1764  static MultiColumnListProperties::ForceHorzScrollbar d_forceHorzScrollProperty;
1765  static MultiColumnListProperties::ForceVertScrollbar d_forceVertScrollProperty;
1766  static MultiColumnListProperties::NominatedSelectionColumnID d_nominatedSelectColProperty;
1767  static MultiColumnListProperties::NominatedSelectionRow d_nominatedSelectRowProperty;
1768  static MultiColumnListProperties::SelectionMode d_selectModeProperty;
1769  static MultiColumnListProperties::SortColumnID d_sortColumnIDProperty;
1770  static MultiColumnListProperties::SortDirection d_sortDirectionProperty;
1771  static MultiColumnListProperties::SortSettingEnabled d_sortSettingProperty;
1772  static MultiColumnListProperties::ColumnHeader d_columnHeaderProperty;
1773  static MultiColumnListProperties::RowCount d_rowCountProperty;
1774  static MultiColumnListProperties::AutoSizeColumnUsesHeader d_autoSizeColumnUsesHeaderProperty;
1775 
1776 
1777  /*************************************************************************
1778  Private methods
1779  *************************************************************************/
1780  void addMultiColumnListProperties(void);
1781 };
1782 
1783 } // End of CEGUI namespace section
1784 
1785 #if defined(_MSC_VER)
1786 # pragma warning(pop)
1787 #endif
1788 
1789 #endif // end of guard _CEGUIMultiColumnList_h_