Crazy Eddie's GUI System  0.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
widgets/MultiColumnList.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 "../Base.h"
34 #include "../Window.h"
35 #include "./ListHeader.h"
36 
37 #if defined(_MSC_VER)
38 # pragma warning(push)
39 # pragma warning(disable : 4251)
40 #endif
41 
42 
43 // Start of CEGUI namespace section
44 namespace CEGUI
45 {
46 
51 struct CEGUIEXPORT MCLGridRef
52 {
53  MCLGridRef(uint r, uint c) : row(r), column(c) {}
54 
55  uint row;
56  uint column;
57 
58  // operators
59  MCLGridRef& operator=(const MCLGridRef& rhs);
60  bool operator<(const MCLGridRef& rhs) const;
61  bool operator<=(const MCLGridRef& rhs) const;
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 };
67 
73 {
74 public:
80 
90  virtual Rectf getListRenderArea(void) const = 0;
91 };
92 
97 class CEGUIEXPORT MultiColumnList : public Window
98 {
99 public:
100  static const String EventNamespace;
101  static const String WidgetTypeName;
102 
103  /*************************************************************************
104  Constants
105  *************************************************************************/
106  // Event names
173 
174  /*************************************************************************
175  Child Widget name constants
176  *************************************************************************/
177  static const String VertScrollbarName;
178  static const String HorzScrollbarName;
179  static const String ListHeaderName;
180 
181  /*************************************************************************
182  Enumerations
183  *************************************************************************/
189  {
190  RowSingle, // Any single row may be selected. All items in the row are selected.
191  RowMultiple, // Multiple rows may be selected. All items in the row are selected.
192  CellSingle, // Any single cell may be selected.
193  CellMultiple, // Multiple cells bay be selected.
194  NominatedColumnSingle, // Any single item in a nominated column may be selected.
195  NominatedColumnMultiple, // Multiple items in a nominated column may be selected.
196  ColumnSingle, // Any single column may be selected. All items in the column are selected.
197  ColumnMultiple, // Multiple columns may be selected. All items in the column are selected.
198  NominatedRowSingle, // Any single item in a nominated row may be selected.
199  NominatedRowMultiple // Multiple items in a nominated row may be selected.
200  };
201 
202 
203  /*************************************************************************
204  Accessor Methods
205  *************************************************************************/
214  bool isUserSortControlEnabled(void) const;
215 
216 
224  bool isUserColumnSizingEnabled(void) const;
225 
226 
234  bool isUserColumnDraggingEnabled(void) const;
235 
236 
244  uint getColumnCount(void) const;
245 
246 
254  uint getRowCount(void) const;
255 
256 
267  uint getSortColumn(void) const;
268  uint getSortColumnID(void) const;
269 
282  uint getColumnWithID(uint col_id) const;
283 
284 
297  uint getColumnWithHeaderText(const String& text) const;
298 
299 
307  UDim getTotalColumnHeadersWidth(void) const;
308 
309 
322  UDim getColumnHeaderWidth(uint col_idx) const;
323 
324 
332  ListHeaderSegment::SortDirection getSortDirection(void) const;
333 
334 
347  ListHeaderSegment& getHeaderSegmentForColumn(uint col_idx) const;
348 
349 
362  uint getItemRowIndex(const ListboxItem* item) const;
363 
364 
377  uint getItemColumnIndex(const ListboxItem* item) const;
378 
379 
392  MCLGridRef getItemGridReference(const ListboxItem* item) const;
393 
394 
407  ListboxItem* getItemAtGridReference(const MCLGridRef& grid_ref) const;
408 
409 
426  bool isListboxItemInColumn(const ListboxItem* item, uint col_idx) const;
427 
428 
445  bool isListboxItemInRow(const ListboxItem* item, uint row_idx) const;
446 
447 
459  bool isListboxItemInList(const ListboxItem* item) const;
460 
461 
480  ListboxItem* findColumnItemWithText(const String& text, uint col_idx, const ListboxItem* start_item) const;
481 
482 
501  ListboxItem* findRowItemWithText(const String& text, uint row_idx, const ListboxItem* start_item) const;
502 
503 
522  ListboxItem* findListItemWithText(const String& text, const ListboxItem* start_item) const;
523 
524 
535  ListboxItem* getFirstSelectedItem(void) const;
536 
537 
553  ListboxItem* getNextSelected(const ListboxItem* start_item) const;
554 
555 
563  uint getSelectedCount(void) const;
564 
565 
579  bool isItemSelected(const MCLGridRef& grid_ref) const;
580 
581 
593  uint getNominatedSelectionColumnID(void) const;
594 
595 
604  uint getNominatedSelectionColumn(void) const;
605 
606 
615  uint getNominatedSelectionRow(void) const;
616 
617 
625  MultiColumnList::SelectionMode getSelectionMode(void) const;
626 
627 
636  bool isVertScrollbarAlwaysShown(void) const;
637 
638 
647  bool isHorzScrollbarAlwaysShown(void) const;
648 
649 
662  uint getColumnID(uint col_idx) const;
663 
664 
677  uint getRowID(uint row_idx) const;
678 
679 
692  uint getRowWithID(uint row_id) const;
693 
694 
704  Rectf getListRenderArea(void) const;
705 
706 
718  Scrollbar* getVertScrollbar() const;
719 
731  Scrollbar* getHorzScrollbar() const;
732 
744  ListHeader* getListHeader() const;
745 
750  float getTotalRowsHeight(void) const;
751 
756  float getWidestColumnItemWidth(uint col_idx) const;
757 
762  float getHighestRowItemHeight(uint row_idx) const;
763 
773  bool getAutoSizeColumnUsesHeader() const;
774 
775  /*************************************************************************
776  Manipulator Methods
777  *************************************************************************/
788  virtual void initialiseComponents(void);
789 
790 
797  void resetList(void);
798 
799 
816  void addColumn(const String& text, uint col_id, const UDim& width);
817  void addColumn(const String& value);
818 
839  void insertColumn(const String& text, uint col_id, const UDim& width, uint position);
840 
841 
854  void removeColumn(uint col_idx);
855 
856 
869  void removeColumnWithID(uint col_id);
870 
871 
887  void moveColumn(uint col_idx, uint position);
888 
889 
905  void moveColumnWithID(uint col_id, uint position);
906 
907 
922  uint addRow(uint row_id = 0);
923 
924 
947  uint addRow(ListboxItem* item, uint col_id, uint row_id = 0);
948 
949 
968  uint insertRow(uint row_idx, uint row_id = 0);
969 
970 
997  uint insertRow(ListboxItem* item, uint col_id, uint row_idx, uint row_id = 0);
998 
999 
1012  void removeRow(uint row_idx);
1013 
1014 
1030  void setItem(ListboxItem* item, const MCLGridRef& position);
1031 
1032 
1051  void setItem(ListboxItem* item, uint col_id, uint row_idx);
1052 
1053 
1066  void setSelectionMode(MultiColumnList::SelectionMode sel_mode);
1067 
1068 
1081  void setNominatedSelectionColumnID(uint col_id);
1082 
1083 
1096  void setNominatedSelectionColumn(uint col_idx);
1097 
1098 
1111  void setNominatedSelectionRow(uint row_idx);
1112 
1113 
1124  void setSortDirection(ListHeaderSegment::SortDirection direction);
1125 
1126 
1139  void setSortColumn(uint col_idx);
1140 
1141 
1154  void setSortColumnByID(uint col_id);
1155 
1156 
1168  void setShowVertScrollbar(bool setting);
1169 
1170 
1182  void setShowHorzScrollbar(bool setting);
1183 
1184 
1192  void clearAllSelections(void);
1193 
1194 
1215  void setItemSelectState(ListboxItem* item, bool state);
1216 
1217 
1238  void setItemSelectState(const MCLGridRef& grid_ref, bool state);
1239 
1240 
1249  void handleUpdatedItemData(void);
1250 
1251 
1267  void setColumnHeaderWidth(uint col_idx, const UDim& width);
1268 
1269 
1281  void setUserSortControlEnabled(bool setting);
1282 
1283 
1295  void setUserColumnSizingEnabled(bool setting);
1296 
1297 
1306  void setUserColumnDraggingEnabled(bool setting);
1307 
1308 
1322  void autoSizeColumnHeader(uint col_idx);
1323 
1324 
1340  void setRowID(uint row_idx, uint row_id);
1341 
1357  void ensureItemIsVisible(const ListboxItem* item);
1358 
1371  void ensureItemIsVisible(const MCLGridRef& grid_ref);
1372 
1388  void ensureItemRowIsVisible(const ListboxItem* item);
1389 
1405  void ensureItemColumnIsVisible(const ListboxItem* item);
1406 
1418  void ensureRowIsVisible(uint row_idx);
1419 
1431  void ensureColumnIsVisible(uint column_idx);
1432 
1445  void setAutoSizeColumnUsesHeader(bool include_header);
1446 
1447 
1448  /*************************************************************************
1449  Construction and Destruction
1450  *************************************************************************/
1455  MultiColumnList(const String& type, const String& name);
1456 
1457 
1462  virtual ~MultiColumnList(void);
1463 
1464 
1465 protected:
1466  /*************************************************************************
1467  Implementation Functions (abstract interface)
1468  *************************************************************************/
1478  //virtual Rect getListRenderArea_impl(void) const = 0;
1479 
1480 
1481  /*************************************************************************
1482  Implementation Functions
1483  *************************************************************************/
1488  void configureScrollbars(void);
1489 
1490 
1495  bool selectRange(const MCLGridRef& start, const MCLGridRef& end);
1496 
1497 
1505  bool clearAllSelections_impl(void);
1506 
1507 
1516  ListboxItem* getItemAtPoint(const Vector2f& pt) const;
1517 
1518 
1525  bool setItemSelectState_impl(const MCLGridRef grid_ref, bool state);
1526 
1527 
1532  void setSelectForItemsInRow(uint row_idx, bool state);
1533 
1534 
1539  void setSelectForItemsInColumn(uint col_idx, bool state);
1540 
1541 
1549  void moveColumn_impl(uint col_idx, uint position);
1550 
1551 
1563  bool resetList_impl(void);
1564 
1565  // overrides function in base class.
1566  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
1567 
1568  // overrides function in base class.
1569  int writePropertiesXML(XMLSerializer& xml_stream) const;
1570 
1575  void resortList();
1576 
1577  /*************************************************************************
1578  New event handlers for multi column list
1579  *************************************************************************/
1584  virtual void onSelectionModeChanged(WindowEventArgs& e);
1585 
1586 
1591  virtual void onNominatedSelectColumnChanged(WindowEventArgs& e);
1592 
1593 
1598  virtual void onNominatedSelectRowChanged(WindowEventArgs& e);
1599 
1600 
1605  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
1606 
1607 
1612  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
1613 
1614 
1619  virtual void onSelectionChanged(WindowEventArgs& e);
1620 
1621 
1626  virtual void onListContentsChanged(WindowEventArgs& e);
1627 
1628 
1633  virtual void onSortColumnChanged(WindowEventArgs& e);
1634 
1635 
1640  virtual void onSortDirectionChanged(WindowEventArgs& e);
1641 
1642 
1647  virtual void onListColumnSized(WindowEventArgs& e);
1648 
1649 
1654  virtual void onListColumnMoved(WindowEventArgs& e);
1655 
1656 
1657  /*************************************************************************
1658  Overridden Event handlers
1659  *************************************************************************/
1660  virtual void onFontChanged(WindowEventArgs& e);
1661  virtual void onSized(ElementEventArgs& e);
1662  virtual void onMouseButtonDown(MouseEventArgs& e);
1663  virtual void onMouseWheel(MouseEventArgs& e);
1664 
1665 
1666  /*************************************************************************
1667  Handlers for subscribed events
1668  *************************************************************************/
1669  bool handleHeaderScroll(const EventArgs& e);
1670  bool handleHeaderSegMove(const EventArgs& e);
1671  bool handleColumnSizeChange(const EventArgs& e);
1672  bool handleHorzScrollbar(const EventArgs& e);
1673  bool handleVertScrollbar(const EventArgs& e);
1674  bool handleSortColumnChange(const EventArgs& e);
1675  bool handleSortDirectionChange(const EventArgs& e);
1676  bool handleHeaderSegDblClick(const EventArgs& e);
1677 
1683  struct ListRow
1684  {
1685  typedef std::vector<ListboxItem*
1686  CEGUI_VECTOR_ALLOC(ListboxItem*)> RowItems;
1687  RowItems d_items;
1688  uint d_sortColumn;
1689  uint d_rowID;
1690 
1691  // operators
1692  ListboxItem* const& operator[](uint idx) const {return d_items[idx];}
1693  ListboxItem*& operator[](uint idx) {return d_items[idx];}
1694  bool operator<(const ListRow& rhs) const;
1695  bool operator>(const ListRow& rhs) const;
1696  };
1697 
1698 
1703  static bool pred_descend(const ListRow& a, const ListRow& b);
1704 
1705 
1706  /*************************************************************************
1707  Implementation Data
1708  *************************************************************************/
1709  // scrollbar settings.
1712 
1713  // selection abilities.
1723 
1725 
1726  // storage of items in the list box.
1727  typedef std::vector<ListRow
1728  CEGUI_VECTOR_ALLOC(ListRow)> ListItemGrid;
1729  ListItemGrid d_grid;
1730 
1733 
1734  friend class MultiColumnListWindowRenderer;
1735 
1736 
1737 private:
1738  /*************************************************************************
1739  Private methods
1740  *************************************************************************/
1741  void addMultiColumnListProperties(void);
1742 };
1743 
1744 
1745 template<>
1746 class PropertyHelper<MultiColumnList::SelectionMode>
1747 {
1748 public:
1752  typedef String string_return_type;
1753 
1754  static const String& getDataTypeName()
1755  {
1756  static String type("SelectionMode");
1757 
1758  return type;
1759  }
1760 
1761  static return_type fromString(const String& str)
1762  {
1764 
1765  if (str == "RowMultiple")
1766  {
1767  mode = MultiColumnList::RowMultiple;
1768  }
1769  else if (str == "ColumnSingle")
1770  {
1771  mode = MultiColumnList::ColumnSingle;
1772  }
1773  else if (str == "ColumnMultiple")
1774  {
1775  mode = MultiColumnList::ColumnMultiple;
1776  }
1777  else if (str == "CellSingle")
1778  {
1779  mode = MultiColumnList::CellSingle;
1780  }
1781  else if (str == "CellMultiple")
1782  {
1783  mode = MultiColumnList::CellMultiple;
1784  }
1785  else if (str == "NominatedColumnSingle")
1786  {
1787  mode = MultiColumnList::NominatedColumnSingle;
1788  }
1789  else if (str == "NominatedColumnMultiple")
1790  {
1791  mode = MultiColumnList::NominatedColumnMultiple;
1792  }
1793  else if (str == "NominatedRowSingle")
1794  {
1795  mode = MultiColumnList::NominatedRowSingle;
1796  }
1797  else if (str == "NominatedRowMultiple")
1798  {
1799  mode = MultiColumnList::NominatedRowMultiple;
1800  }
1801  else
1802  {
1803  mode = MultiColumnList::RowSingle;
1804  }
1805  return mode;
1806  }
1807 
1808  static string_return_type toString(pass_type val)
1809  {
1810  switch(val)
1811  {
1812  case MultiColumnList::RowMultiple:
1813  return String("RowMultiple");
1814  break;
1815 
1816  case MultiColumnList::ColumnSingle:
1817  return String("ColumnSingle");
1818  break;
1819 
1820  case MultiColumnList::ColumnMultiple:
1821  return String("ColumnMultiple");
1822  break;
1823 
1824  case MultiColumnList::CellSingle:
1825  return String("CellSingle");
1826  break;
1827 
1828  case MultiColumnList::CellMultiple:
1829  return String("CellMultiple");
1830  break;
1831 
1832  case MultiColumnList::NominatedColumnSingle:
1833  return String("NominatedColumnSingle");
1834  break;
1835 
1836  case MultiColumnList::NominatedColumnMultiple:
1837  return String("NominatedColumnMultiple");
1838  break;
1839 
1840  case MultiColumnList::NominatedRowSingle:
1841  return String("NominatedRowSingle");
1842  break;
1843 
1844  case MultiColumnList::NominatedRowMultiple:
1845  return String("NominatedRowMultiple");
1846  break;
1847 
1848  default:
1849  return String("RowSingle");
1850  break;
1851  }
1852  }
1853 };
1854 
1855 
1856 } // End of CEGUI namespace section
1857 
1858 #if defined(_MSC_VER)
1859 # pragma warning(pop)
1860 #endif
1861 
1862 #endif // end of guard _CEGUIMultiColumnList_h_