]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktreeviewcolumn.c
Moved search entries into priv data.
[~andy/gtk] / gtk / gtktreeviewcolumn.c
index cba68c0e6ae465ceaaf01a86eed480f70fbcba63..de3178b3c6a8df03c469e4e43e7b6d657b372f7d 100644 (file)
@@ -17,6 +17,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#include <config.h>
 #include <string.h>
 #include "gtktreeviewcolumn.h"
 #include "gtktreeview.h"
@@ -107,6 +108,9 @@ static void gtk_tree_view_column_cell_layout_set_cell_data_func (GtkCellLayout
                                                                  GDestroyNotify         destroy);
 static void gtk_tree_view_column_cell_layout_clear_attributes   (GtkCellLayout         *cell_layout,
                                                                  GtkCellRenderer       *cell);
+static void gtk_tree_view_column_cell_layout_reorder            (GtkCellLayout         *cell_layout,
+                                                                 GtkCellRenderer       *cell,
+                                                                 gint                   position);
 
 /* Button handling code */
 static void gtk_tree_view_column_create_button                 (GtkTreeViewColumn       *tree_column);
@@ -216,24 +220,24 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
   g_object_class_install_property (object_class,
                                    PROP_VISIBLE,
                                    g_param_spec_boolean ("visible",
-                                                        _("Visible"),
-                                                        _("Whether to display the column"),
+                                                        P_("Visible"),
+                                                        P_("Whether to display the column"),
                                                          TRUE,
                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
   
   g_object_class_install_property (object_class,
                                    PROP_RESIZABLE,
                                    g_param_spec_boolean ("resizable",
-                                                        _("Resizable"),
-                                                        _("Column is user-resizable"),
+                                                        P_("Resizable"),
+                                                        P_("Column is user-resizable"),
                                                          FALSE,
                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
   
   g_object_class_install_property (object_class,
                                    PROP_WIDTH,
                                    g_param_spec_int ("width",
-                                                    _("Width"),
-                                                    _("Current width of the column"),
+                                                    P_("Width"),
+                                                    P_("Current width of the column"),
                                                     0,
                                                     G_MAXINT,
                                                     0,
@@ -241,8 +245,8 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
   g_object_class_install_property (object_class,
                                    PROP_SIZING,
                                    g_param_spec_enum ("sizing",
-                                                      _("Sizing"),
-                                                      _("Resize mode of the column"),
+                                                      P_("Sizing"),
+                                                      P_("Resize mode of the column"),
                                                       GTK_TYPE_TREE_VIEW_COLUMN_SIZING,
                                                       GTK_TREE_VIEW_COLUMN_AUTOSIZE,
                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
@@ -250,8 +254,8 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
   g_object_class_install_property (object_class,
                                    PROP_FIXED_WIDTH,
                                    g_param_spec_int ("fixed_width",
-                                                     _("Fixed Width"),
-                                                     _("Current fixed width of the column"),
+                                                     P_("Fixed Width"),
+                                                     P_("Current fixed width of the column"),
                                                      1,
                                                      G_MAXINT,
                                                      1, /* not useful */
@@ -260,8 +264,8 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
   g_object_class_install_property (object_class,
                                    PROP_MIN_WIDTH,
                                    g_param_spec_int ("min_width",
-                                                     _("Minimum Width"),
-                                                     _("Minimum allowed width of the column"),
+                                                     P_("Minimum Width"),
+                                                     P_("Minimum allowed width of the column"),
                                                      -1,
                                                      G_MAXINT,
                                                      -1,
@@ -270,8 +274,8 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
   g_object_class_install_property (object_class,
                                    PROP_MAX_WIDTH,
                                    g_param_spec_int ("max_width",
-                                                     _("Maximum Width"),
-                                                     _("Maximum allowed width of the column"),
+                                                     P_("Maximum Width"),
+                                                     P_("Maximum allowed width of the column"),
                                                      -1,
                                                      G_MAXINT,
                                                      -1,
@@ -280,24 +284,24 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
   g_object_class_install_property (object_class,
                                    PROP_TITLE,
                                    g_param_spec_string ("title",
-                                                        _("Title"),
-                                                        _("Title to appear in column header"),
+                                                        P_("Title"),
+                                                        P_("Title to appear in column header"),
                                                         "",
                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
   
   g_object_class_install_property (object_class,
                                    PROP_EXPAND,
                                    g_param_spec_boolean ("expand",
-                                                        _("Expand"),
-                                                        _("Column gets share of extra width allocated to the widget"),
+                                                        P_("Expand"),
+                                                        P_("Column gets share of extra width allocated to the widget"),
                                                         FALSE,
                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
   
   g_object_class_install_property (object_class,
                                    PROP_CLICKABLE,
                                    g_param_spec_boolean ("clickable",
-                                                        _("Clickable"),
-                                                        _("Whether the header can be clicked"),
+                                                        P_("Clickable"),
+                                                        P_("Whether the header can be clicked"),
                                                          TRUE,
                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
   
@@ -305,16 +309,16 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
   g_object_class_install_property (object_class,
                                    PROP_WIDGET,
                                    g_param_spec_object ("widget",
-                                                        _("Widget"),
-                                                        _("Widget to put in column header button instead of column title"),
+                                                        P_("Widget"),
+                                                        P_("Widget to put in column header button instead of column title"),
                                                         GTK_TYPE_WIDGET,
                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
 
   g_object_class_install_property (object_class,
                                    PROP_ALIGNMENT,
                                    g_param_spec_float ("alignment",
-                                                       _("Alignment"),
-                                                       _("X Alignment of the column header text or widget"),
+                                                       P_("Alignment"),
+                                                       P_("X Alignment of the column header text or widget"),
                                                        0.0,
                                                        1.0,
                                                        0.5,
@@ -323,24 +327,24 @@ gtk_tree_view_column_class_init (GtkTreeViewColumnClass *class)
   g_object_class_install_property (object_class,
                                    PROP_REORDERABLE,
                                    g_param_spec_boolean ("reorderable",
-                                                        _("Reorderable"),
-                                                        _("Whether the column can be reordered around the headers"),
+                                                        P_("Reorderable"),
+                                                        P_("Whether the column can be reordered around the headers"),
                                                         FALSE,
                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
 
   g_object_class_install_property (object_class,
                                    PROP_SORT_INDICATOR,
                                    g_param_spec_boolean ("sort_indicator",
-                                                        _("Sort indicator"),
-                                                        _("Whether to show a sort indicator"),
+                                                        P_("Sort indicator"),
+                                                        P_("Whether to show a sort indicator"),
                                                          FALSE,
                                                          G_PARAM_READABLE | G_PARAM_WRITABLE));
 
   g_object_class_install_property (object_class,
                                    PROP_SORT_ORDER,
                                    g_param_spec_enum ("sort_order",
-                                                      _("Sort order"),
-                                                      _("Sort direction the sort indicator should indicate"),
+                                                      P_("Sort order"),
+                                                      P_("Sort direction the sort indicator should indicate"),
                                                       GTK_TYPE_SORT_TYPE,
                                                       GTK_SORT_ASCENDING,
                                                       G_PARAM_READABLE | G_PARAM_WRITABLE));
@@ -356,6 +360,7 @@ gtk_tree_view_column_cell_layout_init (GtkCellLayoutIface *iface)
   iface->add_attribute = gtk_tree_view_column_cell_layout_add_attribute;
   iface->set_cell_data_func = gtk_tree_view_column_cell_layout_set_cell_data_func;
   iface->clear_attributes = gtk_tree_view_column_cell_layout_clear_attributes;
+  iface->reorder = gtk_tree_view_column_cell_layout_reorder;
 }
 
 static void
@@ -652,23 +657,21 @@ gtk_tree_view_column_cell_layout_pack_end (GtkCellLayout   *cell_layout,
 static void
 gtk_tree_view_column_cell_layout_clear (GtkCellLayout *cell_layout)
 {
-  GList *list;
   GtkTreeViewColumn *column;
 
   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (cell_layout));
   column = GTK_TREE_VIEW_COLUMN (cell_layout);
 
-  for (list = column->cell_list; list; list = list->next)
+  while (column->cell_list)
     {
-      GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *)list->data;
+      GtkTreeViewColumnCellInfo *info = (GtkTreeViewColumnCellInfo *)column->cell_list->data;
 
-      gtk_tree_view_column_clear_attributes (column, info->cell);
-      g_object_unref (info->cell);
+      gtk_tree_view_column_cell_layout_clear_attributes (cell_layout, info->cell);
+      g_object_unref (G_OBJECT (info->cell));
       g_free (info);
+      column->cell_list = g_list_delete_link (column->cell_list, 
+                                             column->cell_list);
     }
-
-  g_list_free (column->cell_list);
-  column->cell_list = NULL;
 }
 
 static void
@@ -739,6 +742,33 @@ gtk_tree_view_column_cell_layout_clear_attributes (GtkCellLayout    *cell_layout
   gtk_tree_view_column_clear_attributes_by_info (column, info);
 }
 
+static void
+gtk_tree_view_column_cell_layout_reorder (GtkCellLayout   *cell_layout,
+                                          GtkCellRenderer *cell,
+                                          gint             position)
+{
+  GList *link;
+  GtkTreeViewColumn *column;
+  GtkTreeViewColumnCellInfo *info;
+
+  g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (cell_layout));
+  column = GTK_TREE_VIEW_COLUMN (cell_layout);
+
+  info = gtk_tree_view_column_get_cell_info (column, cell);
+
+  g_return_if_fail (info != NULL);
+  g_return_if_fail (position >= 0);
+
+  link = g_list_find (column->cell_list, info);
+
+  g_return_if_fail (link != NULL);
+
+  column->cell_list = g_list_remove_link (column->cell_list, link);
+  column->cell_list = g_list_insert (column->cell_list, info, position);
+
+  gtk_widget_queue_draw (column->tree_view);
+}
+
 static void
 gtk_tree_view_column_clear_attributes_by_info (GtkTreeViewColumn *tree_column,
                                               GtkTreeViewColumnCellInfo *info)
@@ -1187,8 +1217,10 @@ _gtk_tree_view_column_realize_button (GtkTreeViewColumn *column)
   GtkTreeView *tree_view;
   GdkWindowAttr attr;
   guint attributes_mask;
+  gboolean rtl;
 
   tree_view = (GtkTreeView *)column->tree_view;
+  rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
 
   g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
   g_return_if_fail (GTK_WIDGET_REALIZED (tree_view));
@@ -1204,8 +1236,8 @@ _gtk_tree_view_column_realize_button (GtkTreeViewColumn *column)
   attr.wclass = GDK_INPUT_ONLY;
   attr.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
   attr.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
-  attr.event_mask = gtk_widget_get_events (GTK_WIDGET (tree_view));
-  attr.event_mask = (GDK_BUTTON_PRESS_MASK |
+  attr.event_mask = gtk_widget_get_events (GTK_WIDGET (tree_view)) |
+                    (GDK_BUTTON_PRESS_MASK |
                     GDK_BUTTON_RELEASE_MASK |
                     GDK_POINTER_MOTION_MASK |
                     GDK_POINTER_MOTION_HINT_MASK |
@@ -1217,8 +1249,7 @@ _gtk_tree_view_column_realize_button (GtkTreeViewColumn *column)
   attr.width = TREE_VIEW_DRAG_WIDTH;
   attr.height = tree_view->priv->header_height;
 
-  attr.x = (column->button->allocation.x + column->button->allocation.width) - 3;
-          
+  attr.x = (column->button->allocation.x + (rtl ? 0 : column->button->allocation.width)) - 3;
   column->window = gdk_window_new (tree_view->priv->header_window,
                                   &attr, attributes_mask);
   gdk_window_set_user_data (column->window, tree_view);
@@ -1442,11 +1473,11 @@ gtk_tree_view_column_get_cell_info (GtkTreeViewColumn *tree_column,
  * gtk_tree_view_column_pack_start:
  * @tree_column: A #GtkTreeViewColumn.
  * @cell: The #GtkCellRenderer. 
- * @expand: %TRUE if @cell is to be given extra space allocated to box.
+ * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
  *
- * Packs the @cell into the beginning of the column. If @expand is FALSE, then
+ * Packs the @cell into the beginning of the column. If @expand is %FALSE, then
  * the @cell is allocated no more space than it needs. Any unused space is divided
- * evenly between cells for which @expand is TRUE.
+ * evenly between cells for which @expand is %TRUE.
  **/
 void
 gtk_tree_view_column_pack_start (GtkTreeViewColumn *tree_column,
@@ -1460,11 +1491,11 @@ gtk_tree_view_column_pack_start (GtkTreeViewColumn *tree_column,
  * gtk_tree_view_column_pack_end:
  * @tree_column: A #GtkTreeViewColumn.
  * @cell: The #GtkCellRenderer. 
- * @expand: %TRUE if @cell is to be given extra space allocated to box.
+ * @expand: %TRUE if @cell is to be given extra space allocated to @tree_column.
  *
- * Adds the @cell to end of the column. If @expand is FALSE, then the @cell
+ * Adds the @cell to end of the column. If @expand is %FALSE, then the @cell
  * is allocated no more space than it needs. Any unused space is divided
- * evenly between cells for which @expand is TRUE.
+ * evenly between cells for which @expand is %TRUE.
  **/
 void
 gtk_tree_view_column_pack_end (GtkTreeViewColumn  *tree_column,
@@ -1719,7 +1750,7 @@ gtk_tree_view_column_get_visible (GtkTreeViewColumn *tree_column)
  * @resizable: %TRUE, if the column can be resized
  * 
  * If @resizable is %TRUE, then the user can explicitly resize the column by
- * grabbing the outer edge of the column button.  If resizable is TRUE and
+ * grabbing the outer edge of the column button.  If resizable is %TRUE and
  * sizing mode of the column is #GTK_TREE_VIEW_COLUMN_AUTOSIZE, then the sizing
  * mode is changed to #GTK_TREE_VIEW_COLUMN_GROW_ONLY.
  **/
@@ -1848,6 +1879,7 @@ gtk_tree_view_column_set_fixed_width (GtkTreeViewColumn *tree_column,
   g_return_if_fail (fixed_width > 0);
 
   tree_column->fixed_width = fixed_width;
+  tree_column->use_resized_width = FALSE;
 
   if (tree_column->tree_view &&
       GTK_WIDGET_REALIZED (tree_column->tree_view) &&
@@ -2024,13 +2056,13 @@ void
 gtk_tree_view_column_set_title (GtkTreeViewColumn *tree_column,
                                const gchar       *title)
 {
+  gchar *new_title;
+  
   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
 
+  new_title = g_strdup (title);
   g_free (tree_column->title);
-  if (title)
-    tree_column->title = g_strdup (title);
-  else
-    tree_column->title = NULL;
+  tree_column->title = new_title;
 
   gtk_tree_view_column_update_button (tree_column);
   g_object_notify (G_OBJECT (tree_column), "title");
@@ -2588,6 +2620,7 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
   GList *list;
   GdkRectangle real_cell_area;
   GdkRectangle real_background_area;
+  GdkRectangle real_expose_area = *cell_area;
   gint expand_cell_count = 0;
   gint full_requested_width = 0;
   gint extra_space;
@@ -2704,7 +2737,7 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
                                    tree_column->tree_view,
                                    &rtl_background_area,
                                    &rtl_cell_area,
-                                   expose_area,
+                                   &real_expose_area, 
                                    flags);
        }
 
@@ -2859,7 +2892,7 @@ gtk_tree_view_column_cell_process_action (GtkTreeViewColumn  *tree_column,
                                    tree_column->tree_view,
                                    &rtl_background_area,
                                    &rtl_cell_area,
-                                   expose_area,
+                                   &real_expose_area,
                                    flags);
        }
       /* FOCUS */
@@ -3317,7 +3350,7 @@ _gtk_tree_view_column_cell_draw_focus (GtkTreeViewColumn       *tree_column,
       gtk_paint_focus (tree_column->tree_view->style,
                       window,
                       cell_state,
-                      NULL,
+                      cell_area,
                       tree_column->tree_view,
                       "treeview",
                       focus_rectangle.x,