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