]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/dataview.h
use 2 extensions in a filter in FileSave() for testing
[wxWidgets.git] / include / wx / generic / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/dataview.h
3 // Purpose: wxDataViewCtrl generic implementation header
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef __GENERICDATAVIEWCTRLH__
11 #define __GENERICDATAVIEWCTRLH__
12
13 #include "wx/defs.h"
14 #include "wx/object.h"
15 #include "wx/list.h"
16 #include "wx/control.h"
17 #include "wx/scrolwin.h"
18 #include "wx/icon.h"
19
20 // ---------------------------------------------------------
21 // classes
22 // ---------------------------------------------------------
23
24 class WXDLLIMPEXP_ADV wxDataViewCtrl;
25 class WXDLLIMPEXP_ADV wxDataViewMainWindow;
26 class WXDLLIMPEXP_ADV wxDataViewHeaderWindow;
27
28 // ---------------------------------------------------------
29 // wxDataViewRenderer
30 // ---------------------------------------------------------
31
32 class WXDLLIMPEXP_ADV wxDataViewRenderer: public wxDataViewRendererBase
33 {
34 public:
35 wxDataViewRenderer( const wxString &varianttype,
36 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
37 int align = wxDVR_DEFAULT_ALIGNMENT );
38 virtual ~wxDataViewRenderer();
39
40 virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
41 virtual wxSize GetSize() const = 0;
42
43 virtual void SetAlignment( int align )
44 { m_align=align; }
45 virtual int GetAlignment() const
46 { return m_align; }
47
48 virtual void SetMode( wxDataViewCellMode mode )
49 { m_mode=mode; }
50 virtual wxDataViewCellMode GetMode() const
51 { return m_mode; }
52
53 virtual bool Activate( wxRect WXUNUSED(cell),
54 wxDataViewListModel *WXUNUSED(model),
55 unsigned int WXUNUSED(col),
56 unsigned int WXUNUSED(row) )
57 { return false; }
58
59 virtual bool LeftClick( wxPoint WXUNUSED(cursor),
60 wxRect WXUNUSED(cell),
61 wxDataViewListModel *WXUNUSED(model),
62 unsigned int WXUNUSED(col),
63 unsigned int WXUNUSED(row) )
64 { return false; }
65 virtual bool RightClick( wxPoint WXUNUSED(cursor),
66 wxRect WXUNUSED(cell),
67 wxDataViewListModel *WXUNUSED(model),
68 unsigned int WXUNUSED(col),
69 unsigned int WXUNUSED(row) )
70 { return false; }
71 virtual bool StartDrag( wxPoint WXUNUSED(cursor),
72 wxRect WXUNUSED(cell),
73 wxDataViewListModel *WXUNUSED(model),
74 unsigned int WXUNUSED(col),
75 unsigned int WXUNUSED(row) )
76 { return false; }
77
78 // Create DC on request
79 virtual wxDC *GetDC();
80
81 private:
82 wxDC *m_dc;
83 int m_align;
84 wxDataViewCellMode m_mode;
85
86 protected:
87 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
88 };
89
90 // ---------------------------------------------------------
91 // wxDataViewCustomRenderer
92 // ---------------------------------------------------------
93
94 class WXDLLIMPEXP_ADV wxDataViewCustomRenderer: public wxDataViewRenderer
95 {
96 public:
97 wxDataViewCustomRenderer( const wxString &varianttype = wxT("string"),
98 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
99 int align = wxDVR_DEFAULT_ALIGNMENT );
100
101 protected:
102 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCustomRenderer)
103 };
104
105 // ---------------------------------------------------------
106 // wxDataViewTextRenderer
107 // ---------------------------------------------------------
108
109 class WXDLLIMPEXP_ADV wxDataViewTextRenderer: public wxDataViewCustomRenderer
110 {
111 public:
112 wxDataViewTextRenderer( const wxString &varianttype = wxT("string"),
113 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
114 int align = wxDVR_DEFAULT_ALIGNMENT );
115
116 bool SetValue( const wxVariant &value );
117 bool GetValue( wxVariant &value ) const;
118
119 bool Render( wxRect cell, wxDC *dc, int state );
120 wxSize GetSize() const;
121
122 private:
123 wxString m_text;
124
125 protected:
126 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextRenderer)
127 };
128
129 // ---------------------------------------------------------
130 // wxDataViewBitmapRenderer
131 // ---------------------------------------------------------
132
133 class WXDLLIMPEXP_ADV wxDataViewBitmapRenderer: public wxDataViewCustomRenderer
134 {
135 public:
136 wxDataViewBitmapRenderer( const wxString &varianttype = wxT("wxBitmap"),
137 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
138 int align = wxDVR_DEFAULT_ALIGNMENT );
139
140 bool SetValue( const wxVariant &value );
141 bool GetValue( wxVariant &value ) const;
142
143 bool Render( wxRect cell, wxDC *dc, int state );
144 wxSize GetSize() const;
145
146 private:
147 wxIcon m_icon;
148 wxBitmap m_bitmap;
149
150 protected:
151 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewBitmapRenderer)
152 };
153
154 // ---------------------------------------------------------
155 // wxDataViewToggleRenderer
156 // ---------------------------------------------------------
157
158 class WXDLLIMPEXP_ADV wxDataViewToggleRenderer: public wxDataViewCustomRenderer
159 {
160 public:
161 wxDataViewToggleRenderer( const wxString &varianttype = wxT("bool"),
162 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
163 int align = wxDVR_DEFAULT_ALIGNMENT );
164
165 bool SetValue( const wxVariant &value );
166 bool GetValue( wxVariant &value ) const;
167
168 bool Render( wxRect cell, wxDC *dc, int state );
169 bool Activate( wxRect cell, wxDataViewListModel *model, unsigned int col,
170 unsigned int row );
171 wxSize GetSize() const;
172
173 private:
174 bool m_toggle;
175
176 protected:
177 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewToggleRenderer)
178 };
179
180 // ---------------------------------------------------------
181 // wxDataViewProgressRenderer
182 // ---------------------------------------------------------
183
184 class WXDLLIMPEXP_ADV wxDataViewProgressRenderer: public wxDataViewCustomRenderer
185 {
186 public:
187 wxDataViewProgressRenderer( const wxString &label = wxEmptyString,
188 const wxString &varianttype = wxT("long"),
189 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
190 int align = wxDVR_DEFAULT_ALIGNMENT );
191 virtual ~wxDataViewProgressRenderer();
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
199 private:
200 wxString m_label;
201 int m_value;
202
203 protected:
204 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressRenderer)
205 };
206
207 // ---------------------------------------------------------
208 // wxDataViewDateRenderer
209 // ---------------------------------------------------------
210
211 class WXDLLIMPEXP_ADV wxDataViewDateRenderer: public wxDataViewCustomRenderer
212 {
213 public:
214 wxDataViewDateRenderer( const wxString &varianttype = wxT("datetime"),
215 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE,
216 int align = wxDVR_DEFAULT_ALIGNMENT );
217
218 bool SetValue( const wxVariant &value );
219 bool GetValue( wxVariant& value ) const;
220
221 virtual bool Render( wxRect cell, wxDC *dc, int state );
222 virtual wxSize GetSize() const;
223 virtual bool Activate( wxRect cell,
224 wxDataViewListModel *model, unsigned int col, unsigned int row );
225
226 private:
227 wxDateTime m_date;
228
229 protected:
230 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateRenderer)
231 };
232
233 // ---------------------------------------------------------
234 // wxDataViewColumn
235 // ---------------------------------------------------------
236
237 class WXDLLIMPEXP_ADV wxDataViewColumn: public wxDataViewColumnBase
238 {
239 friend class wxDataViewHeaderWindowBase;
240 friend class wxDataViewHeaderWindow;
241 friend class wxDataViewHeaderWindowMSW;
242
243 public:
244 wxDataViewColumn( const wxString &title, wxDataViewRenderer *renderer,
245 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
246 wxAlignment align = wxALIGN_CENTER,
247 int flags = wxDATAVIEW_COL_RESIZABLE );
248 wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
249 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
250 wxAlignment align = wxALIGN_CENTER,
251 int flags = wxDATAVIEW_COL_RESIZABLE );
252 virtual ~wxDataViewColumn();
253
254 // setters:
255
256 virtual void SetTitle( const wxString &title )
257 { m_title=title; }
258 virtual void SetAlignment( wxAlignment align )
259 { m_align=align; }
260 virtual void SetMinWidth( int minWidth )
261 { m_minWidth=minWidth; }
262 virtual void SetWidth( int width );
263 virtual void SetSortable( bool sortable );
264 virtual void SetResizeable( bool resizeable );
265 virtual void SetHidden( bool hidden );
266 virtual void SetSortOrder( bool ascending );
267
268
269 // getters:
270
271 virtual wxString GetTitle() const
272 { return m_title; }
273 virtual wxAlignment GetAlignment() const
274 { return m_align; }
275 virtual int GetWidth() const
276 { return m_width; }
277 virtual int GetMinWidth() const
278 { return m_minWidth; }
279 virtual bool IsSortable() const
280 { return (m_flags & wxDATAVIEW_COL_SORTABLE) != 0; }
281 virtual bool IsResizeable() const
282 { return (m_flags & wxDATAVIEW_COL_RESIZABLE) != 0; }
283 virtual bool IsHidden() const
284 { return (m_flags & wxDATAVIEW_COL_HIDDEN) != 0; }
285 virtual bool IsSortOrderAscending() const;
286
287
288 private:
289 int m_width;
290 int m_minWidth;
291 int m_flags;
292 wxAlignment m_align;
293 wxString m_title;
294
295 void Init(int width);
296
297 // like SetWidth() but does not ask the header window of the
298 // wxDataViewCtrl to reflect the width-change.
299 void SetInternalWidth(int width);
300
301 protected:
302 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn)
303 };
304
305 // ---------------------------------------------------------
306 // wxDataViewCtrl
307 // ---------------------------------------------------------
308
309 class WXDLLIMPEXP_ADV wxDataViewCtrl: public wxDataViewCtrlBase,
310 public wxScrollHelperNative
311 {
312 friend class wxDataViewMainWindow;
313 friend class wxDataViewHeaderWindowBase;
314 friend class wxDataViewHeaderWindow;
315 friend class wxDataViewHeaderWindowMSW;
316 friend class wxDataViewColumn;
317
318 public:
319 wxDataViewCtrl() : wxScrollHelperNative(this)
320 {
321 Init();
322 }
323
324 wxDataViewCtrl( wxWindow *parent, wxWindowID id,
325 const wxPoint& pos = wxDefaultPosition,
326 const wxSize& size = wxDefaultSize, long style = 0,
327 const wxValidator& validator = wxDefaultValidator )
328 : wxScrollHelperNative(this)
329 {
330 Create(parent, id, pos, size, style, validator );
331 }
332
333 virtual ~wxDataViewCtrl();
334
335 void Init();
336
337 bool Create(wxWindow *parent, wxWindowID id,
338 const wxPoint& pos = wxDefaultPosition,
339 const wxSize& size = wxDefaultSize, long style = 0,
340 const wxValidator& validator = wxDefaultValidator );
341
342 virtual bool AssociateModel( wxDataViewListModel *model );
343 virtual bool AppendColumn( wxDataViewColumn *col );
344
345 virtual void SetSelection( int row ); // -1 for unselect
346 virtual void SetSelectionRange( unsigned int from, unsigned int to );
347 virtual void SetSelections( const wxArrayInt& aSelections);
348 virtual void Unselect( unsigned int row );
349
350 virtual bool IsSelected( unsigned int row ) const;
351 virtual int GetSelection() const;
352 virtual int GetSelections(wxArrayInt& aSelections) const;
353
354 public: // utility functions not part of the API
355
356 // returns the "best" width for the idx-th column
357 unsigned int GetBestColumnWidth(int WXUNUSED(idx)) const
358 {
359 return GetClientSize().GetWidth() / GetColumnCount();
360 }
361
362 // updates the header window after a change in a column setting
363 void OnColumnChange();
364
365 private:
366 wxDataViewListModelNotifier *m_notifier;
367 wxDataViewMainWindow *m_clientArea;
368 wxDataViewHeaderWindow *m_headerArea;
369
370 private:
371 void OnSize( wxSizeEvent &event );
372
373 // we need to return a special WM_GETDLGCODE value to process just the
374 // arrows but let the other navigation characters through
375 #ifdef __WXMSW__
376 virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
377 #endif // __WXMSW__
378
379 WX_FORWARD_TO_SCROLL_HELPER()
380
381 private:
382 DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
383 DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
384 DECLARE_EVENT_TABLE()
385 };
386
387
388 #endif // __GENERICDATAVIEWCTRLH__