Crazy Eddies GUI System  0.7.7
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 
766  /*************************************************************************
767  Manipulator Methods
768  *************************************************************************/
779  virtual void initialiseComponents(void);
780 
781 
788  void resetList(void);
789 
790 
807  void addColumn(const String& text, uint col_id, const UDim& width);
808 
809 
830  void insertColumn(const String& text, uint col_id, const UDim& width, uint position);
831 
832 
845  void removeColumn(uint col_idx);
846 
847 
860  void removeColumnWithID(uint col_id);
861 
862 
878  void moveColumn(uint col_idx, uint position);
879 
880 
896  void moveColumnWithID(uint col_id, uint position);
897 
898 
913  uint addRow(uint row_id = 0);
914 
915 
938  uint addRow(ListboxItem* item, uint col_id, uint row_id = 0);
939 
940 
959  uint insertRow(uint row_idx, uint row_id = 0);
960 
961 
988  uint insertRow(ListboxItem* item, uint col_id, uint row_idx, uint row_id = 0);
989 
990 
1003  void removeRow(uint row_idx);
1004 
1005 
1021  void setItem(ListboxItem* item, const MCLGridRef& position);
1022 
1023 
1042  void setItem(ListboxItem* item, uint col_id, uint row_idx);
1043 
1044 
1057  void setSelectionMode(MultiColumnList::SelectionMode sel_mode);
1058 
1059 
1072  void setNominatedSelectionColumnID(uint col_id);
1073 
1074 
1087  void setNominatedSelectionColumn(uint col_idx);
1088 
1089 
1102  void setNominatedSelectionRow(uint row_idx);
1103 
1104 
1115  void setSortDirection(ListHeaderSegment::SortDirection direction);
1116 
1117 
1130  void setSortColumn(uint col_idx);
1131 
1132 
1145  void setSortColumnByID(uint col_id);
1146 
1147 
1159  void setShowVertScrollbar(bool setting);
1160 
1161 
1173  void setShowHorzScrollbar(bool setting);
1174 
1175 
1183  void clearAllSelections(void);
1184 
1185 
1206  void setItemSelectState(ListboxItem* item, bool state);
1207 
1208 
1229  void setItemSelectState(const MCLGridRef& grid_ref, bool state);
1230 
1231 
1240  void handleUpdatedItemData(void);
1241 
1242 
1258  void setColumnHeaderWidth(uint col_idx, const UDim& width);
1259 
1260 
1272  void setUserSortControlEnabled(bool setting);
1273 
1274 
1286  void setUserColumnSizingEnabled(bool setting);
1287 
1288 
1297  void setUserColumnDraggingEnabled(bool setting);
1298 
1299 
1313  void autoSizeColumnHeader(uint col_idx);
1314 
1315 
1331  void setRowID(uint row_idx, uint row_id);
1332 
1333 
1334  /*************************************************************************
1335  Construction and Destruction
1336  *************************************************************************/
1341  MultiColumnList(const String& type, const String& name);
1342 
1343 
1348  virtual ~MultiColumnList(void);
1349 
1350 
1351 protected:
1352  /*************************************************************************
1353  Implementation Functions (abstract interface)
1354  *************************************************************************/
1364  //virtual Rect getListRenderArea_impl(void) const = 0;
1365 
1366 
1367  /*************************************************************************
1368  Implementation Functions
1369  *************************************************************************/
1374  void configureScrollbars(void);
1375 
1376 
1381  bool selectRange(const MCLGridRef& start, const MCLGridRef& end);
1382 
1383 
1391  bool clearAllSelections_impl(void);
1392 
1393 
1402  ListboxItem* getItemAtPoint(const Point& pt) const;
1403 
1404 
1411  bool setItemSelectState_impl(const MCLGridRef grid_ref, bool state);
1412 
1413 
1418  void setSelectForItemsInRow(uint row_idx, bool state);
1419 
1420 
1425  void setSelectForItemsInColumn(uint col_idx, bool state);
1426 
1427 
1435  void moveColumn_impl(uint col_idx, uint position);
1436 
1437 
1449  bool resetList_impl(void);
1450 
1451 
1462  virtual bool testClassName_impl(const String& class_name) const
1463  {
1464  if (class_name=="MultiColumnList") return true;
1465  return Window::testClassName_impl(class_name);
1466  }
1467 
1468 
1469  // overrides function in base class.
1470  virtual bool validateWindowRenderer(const String& name) const
1471  {
1472  return (name == "MultiColumnList");
1473  }
1474 
1475  // overrides function in base class.
1476  int writePropertiesXML(XMLSerializer& xml_stream) const;
1477 
1482  void resortList();
1483 
1484  /*************************************************************************
1485  New event handlers for multi column list
1486  *************************************************************************/
1491  virtual void onSelectionModeChanged(WindowEventArgs& e);
1492 
1493 
1498  virtual void onNominatedSelectColumnChanged(WindowEventArgs& e);
1499 
1500 
1505  virtual void onNominatedSelectRowChanged(WindowEventArgs& e);
1506 
1507 
1512  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
1513 
1514 
1519  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
1520 
1521 
1526  virtual void onSelectionChanged(WindowEventArgs& e);
1527 
1528 
1533  virtual void onListContentsChanged(WindowEventArgs& e);
1534 
1535 
1540  virtual void onSortColumnChanged(WindowEventArgs& e);
1541 
1542 
1547  virtual void onSortDirectionChanged(WindowEventArgs& e);
1548 
1549 
1554  virtual void onListColumnSized(WindowEventArgs& e);
1555 
1556 
1561  virtual void onListColumnMoved(WindowEventArgs& e);
1562 
1563 
1564  /*************************************************************************
1565  Overridden Event handlers
1566  *************************************************************************/
1567  virtual void onFontChanged(WindowEventArgs& e);
1568  virtual void onSized(WindowEventArgs& e);
1569  virtual void onMouseButtonDown(MouseEventArgs& e);
1570  virtual void onMouseWheel(MouseEventArgs& e);
1571 
1572 
1573  /*************************************************************************
1574  Handlers for subscribed events
1575  *************************************************************************/
1576  bool handleHeaderScroll(const EventArgs& e);
1577  bool handleHeaderSegMove(const EventArgs& e);
1578  bool handleColumnSizeChange(const EventArgs& e);
1579  bool handleHorzScrollbar(const EventArgs& e);
1580  bool handleVertScrollbar(const EventArgs& e);
1581  bool handleSortColumnChange(const EventArgs& e);
1582  bool handleSortDirectionChange(const EventArgs& e);
1583  bool handleHeaderSegDblClick(const EventArgs& e);
1584 
1590  struct ListRow
1591  {
1592  typedef std::vector<ListboxItem*> RowItems;
1593  RowItems d_items;
1594  uint d_sortColumn;
1595  uint d_rowID;
1596 
1597  // operators
1598  ListboxItem* const& operator[](uint idx) const {return d_items[idx];}
1599  ListboxItem*& operator[](uint idx) {return d_items[idx];}
1600  bool operator<(const ListRow& rhs) const;
1601  bool operator>(const ListRow& rhs) const;
1602  };
1603 
1604 
1609  static bool pred_descend(const ListRow& a, const ListRow& b);
1610 
1611 
1612  /*************************************************************************
1613  Implementation Data
1614  *************************************************************************/
1615  // scrollbar settings.
1618 
1619  // selection abilities.
1629 
1631 
1632  // storage of items in the list box.
1633  typedef std::vector<ListRow> ListItemGrid;
1634  ListItemGrid d_grid;
1635 
1636  friend class MultiColumnListWindowRenderer;
1637 
1638 
1639 private:
1640  /*************************************************************************
1641  Static Properties for this class
1642  *************************************************************************/
1643  static MultiColumnListProperties::ColumnsMovable d_columnsMovableProperty;
1644  static MultiColumnListProperties::ColumnsSizable d_columnsSizableProperty;
1645  static MultiColumnListProperties::ForceHorzScrollbar d_forceHorzScrollProperty;
1646  static MultiColumnListProperties::ForceVertScrollbar d_forceVertScrollProperty;
1647  static MultiColumnListProperties::NominatedSelectionColumnID d_nominatedSelectColProperty;
1648  static MultiColumnListProperties::NominatedSelectionRow d_nominatedSelectRowProperty;
1649  static MultiColumnListProperties::SelectionMode d_selectModeProperty;
1650  static MultiColumnListProperties::SortColumnID d_sortColumnIDProperty;
1651  static MultiColumnListProperties::SortDirection d_sortDirectionProperty;
1652  static MultiColumnListProperties::SortSettingEnabled d_sortSettingProperty;
1653  static MultiColumnListProperties::ColumnHeader d_columnHeaderProperty;
1654  static MultiColumnListProperties::RowCount d_rowCountProperty;
1655 
1656 
1657  /*************************************************************************
1658  Private methods
1659  *************************************************************************/
1660  void addMultiColumnListProperties(void);
1661 };
1662 
1663 } // End of CEGUI namespace section
1664 
1665 #if defined(_MSC_VER)
1666 # pragma warning(pop)
1667 #endif
1668 
1669 #endif // end of guard _CEGUIMultiColumnList_h_