]> git.saurik.com Git - wxWidgets.git/blob - src/common/datavcmn.cpp
7dfb742a165e82adb2482f04ba787d77220a49a6
[wxWidgets.git] / src / common / datavcmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/datavcmn.cpp
3 // Purpose: wxDataViewCtrl base classes and common parts
4 // Author: Robert Roebling
5 // Created: 2006/02/20
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006, Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #include "wx/object.h"
19 #include "wx/dataview.h"
20 #include "wx/log.h"
21 #include "wx/image.h"
22
23 // ---------------------------------------------------------
24 // wxDataViewModel
25 // ---------------------------------------------------------
26
27 IMPLEMENT_ABSTRACT_CLASS(wxDataViewModel, wxObject)
28
29 // ---------------------------------------------------------
30 // wxDataViewListModel
31 // ---------------------------------------------------------
32
33 IMPLEMENT_ABSTRACT_CLASS(wxDataViewListModel, wxDataViewModel)
34
35 wxDataViewListModel::wxDataViewListModel()
36 {
37 m_notifier = NULL;
38 }
39
40 wxDataViewListModel::~wxDataViewListModel()
41 {
42 if (m_notifier)
43 delete m_notifier;
44 }
45
46 bool wxDataViewListModel::RowAppended()
47 {
48 if (m_notifier)
49 return m_notifier->RowAppended();
50
51 return false;
52 }
53
54 bool wxDataViewListModel::RowPrepended()
55 {
56 if (m_notifier)
57 return m_notifier->RowPrepended();
58
59 return false;
60 }
61
62 bool wxDataViewListModel::RowInserted( size_t before )
63 {
64 if (m_notifier)
65 return m_notifier->RowInserted( before );
66
67 return false;
68 }
69
70 bool wxDataViewListModel::RowDeleted( size_t row )
71 {
72 if (m_notifier)
73 return m_notifier->RowDeleted( row );
74
75 return false;
76 }
77
78 bool wxDataViewListModel::RowChanged( size_t row )
79 {
80 if (m_notifier)
81 return m_notifier->RowChanged( row );
82
83 return false;
84 }
85
86 bool wxDataViewListModel::ValueChanged( size_t col, size_t row )
87 {
88 if (m_notifier)
89 return m_notifier->ValueChanged( col, row );
90
91 return false;
92 }
93
94 bool wxDataViewListModel::Cleared()
95 {
96 if (m_notifier)
97 return m_notifier->Cleared();
98
99 return false;
100 }
101
102 void wxDataViewListModel::SetNotifier( wxDataViewListModelNotifier *notifier )
103 {
104 if (m_notifier)
105 delete m_notifier;
106
107 m_notifier = notifier;
108 }
109
110 wxDataViewListModelNotifier* wxDataViewListModel::GetNotifier()
111 {
112 return m_notifier;
113 }
114
115 // ---------------------------------------------------------
116 // wxDataViewCellBase
117 // ---------------------------------------------------------
118
119 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCellBase, wxObject)
120
121 wxDataViewCellBase::wxDataViewCellBase( const wxString &varianttype, wxDataViewCellMode mode )
122 {
123 m_variantType = varianttype;
124 m_mode = mode;
125 }
126
127 // ---------------------------------------------------------
128 // wxDataViewColumnBase
129 // ---------------------------------------------------------
130
131 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
132
133 wxDataViewColumnBase::wxDataViewColumnBase( const wxString &title, wxDataViewCell *cell, size_t model_column, int flags)
134 {
135 m_cell = cell;
136 m_model_column = model_column;
137 m_flags = flags;
138 m_title = title;
139 m_owner = NULL;
140 m_cell->SetOwner( (wxDataViewColumn*) this );
141 }
142
143 wxDataViewColumnBase::~wxDataViewColumnBase()
144 {
145 if (m_cell)
146 delete m_cell;
147 }
148
149 void wxDataViewColumnBase::SetTitle( const wxString &title )
150 {
151 m_title = title;
152 }
153
154 wxString wxDataViewColumnBase::GetTitle()
155 {
156 return m_title;
157 }
158
159 // ---------------------------------------------------------
160 // wxDataViewCtrlBase
161 // ---------------------------------------------------------
162
163 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
164
165 wxDataViewCtrlBase::wxDataViewCtrlBase()
166 {
167 m_model = NULL;
168 m_cols.DeleteContents( true );
169 }
170
171 wxDataViewCtrlBase::~wxDataViewCtrlBase()
172 {
173 if (m_model)
174 delete m_model;
175 }
176
177 bool wxDataViewCtrlBase::AssociateModel( wxDataViewListModel *model )
178 {
179 if (m_model)
180 delete m_model;
181
182 m_model = model;
183
184 return true;
185 }
186
187 wxDataViewListModel* wxDataViewCtrlBase::GetModel()
188 {
189 return m_model;
190 }
191
192 bool wxDataViewCtrlBase::AppendTextColumn( const wxString &label, size_t model_column )
193 {
194 return AppendColumn( new wxDataViewColumn( label, new wxDataViewTextCell(), model_column ) );
195 }
196
197 bool wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, size_t model_column )
198 {
199 return AppendColumn( new wxDataViewColumn( label, new wxDataViewToggleCell(), model_column ) );
200 }
201
202 bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
203 {
204 m_cols.Append( (wxObject*) col );
205 col->SetOwner( (wxDataViewCtrl*) this );
206 return true;
207 }
208
209 size_t wxDataViewCtrlBase::GetNumberOfColumns()
210 {
211 return m_cols.GetCount();
212 }
213
214 bool wxDataViewCtrlBase::DeleteColumn( size_t pos )
215 {
216 return false;
217 }
218
219 bool wxDataViewCtrlBase::ClearColumns()
220 {
221 return false;
222 }
223
224 wxDataViewColumn* wxDataViewCtrlBase::GetColumn( size_t pos )
225 {
226 return (wxDataViewColumn*) m_cols[ pos ];
227 }
228