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