]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dataview.h
Avoid setting attributes in GTK wxDataViewRenderer if not supported.
[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 class WXDLLIMPEXP_FWD_ADV wxDataViewMainWindow;
22 class WXDLLIMPEXP_FWD_ADV wxDataViewHeaderWindow;
23
24 // ---------------------------------------------------------
25 // wxDataViewColumn
26 // ---------------------------------------------------------
27
28 class WXDLLIMPEXP_ADV wxDataViewColumn : public wxDataViewColumnBase
29 {
30 public:
31 wxDataViewColumn(const wxString& title,
32 wxDataViewRenderer *renderer,
33 unsigned int model_column,
34 int width = wxDVC_DEFAULT_WIDTH,
35 wxAlignment align = wxALIGN_CENTER,
36 int flags = wxDATAVIEW_COL_RESIZABLE)
37 : wxDataViewColumnBase(renderer, model_column),
38 m_title(title)
39 {
40 Init(width, align, flags);
41 }
42
43 wxDataViewColumn(const wxBitmap& bitmap,
44 wxDataViewRenderer *renderer,
45 unsigned int model_column,
46 int width = wxDVC_DEFAULT_WIDTH,
47 wxAlignment align = wxALIGN_CENTER,
48 int flags = wxDATAVIEW_COL_RESIZABLE)
49 : wxDataViewColumnBase(bitmap, renderer, model_column)
50 {
51 Init(width, align, flags);
52 }
53
54 // implement wxHeaderColumnBase methods
55 virtual void SetTitle(const wxString& title) { m_title = title; }
56 virtual wxString GetTitle() const { return m_title; }
57
58 virtual void SetWidth(int width) { m_width = width; }
59 virtual int GetWidth() const { return m_width; }
60
61 virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
62 virtual int GetMinWidth() const { return m_minWidth; }
63
64 virtual void SetAlignment(wxAlignment align) { m_align = align; }
65 virtual wxAlignment GetAlignment() const { return m_align; }
66
67 virtual void SetFlags(int flags) { m_flags = flags; }
68 virtual int GetFlags() const { return m_flags; }
69
70 virtual void SetAsSortKey(bool sort = true) { m_sort = sort; }
71 virtual bool IsSortKey() const { return m_sort; }
72
73 virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; }
74 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
75
76 private:
77 // common part of all ctors
78 void Init(int width, wxAlignment align, int flags)
79 {
80 m_width = width == wxCOL_WIDTH_DEFAULT ? wxDVC_DEFAULT_WIDTH : width;
81 m_minWidth = 0;
82 m_align = align;
83 m_flags = flags;
84 m_sort = false;
85 m_sortAscending = true;
86 }
87
88 wxString m_title;
89 int m_width,
90 m_minWidth;
91 wxAlignment m_align;
92 int m_flags;
93 bool m_sort,
94 m_sortAscending;
95
96 friend class wxDataViewHeaderWindowBase;
97 friend class wxDataViewHeaderWindow;
98 friend class wxDataViewHeaderWindowMSW;
99 };
100
101 // ---------------------------------------------------------
102 // wxDataViewCtrl
103 // ---------------------------------------------------------
104
105 WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
106 class WXDLLIMPEXP_ADV);
107
108 class WXDLLIMPEXP_ADV wxDataViewCtrl : public wxDataViewCtrlBase,
109 public wxScrollHelper
110 {
111 friend class wxDataViewMainWindow;
112 friend class wxDataViewHeaderWindowBase;
113 friend class wxDataViewHeaderWindow;
114 friend class wxDataViewHeaderWindowMSW;
115 friend class wxDataViewColumn;
116
117 public:
118 wxDataViewCtrl() : wxScrollHelper(this)
119 {
120 Init();
121 }
122
123 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
124 const wxPoint& pos = wxDefaultPosition,
125 const wxSize& size = wxDefaultSize, long style = 0,
126 const wxValidator& validator = wxDefaultValidator )
127 : wxScrollHelper(this)
128 {
129 Create(parent, id, pos, size, style, validator );
130 }
131
132 virtual ~wxDataViewCtrl();
133
134 void Init();
135
136 bool Create(wxWindow *parent, wxWindowID id,
137 const wxPoint& pos = wxDefaultPosition,
138 const wxSize& size = wxDefaultSize, long style = 0,
139 const wxValidator& validator = wxDefaultValidator );
140
141 virtual bool AssociateModel( wxDataViewModel *model );
142
143 virtual bool AppendColumn( wxDataViewColumn *col );
144 virtual bool PrependColumn( wxDataViewColumn *col );
145 virtual bool InsertColumn( unsigned int pos, wxDataViewColumn *col );
146
147 virtual void DoSetExpanderColumn();
148 virtual void DoSetIndent();
149
150 virtual unsigned int GetColumnCount() const;
151 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
152 virtual bool DeleteColumn( wxDataViewColumn *column );
153 virtual bool ClearColumns();
154 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
155
156 virtual wxDataViewColumn *GetSortingColumn() const;
157
158 virtual wxDataViewItem GetSelection() const;
159 virtual int GetSelections( wxDataViewItemArray & sel ) const;
160 virtual void SetSelections( const wxDataViewItemArray & sel );
161 virtual void Select( const wxDataViewItem & item );
162 virtual void Unselect( const wxDataViewItem & item );
163 virtual bool IsSelected( const wxDataViewItem & item ) const;
164
165 virtual void SelectAll();
166 virtual void UnselectAll();
167
168 virtual void EnsureVisible( const wxDataViewItem & item,
169 const wxDataViewColumn *column = NULL );
170 virtual void HitTest( const wxPoint & point, wxDataViewItem & item,
171 wxDataViewColumn* &column ) const;
172 virtual wxRect GetItemRect( const wxDataViewItem & item,
173 const wxDataViewColumn *column = NULL ) const;
174
175 virtual void Expand( const wxDataViewItem & item );
176 virtual void Collapse( const wxDataViewItem & item );
177 virtual bool IsExpanded( const wxDataViewItem & item ) const;
178
179 virtual void SetFocus();
180
181 #if wxUSE_DRAG_AND_DROP
182 virtual bool EnableDragSource( const wxDataFormat &format );
183 virtual bool EnableDropTarget( const wxDataFormat &format );
184 #endif // wxUSE_DRAG_AND_DROP
185
186 virtual wxBorder GetDefaultBorder() const;
187
188 void StartEditor( const wxDataViewItem & item, unsigned int column );
189
190 protected:
191 virtual int GetSelections( wxArrayInt & sel ) const;
192 virtual void SetSelections( const wxArrayInt & sel );
193 virtual void Select( int row );
194 virtual void Unselect( int row );
195 virtual bool IsSelected( int row ) const;
196 virtual void SelectRange( int from, int to );
197 virtual void UnselectRange( int from, int to );
198
199 virtual void EnsureVisible( int row, int column );
200
201 virtual wxDataViewItem GetItemByRow( unsigned int row ) const;
202 virtual int GetRowByItem( const wxDataViewItem & item ) const;
203
204 int GetSortingColumnIndex() const { return m_sortingColumnIdx; }
205 void SetSortingColumnIndex(int idx) { m_sortingColumnIdx = idx; }
206
207 public: // utility functions not part of the API
208
209 // returns the "best" width for the idx-th column
210 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
211 {
212 return GetClientSize().GetWidth() / GetColumnCount();
213 }
214
215 // called by header window after reorder
216 void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos );
217
218 // update the display after a change to an individual column
219 void OnColumnChange(unsigned int idx);
220
221 // update after a change to the number of columns
222 void OnColumnsCountChanged();
223
224 wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
225
226 // return the index of the given column in m_cols
227 int GetColumnIndex(const wxDataViewColumn *column) const;
228
229 // return the column displayed at the given position in the control
230 wxDataViewColumn *GetColumnAt(unsigned int pos) const;
231
232 private:
233 wxDataViewColumnList m_cols;
234 wxDataViewModelNotifier *m_notifier;
235 wxDataViewMainWindow *m_clientArea;
236 wxDataViewHeaderWindow *m_headerArea;
237
238 // the index of the column currently used for sorting or -1
239 int m_sortingColumnIdx;
240
241 private:
242 void OnSize( wxSizeEvent &event );
243 virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);
244
245 // we need to return a special WM_GETDLGCODE value to process just the
246 // arrows but let the other navigation characters through
247 #ifdef __WXMSW__
248 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
249 #endif // __WXMSW__
250
251 WX_FORWARD_TO_SCROLL_HELPER()
252
253 private:
254 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
255 wxDECLARE_NO_COPY_CLASS(wxDataViewCtrl);
256 DECLARE_EVENT_TABLE()
257 };
258
259
260 #endif // __GENERICDATAVIEWCTRLH__