]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dataview.h
no real changes, just some cleanup
[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
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef __GENERICDATAVIEWCTRLH__
11#define __GENERICDATAVIEWCTRLH__
12
13#include "wx/defs.h"
14#include "wx/object.h"
15#include "wx/list.h"
16#include "wx/control.h"
9d14de69 17#include "wx/scrolwin.h"
2586d4a1 18#include "wx/icon.h"
4ed7af08 19
f554a14b 20// ---------------------------------------------------------
4ed7af08 21// classes
f554a14b 22// ---------------------------------------------------------
4ed7af08 23
b5dbe15d
VS
24class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
25class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow;
26class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
4ed7af08 27
f554a14b 28// ---------------------------------------------------------
baa9ebc4 29// wxDataViewRenderer
f554a14b 30// ---------------------------------------------------------
4ed7af08 31
baa9ebc4 32class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
4ed7af08
RR
33{
34public:
87f0efe2 35 wxDataViewRenderer( const wxString &varianttype,
9861f022
RR
36 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
37 int align = wxDVR_DEFAULT_ALIGNMENT );
baa9ebc4 38 virtual ~wxDataViewRenderer();
4ed7af08 39
3d9d7cc4 40 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
9861f022
RR
41 virtual wxSize GetSize() const = 0;
42
43 virtual void SetAlignment( int align )
44 { m_align=align; }
45 virtual int GetAlignment() const
46 { return m_align; }
47
48 virtual void SetMode( wxDataViewCellMode mode )
49 { m_mode=mode; }
50 virtual wxDataViewCellMode GetMode() const
51 { return m_mode; }
f554a14b
WS
52
53 virtual bool Activate( wxRect WXUNUSED(cell),
aba9bfd0 54 wxDataViewModel *WXUNUSED(model),
704c3490 55 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 56 unsigned int WXUNUSED(col) )
3d9d7cc4 57 { return false; }
f554a14b
WS
58
59 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
60 wxRect WXUNUSED(cell),
aba9bfd0 61 wxDataViewModel *WXUNUSED(model),
704c3490 62 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 63 unsigned int WXUNUSED(col) )
f554a14b
WS
64 { return false; }
65 virtual bool RightClick( wxPoint WXUNUSED(cursor),
66 wxRect WXUNUSED(cell),
aba9bfd0 67 wxDataViewModel *WXUNUSED(model),
704c3490 68 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 69 unsigned int WXUNUSED(col) )
f554a14b
WS
70 { return false; }
71 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
72 wxRect WXUNUSED(cell),
aba9bfd0 73 wxDataViewModel *WXUNUSED(model),
704c3490 74 const wxDataViewItem & WXUNUSED(item),
aba9bfd0 75 unsigned int WXUNUSED(col) )
f554a14b
WS
76 { return false; }
77
3d9d7cc4
RR
78 // Create DC on request
79 virtual wxDC *GetDC();
f554a14b 80
3d9d7cc4 81private:
99d471a5
RR
82 wxDC *m_dc;
83 int m_align;
84 wxDataViewCellMode m_mode;
f554a14b 85
4ed7af08 86protected:
baa9ebc4 87 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
4ed7af08 88};
f554a14b
WS
89
90// ---------------------------------------------------------
baa9ebc4 91// wxDataViewCustomRenderer
f554a14b 92// ---------------------------------------------------------
4ed7af08 93
baa9ebc4 94class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
4ed7af08
RR
95{
96public:
baa9ebc4 97 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
9861f022
RR
98 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
99 int align = wxDVR_DEFAULT_ALIGNMENT );
f554a14b 100
4ed7af08 101protected:
baa9ebc4 102 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
4ed7af08 103};
f554a14b 104
99d471a5 105
f554a14b 106// ---------------------------------------------------------
baa9ebc4 107// wxDataViewTextRenderer
f554a14b 108// ---------------------------------------------------------
4ed7af08 109
baa9ebc4 110class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
111{
112public:
baa9ebc4 113 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
9861f022
RR
114 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
115 int align = wxDVR_DEFAULT_ALIGNMENT );
4ed7af08
RR
116
117 bool SetValue( const wxVariant &value );
9861f022 118 bool GetValue( wxVariant &value ) const;
f554a14b 119
3d9d7cc4 120 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 121 wxSize GetSize() const;
f554a14b 122
99d471a5
RR
123 // in-place editing
124 virtual bool HasEditorCtrl();
125 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
126 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
127
90675b95 128private:
99d471a5 129 wxString m_text;
f554a14b 130
4ed7af08 131protected:
baa9ebc4 132 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
4ed7af08 133};
f554a14b 134
2586d4a1 135// ---------------------------------------------------------
baa9ebc4 136// wxDataViewBitmapRenderer
2586d4a1
RR
137// ---------------------------------------------------------
138
baa9ebc4 139class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
2586d4a1
RR
140{
141public:
baa9ebc4 142 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
9861f022
RR
143 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
144 int align = wxDVR_DEFAULT_ALIGNMENT );
2586d4a1
RR
145
146 bool SetValue( const wxVariant &value );
9861f022 147 bool GetValue( wxVariant &value ) const;
2586d4a1
RR
148
149 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 150 wxSize GetSize() const;
2586d4a1
RR
151
152private:
153 wxIcon m_icon;
154 wxBitmap m_bitmap;
155
156protected:
baa9ebc4 157 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
2586d4a1
RR
158};
159
f554a14b 160// ---------------------------------------------------------
baa9ebc4 161// wxDataViewToggleRenderer
f554a14b 162// ---------------------------------------------------------
4ed7af08 163
baa9ebc4 164class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
165{
166public:
baa9ebc4 167 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
9861f022
RR
168 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
169 int align = wxDVR_DEFAULT_ALIGNMENT );
3d9d7cc4
RR
170
171 bool SetValue( const wxVariant &value );
9861f022 172 bool GetValue( wxVariant &value ) const;
f554a14b 173
3d9d7cc4 174 bool Render( wxRect cell, wxDC *dc, int state );
aba9bfd0
RR
175 bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
176 unsigned int col );
9861f022 177 wxSize GetSize() const;
f554a14b 178
90675b95
RR
179private:
180 bool m_toggle;
f554a14b 181
4ed7af08 182protected:
baa9ebc4 183 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
4ed7af08 184};
f554a14b
WS
185
186// ---------------------------------------------------------
baa9ebc4 187// wxDataViewProgressRenderer
f554a14b 188// ---------------------------------------------------------
4ed7af08 189
baa9ebc4 190class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
191{
192public:
baa9ebc4
RR
193 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
194 const wxString &varianttype = wxT("long"),
9861f022
RR
195 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
196 int align = wxDVR_DEFAULT_ALIGNMENT );
baa9ebc4 197 virtual ~wxDataViewProgressRenderer();
f554a14b 198
4ed7af08 199 bool SetValue( const wxVariant &value );
9861f022 200 bool GetValue( wxVariant& value ) const;
f554a14b 201
4ed7af08 202 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 203 virtual wxSize GetSize() const;
f554a14b 204
4ed7af08
RR
205private:
206 wxString m_label;
207 int m_value;
f554a14b 208
4ed7af08 209protected:
baa9ebc4 210 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
4ed7af08 211};
f554a14b
WS
212
213// ---------------------------------------------------------
baa9ebc4 214// wxDataViewDateRenderer
f554a14b 215// ---------------------------------------------------------
4ed7af08 216
baa9ebc4 217class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
218{
219public:
baa9ebc4 220 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
9861f022
RR
221 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
222 int align = wxDVR_DEFAULT_ALIGNMENT );
f554a14b 223
4ed7af08 224 bool SetValue( const wxVariant &value );
9861f022 225 bool GetValue( wxVariant& value ) const;
f554a14b 226
4ed7af08 227 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 228 virtual wxSize GetSize() const;
4ed7af08 229 virtual bool Activate( wxRect cell,
aba9bfd0 230 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
f554a14b 231
4ed7af08
RR
232private:
233 wxDateTime m_date;
f554a14b 234
4ed7af08 235protected:
baa9ebc4 236 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
4ed7af08 237};
f554a14b
WS
238
239// ---------------------------------------------------------
4ed7af08 240// wxDataViewColumn
f554a14b 241// ---------------------------------------------------------
4ed7af08 242
f460c29d 243class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
4ed7af08 244{
87f0efe2
RR
245 friend class wxDataViewHeaderWindowBase;
246 friend class wxDataViewHeaderWindow;
247 friend class wxDataViewHeaderWindowMSW;
248
4ed7af08 249public:
87f0efe2
RR
250 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
251 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
252 wxAlignment align = wxALIGN_CENTER,
253 int flags = wxDATAVIEW_COL_RESIZABLE );
254 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
255 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
256 wxAlignment align = wxALIGN_CENTER,
257 int flags = wxDATAVIEW_COL_RESIZABLE );
4ed7af08
RR
258 virtual ~wxDataViewColumn();
259
9861f022
RR
260 // setters:
261
262 virtual void SetTitle( const wxString &title )
263 { m_title=title; }
87f0efe2
RR
264 virtual void SetAlignment( wxAlignment align )
265 { m_align=align; }
9861f022
RR
266 virtual void SetMinWidth( int minWidth )
267 { m_minWidth=minWidth; }
268 virtual void SetWidth( int width );
31fb32e1 269 virtual void SetSortable( bool sortable );
9861f022
RR
270 virtual void SetResizeable( bool resizeable );
271 virtual void SetHidden( bool hidden );
47cef10f 272 virtual void SetSortOrder( bool ascending );
87f0efe2 273
87f0efe2 274
9861f022
RR
275 // getters:
276
277 virtual wxString GetTitle() const
278 { return m_title; }
279 virtual wxAlignment GetAlignment() const
280 { return m_align; }
281 virtual int GetWidth() const
282 { return m_width; }
283 virtual int GetMinWidth() const
284 { return m_minWidth; }
285 virtual bool IsSortable() const
286 { return (m_flags & wxDATAVIEW_COL_SORTABLE) != 0; }
287 virtual bool IsResizeable() const
288 { return (m_flags & wxDATAVIEW_COL_RESIZABLE) != 0; }
289 virtual bool IsHidden() const
290 { return (m_flags & wxDATAVIEW_COL_HIDDEN) != 0; }
291 virtual bool IsSortOrderAscending() const;
f554a14b 292
f554a14b 293
4ed7af08 294private:
533544f2 295 int m_width;
9861f022
RR
296 int m_minWidth;
297 int m_flags;
298 wxAlignment m_align;
299 wxString m_title;
c3112d56 300 bool m_ascending;
87f0efe2
RR
301
302 void Init(int width);
4ed7af08 303
9861f022
RR
304 // like SetWidth() but does not ask the header window of the
305 // wxDataViewCtrl to reflect the width-change.
306 void SetInternalWidth(int width);
307
4ed7af08
RR
308protected:
309 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
310};
311
f554a14b 312// ---------------------------------------------------------
4ed7af08 313// wxDataViewCtrl
f554a14b 314// ---------------------------------------------------------
4ed7af08 315
f460c29d 316class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
4ed7af08
RR
317 public wxScrollHelperNative
318{
87f0efe2
RR
319 friend class wxDataViewMainWindow;
320 friend class wxDataViewHeaderWindowBase;
321 friend class wxDataViewHeaderWindow;
322 friend class wxDataViewHeaderWindowMSW;
9861f022 323 friend class wxDataViewColumn;
87f0efe2 324
4ed7af08
RR
325public:
326 wxDataViewCtrl() : wxScrollHelperNative(this)
327 {
328 Init();
329 }
f554a14b 330
4ed7af08
RR
331 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
332 const wxPoint& pos = wxDefaultPosition,
333 const wxSize& size = wxDefaultSize, long style = 0,
f554a14b 334 const wxValidator& validator = wxDefaultValidator )
4b3feaa7 335 : wxScrollHelperNative(this)
4ed7af08
RR
336 {
337 Create(parent, id, pos, size, style, validator );
338 }
339
340 virtual ~wxDataViewCtrl();
341
342 void Init();
343
344 bool Create(wxWindow *parent, wxWindowID id,
345 const wxPoint& pos = wxDefaultPosition,
346 const wxSize& size = wxDefaultSize, long style = 0,
347 const wxValidator& validator = wxDefaultValidator );
348
aba9bfd0 349 virtual bool AssociateModel( wxDataViewModel *model );
4ed7af08 350 virtual bool AppendColumn( wxDataViewColumn *col );
f554a14b 351
3b6280be
RR
352 virtual void DoSetExpanderColumn();
353 virtual void DoSetIndent();
354
704c3490
RR
355 virtual wxDataViewItem GetSelection() ;
356
aba9bfd0 357/********************selection code*********************
6ff7eee7
RR
358 virtual void SetSelection( int row ); // -1 for unselect
359 virtual void SetSelectionRange( unsigned int from, unsigned int to );
360 virtual void SetSelections( const wxArrayInt& aSelections);
fc211fe5 361 virtual void Unselect( unsigned int row );
6ff7eee7
RR
362
363 virtual bool IsSelected( unsigned int row ) const;
364 virtual int GetSelection() const;
365 virtual int GetSelections(wxArrayInt& aSelections) const;
aba9bfd0 366*****************************************************/
6ff7eee7 367
9861f022
RR
368public: // utility functions not part of the API
369
87f0efe2 370 // returns the "best" width for the idx-th column
9861f022 371 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
87f0efe2 372 {
9861f022 373 return GetClientSize().GetWidth() / GetColumnCount();
87f0efe2
RR
374 }
375
9861f022
RR
376 // updates the header window after a change in a column setting
377 void OnColumnChange();
87f0efe2 378
1e510b1e 379 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
99d471a5 380
4ed7af08 381private:
aba9bfd0 382 wxDataViewModelNotifier *m_notifier;
4b3feaa7
RR
383 wxDataViewMainWindow *m_clientArea;
384 wxDataViewHeaderWindow *m_headerArea;
f554a14b 385
4ed7af08 386private:
4b3feaa7 387 void OnSize( wxSizeEvent &event );
f554a14b 388
4ed7af08
RR
389 // we need to return a special WM_GETDLGCODE value to process just the
390 // arrows but let the other navigation characters through
391#ifdef __WXMSW__
392 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
393#endif // __WXMSW__
394
395 WX_FORWARD_TO_SCROLL_HELPER()
4b3feaa7 396
4ed7af08
RR
397private:
398 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
399 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
4b3feaa7 400 DECLARE_EVENT_TABLE()
4ed7af08
RR
401};
402
403
404#endif // __GENERICDATAVIEWCTRLH__