1 /*
2     roxterm - VTE/GTK terminal emulator with tabs
3     Copyright (C) 2004-2015 Tony Houghton <h@realh.co.uk>
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19 
20 #include "multitab-close-button.h"
21 
22 G_DEFINE_TYPE (MultitabCloseButton, multitab_close_button, GTK_TYPE_BUTTON);
23 
24 static void
multitab_close_button_set_size(MultitabCloseButton * self)25 multitab_close_button_set_size (MultitabCloseButton *self)
26 {
27     int x, y;
28     GtkWidget *w = GTK_WIDGET (self);
29 
30     gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &x, &y);
31     gtk_widget_set_size_request (w, x + 2, y + 2);
32 }
33 
34 static void
multitab_close_button_style_updated(GtkWidget * self)35 multitab_close_button_style_updated (GtkWidget *self)
36 {
37     multitab_close_button_set_size (MULTITAB_CLOSE_BUTTON (self));
38     GTK_WIDGET_CLASS (multitab_close_button_parent_class)->style_updated (self);
39 }
40 
41 static void
multitab_close_button_class_init(MultitabCloseButtonClass * klass)42 multitab_close_button_class_init(MultitabCloseButtonClass *klass)
43 {
44     GtkWidgetClass *wk = GTK_WIDGET_CLASS (klass);
45 
46     wk->style_updated = multitab_close_button_style_updated;
47     gtk_widget_class_set_css_name (wk, "multitab-close-button");
48 }
49 
50 static void
multitab_close_button_init(MultitabCloseButton * self)51 multitab_close_button_init(MultitabCloseButton *self)
52 {
53     GtkWidget *image = gtk_image_new ();
54 
55     self->image = GTK_IMAGE (image);
56     gtk_widget_show (image);
57     gtk_container_add (GTK_CONTAINER (self), image);
58 }
59 
60 GtkWidget *
multitab_close_button_new(const char * image_name)61 multitab_close_button_new(const char *image_name)
62 {
63     MultitabCloseButton *self = (MultitabCloseButton *)
64             g_object_new (MULTITAB_TYPE_CLOSE_BUTTON,
65                     "relief", GTK_RELIEF_NONE,
66                     "focus-on-click", FALSE,
67                     NULL);
68 
69     multitab_close_button_set_image (self, image_name);
70     return GTK_WIDGET (self);
71 }
72 
73 void
multitab_close_button_set_image(MultitabCloseButton * self,const char * image_name)74 multitab_close_button_set_image(MultitabCloseButton *self,
75         const char *image_name)
76 {
77     gtk_image_set_from_icon_name (self->image,
78             image_name ? image_name : "window-close-symbolic",
79             GTK_ICON_SIZE_MENU);
80     multitab_close_button_set_size (self);
81 }
82