29 #ifndef __EDELIB_TABLEBASE_H__
30 #define __EDELIB_TABLEBASE_H__
32 #include "edelib-global.h"
34 #include <sys/types.h>
44 #include <FL/Fl_Group.H>
45 #include <FL/Fl_Scroll.H>
46 #include <FL/Fl_Box.H>
47 #include <FL/Fl_Scrollbar.H>
174 CONTEXT_STARTPAGE = 0x01,
175 CONTEXT_ENDPAGE = 0x02,
176 CONTEXT_ROW_HEADER = 0x04,
177 CONTEXT_COL_HEADER = 0x08,
179 CONTEXT_TABLE = 0x20,
180 CONTEXT_RC_RESIZE = 0x40
199 int _redraw_toprow, _redraw_botrow,
200 _redraw_leftcol, _redraw_rightcol;
202 Fl_Color _row_header_color,
217 void init() { arr = NULL; _size = 0; }
218 void copy(
int *newarr,
unsigned int newsize) { size(newsize); memcpy(arr, newarr, newsize *
sizeof(
int)); }
221 IntVector() { init(); }
223 ~IntVector() {
if ( arr ) free(arr); arr = NULL; }
225 IntVector(IntVector&o) { init(); copy(o.arr, o._size); }
227 IntVector& operator=(IntVector&o) { init(); copy(o.arr, o._size);
return(*
this); }
229 int operator[](
int x)
const {
return(arr[x]); }
231 int& operator[](
int x) {
return(arr[x]); }
233 unsigned int size() {
return(_size); }
235 void size(
unsigned int count) {
236 if ( count != _size )
237 { arr = (
int*)realloc(arr, count *
sizeof(
int)); _size = count; }
240 int pop_back() {
int tmp = arr[_size-1]; _size--;
return(tmp); }
242 void push_back(
int val) {
unsigned int x = _size; size(_size+1); arr[x] = val; }
244 int back() {
return(arr[_size-1]); }
251 Fl_Cursor _last_cursor;
254 TableContext _callback_context;
255 int _callback_row, _callback_col;
268 void _redraw_cell(TableContext context,
int R,
int C);
270 void _start_auto_drag();
271 void _stop_auto_drag();
272 void _auto_drag_cb();
273 static void _auto_drag_cb2(
void *d);
281 RESIZE_COL_RIGHT = 2,
282 RESIZE_ROW_ABOVE = 3,
286 int table_w, table_h;
291 int current_row, current_col;
292 int select_row, select_col;
295 int toprow_scrollpos,
299 int tix, tiy, tiw, tih,
304 Fl_Scrollbar *vscrollbar,
311 void recalc_dimensions();
312 void table_resized();
313 void table_scrolled();
314 void get_bounds(TableContext context,
315 int &X,
int &Y,
int &W,
int &H);
316 void change_cursor(Fl_Cursor newcursor);
317 TableContext cursor2rowcol(
int &R,
int &C, ResizeFlag &resizeflag);
319 int find_cell(TableContext context,
320 int R,
int C,
int &X,
int &Y,
int &W,
int &H);
321 int row_col_clamp(TableContext context,
int &R,
int &C);
325 virtual void draw_cell(TableContext context,
int R=0,
int C=0,
326 int X=0,
int Y=0,
int W=0,
int H=0)
329 long row_scroll_position(
int row);
330 long col_scroll_position(
int col);
332 int is_fltk_container()
333 {
return( Fl_Group::children() > 3 ); }
335 static void scroll_cb(Fl_Widget*,
void*);
337 void damage_zone(
int r1,
int c1,
int r2,
int c2,
int r3 = 0,
int c3 = 0);
339 void redraw_range(
int trow,
int brow,
int lcol,
int rcol) {
340 if ( _redraw_toprow == -1 ) {
342 _redraw_toprow = trow;
343 _redraw_botrow = brow;
344 _redraw_leftcol = lcol;
345 _redraw_rightcol = rcol;
348 if ( trow < _redraw_toprow ) _redraw_toprow = trow;
349 if ( brow > _redraw_botrow ) _redraw_botrow = brow;
350 if ( lcol < _redraw_leftcol ) _redraw_leftcol = lcol;
351 if ( rcol > _redraw_rightcol ) _redraw_rightcol = rcol;
355 damage(FL_DAMAGE_CHILD);
359 void redraw_cell(TableContext context,
int R,
int C) { _redraw_cell(context, R, C); }
367 TableBase(
int X,
int Y,
int W,
int H,
const char *l=0);
377 virtual void clear() { rows(0); cols(0); }
383 inline void table_box(Fl_Boxtype val) { table->box(val); table_resized(); }
388 inline Fl_Boxtype
table_box(
void ) {
return(table->box()); }
393 virtual void rows(
int val);
398 inline int rows() {
return _rows; }
403 virtual void cols(
int val);
408 inline int cols() {
return _cols; }
417 inline void visible_cells(
int& r1,
int& r2,
int& c1,
int& c2) { r1 = toprow; r2 = botrow; c1 = leftcol; c2 = rightcol; }
470 void row_header(
int flag) { _row_header = flag; table_resized(); redraw(); }
481 void col_header(
int flag) { _col_header = flag; table_resized(); redraw(); }
491 inline void col_header_height(
int height) { _col_header_h = height; table_resized(); redraw(); }
501 inline void row_header_width(
int width) { _row_header_w = width; table_resized(); redraw(); }
532 void row_height(
int row,
int height);
537 inline int row_height(
int row) {
return ((row<0 || row>=(
int)_rowheights.size()) ? 0 : _rowheights[row]); }
543 void col_width(
int col,
int width);
548 inline int col_width(
int col) {
return ((col<0 || col>=(
int)_colwidths.size()) ? 0 : _colwidths[col]); }
553 void row_height_all(
int height) {
for (
int r=0; r<rows(); r++ ) row_height(r, height); }
558 void col_width_all(
int width) {
for (
int c=0; c<cols(); c++ ) col_width(c, width); }
563 void row_position(
int row);
573 void col_position(
int col);
583 inline void top_row(
int row) { row_position(row); }
588 inline int top_row() {
return row_position(); }
593 int is_selected(
int r,
int c);
601 void get_selection(
int& s_top,
int& s_left,
int& s_bottom,
int& s_right);
609 void set_selection(
int s_top,
int s_left,
int s_bottom,
int s_right);
616 int move_cursor(
int R,
int C);
621 void resize(
int X,
int Y,
int W,
int H);
636 void add(Fl_Widget& widget) { table->add(widget); }
641 void add(Fl_Widget* widget) { table->add(widget); }
646 void insert(Fl_Widget& widget,
int n) { table->insert(widget,n); }
651 void insert(Fl_Widget& widget1, Fl_Widget* widget2) { table->insert(widget1,widget2); }
656 void remove(Fl_Widget& widget) { table->remove(widget); }
672 if ( table->children() > 2 )
677 Fl_Group::current((Fl_Group*)(Fl_Group::parent()));
681 Fl_Widget *
const *array() {
return table->array(); }
682 Fl_Widget *child(
int n)
const {
return table->child(n); }
683 int children()
const {
return table->children()-2; }
684 int find(
const Fl_Widget *widget)
const {
return table->find(widget); }
685 int find(
const Fl_Widget &widget)
const {
return table->find(widget); }
709 _callback_context = context;
712 Fl_Widget::do_callback();
Fl_Color col_header_color()
Definition: TableBase.h:526
int row_header()
Definition: TableBase.h:475
A base class for table widgets.
Definition: TableBase.h:166
void begin()
Definition: TableBase.h:661
void col_header_color(Fl_Color val)
Definition: TableBase.h:521
int is_interactive_resize()
Definition: TableBase.h:422
void add(Fl_Widget &widget)
Definition: TableBase.h:636
int col_header()
Definition: TableBase.h:486
int row_position()
Definition: TableBase.h:568
void do_callback(TableContext context, int row, int col)
Definition: TableBase.h:708
int row_resize_min()
Definition: TableBase.h:464
int col_resize_min()
Definition: TableBase.h:454
void row_resize(int flag)
Definition: TableBase.h:428
int row_resize()
Definition: TableBase.h:433
void insert(Fl_Widget &widget, int n)
Definition: TableBase.h:646
void row_resize_min(int val)
Definition: TableBase.h:459
int col_resize()
Definition: TableBase.h:444
void col_resize_min(int val)
Definition: TableBase.h:449
void table_box(Fl_Boxtype val)
Definition: TableBase.h:383
int callback_row()
Definition: TableBase.h:692
void row_header_color(Fl_Color val)
Definition: TableBase.h:511
int cols()
Definition: TableBase.h:408
int col_header_height()
Definition: TableBase.h:496
int callback_col()
Definition: TableBase.h:698
void top_row(int row)
Definition: TableBase.h:583
TableContext
What happened in table callback.
Definition: TableBase.h:172
void add(Fl_Widget *widget)
Definition: TableBase.h:641
void row_height_all(int height)
Definition: TableBase.h:553
int col_width(int col)
Definition: TableBase.h:548
void row_header_width(int width)
Definition: TableBase.h:501
int top_row()
Definition: TableBase.h:588
void insert(Fl_Widget &widget1, Fl_Widget *widget2)
Definition: TableBase.h:651
void init_sizes()
Definition: TableBase.h:631
int col_position()
Definition: TableBase.h:578
void end()
Definition: TableBase.h:666
TableContext callback_context()
Definition: TableBase.h:703
virtual void clear()
Definition: TableBase.h:377
int rows()
Definition: TableBase.h:398
int row_header_width()
Definition: TableBase.h:506
void col_header(int flag)
Definition: TableBase.h:481
Fl_Boxtype table_box(void)
Definition: TableBase.h:388
void col_resize(int flag)
Definition: TableBase.h:439
Fl_Color row_header_color()
Definition: TableBase.h:516
void col_width_all(int width)
Definition: TableBase.h:558
void col_header_height(int height)
Definition: TableBase.h:491
void visible_cells(int &r1, int &r2, int &c1, int &c2)
Definition: TableBase.h:417
int row_height(int row)
Definition: TableBase.h:537
void row_header(int flag)
Definition: TableBase.h:470