]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dataview.h
fix to make 'wxAtomicInt i = 0;' work with generic implementation and gcc
[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 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 // wxDataViewIconTextRenderer
216 // ---------------------------------------------------------
217
218 class wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
219 {
220 public:
221 wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
222 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
223 int align = wxDVR_DEFAULT_ALIGNMENT );
224 virtual ~wxDataViewIconTextRenderer();
225
226 bool SetValue( const wxVariant &value );
227 bool GetValue( wxVariant &value ) const;
228
229 virtual bool Render( wxRect cell, wxDC *dc, int state );
230 virtual wxSize GetSize() const;
231
232 virtual bool HasEditorCtrl() { return true; }
233 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
234 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
235
236 private:
237 wxDataViewIconText m_value;
238
239 protected:
240 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
241 };
242
243 // ---------------------------------------------------------
244 // wxDataViewDateRenderer
245 // ---------------------------------------------------------
246
247 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
248 {
249 public:
250 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
251 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
252 int align = wxDVR_DEFAULT_ALIGNMENT );
253
254 bool SetValue( const wxVariant &value );
255 bool GetValue( wxVariant& value ) const;
256
257 virtual bool Render( wxRect cell, wxDC *dc, int state );
258 virtual wxSize GetSize() const;
259 virtual bool Activate( wxRect cell,
260 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
261
262 private:
263 wxDateTime m_date;
264
265 protected:
266 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
267 };
268
269 // ---------------------------------------------------------
270 // wxDataViewColumn
271 // ---------------------------------------------------------
272
273 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
274 {
275 friend class wxDataViewHeaderWindowBase;
276 friend class wxDataViewHeaderWindow;
277 friend class wxDataViewHeaderWindowMSW;
278
279 public:
280 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
281 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
282 wxAlignment align = wxALIGN_CENTER,
283 int flags = wxDATAVIEW_COL_RESIZABLE );
284 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
285 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
286 wxAlignment align = wxALIGN_CENTER,
287 int flags = wxDATAVIEW_COL_RESIZABLE );
288 virtual ~wxDataViewColumn();
289
290 // setters:
291
292 virtual void SetTitle( const wxString &title )
293 { m_title=title; }
294 virtual void SetAlignment( wxAlignment align )
295 { m_align=align; }
296 virtual void SetMinWidth( int minWidth )
297 { m_minWidth=minWidth; }
298 virtual void SetWidth( int width );
299 virtual void SetSortable( bool sortable );
300 virtual void SetResizeable( bool resizeable );
301 virtual void SetHidden( bool hidden );
302 virtual void SetSortOrder( bool ascending );
303
304
305 // getters:
306
307 virtual wxString GetTitle() const
308 { return m_title; }
309 virtual wxAlignment GetAlignment() const
310 { return m_align; }
311 virtual int GetWidth() const
312 { return m_width; }
313 virtual int GetMinWidth() const
314 { return m_minWidth; }
315 virtual bool IsSortable() const
316 { return (m_flags & wxDATAVIEW_COL_SORTABLE) != 0; }
317 virtual bool IsResizeable() const
318 { return (m_flags & wxDATAVIEW_COL_RESIZABLE) != 0; }
319 virtual bool IsHidden() const
320 { return (m_flags & wxDATAVIEW_COL_HIDDEN) != 0; }
321 virtual bool IsSortOrderAscending() const;
322
323
324 private:
325 int m_width;
326 int m_minWidth;
327 int m_flags;
328 wxAlignment m_align;
329 wxString m_title;
330 bool m_ascending;
331
332 void Init(int width);
333
334 // like SetWidth() but does not ask the header window of the
335 // wxDataViewCtrl to reflect the width-change.
336 void SetInternalWidth(int width);
337
338 protected:
339 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
340 };
341
342 // ---------------------------------------------------------
343 // wxDataViewCtrl
344 // ---------------------------------------------------------
345
346 WX_DECLARE_LIST(wxDataViewColumn, wxDataViewColumnList );
347
348 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
349 public wxScrollHelperNative
350 {
351 friend class wxDataViewMainWindow;
352 friend class wxDataViewHeaderWindowBase;
353 friend class wxDataViewHeaderWindow;
354 friend class wxDataViewHeaderWindowMSW;
355 friend class wxDataViewColumn;
356
357 public:
358 wxDataViewCtrl() : wxScrollHelperNative(this)
359 {
360 //No sorting column at start, I think
361 m_sortingColumn = NULL;
362 Init();
363 }
364
365 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
366 const wxPoint& pos = wxDefaultPosition,
367 const wxSize& size = wxDefaultSize, long style = 0,
368 const wxValidator& validator = wxDefaultValidator )
369 : wxScrollHelperNative(this)
370 {
371 m_sortingColumn = NULL;
372 Create(parent, id, pos, size, style, validator );
373 }
374
375 virtual ~wxDataViewCtrl();
376
377 void Init();
378
379 bool Create(wxWindow *parent, wxWindowID id,
380 const wxPoint& pos = wxDefaultPosition,
381 const wxSize& size = wxDefaultSize, long style = 0,
382 const wxValidator& validator = wxDefaultValidator );
383
384 virtual bool AssociateModel( wxDataViewModel *model );
385 virtual bool AppendColumn( wxDataViewColumn *col );
386
387 virtual void DoSetExpanderColumn();
388 virtual void DoSetIndent();
389
390 virtual unsigned int GetColumnCount() const;
391 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
392 virtual bool DeleteColumn( wxDataViewColumn *column );
393 virtual bool ClearColumns();
394
395 virtual wxDataViewItem GetSelection() const;
396 virtual int GetSelections( wxDataViewItemArray & sel ) const;
397 virtual void SetSelections( const wxDataViewItemArray & sel );
398 virtual void Select( const wxDataViewItem & item );
399 virtual void Unselect( const wxDataViewItem & item );
400 virtual bool IsSelected( const wxDataViewItem & item ) const;
401
402 virtual void SelectAll();
403 virtual void UnselectAll();
404
405 virtual void EnsureVisible( const wxDataViewItem & item,
406 const wxDataViewColumn *column = NULL );
407 virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const;
408 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const;
409
410 virtual void Expand( const wxDataViewItem & item );
411 virtual void Collapse( const wxDataViewItem & item );
412
413 protected:
414 virtual int GetSelections( wxArrayInt & sel ) const;
415 virtual void SetSelections( const wxArrayInt & sel );
416 virtual void Select( int row );
417 virtual void Unselect( int row );
418 virtual bool IsSelected( int row ) const;
419 virtual void SelectRange( int from, int to );
420 virtual void UnselectRange( int from, int to );
421
422 virtual void EnsureVisible( int row, int column );
423
424 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
425 virtual int GetRowByItem( const wxDataViewItem & item ) const;
426
427 wxDataViewColumn* GetSortingColumn() { return m_sortingColumn; }
428 void SetSortingColumn( wxDataViewColumn* column ) { m_sortingColumn = column; }
429
430 public: // utility functions not part of the API
431
432 // returns the "best" width for the idx-th column
433 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
434 {
435 return GetClientSize().GetWidth() / GetColumnCount();
436 }
437
438 // updates the header window after a change in a column setting
439 void OnColumnChange();
440
441 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
442
443 private:
444 wxDataViewColumnList m_cols;
445 wxDataViewModelNotifier *m_notifier;
446 wxDataViewMainWindow *m_clientArea;
447 wxDataViewHeaderWindow *m_headerArea;
448 wxDataViewColumn* m_sortingColumn;
449
450 private:
451 void OnSize( wxSizeEvent &event );
452
453 // we need to return a special WM_GETDLGCODE value to process just the
454 // arrows but let the other navigation characters through
455 #ifdef __WXMSW__
456 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
457 #endif // __WXMSW__
458
459 WX_FORWARD_TO_SCROLL_HELPER()
460
461 private:
462 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
463 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
464 DECLARE_EVENT_TABLE()
465 };
466
467
468 #endif // __GENERICDATAVIEWCTRLH__