1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Denis Pershin
8 // Copyright: (c) Denis Pershin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
81 void wxTreeCtrl::Init() {
82 m_imageListNormal
= NULL
;
83 m_imageListState
= NULL
;
87 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
88 const wxSize
& size
, long style
,
89 const wxValidator
& validator
, const wxString
& name
) {
97 m_windowStyle
= style
;
112 printf("precreate\n");
113 PreCreation( parent
, id
, pos
, size
, style
, name
);
117 m_widget
= gtk_scrolled_window_new(NULL
, NULL
);
119 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget
),
120 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
123 m_tree
= GTK_TREE(gtk_tree_new());
126 gtk_container_add(GTK_CONTAINER(m_widget
), GTK_WIDGET(m_tree
));
128 gtk_widget_show(GTK_WIDGET(m_tree
));
131 SetValidator(validator
);
133 printf("Robert's new insertion code :-)\n");
134 m_parent
->DoAddChild( this );
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::GetItemParent(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::GetLastChild(const wxTreeItemId
& item
) const
349 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
350 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
352 wxCHECK_MSG( GTK_IS_TREE(parent
), NULL
, "invalid tree item" );
354 return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent
)->children
)->data
);
357 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const {
358 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
359 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
361 if (!GTK_IS_TREE(parent
))
364 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
367 return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
370 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const {
371 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
372 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
374 if (!GTK_IS_TREE(parent
))
377 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
380 return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
383 static void gtk_treectrl_first_visible_callback(GtkWidget
*widget
, gpointer data
) {
384 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
386 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
388 if (tree
->children
!= NULL
) {
389 guint len
= g_list_length(tree
->children
);
390 for (guint i
=0; i
<len
; i
++) {
391 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
)))) {
392 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
);
398 if (GTK_IS_CONTAINER(widget
))
399 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_visible_callback
, data
);
402 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const {
403 GtkTreeItem
*p
= NULL
;
405 if (m_anchor
== NULL
)
408 gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor
), &p
);
413 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const {
414 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
415 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
418 if (!GTK_IS_TREE(parent
))
421 if (parent
->children
== NULL
)
424 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
427 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
428 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
435 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const {
436 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
437 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
440 if (!GTK_IS_TREE(parent
))
443 if (parent
->children
== NULL
)
446 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
449 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
450 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
457 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
, int image
,
458 int selectedImage
, wxTreeItemData
*data
) {
459 return p_InsertItem(0, text
, image
, selectedImage
, data
);
462 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
463 const wxString
& text
, int image
, int selectedImage
,
464 wxTreeItemData
*data
) {
465 #warning "Need to implement PrependItem"
469 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
470 const wxTreeItemId
& idPrevious
, const wxString
& text
,
471 int image
, int selectedImage
, wxTreeItemData
*data
) {
472 #warning "Need to implement InsertItem"
476 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
477 const wxString
& text
, int image
, int selectedImage
,
478 wxTreeItemData
*data
) {
479 return p_InsertItem(parent
, text
, image
, selectedImage
, data
);
482 wxTreeItemId
wxTreeCtrl::p_InsertItem(GtkTreeItem
*p
,
483 const wxString
& text
, int image
, int selectedImage
,
484 wxTreeItemData
*data
) {
487 printf("begin insert\n");
489 item
= GTK_TREE_ITEM(gtk_tree_item_new());
491 GtkHBox
*m_box
= GTK_HBOX(gtk_hbox_new(FALSE
, 0));
492 gtk_container_add (GTK_CONTAINER (item
), GTK_WIDGET(m_box
));
494 gtk_object_set_data(GTK_OBJECT(item
), "w_box", m_box
);
497 const wxImageList
*list
;
498 if ((list
= GetImageList(wxIMAGE_LIST_NORMAL
)) != NULL
)
499 if ((bmp
= list
->GetBitmapPtr(image
)) != NULL
)
501 GdkBitmap
*mask
= NULL
;
503 mask
= bmp
->GetMask()->GetBitmap();
504 GtkPixmap
*m_image_widget
= GTK_PIXMAP(gtk_pixmap_new(bmp
->GetPixmap(), mask
));
505 gtk_misc_set_alignment (GTK_MISC (m_image_widget
), 0.0, 0.5);
506 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_image_widget
), FALSE
, FALSE
, 0);
507 gtk_object_set_data(GTK_OBJECT(item
), "w_image", (void *)m_image_widget
);
508 gtk_object_set_data(GTK_OBJECT(item
), "image", (void *)image
);
509 gtk_widget_show (GTK_WIDGET(m_image_widget
));
511 GtkLabel
*m_label_widget
= GTK_LABEL(gtk_label_new ((char *)(const char *)text
));
512 gtk_misc_set_alignment (GTK_MISC (m_label_widget
), 0.5, 0.5);
513 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_label_widget
), FALSE
, FALSE
, 0);
514 gtk_object_set_data(GTK_OBJECT(item
), "w_label", m_label_widget
);
515 gtk_widget_show (GTK_WIDGET(m_label_widget
));
517 gtk_widget_show(GTK_WIDGET(m_box
));
519 gtk_object_set_data(GTK_OBJECT(item
), "owner", this);
520 gtk_object_set_data(GTK_OBJECT(item
), "data", data
);
521 gtk_object_set_data(GTK_OBJECT(item
), "parent", p
);
524 if (p
->subtree
== NULL
) {
525 GtkTree
*tree
= GTK_TREE(gtk_tree_new());
526 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p
), GTK_WIDGET(tree
));
527 gtk_widget_show(GTK_WIDGET(tree
));
531 gtk_container_add(GTK_CONTAINER(p
->subtree
), GTK_WIDGET(item
));
533 printf("Adding root\n");
534 printf("m_tree = %p\n", m_tree
);
536 gtk_container_add(GTK_CONTAINER(m_tree
), GTK_WIDGET(item
));
539 gtk_widget_show(GTK_WIDGET(item
));
541 gtk_signal_connect(GTK_OBJECT(item
), "select",
542 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
544 gtk_signal_connect(GTK_OBJECT(item
), "deselect",
545 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
547 gtk_signal_connect(GTK_OBJECT(item
), "expand",
548 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback
), (gpointer
)this );
549 gtk_signal_connect(GTK_OBJECT(item
), "collapse",
550 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback
), (gpointer
)this );
555 void wxTreeCtrl::Delete(const wxTreeItemId
& item
) {
559 GtkTreeItem
*parent
= GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem
*)item
)->parent
);
563 gtk_container_remove(GTK_CONTAINER(parent
), GTK_WIDGET((GtkTreeItem
*)item
));
568 void wxTreeCtrl::DeleteAllItems() {
569 gtk_tree_item_remove_subtree(m_anchor
);
572 void wxTreeCtrl::Expand(const wxTreeItemId
& item
) {
576 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
579 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
) {
583 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
586 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
) {
590 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
591 gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem
*)item
));
594 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
) {
598 if (((GtkTreeItem
*)item
)->expanded
)
599 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
601 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
604 static void gtk_treectrl_unselect_callback(GtkWidget
*widget
, gpointer data
) {
607 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
609 if (tree
->selection
!= NULL
) {
610 guint len
= g_list_length(tree
->selection
);
611 for (guint i
=0; i
<len
; i
++) {
612 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->selection
, i
)->data
);
613 gtk_tree_unselect_child(tree
, GTK_WIDGET(p
));
617 if (GTK_IS_CONTAINER(widget
))
618 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_unselect_callback
, data
);
621 void wxTreeCtrl::Unselect() {
622 if (m_anchor
== NULL
)
625 gtk_treectrl_unselect_callback(GTK_WIDGET(m_anchor
), NULL
);
628 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
) {
632 gtk_tree_item_select((GtkTreeItem
*)item
);
635 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
) {
636 #warning "Need to implement EnsureVisible"
639 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
) {
640 #warning "Need to implement ScrollTo"
643 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
644 wxClassInfo
* textControlClass
) {
645 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
646 #warning "Need to implement EditLabel"
651 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label");
652 gtk_label_get(m_label, &s);
654 m_textCtrl = new wxTextCtrl(this, -1, s);
655 // m_textCtrl->SetValue(s);
657 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "w_edit", m_textCtrl->m_widget);
659 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)item), GTK_WIDGET(m_label));
660 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)item), m_textCtrl->m_widget);
666 wxTextCtrl
* wxTreeCtrl::GetEditControl() const {
670 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
) {
671 #warning "Need to implement EndEditLabel"
673 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_label");
674 gtk_label_set(m_label, m_textCtrl->GetValue());
676 gtk_object_remove_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_edit");
678 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)m_editItem), m_textCtrl->m_widget);
679 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)m_editItem), GTK_WIDGET(m_label));
686 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
) {
688 case wxTREE_EXPAND_EXPAND
:
692 case wxTREE_EXPAND_COLLAPSE
:
696 case wxTREE_EXPAND_COLLAPSE_RESET
:
697 CollapseAndReset(item
);
700 case wxTREE_EXPAND_TOGGLE
:
705 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
709 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
710 const wxString
& text
, int image
, int selImage
,
712 // InsertItem(parent, insertAfter, text, image, selImage);
713 #warning "Need to implement InsertItem"
718 long wxTreeCtrl::GetChild(long item) const {
720 GtkTreeItem *next = NULL;
722 p = findGtkTreeItem(item);
723 GList *list = gtk_container_children(GTK_CONTAINER(p));
724 next = GTK_TREE_ITEM(list->data);;
727 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
732 long wxTreeCtrl::GetFirstVisibleItem(void) const {
733 GtkTreeItem *next = NULL;
735 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
736 next = GTK_TREE_ITEM(list->data);;
737 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
740 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
745 long wxTreeCtrl::GetNextVisibleItem(long item) const {
747 GtkTreeItem *next = NULL;
749 p = findGtkTreeItem(item);
750 GList *list = gtk_container_children(GTK_CONTAINER(p));
751 next = GTK_TREE_ITEM(list->data);;
752 // gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
755 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
760 bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
763 p = findGtkTreeItem(info.m_itemId);
766 wxLogSysError("TreeCtrl::GetItem failed");
770 wxConvertFromGtkTreeItem(info, p);
775 bool wxTreeCtrl::SetItem(wxTreeItem& info) {
778 p = findGtkTreeItem(info.m_itemId);
781 wxLogSysError("TreeCtrl::SetItem failed");
785 wxConvertToGtkTreeItem(this, info, &p);
790 int wxTreeCtrl::GetItemState(long item, long stateMask) const {
793 info.m_mask = wxTREE_MASK_STATE ;
794 info.m_stateMask = stateMask;
795 info.m_itemId = item;
803 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
806 info.m_mask = wxTREE_MASK_STATE ;
807 info.m_state = state;
808 info.m_stateMask = stateMask;
809 info.m_itemId = item;
811 return SetItem(info);
817 bool wxTreeCtrl::DeleteChildren(long item) {
820 p = findGtkTreeItem(item);
824 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
831 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
833 GtkTreeItem *item = NULL;
835 info.m_itemId = m_curitemId;
838 wxConvertToGtkTreeItem(this, info, &item);
841 p = findGtkTreeItem(parent);
842 if (p->subtree == NULL) {
843 GtkTree *tree = GTK_TREE(gtk_tree_new());
844 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
845 gtk_widget_show(GTK_WIDGET(tree));
849 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
852 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
855 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
856 GtkTree *tree = GTK_TREE(gtk_tree_new());
857 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
858 gtk_widget_show(GTK_WIDGET(tree));
861 gtk_widget_show(GTK_WIDGET(item));
863 gtk_signal_connect(GTK_OBJECT(item), "select",
864 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
866 gtk_signal_connect(GTK_OBJECT(item), "deselect",
867 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
869 gtk_signal_connect(GTK_OBJECT(item), "expand",
870 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
871 gtk_signal_connect(GTK_OBJECT(item), "collapse",
872 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
874 return info.m_itemId;
877 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
878 int selImage, long insertAfter) {
882 info.m_mask = wxTREE_MASK_TEXT;
884 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
885 info.m_image = image;
887 info.m_selectedImage = image;
889 info.m_selectedImage = selImage;
892 return InsertItem(parent, info, insertAfter);
896 void wxTreeCtrl::SendMessage(wxEventType command
, const wxTreeItemId
& item
) {
897 wxTreeEvent
event(command
, GetId());
898 event
.SetEventObject(this);
903 void wxTreeCtrl::SendExpanding(const wxTreeItemId
& item
) {
904 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING
, item
);
907 void wxTreeCtrl::SendExpanded(const wxTreeItemId
& item
) {
908 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED
, item
);
911 void wxTreeCtrl::SendCollapsing(const wxTreeItemId
& item
) {
912 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, item
);
915 void wxTreeCtrl::SendCollapsed(const wxTreeItemId
& item
) {
916 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, item
);
919 void wxTreeCtrl::SendSelChanging(const wxTreeItemId
& item
) {
920 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED
, item
);
923 void wxTreeCtrl::SendSelChanged(const wxTreeItemId
& item
) {
924 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING
, item
);
928 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
930 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
931 wxCommandEvent(commandType
, id
) {