1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Denis Pershin
8 // Copyright: (c) Denis Pershin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "treectrl.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/gtk/treectrl.h"
28 #include <wx/textctrl.h>
33 //static void wxConvertToGtkTreeItem(wxTreeCtrl *owner, wxTreeItem& info, GtkTreeItem **gtkItem);
34 //static void wxConvertFromGtkTreeItem(wxTreeItem& info, GtkTreeItem *gtkItem);
36 static void gtk_treectrl_count_callback (GtkWidget
*widget
, gpointer data
);
37 static void gtk_treectrl_first_selected_callback(GtkWidget
*widget
, gpointer data
);
38 static void gtk_treectrl_first_visible_callback(GtkWidget
*widget
, gpointer data
);
40 // static void gtk_treectrl_next_callback (GtkWidget *widget, gpointer data);
41 // static void gtk_treectrl_next_visible_callback (GtkWidget *widget, gpointer data);
42 // static void gtk_treectrl_next_selected_callback (GtkWidget *widget, gpointer data);
44 static void gtk_treeitem_expand_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
);
45 static void gtk_treeitem_collapse_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
);
46 static void gtk_treeitem_select_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
);
48 static void gtk_treeitem_expand_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
) {
49 wxTreeCtrl
*owner
= (wxTreeCtrl
*)gtk_object_get_data(GTK_OBJECT(widget
), "owner");
53 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
54 owner
->SendExpanding(GTK_TREE_ITEM(widget
));
55 owner
->SendExpanded(GTK_TREE_ITEM(widget
));
58 static void gtk_treeitem_collapse_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
) {
59 wxTreeCtrl
*owner
= (wxTreeCtrl
*)gtk_object_get_data(GTK_OBJECT(widget
), "owner");
63 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
64 owner
->SendCollapsing(GTK_TREE_ITEM(widget
));
65 owner
->SendCollapsed(GTK_TREE_ITEM(widget
));
68 static void gtk_treeitem_select_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
) {
69 wxTreeCtrl
*owner
= (wxTreeCtrl
*)gtk_object_get_data(GTK_OBJECT(widget
), "owner");
73 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
74 owner
->SendSelChanging(GTK_TREE_ITEM(widget
));
75 owner
->SendSelChanged(GTK_TREE_ITEM(widget
));
78 #if !USE_SHARED_LIBRARY
79 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
83 void wxTreeCtrl::Init() {
84 m_imageListNormal
= NULL
;
85 m_imageListState
= NULL
;
89 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
90 const wxSize
& size
, long style
,
91 const wxValidator
& validator
, const wxString
& name
) {
99 m_windowStyle
= style
;
114 printf("precreate\n");
115 PreCreation( parent
, id
, pos
, size
, style
, name
);
119 m_widget
= gtk_scrolled_window_new(NULL
, NULL
);
121 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget
),
122 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
125 m_tree
= GTK_TREE(gtk_tree_new());
128 gtk_container_add(GTK_CONTAINER(m_widget
), GTK_WIDGET(m_tree
));
130 gtk_widget_show(GTK_WIDGET(m_tree
));
133 SetValidator(validator
);
135 printf("Robert's new insertion code :-)\n");
136 m_parent
->AddChild( this );
137 (m_parent
->m_insertCallback
)( m_parent
, this );
139 printf("postcreate\n");
142 gtk_widget_realize(GTK_WIDGET(m_tree
));
149 wxTreeCtrl::~wxTreeCtrl(void) {
155 static void gtk_treectrl_count_callback (GtkWidget
*widget
, gpointer data
) {
156 int count
= (*((int *)data
));
159 if (GTK_IS_CONTAINER(widget
))
160 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_count_callback
, data
);
163 size_t wxTreeCtrl::GetCount() const {
166 if (m_anchor
!= NULL
)
167 gtk_treectrl_count_callback(GTK_WIDGET(m_anchor
), &count
);
171 unsigned int wxTreeCtrl::GetIndent() const {
172 return m_tree
->indent_value
;
175 void wxTreeCtrl::SetIndent(unsigned int indent
) {
176 m_tree
->indent_value
= indent
;
179 wxImageList
*wxTreeCtrl::GetImageList() const {
180 return m_imageListNormal
;
183 wxImageList
*wxTreeCtrl::GetStateImageList() const {
184 return m_imageListState
;
187 void wxTreeCtrl::SetImageList(wxImageList
*imageList
) {
188 m_imageListNormal
= imageList
;
191 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
) {
192 m_imageListState
= imageList
;
195 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
&item
) const {
201 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
202 gtk_label_get(l
, &t
);
207 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
) const {
211 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "image");
214 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& item
) const {
218 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage");
221 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const {
225 return (wxTreeItemData
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "data");
228 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
) {
232 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
233 gtk_label_set(l
, text
);
236 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
) {
240 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "image", (void *)image
);
243 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& item
, int image
) {
247 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage", (void *)image
);
250 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
) {
254 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "data", data
);
257 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const {
258 return GTK_WIDGET_VISIBLE(GTK_TREE_ITEM((GtkTreeItem
*)item
));
261 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const {
262 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
264 if (p
->subtree
== NULL
)
267 if (GTK_TREE(p
->subtree
)->children
== NULL
)
270 if (g_list_length(GTK_TREE(p
->subtree
)->children
) == 0)
276 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const {
277 return (((GtkTreeItem
*)item
)->expanded
!= 0);
280 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const {
281 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
282 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
284 if (!GTK_IS_TREE(parent
))
287 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
293 wxTreeItemId
wxTreeCtrl::GetRootItem() const {
297 static void gtk_treectrl_first_selected_callback(GtkWidget
*widget
, gpointer data
) {
298 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
300 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
302 if (tree
->selection
!= NULL
) {
303 p
= (GtkTreeItem
*)tree
->selection
->data
;
307 if (GTK_IS_CONTAINER(widget
))
308 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_selected_callback
, data
);
311 wxTreeItemId
wxTreeCtrl::GetSelection() const {
312 GtkTreeItem
*p
= NULL
;
314 if (m_anchor
== NULL
)
317 gtk_treectrl_first_selected_callback(GTK_WIDGET(m_anchor
), &p
);
322 wxTreeItemId
wxTreeCtrl::GetParent(const wxTreeItemId
& item
) const {
324 return (GtkTreeItem
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "parent");
329 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const {
330 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
331 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
333 if (!GTK_IS_TREE(parent
))
337 return GTK_TREE_ITEM(g_list_first(GTK_TREE(parent
)->children
)->data
);
340 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& item
, long& cookie
) const {
341 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
342 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
344 if (!GTK_IS_TREE(parent
))
348 return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent
)->children
, cookie
)->data
);
351 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const {
352 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
353 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
355 if (!GTK_IS_TREE(parent
))
358 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
361 return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
364 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const {
365 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
366 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
368 if (!GTK_IS_TREE(parent
))
371 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
374 return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
377 static void gtk_treectrl_first_visible_callback(GtkWidget
*widget
, gpointer data
) {
378 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
380 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
382 if (tree
->children
!= NULL
) {
383 guint len
= g_list_length(tree
->children
);
384 for (guint i
=0; i
<len
; i
++) {
385 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
)))) {
386 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
);
392 if (GTK_IS_CONTAINER(widget
))
393 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_visible_callback
, data
);
396 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const {
397 GtkTreeItem
*p
= NULL
;
399 if (m_anchor
== NULL
)
402 gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor
), &p
);
407 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const {
408 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
409 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
412 if (!GTK_IS_TREE(parent
))
415 if (parent
->children
== NULL
)
418 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
421 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
422 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
429 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const {
430 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
431 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
434 if (!GTK_IS_TREE(parent
))
437 if (parent
->children
== NULL
)
440 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
443 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
444 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
451 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
, int image
,
452 int selectedImage
, wxTreeItemData
*data
) {
453 return p_InsertItem(0, text
, image
, selectedImage
, data
);
456 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
457 const wxString
& text
, int image
, int selectedImage
,
458 wxTreeItemData
*data
) {
459 #warning "Need to implement PrependItem"
463 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
464 const wxTreeItemId
& idPrevious
, const wxString
& text
,
465 int image
, int selectedImage
, wxTreeItemData
*data
) {
466 #warning "Need to implement InsertItem"
470 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
471 const wxString
& text
, int image
, int selectedImage
,
472 wxTreeItemData
*data
) {
473 return p_InsertItem(parent
, text
, image
, selectedImage
, data
);
476 wxTreeItemId
wxTreeCtrl::p_InsertItem(GtkTreeItem
*p
,
477 const wxString
& text
, int image
, int selectedImage
,
478 wxTreeItemData
*data
) {
481 printf("begin insert\n");
483 item
= GTK_TREE_ITEM(gtk_tree_item_new());
485 GtkHBox
*m_box
= GTK_HBOX(gtk_hbox_new(FALSE
, 0));
486 gtk_container_add (GTK_CONTAINER (item
), GTK_WIDGET(m_box
));
488 gtk_object_set_data(GTK_OBJECT(item
), "w_box", m_box
);
491 const wxImageList
*list
;
492 if ((list
= GetImageList(wxIMAGE_LIST_NORMAL
)) != NULL
)
493 if ((bmp
= list
->GetBitmap(image
)) != NULL
)
495 GdkBitmap
*mask
= NULL
;
497 mask
= bmp
->GetMask()->GetBitmap();
498 GtkPixmap
*m_image_widget
= GTK_PIXMAP(gtk_pixmap_new(bmp
->GetPixmap(), mask
));
499 gtk_misc_set_alignment (GTK_MISC (m_image_widget
), 0.0, 0.5);
500 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_image_widget
), FALSE
, FALSE
, 0);
501 gtk_object_set_data(GTK_OBJECT(item
), "w_image", (void *)m_image_widget
);
502 gtk_object_set_data(GTK_OBJECT(item
), "image", (void *)image
);
503 gtk_widget_show (GTK_WIDGET(m_image_widget
));
505 GtkLabel
*m_label_widget
= GTK_LABEL(gtk_label_new ((char *)(const char *)text
));
506 gtk_misc_set_alignment (GTK_MISC (m_label_widget
), 0.5, 0.5);
507 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_label_widget
), FALSE
, FALSE
, 0);
508 gtk_object_set_data(GTK_OBJECT(item
), "w_label", m_label_widget
);
509 gtk_widget_show (GTK_WIDGET(m_label_widget
));
511 gtk_widget_show(GTK_WIDGET(m_box
));
513 gtk_object_set_data(GTK_OBJECT(item
), "owner", this);
514 gtk_object_set_data(GTK_OBJECT(item
), "data", data
);
515 gtk_object_set_data(GTK_OBJECT(item
), "parent", p
);
518 if (p
->subtree
== NULL
) {
519 GtkTree
*tree
= GTK_TREE(gtk_tree_new());
520 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p
), GTK_WIDGET(tree
));
521 gtk_widget_show(GTK_WIDGET(tree
));
525 gtk_container_add(GTK_CONTAINER(p
->subtree
), GTK_WIDGET(item
));
527 printf("Adding root\n");
528 printf("m_tree = %p\n", m_tree
);
530 gtk_container_add(GTK_CONTAINER(m_tree
), GTK_WIDGET(item
));
533 gtk_widget_show(GTK_WIDGET(item
));
535 gtk_signal_connect(GTK_OBJECT(item
), "select",
536 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
538 gtk_signal_connect(GTK_OBJECT(item
), "deselect",
539 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
541 gtk_signal_connect(GTK_OBJECT(item
), "expand",
542 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback
), (gpointer
)this );
543 gtk_signal_connect(GTK_OBJECT(item
), "collapse",
544 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback
), (gpointer
)this );
549 void wxTreeCtrl::Delete(const wxTreeItemId
& item
) {
553 GtkTreeItem
*parent
= GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem
*)item
)->parent
);
557 gtk_container_remove(GTK_CONTAINER(parent
), GTK_WIDGET((GtkTreeItem
*)item
));
562 void wxTreeCtrl::DeleteAllItems() {
563 gtk_tree_item_remove_subtree(m_anchor
);
566 void wxTreeCtrl::Expand(const wxTreeItemId
& item
) {
570 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
573 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
) {
577 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
580 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
) {
584 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
585 gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem
*)item
));
588 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
) {
592 if (((GtkTreeItem
*)item
)->expanded
)
593 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
595 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
598 static void gtk_treectrl_unselect_callback(GtkWidget
*widget
, gpointer data
) {
601 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
603 if (tree
->selection
!= NULL
) {
604 guint len
= g_list_length(tree
->selection
);
605 for (guint i
=0; i
<len
; i
++) {
606 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->selection
, i
)->data
);
607 gtk_tree_unselect_child(tree
, GTK_WIDGET(p
));
611 if (GTK_IS_CONTAINER(widget
))
612 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_unselect_callback
, data
);
615 void wxTreeCtrl::Unselect() {
616 if (m_anchor
== NULL
)
619 gtk_treectrl_unselect_callback(GTK_WIDGET(m_anchor
), NULL
);
622 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
) {
626 gtk_tree_item_select((GtkTreeItem
*)item
);
629 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
) {
630 #warning "Need to implement EnsureVisible"
633 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
) {
634 #warning "Need to implement ScrollTo"
637 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
638 wxClassInfo
* textControlClass
) {
639 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
640 #warning "Need to implement EditLabel"
645 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label");
646 gtk_label_get(m_label, &s);
648 m_textCtrl = new wxTextCtrl(this, -1, s);
649 // m_textCtrl->SetValue(s);
651 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "w_edit", m_textCtrl->m_widget);
653 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)item), GTK_WIDGET(m_label));
654 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)item), m_textCtrl->m_widget);
660 wxTextCtrl
* wxTreeCtrl::GetEditControl() const {
664 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
) {
665 #warning "Need to implement EndEditLabel"
667 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_label");
668 gtk_label_set(m_label, m_textCtrl->GetValue());
670 gtk_object_remove_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_edit");
672 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)m_editItem), m_textCtrl->m_widget);
673 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)m_editItem), GTK_WIDGET(m_label));
680 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
) {
682 case wxTREE_EXPAND_EXPAND
:
686 case wxTREE_EXPAND_COLLAPSE
:
690 case wxTREE_EXPAND_COLLAPSE_RESET
:
691 CollapseAndReset(item
);
694 case wxTREE_EXPAND_TOGGLE
:
699 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
703 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
704 const wxString
& text
, int image
, int selImage
,
706 // InsertItem(parent, insertAfter, text, image, selImage);
707 #warning "Need to implement InsertItem"
712 long wxTreeCtrl::GetChild(long item) const {
714 GtkTreeItem *next = NULL;
716 p = findGtkTreeItem(item);
717 GList *list = gtk_container_children(GTK_CONTAINER(p));
718 next = GTK_TREE_ITEM(list->data);;
721 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
726 long wxTreeCtrl::GetFirstVisibleItem(void) const {
727 GtkTreeItem *next = NULL;
729 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
730 next = GTK_TREE_ITEM(list->data);;
731 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
734 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
739 long wxTreeCtrl::GetNextVisibleItem(long item) const {
741 GtkTreeItem *next = NULL;
743 p = findGtkTreeItem(item);
744 GList *list = gtk_container_children(GTK_CONTAINER(p));
745 next = GTK_TREE_ITEM(list->data);;
746 // gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
749 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
754 bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
757 p = findGtkTreeItem(info.m_itemId);
760 wxLogSysError("TreeCtrl::GetItem failed");
764 wxConvertFromGtkTreeItem(info, p);
769 bool wxTreeCtrl::SetItem(wxTreeItem& info) {
772 p = findGtkTreeItem(info.m_itemId);
775 wxLogSysError("TreeCtrl::SetItem failed");
779 wxConvertToGtkTreeItem(this, info, &p);
784 int wxTreeCtrl::GetItemState(long item, long stateMask) const {
787 info.m_mask = wxTREE_MASK_STATE ;
788 info.m_stateMask = stateMask;
789 info.m_itemId = item;
797 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
800 info.m_mask = wxTREE_MASK_STATE ;
801 info.m_state = state;
802 info.m_stateMask = stateMask;
803 info.m_itemId = item;
805 return SetItem(info);
811 bool wxTreeCtrl::DeleteChildren(long item) {
814 p = findGtkTreeItem(item);
818 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
825 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
827 GtkTreeItem *item = NULL;
829 info.m_itemId = m_curitemId;
832 wxConvertToGtkTreeItem(this, info, &item);
835 p = findGtkTreeItem(parent);
836 if (p->subtree == NULL) {
837 GtkTree *tree = GTK_TREE(gtk_tree_new());
838 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
839 gtk_widget_show(GTK_WIDGET(tree));
843 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
846 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
849 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
850 GtkTree *tree = GTK_TREE(gtk_tree_new());
851 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
852 gtk_widget_show(GTK_WIDGET(tree));
855 gtk_widget_show(GTK_WIDGET(item));
857 gtk_signal_connect(GTK_OBJECT(item), "select",
858 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
860 gtk_signal_connect(GTK_OBJECT(item), "deselect",
861 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
863 gtk_signal_connect(GTK_OBJECT(item), "expand",
864 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
865 gtk_signal_connect(GTK_OBJECT(item), "collapse",
866 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
868 return info.m_itemId;
871 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
872 int selImage, long insertAfter) {
876 info.m_mask = wxTREE_MASK_TEXT;
878 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
879 info.m_image = image;
881 info.m_selectedImage = image;
883 info.m_selectedImage = selImage;
886 return InsertItem(parent, info, insertAfter);
890 void wxTreeCtrl::SendMessage(wxEventType command
, const wxTreeItemId
& item
) {
891 wxTreeEvent
event(command
, GetId());
892 event
.SetEventObject(this);
897 void wxTreeCtrl::SendExpanding(const wxTreeItemId
& item
) {
898 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING
, item
);
901 void wxTreeCtrl::SendExpanded(const wxTreeItemId
& item
) {
902 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED
, item
);
905 void wxTreeCtrl::SendCollapsing(const wxTreeItemId
& item
) {
906 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, item
);
909 void wxTreeCtrl::SendCollapsed(const wxTreeItemId
& item
) {
910 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, item
);
913 void wxTreeCtrl::SendSelChanging(const wxTreeItemId
& item
) {
914 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED
, item
);
917 void wxTreeCtrl::SendSelChanged(const wxTreeItemId
& item
) {
918 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING
, item
);
922 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
924 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
925 wxCommandEvent(commandType
, id
) {