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
->DoAddChild( this );
137 printf("postcreate\n");
140 gtk_widget_realize(GTK_WIDGET(m_tree
));
147 wxTreeCtrl::~wxTreeCtrl(void) {
153 static void gtk_treectrl_count_callback (GtkWidget
*widget
, gpointer data
) {
154 int count
= (*((int *)data
));
157 if (GTK_IS_CONTAINER(widget
))
158 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_count_callback
, data
);
161 size_t wxTreeCtrl::GetCount() const {
164 if (m_anchor
!= NULL
)
165 gtk_treectrl_count_callback(GTK_WIDGET(m_anchor
), &count
);
169 unsigned int wxTreeCtrl::GetIndent() const {
170 return m_tree
->indent_value
;
173 void wxTreeCtrl::SetIndent(unsigned int indent
) {
174 m_tree
->indent_value
= indent
;
177 wxImageList
*wxTreeCtrl::GetImageList() const {
178 return m_imageListNormal
;
181 wxImageList
*wxTreeCtrl::GetStateImageList() const {
182 return m_imageListState
;
185 void wxTreeCtrl::SetImageList(wxImageList
*imageList
) {
186 m_imageListNormal
= imageList
;
189 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
) {
190 m_imageListState
= imageList
;
193 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
&item
) const {
199 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
200 gtk_label_get(l
, &t
);
205 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
) const {
209 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "image");
212 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& item
) const {
216 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage");
219 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const {
223 return (wxTreeItemData
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "data");
226 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
) {
230 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
231 gtk_label_set(l
, text
);
234 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
) {
238 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "image", (void *)image
);
241 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& item
, int image
) {
245 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage", (void *)image
);
248 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
) {
252 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "data", data
);
255 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const {
256 return GTK_WIDGET_VISIBLE(GTK_TREE_ITEM((GtkTreeItem
*)item
));
259 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const {
260 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
262 if (p
->subtree
== NULL
)
265 if (GTK_TREE(p
->subtree
)->children
== NULL
)
268 if (g_list_length(GTK_TREE(p
->subtree
)->children
) == 0)
274 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const {
275 return (((GtkTreeItem
*)item
)->expanded
!= 0);
278 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const {
279 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
280 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
282 if (!GTK_IS_TREE(parent
))
285 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
291 wxTreeItemId
wxTreeCtrl::GetRootItem() const {
295 static void gtk_treectrl_first_selected_callback(GtkWidget
*widget
, gpointer data
) {
296 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
298 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
300 if (tree
->selection
!= NULL
) {
301 p
= (GtkTreeItem
*)tree
->selection
->data
;
305 if (GTK_IS_CONTAINER(widget
))
306 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_selected_callback
, data
);
309 wxTreeItemId
wxTreeCtrl::GetSelection() const {
310 GtkTreeItem
*p
= NULL
;
312 if (m_anchor
== NULL
)
315 gtk_treectrl_first_selected_callback(GTK_WIDGET(m_anchor
), &p
);
320 wxTreeItemId
wxTreeCtrl::GetParent(const wxTreeItemId
& item
) const {
322 return (GtkTreeItem
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "parent");
327 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const {
328 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
329 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
331 if (!GTK_IS_TREE(parent
))
335 return GTK_TREE_ITEM(g_list_first(GTK_TREE(parent
)->children
)->data
);
338 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& item
, long& cookie
) const {
339 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
340 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
342 if (!GTK_IS_TREE(parent
))
346 return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent
)->children
, cookie
)->data
);
349 wxTreeItemId
wxTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
351 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
352 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
354 wxCHECK_MSG( GTK_IS_TREE(parent
), NULL
, "invalid tree item" );
356 return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent
)->children
)->data
);
359 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const {
360 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
361 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
363 if (!GTK_IS_TREE(parent
))
366 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
369 return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
372 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const {
373 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
374 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
376 if (!GTK_IS_TREE(parent
))
379 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
382 return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
385 static void gtk_treectrl_first_visible_callback(GtkWidget
*widget
, gpointer data
) {
386 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
388 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
390 if (tree
->children
!= NULL
) {
391 guint len
= g_list_length(tree
->children
);
392 for (guint i
=0; i
<len
; i
++) {
393 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
)))) {
394 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
);
400 if (GTK_IS_CONTAINER(widget
))
401 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_visible_callback
, data
);
404 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const {
405 GtkTreeItem
*p
= NULL
;
407 if (m_anchor
== NULL
)
410 gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor
), &p
);
415 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const {
416 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
417 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
420 if (!GTK_IS_TREE(parent
))
423 if (parent
->children
== NULL
)
426 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
429 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
430 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
437 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const {
438 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
439 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
442 if (!GTK_IS_TREE(parent
))
445 if (parent
->children
== NULL
)
448 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
451 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
452 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
459 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
, int image
,
460 int selectedImage
, wxTreeItemData
*data
) {
461 return p_InsertItem(0, text
, image
, selectedImage
, data
);
464 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
465 const wxString
& text
, int image
, int selectedImage
,
466 wxTreeItemData
*data
) {
467 #warning "Need to implement PrependItem"
471 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
472 const wxTreeItemId
& idPrevious
, const wxString
& text
,
473 int image
, int selectedImage
, wxTreeItemData
*data
) {
474 #warning "Need to implement InsertItem"
478 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
479 const wxString
& text
, int image
, int selectedImage
,
480 wxTreeItemData
*data
) {
481 return p_InsertItem(parent
, text
, image
, selectedImage
, data
);
484 wxTreeItemId
wxTreeCtrl::p_InsertItem(GtkTreeItem
*p
,
485 const wxString
& text
, int image
, int selectedImage
,
486 wxTreeItemData
*data
) {
489 printf("begin insert\n");
491 item
= GTK_TREE_ITEM(gtk_tree_item_new());
493 GtkHBox
*m_box
= GTK_HBOX(gtk_hbox_new(FALSE
, 0));
494 gtk_container_add (GTK_CONTAINER (item
), GTK_WIDGET(m_box
));
496 gtk_object_set_data(GTK_OBJECT(item
), "w_box", m_box
);
499 const wxImageList
*list
;
500 if ((list
= GetImageList(wxIMAGE_LIST_NORMAL
)) != NULL
)
501 if ((bmp
= list
->GetBitmap(image
)) != NULL
)
503 GdkBitmap
*mask
= NULL
;
505 mask
= bmp
->GetMask()->GetBitmap();
506 GtkPixmap
*m_image_widget
= GTK_PIXMAP(gtk_pixmap_new(bmp
->GetPixmap(), mask
));
507 gtk_misc_set_alignment (GTK_MISC (m_image_widget
), 0.0, 0.5);
508 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_image_widget
), FALSE
, FALSE
, 0);
509 gtk_object_set_data(GTK_OBJECT(item
), "w_image", (void *)m_image_widget
);
510 gtk_object_set_data(GTK_OBJECT(item
), "image", (void *)image
);
511 gtk_widget_show (GTK_WIDGET(m_image_widget
));
513 GtkLabel
*m_label_widget
= GTK_LABEL(gtk_label_new ((char *)(const char *)text
));
514 gtk_misc_set_alignment (GTK_MISC (m_label_widget
), 0.5, 0.5);
515 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_label_widget
), FALSE
, FALSE
, 0);
516 gtk_object_set_data(GTK_OBJECT(item
), "w_label", m_label_widget
);
517 gtk_widget_show (GTK_WIDGET(m_label_widget
));
519 gtk_widget_show(GTK_WIDGET(m_box
));
521 gtk_object_set_data(GTK_OBJECT(item
), "owner", this);
522 gtk_object_set_data(GTK_OBJECT(item
), "data", data
);
523 gtk_object_set_data(GTK_OBJECT(item
), "parent", p
);
526 if (p
->subtree
== NULL
) {
527 GtkTree
*tree
= GTK_TREE(gtk_tree_new());
528 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p
), GTK_WIDGET(tree
));
529 gtk_widget_show(GTK_WIDGET(tree
));
533 gtk_container_add(GTK_CONTAINER(p
->subtree
), GTK_WIDGET(item
));
535 printf("Adding root\n");
536 printf("m_tree = %p\n", m_tree
);
538 gtk_container_add(GTK_CONTAINER(m_tree
), GTK_WIDGET(item
));
541 gtk_widget_show(GTK_WIDGET(item
));
543 gtk_signal_connect(GTK_OBJECT(item
), "select",
544 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
546 gtk_signal_connect(GTK_OBJECT(item
), "deselect",
547 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
549 gtk_signal_connect(GTK_OBJECT(item
), "expand",
550 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback
), (gpointer
)this );
551 gtk_signal_connect(GTK_OBJECT(item
), "collapse",
552 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback
), (gpointer
)this );
557 void wxTreeCtrl::Delete(const wxTreeItemId
& item
) {
561 GtkTreeItem
*parent
= GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem
*)item
)->parent
);
565 gtk_container_remove(GTK_CONTAINER(parent
), GTK_WIDGET((GtkTreeItem
*)item
));
570 void wxTreeCtrl::DeleteAllItems() {
571 gtk_tree_item_remove_subtree(m_anchor
);
574 void wxTreeCtrl::Expand(const wxTreeItemId
& item
) {
578 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
581 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
) {
585 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
588 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
) {
592 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
593 gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem
*)item
));
596 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
) {
600 if (((GtkTreeItem
*)item
)->expanded
)
601 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
603 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
606 static void gtk_treectrl_unselect_callback(GtkWidget
*widget
, gpointer data
) {
609 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
611 if (tree
->selection
!= NULL
) {
612 guint len
= g_list_length(tree
->selection
);
613 for (guint i
=0; i
<len
; i
++) {
614 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->selection
, i
)->data
);
615 gtk_tree_unselect_child(tree
, GTK_WIDGET(p
));
619 if (GTK_IS_CONTAINER(widget
))
620 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_unselect_callback
, data
);
623 void wxTreeCtrl::Unselect() {
624 if (m_anchor
== NULL
)
627 gtk_treectrl_unselect_callback(GTK_WIDGET(m_anchor
), NULL
);
630 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
) {
634 gtk_tree_item_select((GtkTreeItem
*)item
);
637 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
) {
638 #warning "Need to implement EnsureVisible"
641 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
) {
642 #warning "Need to implement ScrollTo"
645 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
646 wxClassInfo
* textControlClass
) {
647 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
648 #warning "Need to implement EditLabel"
653 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label");
654 gtk_label_get(m_label, &s);
656 m_textCtrl = new wxTextCtrl(this, -1, s);
657 // m_textCtrl->SetValue(s);
659 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "w_edit", m_textCtrl->m_widget);
661 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)item), GTK_WIDGET(m_label));
662 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)item), m_textCtrl->m_widget);
668 wxTextCtrl
* wxTreeCtrl::GetEditControl() const {
672 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
) {
673 #warning "Need to implement EndEditLabel"
675 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_label");
676 gtk_label_set(m_label, m_textCtrl->GetValue());
678 gtk_object_remove_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_edit");
680 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)m_editItem), m_textCtrl->m_widget);
681 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)m_editItem), GTK_WIDGET(m_label));
688 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
) {
690 case wxTREE_EXPAND_EXPAND
:
694 case wxTREE_EXPAND_COLLAPSE
:
698 case wxTREE_EXPAND_COLLAPSE_RESET
:
699 CollapseAndReset(item
);
702 case wxTREE_EXPAND_TOGGLE
:
707 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
711 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
712 const wxString
& text
, int image
, int selImage
,
714 // InsertItem(parent, insertAfter, text, image, selImage);
715 #warning "Need to implement InsertItem"
720 long wxTreeCtrl::GetChild(long item) const {
722 GtkTreeItem *next = NULL;
724 p = findGtkTreeItem(item);
725 GList *list = gtk_container_children(GTK_CONTAINER(p));
726 next = GTK_TREE_ITEM(list->data);;
729 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
734 long wxTreeCtrl::GetFirstVisibleItem(void) const {
735 GtkTreeItem *next = NULL;
737 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
738 next = GTK_TREE_ITEM(list->data);;
739 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
742 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
747 long wxTreeCtrl::GetNextVisibleItem(long item) const {
749 GtkTreeItem *next = NULL;
751 p = findGtkTreeItem(item);
752 GList *list = gtk_container_children(GTK_CONTAINER(p));
753 next = GTK_TREE_ITEM(list->data);;
754 // gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
757 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
762 bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
765 p = findGtkTreeItem(info.m_itemId);
768 wxLogSysError("TreeCtrl::GetItem failed");
772 wxConvertFromGtkTreeItem(info, p);
777 bool wxTreeCtrl::SetItem(wxTreeItem& info) {
780 p = findGtkTreeItem(info.m_itemId);
783 wxLogSysError("TreeCtrl::SetItem failed");
787 wxConvertToGtkTreeItem(this, info, &p);
792 int wxTreeCtrl::GetItemState(long item, long stateMask) const {
795 info.m_mask = wxTREE_MASK_STATE ;
796 info.m_stateMask = stateMask;
797 info.m_itemId = item;
805 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
808 info.m_mask = wxTREE_MASK_STATE ;
809 info.m_state = state;
810 info.m_stateMask = stateMask;
811 info.m_itemId = item;
813 return SetItem(info);
819 bool wxTreeCtrl::DeleteChildren(long item) {
822 p = findGtkTreeItem(item);
826 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
833 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
835 GtkTreeItem *item = NULL;
837 info.m_itemId = m_curitemId;
840 wxConvertToGtkTreeItem(this, info, &item);
843 p = findGtkTreeItem(parent);
844 if (p->subtree == NULL) {
845 GtkTree *tree = GTK_TREE(gtk_tree_new());
846 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
847 gtk_widget_show(GTK_WIDGET(tree));
851 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
854 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
857 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
858 GtkTree *tree = GTK_TREE(gtk_tree_new());
859 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
860 gtk_widget_show(GTK_WIDGET(tree));
863 gtk_widget_show(GTK_WIDGET(item));
865 gtk_signal_connect(GTK_OBJECT(item), "select",
866 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
868 gtk_signal_connect(GTK_OBJECT(item), "deselect",
869 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
871 gtk_signal_connect(GTK_OBJECT(item), "expand",
872 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
873 gtk_signal_connect(GTK_OBJECT(item), "collapse",
874 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
876 return info.m_itemId;
879 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
880 int selImage, long insertAfter) {
884 info.m_mask = wxTREE_MASK_TEXT;
886 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
887 info.m_image = image;
889 info.m_selectedImage = image;
891 info.m_selectedImage = selImage;
894 return InsertItem(parent, info, insertAfter);
898 void wxTreeCtrl::SendMessage(wxEventType command
, const wxTreeItemId
& item
) {
899 wxTreeEvent
event(command
, GetId());
900 event
.SetEventObject(this);
905 void wxTreeCtrl::SendExpanding(const wxTreeItemId
& item
) {
906 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING
, item
);
909 void wxTreeCtrl::SendExpanded(const wxTreeItemId
& item
) {
910 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED
, item
);
913 void wxTreeCtrl::SendCollapsing(const wxTreeItemId
& item
) {
914 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, item
);
917 void wxTreeCtrl::SendCollapsed(const wxTreeItemId
& item
) {
918 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, item
);
921 void wxTreeCtrl::SendSelChanging(const wxTreeItemId
& item
) {
922 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED
, item
);
925 void wxTreeCtrl::SendSelChanged(const wxTreeItemId
& item
) {
926 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING
, item
);
930 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
932 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
933 wxCommandEvent(commandType
, id
) {