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