1 /********************************************************************************
2 *                                                                               *
3 *                            T a b l e   W i d g e t                            *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1999,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXTable.h,v 1.166.2.1 2006/06/07 15:51:04 fox Exp $                          *
23 ********************************************************************************/
24 #ifndef FXTABLE_H
25 #define FXTABLE_H
26 
27 #ifndef FXSCROLLAREA_H
28 #include "FXScrollArea.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 class FXIcon;
35 class FXFont;
36 class FXTable;
37 class FXHeader;
38 class FXButton;
39 
40 
41 /// Default cell margin
42 enum { DEFAULT_MARGIN = 2 };
43 
44 
45 
46 /// Table options
47 enum {
48   TABLE_COL_SIZABLE     = 0x00100000,   /// Columns are resizable
49   TABLE_ROW_SIZABLE     = 0x00200000,   /// Rows are resizable
50   TABLE_NO_COLSELECT    = 0x00400000,   /// Disallow column selections
51   TABLE_NO_ROWSELECT    = 0x00800000,   /// Disallow row selections
52   TABLE_READONLY        = 0x01000000,   /// Table is NOT editable
53   TABLE_COL_RENUMBER    = 0x02000000,   /// Renumber columns
54   TABLE_ROW_RENUMBER    = 0x04000000    /// Renumber rows
55   };
56 
57 
58 /// Position in table
59 struct FXTablePos {
60   FXint  row;
61   FXint  col;
62   };
63 
64 
65 /// Range of table cells
66 struct FXTableRange {
67   FXTablePos fm;
68   FXTablePos to;
69   };
70 
71 
72 /// Item in table
73 class FXAPI FXTableItem : public FXObject {
74   FXDECLARE(FXTableItem)
75   friend class FXTable;
76 protected:
77   FXString    label;
78   FXIcon     *icon;
79   void       *data;
80   FXuint      state;
81 private:
82   FXTableItem(const FXTableItem&);
83   FXTableItem& operator=(const FXTableItem&);
84 protected:
FXTableItem()85   FXTableItem():icon(NULL),data(NULL),state(0){}
86   FXint textWidth(const FXTable* table) const;
87   FXint textHeight(const FXTable* table) const;
88   virtual void draw(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
89   virtual void drawBorders(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
90   virtual void drawContent(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
91   virtual void drawPattern(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
92   virtual void drawBackground(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
93 public:
94   enum{
95     SELECTED   = 0x00000001,    /// Selected
96     FOCUS      = 0x00000002,    /// Focus
97     DISABLED   = 0x00000004,    /// Disabled
98     DRAGGABLE  = 0x00000008,    /// Draggable
99     RESERVED1  = 0x00000010,    /// Reserved
100     RESERVED2  = 0x00000020,    /// Reserved
101     ICONOWNED  = 0x00000040,    /// Icon owned by table item
102     RIGHT      = 0x00002000,    /// Align on right (default)
103     LEFT       = 0x00004000,    /// Align on left
104     CENTER_X   = 0,             /// Aling centered horizontally
105     TOP        = 0x00008000,    /// Align on top
106     BOTTOM     = 0x00010000,    /// Align on bottom
107     CENTER_Y   = 0,             /// Aling centered vertically (default)
108     BEFORE     = 0x00020000,    /// Icon before the text
109     AFTER      = 0x00040000,    /// Icon after the text
110     ABOVE      = 0x00080000,    /// Icon above the text
111     BELOW      = 0x00100000,    /// Icon below the text
112     LBORDER    = 0x00200000,    /// Draw left border
113     RBORDER    = 0x00400000,    /// Draw right border
114     TBORDER    = 0x00800000,    /// Draw top border
115     BBORDER    = 0x01000000     /// Draw bottom border
116     };
117 public:
118 
119   /// Construct new table item
label(text)120   FXTableItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL):label(text),icon(ic),data(ptr),state(RIGHT|CENTER_Y){}
121 
122   /// Change item's text label
123   virtual void setText(const FXString& txt);
124 
125   /// Return item's text label
getText()126   virtual FXString getText() const { return label; }
127 
128   /// Change item's icon, deleting the old icon if it was owned
129   virtual void setIcon(FXIcon* icn,FXbool owned=FALSE);
130 
131   /// Return item's icon
getIcon()132   virtual FXIcon* getIcon() const { return icon; }
133 
134   /// Change item's user data
setData(void * ptr)135   void setData(void* ptr){ data=ptr; }
136 
137   /// Get item's user data
getData()138   void* getData() const { return data; }
139 
140   /// Make item draw as focused
141   virtual void setFocus(FXbool focus);
142 
143   /// Return true if item has focus
hasFocus()144   FXbool hasFocus() const { return (state&FOCUS)!=0; }
145 
146   /// Select item
147   virtual void setSelected(FXbool selected);
148 
149   /// Return true if this item is selected
isSelected()150   FXbool isSelected() const { return (state&SELECTED)!=0; }
151 
152   /// Enable or disable item
153   virtual void setEnabled(FXbool enabled);
154 
155   /// Return true if this item is enabled
isEnabled()156   FXbool isEnabled() const { return (state&DISABLED)==0; }
157 
158   /// Make item draggable
159   virtual void setDraggable(FXbool draggable);
160 
161   /// Return true if this item is draggable
isDraggable()162   FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
163 
164   /// Change item content justification
165   virtual void setJustify(FXuint justify=RIGHT|CENTER_Y);
166 
167   /// Return item content justification
getJustify()168   FXuint getJustify() const { return state&(RIGHT|LEFT|TOP|BOTTOM); }
169 
170   /// Change item icon position
171   virtual void setIconPosition(FXuint mode);
172 
173   /// Return item icon position
getIconPosition()174   FXuint getIconPosition() const { return state&(BEFORE|AFTER|ABOVE|BELOW); }
175 
176   /// Change item borders
177   virtual void setBorders(FXuint borders=0);
178 
179   /// Return item borders
getBorders()180   FXuint getBorders() const { return state&(LBORDER|RBORDER|TBORDER|BBORDER); }
181 
182   /// Change item background stipple
183   virtual void setStipple(FXStipplePattern pattern);
184 
185   /// Return item background stipple
186   FXStipplePattern getStipple() const;
187 
188   /// Create input control for editing this item
189   virtual FXWindow *getControlFor(FXTable* table);
190 
191   /// Set value from input control
192   virtual void setFromControl(FXWindow *control);
193 
194   /// Return width of item
195   virtual FXint getWidth(const FXTable* table) const;
196 
197   /// Return height of item
198   virtual FXint getHeight(const FXTable* table) const;
199 
200   /// Create server-side resources
201   virtual void create();
202 
203   /// Detach server-side resources
204   virtual void detach();
205 
206   /// Destroy server-side resources
207   virtual void destroy();
208 
209   /// Save to stream
210   virtual void save(FXStream& store) const;
211 
212   /// Load from stream
213   virtual void load(FXStream& store);
214 
215   /// Destroy item and free icon if owned
216   virtual ~FXTableItem();
217   };
218 
219 
220 /// Combobox Item
221 class FXAPI FXComboTableItem : public FXTableItem {
222   FXDECLARE(FXComboTableItem)
223 protected:
224   FXString selections;
225 private:
226   FXComboTableItem(const FXComboTableItem&);
227   FXComboTableItem& operator=(const FXComboTableItem&);
228 protected:
FXComboTableItem()229   FXComboTableItem(){}
230 public:
231 
232   /// Construct new table item
233   FXComboTableItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL);
234 
235   /// Create input control for editing this item
236   virtual FXWindow *getControlFor(FXTable* table);
237 
238   /// Set value from input control
239   virtual void setFromControl(FXWindow *control);
240 
241   /// Set selections as newline-separated strings
242   void setSelections(const FXString& strings);
243 
244   /// Return selections
getSelections()245   const FXString& getSelections() const { return selections; }
246   };
247 
248 
249 /**
250 * The Table widget displays a table of items, each with a text and optional
251 * icon.  A column Header control provide captions for each column, and a row
252 * Header control provides captions for each row.  Columns are resizable by
253 * means of the column Header control if the TABLE_COL_SIZABLE option is passed.
254 * Likewise, rows in the table are resizable if the TABLE_ROW_SIZABLE option is
255 * specified.  An entire row (column) can be selected by clicking on the a button
256 * in the row (column) Header control.  Passing TABLE_NO_COLSELECT disables column
257 * selection, and passing TABLE_NO_ROWSELECT disables column selection.
258 * When TABLE_COL_RENUMBER is specified, columns are automatically renumbered when
259 * columns are added or removed.  Similarly, TABLE_ROW_RENUMBER will cause row numbers
260 * to be recalculated automatically when rows are added or removed.
261 * To disable editing of cells in the table, the TABLE_READONLY can be specified.
262 * Cells in the table may or may not have items in them.  When populating a cell
263 * for the first time, an item will be automatically created if necessary.  Thus,
264 * a cell in the table takes no space unless it has actual contents.
265 * Moreover, a contiguous, rectangular region of cells in the table may refer to
266 * one single item; in that case, the item will be stretched to cover all the
267 * cells in the region, and no grid lines will be drawn interior to the spanning
268 * item.
269 * The Table widget issues SEL_SELECTED or SEL_DESELECTED when cells are selected
270 * or deselected, respectively.  The table position affected is passed along as the
271 * 3rd parameter of these messages.
272 * Whenever the current (focus) item is changed, a SEL_CHANGED message is sent with
273 * the new table position as a parameter.
274 * When items are added to the table, a SEL_INSERTED message is sent, with the table
275 * range of the newly added cells as the parameter in the message.
276 * When items are removed from the table, a SEL_DELETED message is sent prior to the
277 * removal of the items, and the table range of the removed cells is passed as a parameter.
278 * A SEL_REPLACED message is sent when the contents of a cell are changed, either through
279 * editing or by other means; the parameter is the range of affected cells.  This message
280 * is sent prior to the change.
281 * SEL_CLICKED, SEL_DOUBLECLICKED, and SEL_TRIPLECLICKED messages are sent when a cell
282 * is clicked, double-clicked, or triple-clicked, respectively.
283 * A SEL_COMMAND is sent when an enabled item is clicked inside the table.
284 */
285 class FXAPI FXTable : public FXScrollArea {
286   FXDECLARE(FXTable)
287 protected:
288   FXHeader     *colHeader;              // Column header
289   FXHeader     *rowHeader;              // Row header
290   FXButton     *cornerButton;           // Corner button
291   FXTableItem **cells;                  // Cells
292   FXWindow     *editor;                 // Editor widget
293   FXFont       *font;                   // Font
294   FXint         nrows;                  // Number of rows
295   FXint         ncols;                  // Number of columns
296   FXint         visiblerows;            // Visible rows
297   FXint         visiblecols;            // Visible columns
298   FXint         margintop;              // Margin top
299   FXint         marginbottom;           // Margin bottom
300   FXint         marginleft;             // Margin left
301   FXint         marginright;            // Margin right
302   FXColor       textColor;              // Normal text color
303   FXColor       baseColor;              // Base color
304   FXColor       hiliteColor;            // Highlight color
305   FXColor       shadowColor;            // Shadow color
306   FXColor       borderColor;            // Border color
307   FXColor       selbackColor;           // Select background color
308   FXColor       seltextColor;           // Select text color
309   FXColor       gridColor;              // Grid line color
310   FXColor       stippleColor;           // Stipple color
311   FXColor       cellBorderColor;        // Cell border color
312   FXint         cellBorderWidth;        // Cell border width
313   FXColor       cellBackColor[2][2];    // Row/Column even/odd background color
314   FXint         defColWidth;            // Default column width [if uniform columns]
315   FXint         defRowHeight;           // Default row height [if uniform rows]
316   FXTablePos    current;                // Current position
317   FXTablePos    anchor;                 // Anchor position
318   FXTableRange  input;                  // Input cell
319   FXTableRange  selection;              // Range of selected cells
320   FXString      clipped;                // Clipped text
321   FXbool        hgrid;                  // Horizontal grid lines shown
322   FXbool        vgrid;                  // Vertical grid lines shown
323   FXuchar       mode;                   // Mode widget is in
324   FXint         grabx;                  // Grab point x
325   FXint         graby;                  // Grab point y
326   FXint         rowcol;                 // Row or column being resized
327   FXString      help;
328 public:
329   static FXDragType csvType;
330   static const FXchar csvTypeName[];
331 protected:
332   FXTable();
333   FXint startRow(FXint row,FXint col) const;
334   FXint startCol(FXint row,FXint col) const;
335   FXint endRow(FXint row,FXint col) const;
336   FXint endCol(FXint row,FXint col) const;
337   void spanningRange(FXint& sr,FXint& er,FXint& sc,FXint& ec,FXint anchrow,FXint anchcol,FXint currow,FXint curcol);
338   virtual void moveContents(FXint x,FXint y);
339   virtual void drawCell(FXDC& dc,FXint sr,FXint er,FXint sc,FXint ec);
340   virtual void drawRange(FXDC& dc,FXint rlo,FXint rhi,FXint clo,FXint chi);
341   virtual void drawHGrid(FXDC& dc,FXint rlo,FXint rhi,FXint clo,FXint chi);
342   virtual void drawVGrid(FXDC& dc,FXint rlo,FXint rhi,FXint clo,FXint chi);
343   virtual void drawContents(FXDC& dc,FXint x,FXint y,FXint w,FXint h);
344   virtual FXTableItem* createItem(const FXString& text,FXIcon* icon,void* ptr);
345   virtual FXWindow *getControlForItem(FXint r,FXint c);
346   virtual void setItemFromControl(FXint r,FXint c,FXWindow *control);
347   virtual void updateColumnNumbers(FXint lo,FXint hi);
348   virtual void updateRowNumbers(FXint lo,FXint hi);
349 protected:
350   enum {
351     MOUSE_NONE,
352     MOUSE_SCROLL,
353     MOUSE_DRAG,
354     MOUSE_SELECT
355     };
356 private:
357   FXTable(const FXTable&);
358   FXTable& operator=(const FXTable&);
359 public:
360   long onPaint(FXObject*,FXSelector,void*);
361   long onFocusIn(FXObject*,FXSelector,void*);
362   long onFocusOut(FXObject*,FXSelector,void*);
363   long onMotion(FXObject*,FXSelector,void*);
364   long onKeyPress(FXObject*,FXSelector,void*);
365   long onKeyRelease(FXObject*,FXSelector,void*);
366   long onLeftBtnPress(FXObject*,FXSelector,void*);
367   long onLeftBtnRelease(FXObject*,FXSelector,void*);
368   long onRightBtnPress(FXObject*,FXSelector,void*);
369   long onRightBtnRelease(FXObject*,FXSelector,void*);
370   long onUngrabbed(FXObject*,FXSelector,void*);
371   long onSelectionLost(FXObject*,FXSelector,void*);
372   long onSelectionGained(FXObject*,FXSelector,void*);
373   long onSelectionRequest(FXObject*,FXSelector,void* ptr);
374   long onClipboardLost(FXObject*,FXSelector,void*);
375   long onClipboardGained(FXObject*,FXSelector,void*);
376   long onClipboardRequest(FXObject*,FXSelector,void*);
377   long onAutoScroll(FXObject*,FXSelector,void*);
378   long onCommand(FXObject*,FXSelector,void*);
379   long onClicked(FXObject*,FXSelector,void*);
380   long onDoubleClicked(FXObject*,FXSelector,void*);
381   long onTripleClicked(FXObject*,FXSelector,void*);
382 
383   long onCmdToggleEditable(FXObject*,FXSelector,void*);
384   long onUpdToggleEditable(FXObject*,FXSelector,void*);
385 
386   // Visual characteristics
387   long onCmdHorzGrid(FXObject*,FXSelector,void*);
388   long onUpdHorzGrid(FXObject*,FXSelector,void*);
389   long onCmdVertGrid(FXObject*,FXSelector,void*);
390   long onUpdVertGrid(FXObject*,FXSelector,void*);
391 
392   // Row/Column manipulations
393   long onCmdDeleteColumn(FXObject*,FXSelector,void*);
394   long onUpdDeleteColumn(FXObject*,FXSelector,void*);
395   long onCmdDeleteRow(FXObject*,FXSelector,void*);
396   long onUpdDeleteRow(FXObject*,FXSelector,void*);
397   long onCmdInsertColumn(FXObject*,FXSelector,void*);
398   long onUpdInsertColumn(FXObject*,FXSelector,void*);
399   long onCmdInsertRow(FXObject*,FXSelector,void*);
400   long onUpdInsertRow(FXObject*,FXSelector,void*);
401 
402   // Movement
403   long onCmdMoveRight(FXObject*,FXSelector,void*);
404   long onCmdMoveLeft(FXObject*,FXSelector,void*);
405   long onCmdMoveUp(FXObject*,FXSelector,void*);
406   long onCmdMoveDown(FXObject*,FXSelector,void*);
407   long onCmdMoveHome(FXObject*,FXSelector,void*);
408   long onCmdMoveEnd(FXObject*,FXSelector,void*);
409   long onCmdMoveTop(FXObject*,FXSelector,void*);
410   long onCmdMoveBottom(FXObject*,FXSelector,void*);
411   long onCmdMovePageDown(FXObject*,FXSelector,void*);
412   long onCmdMovePageUp(FXObject*,FXSelector,void*);
413 
414   // Mark and extend
415   long onCmdMark(FXObject*,FXSelector,void*);
416   long onCmdExtend(FXObject*,FXSelector,void*);
417 
418   // Changing Selection
419   long onUpdSelectCell(FXObject*,FXSelector,void*);
420   long onCmdSelectCell(FXObject*,FXSelector,void*);
421   long onUpdSelectRow(FXObject*,FXSelector,void*);
422   long onCmdSelectRow(FXObject*,FXSelector,void*);
423   long onUpdSelectColumn(FXObject*,FXSelector,void*);
424   long onCmdSelectColumn(FXObject*,FXSelector,void*);
425   long onCmdSelectRowIndex(FXObject*,FXSelector,void*);
426   long onCmdSelectColumnIndex(FXObject*,FXSelector,void*);
427   long onUpdSelectAll(FXObject*,FXSelector,void*);
428   long onCmdSelectAll(FXObject*,FXSelector,void*);
429   long onUpdDeselectAll(FXObject*,FXSelector,void*);
430   long onCmdDeselectAll(FXObject*,FXSelector,void*);
431 
432   // Manipulation Selection
433   long onCmdCutSel(FXObject*,FXSelector,void*);
434   long onCmdCopySel(FXObject*,FXSelector,void*);
435   long onCmdDeleteSel(FXObject*,FXSelector,void*);
436   long onCmdPasteSel(FXObject*,FXSelector,void*);
437   long onUpdHaveSelection(FXObject*,FXSelector,void*);
438 
439   // Edit control
440   long onCmdStartInput(FXObject*,FXSelector,void*);
441   long onUpdStartInput(FXObject*,FXSelector,void*);
442   long onCmdAcceptInput(FXObject*,FXSelector,void*);
443   long onUpdAcceptInput(FXObject*,FXSelector,void*);
444   long onCmdCancelInput(FXObject*,FXSelector,void*);
445 public:
446 
447   enum {
448     ID_HORZ_GRID=FXScrollArea::ID_LAST,
449     ID_VERT_GRID,
450     ID_TOGGLE_EDITABLE,
451     ID_DELETE_COLUMN,
452     ID_DELETE_ROW,
453     ID_INSERT_COLUMN,
454     ID_INSERT_ROW,
455     ID_SELECT_COLUMN_INDEX,
456     ID_SELECT_ROW_INDEX,
457     ID_SELECT_COLUMN,
458     ID_SELECT_ROW,
459     ID_SELECT_CELL,
460     ID_SELECT_ALL,
461     ID_DESELECT_ALL,
462     ID_MOVE_LEFT,
463     ID_MOVE_RIGHT,
464     ID_MOVE_UP,
465     ID_MOVE_DOWN,
466     ID_MOVE_HOME,
467     ID_MOVE_END,
468     ID_MOVE_TOP,
469     ID_MOVE_BOTTOM,
470     ID_MOVE_PAGEDOWN,
471     ID_MOVE_PAGEUP,
472     ID_START_INPUT,
473     ID_CANCEL_INPUT,
474     ID_ACCEPT_INPUT,
475     ID_MARK,
476     ID_EXTEND,
477     ID_CUT_SEL,
478     ID_COPY_SEL,
479     ID_PASTE_SEL,
480     ID_DELETE_SEL,
481     ID_LAST
482     };
483 
484 public:
485 
486   /**
487   * Construct a new table.
488   * The table is initially empty, and reports a default size based on
489   * the scroll areas's scrollbar placement policy.
490   */
491   FXTable(FXComposite *p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=0,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_MARGIN,FXint pr=DEFAULT_MARGIN,FXint pt=DEFAULT_MARGIN,FXint pb=DEFAULT_MARGIN);
492 
493   /// Return default width
494   virtual FXint getDefaultWidth();
495 
496   /// Return default height
497   virtual FXint getDefaultHeight();
498 
499   /// Computes content width
500   virtual FXint getContentWidth();
501 
502   /// Computes content height
503   virtual FXint getContentHeight();
504 
505   /// Create the server-side resources
506   virtual void create();
507 
508   /// Detach the server-side resources
509   virtual void detach();
510 
511   /// Perform layout
512   virtual void layout();
513 
514   /// Mark this window's layout as dirty
515   virtual void recalc();
516 
517   /// Table widget can receive focus
518   virtual bool canFocus() const;
519 
520   /// Move the focus to this window
521   virtual void setFocus();
522 
523   /// Remove the focus from this window
524   virtual void killFocus();
525 
526   /// Notification that focus moved to new child
527   virtual void changeFocus(FXWindow *child);
528 
529   /// Return button in the top/left corner
getCornerButton()530   FXButton* getCornerButton() const { return cornerButton; }
531 
532   /// Return column header control
getColumnHeader()533   FXHeader* getColumnHeader() const { return colHeader; }
534 
535   /// Return row header control
getRowHeader()536   FXHeader* getRowHeader() const { return rowHeader; }
537 
538   /// Change visible rows
539   void setVisibleRows(FXint nvrows);
540 
541   /// return number of visible rows
getVisibleRows()542   FXint getVisibleRows() const { return visiblerows; }
543 
544   /// Change visible columns
545   void setVisibleColumns(FXint nvcols);
546 
547   /// Return number of visible columns
getVisibleColumns()548   FXint getVisibleColumns() const { return visiblecols; }
549 
550   /// Return TRUE if table is editable
551   FXbool isEditable() const;
552 
553   /// Set editable flag
554   void setEditable(FXbool edit=TRUE);
555 
556   /// Show or hide horizontal grid
557   void showHorzGrid(FXbool on=TRUE);
558 
559   /// Is horizontal grid shown
isHorzGridShown()560   FXbool isHorzGridShown() const { return hgrid; }
561 
562   /// Show or hide vertical grid
563   void showVertGrid(FXbool on=TRUE);
564 
565   /// Is vertical grid shown
isVertGridShown()566   FXbool isVertGridShown() const { return vgrid; }
567 
568   /// Get number of rows
getNumRows()569   FXint getNumRows() const { return nrows; }
570 
571   /// Get number of columns
getNumColumns()572   FXint getNumColumns() const { return ncols; }
573 
574   /// Change top cell margin
575   void setMarginTop(FXint pt);
576 
577   /// Return top cell margin
getMarginTop()578   FXint getMarginTop() const { return margintop; }
579 
580   /// Change bottom cell margin
581   void setMarginBottom(FXint pb);
582 
583   /// Return bottom cell margin
getMarginBottom()584   FXint getMarginBottom() const { return marginbottom; }
585 
586   /// Change left cell margin
587   void setMarginLeft(FXint pl);
588 
589   /// Return left cell margin
getMarginLeft()590   FXint getMarginLeft() const { return marginleft; }
591 
592   /// Change right cell margin
593   void setMarginRight(FXint pr);
594 
595   /// Return right cell margin
getMarginRight()596   FXint getMarginRight() const { return marginright; }
597 
598   /**
599   * Start input mode for the cell at the given position.
600   * An input control is created which is used to edit the cell;
601   * it is filled by the original item's contents if the cell contained
602   * an item.  You can enter input mode also by sending the table an
603   * ID_START_INPUT message.
604   */
605   virtual void startInput(FXint row,FXint col);
606 
607   /**
608   * Cancel input mode.  The input control is immediately deleted
609   * and the cell will retain its old value.  You can also cancel
610   * input mode by sending the table an ID_CANCEL_INPUT message.
611   */
612   virtual void cancelInput();
613 
614   /**
615   * End input mode and accept the new value from the control.
616   * The item in the cell will be set to the value from the control,
617   * and the control will be deleted.  If TRUE is passed, a SEL_REPLACED
618   * callback will be generated to signify to the target that this call
619   * has a new value.  You can also accept the input by sending the table
620   * an ID_ACCEPT_INPUT message.
621   */
622   virtual void acceptInput(FXbool notify=FALSE);
623 
624   /**
625   * Determine column containing x.
626   * Returns -1 if x left of first column, and ncols if x right of last column;
627   * otherwise, returns column in table containing x.
628   */
629   FXint colAtX(FXint x) const;
630 
631   /**
632   * Determine row containing y.
633   * Returns -1 if y above first row, and nrows if y below last row;
634   * otherwise, returns row in table containing y.
635   */
636   FXint rowAtY(FXint y) const;
637 
638   /// Return the item at the given index
639   FXTableItem *getItem(FXint row,FXint col) const;
640 
641   /// Replace the item with a [possibly subclassed] item
642   void setItem(FXint row,FXint col,FXTableItem* item,FXbool notify=FALSE);
643 
644   /// Set the table size to nr rows and nc columns; all existing items will be removed
645   virtual void setTableSize(FXint nr,FXint nc,FXbool notify=FALSE);
646 
647   /// Insert new row
648   virtual void insertRows(FXint row,FXint nr=1,FXbool notify=FALSE);
649 
650   /// Insert new column
651   virtual void insertColumns(FXint col,FXint nc=1,FXbool notify=FALSE);
652 
653   /// Remove rows of cells
654   virtual void removeRows(FXint row,FXint nr=1,FXbool notify=FALSE);
655 
656   /// Remove column of cells
657   virtual void removeColumns(FXint col,FXint nc=1,FXbool notify=FALSE);
658 
659   /// Extract item from table
660   virtual FXTableItem* extractItem(FXint row,FXint col,FXbool notify=FALSE);
661 
662   /// Clear single cell
663   virtual void removeItem(FXint row,FXint col,FXbool notify=FALSE);
664 
665   /// Clear all cells in the given range
666   virtual void removeRange(FXint startrow,FXint endrow,FXint startcol,FXint endcol,FXbool notify=FALSE);
667 
668   /// Remove all items from table
669   virtual void clearItems(FXbool notify=FALSE);
670 
671   /// Scroll to make cell at r,c fully visible
672   virtual void makePositionVisible(FXint r,FXint c);
673 
674   /// Return TRUE if item partially visible
675   FXbool isItemVisible(FXint r,FXint c) const;
676 
677   /**
678   * Change column header height mode to fixed or variable.
679   * In variable height mode, the column header will size to
680   * fit the contents in it.  In fixed mode, the size is
681   * explicitly set using setColumnHeaderHeight().
682   */
683   void setColumnHeaderMode(FXuint hint=LAYOUT_FIX_HEIGHT);
684 
685   /// Return column header height mode
686   FXuint getColumnHeaderMode() const;
687 
688   /**
689   * Change row header width mode to fixed or variable.
690   * In variable width mode, the row header will size to
691   * fit the contents in it.  In fixed mode, the size is
692   * explicitly set using setRowHeaderWidth().
693   */
694   void setRowHeaderMode(FXuint hint=LAYOUT_FIX_WIDTH);
695 
696   /// Return row header width mode
697   FXuint getRowHeaderMode() const;
698 
699   /// Set column header font
700   void setColumnHeaderFont(FXFont* fnt);
701 
702   /// Return column header font
703   FXFont* getColumnHeaderFont() const;
704 
705   /// Set row header font
706   void setRowHeaderFont(FXFont* fnt);
707 
708   /// Return row header font
709   FXFont* getRowHeaderFont() const;
710 
711   /// Change column header height
712   void setColumnHeaderHeight(FXint h);
713 
714   /// Return column header height
715   FXint getColumnHeaderHeight() const;
716 
717   /// Change row header width
718   void setRowHeaderWidth(FXint w);
719 
720   /// Return row header width
721   FXint getRowHeaderWidth() const;
722 
723   /// Get X coordinate of column
724   FXint getColumnX(FXint col) const;
725 
726   /// Get Y coordinate of row
727   FXint getRowY(FXint row) const;
728 
729   /// Change column width
730   virtual void setColumnWidth(FXint col,FXint cwidth);
731 
732   /// Get column width
733   FXint getColumnWidth(FXint col) const;
734 
735   /// Change row height
736   virtual void setRowHeight(FXint row,FXint rheight);
737 
738   /// Get row height
739   FXint getRowHeight(FXint row) const;
740 
741   /// Change default column width
742   void setDefColumnWidth(FXint cwidth);
743 
744   /// Get default column width
getDefColumnWidth()745   FXint getDefColumnWidth() const { return defColWidth; }
746 
747   /// Change default row height
748   void setDefRowHeight(FXint rheight);
749 
750   /// Get default row height
getDefRowHeight()751   FXint getDefRowHeight() const { return defRowHeight; }
752 
753   /// Return minimum row height
754   FXint getMinRowHeight(FXint r) const;
755 
756   /// Return minimum column width
757   FXint getMinColumnWidth(FXint c) const;
758 
759   /// Fit row heights to contents
760   void fitRowsToContents(FXint row,FXint nr=1);
761 
762   /// Fit column widths to contents
763   void fitColumnsToContents(FXint col,FXint nc=1);
764 
765   /// Change column header text
766   void setColumnText(FXint index,const FXString& text);
767 
768   /// Return text of column header at index
769   FXString getColumnText(FXint index) const;
770 
771   /// Change row header text
772   void setRowText(FXint index,const FXString& text);
773 
774   /// Return text of row header at index
775   FXString getRowText(FXint index) const;
776 
777   /// Change column header icon
778   void setColumnIcon(FXint index,FXIcon* icon);
779 
780   /// Return icon of column header at index
781   FXIcon* getColumnIcon(FXint index) const;
782 
783   /// Change row header icon
784   void setRowIcon(FXint index,FXIcon* icon);
785 
786   /// Return icon of row header at index
787   FXIcon* getRowIcon(FXint index) const;
788 
789   /// Change column header icon position, e.g. FXHeaderItem::BEFORE, etc.
790   void setColumnIconPosition(FXint index,FXuint mode);
791 
792   /// Return icon position of column header at index
793   FXuint getColumnIconPosition(FXint index) const;
794 
795   /// Change row header icon position, e.g. FXHeaderItem::BEFORE, etc.
796   void setRowIconPosition(FXint index,FXuint mode);
797 
798   /// Return icon position of row header at index
799   FXuint getRowIconPosition(FXint index) const;
800 
801   /// Change column header justify, e.g. FXHeaderItem::RIGHT, etc.
802   void setColumnJustify(FXint index,FXuint justify);
803 
804   /// Return justify of column header at index
805   FXuint getColumnJustify(FXint index) const;
806 
807   /// Change row header justify, e.g. FXHeaderItem::RIGHT, etc.
808   void setRowJustify(FXint index,FXuint justify);
809 
810   /// Return justify of row header at index
811   FXuint getRowJustify(FXint index) const;
812 
813   /// Modify cell text
814   void setItemText(FXint r,FXint c,const FXString& text,FXbool notify=FALSE);
815 
816   /// Return cell text
817   FXString getItemText(FXint r,FXint c) const;
818 
819   /// Modify cell icon, deleting the old icon if it was owned
820   void setItemIcon(FXint r,FXint c,FXIcon* icon,FXbool owned=FALSE,FXbool notify=FALSE);
821 
822   /// Return cell icon
823   FXIcon* getItemIcon(FXint r,FXint c) const;
824 
825   /// Modify cell user-data
826   void setItemData(FXint r,FXint c,void* ptr);
827   void* getItemData(FXint r,FXint c) const;
828 
829   /**
830   * Extract cells from given range as text, each column separated by a string cs,
831   * and each row separated by a string rs.
832   */
833   void extractText(FXchar*& text,FXint& size,FXint startrow,FXint endrow,FXint startcol,FXint endcol,const FXchar* cs="\t",const FXchar* rs="\n") const;
834   void extractText(FXString& text,FXint startrow,FXint endrow,FXint startcol,FXint endcol,const FXchar* cs="\t",const FXchar* rs="\n") const;
835 
836   /**
837   * Overlay text over given cell range; the text is interpreted as
838   * a number of columns separated by a character from the set cs, and
839   * a number of rows separated by a character from the set rs.
840   * Cells outside the given cell range are unaffected.
841   */
842   void overlayText(FXint startrow,FXint endrow,FXint startcol,FXint endcol,const FXchar* text,FXint size,const FXchar* cs="\t,",const FXchar* rs="\n",FXbool notify=FALSE);
843   void overlayText(FXint startrow,FXint endrow,FXint startcol,FXint endcol,const FXString& text,const FXchar* cs="\t,",const FXchar* rs="\n",FXbool notify=FALSE);
844 
845   /**
846   * Determine the number of rows and columns in a block of text
847   * where columns are separated by characters from the set cs, and rows
848   * are separated by characters from the set rs.
849   */
850   void countText(FXint& nr,FXint& nc,const FXchar* text,FXint size,const FXchar* cs="\t,",const FXchar* rs="\n") const;
851   void countText(FXint& nr,FXint& nc,const FXString& text,const FXchar* cs="\t,",const FXchar* rs="\n") const;
852 
853   /// Return TRUE if its a spanning cell
854   FXbool isItemSpanning(FXint r,FXint c) const;
855 
856   /// Repaint cells between grid lines sr,er and grid lines sc,ec
857   void updateRange(FXint sr,FXint er,FXint sc,FXint ec) const;
858 
859   /// Repaint cell at r,c
860   void updateItem(FXint r,FXint c) const;
861 
862   /// Enable item
863   virtual FXbool enableItem(FXint r,FXint c);
864 
865   /// Disable item
866   virtual FXbool disableItem(FXint r,FXint c);
867 
868   /// Is item enabled
869   FXbool isItemEnabled(FXint r,FXint c) const;
870 
871   /**
872   * Change item justification.  Horizontal justification is controlled by passing
873   * FXTableItem::RIGHT,  FXTableItem::LEFT, or FXTableItem::CENTER_X.
874   * Vertical justification is controlled by FXTableItem::TOP, FXTableItem::BOTTOM,
875   * or FXTableItem::CENTER_Y.
876   * The default is a combination of FXTableItem::RIGHT and FXTableItem::CENTER_Y.
877   */
878   void setItemJustify(FXint r,FXint c,FXuint justify);
879 
880   /// Return item justification
881   FXuint getItemJustify(FXint r,FXint c) const;
882 
883   /**
884   * Change relative position of icon and text of item.
885   * Passing FXTableItem::BEFORE or FXTableItem::AFTER places the icon
886   * before or after the text, and passing FXTableItem::ABOVE or
887   * FXTableItem::BELOW places it above or below the text, respectively.
888   * The default is 0 which places the text on top of the icon.
889   */
890   void setItemIconPosition(FXint r,FXint c,FXuint mode);
891 
892   /// Return relative icon and text position
893   FXuint getItemIconPosition(FXint r,FXint c) const;
894 
895   /**
896   * Change item borders style.  Borders on each side of the item can be turned
897   * controlled individually using FXTableItem::LBORDER, FXTableItem::RBORDER,
898   * FXTableItem::TBORDER and FXTableItem::BBORDER.
899   */
900   void setItemBorders(FXint r,FXint c,FXuint borders);
901 
902   /// Return item border style
903   FXuint getItemBorders(FXint r,FXint c) const;
904 
905   /// Change item background stipple style
906   void setItemStipple(FXint r,FXint c,FXStipplePattern pat);
907 
908   /// return item background stipple style
909   FXStipplePattern getItemStipple(FXint r,FXint c) const;
910 
911   /// Change current item
912   virtual void setCurrentItem(FXint r,FXint c,FXbool notify=FALSE);
913 
914   /// Get row number of current item
getCurrentRow()915   FXint getCurrentRow() const { return current.row; }
916 
917   /// Get column number of current item
getCurrentColumn()918   FXint getCurrentColumn() const { return current.col; }
919 
920   /// Is item current
921   FXbool isItemCurrent(FXint r,FXint c) const;
922 
923   /// Change anchor item
924   void setAnchorItem(FXint r,FXint c);
925 
926   /// Get row number of anchor item
getAnchorRow()927   FXint getAnchorRow() const { return anchor.row; }
928 
929   /// Get column number of anchor item
getAnchorColumn()930   FXint getAnchorColumn() const { return anchor.col; }
931 
932   /// Get selection start row; returns -1 if no selection
getSelStartRow()933   FXint getSelStartRow() const { return selection.fm.row; }
934 
935   /// Get selection start column; returns -1 if no selection
getSelStartColumn()936   FXint getSelStartColumn() const { return selection.fm.col; }
937 
938   /// Get selection end row; returns -1 if no selection
getSelEndRow()939   FXint getSelEndRow() const { return selection.to.row; }
940 
941   /// Get selection end column; returns -1 if no selection
getSelEndColumn()942   FXint getSelEndColumn() const { return selection.to.col; }
943 
944   /// Is cell selected
945   FXbool isItemSelected(FXint r,FXint c) const;
946 
947   /// Is row of cells selected
948   FXbool isRowSelected(FXint r) const;
949 
950   /// Is column selected
951   FXbool isColumnSelected(FXint c) const;
952 
953   /// Is anything selected
954   FXbool isAnythingSelected() const;
955 
956   /// Select a row
957   virtual FXbool selectRow(FXint row,FXbool notify=FALSE);
958 
959   /// Select a column
960   virtual FXbool selectColumn(FXint col,FXbool notify=FALSE);
961 
962   /// Select range
963   virtual FXbool selectRange(FXint startrow,FXint endrow,FXint startcol,FXint endcol,FXbool notify=FALSE);
964 
965   /// Extend selection
966   virtual FXbool extendSelection(FXint r,FXint c,FXbool notify=FALSE);
967 
968   /// Kill selection
969   virtual FXbool killSelection(FXbool notify=FALSE);
970 
971   /// Change font
972   void setFont(FXFont* fnt);
973 
974   /// Return current font
getFont()975   FXFont* getFont() const { return font; }
976 
977   /// Obtain colors of various parts
getTextColor()978   FXColor getTextColor() const { return textColor; }
getBaseColor()979   FXColor getBaseColor() const { return baseColor; }
getHiliteColor()980   FXColor getHiliteColor() const { return hiliteColor; }
getShadowColor()981   FXColor getShadowColor() const { return shadowColor; }
getBorderColor()982   FXColor getBorderColor() const { return borderColor; }
getSelBackColor()983   FXColor getSelBackColor() const { return selbackColor; }
getSelTextColor()984   FXColor getSelTextColor() const { return seltextColor; }
getGridColor()985   FXColor getGridColor() const { return gridColor; }
getStippleColor()986   FXColor getStippleColor() const { return stippleColor; }
getCellBorderColor()987   FXColor getCellBorderColor() const { return cellBorderColor; }
988 
989   /// Change colors of various parts
990   void setTextColor(FXColor clr);
991   void setBaseColor(FXColor clr);
992   void setHiliteColor(FXColor clr);
993   void setShadowColor(FXColor clr);
994   void setBorderColor(FXColor clr);
995   void setSelBackColor(FXColor clr);
996   void setSelTextColor(FXColor clr);
997   void setGridColor(FXColor clr);
998   void setStippleColor(FXColor clr);
999   void setCellBorderColor(FXColor clr);
1000 
1001   /// Change cell background color for even/odd rows/columns
1002   void setCellColor(FXint r,FXint c,FXColor clr);
1003 
1004   /// Obtain cell background color for even/odd rows/columns
1005   FXColor getCellColor(FXint r,FXint c) const;
1006 
1007   /// Change cell border width
1008   void setCellBorderWidth(FXint borderwidth);
1009 
1010   /// Return cell border width
getCellBorderWidth()1011   FXint getCellBorderWidth() const { return cellBorderWidth; }
1012 
1013   /// Change table style
1014   void setTableStyle(FXuint style);
1015 
1016   /// Return table style
1017   FXuint getTableStyle() const;
1018 
1019   /// Set column renumbering
1020   void setColumnRenumbering(FXbool flag);
1021 
1022   /// Get column renumbering
1023   FXbool getColumnRenumbering() const;
1024 
1025   /// Set row renumbering
1026   void setRowRenumbering(FXbool flag);
1027 
1028   /// Get row renumbering
1029   FXbool getRowRenumbering() const;
1030 
1031   /// Change help text
setHelpText(const FXString & text)1032   void setHelpText(const FXString& text){ help=text; }
getHelpText()1033   const FXString& getHelpText() const { return help; }
1034 
1035   /// Serialize
1036   virtual void save(FXStream& store) const;
1037   virtual void load(FXStream& store);
1038 
1039   virtual ~FXTable();
1040   };
1041 
1042 }
1043 
1044 #endif
1045