]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrecentchooserdefault.c
gtk: remove "gboolean homogeneous" from gtk_box_new()
[~andy/gtk] / gtk / gtkrecentchooserdefault.c
index 562924559744e613d0a9d4967c758050a382e1fa..f1caf17e26d2ed39ec56e5c1de94d5b7e5c09400 100644 (file)
@@ -29,8 +29,6 @@
 #include <unistd.h>
 #endif
 
-#include <gdk/gdkscreen.h>
-
 #include "gtkstock.h"
 #include "gtkicontheme.h"
 #include "gtkiconfactory.h"
@@ -43,7 +41,7 @@
 #include "gtkcellrenderertext.h"
 #include "gtkcheckmenuitem.h"
 #include "gtkclipboard.h"
-#include "gtkcombobox.h"
+#include "gtkcomboboxtext.h"
 #include "gtkentry.h"
 #include "gtkeventbox.h"
 #include "gtkexpander.h"
@@ -59,6 +57,7 @@
 #include "gtkscrolledwindow.h"
 #include "gtkseparatormenuitem.h"
 #include "gtksizegroup.h"
+#include "gtksizerequest.h"
 #include "gtktable.h"
 #include "gtktreemodelsort.h"
 #include "gtktreemodelfilter.h"
@@ -67,6 +66,7 @@
 #include "gtktooltip.h"
 #include "gtktypebuiltins.h"
 #include "gtkvbox.h"
+#include "gtkactivatable.h"
 
 #include "gtkrecentmanager.h"
 #include "gtkrecentfilter.h"
 #include "gtkrecentchooserdefault.h"
 
 #include "gtkprivate.h"
-#include "gtkalias.h"
 
-\f
+
+enum 
+{
+  PROP_0,
+
+  /* activatable properties */
+  PROP_ACTIVATABLE_RELATED_ACTION,
+  PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
+};
+
 
 struct _GtkRecentChooserDefault
 {
@@ -153,15 +161,6 @@ enum {
   LOAD_FINISHED  /* the model is fully loaded and inserted */
 };
 
-enum {
-  TEXT_URI_LIST
-};
-
-/* Target types for DnD from the file list */
-static const GtkTargetEntry recent_list_source_targets[] = {
-  { "text/uri-list", 0, TEXT_URI_LIST }
-};
-
 /* Icon size for if we can't get it from the theme */
 #define FALLBACK_ICON_SIZE  48
 #define FALLBACK_ITEM_LIMIT 20
@@ -285,13 +284,20 @@ static gboolean recent_view_query_tooltip_cb      (GtkWidget        *widget,
                                                    GtkTooltip       *tooltip,
                                                    gpointer          user_data);
 
-
+static void gtk_recent_chooser_activatable_iface_init (GtkActivatableIface  *iface);
+static void gtk_recent_chooser_update                 (GtkActivatable       *activatable,
+                                                      GtkAction            *action,
+                                                      const gchar          *property_name);
+static void gtk_recent_chooser_sync_action_properties (GtkActivatable       *activatable,
+                                                      GtkAction            *action);
 
 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDefault,
                         _gtk_recent_chooser_default,
                         GTK_TYPE_VBOX,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
-                                               gtk_recent_chooser_iface_init))
+                                               gtk_recent_chooser_iface_init)
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
+                                               gtk_recent_chooser_activatable_iface_init))
 
 
 \f
@@ -313,6 +319,14 @@ gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
   iface->list_filters = gtk_recent_chooser_default_list_filters;
 }
 
+static void
+gtk_recent_chooser_activatable_iface_init (GtkActivatableIface *iface)
+
+{
+  iface->update = gtk_recent_chooser_update;
+  iface->sync_action_properties = gtk_recent_chooser_sync_action_properties;
+}
+
 static void
 _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
 {
@@ -329,6 +343,9 @@ _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
   widget_class->show_all = gtk_recent_chooser_default_show_all;
   
   _gtk_recent_chooser_install_properties (gobject_class);
+
+  g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
+  g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
 }
 
 static void
@@ -345,7 +362,7 @@ _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
   impl->show_icons = TRUE;
   impl->show_private = FALSE;
   impl->show_not_found = TRUE;
-  impl->show_tips = TRUE;
+  impl->show_tips = FALSE;
   impl->select_multiple = FALSE;
   impl->local_only = TRUE;
   
@@ -398,9 +415,9 @@ gtk_recent_chooser_default_constructor (GType                  type,
                    G_CALLBACK (recent_view_popup_menu_cb), impl);
   g_signal_connect (impl->recent_view, "button-press-event",
                    G_CALLBACK (recent_view_button_press_cb), impl);
-  g_signal_connect (impl->recent_view, "drag_begin",
+  g_signal_connect (impl->recent_view, "drag-begin",
                    G_CALLBACK (recent_view_drag_begin_cb), impl);
-  g_signal_connect (impl->recent_view, "drag_data_get",
+  g_signal_connect (impl->recent_view, "drag-data-get",
                    G_CALLBACK (recent_view_drag_data_get_cb), impl);
 
   g_object_set (impl->recent_view, "has-tooltip", TRUE, NULL);
@@ -418,6 +435,7 @@ gtk_recent_chooser_default_constructor (GType                  type,
   gtk_tree_view_column_set_resizable (impl->icon_column, FALSE);
   
   renderer = gtk_cell_renderer_pixbuf_new ();
+  g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
   gtk_tree_view_column_pack_start (impl->icon_column, renderer, FALSE);
   gtk_tree_view_column_set_cell_data_func (impl->icon_column,
                                           renderer,
@@ -451,13 +469,13 @@ gtk_recent_chooser_default_constructor (GType                  type,
   /* drag and drop */
   gtk_drag_source_set (impl->recent_view,
                       GDK_BUTTON1_MASK,
-                      recent_list_source_targets,
-                      G_N_ELEMENTS (recent_list_source_targets),
+                      NULL, 0,
                       GDK_ACTION_COPY);
+  gtk_drag_source_add_uri_targets (impl->recent_view);
 
-  impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
-  
-  impl->filter_combo = gtk_combo_box_new_text ();
+  impl->filter_combo_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+
+  impl->filter_combo = gtk_combo_box_text_new ();
   gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
   g_signal_connect (impl->filter_combo, "changed",
                     G_CALLBACK (filter_combo_changed_cb), impl);
@@ -539,6 +557,12 @@ gtk_recent_chooser_default_set_property (GObject      *object,
     case GTK_RECENT_CHOOSER_PROP_FILTER:
       set_current_filter (impl, g_value_get_object (value));
       break;
+    case PROP_ACTIVATABLE_RELATED_ACTION:
+      _gtk_recent_chooser_set_related_action (GTK_RECENT_CHOOSER (impl), g_value_get_object (value));
+      break;
+    case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: 
+      _gtk_recent_chooser_set_use_action_appearance (GTK_RECENT_CHOOSER (impl), g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -582,6 +606,12 @@ gtk_recent_chooser_default_get_property (GObject    *object,
     case GTK_RECENT_CHOOSER_PROP_FILTER:
       g_value_set_object (value, impl->current_filter);
       break;
+    case PROP_ACTIVATABLE_RELATED_ACTION:
+      g_value_set_object (value, _gtk_recent_chooser_get_related_action (GTK_RECENT_CHOOSER (impl)));
+      break;
+    case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: 
+      g_value_set_boolean (value, _gtk_recent_chooser_get_use_action_appearance (GTK_RECENT_CHOOSER (impl)));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -682,8 +712,9 @@ error_message_with_parent (GtkWindow   *parent,
   gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                            "%s", detail);
 
-  if (parent->group)
-    gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
+  if (gtk_window_has_group (parent))
+    gtk_window_group_add_window (gtk_window_get_group (parent),
+                                 GTK_WINDOW (dialog));
 
   gtk_dialog_run (GTK_DIALOG (dialog));
   gtk_widget_destroy (dialog);
@@ -696,7 +727,7 @@ get_toplevel (GtkWidget *widget)
   GtkWidget *toplevel;
 
   toplevel = gtk_widget_get_toplevel (widget);
-  if (!GTK_WIDGET_TOPLEVEL (toplevel))
+  if (!gtk_widget_is_toplevel (toplevel))
     return NULL;
   else
     return GTK_WINDOW (toplevel);
@@ -720,7 +751,7 @@ set_busy_cursor (GtkRecentChooserDefault *impl,
   GdkCursor *cursor;
 
   toplevel = get_toplevel (GTK_WIDGET (impl));
-  if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
+  if (!toplevel || !gtk_widget_get_realized (GTK_WIDGET (toplevel)))
     return;
   
   display = gtk_widget_get_display (GTK_WIDGET (toplevel));
@@ -729,7 +760,8 @@ set_busy_cursor (GtkRecentChooserDefault *impl,
   if (show_busy_cursor)
     cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
 
-  gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
+  gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (toplevel)),
+                         cursor);
   gdk_display_flush (display);
 
   if (cursor)
@@ -908,20 +940,21 @@ set_default_size (GtkRecentChooserDefault *impl)
   widget = GTK_WIDGET (impl);
 
   /* Size based on characters and the icon size */
-  font_size = pango_font_description_get_size (widget->style->font_desc);
+  font_size = pango_font_description_get_size (gtk_widget_get_style (widget)->font_desc);
   font_size = PANGO_PIXELS (font_size);
 
   width = impl->icon_size + font_size * NUM_CHARS;
   height = (impl->icon_size + font_size) * NUM_LINES;
 
   /* Use at least the requisition size... */
-  gtk_widget_size_request (widget, &req);
+  gtk_widget_get_preferred_size (widget, &req, NULL);
   width = MAX (width, req.width);
   height = MAX (height, req.height);
 
   /* ... but no larger than the monitor */
   screen = gtk_widget_get_screen (widget);
-  monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
+  monitor_num = gdk_screen_get_monitor_at_window (screen,
+                                                  gtk_widget_get_window (widget));
 
   gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
 
@@ -936,9 +969,8 @@ static void
 gtk_recent_chooser_default_map (GtkWidget *widget)
 {
   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (widget);
-  
-  if (GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map)
-    GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);
+
+  GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);
 
   /* reloads everything */
   reload_recent_items (impl);
@@ -953,23 +985,17 @@ recent_icon_data_func (GtkTreeViewColumn *tree_column,
                       GtkTreeIter       *iter,
                       gpointer           user_data)
 {
-  GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
   GtkRecentInfo *info = NULL;
-  GdkPixbuf *pixbuf;
-  
-  gtk_tree_model_get (model, iter,
-                      RECENT_INFO_COLUMN, &info,
-                      -1);
+  GIcon *icon;
+
+  gtk_tree_model_get (model, iter, RECENT_INFO_COLUMN, &info, -1);
   g_assert (info != NULL);
-  
-  pixbuf = gtk_recent_info_get_icon (info, impl->icon_size);
-  
-  g_object_set (cell,
-                "pixbuf", pixbuf,
-                NULL);
-  
-  if (pixbuf)  
-    g_object_unref (pixbuf);
+
+  icon = gtk_recent_info_get_gicon (info);
+  g_object_set (cell, "gicon", icon, NULL);
+
+  if (icon != NULL)
+    g_object_unref (icon);
 
   gtk_recent_info_unref (info);
 }
@@ -1269,9 +1295,9 @@ gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
   name = gtk_recent_filter_get_name (filter);
   if (!name)
     name = _("Untitled filter");
-    
-  gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
-  
+
+  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (impl->filter_combo), name);
+
   if (!g_slist_find (impl->filters, impl->current_filter))
     set_current_filter (impl, filter);
   
@@ -1535,25 +1561,23 @@ recent_view_drag_data_get_cb (GtkWidget        *widget,
                              gpointer          data)
 {
   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
-  DragData *drag_data;
+  DragData drag_data;
   gsize n_uris;
   
   n_uris = gtk_tree_selection_count_selected_rows (impl->selection);
   if (n_uris == 0)
-         return;
+    return;
 
-  drag_data = g_new (DragData, 1);
-  drag_data->uri_list = g_new0 (gchar *, n_uris + 1);
-  drag_data->next_pos = 0;
+  drag_data.uri_list = g_new0 (gchar *, n_uris + 1);
+  drag_data.next_pos = 0;
   
   gtk_tree_selection_selected_foreach (impl->selection,
                                       append_uri_to_urilist,
-                                      drag_data);
+                                      &drag_data);
   
-  gtk_selection_data_set_uris (selection_data, drag_data->uri_list);
+  gtk_selection_data_set_uris (selection_data, drag_data.uri_list);
 
-  g_strfreev (drag_data->uri_list);
-  g_free (drag_data);
+  g_strfreev (drag_data.uri_list);
 }
 
 static gboolean
@@ -1623,7 +1647,7 @@ remove_selected_from_list (GtkRecentChooserDefault *impl)
     {
       gchar *msg;
    
-      msg = strdup (_("Could not remove item"));
+      msg = g_strdup (_("Could not remove item"));
       error_message (impl, msg, err->message);
       
       g_free (msg);
@@ -1651,6 +1675,7 @@ copy_activated_cb (GtkMenuItem *menu_item,
                                                    GDK_SELECTION_CLIPBOARD),
                           utf8_uri, -1);
 
+  gtk_recent_info_unref (info);
   g_free (utf8_uri);
 }
 
@@ -1805,21 +1830,25 @@ popup_position_func (GtkMenu   *menu,
                      gboolean  *push_in,
                      gpointer  user_data)
 {
+  GtkAllocation allocation;
   GtkWidget *widget = GTK_WIDGET (user_data);
   GdkScreen *screen = gtk_widget_get_screen (widget);
   GtkRequisition req;
   gint monitor_num;
   GdkRectangle monitor;
 
-  if (G_UNLIKELY (!GTK_WIDGET_REALIZED (widget)))
+  if (G_UNLIKELY (!gtk_widget_get_realized (widget)))
     return;
 
-  gdk_window_get_origin (widget->window, x, y);
+  gdk_window_get_origin (gtk_widget_get_window (widget),
+                         x, y);
 
-  gtk_widget_size_request (GTK_WIDGET (menu), &req);
+  gtk_widget_get_preferred_size (GTK_WIDGET (menu),
+                                 &req, NULL);
 
-  *x += (widget->allocation.width - req.width) / 2;
-  *y += (widget->allocation.height - req.height) / 2;
+  gtk_widget_get_allocation (widget, &allocation);
+  *x += (allocation.width - req.width) / 2;
+  *y += (allocation.height - req.height) / 2;
 
   monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
   gtk_menu_set_monitor (menu, monitor_num);
@@ -1923,6 +1952,44 @@ set_recent_manager (GtkRecentChooserDefault *impl,
     }
 }
 
+static void
+gtk_recent_chooser_update (GtkActivatable *activatable,
+                          GtkAction      *action,
+                          const gchar    *property_name)
+{
+  if (strcmp (property_name, "visible") == 0)
+    {
+      if (gtk_action_is_visible (action))
+       gtk_widget_show (GTK_WIDGET (activatable));
+      else
+       gtk_widget_hide (GTK_WIDGET (activatable));
+    }
+
+  if (strcmp (property_name, "sensitive") == 0)
+    gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
+
+  _gtk_recent_chooser_update (activatable, action, property_name);
+}
+
+
+static void 
+gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
+                                          GtkAction      *action)
+{
+  if (action)
+    {
+      if (gtk_action_is_visible (action))
+       gtk_widget_show (GTK_WIDGET (activatable));
+      else
+       gtk_widget_hide (GTK_WIDGET (activatable));
+      
+      gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
+    }
+
+  _gtk_recent_chooser_sync_action_properties (activatable, action);
+}
+
+
 GtkWidget *
 _gtk_recent_chooser_default_new (GtkRecentManager *manager)
 {