]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dataview.h
use more natively looking HildonNote instead of GtkMessageDialog under Maemo
[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 { return true; }
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 };
275
276
277 //-----------------------------------------------------------------------------
278 // wxDataViewEditorCtrlEvtHandler
279 //-----------------------------------------------------------------------------
280
281 class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
282 {
283 public:
284 wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
285
286 void AcceptChangesAndFinish();
287 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
288
289 protected:
290 void OnChar( wxKeyEvent &event );
291 void OnKillFocus( wxFocusEvent &event );
292 void OnIdle( wxIdleEvent &event );
293
294 private:
295 wxDataViewRenderer *m_owner;
296 wxControl *m_editorCtrl;
297 bool m_finished;
298 bool m_focusOnIdle;
299
300 private:
301 DECLARE_EVENT_TABLE()
302 };
303
304 // ---------------------------------------------------------
305 // wxDataViewRendererBase
306 // ---------------------------------------------------------
307
308 enum wxDataViewCellMode
309 {
310 wxDATAVIEW_CELL_INERT,
311 wxDATAVIEW_CELL_ACTIVATABLE,
312 wxDATAVIEW_CELL_EDITABLE
313 };
314
315 enum wxDataViewCellRenderState
316 {
317 wxDATAVIEW_CELL_SELECTED = 1,
318 wxDATAVIEW_CELL_PRELIT = 2,
319 wxDATAVIEW_CELL_INSENSITIVE = 4,
320 wxDATAVIEW_CELL_FOCUSED = 8
321 };
322
323 class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
324 {
325 public:
326 wxDataViewRendererBase( const wxString &varianttype,
327 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
328 int alignment = wxDVR_DEFAULT_ALIGNMENT );
329
330 virtual bool Validate( wxVariant& WXUNUSED(value) )
331 { return true; }
332
333 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
334 wxDataViewColumn* GetOwner() { return m_owner; }
335
336 // renderer properties:
337
338 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
339 virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
340
341 wxString GetVariantType() const { return m_variantType; }
342
343 virtual void SetMode( wxDataViewCellMode mode ) = 0;
344 virtual wxDataViewCellMode GetMode() const = 0;
345
346 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
347 // rather an "int"; that's because for rendering cells it's allowed
348 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
349 virtual void SetAlignment( int align ) = 0;
350 virtual int GetAlignment() const = 0;
351
352 // in-place editing
353 virtual bool HasEditorCtrl()
354 { return false; }
355 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
356 wxRect WXUNUSED(labelRect),
357 const wxVariant& WXUNUSED(value))
358 { return NULL; }
359 virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
360 wxVariant& WXUNUSED(value))
361 { return false; }
362
363 virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
364 virtual void CancelEditing();
365 virtual bool FinishEditing();
366
367 wxControl *GetEditorCtrl() { return m_editorCtrl; }
368
369 protected:
370 wxString m_variantType;
371 wxDataViewColumn *m_owner;
372 wxControl *m_editorCtrl;
373 wxDataViewItem m_item; // for m_editorCtrl
374
375 // internal utility:
376 const wxDataViewCtrl* GetView() const;
377
378 protected:
379 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
380 };
381
382 //-----------------------------------------------------------------------------
383 // wxDataViewIconText
384 //-----------------------------------------------------------------------------
385
386 class WXDLLIMPEXP_ADV wxDataViewIconText: public wxObject
387 {
388 public:
389 wxDataViewIconText( const wxString &text = wxEmptyString, const wxIcon& icon = wxNullIcon )
390 { m_icon = icon; m_text = text; }
391 wxDataViewIconText( const wxDataViewIconText &other )
392 { m_icon = other.m_icon; m_text = other.m_text; }
393
394 void SetText( const wxString &text ) { m_text = text; }
395 wxString GetText() const { return m_text; }
396 void SetIcon( const wxIcon &icon ) { m_icon = icon; }
397 const wxIcon &GetIcon() const { return m_icon; }
398
399 private:
400 wxString m_text;
401 wxIcon m_icon;
402
403 private:
404 DECLARE_DYNAMIC_CLASS(wxDataViewIconText)
405 };
406
407 bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two);
408
409 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
410
411 // ---------------------------------------------------------
412 // wxDataViewColumnBase
413 // ---------------------------------------------------------
414
415 enum wxDataViewColumnFlags
416 {
417 wxDATAVIEW_COL_RESIZABLE = 1,
418 wxDATAVIEW_COL_SORTABLE = 2,
419 wxDATAVIEW_COL_HIDDEN = 4
420 };
421
422 class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject
423 {
424 public:
425 wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer,
426 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
427 wxAlignment align = wxALIGN_CENTER,
428 int flags = wxDATAVIEW_COL_RESIZABLE );
429 wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
430 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
431 wxAlignment align = wxALIGN_CENTER,
432 int flags = wxDATAVIEW_COL_RESIZABLE );
433 virtual ~wxDataViewColumnBase();
434
435 // setters:
436
437 virtual void SetTitle( const wxString &title ) = 0;
438 virtual void SetAlignment( wxAlignment align ) = 0;
439 virtual void SetSortable( bool sortable ) = 0;
440 virtual void SetResizeable( bool resizeable ) = 0;
441 virtual void SetHidden( bool hidden ) = 0;
442 virtual void SetSortOrder( bool ascending ) = 0;
443 virtual void SetFlags( int flags );
444 virtual void SetOwner( wxDataViewCtrl *owner )
445 { m_owner = owner; }
446 virtual void SetBitmap( const wxBitmap &bitmap )
447 { m_bitmap=bitmap; }
448
449 virtual void SetMinWidth( int minWidth ) = 0;
450 virtual void SetWidth( int width ) = 0;
451
452
453 // getters:
454
455 virtual wxString GetTitle() const = 0;
456 virtual wxAlignment GetAlignment() const = 0;
457 virtual int GetWidth() const = 0;
458 virtual int GetMinWidth() const = 0;
459
460 virtual int GetFlags() const;
461
462 virtual bool IsSortable() const = 0;
463 virtual bool IsResizeable() const = 0;
464 virtual bool IsHidden() const = 0;
465 virtual bool IsSortOrderAscending() const = 0;
466
467 const wxBitmap &GetBitmap() const { return m_bitmap; }
468 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column); }
469
470 wxDataViewCtrl *GetOwner() { return m_owner; }
471 wxDataViewRenderer* GetRenderer() { return m_renderer; }
472
473 protected:
474 wxDataViewRenderer *m_renderer;
475 int m_model_column;
476 wxBitmap m_bitmap;
477 wxDataViewCtrl *m_owner;
478
479 protected:
480 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
481 };
482
483 // ---------------------------------------------------------
484 // wxDataViewCtrlBase
485 // ---------------------------------------------------------
486
487 #define wxDV_SINGLE 0x0000 // for convenience
488 #define wxDV_MULTIPLE 0x0001 // can select multiple items
489
490 #define wxDV_NO_HEADER 0x0002 // column titles not visible
491 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
492 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
493
494 class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
495 {
496 public:
497 wxDataViewCtrlBase();
498 virtual ~wxDataViewCtrlBase();
499
500 virtual bool AssociateModel( wxDataViewModel *model );
501 wxDataViewModel* GetModel();
502
503 // short cuts
504 wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column,
505 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
506 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
507 int flags = wxDATAVIEW_COL_RESIZABLE );
508 wxDataViewColumn *PrependIconTextColumn( const wxString &label, unsigned int model_column,
509 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
510 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
511 int flags = wxDATAVIEW_COL_RESIZABLE );
512 wxDataViewColumn *PrependToggleColumn( const wxString &label, unsigned int model_column,
513 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
514 wxAlignment align = wxALIGN_CENTER,
515 int flags = wxDATAVIEW_COL_RESIZABLE );
516 wxDataViewColumn *PrependProgressColumn( const wxString &label, unsigned int model_column,
517 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
518 wxAlignment align = wxALIGN_CENTER,
519 int flags = wxDATAVIEW_COL_RESIZABLE );
520 wxDataViewColumn *PrependDateColumn( const wxString &label, unsigned int model_column,
521 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
522 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
523 int flags = wxDATAVIEW_COL_RESIZABLE );
524 wxDataViewColumn *PrependBitmapColumn( const wxString &label, unsigned int model_column,
525 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
526 wxAlignment align = wxALIGN_CENTER,
527 int flags = wxDATAVIEW_COL_RESIZABLE );
528 wxDataViewColumn *PrependTextColumn( const wxBitmap &label, unsigned int model_column,
529 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
530 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
531 int flags = wxDATAVIEW_COL_RESIZABLE );
532 wxDataViewColumn *PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
533 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
534 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
535 int flags = wxDATAVIEW_COL_RESIZABLE );
536 wxDataViewColumn *PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
537 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
538 wxAlignment align = wxALIGN_CENTER,
539 int flags = wxDATAVIEW_COL_RESIZABLE );
540 wxDataViewColumn *PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
541 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
542 wxAlignment align = wxALIGN_CENTER,
543 int flags = wxDATAVIEW_COL_RESIZABLE );
544 wxDataViewColumn *PrependDateColumn( const wxBitmap &label, unsigned int model_column,
545 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
546 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
547 int flags = wxDATAVIEW_COL_RESIZABLE );
548 wxDataViewColumn *PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
549 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
550 wxAlignment align = wxALIGN_CENTER,
551 int flags = wxDATAVIEW_COL_RESIZABLE );
552
553 wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column,
554 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
555 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
556 int flags = wxDATAVIEW_COL_RESIZABLE );
557 wxDataViewColumn *AppendIconTextColumn( const wxString &label, unsigned int model_column,
558 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
559 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
560 int flags = wxDATAVIEW_COL_RESIZABLE );
561 wxDataViewColumn *AppendToggleColumn( const wxString &label, unsigned int model_column,
562 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
563 wxAlignment align = wxALIGN_CENTER,
564 int flags = wxDATAVIEW_COL_RESIZABLE );
565 wxDataViewColumn *AppendProgressColumn( const wxString &label, unsigned int model_column,
566 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
567 wxAlignment align = wxALIGN_CENTER,
568 int flags = wxDATAVIEW_COL_RESIZABLE );
569 wxDataViewColumn *AppendDateColumn( const wxString &label, unsigned int model_column,
570 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
571 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
572 int flags = wxDATAVIEW_COL_RESIZABLE );
573 wxDataViewColumn *AppendBitmapColumn( const wxString &label, unsigned int model_column,
574 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
575 wxAlignment align = wxALIGN_CENTER,
576 int flags = wxDATAVIEW_COL_RESIZABLE );
577 wxDataViewColumn *AppendTextColumn( const wxBitmap &label, unsigned int model_column,
578 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
579 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
580 int flags = wxDATAVIEW_COL_RESIZABLE );
581 wxDataViewColumn *AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
582 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
583 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
584 int flags = wxDATAVIEW_COL_RESIZABLE );
585 wxDataViewColumn *AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
586 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
587 wxAlignment align = wxALIGN_CENTER,
588 int flags = wxDATAVIEW_COL_RESIZABLE );
589 wxDataViewColumn *AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
590 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
591 wxAlignment align = wxALIGN_CENTER,
592 int flags = wxDATAVIEW_COL_RESIZABLE );
593 wxDataViewColumn *AppendDateColumn( const wxBitmap &label, unsigned int model_column,
594 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
595 wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL),
596 int flags = wxDATAVIEW_COL_RESIZABLE );
597 wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
598 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
599 wxAlignment align = wxALIGN_CENTER,
600 int flags = wxDATAVIEW_COL_RESIZABLE );
601
602
603 virtual bool PrependColumn( wxDataViewColumn *col );
604 virtual bool AppendColumn( wxDataViewColumn *col );
605
606 virtual unsigned int GetColumnCount() const = 0;
607 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const = 0;
608 virtual int GetColumnPosition( const wxDataViewColumn *column ) const = 0;
609
610 virtual bool DeleteColumn( wxDataViewColumn *column ) = 0;
611 virtual bool ClearColumns() = 0;
612
613 void SetExpanderColumn( wxDataViewColumn *col )
614 { m_expander_column = col ; DoSetExpanderColumn(); }
615 wxDataViewColumn *GetExpanderColumn() const
616 { return m_expander_column; }
617
618 virtual wxDataViewColumn *GetSortingColumn() const = 0;
619
620 void SetIndent( int indent )
621 { m_indent = indent ; DoSetIndent(); }
622 int GetIndent() const
623 { return m_indent; }
624
625 virtual wxDataViewItem GetSelection() const = 0;
626 virtual int GetSelections( wxDataViewItemArray & sel ) const = 0;
627 virtual void SetSelections( const wxDataViewItemArray & sel ) = 0;
628 virtual void Select( const wxDataViewItem & item ) = 0;
629 virtual void Unselect( const wxDataViewItem & item ) = 0;
630 virtual bool IsSelected( const wxDataViewItem & item ) const = 0;
631
632 virtual void SelectAll() = 0;
633 virtual void UnselectAll() = 0;
634
635 virtual void Expand( const wxDataViewItem & item ) = 0;
636 virtual void Collapse( const wxDataViewItem & item ) = 0;
637
638 virtual void EnsureVisible( const wxDataViewItem & item,
639 const wxDataViewColumn *column = NULL ) = 0;
640 virtual void HitTest( const wxPoint & point, wxDataViewItem &item, wxDataViewColumn* &column ) const = 0;
641 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const = 0;
642
643 protected:
644 virtual void DoSetExpanderColumn() = 0 ;
645 virtual void DoSetIndent() = 0;
646
647 private:
648 wxDataViewModel *m_model;
649 wxDataViewColumn *m_expander_column;
650 int m_indent ;
651
652 protected:
653 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
654 };
655
656 // ----------------------------------------------------------------------------
657 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
658 // ----------------------------------------------------------------------------
659
660 class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
661 {
662 public:
663 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
664 : wxNotifyEvent(commandType, winid),
665 m_item(0),
666 m_col(-1),
667 m_model(NULL),
668 m_value(wxNullVariant),
669 m_column(NULL)
670 { }
671
672 wxDataViewEvent(const wxDataViewEvent& event)
673 : wxNotifyEvent(event),
674 m_item(event.m_item),
675 m_col(event.m_col),
676 m_model(event.m_model),
677 m_value(event.m_value),
678 m_column(event.m_column)
679 { }
680
681 wxDataViewItem GetItem() const { return m_item; }
682 void SetItem( const wxDataViewItem &item ) { m_item = item; }
683
684 int GetColumn() const { return m_col; }
685 void SetColumn( int col ) { m_col = col; }
686
687 wxDataViewModel* GetModel() const { return m_model; }
688 void SetModel( wxDataViewModel *model ) { m_model = model; }
689
690 const wxVariant &GetValue() const { return m_value; }
691 void SetValue( const wxVariant &value ) { m_value = value; }
692
693 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
694 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
695 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
696
697 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
698
699 protected:
700 wxDataViewItem m_item;
701 int m_col;
702 wxDataViewModel *m_model;
703 wxVariant m_value;
704 wxDataViewColumn *m_column;
705
706 private:
707 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
708 };
709
710 BEGIN_DECLARE_EVENT_TYPES()
711 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, -1)
712
713 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, -1)
714 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, -1)
715 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, -1)
716 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, -1)
717 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, -1)
718 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, -1)
719 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, -1)
720 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, -1)
721
722 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1)
723 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1)
724 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, -1)
725 END_DECLARE_EVENT_TYPES()
726
727 typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
728
729 #define wxDataViewEventHandler(func) \
730 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
731
732 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
733 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
734
735 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
736
737 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
738 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
739 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
740 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
741 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
742 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
743 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
744 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
745
746 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
747 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
748 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
749
750 #if defined(wxUSE_GENERICDATAVIEWCTRL)
751 #include "wx/generic/dataview.h"
752 #elif defined(__WXGTK20__)
753 #include "wx/gtk/dataview.h"
754 #elif defined(__WXMAC__)
755 #include "wx/mac/dataview.h"
756 #else
757 #include "wx/generic/dataview.h"
758 #endif
759
760 // -------------------------------------
761 // wxDataViewSpinRenderer
762 // -------------------------------------
763
764 class WXDLLIMPEXP_ADV wxDataViewSpinRenderer: public wxDataViewCustomRenderer
765 {
766 public:
767 wxDataViewSpinRenderer( int min, int max,
768 wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
769 int alignment = wxDVR_DEFAULT_ALIGNMENT );
770 virtual bool HasEditorCtrl() { return true; }
771 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
772 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
773 virtual bool Render( wxRect rect, wxDC *dc, int state );
774 virtual wxSize GetSize() const;
775 virtual bool SetValue( const wxVariant &value );
776 virtual bool GetValue( wxVariant &value ) const;
777
778 private:
779 long m_data;
780 long m_min,m_max;
781 };
782
783 //-----------------------------------------------------------------------------
784 // wxDataViewTreeStore
785 //-----------------------------------------------------------------------------
786
787 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
788 {
789 public:
790 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode *parent,
791 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
792 virtual ~wxDataViewTreeStoreNode();
793
794 void SetText( const wxString &text )
795 { m_text = text; }
796 wxString GetText() const
797 { return m_text; }
798 void SetIcon( const wxIcon &icon )
799 { m_icon = icon; }
800 const wxIcon &GetIcon() const
801 { return m_icon; }
802 void SetData( wxClientData *data )
803 { if (m_data) delete m_data; m_data = data; }
804 wxClientData *GetData() const
805 { return m_data; }
806
807 wxDataViewItem GetItem() const
808 { return wxDataViewItem( (void*) this ); }
809
810 virtual bool IsContainer()
811 { return false; }
812
813 wxDataViewTreeStoreNode *GetParent()
814 { return m_parent; }
815
816 private:
817 wxDataViewTreeStoreNode *m_parent;
818 wxString m_text;
819 wxIcon m_icon;
820 wxClientData *m_data;
821 };
822
823 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode, wxDataViewTreeStoreNodeList,
824 class WXDLLIMPEXP_ADV);
825
826 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode: public wxDataViewTreeStoreNode
827 {
828 public:
829 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode *parent,
830 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
831 wxClientData *data = NULL );
832 virtual ~wxDataViewTreeStoreContainerNode();
833
834 const wxDataViewTreeStoreNodeList &GetChildren() const
835 { return m_children; }
836 wxDataViewTreeStoreNodeList &GetChildren()
837 { return m_children; }
838
839 void SetExpandedIcon( const wxIcon &icon )
840 { m_iconExpanded = icon; }
841 const wxIcon &GetExpandedIcon() const
842 { return m_iconExpanded; }
843
844 virtual bool IsContainer()
845 { return true; }
846
847 private:
848 wxDataViewTreeStoreNodeList m_children;
849 wxIcon m_iconExpanded;
850 };
851
852 //-----------------------------------------------------------------------------
853
854 class WXDLLIMPEXP_ADV wxDataViewTreeStore: public wxDataViewModel
855 {
856 public:
857 wxDataViewTreeStore();
858 ~wxDataViewTreeStore();
859
860 wxDataViewItem AppendItem( const wxDataViewItem& parent,
861 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
862 wxDataViewItem PrependItem( const wxDataViewItem& parent,
863 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
864 wxDataViewItem InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
865 const wxString &text, const wxIcon &icon = wxNullIcon, wxClientData *data = NULL );
866
867 wxDataViewItem PrependContainer( const wxDataViewItem& parent,
868 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
869 wxClientData *data = NULL );
870 wxDataViewItem AppendContainer( const wxDataViewItem& parent,
871 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
872 wxClientData *data = NULL );
873 wxDataViewItem InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
874 const wxString &text, const wxIcon &icon = wxNullIcon, const wxIcon &expanded = wxNullIcon,
875 wxClientData *data = NULL );
876
877 wxDataViewItem GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const;
878 int GetChildCount( const wxDataViewItem& parent ) const;
879
880 void SetItemText( const wxDataViewItem& item, const wxString &text );
881 wxString GetItemText( const wxDataViewItem& item ) const;
882 void SetItemIcon( const wxDataViewItem& item, const wxIcon &icon );
883 const wxIcon &GetItemIcon( const wxDataViewItem& item ) const;
884 void SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon );
885 const wxIcon &GetItemExpandedIcon( const wxDataViewItem& item ) const;
886 void SetItemData( const wxDataViewItem& item, wxClientData *data );
887 wxClientData *GetItemData( const wxDataViewItem& item ) const;
888
889 void DeleteItem( const wxDataViewItem& item );
890 void DeleteChildren( const wxDataViewItem& item );
891 void DeleteAllItems();
892
893 // implement base methods
894
895 virtual void GetValue( wxVariant &variant,
896 const wxDataViewItem &item, unsigned int col ) const;
897 virtual bool SetValue( const wxVariant &variant,
898 const wxDataViewItem &item, unsigned int col );
899 virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
900 virtual bool IsContainer( const wxDataViewItem &item ) const;
901 virtual unsigned int GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const;
902
903 virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
904 unsigned int column, bool ascending );
905
906 virtual bool HasDefaultCompare() const
907 { return true; }
908 virtual unsigned int GetColumnCount() const
909 { return 1; };
910 virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
911 { return "wxDataViewIconText"; }
912
913 wxDataViewTreeStoreNode *FindNode( const wxDataViewItem &item ) const;
914 wxDataViewTreeStoreContainerNode *FindContainerNode( const wxDataViewItem &item ) const;
915 wxDataViewTreeStoreNode *GetRoot() const { return m_root; }
916
917 public:
918 wxDataViewTreeStoreNode *m_root;
919 };
920
921 #if 0
922 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl: public wxDataViewCtrl
923 {
924 public:
925 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
926 const wxPoint& pos = wxDefaultPosition,
927 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER,
928 const wxValidator& validator = wxDefaultValidator );
929
930 bool Create( wxWindow *parent, wxWindowID id,
931 const wxPoint& pos = wxDefaultPosition,
932 const wxSize& size = wxDefaultSize, long style = wxDV_NO_HEADER,
933 const wxValidator& validator = wxDefaultValidator );
934
935 wxDataViewTreeStore *GetStore()
936 { return (wxDataViewTreeStore*) GetModel(); }
937
938 void OnExpand( wxDataViewCtrl &event );
939 void OnCollapse( wxDataViewCtrl &event );
940
941 private:
942 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl)
943 };
944 #endif
945
946 #endif // wxUSE_DATAVIEWCTRL
947
948 #endif
949 // _WX_DATAVIEW_H_BASE_