]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dataview.h
don't use GTK printing in wxUniv
[wxWidgets.git] / include / wx / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dataview.h
3 // Purpose: wxDataViewCtrl base classes
4 // Author: Robert Roebling
5 // Modified by: Bo Yang
6 // Created: 08.01.06
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DATAVIEW_H_BASE_
13 #define _WX_DATAVIEW_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_DATAVIEWCTRL
18
19 #include "wx/control.h"
20 #include "wx/textctrl.h"
21 #include "wx/bitmap.h"
22 #include "wx/variant.h"
23 #include "wx/dynarray.h"
24 #include "wx/icon.h"
25
26 #if defined(__WXGTK20__)
27 // for testing
28 // #define wxUSE_GENERICDATAVIEWCTRL 1
29 #elif defined(__WXMAC__)
30 #else
31 #define wxUSE_GENERICDATAVIEWCTRL 1
32 #endif
33
34 // ----------------------------------------------------------------------------
35 // wxDataViewCtrl flags
36 // ----------------------------------------------------------------------------
37
38 // ----------------------------------------------------------------------------
39 // wxDataViewCtrl globals
40 // ----------------------------------------------------------------------------
41
42 class WXDLLIMPEXP_FWD_ADV wxDataViewItem;
43 class WXDLLIMPEXP_FWD_ADV wxDataViewModel;
44 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
45 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn;
46 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer;
47 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier;
48
49 extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[];
50
51 // the default width of new (text) columns:
52 #define wxDVC_DEFAULT_WIDTH 80
53
54 // the default width of new toggle columns:
55 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
56
57 // the default minimal width of the columns:
58 #define wxDVC_DEFAULT_MINWIDTH 30
59
60 // the default alignment of wxDataViewRenderers:
61 #define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL)
62
63
64 // ---------------------------------------------------------
65 // wxDataViewItem
66 // ---------------------------------------------------------
67
68 class WXDLLIMPEXP_ADV wxDataViewItem
69 {
70 public:
71 wxDataViewItem( void* id = NULL )
72 { m_id = id; }
73 wxDataViewItem( const wxDataViewItem &item )
74 { m_id = item.m_id; }
75 bool IsOk() const { return m_id != NULL; }
76 void* GetID() const { return m_id; }
77 operator const void* () const { return m_id; }
78
79 #ifdef __WXDEBUG__
80 void Print( const wxString &text ) const;
81 #endif
82
83 private:
84 void* m_id;
85 };
86
87 bool operator == (const wxDataViewItem &left, const wxDataViewItem &right);
88
89 WX_DEFINE_ARRAY(wxDataViewItem, wxDataViewItemArray);
90
91 // ---------------------------------------------------------
92 // wxDataViewModelNotifier
93 // ---------------------------------------------------------
94
95 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
96 {
97 public:
98 wxDataViewModelNotifier() { }
99 virtual ~wxDataViewModelNotifier() { m_owner = NULL; }
100
101 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
102 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
103 virtual bool ItemChanged( const wxDataViewItem &item ) = 0;
104 virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
105 virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
106 virtual bool ItemsChanged( const wxDataViewItemArray &items );
107 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
108 virtual bool Cleared() = 0;
109
110 virtual void Resort() = 0;
111
112 void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
113 wxDataViewModel *GetOwner() { return m_owner; }
114
115 private:
116 wxDataViewModel *m_owner;
117 };
118
119
120
121 // ----------------------------------------------------------------------------
122 // wxDataViewItemAttr: a structure containing the visual attributes of an item
123 // ----------------------------------------------------------------------------
124
125 // TODO: this should be renamed to wxItemAttr or something general like this
126
127 class WXDLLIMPEXP_ADV wxDataViewItemAttr
128 {
129 public:
130 // ctors
131 wxDataViewItemAttr()
132 {
133 m_bold = false;
134 m_italic = false;
135 }
136
137 // setters
138 void SetColour(const wxColour& colour) { m_colour = colour; }
139 void SetBold( bool set ) { m_bold = set; }
140 void SetItalic( bool set ) { m_italic = set; }
141
142 // accessors
143 bool HasColour() const { return m_colour.Ok(); }
144 const wxColour& GetColour() const { return m_colour; }
145
146 bool GetBold() const { return m_bold; }
147 bool GetItalic() const { return m_italic; }
148
149 private:
150 wxColour m_colour;
151 bool m_bold;
152 bool m_italic;
153 };
154
155
156 // ---------------------------------------------------------
157 // wxDataViewModel
158 // ---------------------------------------------------------
159
160 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier, wxDataViewModelNotifiers,
161 class WXDLLIMPEXP_ADV);
162
163 class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData
164 {
165 public:
166 wxDataViewModel();
167
168 virtual unsigned int GetColumnCount() const = 0;
169
170 // return type as reported by wxVariant
171 virtual wxString GetColumnType( unsigned int col ) const = 0;
172
173 // get value into a wxVariant
174 virtual void GetValue( wxVariant &variant,
175 const wxDataViewItem &item, unsigned int col ) const = 0;
176
177 // set value, call ValueChanged() afterwards!
178 virtual bool SetValue( const wxVariant &variant,
179 const wxDataViewItem &item, unsigned int col ) = 0;
180
181 // Get text attribute, return false of default attributes should be used
182 virtual bool GetAttr( const wxDataViewItem &WXUNUSED(item), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
183 { return false; }
184
185 // define hierachy
186 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
187 virtual bool IsContainer( const wxDataViewItem &item ) const = 0;
188 // Is the container just a header or an item with all columns
189 virtual bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const
190 { return false; }
191 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const = 0;
192
193 // delegated notifiers
194 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
195 virtual bool ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items );
196 virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item );
197 virtual bool ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items );
198 virtual bool ItemChanged( const wxDataViewItem &item );
199 virtual bool ItemsChanged( const wxDataViewItemArray &items );
200 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
201 virtual bool Cleared();
202
203 // delegatd action
204 virtual void Resort();
205
206 void AddNotifier( wxDataViewModelNotifier *notifier );
207 void RemoveNotifier( wxDataViewModelNotifier *notifier );
208
209 // default compare function
210 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
211 unsigned int column, bool ascending );
212 virtual bool HasDefaultCompare() const { return false; }
213
214 protected:
215 // the user should not delete this class directly: he should use DecRef() instead!
216 virtual ~wxDataViewModel() { }
217
218 wxDataViewModelNotifiers m_notifiers;
219 };
220
221 // ---------------------------------------------------------
222 // wxDataViewIndexListModel
223 // ---------------------------------------------------------
224
225 class WXDLLIMPEXP_ADV wxDataViewIndexListModel: public wxDataViewModel
226 {
227 public:
228 wxDataViewIndexListModel( unsigned int initial_size = 0 );
229 ~wxDataViewIndexListModel();
230
231 virtual unsigned int GetRowCount() = 0;
232
233 virtual void GetValue( wxVariant &variant,
234 unsigned int row, unsigned int col ) const = 0;
235
236 virtual bool SetValue( const wxVariant &variant,
237 unsigned int row, unsigned int col ) = 0;
238
239 virtual bool GetAttr( unsigned int WXUNUSED(row), unsigned int WXUNUSED(col), wxDataViewItemAttr &WXUNUSED(attr) )
240 { return false; }
241
242 void RowPrepended();
243 void RowInserted( unsigned int before );
244 void RowAppended();
245 void RowDeleted( unsigned int row );
246 void RowChanged( unsigned int row );
247 void RowValueChanged( unsigned int row, unsigned int col );
248
249 // convert to/from row/wxDataViewItem
250
251 unsigned int GetRow( const wxDataViewItem &item ) const;
252 wxDataViewItem GetItem( unsigned int row ) const;
253
254 // compare based on index
255
256 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
257 unsigned int column, bool ascending );
258 virtual bool HasDefaultCompare() const;
259
260 // implement base methods
261
262 virtual void GetValue( wxVariant &variant,
263 const wxDataViewItem &item, unsigned int col ) const;
264 virtual bool SetValue( const wxVariant &variant,
265 const wxDataViewItem &item, unsigned int col );
266 virtual bool GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr );
267 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
268 virtual bool IsContainer( const wxDataViewItem &item ) const;
269 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
270
271 private:
272 wxDataViewItemArray m_hash;
273 unsigned int m_lastIndex;
274 bool m_ordered;
275 };
276
277
278 //-----------------------------------------------------------------------------
279 // wxDataViewEditorCtrlEvtHandler
280 //-----------------------------------------------------------------------------
281
282 class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
283 {
284 public:
285 wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
286
287 void AcceptChangesAndFinish();
288 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
289
290 protected:
291 void OnChar( wxKeyEvent &event );
292 void OnKillFocus( wxFocusEvent &event );
293 void OnIdle( wxIdleEvent &event );
294
295 private:
296 wxDataViewRenderer *m_owner;
297 wxControl *m_editorCtrl;
298 bool m_finished;
299 bool m_focusOnIdle;
300
301 private:
302 DECLARE_EVENT_TABLE()
303 };
304
305 // ---------------------------------------------------------
306 // wxDataViewRendererBase
307 // ---------------------------------------------------------
308
309 enum wxDataViewCellMode
310 {
311 wxDATAVIEW_CELL_INERT,
312 wxDATAVIEW_CELL_ACTIVATABLE,
313 wxDATAVIEW_CELL_EDITABLE
314 };
315
316 enum wxDataViewCellRenderState
317 {
318 wxDATAVIEW_CELL_SELECTED = 1,
319 wxDATAVIEW_CELL_PRELIT = 2,
320 wxDATAVIEW_CELL_INSENSITIVE = 4,
321 wxDATAVIEW_CELL_FOCUSED = 8
322 };
323
324 class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
325 {
326 public:
327 wxDataViewRendererBase( const wxString &varianttype,
328 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
329 int alignment = wxDVR_DEFAULT_ALIGNMENT );
330
331 virtual bool Validate( wxVariant& WXUNUSED(value) )
332 { return true; }
333
334 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
335 wxDataViewColumn* GetOwner() { return m_owner; }
336
337 // renderer properties:
338
339 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
340 virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
341
342 wxString GetVariantType() const { return m_variantType; }
343
344 virtual void SetMode( wxDataViewCellMode mode ) = 0;
345 virtual wxDataViewCellMode GetMode() const = 0;
346
347 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
348 // rather an "int"; that's because for rendering cells it's allowed
349 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
350 virtual void SetAlignment( int align ) = 0;
351 virtual int GetAlignment() const = 0;
352
353 // in-place editing
354 virtual bool HasEditorCtrl()
355 { return false; }
356 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
357 wxRect WXUNUSED(labelRect),
358 const wxVariant& WXUNUSED(value))
359 { return NULL; }
360 virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
361 wxVariant& WXUNUSED(value))
362 { return false; }
363
364 virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
365 virtual void CancelEditing();
366 virtual bool FinishEditing();
367
368 wxControl *GetEditorCtrl() { return m_editorCtrl; }
369
370 protected:
371 wxString m_variantType;
372 wxDataViewColumn *m_owner;
373 wxControl *m_editorCtrl;
374 wxDataViewItem m_item; // for m_editorCtrl
375
376 // internal utility:
377 const wxDataViewCtrl* GetView() const;
378
379 protected:
380 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
381 };
382
383 //-----------------------------------------------------------------------------
384 // wxDataViewIconText
385 //-----------------------------------------------------------------------------
386
387 class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject
388 {
389 public:
390 wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon )
391 { m_icon = icon; m_text = text; }
392 wxDataViewIconText( const wxDataViewIconText &other )
393 { m_icon = other.m_icon; m_text = other.m_text; }
394
395 void SetText( const wxString &text ) { m_text = text; }
396 wxString GetText() const { return m_text; }
397 void SetIcon( const wxIcon &icon ) { m_icon = icon; }
398 const wxIcon &GetIcon() const { return m_icon; }
399
400 private:
401 wxString m_text;
402 wxIcon m_icon;
403
404 private:
405 DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
406 };
407
408 bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two);
409
410 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
411
412 // ---------------------------------------------------------
413 // wxDataViewColumnBase
414 // ---------------------------------------------------------
415
416 enum wxDataViewColumnFlags
417 {
418 wxDATAVIEW_COL_RESIZABLE = 1,
419 wxDATAVIEW_COL_SORTABLE = 2,
420 wxDATAVIEW_COL_HIDDEN = 4
421 };
422
423 class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject
424 {
425 public:
426 wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer,
427 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
428 wxAlignment align = wxALIGN_CENTER,
429 int flags = wxDATAVIEW_COL_RESIZABLE );
430 wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
431 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
432 wxAlignment align = wxALIGN_CENTER,
433 int flags = wxDATAVIEW_COL_RESIZABLE );
434 virtual ~wxDataViewColumnBase();
435
436 // setters:
437
438 virtual void SetTitle( const wxString &title ) = 0;
439 virtual void SetAlignment( wxAlignment align ) = 0;
440 virtual void SetSortable( bool sortable ) = 0;
441 virtual void SetResizeable( bool resizeable ) = 0;
442 virtual void SetHidden( bool hidden ) = 0;
443 virtual void SetSortOrder( bool ascending ) = 0;
444 virtual void SetFlags( int flags );
445 virtual void SetOwner( wxDataViewCtrl *owner )
446 { m_owner = owner; }
447 virtual void SetBitmap( const wxBitmap &bitmap )
448 { m_bitmap=bitmap; }
449
450 virtual void SetMinWidth( int minWidth ) = 0;
451 virtual void SetWidth( int width ) = 0;
452
453
454 // getters:
455
456 virtual wxString GetTitle() const = 0;
457 virtual wxAlignment GetAlignment() const = 0;
458 virtual int GetWidth() const = 0;
459 virtual int GetMinWidth() const = 0;
460
461 virtual int GetFlags() const;
462
463 virtual bool IsSortable() const = 0;
464 virtual bool IsResizeable() const = 0;
465 virtual bool IsHidden() const = 0;
466 virtual bool IsSortOrderAscending() const = 0;
467
468 const wxBitmap &GetBitmap() const { return m_bitmap; }
469 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); }
470
471 wxDataViewCtrl *GetOwner() { return m_owner; }
472 wxDataViewRenderer* GetRenderer() { return m_renderer; }
473
474 protected:
475 wxDataViewRenderer *m_renderer;
476 int m_model_column;
477 wxBitmap m_bitmap;
478 wxDataViewCtrl *m_owner;
479
480 protected:
481 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
482 };
483
484 // ---------------------------------------------------------
485 // wxDataViewCtrlBase
486 // ---------------------------------------------------------
487
488 #define wxDV_SINGLE 0x0000 // for convenience
489 #define wxDV_MULTIPLE 0x0001 // can select multiple items
490
491 #define wxDV_NO_HEADER 0x0002 // column titles not visible
492 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
493 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
494
495 class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
496 {
497 public:
498 wxDataViewCtrlBase();
499 virtual ~wxDataViewCtrlBase();
500
501 virtual bool AssociateModel( wxDataViewModel *model );
502 wxDataViewModel* GetModel();
503
504 // short cuts
505 wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column,
506 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
507 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
508 int flags = wxDATAVIEW_COL_RESIZABLE );
509 wxDataViewColumn *PrependIconTextColumn( const wxString &label, unsigned int model_column,
510 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
511 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
512 int flags = wxDATAVIEW_COL_RESIZABLE );
513 wxDataViewColumn *PrependToggleColumn( const wxString &label, unsigned int model_column,
514 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
515 wxAlignment align = wxALIGN_CENTER,
516 int flags = wxDATAVIEW_COL_RESIZABLE );
517 wxDataViewColumn *PrependProgressColumn( const wxString &label, unsigned int model_column,
518 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
519 wxAlignment align = wxALIGN_CENTER,
520 int flags = wxDATAVIEW_COL_RESIZABLE );
521 wxDataViewColumn *PrependDateColumn( const wxString &label, unsigned int model_column,
522 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
523 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
524 int flags = wxDATAVIEW_COL_RESIZABLE );
525 wxDataViewColumn *PrependBitmapColumn( const wxString &label, unsigned int model_column,
526 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
527 wxAlignment align = wxALIGN_CENTER,
528 int flags = wxDATAVIEW_COL_RESIZABLE );
529 wxDataViewColumn *PrependTextColumn( const wxBitmap &label, unsigned int model_column,
530 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
531 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
532 int flags = wxDATAVIEW_COL_RESIZABLE );
533 wxDataViewColumn *PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
534 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
535 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
536 int flags = wxDATAVIEW_COL_RESIZABLE );
537 wxDataViewColumn *PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
538 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
539 wxAlignment align = wxALIGN_CENTER,
540 int flags = wxDATAVIEW_COL_RESIZABLE );
541 wxDataViewColumn *PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
542 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
543 wxAlignment align = wxALIGN_CENTER,
544 int flags = wxDATAVIEW_COL_RESIZABLE );
545 wxDataViewColumn *PrependDateColumn( const wxBitmap &label, unsigned int model_column,
546 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
547 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
548 int flags = wxDATAVIEW_COL_RESIZABLE );
549 wxDataViewColumn *PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
550 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
551 wxAlignment align = wxALIGN_CENTER,
552 int flags = wxDATAVIEW_COL_RESIZABLE );
553
554 wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column,
555 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
556 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
557 int flags = wxDATAVIEW_COL_RESIZABLE );
558 wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column,
559 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
560 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
561 int flags = wxDATAVIEW_COL_RESIZABLE );
562 wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column,
563 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
564 wxAlignment align = wxALIGN_CENTER,
565 int flags = wxDATAVIEW_COL_RESIZABLE );
566 wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column,
567 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
568 wxAlignment align = wxALIGN_CENTER,
569 int flags = wxDATAVIEW_COL_RESIZABLE );
570 wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column,
571 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
572 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
573 int flags = wxDATAVIEW_COL_RESIZABLE );
574 wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column,
575 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
576 wxAlignment align = wxALIGN_CENTER,
577 int flags = wxDATAVIEW_COL_RESIZABLE );
578 wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column,
579 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
580 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
581 int flags = wxDATAVIEW_COL_RESIZABLE );
582 wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
583 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
584 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
585 int flags = wxDATAVIEW_COL_RESIZABLE );
586 wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
587 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
588 wxAlignment align = wxALIGN_CENTER,
589 int flags = wxDATAVIEW_COL_RESIZABLE );
590 wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
591 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
592 wxAlignment align = wxALIGN_CENTER,
593 int flags = wxDATAVIEW_COL_RESIZABLE );
594 wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column,
595 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
596 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
597 int flags = wxDATAVIEW_COL_RESIZABLE );
598 wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
599 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
600 wxAlignment align = wxALIGN_CENTER,
601 int flags = wxDATAVIEW_COL_RESIZABLE );
602
603
604 virtual bool PrependColumn( wxDataViewColumn *col );
605 virtual bool AppendColumn( wxDataViewColumn *col );
606
607 virtual unsigned int GetColumnCount() const = 0;
608 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0;
609 virtual int GetColumnPosition( const wxDataViewColumn *column ) const = 0;
610
611 virtual bool DeleteColumn( wxDataViewColumn *column ) = 0;
612 virtual bool ClearColumns() = 0;
613
614 void SetExpanderColumn( wxDataViewColumn *col )
615 { m_expander_column = col ; DoSetExpanderColumn(); }
616 wxDataViewColumn *GetExpanderColumn() const
617 { return m_expander_column; }
618
619 virtual wxDataViewColumn *GetSortingColumn() const = 0;
620
621 void SetIndent( int indent )
622 { m_indent = indent ; DoSetIndent(); }
623 int GetIndent() const
624 { return m_indent; }
625
626 virtual wxDataViewItem GetSelection() const = 0;
627 virtual int GetSelections( wxDataViewItemArray & sel ) const = 0;
628 virtual void SetSelections( const wxDataViewItemArray & sel ) = 0;
629 virtual void Select( const wxDataViewItem & item ) = 0;
630 virtual void Unselect( const wxDataViewItem & item ) = 0;
631 virtual bool IsSelected( const wxDataViewItem & item ) const = 0;
632
633 virtual void SelectAll() = 0;
634 virtual void UnselectAll() = 0;
635
636 virtual void Expand( const wxDataViewItem & item ) = 0;
637 virtual void Collapse( const wxDataViewItem & item ) = 0;
638
639 virtual void EnsureVisible( const wxDataViewItem & item,
640 const wxDataViewColumn *column = NULL ) = 0;
641 virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
642 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;
643
644 protected:
645 virtual void DoSetExpanderColumn() = 0 ;
646 virtual void DoSetIndent() = 0;
647
648 private:
649 wxDataViewModel *m_model;
650 wxDataViewColumn *m_expander_column;
651 int m_indent ;
652
653 protected:
654 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
655 };
656
657 // ----------------------------------------------------------------------------
658 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
659 // ----------------------------------------------------------------------------
660
661 class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
662 {
663 public:
664 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
665 : wxNotifyEvent(commandType, winid),
666 m_item(0),
667 m_col(-1),
668 m_model(NULL),
669 m_value(wxNullVariant),
670 m_column(NULL)
671 { }
672
673 wxDataViewEvent(const wxDataViewEvent& event)
674 : wxNotifyEvent(event),
675 m_item(event.m_item),
676 m_col(event.m_col),
677 m_model(event.m_model),
678 m_value(event.m_value),
679 m_column(event.m_column)
680 { }
681
682 wxDataViewItem GetItem() const { return m_item; }
683 void SetItem( const wxDataViewItem &item ) { m_item = item; }
684
685 int GetColumn() const { return m_col; }
686 void SetColumn( int col ) { m_col = col; }
687
688 wxDataViewModel* GetModel() const { return m_model; }
689 void SetModel( wxDataViewModel *model ) { m_model = model; }
690
691 const wxVariant &GetValue() const { return m_value; }
692 void SetValue( const wxVariant &value ) { m_value = value; }
693
694 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
695 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
696 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
697
698 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
699
700 protected:
701 wxDataViewItem m_item;
702 int m_col;
703 wxDataViewModel *m_model;
704 wxVariant m_value;
705 wxDataViewColumn *m_column;
706
707 private:
708 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
709 };
710
711 BEGIN_DECLARE_EVENT_TYPES()
712 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, -1)
713
714 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, -1)
715 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, -1)
716 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, -1)
717 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, -1)
718 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, -1)
719 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, -1)
720 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, -1)
721 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, -1)
722
723 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1)
724 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1)
725 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, -1)
726 END_DECLARE_EVENT_TYPES()
727
728 typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
729
730 #define wxDataViewEventHandler(func) \
731 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
732
733 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
734 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
735
736 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
737
738 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
739 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
740 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
741 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
742 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
743 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
744 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
745 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
746
747 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
748 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
749 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
750
751 #if defined(wxUSE_GENERICDATAVIEWCTRL)
752 #include "wx/generic/dataview.h"
753 #elif defined(__WXGTK20__)
754 #include "wx/gtk/dataview.h"
755 #elif defined(__WXMAC__)
756 #include "wx/mac/dataview.h"
757 #else
758 #include "wx/generic/dataview.h"
759 #endif
760
761 // -------------------------------------
762 // wxDataViewSpinRenderer
763 // -------------------------------------
764
765 class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer
766 {
767 public:
768 wxDataViewSpinRenderer( int min, int max,
769 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
770 int alignment = wxDVR_DEFAULT_ALIGNMENT );
771 virtual bool HasEditorCtrl() { return true; }
772 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
773 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
774 virtual bool Render( wxRect rect, wxDC *dc, int state );
775 virtual wxSize GetSize() const;
776 virtual bool SetValue( const wxVariant &value );
777 virtual bool GetValue( wxVariant &value ) const;
778
779 private:
780 long m_data;
781 long m_min,m_max;
782 };
783
784 //-----------------------------------------------------------------------------
785 // wxDataViewTreeStore
786 //-----------------------------------------------------------------------------
787
788 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
789 {
790 public:
791 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent,
792 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
793 virtual ~wxDataViewTreeStoreNode();
794
795 void SetText( const wxString &text )
796 { m_text = text; }
797 wxString GetText() const
798 { return m_text; }
799 void SetIcon( const wxIcon &icon )
800 { m_icon = icon; }
801 const wxIcon &GetIcon() const
802 { return m_icon; }
803 void SetData( wxClientData *data )
804 { if (m_data) delete m_data; m_data = data; }
805 wxClientData *GetData() const
806 { return m_data; }
807
808 wxDataViewItem GetItem() const
809 { return wxDataViewItem( (void*) this ); }
810
811 virtual bool IsContainer()
812 { return false; }
813
814 wxDataViewTreeStoreNode *GetParent()
815 { return m_parent; }
816
817 private:
818 wxDataViewTreeStoreNode *m_parent;
819 wxString m_text;
820 wxIcon m_icon;
821 wxClientData *m_data;
822 };
823
824 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList,
825 class WXDLLIMPEXP_ADV);
826
827 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode
828 {
829 public:
830 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent,
831 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
832 wxClientData *data = NULL );
833 virtual ~wxDataViewTreeStoreContainerNode();
834
835 const wxDataViewTreeStoreNodeList &GetChildren() const
836 { return m_children; }
837 wxDataViewTreeStoreNodeList &GetChildren()
838 { return m_children; }
839
840 void SetExpandedIcon( const wxIcon &icon )
841 { m_iconExpanded = icon; }
842 const wxIcon &GetExpandedIcon() const
843 { return m_iconExpanded; }
844
845 virtual bool IsContainer()
846 { return true; }
847
848 private:
849 wxDataViewTreeStoreNodeList m_children;
850 wxIcon m_iconExpanded;
851 };
852
853 //-----------------------------------------------------------------------------
854
855 class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel
856 {
857 public:
858 wxDataViewTreeStore();
859 ~wxDataViewTreeStore();
860
861 wxDataViewItem AppendItem( const wxDataViewItem& parent,
862 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
863 wxDataViewItem PrependItem( const wxDataViewItem& parent,
864 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
865 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
866 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
867
868 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
869 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
870 wxClientData *data = NULL );
871 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
872 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
873 wxClientData *data = NULL );
874 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
875 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
876 wxClientData *data = NULL );
877
878 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const;
879 int GetChildCount( const wxDataViewItem& parent ) const;
880
881 void SetItemText( const wxDataViewItem& item, const wxString &text );
882 wxString GetItemText( const wxDataViewItem& item ) const;
883 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
884 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const;
885 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
886 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const;
887 void SetItemData( const wxDataViewItem& item, wxClientData *data );
888 wxClientData *GetItemData( const wxDataViewItem& item ) const;
889
890 void DeleteItem( const wxDataViewItem& item );
891 void DeleteChildren( const wxDataViewItem& item );
892 void DeleteAllItems();
893
894 // implement base methods
895
896 virtual void GetValue( wxVariant &variant,
897 const wxDataViewItem &item, unsigned int col ) const;
898 virtual bool SetValue( const wxVariant &variant,
899 const wxDataViewItem &item, unsigned int col );
900 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
901 virtual bool IsContainer( const wxDataViewItem &item ) const;
902 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
903
904 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
905 unsigned int column, bool ascending );
906
907 virtual bool HasDefaultCompare() const
908 { return true; }
909 virtual unsigned int GetColumnCount() const
910 { return 1; };
911 virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
912 { return "wxDataViewIconText"; }
913
914 wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const;
915 wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const;
916 wxDataViewTreeStoreNode *GetRoot() const { return m_root; }
917
918 public:
919 wxDataViewTreeStoreNode *m_root;
920 };
921
922 #if 0
923 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
924 {
925 public:
926 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
927 const wxPoint& pos = wxDefaultPosition,
928 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER,
929 const wxValidator& validator = wxDefaultValidator );
930
931 bool Create( wxWindow *parent, wxWindowID id,
932 const wxPoint& pos = wxDefaultPosition,
933 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER,
934 const wxValidator& validator = wxDefaultValidator );
935
936 wxDataViewTreeStore *GetStore()
937 { return (wxDataViewTreeStore*) GetModel(); }
938
939 void OnExpand( wxDataViewCtrl &event );
940 void OnCollapse( wxDataViewCtrl &event );
941
942 private:
943 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl)
944 };
945 #endif
946
947 #endif // wxUSE_DATAVIEWCTRL
948
949 #endif
950 // _WX_DATAVIEW_H_BASE_