]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/dataview.h
define HDS_FLAT not defined in VC6 headers
[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
RR
14
15// ---------------------------------------------------------
16// classes
17// ---------------------------------------------------------
18
d350fbec
VS
19class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
20class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal;
239eaa41 21
87f0efe2 22
6842a71a 23// ---------------------------------------------------------
baa9ebc4 24// wxDataViewRenderer
6842a71a
RR
25// ---------------------------------------------------------
26
d350fbec 27class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
6842a71a
RR
28{
29public:
87f0efe2 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
6842a71a 54// ---------------------------------------------------------
baa9ebc4 55// wxDataViewTextRenderer
6842a71a
RR
56// ---------------------------------------------------------
57
d350fbec 58class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
6842a71a
RR
59{
60public:
baa9ebc4 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
RR
72};
73
4264606e
RR
74// ---------------------------------------------------------
75// wxDataViewTextRendererAttr
76// ---------------------------------------------------------
77
78class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
79{
80public:
81 wxDataViewTextRendererAttr( const wxString &varianttype = wxT("string"),
82 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
83 int align = wxDVR_DEFAULT_ALIGNMENT );
84
85 // implementation
86 bool GtkHasAttributes() { return true; }
87
88protected:
89 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
90};
91
cbc9145c 92// ---------------------------------------------------------
baa9ebc4 93// wxDataViewBitmapRenderer
cbc9145c
RR
94// ---------------------------------------------------------
95
d350fbec 96class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
cbc9145c
RR
97{
98public:
baa9ebc4 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;
cbc9145c
RR
105
106protected:
baa9ebc4 107 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
cbc9145c
RR
108};
109
605c2c4a 110// ---------------------------------------------------------
baa9ebc4 111// wxDataViewToggleRenderer
605c2c4a
RR
112// ---------------------------------------------------------
113
d350fbec 114class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
605c2c4a
RR
115{
116public:
baa9ebc4 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;
605c2c4a
RR
123
124protected:
baa9ebc4 125 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
605c2c4a
RR
126};
127
e152afc3 128// ---------------------------------------------------------
baa9ebc4 129// wxDataViewCustomRenderer
e152afc3
RR
130// ---------------------------------------------------------
131
d350fbec 132class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
e152afc3
RR
133{
134public:
baa9ebc4
RR
135 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
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;
52e750fc
RR
143
144 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
145
9861f022
RR
146 virtual wxSize GetSize() const = 0;
147
0e9cfa51
RR
148 virtual bool Activate( wxRect WXUNUSED(cell),
149 wxDataViewModel *WXUNUSED(model), const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col) )
4d496ecb 150 { return false; }
9861f022 151
0e9cfa51
RR
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; }
0e9cfa51
RR
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; }
e152afc3
RR
158
159 // Create DC on request
160 virtual wxDC *GetDC();
161
9861f022
RR
162
163protected:
164
165 bool Init(wxDataViewCellMode mode, int align);
166
e152afc3
RR
167private:
168 wxDC *m_dc;
f69c03de
RR
169
170public:
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
RR
182};
183
ad63bf41 184// ---------------------------------------------------------
baa9ebc4 185// wxDataViewProgressRenderer
ad63bf41
RR
186// ---------------------------------------------------------
187
d350fbec 188class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
ad63bf41
RR
189{
190public:
baa9ebc4
RR
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();
ad63bf41
RR
196
197 bool SetValue( const wxVariant &value );
9861f022 198 bool GetValue( wxVariant &value ) const;
ad63bf41
RR
199
200 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 201 virtual wxSize GetSize() const;
ad63bf41
RR
202
203private:
204 wxString m_label;
205 int m_value;
206
207protected:
baa9ebc4 208 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
ad63bf41
RR
209};
210
c9c13e70
RR
211// ---------------------------------------------------------
212// wxDataViewIconTextRenderer
213// ---------------------------------------------------------
214
d350fbec 215class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
c9c13e70
RR
216{
217public:
218 wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
219 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
220 int align = wxDVR_DEFAULT_ALIGNMENT );
221 virtual ~wxDataViewIconTextRenderer();
222
223 bool SetValue( const wxVariant &value );
224 bool GetValue( wxVariant &value ) const;
225
226 virtual bool Render( wxRect cell, wxDC *dc, int state );
227 virtual wxSize GetSize() const;
228
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 );
232
233private:
234 wxDataViewIconText m_value;
235
236protected:
237 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
238};
239
4d496ecb 240// ---------------------------------------------------------
baa9ebc4 241// wxDataViewDateRenderer
4d496ecb
RR
242// ---------------------------------------------------------
243
d350fbec 244class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
4d496ecb
RR
245{
246public:
baa9ebc4 247 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
9861f022
RR
248 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
249 int align = wxDVR_DEFAULT_ALIGNMENT );
4d496ecb
RR
250
251 bool SetValue( const wxVariant &value );
9861f022 252 bool GetValue( wxVariant &value ) const;
4d496ecb
RR
253
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 );
4d496ecb
RR
258
259private:
260 wxDateTime m_date;
261
262protected:
baa9ebc4 263 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
4d496ecb
RR
264};
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
fa28826d
RR
287// ---------------------------------------------------------
288// wxDataViewColumn
289// ---------------------------------------------------------
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
fa28826d
RR
303 virtual ~wxDataViewColumn();
304
9861f022
RR
305
306 // setters:
307
fa28826d 308 virtual void SetTitle( const wxString &title );
07a84e7b 309 virtual void SetBitmap( const wxBitmap &bitmap );
47cef10f 310
b94db696
RR
311 virtual void SetOwner( wxDataViewCtrl *owner );
312
47cef10f 313 virtual void SetAlignment( wxAlignment align );
31fb32e1
RR
314
315 virtual void SetSortable( bool sortable );
47cef10f
RR
316 virtual void SetSortOrder( bool ascending );
317
9861f022
RR
318 virtual void SetResizeable( bool resizeable );
319 virtual void SetHidden( bool hidden );
320
321 virtual void SetMinWidth( int minWidth );
322 virtual void SetWidth( int width );
323
99c75ebc 324 virtual void SetReorderable( bool reorderable );
9861f022 325
56873923
VZ
326 virtual void SetFlags(int flags) { SetIndividualFlags(flags); }
327
9861f022
RR
328 // getters:
329
330 virtual wxString GetTitle() const;
331 virtual wxAlignment GetAlignment() const;
332
87f0efe2
RR
333 virtual bool IsSortable() const;
334 virtual bool IsSortOrderAscending() const;
9861f022
RR
335 virtual bool IsResizeable() const;
336 virtual bool IsHidden() const;
87f0efe2
RR
337
338 virtual int GetWidth() const;
9861f022 339 virtual int GetMinWidth() const;
99c75ebc
RR
340
341 virtual bool IsReorderable() const;
9861f022 342
56873923
VZ
343 virtual int GetFlags() const { return GetFromIndividualFlags(); }
344
fa28826d 345 // implementation
9861f022 346 GtkWidget* GetGtkHandle() { return m_column; }
aed836f3 347 GtkWidget* GetConstGtkHandle() const { return m_column; }
fa28826d
RR
348
349private:
6842a71a 350 // holds the GTK handle
9861f022 351 GtkWidget *m_column;
31fb32e1 352
419a3607
RR
353 // holds GTK handles for title/bitmap in the header
354 GtkWidget *m_image;
355 GtkWidget *m_label;
356
31fb32e1
RR
357 // delayed connection to mouse events
358 friend class wxDataViewCtrl;
359 void OnInternalIdle();
9861f022
RR
360 bool m_isConnected;
361
362 void Init(wxAlignment align, int flags, int width);
363
fa28826d
RR
364protected:
365 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
366};
367
d350fbec
VS
368WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
369 class WXDLLIMPEXP_ADV);
91a6c655 370
239eaa41
RR
371// ---------------------------------------------------------
372// wxDataViewCtrl
373// ---------------------------------------------------------
374
d350fbec 375class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
239eaa41
RR
376{
377public:
378 wxDataViewCtrl()
379 {
380 Init();
381 }
382
383 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
384 const wxPoint& pos = wxDefaultPosition,
385 const wxSize& size = wxDefaultSize, long style = 0,
386 const wxValidator& validator = wxDefaultValidator )
387 {
388 Create(parent, id, pos, size, style, validator );
389 }
390
391 virtual ~wxDataViewCtrl();
392
393 void Init();
394
395 bool Create(wxWindow *parent, wxWindowID id,
396 const wxPoint& pos = wxDefaultPosition,
397 const wxSize& size = wxDefaultSize, long style = 0,
398 const wxValidator& validator = wxDefaultValidator );
399
e0062c04 400 virtual bool AssociateModel( wxDataViewModel *model );
91a6c655 401
736fe67c 402 virtual bool PrependColumn( wxDataViewColumn *col );
1a367564 403 virtual bool AppendColumn( wxDataViewColumn *col );
19723525
RR
404 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
405
91a6c655
RR
406 virtual unsigned int GetColumnCount() const;
407 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
408 virtual bool DeleteColumn( wxDataViewColumn *column );
409 virtual bool ClearColumns();
453091c2 410 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
1e08ad10 411
21f47fb9
RR
412 virtual wxDataViewColumn *GetSortingColumn() const;
413
fbda518c 414 virtual wxDataViewItem GetSelection() const;
e98351ec
RR
415 virtual int GetSelections( wxDataViewItemArray & sel ) const;
416 virtual void SetSelections( const wxDataViewItemArray & sel );
417 virtual void Select( const wxDataViewItem & item );
418 virtual void Unselect( const wxDataViewItem & item );
419 virtual bool IsSelected( const wxDataViewItem & item ) const;
420 virtual void SelectAll();
421 virtual void UnselectAll();
422
fbda518c
RR
423 virtual void EnsureVisible( const wxDataViewItem& item,
424 const wxDataViewColumn *column = NULL );
66e09788 425 virtual void HitTest( const wxPoint &point,
fbda518c 426 wxDataViewItem &item,
a87b466d 427 wxDataViewColumn *&column ) const;
66e09788 428 virtual wxRect GetItemRect( const wxDataViewItem &item,
fbda518c 429 const wxDataViewColumn *column = NULL ) const;
66e09788 430
f71d3ba4
RR
431 virtual void Expand( const wxDataViewItem & item );
432 virtual void Collapse( const wxDataViewItem & item );
66e09788 433
b94db696
RR
434 static wxVisualAttributes
435 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
6ff7eee7 436
1e510b1e 437 wxWindow *GetMainWindow() { return (wxWindow*) this; }
55fbde12
RR
438
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
RR
452 friend class wxDataViewCtrlInternal;
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();
462
239eaa41
RR
463 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
464 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
465};
466
467
901a462f 468#endif // _WX_GTKDATAVIEWCTRL_H_