]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/dataview.h
fix Watcom compilation: removed templates for wxFileSelector() compatibility with...
[wxWidgets.git] / include / wx / dataview.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/dataview.h
3// Purpose: wxDataViewCtrl base classes
4// Author: Robert Roebling
5// Modified by:
6// Created: 08.01.06
7// RCS-ID: $Id$
8// Copyright: (c) Robert Roebling
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_DATAVIEW_H_BASE_
13#define _WX_DATAVIEW_H_BASE_
14
15#include "wx/defs.h"
16
17#if wxUSE_DATAVIEWCTRL
18
19#include "wx/control.h"
20#include "wx/textctrl.h"
21#include "wx/bitmap.h"
22#include "wx/variant.h"
23#include "wx/listctrl.h"
24
25#if defined(__WXGTK20__)
26 // for testing
27 // #define wxUSE_GENERICDATAVIEWCTRL 1
28#elif defined(__WXMAC__)
29#else
30 #define wxUSE_GENERICDATAVIEWCTRL 1
31#endif
32
33// ----------------------------------------------------------------------------
34// wxDataViewCtrl flags
35// ----------------------------------------------------------------------------
36
37// ----------------------------------------------------------------------------
38// wxDataViewCtrl globals
39// ----------------------------------------------------------------------------
40
41class WXDLLIMPEXP_ADV wxDataViewItem;
42class WXDLLIMPEXP_ADV wxDataViewModel;
43class WXDLLIMPEXP_ADV wxDataViewCtrl;
44class WXDLLIMPEXP_ADV wxDataViewColumn;
45class WXDLLIMPEXP_ADV wxDataViewRenderer;
46class WXDLLIMPEXP_ADV wxDataViewModelNotifier;
47class wxDataViewEventModelNotifier;
48
49extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[];
50
51// the default width of new (text) columns:
52#define wxDVC_DEFAULT_WIDTH 80
53
54// the default width of new toggle columns:
55#define wxDVC_TOGGLE_DEFAULT_WIDTH 30
56
57// the default minimal width of the columns:
58#define wxDVC_DEFAULT_MINWIDTH 30
59
60// the default alignment of wxDataViewRenderers:
61#define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_TOP)
62
63
64// ---------------------------------------------------------
65// wxDataViewItem
66// ---------------------------------------------------------
67
68class WXDLLIMPEXP_ADV wxDataViewItem
69{
70public:
71 wxDataViewItem( wxUint32 id = 0 )
72 { m_id = id; m_reserved1 = 0; m_reserved2 = NULL; }
73 wxDataViewItem( const wxDataViewItem &item )
74 { m_id = item.m_id; m_reserved1 = item.m_reserved1; m_reserved2 = item.m_reserved2; }
75 bool IsOk() const { return m_id != 0; }
76 wxUint32 GetID() const { return m_id; }
77
78public:
79 wxUint32 m_reserved1;
80 void* m_reserved2;
81
82private:
83 wxUint32 m_id;
84};
85
86// ---------------------------------------------------------
87// wxDataViewModel
88// ---------------------------------------------------------
89
90class WXDLLIMPEXP_ADV wxDataViewModel: public wxObjectRefData
91{
92public:
93 wxDataViewModel();
94
95 virtual unsigned int GetColumnCount() const = 0;
96
97 // return type as reported by wxVariant
98 virtual wxString GetColumnType( unsigned int col ) const = 0;
99
100 // get value into a wxVariant
101 virtual void GetValue( wxVariant &variant,
102 const wxDataViewItem &item, unsigned int col ) const = 0;
103
104 // set value, call ValueChanged() afterwards!
105 virtual bool SetValue( const wxVariant &variant,
106 const wxDataViewItem &item, unsigned int col ) = 0;
107
108 // define hierachy
109 virtual bool HasChildren( const wxDataViewItem &item ) const = 0;
110 virtual int GetChildCount( const wxDataViewItem &item ) const = 0;
111 virtual wxDataViewItem GetParent( const wxDataViewItem &child ) const = 0;
112 virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const = 0;
113 virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const = 0;
114 virtual wxDataViewItem GetNthChild( const wxDataViewItem &parent, unsigned int n ) const = 0;
115
116 // delegated notifiers
117 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item );
118 virtual bool ItemDeleted( const wxDataViewItem &item );
119 virtual bool ItemChanged( const wxDataViewItem &item );
120 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col );
121 virtual bool Cleared();
122
123 void AddNotifier( wxDataViewModelNotifier *notifier );
124 void RemoveNotifier( wxDataViewModelNotifier *notifier );
125
126protected:
127 // the user should not delete this class directly: he should use DecRef() instead!
128 virtual ~wxDataViewModel() { }
129
130 wxList m_notifiers;
131};
132
133// ---------------------------------------------------------
134// wxDataViewModelNotifier
135// ---------------------------------------------------------
136
137class WXDLLIMPEXP_ADV wxDataViewModelNotifier: public wxObject
138{
139public:
140 wxDataViewModelNotifier() { }
141 virtual ~wxDataViewModelNotifier() { m_owner = NULL; }
142
143 virtual bool ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item ) = 0;
144 virtual bool ItemDeleted( const wxDataViewItem &item ) = 0;
145 virtual bool ItemChanged( const wxDataViewItem &item ) = 0;
146 virtual bool ValueChanged( const wxDataViewItem &item, unsigned int col ) = 0;
147 virtual bool Cleared() = 0;
148
149 void SetOwner( wxDataViewModel *owner ) { m_owner = owner; }
150 wxDataViewModel *GetOwner() { return m_owner; }
151
152private:
153 wxDataViewModel *m_owner;
154};
155
156
157//-----------------------------------------------------------------------------
158// wxDataViewEditorCtrlEvtHandler
159//-----------------------------------------------------------------------------
160
161class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
162{
163public:
164 wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
165
166 void AcceptChangesAndFinish();
167 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
168
169protected:
170 void OnChar( wxKeyEvent &event );
171 void OnKillFocus( wxFocusEvent &event );
172 void OnIdle( wxIdleEvent &event );
173
174private:
175 wxDataViewRenderer *m_owner;
176 wxControl *m_editorCtrl;
177 bool m_finished;
178 bool m_focusOnIdle;
179
180private:
181 DECLARE_EVENT_TABLE()
182};
183
184// ---------------------------------------------------------
185// wxDataViewRendererBase
186// ---------------------------------------------------------
187
188enum wxDataViewCellMode
189{
190 wxDATAVIEW_CELL_INERT,
191 wxDATAVIEW_CELL_ACTIVATABLE,
192 wxDATAVIEW_CELL_EDITABLE
193};
194
195enum wxDataViewCellRenderState
196{
197 wxDATAVIEW_CELL_SELECTED = 1,
198 wxDATAVIEW_CELL_PRELIT = 2,
199 wxDATAVIEW_CELL_INSENSITIVE = 4,
200 wxDATAVIEW_CELL_FOCUSED = 8
201};
202
203class WXDLLIMPEXP_ADV wxDataViewRendererBase: public wxObject
204{
205public:
206 wxDataViewRendererBase( const wxString &varianttype,
207 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT,
208 int alignment = wxDVR_DEFAULT_ALIGNMENT );
209
210 virtual bool Validate( wxVariant& WXUNUSED(value) )
211 { return true; }
212
213 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
214 wxDataViewColumn* GetOwner() { return m_owner; }
215
216 // renderer properties:
217
218 virtual bool SetValue( const wxVariant& WXUNUSED(value) ) = 0;
219 virtual bool GetValue( wxVariant& WXUNUSED(value) ) const = 0;
220
221 wxString GetVariantType() const { return m_variantType; }
222
223 virtual void SetMode( wxDataViewCellMode mode ) = 0;
224 virtual wxDataViewCellMode GetMode() const = 0;
225
226 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
227 // rather an "int"; that's because for rendering cells it's allowed
228 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
229 virtual void SetAlignment( int align ) = 0;
230 virtual int GetAlignment() const = 0;
231
232 // in-place editing
233 virtual bool HasEditorCtrl()
234 { return false; }
235 virtual wxControl* CreateEditorCtrl(wxWindow * WXUNUSED(parent),
236 wxRect WXUNUSED(labelRect),
237 const wxVariant& WXUNUSED(value))
238 { return NULL; }
239 virtual bool GetValueFromEditorCtrl(wxControl * WXUNUSED(editor),
240 wxVariant& WXUNUSED(value))
241 { return false; }
242
243 virtual bool StartEditing( const wxDataViewItem &item, wxRect labelRect );
244 virtual void CancelEditing();
245 virtual bool FinishEditing();
246
247 wxControl *GetEditorCtrl() { return m_editorCtrl; }
248
249protected:
250 wxString m_variantType;
251 wxDataViewColumn *m_owner;
252 wxControl *m_editorCtrl;
253 wxDataViewItem m_item; // for m_editorCtrl
254
255 // internal utility:
256 const wxDataViewCtrl* GetView() const;
257
258protected:
259 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase)
260};
261
262// ---------------------------------------------------------
263// wxDataViewColumnBase
264// ---------------------------------------------------------
265
266enum wxDataViewColumnFlags
267{
268 wxDATAVIEW_COL_RESIZABLE = 1,
269 wxDATAVIEW_COL_SORTABLE = 2,
270 wxDATAVIEW_COL_HIDDEN = 4
271};
272
273class WXDLLIMPEXP_ADV wxDataViewColumnBase: public wxObject
274{
275public:
276 wxDataViewColumnBase( const wxString &title, wxDataViewRenderer *renderer,
277 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
278 wxAlignment align = wxALIGN_CENTER,
279 int flags = wxDATAVIEW_COL_RESIZABLE );
280 wxDataViewColumnBase( const wxBitmap &bitmap, wxDataViewRenderer *renderer,
281 unsigned int model_column, int width = wxDVC_DEFAULT_WIDTH,
282 wxAlignment align = wxALIGN_CENTER,
283 int flags = wxDATAVIEW_COL_RESIZABLE );
284 virtual ~wxDataViewColumnBase();
285
286 // setters:
287
288 virtual void SetTitle( const wxString &title ) = 0;
289 virtual void SetAlignment( wxAlignment align ) = 0;
290 virtual void SetSortable( bool sortable ) = 0;
291 virtual void SetResizeable( bool resizeable ) = 0;
292 virtual void SetHidden( bool hidden ) = 0;
293 virtual void SetSortOrder( bool ascending ) = 0;
294 virtual void SetFlags( int flags );
295 virtual void SetOwner( wxDataViewCtrl *owner )
296 { m_owner = owner; }
297 virtual void SetBitmap( const wxBitmap &bitmap )
298 { m_bitmap=bitmap; }
299
300 virtual void SetMinWidth( int minWidth ) = 0;
301 virtual void SetWidth( int width ) = 0;
302
303
304 // getters:
305
306 virtual wxString GetTitle() const = 0;
307 virtual wxAlignment GetAlignment() const = 0;
308 virtual int GetWidth() const = 0;
309 virtual int GetMinWidth() const = 0;
310
311 virtual int GetFlags() const;
312
313 virtual bool IsSortable() const = 0;
314 virtual bool IsResizeable() const = 0;
315 virtual bool IsHidden() const = 0;
316 virtual bool IsSortOrderAscending() const = 0;
317
318 const wxBitmap &GetBitmap() const { return m_bitmap; }
319 unsigned int GetModelColumn() const { return m_model_column; }
320
321 wxDataViewCtrl *GetOwner() { return m_owner; }
322 wxDataViewRenderer* GetRenderer() { return m_renderer; }
323
324protected:
325 wxDataViewRenderer *m_renderer;
326 int m_model_column;
327 wxBitmap m_bitmap;
328 wxDataViewCtrl *m_owner;
329
330protected:
331 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
332};
333
334// ---------------------------------------------------------
335// wxDataViewCtrlBase
336// ---------------------------------------------------------
337
338#define wxDV_SINGLE 0x0000 // for convenience
339#define wxDV_MULTIPLE 0x0001 // can select multiple items
340
341#define wxDV_NO_HEADER 0x0002 // column titles not visible
342#define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
343#define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
344
345class WXDLLIMPEXP_ADV wxDataViewCtrlBase: public wxControl
346{
347public:
348 wxDataViewCtrlBase();
349 virtual ~wxDataViewCtrlBase();
350
351 virtual bool AssociateModel( wxDataViewModel *model );
352 wxDataViewModel* GetModel();
353
354 // short cuts
355 bool AppendTextColumn( const wxString &label, unsigned int model_column,
356 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
357 wxAlignment align = wxALIGN_CENTER,
358 int flags = wxDATAVIEW_COL_RESIZABLE );
359 bool AppendToggleColumn( const wxString &label, unsigned int model_column,
360 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
361 wxAlignment align = wxALIGN_CENTER,
362 int flags = wxDATAVIEW_COL_RESIZABLE );
363 bool AppendProgressColumn( const wxString &label, unsigned int model_column,
364 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
365 wxAlignment align = wxALIGN_CENTER,
366 int flags = wxDATAVIEW_COL_RESIZABLE );
367 bool AppendDateColumn( const wxString &label, unsigned int model_column,
368 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
369 wxAlignment align = wxALIGN_CENTER,
370 int flags = wxDATAVIEW_COL_RESIZABLE );
371 bool AppendBitmapColumn( const wxString &label, unsigned int model_column,
372 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
373 wxAlignment align = wxALIGN_CENTER,
374 int flags = wxDATAVIEW_COL_RESIZABLE );
375 bool AppendTextColumn( const wxBitmap &label, unsigned int model_column,
376 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
377 wxAlignment align = wxALIGN_CENTER,
378 int flags = wxDATAVIEW_COL_RESIZABLE );
379 bool AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
380 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH,
381 wxAlignment align = wxALIGN_CENTER,
382 int flags = wxDATAVIEW_COL_RESIZABLE );
383 bool AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
384 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH,
385 wxAlignment align = wxALIGN_CENTER,
386 int flags = wxDATAVIEW_COL_RESIZABLE );
387 bool AppendDateColumn( const wxBitmap &label, unsigned int model_column,
388 wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1,
389 wxAlignment align = wxALIGN_CENTER,
390 int flags = wxDATAVIEW_COL_RESIZABLE );
391 bool AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
392 wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1,
393 wxAlignment align = wxALIGN_CENTER,
394 int flags = wxDATAVIEW_COL_RESIZABLE );
395
396 virtual bool AppendColumn( wxDataViewColumn *col );
397
398 virtual unsigned int GetColumnCount() const;
399
400 virtual bool DeleteColumn( unsigned int pos );
401 virtual bool ClearColumns();
402 virtual wxDataViewColumn* GetColumn( unsigned int pos );
403
404 // TODO selection code
405
406private:
407 wxDataViewModel *m_model;
408 wxList m_cols;
409 wxDataViewEventModelNotifier *m_eventNotifier;
410
411protected:
412 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
413};
414
415// ----------------------------------------------------------------------------
416// wxDataViewEvent - the event class for the wxDataViewCtrl notifications
417// ----------------------------------------------------------------------------
418
419class WXDLLIMPEXP_ADV wxDataViewEvent : public wxNotifyEvent
420{
421public:
422 wxDataViewEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
423 : wxNotifyEvent(commandType, winid),
424 m_item(0),
425 m_col(-1),
426 m_model(NULL),
427 m_value(wxNullVariant),
428 m_column(NULL)
429 { }
430
431 wxDataViewEvent(const wxDataViewEvent& event)
432 : wxNotifyEvent(event),
433 m_item(event.m_item),
434 m_col(event.m_col),
435 m_model(event.m_model),
436 m_value(event.m_value),
437 m_column(event.m_column)
438 { }
439
440 wxDataViewItem GetItem() const { return m_item; }
441 void SetItem( const wxDataViewItem &item ) { m_item = item; }
442
443 int GetColumn() const { return m_col; }
444 void SetColumn( int col ) { m_col = col; }
445
446 wxDataViewModel* GetModel() const { return m_model; }
447 void SetModel( wxDataViewModel *model ) { m_model = model; }
448
449 const wxVariant &GetValue() const { return m_value; }
450 void SetValue( const wxVariant &value ) { m_value = value; }
451
452 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
453 void SetDataViewColumn( wxDataViewColumn *col ) { m_column = col; }
454 wxDataViewColumn *GetDataViewColumn() const { return m_column; }
455
456 virtual wxEvent *Clone() const { return new wxDataViewEvent(*this); }
457
458protected:
459 wxDataViewItem m_item;
460 int m_col;
461 wxDataViewModel *m_model;
462 wxVariant m_value;
463 wxDataViewColumn *m_column;
464
465private:
466 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent)
467};
468
469BEGIN_DECLARE_EVENT_TYPES()
470 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED, -1)
471 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, -1)
472 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, -1)
473 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, -1)
474 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, -1)
475 // notifications from the model to the control
476 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED, -1)
477 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED, -1)
478 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED, -1)
479 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED, -1)
480 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV, wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED, -1)
481END_DECLARE_EVENT_TYPES()
482
483typedef void (wxEvtHandler::*wxDataViewEventFunction)(wxDataViewEvent&);
484
485#define wxDataViewEventHandler(func) \
486 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
487
488#define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
489 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
490
491#define EVT_DATAVIEW_ITEM_SELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_SELECTED, id, fn)
492#define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
493#define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
494#define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
495#define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
496
497#define EVT_DATAVIEW_MODEL_ITEM_ADDED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_APPENDED, id, fn)
498#define EVT_DATAVIEW_MODEL_ITEM_DELETED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_DELETED, id, fn)
499#define EVT_DATAVIEW_MODEL_ITEM_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_ITEM_CHANGED, id, fn)
500#define EVT_DATAVIEW_MODEL_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_VALUE_CHANGED, id, fn)
501#define EVT_DATAVIEW_MODEL_CLEARED(id, fn) wx__DECLARE_DATAVIEWEVT(MODEL_CLEARED, id, fn)
502
503
504#if defined(wxUSE_GENERICDATAVIEWCTRL)
505 #include "wx/generic/dataview.h"
506#elif defined(__WXGTK20__)
507 #include "wx/gtk/dataview.h"
508#elif defined(__WXMAC__)
509 #include "wx/mac/dataview.h"
510#else
511 #include "wx/generic/dataview.h"
512#endif
513
514#endif // wxUSE_DATAVIEWCTRL
515
516#endif
517 // _WX_DATAVIEW_H_BASE_