]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dataview.h
add HDF_SORTUP/DOWN definitions
[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
52e750fc
RR
102 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
103
4ed7af08 104protected:
baa9ebc4 105 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
4ed7af08 106};
f554a14b 107
99d471a5 108
f554a14b 109// ---------------------------------------------------------
baa9ebc4 110// wxDataViewTextRenderer
f554a14b 111// ---------------------------------------------------------
4ed7af08 112
baa9ebc4 113class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
114{
115public:
baa9ebc4 116 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
9861f022
RR
117 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
118 int align = wxDVR_DEFAULT_ALIGNMENT );
4ed7af08
RR
119
120 bool SetValue( const wxVariant &value );
9861f022 121 bool GetValue( wxVariant &value ) const;
f554a14b 122
3d9d7cc4 123 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 124 wxSize GetSize() const;
f554a14b 125
99d471a5
RR
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
90675b95 131private:
99d471a5 132 wxString m_text;
f554a14b 133
4ed7af08 134protected:
baa9ebc4 135 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
4ed7af08 136};
f554a14b 137
2586d4a1 138// ---------------------------------------------------------
baa9ebc4 139// wxDataViewBitmapRenderer
2586d4a1
RR
140// ---------------------------------------------------------
141
baa9ebc4 142class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
2586d4a1
RR
143{
144public:
baa9ebc4 145 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
9861f022
RR
146 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
147 int align = wxDVR_DEFAULT_ALIGNMENT );
2586d4a1
RR
148
149 bool SetValue( const wxVariant &value );
9861f022 150 bool GetValue( wxVariant &value ) const;
2586d4a1
RR
151
152 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 153 wxSize GetSize() const;
2586d4a1
RR
154
155private:
156 wxIcon m_icon;
157 wxBitmap m_bitmap;
158
159protected:
baa9ebc4 160 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
2586d4a1
RR
161};
162
f554a14b 163// ---------------------------------------------------------
baa9ebc4 164// wxDataViewToggleRenderer
f554a14b 165// ---------------------------------------------------------
4ed7af08 166
baa9ebc4 167class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
168{
169public:
baa9ebc4 170 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
9861f022
RR
171 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
172 int align = wxDVR_DEFAULT_ALIGNMENT );
3d9d7cc4
RR
173
174 bool SetValue( const wxVariant &value );
9861f022 175 bool GetValue( wxVariant &value ) const;
f554a14b 176
3d9d7cc4 177 bool Render( wxRect cell, wxDC *dc, int state );
aba9bfd0
RR
178 bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
179 unsigned int col );
9861f022 180 wxSize GetSize() const;
f554a14b 181
90675b95
RR
182private:
183 bool m_toggle;
f554a14b 184
4ed7af08 185protected:
baa9ebc4 186 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
4ed7af08 187};
f554a14b
WS
188
189// ---------------------------------------------------------
baa9ebc4 190// wxDataViewProgressRenderer
f554a14b 191// ---------------------------------------------------------
4ed7af08 192
baa9ebc4 193class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
194{
195public:
baa9ebc4
RR
196 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
197 const wxString &varianttype = wxT("long"),
9861f022
RR
198 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
199 int align = wxDVR_DEFAULT_ALIGNMENT );
baa9ebc4 200 virtual ~wxDataViewProgressRenderer();
f554a14b 201
4ed7af08 202 bool SetValue( const wxVariant &value );
9861f022 203 bool GetValue( wxVariant& value ) const;
f554a14b 204
4ed7af08 205 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 206 virtual wxSize GetSize() const;
f554a14b 207
4ed7af08
RR
208private:
209 wxString m_label;
210 int m_value;
f554a14b 211
4ed7af08 212protected:
baa9ebc4 213 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
4ed7af08 214};
24c4a50f
RR
215
216// ---------------------------------------------------------
217// wxDataViewIconTextRenderer
218// ---------------------------------------------------------
219
220class wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
221{
222public:
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
238private:
239 wxDataViewIconText m_value;
240
241protected:
242 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
243};
f554a14b
WS
244
245// ---------------------------------------------------------
baa9ebc4 246// wxDataViewDateRenderer
f554a14b 247// ---------------------------------------------------------
4ed7af08 248
baa9ebc4 249class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
250{
251public:
baa9ebc4 252 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
9861f022
RR
253 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
254 int align = wxDVR_DEFAULT_ALIGNMENT );
f554a14b 255
4ed7af08 256 bool SetValue( const wxVariant &value );
9861f022 257 bool GetValue( wxVariant& value ) const;
f554a14b 258
4ed7af08 259 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 260 virtual wxSize GetSize() const;
4ed7af08 261 virtual bool Activate( wxRect cell,
aba9bfd0 262 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
f554a14b 263
4ed7af08
RR
264private:
265 wxDateTime m_date;
f554a14b 266
4ed7af08 267protected:
baa9ebc4 268 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
4ed7af08 269};
f554a14b
WS
270
271// ---------------------------------------------------------
4ed7af08 272// wxDataViewColumn
f554a14b 273// ---------------------------------------------------------
4ed7af08 274
f460c29d 275class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
4ed7af08 276{
87f0efe2
RR
277 friend class wxDataViewHeaderWindowBase;
278 friend class wxDataViewHeaderWindow;
279 friend class wxDataViewHeaderWindowMSW;
280
4ed7af08 281public:
87f0efe2
RR
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 );
4ed7af08
RR
290 virtual ~wxDataViewColumn();
291
9861f022
RR
292 // setters:
293
294 virtual void SetTitle( const wxString &title )
295 { m_title=title; }
87f0efe2
RR
296 virtual void SetAlignment( wxAlignment align )
297 { m_align=align; }
9861f022
RR
298 virtual void SetMinWidth( int minWidth )
299 { m_minWidth=minWidth; }
300 virtual void SetWidth( int width );
31fb32e1 301 virtual void SetSortable( bool sortable );
9861f022
RR
302 virtual void SetResizeable( bool resizeable );
303 virtual void SetHidden( bool hidden );
47cef10f 304 virtual void SetSortOrder( bool ascending );
87f0efe2 305
87f0efe2 306
9861f022
RR
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;
f554a14b 324
f554a14b 325
4ed7af08 326private:
533544f2 327 int m_width;
9861f022
RR
328 int m_minWidth;
329 int m_flags;
330 wxAlignment m_align;
331 wxString m_title;
c3112d56 332 bool m_ascending;
87f0efe2
RR
333
334 void Init(int width);
4ed7af08 335
9861f022
RR
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
4ed7af08
RR
340protected:
341 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
342};
343
f554a14b 344// ---------------------------------------------------------
4ed7af08 345// wxDataViewCtrl
f554a14b 346// ---------------------------------------------------------
4ed7af08 347
afebb87b
RR
348WX_DECLARE_LIST(wxDataViewColumn, wxDataViewColumnList );
349
f460c29d 350class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
4ed7af08
RR
351 public wxScrollHelperNative
352{
87f0efe2
RR
353 friend class wxDataViewMainWindow;
354 friend class wxDataViewHeaderWindowBase;
355 friend class wxDataViewHeaderWindow;
356 friend class wxDataViewHeaderWindowMSW;
9861f022 357 friend class wxDataViewColumn;
87f0efe2 358
4ed7af08
RR
359public:
360 wxDataViewCtrl() : wxScrollHelperNative(this)
361 {
57f2a652
RR
362 //No sorting column at start, I think
363 m_sortingColumn = NULL;
4ed7af08
RR
364 Init();
365 }
f554a14b 366
4ed7af08
RR
367 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
368 const wxPoint& pos = wxDefaultPosition,
369 const wxSize& size = wxDefaultSize, long style = 0,
f554a14b 370 const wxValidator& validator = wxDefaultValidator )
4b3feaa7 371 : wxScrollHelperNative(this)
4ed7af08 372 {
57f2a652 373 m_sortingColumn = NULL;
4ed7af08
RR
374 Create(parent, id, pos, size, style, validator );
375 }
376
377 virtual ~wxDataViewCtrl();
378
379 void Init();
380
381 bool Create(wxWindow *parent, wxWindowID id,
382 const wxPoint& pos = wxDefaultPosition,
383 const wxSize& size = wxDefaultSize, long style = 0,
384 const wxValidator& validator = wxDefaultValidator );
385
aba9bfd0 386 virtual bool AssociateModel( wxDataViewModel *model );
4ed7af08 387 virtual bool AppendColumn( wxDataViewColumn *col );
736fe67c 388 virtual bool PrependColumn( wxDataViewColumn *col );
f554a14b 389
3b6280be
RR
390 virtual void DoSetExpanderColumn();
391 virtual void DoSetIndent();
392
afebb87b
RR
393 virtual unsigned int GetColumnCount() const;
394 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
395 virtual bool DeleteColumn( wxDataViewColumn *column );
396 virtual bool ClearColumns();
453091c2 397 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
afebb87b 398
21f47fb9
RR
399 virtual wxDataViewColumn *GetSortingColumn() const;
400
fbda518c 401 virtual wxDataViewItem GetSelection() const;
b7e9f8b1
RR
402 virtual int GetSelections( wxDataViewItemArray & sel ) const;
403 virtual void SetSelections( const wxDataViewItemArray & sel );
404 virtual void Select( const wxDataViewItem & item );
405 virtual void Unselect( const wxDataViewItem & item );
406 virtual bool IsSelected( const wxDataViewItem & item ) const;
407
66e09788
RR
408 virtual void SelectAll();
409 virtual void UnselectAll();
410
411 virtual void EnsureVisible( const wxDataViewItem & item,
fbda518c 412 const wxDataViewColumn *column = NULL );
a87b466d 413 virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const;
fbda518c 414 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const;
66e09788 415
afebb87b
RR
416 virtual void Expand( const wxDataViewItem & item );
417 virtual void Collapse( const wxDataViewItem & item );
418
66e09788 419protected:
b7e9f8b1
RR
420 virtual int GetSelections( wxArrayInt & sel ) const;
421 virtual void SetSelections( const wxArrayInt & sel );
422 virtual void Select( int row );
423 virtual void Unselect( int row );
424 virtual bool IsSelected( int row ) const;
425 virtual void SelectRange( int from, int to );
426 virtual void UnselectRange( int from, int to );
427
fbda518c 428 virtual void EnsureVisible( int row, int column );
b7e9f8b1
RR
429
430 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
431 virtual int GetRowByItem( const wxDataViewItem & item ) const;
432
57f2a652
RR
433 wxDataViewColumn* GetSortingColumn() { return m_sortingColumn; }
434 void SetSortingColumn( wxDataViewColumn* column ) { m_sortingColumn = column; }
6ff7eee7 435
9861f022
RR
436public: // utility functions not part of the API
437
87f0efe2 438 // returns the "best" width for the idx-th column
9861f022 439 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
87f0efe2 440 {
9861f022 441 return GetClientSize().GetWidth() / GetColumnCount();
87f0efe2
RR
442 }
443
9861f022
RR
444 // updates the header window after a change in a column setting
445 void OnColumnChange();
87f0efe2 446
1e510b1e 447 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
99d471a5 448
4ed7af08 449private:
afebb87b 450 wxDataViewColumnList m_cols;
aba9bfd0 451 wxDataViewModelNotifier *m_notifier;
4b3feaa7
RR
452 wxDataViewMainWindow *m_clientArea;
453 wxDataViewHeaderWindow *m_headerArea;
57f2a652 454 wxDataViewColumn* m_sortingColumn;
f554a14b 455
4ed7af08 456private:
4b3feaa7 457 void OnSize( wxSizeEvent &event );
f554a14b 458
4ed7af08
RR
459 // we need to return a special WM_GETDLGCODE value to process just the
460 // arrows but let the other navigation characters through
461#ifdef __WXMSW__
462 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
463#endif // __WXMSW__
464
465 WX_FORWARD_TO_SCROLL_HELPER()
4b3feaa7 466
4ed7af08
RR
467private:
468 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
469 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
4b3feaa7 470 DECLARE_EVENT_TABLE()
4ed7af08
RR
471};
472
473
474#endif // __GENERICDATAVIEWCTRLH__