[goffice] GOColorPaletter: use css for styling.



commit 3a2461c9775869044092e4c96d4d593dfc4b3cb6
Author: Morten Welinder <terra gnome org>
Date:   Wed Dec 6 12:02:07 2017 -0500

    GOColorPaletter: use css for styling.
    
    This makes the buttons scale with font size.

 goffice/gtk/go-color-palette.c |   13 +++++++++----
 goffice/gtk/goffice-gtk.c      |   22 ++++++++++++++++++++--
 goffice/gtk/goffice-gtk.h      |    2 ++
 goffice/gtk/goffice.css        |   22 ++++++++++++++++++++++
 4 files changed, 53 insertions(+), 6 deletions(-)
---
diff --git a/goffice/gtk/go-color-palette.c b/goffice/gtk/go-color-palette.c
index 453ffd8..e8e1a1b 100644
--- a/goffice/gtk/go-color-palette.c
+++ b/goffice/gtk/go-color-palette.c
@@ -252,6 +252,7 @@ static void
 go_color_palette_init (GObject *obj)
 {
        g_object_set (obj, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
+       _go_gtk_widget_add_css_provider (GTK_WIDGET (obj));
 }
 
 GSF_CLASS (GOColorPalette, go_color_palette,
@@ -374,13 +375,9 @@ go_color_palette_button_new (GOColorPalette *pal, GtkGrid *grid,
                          NULL);
        g_object_set_data (G_OBJECT (swatch), "color",
                           GUINT_TO_POINTER (color_name->color));
-       gtk_widget_set_size_request (swatch, COLOR_PREVIEW_WIDTH, COLOR_PREVIEW_HEIGHT);
-       gtk_widget_set_halign (swatch, GTK_ALIGN_CENTER);
-       gtk_widget_set_valign (swatch, GTK_ALIGN_CENTER);
 
        /* Wrap inside a vbox with a border so that we can see the focus indicator */
        box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-       gtk_container_set_border_width (GTK_CONTAINER (box), 2);
        gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (swatch), TRUE, TRUE, 0);
 
        button = gtk_button_new ();
@@ -394,6 +391,14 @@ go_color_palette_button_new (GOColorPalette *pal, GtkGrid *grid,
                "signal::button_release_event", G_CALLBACK (cb_swatch_release_event), pal,
                "signal::key_press_event", G_CALLBACK (cb_swatch_key_press), pal,
                NULL);
+
+       if (!_go_gtk_new_theming ()) {
+               gtk_widget_set_size_request (swatch, COLOR_PREVIEW_WIDTH, COLOR_PREVIEW_HEIGHT);
+               gtk_widget_set_halign (swatch, GTK_ALIGN_FILL);
+               gtk_widget_set_valign (swatch, GTK_ALIGN_FILL);
+               gtk_container_set_border_width (GTK_CONTAINER (box), 2);
+       }
+
        return swatch;
 }
 
diff --git a/goffice/gtk/goffice-gtk.c b/goffice/gtk/goffice-gtk.c
index 8c3641b..fac00e4 100644
--- a/goffice/gtk/goffice-gtk.c
+++ b/goffice/gtk/goffice-gtk.c
@@ -1646,8 +1646,10 @@ cb_screen_changed (GtkWidget *widget)
                return;
 
        css_provider_screens = g_slist_prepend (css_provider_screens, screen);
-       gtk_style_context_add_provider_for_screen (screen, css_provider,
-                                                  GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
+       gtk_style_context_add_provider_for_screen
+               (screen,
+                GTK_STYLE_PROVIDER (css_provider),
+                GTK_STYLE_PROVIDER_PRIORITY_FALLBACK);
 }
 
 
@@ -1667,6 +1669,22 @@ _go_gtk_widget_add_css_provider (GtkWidget *w)
        cb_screen_changed (w);
 }
 
+gboolean
+_go_gtk_new_theming (void)
+{
+#if GTK_CHECK_VERSION(3,20,0)
+       return TRUE;
+#else
+       static int new_theming = -1;
+       if (new_theming == -1)
+               new_theming = (gtk_get_major_version() > 3 ||
+                              gtk_get_minor_version() >= 20);
+
+       return new_theming;
+#endif
+}
+
+
 void
 _go_gtk_shutdown (void)
 {
diff --git a/goffice/gtk/goffice-gtk.h b/goffice/gtk/goffice-gtk.h
index 52ca7e6..829ab7d 100644
--- a/goffice/gtk/goffice-gtk.h
+++ b/goffice/gtk/goffice-gtk.h
@@ -61,6 +61,8 @@ void       _go_gtk_shutdown (void);
 // Add goffice-specific css provider
 void       _go_gtk_widget_add_css_provider (GtkWidget *w);
 
+gboolean _go_gtk_new_theming (void);
+
 void      go_gtk_editable_enters (GtkWindow *window, GtkWidget *w);
 
 GtkBuilder *go_gtk_builder_load_internal (char const *uifile,
diff --git a/goffice/gtk/goffice.css b/goffice/gtk/goffice.css
index 95da1d5..fcfbd22 100644
--- a/goffice/gtk/goffice.css
+++ b/goffice/gtk/goffice.css
@@ -30,3 +30,25 @@ rotation3dselector canvas {
   background-image: none;
   background-color: white;
 }
+
+/* ---------------------------------------- */
+
+colorpalette button box {
+  min-height: 1.5em;
+  min-width: 1.5em;
+
+  border-width: 3px;
+  padding: 0;
+  margin: 3px;
+}
+
+colorpalette button {
+  padding: 0;
+}
+
+colorpalette grid {
+  margin: 0;
+  padding: 0.2em;
+}
+
+/* ---------------------------------------- */


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