]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/treectrl.cpp
Did much work on colors. It doesn't work and I guess
[wxWidgets.git] / src / gtk1 / treectrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: treectrl.cpp
3 // Purpose: wxTreeCtrl
4 // Author: Denis Pershin
5 // Modified by:
6 // Created: 07/05/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Denis Pershin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "treectrl.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/gtk/treectrl.h"
28 #include <wx/textctrl.h>
29 #include "wx/log.h"
30
31 #include <gtk/gtk.h>
32
33 //static void wxConvertToGtkTreeItem(wxTreeCtrl *owner, wxTreeItem& info, GtkTreeItem **gtkItem);
34 //static void wxConvertFromGtkTreeItem(wxTreeItem& info, GtkTreeItem *gtkItem);
35 static void gtk_treectrl_count_callback (GtkWidget *widget, gpointer data);
36 // static void gtk_treectrl_next_callback (GtkWidget *widget, gpointer data);
37 // static void gtk_treectrl_next_visible_callback (GtkWidget *widget, gpointer data);
38 // static void gtk_treectrl_next_selected_callback (GtkWidget *widget, gpointer data);
39
40 static void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItemId *treeitem);
41 static void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItemId *treeitem);
42 static void gtk_treeitem_select_callback(GtkWidget *widget, wxTreeItemId *treeitem);
43
44 static void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItemId *treeitem) {
45 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
46 if (owner == NULL)
47 return;
48
49 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
50 owner->SendExpanding(GTK_TREE_ITEM(widget));
51 owner->SendExpanded(GTK_TREE_ITEM(widget));
52 };
53
54 static void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItemId *treeitem) {
55 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
56 if (owner == NULL)
57 return;
58
59 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
60 owner->SendCollapsing(GTK_TREE_ITEM(widget));
61 owner->SendCollapsed(GTK_TREE_ITEM(widget));
62 };
63
64 static void gtk_treeitem_select_callback(GtkWidget *widget, wxTreeItemId *treeitem) {
65 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
66 if (owner == NULL)
67 return;
68
69 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
70 owner->SendSelChanging(GTK_TREE_ITEM(widget));
71 owner->SendSelChanged(GTK_TREE_ITEM(widget));
72 }
73
74 #if !USE_SHARED_LIBRARY
75 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
76
77 #endif
78
79 void wxTreeCtrl::Init() {
80 m_imageListNormal = NULL;
81 m_imageListState = NULL;
82 m_textCtrl = NULL;
83 }
84
85 bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos,
86 const wxSize& size, long style,
87 const wxValidator& validator, const wxString& name) {
88 Init();
89
90 int x = pos.x;
91 int y = pos.y;
92 int width = size.x;
93 int height = size.y;
94
95 m_windowStyle = style;
96
97 SetParent(parent);
98
99 if (width <= 0)
100 width = 100;
101 if (height <= 0)
102 height = 30;
103 if (x < 0)
104 x = 0;
105 if (y < 0)
106 y = 0;
107
108 m_needParent = TRUE;
109
110 printf("precreate\n");
111 PreCreation( parent, id, pos, size, style, name );
112
113 printf("1\n");
114
115 m_widget = gtk_scrolled_window_new(NULL, NULL);
116 printf("2\n");
117 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget),
118 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
119
120 printf("3\n");
121 m_tree = GTK_TREE(gtk_tree_new());
122
123 printf("4\n");
124 gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_tree));
125 printf("5\n");
126 // gtk_widget_set_parent(GTK_WIDGET(m_tree), m_widget);
127 printf("6\n");
128 gtk_widget_show(GTK_WIDGET(m_tree));
129
130 SetName(name);
131 SetValidator(validator);
132
133 printf("postcreate\n");
134 PostCreation();
135
136 gtk_widget_realize(GTK_WIDGET(m_tree));
137
138 Show(TRUE);
139
140 return TRUE;
141 }
142
143 wxTreeCtrl::~wxTreeCtrl(void) {
144 if (m_textCtrl)
145 delete m_textCtrl;
146 }
147
148 // Attributes
149 static void gtk_treectrl_count_callback (GtkWidget *widget, gpointer data) {
150 int count = (*((int *)data));
151
152 count++;
153 if (GTK_IS_CONTAINER(widget))
154 gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_count_callback, data);
155 }
156
157 size_t wxTreeCtrl::GetCount() const {
158 int count = 0;
159
160 if (m_anchor != NULL)
161 gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_count_callback, &count);
162 return count;
163 }
164
165 unsigned int wxTreeCtrl::GetIndent() const {
166 return m_tree->indent_value;
167 }
168
169 void wxTreeCtrl::SetIndent(unsigned int indent) {
170 m_tree->indent_value = indent;
171 }
172
173 wxImageList *wxTreeCtrl::GetImageList() const {
174 return m_imageListNormal;
175 }
176
177 wxImageList *wxTreeCtrl::GetStateImageList() const {
178 return m_imageListState;
179 }
180
181 void wxTreeCtrl::SetImageList(wxImageList *imageList) {
182 m_imageListNormal = imageList;
183 }
184
185 void wxTreeCtrl::SetStateImageList(wxImageList *imageList) {
186 m_imageListState = imageList;
187 }
188
189 wxString wxTreeCtrl::GetItemText(const wxTreeItemId &item) const {
190 char *t;
191
192 if (!item.IsOk())
193 return wxString("");
194
195 GtkLabel *l = GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label"));
196 gtk_label_get(l, &t);
197
198 return t;
199 }
200
201 int wxTreeCtrl::GetItemImage(const wxTreeItemId& item) const {
202 if (!item.IsOk())
203 return (-1);
204
205 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "image");
206 }
207
208 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId& item) const {
209 if (!item.IsOk())
210 return (-1);
211
212 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "selectedImage");
213 }
214
215 wxTreeItemData *wxTreeCtrl::GetItemData(const wxTreeItemId& item) const {
216 if (!item.IsOk())
217 return NULL;
218
219 return (wxTreeItemData *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "data");
220 }
221
222 void wxTreeCtrl::SetItemText(const wxTreeItemId& item, const wxString& text) {
223 if (!item.IsOk())
224 return;
225
226 GtkLabel *l = GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label"));
227 gtk_label_set(l, text);
228 }
229
230 void wxTreeCtrl::SetItemImage(const wxTreeItemId& item, int image) {
231 if (!item.IsOk())
232 return;
233
234 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "image", (void *)image);
235 }
236
237 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId& item, int image) {
238 if (!item.IsOk())
239 return;
240
241 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "selectedImage", (void *)image);
242 }
243
244 void wxTreeCtrl::SetItemData(const wxTreeItemId& item, wxTreeItemData *data) {
245 if (!item.IsOk())
246 return;
247
248 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "data", data);
249 }
250
251 bool wxTreeCtrl::IsVisible(const wxTreeItemId& item) const {
252 #warning "Need to implement IsVisible"
253 return FALSE;
254 }
255
256 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId& item) const {
257 int count = 0;
258
259 gtk_container_foreach(GTK_CONTAINER((GtkTreeItem *)item), gtk_treectrl_count_callback, &count);
260
261 return (count != 0);
262 }
263
264 bool wxTreeCtrl::IsExpanded(const wxTreeItemId& item) const {
265 return (((GtkTreeItem *)item)->expanded != 0);
266 }
267
268 bool wxTreeCtrl::IsSelected(const wxTreeItemId& item) const {
269 #warning "Need to implement IsSelected"
270 return FALSE;
271 }
272
273 wxTreeItemId wxTreeCtrl::GetRootItem() const {
274 return m_anchor;
275 }
276
277 wxTreeItemId wxTreeCtrl::GetSelection() const {
278 #warning "Need to complete gtk_treectrl_next_selected_callback"
279 GtkTreeItem *next = NULL;
280
281 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
282 next = GTK_TREE_ITEM(list->data);
283 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_selected_callback, &next);
284
285 return next;
286 }
287
288 wxTreeItemId wxTreeCtrl::GetParent(const wxTreeItemId& item) const {
289 #warning "data 'parent' is missing!!!"
290 if (item.IsOk())
291 return (GtkTreeItem *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "parent");
292
293 return NULL;
294 }
295
296 wxTreeItemId wxTreeCtrl::GetFirstChild(const wxTreeItemId& item, long& cookie) const {
297 #warning "Need to implement GetFirstChild"
298 return NULL;
299 }
300
301 wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) const {
302 #warning "Need to implement GetNextChild"
303 return NULL;
304 }
305
306 wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const {
307 #warning "Need to implement GetNextSibling"
308 return NULL;
309 }
310
311 wxTreeItemId wxTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const {
312 #warning "Need to implement GetPrevSibling"
313 return NULL;
314 }
315
316 wxTreeItemId wxTreeCtrl::GetFirstVisibleItem() const {
317 #warning "Need to implement GetFirstVisibleItem"
318 return NULL;
319 }
320
321 wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const {
322 #warning "Need to implement GetNextVisible"
323 return NULL;
324 }
325
326 wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const {
327 #warning "Need to implement GetPrevVisible"
328 return NULL;
329 }
330
331 wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text, int image,
332 int selectedImage, wxTreeItemData *data) {
333 return p_InsertItem(0, text, image, selectedImage, data);
334 }
335
336 wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
337 const wxString& text, int image, int selectedImage,
338 wxTreeItemData *data) {
339 #warning "Need to implement PrependItem"
340 return NULL;
341 }
342
343 wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
344 const wxTreeItemId& idPrevious, const wxString& text,
345 int image, int selectedImage, wxTreeItemData *data) {
346 #warning "Need to implement InsertItem"
347 return NULL;
348 }
349
350 wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
351 const wxString& text, int image, int selectedImage,
352 wxTreeItemData *data) {
353 return p_InsertItem(parent, text, image, selectedImage, data);
354 }
355
356 wxTreeItemId wxTreeCtrl::p_InsertItem(GtkTreeItem *p,
357 const wxString& text, int image, int selectedImage,
358 wxTreeItemData *data) {
359 GtkTreeItem *item;
360
361 printf("begin insert\n");
362
363 item = GTK_TREE_ITEM(gtk_tree_item_new());
364
365 GtkHBox *m_box = GTK_HBOX(gtk_hbox_new(FALSE, 0));
366 gtk_container_add (GTK_CONTAINER (item), GTK_WIDGET(m_box));
367
368 gtk_object_set_data(GTK_OBJECT(item), "w_box", m_box);
369
370 const wxBitmap *bmp;
371 const wxImageList *list;
372 if ((list = GetImageList(wxIMAGE_LIST_NORMAL)) != NULL)
373 if ((bmp = list->GetBitmap(image)) != NULL)
374 if (bmp->Ok()) {
375 GdkBitmap *mask = NULL;
376 if (bmp->GetMask())
377 mask = bmp->GetMask()->GetBitmap();
378 GtkPixmap *m_image_widget = GTK_PIXMAP(gtk_pixmap_new(bmp->GetPixmap(), mask));
379 gtk_misc_set_alignment (GTK_MISC (m_image_widget), 0.0, 0.5);
380 gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_image_widget), FALSE, FALSE, 0);
381 gtk_object_set_data(GTK_OBJECT(item), "w_image", (void *)m_image_widget);
382 gtk_object_set_data(GTK_OBJECT(item), "image", (void *)image);
383 gtk_widget_show (GTK_WIDGET(m_image_widget));
384 }
385 GtkLabel *m_label_widget = GTK_LABEL(gtk_label_new ((char *)(const char *)text));
386 gtk_misc_set_alignment (GTK_MISC (m_label_widget), 0.5, 0.5);
387 gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_label_widget), FALSE, FALSE, 0);
388 gtk_object_set_data(GTK_OBJECT(item), "w_label", m_label_widget);
389 gtk_widget_show (GTK_WIDGET(m_label_widget));
390
391 gtk_widget_show(GTK_WIDGET(m_box));
392
393 gtk_object_set_data(GTK_OBJECT(item), "owner", this);
394
395 if (p != 0) {
396 if (p->subtree == NULL) {
397 GtkTree *tree = GTK_TREE(gtk_tree_new());
398 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
399 gtk_widget_show(GTK_WIDGET(tree));
400 p->expanded = 1;
401 }
402
403 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
404 } else {
405 printf("Adding root\n");
406 printf("m_tree = %p\n", m_tree);
407 m_anchor = item;
408 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
409 }
410
411 /*
412 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
413 GtkTree *tree = GTK_TREE(gtk_tree_new());
414 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
415 gtk_widget_show(GTK_WIDGET(tree));
416 }
417 */
418
419 gtk_object_set_data(GTK_OBJECT(item), "data", data);
420
421 gtk_widget_show(GTK_WIDGET(item));
422
423 gtk_signal_connect(GTK_OBJECT(item), "select",
424 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
425
426 gtk_signal_connect(GTK_OBJECT(item), "deselect",
427 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
428
429 gtk_signal_connect(GTK_OBJECT(item), "expand",
430 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
431 gtk_signal_connect(GTK_OBJECT(item), "collapse",
432 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
433
434 return item;
435 }
436
437 void wxTreeCtrl::Delete(const wxTreeItemId& item) {
438 if (!item.IsOk())
439 return;
440
441 GtkTreeItem *parent = GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem *)item)->parent);
442 if (parent == NULL)
443 return;
444
445 gtk_container_remove(GTK_CONTAINER(parent), GTK_WIDGET((GtkTreeItem *)item));
446
447 return;
448 }
449
450 void wxTreeCtrl::DeleteAllItems() {
451 gtk_tree_item_remove_subtree(m_anchor);
452 }
453
454 void wxTreeCtrl::Expand(const wxTreeItemId& item) {
455 if (!item.IsOk())
456 return;
457
458 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem *)item));
459 }
460
461 void wxTreeCtrl::Collapse(const wxTreeItemId& item) {
462 if (!item.IsOk())
463 return;
464
465 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
466 }
467
468 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId& item) {
469 if (!item.IsOk())
470 return;
471
472 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
473 gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem *)item));
474 }
475
476 void wxTreeCtrl::Toggle(const wxTreeItemId& item) {
477 if (!item.IsOk())
478 return;
479
480 if (((GtkTreeItem *)item)->expanded)
481 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
482 else
483 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem *)item));
484 }
485
486 void wxTreeCtrl::Unselect() {
487 #warning "Need to implement Unselect"
488 }
489
490 void wxTreeCtrl::SelectItem(const wxTreeItemId& item) {
491 if (!item.IsOk())
492 return;
493
494 gtk_tree_item_select((GtkTreeItem *)item);
495 }
496
497 void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item) {
498 #warning "Need to implement EnsureVisible"
499 }
500
501 void wxTreeCtrl::ScrollTo(const wxTreeItemId& item) {
502 #warning "Need to implement ScrollTo"
503 }
504
505 wxTextCtrl* wxTreeCtrl::EditLabel(const wxTreeItemId& item,
506 wxClassInfo* textControlClass) {
507 wxASSERT( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)) );
508 #warning "Need to implement EditLabel"
509 return m_textCtrl;
510 }
511
512 wxTextCtrl* wxTreeCtrl::GetEditControl() const {
513 return m_textCtrl;
514 }
515
516 void wxTreeCtrl::EndEditLabel(const wxTreeItemId& item, bool discardChanges) {
517 #warning "Need to implement EndEditLabel"
518 }
519
520 void wxTreeCtrl::ExpandItem(const wxTreeItemId& item, int action) {
521 switch (action) {
522 case wxTREE_EXPAND_EXPAND:
523 Expand(item);
524 break;
525
526 case wxTREE_EXPAND_COLLAPSE:
527 Collapse(item);
528 break;
529
530 case wxTREE_EXPAND_COLLAPSE_RESET:
531 CollapseAndReset(item);
532 break;
533
534 case wxTREE_EXPAND_TOGGLE:
535 Toggle(item);
536 break;
537
538 default:
539 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
540 }
541 }
542
543 wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
544 const wxString& text, int image, int selImage,
545 long insertAfter) {
546 // InsertItem(parent, insertAfter, text, image, selImage);
547 #warning "Need to implement InsertItem"
548 return NULL;
549 }
550
551 /* Old functions
552 long wxTreeCtrl::GetChild(long item) const {
553 GtkTreeItem *p;
554 GtkTreeItem *next = NULL;
555
556 p = findGtkTreeItem(item);
557 GList *list = gtk_container_children(GTK_CONTAINER(p));
558 next = GTK_TREE_ITEM(list->data);;
559
560 if (next != NULL)
561 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
562
563 return (-1);
564 }
565
566 long wxTreeCtrl::GetFirstVisibleItem(void) const {
567 GtkTreeItem *next = NULL;
568
569 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
570 next = GTK_TREE_ITEM(list->data);;
571 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
572
573 if (next != NULL)
574 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
575
576 return (-1);
577 }
578
579 long wxTreeCtrl::GetNextVisibleItem(long item) const {
580 GtkTreeItem *p;
581 GtkTreeItem *next = NULL;
582
583 p = findGtkTreeItem(item);
584 GList *list = gtk_container_children(GTK_CONTAINER(p));
585 next = GTK_TREE_ITEM(list->data);;
586 // gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
587
588 if (next != NULL)
589 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
590
591 return (-1);
592 }
593
594 bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
595 GtkTreeItem *p;
596
597 p = findGtkTreeItem(info.m_itemId);
598
599 if (p == NULL) {
600 wxLogSysError("TreeCtrl::GetItem failed");
601 return FALSE;
602 }
603
604 wxConvertFromGtkTreeItem(info, p);
605
606 return TRUE;
607 }
608
609 bool wxTreeCtrl::SetItem(wxTreeItem& info) {
610 GtkTreeItem *p;
611
612 p = findGtkTreeItem(info.m_itemId);
613
614 if (p == NULL) {
615 wxLogSysError("TreeCtrl::SetItem failed");
616 return FALSE;
617 }
618
619 wxConvertToGtkTreeItem(this, info, &p);
620
621 return TRUE;
622 }
623
624 int wxTreeCtrl::GetItemState(long item, long stateMask) const {
625 wxTreeItem info;
626
627 info.m_mask = wxTREE_MASK_STATE ;
628 info.m_stateMask = stateMask;
629 info.m_itemId = item;
630
631 if (!GetItem(info))
632 return 0;
633
634 return info.m_state;
635 }
636
637 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
638 wxTreeItem info;
639
640 info.m_mask = wxTREE_MASK_STATE ;
641 info.m_state = state;
642 info.m_stateMask = stateMask;
643 info.m_itemId = item;
644
645 return SetItem(info);
646 }
647 */
648
649 // Operations
650 /*
651 bool wxTreeCtrl::DeleteChildren(long item) {
652 GtkTreeItem *p;
653
654 p = findGtkTreeItem(item);
655 if (p == NULL)
656 return FALSE;
657
658 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
659
660 return TRUE;
661 }
662 */
663
664 /*
665 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
666 GtkTreeItem *p;
667 GtkTreeItem *item = NULL;
668
669 info.m_itemId = m_curitemId;
670 m_curitemId++;
671
672 wxConvertToGtkTreeItem(this, info, &item);
673
674 if (parent != 0) {
675 p = findGtkTreeItem(parent);
676 if (p->subtree == NULL) {
677 GtkTree *tree = GTK_TREE(gtk_tree_new());
678 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
679 gtk_widget_show(GTK_WIDGET(tree));
680 p->expanded = 1;
681 }
682
683 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
684 } else {
685 m_anchor = item;
686 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
687 }
688
689 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
690 GtkTree *tree = GTK_TREE(gtk_tree_new());
691 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
692 gtk_widget_show(GTK_WIDGET(tree));
693 }
694
695 gtk_widget_show(GTK_WIDGET(item));
696
697 gtk_signal_connect(GTK_OBJECT(item), "select",
698 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
699
700 gtk_signal_connect(GTK_OBJECT(item), "deselect",
701 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
702
703 gtk_signal_connect(GTK_OBJECT(item), "expand",
704 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
705 gtk_signal_connect(GTK_OBJECT(item), "collapse",
706 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
707
708 return info.m_itemId;
709 }
710
711 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
712 int selImage, long insertAfter) {
713
714 wxTreeItem info;
715 info.m_text = label;
716 info.m_mask = wxTREE_MASK_TEXT;
717 if (image > -1) {
718 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
719 info.m_image = image;
720 if (selImage == -1)
721 info.m_selectedImage = image;
722 else
723 info.m_selectedImage = selImage;
724 }
725
726 return InsertItem(parent, info, insertAfter);
727 }
728 */
729
730 void wxTreeCtrl::SendExpanding(const wxTreeItemId& item) {
731 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId());
732 event.SetEventObject(this);
733 ProcessEvent(event);
734 }
735
736 void wxTreeCtrl::SendExpanded(const wxTreeItemId& item) {
737 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDED, GetId());
738 event.SetEventObject(this);
739 ProcessEvent(event);
740 }
741
742 void wxTreeCtrl::SendCollapsing(const wxTreeItemId& item) {
743 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, GetId());
744 event.SetEventObject(this);
745 ProcessEvent(event);
746 }
747
748 void wxTreeCtrl::SendCollapsed(const wxTreeItemId& item) {
749 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, GetId());
750 event.SetEventObject(this);
751 ProcessEvent(event);
752 }
753
754 void wxTreeCtrl::SendSelChanging(const wxTreeItemId& item) {
755 wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGED, GetId());
756 event.SetEventObject(this);
757 ProcessEvent(event);
758 }
759
760 void wxTreeCtrl::SendSelChanged(const wxTreeItemId& item) {
761 wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, GetId());
762 event.SetEventObject(this);
763 ProcessEvent(event);
764 }
765
766 // Tree event
767 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent)
768
769 wxTreeEvent::wxTreeEvent(wxEventType commandType, int id):
770 wxCommandEvent(commandType, id) {
771 m_code = 0;
772 m_itemOld = 0;
773 }