[gimp] app: Move GimpDockWindow::"font-scale" style property to GimpDock



commit d33f643f6bdb1ded43650de8593cee276ff0c600
Author: Martin Nordholts <martinn src gnome org>
Date:   Thu Dec 3 23:08:30 2009 +0100

    app: Move GimpDockWindow::"font-scale" style property to GimpDock
    
    To make the smaller font in docks also apply in single-window mode,
    move the GimpDockWindow::font-scale style property to GimpDock. We use
    the GimpDockWindow approach, so now each GimpDock has a name of the
    form "gimp-internal-dock-<id>". We add "internal" to avoid clashing
    with the GimpDockWindow legacy id "gimp-dock-<id>".

 app/widgets/gimpdock.c       |   75 ++++++++++++++++++++++++++++++++++++++++++
 app/widgets/gimpdockwindow.c |   51 +---------------------------
 themes/Default/gtkrc         |    2 +-
 themes/Small/gtkrc           |    2 +-
 4 files changed, 79 insertions(+), 51 deletions(-)
---
diff --git a/app/widgets/gimpdock.c b/app/widgets/gimpdock.c
index 08b9397..438cec2 100644
--- a/app/widgets/gimpdock.c
+++ b/app/widgets/gimpdock.c
@@ -41,6 +41,9 @@
 #include "gimp-intl.h"
 
 
+#define DEFAULT_DOCK_FONT_SCALE  PANGO_SCALE_SMALL
+
+
 enum
 {
   PROP_0,
@@ -69,6 +72,8 @@ struct _GimpDockPrivate
   GtkWidget         *paned_vbox;
 
   GList             *dockbooks;
+
+  gint               ID;
 };
 
 
@@ -80,6 +85,8 @@ static void      gimp_dock_get_property      (GObject               *object,
                                               guint                  property_id,
                                               GValue                *value,
                                               GParamSpec            *pspec);
+static void      gimp_dock_style_set         (GtkWidget             *widget,
+                                              GtkStyle              *prev_style);
 
 static void      gimp_dock_destroy           (GtkObject             *object);
 
@@ -104,6 +111,7 @@ gimp_dock_class_init (GimpDockClass *klass)
 {
   GObjectClass   *object_class     = G_OBJECT_CLASS (klass);
   GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class     = GTK_WIDGET_CLASS (klass);
 
   dock_signals[BOOK_ADDED] =
     g_signal_new ("book-added",
@@ -148,6 +156,8 @@ gimp_dock_class_init (GimpDockClass *klass)
 
   gtk_object_class->destroy      = gimp_dock_destroy;
 
+  widget_class->style_set        = gimp_dock_style_set;
+
   klass->setup                   = NULL;
   klass->set_host_geometry_hints = NULL;
   klass->book_added              = gimp_dock_real_book_added;
@@ -175,17 +185,33 @@ gimp_dock_class_init (GimpDockClass *klass)
                                                         GIMP_PARAM_READWRITE |
                                                         G_PARAM_CONSTRUCT_ONLY));
 
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_double ("font-scale",
+                                                                NULL, NULL,
+                                                                0.0,
+                                                                G_MAXDOUBLE,
+                                                                DEFAULT_DOCK_FONT_SCALE,
+                                                                GIMP_PARAM_READABLE));
+
   g_type_class_add_private (klass, sizeof (GimpDockPrivate));
 }
 
 static void
 gimp_dock_init (GimpDock *dock)
 {
+  static gint  dock_ID = 1;
+  gchar       *name    = NULL;
+
   dock->p = G_TYPE_INSTANCE_GET_PRIVATE (dock,
                                          GIMP_TYPE_DOCK,
                                          GimpDockPrivate);
   dock->p->context        = NULL;
   dock->p->dialog_factory = NULL;
+  dock->p->ID             = dock_ID++;
+
+  name = g_strdup_printf ("gimp-internal-dock-%d", dock->p->ID);
+  gtk_widget_set_name (GTK_WIDGET (dock), name);
+  g_free (name);
 
   dock->p->main_vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (dock), dock->p->main_vbox);
@@ -256,6 +282,55 @@ gimp_dock_get_property (GObject    *object,
 }
 
 static void
+gimp_dock_style_set (GtkWidget *widget,
+                     GtkStyle  *prev_style)
+{
+  GimpDock *dock       = GIMP_DOCK (widget);
+  gdouble   font_scale = 1.0;
+
+  GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
+
+  gtk_widget_style_get (widget,
+                        "font-scale", &font_scale,
+                        NULL);
+
+  if (font_scale != 1.0)
+    {
+      PangoContext         *context;
+      PangoFontDescription *font_desc;
+      gint                  font_size;
+      gchar                *font_str;
+      gchar                *rc_string;
+
+      context = gtk_widget_get_pango_context (widget);
+      font_desc = pango_context_get_font_description (context);
+      font_desc = pango_font_description_copy (font_desc);
+
+      font_size = pango_font_description_get_size (font_desc);
+      font_size = font_scale * font_size;
+      pango_font_description_set_size (font_desc, font_size);
+
+      font_str = pango_font_description_to_string (font_desc);
+      pango_font_description_free (font_desc);
+
+      rc_string =
+        g_strdup_printf ("style \"gimp-dock-style\""
+                         "{"
+                         "  font_name = \"%s\""
+                         "}"
+                         "widget \"*.gimp-internal-dock-%d.*\" style \"gimp-dock-style\"",
+                         font_str,
+                         dock->p->ID);
+      g_free (font_str);
+
+      gtk_rc_parse_string (rc_string);
+      g_free (rc_string);
+
+      gtk_widget_reset_rc_styles (widget);
+    }
+}
+
+static void
 gimp_dock_destroy (GtkObject *object)
 {
   GimpDock *dock = GIMP_DOCK (object);
diff --git a/app/widgets/gimpdockwindow.c b/app/widgets/gimpdockwindow.c
index 9eb0bac..e034483 100644
--- a/app/widgets/gimpdockwindow.c
+++ b/app/widgets/gimpdockwindow.c
@@ -50,8 +50,7 @@
 #include "gimp-intl.h"
 
 
-#define DEFAULT_DOCK_HEIGHT     300
-#define DEFAULT_DOCK_FONT_SCALE PANGO_SCALE_SMALL
+#define DEFAULT_DOCK_HEIGHT 300
 
 
 enum
@@ -166,13 +165,6 @@ gimp_dock_window_class_init (GimpDockWindowClass *klass)
                                                              -1, G_MAXINT,
                                                              DEFAULT_DOCK_HEIGHT,
                                                              GIMP_PARAM_READABLE));
-  gtk_widget_class_install_style_property (widget_class,
-                                           g_param_spec_double ("font-scale",
-                                                                NULL, NULL,
-                                                                0.0,
-                                                                G_MAXDOUBLE,
-                                                                DEFAULT_DOCK_FONT_SCALE,
-                                                                GIMP_PARAM_READABLE));
 
   g_type_class_add_private (klass, sizeof (GimpDockWindowPrivate));
 }
@@ -373,54 +365,15 @@ static void
 gimp_dock_window_style_set (GtkWidget *widget,
                             GtkStyle  *prev_style)
 {
-  GimpDockWindow *dock_window = GIMP_DOCK_WINDOW (widget);
-  gint            default_height;
-  gdouble         font_scale;
+  gint default_height = DEFAULT_DOCK_HEIGHT;
 
   GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
 
   gtk_widget_style_get (widget,
                         "default-height", &default_height,
-                        "font-scale",     &font_scale,
                         NULL);
 
   gtk_window_set_default_size (GTK_WINDOW (widget), -1, default_height);
-
-  if (font_scale != 1.0)
-    {
-      PangoContext         *context;
-      PangoFontDescription *font_desc;
-      gint                  font_size;
-      gchar                *font_str;
-      gchar                *rc_string;
-
-      context = gtk_widget_get_pango_context (widget);
-      font_desc = pango_context_get_font_description (context);
-      font_desc = pango_font_description_copy (font_desc);
-
-      font_size = pango_font_description_get_size (font_desc);
-      font_size = font_scale * font_size;
-      pango_font_description_set_size (font_desc, font_size);
-
-      font_str = pango_font_description_to_string (font_desc);
-      pango_font_description_free (font_desc);
-
-      rc_string =
-        g_strdup_printf ("style \"gimp-dock-style\""
-                         "{"
-                         "  font_name = \"%s\""
-                         "}"
-                         "widget \"gimp-dock-%d.*\" style \"gimp-dock-style\"",
-                         font_str,
-                         dock_window->p->ID);
-      g_free (font_str);
-
-      gtk_rc_parse_string (rc_string);
-      g_free (rc_string);
-
-      if (gtk_bin_get_child (GTK_BIN (widget)))
-        gtk_widget_reset_rc_styles (gtk_bin_get_child (GTK_BIN (widget)));
-    }
 }
 
 /**
diff --git a/themes/Default/gtkrc b/themes/Default/gtkrc
index 246b331..1bc8141 100644
--- a/themes/Default/gtkrc
+++ b/themes/Default/gtkrc
@@ -38,7 +38,7 @@ style "gimp-default-style"
 
   GtkPaned::handle-size             = 6
   GimpDockWindow::default-height    = 300
-  GimpDockWindow::font-scale        = 0.8333
+  GimpDock::font-scale              = 0.8333
   GimpMenuDock::minimal-width       = 200
   GimpMenuDock::menu-preview-size   = button
   GimpToolbox::tool-icon-size       = button
diff --git a/themes/Small/gtkrc b/themes/Small/gtkrc
index ff9819a..dea7e63 100644
--- a/themes/Small/gtkrc
+++ b/themes/Small/gtkrc
@@ -45,7 +45,7 @@ style "gimp-default-style"
 
   GtkPaned::handle-size             = 5
   GimpDockWindow::default-height    = 240
-  GimpDockWindow::font-scale        = 0.8333
+  GimpDock::font-scale              = 0.8333
   GimpMenuDock::minimal-width       = 200
   GimpMenuDock::menu-preview-size   = small-toolbar
   GimpToolbox::tool-icon-size       = menu



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