]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dataview.h
sizeof(char) is 1. By definition.
[wxWidgets.git] / include / wx / gtk / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gtk/dataview.h
3 // Purpose: wxDataViewCtrl GTK+2 implementation header
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef __GTKDATAVIEWCTRLH__
11 #define __GTKDATAVIEWCTRLH__
12
13 #include "wx/defs.h"
14 #include "wx/object.h"
15 #include "wx/list.h"
16 #include "wx/control.h"
17
18 // ---------------------------------------------------------
19 // classes
20 // ---------------------------------------------------------
21
22 class WXDLLIMPEXP_CORE wxDataViewCtrl;
23
24
25 // ---------------------------------------------------------
26 // wxDataViewRenderer
27 // ---------------------------------------------------------
28
29 class wxDataViewRenderer: public wxDataViewRendererBase
30 {
31 public:
32 wxDataViewRenderer( const wxString &varianttype,
33 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
34 int align = wxDVR_DEFAULT_ALIGNMENT );
35
36 // implementation
37 GtkWidget* GetGtkHandle() { return m_renderer; }
38
39 virtual void SetMode( wxDataViewCellMode mode );
40 virtual wxDataViewCellMode GetMode() const;
41
42 virtual void SetAlignment( int align );
43 virtual int GetAlignment() const;
44
45 protected:
46 GtkWidget *m_renderer;
47
48 protected:
49 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
50 };
51
52 // ---------------------------------------------------------
53 // wxDataViewTextRenderer
54 // ---------------------------------------------------------
55
56 class wxDataViewTextRenderer: public wxDataViewRenderer
57 {
58 public:
59 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
60 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
61 int align = wxDVR_DEFAULT_ALIGNMENT );
62
63 bool SetValue( const wxVariant &value );
64 bool GetValue( wxVariant &value ) const;
65
66 void SetAlignment( int align );
67
68 protected:
69 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
70 };
71
72 // ---------------------------------------------------------
73 // wxDataViewBitmapRenderer
74 // ---------------------------------------------------------
75
76 class wxDataViewBitmapRenderer: public wxDataViewRenderer
77 {
78 public:
79 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
80 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
81 int align = wxDVR_DEFAULT_ALIGNMENT );
82
83 bool SetValue( const wxVariant &value );
84 bool GetValue( wxVariant &value ) const;
85
86 protected:
87 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
88 };
89
90 // ---------------------------------------------------------
91 // wxDataViewToggleRenderer
92 // ---------------------------------------------------------
93
94 class wxDataViewToggleRenderer: public wxDataViewRenderer
95 {
96 public:
97 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
98 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
99 int align = wxDVR_DEFAULT_ALIGNMENT );
100
101 bool SetValue( const wxVariant &value );
102 bool GetValue( wxVariant &value ) const;
103
104 protected:
105 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
106 };
107
108 // ---------------------------------------------------------
109 // wxDataViewCustomRenderer
110 // ---------------------------------------------------------
111
112 class wxDataViewCustomRenderer: public wxDataViewRenderer
113 {
114 public:
115 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
116 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
117 int align = wxDVR_DEFAULT_ALIGNMENT,
118 bool no_init = false );
119 virtual ~wxDataViewCustomRenderer();
120
121
122 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
123 virtual wxSize GetSize() const = 0;
124
125 virtual bool Activate( wxRect cell,
126 wxDataViewListModel *model, unsigned int col, unsigned int row )
127 { return false; }
128
129 virtual bool LeftClick( wxPoint cursor, wxRect cell,
130 wxDataViewListModel *model, unsigned int col, unsigned int row )
131 { return false; }
132 virtual bool RightClick( wxPoint cursor, wxRect cell,
133 wxDataViewListModel *model, unsigned int col, unsigned int row )
134 { return false; }
135 virtual bool StartDrag( wxPoint cursor, wxRect cell,
136 wxDataViewListModel *model, unsigned int col, unsigned int row )
137 { return false; }
138
139 // Create DC on request
140 virtual wxDC *GetDC();
141
142
143 protected:
144
145 bool Init(wxDataViewCellMode mode, int align);
146
147 private:
148 wxDC *m_dc;
149
150 protected:
151 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
152 };
153
154 // ---------------------------------------------------------
155 // wxDataViewProgressRenderer
156 // ---------------------------------------------------------
157
158 class wxDataViewProgressRenderer: public wxDataViewCustomRenderer
159 {
160 public:
161 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
162 const wxString &varianttype = wxT("long"),
163 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
164 int align = wxDVR_DEFAULT_ALIGNMENT );
165 virtual ~wxDataViewProgressRenderer();
166
167 bool SetValue( const wxVariant &value );
168 bool GetValue( wxVariant &value ) const;
169
170 virtual bool Render( wxRect cell, wxDC *dc, int state );
171 virtual wxSize GetSize() const;
172
173 private:
174 wxString m_label;
175 int m_value;
176
177 protected:
178 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
179 };
180
181 // ---------------------------------------------------------
182 // wxDataViewDateRenderer
183 // ---------------------------------------------------------
184
185 class wxDataViewDateRenderer: public wxDataViewCustomRenderer
186 {
187 public:
188 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
189 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
190 int align = wxDVR_DEFAULT_ALIGNMENT );
191
192 bool SetValue( const wxVariant &value );
193 bool GetValue( wxVariant &value ) const;
194
195 virtual bool Render( wxRect cell, wxDC *dc, int state );
196 virtual wxSize GetSize() const;
197 virtual bool Activate( wxRect cell,
198 wxDataViewListModel *model, unsigned int col, unsigned int row );
199
200 private:
201 wxDateTime m_date;
202
203 protected:
204 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
205 };
206
207 // ---------------------------------------------------------
208 // wxDataViewColumn
209 // ---------------------------------------------------------
210
211 class WXDLLIMPEXP_CORE wxDataViewColumn: public wxDataViewColumnBase
212 {
213 public:
214 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
215 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
216 wxAlignment align = wxALIGN_CENTER,
217 int flags = wxDATAVIEW_COL_RESIZABLE );
218 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
219 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
220 wxAlignment align = wxALIGN_CENTER,
221 int flags = wxDATAVIEW_COL_RESIZABLE );
222
223 virtual ~wxDataViewColumn();
224
225
226 // setters:
227
228 virtual void SetTitle( const wxString &title );
229 virtual void SetBitmap( const wxBitmap &bitmap );
230
231 virtual void SetOwner( wxDataViewCtrl *owner );
232
233 virtual void SetAlignment( wxAlignment align );
234
235 virtual void SetSortable( bool sortable );
236 virtual void SetSortOrder( bool ascending );
237
238 virtual void SetResizeable( bool resizeable );
239 virtual void SetHidden( bool hidden );
240
241 virtual void SetMinWidth( int minWidth );
242 virtual void SetWidth( int width );
243
244
245 // getters:
246
247 virtual wxString GetTitle() const;
248 virtual wxAlignment GetAlignment() const;
249
250 virtual bool IsSortable() const;
251 virtual bool IsSortOrderAscending() const;
252 virtual bool IsResizeable() const;
253 virtual bool IsHidden() const;
254
255 virtual int GetWidth() const;
256 virtual int GetMinWidth() const;
257
258 // implementation
259 GtkWidget* GetGtkHandle() { return m_column; }
260
261 private:
262 // holds the GTK handle
263 GtkWidget *m_column;
264
265 // delayed connection to mouse events
266 friend class wxDataViewCtrl;
267 void OnInternalIdle();
268 bool m_isConnected;
269
270 void Init(wxAlignment align, int flags, int width);
271
272 protected:
273 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
274 };
275
276 // ---------------------------------------------------------
277 // wxDataViewCtrl
278 // ---------------------------------------------------------
279
280 class WXDLLIMPEXP_CORE wxDataViewCtrl: public wxDataViewCtrlBase
281 {
282 public:
283 wxDataViewCtrl()
284 {
285 Init();
286 }
287
288 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
289 const wxPoint& pos = wxDefaultPosition,
290 const wxSize& size = wxDefaultSize, long style = 0,
291 const wxValidator& validator = wxDefaultValidator )
292 {
293 Create(parent, id, pos, size, style, validator );
294 }
295
296 virtual ~wxDataViewCtrl();
297
298 void Init();
299
300 bool Create(wxWindow *parent, wxWindowID id,
301 const wxPoint& pos = wxDefaultPosition,
302 const wxSize& size = wxDefaultSize, long style = 0,
303 const wxValidator& validator = wxDefaultValidator );
304
305 virtual bool AssociateModel( wxDataViewListModel *model );
306 virtual bool AppendColumn( wxDataViewColumn *col );
307
308 virtual void SetSelection( int row ); // -1 for unselect
309 virtual void SetSelectionRange( unsigned int from, unsigned int to );
310 virtual void SetSelections( const wxArrayInt& aSelections);
311 virtual void Unselect( unsigned int row );
312
313 virtual bool IsSelected( unsigned int row ) const;
314 virtual int GetSelection() const;
315 virtual int GetSelections(wxArrayInt& aSelections) const;
316
317 static wxVisualAttributes
318 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
319
320 private:
321 friend class wxDataViewCtrlDC;
322 friend class wxDataViewColumn;
323 friend class wxGtkDataViewListModelNotifier;
324 GtkWidget *m_treeview;
325 wxDataViewListModelNotifier *m_notifier;
326
327 virtual void OnInternalIdle();
328
329 private:
330 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
331 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
332 };
333
334
335 #endif // __GTKDATAVIEWCTRLH__