]>
Commit | Line | Data |
---|---|---|
4ed7af08 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/generic/dataview.h | |
3 | // Purpose: wxDataViewCtrl generic implementation header | |
4 | // Author: Robert Roebling | |
b7e9f8b1 | 5 | // Modified By: Bo Yang |
4ed7af08 RR |
6 | // Id: $Id$ |
7 | // Copyright: (c) 1998 Robert Roebling | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef __GENERICDATAVIEWCTRLH__ | |
12 | #define __GENERICDATAVIEWCTRLH__ | |
13 | ||
14 | #include "wx/defs.h" | |
15 | #include "wx/object.h" | |
16 | #include "wx/list.h" | |
17 | #include "wx/control.h" | |
9d14de69 | 18 | #include "wx/scrolwin.h" |
2586d4a1 | 19 | #include "wx/icon.h" |
4ed7af08 | 20 | |
f554a14b | 21 | // --------------------------------------------------------- |
4ed7af08 | 22 | // classes |
f554a14b | 23 | // --------------------------------------------------------- |
4ed7af08 | 24 | |
b5dbe15d VS |
25 | class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl; |
26 | class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow; | |
27 | class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow; | |
4ed7af08 | 28 | |
f554a14b | 29 | // --------------------------------------------------------- |
baa9ebc4 | 30 | // wxDataViewRenderer |
f554a14b | 31 | // --------------------------------------------------------- |
4ed7af08 | 32 | |
baa9ebc4 | 33 | class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase |
4ed7af08 RR |
34 | { |
35 | public: | |
87f0efe2 | 36 | wxDataViewRenderer( const wxString &varianttype, |
9861f022 RR |
37 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
38 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
baa9ebc4 | 39 | virtual ~wxDataViewRenderer(); |
4ed7af08 | 40 | |
3d9d7cc4 | 41 | virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0; |
9861f022 RR |
42 | virtual wxSize GetSize() const = 0; |
43 | ||
44 | virtual void SetAlignment( int align ) | |
45 | { m_align=align; } | |
46 | virtual int GetAlignment() const | |
47 | { return m_align; } | |
48 | ||
49 | virtual void SetMode( wxDataViewCellMode mode ) | |
50 | { m_mode=mode; } | |
51 | virtual wxDataViewCellMode GetMode() const | |
52 | { return m_mode; } | |
f554a14b WS |
53 | |
54 | virtual bool Activate( wxRect WXUNUSED(cell), | |
aba9bfd0 | 55 | wxDataViewModel *WXUNUSED(model), |
704c3490 | 56 | const wxDataViewItem & WXUNUSED(item), |
aba9bfd0 | 57 | unsigned int WXUNUSED(col) ) |
3d9d7cc4 | 58 | { return false; } |
f554a14b WS |
59 | |
60 | virtual bool LeftClick( wxPoint WXUNUSED(cursor), | |
61 | wxRect WXUNUSED(cell), | |
aba9bfd0 | 62 | wxDataViewModel *WXUNUSED(model), |
704c3490 | 63 | const wxDataViewItem & WXUNUSED(item), |
aba9bfd0 | 64 | unsigned int WXUNUSED(col) ) |
f554a14b WS |
65 | { return false; } |
66 | virtual bool RightClick( wxPoint WXUNUSED(cursor), | |
67 | wxRect WXUNUSED(cell), | |
aba9bfd0 | 68 | wxDataViewModel *WXUNUSED(model), |
704c3490 | 69 | const wxDataViewItem & WXUNUSED(item), |
aba9bfd0 | 70 | unsigned int WXUNUSED(col) ) |
f554a14b WS |
71 | { return false; } |
72 | virtual bool StartDrag( wxPoint WXUNUSED(cursor), | |
73 | wxRect WXUNUSED(cell), | |
aba9bfd0 | 74 | wxDataViewModel *WXUNUSED(model), |
704c3490 | 75 | const wxDataViewItem & WXUNUSED(item), |
aba9bfd0 | 76 | unsigned int WXUNUSED(col) ) |
f554a14b WS |
77 | { return false; } |
78 | ||
3d9d7cc4 RR |
79 | // Create DC on request |
80 | virtual wxDC *GetDC(); | |
f554a14b | 81 | |
3d9d7cc4 | 82 | private: |
99d471a5 RR |
83 | wxDC *m_dc; |
84 | int m_align; | |
85 | wxDataViewCellMode m_mode; | |
f554a14b | 86 | |
4ed7af08 | 87 | protected: |
baa9ebc4 | 88 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer) |
4ed7af08 | 89 | }; |
f554a14b WS |
90 | |
91 | // --------------------------------------------------------- | |
baa9ebc4 | 92 | // wxDataViewCustomRenderer |
f554a14b | 93 | // --------------------------------------------------------- |
4ed7af08 | 94 | |
baa9ebc4 | 95 | class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer |
4ed7af08 RR |
96 | { |
97 | public: | |
baa9ebc4 | 98 | wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"), |
9861f022 RR |
99 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
100 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
f554a14b | 101 | |
4ed7af08 | 102 | protected: |
baa9ebc4 | 103 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer) |
4ed7af08 | 104 | }; |
f554a14b | 105 | |
99d471a5 | 106 | |
f554a14b | 107 | // --------------------------------------------------------- |
baa9ebc4 | 108 | // wxDataViewTextRenderer |
f554a14b | 109 | // --------------------------------------------------------- |
4ed7af08 | 110 | |
baa9ebc4 | 111 | class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer |
4ed7af08 RR |
112 | { |
113 | public: | |
baa9ebc4 | 114 | wxDataViewTextRenderer( const wxString &varianttype = wxT("string"), |
9861f022 RR |
115 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
116 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
4ed7af08 RR |
117 | |
118 | bool SetValue( const wxVariant &value ); | |
9861f022 | 119 | bool GetValue( wxVariant &value ) const; |
f554a14b | 120 | |
3d9d7cc4 | 121 | bool Render( wxRect cell, wxDC *dc, int state ); |
9861f022 | 122 | wxSize GetSize() const; |
f554a14b | 123 | |
99d471a5 RR |
124 | // in-place editing |
125 | virtual bool HasEditorCtrl(); | |
126 | virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); | |
127 | virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); | |
128 | ||
90675b95 | 129 | private: |
99d471a5 | 130 | wxString m_text; |
f554a14b | 131 | |
4ed7af08 | 132 | protected: |
baa9ebc4 | 133 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer) |
4ed7af08 | 134 | }; |
f554a14b | 135 | |
2586d4a1 | 136 | // --------------------------------------------------------- |
baa9ebc4 | 137 | // wxDataViewBitmapRenderer |
2586d4a1 RR |
138 | // --------------------------------------------------------- |
139 | ||
baa9ebc4 | 140 | class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer |
2586d4a1 RR |
141 | { |
142 | public: | |
baa9ebc4 | 143 | wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"), |
9861f022 RR |
144 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
145 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
2586d4a1 RR |
146 | |
147 | bool SetValue( const wxVariant &value ); | |
9861f022 | 148 | bool GetValue( wxVariant &value ) const; |
2586d4a1 RR |
149 | |
150 | bool Render( wxRect cell, wxDC *dc, int state ); | |
9861f022 | 151 | wxSize GetSize() const; |
2586d4a1 RR |
152 | |
153 | private: | |
154 | wxIcon m_icon; | |
155 | wxBitmap m_bitmap; | |
156 | ||
157 | protected: | |
baa9ebc4 | 158 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer) |
2586d4a1 RR |
159 | }; |
160 | ||
f554a14b | 161 | // --------------------------------------------------------- |
baa9ebc4 | 162 | // wxDataViewToggleRenderer |
f554a14b | 163 | // --------------------------------------------------------- |
4ed7af08 | 164 | |
baa9ebc4 | 165 | class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer |
4ed7af08 RR |
166 | { |
167 | public: | |
baa9ebc4 | 168 | wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"), |
9861f022 RR |
169 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
170 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
3d9d7cc4 RR |
171 | |
172 | bool SetValue( const wxVariant &value ); | |
9861f022 | 173 | bool GetValue( wxVariant &value ) const; |
f554a14b | 174 | |
3d9d7cc4 | 175 | bool Render( wxRect cell, wxDC *dc, int state ); |
aba9bfd0 RR |
176 | bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item, |
177 | unsigned int col ); | |
9861f022 | 178 | wxSize GetSize() const; |
f554a14b | 179 | |
90675b95 RR |
180 | private: |
181 | bool m_toggle; | |
f554a14b | 182 | |
4ed7af08 | 183 | protected: |
baa9ebc4 | 184 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer) |
4ed7af08 | 185 | }; |
f554a14b WS |
186 | |
187 | // --------------------------------------------------------- | |
baa9ebc4 | 188 | // wxDataViewProgressRenderer |
f554a14b | 189 | // --------------------------------------------------------- |
4ed7af08 | 190 | |
baa9ebc4 | 191 | class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer |
4ed7af08 RR |
192 | { |
193 | public: | |
baa9ebc4 RR |
194 | wxDataViewProgressRenderer( const wxString &label = wxEmptyString, |
195 | const wxString &varianttype = wxT("long"), | |
9861f022 RR |
196 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
197 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
baa9ebc4 | 198 | virtual ~wxDataViewProgressRenderer(); |
f554a14b | 199 | |
4ed7af08 | 200 | bool SetValue( const wxVariant &value ); |
9861f022 | 201 | bool GetValue( wxVariant& value ) const; |
f554a14b | 202 | |
4ed7af08 | 203 | virtual bool Render( wxRect cell, wxDC *dc, int state ); |
9861f022 | 204 | virtual wxSize GetSize() const; |
f554a14b | 205 | |
4ed7af08 RR |
206 | private: |
207 | wxString m_label; | |
208 | int m_value; | |
f554a14b | 209 | |
4ed7af08 | 210 | protected: |
baa9ebc4 | 211 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer) |
4ed7af08 | 212 | }; |
f554a14b WS |
213 | |
214 | // --------------------------------------------------------- | |
baa9ebc4 | 215 | // wxDataViewDateRenderer |
f554a14b | 216 | // --------------------------------------------------------- |
4ed7af08 | 217 | |
baa9ebc4 | 218 | class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer |
4ed7af08 RR |
219 | { |
220 | public: | |
baa9ebc4 | 221 | wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"), |
9861f022 RR |
222 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, |
223 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
f554a14b | 224 | |
4ed7af08 | 225 | bool SetValue( const wxVariant &value ); |
9861f022 | 226 | bool GetValue( wxVariant& value ) const; |
f554a14b | 227 | |
4ed7af08 | 228 | virtual bool Render( wxRect cell, wxDC *dc, int state ); |
9861f022 | 229 | virtual wxSize GetSize() const; |
4ed7af08 | 230 | virtual bool Activate( wxRect cell, |
aba9bfd0 | 231 | wxDataViewModel *model, const wxDataViewItem & item, unsigned int col ); |
f554a14b | 232 | |
4ed7af08 RR |
233 | private: |
234 | wxDateTime m_date; | |
f554a14b | 235 | |
4ed7af08 | 236 | protected: |
baa9ebc4 | 237 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer) |
4ed7af08 | 238 | }; |
f554a14b WS |
239 | |
240 | // --------------------------------------------------------- | |
4ed7af08 | 241 | // wxDataViewColumn |
f554a14b | 242 | // --------------------------------------------------------- |
4ed7af08 | 243 | |
f460c29d | 244 | class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase |
4ed7af08 | 245 | { |
87f0efe2 RR |
246 | friend class wxDataViewHeaderWindowBase; |
247 | friend class wxDataViewHeaderWindow; | |
248 | friend class wxDataViewHeaderWindowMSW; | |
249 | ||
4ed7af08 | 250 | public: |
87f0efe2 RR |
251 | wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer, |
252 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
253 | wxAlignment align = wxALIGN_CENTER, | |
254 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
255 | wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer, | |
256 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
257 | wxAlignment align = wxALIGN_CENTER, | |
258 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
4ed7af08 RR |
259 | virtual ~wxDataViewColumn(); |
260 | ||
9861f022 RR |
261 | // setters: |
262 | ||
263 | virtual void SetTitle( const wxString &title ) | |
264 | { m_title=title; } | |
87f0efe2 RR |
265 | virtual void SetAlignment( wxAlignment align ) |
266 | { m_align=align; } | |
9861f022 RR |
267 | virtual void SetMinWidth( int minWidth ) |
268 | { m_minWidth=minWidth; } | |
269 | virtual void SetWidth( int width ); | |
31fb32e1 | 270 | virtual void SetSortable( bool sortable ); |
9861f022 RR |
271 | virtual void SetResizeable( bool resizeable ); |
272 | virtual void SetHidden( bool hidden ); | |
47cef10f | 273 | virtual void SetSortOrder( bool ascending ); |
87f0efe2 | 274 | |
87f0efe2 | 275 | |
9861f022 RR |
276 | // getters: |
277 | ||
278 | virtual wxString GetTitle() const | |
279 | { return m_title; } | |
280 | virtual wxAlignment GetAlignment() const | |
281 | { return m_align; } | |
282 | virtual int GetWidth() const | |
283 | { return m_width; } | |
284 | virtual int GetMinWidth() const | |
285 | { return m_minWidth; } | |
286 | virtual bool IsSortable() const | |
287 | { return (m_flags & wxDATAVIEW_COL_SORTABLE) != 0; } | |
288 | virtual bool IsResizeable() const | |
289 | { return (m_flags & wxDATAVIEW_COL_RESIZABLE) != 0; } | |
290 | virtual bool IsHidden() const | |
291 | { return (m_flags & wxDATAVIEW_COL_HIDDEN) != 0; } | |
292 | virtual bool IsSortOrderAscending() const; | |
f554a14b | 293 | |
f554a14b | 294 | |
4ed7af08 | 295 | private: |
533544f2 | 296 | int m_width; |
9861f022 RR |
297 | int m_minWidth; |
298 | int m_flags; | |
299 | wxAlignment m_align; | |
300 | wxString m_title; | |
c3112d56 | 301 | bool m_ascending; |
87f0efe2 RR |
302 | |
303 | void Init(int width); | |
4ed7af08 | 304 | |
9861f022 RR |
305 | // like SetWidth() but does not ask the header window of the |
306 | // wxDataViewCtrl to reflect the width-change. | |
307 | void SetInternalWidth(int width); | |
308 | ||
4ed7af08 RR |
309 | protected: |
310 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn) | |
311 | }; | |
312 | ||
f554a14b | 313 | // --------------------------------------------------------- |
4ed7af08 | 314 | // wxDataViewCtrl |
f554a14b | 315 | // --------------------------------------------------------- |
4ed7af08 | 316 | |
f460c29d | 317 | class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase, |
4ed7af08 RR |
318 | public wxScrollHelperNative |
319 | { | |
87f0efe2 RR |
320 | friend class wxDataViewMainWindow; |
321 | friend class wxDataViewHeaderWindowBase; | |
322 | friend class wxDataViewHeaderWindow; | |
323 | friend class wxDataViewHeaderWindowMSW; | |
9861f022 | 324 | friend class wxDataViewColumn; |
87f0efe2 | 325 | |
4ed7af08 RR |
326 | public: |
327 | wxDataViewCtrl() : wxScrollHelperNative(this) | |
328 | { | |
66e09788 | 329 | m_sortingColumn = 0; |
4ed7af08 RR |
330 | Init(); |
331 | } | |
f554a14b | 332 | |
4ed7af08 RR |
333 | wxDataViewCtrl( wxWindow *parent, wxWindowID id, |
334 | const wxPoint& pos = wxDefaultPosition, | |
335 | const wxSize& size = wxDefaultSize, long style = 0, | |
f554a14b | 336 | const wxValidator& validator = wxDefaultValidator ) |
4b3feaa7 | 337 | : wxScrollHelperNative(this) |
4ed7af08 RR |
338 | { |
339 | Create(parent, id, pos, size, style, validator ); | |
340 | } | |
341 | ||
342 | virtual ~wxDataViewCtrl(); | |
343 | ||
344 | void Init(); | |
345 | ||
346 | bool Create(wxWindow *parent, wxWindowID id, | |
347 | const wxPoint& pos = wxDefaultPosition, | |
348 | const wxSize& size = wxDefaultSize, long style = 0, | |
349 | const wxValidator& validator = wxDefaultValidator ); | |
350 | ||
aba9bfd0 | 351 | virtual bool AssociateModel( wxDataViewModel *model ); |
4ed7af08 | 352 | virtual bool AppendColumn( wxDataViewColumn *col ); |
f554a14b | 353 | |
3b6280be RR |
354 | virtual void DoSetExpanderColumn(); |
355 | virtual void DoSetIndent(); | |
356 | ||
fbda518c | 357 | virtual wxDataViewItem GetSelection() const; |
b7e9f8b1 RR |
358 | virtual int GetSelections( wxDataViewItemArray & sel ) const; |
359 | virtual void SetSelections( const wxDataViewItemArray & sel ); | |
360 | virtual void Select( const wxDataViewItem & item ); | |
361 | virtual void Unselect( const wxDataViewItem & item ); | |
362 | virtual bool IsSelected( const wxDataViewItem & item ) const; | |
363 | ||
66e09788 RR |
364 | virtual void SelectAll(); |
365 | virtual void UnselectAll(); | |
366 | ||
367 | virtual void EnsureVisible( const wxDataViewItem & item, | |
fbda518c | 368 | const wxDataViewColumn *column = NULL ); |
a87b466d | 369 | virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const; |
fbda518c | 370 | virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const; |
66e09788 RR |
371 | |
372 | protected: | |
b7e9f8b1 RR |
373 | virtual int GetSelections( wxArrayInt & sel ) const; |
374 | virtual void SetSelections( const wxArrayInt & sel ); | |
375 | virtual void Select( int row ); | |
376 | virtual void Unselect( int row ); | |
377 | virtual bool IsSelected( int row ) const; | |
378 | virtual void SelectRange( int from, int to ); | |
379 | virtual void UnselectRange( int from, int to ); | |
380 | ||
fbda518c | 381 | virtual void EnsureVisible( int row, int column ); |
b7e9f8b1 RR |
382 | |
383 | virtual wxDataViewItem GetItemByRow( unsigned int row ) const; | |
384 | virtual int GetRowByItem( const wxDataViewItem & item ) const; | |
385 | ||
66e09788 RR |
386 | unsigned int GetSortingColumn() { return m_sortingColumn; } |
387 | void SetSortingColumn( unsigned int column ) { m_sortingColumn = column; } | |
6ff7eee7 | 388 | |
9861f022 RR |
389 | public: // utility functions not part of the API |
390 | ||
87f0efe2 | 391 | // returns the "best" width for the idx-th column |
9861f022 | 392 | unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const |
87f0efe2 | 393 | { |
9861f022 | 394 | return GetClientSize().GetWidth() / GetColumnCount(); |
87f0efe2 RR |
395 | } |
396 | ||
9861f022 RR |
397 | // updates the header window after a change in a column setting |
398 | void OnColumnChange(); | |
87f0efe2 | 399 | |
1e510b1e | 400 | wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; } |
99d471a5 | 401 | |
4ed7af08 | 402 | private: |
aba9bfd0 | 403 | wxDataViewModelNotifier *m_notifier; |
4b3feaa7 RR |
404 | wxDataViewMainWindow *m_clientArea; |
405 | wxDataViewHeaderWindow *m_headerArea; | |
66e09788 | 406 | unsigned int m_sortingColumn; |
f554a14b | 407 | |
4ed7af08 | 408 | private: |
4b3feaa7 | 409 | void OnSize( wxSizeEvent &event ); |
f554a14b | 410 | |
4ed7af08 RR |
411 | // we need to return a special WM_GETDLGCODE value to process just the |
412 | // arrows but let the other navigation characters through | |
413 | #ifdef __WXMSW__ | |
414 | virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
415 | #endif // __WXMSW__ | |
416 | ||
417 | WX_FORWARD_TO_SCROLL_HELPER() | |
4b3feaa7 | 418 | |
4ed7af08 RR |
419 | private: |
420 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
421 | DECLARE_NO_COPY_CLASS(wxDataViewCtrl) | |
4b3feaa7 | 422 | DECLARE_EVENT_TABLE() |
4ed7af08 RR |
423 | }; |
424 | ||
425 | ||
426 | #endif // __GENERICDATAVIEWCTRLH__ |