Correct text position in wxDataViewCustomRenderer::RenderText() in wxGTK.
[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 // RCS-ID: $Id: wxhead.h,v 1.11 2009-06-29 10:23:04 zeitlin Exp $
7 // Copyright: (c) 2006 Robert Roebling
8 // (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GTK_DVRENDERERS_H_
13 #define _WX_GTK_DVRENDERERS_H_
14
15 typedef struct _GdkRectangle GdkRectangle;
16
17 // ---------------------------------------------------------
18 // wxDataViewTextRenderer
19 // ---------------------------------------------------------
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
28 virtual bool SetValue( const wxVariant &value )
29 {
30 return SetTextValue(value);
31 }
32
33 virtual bool GetValue( wxVariant &value ) const
34 {
35 wxString str;
36 if ( !GetTextValue(str) )
37 return false;
38
39 value = str;
40
41 return true;
42 }
43
44 virtual void SetAlignment( int align );
45
46 virtual bool GtkSupportsAttrs() const { return true; }
47
48 protected:
49 // implementation of Set/GetValue()
50 bool SetTextValue(const wxString& str);
51 bool GetTextValue(wxString& str) const;
52
53
54 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
55 };
56
57 // ---------------------------------------------------------
58 // wxDataViewBitmapRenderer
59 // ---------------------------------------------------------
60
61 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
62 {
63 public:
64 wxDataViewBitmapRenderer( const wxString &varianttype = "wxBitmap",
65 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
66 int align = wxDVR_DEFAULT_ALIGNMENT );
67
68 bool SetValue( const wxVariant &value );
69 bool GetValue( wxVariant &value ) const;
70
71 protected:
72 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
73 };
74
75 // ---------------------------------------------------------
76 // wxDataViewToggleRenderer
77 // ---------------------------------------------------------
78
79 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
80 {
81 public:
82 wxDataViewToggleRenderer( const wxString &varianttype = "bool",
83 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
84 int align = wxDVR_DEFAULT_ALIGNMENT );
85
86 bool SetValue( const wxVariant &value );
87 bool GetValue( wxVariant &value ) const;
88
89 protected:
90 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
91 };
92
93 // ---------------------------------------------------------
94 // wxDataViewCustomRenderer
95 // ---------------------------------------------------------
96
97 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewCustomRendererBase
98 {
99 public:
100 wxDataViewCustomRenderer( const wxString &varianttype = "string",
101 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
102 int align = wxDVR_DEFAULT_ALIGNMENT,
103 bool no_init = false );
104 virtual ~wxDataViewCustomRenderer();
105
106
107 // Create DC on request
108 virtual wxDC *GetDC();
109
110 // override the base class function to use GTK text cell renderer
111 virtual void RenderText(const wxString& text,
112 int xoffset,
113 wxRect cell,
114 wxDC *dc,
115 int state);
116
117 // store GTK render call parameters for possible later use
118 void GTKStashRenderParams(GdkWindow *window,
119 GtkWidget *widget,
120 GdkRectangle *background_area,
121 GdkRectangle *expose_area,
122 int flags)
123 {
124 m_renderParams.window = window;
125 m_renderParams.widget = widget;
126 m_renderParams.background_area = background_area;
127 m_renderParams.expose_area = expose_area;
128 m_renderParams.flags = flags;
129 }
130
131 protected:
132 bool Init(wxDataViewCellMode mode, int align);
133
134 private:
135 wxDC *m_dc;
136
137 GtkCellRenderer *m_text_renderer;
138
139 // parameters of the original render() call stored so that we could pass
140 // them forward to m_text_renderer if our RenderText() is called
141 struct GTKRenderParams
142 {
143 GdkWindow *window;
144 GtkWidget *widget;
145 GdkRectangle *background_area;
146 GdkRectangle *expose_area;
147 int flags;
148 } m_renderParams;
149
150 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
151 };
152
153 // ---------------------------------------------------------
154 // wxDataViewProgressRenderer
155 // ---------------------------------------------------------
156
157 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
158 {
159 public:
160 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
161 const wxString &varianttype = "long",
162 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
163 int align = wxDVR_DEFAULT_ALIGNMENT );
164 virtual ~wxDataViewProgressRenderer();
165
166 bool SetValue( const wxVariant &value );
167 bool GetValue( wxVariant &value ) const;
168
169 virtual bool Render( wxRect cell, wxDC *dc, int state );
170 virtual wxSize GetSize() const;
171
172 private:
173 wxString m_label;
174 int m_value;
175
176 protected:
177 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
178 };
179
180 // ---------------------------------------------------------
181 // wxDataViewIconTextRenderer
182 // ---------------------------------------------------------
183
184 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
185 {
186 public:
187 wxDataViewIconTextRenderer( const wxString &varianttype = "wxDataViewIconText",
188 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
189 int align = wxDVR_DEFAULT_ALIGNMENT );
190 virtual ~wxDataViewIconTextRenderer();
191
192 bool SetValue( const wxVariant &value );
193 bool GetValue( wxVariant &value ) const;
194
195 virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
196
197 protected:
198 virtual void GtkOnCellChanged(const wxVariant& value,
199 const wxDataViewItem& item,
200 unsigned col);
201
202 private:
203 wxDataViewIconText m_value;
204
205 // we use the base class m_renderer for the text and this one for the icon
206 GtkCellRenderer *m_rendererIcon;
207
208 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
209 };
210
211 // ---------------------------------------------------------
212 // wxDataViewDateRenderer
213 // ---------------------------------------------------------
214
215 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
216 {
217 public:
218 wxDataViewDateRenderer( const wxString &varianttype = "datetime",
219 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
220 int align = wxDVR_DEFAULT_ALIGNMENT );
221
222 bool SetValue( const wxVariant &value );
223 bool GetValue( wxVariant &value ) const;
224
225 virtual bool Render( wxRect cell, wxDC *dc, int state );
226 virtual wxSize GetSize() const;
227 virtual bool Activate( wxRect cell,
228 wxDataViewModel *model,
229 const wxDataViewItem &item,
230 unsigned int col );
231
232 private:
233 wxDateTime m_date;
234
235 protected:
236 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
237 };
238
239 // -------------------------------------
240 // wxDataViewChoiceRenderer
241 // -------------------------------------
242
243 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
244 {
245 public:
246 wxDataViewChoiceRenderer(const wxArrayString &choices,
247 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
248 int alignment = wxDVR_DEFAULT_ALIGNMENT );
249 virtual bool Render( wxRect rect, wxDC *dc, int state );
250 virtual wxSize GetSize() const;
251 virtual bool SetValue( const wxVariant &value );
252 virtual bool GetValue( wxVariant &value ) const;
253
254 void SetAlignment( int align );
255
256 private:
257 wxArrayString m_choices;
258 wxString m_data;
259 };
260
261 #endif // _WX_GTK_DVRENDERERS_H_
262