]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/dvrenderers.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[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)
6eec70b9
VZ
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
9dc44eff
PC
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
70884c6f 20
6eec70b9
VZ
21// ---------------------------------------------------------
22// wxDataViewTextRenderer
23// ---------------------------------------------------------
24
25class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
26{
27public:
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
c2a738e3 50 virtual bool GtkSupportsAttrs() const { return true; }
c80cde00 51 virtual bool GtkSetAttr(const wxDataViewItemAttr& attr);
c2a738e3 52
17cbc244
VZ
53 virtual GtkCellRendererText *GtkGetTextRenderer() const;
54
6eec70b9
VZ
55protected:
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
68class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
69{
70public:
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
78protected:
79 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
80};
81
82// ---------------------------------------------------------
83// wxDataViewToggleRenderer
84// ---------------------------------------------------------
85
86class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
87{
88public:
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
96protected:
97 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
98};
99
100// ---------------------------------------------------------
101// wxDataViewCustomRenderer
102// ---------------------------------------------------------
103
104class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewCustomRendererBase
105{
106public:
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
6eec70b9
VZ
114 // Create DC on request
115 virtual wxDC *GetDC();
116
62265c2c
VZ
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);
6eec70b9 123
02800dde
PC
124 struct GTKRenderParams;
125
2a454ffd 126 // store GTK render call parameters for possible later use
02800dde 127 void GTKSetRenderParams(GTKRenderParams* renderParams)
2a454ffd 128 {
02800dde 129 m_renderParams = renderParams;
2a454ffd 130 }
6eec70b9 131
c80cde00
VZ
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
17cbc244
VZ
142 virtual GtkCellRendererText *GtkGetTextRenderer() const;
143
95dc31e0 144private:
6eec70b9
VZ
145 bool Init(wxDataViewCellMode mode, int align);
146
3e81bbbf
VZ
147 // Called from GtkGetTextRenderer() to really create the renderer if
148 // necessary.
149 void GtkInitTextRenderer();
150
6eec70b9
VZ
151 wxDC *m_dc;
152
c80cde00 153 GtkCellRendererText *m_text_renderer;
6eec70b9 154
2a454ffd
VZ
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
02800dde 157 GTKRenderParams* m_renderParams;
2a454ffd 158
6eec70b9
VZ
159 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
160};
161
162// ---------------------------------------------------------
163// wxDataViewProgressRenderer
164// ---------------------------------------------------------
165
166class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
167{
168public:
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
181private:
fdd67a6a
VZ
182 void GTKSetLabel();
183
6eec70b9
VZ
184 wxString m_label;
185 int m_value;
186
fdd67a6a
VZ
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
6eec70b9
VZ
193protected:
194 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
195};
196
197// ---------------------------------------------------------
198// wxDataViewIconTextRenderer
199// ---------------------------------------------------------
200
201class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
202{
203public:
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
214protected:
215 virtual void GtkOnCellChanged(const wxVariant& value,
216 const wxDataViewItem& item,
217 unsigned col);
218
219private:
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
6eec70b9
VZ
228// -------------------------------------
229// wxDataViewChoiceRenderer
230// -------------------------------------
231
232class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
233{
234public:
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
f4fcd648
RR
245 wxString GetChoice(size_t index) const { return m_choices[index]; }
246 const wxArrayString& GetChoices() const { return m_choices; }
247
6eec70b9
VZ
248private:
249 wxArrayString m_choices;
250 wxString m_data;
251};
252
65887bd0
RR
253// ----------------------------------------------------------------------------
254// wxDataViewChoiceByIndexRenderer
255// ----------------------------------------------------------------------------
256
257class WXDLLIMPEXP_ADV wxDataViewChoiceByIndexRenderer: public wxDataViewChoiceRenderer
258{
259public:
260 wxDataViewChoiceByIndexRenderer( const wxArrayString &choices,
261 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
262 int alignment = wxDVR_DEFAULT_ALIGNMENT );
ce00f59b 263
65887bd0
RR
264 virtual bool SetValue( const wxVariant &value );
265 virtual bool GetValue( wxVariant &value ) const;
ce00f59b 266
65887bd0 267private:
29e461a2 268 virtual void GtkOnTextEdited(const char *itempath, const wxString& str);
65887bd0
RR
269};
270
271
272
6eec70b9
VZ
273#endif // _WX_GTK_DVRENDERERS_H_
274