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