Avoid #include's of unrelated system headers in Fl_Table*.H.

Possible side effect: programs that relied upon inclusion of unrelated
system headers by FL/Fl_Table.H or FL/Fl_Table_Row.H may fail to compile.

Removed include files (some only on certain platforms, list may be incomplete):

#include <FL/Fl.H>             // moved to implementation (.cxx)
#include <FL/Fl_Box.H>         // moved to implementation (.cxx)
#include <FL/Fl_Scrollbar.H>   // moved to implementation (.cxx)

#include <sys/types.h>
#include <string.h>            // memcpy
#include <malloc.h>            // WINDOWS only: malloc/realloc
#include <stdlib.h>            // UNIX: malloc/realloc


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12390 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Albrecht Schlosser 2017-08-18 15:16:08 +00:00
parent 638fba6020
commit 2828cbde2c
4 changed files with 76 additions and 55 deletions

View File

@ -20,19 +20,8 @@
#ifndef _FL_TABLE_H #ifndef _FL_TABLE_H
#define _FL_TABLE_H #define _FL_TABLE_H
#include <sys/types.h>
#include <string.h> // memcpy
#ifdef WIN32
#include <malloc.h> // WINDOWS: malloc/realloc
#else /*WIN32*/
#include <stdlib.h> // UNIX: malloc/realloc
#endif /*WIN32*/
#include <FL/Fl.H>
#include <FL/Fl_Group.H> #include <FL/Fl_Group.H>
#include <FL/Fl_Scroll.H> #include <FL/Fl_Scroll.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Scrollbar.H>
/** /**
A table of widgets or other content. A table of widgets or other content.
@ -172,16 +161,13 @@ private:
int *arr; int *arr;
unsigned int _size; unsigned int _size;
void init() { void init() {
arr = NULL; arr = 0;
_size = 0; _size = 0;
} }
void copy(int *newarr, unsigned int newsize) { void copy(int *newarr, unsigned int newsize);
size(newsize);
memcpy(arr, newarr, newsize * sizeof(int));
}
public: public:
IntVector() { init(); } // CTOR IntVector() { init(); } // CTOR
~IntVector() { if ( arr ) free(arr); arr = NULL; } // DTOR ~IntVector(); // DTOR
IntVector(IntVector&o) { init(); copy(o.arr, o._size); } // COPY CTOR IntVector(IntVector&o) { init(); copy(o.arr, o._size); } // COPY CTOR
IntVector& operator=(IntVector&o) { // ASSIGN IntVector& operator=(IntVector&o) { // ASSIGN
init(); init();
@ -191,12 +177,7 @@ private:
int operator[](int x) const { return(arr[x]); } int operator[](int x) const { return(arr[x]); }
int& operator[](int x) { return(arr[x]); } int& operator[](int x) { return(arr[x]); }
unsigned int size() { return(_size); } unsigned int size() { return(_size); }
void size(unsigned int count) { void size(unsigned int count);
if ( count != _size ) {
arr = (int*)realloc(arr, count * sizeof(int));
_size = count;
}
}
int pop_back() { int tmp = arr[_size-1]; _size--; return(tmp); } int pop_back() { int tmp = arr[_size-1]; _size--; return(tmp); }
void push_back(int val) { unsigned int x = _size; size(_size+1); arr[x] = val; } void push_back(int val) { unsigned int x = _size; size(_size+1); arr[x] = val; }
int back() { return(arr[_size-1]); } int back() { return(arr[_size-1]); }

View File

@ -22,7 +22,7 @@
// Please report all bugs and problems to "erco at seriss dot com". // Please report all bugs and problems to "erco at seriss dot com".
// //
#include "Fl_Table.H" #include <FL/Fl_Table.H>
/** /**
A table with row selection capabilities. A table with row selection capabilities.
@ -54,21 +54,15 @@ private:
char *arr; char *arr;
int _size; int _size;
void init() { void init() {
arr = NULL; arr = 0;
_size = 0; _size = 0;
} }
void copy(char *newarr, int newsize) { void copy(char *newarr, int newsize);
size(newsize);
memcpy(arr, newarr, newsize * sizeof(char));
}
public: public:
CharVector() { // CTOR CharVector() { // CTOR
init(); init();
} }
~CharVector() { // DTOR ~CharVector(); // DTOR
if ( arr ) free(arr);
arr = NULL;
}
CharVector(CharVector&o) { // COPY CTOR CharVector(CharVector&o) { // COPY CTOR
init(); init();
copy(o.arr, o._size); copy(o.arr, o._size);
@ -87,12 +81,7 @@ private:
int size() { int size() {
return(_size); return(_size);
} }
void size(int count) { void size(int count);
if ( count != _size ) {
arr = (char*)realloc(arr, count * sizeof(char));
_size = count;
}
}
char pop_back() { char pop_back() {
char tmp = arr[_size-1]; char tmp = arr[_size-1];
_size--; _size--;
@ -107,6 +96,7 @@ private:
return(arr[_size-1]); return(arr[_size-1]);
} }
}; };
CharVector _rowselect; // selection flag for each row CharVector _rowselect; // selection flag for each row
// handle() state variables. // handle() state variables.

View File

@ -17,13 +17,42 @@
// http://www.fltk.org/str.php // http://www.fltk.org/str.php
// //
#include <stdio.h> // fprintf
#include <FL/fl_draw.H>
#include <FL/Fl_Table.H> #include <FL/Fl_Table.H>
#if defined(USE_UTF8) && ( defined(MICROSOFT) || defined(LINUX) ) #include <FL/Fl.H>
#include <FL/fl_utf8.H> // currently only Windows and Linux #include <FL/fl_draw.H>
#endif
#include <sys/types.h>
#include <string.h> // memcpy
#include <stdio.h> // fprintf
#ifdef WIN32
#include <malloc.h> // WINDOWS: malloc/realloc
#else /*WIN32*/
#include <stdlib.h> // UNIX: malloc/realloc
#endif /*WIN32*/
// An STL-ish vector without templates (private to Fl_Table)
void Fl_Table::IntVector::copy(int *newarr, unsigned int newsize) {
size(newsize);
memcpy(arr, newarr, newsize * sizeof(int));
}
Fl_Table::IntVector::~IntVector() { // DTOR
if (arr)
free(arr);
arr = 0;
}
void Fl_Table::IntVector::size(unsigned int count) {
if (count != _size) {
arr = (int*)realloc(arr, count * sizeof(int));
_size = count;
}
}
/** Sets the vertical scroll position so 'row' is at the top, /** Sets the vertical scroll position so 'row' is at the top,
and causes the screen to redraw. and causes the screen to redraw.

View File

@ -24,10 +24,40 @@
// o Row headings (only column headings supported currently) // o Row headings (only column headings supported currently)
// //
#include <stdio.h> // for debugging #include <FL/Fl_Table_Row.H>
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/fl_draw.H> #include <FL/fl_draw.H>
#include <FL/Fl_Table_Row.H>
// for debugging...
// #define DEBUG 1
#ifdef DEBUG
#include <FL/names.h>
#include <stdio.h> // fprintf()
#define PRINTEVENT \
fprintf(stderr,"TableRow %s: ** Event: %s --\n", (label()?label():"none"), fl_eventnames[event]);
#else
#define PRINTEVENT
#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 != _size) {
arr = (char*)realloc(arr, count * sizeof(char));
_size = count;
}
}
// Is row selected? // Is row selected?
int Fl_Table_Row::row_selected(int row) { int Fl_Table_Row::row_selected(int row) {
@ -155,15 +185,6 @@ void Fl_Table_Row::rows(int val) {
while ( val < (int)_rowselect.size() ) { _rowselect.pop_back(); } // shrink while ( val < (int)_rowselect.size() ) { _rowselect.pop_back(); } // shrink
} }
//#define DEBUG 1
#ifdef DEBUG
#include <FL/names.h>
#define PRINTEVENT \
fprintf(stderr,"TableRow %s: ** Event: %s --\n", (label()?label():"none"), fl_eventnames[event]);
#else
#define PRINTEVENT
#endif
// Handle events // Handle events
int Fl_Table_Row::handle(int event) { int Fl_Table_Row::handle(int event) {
PRINTEVENT; PRINTEVENT;