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