]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dataview.h
fix warnings in EventsSuppressor ctor from gcc with -O option
[wxWidgets.git] / include / wx / generic / dataview.h
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 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
103
104 protected:
105 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
106 };
107
108
109 // ---------------------------------------------------------
110 // wxDataViewTextRenderer
111 // ---------------------------------------------------------
112
113 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
114 {
115 public:
116 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
117 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
118 int align = wxDVR_DEFAULT_ALIGNMENT );
119
120 bool SetValue( const wxVariant &value );
121 bool GetValue( wxVariant &value ) const;
122
123 bool Render( wxRect cell, wxDC *dc, int state );
124 wxSize GetSize() const;
125
126 // in-place editing
127 virtual bool HasEditorCtrl();
128 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
129 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
130
131 private:
132 wxString m_text;
133
134 protected:
135 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
136 };
137
138 // ---------------------------------------------------------
139 // wxDataViewBitmapRenderer
140 // ---------------------------------------------------------
141
142 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
143 {
144 public:
145 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
146 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
147 int align = wxDVR_DEFAULT_ALIGNMENT );
148
149 bool SetValue( const wxVariant &value );
150 bool GetValue( wxVariant &value ) const;
151
152 bool Render( wxRect cell, wxDC *dc, int state );
153 wxSize GetSize() const;
154
155 private:
156 wxIcon m_icon;
157 wxBitmap m_bitmap;
158
159 protected:
160 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
161 };
162
163 // ---------------------------------------------------------
164 // wxDataViewToggleRenderer
165 // ---------------------------------------------------------
166
167 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
168 {
169 public:
170 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
171 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
172 int align = wxDVR_DEFAULT_ALIGNMENT );
173
174 bool SetValue( const wxVariant &value );
175 bool GetValue( wxVariant &value ) const;
176
177 bool Render( wxRect cell, wxDC *dc, int state );
178 bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
179 unsigned int col );
180 wxSize GetSize() const;
181
182 private:
183 bool m_toggle;
184
185 protected:
186 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
187 };
188
189 // ---------------------------------------------------------
190 // wxDataViewProgressRenderer
191 // ---------------------------------------------------------
192
193 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
194 {
195 public:
196 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
197 const wxString &varianttype = wxT("long"),
198 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
199 int align = wxDVR_DEFAULT_ALIGNMENT );
200 virtual ~wxDataViewProgressRenderer();
201
202 bool SetValue( const wxVariant &value );
203 bool GetValue( wxVariant& value ) const;
204
205 virtual bool Render( wxRect cell, wxDC *dc, int state );
206 virtual wxSize GetSize() const;
207
208 private:
209 wxString m_label;
210 int m_value;
211
212 protected:
213 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
214 };
215
216 // ---------------------------------------------------------
217 // wxDataViewIconTextRenderer
218 // ---------------------------------------------------------
219
220 class wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
221 {
222 public:
223 wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
224 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
225 int align = wxDVR_DEFAULT_ALIGNMENT );
226 virtual ~wxDataViewIconTextRenderer();
227
228 bool SetValue( const wxVariant &value );
229 bool GetValue( wxVariant &value ) const;
230
231 virtual bool Render( wxRect cell, wxDC *dc, int state );
232 virtual wxSize GetSize() const;
233
234 virtual bool HasEditorCtrl() { return true; }
235 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
236 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
237
238 private:
239 wxDataViewIconText m_value;
240
241 protected:
242 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
243 };
244
245 // ---------------------------------------------------------
246 // wxDataViewDateRenderer
247 // ---------------------------------------------------------
248
249 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
250 {
251 public:
252 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
253 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
254 int align = wxDVR_DEFAULT_ALIGNMENT );
255
256 bool SetValue( const wxVariant &value );
257 bool GetValue( wxVariant& value ) const;
258
259 virtual bool Render( wxRect cell, wxDC *dc, int state );
260 virtual wxSize GetSize() const;
261 virtual bool Activate( wxRect cell,
262 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
263
264 private:
265 wxDateTime m_date;
266
267 protected:
268 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
269 };
270
271 // ---------------------------------------------------------
272 // wxDataViewColumn
273 // ---------------------------------------------------------
274
275 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
276 {
277 friend class wxDataViewHeaderWindowBase;
278 friend class wxDataViewHeaderWindow;
279 friend class wxDataViewHeaderWindowMSW;
280
281 public:
282 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
283 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
284 wxAlignment align = wxALIGN_CENTER,
285 int flags = wxDATAVIEW_COL_RESIZABLE );
286 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
287 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
288 wxAlignment align = wxALIGN_CENTER,
289 int flags = wxDATAVIEW_COL_RESIZABLE );
290 virtual ~wxDataViewColumn();
291
292 // setters:
293
294 virtual void SetTitle( const wxString &title )
295 { m_title=title; }
296 virtual void SetAlignment( wxAlignment align )
297 { m_align=align; }
298 virtual void SetMinWidth( int minWidth )
299 { m_minWidth=minWidth; }
300 virtual void SetWidth( int width );
301 virtual void SetSortable( bool sortable );
302 virtual void SetResizeable( bool resizeable );
303 virtual void SetHidden( bool hidden );
304 virtual void SetSortOrder( bool ascending );
305
306
307 // getters:
308
309 virtual wxString GetTitle() const
310 { return m_title; }
311 virtual wxAlignment GetAlignment() const
312 { return m_align; }
313 virtual int GetWidth() const
314 { return m_width; }
315 virtual int GetMinWidth() const
316 { return m_minWidth; }
317 virtual bool IsSortable() const
318 { return (m_flags & wxDATAVIEW_COL_SORTABLE) != 0; }
319 virtual bool IsResizeable() const
320 { return (m_flags & wxDATAVIEW_COL_RESIZABLE) != 0; }
321 virtual bool IsHidden() const
322 { return (m_flags & wxDATAVIEW_COL_HIDDEN) != 0; }
323 virtual bool IsSortOrderAscending() const;
324
325
326 private:
327 int m_width;
328 int m_minWidth;
329 int m_flags;
330 wxAlignment m_align;
331 wxString m_title;
332 bool m_ascending;
333
334 void Init(int width);
335
336 // like SetWidth() but does not ask the header window of the
337 // wxDataViewCtrl to reflect the width-change.
338 void SetInternalWidth(int width);
339
340 protected:
341 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
342 };
343
344 // ---------------------------------------------------------
345 // wxDataViewCtrl
346 // ---------------------------------------------------------
347
348 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
349 class WXDLLIMPEXP_ADV);
350
351 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
352 public wxScrollHelperNative
353 {
354 friend class wxDataViewMainWindow;
355 friend class wxDataViewHeaderWindowBase;
356 friend class wxDataViewHeaderWindow;
357 friend class wxDataViewHeaderWindowMSW;
358 friend class wxDataViewColumn;
359
360 public:
361 wxDataViewCtrl() : wxScrollHelperNative(this)
362 {
363 //No sorting column at start, I think
364 m_sortingColumn = NULL;
365 Init();
366 }
367
368 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
369 const wxPoint& pos = wxDefaultPosition,
370 const wxSize& size = wxDefaultSize, long style = 0,
371 const wxValidator& validator = wxDefaultValidator )
372 : wxScrollHelperNative(this)
373 {
374 m_sortingColumn = NULL;
375 Create(parent, id, pos, size, style, validator );
376 }
377
378 virtual ~wxDataViewCtrl();
379
380 void Init();
381
382 bool Create(wxWindow *parent, wxWindowID id,
383 const wxPoint& pos = wxDefaultPosition,
384 const wxSize& size = wxDefaultSize, long style = 0,
385 const wxValidator& validator = wxDefaultValidator );
386
387 virtual bool AssociateModel( wxDataViewModel *model );
388 virtual bool AppendColumn( wxDataViewColumn *col );
389 virtual bool PrependColumn( wxDataViewColumn *col );
390
391 virtual void DoSetExpanderColumn();
392 virtual void DoSetIndent();
393
394 virtual unsigned int GetColumnCount() const;
395 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
396 virtual bool DeleteColumn( wxDataViewColumn *column );
397 virtual bool ClearColumns();
398 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
399
400 virtual wxDataViewColumn *GetSortingColumn() const;
401
402 virtual wxDataViewItem GetSelection() const;
403 virtual int GetSelections( wxDataViewItemArray & sel ) const;
404 virtual void SetSelections( const wxDataViewItemArray & sel );
405 virtual void Select( const wxDataViewItem & item );
406 virtual void Unselect( const wxDataViewItem & item );
407 virtual bool IsSelected( const wxDataViewItem & item ) const;
408
409 virtual void SelectAll();
410 virtual void UnselectAll();
411
412 virtual void EnsureVisible( const wxDataViewItem & item,
413 const wxDataViewColumn *column = NULL );
414 virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const;
415 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const;
416
417 virtual void Expand( const wxDataViewItem & item );
418 virtual void Collapse( const wxDataViewItem & item );
419
420 protected:
421 virtual int GetSelections( wxArrayInt & sel ) const;
422 virtual void SetSelections( const wxArrayInt & sel );
423 virtual void Select( int row );
424 virtual void Unselect( int row );
425 virtual bool IsSelected( int row ) const;
426 virtual void SelectRange( int from, int to );
427 virtual void UnselectRange( int from, int to );
428
429 virtual void EnsureVisible( int row, int column );
430
431 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
432 virtual int GetRowByItem( const wxDataViewItem & item ) const;
433
434 wxDataViewColumn* GetSortingColumn() { return m_sortingColumn; }
435 void SetSortingColumn( wxDataViewColumn* column ) { m_sortingColumn = column; }
436
437 public: // utility functions not part of the API
438
439 // returns the "best" width for the idx-th column
440 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
441 {
442 return GetClientSize().GetWidth() / GetColumnCount();
443 }
444
445 // updates the header window after a change in a column setting
446 void OnColumnChange();
447
448 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
449
450 private:
451 wxDataViewColumnList m_cols;
452 wxDataViewModelNotifier *m_notifier;
453 wxDataViewMainWindow *m_clientArea;
454 wxDataViewHeaderWindow *m_headerArea;
455 wxDataViewColumn* m_sortingColumn;
456
457 private:
458 void OnSize( wxSizeEvent &event );
459
460 // we need to return a special WM_GETDLGCODE value to process just the
461 // arrows but let the other navigation characters through
462 #ifdef __WXMSW__
463 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
464 #endif // __WXMSW__
465
466 WX_FORWARD_TO_SCROLL_HELPER()
467
468 private:
469 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
470 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
471 DECLARE_EVENT_TABLE()
472 };
473
474
475 #endif // __GENERICDATAVIEWCTRLH__