]>
Commit | Line | Data |
---|---|---|
239eaa41 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/gtk/dataview.h | |
3 | // Purpose: wxDataViewCtrl GTK+2 implementation header | |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef __GTKDATAVIEWCTRLH__ | |
11 | #define __GTKDATAVIEWCTRLH__ | |
12 | ||
13 | #include "wx/defs.h" | |
14 | #include "wx/object.h" | |
15 | #include "wx/list.h" | |
16 | #include "wx/control.h" | |
17 | ||
18 | // --------------------------------------------------------- | |
19 | // classes | |
20 | // --------------------------------------------------------- | |
21 | ||
b5dbe15d | 22 | class WXDLLIMPEXP_FWD_CORE wxDataViewCtrl; |
55fbde12 | 23 | class WXDLLIMPEXP_FWD_CORE wxDataViewCtrlInternal; |
239eaa41 | 24 | |
87f0efe2 | 25 | |
6842a71a | 26 | // --------------------------------------------------------- |
baa9ebc4 | 27 | // wxDataViewRenderer |
6842a71a RR |
28 | // --------------------------------------------------------- |
29 | ||
baa9ebc4 | 30 | class wxDataViewRenderer: public wxDataViewRendererBase |
6842a71a RR |
31 | { |
32 | public: | |
87f0efe2 | 33 | wxDataViewRenderer( const wxString &varianttype, |
9861f022 RR |
34 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
35 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
6842a71a | 36 | |
9861f022 RR |
37 | virtual void SetMode( wxDataViewCellMode mode ); |
38 | virtual wxDataViewCellMode GetMode() const; | |
39 | ||
40 | virtual void SetAlignment( int align ); | |
41 | virtual int GetAlignment() const; | |
6842a71a | 42 | |
f71d3ba4 RR |
43 | // implementation |
44 | GtkCellRenderer* GetGtkHandle() { return m_renderer; } | |
45 | void GtkInitHandlers(); | |
46 | ||
6842a71a | 47 | protected: |
ed38aa55 | 48 | GtkCellRenderer *m_renderer; |
6842a71a RR |
49 | |
50 | protected: | |
baa9ebc4 | 51 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer) |
6842a71a | 52 | }; |
9861f022 | 53 | |
6842a71a | 54 | // --------------------------------------------------------- |
baa9ebc4 | 55 | // wxDataViewTextRenderer |
6842a71a RR |
56 | // --------------------------------------------------------- |
57 | ||
baa9ebc4 | 58 | class wxDataViewTextRenderer: public wxDataViewRenderer |
6842a71a RR |
59 | { |
60 | public: | |
baa9ebc4 | 61 | wxDataViewTextRenderer( const wxString &varianttype = wxT("string"), |
9861f022 RR |
62 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
63 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
6842a71a | 64 | |
7b4fde82 | 65 | bool SetValue( const wxVariant &value ); |
9861f022 RR |
66 | bool GetValue( wxVariant &value ) const; |
67 | ||
68 | void SetAlignment( int align ); | |
69 | ||
6842a71a | 70 | protected: |
baa9ebc4 | 71 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer) |
6842a71a RR |
72 | }; |
73 | ||
cbc9145c | 74 | // --------------------------------------------------------- |
baa9ebc4 | 75 | // wxDataViewBitmapRenderer |
cbc9145c RR |
76 | // --------------------------------------------------------- |
77 | ||
baa9ebc4 | 78 | class wxDataViewBitmapRenderer: public wxDataViewRenderer |
cbc9145c RR |
79 | { |
80 | public: | |
baa9ebc4 | 81 | wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"), |
9861f022 RR |
82 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
83 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
cbc9145c RR |
84 | |
85 | bool SetValue( const wxVariant &value ); | |
9861f022 | 86 | bool GetValue( wxVariant &value ) const; |
cbc9145c RR |
87 | |
88 | protected: | |
baa9ebc4 | 89 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer) |
cbc9145c RR |
90 | }; |
91 | ||
605c2c4a | 92 | // --------------------------------------------------------- |
baa9ebc4 | 93 | // wxDataViewToggleRenderer |
605c2c4a RR |
94 | // --------------------------------------------------------- |
95 | ||
baa9ebc4 | 96 | class wxDataViewToggleRenderer: public wxDataViewRenderer |
605c2c4a RR |
97 | { |
98 | public: | |
baa9ebc4 | 99 | wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"), |
9861f022 RR |
100 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
101 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
605c2c4a RR |
102 | |
103 | bool SetValue( const wxVariant &value ); | |
9861f022 | 104 | bool GetValue( wxVariant &value ) const; |
605c2c4a RR |
105 | |
106 | protected: | |
baa9ebc4 | 107 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer) |
605c2c4a RR |
108 | }; |
109 | ||
e152afc3 | 110 | // --------------------------------------------------------- |
baa9ebc4 | 111 | // wxDataViewCustomRenderer |
e152afc3 RR |
112 | // --------------------------------------------------------- |
113 | ||
baa9ebc4 | 114 | class wxDataViewCustomRenderer: public wxDataViewRenderer |
e152afc3 RR |
115 | { |
116 | public: | |
baa9ebc4 RR |
117 | wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"), |
118 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
9861f022 | 119 | int align = wxDVR_DEFAULT_ALIGNMENT, |
baa9ebc4 RR |
120 | bool no_init = false ); |
121 | virtual ~wxDataViewCustomRenderer(); | |
9861f022 RR |
122 | |
123 | ||
e152afc3 | 124 | virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0; |
9861f022 RR |
125 | virtual wxSize GetSize() const = 0; |
126 | ||
4d496ecb | 127 | virtual bool Activate( wxRect cell, |
e0062c04 | 128 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) |
4d496ecb | 129 | { return false; } |
9861f022 | 130 | |
4d496ecb | 131 | virtual bool LeftClick( wxPoint cursor, wxRect cell, |
e0062c04 | 132 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) |
4d496ecb RR |
133 | { return false; } |
134 | virtual bool RightClick( wxPoint cursor, wxRect cell, | |
e0062c04 | 135 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) |
4d496ecb RR |
136 | { return false; } |
137 | virtual bool StartDrag( wxPoint cursor, wxRect cell, | |
e0062c04 | 138 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) |
4d496ecb | 139 | { return false; } |
e152afc3 RR |
140 | |
141 | // Create DC on request | |
142 | virtual wxDC *GetDC(); | |
143 | ||
9861f022 RR |
144 | |
145 | protected: | |
146 | ||
147 | bool Init(wxDataViewCellMode mode, int align); | |
148 | ||
e152afc3 RR |
149 | private: |
150 | wxDC *m_dc; | |
151 | ||
152 | protected: | |
baa9ebc4 | 153 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer) |
e152afc3 RR |
154 | }; |
155 | ||
ad63bf41 | 156 | // --------------------------------------------------------- |
baa9ebc4 | 157 | // wxDataViewProgressRenderer |
ad63bf41 RR |
158 | // --------------------------------------------------------- |
159 | ||
baa9ebc4 | 160 | class wxDataViewProgressRenderer: public wxDataViewCustomRenderer |
ad63bf41 RR |
161 | { |
162 | public: | |
baa9ebc4 RR |
163 | wxDataViewProgressRenderer( const wxString &label = wxEmptyString, |
164 | const wxString &varianttype = wxT("long"), | |
9861f022 RR |
165 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
166 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
baa9ebc4 | 167 | virtual ~wxDataViewProgressRenderer(); |
ad63bf41 RR |
168 | |
169 | bool SetValue( const wxVariant &value ); | |
9861f022 | 170 | bool GetValue( wxVariant &value ) const; |
ad63bf41 RR |
171 | |
172 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
9861f022 | 173 | virtual wxSize GetSize() const; |
ad63bf41 RR |
174 | |
175 | private: | |
176 | wxString m_label; | |
177 | int m_value; | |
178 | ||
179 | protected: | |
baa9ebc4 | 180 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer) |
ad63bf41 RR |
181 | }; |
182 | ||
c9c13e70 RR |
183 | // --------------------------------------------------------- |
184 | // wxDataViewIconTextRenderer | |
185 | // --------------------------------------------------------- | |
186 | ||
187 | class wxDataViewIconTextRenderer: public wxDataViewCustomRenderer | |
188 | { | |
189 | public: | |
190 | wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"), | |
191 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
192 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
193 | virtual ~wxDataViewIconTextRenderer(); | |
194 | ||
195 | bool SetValue( const wxVariant &value ); | |
196 | bool GetValue( wxVariant &value ) const; | |
197 | ||
198 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
199 | virtual wxSize GetSize() const; | |
200 | ||
201 | virtual bool HasEditorCtrl() { return true; } | |
202 | virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); | |
203 | virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); | |
204 | ||
205 | private: | |
206 | wxDataViewIconText m_value; | |
207 | ||
208 | protected: | |
209 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer) | |
210 | }; | |
211 | ||
4d496ecb | 212 | // --------------------------------------------------------- |
baa9ebc4 | 213 | // wxDataViewDateRenderer |
4d496ecb RR |
214 | // --------------------------------------------------------- |
215 | ||
baa9ebc4 | 216 | class wxDataViewDateRenderer: public wxDataViewCustomRenderer |
4d496ecb RR |
217 | { |
218 | public: | |
baa9ebc4 | 219 | wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"), |
9861f022 RR |
220 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, |
221 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
4d496ecb RR |
222 | |
223 | bool SetValue( const wxVariant &value ); | |
9861f022 | 224 | bool GetValue( wxVariant &value ) const; |
4d496ecb RR |
225 | |
226 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
9861f022 | 227 | virtual wxSize GetSize() const; |
4d496ecb | 228 | virtual bool Activate( wxRect cell, |
e0062c04 | 229 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ); |
4d496ecb RR |
230 | |
231 | private: | |
232 | wxDateTime m_date; | |
233 | ||
234 | protected: | |
baa9ebc4 | 235 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer) |
4d496ecb RR |
236 | }; |
237 | ||
fa28826d RR |
238 | // --------------------------------------------------------- |
239 | // wxDataViewColumn | |
240 | // --------------------------------------------------------- | |
241 | ||
242 | class WXDLLIMPEXP_CORE wxDataViewColumn: public wxDataViewColumnBase | |
243 | { | |
244 | public: | |
87f0efe2 RR |
245 | wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer, |
246 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
247 | wxAlignment align = wxALIGN_CENTER, | |
248 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
249 | wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer, | |
250 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
251 | wxAlignment align = wxALIGN_CENTER, | |
252 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
253 | ||
fa28826d RR |
254 | virtual ~wxDataViewColumn(); |
255 | ||
9861f022 RR |
256 | |
257 | // setters: | |
258 | ||
fa28826d | 259 | virtual void SetTitle( const wxString &title ); |
07a84e7b | 260 | virtual void SetBitmap( const wxBitmap &bitmap ); |
47cef10f | 261 | |
b94db696 RR |
262 | virtual void SetOwner( wxDataViewCtrl *owner ); |
263 | ||
47cef10f | 264 | virtual void SetAlignment( wxAlignment align ); |
31fb32e1 RR |
265 | |
266 | virtual void SetSortable( bool sortable ); | |
47cef10f RR |
267 | virtual void SetSortOrder( bool ascending ); |
268 | ||
9861f022 RR |
269 | virtual void SetResizeable( bool resizeable ); |
270 | virtual void SetHidden( bool hidden ); | |
271 | ||
272 | virtual void SetMinWidth( int minWidth ); | |
273 | virtual void SetWidth( int width ); | |
274 | ||
275 | ||
276 | // getters: | |
277 | ||
278 | virtual wxString GetTitle() const; | |
279 | virtual wxAlignment GetAlignment() const; | |
280 | ||
87f0efe2 RR |
281 | virtual bool IsSortable() const; |
282 | virtual bool IsSortOrderAscending() const; | |
9861f022 RR |
283 | virtual bool IsResizeable() const; |
284 | virtual bool IsHidden() const; | |
87f0efe2 RR |
285 | |
286 | virtual int GetWidth() const; | |
9861f022 RR |
287 | virtual int GetMinWidth() const; |
288 | ||
fa28826d | 289 | // implementation |
9861f022 | 290 | GtkWidget* GetGtkHandle() { return m_column; } |
aed836f3 | 291 | GtkWidget* GetConstGtkHandle() const { return m_column; } |
fa28826d RR |
292 | |
293 | private: | |
6842a71a | 294 | // holds the GTK handle |
9861f022 | 295 | GtkWidget *m_column; |
31fb32e1 RR |
296 | |
297 | // delayed connection to mouse events | |
298 | friend class wxDataViewCtrl; | |
299 | void OnInternalIdle(); | |
9861f022 RR |
300 | bool m_isConnected; |
301 | ||
302 | void Init(wxAlignment align, int flags, int width); | |
303 | ||
fa28826d RR |
304 | protected: |
305 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn) | |
306 | }; | |
307 | ||
91a6c655 RR |
308 | WX_DECLARE_LIST(wxDataViewColumn, wxDataViewColumnList ); |
309 | ||
239eaa41 RR |
310 | // --------------------------------------------------------- |
311 | // wxDataViewCtrl | |
312 | // --------------------------------------------------------- | |
313 | ||
314 | class WXDLLIMPEXP_CORE wxDataViewCtrl: public wxDataViewCtrlBase | |
315 | { | |
316 | public: | |
317 | wxDataViewCtrl() | |
318 | { | |
319 | Init(); | |
320 | } | |
321 | ||
322 | wxDataViewCtrl( wxWindow *parent, wxWindowID id, | |
323 | const wxPoint& pos = wxDefaultPosition, | |
324 | const wxSize& size = wxDefaultSize, long style = 0, | |
325 | const wxValidator& validator = wxDefaultValidator ) | |
326 | { | |
327 | Create(parent, id, pos, size, style, validator ); | |
328 | } | |
329 | ||
330 | virtual ~wxDataViewCtrl(); | |
331 | ||
332 | void Init(); | |
333 | ||
334 | bool Create(wxWindow *parent, wxWindowID id, | |
335 | const wxPoint& pos = wxDefaultPosition, | |
336 | const wxSize& size = wxDefaultSize, long style = 0, | |
337 | const wxValidator& validator = wxDefaultValidator ); | |
338 | ||
e0062c04 | 339 | virtual bool AssociateModel( wxDataViewModel *model ); |
91a6c655 | 340 | |
1a367564 | 341 | virtual bool AppendColumn( wxDataViewColumn *col ); |
91a6c655 RR |
342 | virtual unsigned int GetColumnCount() const; |
343 | virtual wxDataViewColumn* GetColumn( unsigned int pos ) const; | |
344 | virtual bool DeleteColumn( wxDataViewColumn *column ); | |
345 | virtual bool ClearColumns(); | |
453091c2 | 346 | virtual int GetColumnPosition( const wxDataViewColumn *column ) const; |
1e08ad10 | 347 | |
21f47fb9 RR |
348 | virtual wxDataViewColumn *GetSortingColumn() const; |
349 | ||
fbda518c | 350 | virtual wxDataViewItem GetSelection() const; |
e98351ec RR |
351 | virtual int GetSelections( wxDataViewItemArray & sel ) const; |
352 | virtual void SetSelections( const wxDataViewItemArray & sel ); | |
353 | virtual void Select( const wxDataViewItem & item ); | |
354 | virtual void Unselect( const wxDataViewItem & item ); | |
355 | virtual bool IsSelected( const wxDataViewItem & item ) const; | |
356 | virtual void SelectAll(); | |
357 | virtual void UnselectAll(); | |
358 | ||
fbda518c RR |
359 | virtual void EnsureVisible( const wxDataViewItem& item, |
360 | const wxDataViewColumn *column = NULL ); | |
66e09788 | 361 | virtual void HitTest( const wxPoint &point, |
fbda518c | 362 | wxDataViewItem &item, |
a87b466d | 363 | wxDataViewColumn *&column ) const; |
66e09788 | 364 | virtual wxRect GetItemRect( const wxDataViewItem &item, |
fbda518c | 365 | const wxDataViewColumn *column = NULL ) const; |
66e09788 | 366 | |
f71d3ba4 RR |
367 | virtual void Expand( const wxDataViewItem & item ); |
368 | virtual void Collapse( const wxDataViewItem & item ); | |
66e09788 | 369 | |
b94db696 RR |
370 | static wxVisualAttributes |
371 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
6ff7eee7 | 372 | |
1e510b1e | 373 | wxWindow *GetMainWindow() { return (wxWindow*) this; } |
55fbde12 RR |
374 | |
375 | GtkWidget *GtkGetTreeView() { return m_treeview; } | |
376 | wxDataViewCtrlInternal* GtkGetInternal() { return m_internal; } | |
3b6280be RR |
377 | |
378 | protected: | |
379 | virtual void DoSetExpanderColumn(); | |
380 | virtual void DoSetIndent(); | |
381 | ||
1a367564 RR |
382 | private: |
383 | friend class wxDataViewCtrlDC; | |
31fb32e1 | 384 | friend class wxDataViewColumn; |
e0062c04 RR |
385 | friend class wxGtkDataViewModelNotifier; |
386 | GtkWidget *m_treeview; | |
387 | wxDataViewModelNotifier *m_notifier; | |
55fbde12 | 388 | wxDataViewCtrlInternal *m_internal; |
91a6c655 | 389 | wxDataViewColumnList m_cols; |
3b6280be | 390 | |
239eaa41 | 391 | |
31fb32e1 RR |
392 | virtual void OnInternalIdle(); |
393 | ||
b086d55f RR |
394 | void GtkEnableSelectionEvents(); |
395 | void GtkDisableSelectionEvents(); | |
396 | ||
239eaa41 RR |
397 | private: |
398 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
399 | DECLARE_NO_COPY_CLASS(wxDataViewCtrl) | |
400 | }; | |
401 | ||
402 | ||
403 | #endif // __GTKDATAVIEWCTRLH__ |