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