]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/dataview.h
removed WXWIN_COMPATIBILITY_2_4 from common and wxMSW files (patch 1675546)
[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
f460c29d
RD
24class WXDLLIMPEXP_ADV wxDataViewCtrl;
25class WXDLLIMPEXP_ADV wxDataViewMainWindow;
26class WXDLLIMPEXP_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),
54 wxDataViewListModel *WXUNUSED(model),
0a71f9e9
RR
55 unsigned int WXUNUSED(col),
56 unsigned int WXUNUSED(row) )
3d9d7cc4 57 { return false; }
f554a14b
WS
58
59 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
60 wxRect WXUNUSED(cell),
61 wxDataViewListModel *WXUNUSED(model),
0a71f9e9
RR
62 unsigned int WXUNUSED(col),
63 unsigned int WXUNUSED(row) )
f554a14b
WS
64 { return false; }
65 virtual bool RightClick( wxPoint WXUNUSED(cursor),
66 wxRect WXUNUSED(cell),
67 wxDataViewListModel *WXUNUSED(model),
0a71f9e9
RR
68 unsigned int WXUNUSED(col),
69 unsigned int WXUNUSED(row) )
f554a14b
WS
70 { return false; }
71 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
72 wxRect WXUNUSED(cell),
73 wxDataViewListModel *WXUNUSED(model),
0a71f9e9
RR
74 unsigned int WXUNUSED(col),
75 unsigned int WXUNUSED(row) )
f554a14b
WS
76 { return false; }
77
3d9d7cc4
RR
78 // Create DC on request
79 virtual wxDC *GetDC();
f554a14b 80
3d9d7cc4 81private:
9861f022
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
WS
104
105// ---------------------------------------------------------
baa9ebc4 106// wxDataViewTextRenderer
f554a14b 107// ---------------------------------------------------------
4ed7af08 108
baa9ebc4 109class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
110{
111public:
baa9ebc4 112 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
9861f022
RR
113 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
114 int align = wxDVR_DEFAULT_ALIGNMENT );
4ed7af08
RR
115
116 bool SetValue( const wxVariant &value );
9861f022 117 bool GetValue( wxVariant &value ) const;
f554a14b 118
3d9d7cc4 119 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 120 wxSize GetSize() const;
f554a14b 121
90675b95
RR
122private:
123 wxString m_text;
f554a14b 124
4ed7af08 125protected:
baa9ebc4 126 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
4ed7af08 127};
f554a14b 128
2586d4a1 129// ---------------------------------------------------------
baa9ebc4 130// wxDataViewBitmapRenderer
2586d4a1
RR
131// ---------------------------------------------------------
132
baa9ebc4 133class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
2586d4a1
RR
134{
135public:
baa9ebc4 136 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
9861f022
RR
137 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
138 int align = wxDVR_DEFAULT_ALIGNMENT );
2586d4a1
RR
139
140 bool SetValue( const wxVariant &value );
9861f022 141 bool GetValue( wxVariant &value ) const;
2586d4a1
RR
142
143 bool Render( wxRect cell, wxDC *dc, int state );
9861f022 144 wxSize GetSize() const;
2586d4a1
RR
145
146private:
147 wxIcon m_icon;
148 wxBitmap m_bitmap;
149
150protected:
baa9ebc4 151 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
2586d4a1
RR
152};
153
f554a14b 154// ---------------------------------------------------------
baa9ebc4 155// wxDataViewToggleRenderer
f554a14b 156// ---------------------------------------------------------
4ed7af08 157
baa9ebc4 158class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
159{
160public:
baa9ebc4 161 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
9861f022
RR
162 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
163 int align = wxDVR_DEFAULT_ALIGNMENT );
3d9d7cc4
RR
164
165 bool SetValue( const wxVariant &value );
9861f022 166 bool GetValue( wxVariant &value ) const;
f554a14b 167
3d9d7cc4 168 bool Render( wxRect cell, wxDC *dc, int state );
87f0efe2
RR
169 bool Activate( wxRect cell, wxDataViewListModel *model, unsigned int col,
170 unsigned int row );
9861f022 171 wxSize GetSize() const;
f554a14b 172
90675b95
RR
173private:
174 bool m_toggle;
f554a14b 175
4ed7af08 176protected:
baa9ebc4 177 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
4ed7af08 178};
f554a14b
WS
179
180// ---------------------------------------------------------
baa9ebc4 181// wxDataViewProgressRenderer
f554a14b 182// ---------------------------------------------------------
4ed7af08 183
baa9ebc4 184class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
185{
186public:
baa9ebc4
RR
187 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
188 const wxString &varianttype = wxT("long"),
9861f022
RR
189 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
190 int align = wxDVR_DEFAULT_ALIGNMENT );
baa9ebc4 191 virtual ~wxDataViewProgressRenderer();
f554a14b 192
4ed7af08 193 bool SetValue( const wxVariant &value );
9861f022 194 bool GetValue( wxVariant& value ) const;
f554a14b 195
4ed7af08 196 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 197 virtual wxSize GetSize() const;
f554a14b 198
4ed7af08
RR
199private:
200 wxString m_label;
201 int m_value;
f554a14b 202
4ed7af08 203protected:
baa9ebc4 204 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
4ed7af08 205};
f554a14b
WS
206
207// ---------------------------------------------------------
baa9ebc4 208// wxDataViewDateRenderer
f554a14b 209// ---------------------------------------------------------
4ed7af08 210
baa9ebc4 211class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
4ed7af08
RR
212{
213public:
baa9ebc4 214 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
9861f022
RR
215 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
216 int align = wxDVR_DEFAULT_ALIGNMENT );
f554a14b 217
4ed7af08 218 bool SetValue( const wxVariant &value );
9861f022 219 bool GetValue( wxVariant& value ) const;
f554a14b 220
4ed7af08 221 virtual bool Render( wxRect cell, wxDC *dc, int state );
9861f022 222 virtual wxSize GetSize() const;
4ed7af08 223 virtual bool Activate( wxRect cell,
0a71f9e9 224 wxDataViewListModel *model, unsigned int col, unsigned int row );
f554a14b 225
4ed7af08
RR
226private:
227 wxDateTime m_date;
f554a14b 228
4ed7af08 229protected:
baa9ebc4 230 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
4ed7af08 231};
f554a14b
WS
232
233// ---------------------------------------------------------
4ed7af08 234// wxDataViewColumn
f554a14b 235// ---------------------------------------------------------
4ed7af08 236
f460c29d 237class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
4ed7af08 238{
87f0efe2
RR
239 friend class wxDataViewHeaderWindowBase;
240 friend class wxDataViewHeaderWindow;
241 friend class wxDataViewHeaderWindowMSW;
242
4ed7af08 243public:
87f0efe2
RR
244 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
245 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
246 wxAlignment align = wxALIGN_CENTER,
247 int flags = wxDATAVIEW_COL_RESIZABLE );
248 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
249 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
250 wxAlignment align = wxALIGN_CENTER,
251 int flags = wxDATAVIEW_COL_RESIZABLE );
4ed7af08
RR
252 virtual ~wxDataViewColumn();
253
9861f022
RR
254 // setters:
255
256 virtual void SetTitle( const wxString &title )
257 { m_title=title; }
87f0efe2
RR
258 virtual void SetAlignment( wxAlignment align )
259 { m_align=align; }
9861f022
RR
260 virtual void SetMinWidth( int minWidth )
261 { m_minWidth=minWidth; }
262 virtual void SetWidth( int width );
31fb32e1 263 virtual void SetSortable( bool sortable );
9861f022
RR
264 virtual void SetResizeable( bool resizeable );
265 virtual void SetHidden( bool hidden );
47cef10f 266 virtual void SetSortOrder( bool ascending );
87f0efe2 267
87f0efe2 268
9861f022
RR
269 // getters:
270
271 virtual wxString GetTitle() const
272 { return m_title; }
273 virtual wxAlignment GetAlignment() const
274 { return m_align; }
275 virtual int GetWidth() const
276 { return m_width; }
277 virtual int GetMinWidth() const
278 { return m_minWidth; }
279 virtual bool IsSortable() const
280 { return (m_flags & wxDATAVIEW_COL_SORTABLE) != 0; }
281 virtual bool IsResizeable() const
282 { return (m_flags & wxDATAVIEW_COL_RESIZABLE) != 0; }
283 virtual bool IsHidden() const
284 { return (m_flags & wxDATAVIEW_COL_HIDDEN) != 0; }
285 virtual bool IsSortOrderAscending() const;
f554a14b 286
f554a14b 287
4ed7af08 288private:
533544f2 289 int m_width;
9861f022
RR
290 int m_minWidth;
291 int m_flags;
292 wxAlignment m_align;
293 wxString m_title;
87f0efe2
RR
294
295 void Init(int width);
4ed7af08 296
9861f022
RR
297 // like SetWidth() but does not ask the header window of the
298 // wxDataViewCtrl to reflect the width-change.
299 void SetInternalWidth(int width);
300
4ed7af08
RR
301protected:
302 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
303};
304
f554a14b 305// ---------------------------------------------------------
4ed7af08 306// wxDataViewCtrl
f554a14b 307// ---------------------------------------------------------
4ed7af08 308
f460c29d 309class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
4ed7af08
RR
310 public wxScrollHelperNative
311{
87f0efe2
RR
312 friend class wxDataViewMainWindow;
313 friend class wxDataViewHeaderWindowBase;
314 friend class wxDataViewHeaderWindow;
315 friend class wxDataViewHeaderWindowMSW;
9861f022 316 friend class wxDataViewColumn;
87f0efe2 317
4ed7af08
RR
318public:
319 wxDataViewCtrl() : wxScrollHelperNative(this)
320 {
321 Init();
322 }
f554a14b 323
4ed7af08
RR
324 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
325 const wxPoint& pos = wxDefaultPosition,
326 const wxSize& size = wxDefaultSize, long style = 0,
f554a14b 327 const wxValidator& validator = wxDefaultValidator )
4b3feaa7 328 : wxScrollHelperNative(this)
4ed7af08
RR
329 {
330 Create(parent, id, pos, size, style, validator );
331 }
332
333 virtual ~wxDataViewCtrl();
334
335 void Init();
336
337 bool Create(wxWindow *parent, wxWindowID id,
338 const wxPoint& pos = wxDefaultPosition,
339 const wxSize& size = wxDefaultSize, long style = 0,
340 const wxValidator& validator = wxDefaultValidator );
341
342 virtual bool AssociateModel( wxDataViewListModel *model );
343 virtual bool AppendColumn( wxDataViewColumn *col );
f554a14b 344
6ff7eee7
RR
345 virtual void SetSelection( int row ); // -1 for unselect
346 virtual void SetSelectionRange( unsigned int from, unsigned int to );
347 virtual void SetSelections( const wxArrayInt& aSelections);
fc211fe5 348 virtual void Unselect( unsigned int row );
6ff7eee7
RR
349
350 virtual bool IsSelected( unsigned int row ) const;
351 virtual int GetSelection() const;
352 virtual int GetSelections(wxArrayInt& aSelections) const;
353
9861f022
RR
354public: // utility functions not part of the API
355
87f0efe2 356 // returns the "best" width for the idx-th column
9861f022 357 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
87f0efe2 358 {
9861f022 359 return GetClientSize().GetWidth() / GetColumnCount();
87f0efe2
RR
360 }
361
9861f022
RR
362 // updates the header window after a change in a column setting
363 void OnColumnChange();
87f0efe2 364
4ed7af08
RR
365private:
366 wxDataViewListModelNotifier *m_notifier;
4b3feaa7
RR
367 wxDataViewMainWindow *m_clientArea;
368 wxDataViewHeaderWindow *m_headerArea;
f554a14b 369
4ed7af08 370private:
4b3feaa7 371 void OnSize( wxSizeEvent &event );
f554a14b 372
4ed7af08
RR
373 // we need to return a special WM_GETDLGCODE value to process just the
374 // arrows but let the other navigation characters through
375#ifdef __WXMSW__
376 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
377#endif // __WXMSW__
378
379 WX_FORWARD_TO_SCROLL_HELPER()
4b3feaa7 380
4ed7af08
RR
381private:
382 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
383 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
4b3feaa7 384 DECLARE_EVENT_TABLE()
4ed7af08
RR
385};
386
387
388#endif // __GENERICDATAVIEWCTRLH__