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