2 // "$Id: Fl_Table_Row.H 8301 2011-01-22 22:40:11Z AlbrechtS $"
5 #ifndef _FL_TABLE_ROW_H
6 #define _FL_TABLE_ROW_H
9 // Fl_Table_Row -- A row oriented table widget
11 // A class specializing in a table of rows.
12 // Handles row-specific selection behavior.
14 // Copyright 2002 by Greg Ercolano.
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.
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.
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
31 // Please report all bugs and problems to "erco at seriss dot com".
38 A table with row selection capabilities.
40 This class implements a simple table with the ability to select
41 rows. This widget is similar to an Fl_Browser with columns. Most
42 methods of importance will be found in the Fl_Table widget, such
43 as Fl_Table::rows() and Fl_Table::cols().
45 To be useful it must be subclassed and at minimum the draw_cell()
46 method must be overridden to provide the content of the cells. This widget
47 does \em not manage the cell's data content; it is up to the parent
48 class's draw_cell() method override to provide this.
50 Events on the cells and/or headings generate callbacks when they are
51 clicked by the user. You control when events are generated based on
52 the values you supply for Fl_Table::when().
54 class FL_EXPORT Fl_Table_Row : public Fl_Table {
56 enum TableRowSelectMode {
57 SELECT_NONE, // no selection allowed
58 SELECT_SINGLE, // single row selection
59 SELECT_MULTI // multiple row selection (default)
62 // An STL-ish vector without templates
63 class FL_EXPORT CharVector {
70 void copy(char *newarr, int newsize) {
72 memcpy(arr, newarr, newsize * sizeof(char));
75 CharVector() { // CTOR
78 ~CharVector() { // DTOR
82 CharVector(CharVector&o) { // COPY CTOR
86 CharVector& operator=(CharVector&o) { // ASSIGN
91 char operator[](int x) const {
94 char& operator[](int x) {
100 void size(int count) {
101 if ( count != _size ) {
102 arr = (char*)realloc(arr, count * sizeof(char));
107 char tmp = arr[_size-1];
111 void push_back(char val) {
117 return(arr[_size-1]);
120 CharVector _rowselect; // selection flag for each row
122 // handle() state variables.
123 // Put here instead of local statics in handle(), so more
124 // than one instance can exist without crosstalk between.
126 int _dragging_select; // dragging out a selection?
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
132 TableRowSelectMode _selectmode;
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));
143 The constructor for the Fl_Table_Row.
144 This creates an empty table with no rows or columns,
145 with headers and row/column resize behavior disabled.
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;
153 _selectmode = SELECT_MULTI;
157 The destructor for the Fl_Table_Row.
158 Destroys the table and its associated widgets.
162 void rows(int val); // set number of rows
163 int rows() { // get number of rows
164 return(Fl_Table::rows());
168 Sets the table selection mode.
170 - \p Fl_Table_Row::SELECT_NONE - No selection allowed
171 - \p Fl_Table_Row::SELECT_SINGLE - Only single rows can be selected
172 - \p Fl_Table_Row::SELECT_MULTI - Multiple rows can be selected
174 void type(TableRowSelectMode val); // set selection mode
176 TableRowSelectMode type() const { // get selection mode
181 Checks to see if 'row' is selected. Returns 1 if selected, 0 if not. You can
182 change the selection of a row by clicking on it, or by using
183 select_row(row, flag)
185 int row_selected(int row); // is row selected? (0=no, 1=yes, -1=range err)
188 Changes the selection state for 'row', depending on the value
189 of 'flag'. 0=deselected, 1=select, 2=toggle existing state.
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
195 This convenience function changes the selection state
196 for \em all rows based on 'flag'. 0=deselect, 1=select, 2=toggle existing state.
198 void select_all_rows(int flag=1); // all rows to a known state
201 rows(0); // implies clearing selection
203 Fl_Table::clear(); // clear the table
207 #endif /*_FL_TABLE_ROW_H*/
210 // End of "$Id: Fl_Table_Row.H 8301 2011-01-22 22:40:11Z AlbrechtS $".