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 
11 #ifndef _WX_GTK_DVRENDERERS_H_
12 #define _WX_GTK_DVRENDERERS_H_
13 
14 #ifdef __WXGTK3__
15     typedef struct _cairo_rectangle_int cairo_rectangle_int_t;
16     typedef cairo_rectangle_int_t GdkRectangle;
17 #else
18     typedef struct _GdkRectangle GdkRectangle;
19 #endif
20 
21 // ---------------------------------------------------------
22 // wxDataViewTextRenderer
23 // ---------------------------------------------------------
24 
25 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
26 {
27 public:
GetDefaultType()28     static wxString GetDefaultType() { return wxS("string"); }
29 
30     wxDataViewTextRenderer( const wxString &varianttype = GetDefaultType(),
31                             wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
32                             int align = wxDVR_DEFAULT_ALIGNMENT );
33 
34 #if wxUSE_MARKUP
35     void EnableMarkup(bool enable = true);
36 #endif // wxUSE_MARKUP
37 
SetValue(const wxVariant & value)38     virtual bool SetValue( const wxVariant &value ) wxOVERRIDE
39     {
40         return SetTextValue(value);
41     }
42 
GetValue(wxVariant & value)43     virtual bool GetValue( wxVariant &value ) const wxOVERRIDE
44     {
45         wxString str;
46         if ( !GetTextValue(str) )
47             return false;
48 
49         value = str;
50 
51         return true;
52     }
53 
54     virtual void GtkUpdateAlignment() wxOVERRIDE;
55 
56     virtual GtkCellRendererText *GtkGetTextRenderer() const wxOVERRIDE;
57 
58 protected:
59     virtual void SetAttr(const wxDataViewItemAttr& attr) wxOVERRIDE;
60 
61     // implementation of Set/GetValue()
62     bool SetTextValue(const wxString& str);
63     bool GetTextValue(wxString& str) const;
64 
65     // Return the name of the GtkCellRendererText property to use: "text" or
66     // "markup".
67     const char* GetTextPropertyName() const;
68 
69 #if wxUSE_MARKUP
70     // True if we should interpret markup in our text.
71     bool m_useMarkup;
72 #endif // wxUSE_MARKUP
73 
74     wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer);
75 };
76 
77 // ---------------------------------------------------------
78 // wxDataViewBitmapRenderer
79 // ---------------------------------------------------------
80 
81 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
82 {
83 public:
GetDefaultType()84     static wxString GetDefaultType() { return wxS("wxBitmap"); }
85 
86     wxDataViewBitmapRenderer( const wxString &varianttype = GetDefaultType(),
87                               wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
88                               int align = wxDVR_DEFAULT_ALIGNMENT );
89 
90     bool SetValue( const wxVariant &value ) wxOVERRIDE;
91     bool GetValue( wxVariant &value ) const wxOVERRIDE;
92 
93 protected:
94     wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer);
95 };
96 
97 // ---------------------------------------------------------
98 // wxDataViewToggleRenderer
99 // ---------------------------------------------------------
100 
101 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
102 {
103 public:
GetDefaultType()104     static wxString GetDefaultType() { return wxS("bool"); }
105 
106     wxDataViewToggleRenderer( const wxString &varianttype = GetDefaultType(),
107                               wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
108                               int align = wxDVR_DEFAULT_ALIGNMENT );
109 
110     void ShowAsRadio();
111 
112     bool SetValue( const wxVariant &value ) wxOVERRIDE;
113     bool GetValue( wxVariant &value ) const wxOVERRIDE;
114 
115 protected:
116     wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer);
117 };
118 
119 // ---------------------------------------------------------
120 // wxDataViewCustomRenderer
121 // ---------------------------------------------------------
122 
123 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewCustomRendererBase
124 {
125 public:
GetDefaultType()126     static wxString GetDefaultType() { return wxS("string"); }
127 
128     wxDataViewCustomRenderer( const wxString &varianttype = GetDefaultType(),
129                               wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
130                               int align = wxDVR_DEFAULT_ALIGNMENT,
131                               bool no_init = false );
132     virtual ~wxDataViewCustomRenderer();
133 
134 
135     // Create DC on request
136     virtual wxDC *GetDC() wxOVERRIDE;
137 
138     // override the base class function to use GTK text cell renderer
139     virtual void RenderText(const wxString& text,
140                             int xoffset,
141                             wxRect cell,
142                             wxDC *dc,
143                             int state) wxOVERRIDE;
144 
145     struct GTKRenderParams;
146 
147     // store GTK render call parameters for possible later use
GTKSetRenderParams(GTKRenderParams * renderParams)148     void GTKSetRenderParams(GTKRenderParams* renderParams)
149     {
150         m_renderParams = renderParams;
151     }
152 
153     virtual GtkCellRendererText *GtkGetTextRenderer() const wxOVERRIDE;
154     virtual GtkWidget* GtkGetEditorWidget() const wxOVERRIDE;
155 
156     virtual void GtkUpdateAlignment() wxOVERRIDE;
157 
158 private:
159     bool Init(wxDataViewCellMode mode, int align);
160 
161     // Called from GtkGetTextRenderer() to really create the renderer if
162     // necessary.
163     void GtkInitTextRenderer();
164 
165     wxDC        *m_dc;
166 
167     GtkCellRendererText      *m_text_renderer;
168 
169     // parameters of the original render() call stored so that we could pass
170     // them forward to m_text_renderer if our RenderText() is called
171     GTKRenderParams* m_renderParams;
172 
173     wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer);
174 };
175 
176 // ---------------------------------------------------------
177 // wxDataViewProgressRenderer
178 // ---------------------------------------------------------
179 
180 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
181 {
182 public:
GetDefaultType()183     static wxString GetDefaultType() { return wxS("long"); }
184 
185     wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
186                                 const wxString &varianttype = GetDefaultType(),
187                                 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
188                                 int align = wxDVR_DEFAULT_ALIGNMENT );
189     virtual ~wxDataViewProgressRenderer();
190 
191     bool SetValue( const wxVariant &value ) wxOVERRIDE;
192     bool GetValue( wxVariant &value ) const wxOVERRIDE;
193 
194     virtual bool Render( wxRect cell, wxDC *dc, int state ) wxOVERRIDE;
195     virtual wxSize GetSize() const wxOVERRIDE;
196 
197 private:
198     void GTKSetLabel();
199 
200     wxString    m_label;
201     int         m_value;
202 
203 #if !wxUSE_UNICODE
204     // Flag used to indicate that we need to set the label because we were
205     // unable to do it in the ctor (see comments there).
206     bool m_needsToSetLabel;
207 #endif // !wxUSE_UNICODE
208 
209 protected:
210     wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer);
211 };
212 
213 // ---------------------------------------------------------
214 // wxDataViewIconTextRenderer
215 // ---------------------------------------------------------
216 
217 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
218 {
219 public:
GetDefaultType()220     static wxString GetDefaultType() { return wxS("wxDataViewIconText"); }
221 
222     wxDataViewIconTextRenderer( const wxString &varianttype = GetDefaultType(),
223                                 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
224                                 int align = wxDVR_DEFAULT_ALIGNMENT );
225     virtual ~wxDataViewIconTextRenderer();
226 
227     bool SetValue( const wxVariant &value ) wxOVERRIDE;
228     bool GetValue( wxVariant &value ) const wxOVERRIDE;
229 
230     virtual void GtkPackIntoColumn(GtkTreeViewColumn *column) wxOVERRIDE;
231 
232 protected:
233     virtual wxVariant GtkGetValueFromString(const wxString& str) const wxOVERRIDE;
234 
235 private:
236     wxDataViewIconText   m_value;
237 
238     // we use the base class m_renderer for the text and this one for the icon
239     GtkCellRenderer *m_rendererIcon;
240 
241     wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer);
242 };
243 
244 // -------------------------------------
245 // wxDataViewChoiceRenderer
246 // -------------------------------------
247 
248 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
249 {
250 public:
251     wxDataViewChoiceRenderer(const wxArrayString &choices,
252                              wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
253                              int alignment = wxDVR_DEFAULT_ALIGNMENT );
254     virtual bool Render( wxRect rect, wxDC *dc, int state ) wxOVERRIDE;
255     virtual wxSize GetSize() const wxOVERRIDE;
256     virtual bool SetValue( const wxVariant &value ) wxOVERRIDE;
257     virtual bool GetValue( wxVariant &value ) const wxOVERRIDE;
258 
259     virtual void GtkUpdateAlignment() wxOVERRIDE;
260 
GetChoice(size_t index)261     wxString GetChoice(size_t index) const { return m_choices[index]; }
GetChoices()262     const wxArrayString& GetChoices() const { return m_choices; }
263 
264 private:
265     wxArrayString m_choices;
266     wxString      m_data;
267 };
268 
269 // ----------------------------------------------------------------------------
270 // wxDataViewChoiceByIndexRenderer
271 // ----------------------------------------------------------------------------
272 
273 class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer: public wxDataViewChoiceRenderer
274 {
275 public:
276     wxDataViewChoiceByIndexRenderer( const wxArrayString &choices,
277                               wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
278                               int alignment = wxDVR_DEFAULT_ALIGNMENT );
279 
280     virtual bool SetValue( const wxVariant &value ) wxOVERRIDE;
281     virtual bool GetValue( wxVariant &value ) const wxOVERRIDE;
282 
283 private:
284     virtual wxVariant GtkGetValueFromString(const wxString& str) const wxOVERRIDE;
285 };
286 
287 
288 
289 #endif // _WX_GTK_DVRENDERERS_H_
290 
291