You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

304 lines
8.6KB

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