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