FLTK 1.3.0
Fl_Table_Row.H
1 //
2 // "$Id: Fl_Table_Row.H 8301 2011-01-22 22:40:11Z AlbrechtS $"
3 //
4 
5 #ifndef _FL_TABLE_ROW_H
6 #define _FL_TABLE_ROW_H
7 
8 //
9 // Fl_Table_Row -- A row oriented table widget
10 //
11 // A class specializing in a table of rows.
12 // Handles row-specific selection behavior.
13 //
14 // Copyright 2002 by Greg Ercolano.
15 //
16 // This library is free software; you can redistribute it and/or
17 // modify it under the terms of the GNU Library General Public
18 // License as published by the Free Software Foundation; either
19 // version 2 of the License, or (at your option) any later version.
20 //
21 // This library is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 // Library General Public License for more details.
25 //
26 // You should have received a copy of the GNU Library General Public
27 // License along with this library; if not, write to the Free Software
28 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 // USA.
30 //
31 // Please report all bugs and problems to "erco at seriss dot com".
32 //
33 //
34 
35 #include "Fl_Table.H"
36 
54 class FL_EXPORT Fl_Table_Row : public Fl_Table {
55 public:
56  enum TableRowSelectMode {
57  SELECT_NONE, // no selection allowed
58  SELECT_SINGLE, // single row selection
59  SELECT_MULTI // multiple row selection (default)
60  };
61 private:
62  // An STL-ish vector without templates
63  class FL_EXPORT CharVector {
64  char *arr;
65  int _size;
66  void init() {
67  arr = NULL;
68  _size = 0;
69  }
70  void copy(char *newarr, int newsize) {
71  size(newsize);
72  memcpy(arr, newarr, newsize * sizeof(char));
73  }
74  public:
75  CharVector() { // CTOR
76  init();
77  }
78  ~CharVector() { // DTOR
79  if ( arr ) free(arr);
80  arr = NULL;
81  }
82  CharVector(CharVector&o) { // COPY CTOR
83  init();
84  copy(o.arr, o._size);
85  }
86  CharVector& operator=(CharVector&o) { // ASSIGN
87  init();
88  copy(o.arr, o._size);
89  return(*this);
90  }
91  char operator[](int x) const {
92  return(arr[x]);
93  }
94  char& operator[](int x) {
95  return(arr[x]);
96  }
97  int size() {
98  return(_size);
99  }
100  void size(int count) {
101  if ( count != _size ) {
102  arr = (char*)realloc(arr, count * sizeof(char));
103  _size = count;
104  }
105  }
106  char pop_back() {
107  char tmp = arr[_size-1];
108  _size--;
109  return(tmp);
110  }
111  void push_back(char val) {
112  int x = _size;
113  size(_size+1);
114  arr[x] = val;
115  }
116  char back() {
117  return(arr[_size-1]);
118  }
119  };
120  CharVector _rowselect; // selection flag for each row
121 
122  // handle() state variables.
123  // Put here instead of local statics in handle(), so more
124  // than one instance can exist without crosstalk between.
125  //
126  int _dragging_select; // dragging out a selection?
127  int _last_row;
128  int _last_y; // last event's Y position
129  int _last_push_x; // last PUSH event's X position
130  int _last_push_y; // last PUSH event's Y position
131 
132  TableRowSelectMode _selectmode;
133 
134 protected:
135  int handle(int event);
136  int find_cell(TableContext context, // find cell's x/y/w/h given r/c
137  int R, int C, int &X, int &Y, int &W, int &H) {
138  return(Fl_Table::find_cell(context, R, C, X, Y, W, H));
139  }
140 
141 public:
147  Fl_Table_Row(int X, int Y, int W, int H, const char *l=0) : Fl_Table(X,Y,W,H,l) {
148  _dragging_select = 0;
149  _last_row = -1;
150  _last_y = -1;
151  _last_push_x = -1;
152  _last_push_y = -1;
153  _selectmode = SELECT_MULTI;
154  }
155 
161 
162  void rows(int val); // set number of rows
163  int rows() { // get number of rows
164  return(Fl_Table::rows());
165  }
166 
174  void type(TableRowSelectMode val); // set selection mode
175 
176  TableRowSelectMode type() const { // get selection mode
177  return(_selectmode);
178  }
179 
185  int row_selected(int row); // is row selected? (0=no, 1=yes, -1=range err)
186 
191  int select_row(int row, int flag=1); // select state for row: flag:0=off, 1=on, 2=toggle
192  // returns: 0=no change, 1=changed, -1=range err
193 
198  void select_all_rows(int flag=1); // all rows to a known state
199 
200  void clear() {
201  rows(0); // implies clearing selection
202  cols(0);
203  Fl_Table::clear(); // clear the table
204  }
205 };
206 
207 #endif /*_FL_TABLE_ROW_H*/
208 
209 //
210 // End of "$Id: Fl_Table_Row.H 8301 2011-01-22 22:40:11Z AlbrechtS $".
211 //
A table of widgets or other content.
Definition: Fl_Table.H:181
~Fl_Table_Row()
The destructor for the Fl_Table_Row.
Definition: Fl_Table_Row.H:160
int rows()
Returns the number of rows in the table.
Definition: Fl_Table.H:522
virtual void clear()
Clears the table to zero rows, zero columns.
Definition: Fl_Table.H:493
TableContext
The context bit flags for Fl_Table related callbacks (eg.
Definition: Fl_Table.H:186
void clear()
Clears the table to zero rows, zero columns.
Definition: Fl_Table_Row.H:200
A table with row selection capabilities.
Definition: Fl_Table_Row.H:54
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:147