1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/treectrl.cpp
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"
24 #include "wx/gtk1/treectrl.h"
25 #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
194 return wxEmptyString
;
196 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
197 gtk_label_get(l
, &t
);
202 int wxTreeCtrl::GetItemImage(const wxTreeItemId
& item
) const {
206 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "image");
209 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& item
) const {
213 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage");
216 wxTreeItemData
*wxTreeCtrl::GetItemData(const wxTreeItemId
& item
) const {
220 return (wxTreeItemData
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "data");
223 void wxTreeCtrl::SetItemText(const wxTreeItemId
& item
, const wxString
& text
) {
227 GtkLabel
*l
= GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "w_label"));
228 gtk_label_set(l
, text
);
231 void wxTreeCtrl::SetItemImage(const wxTreeItemId
& item
, int image
) {
235 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "image", (void *)image
);
238 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& item
, int image
) {
242 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "selectedImage", (void *)image
);
245 void wxTreeCtrl::SetItemData(const wxTreeItemId
& item
, wxTreeItemData
*data
) {
249 gtk_object_set_data(GTK_OBJECT((GtkTreeItem
*)item
), "data", data
);
252 bool wxTreeCtrl::IsVisible(const wxTreeItemId
& item
) const {
253 return GTK_WIDGET_VISIBLE(GTK_TREE_ITEM((GtkTreeItem
*)item
));
256 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId
& item
) const {
257 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
259 if (p
->subtree
== NULL
)
262 if (GTK_TREE(p
->subtree
)->children
== NULL
)
265 if (g_list_length(GTK_TREE(p
->subtree
)->children
) == 0)
271 bool wxTreeCtrl::IsExpanded(const wxTreeItemId
& item
) const {
272 return (((GtkTreeItem
*)item
)->expanded
!= 0);
275 bool wxTreeCtrl::IsSelected(const wxTreeItemId
& item
) const {
276 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
277 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
279 if (!GTK_IS_TREE(parent
))
282 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
288 wxTreeItemId
wxTreeCtrl::GetRootItem() const {
292 static void gtk_treectrl_first_selected_callback(GtkWidget
*widget
, gpointer data
) {
293 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
295 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
297 if (tree
->selection
!= NULL
) {
298 p
= (GtkTreeItem
*)tree
->selection
->data
;
302 if (GTK_IS_CONTAINER(widget
))
303 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_selected_callback
, data
);
306 wxTreeItemId
wxTreeCtrl::GetSelection() const {
307 GtkTreeItem
*p
= NULL
;
309 if (m_anchor
== NULL
)
312 gtk_treectrl_first_selected_callback(GTK_WIDGET(m_anchor
), &p
);
317 wxTreeItemId
wxTreeCtrl::GetItemParent(const wxTreeItemId
& item
) const {
319 return (GtkTreeItem
*)gtk_object_get_data(GTK_OBJECT((GtkTreeItem
*)item
), "parent");
324 wxTreeItemId
wxTreeCtrl::GetFirstChild(const wxTreeItemId
& item
, long& cookie
) const {
325 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
326 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
328 if (!GTK_IS_TREE(parent
))
332 return GTK_TREE_ITEM(g_list_first(GTK_TREE(parent
)->children
)->data
);
335 wxTreeItemId
wxTreeCtrl::GetNextChild(const wxTreeItemId
& item
, long& cookie
) const {
336 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
337 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
339 if (!GTK_IS_TREE(parent
))
343 return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent
)->children
, cookie
)->data
);
346 wxTreeItemId
wxTreeCtrl::GetLastChild(const wxTreeItemId
& item
) const
348 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
349 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
351 wxCHECK_MSG( GTK_IS_TREE(parent
), NULL
, "invalid tree item" );
353 return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent
)->children
)->data
);
356 wxTreeItemId
wxTreeCtrl::GetNextSibling(const wxTreeItemId
& item
) const {
357 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
358 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
360 if (!GTK_IS_TREE(parent
))
363 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
366 return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
369 wxTreeItemId
wxTreeCtrl::GetPrevSibling(const wxTreeItemId
& item
) const {
370 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
371 GtkWidget
*parent
= GTK_WIDGET(p
)->parent
;
373 if (!GTK_IS_TREE(parent
))
376 if (g_list_index(GTK_TREE(parent
)->children
, p
) == -1)
379 return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
382 static void gtk_treectrl_first_visible_callback(GtkWidget
*widget
, gpointer data
) {
383 GtkTreeItem
*p
= (*((GtkTreeItem
**)data
));
385 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
387 if (tree
->children
!= NULL
) {
388 guint len
= g_list_length(tree
->children
);
389 for (guint i
=0; i
<len
; i
++) {
390 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
)))) {
391 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->children
, i
)->data
);
397 if (GTK_IS_CONTAINER(widget
))
398 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_first_visible_callback
, data
);
401 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem() const {
402 GtkTreeItem
*p
= NULL
;
404 if (m_anchor
== NULL
)
407 gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor
), &p
);
412 wxTreeItemId
wxTreeCtrl::GetNextVisible(const wxTreeItemId
& item
) const {
413 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
414 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
417 if (!GTK_IS_TREE(parent
))
420 if (parent
->children
== NULL
)
423 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
426 q
= GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
427 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
434 wxTreeItemId
wxTreeCtrl::GetPrevVisible(const wxTreeItemId
& item
) const {
435 GtkTreeItem
*p
= (GtkTreeItem
*)item
;
436 GtkTree
*parent
= GTK_TREE(GTK_WIDGET(p
)->parent
);
439 if (!GTK_IS_TREE(parent
))
442 if (parent
->children
== NULL
)
445 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, p
))->data
);
448 q
= GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent
)->children
, q
))->data
);
449 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q
)))
456 wxTreeItemId
wxTreeCtrl::AddRoot(const wxString
& text
, int image
,
457 int selectedImage
, wxTreeItemData
*data
) {
458 return p_InsertItem(0, text
, image
, selectedImage
, data
);
461 wxTreeItemId
wxTreeCtrl::PrependItem(const wxTreeItemId
& parent
,
462 const wxString
& text
, int image
, int selectedImage
,
463 wxTreeItemData
*data
) {
464 #warning "Need to implement PrependItem"
468 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
469 const wxTreeItemId
& idPrevious
, const wxString
& text
,
470 int image
, int selectedImage
, wxTreeItemData
*data
) {
471 #warning "Need to implement InsertItem"
475 wxTreeItemId
wxTreeCtrl::AppendItem(const wxTreeItemId
& parent
,
476 const wxString
& text
, int image
, int selectedImage
,
477 wxTreeItemData
*data
) {
478 return p_InsertItem(parent
, text
, image
, selectedImage
, data
);
481 wxTreeItemId
wxTreeCtrl::p_InsertItem(GtkTreeItem
*p
,
482 const wxString
& text
, int image
, int selectedImage
,
483 wxTreeItemData
*data
) {
486 printf("begin insert\n");
488 item
= GTK_TREE_ITEM(gtk_tree_item_new());
490 GtkHBox
*m_box
= GTK_HBOX(gtk_hbox_new(FALSE
, 0));
491 gtk_container_add (GTK_CONTAINER (item
), GTK_WIDGET(m_box
));
493 gtk_object_set_data(GTK_OBJECT(item
), "w_box", m_box
);
496 const wxImageList
*list
;
497 if ((list
= GetImageList(wxIMAGE_LIST_NORMAL
)) != NULL
)
498 if ((bmp
= list
->GetBitmapPtr(image
)) != NULL
)
500 GdkBitmap
*mask
= NULL
;
502 mask
= bmp
->GetMask()->GetBitmap();
503 GtkPixmap
*m_image_widget
= GTK_PIXMAP(gtk_pixmap_new(bmp
->GetPixmap(), mask
));
504 gtk_misc_set_alignment (GTK_MISC (m_image_widget
), 0.0, 0.5);
505 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_image_widget
), FALSE
, FALSE
, 0);
506 gtk_object_set_data(GTK_OBJECT(item
), "w_image", (void *)m_image_widget
);
507 gtk_object_set_data(GTK_OBJECT(item
), "image", (void *)image
);
508 gtk_widget_show (GTK_WIDGET(m_image_widget
));
510 GtkLabel
*m_label_widget
= GTK_LABEL(gtk_label_new ((char *)(const char *)text
));
511 gtk_misc_set_alignment (GTK_MISC (m_label_widget
), 0.5, 0.5);
512 gtk_box_pack_start(GTK_BOX(m_box
), GTK_WIDGET(m_label_widget
), FALSE
, FALSE
, 0);
513 gtk_object_set_data(GTK_OBJECT(item
), "w_label", m_label_widget
);
514 gtk_widget_show (GTK_WIDGET(m_label_widget
));
516 gtk_widget_show(GTK_WIDGET(m_box
));
518 gtk_object_set_data(GTK_OBJECT(item
), "owner", this);
519 gtk_object_set_data(GTK_OBJECT(item
), "data", data
);
520 gtk_object_set_data(GTK_OBJECT(item
), "parent", p
);
523 if (p
->subtree
== NULL
) {
524 GtkTree
*tree
= GTK_TREE(gtk_tree_new());
525 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p
), GTK_WIDGET(tree
));
526 gtk_widget_show(GTK_WIDGET(tree
));
530 gtk_container_add(GTK_CONTAINER(p
->subtree
), GTK_WIDGET(item
));
532 printf("Adding root\n");
533 printf("m_tree = %p\n", m_tree
);
535 gtk_container_add(GTK_CONTAINER(m_tree
), GTK_WIDGET(item
));
538 gtk_widget_show(GTK_WIDGET(item
));
540 gtk_signal_connect(GTK_OBJECT(item
), "select",
541 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
543 gtk_signal_connect(GTK_OBJECT(item
), "deselect",
544 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback
), (gpointer
)this );
546 gtk_signal_connect(GTK_OBJECT(item
), "expand",
547 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback
), (gpointer
)this );
548 gtk_signal_connect(GTK_OBJECT(item
), "collapse",
549 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback
), (gpointer
)this );
554 void wxTreeCtrl::Delete(const wxTreeItemId
& item
) {
558 GtkTreeItem
*parent
= GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem
*)item
)->parent
);
562 gtk_container_remove(GTK_CONTAINER(parent
), GTK_WIDGET((GtkTreeItem
*)item
));
567 void wxTreeCtrl::DeleteAllItems() {
568 gtk_tree_item_remove_subtree(m_anchor
);
571 void wxTreeCtrl::Expand(const wxTreeItemId
& item
) {
575 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
578 void wxTreeCtrl::Collapse(const wxTreeItemId
& item
) {
582 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
585 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId
& item
) {
589 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
590 gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem
*)item
));
593 void wxTreeCtrl::Toggle(const wxTreeItemId
& item
) {
597 if (((GtkTreeItem
*)item
)->expanded
)
598 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem
*)item
));
600 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem
*)item
));
603 static void gtk_treectrl_unselect_callback(GtkWidget
*widget
, gpointer data
) {
606 GtkTree
*tree
= GTK_TREE(GTK_TREE_ITEM(widget
)->subtree
);
608 if (tree
->selection
!= NULL
) {
609 guint len
= g_list_length(tree
->selection
);
610 for (guint i
=0; i
<len
; i
++) {
611 p
= GTK_TREE_ITEM((GtkTreeItem
*)g_list_nth(tree
->selection
, i
)->data
);
612 gtk_tree_unselect_child(tree
, GTK_WIDGET(p
));
616 if (GTK_IS_CONTAINER(widget
))
617 gtk_container_foreach(GTK_CONTAINER(widget
), gtk_treectrl_unselect_callback
, data
);
620 void wxTreeCtrl::Unselect() {
621 if (m_anchor
== NULL
)
624 gtk_treectrl_unselect_callback(GTK_WIDGET(m_anchor
), NULL
);
627 void wxTreeCtrl::SelectItem(const wxTreeItemId
& item
) {
631 gtk_tree_item_select((GtkTreeItem
*)item
);
634 void wxTreeCtrl::EnsureVisible(const wxTreeItemId
& item
) {
635 #warning "Need to implement EnsureVisible"
638 void wxTreeCtrl::ScrollTo(const wxTreeItemId
& item
) {
639 #warning "Need to implement ScrollTo"
642 wxTextCtrl
* wxTreeCtrl::EditLabel(const wxTreeItemId
& item
,
643 wxClassInfo
* textControlClass
) {
644 wxASSERT( textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
)) );
645 #warning "Need to implement EditLabel"
650 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label");
651 gtk_label_get(m_label, &s);
653 m_textCtrl = new wxTextCtrl(this, -1, s);
654 // m_textCtrl->SetValue(s);
656 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "w_edit", m_textCtrl->m_widget);
658 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)item), GTK_WIDGET(m_label));
659 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)item), m_textCtrl->m_widget);
665 wxTextCtrl
* wxTreeCtrl::GetEditControl() const {
669 void wxTreeCtrl::EndEditLabel(const wxTreeItemId
& item
, bool discardChanges
) {
670 #warning "Need to implement EndEditLabel"
672 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_label");
673 gtk_label_set(m_label, m_textCtrl->GetValue());
675 gtk_object_remove_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_edit");
677 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)m_editItem), m_textCtrl->m_widget);
678 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)m_editItem), GTK_WIDGET(m_label));
685 void wxTreeCtrl::ExpandItem(const wxTreeItemId
& item
, int action
) {
687 case wxTREE_EXPAND_EXPAND
:
691 case wxTREE_EXPAND_COLLAPSE
:
695 case wxTREE_EXPAND_COLLAPSE_RESET
:
696 CollapseAndReset(item
);
699 case wxTREE_EXPAND_TOGGLE
:
704 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
708 wxTreeItemId
wxTreeCtrl::InsertItem(const wxTreeItemId
& parent
,
709 const wxString
& text
, int image
, int selImage
,
711 // InsertItem(parent, insertAfter, text, image, selImage);
712 #warning "Need to implement InsertItem"
717 long wxTreeCtrl::GetChild(long item) const {
719 GtkTreeItem *next = NULL;
721 p = findGtkTreeItem(item);
722 GList *list = gtk_container_children(GTK_CONTAINER(p));
723 next = GTK_TREE_ITEM(list->data);
726 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
731 long wxTreeCtrl::GetFirstVisibleItem(void) const {
732 GtkTreeItem *next = NULL;
734 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
735 next = GTK_TREE_ITEM(list->data);
736 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
739 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
744 long wxTreeCtrl::GetNextVisibleItem(long item) const {
746 GtkTreeItem *next = NULL;
748 p = findGtkTreeItem(item);
749 GList *list = gtk_container_children(GTK_CONTAINER(p));
750 next = GTK_TREE_ITEM(list->data);
751 // gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
754 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
759 bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
762 p = findGtkTreeItem(info.m_itemId);
765 wxLogSysError("TreeCtrl::GetItem failed");
769 wxConvertFromGtkTreeItem(info, p);
774 bool wxTreeCtrl::SetItem(wxTreeItem& info) {
777 p = findGtkTreeItem(info.m_itemId);
780 wxLogSysError("TreeCtrl::SetItem failed");
784 wxConvertToGtkTreeItem(this, info, &p);
789 int wxTreeCtrl::GetItemState(long item, long stateMask) const {
792 info.m_mask = wxTREE_MASK_STATE ;
793 info.m_stateMask = stateMask;
794 info.m_itemId = item;
802 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
805 info.m_mask = wxTREE_MASK_STATE ;
806 info.m_state = state;
807 info.m_stateMask = stateMask;
808 info.m_itemId = item;
810 return SetItem(info);
816 bool wxTreeCtrl::DeleteChildren(long item) {
819 p = findGtkTreeItem(item);
823 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
830 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
832 GtkTreeItem *item = NULL;
834 info.m_itemId = m_curitemId;
837 wxConvertToGtkTreeItem(this, info, &item);
840 p = findGtkTreeItem(parent);
841 if (p->subtree == NULL) {
842 GtkTree *tree = GTK_TREE(gtk_tree_new());
843 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
844 gtk_widget_show(GTK_WIDGET(tree));
848 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
851 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
854 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
855 GtkTree *tree = GTK_TREE(gtk_tree_new());
856 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
857 gtk_widget_show(GTK_WIDGET(tree));
860 gtk_widget_show(GTK_WIDGET(item));
862 gtk_signal_connect(GTK_OBJECT(item), "select",
863 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
865 gtk_signal_connect(GTK_OBJECT(item), "deselect",
866 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
868 gtk_signal_connect(GTK_OBJECT(item), "expand",
869 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
870 gtk_signal_connect(GTK_OBJECT(item), "collapse",
871 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
873 return info.m_itemId;
876 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
877 int selImage, long insertAfter) {
881 info.m_mask = wxTREE_MASK_TEXT;
883 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
884 info.m_image = image;
886 info.m_selectedImage = image;
888 info.m_selectedImage = selImage;
891 return InsertItem(parent, info, insertAfter);
895 void wxTreeCtrl::SendMessage(wxEventType command
, const wxTreeItemId
& item
) {
896 wxTreeEvent
event(command
, GetId());
897 event
.SetEventObject(this);
902 void wxTreeCtrl::SendExpanding(const wxTreeItemId
& item
) {
903 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING
, item
);
906 void wxTreeCtrl::SendExpanded(const wxTreeItemId
& item
) {
907 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED
, item
);
910 void wxTreeCtrl::SendCollapsing(const wxTreeItemId
& item
) {
911 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING
, item
);
914 void wxTreeCtrl::SendCollapsed(const wxTreeItemId
& item
) {
915 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED
, item
);
918 void wxTreeCtrl::SendSelChanging(const wxTreeItemId
& item
) {
919 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED
, item
);
922 void wxTreeCtrl::SendSelChanged(const wxTreeItemId
& item
) {
923 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING
, item
);
927 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
929 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
930 wxCommandEvent(commandType
, id
) {