summaryrefslogtreecommitdiff
path: root/src/Fl_Table.cxx
diff options
context:
space:
mode:
authormaxim nikonov <maxim.nikonov@hqo.co>2026-02-05 16:35:56 +0500
committermaxim nikonov <maxim.nikonov@hqo.co>2026-02-05 16:35:56 +0500
commit7d3793ce1d8cb26e7608bf859beca21359cec6e9 (patch)
tree70f168b5daafa2b013dc518a393378022172940a /src/Fl_Table.cxx
parentcdf2832347b8fdf0389cd373c2ead0ac5d071037 (diff)
wip
Diffstat (limited to 'src/Fl_Table.cxx')
-rw-r--r--src/Fl_Table.cxx96
1 files changed, 70 insertions, 26 deletions
diff --git a/src/Fl_Table.cxx b/src/Fl_Table.cxx
index c3fddc5fa..79d152acb 100644
--- a/src/Fl_Table.cxx
+++ b/src/Fl_Table.cxx
@@ -145,8 +145,12 @@ Fl_Table::Fl_Table(int X, int Y, int W, int H, const char *l) : Fl_Group(X,Y,W,H
_scrollbar_size = 0;
flags_ = 0; // TABCELLNAV off
- _colwidths = new std::vector<int>; // column widths in pixels
- _rowheights = new std::vector<int>; // row heights in pixels
+ _colwidths = 0;
+ _colwidths_size = 0;
+ _colwidths_alloc = 0;
+ _rowheights = 0;
+ _rowheights_size = 0;
+ _rowheights_alloc = 0;
box(FL_THIN_DOWN_FRAME);
@@ -181,8 +185,8 @@ Fl_Table::Fl_Table(int X, int Y, int W, int H, const char *l) : Fl_Group(X,Y,W,H
*/
Fl_Table::~Fl_Table() {
// The parent Fl_Group takes care of destroying scrollbars
- delete _colwidths;
- delete _rowheights;
+ if (_colwidths) free(_colwidths);
+ if (_rowheights) free(_rowheights);
}
@@ -194,7 +198,7 @@ Fl_Table::~Fl_Table() {
\returns Number of columns.
*/
int Fl_Table::col_size() {
- return int(_colwidths->size());
+ return _colwidths_size;
}
/**
@@ -205,7 +209,7 @@ int Fl_Table::col_size() {
\returns Number of rows.
*/
int Fl_Table::row_size() {
- return int(_rowheights->size());
+ return _rowheights_size;
}
/**
@@ -216,15 +220,26 @@ int Fl_Table::row_size() {
*/
void Fl_Table::row_height(int row, int height) {
if ( row < 0 ) return;
- if ( row < row_size() && (*_rowheights)[row] == height ) {
+ if ( row < row_size() && _rowheights[row] == height ) {
return; // OPTIMIZATION: no change? avoid redraw
}
// Add row heights, even if none yet
- int now_size = row_size();
- if (row >= now_size) {
- _rowheights->resize(row, height);
+ if (row >= _rowheights_size) {
+ // Need to grow array
+ int newsize = row + 1;
+ if (newsize > _rowheights_alloc) {
+ int newalloc = _rowheights_alloc ? _rowheights_alloc * 2 : 8;
+ if (newalloc < newsize) newalloc = newsize;
+ _rowheights = (int*)realloc(_rowheights, newalloc * sizeof(int));
+ _rowheights_alloc = newalloc;
+ }
+ // Fill new entries with height
+ int i;
+ for (i = _rowheights_size; i < newsize; i++)
+ _rowheights[i] = height;
+ _rowheights_size = newsize;
}
- (*_rowheights)[row] = height;
+ _rowheights[row] = height;
table_resized();
if ( row <= botrow ) { // OPTIMIZATION: only redraw if onscreen or above screen
redraw();
@@ -243,15 +258,26 @@ void Fl_Table::row_height(int row, int height) {
void Fl_Table::col_width(int col, int width)
{
if ( col < 0 ) return;
- if ( col < col_size() && (*_colwidths)[col] == width ) {
+ if ( col < col_size() && _colwidths[col] == width ) {
return; // OPTIMIZATION: no change? avoid redraw
}
// Add column widths, even if none yet
- int now_size = col_size();
- if ( col >= now_size ) {
- _colwidths->resize(col+1, width);
+ if ( col >= _colwidths_size ) {
+ // Need to grow array
+ int newsize = col + 1;
+ if (newsize > _colwidths_alloc) {
+ int newalloc = _colwidths_alloc ? _colwidths_alloc * 2 : 8;
+ if (newalloc < newsize) newalloc = newsize;
+ _colwidths = (int*)realloc(_colwidths, newalloc * sizeof(int));
+ _colwidths_alloc = newalloc;
+ }
+ // Fill new entries with width
+ int i;
+ for (i = _colwidths_size; i < newsize; i++)
+ _colwidths[i] = width;
+ _colwidths_size = newsize;
}
- (*_colwidths)[col] = width;
+ _colwidths[col] = width;
table_resized();
if ( col <= rightcol ) { // OPTIMIZATION: only redraw if onscreen or to the left
redraw();
@@ -660,11 +686,20 @@ void Fl_Table::rows(int val) {
int oldrows = _rows;
_rows = val;
- int default_h = row_size() > 0 ? _rowheights->back() : 25;
- int now_size = row_size();
+ int default_h = row_size() > 0 ? _rowheights[row_size()-1] : 25;
- if (now_size != val)
- _rowheights->resize(val, default_h); // enlarge or shrink as needed
+ if (_rowheights_size != val) {
+ // resize array
+ if (val > _rowheights_alloc) {
+ _rowheights = (int*)realloc(_rowheights, val * sizeof(int));
+ _rowheights_alloc = val;
+ }
+ // Fill new entries
+ int i;
+ for (i = _rowheights_size; i < val; i++)
+ _rowheights[i] = default_h;
+ _rowheights_size = val;
+ }
table_resized();
@@ -682,11 +717,20 @@ void Fl_Table::rows(int val) {
void Fl_Table::cols(int val) {
_cols = val;
- int default_w = col_size() > 0 ? (*_colwidths)[col_size()-1] : 80;
- int now_size = col_size();
+ int default_w = col_size() > 0 ? _colwidths[col_size()-1] : 80;
- if (now_size != val)
- _colwidths->resize(val, default_w); // enlarge or shrink as needed
+ if (_colwidths_size != val) {
+ // resize array
+ if (val > _colwidths_alloc) {
+ _colwidths = (int*)realloc(_colwidths, val * sizeof(int));
+ _colwidths_alloc = val;
+ }
+ // Fill new entries
+ int i;
+ for (i = _colwidths_size; i < val; i++)
+ _colwidths[i] = default_w;
+ _colwidths_size = val;
+ }
table_resized();
redraw();
@@ -1398,12 +1442,12 @@ void Fl_Table::draw() {
Returns the current height of the specified row as a value in pixels.
*/
int Fl_Table::row_height(int row) {
- return((row < 0 || row >= row_size()) ? 0 : (*_rowheights)[row]);
+ return((row < 0 || row >= row_size()) ? 0 : _rowheights[row]);
}
/**
Returns the current width of the specified column in pixels.
*/
int Fl_Table::col_width(int col) {
- return((col < 0 || col >= col_size()) ? 0 : (*_colwidths)[col]);
+ return((col < 0 || col >= col_size()) ? 0 : _colwidths[col]);
}