FLTK 1.3.2

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

Fl_Table_Row.H
1 //
2 // "$Id: Fl_Table_Row.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
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. Distribution and use rights are outlined in
17 // the file "COPYING" which should have been included with this file. If this
18 // file is missing or damaged, see the license at:
19 //
20 // http://www.fltk.org/COPYING.php
21 //
22 // Please report all bugs and problems to "erco at seriss dot com".
23 //
24
25 #include "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 = NULL;
58 _size = 0;
59 }
60 void copy(char *newarr, int newsize) {
61 size(newsize);
62 memcpy(arr, newarr, newsize * sizeof(char));
63 }
64 public:
65 CharVector() { // CTOR
66 init();
67 }
68 ~CharVector() { // DTOR
69 if ( arr ) free(arr);
70 arr = NULL;
71 }
72 CharVector(CharVector&o) { // COPY CTOR
73 init();
74 copy(o.arr, o._size);
75 }
76 CharVector& operator=(CharVector&o) { // ASSIGN
77 init();
78 copy(o.arr, o._size);
79 return(*this);
80 }
81 char operator[](int x) const {
82 return(arr[x]);
83 }
84 char& operator[](int x) {
85 return(arr[x]);
86 }
87 int size() {
88 return(_size);
89 }
90 void size(int count) {
91 if ( count != _size ) {
92 arr = (char*)realloc(arr, count * sizeof(char));
93 _size = count;
94 }
95 }
96 char pop_back() {
97 char tmp = arr[_size-1];
98 _size--;
99 return(tmp);
100 }
101 void push_back(char val) {
102 int x = _size;
103 size(_size+1);
104 arr[x] = val;
105 }
106 char back() {
107 return(arr[_size-1]);
108 }
109 };
110 CharVector _rowselect; // selection flag for each row
111
112 // handle() state variables.
113 // Put here instead of local statics in handle(), so more
114 // than one instance can exist without crosstalk between.
115 //
116 int _dragging_select; // dragging out a selection?
117 int _last_row;
118 int _last_y; // last event's Y position
119 int _last_push_x; // last PUSH event's X position
120 int _last_push_y; // last PUSH event's Y position
121
122 TableRowSelectMode _selectmode;
123
124 protected:
125 int handle(int event);
126 int find_cell(TableContext context, // find cell's x/y/w/h given r/c
127 int R, int C, int &X, int &Y, int &W, int &H) {
128 return(Fl_Table::find_cell(context, R, C, X, Y, W, H));
129 }
130
131 public:
137 Fl_Table_Row(int X, int Y, int W, int H, const char *l=0) : Fl_Table(X,Y,W,H,l) {
138 _dragging_select = 0;
139 _last_row = -1;
140 _last_y = -1;
141 _last_push_x = -1;
142 _last_push_y = -1;
143 _selectmode = SELECT_MULTI;
144 }
145
150 ~Fl_Table_Row() { }
151
152 void rows(int val); // set number of rows
153 int rows() { // get number of rows
154 return(Fl_Table::rows());
155 }
156
164 void type(TableRowSelectMode val); // set selection mode
165
166 TableRowSelectMode type() const { // get selection mode
167 return(_selectmode);
168 }
169
175 int row_selected(int row); // is row selected? (0=no, 1=yes, -1=range err)
176
181 int select_row(int row, int flag=1); // select state for row: flag:0=off, 1=on, 2=toggle
182 // returns: 0=no change, 1=changed, -1=range err
183
188 void select_all_rows(int flag=1); // all rows to a known state
189
190 void clear() {
191 rows(0); // implies clearing selection
192 cols(0);
193 Fl_Table::clear(); // clear the table
194 }
195 };
196
197 #endif /*_FL_TABLE_ROW_H*/
198
199 //
200 // End of "$Id: Fl_Table_Row.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
201 //
Fl_Table
A table of widgets or other content.
Definition: Fl_Table.H:170
Fl_Table_Row::~Fl_Table_Row
~Fl_Table_Row()
The destructor for the Fl_Table_Row.
Definition: Fl_Table_Row.H:150
Fl_Table::rows
int rows()
Returns the number of rows in the table.
Definition: Fl_Table.H:514
Fl_Table::clear
virtual void clear()
Clears the table to zero rows (rows(0)), zero columns (cols(0)), and clears any widgets (table-&gt;clear...
Definition: Fl_Table.H:485
Fl_Table::TableContext
TableContext
The context bit flags for Fl_Table related callbacks (eg.
Definition: Fl_Table.H:175
Fl_Table_Row::clear
void clear()
Clears the table to zero rows (rows(0)), zero columns (cols(0)), and clears any widgets (table-&gt;clear...
Definition: Fl_Table_Row.H:190
Fl_Table_Row
A table with row selection capabilities.
Definition: Fl_Table_Row.H:44
Fl_Table_Row::Fl_Table_Row
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:137
- © 1998-2012 by Bill Spitzak and others.