Crazy Eddies GUI System  0.7.1
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
120 
121  /*************************************************************************
122  Child Widget name suffix constants
123  *************************************************************************/
127 
128  /*************************************************************************
129  Enumerations
130  *************************************************************************/
136  {
137  RowSingle, // Any single row may be selected. All items in the row are selected.
138  RowMultiple, // Multiple rows may be selected. All items in the row are selected.
139  CellSingle, // Any single cell may be selected.
140  CellMultiple, // Multiple cells bay be selected.
141  NominatedColumnSingle, // Any single item in a nominated column may be selected.
142  NominatedColumnMultiple, // Multiple items in a nominated column may be selected.
143  ColumnSingle, // Any single column may be selected. All items in the column are selected.
144  ColumnMultiple, // Multiple columns may be selected. All items in the column are selected.
145  NominatedRowSingle, // Any single item in a nominated row may be selected.
146  NominatedRowMultiple // Multiple items in a nominated row may be selected.
147  };
148 
149 
150  /*************************************************************************
151  Accessor Methods
152  *************************************************************************/
161  bool isUserSortControlEnabled(void) const;
162 
163 
171  bool isUserColumnSizingEnabled(void) const;
172 
173 
181  bool isUserColumnDraggingEnabled(void) const;
182 
183 
191  uint getColumnCount(void) const;
192 
193 
201  uint getRowCount(void) const;
202 
203 
214  uint getSortColumn(void) const;
215 
216 
229  uint getColumnWithID(uint col_id) const;
230 
231 
244  uint getColumnWithHeaderText(const String& text) const;
245 
246 
254  UDim getTotalColumnHeadersWidth(void) const;
255 
256 
269  UDim getColumnHeaderWidth(uint col_idx) const;
270 
271 
279  ListHeaderSegment::SortDirection getSortDirection(void) const;
280 
281 
294  ListHeaderSegment& getHeaderSegmentForColumn(uint col_idx) const;
295 
296 
309  uint getItemRowIndex(const ListboxItem* item) const;
310 
311 
324  uint getItemColumnIndex(const ListboxItem* item) const;
325 
326 
339  MCLGridRef getItemGridReference(const ListboxItem* item) const;
340 
341 
354  ListboxItem* getItemAtGridReference(const MCLGridRef& grid_ref) const;
355 
356 
373  bool isListboxItemInColumn(const ListboxItem* item, uint col_idx) const;
374 
375 
392  bool isListboxItemInRow(const ListboxItem* item, uint row_idx) const;
393 
394 
406  bool isListboxItemInList(const ListboxItem* item) const;
407 
408 
427  ListboxItem* findColumnItemWithText(const String& text, uint col_idx, const ListboxItem* start_item) const;
428 
429 
448  ListboxItem* findRowItemWithText(const String& text, uint row_idx, const ListboxItem* start_item) const;
449 
450 
469  ListboxItem* findListItemWithText(const String& text, const ListboxItem* start_item) const;
470 
471 
482  ListboxItem* getFirstSelectedItem(void) const;
483 
484 
500  ListboxItem* getNextSelected(const ListboxItem* start_item) const;
501 
502 
510  uint getSelectedCount(void) const;
511 
512 
526  bool isItemSelected(const MCLGridRef& grid_ref) const;
527 
528 
540  uint getNominatedSelectionColumnID(void) const;
541 
542 
551  uint getNominatedSelectionColumn(void) const;
552 
553 
562  uint getNominatedSelectionRow(void) const;
563 
564 
572  MultiColumnList::SelectionMode getSelectionMode(void) const;
573 
574 
583  bool isVertScrollbarAlwaysShown(void) const;
584 
585 
594  bool isHorzScrollbarAlwaysShown(void) const;
595 
596 
609  uint getColumnID(uint col_idx) const;
610 
611 
624  uint getRowID(uint row_idx) const;
625 
626 
639  uint getRowWithID(uint row_id) const;
640 
641 
651  Rect getListRenderArea(void) const;
652 
653 
665  Scrollbar* getVertScrollbar() const;
666 
678  Scrollbar* getHorzScrollbar() const;
679 
691  ListHeader* getListHeader() const;
692 
697  float getTotalRowsHeight(void) const;
698 
703  float getWidestColumnItemWidth(uint col_idx) const;
704 
709  float getHighestRowItemHeight(uint row_idx) const;
710 
711  /*************************************************************************
712  Manipulator Methods
713  *************************************************************************/
724  virtual void initialiseComponents(void);
725 
726 
733  void resetList(void);
734 
735 
752  void addColumn(const String& text, uint col_id, const UDim& width);
753 
754 
775  void insertColumn(const String& text, uint col_id, const UDim& width, uint position);
776 
777 
790  void removeColumn(uint col_idx);
791 
792 
805  void removeColumnWithID(uint col_id);
806 
807 
823  void moveColumn(uint col_idx, uint position);
824 
825 
841  void moveColumnWithID(uint col_id, uint position);
842 
843 
858  uint addRow(uint row_id = 0);
859 
860 
883  uint addRow(ListboxItem* item, uint col_id, uint row_id = 0);
884 
885 
904  uint insertRow(uint row_idx, uint row_id = 0);
905 
906 
933  uint insertRow(ListboxItem* item, uint col_id, uint row_idx, uint row_id = 0);
934 
935 
948  void removeRow(uint row_idx);
949 
950 
966  void setItem(ListboxItem* item, const MCLGridRef& position);
967 
968 
987  void setItem(ListboxItem* item, uint col_id, uint row_idx);
988 
989 
1002  void setSelectionMode(MultiColumnList::SelectionMode sel_mode);
1003 
1004 
1017  void setNominatedSelectionColumnID(uint col_id);
1018 
1019 
1032  void setNominatedSelectionColumn(uint col_idx);
1033 
1034 
1047  void setNominatedSelectionRow(uint row_idx);
1048 
1049 
1060  void setSortDirection(ListHeaderSegment::SortDirection direction);
1061 
1062 
1075  void setSortColumn(uint col_idx);
1076 
1077 
1090  void setSortColumnByID(uint col_id);
1091 
1092 
1104  void setShowVertScrollbar(bool setting);
1105 
1106 
1118  void setShowHorzScrollbar(bool setting);
1119 
1120 
1128  void clearAllSelections(void);
1129 
1130 
1151  void setItemSelectState(ListboxItem* item, bool state);
1152 
1153 
1174  void setItemSelectState(const MCLGridRef& grid_ref, bool state);
1175 
1176 
1185  void handleUpdatedItemData(void);
1186 
1187 
1203  void setColumnHeaderWidth(uint col_idx, const UDim& width);
1204 
1205 
1217  void setUserSortControlEnabled(bool setting);
1218 
1219 
1231  void setUserColumnSizingEnabled(bool setting);
1232 
1233 
1242  void setUserColumnDraggingEnabled(bool setting);
1243 
1244 
1258  void autoSizeColumnHeader(uint col_idx);
1259 
1260 
1276  void setRowID(uint row_idx, uint row_id);
1277 
1278 
1279  /*************************************************************************
1280  Construction and Destruction
1281  *************************************************************************/
1286  MultiColumnList(const String& type, const String& name);
1287 
1288 
1293  virtual ~MultiColumnList(void);
1294 
1295 
1296 protected:
1297  /*************************************************************************
1298  Implementation Functions (abstract interface)
1299  *************************************************************************/
1309  //virtual Rect getListRenderArea_impl(void) const = 0;
1310 
1311 
1312  /*************************************************************************
1313  Implementation Functions
1314  *************************************************************************/
1319  void configureScrollbars(void);
1320 
1321 
1326  bool selectRange(const MCLGridRef& start, const MCLGridRef& end);
1327 
1328 
1336  bool clearAllSelections_impl(void);
1337 
1338 
1347  ListboxItem* getItemAtPoint(const Point& pt) const;
1348 
1349 
1356  bool setItemSelectState_impl(const MCLGridRef grid_ref, bool state);
1357 
1358 
1363  void setSelectForItemsInRow(uint row_idx, bool state);
1364 
1365 
1370  void setSelectForItemsInColumn(uint col_idx, bool state);
1371 
1372 
1380  void moveColumn_impl(uint col_idx, uint position);
1381 
1382 
1394  bool resetList_impl(void);
1395 
1396 
1407  virtual bool testClassName_impl(const String& class_name) const
1408  {
1409  if (class_name=="MultiColumnList") return true;
1410  return Window::testClassName_impl(class_name);
1411  }
1412 
1413 
1414  // overrides function in base class.
1415  virtual bool validateWindowRenderer(const String& name) const
1416  {
1417  return (name == "MultiColumnList");
1418  }
1419 
1420  // overrides function in base class.
1421  int writePropertiesXML(XMLSerializer& xml_stream) const;
1422 
1427  void resortList();
1428 
1429  /*************************************************************************
1430  New event handlers for multi column list
1431  *************************************************************************/
1436  virtual void onSelectionModeChanged(WindowEventArgs& e);
1437 
1438 
1443  virtual void onNominatedSelectColumnChanged(WindowEventArgs& e);
1444 
1445 
1450  virtual void onNominatedSelectRowChanged(WindowEventArgs& e);
1451 
1452 
1457  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
1458 
1459 
1464  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
1465 
1466 
1471  virtual void onSelectionChanged(WindowEventArgs& e);
1472 
1473 
1478  virtual void onListContentsChanged(WindowEventArgs& e);
1479 
1480 
1485  virtual void onSortColumnChanged(WindowEventArgs& e);
1486 
1487 
1492  virtual void onSortDirectionChanged(WindowEventArgs& e);
1493 
1494 
1499  virtual void onListColumnSized(WindowEventArgs& e);
1500 
1501 
1506  virtual void onListColumnMoved(WindowEventArgs& e);
1507 
1508 
1509  /*************************************************************************
1510  Overridden Event handlers
1511  *************************************************************************/
1512  virtual void onFontChanged(WindowEventArgs& e);
1513  virtual void onSized(WindowEventArgs& e);
1514  virtual void onMouseButtonDown(MouseEventArgs& e);
1515  virtual void onMouseWheel(MouseEventArgs& e);
1516 
1517 
1518  /*************************************************************************
1519  Handlers for subscribed events
1520  *************************************************************************/
1521  bool handleHeaderScroll(const EventArgs& e);
1522  bool handleHeaderSegMove(const EventArgs& e);
1523  bool handleColumnSizeChange(const EventArgs& e);
1524  bool handleHorzScrollbar(const EventArgs& e);
1525  bool handleVertScrollbar(const EventArgs& e);
1526  bool handleSortColumnChange(const EventArgs& e);
1527  bool handleSortDirectionChange(const EventArgs& e);
1528  bool handleHeaderSegDblClick(const EventArgs& e);
1529 
1535  struct ListRow
1536  {
1537  typedef std::vector<ListboxItem*> RowItems;
1538  RowItems d_items;
1539  uint d_sortColumn;
1540  uint d_rowID;
1541 
1542  // operators
1543  ListboxItem* const& operator[](uint idx) const {return d_items[idx];}
1544  ListboxItem*& operator[](uint idx) {return d_items[idx];}
1545  bool operator<(const ListRow& rhs) const;
1546  bool operator>(const ListRow& rhs) const;
1547  };
1548 
1549 
1554  static bool pred_descend(const ListRow& a, const ListRow& b);
1555 
1556 
1557  /*************************************************************************
1558  Implementation Data
1559  *************************************************************************/
1560  // scrollbar settings.
1563 
1564  // selection abilities.
1574 
1576 
1577  // storage of items in the list box.
1578  typedef std::vector<ListRow> ListItemGrid;
1579  ListItemGrid d_grid;
1580 
1581  friend class MultiColumnListWindowRenderer;
1582 
1583 
1584 private:
1585  /*************************************************************************
1586  Static Properties for this class
1587  *************************************************************************/
1588  static MultiColumnListProperties::ColumnsMovable d_columnsMovableProperty;
1589  static MultiColumnListProperties::ColumnsSizable d_columnsSizableProperty;
1590  static MultiColumnListProperties::ForceHorzScrollbar d_forceHorzScrollProperty;
1591  static MultiColumnListProperties::ForceVertScrollbar d_forceVertScrollProperty;
1592  static MultiColumnListProperties::NominatedSelectionColumnID d_nominatedSelectColProperty;
1593  static MultiColumnListProperties::NominatedSelectionRow d_nominatedSelectRowProperty;
1594  static MultiColumnListProperties::SelectionMode d_selectModeProperty;
1595  static MultiColumnListProperties::SortColumnID d_sortColumnIDProperty;
1596  static MultiColumnListProperties::SortDirection d_sortDirectionProperty;
1597  static MultiColumnListProperties::SortSettingEnabled d_sortSettingProperty;
1598  static MultiColumnListProperties::ColumnHeader d_columnHeaderProperty;
1599  static MultiColumnListProperties::RowCount d_rowCountProperty;
1600 
1601 
1602  /*************************************************************************
1603  Private methods
1604  *************************************************************************/
1605  void addMultiColumnListProperties(void);
1606 };
1607 
1608 } // End of CEGUI namespace section
1609 
1610 #if defined(_MSC_VER)
1611 # pragma warning(pop)
1612 #endif
1613 
1614 #endif // end of guard _CEGUIMultiColumnList_h_