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