]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dataview.h
42da39cab3115f5ff8f9b520a0f50a2b75838d08
[wxWidgets.git] / include / wx / dataview.h
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
24 // ----------------------------------------------------------------------------
25 // wxDataViewCtrl flags
26 // ----------------------------------------------------------------------------
27
28 // ----------------------------------------------------------------------------
29 // wxDataViewCtrl globals
30 // ----------------------------------------------------------------------------
31
32 class WXDLLIMPEXP_CORE wxDataViewCtrl;
33 class WXDLLIMPEXP_CORE wxDataViewColumn;
34 class WXDLLIMPEXP_CORE wxDataViewCell;
35
36 extern WXDLLEXPORT_DATA(const wxChar) wxDataViewCtrlNameStr[];
37
38 // ---------------------------------------------------------
39 // wxDataViewModel
40 // ---------------------------------------------------------
41
42 class wxDataViewModel: public wxObject
43 {
44 public:
45 wxDataViewModel() { }
46 virtual ~wxDataViewModel() { }
47
48 protected:
49 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewModel)
50 };
51
52 // ---------------------------------------------------------
53 // wxDataViewListModelNotifier
54 // ---------------------------------------------------------
55
56 class wxDataViewListModelNotifier
57 {
58 public:
59 wxDataViewListModelNotifier() { }
60 virtual ~wxDataViewListModelNotifier() { }
61
62 virtual bool RowAppended() = 0;
63 virtual bool RowPrepended() = 0;
64 virtual bool RowInserted( size_t before ) = 0;
65 virtual bool RowDeleted( size_t row ) = 0;
66 virtual bool RowChanged( size_t row ) = 0;
67 virtual bool ValueChanged( size_t row, size_t col ) = 0;
68 virtual bool Cleared() = 0;
69 };
70
71 // ---------------------------------------------------------
72 // wxDataViewListModel
73 // ---------------------------------------------------------
74
75 class wxDataViewListModel: public wxDataViewModel
76 {
77 public:
78 wxDataViewListModel();
79 virtual ~wxDataViewListModel();
80
81 virtual size_t GetNumberOfRows() = 0;
82 virtual size_t GetNumberOfCols() = 0;
83 // as reported by wxVariant
84 virtual wxString GetColType( size_t col ) = 0;
85 virtual wxVariant GetValue( size_t col, size_t row ) = 0;
86
87 // delegated notifiers
88 bool RowAppended();
89 bool RowPrepended();
90 bool RowInserted( size_t before );
91 bool RowDeleted( size_t row );
92 bool RowChanged( size_t row );
93 bool ValueChanged( size_t row, size_t col );
94 bool Cleared();
95
96 void SetNotifier( wxDataViewListModelNotifier *notifier );
97 wxDataViewListModelNotifier* GetNotifier();
98
99 private:
100 wxDataViewListModelNotifier *m_notifier;
101
102 protected:
103 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel)
104 };
105
106 // ---------------------------------------------------------
107 // wxDataViewCellBase
108 // ---------------------------------------------------------
109
110 enum wxDataViewCellMode
111 {
112 wxDATAVIEW_CELL_INERT,
113 wxDATAVIEW_CELL_ACTIVATABLE,
114 wxDATAVIEW_CELL_EDITABLE
115 };
116
117 enum wxDataViewCellRenderState
118 {
119 wxDATAVIEW_CELL_SELECTED = 1,
120 wxDATAVIEW_CELL_PRELIT = 2,
121 wxDATAVIEW_CELL_INSENSITIVE = 4,
122 wxDATAVIEW_CELL_FOCUSED = 8
123 };
124
125 class wxDataViewCellBase: public wxObject
126 {
127 public:
128 wxDataViewCellBase( const wxString &varianttype, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
129
130 virtual bool SetValue( const wxVariant &value ) { return true; }
131 virtual bool GetValue( wxVariant &value ) { return true; }
132 virtual bool BeginEdit() { return true; }
133 virtual bool EndEdit() { return true; }
134
135 virtual bool Render( wxRect cell, wxRect exposed, wxDC *dc, int state ) { return true; }
136
137 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
138 wxDataViewColumn* GetOwner() { return m_owner; }
139
140 wxString GetVariantType() { return m_variantType; }
141
142 private:
143 wxDataViewCellMode m_mode;
144 wxString m_variantType;
145 wxDataViewColumn *m_owner;
146
147 protected:
148 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCellBase)
149 };
150
151 // ---------------------------------------------------------
152 // wxDataViewColumnBase
153 // ---------------------------------------------------------
154
155 enum wxDataViewColumnFlags
156 {
157 wxDATAVIEW_COL_RESIZABLE = 1,
158 wxDATAVIEW_COL_SORTABLE = 2,
159 wxDATAVIEW_COL_HIDDEN = 4
160 };
161
162 class wxDataViewColumnBase: public wxObject
163 {
164 public:
165 wxDataViewColumnBase( const wxString &title, wxDataViewCell *cell, size_t model_column, int flags = 0 );
166 ~wxDataViewColumnBase();
167
168 virtual void SetTitle( const wxString &title );
169 virtual wxString GetTitle();
170
171 wxDataViewCell* GetCell() { return m_cell; }
172
173 size_t GetModelColumn() { return m_model_column; }
174
175 void SetOwner( wxDataViewCtrl *owner ) { m_owner = owner; }
176 wxDataViewCtrl *GetOwner() { return m_owner; }
177
178 private:
179 wxDataViewCtrl *m_ctrl;
180 wxDataViewCell *m_cell;
181 int m_model_column;
182 int m_flags;
183 wxString m_title;
184 wxDataViewCtrl *m_owner;
185
186 protected:
187 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
188 };
189
190 // ---------------------------------------------------------
191 // wxDataViewCtrlBase
192 // ---------------------------------------------------------
193
194 class wxDataViewCtrlBase: public wxControl
195 {
196 public:
197 wxDataViewCtrlBase();
198 ~wxDataViewCtrlBase();
199
200 virtual bool AssociateModel( wxDataViewListModel *model );
201 wxDataViewListModel* GetModel();
202
203 virtual bool AppendStringColumn( const wxString &label, size_t model_column );
204 virtual bool AppendColumn( wxDataViewColumn *col );
205 virtual size_t GetNumberOfColumns();
206 virtual bool DeleteColumn( size_t pos );
207 virtual bool ClearColumns();
208 virtual wxDataViewColumn* GetColumn( size_t pos );
209
210 private:
211 wxDataViewListModel *m_model;
212 wxList m_cols;
213
214 protected:
215 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
216 };
217
218 #if defined(__WXGTK20__)
219 #include "wx/gtk/dataview.h"
220 #elif defined(__WXMAC__)
221 #include "wx/mac/dataview.h"
222 #else
223 #include "wx/generic/dataview.h"
224 #endif
225
226 #endif // wxUSE_DATAVIEWCTRL
227
228 #endif
229 // _WX_DATAVIEW_H_BASE_