]>
Commit | Line | Data |
---|---|---|
bcd846ea RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/dataview.h | |
3 | // Purpose: wxDataViewCtrl base classes | |
4 | // Author: Robert Roebling | |
b7e9f8b1 | 5 | // Modified by: Bo Yang |
bcd846ea RR |
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 | ||
239eaa41 RR |
19 | #include "wx/control.h" |
20 | #include "wx/textctrl.h" | |
21 | #include "wx/bitmap.h" | |
64ffb888 | 22 | #include "wx/variant.h" |
b9b8b59c | 23 | #include "wx/listctrl.h" |
b7e9f8b1 | 24 | #include "wx/dynarray.h" |
4ed7af08 RR |
25 | |
26 | #if defined(__WXGTK20__) | |
27 | // for testing | |
e98351ec | 28 | // #define wxUSE_GENERICDATAVIEWCTRL 1 |
4ed7af08 | 29 | #elif defined(__WXMAC__) |
4ed7af08 RR |
30 | #else |
31 | #define wxUSE_GENERICDATAVIEWCTRL 1 | |
32 | #endif | |
33 | ||
bcd846ea | 34 | // ---------------------------------------------------------------------------- |
f554a14b | 35 | // wxDataViewCtrl flags |
bcd846ea RR |
36 | // ---------------------------------------------------------------------------- |
37 | ||
239eaa41 RR |
38 | // ---------------------------------------------------------------------------- |
39 | // wxDataViewCtrl globals | |
40 | // ---------------------------------------------------------------------------- | |
bcd846ea | 41 | |
b5dbe15d VS |
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; | |
fa28826d | 48 | |
f460c29d | 49 | extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[]; |
bcd846ea | 50 | |
87f0efe2 RR |
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 | ||
9861f022 RR |
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_TOP) | |
62 | ||
87f0efe2 | 63 | |
f554a14b | 64 | // --------------------------------------------------------- |
e0062c04 | 65 | // wxDataViewItem |
f554a14b | 66 | // --------------------------------------------------------- |
239eaa41 | 67 | |
e0062c04 | 68 | class WXDLLIMPEXP_ADV wxDataViewItem |
239eaa41 RR |
69 | { |
70 | public: | |
9d52aad3 RR |
71 | wxDataViewItem( void* id = NULL ) |
72 | { m_id = id; } | |
e0062c04 | 73 | wxDataViewItem( const wxDataViewItem &item ) |
9d52aad3 RR |
74 | { m_id = item.m_id; } |
75 | bool IsOk() const { return m_id != NULL; } | |
76 | void* GetID() const { return m_id; } | |
e0062c04 | 77 | |
8f850e28 | 78 | private: |
9d52aad3 | 79 | void* m_id; |
64ffb888 | 80 | }; |
239eaa41 | 81 | |
d5025dc0 | 82 | bool operator == (const wxDataViewItem &left, const wxDataViewItem &right); |
aba9bfd0 | 83 | |
9d8fe14a RR |
84 | // --------------------------------------------------------- |
85 | // wxDataViewModelNotifier | |
86 | // --------------------------------------------------------- | |
87 | ||
88 | class WXDLLIMPEXP_ADV wxDataViewModelNotifier | |
89 | { | |
90 | public: | |
91 | wxDataViewModelNotifier() { } | |
92 | virtual ~wxDataViewModelNotifier() { m_owner = NULL; } | |
93 | ||
94 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0; | |
95 | virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0; | |
96 | virtual bool ItemChanged( const wxDataViewItem &item ) = 0; | |
97 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0; | |
98 | virtual bool Cleared() = 0; | |
99 | ||
d3f00f59 | 100 | virtual void Resort() = 0; |
9d8fe14a RR |
101 | |
102 | void SetOwner( wxDataViewModel *owner ) { m_owner = owner; } | |
103 | wxDataViewModel *GetOwner() { return m_owner; } | |
104 | ||
105 | private: | |
106 | wxDataViewModel *m_owner; | |
107 | }; | |
108 | ||
109 | ||
f554a14b | 110 | // --------------------------------------------------------- |
e0062c04 | 111 | // wxDataViewModel |
f554a14b | 112 | // --------------------------------------------------------- |
239eaa41 | 113 | |
9d8fe14a RR |
114 | WX_DECLARE_LIST(wxDataViewModelNotifier, wxDataViewModelNotifiers ); |
115 | ||
e0062c04 | 116 | class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData |
239eaa41 RR |
117 | { |
118 | public: | |
e0062c04 | 119 | wxDataViewModel(); |
239eaa41 | 120 | |
9861f022 | 121 | virtual unsigned int GetColumnCount() const = 0; |
87f0efe2 | 122 | |
a7f61f76 | 123 | // return type as reported by wxVariant |
9861f022 | 124 | virtual wxString GetColumnType( unsigned int col ) const = 0; |
87f0efe2 | 125 | |
a7f61f76 | 126 | // get value into a wxVariant |
e0062c04 RR |
127 | virtual void GetValue( wxVariant &variant, |
128 | const wxDataViewItem &item, unsigned int col ) const = 0; | |
87f0efe2 | 129 | |
a7f61f76 | 130 | // set value, call ValueChanged() afterwards! |
e0062c04 RR |
131 | virtual bool SetValue( const wxVariant &variant, |
132 | const wxDataViewItem &item, unsigned int col ) = 0; | |
239eaa41 | 133 | |
e0062c04 | 134 | // define hierachy |
ed903e42 RR |
135 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0; |
136 | virtual bool IsContainer( const wxDataViewItem &item ) const = 0; | |
e0062c04 RR |
137 | virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const = 0; |
138 | virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const = 0; | |
b9b8b59c | 139 | |
239eaa41 | 140 | // delegated notifiers |
e0062c04 | 141 | virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ); |
469d3e9b | 142 | virtual bool ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item ); |
e0062c04 RR |
143 | virtual bool ItemChanged( const wxDataViewItem &item ); |
144 | virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ); | |
8981608c | 145 | virtual bool Cleared(); |
b5d777c7 | 146 | |
ef427989 RR |
147 | // delegatd action |
148 | virtual void Resort(); | |
149 | ||
e0062c04 RR |
150 | void AddNotifier( wxDataViewModelNotifier *notifier ); |
151 | void RemoveNotifier( wxDataViewModelNotifier *notifier ); | |
63415a42 | 152 | |
ef427989 | 153 | // default compare function |
7ee7191c RR |
154 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, |
155 | unsigned int column, bool ascending ); | |
5732efaa | 156 | |
87f0efe2 RR |
157 | protected: |
158 | // the user should not delete this class directly: he should use DecRef() instead! | |
5debbdcf | 159 | virtual ~wxDataViewModel() { } |
87f0efe2 | 160 | |
9d8fe14a | 161 | wxDataViewModelNotifiers m_notifiers; |
ef427989 RR |
162 | }; |
163 | ||
164 | // --------------------------------------------------------- | |
c534e696 | 165 | // wxDataViewIndexListModel |
ef427989 RR |
166 | // --------------------------------------------------------- |
167 | ||
c534e696 RR |
168 | // use hash map later |
169 | WX_DEFINE_ARRAY_PTR( void*, wxDataViewItemHash ); | |
170 | ||
ef427989 RR |
171 | class wxDataViewIndexListModel: public wxDataViewModel |
172 | { | |
173 | public: | |
c534e696 | 174 | wxDataViewIndexListModel( unsigned int initial_size = 0 ); |
ef427989 RR |
175 | ~wxDataViewIndexListModel(); |
176 | ||
177 | virtual unsigned int GetRowCount() = 0; | |
178 | ||
179 | virtual void GetValue( wxVariant &variant, | |
180 | unsigned int row, unsigned int col ) const = 0; | |
181 | ||
182 | virtual bool SetValue( const wxVariant &variant, | |
183 | unsigned int row, unsigned int col ) = 0; | |
184 | ||
c534e696 RR |
185 | void RowPrepended(); |
186 | void RowInserted( unsigned int before ); | |
187 | void RowAppended(); | |
188 | void RowDeleted( unsigned int row ); | |
189 | void RowChanged( unsigned int row ); | |
190 | void RowValueChanged( unsigned int row, unsigned int col ); | |
191 | ||
192 | // convert to/from row/wxDataViewItem | |
ef427989 | 193 | |
c534e696 RR |
194 | unsigned int GetRow( const wxDataViewItem &item ) const; |
195 | wxDataViewItem GetItem( unsigned int row ) const; | |
196 | ||
197 | // compare based on index | |
ef427989 | 198 | |
7ee7191c RR |
199 | virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2, |
200 | unsigned int column, bool ascending ); | |
c534e696 RR |
201 | |
202 | // implement base methods | |
203 | ||
204 | virtual void GetValue( wxVariant &variant, | |
205 | const wxDataViewItem &item, unsigned int col ) const; | |
206 | virtual bool SetValue( const wxVariant &variant, | |
207 | const wxDataViewItem &item, unsigned int col ); | |
208 | virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const; | |
209 | virtual bool IsContainer( const wxDataViewItem &item ) const; | |
210 | virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const; | |
211 | virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const; | |
ef427989 | 212 | |
c534e696 RR |
213 | private: |
214 | wxDataViewItemHash m_hash; | |
215 | unsigned int m_lastIndex; | |
239eaa41 RR |
216 | }; |
217 | ||
1e510b1e RR |
218 | //----------------------------------------------------------------------------- |
219 | // wxDataViewEditorCtrlEvtHandler | |
220 | //----------------------------------------------------------------------------- | |
221 | ||
222 | class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler | |
223 | { | |
224 | public: | |
225 | wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner ); | |
226 | ||
227 | void AcceptChangesAndFinish(); | |
30715fa1 | 228 | void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; } |
1e510b1e RR |
229 | |
230 | protected: | |
231 | void OnChar( wxKeyEvent &event ); | |
232 | void OnKillFocus( wxFocusEvent &event ); | |
30715fa1 | 233 | void OnIdle( wxIdleEvent &event ); |
1e510b1e RR |
234 | |
235 | private: | |
236 | wxDataViewRenderer *m_owner; | |
237 | wxControl *m_editorCtrl; | |
238 | bool m_finished; | |
30715fa1 | 239 | bool m_focusOnIdle; |
1e510b1e RR |
240 | |
241 | private: | |
242 | DECLARE_EVENT_TABLE() | |
243 | }; | |
244 | ||
f554a14b | 245 | // --------------------------------------------------------- |
baa9ebc4 | 246 | // wxDataViewRendererBase |
f554a14b | 247 | // --------------------------------------------------------- |
fa28826d | 248 | |
6842a71a | 249 | enum wxDataViewCellMode |
fa28826d | 250 | { |
6842a71a RR |
251 | wxDATAVIEW_CELL_INERT, |
252 | wxDATAVIEW_CELL_ACTIVATABLE, | |
253 | wxDATAVIEW_CELL_EDITABLE | |
fa28826d RR |
254 | }; |
255 | ||
6842a71a RR |
256 | enum wxDataViewCellRenderState |
257 | { | |
258 | wxDATAVIEW_CELL_SELECTED = 1, | |
259 | wxDATAVIEW_CELL_PRELIT = 2, | |
260 | wxDATAVIEW_CELL_INSENSITIVE = 4, | |
261 | wxDATAVIEW_CELL_FOCUSED = 8 | |
262 | }; | |
263 | ||
baa9ebc4 | 264 | class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject |
6842a71a RR |
265 | { |
266 | public: | |
9861f022 RR |
267 | wxDataViewRendererBase( const wxString &varianttype, |
268 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
269 | int alignment = wxDVR_DEFAULT_ALIGNMENT ); | |
6842a71a | 270 | |
9861f022 RR |
271 | virtual bool Validate( wxVariant& WXUNUSED(value) ) |
272 | { return true; } | |
f554a14b | 273 | |
6842a71a RR |
274 | void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; } |
275 | wxDataViewColumn* GetOwner() { return m_owner; } | |
f554a14b | 276 | |
9861f022 RR |
277 | // renderer properties: |
278 | ||
279 | virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0; | |
280 | virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0; | |
281 | ||
282 | wxString GetVariantType() const { return m_variantType; } | |
283 | ||
284 | virtual void SetMode( wxDataViewCellMode mode ) = 0; | |
285 | virtual wxDataViewCellMode GetMode() const = 0; | |
286 | ||
287 | // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but | |
288 | // rather an "int"; that's because for rendering cells it's allowed | |
289 | // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM) | |
290 | virtual void SetAlignment( int align ) = 0; | |
291 | virtual int GetAlignment() const = 0; | |
99d471a5 | 292 | |
1e510b1e RR |
293 | // in-place editing |
294 | virtual bool HasEditorCtrl() | |
295 | { return false; } | |
96c2a0dd VZ |
296 | virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent), |
297 | wxRect WXUNUSED(labelRect), | |
298 | const wxVariant& WXUNUSED(value)) | |
1e510b1e | 299 | { return NULL; } |
96c2a0dd VZ |
300 | virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor), |
301 | wxVariant& WXUNUSED(value)) | |
1e510b1e RR |
302 | { return false; } |
303 | ||
e0062c04 | 304 | virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect ); |
1e510b1e RR |
305 | virtual void CancelEditing(); |
306 | virtual bool FinishEditing(); | |
307 | ||
308 | wxControl *GetEditorCtrl() { return m_editorCtrl; } | |
309 | ||
a7f61f76 | 310 | protected: |
6842a71a RR |
311 | wxString m_variantType; |
312 | wxDataViewColumn *m_owner; | |
1e510b1e | 313 | wxControl *m_editorCtrl; |
e0062c04 | 314 | wxDataViewItem m_item; // for m_editorCtrl |
6842a71a | 315 | |
9861f022 RR |
316 | // internal utility: |
317 | const wxDataViewCtrl* GetView() const; | |
318 | ||
6842a71a | 319 | protected: |
baa9ebc4 | 320 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase) |
6842a71a RR |
321 | }; |
322 | ||
f554a14b | 323 | // --------------------------------------------------------- |
6842a71a | 324 | // wxDataViewColumnBase |
f554a14b | 325 | // --------------------------------------------------------- |
6842a71a | 326 | |
fa28826d RR |
327 | enum wxDataViewColumnFlags |
328 | { | |
329 | wxDATAVIEW_COL_RESIZABLE = 1, | |
330 | wxDATAVIEW_COL_SORTABLE = 2, | |
331 | wxDATAVIEW_COL_HIDDEN = 4 | |
332 | }; | |
333 | ||
f460c29d | 334 | class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject |
fa28826d RR |
335 | { |
336 | public: | |
87f0efe2 RR |
337 | wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer, |
338 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
339 | wxAlignment align = wxALIGN_CENTER, | |
340 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
341 | wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer, | |
342 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
343 | wxAlignment align = wxALIGN_CENTER, | |
344 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
d3c7fc99 | 345 | virtual ~wxDataViewColumnBase(); |
fa28826d | 346 | |
9861f022 | 347 | // setters: |
07b6378f | 348 | |
9861f022 | 349 | virtual void SetTitle( const wxString &title ) = 0; |
47cef10f | 350 | virtual void SetAlignment( wxAlignment align ) = 0; |
31fb32e1 | 351 | virtual void SetSortable( bool sortable ) = 0; |
9861f022 RR |
352 | virtual void SetResizeable( bool resizeable ) = 0; |
353 | virtual void SetHidden( bool hidden ) = 0; | |
47cef10f | 354 | virtual void SetSortOrder( bool ascending ) = 0; |
9861f022 RR |
355 | virtual void SetFlags( int flags ); |
356 | virtual void SetOwner( wxDataViewCtrl *owner ) | |
357 | { m_owner = owner; } | |
358 | virtual void SetBitmap( const wxBitmap &bitmap ) | |
359 | { m_bitmap=bitmap; } | |
07a84e7b | 360 | |
9861f022 RR |
361 | virtual void SetMinWidth( int minWidth ) = 0; |
362 | virtual void SetWidth( int width ) = 0; | |
f554a14b | 363 | |
f554a14b | 364 | |
9861f022 | 365 | // getters: |
07b6378f | 366 | |
9861f022 RR |
367 | virtual wxString GetTitle() const = 0; |
368 | virtual wxAlignment GetAlignment() const = 0; | |
87f0efe2 | 369 | virtual int GetWidth() const = 0; |
9861f022 | 370 | virtual int GetMinWidth() const = 0; |
07b6378f | 371 | |
9861f022 RR |
372 | virtual int GetFlags() const; |
373 | ||
374 | virtual bool IsSortable() const = 0; | |
375 | virtual bool IsResizeable() const = 0; | |
376 | virtual bool IsHidden() const = 0; | |
377 | virtual bool IsSortOrderAscending() const = 0; | |
378 | ||
379 | const wxBitmap &GetBitmap() const { return m_bitmap; } | |
380 | unsigned int GetModelColumn() const { return m_model_column; } | |
381 | ||
382 | wxDataViewCtrl *GetOwner() { return m_owner; } | |
383 | wxDataViewRenderer* GetRenderer() { return m_renderer; } | |
384 | ||
385 | protected: | |
baa9ebc4 | 386 | wxDataViewRenderer *m_renderer; |
6842a71a | 387 | int m_model_column; |
07a84e7b | 388 | wxBitmap m_bitmap; |
6842a71a | 389 | wxDataViewCtrl *m_owner; |
fa28826d RR |
390 | |
391 | protected: | |
392 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase) | |
393 | }; | |
394 | ||
f554a14b | 395 | // --------------------------------------------------------- |
239eaa41 | 396 | // wxDataViewCtrlBase |
f554a14b | 397 | // --------------------------------------------------------- |
239eaa41 | 398 | |
b7e9f8b1 RR |
399 | WX_DECLARE_OBJARRAY(wxDataViewItem, wxDataViewItemArray); |
400 | ||
c21f7aa1 | 401 | #define wxDV_SINGLE 0x0000 // for convenience |
9861f022 RR |
402 | #define wxDV_MULTIPLE 0x0001 // can select multiple items |
403 | ||
404 | #define wxDV_NO_HEADER 0x0002 // column titles not visible | |
405 | #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows | |
406 | #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns | |
c21f7aa1 | 407 | |
f460c29d | 408 | class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl |
239eaa41 RR |
409 | { |
410 | public: | |
411 | wxDataViewCtrlBase(); | |
d3c7fc99 | 412 | virtual ~wxDataViewCtrlBase(); |
f554a14b | 413 | |
e0062c04 RR |
414 | virtual bool AssociateModel( wxDataViewModel *model ); |
415 | wxDataViewModel* GetModel(); | |
f554a14b | 416 | |
07a84e7b | 417 | // short cuts |
1286b7ba | 418 | bool AppendTextColumn( const wxString &label, unsigned int model_column, |
87f0efe2 RR |
419 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, |
420 | wxAlignment align = wxALIGN_CENTER, | |
421 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1286b7ba | 422 | bool AppendToggleColumn( const wxString &label, unsigned int model_column, |
87f0efe2 RR |
423 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, |
424 | wxAlignment align = wxALIGN_CENTER, | |
425 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1286b7ba | 426 | bool AppendProgressColumn( const wxString &label, unsigned int model_column, |
87f0efe2 RR |
427 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, |
428 | wxAlignment align = wxALIGN_CENTER, | |
429 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1286b7ba | 430 | bool AppendDateColumn( const wxString &label, unsigned int model_column, |
87f0efe2 RR |
431 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, |
432 | wxAlignment align = wxALIGN_CENTER, | |
433 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1286b7ba | 434 | bool AppendBitmapColumn( const wxString &label, unsigned int model_column, |
87f0efe2 RR |
435 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, |
436 | wxAlignment align = wxALIGN_CENTER, | |
437 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1286b7ba | 438 | bool AppendTextColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 RR |
439 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, |
440 | wxAlignment align = wxALIGN_CENTER, | |
441 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1286b7ba | 442 | bool AppendToggleColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 RR |
443 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, |
444 | wxAlignment align = wxALIGN_CENTER, | |
445 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1286b7ba | 446 | bool AppendProgressColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 RR |
447 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, |
448 | wxAlignment align = wxALIGN_CENTER, | |
449 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1286b7ba | 450 | bool AppendDateColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 RR |
451 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, |
452 | wxAlignment align = wxALIGN_CENTER, | |
453 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
1286b7ba | 454 | bool AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, |
87f0efe2 RR |
455 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, |
456 | wxAlignment align = wxALIGN_CENTER, | |
457 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
07a84e7b | 458 | |
f554a14b | 459 | virtual bool AppendColumn( wxDataViewColumn *col ); |
9861f022 RR |
460 | |
461 | virtual unsigned int GetColumnCount() const; | |
462 | ||
0a71f9e9 | 463 | virtual bool DeleteColumn( unsigned int pos ); |
fa28826d | 464 | virtual bool ClearColumns(); |
0a71f9e9 | 465 | virtual wxDataViewColumn* GetColumn( unsigned int pos ); |
f554a14b | 466 | |
3b6280be RR |
467 | void SetExpanderColumn( unsigned int col ) |
468 | { m_expander_column = col ; DoSetExpanderColumn(); } | |
469 | unsigned int GetExpanderColumn() const | |
470 | { return m_expander_column; } | |
471 | ||
472 | void SetIndent( int indent ) | |
473 | { m_indent = indent ; DoSetIndent(); } | |
474 | int GetIndent() const | |
475 | { return m_indent; } | |
476 | ||
e98351ec | 477 | virtual wxDataViewItem GetSelection() = 0; |
b7e9f8b1 RR |
478 | virtual int GetSelections( wxDataViewItemArray & sel ) const = 0; |
479 | virtual void SetSelections( const wxDataViewItemArray & sel ) = 0; | |
480 | virtual void Select( const wxDataViewItem & item ) = 0; | |
481 | virtual void Unselect( const wxDataViewItem & item ) = 0; | |
482 | virtual bool IsSelected( const wxDataViewItem & item ) const = 0; | |
483 | ||
b7e9f8b1 RR |
484 | virtual void SelectAll() = 0; |
485 | virtual void UnselectAll() = 0; | |
486 | ||
6154212e RR |
487 | virtual void EnsureVisible( const wxDataViewItem & item, |
488 | wxDataViewColumn *column = NULL ) = 0; | |
b7e9f8b1 | 489 | |
3b6280be RR |
490 | protected: |
491 | virtual void DoSetExpanderColumn() = 0 ; | |
492 | virtual void DoSetIndent() = 0; | |
493 | ||
239eaa41 | 494 | private: |
e0062c04 | 495 | wxDataViewModel *m_model; |
fa28826d | 496 | wxList m_cols; |
3b6280be RR |
497 | unsigned int m_expander_column; |
498 | int m_indent ; | |
499 | ||
239eaa41 | 500 | protected: |
260b9be7 | 501 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase) |
239eaa41 | 502 | }; |
bcd846ea | 503 | |
eb7f97f8 RR |
504 | // ---------------------------------------------------------------------------- |
505 | // wxDataViewEvent - the event class for the wxDataViewCtrl notifications | |
506 | // ---------------------------------------------------------------------------- | |
507 | ||
2f799ae8 | 508 | class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent |
eb7f97f8 RR |
509 | { |
510 | public: | |
511 | wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) | |
512 | : wxNotifyEvent(commandType, winid), | |
e0062c04 | 513 | m_item(0), |
eb7f97f8 | 514 | m_col(-1), |
eb7f97f8 RR |
515 | m_model(NULL), |
516 | m_value(wxNullVariant), | |
31fb32e1 | 517 | m_column(NULL) |
eb7f97f8 RR |
518 | { } |
519 | ||
520 | wxDataViewEvent(const wxDataViewEvent& event) | |
521 | : wxNotifyEvent(event), | |
e0062c04 | 522 | m_item(event.m_item), |
eb7f97f8 | 523 | m_col(event.m_col), |
eb7f97f8 RR |
524 | m_model(event.m_model), |
525 | m_value(event.m_value), | |
31fb32e1 | 526 | m_column(event.m_column) |
eb7f97f8 RR |
527 | { } |
528 | ||
e0062c04 RR |
529 | wxDataViewItem GetItem() const { return m_item; } |
530 | void SetItem( const wxDataViewItem &item ) { m_item = item; } | |
531 | ||
eb7f97f8 RR |
532 | int GetColumn() const { return m_col; } |
533 | void SetColumn( int col ) { m_col = col; } | |
9861f022 | 534 | |
eb7f97f8 RR |
535 | wxDataViewModel* GetModel() const { return m_model; } |
536 | void SetModel( wxDataViewModel *model ) { m_model = model; } | |
9861f022 | 537 | |
eb7f97f8 RR |
538 | const wxVariant &GetValue() const { return m_value; } |
539 | void SetValue( const wxVariant &value ) { m_value = value; } | |
540 | ||
31fb32e1 RR |
541 | // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only |
542 | void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; } | |
9861f022 | 543 | wxDataViewColumn *GetDataViewColumn() const { return m_column; } |
31fb32e1 | 544 | |
eb7f97f8 RR |
545 | virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); } |
546 | ||
547 | protected: | |
e0062c04 | 548 | wxDataViewItem m_item; |
eb7f97f8 | 549 | int m_col; |
eb7f97f8 RR |
550 | wxDataViewModel *m_model; |
551 | wxVariant m_value; | |
31fb32e1 | 552 | wxDataViewColumn *m_column; |
eb7f97f8 RR |
553 | |
554 | private: | |
555 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent) | |
556 | }; | |
557 | ||
558 | BEGIN_DECLARE_EVENT_TYPES() | |
e0062c04 | 559 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, -1) |
e98351ec | 560 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_DESELECTED, -1) |
e0062c04 | 561 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, -1) |
d209a914 RR |
562 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, -1) |
563 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, -1) | |
6977c3bf RR |
564 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, -1) |
565 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, -1) | |
e07c1146 PC |
566 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1) |
567 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1) | |
c0a66d92 | 568 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, -1) |
1821abd1 | 569 | // notifications from the model to the control |
e0062c04 RR |
570 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED, -1) |
571 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, -1) | |
572 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED, -1) | |
1821abd1 | 573 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, -1) |
1821abd1 | 574 | DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED, -1) |
eb7f97f8 RR |
575 | END_DECLARE_EVENT_TYPES() |
576 | ||
577 | typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&); | |
578 | ||
579 | #define wxDataViewEventHandler(func) \ | |
580 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func) | |
581 | ||
582 | #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \ | |
583 | wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn)) | |
584 | ||
e0062c04 | 585 | #define EVT_DATAVIEW_ITEM_SELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_SELECTED, id, fn) |
e98351ec | 586 | #define EVT_DATAVIEW_ITEM_DESELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_DESELECTED, id, fn) |
e0062c04 | 587 | #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn) |
6977c3bf | 588 | #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn) |
3ecb8a53 | 589 | #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn) |
6977c3bf | 590 | #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn) |
3ecb8a53 | 591 | #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn) |
31fb32e1 RR |
592 | #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn) |
593 | #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn) | |
c0a66d92 | 594 | #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn) |
eb7f97f8 | 595 | |
d8331a01 | 596 | #define EVT_DATAVIEW_MODEL_ITEM_ADDED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_ADDED, id, fn) |
e0062c04 RR |
597 | #define EVT_DATAVIEW_MODEL_ITEM_DELETED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_DELETED, id, fn) |
598 | #define EVT_DATAVIEW_MODEL_ITEM_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_CHANGED, id, fn) | |
1821abd1 | 599 | #define EVT_DATAVIEW_MODEL_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_VALUE_CHANGED, id, fn) |
1821abd1 RR |
600 | #define EVT_DATAVIEW_MODEL_CLEARED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_CLEARED, id, fn) |
601 | ||
eb7f97f8 | 602 | |
4ed7af08 RR |
603 | #if defined(wxUSE_GENERICDATAVIEWCTRL) |
604 | #include "wx/generic/dataview.h" | |
605 | #elif defined(__WXGTK20__) | |
bcd846ea RR |
606 | #include "wx/gtk/dataview.h" |
607 | #elif defined(__WXMAC__) | |
c0a66d92 | 608 | #include "wx/mac/dataview.h" |
bcd846ea RR |
609 | #else |
610 | #include "wx/generic/dataview.h" | |
611 | #endif | |
612 | ||
613 | #endif // wxUSE_DATAVIEWCTRL | |
614 | ||
615 | #endif | |
616 | // _WX_DATAVIEW_H_BASE_ |