griddemo.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: griddemo.h
  3. // Purpose: Grid control wxWidgets sample
  4. // Author: Michael Bedward
  5. // Modified by:
  6. // Copyright: (c) Michael Bedward, Julian Smart
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef griddemo_h
  10. #define griddemo_h
  11. class wxGrid;
  12. class GridApp : public wxApp
  13. {
  14. public:
  15. bool OnInit();
  16. };
  17. class GridFrame : public wxFrame
  18. {
  19. wxGrid *grid;
  20. #if wxUSE_LOG
  21. wxTextCtrl *logWin;
  22. wxLogTextCtrl *logger;
  23. #endif // wxUSE_LOG
  24. void SetDefaults();
  25. void ToggleRowLabels( wxCommandEvent& );
  26. void ToggleColLabels( wxCommandEvent& );
  27. void ToggleEditing( wxCommandEvent& );
  28. void ToggleRowSizing( wxCommandEvent& );
  29. void ToggleColSizing( wxCommandEvent& );
  30. void ToggleColMoving( wxCommandEvent& );
  31. void ToggleGridSizing( wxCommandEvent& );
  32. void ToggleGridDragCell ( wxCommandEvent& );
  33. void SetNativeColHeader ( wxCommandEvent& );
  34. void SetCustomColHeader( wxCommandEvent& );
  35. void SetDefaultColHeader( wxCommandEvent& );
  36. void SetTabBehaviour( wxCommandEvent& );
  37. void SetTabCustomHandler( wxCommandEvent& );
  38. void ToggleGridLines( wxCommandEvent& );
  39. void AutoSizeCols( wxCommandEvent& );
  40. void CellOverflow( wxCommandEvent& );
  41. void ResizeCell( wxCommandEvent& );
  42. void SetLabelColour( wxCommandEvent& );
  43. void SetLabelTextColour( wxCommandEvent& );
  44. void SetLabelFont(wxCommandEvent &);
  45. void SetRowLabelHorizAlignment( wxCommandEvent& );
  46. void SetRowLabelVertAlignment( wxCommandEvent& );
  47. void SetColLabelHorizAlignment( wxCommandEvent& );
  48. void SetColLabelVertAlignment( wxCommandEvent& );
  49. void SetGridLineColour( wxCommandEvent& );
  50. void SetCellFgColour(wxCommandEvent &);
  51. void SetCellBgColour(wxCommandEvent &);
  52. void InsertRow( wxCommandEvent& );
  53. void InsertCol( wxCommandEvent& );
  54. void DeleteSelectedRows( wxCommandEvent& );
  55. void DeleteSelectedCols( wxCommandEvent& );
  56. void ClearGrid( wxCommandEvent& );
  57. void SelectCells( wxCommandEvent& );
  58. void SelectRows( wxCommandEvent& );
  59. void SelectCols( wxCommandEvent& );
  60. void SelectRowsOrCols( wxCommandEvent& );
  61. void DeselectCell(wxCommandEvent& event);
  62. void DeselectCol(wxCommandEvent& event);
  63. void DeselectRow(wxCommandEvent& event);
  64. void DeselectAll(wxCommandEvent& event);
  65. void SelectCell(wxCommandEvent& event);
  66. void SelectCol(wxCommandEvent& event);
  67. void SelectRow(wxCommandEvent& event);
  68. void SelectAll(wxCommandEvent& event);
  69. void OnAddToSelectToggle(wxCommandEvent& event);
  70. void AutoSizeRow(wxCommandEvent& event);
  71. void AutoSizeCol(wxCommandEvent& event);
  72. void AutoSizeRowLabel(wxCommandEvent& event);
  73. void AutoSizeColLabel(wxCommandEvent& event);
  74. void AutoSizeLabelsCol(wxCommandEvent& event);
  75. void AutoSizeLabelsRow(wxCommandEvent& event);
  76. void AutoSizeTable(wxCommandEvent& event);
  77. void HideCol(wxCommandEvent& event);
  78. void ShowCol(wxCommandEvent& event);
  79. void HideRow(wxCommandEvent& event);
  80. void ShowRow(wxCommandEvent& event);
  81. void OnLabelLeftClick( wxGridEvent& );
  82. void OnCellLeftClick( wxGridEvent& );
  83. void OnRowSize( wxGridSizeEvent& );
  84. void OnColSize( wxGridSizeEvent& );
  85. void OnColAutoSize( wxGridSizeEvent& );
  86. void OnSelectCell( wxGridEvent& );
  87. void OnRangeSelected( wxGridRangeSelectEvent& );
  88. void OnCellValueChanging( wxGridEvent& );
  89. void OnCellValueChanged( wxGridEvent& );
  90. void OnCellBeginDrag( wxGridEvent& );
  91. void OnEditorShown(wxGridEvent&);
  92. void OnEditorHidden(wxGridEvent&);
  93. void OnSetHighlightWidth(wxCommandEvent&);
  94. void OnSetROHighlightWidth(wxCommandEvent&);
  95. void OnGridCustomTab(wxGridEvent& event);
  96. public:
  97. GridFrame();
  98. ~GridFrame();
  99. void OnQuit( wxCommandEvent& );
  100. void About( wxCommandEvent& );
  101. void OnVTable( wxCommandEvent& );
  102. void OnBugsTable( wxCommandEvent& );
  103. void OnTabularTable( wxCommandEvent& );
  104. void OnGridRender( wxCommandEvent& event );
  105. void OnRenderPaint( wxPaintEvent& event );
  106. enum
  107. {
  108. ID_TOGGLEROWLABELS = 100,
  109. ID_TOGGLECOLLABELS,
  110. ID_TOGGLEEDIT,
  111. ID_TOGGLEROWSIZING,
  112. ID_TOGGLECOLSIZING,
  113. ID_TOGGLECOLMOVING,
  114. ID_TOGGLEGRIDSIZING,
  115. ID_TOGGLEGRIDDRAGCELL,
  116. ID_TOGGLEGRIDLINES,
  117. ID_AUTOSIZECOLS,
  118. ID_CELLOVERFLOW,
  119. ID_HIDECOL,
  120. ID_SHOWCOL,
  121. ID_HIDEROW,
  122. ID_SHOWROW,
  123. ID_RESIZECELL,
  124. ID_SETLABELCOLOUR,
  125. ID_SETLABELTEXTCOLOUR,
  126. ID_SETLABEL_FONT,
  127. ID_ROWLABELALIGN,
  128. ID_ROWLABELHORIZALIGN,
  129. ID_ROWLABELVERTALIGN,
  130. ID_COLLABELALIGN,
  131. ID_COLLABELHORIZALIGN,
  132. ID_COLLABELVERTALIGN,
  133. ID_COLDEFAULTHEADER,
  134. ID_COLNATIVEHEADER,
  135. ID_COLCUSTOMHEADER,
  136. ID_TAB_STOP,
  137. ID_TAB_WRAP,
  138. ID_TAB_LEAVE,
  139. ID_TAB_CUSTOM,
  140. ID_GRIDLINECOLOUR,
  141. ID_INSERTROW,
  142. ID_INSERTCOL,
  143. ID_DELETEROW,
  144. ID_DELETECOL,
  145. ID_CLEARGRID,
  146. ID_CHANGESEL,
  147. ID_SELCELLS,
  148. ID_SELROWS,
  149. ID_SELCOLS,
  150. ID_SELROWSORCOLS,
  151. ID_SET_CELL_FG_COLOUR,
  152. ID_SET_CELL_BG_COLOUR,
  153. ID_VTABLE,
  154. ID_BUGS_TABLE,
  155. ID_TABULAR_TABLE,
  156. ID_SELECT_UNSELECT,
  157. ID_SELECT_ALL,
  158. ID_SELECT_ROW,
  159. ID_SELECT_COL,
  160. ID_SELECT_CELL,
  161. ID_DESELECT_ALL,
  162. ID_DESELECT_ROW,
  163. ID_DESELECT_COL,
  164. ID_DESELECT_CELL,
  165. ID_SIZE_ROW,
  166. ID_SIZE_COL,
  167. ID_SIZE_ROW_LABEL,
  168. ID_SIZE_COL_LABEL,
  169. ID_SIZE_LABELS_COL,
  170. ID_SIZE_LABELS_ROW,
  171. ID_SIZE_GRID,
  172. ID_SET_HIGHLIGHT_WIDTH,
  173. ID_SET_RO_HIGHLIGHT_WIDTH,
  174. ID_TESTFUNC,
  175. ID_RENDER_ROW_LABEL,
  176. ID_RENDER_COL_LABEL,
  177. ID_RENDER_GRID_LINES,
  178. ID_RENDER_GRID_BORDER,
  179. ID_RENDER_SELECT_HLIGHT,
  180. ID_RENDER_LOMETRIC,
  181. ID_RENDER_COORDS,
  182. ID_RENDER_ZOOM,
  183. ID_RENDER_MARGIN,
  184. ID_RENDER_DEFAULT_SIZE,
  185. };
  186. #if wxUSE_LOG
  187. wxLog *m_logOld;
  188. #endif // wxUSE_LOG
  189. // add the cells to selection when using commands from select menu?
  190. bool m_addToSel;
  191. wxBitmap m_gridBitmap;
  192. wxDECLARE_EVENT_TABLE();
  193. };
  194. class MyGridCellRenderer : public wxGridCellStringRenderer
  195. {
  196. public:
  197. virtual void Draw(wxGrid& grid,
  198. wxGridCellAttr& attr,
  199. wxDC& dc,
  200. const wxRect& rect,
  201. int row, int col,
  202. bool isSelected);
  203. };
  204. // ----------------------------------------------------------------------------
  205. // demonstration of virtual table which doesn't store all of its data in
  206. // memory
  207. // ----------------------------------------------------------------------------
  208. class BigGridTable : public wxGridTableBase
  209. {
  210. public:
  211. BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
  212. int GetNumberRows() { return m_sizeGrid; }
  213. int GetNumberCols() { return m_sizeGrid; }
  214. wxString GetValue( int row, int col )
  215. {
  216. return wxString::Format(wxT("(%d, %d)"), row, col);
  217. }
  218. void SetValue( int , int , const wxString& ) { /* ignore */ }
  219. bool IsEmptyCell( int , int ) { return false; }
  220. private:
  221. long m_sizeGrid;
  222. };
  223. class BigGridFrame : public wxFrame
  224. {
  225. public:
  226. BigGridFrame(long sizeGrid);
  227. private:
  228. wxGrid* m_grid;
  229. BigGridTable* m_table;
  230. };
  231. // ----------------------------------------------------------------------------
  232. // an example of custom attr provider: this one makes all odd rows appear grey
  233. // ----------------------------------------------------------------------------
  234. class MyGridCellAttrProvider : public wxGridCellAttrProvider
  235. {
  236. public:
  237. MyGridCellAttrProvider();
  238. virtual ~MyGridCellAttrProvider();
  239. virtual wxGridCellAttr *GetAttr(int row, int col,
  240. wxGridCellAttr::wxAttrKind kind) const;
  241. private:
  242. wxGridCellAttr *m_attrForOddRows;
  243. };
  244. // ----------------------------------------------------------------------------
  245. // another, more realistic, grid example: shows typed columns and more
  246. // ----------------------------------------------------------------------------
  247. class BugsGridTable : public wxGridTableBase
  248. {
  249. public:
  250. BugsGridTable() { }
  251. virtual int GetNumberRows();
  252. virtual int GetNumberCols();
  253. virtual bool IsEmptyCell( int row, int col );
  254. virtual wxString GetValue( int row, int col );
  255. virtual void SetValue( int row, int col, const wxString& value );
  256. virtual wxString GetColLabelValue( int col );
  257. virtual wxString GetTypeName( int row, int col );
  258. virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
  259. virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
  260. virtual long GetValueAsLong( int row, int col );
  261. virtual bool GetValueAsBool( int row, int col );
  262. virtual void SetValueAsLong( int row, int col, long value );
  263. virtual void SetValueAsBool( int row, int col, bool value );
  264. };
  265. class BugsGridFrame : public wxFrame
  266. {
  267. public:
  268. BugsGridFrame();
  269. };
  270. #endif // griddemo_h