]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/generic/dataview.h | |
3 | // Purpose: wxDataViewCtrl generic implementation header | |
4 | // Author: Robert Roebling | |
5 | // Modified By: Bo Yang | |
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" | |
18 | #include "wx/scrolwin.h" | |
19 | #include "wx/icon.h" | |
20 | ||
21 | // --------------------------------------------------------- | |
22 | // classes | |
23 | // --------------------------------------------------------- | |
24 | ||
25 | class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl; | |
26 | class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow; | |
27 | class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow; | |
28 | ||
29 | // --------------------------------------------------------- | |
30 | // wxDataViewRenderer | |
31 | // --------------------------------------------------------- | |
32 | ||
33 | class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase | |
34 | { | |
35 | public: | |
36 | wxDataViewRenderer( const wxString &varianttype, | |
37 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
38 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
39 | virtual ~wxDataViewRenderer(); | |
40 | ||
41 | virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0; | |
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; } | |
53 | ||
54 | virtual bool Activate( wxRect WXUNUSED(cell), | |
55 | wxDataViewModel *WXUNUSED(model), | |
56 | const wxDataViewItem & WXUNUSED(item), | |
57 | unsigned int WXUNUSED(col) ) | |
58 | { return false; } | |
59 | ||
60 | virtual bool LeftClick( wxPoint WXUNUSED(cursor), | |
61 | wxRect WXUNUSED(cell), | |
62 | wxDataViewModel *WXUNUSED(model), | |
63 | const wxDataViewItem & WXUNUSED(item), | |
64 | unsigned int WXUNUSED(col) ) | |
65 | { return false; } | |
66 | virtual bool RightClick( wxPoint WXUNUSED(cursor), | |
67 | wxRect WXUNUSED(cell), | |
68 | wxDataViewModel *WXUNUSED(model), | |
69 | const wxDataViewItem & WXUNUSED(item), | |
70 | unsigned int WXUNUSED(col) ) | |
71 | { return false; } | |
72 | virtual bool StartDrag( wxPoint WXUNUSED(cursor), | |
73 | wxRect WXUNUSED(cell), | |
74 | wxDataViewModel *WXUNUSED(model), | |
75 | const wxDataViewItem & WXUNUSED(item), | |
76 | unsigned int WXUNUSED(col) ) | |
77 | { return false; } | |
78 | ||
79 | // Create DC on request | |
80 | virtual wxDC *GetDC(); | |
81 | ||
82 | private: | |
83 | wxDC *m_dc; | |
84 | int m_align; | |
85 | wxDataViewCellMode m_mode; | |
86 | ||
87 | protected: | |
88 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer) | |
89 | }; | |
90 | ||
91 | // --------------------------------------------------------- | |
92 | // wxDataViewCustomRenderer | |
93 | // --------------------------------------------------------- | |
94 | ||
95 | class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer | |
96 | { | |
97 | public: | |
98 | wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"), | |
99 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
100 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
101 | ||
102 | protected: | |
103 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer) | |
104 | }; | |
105 | ||
106 | ||
107 | // --------------------------------------------------------- | |
108 | // wxDataViewTextRenderer | |
109 | // --------------------------------------------------------- | |
110 | ||
111 | class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer | |
112 | { | |
113 | public: | |
114 | wxDataViewTextRenderer( const wxString &varianttype = wxT("string"), | |
115 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
116 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
117 | ||
118 | bool SetValue( const wxVariant &value ); | |
119 | bool GetValue( wxVariant &value ) const; | |
120 | ||
121 | bool Render( wxRect cell, wxDC *dc, int state ); | |
122 | wxSize GetSize() const; | |
123 | ||
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 | ||
129 | private: | |
130 | wxString m_text; | |
131 | ||
132 | protected: | |
133 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer) | |
134 | }; | |
135 | ||
136 | // --------------------------------------------------------- | |
137 | // wxDataViewBitmapRenderer | |
138 | // --------------------------------------------------------- | |
139 | ||
140 | class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer | |
141 | { | |
142 | public: | |
143 | wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"), | |
144 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
145 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
146 | ||
147 | bool SetValue( const wxVariant &value ); | |
148 | bool GetValue( wxVariant &value ) const; | |
149 | ||
150 | bool Render( wxRect cell, wxDC *dc, int state ); | |
151 | wxSize GetSize() const; | |
152 | ||
153 | private: | |
154 | wxIcon m_icon; | |
155 | wxBitmap m_bitmap; | |
156 | ||
157 | protected: | |
158 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer) | |
159 | }; | |
160 | ||
161 | // --------------------------------------------------------- | |
162 | // wxDataViewToggleRenderer | |
163 | // --------------------------------------------------------- | |
164 | ||
165 | class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer | |
166 | { | |
167 | public: | |
168 | wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"), | |
169 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
170 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
171 | ||
172 | bool SetValue( const wxVariant &value ); | |
173 | bool GetValue( wxVariant &value ) const; | |
174 | ||
175 | bool Render( wxRect cell, wxDC *dc, int state ); | |
176 | bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item, | |
177 | unsigned int col ); | |
178 | wxSize GetSize() const; | |
179 | ||
180 | private: | |
181 | bool m_toggle; | |
182 | ||
183 | protected: | |
184 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer) | |
185 | }; | |
186 | ||
187 | // --------------------------------------------------------- | |
188 | // wxDataViewProgressRenderer | |
189 | // --------------------------------------------------------- | |
190 | ||
191 | class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer | |
192 | { | |
193 | public: | |
194 | wxDataViewProgressRenderer( const wxString &label = wxEmptyString, | |
195 | const wxString &varianttype = wxT("long"), | |
196 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
197 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
198 | virtual ~wxDataViewProgressRenderer(); | |
199 | ||
200 | bool SetValue( const wxVariant &value ); | |
201 | bool GetValue( wxVariant& value ) const; | |
202 | ||
203 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
204 | virtual wxSize GetSize() const; | |
205 | ||
206 | private: | |
207 | wxString m_label; | |
208 | int m_value; | |
209 | ||
210 | protected: | |
211 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer) | |
212 | }; | |
213 | ||
214 | // --------------------------------------------------------- | |
215 | // wxDataViewDateRenderer | |
216 | // --------------------------------------------------------- | |
217 | ||
218 | class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer | |
219 | { | |
220 | public: | |
221 | wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"), | |
222 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, | |
223 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
224 | ||
225 | bool SetValue( const wxVariant &value ); | |
226 | bool GetValue( wxVariant& value ) const; | |
227 | ||
228 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
229 | virtual wxSize GetSize() const; | |
230 | virtual bool Activate( wxRect cell, | |
231 | wxDataViewModel *model, const wxDataViewItem & item, unsigned int col ); | |
232 | ||
233 | private: | |
234 | wxDateTime m_date; | |
235 | ||
236 | protected: | |
237 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer) | |
238 | }; | |
239 | ||
240 | // --------------------------------------------------------- | |
241 | // wxDataViewColumn | |
242 | // --------------------------------------------------------- | |
243 | ||
244 | class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase | |
245 | { | |
246 | friend class wxDataViewHeaderWindowBase; | |
247 | friend class wxDataViewHeaderWindow; | |
248 | friend class wxDataViewHeaderWindowMSW; | |
249 | ||
250 | public: | |
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 ); | |
259 | virtual ~wxDataViewColumn(); | |
260 | ||
261 | // setters: | |
262 | ||
263 | virtual void SetTitle( const wxString &title ) | |
264 | { m_title=title; } | |
265 | virtual void SetAlignment( wxAlignment align ) | |
266 | { m_align=align; } | |
267 | virtual void SetMinWidth( int minWidth ) | |
268 | { m_minWidth=minWidth; } | |
269 | virtual void SetWidth( int width ); | |
270 | virtual void SetSortable( bool sortable ); | |
271 | virtual void SetResizeable( bool resizeable ); | |
272 | virtual void SetHidden( bool hidden ); | |
273 | virtual void SetSortOrder( bool ascending ); | |
274 | ||
275 | ||
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; | |
293 | ||
294 | ||
295 | private: | |
296 | int m_width; | |
297 | int m_minWidth; | |
298 | int m_flags; | |
299 | wxAlignment m_align; | |
300 | wxString m_title; | |
301 | bool m_ascending; | |
302 | ||
303 | void Init(int width); | |
304 | ||
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 | ||
309 | protected: | |
310 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn) | |
311 | }; | |
312 | ||
313 | // --------------------------------------------------------- | |
314 | // wxDataViewCtrl | |
315 | // --------------------------------------------------------- | |
316 | ||
317 | class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase, | |
318 | public wxScrollHelperNative | |
319 | { | |
320 | friend class wxDataViewMainWindow; | |
321 | friend class wxDataViewHeaderWindowBase; | |
322 | friend class wxDataViewHeaderWindow; | |
323 | friend class wxDataViewHeaderWindowMSW; | |
324 | friend class wxDataViewColumn; | |
325 | ||
326 | public: | |
327 | wxDataViewCtrl() : wxScrollHelperNative(this) | |
328 | { | |
329 | Init(); | |
330 | } | |
331 | ||
332 | wxDataViewCtrl( wxWindow *parent, wxWindowID id, | |
333 | const wxPoint& pos = wxDefaultPosition, | |
334 | const wxSize& size = wxDefaultSize, long style = 0, | |
335 | const wxValidator& validator = wxDefaultValidator ) | |
336 | : wxScrollHelperNative(this) | |
337 | { | |
338 | Create(parent, id, pos, size, style, validator ); | |
339 | } | |
340 | ||
341 | virtual ~wxDataViewCtrl(); | |
342 | ||
343 | void Init(); | |
344 | ||
345 | bool Create(wxWindow *parent, wxWindowID id, | |
346 | const wxPoint& pos = wxDefaultPosition, | |
347 | const wxSize& size = wxDefaultSize, long style = 0, | |
348 | const wxValidator& validator = wxDefaultValidator ); | |
349 | ||
350 | virtual bool AssociateModel( wxDataViewModel *model ); | |
351 | virtual bool AppendColumn( wxDataViewColumn *col ); | |
352 | ||
353 | virtual void DoSetExpanderColumn(); | |
354 | virtual void DoSetIndent(); | |
355 | ||
356 | virtual int GetSelections( wxDataViewItemArray & sel ) const; | |
357 | virtual void SetSelections( const wxDataViewItemArray & sel ); | |
358 | virtual void Select( const wxDataViewItem & item ); | |
359 | virtual void Unselect( const wxDataViewItem & item ); | |
360 | virtual bool IsSelected( const wxDataViewItem & item ) const; | |
361 | ||
362 | virtual int GetSelections( wxArrayInt & sel ) const; | |
363 | virtual void SetSelections( const wxArrayInt & sel ); | |
364 | virtual void Select( int row ); | |
365 | virtual void Unselect( int row ); | |
366 | virtual bool IsSelected( int row ) const; | |
367 | virtual void SelectRange( int from, int to ); | |
368 | virtual void UnselectRange( int from, int to ); | |
369 | ||
370 | virtual void SelectAll(); | |
371 | virtual void UnselectAll(); | |
372 | ||
373 | virtual void EnsureVisible( int row ); | |
374 | virtual void EnsureVisible( const wxDataViewItem & item ); | |
375 | ||
376 | virtual wxDataViewItem GetItemByRow( unsigned int row ) const; | |
377 | virtual int GetRowByItem( const wxDataViewItem & item ) const; | |
378 | ||
379 | ||
380 | public: // utility functions not part of the API | |
381 | ||
382 | // returns the "best" width for the idx-th column | |
383 | unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const | |
384 | { | |
385 | return GetClientSize().GetWidth() / GetColumnCount(); | |
386 | } | |
387 | ||
388 | // updates the header window after a change in a column setting | |
389 | void OnColumnChange(); | |
390 | ||
391 | wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; } | |
392 | ||
393 | private: | |
394 | wxDataViewModelNotifier *m_notifier; | |
395 | wxDataViewMainWindow *m_clientArea; | |
396 | wxDataViewHeaderWindow *m_headerArea; | |
397 | ||
398 | private: | |
399 | void OnSize( wxSizeEvent &event ); | |
400 | ||
401 | // we need to return a special WM_GETDLGCODE value to process just the | |
402 | // arrows but let the other navigation characters through | |
403 | #ifdef __WXMSW__ | |
404 | virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); | |
405 | #endif // __WXMSW__ | |
406 | ||
407 | WX_FORWARD_TO_SCROLL_HELPER() | |
408 | ||
409 | private: | |
410 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
411 | DECLARE_NO_COPY_CLASS(wxDataViewCtrl) | |
412 | DECLARE_EVENT_TABLE() | |
413 | }; | |
414 | ||
415 | ||
416 | #endif // __GENERICDATAVIEWCTRLH__ |