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