1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Denis Pershin
8 // Copyright: (c) Denis Pershin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/gtk/treectrl.h"
24 #include "wx/textctrl.h"
29 //static void wxConvertToGtkTreeItem(wxTreeCtrl *owner, wxTreeItem& info, GtkTreeItem **gtkItem);
30 //static void wxConvertFromGtkTreeItem(wxTreeItem& info, GtkTreeItem *gtkItem);
32 static void gtk_treectrl_count_callback (GtkWidget
*widget
, gpointer data
);
33 static void gtk_treectrl_first_selected_callback(GtkWidget
*widget
, gpointer data
);
34 static void gtk_treectrl_first_visible_callback(GtkWidget
*widget
, gpointer data
);
36 // static void gtk_treectrl_next_callback (GtkWidget *widget, gpointer data);
37 // static void gtk_treectrl_next_visible_callback (GtkWidget *widget, gpointer data);
38 // static void gtk_treectrl_next_selected_callback (GtkWidget *widget, gpointer data);
40 static void gtk_treeitem_expand_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
);
41 static void gtk_treeitem_collapse_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
);
42 static void gtk_treeitem_select_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
);
44 static void gtk_treeitem_expand_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
) {
45 wxTreeCtrl
*owner
= (wxTreeCtrl
*)gtk_object_get_data(GTK_OBJECT(widget
), "owner");
49 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
50 owner
->SendExpanding(GTK_TREE_ITEM(widget
));
51 owner
->SendExpanded(GTK_TREE_ITEM(widget
));
54 static void gtk_treeitem_collapse_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
) {
55 wxTreeCtrl
*owner
= (wxTreeCtrl
*)gtk_object_get_data(GTK_OBJECT(widget
), "owner");
59 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
60 owner
->SendCollapsing(GTK_TREE_ITEM(widget
));
61 owner
->SendCollapsed(GTK_TREE_ITEM(widget
));
64 static void gtk_treeitem_select_callback(GtkWidget
*widget
, wxTreeItemId
*treeitem
) {
65 wxTreeCtrl
*owner
= (wxTreeCtrl
*)gtk_object_get_data(GTK_OBJECT(widget
), "owner");
69 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
70 owner
->SendSelChanging(GTK_TREE_ITEM(widget
));
71 owner
->SendSelChanged(GTK_TREE_ITEM(widget
));
74 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
77 void wxTreeCtrl::Init() {
78 m_imageListNormal
= NULL
;
79 m_imageListState
= NULL
;
83 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
,
84 const wxSize
& size
, long style
,
85 const wxValidator
& validator
, const wxString
& name
) {
93 m_windowStyle
= style
;
108 printf("precreate\n");
109 PreCreation( parent
, id
, pos
, size
, style
, name
);
113 m_widget
= gtk_scrolled_window_new(NULL
, NULL
);
115 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget
),
116 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
119 m_tree
= GTK_TREE(gtk_tree_new());
122 gtk_container_add(GTK_CONTAINER(m_widget
), GTK_WIDGET(m_tree
));
124 gtk_widget_show(GTK_WIDGET(m_tree
));
127 SetValidator(validator
);
129 printf("Robert's new insertion code :-)\n");
130 m_parent
->DoAddChild( this );
131 printf("postcreate\n");
134 gtk_widget_realize(GTK_WIDGET(m_tree
));
141 wxTreeCtrl::~wxTreeCtrl(void) {
147 static void gtk_treectrl_count_callback (GtkWidget
*widget
, gpointer data
) {
148 int count
= (*((int *)data
));
151 if (GTK_IS_CONTAINER(widget
))
152 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_count_callback
, data
);
155 size_t wxTreeCtrl::GetCount() const {
158 if (m_anchor
!= NULL
)
159 gtk_treectrl_count_callback(GTK_WIDGET(m_anchor
), &count
);
163 unsigned int wxTreeCtrl::GetIndent() const {
164 return m_tree
->indent_value
;
167 void wxTreeCtrl::SetIndent(unsigned int indent
) {
168 m_tree
->indent_value
= indent
;
171 wxImageList
*wxTreeCtrl::GetImageList() const {
172 return m_imageListNormal
;
175 wxImageList
*wxTreeCtrl::GetStateImageList() const {
176 return m_imageListState
;
179 void wxTreeCtrl::SetImageList(wxImageList
*imageList
) {
180 m_imageListNormal
= imageList
;
183 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
) {
184 m_imageListState
= imageList
;
187 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
&item
) const {
193 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
194 gtk_label_get(l
, &t
);
199 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
) const {
203 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "image");
206 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& item
) const {
210 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage");
213 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const {
217 return (wxTreeItemData
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "data");
220 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
) {
224 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
225 gtk_label_set(l
, text
);
228 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
) {
232 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "image", (void *)image
);
235 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& item
, int image
) {
239 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage", (void *)image
);
242 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
) {
246 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "data", data
);
249 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const {
250 return GTK_WIDGET_VISIBLE(GTK_TREE_ITEM((GtkTreeItem
*)item
));
253 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const {
254 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
256 if (p
->subtree
== NULL
)
259 if (GTK_TREE(p
->subtree
)->children
== NULL
)
262 if (g_list_length(GTK_TREE(p
->subtree
)->children
) == 0)
268 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const {
269 return (((GtkTreeItem
*)item
)->expanded
!= 0);
272 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const {
273 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
274 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
276 if (!GTK_IS_TREE(parent
))
279 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
285 wxTreeItemId
wxTreeCtrl::GetRootItem() const {
289 static void gtk_treectrl_first_selected_callback(GtkWidget
*widget
, gpointer data
) {
290 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
292 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
294 if (tree
->selection
!= NULL
) {
295 p
= (GtkTreeItem
*)tree
->selection
->data
;
299 if (GTK_IS_CONTAINER(widget
))
300 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_selected_callback
, data
);
303 wxTreeItemId
wxTreeCtrl::GetSelection() const {
304 GtkTreeItem
*p
= NULL
;
306 if (m_anchor
== NULL
)
309 gtk_treectrl_first_selected_callback(GTK_WIDGET(m_anchor
), &p
);
314 wxTreeItemId
wxTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const {
316 return (GtkTreeItem
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "parent");
321 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const {
322 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
323 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
325 if (!GTK_IS_TREE(parent
))
329 return GTK_TREE_ITEM(g_list_first(GTK_TREE(parent
)->children
)->data
);
332 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& item
, long& cookie
) const {
333 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
334 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
336 if (!GTK_IS_TREE(parent
))
340 return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent
)->children
, cookie
)->data
);
343 wxTreeItemId
wxTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
345 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
346 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
348 wxCHECK_MSG( GTK_IS_TREE(parent
), NULL
, "invalid tree item" );
350 return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent
)->children
)->data
);
353 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const {
354 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
355 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
357 if (!GTK_IS_TREE(parent
))
360 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
363 return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
366 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const {
367 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
368 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
370 if (!GTK_IS_TREE(parent
))
373 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
376 return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
379 static void gtk_treectrl_first_visible_callback(GtkWidget
*widget
, gpointer data
) {
380 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
382 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
384 if (tree
->children
!= NULL
) {
385 guint len
= g_list_length(tree
->children
);
386 for (guint i
=0; i
<len
; i
++) {
387 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
)))) {
388 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
);
394 if (GTK_IS_CONTAINER(widget
))
395 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_visible_callback
, data
);
398 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const {
399 GtkTreeItem
*p
= NULL
;
401 if (m_anchor
== NULL
)
404 gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor
), &p
);
409 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const {
410 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
411 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
414 if (!GTK_IS_TREE(parent
))
417 if (parent
->children
== NULL
)
420 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
423 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
424 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
431 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const {
432 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
433 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
436 if (!GTK_IS_TREE(parent
))
439 if (parent
->children
== NULL
)
442 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
445 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
446 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
453 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
, int image
,
454 int selectedImage
, wxTreeItemData
*data
) {
455 return p_InsertItem(0, text
, image
, selectedImage
, data
);
458 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
459 const wxString
& text
, int image
, int selectedImage
,
460 wxTreeItemData
*data
) {
461 #warning "Need to implement PrependItem"
465 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
466 const wxTreeItemId
& idPrevious
, const wxString
& text
,
467 int image
, int selectedImage
, wxTreeItemData
*data
) {
468 #warning "Need to implement InsertItem"
472 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
473 const wxString
& text
, int image
, int selectedImage
,
474 wxTreeItemData
*data
) {
475 return p_InsertItem(parent
, text
, image
, selectedImage
, data
);
478 wxTreeItemId
wxTreeCtrl::p_InsertItem(GtkTreeItem
*p
,
479 const wxString
& text
, int image
, int selectedImage
,
480 wxTreeItemData
*data
) {
483 printf("begin insert\n");
485 item
= GTK_TREE_ITEM(gtk_tree_item_new());
487 GtkHBox
*m_box
= GTK_HBOX(gtk_hbox_new(FALSE
, 0));
488 gtk_container_add (GTK_CONTAINER (item
), GTK_WIDGET(m_box
));
490 gtk_object_set_data(GTK_OBJECT(item
), "w_box", m_box
);
493 const wxImageList
*list
;
494 if ((list
= GetImageList(wxIMAGE_LIST_NORMAL
)) != NULL
)
495 if ((bmp
= list
->GetBitmapPtr(image
)) != NULL
)
497 GdkBitmap
*mask
= NULL
;
499 mask
= bmp
->GetMask()->GetBitmap();
500 GtkPixmap
*m_image_widget
= GTK_PIXMAP(gtk_pixmap_new(bmp
->GetPixmap(), mask
));
501 gtk_misc_set_alignment (GTK_MISC (m_image_widget
), 0.0, 0.5);
502 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_image_widget
), FALSE
, FALSE
, 0);
503 gtk_object_set_data(GTK_OBJECT(item
), "w_image", (void *)m_image_widget
);
504 gtk_object_set_data(GTK_OBJECT(item
), "image", (void *)image
);
505 gtk_widget_show (GTK_WIDGET(m_image_widget
));
507 GtkLabel
*m_label_widget
= GTK_LABEL(gtk_label_new ((char *)(const char *)text
));
508 gtk_misc_set_alignment (GTK_MISC (m_label_widget
), 0.5, 0.5);
509 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_label_widget
), FALSE
, FALSE
, 0);
510 gtk_object_set_data(GTK_OBJECT(item
), "w_label", m_label_widget
);
511 gtk_widget_show (GTK_WIDGET(m_label_widget
));
513 gtk_widget_show(GTK_WIDGET(m_box
));
515 gtk_object_set_data(GTK_OBJECT(item
), "owner", this);
516 gtk_object_set_data(GTK_OBJECT(item
), "data", data
);
517 gtk_object_set_data(GTK_OBJECT(item
), "parent", p
);
520 if (p
->subtree
== NULL
) {
521 GtkTree
*tree
= GTK_TREE(gtk_tree_new());
522 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p
), GTK_WIDGET(tree
));
523 gtk_widget_show(GTK_WIDGET(tree
));
527 gtk_container_add(GTK_CONTAINER(p
->subtree
), GTK_WIDGET(item
));
529 printf("Adding root\n");
530 printf("m_tree = %p\n", m_tree
);
532 gtk_container_add(GTK_CONTAINER(m_tree
), GTK_WIDGET(item
));
535 gtk_widget_show(GTK_WIDGET(item
));
537 g_signal_connect (item
, "select",
538 G_CALLBACK (gtk_treeitem_select_callback
), this);
539 g_signal_connect (item
, "deselect",
540 G_CALLBACK (gtk_treeitem_select_callback
), this);
541 g_signal_connect (item
, "expand",
542 G_CALLBACK (gtk_treeitem_expand_callback
), this);
543 g_signal_connect (item
, "collapse",
544 G_CALLBACK (gtk_treeitem_collapse_callback
), 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 g_signal_connect (item, "select",
858 G_CALLBACK (gtk_treeitem_select_callback), this);
859 g_signal_connect (item, "deselect",
860 G_CALLBACK (gtk_treeitem_select_callback), this);
861 g_signal_connect (item, "expand",
862 G_CALLBACK (gtk_treeitem_expand_callback), this);
863 g_signal_connect (item, "collapse",
864 G_CALLBACK (gtk_treeitem_collapse_callback), this);
866 return info.m_itemId;
869 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
870 int selImage, long insertAfter) {
874 info.m_mask = wxTREE_MASK_TEXT;
876 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
877 info.m_image = image;
879 info.m_selectedImage = image;
881 info.m_selectedImage = selImage;
884 return InsertItem(parent, info, insertAfter);
888 void wxTreeCtrl::SendMessage(wxEventType command
, const wxTreeItemId
& item
) {
889 wxTreeEvent
event(command
, GetId());
890 event
.SetEventObject(this);
895 void wxTreeCtrl::SendExpanding(const wxTreeItemId
& item
) {
896 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING
, item
);
899 void wxTreeCtrl::SendExpanded(const wxTreeItemId
& item
) {
900 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED
, item
);
903 void wxTreeCtrl::SendCollapsing(const wxTreeItemId
& item
) {
904 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, item
);
907 void wxTreeCtrl::SendCollapsed(const wxTreeItemId
& item
) {
908 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, item
);
911 void wxTreeCtrl::SendSelChanging(const wxTreeItemId
& item
) {
912 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED
, item
);
915 void wxTreeCtrl::SendSelChanged(const wxTreeItemId
& item
) {
916 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING
, item
);
920 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
922 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
923 wxCommandEvent(commandType
, id
) {