00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef FXTABLE_H
00025 #define FXTABLE_H
00026
00027 #ifndef FXSCROLLAREA_H
00028 #include "FXScrollArea.h"
00029 #endif
00030
00031 namespace FX {
00032
00033
00034
00035
00036 class FXIcon;
00037 class FXFont;
00038 class FXTable;
00039 class FXHeader;
00040 class FXButton;
00041
00042
00043
00044 enum { DEFAULT_MARGIN = 2 };
00045
00046
00047
00048
00049 enum {
00050 TABLE_COL_SIZABLE = 0x00100000,
00051 TABLE_ROW_SIZABLE = 0x00200000,
00052 TABLE_HEADERS_SIZABLE = 0x00400000,
00053 TABLE_NO_COLSELECT = 0x00900000,
00054 TABLE_NO_ROWSELECT = 0x01000000
00055 };
00056
00057
00058
00059 struct FXTablePos {
00060 FXint row;
00061 FXint col;
00062 };
00063
00064
00065
00066 struct FXTableRange {
00067 FXTablePos fm;
00068 FXTablePos to;
00069 };
00070
00071
00072
00073 class FXAPI FXTableItem : public FXObject {
00074 FXDECLARE(FXTableItem)
00075 friend class FXTable;
00076 protected:
00077 FXString label;
00078 FXIcon *icon;
00079 void *data;
00080 FXuint state;
00081 protected:
00082 FXTableItem():icon(NULL),data(NULL),state(0){}
00083 FXint textWidth(const FXTable* table) const;
00084 FXint textHeight(const FXTable* table) const;
00085 virtual void draw(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00086 virtual void drawBorders(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00087 virtual void drawContent(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00088 virtual void drawPattern(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00089 virtual void drawBackground(const FXTable* table,FXDC& dc,FXint x,FXint y,FXint w,FXint h) const;
00090 protected:
00091 enum{
00092 SELECTED = 0x00000001,
00093 FOCUS = 0x00000002,
00094 DISABLED = 0x00000004,
00095 DRAGGABLE = 0x00000008,
00096 RESERVED1 = 0x00000010,
00097 RESERVED2 = 0x00000020,
00098 ICONOWNED = 0x00000040
00099 };
00100 public:
00101 enum{
00102 RIGHT = 0x00002000,
00103 LEFT = 0x00004000,
00104 CENTER_X = 0,
00105 TOP = 0x00008000,
00106 BOTTOM = 0x00010000,
00107 CENTER_Y = 0,
00108 BEFORE = 0x00020000,
00109 AFTER = 0x00040000,
00110 ABOVE = 0x00080000,
00111 BELOW = 0x00100000,
00112 LBORDER = 0x00200000,
00113 RBORDER = 0x00400000,
00114 TBORDER = 0x00800000,
00115 BBORDER = 0x01000000
00116 };
00117 public:
00118 FXTableItem(const FXString& text,FXIcon* ic=NULL,void* ptr=NULL):label(text),icon(ic),data(ptr),state(FXTableItem::RIGHT){}
00119 virtual void setText(const FXString& txt){ label=txt; }
00120 const FXString& getText() const { return label; }
00121 virtual void setIcon(FXIcon* icn){ icon=icn; }
00122 FXIcon* getIcon() const { return icon; }
00123 void setData(void* ptr){ data=ptr; }
00124 void* getData() const { return data; }
00125 virtual void setFocus(FXbool focus);
00126 FXbool hasFocus() const { return (state&FOCUS)!=0; }
00127 virtual void setSelected(FXbool selected);
00128 FXbool isSelected() const { return (state&SELECTED)!=0; }
00129 virtual void setEnabled(FXbool enabled);
00130 FXbool isEnabled() const { return (state&DISABLED)==0; }
00131 virtual void setDraggable(FXbool draggable);
00132 FXbool isDraggable() const { return (state&DRAGGABLE)!=0; }
00133 void setJustify(FXuint justify);
00134 FXuint getJustify() const { return state&(RIGHT|LEFT|TOP|BOTTOM); }
00135 void setIconPosition(FXuint mode);
00136 FXuint getIconPosition() const { return state&(BEFORE|AFTER|ABOVE|BELOW); }
00137 void setBorders(FXuint borders);
00138 FXuint getBorders() const { return state&(LBORDER|RBORDER|TBORDER|BBORDER); }
00139 void setStipple(FXStipplePattern pattern);
00140 FXStipplePattern getStipple() const;
00141 virtual void setIconOwned(FXuint owned=ICONOWNED);
00142 FXuint isIconOwned() const { return (state&ICONOWNED); }
00143 virtual FXint getWidth(const FXTable* table) const;
00144 virtual FXint getHeight(const FXTable* table) const;
00145 virtual void create();
00146 virtual void detach();
00147 virtual void destroy();
00148 virtual void save(FXStream& store) const;
00149 virtual void load(FXStream& store);
00150 virtual ~FXTableItem();
00151 };
00152
00153
00154
00155
00156 class FXAPI FXTable : public FXScrollArea {
00157 FXDECLARE(FXTable)
00158 protected:
00159 FXHeader *colHeader;
00160 FXHeader *rowHeader;
00161 FXButton *cornerButton;
00162 FXTableItem **cells;
00163 FXFont *font;
00164 FXint nrows;
00165 FXint ncols;
00166 FXint visiblerows;
00167 FXint visiblecols;
00168 FXint margintop;
00169 FXint marginbottom;
00170 FXint marginleft;
00171 FXint marginright;
00172 FXColor textColor;
00173 FXColor baseColor;
00174 FXColor hiliteColor;
00175 FXColor shadowColor;
00176 FXColor borderColor;
00177 FXColor selbackColor;
00178 FXColor seltextColor;
00179 FXColor gridColor;
00180 FXColor stippleColor;
00181 FXColor cellBorderColor;
00182 FXint cellBorderWidth;
00183 FXColor cellBackColor[2][2];
00184 FXint defColWidth;
00185 FXint defRowHeight;
00186 FXTablePos current;
00187 FXTablePos anchor;
00188 FXTableRange selection;
00189 FXint cellcursor;
00190 FXint cellanchor;
00191 FXint cellscroll;
00192 FXbool hgrid;
00193 FXbool vgrid;
00194 FXuchar mode;
00195 FXint grabx;
00196 FXint graby;
00197 FXint rowcol;
00198 FXString help;
00199 public:
00200 static FXDragType csvType;
00201 static const FXchar csvTypeName[];
00202 protected:
00203 FXTable();
00204 FXint startRow(FXint row,FXint col) const;
00205 FXint startCol(FXint row,FXint col) const;
00206 FXint endRow(FXint row,FXint col) const;
00207 FXint endCol(FXint row,FXint col) const;
00208 void findExtent(FXint& sr,FXint& er,FXint& sc,FXint& ec,FXint anchrow,FXint anchcol,FXint currow,FXint curcol);
00209 void drawCursor(FXuint state);
00210 virtual void moveContents(FXint x,FXint y);
00211 virtual void drawCell(FXDC& dc,FXint sr,FXint er,FXint sc,FXint ec);
00212 virtual void drawRange(FXDC& dc,FXint rlo,FXint rhi,FXint clo,FXint chi);
00213 virtual void drawHGrid(FXDC& dc,FXint rlo,FXint rhi,FXint clo,FXint chi);
00214 virtual void drawVGrid(FXDC& dc,FXint rlo,FXint rhi,FXint clo,FXint chi);
00215 virtual void drawContents(FXDC& dc,FXint x,FXint y,FXint w,FXint h);
00216 virtual FXTableItem* createItem(const FXString& text,FXIcon* icon,void* ptr);
00217 protected:
00218 enum {
00219 MOUSE_NONE,
00220 MOUSE_SCROLL,
00221 MOUSE_DRAG,
00222 MOUSE_SELECT,
00223 MOUSE_COL_SIZE,
00224 MOUSE_ROW_SIZE
00225 };
00226 private:
00227 FXTable(const FXTable&);
00228 FXTable& operator=(const FXTable&);
00229 public:
00230 long onPaint(FXObject*,FXSelector,void*);
00231 long onFocusIn(FXObject*,FXSelector,void*);
00232 long onFocusOut(FXObject*,FXSelector,void*);
00233 long onMotion(FXObject*,FXSelector,void*);
00234 long onKeyPress(FXObject*,FXSelector,void*);
00235 long onKeyRelease(FXObject*,FXSelector,void*);
00236 long onLeftBtnPress(FXObject*,FXSelector,void*);
00237 long onLeftBtnRelease(FXObject*,FXSelector,void*);
00238 long onRightBtnPress(FXObject*,FXSelector,void*);
00239 long onRightBtnRelease(FXObject*,FXSelector,void*);
00240 long onUngrabbed(FXObject*,FXSelector,void*);
00241 long onBlink(FXObject*,FXSelector,void*);
00242 long onSelectionLost(FXObject*,FXSelector,void*);
00243 long onSelectionGained(FXObject*,FXSelector,void*);
00244 long onSelectionRequest(FXObject*,FXSelector,void* ptr);
00245 long onClipboardLost(FXObject*,FXSelector,void*);
00246 long onClipboardGained(FXObject*,FXSelector,void*);
00247 long onClipboardRequest(FXObject*,FXSelector,void*);
00248 long onAutoScroll(FXObject*,FXSelector,void*);
00249 long onCommand(FXObject*,FXSelector,void*);
00250 long onClicked(FXObject*,FXSelector,void*);
00251 long onDoubleClicked(FXObject*,FXSelector,void*);
00252 long onTripleClicked(FXObject*,FXSelector,void*);
00253
00254
00255 long onCmdHorzGrid(FXObject*,FXSelector,void*);
00256 long onUpdHorzGrid(FXObject*,FXSelector,void*);
00257 long onCmdVertGrid(FXObject*,FXSelector,void*);
00258 long onUpdVertGrid(FXObject*,FXSelector,void*);
00259
00260
00261 long onCmdDeleteColumn(FXObject*,FXSelector,void*);
00262 long onUpdDeleteColumn(FXObject*,FXSelector,void*);
00263 long onCmdDeleteRow(FXObject*,FXSelector,void*);
00264 long onUpdDeleteRow(FXObject*,FXSelector,void*);
00265 long onCmdInsertColumn(FXObject*,FXSelector,void*);
00266 long onCmdInsertRow(FXObject*,FXSelector,void*);
00267
00268
00269 long onCmdMoveRight(FXObject*,FXSelector,void*);
00270 long onCmdMoveLeft(FXObject*,FXSelector,void*);
00271 long onCmdMoveUp(FXObject*,FXSelector,void*);
00272 long onCmdMoveDown(FXObject*,FXSelector,void*);
00273 long onCmdMoveHome(FXObject*,FXSelector,void*);
00274 long onCmdMoveEnd(FXObject*,FXSelector,void*);
00275 long onCmdMoveTop(FXObject*,FXSelector,void*);
00276 long onCmdMoveBottom(FXObject*,FXSelector,void*);
00277 long onCmdMovePageDown(FXObject*,FXSelector,void*);
00278 long onCmdMovePageUp(FXObject*,FXSelector,void*);
00279
00280
00281 long onCmdMark(FXObject*,FXSelector,void*);
00282 long onCmdExtend(FXObject*,FXSelector,void*);
00283
00284
00285 long onCmdSelectCell(FXObject*,FXSelector,void*);
00286 long onCmdSelectRow(FXObject*,FXSelector,void*);
00287 long onCmdSelectColumn(FXObject*,FXSelector,void*);
00288 long onCmdSelectRowIndex(FXObject*,FXSelector,void*);
00289 long onCmdSelectColumnIndex(FXObject*,FXSelector,void*);
00290 long onCmdSelectAll(FXObject*,FXSelector,void*);
00291 long onCmdDeselectAll(FXObject*,FXSelector,void*);
00292
00293 public:
00294
00295 enum {
00296 ID_HORZ_GRID=FXScrollArea::ID_LAST,
00297 ID_VERT_GRID,
00298 ID_DELETE_COLUMN,
00299 ID_DELETE_ROW,
00300 ID_INSERT_COLUMN,
00301 ID_INSERT_ROW,
00302 ID_SELECT_COLUMN_INDEX,
00303 ID_SELECT_ROW_INDEX,
00304 ID_SELECT_COLUMN,
00305 ID_SELECT_ROW,
00306 ID_SELECT_CELL,
00307 ID_SELECT_ALL,
00308 ID_DESELECT_ALL,
00309 ID_MOVE_LEFT,
00310 ID_MOVE_RIGHT,
00311 ID_MOVE_UP,
00312 ID_MOVE_DOWN,
00313 ID_MOVE_HOME,
00314 ID_MOVE_END,
00315 ID_MOVE_TOP,
00316 ID_MOVE_BOTTOM,
00317 ID_MOVE_PAGEDOWN,
00318 ID_MOVE_PAGEUP,
00319 ID_MARK,
00320 ID_EXTEND,
00321 ID_CUT_SEL,
00322 ID_COPY_SEL,
00323 ID_PASTE_SEL,
00324 ID_BLINK,
00325 ID_LAST
00326 };
00327
00328 public:
00329
00330
00331
00332
00333
00334
00335 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);
00336
00337
00338 virtual void create();
00339
00340
00341 virtual void detach();
00342
00343
00344 virtual void layout();
00345
00346
00347 virtual void recalc();
00348
00349
00350 virtual FXbool canFocus() const;
00351
00352
00353 virtual void setFocus();
00354
00355
00356 virtual void killFocus();
00357
00358
00359 FXHeader* getColumnHeader() const { return colHeader; }
00360
00361
00362 FXHeader* getRowHeader() const { return rowHeader; }
00363
00364
00365 void setVisibleRows(FXint nvrows);
00366 FXint getVisibleRows() const { return visiblerows; }
00367 void setVisibleColumns(FXint nvcols);
00368 FXint getVisibleColumns() const { return visiblecols; }
00369
00370
00371 void showHorzGrid(FXbool on=TRUE);
00372
00373
00374 FXbool isHorzGridShown() const { return hgrid; }
00375
00376
00377 void showVertGrid(FXbool on=TRUE);
00378
00379
00380 FXbool isVertGridShown() const { return vgrid; }
00381
00382
00383 virtual FXint getDefaultWidth();
00384
00385
00386 virtual FXint getDefaultHeight();
00387
00388
00389 virtual FXint getContentWidth();
00390 virtual FXint getContentHeight();
00391
00392
00393 virtual void setTableSize(FXint nr,FXint nc,FXbool notify=FALSE);
00394
00395
00396 FXint getNumRows() const { return nrows; }
00397
00398
00399 FXint getNumColumns() const { return ncols; }
00400
00401
00402 void setMarginTop(FXint pt);
00403
00404
00405 FXint getMarginTop() const { return margintop; }
00406
00407
00408 void setMarginBottom(FXint pb);
00409
00410
00411 FXint getMarginBottom() const { return marginbottom; }
00412
00413
00414 void setMarginLeft(FXint pl);
00415
00416
00417 FXint getMarginLeft() const { return marginleft; }
00418
00419
00420 void setMarginRight(FXint pr);
00421
00422
00423 FXint getMarginRight() const { return marginright; }
00424
00425
00426 FXuint getTableStyle() const;
00427 void setTableStyle(FXuint style);
00428
00429
00430
00431
00432
00433
00434 FXint rowAtY(FXint y) const;
00435
00436
00437
00438
00439
00440
00441 FXint colAtX(FXint x) const;
00442
00443
00444 FXTableItem *getItem(FXint row,FXint col) const;
00445
00446
00447 void setItem(FXint row,FXint col,FXTableItem* item,FXbool notify=FALSE);
00448
00449
00450 virtual void insertRows(FXint row,FXint nr=1,FXbool notify=FALSE);
00451
00452
00453 virtual void insertColumns(FXint col,FXint nc=1,FXbool notify=FALSE);
00454
00455
00456 virtual void removeRows(FXint row,FXint nr=1,FXbool notify=FALSE);
00457
00458
00459 virtual void removeColumns(FXint col,FXint nc=1,FXbool notify=FALSE);
00460
00461
00462 virtual void removeItem(FXint row,FXint col,FXbool notify=FALSE);
00463
00464
00465 virtual void clearItems(FXbool notify=FALSE);
00466
00467
00468 void makePositionVisible(FXint r,FXint c);
00469
00470
00471 virtual void setColumnWidth(FXint col,FXint cwidth);
00472 FXint getColumnWidth(FXint col) const;
00473
00474
00475 virtual void setRowHeight(FXint row,FXint rheight);
00476 FXint getRowHeight(FXint row) const;
00477
00478
00479 virtual void setColumnX(FXint col,FXint x);
00480 FXint getColumnX(FXint col) const;
00481
00482
00483 virtual void setRowY(FXint row,FXint y);
00484 FXint getRowY(FXint row) const;
00485
00486
00487 void setDefColumnWidth(FXint cwidth);
00488 FXint getDefColumnWidth() const { return defColWidth; }
00489
00490
00491 void setDefRowHeight(FXint rheight);
00492 FXint getDefRowHeight() const { return defRowHeight; }
00493
00494
00495 FXint getMinRowHeight(FXint r) const;
00496
00497
00498 FXint getMinColumnWidth(FXint c) const;
00499
00500
00501 void setColumnText(FXint index,const FXString& text);
00502
00503
00504 FXString getColumnText(FXint index) const;
00505
00506
00507 void setRowText(FXint index,const FXString& text);
00508
00509
00510 FXString getRowText(FXint index) const;
00511
00512
00513 void setItemText(FXint r,FXint c,const FXString& text);
00514 FXString getItemText(FXint r,FXint c) const;
00515
00516
00517 void setItemIcon(FXint r,FXint c,FXIcon* icon);
00518 FXIcon* getItemIcon(FXint r,FXint c) const;
00519
00520
00521 void setItemData(FXint r,FXint c,void* ptr);
00522 void* getItemData(FXint r,FXint c) const;
00523
00524
00525 FXbool isItemSelected(FXint r,FXint c) const;
00526 FXbool isItemCurrent(FXint r,FXint c) const;
00527 FXbool isItemVisible(FXint r,FXint c) const;
00528 FXbool isItemEnabled(FXint r,FXint c) const;
00529
00530
00531 FXbool isItemSpanning(FXint r,FXint c) const;
00532
00533
00534 void updateRange(FXint sr,FXint er,FXint sc,FXint ec) const;
00535
00536
00537 void updateItem(FXint r,FXint c) const;
00538
00539
00540 FXbool enableItem(FXint r,FXint c);
00541
00542
00543 FXbool disableItem(FXint r,FXint c);
00544
00545
00546 virtual FXbool selectItem(FXint r,FXint c,FXbool notify=FALSE);
00547
00548
00549 virtual FXbool deselectItem(FXint r,FXint c,FXbool notify=FALSE);
00550
00551
00552 virtual FXbool toggleItem(FXint r,FXint c,FXbool notify=FALSE);
00553
00554
00555 void setItemJustify(FXint r,FXint c,FXuint justify);
00556
00557
00558 FXuint getItemJustify(FXint r,FXint c) const;
00559
00560
00561 void setItemIconPosition(FXint r,FXint c,FXuint mode);
00562
00563
00564 FXuint getItemIconPosition(FXint r,FXint c) const;
00565
00566
00567 void setItemBorders(FXint r,FXint c,FXuint borders);
00568
00569
00570 FXuint getItemBorders(FXint r,FXint c) const;
00571
00572
00573 void setItemStipple(FXint r,FXint c,FXStipplePattern pat);
00574
00575
00576 FXStipplePattern getItemStipple(FXint r,FXint c) const;
00577
00578
00579 virtual void setCurrentItem(FXint r,FXint c,FXbool notify=FALSE);
00580
00581
00582 FXint getCurrentRow() const { return current.row; }
00583
00584
00585 FXint getCurrentColumn() const { return current.col; }
00586
00587
00588 void setAnchorItem(FXint r,FXint c);
00589
00590
00591 FXint getAnchorRow() const { return anchor.row; }
00592
00593
00594 FXint getAnchorColumn() const { return anchor.col; }
00595
00596
00597 FXint getSelStartRow() const { return selection.fm.row; }
00598
00599
00600 FXint getSelStartColumn() const { return selection.fm.col; }
00601
00602
00603 FXint getSelEndRow() const { return selection.to.row; }
00604
00605
00606 FXint getSelEndColumn() const { return selection.to.col; }
00607
00608
00609 virtual FXbool selectRange(FXint sr,FXint er,FXint sc,FXint ec,FXbool notify=FALSE);
00610
00611
00612 virtual FXbool extendSelection(FXint r,FXint c,FXbool notify=FALSE);
00613
00614
00615 virtual FXbool killSelection(FXbool notify=FALSE);
00616
00617
00618 void setFont(FXFont* fnt);
00619 FXFont* getFont() const { return font; }
00620
00621
00622 FXColor getTextColor() const { return textColor; }
00623 FXColor getBaseColor() const { return baseColor; }
00624 FXColor getHiliteColor() const { return hiliteColor; }
00625 FXColor getShadowColor() const { return shadowColor; }
00626 FXColor getBorderColor() const { return borderColor; }
00627 FXColor getSelBackColor() const { return selbackColor; }
00628 FXColor getSelTextColor() const { return seltextColor; }
00629 FXColor getGridColor() const { return gridColor; }
00630 FXColor getStippleColor() const { return stippleColor; }
00631 FXColor getCellBorderColor() const { return cellBorderColor; }
00632
00633
00634 void setTextColor(FXColor clr);
00635 void setBaseColor(FXColor clr);
00636 void setHiliteColor(FXColor clr);
00637 void setShadowColor(FXColor clr);
00638 void setBorderColor(FXColor clr);
00639 void setSelBackColor(FXColor clr);
00640 void setSelTextColor(FXColor clr);
00641 void setGridColor(FXColor clr);
00642 void setStippleColor(FXColor clr);
00643 void setCellBorderColor(FXColor clr);
00644
00645
00646 void setCellColor(FXint r,FXint c,FXColor clr);
00647
00648
00649 FXColor getCellColor(FXint r,FXint c) const;
00650
00651
00652 void setCellBorderWidth(FXint borderwidth);
00653
00654
00655 FXint getCellBorderWidth() const { return cellBorderWidth; }
00656
00657
00658 void setHelpText(const FXString& text);
00659 FXString getHelpText() const { return help; }
00660
00661
00662 virtual void save(FXStream& store) const;
00663 virtual void load(FXStream& store);
00664
00665 virtual ~FXTable();
00666 };
00667
00668 }
00669
00670 #endif