]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dataview.h
Always make wxWindow::SetFocus() focus the window, overriding SetCanFocus, some more...
[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
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; }
f554a14b
WS
53
54 virtual bool Activate( wxRect WXUNUSED(cell),
aba9bfd0 55 wxDataViewModel *WXUNUSED(model),
704c3490 56 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 57 unsigned int WXUNUSED(col) )
3d9d7cc4 58 { return false; }
f554a14b
WS
59
60 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
61 wxRect WXUNUSED(cell),
aba9bfd0 62 wxDataViewModel *WXUNUSED(model),
704c3490 63 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 64 unsigned int WXUNUSED(col) )
f554a14b
WS
65 { return false; }
66 virtual bool RightClick( wxPoint WXUNUSED(cursor),
67 wxRect WXUNUSED(cell),
aba9bfd0 68 wxDataViewModel *WXUNUSED(model),
704c3490 69 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 70 unsigned int WXUNUSED(col) )
f554a14b
WS
71 { return false; }
72 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
73 wxRect WXUNUSED(cell),
aba9bfd0 74 wxDataViewModel *WXUNUSED(model),
704c3490 75 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 76 unsigned int WXUNUSED(col) )
f554a14b
WS
77 { return false; }
78
3d9d7cc4
RR
79 // Create DC on request
80 virtual wxDC *GetDC();
f554a14b 81
3d9d7cc4 82private:
99d471a5
RR
83 wxDC *m_dc;
84 int m_align;
85 wxDataViewCellMode m_mode;
f554a14b 86
4ed7af08 87protected:
baa9ebc4 88 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
4ed7af08 89};
f554a14b
WS
90
91// ---------------------------------------------------------
baa9ebc4 92// wxDataViewCustomRenderer
f554a14b 93// ---------------------------------------------------------
4ed7af08 94
baa9ebc4 95class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
4ed7af08
RR
96{
97public:
baa9ebc4 98 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
9861f022
RR
99 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
100 int align = wxDVR_DEFAULT_ALIGNMENT );
f554a14b 101
4ed7af08 102protected:
baa9ebc4 103 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
4ed7af08 104};
f554a14b 105
99d471a5 106
f554a14b 107// ---------------------------------------------------------
baa9ebc4 108// wxDataViewTextRenderer
f554a14b 109// ---------------------------------------------------------
4ed7af08 110
baa9ebc4 111class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
112{
113public:
baa9ebc4 114 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
9861f022
RR
115 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
116 int align = wxDVR_DEFAULT_ALIGNMENT );
4ed7af08
RR
117
118 bool SetValue( const wxVariant &value );
9861f022 119 bool GetValue( wxVariant &value ) const;
f554a14b 120
3d9d7cc4 121 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 122 wxSize GetSize() const;
f554a14b 123
99d471a5
RR
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
90675b95 129private:
99d471a5 130 wxString m_text;
f554a14b 131
4ed7af08 132protected:
baa9ebc4 133 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
4ed7af08 134};
f554a14b 135
2586d4a1 136// ---------------------------------------------------------
baa9ebc4 137// wxDataViewBitmapRenderer
2586d4a1
RR
138// ---------------------------------------------------------
139
baa9ebc4 140class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
2586d4a1
RR
141{
142public:
baa9ebc4 143 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
9861f022
RR
144 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
145 int align = wxDVR_DEFAULT_ALIGNMENT );
2586d4a1
RR
146
147 bool SetValue( const wxVariant &value );
9861f022 148 bool GetValue( wxVariant &value ) const;
2586d4a1
RR
149
150 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 151 wxSize GetSize() const;
2586d4a1
RR
152
153private:
154 wxIcon m_icon;
155 wxBitmap m_bitmap;
156
157protected:
baa9ebc4 158 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
2586d4a1
RR
159};
160
f554a14b 161// ---------------------------------------------------------
baa9ebc4 162// wxDataViewToggleRenderer
f554a14b 163// ---------------------------------------------------------
4ed7af08 164
baa9ebc4 165class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
166{
167public:
baa9ebc4 168 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
9861f022
RR
169 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
170 int align = wxDVR_DEFAULT_ALIGNMENT );
3d9d7cc4
RR
171
172 bool SetValue( const wxVariant &value );
9861f022 173 bool GetValue( wxVariant &value ) const;
f554a14b 174
3d9d7cc4 175 bool Render( wxRect cell, wxDC *dc, int state );
aba9bfd0
RR
176 bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
177 unsigned int col );
9861f022 178 wxSize GetSize() const;
f554a14b 179
90675b95
RR
180private:
181 bool m_toggle;
f554a14b 182
4ed7af08 183protected:
baa9ebc4 184 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
4ed7af08 185};
f554a14b
WS
186
187// ---------------------------------------------------------
baa9ebc4 188// wxDataViewProgressRenderer
f554a14b 189// ---------------------------------------------------------
4ed7af08 190
baa9ebc4 191class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
192{
193public:
baa9ebc4
RR
194 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
195 const wxString &varianttype = wxT("long"),
9861f022
RR
196 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
197 int align = wxDVR_DEFAULT_ALIGNMENT );
baa9ebc4 198 virtual ~wxDataViewProgressRenderer();
f554a14b 199
4ed7af08 200 bool SetValue( const wxVariant &value );
9861f022 201 bool GetValue( wxVariant& value ) const;
f554a14b 202
4ed7af08 203 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 204 virtual wxSize GetSize() const;
f554a14b 205
4ed7af08
RR
206private:
207 wxString m_label;
208 int m_value;
f554a14b 209
4ed7af08 210protected:
baa9ebc4 211 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
4ed7af08 212};
24c4a50f
RR
213
214// ---------------------------------------------------------
215// wxDataViewIconTextRenderer
216// ---------------------------------------------------------
217
218class wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
219{
220public:
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
236private:
237 wxDataViewIconText m_value;
238
239protected:
240 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
241};
f554a14b
WS
242
243// ---------------------------------------------------------
baa9ebc4 244// wxDataViewDateRenderer
f554a14b 245// ---------------------------------------------------------
4ed7af08 246
baa9ebc4 247class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
248{
249public:
baa9ebc4 250 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
9861f022
RR
251 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
252 int align = wxDVR_DEFAULT_ALIGNMENT );
f554a14b 253
4ed7af08 254 bool SetValue( const wxVariant &value );
9861f022 255 bool GetValue( wxVariant& value ) const;
f554a14b 256
4ed7af08 257 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 258 virtual wxSize GetSize() const;
4ed7af08 259 virtual bool Activate( wxRect cell,
aba9bfd0 260 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
f554a14b 261
4ed7af08
RR
262private:
263 wxDateTime m_date;
f554a14b 264
4ed7af08 265protected:
baa9ebc4 266 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
4ed7af08 267};
f554a14b
WS
268
269// ---------------------------------------------------------
4ed7af08 270// wxDataViewColumn
f554a14b 271// ---------------------------------------------------------
4ed7af08 272
f460c29d 273class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
4ed7af08 274{
87f0efe2
RR
275 friend class wxDataViewHeaderWindowBase;
276 friend class wxDataViewHeaderWindow;
277 friend class wxDataViewHeaderWindowMSW;
278
4ed7af08 279public:
87f0efe2
RR
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 );
4ed7af08
RR
288 virtual ~wxDataViewColumn();
289
9861f022
RR
290 // setters:
291
292 virtual void SetTitle( const wxString &title )
293 { m_title=title; }
87f0efe2
RR
294 virtual void SetAlignment( wxAlignment align )
295 { m_align=align; }
9861f022
RR
296 virtual void SetMinWidth( int minWidth )
297 { m_minWidth=minWidth; }
298 virtual void SetWidth( int width );
31fb32e1 299 virtual void SetSortable( bool sortable );
9861f022
RR
300 virtual void SetResizeable( bool resizeable );
301 virtual void SetHidden( bool hidden );
47cef10f 302 virtual void SetSortOrder( bool ascending );
87f0efe2 303
87f0efe2 304
9861f022
RR
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;
f554a14b 322
f554a14b 323
4ed7af08 324private:
533544f2 325 int m_width;
9861f022
RR
326 int m_minWidth;
327 int m_flags;
328 wxAlignment m_align;
329 wxString m_title;
c3112d56 330 bool m_ascending;
87f0efe2
RR
331
332 void Init(int width);
4ed7af08 333
9861f022
RR
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
4ed7af08
RR
338protected:
339 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
340};
341
f554a14b 342// ---------------------------------------------------------
4ed7af08 343// wxDataViewCtrl
f554a14b 344// ---------------------------------------------------------
4ed7af08 345
afebb87b
RR
346WX_DECLARE_LIST(wxDataViewColumn, wxDataViewColumnList );
347
f460c29d 348class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
4ed7af08
RR
349 public wxScrollHelperNative
350{
87f0efe2
RR
351 friend class wxDataViewMainWindow;
352 friend class wxDataViewHeaderWindowBase;
353 friend class wxDataViewHeaderWindow;
354 friend class wxDataViewHeaderWindowMSW;
9861f022 355 friend class wxDataViewColumn;
87f0efe2 356
4ed7af08
RR
357public:
358 wxDataViewCtrl() : wxScrollHelperNative(this)
359 {
57f2a652
RR
360 //No sorting column at start, I think
361 m_sortingColumn = NULL;
4ed7af08
RR
362 Init();
363 }
f554a14b 364
4ed7af08
RR
365 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
366 const wxPoint& pos = wxDefaultPosition,
367 const wxSize& size = wxDefaultSize, long style = 0,
f554a14b 368 const wxValidator& validator = wxDefaultValidator )
4b3feaa7 369 : wxScrollHelperNative(this)
4ed7af08 370 {
57f2a652 371 m_sortingColumn = NULL;
4ed7af08
RR
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
aba9bfd0 384 virtual bool AssociateModel( wxDataViewModel *model );
4ed7af08 385 virtual bool AppendColumn( wxDataViewColumn *col );
f554a14b 386
3b6280be
RR
387 virtual void DoSetExpanderColumn();
388 virtual void DoSetIndent();
389
afebb87b
RR
390 virtual unsigned int GetColumnCount() const;
391 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
392 virtual bool DeleteColumn( wxDataViewColumn *column );
393 virtual bool ClearColumns();
453091c2 394 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
afebb87b 395
21f47fb9
RR
396 virtual wxDataViewColumn *GetSortingColumn() const;
397
fbda518c 398 virtual wxDataViewItem GetSelection() const;
b7e9f8b1
RR
399 virtual int GetSelections( wxDataViewItemArray & sel ) const;
400 virtual void SetSelections( const wxDataViewItemArray & sel );
401 virtual void Select( const wxDataViewItem & item );
402 virtual void Unselect( const wxDataViewItem & item );
403 virtual bool IsSelected( const wxDataViewItem & item ) const;
404
66e09788
RR
405 virtual void SelectAll();
406 virtual void UnselectAll();
407
408 virtual void EnsureVisible( const wxDataViewItem & item,
fbda518c 409 const wxDataViewColumn *column = NULL );
a87b466d 410 virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const;
fbda518c 411 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const;
66e09788 412
afebb87b
RR
413 virtual void Expand( const wxDataViewItem & item );
414 virtual void Collapse( const wxDataViewItem & item );
415
66e09788 416protected:
b7e9f8b1
RR
417 virtual int GetSelections( wxArrayInt & sel ) const;
418 virtual void SetSelections( const wxArrayInt & sel );
419 virtual void Select( int row );
420 virtual void Unselect( int row );
421 virtual bool IsSelected( int row ) const;
422 virtual void SelectRange( int from, int to );
423 virtual void UnselectRange( int from, int to );
424
fbda518c 425 virtual void EnsureVisible( int row, int column );
b7e9f8b1
RR
426
427 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
428 virtual int GetRowByItem( const wxDataViewItem & item ) const;
429
57f2a652
RR
430 wxDataViewColumn* GetSortingColumn() { return m_sortingColumn; }
431 void SetSortingColumn( wxDataViewColumn* column ) { m_sortingColumn = column; }
6ff7eee7 432
9861f022
RR
433public: // utility functions not part of the API
434
87f0efe2 435 // returns the "best" width for the idx-th column
9861f022 436 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
87f0efe2 437 {
9861f022 438 return GetClientSize().GetWidth() / GetColumnCount();
87f0efe2
RR
439 }
440
9861f022
RR
441 // updates the header window after a change in a column setting
442 void OnColumnChange();
87f0efe2 443
1e510b1e 444 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
99d471a5 445
4ed7af08 446private:
afebb87b 447 wxDataViewColumnList m_cols;
aba9bfd0 448 wxDataViewModelNotifier *m_notifier;
4b3feaa7
RR
449 wxDataViewMainWindow *m_clientArea;
450 wxDataViewHeaderWindow *m_headerArea;
57f2a652 451 wxDataViewColumn* m_sortingColumn;
f554a14b 452
4ed7af08 453private:
4b3feaa7 454 void OnSize( wxSizeEvent &event );
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__