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