]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dataview.h
c85c6d34f75ef0844571e5648827636a74d7334e
[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_FWD_ADV wxDataViewCtrl;
23 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal;
24
25
26 // ---------------------------------------------------------
27 // wxDataViewRenderer
28 // ---------------------------------------------------------
29
30 class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
31 {
32 public:
33 wxDataViewRenderer( const wxString &varianttype,
34 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
35 int align = wxDVR_DEFAULT_ALIGNMENT );
36
37 virtual void SetMode( wxDataViewCellMode mode );
38 virtual wxDataViewCellMode GetMode() const;
39
40 virtual void SetAlignment( int align );
41 virtual int GetAlignment() const;
42
43 // implementation
44 GtkCellRenderer* GetGtkHandle() { return m_renderer; }
45 void GtkInitHandlers();
46 virtual bool GtkHasAttributes() { return false; }
47
48 protected:
49 GtkCellRenderer *m_renderer;
50
51 protected:
52 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
53 };
54
55 // ---------------------------------------------------------
56 // wxDataViewTextRenderer
57 // ---------------------------------------------------------
58
59 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
60 {
61 public:
62 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
63 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
64 int align = wxDVR_DEFAULT_ALIGNMENT );
65
66 bool SetValue( const wxVariant &value );
67 bool GetValue( wxVariant &value ) const;
68
69 void SetAlignment( int align );
70
71 protected:
72 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
73 };
74
75 // ---------------------------------------------------------
76 // wxDataViewTextRendererAttr
77 // ---------------------------------------------------------
78
79 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
80 {
81 public:
82 wxDataViewTextRendererAttr( const wxString &varianttype = wxT("string"),
83 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
84 int align = wxDVR_DEFAULT_ALIGNMENT );
85
86 // implementation
87 bool GtkHasAttributes() { return true; }
88
89 protected:
90 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
91 };
92
93 // ---------------------------------------------------------
94 // wxDataViewBitmapRenderer
95 // ---------------------------------------------------------
96
97 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
98 {
99 public:
100 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
101 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
102 int align = wxDVR_DEFAULT_ALIGNMENT );
103
104 bool SetValue( const wxVariant &value );
105 bool GetValue( wxVariant &value ) const;
106
107 protected:
108 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
109 };
110
111 // ---------------------------------------------------------
112 // wxDataViewToggleRenderer
113 // ---------------------------------------------------------
114
115 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
116 {
117 public:
118 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
119 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
120 int align = wxDVR_DEFAULT_ALIGNMENT );
121
122 bool SetValue( const wxVariant &value );
123 bool GetValue( wxVariant &value ) const;
124
125 protected:
126 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
127 };
128
129 // ---------------------------------------------------------
130 // wxDataViewCustomRenderer
131 // ---------------------------------------------------------
132
133 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
134 {
135 public:
136 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
137 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
138 int align = wxDVR_DEFAULT_ALIGNMENT,
139 bool no_init = false );
140 virtual ~wxDataViewCustomRenderer();
141
142
143 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
144
145 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
146
147 virtual wxSize GetSize() const = 0;
148
149 virtual bool Activate( wxRect WXUNUSED(cell),
150 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
151 { return false; }
152
153 virtual bool LeftClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
154 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
155 { return false; }
156 virtual bool RightClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
157 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
158 { return false; }
159 virtual bool StartDrag( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
160 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
161 { return false; }
162
163 // Create DC on request
164 virtual wxDC *GetDC();
165
166
167 protected:
168
169 bool Init(wxDataViewCellMode mode, int align);
170
171 private:
172 wxDC *m_dc;
173
174 public:
175 // Internal, temporay for RenderText.
176 GtkCellRenderer *m_text_renderer;
177 GdkWindow *window;
178 GtkWidget *widget;
179 void *background_area;
180 void *cell_area;
181 void *expose_area;
182 int flags;
183
184 protected:
185 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
186 };
187
188 // ---------------------------------------------------------
189 // wxDataViewProgressRenderer
190 // ---------------------------------------------------------
191
192 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
193 {
194 public:
195 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
196 const wxString &varianttype = wxT("long"),
197 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
198 int align = wxDVR_DEFAULT_ALIGNMENT );
199 virtual ~wxDataViewProgressRenderer();
200
201 bool SetValue( const wxVariant &value );
202 bool GetValue( wxVariant &value ) const;
203
204 virtual bool Render( wxRect cell, wxDC *dc, int state );
205 virtual wxSize GetSize() const;
206
207 private:
208 wxString m_label;
209 int m_value;
210
211 protected:
212 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
213 };
214
215 // ---------------------------------------------------------
216 // wxDataViewIconTextRenderer
217 // ---------------------------------------------------------
218
219 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
220 {
221 public:
222 wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
223 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
224 int align = wxDVR_DEFAULT_ALIGNMENT );
225 virtual ~wxDataViewIconTextRenderer();
226
227 bool SetValue( const wxVariant &value );
228 bool GetValue( wxVariant &value ) const;
229
230 virtual bool Render( wxRect cell, wxDC *dc, int state );
231 virtual wxSize GetSize() const;
232
233 virtual bool HasEditorCtrl() { return true; }
234 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
235 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
236
237 private:
238 wxDataViewIconText m_value;
239
240 protected:
241 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
242 };
243
244 // ---------------------------------------------------------
245 // wxDataViewDateRenderer
246 // ---------------------------------------------------------
247
248 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
249 {
250 public:
251 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
252 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
253 int align = wxDVR_DEFAULT_ALIGNMENT );
254
255 bool SetValue( const wxVariant &value );
256 bool GetValue( wxVariant &value ) const;
257
258 virtual bool Render( wxRect cell, wxDC *dc, int state );
259 virtual wxSize GetSize() const;
260 virtual bool Activate( wxRect cell,
261 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col );
262
263 private:
264 wxDateTime m_date;
265
266 protected:
267 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
268 };
269
270 // ---------------------------------------------------------
271 // wxDataViewColumn
272 // ---------------------------------------------------------
273
274 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
275 {
276 public:
277 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
278 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
279 wxAlignment align = wxALIGN_CENTER,
280 int flags = wxDATAVIEW_COL_RESIZABLE );
281 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
282 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
283 wxAlignment align = wxALIGN_CENTER,
284 int flags = wxDATAVIEW_COL_RESIZABLE );
285
286 virtual ~wxDataViewColumn();
287
288
289 // setters:
290
291 virtual void SetTitle( const wxString &title );
292 virtual void SetBitmap( const wxBitmap &bitmap );
293
294 virtual void SetOwner( wxDataViewCtrl *owner );
295
296 virtual void SetAlignment( wxAlignment align );
297
298 virtual void SetSortable( bool sortable );
299 virtual void SetSortOrder( bool ascending );
300
301 virtual void SetResizeable( bool resizeable );
302 virtual void SetHidden( bool hidden );
303
304 virtual void SetMinWidth( int minWidth );
305 virtual void SetWidth( int width );
306
307
308 // getters:
309
310 virtual wxString GetTitle() const;
311 virtual wxAlignment GetAlignment() const;
312
313 virtual bool IsSortable() const;
314 virtual bool IsSortOrderAscending() const;
315 virtual bool IsResizeable() const;
316 virtual bool IsHidden() const;
317
318 virtual int GetWidth() const;
319 virtual int GetMinWidth() const;
320
321 // implementation
322 GtkWidget* GetGtkHandle() { return m_column; }
323 GtkWidget* GetConstGtkHandle() const { return m_column; }
324
325 private:
326 // holds the GTK handle
327 GtkWidget *m_column;
328
329 // delayed connection to mouse events
330 friend class wxDataViewCtrl;
331 void OnInternalIdle();
332 bool m_isConnected;
333
334 void Init(wxAlignment align, int flags, int width);
335
336 protected:
337 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
338 };
339
340 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
341 class WXDLLIMPEXP_ADV);
342
343 // ---------------------------------------------------------
344 // wxDataViewCtrl
345 // ---------------------------------------------------------
346
347 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
348 {
349 public:
350 wxDataViewCtrl()
351 {
352 Init();
353 }
354
355 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
356 const wxPoint& pos = wxDefaultPosition,
357 const wxSize& size = wxDefaultSize, long style = 0,
358 const wxValidator& validator = wxDefaultValidator )
359 {
360 Create(parent, id, pos, size, style, validator );
361 }
362
363 virtual ~wxDataViewCtrl();
364
365 void Init();
366
367 bool Create(wxWindow *parent, wxWindowID id,
368 const wxPoint& pos = wxDefaultPosition,
369 const wxSize& size = wxDefaultSize, long style = 0,
370 const wxValidator& validator = wxDefaultValidator );
371
372 virtual bool AssociateModel( wxDataViewModel *model );
373
374 virtual bool PrependColumn( wxDataViewColumn *col );
375 virtual bool AppendColumn( wxDataViewColumn *col );
376 virtual unsigned int GetColumnCount() const;
377 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
378 virtual bool DeleteColumn( wxDataViewColumn *column );
379 virtual bool ClearColumns();
380 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
381
382 virtual wxDataViewColumn *GetSortingColumn() const;
383
384 virtual wxDataViewItem GetSelection() const;
385 virtual int GetSelections( wxDataViewItemArray & sel ) const;
386 virtual void SetSelections( const wxDataViewItemArray & sel );
387 virtual void Select( const wxDataViewItem & item );
388 virtual void Unselect( const wxDataViewItem & item );
389 virtual bool IsSelected( const wxDataViewItem & item ) const;
390 virtual void SelectAll();
391 virtual void UnselectAll();
392
393 virtual void EnsureVisible( const wxDataViewItem& item,
394 const wxDataViewColumn *column = NULL );
395 virtual void HitTest( const wxPoint &point,
396 wxDataViewItem &item,
397 wxDataViewColumn *&column ) const;
398 virtual wxRect GetItemRect( const wxDataViewItem &item,
399 const wxDataViewColumn *column = NULL ) const;
400
401 virtual void Expand( const wxDataViewItem & item );
402 virtual void Collapse( const wxDataViewItem & item );
403
404 static wxVisualAttributes
405 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
406
407 wxWindow *GetMainWindow() { return (wxWindow*) this; }
408
409 GtkWidget *GtkGetTreeView() { return m_treeview; }
410 wxDataViewCtrlInternal* GtkGetInternal() { return m_internal; }
411
412 protected:
413 virtual void DoSetExpanderColumn();
414 virtual void DoSetIndent();
415
416 private:
417 friend class wxDataViewCtrlDCImpl;
418 friend class wxDataViewColumn;
419 friend class wxGtkDataViewModelNotifier;
420 GtkWidget *m_treeview;
421 wxDataViewModelNotifier *m_notifier;
422 wxDataViewCtrlInternal *m_internal;
423 wxDataViewColumnList m_cols;
424
425
426 virtual void OnInternalIdle();
427
428 void GtkEnableSelectionEvents();
429 void GtkDisableSelectionEvents();
430
431 private:
432 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
433 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
434 };
435
436
437 #endif // __GTKDATAVIEWCTRLH__