]> git.0d.be Git - empathy.git/blob - src/gedit-close-button.c
Merge branch 'change-audio'
[empathy.git] / src / gedit-close-button.c
1 /*
2  * gedit-close-button.c
3  * This file is part of gedit
4  *
5  * Copyright (C) 2010 - Paolo Borelli
6  * Copyright (C) 2011 - Ignacio Casal Quinteiro
7  *
8  * gedit is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * gedit is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include "gedit-close-button.h"
24
25 struct _GeditCloseButtonClassPrivate
26 {
27         GtkCssProvider *css;
28 };
29
30 G_DEFINE_TYPE_WITH_CODE (GeditCloseButton, gedit_close_button, GTK_TYPE_BUTTON,
31                          g_type_add_class_private (g_define_type_id, sizeof (GeditCloseButtonClassPrivate)))
32
33 static void
34 gedit_close_button_class_init (GeditCloseButtonClass *klass)
35 {
36         static const gchar button_style[] =
37                 "* {\n"
38                   "-GtkButton-default-border : 0;\n"
39                   "-GtkButton-default-outside-border : 0;\n"
40                   "-GtkButton-inner-border: 0;\n"
41                   "-GtkWidget-focus-line-width : 0;\n"
42                   "-GtkWidget-focus-padding : 0;\n"
43                   "padding: 0;\n"
44                 "}";
45
46         klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButtonClassPrivate);
47
48         klass->priv->css = gtk_css_provider_new ();
49         gtk_css_provider_load_from_data (klass->priv->css, button_style, -1, NULL);
50 }
51
52 static void
53 gedit_close_button_init (GeditCloseButton *button)
54 {
55         GtkStyleContext *context;
56         GtkWidget *image;
57
58         image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
59                                           GTK_ICON_SIZE_MENU);
60         gtk_widget_show (image);
61
62         gtk_container_add (GTK_CONTAINER (button), image);
63
64         /* make it small */
65         context = gtk_widget_get_style_context (GTK_WIDGET (button));
66         gtk_style_context_add_provider (context,
67                                         GTK_STYLE_PROVIDER (GEDIT_CLOSE_BUTTON_GET_CLASS (button)->priv->css),
68                                         GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
69 }
70
71 GtkWidget *
72 gedit_close_button_new ()
73 {
74         return GTK_WIDGET (g_object_new (GEDIT_TYPE_CLOSE_BUTTON,
75                                          "relief", GTK_RELIEF_NONE,
76                                          "focus-on-click", FALSE,
77                                          NULL));
78 }
79
80 /* ex:set ts=8 noet: */