]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: treectrl.cpp | |
3 | // Purpose: wxTreeCtrl. See also Robert's generic wxTreeCtrl. | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #include "wx/stubs/textctrl.h" | |
15 | #include "wx/treebase.h" | |
16 | #include "wx/stubs/treectrl.h" | |
17 | ||
18 | IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl) | |
19 | IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject) | |
20 | ||
21 | wxTreeCtrl::wxTreeCtrl() | |
22 | { | |
23 | m_imageListNormal = NULL; | |
24 | m_imageListState = NULL; | |
25 | m_textCtrl = NULL; | |
26 | } | |
27 | ||
28 | bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, | |
29 | long style, const wxValidator& validator, const wxString& name) | |
30 | { | |
31 | SetName(name); | |
32 | SetValidator(validator); | |
33 | ||
34 | m_imageListNormal = NULL; | |
35 | m_imageListState = NULL; | |
36 | m_textCtrl = NULL; | |
37 | ||
38 | m_windowStyle = style; | |
39 | ||
40 | SetParent(parent); | |
41 | ||
42 | m_windowId = (id == -1) ? NewControlId() : id; | |
43 | ||
44 | if (parent) parent->AddChild(this); | |
45 | ||
46 | // TODO create tree control | |
47 | ||
48 | return FALSE; | |
49 | } | |
50 | ||
51 | wxTreeCtrl::~wxTreeCtrl() | |
52 | { | |
53 | if (m_textCtrl) | |
54 | { | |
55 | delete m_textCtrl; | |
56 | } | |
57 | } | |
58 | ||
59 | // Attributes | |
60 | int wxTreeCtrl::GetCount() const | |
61 | { | |
62 | // TODO | |
63 | return 0; | |
64 | } | |
65 | ||
66 | int wxTreeCtrl::GetIndent() const | |
67 | { | |
68 | // TODO | |
69 | return 0; | |
70 | } | |
71 | ||
72 | void wxTreeCtrl::SetIndent(int indent) | |
73 | { | |
74 | // TODO | |
75 | } | |
76 | ||
77 | wxImageList *wxTreeCtrl::GetImageList(int which) const | |
78 | { | |
79 | if ( which == wxIMAGE_LIST_NORMAL ) | |
80 | { | |
81 | return m_imageListNormal; | |
82 | } | |
83 | else if ( which == wxIMAGE_LIST_STATE ) | |
84 | { | |
85 | return m_imageListState; | |
86 | } | |
87 | return NULL; | |
88 | } | |
89 | ||
90 | void wxTreeCtrl::SetImageList(wxImageList *imageList, int which) | |
91 | { | |
92 | if ( which == wxIMAGE_LIST_NORMAL ) | |
93 | { | |
94 | m_imageListNormal = imageList; | |
95 | } | |
96 | else if ( which == wxIMAGE_LIST_STATE ) | |
97 | { | |
98 | m_imageListState = imageList; | |
99 | } | |
100 | // TODO | |
101 | } | |
102 | ||
103 | long wxTreeCtrl::GetNextItem(long item, int code) const | |
104 | { | |
105 | // TODO | |
106 | return 0; | |
107 | } | |
108 | ||
109 | bool wxTreeCtrl::ItemHasChildren(long item) const | |
110 | { | |
111 | // TODO | |
112 | return FALSE; | |
113 | } | |
114 | ||
115 | long wxTreeCtrl::GetChild(long item) const | |
116 | { | |
117 | // TODO | |
118 | return 0; | |
119 | } | |
120 | ||
121 | long wxTreeCtrl::GetItemParent(long item) const | |
122 | { | |
123 | // TODO | |
124 | return 0; | |
125 | } | |
126 | ||
127 | long wxTreeCtrl::GetFirstVisibleItem() const | |
128 | { | |
129 | // TODO | |
130 | return 0; | |
131 | } | |
132 | ||
133 | long wxTreeCtrl::GetNextVisibleItem(long item) const | |
134 | { | |
135 | // TODO | |
136 | return 0; | |
137 | } | |
138 | ||
139 | long wxTreeCtrl::GetSelection() const | |
140 | { | |
141 | // TODO | |
142 | return 0; | |
143 | } | |
144 | ||
145 | long wxTreeCtrl::GetRootItem() const | |
146 | { | |
147 | // TODO | |
148 | return 0; | |
149 | } | |
150 | ||
151 | bool wxTreeCtrl::GetItem(wxTreeItem& info) const | |
152 | { | |
153 | // TODO | |
154 | return FALSE; | |
155 | } | |
156 | ||
157 | bool wxTreeCtrl::SetItem(wxTreeItem& info) | |
158 | { | |
159 | // TODO | |
160 | return FALSE; | |
161 | } | |
162 | ||
163 | int wxTreeCtrl::GetItemState(long item, long stateMask) const | |
164 | { | |
165 | wxTreeItem info; | |
166 | ||
167 | info.m_mask = wxTREE_MASK_STATE ; | |
168 | info.m_stateMask = stateMask; | |
169 | info.m_itemId = item; | |
170 | ||
171 | if (!GetItem(info)) | |
172 | return 0; | |
173 | ||
174 | return info.m_state; | |
175 | } | |
176 | ||
177 | bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) | |
178 | { | |
179 | wxTreeItem info; | |
180 | ||
181 | info.m_mask = wxTREE_MASK_STATE ; | |
182 | info.m_state = state; | |
183 | info.m_stateMask = stateMask; | |
184 | info.m_itemId = item; | |
185 | ||
186 | return SetItem(info); | |
187 | } | |
188 | ||
189 | bool wxTreeCtrl::SetItemImage(long item, int image, int selImage) | |
190 | { | |
191 | wxTreeItem info; | |
192 | ||
193 | info.m_mask = wxTREE_MASK_IMAGE ; | |
194 | info.m_image = image; | |
195 | if ( selImage > -1) | |
196 | { | |
197 | info.m_selectedImage = selImage; | |
198 | info.m_mask |= wxTREE_MASK_SELECTED_IMAGE; | |
199 | } | |
200 | info.m_itemId = item; | |
201 | ||
202 | return SetItem(info); | |
203 | } | |
204 | ||
205 | wxString wxTreeCtrl::GetItemText(long item) const | |
206 | { | |
207 | wxTreeItem info; | |
208 | ||
209 | info.m_mask = wxTREE_MASK_TEXT ; | |
210 | info.m_itemId = item; | |
211 | ||
212 | if (!GetItem(info)) | |
213 | return wxString(""); | |
214 | return info.m_text; | |
215 | } | |
216 | ||
217 | void wxTreeCtrl::SetItemText(long item, const wxString& str) | |
218 | { | |
219 | wxTreeItem info; | |
220 | ||
221 | info.m_mask = wxTREE_MASK_TEXT ; | |
222 | info.m_itemId = item; | |
223 | info.m_text = str; | |
224 | ||
225 | SetItem(info); | |
226 | } | |
227 | ||
228 | long wxTreeCtrl::GetItemData(long item) const | |
229 | { | |
230 | wxTreeItem info; | |
231 | ||
232 | info.m_mask = wxTREE_MASK_DATA ; | |
233 | info.m_itemId = item; | |
234 | ||
235 | if (!GetItem(info)) | |
236 | return 0; | |
237 | return info.m_data; | |
238 | } | |
239 | ||
240 | bool wxTreeCtrl::SetItemData(long item, long data) | |
241 | { | |
242 | wxTreeItem info; | |
243 | ||
244 | info.m_mask = wxTREE_MASK_DATA ; | |
245 | info.m_itemId = item; | |
246 | info.m_data = data; | |
247 | ||
248 | return SetItem(info); | |
249 | } | |
250 | ||
251 | bool wxTreeCtrl::GetItemRect(long item, wxRect& rect, bool textOnly) const | |
252 | { | |
253 | // TODO | |
254 | return FALSE; | |
255 | } | |
256 | ||
257 | wxTextCtrl* wxTreeCtrl::GetEditControl() const | |
258 | { | |
259 | return m_textCtrl; | |
260 | } | |
261 | ||
262 | // Operations | |
263 | bool wxTreeCtrl::DeleteItem(long item) | |
264 | { | |
265 | // TODO | |
266 | return FALSE; | |
267 | } | |
268 | ||
269 | bool wxTreeCtrl::ExpandItem(long item, int action) | |
270 | { | |
271 | // TODO | |
272 | switch ( action ) | |
273 | { | |
274 | case wxTREE_EXPAND_EXPAND: | |
275 | break; | |
276 | ||
277 | case wxTREE_EXPAND_COLLAPSE: | |
278 | break; | |
279 | ||
280 | case wxTREE_EXPAND_COLLAPSE_RESET: | |
281 | break; | |
282 | ||
283 | case wxTREE_EXPAND_TOGGLE: | |
284 | break; | |
285 | ||
286 | default: | |
287 | wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem"); | |
288 | } | |
289 | ||
290 | bool bOk = FALSE; // TODO expand item | |
291 | ||
292 | // May not send messages, so emulate them | |
293 | if ( bOk ) { | |
294 | wxTreeEvent event(wxEVT_NULL, m_windowId); | |
295 | event.m_item.m_itemId = item; | |
296 | event.m_item.m_mask = | |
297 | event.m_item.m_stateMask = 0xffff; // get all | |
298 | GetItem(event.m_item); | |
299 | ||
300 | bool bIsExpanded = (event.m_item.m_state & wxTREE_STATE_EXPANDED) != 0; | |
301 | ||
302 | event.m_code = action; | |
303 | event.SetEventObject(this); | |
304 | ||
305 | // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded | |
306 | event.SetEventType(bIsExpanded ? wxEVT_COMMAND_TREE_ITEM_EXPANDING | |
307 | : wxEVT_COMMAND_TREE_ITEM_COLLAPSING); | |
308 | GetEventHandler()->ProcessEvent(event); | |
309 | ||
310 | event.SetEventType(bIsExpanded ? wxEVT_COMMAND_TREE_ITEM_EXPANDED | |
311 | : wxEVT_COMMAND_TREE_ITEM_COLLAPSED); | |
312 | GetEventHandler()->ProcessEvent(event); | |
313 | } | |
314 | ||
315 | return bOk; | |
316 | } | |
317 | ||
318 | long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) | |
319 | { | |
320 | // TODO | |
321 | return 0; | |
322 | } | |
323 | ||
324 | long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image, int selImage, | |
325 | long insertAfter) | |
326 | { | |
327 | wxTreeItem info; | |
328 | info.m_text = label; | |
329 | info.m_mask = wxTREE_MASK_TEXT; | |
330 | if ( image > -1 ) | |
331 | { | |
332 | info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE; | |
333 | info.m_image = image; | |
334 | if ( selImage == -1 ) | |
335 | info.m_selectedImage = image; | |
336 | else | |
337 | info.m_selectedImage = selImage; | |
338 | } | |
339 | ||
340 | return InsertItem(parent, info, insertAfter); | |
341 | } | |
342 | ||
343 | bool wxTreeCtrl::SelectItem(long item) | |
344 | { | |
345 | // TODO | |
346 | return FALSE; | |
347 | } | |
348 | ||
349 | bool wxTreeCtrl::ScrollTo(long item) | |
350 | { | |
351 | // TODO | |
352 | return FALSE; | |
353 | } | |
354 | ||
355 | bool wxTreeCtrl::DeleteAllItems() | |
356 | { | |
357 | // TODO | |
358 | return FALSE; | |
359 | } | |
360 | ||
361 | wxTextCtrl* wxTreeCtrl::EditLabel(long item, wxClassInfo* textControlClass) | |
362 | { | |
363 | // TODO | |
364 | return NULL; | |
365 | } | |
366 | ||
367 | // End label editing, optionally cancelling the edit | |
368 | bool wxTreeCtrl::EndEditLabel(bool cancel) | |
369 | { | |
370 | // TODO | |
371 | return FALSE; | |
372 | } | |
373 | ||
374 | long wxTreeCtrl::HitTest(const wxPoint& point, int& flags) | |
375 | { | |
376 | // TODO | |
377 | return 0; | |
378 | } | |
379 | ||
380 | bool wxTreeCtrl::SortChildren(long item) | |
381 | { | |
382 | // TODO | |
383 | return FALSE; | |
384 | } | |
385 | ||
386 | bool wxTreeCtrl::EnsureVisible(long item) | |
387 | { | |
388 | // TODO | |
389 | return FALSE; | |
390 | } | |
391 | ||
392 | // Tree item structure | |
393 | wxTreeItem::wxTreeItem() | |
394 | { | |
395 | m_mask = 0; | |
396 | m_itemId = 0; | |
397 | m_state = 0; | |
398 | m_stateMask = 0; | |
399 | m_image = -1; | |
400 | m_selectedImage = -1; | |
401 | m_children = 0; | |
402 | m_data = 0; | |
403 | } | |
404 | ||
405 | // Tree event | |
406 | IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent) | |
407 | ||
408 | wxTreeEvent::wxTreeEvent(wxEventType commandType, int id): | |
409 | wxCommandEvent(commandType, id) | |
410 | { | |
411 | m_code = 0; | |
412 | m_oldItem = 0; | |
413 | } | |
414 |