psppire: Reimplement overview pane for output viewer window. fc11-i386-build76 fc11-x64-build73 sid-i386-build143
authorBen Pfaff <blp@gnu.org>
Sun, 17 Jan 2010 06:11:47 +0000 (22:11 -0800)
committerBen Pfaff <blp@gnu.org>
Sun, 17 Jan 2010 06:11:47 +0000 (22:11 -0800)
src/ui/gui/psppire-output-window.c
src/ui/gui/psppire-output-window.h

index b2e821e2e5060a902f7555b9b7cc261416ff2a62..ebca5533ddfc8f5d3db601e9e4adf2abeab8145b 100644 (file)
 #include <libpspp/message.h>
 #include <libpspp/string-map.h>
 #include <output/cairo.h>
+#include <output/chart-item.h>
 #include <output/driver-provider.h>
 #include <output/output-item.h>
+#include <output/table-item.h>
+#include <output/text-item.h>
 #include <output/tab.h>
 #include <stdlib.h>
 
@@ -176,6 +179,10 @@ psppire_output_submit (struct output_driver *this,
   PsppireOutputWindow *viewer;
   GtkWidget *drawing_area;
   struct xr_rendering *r;
+  struct string title;
+  GtkTreeStore *store;
+  GtkTreePath *path;
+  GtkTreeIter iter;
   cairo_t *cr;
   int tw, th;
 
@@ -187,6 +194,26 @@ psppire_output_submit (struct output_driver *this,
     }
   viewer = pod->viewer;
 
+  if (viewer->n_items >= viewer->allocated_items)
+    viewer->items = x2nrealloc (viewer->items, &viewer->allocated_items,
+                                sizeof *viewer->items);
+  viewer->items[viewer->n_items++] = output_item_ref (item);
+
+  if (is_text_item (item))
+    {
+      const struct text_item *text_item = to_text_item (item);
+      enum text_item_type type = text_item_get_type (text_item);
+      const char *text = text_item_get_text (text_item);
+
+      if (type == TEXT_ITEM_COMMAND_CLOSE)
+        {
+          viewer->in_command = false;
+          return;
+        }
+      else if (text[0] == '\0')
+        return;
+    }
+
   cr = gdk_cairo_create (GTK_WIDGET (pod->viewer)->window);
   if (pod->xr == NULL)
     pod->xr = xr_create_driver (cr);
@@ -195,11 +222,6 @@ psppire_output_submit (struct output_driver *this,
   if (r == NULL)
     goto done;
 
-  if (viewer->n_items >= viewer->allocated_items)
-    viewer->items = x2nrealloc (viewer->items, &viewer->allocated_items,
-                                sizeof *viewer->items);
-  viewer->items[viewer->n_items++] = output_item_ref (item);
-
   xr_rendering_measure (r, &tw, &th);
 
   drawing_area = gtk_drawing_area_new ();
@@ -213,6 +235,56 @@ psppire_output_submit (struct output_driver *this,
   g_signal_connect (G_OBJECT (drawing_area), "expose_event",
                      G_CALLBACK (expose_event_callback), NULL);
 
+  if (!is_text_item (item)
+      || text_item_get_type (to_text_item (item)) != TEXT_ITEM_SYNTAX
+      || !viewer->in_command)
+    {
+      store = GTK_TREE_STORE (gtk_tree_view_get_model (viewer->overview));
+
+      ds_init_empty (&title);
+      if (is_text_item (item)
+          && text_item_get_type (to_text_item (item)) == TEXT_ITEM_COMMAND_OPEN)
+        {
+          gtk_tree_store_append (store, &iter, NULL);
+          viewer->cur_command = iter; /* XXX shouldn't save a GtkTreeIter */
+          viewer->in_command = true;
+        }
+      else
+        {
+          GtkTreeIter *p = viewer->in_command ? &viewer->cur_command : NULL;
+          gtk_tree_store_append (store, &iter, p);
+        }
+
+      ds_clear (&title);
+      if (is_text_item (item))
+        ds_put_cstr (&title, text_item_get_text (to_text_item (item)));
+      else if (is_table_item (item))
+        {
+          const char *caption = table_item_get_caption (to_table_item (item));
+          if (caption != NULL)
+            ds_put_format (&title, "Table: %s", caption);
+          else
+            ds_put_cstr (&title, "Table");
+        }
+      else if (is_chart_item (item))
+        {
+          const char *s = chart_item_get_title (to_chart_item (item));
+          if (s != NULL)
+            ds_put_format (&title, "Chart: %s", s);
+          else
+            ds_put_cstr (&title, "Chart");
+        }
+      gtk_tree_store_set (store, &iter,
+                          COL_TITLE, ds_cstr (&title),
+                          COL_Y, viewer->y,
+                          -1);
+      ds_destroy (&title);
+
+      path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
+      gtk_tree_view_expand_row (viewer->overview, path, TRUE);
+      gtk_tree_path_free (path);
+    }
+
   if (pod->viewer->max_width < tw)
     pod->viewer->max_width = tw;
   pod->viewer->y += th;
@@ -437,7 +509,8 @@ psppire_output_window_init (PsppireOutputWindow *window)
                                              N_COLS,
                                              G_TYPE_STRING, /* COL_TITLE */
                                              G_TYPE_LONG))); /* COL_Y */
-  window->last_table_num = -1;
+
+  window->in_command = false;
 
   window->items = NULL;
   window->n_items = window->allocated_items = 0;
index bc0da8531b750c80180d6b42dd8f45d4a92d6c27..95deed93fec542dbd9bb8ee891fb4c2a289f6260 100644 (file)
@@ -58,8 +58,8 @@ struct _PsppireOutputWindow
   int y;
 
   GtkTreeView *overview;
-  int last_table_num;
-  GtkTreeIter last_top_level;
+  GtkTreeIter cur_command;
+  bool in_command;
 
   struct output_item **items;
   size_t n_items, allocated_items;