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