]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkiconview.c
Replace a lot of idle and timeout calls by the new gdk_threads api.
[~andy/gtk] / gtk / gtkiconview.c
index b33395c7a930673152042f113b75cb8bb92d6e3d..45280f63c4e38ec2d13dacb0f77072094e71432e 100644 (file)
@@ -222,7 +222,6 @@ enum
 };
 
 /* GObject vfuncs */
-static void             gtk_icon_view_class_init                (GtkIconViewClass   *klass);
 static void             gtk_icon_view_cell_layout_init          (GtkCellLayoutIface *iface);
 static void             gtk_icon_view_finalize                  (GObject            *object);
 static void             gtk_icon_view_set_property              (GObject            *object,
@@ -240,6 +239,10 @@ static void             gtk_icon_view_destroy                   (GtkObject
 /* GtkWidget vfuncs */
 static void             gtk_icon_view_realize                   (GtkWidget          *widget);
 static void             gtk_icon_view_unrealize                 (GtkWidget          *widget);
+static void             gtk_icon_view_style_set                 (GtkWidget        *widget,
+                                                                GtkStyle         *previous_style);
+static void             gtk_icon_view_state_changed             (GtkWidget        *widget,
+                                                                GtkStateType      previous_state);
 static void             gtk_icon_view_size_request              (GtkWidget          *widget,
                                                                 GtkRequisition     *requisition);
 static void             gtk_icon_view_size_allocate             (GtkWidget          *widget,
@@ -441,7 +444,7 @@ static guint icon_view_signals[LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
-                                               gtk_icon_view_cell_layout_init));
+                                               gtk_icon_view_cell_layout_init))
 
 static void
 gtk_icon_view_class_init (GtkIconViewClass *klass)
@@ -469,6 +472,8 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
   
   widget_class->realize = gtk_icon_view_realize;
   widget_class->unrealize = gtk_icon_view_unrealize;
+  widget_class->style_set = gtk_icon_view_style_set;
+  widget_class->get_accessible = gtk_icon_view_get_accessible;
   widget_class->size_request = gtk_icon_view_size_request;
   widget_class->size_allocate = gtk_icon_view_size_allocate;
   widget_class->expose_event = gtk_icon_view_expose;
@@ -483,7 +488,7 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
   widget_class->drag_motion = gtk_icon_view_drag_motion;
   widget_class->drag_drop = gtk_icon_view_drag_drop;
   widget_class->drag_data_received = gtk_icon_view_drag_data_received;
-  widget_class->get_accessible = gtk_icon_view_get_accessible;
+  widget_class->state_changed = gtk_icon_view_state_changed;
 
   container_class->remove = gtk_icon_view_remove;
   container_class->forall = gtk_icon_view_forall;
@@ -598,7 +603,7 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
   
 
   /**
-   * GtkIconView::item-width:
+   * GtkIconView:item-width:
    *
    * The item-width property specifies the width to use for each item. 
    * If it is set to -1, the icon view will automatically determine a 
@@ -615,7 +620,7 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
                                                     GTK_PARAM_READWRITE));  
 
   /**
-   * GtkIconView::spacing:
+   * GtkIconView:spacing:
    *
    * The spacing property specifies the space which is inserted between
    * the cells (i.e. the icon and the text) of an item.
@@ -631,7 +636,7 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
                                                     GTK_PARAM_READWRITE));
 
   /**
-   * GtkIconView::row-spacing:
+   * GtkIconView:row-spacing:
    *
    * The row-spacing property specifies the space which is inserted between
    * the rows of the icon view.
@@ -647,7 +652,7 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
                                                     GTK_PARAM_READWRITE));
 
   /**
-   * GtkIconView::column-spacing:
+   * GtkIconView:column-spacing:
    *
    * The column-spacing property specifies the space which is inserted between
    * the columns of the icon view.
@@ -663,7 +668,7 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
                                                     GTK_PARAM_READWRITE));
 
   /**
-   * GtkIconView::margin:
+   * GtkIconView:margin:
    *
    * The margin property specifies the space which is inserted 
    * at the edges of the icon view.
@@ -680,7 +685,7 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
 
 
   /**
-   * GtkIconView::orientation:
+   * GtkIconView:orientation:
    *
    * The orientation property specifies how the cells (i.e. the icon and 
    * the text) of the item are positioned relative to each other.
@@ -750,7 +755,7 @@ gtk_icon_view_class_init (GtkIconViewClass *klass)
                  GTK_TYPE_TREE_PATH);
 
   icon_view_signals[SELECTION_CHANGED] =
-    g_signal_new (I_("selection_changed"),
+    g_signal_new (I_("selection-changed"),
                  G_TYPE_FROM_CLASS (gobject_class),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
@@ -949,6 +954,18 @@ gtk_icon_view_destroy (GtkObject *object)
     }
 
   remove_scroll_timeout (icon_view);
+
+  if (icon_view->priv->hadjustment != NULL)
+    {
+      g_object_unref (icon_view->priv->hadjustment);
+      icon_view->priv->hadjustment = NULL;
+    }
+
+  if (icon_view->priv->vadjustment != NULL)
+    {
+      g_object_unref (icon_view->priv->vadjustment);
+      icon_view->priv->vadjustment = NULL;
+    }
   
   (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
 }
@@ -1106,6 +1123,7 @@ gtk_icon_view_realize (GtkWidget *widget)
 
   widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
                                   &attributes, attributes_mask);
+  gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
   gdk_window_set_user_data (widget->window, widget);
 
   /* Make the window for the icon view */
@@ -1128,7 +1146,6 @@ gtk_icon_view_realize (GtkWidget *widget)
 
   widget->style = gtk_style_attach (widget->style, widget->window);
   gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
-  gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
 
   gdk_window_show (icon_view->priv->bin_window);
 }
@@ -1149,6 +1166,40 @@ gtk_icon_view_unrealize (GtkWidget *widget)
     (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
 }
 
+static void
+gtk_icon_view_state_changed (GtkWidget      *widget,
+                            GtkStateType    previous_state)
+{
+  GtkIconView *icon_view = GTK_ICON_VIEW (widget);
+
+  if (GTK_WIDGET_REALIZED (widget))
+    {
+      gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
+      gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
+    }
+
+  gtk_widget_queue_draw (widget);
+}
+
+static void
+gtk_icon_view_style_set (GtkWidget *widget,
+                        GtkStyle *previous_style)
+{
+  GtkIconView *icon_view;
+
+  g_return_if_fail (GTK_IS_ICON_VIEW (widget));
+
+  icon_view = GTK_ICON_VIEW (widget);
+
+  if (GTK_WIDGET_REALIZED (widget))
+    {
+      gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
+      gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
+    }
+
+  gtk_widget_queue_resize (widget);
+}
+
 static void
 gtk_icon_view_size_request (GtkWidget      *widget,
                            GtkRequisition *requisition)
@@ -1410,8 +1461,6 @@ rubberband_scroll_timeout (gpointer data)
   GtkIconView *icon_view;
   gdouble value;
 
-  GDK_THREADS_ENTER ();
-  
   icon_view = data;
 
   value = MIN (icon_view->priv->vadjustment->value +
@@ -1423,8 +1472,6 @@ rubberband_scroll_timeout (gpointer data)
 
   gtk_icon_view_update_rubberband (icon_view);
   
-  GDK_THREADS_LEAVE ();
-
   return TRUE;
 }
 
@@ -1459,7 +1506,7 @@ gtk_icon_view_motion (GtkWidget      *widget,
          icon_view->priv->event_last_y = event->y;
 
          if (icon_view->priv->scroll_timeout_id == 0)
-           icon_view->priv->scroll_timeout_id = g_timeout_add (30, rubberband_scroll_timeout, 
+           icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout, 
                                                                icon_view);
        }
       else 
@@ -1650,7 +1697,7 @@ gtk_icon_view_start_editing (GtkIconView         *icon_view,
 
       /* FIXME ugly special case */ 
       if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
-       g_object_set (editable, "has_frame", TRUE, NULL);
+       g_object_set (editable, "has-frame", TRUE, NULL);
 
       /* the rest corresponds to tree_view_real_start_editing... */
       icon_view->priv->edited_item = item;
@@ -1720,7 +1767,7 @@ gtk_icon_view_stop_editing (GtkIconView *icon_view,
  * gtk_icon_view_set_cursor:
  * @icon_view: A #GtkIconView
  * @path: A #GtkTreePath
- * @cell: A #GtkCellRenderer or %NULL
+ * @cell: One of the cell renderers of @icon_view, or %NULL
  * @start_editing: %TRUE if the specified cell should start being edited.
  *
  * Sets the current keyboard focus to be at @path, and selects it.  This is
@@ -1758,29 +1805,27 @@ gtk_icon_view_set_cursor (GtkIconView     *icon_view,
   
   if (!item)
     return;
-  
+
   cell_pos = -1;
   for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
     {
       info = l->data;
-
+      
       if (info->cell == cell)
        {
          cell_pos = i;
          break;
        }
-
+         
       info = NULL;
     }
+  
+  g_return_if_fail (cell == NULL || info != NULL);
 
   gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
-  if (FALSE && GTK_WIDGET_REALIZED (icon_view))
-    gtk_icon_view_scroll_to_item (icon_view, item);
-  else
-    gtk_icon_view_scroll_to_path (icon_view, path,
-                                 FALSE, 0.0, 0.0);
-
-  if (start_editing)
+  gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
+  
+  if (info && start_editing)
     gtk_icon_view_start_editing (icon_view, item, info, NULL);
 }
 
@@ -3018,16 +3063,12 @@ layout_callback (gpointer user_data)
 {
   GtkIconView *icon_view;
 
-  GDK_THREADS_ENTER ();
-
   icon_view = GTK_ICON_VIEW (user_data);
   
   icon_view->priv->layout_idle_id = 0;
 
   gtk_icon_view_layout (icon_view);
   
-  GDK_THREADS_LEAVE();
-
   return FALSE;
 }
 
@@ -3037,7 +3078,7 @@ gtk_icon_view_queue_layout (GtkIconView *icon_view)
   if (icon_view->priv->layout_idle_id != 0)
     return;
 
-  icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
+  icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
 }
 
 static void
@@ -3747,7 +3788,10 @@ gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
     }
 
   if (!item)
-    return;
+    {
+      gtk_widget_error_bell (GTK_WIDGET (icon_view));
+      return;
+    }
 
   if (icon_view->priv->ctrl_pressed ||
       !icon_view->priv->shift_pressed ||
@@ -3798,6 +3842,9 @@ gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
                                   icon_view->priv->cursor_item,
                                   count);
 
+  if (item == icon_view->priv->cursor_item)
+    gtk_widget_error_bell (GTK_WIDGET (icon_view));
+
   if (!item)
     return;
 
@@ -3866,7 +3913,10 @@ gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
     }
 
   if (!item)
-    return;
+    {
+      gtk_widget_error_bell (GTK_WIDGET (icon_view));
+      return;
+    }
 
   if (icon_view->priv->ctrl_pressed ||
       !icon_view->priv->shift_pressed ||
@@ -3909,6 +3959,9 @@ gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
   
   item = list ? list->data : NULL;
 
+  if (item == icon_view->priv->cursor_item)
+    gtk_widget_error_bell (GTK_WIDGET (icon_view));
+
   if (!item)
     return;
 
@@ -3944,18 +3997,19 @@ gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
  * @col_align: The horizontal alignment of the item specified by @path.
  *
  * Moves the alignments of @icon_view to the position specified by @path.  
- * @row_align determines where the row is placed, and @col_align determines where 
- * @column is placed.  Both are expected to be between 0.0 and 1.0. 
- * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means center.
+ * @row_align determines where the row is placed, and @col_align determines 
+ * where @column is placed.  Both are expected to be between 0.0 and 1.0. 
+ * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means 
+ * center.
  *
  * If @use_align is %FALSE, then the alignment arguments are ignored, and the
  * tree does the minimum amount of work to scroll the item onto the screen.
  * This means that the item will be scrolled to the edge closest to its current
  * position.  If the item is currently visible on the screen, nothing is done.
  *
- * This function only works if the model is set, and @path is a valid row on the
- * model.  If the model changes before the @icon_view is realized, the centered
- * path will be modified to reflect this change.
+ * This function only works if the model is set, and @path is a valid row on 
+ * the model. If the model changes before the @icon_view is realized, the 
+ * centered path will be modified to reflect this change.
  *
  * Since: 2.8
  **/
@@ -4772,15 +4826,15 @@ update_text_cell (GtkIconView *icon_view)
 
       if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
        g_object_set (info->cell,
-                     "wrap_mode", PANGO_WRAP_CHAR,
-                     "wrap_width", icon_view->priv->item_width,
+                     "wrap-mode", PANGO_WRAP_CHAR,
+                     "wrap-width", icon_view->priv->item_width,
                      "xalign", 0.5,
                      "yalign", 0.0,
                      NULL);
       else
        g_object_set (info->cell,
-                     "wrap_mode", PANGO_WRAP_CHAR,
-                     "wrap_width", icon_view->priv->item_width,
+                     "wrap-mode", PANGO_WRAP_CHAR,
+                     "wrap-width", icon_view->priv->item_width,
                      "xalign", 0.0,
                      "yalign", 0.0,
                      NULL);
@@ -4840,13 +4894,13 @@ update_pixbuf_cell (GtkIconView *icon_view)
 
        if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
          g_object_set (info->cell,
-                       "follow_state", TRUE, 
+                       "follow-state", TRUE, 
                        "xalign", 0.5,
                        "yalign", 1.0,
                        NULL);
        else
          g_object_set (info->cell,
-                       "follow_state", TRUE, 
+                       "follow-state", TRUE, 
                        "xalign", 0.0,
                        "yalign", 0.0,
                        NULL);
@@ -5202,7 +5256,7 @@ gtk_icon_view_unselect_all (GtkIconView *icon_view)
  * @path: A #GtkTreePath to check selection on.
  * 
  * Returns %TRUE if the icon pointed to by @path is currently
- * selected. If @icon does not point to a valid location, %FALSE is returned.
+ * selected. If @path does not point to a valid location, %FALSE is returned.
  * 
  * Return value: %TRUE if @path is selected.
  *
@@ -5806,12 +5860,8 @@ drag_scroll_timeout (gpointer data)
 {
   GtkIconView *icon_view = GTK_ICON_VIEW (data);
 
-  GDK_THREADS_ENTER ();
-
   gtk_icon_view_autoscroll (icon_view);
 
-  GDK_THREADS_LEAVE ();
-
   return TRUE;
 }
 
@@ -6208,7 +6258,7 @@ gtk_icon_view_drag_motion (GtkWidget      *widget,
       if (icon_view->priv->scroll_timeout_id == 0)
        {
          icon_view->priv->scroll_timeout_id =
-           g_timeout_add (50, drag_scroll_timeout, icon_view);
+           gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
        }
 
       if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
@@ -6413,7 +6463,7 @@ gtk_icon_view_enable_model_drag_source (GtkIconView              *icon_view,
  * @icon_view: a #GtkIconView
  * @targets: the table of targets that the drag will support
  * @n_targets: the number of items in @targets
- * @actions: the bitmask of possible actions for a drag from this
+ * @actions: the bitmask of possible actions for a drag to this
  *    widget
  * 
  * Turns @icon_view into a drop destination for automatic DND.
@@ -6849,8 +6899,6 @@ gtk_icon_view_item_accessible_idle_do_action (gpointer data)
   GtkIconView *icon_view;
   GtkTreePath *path;
 
-  GDK_THREADS_ENTER ();
-
   item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
   item->action_idle_handler = 0;
 
@@ -6862,8 +6910,6 @@ gtk_icon_view_item_accessible_idle_do_action (gpointer data)
       gtk_tree_path_free (path);
     }
 
-  GDK_THREADS_LEAVE ();
-
   return FALSE;
 }
 
@@ -6888,7 +6934,7 @@ gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
     {
     case ACTION_ACTIVATE:
       if (!item->action_idle_handler)
-        item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
+        item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
       break;
     default:
       g_assert_not_reached ();
@@ -8042,7 +8088,7 @@ gtk_icon_view_item_accessible_get_type (void)
 
   if (!type)
     {
-      static const GTypeInfo tinfo =
+      const GTypeInfo tinfo =
       {
         sizeof (GtkIconViewItemAccessibleClass),
         (GBaseInitFunc) NULL, /* base init */
@@ -8364,7 +8410,7 @@ gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
   AtkObject *atk_obj;
 
   atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
-  g_signal_emit_by_name (atk_obj, "visible-data-changed");
+  g_signal_emit_by_name (atk_obj, "visible_data_changed");
 
   return;
 }
@@ -8489,7 +8535,6 @@ gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
 {
   GtkIconViewAccessiblePrivate *priv;
   GtkIconViewItemAccessibleInfo *info;
-  GtkIconViewAccessible *view;
   GtkIconView *icon_view;
   GtkIconViewItemAccessible *item;
   GList *items;
@@ -8497,7 +8542,6 @@ gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
 
   atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
   icon_view = GTK_ICON_VIEW (user_data);
-  view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
   priv = gtk_icon_view_accessible_get_priv (atk_obj);
 
   items = priv->items;
@@ -8534,16 +8578,16 @@ gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
   GObject *obj;
 
   obj = G_OBJECT (icon_view->priv->model);
-  g_signal_connect_data (obj, "row-changed",
+  g_signal_connect_data (obj, "row_changed",
                          (GCallback) gtk_icon_view_accessible_model_row_changed,
                          icon_view, NULL, 0);
-  g_signal_connect_data (obj, "row-inserted",
+  g_signal_connect_data (obj, "row_inserted",
                          (GCallback) gtk_icon_view_accessible_model_row_inserted, 
                          icon_view, NULL, G_CONNECT_AFTER);
-  g_signal_connect_data (obj, "row-deleted",
+  g_signal_connect_data (obj, "row_deleted",
                          (GCallback) gtk_icon_view_accessible_model_row_deleted, 
                          icon_view, NULL, G_CONNECT_AFTER);
-  g_signal_connect_data (obj, "rows-reordered",
+  g_signal_connect_data (obj, "rows_reordered",
                          (GCallback) gtk_icon_view_accessible_model_rows_reordered, 
                          icon_view, NULL, G_CONNECT_AFTER);
 }
@@ -8873,7 +8917,6 @@ gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
   GtkWidget *widget;
   GtkIconView *icon_view;
   GtkIconViewItem *item;
-  GList *l;
 
   widget = GTK_ACCESSIBLE (selection)->widget;
   if (widget == NULL)
@@ -9050,7 +9093,7 @@ gtk_icon_view_accessible_factory_get_type (void)
 
   if (!type)
     {
-      static const GTypeInfo tinfo =
+      const GTypeInfo tinfo =
       {
         sizeof (AtkObjectFactoryClass),
         NULL,           /* base_init */