Commit fb99f997 authored by Martin Nordholts's avatar Martin Nordholts

Move dock window themeing to GimpDockWindow

Move the dock window related themeing namely default dock heght and
font scale from GimpDock to GimpDockWindow to get rid of yet another
GtkWindow dependency from GimpDock.

Note that this change requires gtkrc updates where "GimpDock::" needs
to be repaced with "GimpDockWindow::".
parent fc3ab536
......@@ -272,7 +272,7 @@ windows_actions_dock_added (GimpDialogFactory *factory,
GtkAction *action;
GimpActionEntry entry;
gchar *action_name = g_strdup_printf ("windows-dock-%04d",
gimp_dock_get_id (dock));
gimp_dock_window_get_id (GIMP_DOCK_WINDOW (dock)));
entry.name = action_name;
entry.stock_id = NULL;
......@@ -309,7 +309,8 @@ windows_actions_dock_removed (GimpDialogFactory *factory,
GimpActionGroup *group)
{
GtkAction *action;
gchar *action_name = g_strdup_printf ("windows-dock-%04d", gimp_dock_get_id (dock));
gchar *action_name = g_strdup_printf ("windows-dock-%04d",
gimp_dock_window_get_id (GIMP_DOCK_WINDOW (dock)));
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name);
......@@ -327,7 +328,8 @@ windows_actions_dock_notify (GimpDock *dock,
GtkAction *action;
gchar *action_name;
action_name = g_strdup_printf ("windows-dock-%04d", gimp_dock_get_id (dock));
action_name = g_strdup_printf ("windows-dock-%04d",
gimp_dock_window_get_id (GIMP_DOCK_WINDOW (dock)));
action = gtk_action_group_get_action (GTK_ACTION_GROUP (group), action_name);
g_free (action_name);
......
......@@ -34,6 +34,7 @@
#include "widgets/gimpaction.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpdock.h"
#include "widgets/gimpdockwindow.h"
#include "widgets/gimpuimanager.h"
#include "display/gimpdisplay.h"
......@@ -255,10 +256,13 @@ windows_menu_dock_added (GimpDialogFactory *factory,
ui_path = g_object_get_data (G_OBJECT (manager), "image-menu-ui-path");
action_name = g_strdup_printf ("windows-dock-%04d", gimp_dock_get_id (dock));
action_path = g_strdup_printf ("%s/Windows/Docks", ui_path);
action_name = g_strdup_printf ("windows-dock-%04d",
gimp_dock_window_get_id (GIMP_DOCK_WINDOW (dock)));
action_path = g_strdup_printf ("%s/Windows/Docks",
ui_path);
merge_key = g_strdup_printf ("windows-dock-%04d-merge-id", gimp_dock_get_id (dock));
merge_key = g_strdup_printf ("windows-dock-%04d-merge-id",
gimp_dock_window_get_id (GIMP_DOCK_WINDOW (dock)));
merge_id = gtk_ui_manager_new_merge_id (GTK_UI_MANAGER (manager));
g_object_set_data (G_OBJECT (manager), merge_key,
......@@ -279,7 +283,8 @@ windows_menu_dock_removed (GimpDialogFactory *factory,
GimpDock *dock,
GimpUIManager *manager)
{
gchar *merge_key = g_strdup_printf ("windows-dock-%04d-merge-id", gimp_dock_get_id (dock));
gchar *merge_key = g_strdup_printf ("windows-dock-%04d-merge-id",
gimp_dock_window_get_id (GIMP_DOCK_WINDOW (dock)));
guint merge_id;
merge_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (manager),
......
......@@ -43,9 +43,6 @@
#include "gimp-intl.h"
#define DEFAULT_DOCK_HEIGHT 300
#define DEFAULT_DOCK_FONT_SCALE PANGO_SCALE_SMALL
enum
{
PROP_0,
......@@ -70,8 +67,6 @@ struct _GimpDockPrivate
GtkWidget *vbox;
GList *dockbooks;
gint ID; /* for themeing */
};
......@@ -88,8 +83,6 @@ static void gimp_dock_destroy (GtkObject *object);
static gboolean gimp_dock_delete_event (GtkWidget *widget,
GdkEventAny *event);
static void gimp_dock_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gimp_dock_real_book_added (GimpDock *dock,
GimpDockbook *dockbook);
......@@ -137,7 +130,6 @@ gimp_dock_class_init (GimpDockClass *klass)
gtk_object_class->destroy = gimp_dock_destroy;
widget_class->delete_event = gimp_dock_delete_event;
widget_class->style_set = gimp_dock_style_set;
klass->setup = NULL;
klass->book_added = gimp_dock_real_book_added;
......@@ -156,29 +148,13 @@ gimp_dock_class_init (GimpDockClass *klass)
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("default-height",
NULL, NULL,
-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 (GimpDockPrivate));
}
static void
gimp_dock_init (GimpDock *dock)
{
static gint dock_ID = 1;
GtkWidget *separator;
gchar *name;
GtkWidget *separator;
dock->p = G_TYPE_INSTANCE_GET_PRIVATE (dock,
GIMP_TYPE_DOCK,
......@@ -186,11 +162,6 @@ gimp_dock_init (GimpDock *dock)
dock->p->context = NULL;
dock->p->dialog_factory = NULL;
dock->p->dockbooks = NULL;
dock->p->ID = dock_ID++;
name = g_strdup_printf ("gimp-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);
......@@ -299,59 +270,6 @@ gimp_dock_delete_event (GtkWidget *widget,
return FALSE;
}
static void
gimp_dock_style_set (GtkWidget *widget,
GtkStyle *prev_style)
{
gint default_height;
gdouble font_scale;
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,
GIMP_DOCK (widget)->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)));
}
}
static void
gimp_dock_real_book_added (GimpDock *dock,
GimpDockbook *dockbook)
......@@ -441,14 +359,6 @@ gimp_dock_get_vbox (GimpDock *dock)
return dock->p->vbox;
}
gint
gimp_dock_get_id (GimpDock *dock)
{
g_return_val_if_fail (GIMP_IS_DOCK (dock), 0);
return dock->p->ID;
}
void
gimp_dock_add (GimpDock *dock,
GimpDockable *dockable,
......
......@@ -43,6 +43,10 @@
#include "gimp-intl.h"
#define DEFAULT_DOCK_HEIGHT 300
#define DEFAULT_DOCK_FONT_SCALE PANGO_SCALE_SMALL
enum
{
PROP_0,
......@@ -61,6 +65,8 @@ struct _GimpDockWindowPrivate
gchar *ui_manager_name;
GimpUIManager *ui_manager;
GQuark image_flush_handler_id;
gint ID;
};
static GObject * gimp_dock_window_constructor (GType type,
......@@ -75,6 +81,8 @@ static void gimp_dock_window_get_property (GObject *obje
guint property_id,
GValue *value,
GParamSpec *pspec);
static void gimp_dock_window_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void gimp_dock_window_display_changed (GimpDockWindow *dock_window,
GimpObject *display,
GimpContext *context);
......@@ -93,13 +101,16 @@ G_DEFINE_TYPE (GimpDockWindow, gimp_dock_window, GIMP_TYPE_WINDOW)
static void
gimp_dock_window_class_init (GimpDockWindowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->constructor = gimp_dock_window_constructor;
object_class->dispose = gimp_dock_window_dispose;
object_class->set_property = gimp_dock_window_set_property;
object_class->get_property = gimp_dock_window_get_property;
widget_class->style_set = gimp_dock_window_style_set;
g_object_class_install_property (object_class, PROP_CONTEXT,
g_param_spec_object ("gimp-context", NULL, NULL,
GIMP_TYPE_CONTEXT,
......@@ -120,12 +131,30 @@ gimp_dock_window_class_init (GimpDockWindowClass *klass)
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_int ("default-height",
NULL, NULL,
-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));
}
static void
gimp_dock_window_init (GimpDockWindow *dock_window)
{
static gint dock_ID = 1;
gchar *name;
/* Initialize members */
dock_window->p = G_TYPE_INSTANCE_GET_PRIVATE (dock_window,
GIMP_TYPE_DOCK_WINDOW,
GimpDockWindowPrivate);
......@@ -134,9 +163,16 @@ gimp_dock_window_init (GimpDockWindow *dock_window)
dock_window->p->ui_manager_name = NULL;
dock_window->p->ui_manager = NULL;
dock_window->p->image_flush_handler_id = 0;
dock_window->p->ID = dock_ID++;
/* Some common initialization for all dock windows */
gtk_window_set_resizable (GTK_WINDOW (dock_window), TRUE);
gtk_window_set_focus_on_map (GTK_WINDOW (dock_window), FALSE);
/* Initialize theming and style-setting stuff */
name = g_strdup_printf ("gimp-dock-%d", dock_window->p->ID);
gtk_widget_set_name (GTK_WIDGET (dock_window), name);
g_free (name);
}
static GObject *
......@@ -278,6 +314,60 @@ gimp_dock_window_get_property (GObject *object,
}
}
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;
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)));
}
}
static void
gimp_dock_window_display_changed (GimpDockWindow *dock_window,
GimpObject *display,
......@@ -310,6 +400,14 @@ gimp_dock_window_image_flush (GimpImage *image,
}
}
gint
gimp_dock_window_get_id (GimpDockWindow *dock_window)
{
g_return_val_if_fail (GIMP_IS_DOCK_WINDOW (dock_window), 0);
return dock_window->p->ID;
}
GimpUIManager *
gimp_dock_window_get_ui_manager (GimpDockWindow *dock_window)
{
......
......@@ -54,6 +54,7 @@ struct _GimpDockWindowClass
GType gimp_dock_window_get_type (void) G_GNUC_CONST;
gint gimp_dock_window_get_id (GimpDockWindow *dock_window);
GimpUIManager * gimp_dock_window_get_ui_manager (GimpDockWindow *dock_window);
......
......@@ -37,8 +37,8 @@ style "gimp-default-style"
}
GtkPaned::handle-size = 6
GimpDock::default-height = 300
GimpDock::font-scale = 0.8333
GimpDockWindow::default-height = 300
GimpDockWindow::font-scale = 0.8333
GimpDockSeparator::height = 6
GimpMenuDock::minimal-width = 200
GimpMenuDock::menu-preview-size = button
......
......@@ -44,8 +44,8 @@ style "gimp-default-style"
GtkOptionMenu::indicator-spacing = { 4, 3, 1, 1 }
GtkPaned::handle-size = 5
GimpDock::default-height = 240
GimpDock::font-scale = 0.8333
GimpDockWindow::default-height = 240
GimpDockWindow::font-scale = 0.8333
GimpDockSeparator::height = 5
GimpMenuDock::minimal-width = 200
GimpMenuDock::menu-preview-size = small-toolbar
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment