]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/gtk/dataview.h
Make SaveFile and LoadFile virtual so they can be overridden
[wxWidgets.git] / include / wx / gtk / dataview.h
... / ...
CommitLineData
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
22class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl;
23class WXDLLIMPEXP_FWD_ADV wxDataViewCtrlInternal;
24
25
26// ---------------------------------------------------------
27// wxDataViewRenderer
28// ---------------------------------------------------------
29
30class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
31{
32public:
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
47protected:
48 GtkCellRenderer *m_renderer;
49
50protected:
51 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
52};
53
54// ---------------------------------------------------------
55// wxDataViewTextRenderer
56// ---------------------------------------------------------
57
58class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewRenderer
59{
60public:
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
70protected:
71 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
72};
73
74// ---------------------------------------------------------
75// wxDataViewBitmapRenderer
76// ---------------------------------------------------------
77
78class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewRenderer
79{
80public:
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
88protected:
89 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
90};
91
92// ---------------------------------------------------------
93// wxDataViewToggleRenderer
94// ---------------------------------------------------------
95
96class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewRenderer
97{
98public:
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
106protected:
107 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
108};
109
110// ---------------------------------------------------------
111// wxDataViewCustomRenderer
112// ---------------------------------------------------------
113
114class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
115{
116public:
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
145protected:
146
147 bool Init(wxDataViewCellMode mode, int align);
148
149private:
150 wxDC *m_dc;
151
152protected:
153 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
154};
155
156// ---------------------------------------------------------
157// wxDataViewProgressRenderer
158// ---------------------------------------------------------
159
160class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
161{
162public:
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
175private:
176 wxString m_label;
177 int m_value;
178
179protected:
180 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
181};
182
183// ---------------------------------------------------------
184// wxDataViewIconTextRenderer
185// ---------------------------------------------------------
186
187class WXDLLIMPEXP_ADV wxDataViewIconTextRenderer: public wxDataViewCustomRenderer
188{
189public:
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
205private:
206 wxDataViewIconText m_value;
207
208protected:
209 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewIconTextRenderer)
210};
211
212// ---------------------------------------------------------
213// wxDataViewDateRenderer
214// ---------------------------------------------------------
215
216class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
217{
218public:
219 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
220 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
221 int align = wxDVR_DEFAULT_ALIGNMENT );
222
223 bool SetValue( const wxVariant &value );
224 bool GetValue( wxVariant &value ) const;
225
226 virtual bool Render( wxRect cell, wxDC *dc, int state );
227 virtual wxSize GetSize() const;
228 virtual bool Activate( wxRect cell,
229 wxDataViewModel *model, const wxDataViewItem &item, unsigned int col );
230
231private:
232 wxDateTime m_date;
233
234protected:
235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
236};
237
238// ---------------------------------------------------------
239// wxDataViewColumn
240// ---------------------------------------------------------
241
242class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
243{
244public:
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
254 virtual ~wxDataViewColumn();
255
256
257 // setters:
258
259 virtual void SetTitle( const wxString &title );
260 virtual void SetBitmap( const wxBitmap &bitmap );
261
262 virtual void SetOwner( wxDataViewCtrl *owner );
263
264 virtual void SetAlignment( wxAlignment align );
265
266 virtual void SetSortable( bool sortable );
267 virtual void SetSortOrder( bool ascending );
268
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
281 virtual bool IsSortable() const;
282 virtual bool IsSortOrderAscending() const;
283 virtual bool IsResizeable() const;
284 virtual bool IsHidden() const;
285
286 virtual int GetWidth() const;
287 virtual int GetMinWidth() const;
288
289 // implementation
290 GtkWidget* GetGtkHandle() { return m_column; }
291 GtkWidget* GetConstGtkHandle() const { return m_column; }
292
293private:
294 // holds the GTK handle
295 GtkWidget *m_column;
296
297 // delayed connection to mouse events
298 friend class wxDataViewCtrl;
299 void OnInternalIdle();
300 bool m_isConnected;
301
302 void Init(wxAlignment align, int flags, int width);
303
304protected:
305 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
306};
307
308WX_DECLARE_LIST_WITH_DECL(wxDataViewColumn, wxDataViewColumnList,
309 class WXDLLIMPEXP_ADV);
310
311// ---------------------------------------------------------
312// wxDataViewCtrl
313// ---------------------------------------------------------
314
315class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase
316{
317public:
318 wxDataViewCtrl()
319 {
320 Init();
321 }
322
323 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
324 const wxPoint& pos = wxDefaultPosition,
325 const wxSize& size = wxDefaultSize, long style = 0,
326 const wxValidator& validator = wxDefaultValidator )
327 {
328 Create(parent, id, pos, size, style, validator );
329 }
330
331 virtual ~wxDataViewCtrl();
332
333 void Init();
334
335 bool Create(wxWindow *parent, wxWindowID id,
336 const wxPoint& pos = wxDefaultPosition,
337 const wxSize& size = wxDefaultSize, long style = 0,
338 const wxValidator& validator = wxDefaultValidator );
339
340 virtual bool AssociateModel( wxDataViewModel *model );
341
342 virtual bool AppendColumn( wxDataViewColumn *col );
343 virtual unsigned int GetColumnCount() const;
344 virtual wxDataViewColumn* GetColumn( unsigned int pos ) const;
345 virtual bool DeleteColumn( wxDataViewColumn *column );
346 virtual bool ClearColumns();
347 virtual int GetColumnPosition( const wxDataViewColumn *column ) const;
348
349 virtual wxDataViewColumn *GetSortingColumn() const;
350
351 virtual wxDataViewItem GetSelection() const;
352 virtual int GetSelections( wxDataViewItemArray & sel ) const;
353 virtual void SetSelections( const wxDataViewItemArray & sel );
354 virtual void Select( const wxDataViewItem & item );
355 virtual void Unselect( const wxDataViewItem & item );
356 virtual bool IsSelected( const wxDataViewItem & item ) const;
357 virtual void SelectAll();
358 virtual void UnselectAll();
359
360 virtual void EnsureVisible( const wxDataViewItem& item,
361 const wxDataViewColumn *column = NULL );
362 virtual void HitTest( const wxPoint &point,
363 wxDataViewItem &item,
364 wxDataViewColumn *&column ) const;
365 virtual wxRect GetItemRect( const wxDataViewItem &item,
366 const wxDataViewColumn *column = NULL ) const;
367
368 virtual void Expand( const wxDataViewItem & item );
369 virtual void Collapse( const wxDataViewItem & item );
370
371 static wxVisualAttributes
372 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
373
374 wxWindow *GetMainWindow() { return (wxWindow*) this; }
375
376 GtkWidget *GtkGetTreeView() { return m_treeview; }
377 wxDataViewCtrlInternal* GtkGetInternal() { return m_internal; }
378
379protected:
380 virtual void DoSetExpanderColumn();
381 virtual void DoSetIndent();
382
383private:
384 friend class wxDataViewCtrlDC;
385 friend class wxDataViewColumn;
386 friend class wxGtkDataViewModelNotifier;
387 GtkWidget *m_treeview;
388 wxDataViewModelNotifier *m_notifier;
389 wxDataViewCtrlInternal *m_internal;
390 wxDataViewColumnList m_cols;
391
392
393 virtual void OnInternalIdle();
394
395 void GtkEnableSelectionEvents();
396 void GtkDisableSelectionEvents();
397
398private:
399 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
400 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
401};
402
403
404#endif // __GTKDATAVIEWCTRLH__