2009-11-18 15:22:51 +03:00
|
|
|
//
|
|
|
|
|
2009-11-14 16:05:37 +03:00
|
|
|
#ifndef _FL_TABLE_ROW_H
|
|
|
|
#define _FL_TABLE_ROW_H
|
|
|
|
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Fl_Table_Row -- A row oriented table widget for the Fast Light Tool Kit (FLTK).
|
2009-11-14 16:05:37 +03:00
|
|
|
//
|
|
|
|
// A class specializing in a table of rows.
|
|
|
|
// Handles row-specific selection behavior.
|
|
|
|
//
|
|
|
|
// Copyright 2002 by Greg Ercolano.
|
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
2009-11-14 16:05:37 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
|
|
|
//
|
|
|
|
// Please see the following page on how to report bugs and issues:
|
2009-11-14 16:05:37 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2009-11-14 16:05:37 +03:00
|
|
|
//
|
|
|
|
|
2017-08-18 18:16:08 +03:00
|
|
|
#include <FL/Fl_Table.H>
|
2009-11-14 16:05:37 +03:00
|
|
|
|
2009-11-14 17:51:10 +03:00
|
|
|
/**
|
|
|
|
A table with row selection capabilities.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2010-12-05 04:22:53 +03:00
|
|
|
This class implements a simple table with the ability to select
|
|
|
|
rows. This widget is similar to an Fl_Browser with columns. Most
|
|
|
|
methods of importance will be found in the Fl_Table widget, such
|
|
|
|
as Fl_Table::rows() and Fl_Table::cols().
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-11-14 17:51:10 +03:00
|
|
|
To be useful it must be subclassed and at minimum the draw_cell()
|
|
|
|
method must be overridden to provide the content of the cells. This widget
|
|
|
|
does \em not manage the cell's data content; it is up to the parent
|
|
|
|
class's draw_cell() method override to provide this.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
|
|
|
Events on the cells and/or headings generate callbacks when they are
|
2009-11-14 17:51:10 +03:00
|
|
|
clicked by the user. You control when events are generated based on
|
|
|
|
the values you supply for Fl_Table::when().
|
|
|
|
*/
|
2010-12-13 02:21:03 +03:00
|
|
|
class FL_EXPORT Fl_Table_Row : public Fl_Table {
|
2009-11-14 16:05:37 +03:00
|
|
|
public:
|
|
|
|
enum TableRowSelectMode {
|
2020-07-01 19:03:10 +03:00
|
|
|
SELECT_NONE, // no selection allowed
|
|
|
|
SELECT_SINGLE, // single row selection
|
|
|
|
SELECT_MULTI // multiple row selection (default)
|
|
|
|
};
|
2009-11-14 16:05:37 +03:00
|
|
|
private:
|
|
|
|
// An STL-ish vector without templates
|
2011-01-23 01:40:11 +03:00
|
|
|
class FL_EXPORT CharVector {
|
2009-11-14 16:05:37 +03:00
|
|
|
char *arr;
|
|
|
|
int _size;
|
|
|
|
void init() {
|
2017-08-18 18:16:08 +03:00
|
|
|
arr = 0;
|
2009-11-14 16:05:37 +03:00
|
|
|
_size = 0;
|
|
|
|
}
|
2017-08-18 18:16:08 +03:00
|
|
|
void copy(char *newarr, int newsize);
|
2009-11-14 16:05:37 +03:00
|
|
|
public:
|
2020-07-01 19:03:10 +03:00
|
|
|
CharVector() { // CTOR
|
2009-11-14 16:05:37 +03:00
|
|
|
init();
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
~CharVector(); // DTOR
|
|
|
|
CharVector(CharVector&o) { // COPY CTOR
|
2009-11-14 16:05:37 +03:00
|
|
|
init();
|
|
|
|
copy(o.arr, o._size);
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
CharVector& operator=(CharVector&o) { // ASSIGN
|
2009-11-14 16:05:37 +03:00
|
|
|
init();
|
|
|
|
copy(o.arr, o._size);
|
|
|
|
return(*this);
|
|
|
|
}
|
|
|
|
char operator[](int x) const {
|
|
|
|
return(arr[x]);
|
|
|
|
}
|
|
|
|
char& operator[](int x) {
|
|
|
|
return(arr[x]);
|
|
|
|
}
|
|
|
|
int size() {
|
|
|
|
return(_size);
|
|
|
|
}
|
2017-08-18 18:16:08 +03:00
|
|
|
void size(int count);
|
2009-11-14 16:05:37 +03:00
|
|
|
char pop_back() {
|
|
|
|
char tmp = arr[_size-1];
|
|
|
|
_size--;
|
|
|
|
return(tmp);
|
|
|
|
}
|
|
|
|
void push_back(char val) {
|
|
|
|
int x = _size;
|
|
|
|
size(_size+1);
|
|
|
|
arr[x] = val;
|
|
|
|
}
|
|
|
|
char back() {
|
|
|
|
return(arr[_size-1]);
|
|
|
|
}
|
|
|
|
};
|
2017-08-18 18:16:08 +03:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
CharVector _rowselect; // selection flag for each row
|
|
|
|
|
2009-11-14 16:05:37 +03:00
|
|
|
// handle() state variables.
|
|
|
|
// Put here instead of local statics in handle(), so more
|
|
|
|
// than one instance can exist without crosstalk between.
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
int _dragging_select; // dragging out a selection?
|
2009-11-14 16:05:37 +03:00
|
|
|
int _last_row;
|
2020-07-01 19:03:10 +03:00
|
|
|
int _last_y; // last event's Y position
|
|
|
|
int _last_push_x; // last PUSH event's X position
|
|
|
|
int _last_push_y; // last PUSH event's Y position
|
|
|
|
|
2009-11-14 16:05:37 +03:00
|
|
|
TableRowSelectMode _selectmode;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-11-14 16:05:37 +03:00
|
|
|
protected:
|
2022-12-30 21:14:36 +03:00
|
|
|
int handle(int event) FL_OVERRIDE;
|
2020-07-01 19:03:10 +03:00
|
|
|
int find_cell(TableContext context, // find cell's x/y/w/h given r/c
|
2009-11-14 18:49:12 +03:00
|
|
|
int R, int C, int &X, int &Y, int &W, int &H) {
|
2009-11-14 16:05:37 +03:00
|
|
|
return(Fl_Table::find_cell(context, R, C, X, Y, W, H));
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-11-14 16:05:37 +03:00
|
|
|
public:
|
2009-11-14 17:51:10 +03:00
|
|
|
/**
|
|
|
|
The constructor for the Fl_Table_Row.
|
|
|
|
This creates an empty table with no rows or columns,
|
|
|
|
with headers and row/column resize behavior disabled.
|
2020-07-01 19:03:10 +03:00
|
|
|
*/
|
2009-11-14 16:05:37 +03:00
|
|
|
Fl_Table_Row(int X, int Y, int W, int H, const char *l=0) : Fl_Table(X,Y,W,H,l) {
|
|
|
|
_dragging_select = 0;
|
|
|
|
_last_row = -1;
|
|
|
|
_last_y = -1;
|
|
|
|
_last_push_x = -1;
|
|
|
|
_last_push_y = -1;
|
|
|
|
_selectmode = SELECT_MULTI;
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-11-14 17:51:10 +03:00
|
|
|
/**
|
|
|
|
The destructor for the Fl_Table_Row.
|
|
|
|
Destroys the table and its associated widgets.
|
|
|
|
*/
|
2009-11-14 16:05:37 +03:00
|
|
|
~Fl_Table_Row() { }
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2022-12-30 21:14:36 +03:00
|
|
|
void rows(int val) FL_OVERRIDE; // set number of rows
|
2020-07-01 19:03:10 +03:00
|
|
|
int rows() { // get number of rows
|
2009-11-14 16:05:37 +03:00
|
|
|
return(Fl_Table::rows());
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-11-14 17:51:10 +03:00
|
|
|
/**
|
|
|
|
Sets the table selection mode.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-11-14 17:51:10 +03:00
|
|
|
- \p Fl_Table_Row::SELECT_NONE - No selection allowed
|
|
|
|
- \p Fl_Table_Row::SELECT_SINGLE - Only single rows can be selected
|
|
|
|
- \p Fl_Table_Row::SELECT_MULTI - Multiple rows can be selected
|
2009-11-14 18:49:12 +03:00
|
|
|
*/
|
2020-07-01 19:03:10 +03:00
|
|
|
void type(TableRowSelectMode val); // set selection mode
|
|
|
|
|
|
|
|
TableRowSelectMode type() const { // get selection mode
|
2009-11-14 16:05:37 +03:00
|
|
|
return(_selectmode);
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-11-14 17:51:10 +03:00
|
|
|
/**
|
|
|
|
Checks to see if 'row' is selected. Returns 1 if selected, 0 if not. You can
|
|
|
|
change the selection of a row by clicking on it, or by using
|
|
|
|
select_row(row, flag)
|
|
|
|
*/
|
2020-07-01 19:03:10 +03:00
|
|
|
int row_selected(int row); // is row selected? (0=no, 1=yes, -1=range err)
|
|
|
|
|
2009-11-14 17:51:10 +03:00
|
|
|
/**
|
|
|
|
Changes the selection state for 'row', depending on the value
|
|
|
|
of 'flag'. 0=deselected, 1=select, 2=toggle existing state.
|
|
|
|
*/
|
2020-07-01 19:03:10 +03:00
|
|
|
int select_row(int row, int flag=1); // select state for row: flag:0=off, 1=on, 2=toggle
|
2009-11-14 18:49:12 +03:00
|
|
|
// returns: 0=no change, 1=changed, -1=range err
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-11-14 17:51:10 +03:00
|
|
|
/**
|
2020-07-01 19:03:10 +03:00
|
|
|
This convenience function changes the selection state
|
2009-11-14 17:51:10 +03:00
|
|
|
for \em all rows based on 'flag'. 0=deselect, 1=select, 2=toggle existing state.
|
|
|
|
*/
|
2020-07-01 19:03:10 +03:00
|
|
|
void select_all_rows(int flag=1); // all rows to a known state
|
|
|
|
|
2022-12-30 21:14:36 +03:00
|
|
|
void clear() FL_OVERRIDE {
|
2020-07-01 19:03:10 +03:00
|
|
|
rows(0); // implies clearing selection
|
2009-11-14 16:05:37 +03:00
|
|
|
cols(0);
|
2020-07-01 19:03:10 +03:00
|
|
|
Fl_Table::clear(); // clear the table
|
2009-11-14 16:05:37 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /*_FL_TABLE_ROW_H*/
|