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