Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
widgets/MultiColumnList.h
1 /***********************************************************************
2  created: 13/4/2004
3  author: Paul D Turner
4 
5  purpose: Interface to base class for MultiColumnList widget
6 *************************************************************************/
7 /***************************************************************************
8  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  ***************************************************************************/
29 #ifndef _CEGUIMultiColumnList_h_
30 #define _CEGUIMultiColumnList_h_
31 
32 #include "../Base.h"
33 #include "../Window.h"
34 #include "./ListHeader.h"
35 
36 #if defined(_MSC_VER)
37 # pragma warning(push)
38 # pragma warning(disable : 4251)
39 #endif
40 
41 
42 // Start of CEGUI namespace section
43 namespace CEGUI
44 {
45 
50 struct CEGUIEXPORT MCLGridRef
51 {
52  MCLGridRef(uint r, uint c) : row(r), column(c) {}
53 
54  uint row;
55  uint column;
56 
57  // operators
58  MCLGridRef& operator=(const MCLGridRef& rhs);
59  bool operator<(const MCLGridRef& rhs) const;
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 };
66 
72 {
73 public:
79 
89  virtual Rectf getListRenderArea(void) const = 0;
90 };
91 
96 class CEGUIEXPORT MultiColumnList : public Window
97 {
98 public:
99  static const String EventNamespace;
100  static const String WidgetTypeName;
101 
102  /*************************************************************************
103  Constants
104  *************************************************************************/
105  // Event names
172 
173  /*************************************************************************
174  Child Widget name constants
175  *************************************************************************/
176  static const String VertScrollbarName;
177  static const String HorzScrollbarName;
178  static const String ListHeaderName;
179 
180  /*************************************************************************
181  Enumerations
182  *************************************************************************/
188  {
189  RowSingle, // Any single row may be selected. All items in the row are selected.
190  RowMultiple, // Multiple rows may be selected. All items in the row are selected.
191  CellSingle, // Any single cell may be selected.
192  CellMultiple, // Multiple cells bay be selected.
193  NominatedColumnSingle, // Any single item in a nominated column may be selected.
194  NominatedColumnMultiple, // Multiple items in a nominated column may be selected.
195  ColumnSingle, // Any single column may be selected. All items in the column are selected.
196  ColumnMultiple, // Multiple columns may be selected. All items in the column are selected.
197  NominatedRowSingle, // Any single item in a nominated row may be selected.
198  NominatedRowMultiple // Multiple items in a nominated row may be selected.
199  };
200 
201 
202  /*************************************************************************
203  Accessor Methods
204  *************************************************************************/
213  bool isUserSortControlEnabled(void) const;
214 
215 
223  bool isUserColumnSizingEnabled(void) const;
224 
225 
233  bool isUserColumnDraggingEnabled(void) const;
234 
235 
243  uint getColumnCount(void) const;
244 
245 
253  uint getRowCount(void) const;
254 
255 
266  uint getSortColumn(void) const;
267  uint getSortColumnID(void) const;
268 
281  uint getColumnWithID(uint col_id) const;
282 
283 
296  uint getColumnWithHeaderText(const String& text) const;
297 
298 
306  UDim getTotalColumnHeadersWidth(void) const;
307 
308 
321  UDim getColumnHeaderWidth(uint col_idx) const;
322 
323 
331  ListHeaderSegment::SortDirection getSortDirection(void) const;
332 
333 
346  ListHeaderSegment& getHeaderSegmentForColumn(uint col_idx) const;
347 
348 
361  uint getItemRowIndex(const ListboxItem* item) const;
362 
363 
376  uint getItemColumnIndex(const ListboxItem* item) const;
377 
378 
391  MCLGridRef getItemGridReference(const ListboxItem* item) const;
392 
393 
406  ListboxItem* getItemAtGridReference(const MCLGridRef& grid_ref) const;
407 
408 
425  bool isListboxItemInColumn(const ListboxItem* item, uint col_idx) const;
426 
427 
444  bool isListboxItemInRow(const ListboxItem* item, uint row_idx) const;
445 
446 
458  bool isListboxItemInList(const ListboxItem* item) const;
459 
460 
479  ListboxItem* findColumnItemWithText(const String& text, uint col_idx, const ListboxItem* start_item) const;
480 
481 
500  ListboxItem* findRowItemWithText(const String& text, uint row_idx, const ListboxItem* start_item) const;
501 
502 
521  ListboxItem* findListItemWithText(const String& text, const ListboxItem* start_item) const;
522 
523 
534  ListboxItem* getFirstSelectedItem(void) const;
535 
536 
552  ListboxItem* getNextSelected(const ListboxItem* start_item) const;
553 
554 
562  uint getSelectedCount(void) const;
563 
564 
578  bool isItemSelected(const MCLGridRef& grid_ref) const;
579 
580 
592  uint getNominatedSelectionColumnID(void) const;
593 
594 
603  uint getNominatedSelectionColumn(void) const;
604 
605 
614  uint getNominatedSelectionRow(void) const;
615 
616 
624  MultiColumnList::SelectionMode getSelectionMode(void) const;
625 
626 
635  bool isVertScrollbarAlwaysShown(void) const;
636 
637 
646  bool isHorzScrollbarAlwaysShown(void) const;
647 
648 
661  uint getColumnID(uint col_idx) const;
662 
663 
676  uint getRowID(uint row_idx) const;
677 
678 
691  uint getRowWithID(uint row_id) const;
692 
693 
703  Rectf getListRenderArea(void) const;
704 
705 
717  Scrollbar* getVertScrollbar() const;
718 
730  Scrollbar* getHorzScrollbar() const;
731 
743  ListHeader* getListHeader() const;
744 
749  float getTotalRowsHeight(void) const;
750 
755  float getWidestColumnItemWidth(uint col_idx) const;
756 
761  float getHighestRowItemHeight(uint row_idx) const;
762 
772  bool getAutoSizeColumnUsesHeader() const;
773 
774  /*************************************************************************
775  Manipulator Methods
776  *************************************************************************/
787  virtual void initialiseComponents(void);
788 
789 
796  void resetList(void);
797 
798 
815  void addColumn(const String& text, uint col_id, const UDim& width);
816  void addColumn(const String& value);
817 
838  void insertColumn(const String& text, uint col_id, const UDim& width, uint position);
839 
840 
853  void removeColumn(uint col_idx);
854 
855 
868  void removeColumnWithID(uint col_id);
869 
870 
886  void moveColumn(uint col_idx, uint position);
887 
888 
904  void moveColumnWithID(uint col_id, uint position);
905 
906 
921  uint addRow(uint row_id = 0);
922 
923 
946  uint addRow(ListboxItem* item, uint col_id, uint row_id = 0);
947 
948 
967  uint insertRow(uint row_idx, uint row_id = 0);
968 
969 
996  uint insertRow(ListboxItem* item, uint col_id, uint row_idx, uint row_id = 0);
997 
998 
1011  void removeRow(uint row_idx);
1012 
1013 
1029  void setItem(ListboxItem* item, const MCLGridRef& position);
1030 
1031 
1050  void setItem(ListboxItem* item, uint col_id, uint row_idx);
1051 
1052 
1065  void setSelectionMode(MultiColumnList::SelectionMode sel_mode);
1066 
1067 
1080  void setNominatedSelectionColumnID(uint col_id);
1081 
1082 
1095  void setNominatedSelectionColumn(uint col_idx);
1096 
1097 
1110  void setNominatedSelectionRow(uint row_idx);
1111 
1112 
1123  void setSortDirection(ListHeaderSegment::SortDirection direction);
1124 
1125 
1138  void setSortColumn(uint col_idx);
1139 
1140 
1153  void setSortColumnByID(uint col_id);
1154 
1155 
1167  void setShowVertScrollbar(bool setting);
1168 
1169 
1181  void setShowHorzScrollbar(bool setting);
1182 
1183 
1191  void clearAllSelections(void);
1192 
1193 
1214  void setItemSelectState(ListboxItem* item, bool state);
1215 
1216 
1237  void setItemSelectState(const MCLGridRef& grid_ref, bool state);
1238 
1239 
1248  void handleUpdatedItemData(void);
1249 
1250 
1266  void setColumnHeaderWidth(uint col_idx, const UDim& width);
1267 
1268 
1280  void setUserSortControlEnabled(bool setting);
1281 
1282 
1294  void setUserColumnSizingEnabled(bool setting);
1295 
1296 
1305  void setUserColumnDraggingEnabled(bool setting);
1306 
1307 
1321  void autoSizeColumnHeader(uint col_idx);
1322 
1323 
1339  void setRowID(uint row_idx, uint row_id);
1340 
1356  void ensureItemIsVisible(const ListboxItem* item);
1357 
1370  void ensureItemIsVisible(const MCLGridRef& grid_ref);
1371 
1387  void ensureItemRowIsVisible(const ListboxItem* item);
1388 
1404  void ensureItemColumnIsVisible(const ListboxItem* item);
1405 
1417  void ensureRowIsVisible(uint row_idx);
1418 
1430  void ensureColumnIsVisible(uint column_idx);
1431 
1444  void setAutoSizeColumnUsesHeader(bool include_header);
1445 
1446 
1447  /*************************************************************************
1448  Construction and Destruction
1449  *************************************************************************/
1454  MultiColumnList(const String& type, const String& name);
1455 
1456 
1461  virtual ~MultiColumnList(void);
1462 
1463 
1464 protected:
1465  /*************************************************************************
1466  Implementation Functions (abstract interface)
1467  *************************************************************************/
1477  //virtual Rect getListRenderArea_impl(void) const = 0;
1478 
1479 
1480  /*************************************************************************
1481  Implementation Functions
1482  *************************************************************************/
1487  void configureScrollbars(void);
1488 
1489 
1494  bool selectRange(const MCLGridRef& start, const MCLGridRef& end);
1495 
1496 
1504  bool clearAllSelections_impl(void);
1505 
1506 
1515  ListboxItem* getItemAtPoint(const Vector2f& pt) const;
1516 
1517 
1524  bool setItemSelectState_impl(const MCLGridRef grid_ref, bool state);
1525 
1526 
1531  void setSelectForItemsInRow(uint row_idx, bool state);
1532 
1533 
1538  void setSelectForItemsInColumn(uint col_idx, bool state);
1539 
1540 
1548  void moveColumn_impl(uint col_idx, uint position);
1549 
1550 
1562  bool resetList_impl(void);
1563 
1564  // overrides function in base class.
1565  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
1566 
1567  // overrides function in base class.
1568  int writePropertiesXML(XMLSerializer& xml_stream) const;
1569 
1574  void resortList();
1575 
1576  /*************************************************************************
1577  New event handlers for multi column list
1578  *************************************************************************/
1583  virtual void onSelectionModeChanged(WindowEventArgs& e);
1584 
1585 
1590  virtual void onNominatedSelectColumnChanged(WindowEventArgs& e);
1591 
1592 
1597  virtual void onNominatedSelectRowChanged(WindowEventArgs& e);
1598 
1599 
1604  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
1605 
1606 
1611  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
1612 
1613 
1618  virtual void onSelectionChanged(WindowEventArgs& e);
1619 
1620 
1625  virtual void onListContentsChanged(WindowEventArgs& e);
1626 
1627 
1632  virtual void onSortColumnChanged(WindowEventArgs& e);
1633 
1634 
1639  virtual void onSortDirectionChanged(WindowEventArgs& e);
1640 
1641 
1646  virtual void onListColumnSized(WindowEventArgs& e);
1647 
1648 
1653  virtual void onListColumnMoved(WindowEventArgs& e);
1654 
1655 
1656  /*************************************************************************
1657  Overridden Event handlers
1658  *************************************************************************/
1659  virtual void onFontChanged(WindowEventArgs& e);
1660  virtual void onSized(ElementEventArgs& e);
1661  virtual void onMouseButtonDown(MouseEventArgs& e);
1662  virtual void onMouseWheel(MouseEventArgs& e);
1663 
1664 
1665  /*************************************************************************
1666  Handlers for subscribed events
1667  *************************************************************************/
1668  bool handleHeaderScroll(const EventArgs& e);
1669  bool handleHeaderSegMove(const EventArgs& e);
1670  bool handleColumnSizeChange(const EventArgs& e);
1671  bool handleHorzScrollbar(const EventArgs& e);
1672  bool handleVertScrollbar(const EventArgs& e);
1673  bool handleSortColumnChange(const EventArgs& e);
1674  bool handleSortDirectionChange(const EventArgs& e);
1675  bool handleHeaderSegDblClick(const EventArgs& e);
1676 
1682  struct ListRow
1683  {
1684  typedef std::vector<ListboxItem*
1685  CEGUI_VECTOR_ALLOC(ListboxItem*)> RowItems;
1686  RowItems d_items;
1687  uint d_sortColumn;
1688  uint d_rowID;
1689 
1690  // operators
1691  ListboxItem* const& operator[](uint idx) const {return d_items[idx];}
1692  ListboxItem*& operator[](uint idx) {return d_items[idx];}
1693  bool operator<(const ListRow& rhs) const;
1694  bool operator>(const ListRow& rhs) const;
1695  };
1696 
1697 
1702  static bool pred_descend(const ListRow& a, const ListRow& b);
1703 
1704 
1705  /*************************************************************************
1706  Implementation Data
1707  *************************************************************************/
1708  // scrollbar settings.
1711 
1712  // selection abilities.
1722 
1724 
1725  // storage of items in the list box.
1726  typedef std::vector<ListRow
1727  CEGUI_VECTOR_ALLOC(ListRow)> ListItemGrid;
1728  ListItemGrid d_grid;
1729 
1732 
1733  friend class MultiColumnListWindowRenderer;
1734 
1735 
1736 private:
1737  /*************************************************************************
1738  Private methods
1739  *************************************************************************/
1740  void addMultiColumnListProperties(void);
1741 };
1742 
1743 
1744 template<>
1745 class PropertyHelper<MultiColumnList::SelectionMode>
1746 {
1747 public:
1751  typedef String string_return_type;
1752 
1753  static const String& getDataTypeName()
1754  {
1755  static String type("SelectionMode");
1756 
1757  return type;
1758  }
1759 
1760  static return_type fromString(const String& str)
1761  {
1763 
1764  if (str == "RowMultiple")
1765  {
1766  mode = MultiColumnList::RowMultiple;
1767  }
1768  else if (str == "ColumnSingle")
1769  {
1770  mode = MultiColumnList::ColumnSingle;
1771  }
1772  else if (str == "ColumnMultiple")
1773  {
1774  mode = MultiColumnList::ColumnMultiple;
1775  }
1776  else if (str == "CellSingle")
1777  {
1778  mode = MultiColumnList::CellSingle;
1779  }
1780  else if (str == "CellMultiple")
1781  {
1782  mode = MultiColumnList::CellMultiple;
1783  }
1784  else if (str == "NominatedColumnSingle")
1785  {
1786  mode = MultiColumnList::NominatedColumnSingle;
1787  }
1788  else if (str == "NominatedColumnMultiple")
1789  {
1790  mode = MultiColumnList::NominatedColumnMultiple;
1791  }
1792  else if (str == "NominatedRowSingle")
1793  {
1794  mode = MultiColumnList::NominatedRowSingle;
1795  }
1796  else if (str == "NominatedRowMultiple")
1797  {
1798  mode = MultiColumnList::NominatedRowMultiple;
1799  }
1800  else
1801  {
1802  mode = MultiColumnList::RowSingle;
1803  }
1804  return mode;
1805  }
1806 
1807  static string_return_type toString(pass_type val)
1808  {
1809  switch(val)
1810  {
1811  case MultiColumnList::RowMultiple:
1812  return String("RowMultiple");
1813  break;
1814 
1815  case MultiColumnList::ColumnSingle:
1816  return String("ColumnSingle");
1817  break;
1818 
1819  case MultiColumnList::ColumnMultiple:
1820  return String("ColumnMultiple");
1821  break;
1822 
1823  case MultiColumnList::CellSingle:
1824  return String("CellSingle");
1825  break;
1826 
1827  case MultiColumnList::CellMultiple:
1828  return String("CellMultiple");
1829  break;
1830 
1831  case MultiColumnList::NominatedColumnSingle:
1832  return String("NominatedColumnSingle");
1833  break;
1834 
1835  case MultiColumnList::NominatedColumnMultiple:
1836  return String("NominatedColumnMultiple");
1837  break;
1838 
1839  case MultiColumnList::NominatedRowSingle:
1840  return String("NominatedRowSingle");
1841  break;
1842 
1843  case MultiColumnList::NominatedRowMultiple:
1844  return String("NominatedRowMultiple");
1845  break;
1846 
1847  default:
1848  return String("RowSingle");
1849  break;
1850  }
1851  }
1852 };
1853 
1854 
1855 } // End of CEGUI namespace section
1856 
1857 #if defined(_MSC_VER)
1858 # pragma warning(pop)
1859 #endif
1860 
1861 #endif // end of guard _CEGUIMultiColumnList_h_