]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/generic/dataview.h
fix crash when using wxDataViewListStore::DeleteAllItems
[wxWidgets.git] / include / wx / generic / dataview.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/generic/dataview.h
3// Purpose: wxDataViewCtrl generic implementation header
4// Author: Robert Roebling
5// Modified By: Bo Yang
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"
18#include "wx/scrolwin.h"
19#include "wx/icon.h"
20
21// ---------------------------------------------------------
22// classes
23// ---------------------------------------------------------
24
25class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
26class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow;
27class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
28
29// ---------------------------------------------------------
30// wxDataViewRenderer
31// ---------------------------------------------------------
32
33class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
34{
35public:
36 wxDataViewRenderer( const wxString &varianttype,
37 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
38 int align = wxDVR_DEFAULT_ALIGNMENT );
39 virtual ~wxDataViewRenderer();
40
41 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
42 virtual wxSize GetSize() const = 0;
43
44 virtual void SetAlignment( int align );
45 virtual int GetAlignment() const;
46
47 virtual void SetMode( wxDataViewCellMode mode )
48 { m_mode=mode; }
49 virtual wxDataViewCellMode GetMode() const
50 { return m_mode; }
51
52 virtual bool Activate( wxRect WXUNUSED(cell),
53 wxDataViewModel *WXUNUSED(model),
54 const wxDataViewItem & WXUNUSED(item),
55 unsigned int WXUNUSED(col) )
56 { return false; }
57
58 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
59 wxRect WXUNUSED(cell),
60 wxDataViewModel *WXUNUSED(model),
61 const wxDataViewItem & WXUNUSED(item),
62 unsigned int WXUNUSED(col) )
63 { return false; }
64 virtual bool RightClick( wxPoint WXUNUSED(cursor),
65 wxRect WXUNUSED(cell),
66 wxDataViewModel *WXUNUSED(model),
67 const wxDataViewItem & WXUNUSED(item),
68 unsigned int WXUNUSED(col) )
69 { return false; }
70 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
71 wxRect WXUNUSED(cell),
72 wxDataViewModel *WXUNUSED(model),
73 const wxDataViewItem & WXUNUSED(item),
74 unsigned int WXUNUSED(col) )
75 { return false; }
76
77 // Create DC on request
78 virtual wxDC *GetDC();
79
80 void SetHasAttr( bool set ) { m_hasAttr = set; }
81 void SetAttr( const wxDataViewItemAttr &attr ) { m_attr = attr; }
82 bool GetWantsAttr() { return m_wantsAttr; }
83
84 // implementation
85 int CalculateAlignment() const;
86
87private:
88 wxDC *m_dc;
89 int m_align;
90 wxDataViewCellMode m_mode;
91
92protected:
93 bool m_wantsAttr;
94 bool m_hasAttr;
95 wxDataViewItemAttr m_attr;
96
97protected:
98 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
99};
100
101// ---------------------------------------------------------
102// wxDataViewCustomRenderer
103// ---------------------------------------------------------
104
105class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
106{
107public:
108 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
109 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
110 int align = wxDVR_DEFAULT_ALIGNMENT );
111
112 void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state );
113
114protected:
115 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
116};
117
118
119// ---------------------------------------------------------
120// wxDataViewTextRenderer
121// ---------------------------------------------------------
122
123class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
124{
125public:
126 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
127 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
128 int align = wxDVR_DEFAULT_ALIGNMENT );
129
130 bool SetValue( const wxVariant &value );
131 bool GetValue( wxVariant &value ) const;
132
133 bool Render( wxRect cell, wxDC *dc, int state );
134 wxSize GetSize() const;
135
136 // in-place editing
137 virtual bool HasEditorCtrl();
138 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
139 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
140
141protected:
142 wxString m_text;
143
144protected:
145 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
146};
147
148// ---------------------------------------------------------
149// wxDataViewTextRendererAttr
150// ---------------------------------------------------------
151
152class WXDLLIMPEXP_ADV wxDataViewTextRendererAttr: public wxDataViewTextRenderer
153{
154public:
155 wxDataViewTextRendererAttr( const wxString &varianttype = wxT("string"),
156 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
157 int align = wxDVR_DEFAULT_ALIGNMENT );
158
159 bool Render( wxRect cell, wxDC *dc, int state );
160
161protected:
162 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRendererAttr)
163};
164
165// ---------------------------------------------------------
166// wxDataViewBitmapRenderer
167// ---------------------------------------------------------
168
169class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
170{
171public:
172 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
173 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
174 int align = wxDVR_DEFAULT_ALIGNMENT );
175
176 bool SetValue( const wxVariant &value );
177 bool GetValue( wxVariant &value ) const;
178
179 bool Render( wxRect cell, wxDC *dc, int state );
180 wxSize GetSize() const;
181
182private:
183 wxIcon m_icon;
184 wxBitmap m_bitmap;
185
186protected:
187 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
188};
189
190// ---------------------------------------------------------
191// wxDataViewToggleRenderer
192// ---------------------------------------------------------
193
194class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
195{
196public:
197 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
198 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
199 int align = wxDVR_DEFAULT_ALIGNMENT );
200
201 bool SetValue( const wxVariant &value );
202 bool GetValue( wxVariant &value ) const;
203
204 bool Render( wxRect cell, wxDC *dc, int state );
205 bool Activate( wxRect cell, wxDataViewModel *model, const wxDataViewItem & item,
206 unsigned int col );
207 wxSize GetSize() const;
208
209private:
210 bool m_toggle;
211
212protected:
213 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
214};
215
216// ---------------------------------------------------------
217// wxDataViewProgressRenderer
218// ---------------------------------------------------------
219
220class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
221{
222public:
223 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
224 const wxString &varianttype = wxT("long"),
225 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
226 int align = wxDVR_DEFAULT_ALIGNMENT );
227 virtual ~wxDataViewProgressRenderer();
228
229 bool SetValue( const wxVariant &value );
230 bool GetValue( wxVariant& value ) const;
231
232 virtual bool Render( wxRect cell, wxDC *dc, int state );
233 virtual wxSize GetSize() const;
234
235private:
236 wxString m_label;
237 int m_value;
238
239protected:
240 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
241};
242
243// ---------------------------------------------------------
244// wxDataViewIconTextRenderer
245// ---------------------------------------------------------
246
247class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
248{
249public:
250 wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"),
251 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
252 int align = wxDVR_DEFAULT_ALIGNMENT );
253 virtual ~wxDataViewIconTextRenderer();
254
255 bool SetValue( const wxVariant &value );
256 bool GetValue( wxVariant &value ) const;
257
258 virtual bool Render( wxRect cell, wxDC *dc, int state );
259 virtual wxSize GetSize() const;
260
261 virtual bool HasEditorCtrl() { return true; }
262 virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value );
263 virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value );
264
265private:
266 wxDataViewIconText m_value;
267
268protected:
269 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
270};
271
272// ---------------------------------------------------------
273// wxDataViewDateRenderer
274// ---------------------------------------------------------
275
276class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
277{
278public:
279 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
280 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
281 int align = wxDVR_DEFAULT_ALIGNMENT );
282
283 bool SetValue( const wxVariant &value );
284 bool GetValue( wxVariant& value ) const;
285
286 virtual bool Render( wxRect cell, wxDC *dc, int state );
287 virtual wxSize GetSize() const;
288 virtual bool Activate( wxRect cell,
289 wxDataViewModel *model, const wxDataViewItem & item, unsigned int col );
290
291private:
292 wxDateTime m_date;
293
294protected:
295 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
296};
297
298// ---------------------------------------------------------
299// wxDataViewColumn
300// ---------------------------------------------------------
301
302class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase
303{
304public:
305 wxDataViewColumn(const wxString& title,
306 wxDataViewRenderer *renderer,
307 unsigned int model_column,
308 int width = wxDVC_DEFAULT_WIDTH,
309 wxAlignment align = wxALIGN_CENTER,
310 int flags = wxDATAVIEW_COL_RESIZABLE)
311 : wxDataViewColumnBase(renderer, model_column),
312 m_title(title)
313 {
314 Init(width, align, flags);
315 }
316
317 wxDataViewColumn(const wxBitmap& bitmap,
318 wxDataViewRenderer *renderer,
319 unsigned int model_column,
320 int width = wxDVC_DEFAULT_WIDTH,
321 wxAlignment align = wxALIGN_CENTER,
322 int flags = wxDATAVIEW_COL_RESIZABLE)
323 : wxDataViewColumnBase(bitmap, renderer, model_column)
324 {
325 Init(width, align, flags);
326 }
327
328 // implement wxHeaderColumnBase methods
329 virtual void SetTitle(const wxString& title) { m_title = title; }
330 virtual wxString GetTitle() const { return m_title; }
331
332 virtual void SetWidth(int width) { m_width = width; }
333 virtual int GetWidth() const { return m_width; }
334
335 virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
336 virtual int GetMinWidth() const { return m_minWidth; }
337
338 virtual void SetAlignment(wxAlignment align) { m_align = align; }
339 virtual wxAlignment GetAlignment() const { return m_align; }
340
341 virtual void SetFlags(int flags) { m_flags = flags; }
342 virtual int GetFlags() const { return m_flags; }
343
344 virtual void SetAsSortKey(bool sort = true) { m_sort = sort; }
345 virtual bool IsSortKey() const { return m_sort; }
346
347 virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; }
348 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
349
350private:
351 // common part of all ctors
352 void Init(int width, wxAlignment align, int flags)
353 {
354 m_width = width == wxCOL_WIDTH_DEFAULT ? wxDVC_DEFAULT_WIDTH : width;
355 m_minWidth = 0;
356 m_align = align;
357 m_flags = flags;
358 m_sort = false;
359 m_sortAscending = true;
360 }
361
362 wxString m_title;
363 int m_width,
364 m_minWidth;
365 wxAlignment m_align;
366 int m_flags;
367 bool m_sort,
368 m_sortAscending;
369
370 friend class wxDataViewHeaderWindowBase;
371 friend class wxDataViewHeaderWindow;
372 friend class wxDataViewHeaderWindowMSW;
373};
374
375// ---------------------------------------------------------
376// wxDataViewCtrl
377// ---------------------------------------------------------
378
379WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
380 class WXDLLIMPEXP_ADV);
381
382class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase,
383 public wxScrollHelper
384{
385 friend class wxDataViewMainWindow;
386 friend class wxDataViewHeaderWindowBase;
387 friend class wxDataViewHeaderWindow;
388 friend class wxDataViewHeaderWindowMSW;
389 friend class wxDataViewColumn;
390
391public:
392 wxDataViewCtrl() : wxScrollHelper(this)
393 {
394 Init();
395 }
396
397 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
398 const wxPoint& pos = wxDefaultPosition,
399 const wxSize& size = wxDefaultSize, long style = 0,
400 const wxValidator& validator = wxDefaultValidator )
401 : wxScrollHelper(this)
402 {
403 Create(parent, id, pos, size, style, validator );
404 }
405
406 virtual ~wxDataViewCtrl();
407
408 void Init();
409
410 bool Create(wxWindow *parent, wxWindowID id,
411 const wxPoint& pos = wxDefaultPosition,
412 const wxSize& size = wxDefaultSize, long style = 0,
413 const wxValidator& validator = wxDefaultValidator );
414
415 virtual bool AssociateModel( wxDataViewModel *model );
416
417 virtual bool AppendColumn( wxDataViewColumn *col );
418 virtual bool PrependColumn( wxDataViewColumn *col );
419 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
420
421 virtual void DoSetExpanderColumn();
422 virtual void DoSetIndent();
423
424 virtual unsigned int GetColumnCount() const;
425 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
426 virtual bool DeleteColumn( wxDataViewColumn *column );
427 virtual bool ClearColumns();
428 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
429
430 virtual wxDataViewColumn *GetSortingColumn() const;
431
432 virtual wxDataViewItem GetSelection() const;
433 virtual int GetSelections( wxDataViewItemArray & sel ) const;
434 virtual void SetSelections( const wxDataViewItemArray & sel );
435 virtual void Select( const wxDataViewItem & item );
436 virtual void Unselect( const wxDataViewItem & item );
437 virtual bool IsSelected( const wxDataViewItem & item ) const;
438
439 virtual void SelectAll();
440 virtual void UnselectAll();
441
442 virtual void EnsureVisible( const wxDataViewItem & item,
443 const wxDataViewColumn *column = NULL );
444 virtual void HitTest( const wxPoint & point, wxDataViewItem & item, wxDataViewColumn* &column ) const;
445 virtual wxRect GetItemRect( const wxDataViewItem & item, const wxDataViewColumn *column = NULL ) const;
446
447 virtual void Expand( const wxDataViewItem & item );
448 virtual void Collapse( const wxDataViewItem & item );
449 virtual bool IsExpanded( const wxDataViewItem & item ) const;
450
451 virtual void SetFocus();
452
453#if wxUSE_DRAG_AND_DROP
454 virtual bool EnableDragSource( const wxDataFormat &format );
455 virtual bool EnableDropTarget( const wxDataFormat &format );
456#endif // wxUSE_DRAG_AND_DROP
457
458 virtual wxBorder GetDefaultBorder() const;
459
460protected:
461 virtual int GetSelections( wxArrayInt & sel ) const;
462 virtual void SetSelections( const wxArrayInt & sel );
463 virtual void Select( int row );
464 virtual void Unselect( int row );
465 virtual bool IsSelected( int row ) const;
466 virtual void SelectRange( int from, int to );
467 virtual void UnselectRange( int from, int to );
468
469 virtual void EnsureVisible( int row, int column );
470
471 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
472 virtual int GetRowByItem( const wxDataViewItem & item ) const;
473
474 int GetSortingColumnIndex() const { return m_sortingColumnIdx; }
475 void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; }
476
477public: // utility functions not part of the API
478
479 // returns the "best" width for the idx-th column
480 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
481 {
482 return GetClientSize().GetWidth() / GetColumnCount();
483 }
484
485 // called by header window after reorder
486 void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos );
487
488 // update the display after a change to an individual column
489 void OnColumnChange(unsigned int idx);
490
491 // update after a change to the number of columns
492 void OnColumnsCountChanged();
493
494 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
495
496 // return the index of the given column in m_cols
497 int GetColumnIndex(const wxDataViewColumn *column) const;
498
499 // return the column displayed at the given position in the control
500 wxDataViewColumn *GetColumnAt(unsigned int pos) const;
501
502private:
503 wxDataViewColumnList m_cols;
504 wxDataViewModelNotifier *m_notifier;
505 wxDataViewMainWindow *m_clientArea;
506 wxDataViewHeaderWindow *m_headerArea;
507
508 // the index of the column currently used for sorting or -1
509 int m_sortingColumnIdx;
510
511private:
512 void OnSize( wxSizeEvent &event );
513 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
514
515 // we need to return a special WM_GETDLGCODE value to process just the
516 // arrows but let the other navigation characters through
517#ifdef __WXMSW__
518 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
519#endif // __WXMSW__
520
521 WX_FORWARD_TO_SCROLL_HELPER()
522
523private:
524 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
525 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl);
526 DECLARE_EVENT_TABLE()
527};
528
529
530#endif // __GENERICDATAVIEWCTRLH__