]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dataview.h
no changes, just fix a typo in comment
[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 _WX_GTKDATAVIEWCTRL_H_
11 #define _WX_GTKDATAVIEWCTRL_H_
12
13 #include "wx/list.h"
14
15 // ---------------------------------------------------------
16 // classes
17 // ---------------------------------------------------------
18
19 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
20 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal;
21
22
23 // ---------------------------------------------------------
24 // wxDataViewRenderer
25 // ---------------------------------------------------------
26
27 class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
28 {
29 public:
30 wxDataViewRenderer( const wxString &varianttype,
31 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
32 int align = wxDVR_DEFAULT_ALIGNMENT );
33
34 virtual void SetMode( wxDataViewCellMode mode );
35 virtual wxDataViewCellMode GetMode() const;
36
37 virtual void SetAlignment( int align );
38 virtual int GetAlignment() const;
39
40 // implementation
41 GtkCellRenderer* GetGtkHandle() { return m_renderer; }
42 void GtkInitHandlers();
43 virtual bool GtkHasAttributes() { return false; }
44
45 protected:
46 GtkCellRenderer *m_renderer;
47
48 protected:
49 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
50 };
51
52 // ---------------------------------------------------------
53 // wxDataViewTextRenderer
54 // ---------------------------------------------------------
55
56 class WXDLLIMPEXP_ADV 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 // wxDataViewTextRendererAttr
74 // ---------------------------------------------------------
75
76 class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
77 {
78 public:
79 wxDataViewTextRendererAttr( const wxString &varianttype = wxT("string"),
80 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
81 int align = wxDVR_DEFAULT_ALIGNMENT );
82
83 // implementation
84 bool GtkHasAttributes() { return true; }
85
86 protected:
87 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
88 };
89
90 // ---------------------------------------------------------
91 // wxDataViewBitmapRenderer
92 // ---------------------------------------------------------
93
94 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
95 {
96 public:
97 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
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(wxDataViewBitmapRenderer)
106 };
107
108 // ---------------------------------------------------------
109 // wxDataViewToggleRenderer
110 // ---------------------------------------------------------
111
112 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
113 {
114 public:
115 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
116 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
117 int align = wxDVR_DEFAULT_ALIGNMENT );
118
119 bool SetValue( const wxVariant &value );
120 bool GetValue( wxVariant &value ) const;
121
122 protected:
123 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
124 };
125
126 // ---------------------------------------------------------
127 // wxDataViewCustomRenderer
128 // ---------------------------------------------------------
129
130 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
131 {
132 public:
133 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
134 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
135 int align = wxDVR_DEFAULT_ALIGNMENT,
136 bool no_init = false );
137 virtual ~wxDataViewCustomRenderer();
138
139
140 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
141
142 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
143
144 virtual wxSize GetSize() const = 0;
145
146 virtual bool Activate( wxRect WXUNUSED(cell),
147 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
148 { return false; }
149
150 virtual bool LeftClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
151 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
152 { return false; }
153 virtual bool RightClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
154 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
155 { return false; }
156 virtual bool StartDrag( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
157 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
158 { return false; }
159
160 // Create DC on request
161 virtual wxDC *GetDC();
162
163
164 protected:
165
166 bool Init(wxDataViewCellMode mode, int align);
167
168 private:
169 wxDC *m_dc;
170
171 public:
172 // Internal, temporay for RenderText.
173 GtkCellRenderer *m_text_renderer;
174 GdkWindow *window;
175 GtkWidget *widget;
176 void *background_area;
177 void *cell_area;
178 void *expose_area;
179 int flags;
180
181 protected:
182 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
183 };
184
185 // ---------------------------------------------------------
186 // wxDataViewProgressRenderer
187 // ---------------------------------------------------------
188
189 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
190 {
191 public:
192 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
193 const wxString &varianttype = wxT("long"),
194 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
195 int align = wxDVR_DEFAULT_ALIGNMENT );
196 virtual ~wxDataViewProgressRenderer();
197
198 bool SetValue( const wxVariant &value );
199 bool GetValue( wxVariant &value ) const;
200
201 virtual bool Render( wxRect cell, wxDC *dc, int state );
202 virtual wxSize GetSize() const;
203
204 private:
205 wxString m_label;
206 int m_value;
207
208 protected:
209 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
210 };
211
212 // ---------------------------------------------------------
213 // wxDataViewIconTextRenderer
214 // ---------------------------------------------------------
215
216 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
217 {
218 public:
219 wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
220 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
221 int align = wxDVR_DEFAULT_ALIGNMENT );
222 virtual ~wxDataViewIconTextRenderer();
223
224 bool SetValue( const wxVariant &value );
225 bool GetValue( wxVariant &value ) const;
226
227 virtual bool Render( wxRect cell, wxDC *dc, int state );
228 virtual wxSize GetSize() const;
229
230 virtual bool HasEditorCtrl() { return true; }
231 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
232 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
233
234 private:
235 wxDataViewIconText m_value;
236
237 protected:
238 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
239 };
240
241 // ---------------------------------------------------------
242 // wxDataViewDateRenderer
243 // ---------------------------------------------------------
244
245 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
246 {
247 public:
248 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
249 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
250 int align = wxDVR_DEFAULT_ALIGNMENT );
251
252 bool SetValue( const wxVariant &value );
253 bool GetValue( wxVariant &value ) const;
254
255 virtual bool Render( wxRect cell, wxDC *dc, int state );
256 virtual wxSize GetSize() const;
257 virtual bool Activate( wxRect cell,
258 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col );
259
260 private:
261 wxDateTime m_date;
262
263 protected:
264 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
265 };
266
267 // ---------------------------------------------------------
268 // wxDataViewColumn
269 // ---------------------------------------------------------
270
271 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
272 {
273 public:
274 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
275 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
276 wxAlignment align = wxALIGN_CENTER,
277 int flags = wxDATAVIEW_COL_RESIZABLE );
278 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
279 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
280 wxAlignment align = wxALIGN_CENTER,
281 int flags = wxDATAVIEW_COL_RESIZABLE );
282
283 virtual ~wxDataViewColumn();
284
285
286 // setters:
287
288 virtual void SetTitle( const wxString &title );
289 virtual void SetBitmap( const wxBitmap &bitmap );
290
291 virtual void SetOwner( wxDataViewCtrl *owner );
292
293 virtual void SetAlignment( wxAlignment align );
294
295 virtual void SetSortable( bool sortable );
296 virtual void SetSortOrder( bool ascending );
297
298 virtual void SetResizeable( bool resizeable );
299 virtual void SetHidden( bool hidden );
300
301 virtual void SetMinWidth( int minWidth );
302 virtual void SetWidth( int width );
303
304 virtual void SetReorderable( bool reorderable );
305
306 // getters:
307
308 virtual wxString GetTitle() const;
309 virtual wxAlignment GetAlignment() const;
310
311 virtual bool IsSortable() const;
312 virtual bool IsSortOrderAscending() const;
313 virtual bool IsResizeable() const;
314 virtual bool IsHidden() const;
315
316 virtual int GetWidth() const;
317 virtual int GetMinWidth() const;
318
319 virtual bool IsReorderable() 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 virtual void OnInternalIdle();
413
414 protected:
415 virtual void DoSetExpanderColumn();
416 virtual void DoSetIndent();
417
418 private:
419 friend class wxDataViewCtrlDCImpl;
420 friend class wxDataViewColumn;
421 friend class wxGtkDataViewModelNotifier;
422 friend class wxDataViewCtrlInternal;
423
424 GtkWidget *m_treeview;
425 wxDataViewModelNotifier *m_notifier;
426 wxDataViewCtrlInternal *m_internal;
427 wxDataViewColumnList m_cols;
428
429 void GtkEnableSelectionEvents();
430 void GtkDisableSelectionEvents();
431
432 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
433 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
434 };
435
436
437 #endif // _WX_GTKDATAVIEWCTRL_H_