]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dataview.h
d217d2f88eb9a375b637e5775eb9aad1ca2498d6
[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 typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
23
24 // ---------------------------------------------------------
25 // wxDataViewRenderer
26 // ---------------------------------------------------------
27
28 class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
29 {
30 public:
31 wxDataViewRenderer( const wxString &varianttype,
32 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
33 int align = wxDVR_DEFAULT_ALIGNMENT );
34
35 virtual void SetMode( wxDataViewCellMode mode );
36 virtual wxDataViewCellMode GetMode() const;
37
38 virtual void SetAlignment( int align );
39 virtual int GetAlignment() const;
40
41
42 // GTK-specific implementation
43 // ---------------------------
44
45 // pack the GTK cell renderers used by this renderer to the given column
46 //
47 // by default only a single m_renderer is used but some renderers use more
48 // than one GTK cell renderer
49 virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
50
51 // called when the cell value was edited by user with the new value
52 //
53 // it validates the new value and notifies the model about the change by
54 // calling GtkOnCellChanged() if it was accepted
55 void GtkOnTextEdited(const gchar *itempath, const wxString& value);
56
57 GtkCellRenderer* GetGtkHandle() { return m_renderer; }
58 void GtkInitHandlers();
59 void GtkUpdateAlignment();
60
61 bool GtkIsUsingDefaultAttrs() const { return m_usingDefaultAttrs; }
62 void GtkSetUsingDefaultAttrs(bool def) { m_usingDefaultAttrs = def; }
63
64 protected:
65 virtual void GtkOnCellChanged(const wxVariant& value,
66 const wxDataViewItem& item,
67 unsigned col);
68
69
70 GtkCellRenderer *m_renderer;
71 int m_alignment;
72
73 // true if we hadn't changed any visual attributes or restored them since
74 // doing this
75 bool m_usingDefaultAttrs;
76
77 protected:
78 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
79 };
80
81 // ---------------------------------------------------------
82 // wxDataViewTextRenderer
83 // ---------------------------------------------------------
84
85 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
86 {
87 public:
88 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
89 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
90 int align = wxDVR_DEFAULT_ALIGNMENT );
91
92 virtual bool SetValue( const wxVariant &value )
93 {
94 return SetTextValue(value);
95 }
96
97 virtual bool GetValue( wxVariant &value ) const
98 {
99 wxString str;
100 if ( !GetTextValue(str) )
101 return false;
102
103 value = str;
104
105 return true;
106 }
107
108 virtual void SetAlignment( int align );
109
110 protected:
111 // implementation of Set/GetValue()
112 bool SetTextValue(const wxString& str);
113 bool GetTextValue(wxString& str) const;
114
115
116 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
117 };
118
119 // ---------------------------------------------------------
120 // wxDataViewBitmapRenderer
121 // ---------------------------------------------------------
122
123 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
124 {
125 public:
126 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
127 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
128 int align = wxDVR_DEFAULT_ALIGNMENT );
129
130 bool SetValue( const wxVariant &value );
131 bool GetValue( wxVariant &value ) const;
132
133 protected:
134 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
135 };
136
137 // ---------------------------------------------------------
138 // wxDataViewToggleRenderer
139 // ---------------------------------------------------------
140
141 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
142 {
143 public:
144 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
145 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
146 int align = wxDVR_DEFAULT_ALIGNMENT );
147
148 bool SetValue( const wxVariant &value );
149 bool GetValue( wxVariant &value ) const;
150
151 protected:
152 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
153 };
154
155 // ---------------------------------------------------------
156 // wxDataViewCustomRenderer
157 // ---------------------------------------------------------
158
159 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
160 {
161 public:
162 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
163 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
164 int align = wxDVR_DEFAULT_ALIGNMENT,
165 bool no_init = false );
166 virtual ~wxDataViewCustomRenderer();
167
168
169 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
170
171 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
172
173 virtual wxSize GetSize() const = 0;
174
175 virtual bool Activate( wxRect WXUNUSED(cell),
176 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
177 { return false; }
178
179 virtual bool LeftClick( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
180 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
181 { return false; }
182 virtual bool StartDrag( wxPoint WXUNUSED(cursor), wxRect WXUNUSED(cell),
183 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
184 { return false; }
185
186 // Create DC on request
187 virtual wxDC *GetDC();
188
189
190 protected:
191
192 bool Init(wxDataViewCellMode mode, int align);
193
194 private:
195 wxDC *m_dc;
196
197 public:
198 // Internal, temporary for RenderText.
199 GtkCellRenderer *m_text_renderer;
200 GdkWindow *window;
201 GtkWidget *widget;
202 void *background_area;
203 void *cell_area;
204 void *expose_area;
205 int flags;
206
207 protected:
208 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
209 };
210
211 // ---------------------------------------------------------
212 // wxDataViewProgressRenderer
213 // ---------------------------------------------------------
214
215 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
216 {
217 public:
218 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
219 const wxString &varianttype = wxT("long"),
220 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
221 int align = wxDVR_DEFAULT_ALIGNMENT );
222 virtual ~wxDataViewProgressRenderer();
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 private:
231 wxString m_label;
232 int m_value;
233
234 protected:
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
236 };
237
238 // ---------------------------------------------------------
239 // wxDataViewIconTextRenderer
240 // ---------------------------------------------------------
241
242 class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewTextRenderer
243 {
244 public:
245 wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
246 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
247 int align = wxDVR_DEFAULT_ALIGNMENT );
248 virtual ~wxDataViewIconTextRenderer();
249
250 bool SetValue( const wxVariant &value );
251 bool GetValue( wxVariant &value ) const;
252
253 virtual void GtkPackIntoColumn(GtkTreeViewColumn *column);
254
255 protected:
256 virtual void GtkOnCellChanged(const wxVariant& value,
257 const wxDataViewItem& item,
258 unsigned col);
259
260 private:
261 wxDataViewIconText m_value;
262
263 // we use the base class m_renderer for the text and this one for the icon
264 GtkCellRenderer *m_rendererIcon;
265
266 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
267 };
268
269 // ---------------------------------------------------------
270 // wxDataViewDateRenderer
271 // ---------------------------------------------------------
272
273 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
274 {
275 public:
276 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
277 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
278 int align = wxDVR_DEFAULT_ALIGNMENT );
279
280 bool SetValue( const wxVariant &value );
281 bool GetValue( wxVariant &value ) const;
282
283 virtual bool Render( wxRect cell, wxDC *dc, int state );
284 virtual wxSize GetSize() const;
285 virtual bool Activate( wxRect cell,
286 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col );
287
288 private:
289 wxDateTime m_date;
290
291 protected:
292 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
293 };
294
295 // -------------------------------------
296 // wxDataViewChoiceRenderer
297 // -------------------------------------
298
299 class WXDLLIMPEXP_ADV wxDataViewChoiceRenderer: public wxDataViewCustomRenderer
300 {
301 public:
302 wxDataViewChoiceRenderer( const wxArrayString &choices,
303 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
304 int alignment = wxDVR_DEFAULT_ALIGNMENT );
305 virtual bool Render( wxRect rect, wxDC *dc, int state );
306 virtual wxSize GetSize() const;
307 virtual bool SetValue( const wxVariant &value );
308 virtual bool GetValue( wxVariant &value ) const;
309
310 void SetAlignment( int align );
311 private:
312 wxArrayString m_choices;
313 wxString m_data;
314 };
315
316 // ---------------------------------------------------------
317 // wxDataViewColumn
318 // ---------------------------------------------------------
319
320 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
321 {
322 public:
323 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
324 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
325 wxAlignment align = wxALIGN_CENTER,
326 int flags = wxDATAVIEW_COL_RESIZABLE );
327 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
328 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
329 wxAlignment align = wxALIGN_CENTER,
330 int flags = wxDATAVIEW_COL_RESIZABLE );
331
332
333 // setters:
334
335 virtual void SetTitle( const wxString &title );
336 virtual void SetBitmap( const wxBitmap &bitmap );
337
338 virtual void SetOwner( wxDataViewCtrl *owner );
339
340 virtual void SetAlignment( wxAlignment align );
341
342 virtual void SetSortable( bool sortable );
343 virtual void SetSortOrder( bool ascending );
344 virtual void SetAsSortKey(bool sort = true);
345
346 virtual void SetResizeable( bool resizeable );
347 virtual void SetHidden( bool hidden );
348
349 virtual void SetMinWidth( int minWidth );
350 virtual void SetWidth( int width );
351
352 virtual void SetReorderable( bool reorderable );
353
354 virtual void SetFlags(int flags) { SetIndividualFlags(flags); }
355
356 // getters:
357
358 virtual wxString GetTitle() const;
359 virtual wxAlignment GetAlignment() const;
360
361 virtual bool IsSortable() const;
362 virtual bool IsSortOrderAscending() const;
363 virtual bool IsSortKey() const;
364
365 virtual bool IsResizeable() const;
366 virtual bool IsHidden() const;
367
368 virtual int GetWidth() const;
369 virtual int GetMinWidth() const;
370
371 virtual bool IsReorderable() const;
372
373 virtual int GetFlags() const { return GetFromIndividualFlags(); }
374
375 // implementation
376 GtkWidget* GetGtkHandle() { return m_column; }
377 GtkWidget* GetConstGtkHandle() const { return m_column; }
378
379 private:
380 // holds the GTK handle
381 GtkWidget *m_column;
382
383 // holds GTK handles for title/bitmap in the header
384 GtkWidget *m_image;
385 GtkWidget *m_label;
386
387 // delayed connection to mouse events
388 friend class wxDataViewCtrl;
389 void OnInternalIdle();
390 bool m_isConnected;
391
392 void Init(wxAlignment align, int flags, int width);
393 };
394
395 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
396 class WXDLLIMPEXP_ADV);
397
398 // ---------------------------------------------------------
399 // wxDataViewCtrl
400 // ---------------------------------------------------------
401
402 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
403 {
404 public:
405 wxDataViewCtrl()
406 {
407 Init();
408 }
409
410 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
411 const wxPoint& pos = wxDefaultPosition,
412 const wxSize& size = wxDefaultSize, long style = 0,
413 const wxValidator& validator = wxDefaultValidator )
414 {
415 Create(parent, id, pos, size, style, validator );
416 }
417
418 virtual ~wxDataViewCtrl();
419
420 void Init();
421
422 bool Create(wxWindow *parent, wxWindowID id,
423 const wxPoint& pos = wxDefaultPosition,
424 const wxSize& size = wxDefaultSize, long style = 0,
425 const wxValidator& validator = wxDefaultValidator );
426
427 virtual bool AssociateModel( wxDataViewModel *model );
428
429 virtual bool PrependColumn( wxDataViewColumn *col );
430 virtual bool AppendColumn( wxDataViewColumn *col );
431 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
432
433 virtual unsigned int GetColumnCount() const;
434 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
435 virtual bool DeleteColumn( wxDataViewColumn *column );
436 virtual bool ClearColumns();
437 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
438
439 virtual wxDataViewColumn *GetSortingColumn() const;
440
441 virtual wxDataViewItem GetSelection() const;
442 virtual int GetSelections( wxDataViewItemArray & sel ) const;
443 virtual void SetSelections( const wxDataViewItemArray & sel );
444 virtual void Select( const wxDataViewItem & item );
445 virtual void Unselect( const wxDataViewItem & item );
446 virtual bool IsSelected( const wxDataViewItem & item ) const;
447 virtual void SelectAll();
448 virtual void UnselectAll();
449
450 virtual void EnsureVisible( const wxDataViewItem& item,
451 const wxDataViewColumn *column = NULL );
452 virtual void HitTest( const wxPoint &point,
453 wxDataViewItem &item,
454 wxDataViewColumn *&column ) const;
455 virtual wxRect GetItemRect( const wxDataViewItem &item,
456 const wxDataViewColumn *column = NULL ) const;
457
458 virtual void Expand( const wxDataViewItem & item );
459 virtual void Collapse( const wxDataViewItem & item );
460 virtual bool IsExpanded( const wxDataViewItem & item ) const;
461
462 virtual bool EnableDragSource( const wxDataFormat &format );
463 virtual bool EnableDropTarget( const wxDataFormat &format );
464
465 static wxVisualAttributes
466 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
467
468 wxWindow *GetMainWindow() { return (wxWindow*) this; }
469
470 GtkWidget *GtkGetTreeView() { return m_treeview; }
471 wxDataViewCtrlInternal* GtkGetInternal() { return m_internal; }
472
473 virtual void OnInternalIdle();
474
475 protected:
476 virtual void DoSetExpanderColumn();
477 virtual void DoSetIndent();
478
479 virtual void DoApplyWidgetStyle(GtkRcStyle *style);
480
481 private:
482 friend class wxDataViewCtrlDCImpl;
483 friend class wxDataViewColumn;
484 friend class wxGtkDataViewModelNotifier;
485 friend class wxDataViewCtrlInternal;
486
487 GtkWidget *m_treeview;
488 wxDataViewModelNotifier *m_notifier;
489 wxDataViewCtrlInternal *m_internal;
490 wxDataViewColumnList m_cols;
491
492 virtual void AddChildGTK(wxWindowGTK* child);
493 void GtkEnableSelectionEvents();
494 void GtkDisableSelectionEvents();
495
496 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
497 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl);
498 };
499
500
501 #endif // _WX_GTKDATAVIEWCTRL_H_