gridctrl.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. ///////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/gridctrl.h
  3. // Purpose: wxGrid controls
  4. // Author: Paul Gammans, Roger Gammans
  5. // Modified by:
  6. // Created: 11/04/2001
  7. // Copyright: (c) The Computer Surgery (paul@compsurg.co.uk)
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GENERIC_GRIDCTRL_H_
  11. #define _WX_GENERIC_GRIDCTRL_H_
  12. #include "wx/grid.h"
  13. #if wxUSE_GRID
  14. #define wxGRID_VALUE_CHOICEINT wxT("choiceint")
  15. #define wxGRID_VALUE_DATETIME wxT("datetime")
  16. // the default renderer for the cells containing string data
  17. class WXDLLIMPEXP_ADV wxGridCellStringRenderer : public wxGridCellRenderer
  18. {
  19. public:
  20. // draw the string
  21. virtual void Draw(wxGrid& grid,
  22. wxGridCellAttr& attr,
  23. wxDC& dc,
  24. const wxRect& rect,
  25. int row, int col,
  26. bool isSelected);
  27. // return the string extent
  28. virtual wxSize GetBestSize(wxGrid& grid,
  29. wxGridCellAttr& attr,
  30. wxDC& dc,
  31. int row, int col);
  32. virtual wxGridCellRenderer *Clone() const
  33. { return new wxGridCellStringRenderer; }
  34. protected:
  35. // set the text colours before drawing
  36. void SetTextColoursAndFont(const wxGrid& grid,
  37. const wxGridCellAttr& attr,
  38. wxDC& dc,
  39. bool isSelected);
  40. // calc the string extent for given string/font
  41. wxSize DoGetBestSize(const wxGridCellAttr& attr,
  42. wxDC& dc,
  43. const wxString& text);
  44. };
  45. // the default renderer for the cells containing numeric (long) data
  46. class WXDLLIMPEXP_ADV wxGridCellNumberRenderer : public wxGridCellStringRenderer
  47. {
  48. public:
  49. // draw the string right aligned
  50. virtual void Draw(wxGrid& grid,
  51. wxGridCellAttr& attr,
  52. wxDC& dc,
  53. const wxRect& rect,
  54. int row, int col,
  55. bool isSelected);
  56. virtual wxSize GetBestSize(wxGrid& grid,
  57. wxGridCellAttr& attr,
  58. wxDC& dc,
  59. int row, int col);
  60. virtual wxGridCellRenderer *Clone() const
  61. { return new wxGridCellNumberRenderer; }
  62. protected:
  63. wxString GetString(const wxGrid& grid, int row, int col);
  64. };
  65. class WXDLLIMPEXP_ADV wxGridCellFloatRenderer : public wxGridCellStringRenderer
  66. {
  67. public:
  68. wxGridCellFloatRenderer(int width = -1,
  69. int precision = -1,
  70. int format = wxGRID_FLOAT_FORMAT_DEFAULT);
  71. // get/change formatting parameters
  72. int GetWidth() const { return m_width; }
  73. void SetWidth(int width) { m_width = width; m_format.clear(); }
  74. int GetPrecision() const { return m_precision; }
  75. void SetPrecision(int precision) { m_precision = precision; m_format.clear(); }
  76. int GetFormat() const { return m_style; }
  77. void SetFormat(int format) { m_style = format; m_format.clear(); }
  78. // draw the string right aligned with given width/precision
  79. virtual void Draw(wxGrid& grid,
  80. wxGridCellAttr& attr,
  81. wxDC& dc,
  82. const wxRect& rect,
  83. int row, int col,
  84. bool isSelected);
  85. virtual wxSize GetBestSize(wxGrid& grid,
  86. wxGridCellAttr& attr,
  87. wxDC& dc,
  88. int row, int col);
  89. // parameters string format is "width[,precision[,format]]"
  90. // with format being one of f|e|g|E|F|G
  91. virtual void SetParameters(const wxString& params);
  92. virtual wxGridCellRenderer *Clone() const;
  93. protected:
  94. wxString GetString(const wxGrid& grid, int row, int col);
  95. private:
  96. // formatting parameters
  97. int m_width,
  98. m_precision;
  99. int m_style;
  100. wxString m_format;
  101. };
  102. // renderer for boolean fields
  103. class WXDLLIMPEXP_ADV wxGridCellBoolRenderer : public wxGridCellRenderer
  104. {
  105. public:
  106. // draw a check mark or nothing
  107. virtual void Draw(wxGrid& grid,
  108. wxGridCellAttr& attr,
  109. wxDC& dc,
  110. const wxRect& rect,
  111. int row, int col,
  112. bool isSelected);
  113. // return the checkmark size
  114. virtual wxSize GetBestSize(wxGrid& grid,
  115. wxGridCellAttr& attr,
  116. wxDC& dc,
  117. int row, int col);
  118. virtual wxGridCellRenderer *Clone() const
  119. { return new wxGridCellBoolRenderer; }
  120. private:
  121. static wxSize ms_sizeCheckMark;
  122. };
  123. #if wxUSE_DATETIME
  124. #include "wx/datetime.h"
  125. // the default renderer for the cells containing times and dates
  126. class WXDLLIMPEXP_ADV wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
  127. {
  128. public:
  129. wxGridCellDateTimeRenderer(const wxString& outformat = wxDefaultDateTimeFormat,
  130. const wxString& informat = wxDefaultDateTimeFormat);
  131. // draw the string right aligned
  132. virtual void Draw(wxGrid& grid,
  133. wxGridCellAttr& attr,
  134. wxDC& dc,
  135. const wxRect& rect,
  136. int row, int col,
  137. bool isSelected);
  138. virtual wxSize GetBestSize(wxGrid& grid,
  139. wxGridCellAttr& attr,
  140. wxDC& dc,
  141. int row, int col);
  142. virtual wxGridCellRenderer *Clone() const;
  143. // output strptime()-like format string
  144. virtual void SetParameters(const wxString& params);
  145. protected:
  146. wxString GetString(const wxGrid& grid, int row, int col);
  147. wxString m_iformat;
  148. wxString m_oformat;
  149. wxDateTime m_dateDef;
  150. wxDateTime::TimeZone m_tz;
  151. };
  152. #endif // wxUSE_DATETIME
  153. // renders a number using the corresponding text string
  154. class WXDLLIMPEXP_ADV wxGridCellEnumRenderer : public wxGridCellStringRenderer
  155. {
  156. public:
  157. wxGridCellEnumRenderer( const wxString& choices = wxEmptyString );
  158. // draw the string right aligned
  159. virtual void Draw(wxGrid& grid,
  160. wxGridCellAttr& attr,
  161. wxDC& dc,
  162. const wxRect& rect,
  163. int row, int col,
  164. bool isSelected);
  165. virtual wxSize GetBestSize(wxGrid& grid,
  166. wxGridCellAttr& attr,
  167. wxDC& dc,
  168. int row, int col);
  169. virtual wxGridCellRenderer *Clone() const;
  170. // parameters string format is "item1[,item2[...,itemN]]" where itemN will
  171. // be used if the cell value is N-1
  172. virtual void SetParameters(const wxString& params);
  173. protected:
  174. wxString GetString(const wxGrid& grid, int row, int col);
  175. wxArrayString m_choices;
  176. };
  177. class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
  178. {
  179. public:
  180. wxGridCellAutoWrapStringRenderer() : wxGridCellStringRenderer() { }
  181. virtual void Draw(wxGrid& grid,
  182. wxGridCellAttr& attr,
  183. wxDC& dc,
  184. const wxRect& rect,
  185. int row, int col,
  186. bool isSelected);
  187. virtual wxSize GetBestSize(wxGrid& grid,
  188. wxGridCellAttr& attr,
  189. wxDC& dc,
  190. int row, int col);
  191. virtual wxGridCellRenderer *Clone() const
  192. { return new wxGridCellAutoWrapStringRenderer; }
  193. private:
  194. wxArrayString GetTextLines( wxGrid& grid,
  195. wxDC& dc,
  196. const wxGridCellAttr& attr,
  197. const wxRect& rect,
  198. int row, int col);
  199. // Helper methods of GetTextLines()
  200. // Break a single logical line of text into several physical lines, all of
  201. // which are added to the lines array. The lines are broken at maxWidth and
  202. // the dc is used for measuring text extent only.
  203. void BreakLine(wxDC& dc,
  204. const wxString& logicalLine,
  205. wxCoord maxWidth,
  206. wxArrayString& lines);
  207. // Break a word, which is supposed to be wider than maxWidth, into several
  208. // lines, which are added to lines array and the last, incomplete, of which
  209. // is returned in line output parameter.
  210. //
  211. // Returns the width of the last line.
  212. wxCoord BreakWord(wxDC& dc,
  213. const wxString& word,
  214. wxCoord maxWidth,
  215. wxArrayString& lines,
  216. wxString& line);
  217. };
  218. #endif // wxUSE_GRID
  219. #endif // _WX_GENERIC_GRIDCTRL_H_