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>".
This commit is contained in:
Martin Nordholts 2009-12-03 23:08:30 +01:00
parent 5ae5ef0f9f
commit d33f643f6b
4 changed files with 79 additions and 51 deletions

View File

@ -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);
@ -255,6 +281,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)
{

View File

@ -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)));
}
}
/**

View File

@ -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

View File

@ -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