enable autobrief comments
[wxWidgets.git] / include / wx / generic / dataview.h
CommitLineData
4ed7af08
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/generic/dataview.h
3// Purpose: wxDataViewCtrl generic implementation header
4// Author: Robert Roebling
b7e9f8b1 5// Modified By: Bo Yang
4ed7af08
RR
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"
9d14de69 18#include "wx/scrolwin.h"
2586d4a1 19#include "wx/icon.h"
4ed7af08 20
f554a14b 21// ---------------------------------------------------------
4ed7af08 22// classes
f554a14b 23// ---------------------------------------------------------
4ed7af08 24
b5dbe15d
VS
25class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
26class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow;
27class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
4ed7af08 28
f554a14b 29// ---------------------------------------------------------
baa9ebc4 30// wxDataViewRenderer
f554a14b 31// ---------------------------------------------------------
4ed7af08 32
baa9ebc4 33class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
4ed7af08
RR
34{
35public:
87f0efe2 36 wxDataViewRenderer( const wxString &varianttype,
9861f022
RR
37 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
38 int align = wxDVR_DEFAULT_ALIGNMENT );
baa9ebc4 39 virtual ~wxDataViewRenderer();
4ed7af08 40
3d9d7cc4 41 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
9861f022
RR
42 virtual wxSize GetSize() const = 0;
43
e51bf699
RR
44 virtual void SetAlignment( int align );
45 virtual int GetAlignment() const;
9861f022
RR
46
47 virtual void SetMode( wxDataViewCellMode mode )
48 { m_mode=mode; }
49 virtual wxDataViewCellMode GetMode() const
50 { return m_mode; }
f554a14b
WS
51
52 virtual bool Activate( wxRect WXUNUSED(cell),
aba9bfd0 53 wxDataViewModel *WXUNUSED(model),
704c3490 54 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 55 unsigned int WXUNUSED(col) )
3d9d7cc4 56 { return false; }
f554a14b
WS
57
58 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
59 wxRect WXUNUSED(cell),
aba9bfd0 60 wxDataViewModel *WXUNUSED(model),
704c3490 61 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 62 unsigned int WXUNUSED(col) )
f554a14b
WS
63 { return false; }
64 virtual bool RightClick( wxPoint WXUNUSED(cursor),
65 wxRect WXUNUSED(cell),
aba9bfd0 66 wxDataViewModel *WXUNUSED(model),
704c3490 67 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 68 unsigned int WXUNUSED(col) )
f554a14b
WS
69 { return false; }
70 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
71 wxRect WXUNUSED(cell),
aba9bfd0 72 wxDataViewModel *WXUNUSED(model),
704c3490 73 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 74 unsigned int WXUNUSED(col) )
f554a14b
WS
75 { return false; }
76
3d9d7cc4
RR
77 // Create DC on request
78 virtual wxDC *GetDC();
4264606e
RR
79
80 void SetHasAttr( bool set ) { m_hasAttr = set; }
81 void SetAttr( const wxDataViewItemAttr &attr ) { m_attr = attr; }
82 bool GetWantsAttr() { return m_wantsAttr; }
f554a14b 83
e51bf699
RR
84 // implementation
85 int CalculateAlignment() const;
86
3d9d7cc4 87private:
99d471a5
RR
88 wxDC *m_dc;
89 int m_align;
90 wxDataViewCellMode m_mode;
4264606e
RR
91
92protected:
93 bool m_wantsAttr;
94 bool m_hasAttr;
95 wxDataViewItemAttr m_attr;
f554a14b 96
4ed7af08 97protected:
baa9ebc4 98 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
4ed7af08 99};
f554a14b
WS
100
101// ---------------------------------------------------------
baa9ebc4 102// wxDataViewCustomRenderer
f554a14b 103// ---------------------------------------------------------
4ed7af08 104
baa9ebc4 105class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
4ed7af08
RR
106{
107public:
baa9ebc4 108 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
9861f022
RR
109 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
110 int align = wxDVR_DEFAULT_ALIGNMENT );
f554a14b 111
52e750fc
RR
112 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
113
4ed7af08 114protected:
baa9ebc4 115 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
4ed7af08 116};
f554a14b 117
99d471a5 118
f554a14b 119// ---------------------------------------------------------
baa9ebc4 120// wxDataViewTextRenderer
f554a14b 121// ---------------------------------------------------------
4ed7af08 122
baa9ebc4 123class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
124{
125public:
baa9ebc4 126 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
9861f022
RR
127 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
128 int align = wxDVR_DEFAULT_ALIGNMENT );
4ed7af08
RR
129
130 bool SetValue( const wxVariant &value );
9861f022 131 bool GetValue( wxVariant &value ) const;
f554a14b 132
3d9d7cc4 133 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 134 wxSize GetSize() const;
f554a14b 135
99d471a5
RR
136 // in-place editing
137 virtual bool HasEditorCtrl();
138 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
139 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
140
4264606e 141protected:
99d471a5 142 wxString m_text;
f554a14b 143
4ed7af08 144protected:
baa9ebc4 145 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
4ed7af08 146};
f554a14b 147
4264606e
RR
148// ---------------------------------------------------------
149// wxDataViewTextRendererAttr
150// ---------------------------------------------------------
151
152class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
153{
154public:
155 wxDataViewTextRendererAttr( const wxString &varianttype = wxT("string"),
156 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
157 int align = wxDVR_DEFAULT_ALIGNMENT );
158
159 bool Render( wxRect cell, wxDC *dc, int state );
160
161protected:
162 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
163};
164
2586d4a1 165// ---------------------------------------------------------
baa9ebc4 166// wxDataViewBitmapRenderer
2586d4a1
RR
167// ---------------------------------------------------------
168
baa9ebc4 169class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
2586d4a1
RR
170{
171public:
baa9ebc4 172 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
9861f022
RR
173 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
174 int align = wxDVR_DEFAULT_ALIGNMENT );
2586d4a1
RR
175
176 bool SetValue( const wxVariant &value );
9861f022 177 bool GetValue( wxVariant &value ) const;
2586d4a1
RR
178
179 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 180 wxSize GetSize() const;
2586d4a1
RR
181
182private:
183 wxIcon m_icon;
184 wxBitmap m_bitmap;
185
186protected:
baa9ebc4 187 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
2586d4a1
RR
188};
189
f554a14b 190// ---------------------------------------------------------
baa9ebc4 191// wxDataViewToggleRenderer
f554a14b 192// ---------------------------------------------------------
4ed7af08 193
baa9ebc4 194class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
195{
196public:
baa9ebc4 197 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
9861f022
RR
198 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
199 int align = wxDVR_DEFAULT_ALIGNMENT );
3d9d7cc4
RR
200
201 bool SetValue( const wxVariant &value );
9861f022 202 bool GetValue( wxVariant &value ) const;
f554a14b 203
3d9d7cc4 204 bool Render( wxRect cell, wxDC *dc, int state );
aba9bfd0
RR
205 bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
206 unsigned int col );
9861f022 207 wxSize GetSize() const;
f554a14b 208
90675b95
RR
209private:
210 bool m_toggle;
f554a14b 211
4ed7af08 212protected:
baa9ebc4 213 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
4ed7af08 214};
f554a14b
WS
215
216// ---------------------------------------------------------
baa9ebc4 217// wxDataViewProgressRenderer
f554a14b 218// ---------------------------------------------------------
4ed7af08 219
baa9ebc4 220class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
221{
222public:
baa9ebc4
RR
223 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
224 const wxString &varianttype = wxT("long"),
9861f022
RR
225 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
226 int align = wxDVR_DEFAULT_ALIGNMENT );
baa9ebc4 227 virtual ~wxDataViewProgressRenderer();
f554a14b 228
4ed7af08 229 bool SetValue( const wxVariant &value );
9861f022 230 bool GetValue( wxVariant& value ) const;
f554a14b 231
4ed7af08 232 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 233 virtual wxSize GetSize() const;
f554a14b 234
4ed7af08
RR
235private:
236 wxString m_label;
237 int m_value;
f554a14b 238
4ed7af08 239protected:
baa9ebc4 240 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
4ed7af08 241};
24c4a50f
RR
242
243// ---------------------------------------------------------
244// wxDataViewIconTextRenderer
245// ---------------------------------------------------------
246
5cfb6fee 247class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
24c4a50f
RR
248{
249public:
250 wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
251 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
252 int align = wxDVR_DEFAULT_ALIGNMENT );
253 virtual ~wxDataViewIconTextRenderer();
254
255 bool SetValue( const wxVariant &value );
256 bool GetValue( wxVariant &value ) const;
257
258 virtual bool Render( wxRect cell, wxDC *dc, int state );
259 virtual wxSize GetSize() const;
260
261 virtual bool HasEditorCtrl() { return true; }
262 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
263 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
264
265private:
266 wxDataViewIconText m_value;
267
268protected:
269 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
270};
f554a14b
WS
271
272// ---------------------------------------------------------
baa9ebc4 273// wxDataViewDateRenderer
f554a14b 274// ---------------------------------------------------------
4ed7af08 275
baa9ebc4 276class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
277{
278public:
baa9ebc4 279 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
9861f022
RR
280 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
281 int align = wxDVR_DEFAULT_ALIGNMENT );
f554a14b 282
4ed7af08 283 bool SetValue( const wxVariant &value );
9861f022 284 bool GetValue( wxVariant& value ) const;
f554a14b 285
4ed7af08 286 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 287 virtual wxSize GetSize() const;
4ed7af08 288 virtual bool Activate( wxRect cell,
aba9bfd0 289 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
f554a14b 290
4ed7af08
RR
291private:
292 wxDateTime m_date;
f554a14b 293
4ed7af08 294protected:
baa9ebc4 295 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
4ed7af08 296};
f554a14b
WS
297
298// ---------------------------------------------------------
4ed7af08 299// wxDataViewColumn
f554a14b 300// ---------------------------------------------------------
4ed7af08 301
56873923 302class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase
4ed7af08
RR
303{
304public:
87f0efe2
RR
305 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
306 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
307 wxAlignment align = wxALIGN_CENTER,
308 int flags = wxDATAVIEW_COL_RESIZABLE );
309 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
310 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
311 wxAlignment align = wxALIGN_CENTER,
312 int flags = wxDATAVIEW_COL_RESIZABLE );
f554a14b 313
56873923
VZ
314 // override some methods to notify the owner about changes
315 virtual void SetFlags(int flags);
316 virtual void SetWidth(int width);
317 virtual void SetSortOrder(bool ascending);
87f0efe2 318
56873923
VZ
319 // override this one to return our default width for columns whose width
320 // was not explicitly set
321 virtual int GetWidth() const;
4ed7af08 322
56873923 323private:
9861f022
RR
324 // like SetWidth() but does not ask the header window of the
325 // wxDataViewCtrl to reflect the width-change.
326 void SetInternalWidth(int width);
327
56873923
VZ
328 friend class wxDataViewHeaderWindowBase;
329 friend class wxDataViewHeaderWindow;
330 friend class wxDataViewHeaderWindowMSW;
331
4ed7af08
RR
332 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
333};
334
f554a14b 335// ---------------------------------------------------------
4ed7af08 336// wxDataViewCtrl
f554a14b 337// ---------------------------------------------------------
4ed7af08 338
4660b556
VZ
339WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
340 class WXDLLIMPEXP_ADV);
afebb87b 341
f460c29d 342class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
4ed7af08
RR
343 public wxScrollHelperNative
344{
87f0efe2
RR
345 friend class wxDataViewMainWindow;
346 friend class wxDataViewHeaderWindowBase;
347 friend class wxDataViewHeaderWindow;
348 friend class wxDataViewHeaderWindowMSW;
9861f022 349 friend class wxDataViewColumn;
87f0efe2 350
4ed7af08
RR
351public:
352 wxDataViewCtrl() : wxScrollHelperNative(this)
353 {
354 Init();
355 }
f554a14b 356
4ed7af08
RR
357 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
358 const wxPoint& pos = wxDefaultPosition,
359 const wxSize& size = wxDefaultSize, long style = 0,
f554a14b 360 const wxValidator& validator = wxDefaultValidator )
4b3feaa7 361 : wxScrollHelperNative(this)
4ed7af08
RR
362 {
363 Create(parent, id, pos, size, style, validator );
364 }
365
366 virtual ~wxDataViewCtrl();
367
368 void Init();
369
370 bool Create(wxWindow *parent, wxWindowID id,
371 const wxPoint& pos = wxDefaultPosition,
372 const wxSize& size = wxDefaultSize, long style = 0,
373 const wxValidator& validator = wxDefaultValidator );
374
aba9bfd0 375 virtual bool AssociateModel( wxDataViewModel *model );
19723525 376
4ed7af08 377 virtual bool AppendColumn( wxDataViewColumn *col );
736fe67c 378 virtual bool PrependColumn( wxDataViewColumn *col );
19723525 379 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
f554a14b 380
3b6280be
RR
381 virtual void DoSetExpanderColumn();
382 virtual void DoSetIndent();
383
afebb87b
RR
384 virtual unsigned int GetColumnCount() const;
385 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
386 virtual bool DeleteColumn( wxDataViewColumn *column );
387 virtual bool ClearColumns();
453091c2 388 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
afebb87b 389
21f47fb9
RR
390 virtual wxDataViewColumn *GetSortingColumn() const;
391
fbda518c 392 virtual wxDataViewItem GetSelection() const;
b7e9f8b1
RR
393 virtual int GetSelections( wxDataViewItemArray & sel ) const;
394 virtual void SetSelections( const wxDataViewItemArray & sel );
395 virtual void Select( const wxDataViewItem & item );
396 virtual void Unselect( const wxDataViewItem & item );
397 virtual bool IsSelected( const wxDataViewItem & item ) const;
398
66e09788
RR
399 virtual void SelectAll();
400 virtual void UnselectAll();
401
402 virtual void EnsureVisible( const wxDataViewItem & item,
fbda518c 403 const wxDataViewColumn *column = NULL );
a87b466d 404 virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const;
fbda518c 405 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const;
66e09788 406
afebb87b
RR
407 virtual void Expand( const wxDataViewItem & item );
408 virtual void Collapse( const wxDataViewItem & item );
788432e3
RR
409
410 virtual void SetFocus();
afebb87b 411
66e09788 412protected:
b7e9f8b1
RR
413 virtual int GetSelections( wxArrayInt & sel ) const;
414 virtual void SetSelections( const wxArrayInt & sel );
415 virtual void Select( int row );
416 virtual void Unselect( int row );
417 virtual bool IsSelected( int row ) const;
418 virtual void SelectRange( int from, int to );
419 virtual void UnselectRange( int from, int to );
420
fbda518c 421 virtual void EnsureVisible( int row, int column );
b7e9f8b1
RR
422
423 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
424 virtual int GetRowByItem( const wxDataViewItem & item ) const;
425
57f2a652
RR
426 wxDataViewColumn* GetSortingColumn() { return m_sortingColumn; }
427 void SetSortingColumn( wxDataViewColumn* column ) { m_sortingColumn = column; }
6ff7eee7 428
9861f022
RR
429public: // utility functions not part of the API
430
87f0efe2 431 // returns the "best" width for the idx-th column
9861f022 432 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
87f0efe2 433 {
9861f022 434 return GetClientSize().GetWidth() / GetColumnCount();
87f0efe2
RR
435 }
436
fc8c1a15
RR
437 // called by header window after reorder
438 void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos );
439
9861f022
RR
440 // updates the header window after a change in a column setting
441 void OnColumnChange();
87f0efe2 442
1e510b1e 443 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
99d471a5 444
4ed7af08 445private:
ad386793
RR
446 wxDataViewColumnList m_cols;
447 wxDataViewModelNotifier *m_notifier;
448 wxDataViewMainWindow *m_clientArea;
449 wxDataViewHeaderWindow *m_headerArea;
450 wxDataViewColumn *m_sortingColumn;
f554a14b 451
4ed7af08 452private:
4b3feaa7 453 void OnSize( wxSizeEvent &event );
2571a33f 454 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
f554a14b 455
4ed7af08
RR
456 // we need to return a special WM_GETDLGCODE value to process just the
457 // arrows but let the other navigation characters through
458#ifdef __WXMSW__
459 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
460#endif // __WXMSW__
461
462 WX_FORWARD_TO_SCROLL_HELPER()
4b3feaa7 463
4ed7af08
RR
464private:
465 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
466 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
4b3feaa7 467 DECLARE_EVENT_TABLE()
4ed7af08
RR
468};
469
470
471#endif // __GENERICDATAVIEWCTRLH__