+wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text, int image,
+ int selectedImage, wxTreeItemData *data) {
+ return p_InsertItem(0, text, image, selectedImage, data);
+}
+
+wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
+ const wxString& text, int image, int selectedImage,
+ wxTreeItemData *data) {
+#warning "Need to implement PrependItem"
+ return NULL;
+}
+
+wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
+ const wxTreeItemId& idPrevious, const wxString& text,
+ int image, int selectedImage, wxTreeItemData *data) {
+#warning "Need to implement InsertItem"
+ return NULL;
+}
+
+wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
+ const wxString& text, int image, int selectedImage,
+ wxTreeItemData *data) {
+ return p_InsertItem(parent, text, image, selectedImage, data);
+}
+
+wxTreeItemId wxTreeCtrl::p_InsertItem(GtkTreeItem *p,
+ const wxString& text, int image, int selectedImage,
+ wxTreeItemData *data) {
+ GtkTreeItem *item;
+
+printf("begin insert\n");
+
+ item = GTK_TREE_ITEM(gtk_tree_item_new());
+
+ GtkHBox *m_box = GTK_HBOX(gtk_hbox_new(FALSE, 0));
+ gtk_container_add (GTK_CONTAINER (item), GTK_WIDGET(m_box));
+
+ gtk_object_set_data(GTK_OBJECT(item), "w_box", m_box);
+
+ const wxBitmap *bmp;
+ const wxImageList *list;
+ if ((list = GetImageList(wxIMAGE_LIST_NORMAL)) != NULL)
+ if ((bmp = list->GetBitmap(image)) != NULL)
+ if (bmp->Ok()) {
+ GdkBitmap *mask = NULL;
+ if (bmp->GetMask())
+ mask = bmp->GetMask()->GetBitmap();
+ GtkPixmap *m_image_widget = GTK_PIXMAP(gtk_pixmap_new(bmp->GetPixmap(), mask));
+ gtk_misc_set_alignment (GTK_MISC (m_image_widget), 0.0, 0.5);
+ gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_image_widget), FALSE, FALSE, 0);
+ gtk_object_set_data(GTK_OBJECT(item), "w_image", (void *)m_image_widget);
+ gtk_object_set_data(GTK_OBJECT(item), "image", (void *)image);
+ gtk_widget_show (GTK_WIDGET(m_image_widget));
+ }
+ GtkLabel *m_label_widget = GTK_LABEL(gtk_label_new ((char *)(const char *)text));
+ gtk_misc_set_alignment (GTK_MISC (m_label_widget), 0.5, 0.5);
+ gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_label_widget), FALSE, FALSE, 0);
+ gtk_object_set_data(GTK_OBJECT(item), "w_label", m_label_widget);
+ gtk_widget_show (GTK_WIDGET(m_label_widget));
+
+ gtk_widget_show(GTK_WIDGET(m_box));
+
+ gtk_object_set_data(GTK_OBJECT(item), "owner", this);
+ gtk_object_set_data(GTK_OBJECT(item), "data", data);
+ gtk_object_set_data(GTK_OBJECT(item), "parent", p);
+
+ if (p != 0) {
+ if (p->subtree == NULL) {
+ GtkTree *tree = GTK_TREE(gtk_tree_new());
+ gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
+ gtk_widget_show(GTK_WIDGET(tree));
+ p->expanded = 1;
+ }
+
+ gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
+ } else {
+printf("Adding root\n");
+printf("m_tree = %p\n", m_tree);
+ m_anchor = item;
+ gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
+ }
+
+ gtk_widget_show(GTK_WIDGET(item));
+
+ gtk_signal_connect(GTK_OBJECT(item), "select",
+ GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
+
+ gtk_signal_connect(GTK_OBJECT(item), "deselect",
+ GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
+
+ gtk_signal_connect(GTK_OBJECT(item), "expand",
+ GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
+ gtk_signal_connect(GTK_OBJECT(item), "collapse",
+ GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
+
+ return item;
+}
+
+void wxTreeCtrl::Delete(const wxTreeItemId& item) {
+ if (!item.IsOk())
+ return;
+
+ GtkTreeItem *parent = GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem *)item)->parent);
+ if (parent == NULL)
+ return;
+
+ gtk_container_remove(GTK_CONTAINER(parent), GTK_WIDGET((GtkTreeItem *)item));
+
+ return;
+}
+
+void wxTreeCtrl::DeleteAllItems() {
+ gtk_tree_item_remove_subtree(m_anchor);
+}
+
+void wxTreeCtrl::Expand(const wxTreeItemId& item) {
+ if (!item.IsOk())
+ return;
+
+ gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem *)item));
+}
+
+void wxTreeCtrl::Collapse(const wxTreeItemId& item) {
+ if (!item.IsOk())
+ return;
+
+ gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
+}
+
+void wxTreeCtrl::CollapseAndReset(const wxTreeItemId& item) {
+ if (!item.IsOk())
+ return;
+
+ gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
+ gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem *)item));
+}
+
+void wxTreeCtrl::Toggle(const wxTreeItemId& item) {
+ if (!item.IsOk())
+ return;
+
+ if (((GtkTreeItem *)item)->expanded)
+ gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
+ else
+ gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem *)item));
+}
+
+static void gtk_treectrl_unselect_callback(GtkWidget *widget, gpointer data) {
+ GtkTreeItem *p;
+
+ GtkTree *tree = GTK_TREE(GTK_TREE_ITEM(widget)->subtree);
+
+ if (tree->selection != NULL) {
+ guint len = g_list_length(tree->selection);
+ for (guint i=0; i<len; i++) {
+ p = GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->selection, i)->data);
+ gtk_tree_unselect_child(tree, GTK_WIDGET(p));
+ }
+ }
+
+ if (GTK_IS_CONTAINER(widget))
+ gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_unselect_callback, data);