"Fossies" - the Fresh Open Source Software Archive

Member "fltk-1.3.2/documentation/html/Fl__Table__Row_8H_source.html" (9 Dec 2012, 17297 Bytes) of package /linux/misc/fltk-1.3.2-docs-html.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. Alternatively you can here view or download the uninterpreted raw source code. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

FLTK 1.3.2
Fl_Table_Row.H
00001 //
00002 // "$Id: Fl_Table_Row.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
00003 //
00004 
00005 #ifndef _FL_TABLE_ROW_H
00006 #define _FL_TABLE_ROW_H
00007 
00008 //
00009 // Fl_Table_Row -- A row oriented table widget
00010 //
00011 //    A class specializing in a table of rows.
00012 //    Handles row-specific selection behavior.
00013 //
00014 // Copyright 2002 by Greg Ercolano.
00015 //
00016 // This library is free software. Distribution and use rights are outlined in
00017 // the file "COPYING" which should have been included with this file.  If this
00018 // file is missing or damaged, see the license at:
00019 //
00020 //     http://www.fltk.org/COPYING.php
00021 //
00022 // Please report all bugs and problems to "erco at seriss dot com".
00023 //
00024 
00025 #include "Fl_Table.H"
00026 
00044 class FL_EXPORT Fl_Table_Row : public Fl_Table {
00045 public:
00046   enum TableRowSelectMode {
00047     SELECT_NONE,                // no selection allowed
00048     SELECT_SINGLE,              // single row selection
00049     SELECT_MULTI                // multiple row selection (default)
00050   }; 
00051 private:
00052   // An STL-ish vector without templates
00053   class FL_EXPORT CharVector {
00054     char *arr;
00055     int _size;
00056     void init() {
00057       arr = NULL;
00058       _size = 0;
00059     }
00060     void copy(char *newarr, int newsize) {
00061       size(newsize);
00062       memcpy(arr, newarr, newsize * sizeof(char));
00063     }
00064   public:
00065     CharVector() {                              // CTOR
00066       init();
00067     }
00068     ~CharVector() {                             // DTOR
00069       if ( arr ) free(arr);
00070       arr = NULL;
00071     }
00072     CharVector(CharVector&o) {                  // COPY CTOR
00073       init();
00074       copy(o.arr, o._size);
00075     }
00076     CharVector& operator=(CharVector&o) {       // ASSIGN
00077       init();
00078       copy(o.arr, o._size);
00079       return(*this);
00080     }
00081     char operator[](int x) const {
00082       return(arr[x]);
00083     }
00084     char& operator[](int x) {
00085       return(arr[x]);
00086     }
00087     int size() {
00088       return(_size);
00089     }
00090     void size(int count) {
00091       if ( count != _size ) {
00092         arr = (char*)realloc(arr, count * sizeof(char));
00093         _size = count;
00094       }
00095     }
00096     char pop_back() {
00097       char tmp = arr[_size-1];
00098       _size--;
00099       return(tmp);
00100     }
00101     void push_back(char val) {
00102       int x = _size;
00103       size(_size+1);
00104       arr[x] = val;
00105     }
00106     char back() {
00107       return(arr[_size-1]);
00108     }
00109   };
00110   CharVector _rowselect;                // selection flag for each row
00111   
00112   // handle() state variables.
00113   //    Put here instead of local statics in handle(), so more
00114   //    than one instance can exist without crosstalk between.
00115   //
00116   int _dragging_select;         // dragging out a selection?
00117   int _last_row;
00118   int _last_y;                  // last event's Y position
00119   int _last_push_x;             // last PUSH event's X position
00120   int _last_push_y;             // last PUSH event's Y position
00121   
00122   TableRowSelectMode _selectmode;
00123   
00124 protected:
00125   int handle(int event);
00126   int find_cell(TableContext context,           // find cell's x/y/w/h given r/c
00127                 int R, int C, int &X, int &Y, int &W, int &H) {
00128     return(Fl_Table::find_cell(context, R, C, X, Y, W, H));
00129   }
00130   
00131 public:
00137   Fl_Table_Row(int X, int Y, int W, int H, const char *l=0) : Fl_Table(X,Y,W,H,l) {
00138     _dragging_select = 0;
00139     _last_row        = -1;
00140     _last_y          = -1;
00141     _last_push_x     = -1;
00142     _last_push_y     = -1;
00143     _selectmode      = SELECT_MULTI;
00144   }
00145   
00150   ~Fl_Table_Row() { }
00151   
00152   void rows(int val);                   // set number of rows
00153   int rows() {                          // get number of rows
00154     return(Fl_Table::rows());
00155   }
00156   
00164   void type(TableRowSelectMode val);    // set selection mode
00165   
00166   TableRowSelectMode type() const {     // get selection mode
00167     return(_selectmode);
00168   }
00169   
00175   int row_selected(int row);            // is row selected? (0=no, 1=yes, -1=range err)
00176   
00181   int select_row(int row, int flag=1);  // select state for row: flag:0=off, 1=on, 2=toggle
00182   // returns: 0=no change, 1=changed, -1=range err
00183   
00188   void select_all_rows(int flag=1);     // all rows to a known state
00189   
00190   void clear() {
00191     rows(0);            // implies clearing selection
00192     cols(0);
00193     Fl_Table::clear();  // clear the table
00194   }
00195 };
00196 
00197 #endif /*_FL_TABLE_ROW_H*/
00198 
00199 //
00200 // End of "$Id: Fl_Table_Row.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
00201 //