dvrenderers.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk/dvrenderers.h
  3. // Purpose: All GTK wxDataViewCtrl renderer classes
  4. // Author: Robert Roebling, Vadim Zeitlin
  5. // Created: 2009-11-07 (extracted from wx/gtk/dataview.h)
  6. // Copyright: (c) 2006 Robert Roebling
  7. // (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GTK_DVRENDERERS_H_
  11. #define _WX_GTK_DVRENDERERS_H_
  12. #ifdef __WXGTK3__
  13. typedef struct _cairo_rectangle_int cairo_rectangle_int_t;
  14. typedef cairo_rectangle_int_t GdkRectangle;
  15. #else
  16. typedef struct _GdkRectangle GdkRectangle;
  17. #endif
  18. // ---------------------------------------------------------
  19. // wxDataViewTextRenderer
  20. // ---------------------------------------------------------
  21. class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
  22. {
  23. public:
  24. wxDataViewTextRenderer( const wxString &varianttype = "string",
  25. wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
  26. int align = wxDVR_DEFAULT_ALIGNMENT );
  27. virtual bool SetValue( const wxVariant &value )
  28. {
  29. return SetTextValue(value);
  30. }
  31. virtual bool GetValue( wxVariant &value ) const
  32. {
  33. wxString str;
  34. if ( !GetTextValue(str) )
  35. return false;
  36. value = str;
  37. return true;
  38. }
  39. virtual void SetAlignment( int align );
  40. virtual bool GtkSupportsAttrs() const { return true; }
  41. virtual bool GtkSetAttr(const wxDataViewItemAttr& attr);
  42. virtual GtkCellRendererText *GtkGetTextRenderer() const;
  43. protected:
  44. // implementation of Set/GetValue()
  45. bool SetTextValue(const wxString& str);
  46. bool GetTextValue(wxString& str) const;
  47. DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
  48. };
  49. // ---------------------------------------------------------
  50. // wxDataViewBitmapRenderer
  51. // ---------------------------------------------------------
  52. class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
  53. {
  54. public:
  55. wxDataViewBitmapRenderer( const wxString &varianttype = "wxBitmap",
  56. wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
  57. int align = wxDVR_DEFAULT_ALIGNMENT );
  58. bool SetValue( const wxVariant &value );
  59. bool GetValue( wxVariant &value ) const;
  60. protected:
  61. DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
  62. };
  63. // ---------------------------------------------------------
  64. // wxDataViewToggleRenderer
  65. // ---------------------------------------------------------
  66. class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
  67. {
  68. public:
  69. wxDataViewToggleRenderer( const wxString &varianttype = "bool",
  70. wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
  71. int align = wxDVR_DEFAULT_ALIGNMENT );
  72. bool SetValue( const wxVariant &value );
  73. bool GetValue( wxVariant &value ) const;
  74. protected:
  75. DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
  76. };
  77. // ---------------------------------------------------------
  78. // wxDataViewCustomRenderer
  79. // ---------------------------------------------------------
  80. class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewCustomRendererBase
  81. {
  82. public:
  83. wxDataViewCustomRenderer( const wxString &varianttype = "string",
  84. wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
  85. int align = wxDVR_DEFAULT_ALIGNMENT,
  86. bool no_init = false );
  87. virtual ~wxDataViewCustomRenderer();
  88. // Create DC on request
  89. virtual wxDC *GetDC();
  90. // override the base class function to use GTK text cell renderer
  91. virtual void RenderText(const wxString& text,
  92. int xoffset,
  93. wxRect cell,
  94. wxDC *dc,
  95. int state);
  96. struct GTKRenderParams;
  97. // store GTK render call parameters for possible later use
  98. void GTKSetRenderParams(GTKRenderParams* renderParams)
  99. {
  100. m_renderParams = renderParams;
  101. }
  102. // we may or not support attributes, as we don't know it, return true to
  103. // make it possible to use them
  104. virtual bool GtkSupportsAttrs() const { return true; }
  105. virtual bool GtkSetAttr(const wxDataViewItemAttr& attr)
  106. {
  107. SetAttr(attr);
  108. return !attr.IsDefault();
  109. }
  110. virtual GtkCellRendererText *GtkGetTextRenderer() const;
  111. private:
  112. bool Init(wxDataViewCellMode mode, int align);
  113. // Called from GtkGetTextRenderer() to really create the renderer if
  114. // necessary.
  115. void GtkInitTextRenderer();
  116. wxDC *m_dc;
  117. GtkCellRendererText *m_text_renderer;
  118. // parameters of the original render() call stored so that we could pass
  119. // them forward to m_text_renderer if our RenderText() is called
  120. GTKRenderParams* m_renderParams;
  121. DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
  122. };
  123. // ---------------------------------------------------------
  124. // wxDataViewProgressRenderer
  125. // ---------------------------------------------------------
  126. class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
  127. {
  128. public:
  129. wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
  130. const wxString &varianttype = "long",
  131. wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
  132. int align = wxDVR_DEFAULT_ALIGNMENT );
  133. virtual ~wxDataViewProgressRenderer();
  134. bool SetValue( const wxVariant &value );
  135. bool GetValue( wxVariant &value ) const;
  136. virtual bool Render( wxRect cell, wxDC *dc, int state );
  137. virtual wxSize GetSize() const;
  138. private:
  139. void GTKSetLabel();
  140. wxString m_label;
  141. int m_value;
  142. #if !wxUSE_UNICODE
  143. // Flag used to indicate that we need to set the label because we were
  144. // unable to do it in the ctor (see comments there).
  145. bool m_needsToSetLabel;
  146. #endif // !wxUSE_UNICODE
  147. protected:
  148. DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
  149. };
  150. // ---------------------------------------------------------
  151. // wxDataViewIconTextRenderer
  152. // ---------------------------------------------------------
  153. class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
  154. {
  155. public:
  156. wxDataViewIconTextRenderer( const wxString &varianttype = "wxDataViewIconText",
  157. wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
  158. int align = wxDVR_DEFAULT_ALIGNMENT );
  159. virtual ~wxDataViewIconTextRenderer();
  160. bool SetValue( const wxVariant &value );
  161. bool GetValue( wxVariant &value ) const;
  162. virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
  163. protected:
  164. virtual void GtkOnCellChanged(const wxVariant& value,
  165. const wxDataViewItem& item,
  166. unsigned col);
  167. private:
  168. wxDataViewIconText m_value;
  169. // we use the base class m_renderer for the text and this one for the icon
  170. GtkCellRenderer *m_rendererIcon;
  171. DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
  172. };
  173. // -------------------------------------
  174. // wxDataViewChoiceRenderer
  175. // -------------------------------------
  176. class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
  177. {
  178. public:
  179. wxDataViewChoiceRenderer(const wxArrayString &choices,
  180. wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
  181. int alignment = wxDVR_DEFAULT_ALIGNMENT );
  182. virtual bool Render( wxRect rect, wxDC *dc, int state );
  183. virtual wxSize GetSize() const;
  184. virtual bool SetValue( const wxVariant &value );
  185. virtual bool GetValue( wxVariant &value ) const;
  186. void SetAlignment( int align );
  187. wxString GetChoice(size_t index) const { return m_choices[index]; }
  188. const wxArrayString& GetChoices() const { return m_choices; }
  189. private:
  190. wxArrayString m_choices;
  191. wxString m_data;
  192. };
  193. // ----------------------------------------------------------------------------
  194. // wxDataViewChoiceByIndexRenderer
  195. // ----------------------------------------------------------------------------
  196. class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer: public wxDataViewChoiceRenderer
  197. {
  198. public:
  199. wxDataViewChoiceByIndexRenderer( const wxArrayString &choices,
  200. wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
  201. int alignment = wxDVR_DEFAULT_ALIGNMENT );
  202. virtual bool SetValue( const wxVariant &value );
  203. virtual bool GetValue( wxVariant &value ) const;
  204. private:
  205. virtual void GtkOnTextEdited(const char *itempath, const wxString& str);
  206. };
  207. #endif // _WX_GTK_DVRENDERERS_H_