Fl_Table_Row: replace private class CharVector with std::vector
FL/Fl_Table_Row.H: use `std::vector<uint8_t> _rowselect;`, remove declaration of class `CharVector` src/Fl_Table_Row.cxx: remove implementation of class `CharVector`, simplify loops (use range based for loops), use resize() to change vector size. Unify copyright year of Fl_Table* headers and implementation.
This commit is contained in:
parent
51cca24d04
commit
bdde3e5d2b
@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2002 by Greg Ercolano.
|
// Copyright 2002 by Greg Ercolano.
|
||||||
// Copyright (c) 2004 O'ksi'D
|
// Copyright (c) 2004 O'ksi'D
|
||||||
// Copyright 2023 by Bill Spitzak and others.
|
// Copyright 2009-2025 by Bill Spitzak and others.
|
||||||
//
|
//
|
||||||
// This library is free software. Distribution and use rights are outlined in
|
// 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
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
|
|||||||
@ -1,8 +1,3 @@
|
|||||||
//
|
|
||||||
|
|
||||||
#ifndef _FL_TABLE_ROW_H
|
|
||||||
#define _FL_TABLE_ROW_H
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fl_Table_Row -- A row oriented table widget for the Fast Light Tool Kit (FLTK).
|
// Fl_Table_Row -- A row oriented table widget for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@ -10,6 +5,7 @@
|
|||||||
// Handles row-specific selection behavior.
|
// Handles row-specific selection behavior.
|
||||||
//
|
//
|
||||||
// Copyright 2002 by Greg Ercolano.
|
// Copyright 2002 by Greg Ercolano.
|
||||||
|
// Copyright 2009-2025 by Bill Spitzak and others.
|
||||||
//
|
//
|
||||||
// This library is free software. Distribution and use rights are outlined in
|
// 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
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
@ -22,8 +18,14 @@
|
|||||||
// https://www.fltk.org/bugs.php
|
// https://www.fltk.org/bugs.php
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#ifndef _FL_TABLE_ROW_H
|
||||||
|
#define _FL_TABLE_ROW_H
|
||||||
|
|
||||||
#include <FL/Fl_Table.H>
|
#include <FL/Fl_Table.H>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A table with row selection capabilities.
|
A table with row selection capabilities.
|
||||||
|
|
||||||
@ -49,55 +51,8 @@ public:
|
|||||||
SELECT_MULTI // multiple row selection (default)
|
SELECT_MULTI // multiple row selection (default)
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
// An STL-ish vector without templates
|
|
||||||
class FL_EXPORT CharVector {
|
|
||||||
char *arr;
|
|
||||||
int _size;
|
|
||||||
void init() {
|
|
||||||
arr = 0;
|
|
||||||
_size = 0;
|
|
||||||
}
|
|
||||||
void copy(char *newarr, int newsize);
|
|
||||||
public:
|
|
||||||
CharVector() { // CTOR
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
~CharVector(); // DTOR
|
|
||||||
CharVector(CharVector&o) { // COPY CTOR
|
|
||||||
init();
|
|
||||||
copy(o.arr, o._size);
|
|
||||||
}
|
|
||||||
CharVector& operator=(CharVector&o) { // ASSIGN
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
void size(int count);
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
CharVector _rowselect; // selection flag for each row
|
std::vector<uint8_t> _rowselect; // selection flag for each row
|
||||||
|
|
||||||
// handle() state variables.
|
// handle() state variables.
|
||||||
// Put here instead of local statics in handle(), so more
|
// Put here instead of local statics in handle(), so more
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
// Copyright 2002 by Greg Ercolano.
|
// Copyright 2002 by Greg Ercolano.
|
||||||
// Copyright (c) 2004 O'ksi'D
|
// Copyright (c) 2004 O'ksi'D
|
||||||
// Copyright 2023-2025 by Bill Spitzak and others.
|
// Copyright 2009-2025 by Bill Spitzak and others.
|
||||||
//
|
//
|
||||||
// This library is free software. Distribution and use rights are outlined in
|
// 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
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
// Handles row-specific selection behavior.
|
// Handles row-specific selection behavior.
|
||||||
//
|
//
|
||||||
// Copyright 2002 by Greg Ercolano.
|
// Copyright 2002 by Greg Ercolano.
|
||||||
|
// Copyright 2009-2025 by Bill Spitzak and others.
|
||||||
//
|
//
|
||||||
// This library is free software. Distribution and use rights are outlined in
|
// 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
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
@ -38,31 +39,6 @@
|
|||||||
#define PRINTEVENT
|
#define PRINTEVENT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// An STL-ish vector without templates (private to Fl_Table_Row)
|
|
||||||
|
|
||||||
void Fl_Table_Row::CharVector::copy(char *newarr, int newsize) {
|
|
||||||
size(newsize);
|
|
||||||
memcpy(arr, newarr, newsize * sizeof(char));
|
|
||||||
}
|
|
||||||
|
|
||||||
Fl_Table_Row::CharVector::~CharVector() { // DTOR
|
|
||||||
if (arr) free(arr);
|
|
||||||
arr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Fl_Table_Row::CharVector::size(int count) {
|
|
||||||
if (count <= 0 ) { // Same state as init() - (issue #296)
|
|
||||||
if ( arr ) free(arr);
|
|
||||||
arr = 0;
|
|
||||||
_size = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (count != _size) {
|
|
||||||
arr = (char*)realloc(arr, (unsigned)count * sizeof(char));
|
|
||||||
_size = count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Checks to see if 'row' is selected.
|
Checks to see if 'row' is selected.
|
||||||
@ -89,18 +65,18 @@ void Fl_Table_Row::type(TableRowSelectMode val) {
|
|||||||
_selectmode = val;
|
_selectmode = val;
|
||||||
switch ( _selectmode ) {
|
switch ( _selectmode ) {
|
||||||
case SELECT_NONE: {
|
case SELECT_NONE: {
|
||||||
for ( int row=0; row<rows(); row++ ) {
|
for (auto &sel : _rowselect) {
|
||||||
_rowselect[row] = 0;
|
sel = 0;
|
||||||
}
|
}
|
||||||
redraw();
|
redraw();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SELECT_SINGLE: {
|
case SELECT_SINGLE: {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for ( int row=0; row<rows(); row++ ) {
|
for (auto &sel : _rowselect) {
|
||||||
if ( _rowselect[row] ) {
|
if (sel) {
|
||||||
if ( ++count > 1 ) { // only one allowed
|
if (++count > 1) { // only one allowed
|
||||||
_rowselect[row] = 0;
|
sel = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,14 +160,14 @@ void Fl_Table_Row::select_all_rows(int flag) {
|
|||||||
case SELECT_MULTI: {
|
case SELECT_MULTI: {
|
||||||
char changed = 0;
|
char changed = 0;
|
||||||
if ( flag == 2 ) {
|
if ( flag == 2 ) {
|
||||||
for ( int row=0; row<(int)_rowselect.size(); row++ ) {
|
for (auto &sel : _rowselect) {
|
||||||
_rowselect[row] ^= 1;
|
sel ^= 1;
|
||||||
}
|
}
|
||||||
changed = 1;
|
changed = 1;
|
||||||
} else {
|
} else {
|
||||||
for ( int row=0; row<(int)_rowselect.size(); row++ ) {
|
for (auto &sel : _rowselect) {
|
||||||
changed |= (_rowselect[row] != flag)?1:0;
|
changed |= (sel != flag) ? 1 : 0;
|
||||||
_rowselect[row] = flag;
|
sel = flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( changed ) {
|
if ( changed ) {
|
||||||
@ -203,9 +179,10 @@ void Fl_Table_Row::select_all_rows(int flag) {
|
|||||||
|
|
||||||
// Set number of rows
|
// Set number of rows
|
||||||
void Fl_Table_Row::rows(int val) {
|
void Fl_Table_Row::rows(int val) {
|
||||||
while ( val > (int)_rowselect.size() ) { _rowselect.push_back(0); } // enlarge
|
// Note: order of operations below matters, see PR #1187
|
||||||
|
if (val > (int)_rowselect.size()) { _rowselect.resize(val, 0); } // enlarge
|
||||||
Fl_Table::rows(val);
|
Fl_Table::rows(val);
|
||||||
while ( val < (int)_rowselect.size() ) { _rowselect.pop_back(); } // shrink
|
if (val < (int)_rowselect.size()) { _rowselect.resize(val); } // shrink
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle events
|
// Handle events
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user