]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gtk/dataview.h
set eol-style
[wxWidgets.git] / include / wx / gtk / dataview.h
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
22 class WXDLLIMPEXP_FWD_CORE wxDataViewCtrl;
23 class WXDLLIMPEXP_FWD_CORE wxDataViewCtrlInternal;
24
25
26 // ---------------------------------------------------------
27 // wxDataViewRenderer
28 // ---------------------------------------------------------
29
30 class wxDataViewRenderer: public wxDataViewRendererBase
31 {
32 public:
33 wxDataViewRenderer( const wxString &varianttype,
34 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
35 int align = wxDVR_DEFAULT_ALIGNMENT );
36
37 // implementation
38 GtkCellRenderer* GetGtkHandle() { return m_renderer; }
39
40 virtual void SetMode( wxDataViewCellMode mode );
41 virtual wxDataViewCellMode GetMode() const;
42
43 virtual void SetAlignment( int align );
44 virtual int GetAlignment() const;
45
46 protected:
47 GtkCellRenderer *m_renderer;
48
49 protected:
50 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
51 };
52
53 // ---------------------------------------------------------
54 // wxDataViewTextRenderer
55 // ---------------------------------------------------------
56
57 class wxDataViewTextRenderer: public wxDataViewRenderer
58 {
59 public:
60 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
61 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
62 int align = wxDVR_DEFAULT_ALIGNMENT );
63
64 bool SetValue( const wxVariant &value );
65 bool GetValue( wxVariant &value ) const;
66
67 void SetAlignment( int align );
68
69 protected:
70 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
71 };
72
73 // ---------------------------------------------------------
74 // wxDataViewBitmapRenderer
75 // ---------------------------------------------------------
76
77 class wxDataViewBitmapRenderer: public wxDataViewRenderer
78 {
79 public:
80 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
81 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
82 int align = wxDVR_DEFAULT_ALIGNMENT );
83
84 bool SetValue( const wxVariant &value );
85 bool GetValue( wxVariant &value ) const;
86
87 protected:
88 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
89 };
90
91 // ---------------------------------------------------------
92 // wxDataViewToggleRenderer
93 // ---------------------------------------------------------
94
95 class wxDataViewToggleRenderer: public wxDataViewRenderer
96 {
97 public:
98 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
99 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
100 int align = wxDVR_DEFAULT_ALIGNMENT );
101
102 bool SetValue( const wxVariant &value );
103 bool GetValue( wxVariant &value ) const;
104
105 protected:
106 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
107 };
108
109 // ---------------------------------------------------------
110 // wxDataViewCustomRenderer
111 // ---------------------------------------------------------
112
113 class wxDataViewCustomRenderer: public wxDataViewRenderer
114 {
115 public:
116 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
117 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
118 int align = wxDVR_DEFAULT_ALIGNMENT,
119 bool no_init = false );
120 virtual ~wxDataViewCustomRenderer();
121
122
123 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
124 virtual wxSize GetSize() const = 0;
125
126 virtual bool Activate( wxRect cell,
127 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col )
128 { return false; }
129
130 virtual bool LeftClick( wxPoint cursor, wxRect cell,
131 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col )
132 { return false; }
133 virtual bool RightClick( wxPoint cursor, wxRect cell,
134 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col )
135 { return false; }
136 virtual bool StartDrag( wxPoint cursor, wxRect cell,
137 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col )
138 { return false; }
139
140 // Create DC on request
141 virtual wxDC *GetDC();
142
143
144 protected:
145
146 bool Init(wxDataViewCellMode mode, int align);
147
148 private:
149 wxDC *m_dc;
150
151 protected:
152 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
153 };
154
155 // ---------------------------------------------------------
156 // wxDataViewProgressRenderer
157 // ---------------------------------------------------------
158
159 class wxDataViewProgressRenderer: public wxDataViewCustomRenderer
160 {
161 public:
162 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
163 const wxString &varianttype = wxT("long"),
164 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
165 int align = wxDVR_DEFAULT_ALIGNMENT );
166 virtual ~wxDataViewProgressRenderer();
167
168 bool SetValue( const wxVariant &value );
169 bool GetValue( wxVariant &value ) const;
170
171 virtual bool Render( wxRect cell, wxDC *dc, int state );
172 virtual wxSize GetSize() const;
173
174 private:
175 wxString m_label;
176 int m_value;
177
178 protected:
179 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
180 };
181
182 // ---------------------------------------------------------
183 // wxDataViewDateRenderer
184 // ---------------------------------------------------------
185
186 class wxDataViewDateRenderer: public wxDataViewCustomRenderer
187 {
188 public:
189 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
190 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
191 int align = wxDVR_DEFAULT_ALIGNMENT );
192
193 bool SetValue( const wxVariant &value );
194 bool GetValue( wxVariant &value ) const;
195
196 virtual bool Render( wxRect cell, wxDC *dc, int state );
197 virtual wxSize GetSize() const;
198 virtual bool Activate( wxRect cell,
199 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col );
200
201 private:
202 wxDateTime m_date;
203
204 protected:
205 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
206 };
207
208 // ---------------------------------------------------------
209 // wxDataViewColumn
210 // ---------------------------------------------------------
211
212 class WXDLLIMPEXP_CORE wxDataViewColumn: public wxDataViewColumnBase
213 {
214 public:
215 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
216 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
217 wxAlignment align = wxALIGN_CENTER,
218 int flags = wxDATAVIEW_COL_RESIZABLE );
219 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
220 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
221 wxAlignment align = wxALIGN_CENTER,
222 int flags = wxDATAVIEW_COL_RESIZABLE );
223
224 virtual ~wxDataViewColumn();
225
226
227 // setters:
228
229 virtual void SetTitle( const wxString &title );
230 virtual void SetBitmap( const wxBitmap &bitmap );
231
232 virtual void SetOwner( wxDataViewCtrl *owner );
233
234 virtual void SetAlignment( wxAlignment align );
235
236 virtual void SetSortable( bool sortable );
237 virtual void SetSortOrder( bool ascending );
238
239 virtual void SetResizeable( bool resizeable );
240 virtual void SetHidden( bool hidden );
241
242 virtual void SetMinWidth( int minWidth );
243 virtual void SetWidth( int width );
244
245
246 // getters:
247
248 virtual wxString GetTitle() const;
249 virtual wxAlignment GetAlignment() const;
250
251 virtual bool IsSortable() const;
252 virtual bool IsSortOrderAscending() const;
253 virtual bool IsResizeable() const;
254 virtual bool IsHidden() const;
255
256 virtual int GetWidth() const;
257 virtual int GetMinWidth() const;
258
259 // implementation
260 GtkWidget* GetGtkHandle() { return m_column; }
261
262 private:
263 // holds the GTK handle
264 GtkWidget *m_column;
265
266 // delayed connection to mouse events
267 friend class wxDataViewCtrl;
268 void OnInternalIdle();
269 bool m_isConnected;
270
271 void Init(wxAlignment align, int flags, int width);
272
273 protected:
274 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
275 };
276
277 // ---------------------------------------------------------
278 // wxDataViewCtrl
279 // ---------------------------------------------------------
280
281 class WXDLLIMPEXP_CORE wxDataViewCtrl: public wxDataViewCtrlBase
282 {
283 public:
284 wxDataViewCtrl()
285 {
286 Init();
287 }
288
289 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
290 const wxPoint& pos = wxDefaultPosition,
291 const wxSize& size = wxDefaultSize, long style = 0,
292 const wxValidator& validator = wxDefaultValidator )
293 {
294 Create(parent, id, pos, size, style, validator );
295 }
296
297 virtual ~wxDataViewCtrl();
298
299 void Init();
300
301 bool Create(wxWindow *parent, wxWindowID id,
302 const wxPoint& pos = wxDefaultPosition,
303 const wxSize& size = wxDefaultSize, long style = 0,
304 const wxValidator& validator = wxDefaultValidator );
305
306 virtual bool AssociateModel( wxDataViewModel *model );
307 virtual bool AppendColumn( wxDataViewColumn *col );
308
309 // selection code
310 virtual wxDataViewItem GetSelection();
311
312
313 static wxVisualAttributes
314 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
315
316 wxWindow *GetMainWindow() { return (wxWindow*) this; }
317
318 GtkWidget *GtkGetTreeView() { return m_treeview; }
319 wxDataViewCtrlInternal* GtkGetInternal() { return m_internal; }
320
321 protected:
322 virtual void DoSetExpanderColumn();
323 virtual void DoSetIndent();
324
325 private:
326 friend class wxDataViewCtrlDC;
327 friend class wxDataViewColumn;
328 friend class wxGtkDataViewModelNotifier;
329 GtkWidget *m_treeview;
330 wxDataViewModelNotifier *m_notifier;
331 wxDataViewCtrlInternal *m_internal;
332
333
334 virtual void OnInternalIdle();
335
336 void GtkEnableSelectionEvents();
337 void GtkDisableSelectionEvents();
338
339 private:
340 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
341 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
342 };
343
344
345 #endif // __GTKDATAVIEWCTRLH__