]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/treectrl.cpp
[ 1563875 ] wxTreeCtrl::FindItem asserts when item not found
[wxWidgets.git] / src / mac / classic / treectrl.cpp
CommitLineData
2646f485 1/////////////////////////////////////////////////////////////////////////////
3b38e2a0 2// Name: src/mac/classic/treectrl.cpp
2646f485
SC
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
3b38e2a0 9// Licence: wxWindows licence
2646f485
SC
10/////////////////////////////////////////////////////////////////////////////
11
2646f485
SC
12#include "wx/stubs/textctrl.h"
13#include "wx/treebase.h"
14#include "wx/stubs/treectrl.h"
15
2646f485
SC
16IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
17IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject)
18
2646f485
SC
19wxTreeCtrl::wxTreeCtrl()
20{
21 m_imageListNormal = NULL;
22 m_imageListState = NULL;
23 m_textCtrl = NULL;
24}
25
26bool 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
3b38e2a0 40 m_windowId = (id == wxID_ANY) ? NewControlId() : id;
2646f485
SC
41
42 if (parent) parent->AddChild(this);
43
44 // TODO create tree control
45
3b38e2a0 46 return false;
2646f485
SC
47}
48
49wxTreeCtrl::~wxTreeCtrl()
50{
51 if (m_textCtrl)
52 {
53 delete m_textCtrl;
54 }
55}
56
57// Attributes
027d45e8 58unsigned int wxTreeCtrl::GetCount() const
2646f485
SC
59{
60 // TODO
61 return 0;
62}
63
64int wxTreeCtrl::GetIndent() const
65{
66 // TODO
67 return 0;
68}
69
70void wxTreeCtrl::SetIndent(int indent)
71{
72 // TODO
73}
74
75wxImageList *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
88void 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
101long wxTreeCtrl::GetNextItem(long item, int code) const
102{
103 // TODO
104 return 0;
105}
106
107bool wxTreeCtrl::ItemHasChildren(long item) const
108{
109 // TODO
3b38e2a0 110 return false;
2646f485
SC
111}
112
113long wxTreeCtrl::GetChild(long item) const
114{
115 // TODO
116 return 0;
117}
118
119long wxTreeCtrl::GetItemParent(long item) const
120{
121 // TODO
122 return 0;
123}
124
125long wxTreeCtrl::GetFirstVisibleItem() const
126{
127 // TODO
128 return 0;
129}
130
131long wxTreeCtrl::GetNextVisibleItem(long item) const
132{
133 // TODO
134 return 0;
135}
136
137long wxTreeCtrl::GetSelection() const
138{
139 // TODO
140 return 0;
141}
142
143long wxTreeCtrl::GetRootItem() const
144{
145 // TODO
146 return 0;
147}
148
149bool wxTreeCtrl::GetItem(wxTreeItem& info) const
150{
151 // TODO
3b38e2a0 152 return false;
2646f485
SC
153}
154
155bool wxTreeCtrl::SetItem(wxTreeItem& info)
156{
157 // TODO
3b38e2a0 158 return false;
2646f485
SC
159}
160
161int 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
175bool 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
187bool 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
203wxString 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))
3b38e2a0 211 return wxEmptyString;
2646f485
SC
212 return info.m_text;
213}
214
215void 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
226long 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
238bool 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
249bool wxTreeCtrl::GetItemRect(long item, wxRect& rect, bool textOnly) const
250{
251 // TODO
3b38e2a0 252 return false;
2646f485
SC
253}
254
255wxTextCtrl* wxTreeCtrl::GetEditControl() const
256{
257 return m_textCtrl;
258}
259
260// Operations
261bool wxTreeCtrl::DeleteItem(long item)
262{
263 // TODO
3b38e2a0 264 return false;
2646f485
SC
265}
266
267bool wxTreeCtrl::ExpandItem(long item, int action)
268{
269 // TODO
270 switch ( action )
271 {
272 case wxTREE_EXPAND_EXPAND:
273 break;
3b38e2a0 274
2646f485
SC
275 case wxTREE_EXPAND_COLLAPSE:
276 break;
3b38e2a0 277
2646f485
SC
278 case wxTREE_EXPAND_COLLAPSE_RESET:
279 break;
3b38e2a0 280
2646f485
SC
281 case wxTREE_EXPAND_TOGGLE:
282 break;
3b38e2a0 283
2646f485
SC
284 default:
285 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
286 }
3b38e2a0
WS
287
288 bool bOk = false; // TODO expand item
289
2646f485
SC
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);
3b38e2a0 297
2646f485 298 bool bIsExpanded = (event.m_item.m_state & wxTREE_STATE_EXPANDED) != 0;
3b38e2a0 299
2646f485
SC
300 event.m_code = action;
301 event.SetEventObject(this);
3b38e2a0 302
2646f485
SC
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);
3b38e2a0 307
2646f485
SC
308 event.SetEventType(bIsExpanded ? wxEVT_COMMAND_TREE_ITEM_EXPANDED
309 : wxEVT_COMMAND_TREE_ITEM_COLLAPSED);
310 GetEventHandler()->ProcessEvent(event);
311 }
3b38e2a0 312
2646f485
SC
313 return bOk;
314}
315
316long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter)
317{
318 // TODO
319 return 0;
320}
321
322long 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
341bool wxTreeCtrl::SelectItem(long item)
342{
343 // TODO
3b38e2a0 344 return false;
2646f485
SC
345}
346
347bool wxTreeCtrl::ScrollTo(long item)
348{
349 // TODO
3b38e2a0 350 return false;
2646f485
SC
351}
352
353bool wxTreeCtrl::DeleteAllItems()
354{
355 // TODO
3b38e2a0 356 return false;
2646f485
SC
357}
358
359wxTextCtrl* wxTreeCtrl::EditLabel(long item, wxClassInfo* textControlClass)
360{
361 // TODO
362 return NULL;
363}
364
365// End label editing, optionally cancelling the edit
366bool wxTreeCtrl::EndEditLabel(bool cancel)
367{
368 // TODO
3b38e2a0 369 return false;
2646f485
SC
370}
371
372long wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
373{
374 // TODO
375 return 0;
376}
377
378bool wxTreeCtrl::SortChildren(long item)
379{
380 // TODO
3b38e2a0 381 return false;
2646f485
SC
382}
383
384bool wxTreeCtrl::EnsureVisible(long item)
385{
386 // TODO
3b38e2a0 387 return false;
2646f485
SC
388}
389
390// Tree item structure
391wxTreeItem::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
404IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent)
405
406wxTreeEvent::wxTreeEvent(wxEventType commandType, int id):
407 wxCommandEvent(commandType, id)
408{
409 m_code = 0;
410 m_oldItem = 0;
411}