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