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