]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dataview.h
renamed wxImplStringBuffer to wxStringInternalBuffer
[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};
f554a14b
WS
213
214// ---------------------------------------------------------
baa9ebc4 215// wxDataViewDateRenderer
f554a14b 216// ---------------------------------------------------------
4ed7af08 217
baa9ebc4 218class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
219{
220public:
baa9ebc4 221 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
9861f022
RR
222 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
223 int align = wxDVR_DEFAULT_ALIGNMENT );
f554a14b 224
4ed7af08 225 bool SetValue( const wxVariant &value );
9861f022 226 bool GetValue( wxVariant& value ) const;
f554a14b 227
4ed7af08 228 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 229 virtual wxSize GetSize() const;
4ed7af08 230 virtual bool Activate( wxRect cell,
aba9bfd0 231 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
f554a14b 232
4ed7af08
RR
233private:
234 wxDateTime m_date;
f554a14b 235
4ed7af08 236protected:
baa9ebc4 237 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
4ed7af08 238};
f554a14b
WS
239
240// ---------------------------------------------------------
4ed7af08 241// wxDataViewColumn
f554a14b 242// ---------------------------------------------------------
4ed7af08 243
f460c29d 244class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
4ed7af08 245{
87f0efe2
RR
246 friend class wxDataViewHeaderWindowBase;
247 friend class wxDataViewHeaderWindow;
248 friend class wxDataViewHeaderWindowMSW;
249
4ed7af08 250public:
87f0efe2
RR
251 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
252 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
253 wxAlignment align = wxALIGN_CENTER,
254 int flags = wxDATAVIEW_COL_RESIZABLE );
255 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
256 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
257 wxAlignment align = wxALIGN_CENTER,
258 int flags = wxDATAVIEW_COL_RESIZABLE );
4ed7af08
RR
259 virtual ~wxDataViewColumn();
260
9861f022
RR
261 // setters:
262
263 virtual void SetTitle( const wxString &title )
264 { m_title=title; }
87f0efe2
RR
265 virtual void SetAlignment( wxAlignment align )
266 { m_align=align; }
9861f022
RR
267 virtual void SetMinWidth( int minWidth )
268 { m_minWidth=minWidth; }
269 virtual void SetWidth( int width );
31fb32e1 270 virtual void SetSortable( bool sortable );
9861f022
RR
271 virtual void SetResizeable( bool resizeable );
272 virtual void SetHidden( bool hidden );
47cef10f 273 virtual void SetSortOrder( bool ascending );
87f0efe2 274
87f0efe2 275
9861f022
RR
276 // getters:
277
278 virtual wxString GetTitle() const
279 { return m_title; }
280 virtual wxAlignment GetAlignment() const
281 { return m_align; }
282 virtual int GetWidth() const
283 { return m_width; }
284 virtual int GetMinWidth() const
285 { return m_minWidth; }
286 virtual bool IsSortable() const
287 { return (m_flags & wxDATAVIEW_COL_SORTABLE) != 0; }
288 virtual bool IsResizeable() const
289 { return (m_flags & wxDATAVIEW_COL_RESIZABLE) != 0; }
290 virtual bool IsHidden() const
291 { return (m_flags & wxDATAVIEW_COL_HIDDEN) != 0; }
292 virtual bool IsSortOrderAscending() const;
f554a14b 293
f554a14b 294
4ed7af08 295private:
533544f2 296 int m_width;
9861f022
RR
297 int m_minWidth;
298 int m_flags;
299 wxAlignment m_align;
300 wxString m_title;
c3112d56 301 bool m_ascending;
87f0efe2
RR
302
303 void Init(int width);
4ed7af08 304
9861f022
RR
305 // like SetWidth() but does not ask the header window of the
306 // wxDataViewCtrl to reflect the width-change.
307 void SetInternalWidth(int width);
308
4ed7af08
RR
309protected:
310 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
311};
312
f554a14b 313// ---------------------------------------------------------
4ed7af08 314// wxDataViewCtrl
f554a14b 315// ---------------------------------------------------------
4ed7af08 316
f460c29d 317class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
4ed7af08
RR
318 public wxScrollHelperNative
319{
87f0efe2
RR
320 friend class wxDataViewMainWindow;
321 friend class wxDataViewHeaderWindowBase;
322 friend class wxDataViewHeaderWindow;
323 friend class wxDataViewHeaderWindowMSW;
9861f022 324 friend class wxDataViewColumn;
87f0efe2 325
4ed7af08
RR
326public:
327 wxDataViewCtrl() : wxScrollHelperNative(this)
328 {
329 Init();
330 }
f554a14b 331
4ed7af08
RR
332 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
333 const wxPoint& pos = wxDefaultPosition,
334 const wxSize& size = wxDefaultSize, long style = 0,
f554a14b 335 const wxValidator& validator = wxDefaultValidator )
4b3feaa7 336 : wxScrollHelperNative(this)
4ed7af08
RR
337 {
338 Create(parent, id, pos, size, style, validator );
339 }
340
341 virtual ~wxDataViewCtrl();
342
343 void Init();
344
345 bool Create(wxWindow *parent, wxWindowID id,
346 const wxPoint& pos = wxDefaultPosition,
347 const wxSize& size = wxDefaultSize, long style = 0,
348 const wxValidator& validator = wxDefaultValidator );
349
aba9bfd0 350 virtual bool AssociateModel( wxDataViewModel *model );
4ed7af08 351 virtual bool AppendColumn( wxDataViewColumn *col );
f554a14b 352
3b6280be
RR
353 virtual void DoSetExpanderColumn();
354 virtual void DoSetIndent();
355
b7e9f8b1
RR
356 virtual int GetSelections( wxDataViewItemArray & sel ) const;
357 virtual void SetSelections( const wxDataViewItemArray & sel );
358 virtual void Select( const wxDataViewItem & item );
359 virtual void Unselect( const wxDataViewItem & item );
360 virtual bool IsSelected( const wxDataViewItem & item ) const;
361
362 virtual int GetSelections( wxArrayInt & sel ) const;
363 virtual void SetSelections( const wxArrayInt & sel );
364 virtual void Select( int row );
365 virtual void Unselect( int row );
366 virtual bool IsSelected( int row ) const;
367 virtual void SelectRange( int from, int to );
368 virtual void UnselectRange( int from, int to );
369
370 virtual void SelectAll();
371 virtual void UnselectAll();
372
373 virtual void EnsureVisible( int row );
374 virtual void EnsureVisible( const wxDataViewItem & item );
375
376 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
377 virtual int GetRowByItem( const wxDataViewItem & item ) const;
378
6ff7eee7 379
9861f022
RR
380public: // utility functions not part of the API
381
87f0efe2 382 // returns the "best" width for the idx-th column
9861f022 383 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
87f0efe2 384 {
9861f022 385 return GetClientSize().GetWidth() / GetColumnCount();
87f0efe2
RR
386 }
387
9861f022
RR
388 // updates the header window after a change in a column setting
389 void OnColumnChange();
87f0efe2 390
1e510b1e 391 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
99d471a5 392
4ed7af08 393private:
aba9bfd0 394 wxDataViewModelNotifier *m_notifier;
4b3feaa7
RR
395 wxDataViewMainWindow *m_clientArea;
396 wxDataViewHeaderWindow *m_headerArea;
f554a14b 397
4ed7af08 398private:
4b3feaa7 399 void OnSize( wxSizeEvent &event );
f554a14b 400
4ed7af08
RR
401 // we need to return a special WM_GETDLGCODE value to process just the
402 // arrows but let the other navigation characters through
403#ifdef __WXMSW__
404 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
405#endif // __WXMSW__
406
407 WX_FORWARD_TO_SCROLL_HELPER()
4b3feaa7 408
4ed7af08
RR
409private:
410 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
411 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
4b3feaa7 412 DECLARE_EVENT_TABLE()
4ed7af08
RR
413};
414
415
416#endif // __GENERICDATAVIEWCTRLH__