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