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