]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/treectrl.cpp
fixing border drawing for toplevel controls on dialogs, fixes #10877
[wxWidgets.git] / src / osx / carbon / treectrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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
19 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
20 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject)
21
22
23 wxTreeCtrl::wxTreeCtrl()
24 {
25 m_imageListNormal = NULL;
26 m_imageListState = NULL;
27 m_textCtrl = NULL;
28 }
29
30 bool wxTreeCtrl::Create(wxWindow *parent,
31 wxWindowID id, const wxPoint& pos, const wxSize& size,
32 long style, const wxValidator& wxVALIDATOR_PARAM(validator),
33 const wxString& name)
34 {
35 m_imageListNormal = NULL;
36 m_imageListState = NULL;
37 m_textCtrl = NULL;
38
39 SetName(name);
40 #if wxUSE_VALIDATORS
41 SetValidator(validator);
42 #endif
43 SetParent(parent);
44
45 m_windowStyle = style;
46
47 m_windowId = (id == wxID_ANY) ? NewControlId() : id;
48
49 if (parent)
50 parent->AddChild(this);
51
52 // TODO: create tree control
53
54 return false;
55 }
56
57 wxTreeCtrl::~wxTreeCtrl()
58 {
59 delete m_textCtrl;
60 }
61
62 // Attributes
63 unsigned int wxTreeCtrl::GetCount() const
64 {
65 // TODO
66 return 0;
67 }
68
69 int wxTreeCtrl::GetIndent() const
70 {
71 // TODO
72 return 0;
73 }
74
75 void wxTreeCtrl::SetIndent(int indent)
76 {
77 // TODO
78 }
79
80 wxImageList *wxTreeCtrl::GetImageList(int which) const
81 {
82 if ( which == wxIMAGE_LIST_NORMAL )
83 return m_imageListNormal;
84 else if ( which == wxIMAGE_LIST_STATE )
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 m_imageListNormal = imageList;
94 else if ( which == wxIMAGE_LIST_STATE )
95 m_imageListState = imageList;
96
97 // TODO
98 }
99
100 long wxTreeCtrl::GetNextItem(long item, int code) const
101 {
102 // TODO
103 return 0;
104 }
105
106 bool wxTreeCtrl::ItemHasChildren(long item) const
107 {
108 // TODO
109 return false;
110 }
111
112 long wxTreeCtrl::GetChild(long item) const
113 {
114 // TODO
115 return 0;
116 }
117
118 long wxTreeCtrl::GetItemParent(long item) const
119 {
120 // TODO
121 return 0;
122 }
123
124 long wxTreeCtrl::GetFirstVisibleItem() const
125 {
126 // TODO
127 return 0;
128 }
129
130 long wxTreeCtrl::GetNextVisibleItem(long item) const
131 {
132 // TODO
133 return 0;
134 }
135
136 long wxTreeCtrl::GetSelection() const
137 {
138 // TODO
139 return 0;
140 }
141
142 long wxTreeCtrl::GetRootItem() const
143 {
144 // TODO
145 return 0;
146 }
147
148 bool wxTreeCtrl::GetItem(wxTreeItem& info) const
149 {
150 // TODO
151 return false;
152 }
153
154 bool wxTreeCtrl::SetItem(wxTreeItem& info)
155 {
156 // TODO
157 return false;
158 }
159
160 int wxTreeCtrl::GetItemState(long item, long stateMask) const
161 {
162 wxTreeItem info;
163
164 info.m_mask = wxTREE_MASK_STATE;
165 info.m_stateMask = stateMask;
166 info.m_itemId = item;
167
168 if (!GetItem(info))
169 return 0;
170
171 return info.m_state;
172 }
173
174 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask)
175 {
176 wxTreeItem info;
177
178 info.m_mask = wxTREE_MASK_STATE;
179 info.m_state = state;
180 info.m_stateMask = stateMask;
181 info.m_itemId = item;
182
183 return SetItem(info);
184 }
185
186 bool wxTreeCtrl::SetItemImage(long item, int image, int selImage)
187 {
188 wxTreeItem info;
189
190 info.m_mask = wxTREE_MASK_IMAGE;
191 info.m_image = image;
192 if ( selImage > -1)
193 {
194 info.m_selectedImage = selImage;
195 info.m_mask |= wxTREE_MASK_SELECTED_IMAGE;
196 }
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
213 return info.m_text;
214 }
215
216 void wxTreeCtrl::SetItemText(long item, const wxString& str)
217 {
218 wxTreeItem info;
219
220 info.m_mask = wxTREE_MASK_TEXT;
221 info.m_itemId = item;
222 info.m_text = str;
223
224 SetItem(info);
225 }
226
227 long wxTreeCtrl::GetItemData(long item) const
228 {
229 wxTreeItem info;
230
231 info.m_mask = wxTREE_MASK_DATA;
232 info.m_itemId = item;
233
234 if (!GetItem(info))
235 return 0;
236
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(wxT("unknown action in wxTreeCtrl::ExpandItem");
288 }
289
290 // TODO: expand item
291 bool bOk = false;
292
293 // May not send messages, so emulate them
294 if ( bOk )
295 {
296 wxTreeEvent event(wxEVT_NULL, m_windowId);
297 event.m_item.m_itemId = item;
298 event.m_item.m_mask = event.m_item.m_stateMask = 0xFFFF; // get all
299 GetItem(event.m_item);
300
301 bool bIsExpanded = (event.m_item.m_state & wxTREE_STATE_EXPANDED) != 0;
302
303 event.m_code = action;
304 event.SetEventObject(this);
305
306 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
307 event.SetEventType(
308 bIsExpanded
309 ? wxEVT_COMMAND_TREE_ITEM_EXPANDING
310 : wxEVT_COMMAND_TREE_ITEM_COLLAPSING);
311 HandleWindowEvent(event);
312
313 event.SetEventType(
314 bIsExpanded
315 ? wxEVT_COMMAND_TREE_ITEM_EXPANDED
316 : wxEVT_COMMAND_TREE_ITEM_COLLAPSED);
317 HandleWindowEvent(event);
318 }
319
320 return bOk;
321 }
322
323 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter)
324 {
325 // TODO
326 return 0;
327 }
328
329 long wxTreeCtrl::InsertItem(long parent, const wxString& label,
330 int image, int selImage, long insertAfter)
331 {
332 wxTreeItem info;
333 info.m_text = label;
334 info.m_mask = wxTREE_MASK_TEXT;
335 if ( image > -1 )
336 {
337 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
338 info.m_image = image;
339 if ( selImage == -1 )
340 info.m_selectedImage = image;
341 else
342 info.m_selectedImage = selImage;
343 }
344
345 return InsertItem(parent, info, insertAfter);
346 }
347
348 bool wxTreeCtrl::SelectItem(long item)
349 {
350 // TODO
351 return false;
352 }
353
354 bool wxTreeCtrl::ScrollTo(long item)
355 {
356 // TODO
357 return false;
358 }
359
360 bool wxTreeCtrl::DeleteAllItems()
361 {
362 // TODO
363 return false;
364 }
365
366 wxTextCtrl * wxTreeCtrl::EditLabel(long item, wxClassInfo* textControlClass)
367 {
368 // TODO
369 return NULL;
370 }
371
372 // End label editing, optionally cancelling the edit
373 bool wxTreeCtrl::EndEditLabel(bool cancel)
374 {
375 // TODO
376 return false;
377 }
378
379 long wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
380 {
381 // TODO
382 return 0;
383 }
384
385 bool wxTreeCtrl::SortChildren(long item)
386 {
387 // TODO
388 return false;
389 }
390
391 bool wxTreeCtrl::EnsureVisible(long item)
392 {
393 // TODO
394 return false;
395 }
396
397 // Tree item structure
398 wxTreeItem::wxTreeItem()
399 {
400 m_mask = 0;
401 m_itemId = 0;
402 m_state = 0;
403 m_stateMask = 0;
404 m_image = -1;
405 m_selectedImage = -1;
406 m_children = 0;
407 m_data = 0;
408 }
409
410 // Tree event
411 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent)
412
413 wxTreeEvent::wxTreeEvent(wxEventType commandType, int id)
414 : wxCommandEvent(commandType, id)
415 {
416 m_code = 0;
417 m_oldItem = 0;
418 }