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/gtk1/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 unsigned int wxTreeCtrl::GetCount() const
159 if (m_anchor
!= NULL
)
160 gtk_treectrl_count_callback(GTK_WIDGET(m_anchor
), &count
);
162 return (unsigned int)count
;
165 unsigned int wxTreeCtrl::GetIndent() const {
166 return m_tree
->indent_value
;
169 void wxTreeCtrl::SetIndent(unsigned int indent
) {
170 m_tree
->indent_value
= indent
;
173 wxImageList
*wxTreeCtrl::GetImageList() const {
174 return m_imageListNormal
;
177 wxImageList
*wxTreeCtrl::GetStateImageList() const {
178 return m_imageListState
;
181 void wxTreeCtrl::SetImageList(wxImageList
*imageList
) {
182 m_imageListNormal
= imageList
;
185 void wxTreeCtrl::SetStateImageList(wxImageList
*imageList
) {
186 m_imageListState
= imageList
;
189 wxString
wxTreeCtrl::GetItemText(const wxTreeItemId
&item
) const {
195 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
196 gtk_label_get(l
, &t
);
201 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
) const {
205 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "image");
208 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& item
) const {
212 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage");
215 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const {
219 return (wxTreeItemData
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "data");
222 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
) {
226 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
227 gtk_label_set(l
, text
);
230 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
) {
234 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "image", (void *)image
);
237 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& item
, int image
) {
241 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage", (void *)image
);
244 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
) {
248 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "data", data
);
251 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const {
252 return GTK_WIDGET_VISIBLE(GTK_TREE_ITEM((GtkTreeItem
*)item
));
255 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const {
256 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
258 if (p
->subtree
== NULL
)
261 if (GTK_TREE(p
->subtree
)->children
== NULL
)
264 if (g_list_length(GTK_TREE(p
->subtree
)->children
) == 0)
270 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const {
271 return (((GtkTreeItem
*)item
)->expanded
!= 0);
274 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const {
275 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
276 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
278 if (!GTK_IS_TREE(parent
))
281 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
287 wxTreeItemId
wxTreeCtrl::GetRootItem() const {
291 static void gtk_treectrl_first_selected_callback(GtkWidget
*widget
, gpointer data
) {
292 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
294 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
296 if (tree
->selection
!= NULL
) {
297 p
= (GtkTreeItem
*)tree
->selection
->data
;
301 if (GTK_IS_CONTAINER(widget
))
302 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_selected_callback
, data
);
305 wxTreeItemId
wxTreeCtrl::GetSelection() const {
306 GtkTreeItem
*p
= NULL
;
308 if (m_anchor
== NULL
)
311 gtk_treectrl_first_selected_callback(GTK_WIDGET(m_anchor
), &p
);
316 wxTreeItemId
wxTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const {
318 return (GtkTreeItem
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "parent");
323 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const {
324 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
325 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
327 if (!GTK_IS_TREE(parent
))
331 return GTK_TREE_ITEM(g_list_first(GTK_TREE(parent
)->children
)->data
);
334 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& item
, long& cookie
) const {
335 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
336 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
338 if (!GTK_IS_TREE(parent
))
342 return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent
)->children
, cookie
)->data
);
345 wxTreeItemId
wxTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
347 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
348 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
350 wxCHECK_MSG( GTK_IS_TREE(parent
), NULL
, "invalid tree item" );
352 return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent
)->children
)->data
);
355 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const {
356 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
357 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
359 if (!GTK_IS_TREE(parent
))
362 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
365 return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
368 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const {
369 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
370 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
372 if (!GTK_IS_TREE(parent
))
375 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
378 return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
381 static void gtk_treectrl_first_visible_callback(GtkWidget
*widget
, gpointer data
) {
382 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
384 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
386 if (tree
->children
!= NULL
) {
387 guint len
= g_list_length(tree
->children
);
388 for (guint i
=0; i
<len
; i
++) {
389 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
)))) {
390 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
);
396 if (GTK_IS_CONTAINER(widget
))
397 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_visible_callback
, data
);
400 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const {
401 GtkTreeItem
*p
= NULL
;
403 if (m_anchor
== NULL
)
406 gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor
), &p
);
411 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const {
412 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
413 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
416 if (!GTK_IS_TREE(parent
))
419 if (parent
->children
== NULL
)
422 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
425 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
426 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
433 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const {
434 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
435 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
438 if (!GTK_IS_TREE(parent
))
441 if (parent
->children
== NULL
)
444 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
447 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
448 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
455 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
, int image
,
456 int selectedImage
, wxTreeItemData
*data
) {
457 return p_InsertItem(0, text
, image
, selectedImage
, data
);
460 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
461 const wxString
& text
, int image
, int selectedImage
,
462 wxTreeItemData
*data
) {
463 #warning "Need to implement PrependItem"
467 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
468 const wxTreeItemId
& idPrevious
, const wxString
& text
,
469 int image
, int selectedImage
, wxTreeItemData
*data
) {
470 #warning "Need to implement InsertItem"
474 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
475 const wxString
& text
, int image
, int selectedImage
,
476 wxTreeItemData
*data
) {
477 return p_InsertItem(parent
, text
, image
, selectedImage
, data
);
480 wxTreeItemId
wxTreeCtrl::p_InsertItem(GtkTreeItem
*p
,
481 const wxString
& text
, int image
, int selectedImage
,
482 wxTreeItemData
*data
) {
485 printf("begin insert\n");
487 item
= GTK_TREE_ITEM(gtk_tree_item_new());
489 GtkHBox
*m_box
= GTK_HBOX(gtk_hbox_new(FALSE
, 0));
490 gtk_container_add (GTK_CONTAINER (item
), GTK_WIDGET(m_box
));
492 gtk_object_set_data(GTK_OBJECT(item
), "w_box", m_box
);
495 const wxImageList
*list
;
496 if ((list
= GetImageList(wxIMAGE_LIST_NORMAL
)) != NULL
)
497 if ((bmp
= list
->GetBitmapPtr(image
)) != NULL
)
499 GdkBitmap
*mask
= NULL
;
501 mask
= bmp
->GetMask()->GetBitmap();
502 GtkPixmap
*m_image_widget
= GTK_PIXMAP(gtk_pixmap_new(bmp
->GetPixmap(), mask
));
503 gtk_misc_set_alignment (GTK_MISC (m_image_widget
), 0.0, 0.5);
504 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_image_widget
), FALSE
, FALSE
, 0);
505 gtk_object_set_data(GTK_OBJECT(item
), "w_image", (void *)m_image_widget
);
506 gtk_object_set_data(GTK_OBJECT(item
), "image", (void *)image
);
507 gtk_widget_show (GTK_WIDGET(m_image_widget
));
509 GtkLabel
*m_label_widget
= GTK_LABEL(gtk_label_new ((char *)(const char *)text
));
510 gtk_misc_set_alignment (GTK_MISC (m_label_widget
), 0.5, 0.5);
511 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_label_widget
), FALSE
, FALSE
, 0);
512 gtk_object_set_data(GTK_OBJECT(item
), "w_label", m_label_widget
);
513 gtk_widget_show (GTK_WIDGET(m_label_widget
));
515 gtk_widget_show(GTK_WIDGET(m_box
));
517 gtk_object_set_data(GTK_OBJECT(item
), "owner", this);
518 gtk_object_set_data(GTK_OBJECT(item
), "data", data
);
519 gtk_object_set_data(GTK_OBJECT(item
), "parent", p
);
522 if (p
->subtree
== NULL
) {
523 GtkTree
*tree
= GTK_TREE(gtk_tree_new());
524 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p
), GTK_WIDGET(tree
));
525 gtk_widget_show(GTK_WIDGET(tree
));
529 gtk_container_add(GTK_CONTAINER(p
->subtree
), GTK_WIDGET(item
));
531 printf("Adding root\n");
532 printf("m_tree = %p\n", m_tree
);
534 gtk_container_add(GTK_CONTAINER(m_tree
), GTK_WIDGET(item
));
537 gtk_widget_show(GTK_WIDGET(item
));
539 gtk_signal_connect(GTK_OBJECT(item
), "select",
540 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
542 gtk_signal_connect(GTK_OBJECT(item
), "deselect",
543 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
545 gtk_signal_connect(GTK_OBJECT(item
), "expand",
546 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback
), (gpointer
)this );
547 gtk_signal_connect(GTK_OBJECT(item
), "collapse",
548 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback
), (gpointer
)this );
553 void wxTreeCtrl::Delete(const wxTreeItemId
& item
) {
557 GtkTreeItem
*parent
= GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem
*)item
)->parent
);
561 gtk_container_remove(GTK_CONTAINER(parent
), GTK_WIDGET((GtkTreeItem
*)item
));
566 void wxTreeCtrl::DeleteAllItems() {
567 gtk_tree_item_remove_subtree(m_anchor
);
570 void wxTreeCtrl::Expand(const wxTreeItemId
& item
) {
574 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
577 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
) {
581 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
584 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
) {
588 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
589 gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem
*)item
));
592 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
) {
596 if (((GtkTreeItem
*)item
)->expanded
)
597 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
599 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
602 static void gtk_treectrl_unselect_callback(GtkWidget
*widget
, gpointer data
) {
605 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
607 if (tree
->selection
!= NULL
) {
608 guint len
= g_list_length(tree
->selection
);
609 for (guint i
=0; i
<len
; i
++) {
610 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->selection
, i
)->data
);
611 gtk_tree_unselect_child(tree
, GTK_WIDGET(p
));
615 if (GTK_IS_CONTAINER(widget
))
616 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_unselect_callback
, data
);
619 void wxTreeCtrl::Unselect() {
620 if (m_anchor
== NULL
)
623 gtk_treectrl_unselect_callback(GTK_WIDGET(m_anchor
), NULL
);
626 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
) {
630 gtk_tree_item_select((GtkTreeItem
*)item
);
633 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
) {
634 #warning "Need to implement EnsureVisible"
637 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
) {
638 #warning "Need to implement ScrollTo"
641 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
642 wxClassInfo
* textControlClass
) {
643 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
644 #warning "Need to implement EditLabel"
649 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label");
650 gtk_label_get(m_label, &s);
652 m_textCtrl = new wxTextCtrl(this, -1, s);
653 // m_textCtrl->SetValue(s);
655 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "w_edit", m_textCtrl->m_widget);
657 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)item), GTK_WIDGET(m_label));
658 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)item), m_textCtrl->m_widget);
664 wxTextCtrl
* wxTreeCtrl::GetEditControl() const {
668 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
) {
669 #warning "Need to implement EndEditLabel"
671 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_label");
672 gtk_label_set(m_label, m_textCtrl->GetValue());
674 gtk_object_remove_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_edit");
676 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)m_editItem), m_textCtrl->m_widget);
677 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)m_editItem), GTK_WIDGET(m_label));
684 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
) {
686 case wxTREE_EXPAND_EXPAND
:
690 case wxTREE_EXPAND_COLLAPSE
:
694 case wxTREE_EXPAND_COLLAPSE_RESET
:
695 CollapseAndReset(item
);
698 case wxTREE_EXPAND_TOGGLE
:
703 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
707 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
708 const wxString
& text
, int image
, int selImage
,
710 // InsertItem(parent, insertAfter, text, image, selImage);
711 #warning "Need to implement InsertItem"
716 long wxTreeCtrl::GetChild(long item) const {
718 GtkTreeItem *next = NULL;
720 p = findGtkTreeItem(item);
721 GList *list = gtk_container_children(GTK_CONTAINER(p));
722 next = GTK_TREE_ITEM(list->data);
725 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
730 long wxTreeCtrl::GetFirstVisibleItem(void) const {
731 GtkTreeItem *next = NULL;
733 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
734 next = GTK_TREE_ITEM(list->data);
735 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
738 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
743 long wxTreeCtrl::GetNextVisibleItem(long item) const {
745 GtkTreeItem *next = NULL;
747 p = findGtkTreeItem(item);
748 GList *list = gtk_container_children(GTK_CONTAINER(p));
749 next = GTK_TREE_ITEM(list->data);
750 // gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
753 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
758 bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
761 p = findGtkTreeItem(info.m_itemId);
764 wxLogSysError("TreeCtrl::GetItem failed");
768 wxConvertFromGtkTreeItem(info, p);
773 bool wxTreeCtrl::SetItem(wxTreeItem& info) {
776 p = findGtkTreeItem(info.m_itemId);
779 wxLogSysError("TreeCtrl::SetItem failed");
783 wxConvertToGtkTreeItem(this, info, &p);
788 int wxTreeCtrl::GetItemState(long item, long stateMask) const {
791 info.m_mask = wxTREE_MASK_STATE ;
792 info.m_stateMask = stateMask;
793 info.m_itemId = item;
801 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
804 info.m_mask = wxTREE_MASK_STATE ;
805 info.m_state = state;
806 info.m_stateMask = stateMask;
807 info.m_itemId = item;
809 return SetItem(info);
815 bool wxTreeCtrl::DeleteChildren(long item) {
818 p = findGtkTreeItem(item);
822 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
829 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
831 GtkTreeItem *item = NULL;
833 info.m_itemId = m_curitemId;
836 wxConvertToGtkTreeItem(this, info, &item);
839 p = findGtkTreeItem(parent);
840 if (p->subtree == NULL) {
841 GtkTree *tree = GTK_TREE(gtk_tree_new());
842 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
843 gtk_widget_show(GTK_WIDGET(tree));
847 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
850 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
853 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
854 GtkTree *tree = GTK_TREE(gtk_tree_new());
855 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
856 gtk_widget_show(GTK_WIDGET(tree));
859 gtk_widget_show(GTK_WIDGET(item));
861 gtk_signal_connect(GTK_OBJECT(item), "select",
862 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
864 gtk_signal_connect(GTK_OBJECT(item), "deselect",
865 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
867 gtk_signal_connect(GTK_OBJECT(item), "expand",
868 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
869 gtk_signal_connect(GTK_OBJECT(item), "collapse",
870 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
872 return info.m_itemId;
875 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
876 int selImage, long insertAfter) {
880 info.m_mask = wxTREE_MASK_TEXT;
882 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
883 info.m_image = image;
885 info.m_selectedImage = image;
887 info.m_selectedImage = selImage;
890 return InsertItem(parent, info, insertAfter);
894 void wxTreeCtrl::SendMessage(wxEventType command
, const wxTreeItemId
& item
) {
895 wxTreeEvent
event(command
, GetId());
896 event
.SetEventObject(this);
901 void wxTreeCtrl::SendExpanding(const wxTreeItemId
& item
) {
902 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING
, item
);
905 void wxTreeCtrl::SendExpanded(const wxTreeItemId
& item
) {
906 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED
, item
);
909 void wxTreeCtrl::SendCollapsing(const wxTreeItemId
& item
) {
910 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, item
);
913 void wxTreeCtrl::SendCollapsed(const wxTreeItemId
& item
) {
914 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, item
);
917 void wxTreeCtrl::SendSelChanging(const wxTreeItemId
& item
) {
918 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED
, item
);
921 void wxTreeCtrl::SendSelChanged(const wxTreeItemId
& item
) {
922 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING
, item
);
926 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
928 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
929 wxCommandEvent(commandType
, id
) {