Remember the doodle and bubble tool status
[tbo.git] / src / doodle-tool.c
index 19fa3af..ff13d52 100644 (file)
 #include "doodle-tool.h"
 
 static gboolean BUBBLE_MODE = FALSE;
+static GtkWidget *BUBBLE_TREE = NULL;
+static GtkWidget *DOODLE_TREE = NULL;
+static GtkWidget *TREE = NULL;
+static gdouble HADJUSTD, HADJUSTB = 0;
+static gdouble VADJUSTD, VADJUSTB = 0;
 
 void
 doodle_tool_bubble_on_select (TboWindow *tbo)
 {
     BUBBLE_MODE = TRUE;
+    TREE = BUBBLE_TREE;
     doodle_tool_on_select (tbo);
 }
 
@@ -24,26 +30,79 @@ doodle_tool_bubble_on_unselect (TboWindow *tbo)
 {
     doodle_tool_on_unselect (tbo);
     BUBBLE_MODE = FALSE;
+    BUBBLE_TREE = TREE;
+}
+
+gboolean
+update_scroll_cb (gpointer p)
+{
+    GtkAdjustment *adjust;
+    gdouble hadjust, vadjust;
+    TboWindow *tbo = (TboWindow *)p;
+    if (BUBBLE_MODE)
+    {
+        hadjust = HADJUSTB;
+        vadjust = VADJUSTB;
+    }
+    else
+    {
+        hadjust = HADJUSTD;
+        vadjust = VADJUSTD;
+    }
+    adjust = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (tbo->scroll2));
+    gtk_adjustment_set_value (adjust, hadjust);
+    adjust = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (tbo->scroll2));
+    gtk_adjustment_set_value (adjust, vadjust);
+    return FALSE;
 }
 
 void
 doodle_tool_on_select (TboWindow *tbo)
 {
-    GtkWidget *tree;
+    if (!BUBBLE_MODE)
+        TREE = DOODLE_TREE;
+    if (!TREE)
+    {
+        TREE = doodle_setup_tree (tbo, BUBBLE_MODE);
+        gtk_widget_show_all (TREE);
+        TREE = g_object_ref (TREE);
+    }
 
-    tree = doodle_setup_tree (tbo, BUBBLE_MODE);
+    tbo_empty_tool_area (tbo);
+    gtk_container_add (GTK_CONTAINER (tbo->toolarea), TREE);
 
-    gtk_widget_show_all (tree);
 
-    tbo_empty_tool_area (tbo);
-    gtk_container_add (GTK_CONTAINER (tbo->toolarea), tree);
+    g_timeout_add (5, update_scroll_cb, tbo);
 }
 
 void
 doodle_tool_on_unselect (TboWindow *tbo)
 {
+    GtkAdjustment *adjust;
+    gdouble hadjust, vadjust;
+    if (GTK_IS_WIDGET (TREE) && TREE->parent == GTK_WIDGET (tbo->toolarea))
+    {
+        adjust = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (tbo->scroll2));
+        hadjust = gtk_adjustment_get_value (adjust);
+        adjust = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (tbo->scroll2));
+        vadjust = gtk_adjustment_get_value (adjust);
+
+        if (!BUBBLE_MODE)
+        {
+            DOODLE_TREE = TREE;
+            HADJUSTD = hadjust;
+            VADJUSTD = vadjust;
+        }
+        else
+        {
+            HADJUSTB = hadjust;
+            VADJUSTB = vadjust;
+        }
+
+        gtk_container_remove (GTK_CONTAINER (tbo->toolarea), TREE);
+    }
+
     tbo_empty_tool_area (tbo);
-    doodle_free_all ();
 }
 
 void doodle_tool_on_move (GtkWidget *widget, GdkEventMotion *event, TboWindow *tbo){}