]>
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 | ||
d350fbec VS |
22 | class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl; |
23 | class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal; | |
239eaa41 | 24 | |
87f0efe2 | 25 | |
6842a71a | 26 | // --------------------------------------------------------- |
baa9ebc4 | 27 | // wxDataViewRenderer |
6842a71a RR |
28 | // --------------------------------------------------------- |
29 | ||
d350fbec | 30 | class WXDLLIMPEXP_ADV 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 | ||
d350fbec | 58 | class WXDLLIMPEXP_ADV 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 | ||
d350fbec | 78 | class WXDLLIMPEXP_ADV 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 | ||
d350fbec | 96 | class WXDLLIMPEXP_ADV 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 | ||
d350fbec | 114 | class WXDLLIMPEXP_ADV 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; |
52e750fc RR |
125 | |
126 | void RenderText( const wxString &text, int xoffset, wxRect cell, wxDC *dc, int state ); | |
127 | ||
9861f022 RR |
128 | virtual wxSize GetSize() const = 0; |
129 | ||
4d496ecb | 130 | virtual bool Activate( wxRect cell, |
e0062c04 | 131 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) |
4d496ecb | 132 | { return false; } |
9861f022 | 133 | |
4d496ecb | 134 | virtual bool LeftClick( wxPoint cursor, wxRect cell, |
e0062c04 | 135 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) |
4d496ecb RR |
136 | { return false; } |
137 | virtual bool RightClick( wxPoint cursor, wxRect cell, | |
e0062c04 | 138 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) |
4d496ecb RR |
139 | { return false; } |
140 | virtual bool StartDrag( wxPoint cursor, wxRect cell, | |
e0062c04 | 141 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ) |
4d496ecb | 142 | { return false; } |
e152afc3 RR |
143 | |
144 | // Create DC on request | |
145 | virtual wxDC *GetDC(); | |
146 | ||
9861f022 RR |
147 | |
148 | protected: | |
149 | ||
150 | bool Init(wxDataViewCellMode mode, int align); | |
151 | ||
e152afc3 RR |
152 | private: |
153 | wxDC *m_dc; | |
f69c03de RR |
154 | |
155 | public: | |
156 | // Internal, temporay for RenderText. | |
157 | GtkCellRenderer *m_text_renderer; | |
158 | GdkWindow *window; | |
159 | GtkWidget *widget; | |
160 | void *background_area; | |
161 | void *cell_area; | |
162 | void *expose_area; | |
163 | int flags; | |
164 | ||
e152afc3 | 165 | protected: |
baa9ebc4 | 166 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer) |
e152afc3 RR |
167 | }; |
168 | ||
ad63bf41 | 169 | // --------------------------------------------------------- |
baa9ebc4 | 170 | // wxDataViewProgressRenderer |
ad63bf41 RR |
171 | // --------------------------------------------------------- |
172 | ||
d350fbec | 173 | class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer |
ad63bf41 RR |
174 | { |
175 | public: | |
baa9ebc4 RR |
176 | wxDataViewProgressRenderer( const wxString &label = wxEmptyString, |
177 | const wxString &varianttype = wxT("long"), | |
9861f022 RR |
178 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, |
179 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
baa9ebc4 | 180 | virtual ~wxDataViewProgressRenderer(); |
ad63bf41 RR |
181 | |
182 | bool SetValue( const wxVariant &value ); | |
9861f022 | 183 | bool GetValue( wxVariant &value ) const; |
ad63bf41 RR |
184 | |
185 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
9861f022 | 186 | virtual wxSize GetSize() const; |
ad63bf41 RR |
187 | |
188 | private: | |
189 | wxString m_label; | |
190 | int m_value; | |
191 | ||
192 | protected: | |
baa9ebc4 | 193 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer) |
ad63bf41 RR |
194 | }; |
195 | ||
c9c13e70 RR |
196 | // --------------------------------------------------------- |
197 | // wxDataViewIconTextRenderer | |
198 | // --------------------------------------------------------- | |
199 | ||
d350fbec | 200 | class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer |
c9c13e70 RR |
201 | { |
202 | public: | |
203 | wxDataViewIconTextRenderer( const wxString &varianttype = wxT("wxDataViewIconText"), | |
204 | wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, | |
205 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
206 | virtual ~wxDataViewIconTextRenderer(); | |
207 | ||
208 | bool SetValue( const wxVariant &value ); | |
209 | bool GetValue( wxVariant &value ) const; | |
210 | ||
211 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
212 | virtual wxSize GetSize() const; | |
213 | ||
214 | virtual bool HasEditorCtrl() { return true; } | |
215 | virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ); | |
216 | virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ); | |
217 | ||
218 | private: | |
219 | wxDataViewIconText m_value; | |
220 | ||
221 | protected: | |
222 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer) | |
223 | }; | |
224 | ||
4d496ecb | 225 | // --------------------------------------------------------- |
baa9ebc4 | 226 | // wxDataViewDateRenderer |
4d496ecb RR |
227 | // --------------------------------------------------------- |
228 | ||
d350fbec | 229 | class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer |
4d496ecb RR |
230 | { |
231 | public: | |
baa9ebc4 | 232 | wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"), |
9861f022 RR |
233 | wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, |
234 | int align = wxDVR_DEFAULT_ALIGNMENT ); | |
4d496ecb RR |
235 | |
236 | bool SetValue( const wxVariant &value ); | |
9861f022 | 237 | bool GetValue( wxVariant &value ) const; |
4d496ecb RR |
238 | |
239 | virtual bool Render( wxRect cell, wxDC *dc, int state ); | |
9861f022 | 240 | virtual wxSize GetSize() const; |
4d496ecb | 241 | virtual bool Activate( wxRect cell, |
e0062c04 | 242 | wxDataViewModel *model, const wxDataViewItem &item, unsigned int col ); |
4d496ecb RR |
243 | |
244 | private: | |
245 | wxDateTime m_date; | |
246 | ||
247 | protected: | |
baa9ebc4 | 248 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer) |
4d496ecb RR |
249 | }; |
250 | ||
fa28826d RR |
251 | // --------------------------------------------------------- |
252 | // wxDataViewColumn | |
253 | // --------------------------------------------------------- | |
254 | ||
d350fbec | 255 | class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase |
fa28826d RR |
256 | { |
257 | public: | |
87f0efe2 RR |
258 | wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer, |
259 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
260 | wxAlignment align = wxALIGN_CENTER, | |
261 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
262 | wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer, | |
263 | unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH, | |
264 | wxAlignment align = wxALIGN_CENTER, | |
265 | int flags = wxDATAVIEW_COL_RESIZABLE ); | |
266 | ||
fa28826d RR |
267 | virtual ~wxDataViewColumn(); |
268 | ||
9861f022 RR |
269 | |
270 | // setters: | |
271 | ||
fa28826d | 272 | virtual void SetTitle( const wxString &title ); |
07a84e7b | 273 | virtual void SetBitmap( const wxBitmap &bitmap ); |
47cef10f | 274 | |
b94db696 RR |
275 | virtual void SetOwner( wxDataViewCtrl *owner ); |
276 | ||
47cef10f | 277 | virtual void SetAlignment( wxAlignment align ); |
31fb32e1 RR |
278 | |
279 | virtual void SetSortable( bool sortable ); | |
47cef10f RR |
280 | virtual void SetSortOrder( bool ascending ); |
281 | ||
9861f022 RR |
282 | virtual void SetResizeable( bool resizeable ); |
283 | virtual void SetHidden( bool hidden ); | |
284 | ||
285 | virtual void SetMinWidth( int minWidth ); | |
286 | virtual void SetWidth( int width ); | |
287 | ||
288 | ||
289 | // getters: | |
290 | ||
291 | virtual wxString GetTitle() const; | |
292 | virtual wxAlignment GetAlignment() const; | |
293 | ||
87f0efe2 RR |
294 | virtual bool IsSortable() const; |
295 | virtual bool IsSortOrderAscending() const; | |
9861f022 RR |
296 | virtual bool IsResizeable() const; |
297 | virtual bool IsHidden() const; | |
87f0efe2 RR |
298 | |
299 | virtual int GetWidth() const; | |
9861f022 RR |
300 | virtual int GetMinWidth() const; |
301 | ||
fa28826d | 302 | // implementation |
9861f022 | 303 | GtkWidget* GetGtkHandle() { return m_column; } |
aed836f3 | 304 | GtkWidget* GetConstGtkHandle() const { return m_column; } |
fa28826d RR |
305 | |
306 | private: | |
6842a71a | 307 | // holds the GTK handle |
9861f022 | 308 | GtkWidget *m_column; |
31fb32e1 RR |
309 | |
310 | // delayed connection to mouse events | |
311 | friend class wxDataViewCtrl; | |
312 | void OnInternalIdle(); | |
9861f022 RR |
313 | bool m_isConnected; |
314 | ||
315 | void Init(wxAlignment align, int flags, int width); | |
316 | ||
fa28826d RR |
317 | protected: |
318 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn) | |
319 | }; | |
320 | ||
d350fbec VS |
321 | WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList, |
322 | class WXDLLIMPEXP_ADV); | |
91a6c655 | 323 | |
239eaa41 RR |
324 | // --------------------------------------------------------- |
325 | // wxDataViewCtrl | |
326 | // --------------------------------------------------------- | |
327 | ||
d350fbec | 328 | class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase |
239eaa41 RR |
329 | { |
330 | public: | |
331 | wxDataViewCtrl() | |
332 | { | |
333 | Init(); | |
334 | } | |
335 | ||
336 | wxDataViewCtrl( wxWindow *parent, wxWindowID id, | |
337 | const wxPoint& pos = wxDefaultPosition, | |
338 | const wxSize& size = wxDefaultSize, long style = 0, | |
339 | const wxValidator& validator = wxDefaultValidator ) | |
340 | { | |
341 | Create(parent, id, pos, size, style, validator ); | |
342 | } | |
343 | ||
344 | virtual ~wxDataViewCtrl(); | |
345 | ||
346 | void Init(); | |
347 | ||
348 | bool Create(wxWindow *parent, wxWindowID id, | |
349 | const wxPoint& pos = wxDefaultPosition, | |
350 | const wxSize& size = wxDefaultSize, long style = 0, | |
351 | const wxValidator& validator = wxDefaultValidator ); | |
352 | ||
e0062c04 | 353 | virtual bool AssociateModel( wxDataViewModel *model ); |
91a6c655 | 354 | |
736fe67c | 355 | virtual bool PrependColumn( wxDataViewColumn *col ); |
1a367564 | 356 | virtual bool AppendColumn( wxDataViewColumn *col ); |
91a6c655 RR |
357 | virtual unsigned int GetColumnCount() const; |
358 | virtual wxDataViewColumn* GetColumn( unsigned int pos ) const; | |
359 | virtual bool DeleteColumn( wxDataViewColumn *column ); | |
360 | virtual bool ClearColumns(); | |
453091c2 | 361 | virtual int GetColumnPosition( const wxDataViewColumn *column ) const; |
1e08ad10 | 362 | |
21f47fb9 RR |
363 | virtual wxDataViewColumn *GetSortingColumn() const; |
364 | ||
fbda518c | 365 | virtual wxDataViewItem GetSelection() const; |
e98351ec RR |
366 | virtual int GetSelections( wxDataViewItemArray & sel ) const; |
367 | virtual void SetSelections( const wxDataViewItemArray & sel ); | |
368 | virtual void Select( const wxDataViewItem & item ); | |
369 | virtual void Unselect( const wxDataViewItem & item ); | |
370 | virtual bool IsSelected( const wxDataViewItem & item ) const; | |
371 | virtual void SelectAll(); | |
372 | virtual void UnselectAll(); | |
373 | ||
fbda518c RR |
374 | virtual void EnsureVisible( const wxDataViewItem& item, |
375 | const wxDataViewColumn *column = NULL ); | |
66e09788 | 376 | virtual void HitTest( const wxPoint &point, |
fbda518c | 377 | wxDataViewItem &item, |
a87b466d | 378 | wxDataViewColumn *&column ) const; |
66e09788 | 379 | virtual wxRect GetItemRect( const wxDataViewItem &item, |
fbda518c | 380 | const wxDataViewColumn *column = NULL ) const; |
66e09788 | 381 | |
f71d3ba4 RR |
382 | virtual void Expand( const wxDataViewItem & item ); |
383 | virtual void Collapse( const wxDataViewItem & item ); | |
66e09788 | 384 | |
b94db696 RR |
385 | static wxVisualAttributes |
386 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
6ff7eee7 | 387 | |
1e510b1e | 388 | wxWindow *GetMainWindow() { return (wxWindow*) this; } |
55fbde12 RR |
389 | |
390 | GtkWidget *GtkGetTreeView() { return m_treeview; } | |
391 | wxDataViewCtrlInternal* GtkGetInternal() { return m_internal; } | |
3b6280be RR |
392 | |
393 | protected: | |
394 | virtual void DoSetExpanderColumn(); | |
395 | virtual void DoSetIndent(); | |
396 | ||
1a367564 RR |
397 | private: |
398 | friend class wxDataViewCtrlDC; | |
31fb32e1 | 399 | friend class wxDataViewColumn; |
e0062c04 RR |
400 | friend class wxGtkDataViewModelNotifier; |
401 | GtkWidget *m_treeview; | |
402 | wxDataViewModelNotifier *m_notifier; | |
55fbde12 | 403 | wxDataViewCtrlInternal *m_internal; |
91a6c655 | 404 | wxDataViewColumnList m_cols; |
3b6280be | 405 | |
239eaa41 | 406 | |
31fb32e1 RR |
407 | virtual void OnInternalIdle(); |
408 | ||
b086d55f RR |
409 | void GtkEnableSelectionEvents(); |
410 | void GtkDisableSelectionEvents(); | |
411 | ||
239eaa41 RR |
412 | private: |
413 | DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) | |
414 | DECLARE_NO_COPY_CLASS(wxDataViewCtrl) | |
415 | }; | |
416 | ||
417 | ||
418 | #endif // __GTKDATAVIEWCTRLH__ |