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("postcreate\n");
138 gtk_widget_realize(GTK_WIDGET(m_tree
));
145 wxTreeCtrl::~wxTreeCtrl(void) {
151 static void gtk_treectrl_count_callback (GtkWidget
*widget
, gpointer data
) {
152 int count
= (*((int *)data
));
155 if (GTK_IS_CONTAINER(widget
))
156 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_count_callback
, data
);
159 size_t wxTreeCtrl::GetCount() const {
162 if (m_anchor
!= NULL
)
163 gtk_treectrl_count_callback(GTK_WIDGET(m_anchor
), &count
);
167 unsigned int wxTreeCtrl::GetIndent() const {
168 return m_tree
->indent_value
;
171 void wxTreeCtrl::SetIndent(unsigned int indent
) {
172 m_tree
->indent_value
= indent
;
175 wxImageList
*wxTreeCtrl::GetImageList() const {
176 return m_imageListNormal
;
179 wxImageList
*wxTreeCtrl::GetStateImageList() const {
180 return m_imageListState
;
183 void wxTreeCtrl::SetImageList(wxImageList
*imageList
) {
184 m_imageListNormal
= imageList
;
187 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
) {
188 m_imageListState
= imageList
;
191 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
&item
) const {
197 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
198 gtk_label_get(l
, &t
);
203 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
) const {
207 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "image");
210 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& item
) const {
214 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage");
217 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const {
221 return (wxTreeItemData
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "data");
224 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
) {
228 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
229 gtk_label_set(l
, text
);
232 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
) {
236 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "image", (void *)image
);
239 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& item
, int image
) {
243 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage", (void *)image
);
246 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
) {
250 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "data", data
);
253 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const {
254 return GTK_WIDGET_VISIBLE(GTK_TREE_ITEM((GtkTreeItem
*)item
));
257 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const {
258 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
260 if (p
->subtree
== NULL
)
263 if (GTK_TREE(p
->subtree
)->children
== NULL
)
266 if (g_list_length(GTK_TREE(p
->subtree
)->children
) == 0)
272 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const {
273 return (((GtkTreeItem
*)item
)->expanded
!= 0);
276 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const {
277 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
278 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
280 if (!GTK_IS_TREE(parent
))
283 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
289 wxTreeItemId
wxTreeCtrl::GetRootItem() const {
293 static void gtk_treectrl_first_selected_callback(GtkWidget
*widget
, gpointer data
) {
294 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
296 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
298 if (tree
->selection
!= NULL
) {
299 p
= (GtkTreeItem
*)tree
->selection
->data
;
303 if (GTK_IS_CONTAINER(widget
))
304 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_selected_callback
, data
);
307 wxTreeItemId
wxTreeCtrl::GetSelection() const {
308 GtkTreeItem
*p
= NULL
;
310 if (m_anchor
== NULL
)
313 gtk_treectrl_first_selected_callback(GTK_WIDGET(m_anchor
), &p
);
318 wxTreeItemId
wxTreeCtrl::GetParent(const wxTreeItemId
& item
) const {
320 return (GtkTreeItem
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "parent");
325 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const {
326 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
327 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
329 if (!GTK_IS_TREE(parent
))
333 return GTK_TREE_ITEM(g_list_first(GTK_TREE(parent
)->children
)->data
);
336 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& item
, long& cookie
) const {
337 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
338 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
340 if (!GTK_IS_TREE(parent
))
344 return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent
)->children
, cookie
)->data
);
347 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const {
348 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
349 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
351 if (!GTK_IS_TREE(parent
))
354 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
357 return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
360 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const {
361 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
362 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
364 if (!GTK_IS_TREE(parent
))
367 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
370 return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
373 static void gtk_treectrl_first_visible_callback(GtkWidget
*widget
, gpointer data
) {
374 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
376 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
378 if (tree
->children
!= NULL
) {
379 guint len
= g_list_length(tree
->children
);
380 for (guint i
=0; i
<len
; i
++) {
381 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
)))) {
382 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
);
388 if (GTK_IS_CONTAINER(widget
))
389 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_visible_callback
, data
);
392 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const {
393 GtkTreeItem
*p
= NULL
;
395 if (m_anchor
== NULL
)
398 gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor
), &p
);
403 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const {
404 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
405 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
408 if (!GTK_IS_TREE(parent
))
411 if (parent
->children
== NULL
)
414 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
417 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
418 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
425 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const {
426 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
427 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
430 if (!GTK_IS_TREE(parent
))
433 if (parent
->children
== NULL
)
436 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
439 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
440 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
447 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
, int image
,
448 int selectedImage
, wxTreeItemData
*data
) {
449 return p_InsertItem(0, text
, image
, selectedImage
, data
);
452 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
453 const wxString
& text
, int image
, int selectedImage
,
454 wxTreeItemData
*data
) {
455 #warning "Need to implement PrependItem"
459 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
460 const wxTreeItemId
& idPrevious
, const wxString
& text
,
461 int image
, int selectedImage
, wxTreeItemData
*data
) {
462 #warning "Need to implement InsertItem"
466 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
467 const wxString
& text
, int image
, int selectedImage
,
468 wxTreeItemData
*data
) {
469 return p_InsertItem(parent
, text
, image
, selectedImage
, data
);
472 wxTreeItemId
wxTreeCtrl::p_InsertItem(GtkTreeItem
*p
,
473 const wxString
& text
, int image
, int selectedImage
,
474 wxTreeItemData
*data
) {
477 printf("begin insert\n");
479 item
= GTK_TREE_ITEM(gtk_tree_item_new());
481 GtkHBox
*m_box
= GTK_HBOX(gtk_hbox_new(FALSE
, 0));
482 gtk_container_add (GTK_CONTAINER (item
), GTK_WIDGET(m_box
));
484 gtk_object_set_data(GTK_OBJECT(item
), "w_box", m_box
);
487 const wxImageList
*list
;
488 if ((list
= GetImageList(wxIMAGE_LIST_NORMAL
)) != NULL
)
489 if ((bmp
= list
->GetBitmap(image
)) != NULL
)
491 GdkBitmap
*mask
= NULL
;
493 mask
= bmp
->GetMask()->GetBitmap();
494 GtkPixmap
*m_image_widget
= GTK_PIXMAP(gtk_pixmap_new(bmp
->GetPixmap(), mask
));
495 gtk_misc_set_alignment (GTK_MISC (m_image_widget
), 0.0, 0.5);
496 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_image_widget
), FALSE
, FALSE
, 0);
497 gtk_object_set_data(GTK_OBJECT(item
), "w_image", (void *)m_image_widget
);
498 gtk_object_set_data(GTK_OBJECT(item
), "image", (void *)image
);
499 gtk_widget_show (GTK_WIDGET(m_image_widget
));
501 GtkLabel
*m_label_widget
= GTK_LABEL(gtk_label_new ((char *)(const char *)text
));
502 gtk_misc_set_alignment (GTK_MISC (m_label_widget
), 0.5, 0.5);
503 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_label_widget
), FALSE
, FALSE
, 0);
504 gtk_object_set_data(GTK_OBJECT(item
), "w_label", m_label_widget
);
505 gtk_widget_show (GTK_WIDGET(m_label_widget
));
507 gtk_widget_show(GTK_WIDGET(m_box
));
509 gtk_object_set_data(GTK_OBJECT(item
), "owner", this);
510 gtk_object_set_data(GTK_OBJECT(item
), "data", data
);
511 gtk_object_set_data(GTK_OBJECT(item
), "parent", p
);
514 if (p
->subtree
== NULL
) {
515 GtkTree
*tree
= GTK_TREE(gtk_tree_new());
516 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p
), GTK_WIDGET(tree
));
517 gtk_widget_show(GTK_WIDGET(tree
));
521 gtk_container_add(GTK_CONTAINER(p
->subtree
), GTK_WIDGET(item
));
523 printf("Adding root\n");
524 printf("m_tree = %p\n", m_tree
);
526 gtk_container_add(GTK_CONTAINER(m_tree
), GTK_WIDGET(item
));
529 gtk_widget_show(GTK_WIDGET(item
));
531 gtk_signal_connect(GTK_OBJECT(item
), "select",
532 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
534 gtk_signal_connect(GTK_OBJECT(item
), "deselect",
535 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
537 gtk_signal_connect(GTK_OBJECT(item
), "expand",
538 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback
), (gpointer
)this );
539 gtk_signal_connect(GTK_OBJECT(item
), "collapse",
540 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback
), (gpointer
)this );
545 void wxTreeCtrl::Delete(const wxTreeItemId
& item
) {
549 GtkTreeItem
*parent
= GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem
*)item
)->parent
);
553 gtk_container_remove(GTK_CONTAINER(parent
), GTK_WIDGET((GtkTreeItem
*)item
));
558 void wxTreeCtrl::DeleteAllItems() {
559 gtk_tree_item_remove_subtree(m_anchor
);
562 void wxTreeCtrl::Expand(const wxTreeItemId
& item
) {
566 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
569 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
) {
573 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
576 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
) {
580 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
581 gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem
*)item
));
584 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
) {
588 if (((GtkTreeItem
*)item
)->expanded
)
589 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
591 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
594 static void gtk_treectrl_unselect_callback(GtkWidget
*widget
, gpointer data
) {
597 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
599 if (tree
->selection
!= NULL
) {
600 guint len
= g_list_length(tree
->selection
);
601 for (guint i
=0; i
<len
; i
++) {
602 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->selection
, i
)->data
);
603 gtk_tree_unselect_child(tree
, GTK_WIDGET(p
));
607 if (GTK_IS_CONTAINER(widget
))
608 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_unselect_callback
, data
);
611 void wxTreeCtrl::Unselect() {
612 if (m_anchor
== NULL
)
615 gtk_treectrl_unselect_callback(GTK_WIDGET(m_anchor
), NULL
);
618 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
) {
622 gtk_tree_item_select((GtkTreeItem
*)item
);
625 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
) {
626 #warning "Need to implement EnsureVisible"
629 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
) {
630 #warning "Need to implement ScrollTo"
633 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
634 wxClassInfo
* textControlClass
) {
635 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
636 #warning "Need to implement EditLabel"
641 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label");
642 gtk_label_get(m_label, &s);
644 m_textCtrl = new wxTextCtrl(this, -1, s);
645 // m_textCtrl->SetValue(s);
647 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "w_edit", m_textCtrl->m_widget);
649 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)item), GTK_WIDGET(m_label));
650 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)item), m_textCtrl->m_widget);
656 wxTextCtrl
* wxTreeCtrl::GetEditControl() const {
660 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
) {
661 #warning "Need to implement EndEditLabel"
663 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_label");
664 gtk_label_set(m_label, m_textCtrl->GetValue());
666 gtk_object_remove_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_edit");
668 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)m_editItem), m_textCtrl->m_widget);
669 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)m_editItem), GTK_WIDGET(m_label));
676 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
) {
678 case wxTREE_EXPAND_EXPAND
:
682 case wxTREE_EXPAND_COLLAPSE
:
686 case wxTREE_EXPAND_COLLAPSE_RESET
:
687 CollapseAndReset(item
);
690 case wxTREE_EXPAND_TOGGLE
:
695 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
699 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
700 const wxString
& text
, int image
, int selImage
,
702 // InsertItem(parent, insertAfter, text, image, selImage);
703 #warning "Need to implement InsertItem"
708 long wxTreeCtrl::GetChild(long item) const {
710 GtkTreeItem *next = NULL;
712 p = findGtkTreeItem(item);
713 GList *list = gtk_container_children(GTK_CONTAINER(p));
714 next = GTK_TREE_ITEM(list->data);;
717 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
722 long wxTreeCtrl::GetFirstVisibleItem(void) const {
723 GtkTreeItem *next = NULL;
725 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
726 next = GTK_TREE_ITEM(list->data);;
727 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
730 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
735 long wxTreeCtrl::GetNextVisibleItem(long item) const {
737 GtkTreeItem *next = NULL;
739 p = findGtkTreeItem(item);
740 GList *list = gtk_container_children(GTK_CONTAINER(p));
741 next = GTK_TREE_ITEM(list->data);;
742 // gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
745 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
750 bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
753 p = findGtkTreeItem(info.m_itemId);
756 wxLogSysError("TreeCtrl::GetItem failed");
760 wxConvertFromGtkTreeItem(info, p);
765 bool wxTreeCtrl::SetItem(wxTreeItem& info) {
768 p = findGtkTreeItem(info.m_itemId);
771 wxLogSysError("TreeCtrl::SetItem failed");
775 wxConvertToGtkTreeItem(this, info, &p);
780 int wxTreeCtrl::GetItemState(long item, long stateMask) const {
783 info.m_mask = wxTREE_MASK_STATE ;
784 info.m_stateMask = stateMask;
785 info.m_itemId = item;
793 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
796 info.m_mask = wxTREE_MASK_STATE ;
797 info.m_state = state;
798 info.m_stateMask = stateMask;
799 info.m_itemId = item;
801 return SetItem(info);
807 bool wxTreeCtrl::DeleteChildren(long item) {
810 p = findGtkTreeItem(item);
814 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
821 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
823 GtkTreeItem *item = NULL;
825 info.m_itemId = m_curitemId;
828 wxConvertToGtkTreeItem(this, info, &item);
831 p = findGtkTreeItem(parent);
832 if (p->subtree == NULL) {
833 GtkTree *tree = GTK_TREE(gtk_tree_new());
834 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
835 gtk_widget_show(GTK_WIDGET(tree));
839 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
842 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
845 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
846 GtkTree *tree = GTK_TREE(gtk_tree_new());
847 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
848 gtk_widget_show(GTK_WIDGET(tree));
851 gtk_widget_show(GTK_WIDGET(item));
853 gtk_signal_connect(GTK_OBJECT(item), "select",
854 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
856 gtk_signal_connect(GTK_OBJECT(item), "deselect",
857 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
859 gtk_signal_connect(GTK_OBJECT(item), "expand",
860 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
861 gtk_signal_connect(GTK_OBJECT(item), "collapse",
862 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
864 return info.m_itemId;
867 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
868 int selImage, long insertAfter) {
872 info.m_mask = wxTREE_MASK_TEXT;
874 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
875 info.m_image = image;
877 info.m_selectedImage = image;
879 info.m_selectedImage = selImage;
882 return InsertItem(parent, info, insertAfter);
886 void wxTreeCtrl::SendMessage(wxEventType command
, const wxTreeItemId
& item
) {
887 wxTreeEvent
event(command
, GetId());
888 event
.SetEventObject(this);
893 void wxTreeCtrl::SendExpanding(const wxTreeItemId
& item
) {
894 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING
, item
);
897 void wxTreeCtrl::SendExpanded(const wxTreeItemId
& item
) {
898 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED
, item
);
901 void wxTreeCtrl::SendCollapsing(const wxTreeItemId
& item
) {
902 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, item
);
905 void wxTreeCtrl::SendCollapsed(const wxTreeItemId
& item
) {
906 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, item
);
909 void wxTreeCtrl::SendSelChanging(const wxTreeItemId
& item
) {
910 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED
, item
);
913 void wxTreeCtrl::SendSelChanged(const wxTreeItemId
& item
) {
914 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING
, item
);
918 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
920 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
921 wxCommandEvent(commandType
, id
) {