Commit 0a5840d2 authored by Paolo Borelli's avatar Paolo Borelli
Browse files

Sync close-button with the original gedit widget. This way the proper

symbolic close icon is used for the button.
parent c674da0a
......@@ -3,6 +3,7 @@
* This file was taken from gedit
*
* Copyright (C) 2010 - Paolo Borelli
* Copyright (C) 2011 - Ignacio Casal Quinteiro
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -22,51 +23,59 @@
#include "glade-close-button.h"
G_DEFINE_TYPE (GladeCloseButton, glade_close_button, GTK_TYPE_BUTTON)
static void glade_close_button_class_init (GladeCloseButtonClass * klass)
struct _GladeCloseButtonClassPrivate
{
}
GtkCssProvider *css;
};
G_DEFINE_TYPE_WITH_CODE (GladeCloseButton, glade_close_button, GTK_TYPE_BUTTON,
g_type_add_class_private (g_define_type_id, sizeof (GladeCloseButtonClassPrivate)))
static void
glade_close_button_init (GladeCloseButton * button)
glade_close_button_class_init (GladeCloseButtonClass *klass)
{
GtkWidget *image;
GtkCssProvider *provider;
gtk_widget_set_can_focus (GTK_WIDGET (button), FALSE);
static const gchar button_style[] =
"* {\n"
"-GtkButton-default-border : 0;\n"
"-GtkButton-default-outside-border : 0;\n"
"-GtkButton-inner-border: 0;\n"
"-GtkWidget-focus-line-width : 0;\n"
"-GtkWidget-focus-padding : 0;\n"
"padding: 0;\n"
"}";
/* make it as small as possible */
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider,
"* {\n"
" -GtkButton-default-border : 0;\n"
" -GtkButton-default-outside-border : 0;\n"
" -GtkButton-inner-border : 0;\n"
" -GtkWidget-focus-line-width : 0;\n"
" -GtkWidget-focus-padding : 0;\n"
" padding : 0;\n" "}", -1, NULL);
klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GLADE_TYPE_CLOSE_BUTTON, GladeCloseButtonClassPrivate);
gtk_style_context_add_provider (gtk_widget_get_style_context
(GTK_WIDGET (button)),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);
klass->priv->css = gtk_css_provider_new ();
gtk_css_provider_load_from_data (klass->priv->css, button_style, -1, NULL);
}
image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
static void
glade_close_button_init (GladeCloseButton *button)
{
GtkStyleContext *context;
GtkWidget *image;
GIcon *icon;
icon = g_themed_icon_new_with_default_fallbacks ("window-close-symbolic");
image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
gtk_widget_show (image);
g_object_unref (icon);
gtk_container_add (GTK_CONTAINER (button), image);
/* make it small */
context = gtk_widget_get_style_context (GTK_WIDGET (button));
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (GLADE_CLOSE_BUTTON_GET_CLASS (button)->priv->css),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
GtkWidget *
glade_close_button_new ()
{
GladeCloseButton *button;
button = g_object_new (GLADE_TYPE_CLOSE_BUTTON,
"relief", GTK_RELIEF_NONE,
"focus-on-click", FALSE, NULL);
return GTK_WIDGET (button);
return GTK_WIDGET (g_object_new (GLADE_TYPE_CLOSE_BUTTON,
"relief", GTK_RELIEF_NONE,
"focus-on-click", FALSE,
NULL));
}
......@@ -37,7 +37,7 @@ G_BEGIN_DECLS
typedef struct _GladeCloseButton GladeCloseButton;
typedef struct _GladeCloseButtonClass GladeCloseButtonClass;
typedef struct _GladeCloseButtonPrivate GladeCloseButtonPrivate;
typedef struct _GladeCloseButtonClassPrivate GladeCloseButtonClassPrivate;
struct _GladeCloseButton {
GtkButton parent;
......@@ -45,6 +45,8 @@ struct _GladeCloseButton {
struct _GladeCloseButtonClass {
GtkButtonClass parent_class;
GladeCloseButtonClassPrivate *priv;
};
GType glade_close_button_get_type (void) G_GNUC_CONST;
......
Supports Markdown
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