Honour the display width variable property
[pspp] / src / ui / gui / psppire-dict.c
index 59b57b490c200df5a535a20c89b9ad85226db3e1..f491ebff7161c71a6064eb25172c2752cca07434 100644 (file)
@@ -34,8 +34,6 @@
 #include "ui/gui/psppire-marshal.h"
 #include "ui/gui/psppire-var-ptr.h"
 
-#include <ssw-datum.h>
-
 #include <gobject/genums.h>
 
 #include <gettext.h>
@@ -81,29 +79,45 @@ gni (GListModel *list)
 static GType
 git (GListModel *list)
 {
-  return SSW_TYPE_DATUM;
+  return GTK_TYPE_BUTTON;
 }
 
 static gpointer
 gi (GListModel *list, guint id)
 {
-  SswDatum *gd = SSW_DATUM (g_object_new (SSW_TYPE_DATUM, NULL));
+  GtkWidget *button = gtk_button_new ();
 
   PsppireDict *dict = PSPPIRE_DICT (list);
 
   if (id >= psppire_dict_get_var_cnt (dict))
     {
-      gd->text = g_strdup (_("Var"));
+      gtk_button_set_label (GTK_BUTTON (button),  _("Var"));
     }
   else
     {
       const struct variable *v =  psppire_dict_get_variable (dict, id);
 
-      gd->text = g_strdup (var_get_name (v));
-      gd->label = g_strdup (var_get_label (v));
+      gtk_button_set_label (GTK_BUTTON (button),  var_get_name (v));
+      gtk_widget_set_tooltip_text (button, var_get_label (v));
+
+      PangoRectangle rect;
+      
+      PangoContext *context = gtk_widget_create_pango_context (button);
+      PangoLayout *layout = pango_layout_new (context);
+      
+      pango_layout_set_text (layout, "M", 1);
+      
+      pango_layout_get_extents (layout, NULL, &rect);
+      
+      g_object_unref (G_OBJECT (layout));
+      g_object_unref (G_OBJECT (context));
+      
+      gtk_widget_set_size_request (button,
+                                  var_get_display_width (v) * rect.width / PANGO_SCALE,
+                                  -1);
     }
 
-  return gd;
+  return button;
 }
 
 
@@ -390,7 +404,7 @@ psppire_dict_generate_name (const PsppireDict *dict, char *name, size_t size)
          - The string may not contain whitespace.
          - The first character may not be '$'
          - The first character may not be a digit
-         - The final charactor may not be '.' or '_'
+         - The final character may not be '.' or '_'
       */
       len = snprintf (name, size, _("Var%04d"), d);
       if (len + 1 >= size)