Planeshift
pawslistbox.h
Go to the documentation of this file.
1 /*
2  * pawslistbox.h - Author: Andrew Craig
3  *
4  * Copyright (C) 2003 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef PAWS_LIST_BOX_HEADER
21 #define PAWS_LIST_BOX_HEADER
22 
23 #include "pawswidget.h"
24 #include "pawsmanager.h"
25 #include "pawstextbox.h"
26 #include "util/log.h"
27 
28 class pawsScrollBar;
29 
36 
38 int textBoxSortFunc(pawsWidget* widgetA, pawsWidget* widgetB);
39 
41 int textBoxSortFunc_number(pawsWidget * widgetA, pawsWidget * widgetB);
42 
43 //-----------------------------------------------------------------------------
44 // struct ColumnInfo
45 //-----------------------------------------------------------------------------
46 
53 struct ColumnDef
54 {
56  {
57  widgetNode = NULL;
58  sortFunc = NULL;
59  sortable = true;
60  width = 0;
61  height = 0;
62  }
63 
64  int width;
65  int height;
66  csRef<iDocumentNode> widgetNode;
67  csString xmlbinding;
68  bool sortable;
69 
71 };
72 
73 
74 #define LISTBOX_HIGHLIGHTED 0x01
75 #define LISTBOX_SELECTED 0x02
76 
77 //-----------------------------------------------------------------------------
78 // class pawsListBoxRow
79 //-----------------------------------------------------------------------------
80 
81 
85 class pawsListBoxRow : public pawsWidget
86 {
87 public:
89  pawsListBoxRow(const pawsListBoxRow &origin);
91  pawsWidget* GetColumn(size_t column);
92 
94  size_t GetTotalColumns()
95  {
96  return columns.GetSize();
97  }
98 
100  void AddColumn(int column, ColumnDef* def);
101 
103  void AddTitleColumn(int column, ColumnDef* def);
104 
105  bool OnKeyDown(utf32_char keyCode, utf32_char keyChar, int modifiers);
106 
108  bool OnMouseDown(int button, int modifiers, int x, int y);
109 
111  bool OnDoubleClick(int button, int modifiers, int x, int y);
112 
114  void SetHeading(bool flag);
115 
117  void SetTitleRow(bool flag);
118 
120  int GetLastIndex()const
121  {
122  return lastIndex;
123  }
124 
126  void SetLastIndex(int index)
127  {
128  lastIndex = index;
129  }
130 
135  void Hide();
136 
137  bool IsHeading()
138  {
139  return isHeading;
140  }
141 
142 private:
143 
144  bool isHeading;
145  bool isTitleRow;
146 
147  int lastIndex;
148 
150  csArray<pawsWidget*> columns;
151 
152 };
153 
154 
155 //-----------------------------------------------------------------------------
156 // class pawsListBox
157 //-----------------------------------------------------------------------------
158 
159 
160 #define LISTBOX_MOUSE_SCROLL_AMOUNT 3
161 
202 class pawsListBox : public pawsWidget
203 {
204 public:
205  pawsListBox();
206  pawsListBox(const pawsListBox &origin);
207  bool Setup(iDocumentNode* node);
208  bool PostSetup();
209 
210  virtual ~pawsListBox();
211 
217  {
218  return selected;
219  }
220 
222  pawsListBoxRow* GetSelectedRow();
223 
225  const char* GetSelectedText(size_t columnId);
226 
228  int GetSelectedRowNum();
229 
231  pawsListBoxRow* RemoveSelected();
232 
234  void Remove(int id);
235 
237  void Remove(pawsListBoxRow* rowToRemove);
238 
239  void AddRow(pawsListBoxRow* row);
240 
242  size_t GetRowCount();
243 
245  pawsListBoxRow* GetRow(size_t x);
246 
248  pawsListBoxRow* NewRow(size_t position = (size_t)-1);
250  pawsListBoxRow* NewTextBoxRow(csList<csString> &rowEntry,size_t position = (size_t)-1);
251 
252  void Clear();
253 
255  void SendOnListAction(int status);
256 
258  bool Select(pawsListBoxRow* row, bool notify = true);
259 
261  bool SelectByIndex(int index, bool notify = true);
262 
264  void CreateTitleRow();
265 
266  virtual bool OnScroll(int direction, pawsScrollBar* widget);
267 
268  bool OnMouseDown(int button, int modifiers, int x, int y);
269 
271  {
272  return totalColumns;
273  }
274 
281  void SetTotalColumns(int numCols);
282 
293  void SetColumnDef(int col, int width, int height, const char* widgetDesc);
294 
295  void UseTitleRow(bool yes);
296 
300  virtual bool SelfPopulate(iDocumentNode* node);
301 
303  {
304  return selectable;
305  }
306 
310  bool IsAutoID()
311  {
312  return autoID;
313  }
314 
318  bool ConvertFromAutoID(int id, int &row, int &col);
319 
323  void MoveSelectBar(bool direction);
324 
325  void CalculateDrawPositions();
326 
331  bool OnKeyDown(utf32_char keyCode, utf32_char keyChar, int modifiers);
332 
333  void Resize();
334 
340  void SetNotify(pawsWidget* target)
341  {
342  notifyTarget = target;
343  };
344 
349  int GetSortedColumn();
350  void SetSortedColumn(int colNum);
351 
352  bool GetSortOrder();
353  void SetSortOrder(bool ascOrder);
354 
359  void SetSortingFunc(int colNum, listBoxSortingFunc sortFunc);
360 
365  void SortRows();
366 
367 
371  pawsTextBox* GetTextCell(int rowNum, int colNum);
372 
376  csString GetTextCellValue(int rowNum, int colNum);
377 
381  void SetTextCellValue(int rowNum, int colNum, const csString &value);
382 
383  void AutoScrollUpdate(bool v)
384  {
385  autoUpdateScroll = v;
386  }
387 
388  void SetScrollBarMaxValue();
389  void MoveRow(int rownr,int dest);
390 
391 protected:
392 
399  static const int BORDER_SIZE = 5;
400 
401  void CreateSortingArrow(int colNum);
402  void SetSortingArrow(int colNum, bool ascOrder);
403  void CheckSortingArrow(int colNum, bool ascOrder);
404  void DeleteSortingArrow(int colNum);
405 
406  pawsWidget* GetColumnTitle(int colNum);
407 
413  int GetUnborderedHeight();
414 
416 
419 
423  int rowWidth;
424  int topRow;
425  int selected;
426  int xMod;
427  bool autoID;
430 
432 
435 
436  csArray<pawsListBoxRow*> rows;
438  csString xmlbinding_row;
439 
440  int sortColNum; // number of sorted column (or -1)
441  bool ascOrder;
442 
447  static int sort_cmp(const void* rowA, const void* rowB);
449  static int sort_sortColNum;
450  static bool sort_ascOrder;
451 
452  csString highlightImage;
453  unsigned int highlightAlpha;
454 
458  bool useBorder;
459  bool selectable; // can the user select listbox rows ?
460  csString arrowUp;
461  csString arrowDown;
462 };
463 
465 
466 
469 #endif
int columnHeight
Definition: pawslistbox.h:422
static int sort_sortColNum
Definition: pawslistbox.h:449
The main base widget that all other widgets should inherit from.
Definition: pawswidget.h:116
int(* listBoxSortingFunc)(pawsWidget *a, pawsWidget *b)
Type of functions that are used to compare listbox rows during sorting:
Definition: pawslistbox.h:35
void SetNotify(pawsWidget *target)
Sets the widget that will be notified when a row is selected.
Definition: pawslistbox.h:340
static listBoxSortingFunc sort_sortFunc
Definition: pawslistbox.h:448
int GetSelection()
Get the row that is currently selected.
Definition: pawslistbox.h:216
bool autoResize
Definition: pawslistbox.h:428
Defines the structure of the list box table.
Definition: pawslistbox.h:53
int textBoxSortFunc(pawsWidget *widgetA, pawsWidget *widgetB)
Compare function that works with listbox columns that are pawsTextBox widgets:
pawsWidget * notifyTarget
the widget that will be notified when a row is selected
Definition: pawslistbox.h:434
pawsListBoxRow * titleRow
Definition: pawslistbox.h:437
csRef< iDocumentNode > widgetNode
Definition: pawslistbox.h:66
bool IsHeading()
Definition: pawslistbox.h:137
int scrollbarHeightMod
Definition: pawslistbox.h:457
void AutoScrollUpdate(bool v)
Definition: pawslistbox.h:383
size_t GetTotalColumns()
Get total columns.
Definition: pawslistbox.h:94
pawsScrollBar * scrollBar
Definition: pawslistbox.h:417
bool useBorder
Definition: pawslistbox.h:458
int height
Definition: pawslistbox.h:65
csArray< pawsListBoxRow * > rows
Definition: pawslistbox.h:436
bool IsSelectable()
Definition: pawslistbox.h:302
int scrollbarWidth
Definition: pawslistbox.h:456
bool autoUpdateScroll
Definition: pawslistbox.h:429
void SetLastIndex(int index)
Sets the last index of the row. Is used by pawsListBox to update lastIndex variable when sorting...
Definition: pawslistbox.h:126
A simple list box widget.
Definition: pawslistbox.h:202
A simple scroll bar widget.
Definition: pawscrollbar.h:64
static bool sort_ascOrder
Definition: pawslistbox.h:450
bool selectable
Definition: pawslistbox.h:459
csString arrowUp
Definition: pawslistbox.h:460
int textBoxSortFunc_number(pawsWidget *widgetA, pawsWidget *widgetB)
Function that compares listbox rows which contain pawsTextBoxWidget with numbers inside.
csString arrowDown
Definition: pawslistbox.h:461
csString highlightImage
Definition: pawslistbox.h:452
int totalColumns
Definition: pawslistbox.h:420
pawsScrollBar * horzscrollBar
Definition: pawslistbox.h:418
int GetTotalColumns()
Definition: pawslistbox.h:270
csString xmlbinding
Passed to new column widgets to create.
Definition: pawslistbox.h:67
bool sortable
Definition: pawslistbox.h:68
A List Box Row.
Definition: pawslistbox.h:85
bool usingTitleRow
Definition: pawslistbox.h:415
ColumnDef * columnDef
Definition: pawslistbox.h:431
listBoxSortingFunc sortFunc
Definition: pawslistbox.h:70
unsigned int highlightAlpha
Definition: pawslistbox.h:453
csString xmlbinding_row
Definition: pawslistbox.h:438
bool IsAutoID()
Is this an autoID listbox.
Definition: pawslistbox.h:310
CREATE_PAWS_FACTORY(pawsListBox)
int GetLastIndex() const
Returns the last index of the row.
Definition: pawslistbox.h:120
A basic text box widget.
Definition: pawstextbox.h:42