FLTK
Fl_Table_Row.H
1 //
2 
3 #ifndef _FL_TABLE_ROW_H
4 #define _FL_TABLE_ROW_H
5 
6 //
7 // Fl_Table_Row -- A row oriented table widget for the Fast Light Tool Kit (FLTK).
8 //
9 // A class specializing in a table of rows.
10 // Handles row-specific selection behavior.
11 //
12 // Copyright 2002 by Greg Ercolano.
13 //
14 // This library is free software. Distribution and use rights are outlined in
15 // the file "COPYING" which should have been included with this file. If this
16 // file is missing or damaged, see the license at:
17 //
18 // https://www.fltk.org/COPYING.php
19 //
20 // Please see the following page on how to report bugs and issues:
21 //
22 // https://www.fltk.org/bugs.php
23 //
24 
25 #include <FL/Fl_Table.H>
26 
44 class FL_EXPORT Fl_Table_Row : public Fl_Table {
45 public:
46  enum TableRowSelectMode {
47  SELECT_NONE, // no selection allowed
48  SELECT_SINGLE, // single row selection
49  SELECT_MULTI // multiple row selection (default)
50  };
51 private:
52  // An STL-ish vector without templates
53  class FL_EXPORT CharVector {
54  char *arr;
55  int _size;
56  void init() {
57  arr = 0;
58  _size = 0;
59  }
60  void copy(char *newarr, int newsize);
61  public:
62  CharVector() { // CTOR
63  init();
64  }
65  ~CharVector(); // DTOR
66  CharVector(CharVector&o) { // COPY CTOR
67  init();
68  copy(o.arr, o._size);
69  }
70  CharVector& operator=(CharVector&o) { // ASSIGN
71  init();
72  copy(o.arr, o._size);
73  return(*this);
74  }
75  char operator[](int x) const {
76  return(arr[x]);
77  }
78  char& operator[](int x) {
79  return(arr[x]);
80  }
81  int size() {
82  return(_size);
83  }
84  void size(int count);
85  char pop_back() {
86  char tmp = arr[_size-1];
87  _size--;
88  return(tmp);
89  }
90  void push_back(char val) {
91  int x = _size;
92  size(_size+1);
93  arr[x] = val;
94  }
95  char back() {
96  return(arr[_size-1]);
97  }
98  };
99 
100  CharVector _rowselect; // selection flag for each row
101 
102  // handle() state variables.
103  // Put here instead of local statics in handle(), so more
104  // than one instance can exist without crosstalk between.
105  //
106  int _dragging_select; // dragging out a selection?
107  int _last_row;
108  int _last_y; // last event's Y position
109  int _last_push_x; // last PUSH event's X position
110  int _last_push_y; // last PUSH event's Y position
111 
112  TableRowSelectMode _selectmode;
113 
114 protected:
115  int handle(int event);
116  int find_cell(TableContext context, // find cell's x/y/w/h given r/c
117  int R, int C, int &X, int &Y, int &W, int &H) {
118  return(Fl_Table::find_cell(context, R, C, X, Y, W, H));
119  }
120 
121 public:
127  Fl_Table_Row(int X, int Y, int W, int H, const char *l=0) : Fl_Table(X,Y,W,H,l) {
128  _dragging_select = 0;
129  _last_row = -1;
130  _last_y = -1;
131  _last_push_x = -1;
132  _last_push_y = -1;
133  _selectmode = SELECT_MULTI;
134  }
135 
141 
142  void rows(int val); // set number of rows
143  int rows() { // get number of rows
144  return(Fl_Table::rows());
145  }
146 
154  void type(TableRowSelectMode val); // set selection mode
155 
156  TableRowSelectMode type() const { // get selection mode
157  return(_selectmode);
158  }
159 
165  int row_selected(int row); // is row selected? (0=no, 1=yes, -1=range err)
166 
171  int select_row(int row, int flag=1); // select state for row: flag:0=off, 1=on, 2=toggle
172  // returns: 0=no change, 1=changed, -1=range err
173 
178  void select_all_rows(int flag=1); // all rows to a known state
179 
180  void clear() {
181  rows(0); // implies clearing selection
182  cols(0);
183  Fl_Table::clear(); // clear the table
184  }
185 };
186 
187 #endif /*_FL_TABLE_ROW_H*/
A table of widgets or other content.
Definition: Fl_Table.H:108
~Fl_Table_Row()
The destructor for the Fl_Table_Row.
Definition: Fl_Table_Row.H:140
int rows()
Returns the number of rows in the table.
Definition: Fl_Table.H:467
virtual void clear()
Clears the table to zero rows (rows(0)), zero columns (cols(0)), and clears any widgets (table->clear...
Definition: Fl_Table.H:437
int find_cell(TableContext context, int R, int C, int &X, int &Y, int &W, int &H)
Find a cell&#39;s X/Y/W/H region for the specified cell in row &#39;R&#39;, column &#39;C&#39;.
Definition: Fl_Table.cxx:413
TableContext
The context bit flags for Fl_Table related callbacks.
Definition: Fl_Table.H:116
void clear()
Clears the table to zero rows (rows(0)), zero columns (cols(0)), and clears any widgets (table->clear...
Definition: Fl_Table_Row.H:180
A table with row selection capabilities.
Definition: Fl_Table_Row.H:44
Fl_Table_Row(int X, int Y, int W, int H, const char *l=0)
The constructor for the Fl_Table_Row.
Definition: Fl_Table_Row.H:127