PsppSheetViewColumn: Replace GtkAlignment with a GtkBin
[pspp] / src / ui / gui / pspp-sheet-view-column.c
index 8dab5b548209cdc32d61b67746fd7955512bf527..4acd3f03b4bd8620f09b87f8f6c810c39e13ce70 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2011, 2012, 2015 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -484,7 +484,7 @@ static void
 pspp_sheet_view_column_init (PsppSheetViewColumn *tree_column)
 {
   tree_column->button = NULL;
-  tree_column->xalign = 0.0;
+  tree_column->halign = GTK_ALIGN_START;
   tree_column->width = 0;
   tree_column->spacing = 0;
   tree_column->requested_width = -1;
@@ -1044,10 +1044,10 @@ pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column)
                     G_CALLBACK (on_query_tooltip), tree_column);
   g_object_set (tree_column->button, "has-tooltip", TRUE, NULL);
 
-  tree_column->alignment = gtk_alignment_new (tree_column->xalign, 0.5, 0.0, 0.0);
+  tree_column->bin = gtk_event_box_new ();
+  g_object_set (tree_column->bin, "halign", GTK_ALIGN_CENTER, NULL);
 
-  hbox = gtk_hbox_new (FALSE, 2);
-  tree_column->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
 
   if (tree_column->child)
     child = tree_column->child;
@@ -1061,18 +1061,14 @@ pspp_sheet_view_column_create_button (PsppSheetViewColumn *tree_column)
                    G_CALLBACK (pspp_sheet_view_column_mnemonic_activate),
                    tree_column);
 
-  if (tree_column->xalign <= 0.5)
-    gtk_box_pack_end (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
-  else
-    gtk_box_pack_start (GTK_BOX (hbox), tree_column->arrow, FALSE, FALSE, 0);
 
-  gtk_box_pack_start (GTK_BOX (hbox), tree_column->alignment, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), tree_column->bin, TRUE, TRUE, 0);
         
-  gtk_container_add (GTK_CONTAINER (tree_column->alignment), child);
+  gtk_container_add (GTK_CONTAINER (tree_column->bin), child);
   gtk_container_add (GTK_CONTAINER (tree_column->button), hbox);
 
   gtk_widget_show (hbox);
-  gtk_widget_show (tree_column->alignment);
+  gtk_widget_show (tree_column->bin);
   pspp_sheet_view_column_update_button (tree_column);
 }
 
@@ -1080,11 +1076,8 @@ void
 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column)
 {
   gint sort_column_id = -1;
-  GtkWidget *hbox;
   GtkWidget *alignment;
-  GtkWidget *arrow;
   GtkWidget *current_child;
-  GtkArrowType arrow_type = GTK_ARROW_NONE;
   GtkTreeModel *model;
   gboolean can_focus;
 
@@ -1103,14 +1096,13 @@ pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column)
   if (! tree_column->button)
     return;
 
-  hbox = gtk_bin_get_child (GTK_BIN (tree_column->button));
-  alignment = tree_column->alignment;
-  arrow = tree_column->arrow;
+  alignment = tree_column->bin;
   current_child = gtk_bin_get_child (GTK_BIN (alignment));
 
   /* Set up the actual button */
-  gtk_alignment_set (GTK_ALIGNMENT (alignment), tree_column->xalign,
-                    0.5, 0.0, 0.0);
+  g_object_set (alignment,
+               "halign", tree_column->halign,
+               "valign", GTK_ALIGN_CENTER, NULL);
       
   if (tree_column->child)
     {
@@ -1147,58 +1139,6 @@ pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column)
                                          &sort_column_id,
                                          NULL);
 
-  if (tree_column->show_sort_indicator)
-    {
-      gboolean alternative;
-
-      g_object_get (gtk_widget_get_settings (tree_column->tree_view),
-                   "gtk-alternative-sort-arrows", &alternative,
-                   NULL);
-
-      switch (tree_column->sort_order)
-        {
-         case GTK_SORT_ASCENDING:
-           arrow_type = alternative ? GTK_ARROW_UP : GTK_ARROW_DOWN;
-           break;
-
-         case GTK_SORT_DESCENDING:
-           arrow_type = alternative ? GTK_ARROW_DOWN : GTK_ARROW_UP;
-           break;
-
-         default:
-           g_warning (G_STRLOC": bad sort order");
-           break;
-       }
-    }
-
-  gtk_arrow_set (GTK_ARROW (arrow),
-                arrow_type,
-                GTK_SHADOW_IN);
-
-  /* Put arrow on the right if the text is left-or-center justified, and on the
-   * left otherwise; do this by packing boxes, so flipping text direction will
-   * reverse things
-   */
-  g_object_ref (arrow);
-  gtk_container_remove (GTK_CONTAINER (hbox), arrow);
-
-  if (tree_column->xalign <= 0.5)
-    {
-      gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
-    }
-  else
-    {
-      gtk_box_pack_start (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
-      /* move it to the front */
-      gtk_box_reorder_child (GTK_BOX (hbox), arrow, 0);
-    }
-  g_object_unref (arrow);
-
-  if (tree_column->show_sort_indicator
-      || (GTK_IS_TREE_SORTABLE (model) && tree_column->sort_column_id >= 0))
-    gtk_widget_show (arrow);
-  else
-    gtk_widget_hide (arrow);
 
   /* It's always safe to hide the button.  It isn't always safe to show it, as
    * if you show it before it's realized, it'll get the wrong window. */
@@ -1616,7 +1556,7 @@ _pspp_sheet_view_column_realize_button (PsppSheetViewColumn *column)
 
   pspp_sheet_view_column_update_button (column);
 
-  gdk_cursor_unref (attr.cursor);
+  g_object_unref (attr.cursor);
 }
 
 void
@@ -2541,21 +2481,19 @@ pspp_sheet_view_column_get_widget (PsppSheetViewColumn *tree_column)
  * @xalign: The alignment, which is between [0.0 and 1.0] inclusive.
  * 
  * Sets the alignment of the title or custom widget inside the column header.
- * The alignment determines its location inside the button -- 0.0 for left, 0.5
- * for center, 1.0 for right.
+ * The alignment determines its location inside the button.
  **/
 void
 pspp_sheet_view_column_set_alignment (PsppSheetViewColumn *tree_column,
-                                    gfloat             xalign)
+                                    GtkAlign  xalign)
 {
   g_return_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column));
 
-  xalign = CLAMP (xalign, 0.0, 1.0);
 
-  if (tree_column->xalign == xalign)
+  if (tree_column->halign == xalign)
     return;
 
-  tree_column->xalign = xalign;
+  tree_column->halign = xalign;
   pspp_sheet_view_column_update_button (tree_column);
   g_object_notify (G_OBJECT (tree_column), "alignment");
 }
@@ -2564,19 +2502,19 @@ pspp_sheet_view_column_set_alignment (PsppSheetViewColumn *tree_column,
  * pspp_sheet_view_column_get_alignment:
  * @tree_column: A #PsppSheetViewColumn.
  * 
- * Returns the current x alignment of @tree_column.  This value can range
- * between 0.0 and 1.0.
+ * Returns the current x alignment of @tree_column.
  * 
  * Return value: The current alignent of @tree_column.
  **/
-gfloat
+GtkAlign
 pspp_sheet_view_column_get_alignment (PsppSheetViewColumn *tree_column)
 {
-  g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), 0.5);
+  g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (tree_column), GTK_ALIGN_CENTER);
 
-  return tree_column->xalign;
+  return tree_column->halign;
 }
 
+
 /**
  * pspp_sheet_view_column_set_reorderable:
  * @tree_column: A #PsppSheetViewColumn