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