[gtk/wip/otte/css: 45/48] filechooser: Remove default size machinery



commit afbff574f5ab49c81f05d1283339763a11e307ec
Author: Benjamin Otte <otte redhat com>
Date:   Mon Jan 27 22:58:15 2020 +0100

    filechooser: Remove default size machinery
    
    The FileChooser ToolKit (fctk) had its own machinery to handle default
    sizes which was completely busted and trying to marshal random numbers
    through the widget hierarchy that maybe made sense in 2012 but don't do
    now.
    
    Get rid of it, just keep the dialog's GSetting - which funnily enough
    used to be written by the dialog but written by the widget.
    But that's fctk for you.

 gtk/gtkfilechooserdialog.c     | 48 +++++++++-------------
 gtk/gtkfilechooserembed.c      | 42 -------------------
 gtk/gtkfilechooserembed.h      |  8 ----
 gtk/gtkfilechooserwidget.c     | 92 ------------------------------------------
 gtk/gtkfontchooserwidget.c     | 15 +++----
 gtk/ui/gtkfilechooserdialog.ui |  1 -
 6 files changed, 25 insertions(+), 181 deletions(-)
---
diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index 2ce649e258..b2929d988d 100644
--- a/gtk/gtkfilechooserdialog.c
+++ b/gtk/gtkfilechooserdialog.c
@@ -240,6 +240,7 @@ static void     gtk_file_chooser_dialog_get_property (GObject               *obj
 static void     gtk_file_chooser_dialog_notify       (GObject               *object,
                                                       GParamSpec            *pspec);
 
+static void     gtk_file_chooser_dialog_realize      (GtkWidget             *widget);
 static void     gtk_file_chooser_dialog_map          (GtkWidget             *widget);
 static void     gtk_file_chooser_dialog_unmap        (GtkWidget             *widget);
 static void     gtk_file_chooser_dialog_size_allocate (GtkWidget            *widget,
@@ -248,8 +249,6 @@ static void     gtk_file_chooser_dialog_size_allocate (GtkWidget            *wid
                                                        int                    baseline);
 static void     file_chooser_widget_file_activated   (GtkFileChooser        *chooser,
                                                       GtkFileChooserDialog  *dialog);
-static void     file_chooser_widget_default_size_changed (GtkWidget            *widget,
-                                                          GtkFileChooserDialog *dialog);
 static void     file_chooser_widget_response_requested (GtkWidget            *widget,
                                                         GtkFileChooserDialog *dialog);
 static void     file_chooser_widget_selection_changed (GtkWidget            *widget,
@@ -275,6 +274,7 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
   gobject_class->get_property = gtk_file_chooser_dialog_get_property;
   gobject_class->notify = gtk_file_chooser_dialog_notify;
 
+  widget_class->realize = gtk_file_chooser_dialog_realize;
   widget_class->map = gtk_file_chooser_dialog_map;
   widget_class->unmap = gtk_file_chooser_dialog_unmap;
   widget_class->size_allocate = gtk_file_chooser_dialog_size_allocate;
@@ -292,7 +292,6 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
   gtk_widget_class_bind_template_child_private (widget_class, GtkFileChooserDialog, buttons);
   gtk_widget_class_bind_template_callback (widget_class, response_cb);
   gtk_widget_class_bind_template_callback (widget_class, file_chooser_widget_file_activated);
-  gtk_widget_class_bind_template_callback (widget_class, file_chooser_widget_default_size_changed);
   gtk_widget_class_bind_template_callback (widget_class, file_chooser_widget_response_requested);
   gtk_widget_class_bind_template_callback (widget_class, file_chooser_widget_selection_changed);
 }
@@ -357,32 +356,6 @@ file_chooser_widget_file_activated (GtkFileChooser       *chooser,
   gtk_widget_activate_default (GTK_WIDGET (chooser));
 }
 
-static void
-file_chooser_widget_default_size_changed (GtkWidget            *widget,
-                                          GtkFileChooserDialog *dialog)
-{
-  GtkFileChooserDialogPrivate *priv = gtk_file_chooser_dialog_get_instance_private (dialog);
-  gint default_width, default_height;
-  GtkRequisition req, widget_req;
-
-  /* Unset any previously set size */
-  gtk_widget_set_size_request (GTK_WIDGET (dialog), -1, -1);
-
-  if (gtk_widget_is_drawable (widget))
-    {
-      /* Force a size request of everything before we start. This will make sure
-       * that widget->requisition is meaningful.
-       */
-      gtk_widget_get_preferred_size (GTK_WIDGET (dialog), &req, NULL);
-      gtk_widget_get_preferred_size (widget, &widget_req, NULL);
-    }
-
-  _gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget),
-                                            &default_width, &default_height);
-
-  gtk_window_resize (GTK_WINDOW (dialog), default_width, default_height);
-}
-
 static void
 file_chooser_widget_selection_changed (GtkWidget            *widget,
                                        GtkFileChooserDialog *dialog)
@@ -562,6 +535,23 @@ ensure_default_response (GtkFileChooserDialog *dialog)
     gtk_window_set_default_widget (GTK_WINDOW (dialog), widget);
 }
 
+static void
+gtk_file_chooser_dialog_realize (GtkWidget *widget)
+{
+  GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (widget);
+  GSettings *settings;
+  gint width, height;
+
+  settings = _gtk_file_chooser_get_settings_for_widget (widget);
+  g_settings_get (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", &width, &height);
+
+  if (width != 0 && height != 0)
+    gtk_window_set_default_size (GTK_WINDOW (dialog), width, height);
+  g_print ("%d %d\n", width, height);
+
+  GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->realize (widget);
+}
+
 static void
 gtk_file_chooser_dialog_map (GtkWidget *widget)
 {
diff --git a/gtk/gtkfilechooserembed.c b/gtk/gtkfilechooserembed.c
index 7c64f37961..24c171a730 100644
--- a/gtk/gtkfilechooserembed.c
+++ b/gtk/gtkfilechooserembed.c
@@ -22,13 +22,8 @@
 #include "gtkintl.h"
 
 static void gtk_file_chooser_embed_class_init (gpointer g_iface);
-static void delegate_get_default_size         (GtkFileChooserEmbed *chooser_embed,
-                                              gint                *default_width,
-                                              gint                *default_height);
 static gboolean delegate_should_respond       (GtkFileChooserEmbed *chooser_embed);
 static void delegate_initial_focus            (GtkFileChooserEmbed *chooser_embed);
-static void delegate_default_size_changed     (GtkFileChooserEmbed *chooser_embed,
-                                              gpointer             data);
 static void delegate_response_requested       (GtkFileChooserEmbed *chooser_embed,
                                               gpointer             data);
 
@@ -50,7 +45,6 @@ get_delegate (GtkFileChooserEmbed *receiver)
 void
 _gtk_file_chooser_embed_delegate_iface_init (GtkFileChooserEmbedIface *iface)
 {
-  iface->get_default_size = delegate_get_default_size;
   iface->should_respond = delegate_should_respond;
   iface->initial_focus = delegate_initial_focus;
 }
@@ -74,22 +68,12 @@ _gtk_file_chooser_embed_set_delegate (GtkFileChooserEmbed *receiver,
   
   g_object_set_data (G_OBJECT (receiver), I_("gtk-file-chooser-embed-delegate"), delegate);
 
-  g_signal_connect (delegate, "default-size-changed",
-                   G_CALLBACK (delegate_default_size_changed), receiver);
   g_signal_connect (delegate, "response-requested",
                    G_CALLBACK (delegate_response_requested), receiver);
 }
 
 
 
-static void
-delegate_get_default_size (GtkFileChooserEmbed *chooser_embed,
-                          gint                *default_width,
-                          gint                *default_height)
-{
-  _gtk_file_chooser_embed_get_default_size (get_delegate (chooser_embed), default_width, default_height);
-}
-
 static gboolean
 delegate_should_respond (GtkFileChooserEmbed *chooser_embed)
 {
@@ -102,13 +86,6 @@ delegate_initial_focus (GtkFileChooserEmbed *chooser_embed)
   _gtk_file_chooser_embed_initial_focus (get_delegate (chooser_embed));
 }
 
-static void
-delegate_default_size_changed (GtkFileChooserEmbed *chooser_embed,
-                              gpointer             data)
-{
-  g_signal_emit_by_name (data, "default-size-changed");
-}
-
 static void
 delegate_response_requested (GtkFileChooserEmbed *chooser_embed,
                             gpointer             data)
@@ -149,13 +126,6 @@ gtk_file_chooser_embed_class_init (gpointer g_iface)
 {
   GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
 
-  g_signal_new (I_("default-size-changed"),
-               iface_type,
-               G_SIGNAL_RUN_LAST,
-               G_STRUCT_OFFSET (GtkFileChooserEmbedIface, default_size_changed),
-               NULL, NULL,
-               NULL,
-               G_TYPE_NONE, 0);
   g_signal_new (I_("response-requested"),
                iface_type,
                G_SIGNAL_RUN_LAST,
@@ -165,18 +135,6 @@ gtk_file_chooser_embed_class_init (gpointer g_iface)
                G_TYPE_NONE, 0);
 }
 
-void
-_gtk_file_chooser_embed_get_default_size (GtkFileChooserEmbed *chooser_embed,
-                                        gint                *default_width,
-                                        gint                *default_height)
-{
-  g_return_if_fail (GTK_IS_FILE_CHOOSER_EMBED (chooser_embed));
-  g_return_if_fail (default_width != NULL);
-  g_return_if_fail (default_height != NULL);
-
-  GTK_FILE_CHOOSER_EMBED_GET_IFACE (chooser_embed)->get_default_size (chooser_embed, default_width, 
default_height);
-}
-
 gboolean
 _gtk_file_chooser_embed_should_respond (GtkFileChooserEmbed *chooser_embed)
 {
diff --git a/gtk/gtkfilechooserembed.h b/gtk/gtkfilechooserembed.h
index 1e333588fe..5a013190a3 100644
--- a/gtk/gtkfilechooserembed.h
+++ b/gtk/gtkfilechooserembed.h
@@ -38,24 +38,16 @@ struct _GtkFileChooserEmbedIface
 
   /* Methods
    */
-  void (*get_default_size)        (GtkFileChooserEmbed *chooser_embed,
-                                  gint                *default_width,
-                                  gint                *default_height);
-
   gboolean (*should_respond)      (GtkFileChooserEmbed *chooser_embed);
 
   void (*initial_focus)           (GtkFileChooserEmbed *chooser_embed);
   /* Signals
    */
-  void (*default_size_changed)    (GtkFileChooserEmbed *chooser_embed);
   void (*response_requested)      (GtkFileChooserEmbed *chooser_embed);
 };
 
 GType _gtk_file_chooser_embed_get_type (void) G_GNUC_CONST;
 
-void  _gtk_file_chooser_embed_get_default_size    (GtkFileChooserEmbed *chooser_embed,
-                                                  gint                *default_width,
-                                                  gint                *default_height);
 gboolean _gtk_file_chooser_embed_should_respond (GtkFileChooserEmbed *chooser_embed);
 
 void _gtk_file_chooser_embed_initial_focus (GtkFileChooserEmbed *chooser_embed);
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index f6d5c1b2e6..12988b498c 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -476,7 +476,6 @@ static void     gtk_file_chooser_widget_get_property (GObject               *obj
                                                        GValue                *value,
                                                        GParamSpec            *pspec);
 static void     gtk_file_chooser_widget_dispose      (GObject               *object);
-static void     gtk_file_chooser_widget_realize        (GtkWidget             *widget);
 static void     gtk_file_chooser_widget_map            (GtkWidget             *widget);
 static void     gtk_file_chooser_widget_unmap          (GtkWidget             *widget);
 static void     gtk_file_chooser_widget_root           (GtkWidget             *widget);
@@ -518,9 +517,6 @@ static gboolean       gtk_file_chooser_widget_remove_shortcut_folder (GtkFileCho
                                                                        GError           **error);
 static GSList *       gtk_file_chooser_widget_list_shortcut_folders  (GtkFileChooser    *chooser);
 
-static void           gtk_file_chooser_widget_get_default_size       (GtkFileChooserEmbed *chooser_embed,
-                                                                       gint                *default_width,
-                                                                       gint                *default_height);
 static gboolean       gtk_file_chooser_widget_should_respond         (GtkFileChooserEmbed *chooser_embed);
 static void           gtk_file_chooser_widget_initial_focus          (GtkFileChooserEmbed *chooser_embed);
 
@@ -660,7 +656,6 @@ gtk_file_chooser_widget_iface_init (GtkFileChooserIface *iface)
 static void
 gtk_file_chooser_embed_default_iface_init (GtkFileChooserEmbedIface *iface)
 {
-  iface->get_default_size = gtk_file_chooser_widget_get_default_size;
   iface->should_respond = gtk_file_chooser_widget_should_respond;
   iface->initial_focus = gtk_file_chooser_widget_initial_focus;
 }
@@ -945,14 +940,6 @@ change_folder_and_display_error (GtkFileChooserWidget *impl,
   return result;
 }
 
-static void
-emit_default_size_changed (GtkFileChooserWidget *impl)
-{
-  profile_msg ("    emit default-size-changed start", NULL);
-  g_signal_emit_by_name (impl, "default-size-changed");
-  profile_msg ("    emit default-size-changed end", NULL);
-}
-
 static void
 update_preview_widget_visibility (GtkFileChooserWidget *impl)
 {
@@ -980,9 +967,6 @@ update_preview_widget_visibility (GtkFileChooserWidget *impl)
     gtk_widget_show (priv->preview_box);
   else
     gtk_widget_hide (priv->preview_box);
-
-  if (!gtk_widget_get_mapped (GTK_WIDGET (impl)))
-    emit_default_size_changed (impl);
 }
 
 static void
@@ -3226,8 +3210,6 @@ update_appearance (GtkFileChooserWidget *impl)
    * of files may change depending whether we are in a file or folder-only mode.
    */
   gtk_widget_queue_draw (priv->browse_files_tree_view);
-
-  emit_default_size_changed (impl);
 }
 
 static gchar *
@@ -3679,8 +3661,6 @@ gtk_file_chooser_widget_style_updated (GtkWidget *widget)
 
   change_icon_theme (impl);
 
-  emit_default_size_changed (impl);
-
   profile_end ("end", NULL);
 }
 
@@ -3789,19 +3769,6 @@ settings_save (GtkFileChooserWidget *impl)
   g_settings_apply (settings);
 }
 
-/* GtkWidget::realize method */
-static void
-gtk_file_chooser_widget_realize (GtkWidget *widget)
-{
-  GtkFileChooserWidget *impl;
-
-  impl = GTK_FILE_CHOOSER_WIDGET (widget);
-
-  GTK_WIDGET_CLASS (gtk_file_chooser_widget_parent_class)->realize (widget);
-
-  emit_default_size_changed (impl);
-}
-
 /* Changes the current folder to $CWD */
 static void
 switch_to_cwd (GtkFileChooserWidget *impl)
@@ -6173,64 +6140,6 @@ gtk_file_chooser_widget_list_shortcut_folders (GtkFileChooser *chooser)
   return gtk_places_sidebar_list_shortcuts (GTK_PLACES_SIDEBAR (priv->places_sidebar));
 }
 
-/* Guesses a size based upon font sizes */
-static void
-find_good_size_from_style (GtkWidget *widget,
-                           gint      *width,
-                           gint      *height)
-{
-  GtkCssStyle *style;
-  double font_size;
-
-  style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
-  font_size = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_FONT_SIZE), 100);
-
-  *width = font_size * NUM_CHARS;
-  *height = font_size * NUM_LINES;
-}
-
-static void
-gtk_file_chooser_widget_get_default_size (GtkFileChooserEmbed *chooser_embed,
-                                          gint                *default_width,
-                                          gint                *default_height)
-{
-  GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser_embed);
-  GtkFileChooserWidgetPrivate *priv = gtk_file_chooser_widget_get_instance_private (impl);
-  GtkRequisition req;
-  int width, height;
-  GSettings *settings;
-
-  settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
-
-  g_settings_get (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", &width, &height);
-
-  if (width > 0 && height > 0)
-    {
-      *default_width = width;
-      *default_height = height;
-      return;
-    }
-
-  find_good_size_from_style (GTK_WIDGET (chooser_embed), default_width, default_height);
-
-  if (priv->preview_widget_active &&
-      priv->preview_widget &&
-      gtk_widget_get_visible (priv->preview_widget))
-    {
-      gtk_widget_get_preferred_size (priv->preview_box,
-                                     &req, NULL);
-      *default_width += PREVIEW_HBOX_SPACING + req.width;
-    }
-
-  if (priv->extra_widget &&
-      gtk_widget_get_visible (priv->extra_widget))
-    {
-      gtk_widget_get_preferred_size (priv->extra_align,
-                                     &req, NULL);
-      *default_height += gtk_box_get_spacing (GTK_BOX (priv->box)) + req.height;
-    }
-}
-
 struct switch_folder_closure {
   GtkFileChooserWidget *impl;
   GFile *file;
@@ -8032,7 +7941,6 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
   gobject_class->get_property = gtk_file_chooser_widget_get_property;
   gobject_class->dispose = gtk_file_chooser_widget_dispose;
 
-  widget_class->realize = gtk_file_chooser_widget_realize;
   widget_class->map = gtk_file_chooser_widget_map;
   widget_class->unmap = gtk_file_chooser_widget_unmap;
   widget_class->root = gtk_file_chooser_widget_root;
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 0ad56e8318..c25a4889b3 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -1111,17 +1111,14 @@ gtk_font_chooser_widget_get_preview_text_height (GtkFontChooserWidget *fontchoos
   GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (fontchooser);
   GtkWidget *treeview = priv->family_face_list;
   GtkStyleContext *context;
-  double dpi, font_size;
+  double font_size;
 
   context = gtk_widget_get_style_context (treeview);
-  dpi = _gtk_css_number_value_get (_gtk_style_context_peek_property (context,
-                                                                     GTK_CSS_PROPERTY_DPI),
-                                   100);
-  gtk_style_context_get (context,
-                         "font-size", &font_size,
-                         NULL);
-
-  return (dpi < 0.0 ? 96.0 : dpi) / 72.0 * PANGO_SCALE_X_LARGE * font_size * PANGO_SCALE;
+  font_size = _gtk_css_number_value_get (_gtk_style_context_peek_property (context,
+                                                                     GTK_CSS_PROPERTY_FONT_SIZE),
+                                         100);
+
+  return PANGO_SCALE_X_LARGE * font_size * PANGO_SCALE;
 }
 
 static PangoAttrList *
diff --git a/gtk/ui/gtkfilechooserdialog.ui b/gtk/ui/gtkfilechooserdialog.ui
index 4434b186de..425dab20e6 100644
--- a/gtk/ui/gtkfilechooserdialog.ui
+++ b/gtk/ui/gtkfilechooserdialog.ui
@@ -17,7 +17,6 @@
         <child>
           <object class="GtkFileChooserWidget" id="widget">
             <property name="expand">1</property>
-            <signal name="default-size-changed" handler="file_chooser_widget_default_size_changed" 
swapped="no"/>
             <signal name="file-activated" handler="file_chooser_widget_file_activated" swapped="no"/>
             <signal name="response-requested" handler="file_chooser_widget_response_requested" swapped="no"/>
             <signal name="selection-changed" handler="file_chooser_widget_selection_changed" swapped="no"/>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]