]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/treectrl.cpp
wxIMage accessors
[wxWidgets.git] / src / gtk1 / treectrl.cpp
index 3ae18cf4f674b71ea98861285616cd398e728c7a..8768e4e8677cdba6cffacabaa719993b2b3e0ed6 100644 (file)
 /////////////////////////////////////////////////////////////////////////////
 // Name:        treectrl.cpp
-// Purpose:
+// Purpose:     wxTreeCtrl
 // Author:      Denis Pershin
+// Modified by:
 // Created:     07/05/98
-// Id:          $Id$
-// Copyright:   (c) 1998 Denis Pershin and Julian Smart
-// Licence:     wxWindows licence
+// RCS-ID:      $Id$
+// Copyright:   (c) Denis Pershin
+// Licence:    wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 #pragma implementation "treectrl.h"
 #endif
 
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include "wx/wx.h"
+#endif
+
 #include "wx/gtk/treectrl.h"
-#include "wx/settings.h"
+#include <wx/textctrl.h>
 #include "wx/log.h"
 
-#ifdef USE_GDK_IMLIB
-#include "../gdk_imlib/gdk_imlib.h"
-#endif
+#include <gtk/gtk.h>
 
-//-----------------------------------------------------------------------------
-// wxTreeItem
-//-----------------------------------------------------------------------------
+//static void wxConvertToGtkTreeItem(wxTreeCtrl *owner, wxTreeItem& info, GtkTreeItem **gtkItem);
+//static void wxConvertFromGtkTreeItem(wxTreeItem& info, GtkTreeItem *gtkItem);
 
-// clicked
+static void gtk_treectrl_count_callback (GtkWidget *widget, gpointer data);
+static void gtk_treectrl_first_selected_callback(GtkWidget *widget, gpointer data);
+static void gtk_treectrl_first_visible_callback(GtkWidget *widget, gpointer data);
 
-void gtk_treeitem_expand_callback(GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) {
-  if (treeitem->ignore)
+// static void gtk_treectrl_next_callback (GtkWidget *widget, gpointer data);
+// static void gtk_treectrl_next_visible_callback (GtkWidget *widget, gpointer data);
+// static void gtk_treectrl_next_selected_callback (GtkWidget *widget, gpointer data);
+
+static void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItemId *treeitem);
+static void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItemId *treeitem);
+static void gtk_treeitem_select_callback(GtkWidget *widget, wxTreeItemId *treeitem);
+
+static void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItemId *treeitem) {
+  wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
+  if (owner == NULL)
     return;
-  treeitem->SendExpanding(treeitem->m_owner);
-  treeitem->SendExpand(treeitem->m_owner);
+
+//  long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
+  owner->SendExpanding(GTK_TREE_ITEM(widget));
+  owner->SendExpanded(GTK_TREE_ITEM(widget));
 };
 
-void gtk_treeitem_collapse_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) {
-  if (treeitem->ignore)
+static void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItemId *treeitem) {
+  wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
+  if (owner == NULL)
     return;
-  treeitem->SendCollapsing(treeitem->m_owner);
-  treeitem->SendCollapse(treeitem->m_owner);
-};
 
-void gtk_treeitem_select_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) {
-  treeitem->SendSelChanging(treeitem->m_owner);
-  treeitem->m_state |= wxTREE_STATE_SELECTED;
-  treeitem->SendSelChanged(treeitem->m_owner);
-}
-
-void gtk_treeitem_deselect_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem) {
-  treeitem->SendSelChanging(treeitem->m_owner);
-  treeitem->m_state &= !wxTREE_STATE_SELECTED;
-  treeitem->SendSelChanged(treeitem->m_owner);
-}
-
-IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject)
-
-wxTreeItem::wxTreeItem() {
-  m_mask = 0;
-  m_itemId = 0;
-  m_state = 0;
-  m_stateMask = 0;
-  m_image = -1;
-  m_children = 0;
-  m_selectedImage = -1;
-  m_tree = NULL;
-  m_parentwidget = NULL;
-  m_widget = NULL;
-  m_data = 0;
-  m_owner = 0;
-  expand_handler = 0;
-  collapse_handler = 0;
+//  long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
+  owner->SendCollapsing(GTK_TREE_ITEM(widget));
+  owner->SendCollapsed(GTK_TREE_ITEM(widget));
 };
 
-wxTreeItem::wxTreeItem(GtkWidget *parent, const wxTreeItem &item) {
-  m_mask = item.m_mask;
-  m_text = item.m_text;
-  m_itemId = item.m_itemId;
-  m_state = item.m_state;
-  m_stateMask = item.m_stateMask;
-  m_image = item.m_image;
-  m_tree = NULL;
-  m_owner = 0;
-  m_selectedImage = item.m_selectedImage;
-  m_children = item.m_children;
-  m_childlist = item.m_childlist;
-  m_data = item.m_data;
-  m_parentwidget = parent;
-  expand_handler = 0;
-  collapse_handler = 0;
-
-  Create();
-}
-
-void wxTreeItem::Create() {
-  wxASSERT(m_parentwidget != NULL);
-
-  m_widget = GTK_TREE_ITEM(gtk_tree_item_new_with_label ((char *)(const char *)m_text));
-  gtk_container_add (GTK_CONTAINER(m_parentwidget), GTK_WIDGET(m_widget));
-  gtk_widget_show(GTK_WIDGET(m_widget));
-
-  ignore  = FALSE;
-
-  gtk_signal_connect(GTK_OBJECT(m_widget), "select",
-      GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
-
-  gtk_signal_connect(GTK_OBJECT(m_widget), "deselect",
-      GTK_SIGNAL_FUNC(gtk_treeitem_deselect_callback), (gpointer)this );
-
-  if (expand_handler == 0)
-    expand_handler = gtk_signal_connect(GTK_OBJECT(m_widget), "expand",
-      GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
-
-  if (collapse_handler == 0)
-    collapse_handler = gtk_signal_connect( GTK_OBJECT(m_widget), "collapse",
-      GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
-
-  if ((m_mask & wxTREE_MASK_CHILDREN) != 0)
-    AddSubtree();
-}
-
-wxTreeItem::~wxTreeItem() {
-  if (m_owner != NULL)
-    SendDelete(m_owner);
-  DeleteChildren();
-  if ((m_widget != NULL) && (m_parentwidget != NULL))
-    gtk_container_remove(GTK_CONTAINER(m_parentwidget),
-                         GTK_WIDGET(m_widget));
-//  if (m_tree != NULL) {
-//    gtk_widget_destroy(GTK_WIDGET(m_tree));
-//    m_tree = NULL;
-//  }
-    
-//  if (m_widget != NULL)
-//    gtk_widget_destroy(GTK_WIDGET(m_widget));
-}
-
-void wxTreeItem::AddSubtree() {
-  if (m_widget == NULL)
+static void gtk_treeitem_select_callback(GtkWidget *widget, wxTreeItemId *treeitem) {
+  wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
+  if (owner == NULL)
     return;
 
+//  long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
+  owner->SendSelChanging(GTK_TREE_ITEM(widget));
+  owner->SendSelChanged(GTK_TREE_ITEM(widget));
+}
+
+#if !USE_SHARED_LIBRARY
+IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
+
+#endif
+
+void wxTreeCtrl::Init() {
+  m_imageListNormal = NULL;
+  m_imageListState = NULL;
+  m_textCtrl = NULL;
+}
+
+bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos,
+                        const wxSize& size, long style,
+                        const wxValidator& validator, const wxString& name) {
+  Init();
+
+  int x = pos.x;
+  int y = pos.y;
+  int width = size.x;
+  int height = size.y;
+
+  m_windowStyle = style;
+
+  SetParent(parent);
+
+  if (width <= 0)
+    width = 100;
+  if (height <= 0)
+    height = 30;
+  if (x < 0)
+    x = 0;
+  if (y < 0)
+    y = 0;
+
+  m_needParent = TRUE;
+  
+printf("precreate\n");
+  PreCreation( parent, id, pos, size, style, name );
+
+printf("1\n");
+
+  m_widget = gtk_scrolled_window_new(NULL, NULL);
+printf("2\n");
+  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget),
+      GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+printf("3\n");
   m_tree = GTK_TREE(gtk_tree_new());
-  gtk_tree_item_set_subtree(GTK_TREE_ITEM(m_widget), GTK_WIDGET(m_tree));
+
+printf("4\n");
+  gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_tree));
+printf("5\n");
   gtk_widget_show(GTK_WIDGET(m_tree));
 
-  ignore = TRUE;
-  gtk_tree_item_expand(m_widget);
-  gtk_tree_item_collapse(m_widget);
-  ignore  = FALSE;
+  SetName(name);
+  SetValidator(validator);
+
+printf("Robert's new insertion code :-)\n");
+  m_parent->AddChild( this );
+  (m_parent->m_insertCallback)( m_parent, this );
+  
+printf("postcreate\n");
+  PostCreation();
+
+  gtk_widget_realize(GTK_WIDGET(m_tree));
+
+  Show(TRUE);
+  
+  return TRUE;
+}
+
+wxTreeCtrl::~wxTreeCtrl(void) {
+  if (m_textCtrl)
+    delete m_textCtrl;
 }
 
-void wxTreeItem::AddChild(wxTreeItem *child) {
-  wxASSERT(child != NULL);
+// Attributes
+static void gtk_treectrl_count_callback (GtkWidget *widget, gpointer data) {
+  int count = (*((int *)data));
 
-  m_childlist.Append(child);
+  count++;
+  if (GTK_IS_CONTAINER(widget))
+    gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_count_callback, data);
 }
 
-bool wxTreeItem::HasChildren() {
-  return (m_childlist.Number() != 0);
+size_t wxTreeCtrl::GetCount() const {
+  int count = 0;
+
+  if (m_anchor != NULL)
+    gtk_treectrl_count_callback(GTK_WIDGET(m_anchor), &count);
+  return count;
 }
 
-void wxTreeItem::DeleteChildren() {
-  wxTreeItem *item;
-  
-  long no = GetChildrenNumber();
-  for (long i=0; i<no; i++)
-    if ((item = GetChild(i)) != 0)
-      delete item;
-  m_childlist.Clear();
-  
-  if ((no == 0) && (m_widget != NULL))
-    gtk_tree_item_remove_subtree(m_widget);
+unsigned int wxTreeCtrl::GetIndent() const {
+  return m_tree->indent_value;
+}
 
-  m_tree = NULL;
-  
-  if ((m_mask & wxTREE_MASK_CHILDREN) != 0)
-    if (m_widget != NULL)
-      if (m_widget->subtree == 0)
-        AddSubtree();
-}
-
-int wxTreeItem::NumberOfVisibleDescendents() {
-  wxTreeItem *item;
-  long no = GetChildrenNumber();
-  long num = 0;
-  for (long i=0; i<no; i++)
-    if ((item = GetChild(i)) != 0)
-      num += item->NumberOfVisibleDescendents();
-  
-  num+=no;
+void wxTreeCtrl::SetIndent(unsigned int indent) {
+  m_tree->indent_value = indent;
+}
 
-  return num;
+wxImageList *wxTreeCtrl::GetImageList() const {
+  return m_imageListNormal;
 }
 
-wxTreeItem *wxTreeItem::FindItem(long itemId) const {
-  if (m_itemId == itemId) return (wxTreeItem*)(this);
-  wxNode *node = m_childlist.First();
-  while (node) {
-    wxTreeItem *item = (wxTreeItem*)node->Data();
-    wxTreeItem *res = item->FindItem( itemId );
-    if (res) return (wxTreeItem*)(res);
-    node = node->Next();
-  };
-  return NULL;
-};
+wxImageList *wxTreeCtrl::GetStateImageList() const {
+  return m_imageListState;
+}
 
-wxTreeItem *wxTreeItem::FindItem(GtkTreeItem *item) const {
-  if (m_widget == item)
-    return (wxTreeItem*)(this);
-  wxNode *node = m_childlist.First();
-  while (node) {
-    wxTreeItem *i = (wxTreeItem*)node->Data();
-    wxTreeItem *res = i->FindItem(item);
-    if (res) return (wxTreeItem*)(res);
-    node = node->Next();
-  };
-  return NULL;
-};
+void wxTreeCtrl::SetImageList(wxImageList *imageList) {
+  m_imageListNormal = imageList;
+}
 
-void wxTreeItem::PrepareEvent(wxTreeEvent &event) {
-  event.m_item.m_itemId = m_itemId;
-  event.m_item.m_state = m_state;
-  event.m_item.m_text = m_text;
-  event.m_item.m_image = m_image;
-  event.m_item.m_selectedImage = m_selectedImage;
-  event.m_item.m_children = (GetChildrenNumber() > 0);
-  event.m_item.m_data = m_data;
-  event.m_oldItem = 0;
-  event.m_code = 0;
-//  event.m_pointDrag.x = 0;
-//  event.m_pointDrag.y = 0;
-};
+void wxTreeCtrl::SetStateImageList(wxImageList *imageList) {
+  m_imageListState = imageList;
+}
 
-void wxTreeItem::SendDelete(wxWindow *target) {
-  wxTreeEvent event(wxEVT_COMMAND_TREE_DELETE_ITEM, target->GetId());
-  PrepareEvent(event);
-  event.SetEventObject(target);
-  target->ProcessEvent(event);
-};
+wxString wxTreeCtrl::GetItemText(const wxTreeItemId &item) const {
+  char *t;
 
-void wxTreeItem::SendExpand(wxWindow *target) {
-  wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDED, target->GetId());
-  PrepareEvent(event);
-  event.SetEventObject(target);
-  target->ProcessEvent(event);
-};
+  if (!item.IsOk())
+    return wxString("");
 
-void wxTreeItem::SendExpanding(wxWindow *target) {
-  wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDING, target->GetId());
-  PrepareEvent(event);
-  event.SetEventObject(target);
-  target->ProcessEvent(event);
-};
+  GtkLabel *l = GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label"));
+  gtk_label_get(l, &t);
 
-void wxTreeItem::SendCollapse(wxWindow *target) {
-  wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, target->GetId());
-  PrepareEvent(event);
-  event.SetEventObject(target);
-  target->ProcessEvent(event);
-};
+  return t;
+}
 
-void wxTreeItem::SendCollapsing(wxWindow *target) {
-  wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, target->GetId());
-  PrepareEvent(event);
-  event.SetEventObject(target);
-  target->ProcessEvent(event);
-};
+int wxTreeCtrl::GetItemImage(const wxTreeItemId& item) const {
+  if (!item.IsOk())
+    return (-1);
 
-void wxTreeItem::SendSelChanged(wxWindow *target) {
-  wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGED, target->GetId());
-  PrepareEvent(event);
-  event.SetEventObject(target);
-  target->ProcessEvent(event);
-};
+  return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "image");
+}
 
-void wxTreeItem::SendSelChanging(wxWindow *target) {
-  wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, target->GetId());
-  PrepareEvent(event);
-  event.SetEventObject(target);
-  target->ProcessEvent(event);
-};
+int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId& item) const {
+  if (!item.IsOk())
+    return (-1);
 
-//-----------------------------------------------------------------------------
-// wxTreeCtrl
-//-----------------------------------------------------------------------------
+  return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "selectedImage");
+}
 
-IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxScrolledWindow)
+wxTreeItemData *wxTreeCtrl::GetItemData(const wxTreeItemId& item) const {
+  if (!item.IsOk())
+    return NULL;
 
-wxTreeCtrl::wxTreeCtrl() {
-  m_current = NULL;
-  m_lastId = 0;
-  m_isCreated = FALSE;
-  m_imageList = NULL;
-  m_smallImageList = NULL;
-};
+  return (wxTreeItemData *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "data");
+}
 
-wxTreeCtrl::wxTreeCtrl(wxWindow *parent, wxWindowID id,
-            const wxPoint& pos, const wxSize& size,
-            long style, const wxString& name ) {
-  m_current = NULL;
-  m_lastId = 0;
-  m_isCreated = FALSE;
-  m_imageList = NULL;
-  m_smallImageList = NULL;
-  Create( parent, id, pos, size, style, name );
-};
+void wxTreeCtrl::SetItemText(const wxTreeItemId& item, const wxString& text) {
+  if (!item.IsOk())
+    return;
 
-wxTreeCtrl::~wxTreeCtrl() {
-  DeleteAllItems();
-};
+  GtkLabel *l = GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label"));
+  gtk_label_set(l, text);
+}
 
-bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id,
-            const wxPoint& pos, const wxSize& size,
-            long style, const wxString& name ) {
-  m_needParent = TRUE;
-  
-  PreCreation( parent, id, pos, size, style, name );
-    
-  m_widget = gtk_scrolled_window_new(NULL, NULL);
-  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget),
-      GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-           
-  m_tree = GTK_TREE(gtk_tree_new());
-  
-/*
-  gtk_signal_connect( GTK_OBJECT(m_tree), "selection_changed",
-      GTK_SIGNAL_FUNC(gtk_treectrl_selection_changed_callback), (gpointer)this);
-  gtk_signal_connect( GTK_OBJECT(m_tree), "select_child",
-      GTK_SIGNAL_FUNC(gtk_treectrl_select_child_callback), (gpointer)this);
-  gtk_signal_connect( GTK_OBJECT(m_tree), "unselect_child",
-      GTK_SIGNAL_FUNC(gtk_treectrl_unselect_child_callback), (gpointer)this);
-*/
+void wxTreeCtrl::SetItemImage(const wxTreeItemId& item, int image) {
+  if (!item.IsOk())
+    return;
 
-  gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_tree));
-  gtk_widget_show(GTK_WIDGET(m_tree));
+  gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "image", (void *)image);
+}
 
-  PostCreation();
+void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId& item, int image) {
+  if (!item.IsOk())
+    return;
 
-  gtk_widget_realize(GTK_WIDGET(m_tree));
-  
-  Show(TRUE);
+  gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "selectedImage", (void *)image);
+}
 
-  return TRUE;
-};
+void wxTreeCtrl::SetItemData(const wxTreeItemId& item, wxTreeItemData *data) {
+  if (!item.IsOk())
+    return;
 
-int wxTreeCtrl::GetCount() const
-{
-  if (!m_anchor) return 0;
-  return m_anchor->NumberOfVisibleDescendents();
-};
+  gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "data", data);
+}
 
-long wxTreeCtrl::InsertItem(long parent, const wxString& label,
-      int image, int selImage, long insertAfter) {
-  wxTreeItem item;
-  if (!label.IsNull() || (label == "")) {
-    item.m_text = label;
-    item.m_mask |= wxTREE_MASK_TEXT;
-  };
-
-  if (image >= 0) {
-    item.m_image = image;
-    item.m_mask |= wxTREE_MASK_IMAGE;
-  };
-
-  if (selImage >= 0) {
-    item.m_selectedImage = selImage;
-    item.m_mask |= wxTREE_MASK_SELECTED_IMAGE;
-  };
-
-  return InsertItem(parent, item, insertAfter);
-};
+bool wxTreeCtrl::IsVisible(const wxTreeItemId& item) const {
+  return GTK_WIDGET_VISIBLE(GTK_TREE_ITEM((GtkTreeItem *)item));
+}
 
-long wxTreeCtrl::InsertItem( long parent, wxTreeItem &info, long WXUNUSED(insertAfter) ) {
-  int oldMask = info.m_mask;
-  long ret = 0;
-  wxTreeItem *p = NULL;
-  wxTreeItem *new_child;
+bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId& item) const {
+  GtkTreeItem *p = (GtkTreeItem *)item;
 
-  if (parent == 0) {
-    if (m_anchor)
-      return -1;
-  } else {
-    p = FindItem(parent);
-    if (!p) return -1;
-  };
-
-  if ((info.m_mask & wxTREE_MASK_HANDLE) == 0) {
-    m_lastId++;
-    info.m_itemId = m_lastId;
-    info.m_mask |= wxTREE_MASK_HANDLE;
-    ret = m_lastId;
-  } else
-    ret = info.m_itemId;
-
-  if (p) {
-    if (p->m_tree == NULL)
-      p->AddSubtree();
-  
-    new_child = new wxTreeItem(GTK_WIDGET(p->m_tree), info);
-    p->AddChild(new_child);
-gtk_widget_draw_default(GTK_WIDGET(m_tree));
-  } else {
-    new_child = new wxTreeItem(GTK_WIDGET(m_tree), info);
-    m_anchor = new_child;
+  if (p->subtree == NULL)
+    return wxFalse;
+
+  if (GTK_TREE(p->subtree)->children == NULL)
+    return wxFalse;
+
+  if (g_list_length(GTK_TREE(p->subtree)->children) == 0)
+    return wxFalse;
+
+  return wxTrue;
+}
+
+bool wxTreeCtrl::IsExpanded(const wxTreeItemId& item) const {
+  return (((GtkTreeItem *)item)->expanded != 0);
+}
+
+bool wxTreeCtrl::IsSelected(const wxTreeItemId& item) const {
+  GtkTreeItem *p = (GtkTreeItem *)item;
+  GtkWidget *parent = GTK_WIDGET(p)->parent;
+
+  if (!GTK_IS_TREE(parent))
+    return wxFalse;
+
+  if (g_list_index(GTK_TREE(parent)->children, p) == -1)
+    return wxFalse;
+
+  return wxTrue;
+}
+
+wxTreeItemId wxTreeCtrl::GetRootItem() const {
+  return m_anchor;
+}
+
+static void gtk_treectrl_first_selected_callback(GtkWidget *widget, gpointer data) {
+  GtkTreeItem *p = (*((GtkTreeItem **)data));
+
+  GtkTree *tree = GTK_TREE(GTK_TREE_ITEM(widget)->subtree);
+
+  if (tree->selection != NULL) {
+    p = (GtkTreeItem *)tree->selection->data;
+    return;
   }
 
-/* Disabled until wxImageList q solved  >>> seems it solved */
-/*
-  wxBitmap *bmp;
-  if ((new_child->m_mask & wxTREE_MASK_IMAGE) != 0) {
-    if (m_imageList != NULL) {
-//      if ((bmp = m_imageList->GetBitmap(new_child->m_image)) != NULL) {
-      if ((bmp = m_imageList->GetBitmap(0)) != NULL) {
-        if (bmp->Ok()) {
-          GdkBitmap *mask = NULL;
-          if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap();
-          GtkWidget *pixmap = gtk_pixmap_new(bmp->GetPixmap(), mask);
-
-gtk_widget_unref(new_child->m_widget->plus_pix_widget);
-gtk_container_remove(GTK_CONTAINER(new_child->m_widget->pixmaps_box),
-                     new_child->m_widget->plus_pix_widget);
-gtk_container_add(GTK_CONTAINER(new_child->m_widget->pixmaps_box),
-                  pixmap);
-          gtk_widget_show(pixmap);
-          GTK_TREE_ITEM(new_child->m_widget)->plus_pix_widget = pixmap;
-        }
+  if (GTK_IS_CONTAINER(widget))
+    gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_first_selected_callback, data);
+}
+
+wxTreeItemId wxTreeCtrl::GetSelection() const {
+  GtkTreeItem *p = NULL;
+
+  if (m_anchor == NULL)
+    return NULL;
+
+  gtk_treectrl_first_selected_callback(GTK_WIDGET(m_anchor), &p);
+
+  return p;
+}
+
+wxTreeItemId wxTreeCtrl::GetParent(const wxTreeItemId& item) const {
+  if (item.IsOk())
+    return (GtkTreeItem *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "parent");
+
+  return NULL;
+}
+
+wxTreeItemId wxTreeCtrl::GetFirstChild(const wxTreeItemId& item, long& cookie) const {
+  GtkTreeItem *p = (GtkTreeItem *)item;
+  GtkWidget *parent = GTK_WIDGET(p)->parent;
+
+  if (!GTK_IS_TREE(parent))
+    return NULL;
+
+  cookie = 0;
+  return GTK_TREE_ITEM(g_list_first(GTK_TREE(parent)->children)->data);
+}
+
+wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) const {
+  GtkTreeItem *p = (GtkTreeItem *)item;
+  GtkWidget *parent = GTK_WIDGET(p)->parent;
+
+  if (!GTK_IS_TREE(parent))
+    return NULL;
+
+  cookie++;
+  return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent)->children, cookie)->data);
+}
+
+wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const {
+  GtkTreeItem *p = (GtkTreeItem *)item;
+  GtkWidget *parent = GTK_WIDGET(p)->parent;
+
+  if (!GTK_IS_TREE(parent))
+    return NULL;
+
+  if (g_list_index(GTK_TREE(parent)->children, p) == -1)
+    return NULL;
+
+  return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent)->children, p))->data);
+}
+
+wxTreeItemId wxTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const {
+  GtkTreeItem *p = (GtkTreeItem *)item;
+  GtkWidget *parent = GTK_WIDGET(p)->parent;
+
+  if (!GTK_IS_TREE(parent))
+    return NULL;
+
+  if (g_list_index(GTK_TREE(parent)->children, p) == -1)
+    return NULL;
+
+  return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, p))->data);
+}
+
+static void gtk_treectrl_first_visible_callback(GtkWidget *widget, gpointer data) {
+  GtkTreeItem *p = (*((GtkTreeItem **)data));
+
+  GtkTree *tree = GTK_TREE(GTK_TREE_ITEM(widget)->subtree);
+
+  if (tree->children != NULL) {
+    guint len = g_list_length(tree->children);
+    for (guint i=0; i<len; i++) {
+      if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->children, i)->data)))) {
+        p = GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->children, i)->data);
+        return;
       }
+    }
+  }
+
+  if (GTK_IS_CONTAINER(widget))
+    gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_first_visible_callback, data);
+}
+
+wxTreeItemId wxTreeCtrl::GetFirstVisibleItem() const {
+  GtkTreeItem *p = NULL;
+
+  if (m_anchor == NULL)
+    return NULL;
+
+  gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor), &p);
+
+  return p;
+}
+
+wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const {
+  GtkTreeItem *p = (GtkTreeItem *)item;
+  GtkTree *parent = GTK_TREE(GTK_WIDGET(p)->parent);
+  GtkTreeItem *q;
+
+  if (!GTK_IS_TREE(parent))
+    return NULL;
+
+  if (parent->children == NULL)
+    return NULL;
+
+  q = GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent)->children, p))->data);
+
+  while (q != p) {
+    q = GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent)->children, q))->data);
+    if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q)))
+      return q;
+  }
+
+  return NULL;
+}
+
+wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const {
+  GtkTreeItem *p = (GtkTreeItem *)item;
+  GtkTree *parent = GTK_TREE(GTK_WIDGET(p)->parent);
+  GtkTreeItem *q;
+
+  if (!GTK_IS_TREE(parent))
+    return NULL;
+
+  if (parent->children == NULL)
+    return NULL;
+
+  q = GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, p))->data);
 
-      if ((bmp = m_imageList->GetBitmap(1)) != NULL) {
-        if (bmp->Ok()) {
-          GdkBitmap *mask = NULL;
-          if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap();
-          GtkWidget *pixmap = gtk_pixmap_new(bmp->GetPixmap(), mask);
-
-gtk_widget_unref(new_child->m_widget->minus_pix_widget);
-//gtk_container_remove(GTK_CONTAINER(new_child->m_widget->pixmaps_box),
-//                     new_child->m_widget->plus_pix_widget);
-//gtk_container_add(GTK_CONTAINER(new_child->m_widget->pixmaps_box),
-//                  pixmap);
-          gtk_widget_show(pixmap);
-          GTK_TREE_ITEM(new_child->m_widget)->minus_pix_widget = pixmap;
-        }
+  while (q != p) {
+    q = GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, q))->data);
+    if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q)))
+      return q;
+  }
+
+  return NULL;
+}
+
+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);
+}
+
+void wxTreeCtrl::Unselect() {
+  if (m_anchor == NULL)
+    return;
+
+  gtk_treectrl_unselect_callback(GTK_WIDGET(m_anchor), NULL);
+}
+
+void wxTreeCtrl::SelectItem(const wxTreeItemId& item) {
+  if (!item.IsOk())
+    return;
+
+  gtk_tree_item_select((GtkTreeItem *)item);
+}
+
+void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item) {
+#warning "Need to implement EnsureVisible"
+}
+
+void wxTreeCtrl::ScrollTo(const wxTreeItemId& item) {
+#warning "Need to implement ScrollTo"
+}
+
+wxTextCtrl* wxTreeCtrl::EditLabel(const wxTreeItemId& item,
+                          wxClassInfo* textControlClass) {
+    wxASSERT( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)) );
+#warning "Need to implement EditLabel"
+/*
+  char *s;
+  m_editItem = item;
+
+  GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label");
+  gtk_label_get(m_label, &s);
+
+  m_textCtrl = new wxTextCtrl(this, -1, s);
+//  m_textCtrl->SetValue(s);
+
+  gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "w_edit", m_textCtrl->m_widget);
+
+  gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)item), GTK_WIDGET(m_label));
+  gtk_container_add(GTK_CONTAINER((GtkTreeItem *)item), m_textCtrl->m_widget);
+
 */
+  return m_textCtrl;
+}
+
+wxTextCtrl* wxTreeCtrl::GetEditControl() const {
+  return m_textCtrl;
+}
 
-  new_child->m_owner = this;
+void wxTreeCtrl::EndEditLabel(const wxTreeItemId& item, bool discardChanges) {
+#warning "Need to implement EndEditLabel"
+/*
+  GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_label");
+  gtk_label_set(m_label, m_textCtrl->GetValue());
 
-  info.m_mask = oldMask;
-  return ret;
-};
+  gtk_object_remove_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_edit");
 
+  gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)m_editItem), m_textCtrl->m_widget);
+  gtk_container_add(GTK_CONTAINER((GtkTreeItem *)m_editItem), GTK_WIDGET(m_label));
 
-bool wxTreeCtrl::ExpandItem( long item, int action ) {
-  wxTreeItem *i = FindItem( item );
-  if (!i)
-    return FALSE;
+  delete m_textCtrl;
+  m_textCtrl = NULL;
+*/
+}
 
+void wxTreeCtrl::ExpandItem(const wxTreeItemId& item, int action) {
   switch (action) {
     case wxTREE_EXPAND_EXPAND:
-      gtk_tree_item_expand(GTK_TREE_ITEM(i->m_widget));
+      Expand(item);
       break;
 
-    case wxTREE_EXPAND_COLLAPSE_RESET:
     case wxTREE_EXPAND_COLLAPSE:
-      gtk_tree_item_collapse(GTK_TREE_ITEM(i->m_widget));
+      Collapse(item);
+      break;
+
+    case wxTREE_EXPAND_COLLAPSE_RESET:
+      CollapseAndReset(item);
       break;
 
     case wxTREE_EXPAND_TOGGLE:
-      if ((i->GetState() & wxTREE_STATE_EXPANDED) == 0)
-        gtk_tree_item_expand(GTK_TREE_ITEM(i->m_widget));
-      else
-        gtk_tree_item_collapse(GTK_TREE_ITEM(i->m_widget));
+      Toggle(item);
       break;
+
+    default:
+      wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
   }
+}
 
-  return TRUE;
-};
+wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
+                            const wxString& text, int image, int selImage,
+                            long insertAfter) {
+//  InsertItem(parent, insertAfter, text, image, selImage);
+  #warning "Need to implement InsertItem"
+  return NULL;
+}
+
+/* Old functions
+long wxTreeCtrl::GetChild(long item) const {
+  GtkTreeItem *p;
+  GtkTreeItem *next = NULL;
 
-void wxTreeCtrl::DeleteItem( long item )
-{
-  wxTreeItem *pItem = FindItem( item );
-  wxCHECK_RET( pItem != NULL, "wxTreeCtrl::DeleteItem: no such pItem." );
+  p = findGtkTreeItem(item);
+  GList *list = gtk_container_children(GTK_CONTAINER(p));
+  next = GTK_TREE_ITEM(list->data);;
 
-//  pItem->m_parent->m_childlist.DeleteObject(pItem);
+  if (next != NULL)
+    return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
+  
+  return (-1);
 }
 
-void wxTreeCtrl::DeleteChildren( long item )
-{
-  wxTreeItem *pItem = FindItem( item );
-  wxCHECK_RET( pItem != NULL, "wxTreeCtrl::DeleteChildren: no such pItem." );
+long wxTreeCtrl::GetFirstVisibleItem(void) const {
+  GtkTreeItem *next = NULL;
+
+  GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
+  next = GTK_TREE_ITEM(list->data);;
+//  gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
 
-  pItem->DeleteChildren();
+  if (next != NULL)
+    return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
+  
+  return (-1);
 }
 
-bool wxTreeCtrl::DeleteAllItems()
-{
-  delete m_anchor;
-  m_anchor = NULL;
-  return TRUE;
-};
+long wxTreeCtrl::GetNextVisibleItem(long item) const {
+  GtkTreeItem *p;
+  GtkTreeItem *next = NULL;
 
-/*
-bool wxTreeCtrl::GetItem( wxTreeItem &info ) const
-{
-  wxTreeItem *i = FindItem( info.m_itemId );
-  if (!i) return FALSE;
-  i->GetItem( info );
-  return TRUE;
-};
-*/
+  p = findGtkTreeItem(item);
+  GList *list = gtk_container_children(GTK_CONTAINER(p));
+  next = GTK_TREE_ITEM(list->data);;
+//  gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
 
-long wxTreeCtrl::GetItemData( long item ) const
-{
-  wxTreeItem *i = FindItem( item );
-  if (!i) return 0;
-  return i->m_data;
-};
+  if (next != NULL)
+    return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
+  
+  return (-1);
+}
 
-wxString wxTreeCtrl::GetItemText( long item ) const
-{
-  wxTreeItem *i = FindItem( item );
-  if (!i) return "";
-  return i->m_text;
-};
+bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
+  GtkTreeItem *p;
 
-int wxTreeCtrl::GetItemImage(long item) const
-{
-  wxTreeItem *i = FindItem( item );
-  return i == 0 ? -1 : i->GetImage();
-}
+  p = findGtkTreeItem(info.m_itemId);
 
-long wxTreeCtrl::GetParent( long item ) const
-{
-  wxTreeItem *i = FindItem( item );
-  if (!i) return -1;
-/*
-  i = i->m_parent;
-  if (!i) return -1;
-  return i->m_parent->m_itemId;
-*/
-  return -1;
-};
+  if (p == NULL) {
+    wxLogSysError("TreeCtrl::GetItem failed");
+    return FALSE;
+  }
 
-long wxTreeCtrl::GetRootItem() const
-{
-  if (m_anchor) return m_anchor->m_itemId;
-  return -1;
-};
+  wxConvertFromGtkTreeItem(info, p);
 
-/*
-long wxTreeCtrl::GetSelection() const
-{
-  return m_current ? m_current->GetItemId() : -1;
-};
+  return TRUE;
+}
+
+bool wxTreeCtrl::SetItem(wxTreeItem& info) {
+  GtkTreeItem *p;
 
-bool wxTreeCtrl::SelectItem(long itemId)
-{
-  wxTreeItem *pItem = FindItem(itemId);
-  if ( !pItem ) {
-    wxLogDebug("Can't select an item %d which doesn't exist.", itemId);
+  p = findGtkTreeItem(info.m_itemId);
 
+  if (p == NULL) {
+    wxLogSysError("TreeCtrl::SetItem failed");
     return FALSE;
   }
 
-  SelectItem(pItem);
+  wxConvertToGtkTreeItem(this, info, &p);
 
   return TRUE;
-};
+}
 
-void wxTreeCtrl::SelectItem(wxTreeItem *item, bool bDoEvents )
-{
-  if (m_current != item)
-  {
-    if (m_current)
-    {
-      m_current->SetHilight( FALSE );
-//      RefreshLine( m_current );
-    };
-    m_current = item;
-    m_current->SetHilight( TRUE );
-//    RefreshLine( m_current );
-
-    if (bDoEvents) m_current->SendSelected( this );
-  }
+int wxTreeCtrl::GetItemState(long item, long stateMask) const {
+  wxTreeItem info;
+
+  info.m_mask = wxTREE_MASK_STATE ;
+  info.m_stateMask = stateMask;
+  info.m_itemId = item;
+
+  if (!GetItem(info))
+    return 0;
+
+  return info.m_state;
 }
-*/
 
-bool wxTreeCtrl::ItemHasChildren( long item ) const
-{
-  wxTreeItem *i = FindItem( item );
-  if (!i) return FALSE;
-  return i->HasChildren();
-};
+bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
+  wxTreeItem info;
 
-void wxTreeCtrl::SetIndent( int indent )
-{
-  m_indent = indent;
-  Refresh();
-};
+  info.m_mask = wxTREE_MASK_STATE ;
+  info.m_state = state;
+  info.m_stateMask = stateMask;
+  info.m_itemId = item;
 
-int wxTreeCtrl::GetIndent() const
-{
-  return m_indent;
-};
+  return SetItem(info);
+}
+*/
 
+// Operations
 /*
-bool wxTreeCtrl::SetItem( wxTreeItem &info )
-{
-  wxTreeItem *i = FindItem( info.m_itemId );
-  if (!i) return FALSE;
-  wxClientDC dc(this);
-  i->SetItem( info, &dc );
-  Refresh();
-  return TRUE;
-};
+bool wxTreeCtrl::DeleteChildren(long item) {
+  GtkTreeItem *p;
 
-bool wxTreeCtrl::SetItemData( long item, long data )
-{
-  wxTreeItem *i = FindItem( item );
-  if (!i) return FALSE;
-  i->m_data = data;
-  return TRUE;
-};
+  p = findGtkTreeItem(item);
+  if (p == NULL)
+    return FALSE;
 
-bool wxTreeCtrl::SetItemText( long item, const wxString &text )
-{
-  wxTreeItem *i = FindItem( item );
-  if (!i) return FALSE;
-  wxClientDC dc(this);
-  i->SetText( text, &dc );
-  return TRUE;
-};
+  gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
 
-void wxTreeCtrl::SetItemImage(long item, int image, int imageSel) const
-{
-  wxTreeItem *i = FindItem( item );
-  if ( i != 0 ) {
-    i->SetImage(image);
-    i->SetSelectedImage(imageSel);
-  }
+  return TRUE;
 }
-
-long wxTreeCtrl::HitTest( const wxPoint& point, int &flags )
-{
-  flags = 0;
-  if (!m_anchor) return -1;
-  return m_anchor->HitTest( point, flags );
-};
 */
 
-wxImageList *wxTreeCtrl::GetImageList( int which ) const
-{
-  if (which == wxIMAGE_LIST_NORMAL) return m_imageList;
-  return m_smallImageList;
-};
+/*
+long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
+  GtkTreeItem *p;
+  GtkTreeItem *item = NULL;
+
+  info.m_itemId = m_curitemId;
+  m_curitemId++;
+
+  wxConvertToGtkTreeItem(this, info, &item);
+
+  if (parent != 0) {
+    p = findGtkTreeItem(parent);
+    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;
+    }
 
-void wxTreeCtrl::SetImageList( wxImageList *imageList, int which )
-{
-  if (which == wxIMAGE_LIST_NORMAL)
-  {
-    if (m_imageList) delete m_imageList;
-    m_imageList = imageList;
+    gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
+  } else {
+    m_anchor = item;
+    gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
   }
-  else
-  {
-    if (m_smallImageList) delete m_smallImageList;
-    m_smallImageList = imageList;
-  };
-};
 
-wxTreeItem *wxTreeCtrl::FindItem( long itemId ) const {
-  if (!m_anchor) return NULL;
-  return m_anchor->FindItem( itemId );
-  return 0;
-};
-
-wxTreeItem *wxTreeCtrl::FindItem(GtkTreeItem *item) const {
-  if (!m_anchor) return NULL;
-  return m_anchor->FindItem(item);
-  return 0;
-};
+  if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
+    GtkTree *tree = GTK_TREE(gtk_tree_new());
+    gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
+    gtk_widget_show(GTK_WIDGET(tree));
+  }
 
-//-----------------------------------------------------------------------------
-// wxTreeEvent
-//-----------------------------------------------------------------------------
+  gtk_widget_show(GTK_WIDGET(item));
 
-IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent,wxCommandEvent)
+  gtk_signal_connect(GTK_OBJECT(item), "select",
+    GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
 
-wxTreeEvent::wxTreeEvent( wxEventType commandType, int id ) :
-  wxCommandEvent( commandType, id )
-{
-  m_code = 0;
-  m_oldItem = 0;
-};
+  gtk_signal_connect(GTK_OBJECT(item), "deselect",
+    GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
 
-/* Bunch of old code might be useful */
-/*
-  wxBitmap *bmp;
+  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 );
 
-  if ((bmp = m_imageList->GetItem(0))->Ok()) {
-    GdkBitmap *mask = NULL;
-    if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap();
-    GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask );
+  return info.m_itemId;
+}
 
-    gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget));
-    gtk_widget_show(pixmap);
-    GTK_TREE_ITEM(new_child->m_widget)->pixmaps_box = pixmap;
+long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
+  int selImage, long insertAfter) {
+
+  wxTreeItem info;
+  info.m_text = label;
+  info.m_mask = wxTREE_MASK_TEXT;
+  if (image > -1) {
+    info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
+    info.m_image = image;
+    if (selImage == -1)
+      info.m_selectedImage = image;
+    else
+      info.m_selectedImage = selImage;
   }
 
-  if ((bmp = m_imageList->GetItem(1))->Ok()) {
-    GdkBitmap *mask = NULL;
-    if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap();
-    GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask );
+  return InsertItem(parent, info, insertAfter);
+}
+*/
 
-    gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget));
-    gtk_widget_show(pixmap);
-    GTK_TREE_ITEM(new_child->m_widget)->plus_pix_widget = pixmap;
-  }
+void wxTreeCtrl::SendMessage(wxEventType command, const wxTreeItemId& item) {
+  wxTreeEvent event(command, GetId());
+  event.SetEventObject(this);
+  event.m_item = item;
+  ProcessEvent(event);
+}
 
-  if ((bmp = m_imageList->GetItem(2))->Ok()) {
-    GdkBitmap *mask = NULL;
-    if (bmp->GetMask()) mask = bmp->GetMask()->GetBitmap();
-    GtkWidget *pixmap = gtk_pixmap_new( bmp->GetPixmap(), mask );
+void wxTreeCtrl::SendExpanding(const wxTreeItemId& item) {
+  SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING, item);
+}
 
-    gtk_widget_set_parent(pixmap, GTK_WIDGET(new_child->m_widget));
-    gtk_widget_show(pixmap);
-    GTK_TREE_ITEM(new_child->m_widget)->minus_pix_widget = pixmap;
-  }
+void wxTreeCtrl::SendExpanded(const wxTreeItemId& item) {
+  SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED, item);
+}
 
-  if (p)
-    if (p->m_childlist.Number() == 1) {
-      gtk_tree_item_collapse(GTK_TREE_ITEM(p->m_widget));
-      gtk_tree_item_expand(GTK_TREE_ITEM(p->m_widget));
-    }
-*/
+void wxTreeCtrl::SendCollapsing(const wxTreeItemId& item) {
+  SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, item);
+}
+
+void wxTreeCtrl::SendCollapsed(const wxTreeItemId& item) {
+  SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, item);
+}
+
+void wxTreeCtrl::SendSelChanging(const wxTreeItemId& item) {
+  SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED, item);
+}
+
+void wxTreeCtrl::SendSelChanged(const wxTreeItemId& item) {
+  SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING, item);
+}
+
+// Tree event
+IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent)
+
+wxTreeEvent::wxTreeEvent(wxEventType commandType, int id):
+  wxCommandEvent(commandType, id) {
+  m_code = 0;
+  m_itemOld = 0;
+}