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