FLTK 1.4.4: Fl_Table_Row.H Source File

FLTK 1.4.4

Loading...
Searching...
No Matches
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 {
45public:
46 enum TableRowSelectMode {
47 SELECT_NONE, // no selection allowed
48 SELECT_SINGLE, // single row selection
49 SELECT_MULTI // multiple row selection (default)
50 };
51private:
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
114protected:
115 int handle(int event) FL_OVERRIDE;
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
121public:
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
140 ~Fl_Table_Row() { }
141
142 void rows(int val) FL_OVERRIDE; // 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
160 // Checks to see if 'row' is selected. Returns 1 if selected, 0 if not.
161 int row_selected(int row);
162
163 // Changes the selection state for 'row', depending on the value of 'flag'.
164 int select_row(int row, int flag = 1);
165
170 void select_all_rows(int flag=1); // all rows to a known state
171
172 void clear() FL_OVERRIDE {
173 rows(0); // implies clearing selection
174 cols(0);
175 Fl_Table::clear(); // clear the table
176 }
177};
178
179#endif /*_FL_TABLE_ROW_H*/
Fl_Table_Row::rows
void rows(int val) FL_OVERRIDE
Sets the number of rows in the table, and the table is redrawn.
Definition Fl_Table_Row.cxx:205
Fl_Table_Row::~Fl_Table_Row
~Fl_Table_Row()
The destructor for the Fl_Table_Row.
Definition Fl_Table_Row.H:140
Fl_Table_Row::clear
void clear() FL_OVERRIDE
Clears the table to zero rows (rows(0)), zero columns (cols(0)), and clears any widgets (table->clear...
Definition Fl_Table_Row.H:172
Fl_Table_Row::handle
int handle(int event) FL_OVERRIDE
Handle FLTK events.
Definition Fl_Table_Row.cxx:212
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:127
Fl_Table::clear
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:427
Fl_Table::TableContext
TableContext
The context bit flags for Fl_Table related callbacks.
Definition Fl_Table.H:129
Fl_Table::Fl_Table
Fl_Table(int X, int Y, int W, int H, const char *l=0)
The constructor for Fl_Table.
Definition Fl_Table.cxx:119
Fl_Table::rows
virtual void rows(int val)
Sets the number of rows in the table, and the table is redrawn.
Definition Fl_Table.cxx:686
Fl_Table::cols
virtual void cols(int val)
Set the number of columns in the table and redraw.
Definition Fl_Table.cxx:715
Fl_Table::find_cell
int find_cell(TableContext context, int R, int C, int &X, int &Y, int &W, int &H)
Find a cell's X/Y/W/H region for the specified cell in row 'R', column 'C'.
Definition Fl_Table.cxx:443
Fl_Widget::x
void x(int v)
Internal use only.
Definition Fl_Widget.H:150
Fl_Widget::size
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:418
FL_OVERRIDE
#define FL_OVERRIDE
This macro makes it safe to use the C++11 keyword override with older compilers.
Definition fl_attr.h:46