[devhelp/wip/wintemplate: 4/7] Use gedit close button



commit 9ce3be60e4bf5d5da2aac2640cab5e444edd37d4
Author: Ignacio Casal Quinteiro <ignacio casal nice-software com>
Date:   Tue Jul 23 17:59:13 2013 +0200

    Use gedit close button

 src/Makefile.am          |    4 ++-
 src/dh-window.c          |   19 +---------
 src/gedit-close-button.c |   82 ++++++++++++++++++++++++++++++++++++++++++++++
 src/gedit-close-button.h |   60 +++++++++++++++++++++++++++++++++
 4 files changed, 147 insertions(+), 18 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index b09aaa7..83c6156 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -91,7 +91,9 @@ libdevhelp_3_la_SOURCES =                             \
        dh-resources.c                                  \
        dh-resources.h                                  \
        eggfindbar.c                                    \
-       eggfindbar.h
+       eggfindbar.h                                    \
+       gedit-close-button.h                            \
+       gedit-close-button.c
 
 libdevhelp_3_la_CPPFLAGS =                             \
        $(AM_CPPFLAGS)                                  \
diff --git a/src/dh-window.c b/src/dh-window.c
index a1f4092..21eabaa 100644
--- a/src/dh-window.c
+++ b/src/dh-window.c
@@ -36,6 +36,7 @@
 #include "dh-enum-types.h"
 #include "dh-settings.h"
 #include "eggfindbar.h"
+#include "gedit-close-button.h"
 
 #define TAB_WIDTH_N_CHARS 15
 
@@ -580,16 +581,6 @@ dh_window_class_init (DhWindowClass *klass)
                               G_TYPE_STRING,
                               DH_TYPE_OPEN_LINK_FLAGS);
 
-        gtk_rc_parse_string ("style \"devhelp-tab-close-button-style\"\n"
-                             "{\n"
-                             "GtkWidget::focus-padding = 0\n"
-                             "GtkWidget::focus-line-width = 0\n"
-                             "xthickness = 0\n"
-                             "ythickness = 0\n"
-                             "}\n"
-                             "widget \"*.devhelp-tab-close-button\" "
-                             "style \"devhelp-tab-close-button-style\"");
-
         /* Bind class to template */
         gtk_widget_class_set_template_from_resource (widget_class,
                                                      "/org/gnome/devhelp/dh-window.ui");
@@ -1210,7 +1201,6 @@ window_new_tab_label (DhWindow        *window,
         GtkWidget *label;
         GtkWidget *hbox;
         GtkWidget *close_button;
-        GtkWidget *image;
 
         hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
 
@@ -1219,17 +1209,12 @@ window_new_tab_label (DhWindow        *window,
         gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
         gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
 
-        close_button = gtk_button_new ();
-        gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
-        gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
-        gtk_widget_set_name (close_button, "devhelp-tab-close-button");
+        close_button = gedit_close_button_new ();
         g_object_set_data (G_OBJECT (close_button), "parent_tab", (gpointer) parent);
 
-        image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
         g_signal_connect (close_button, "clicked",
                           G_CALLBACK (close_button_clicked_cb),
                           window);
-        gtk_container_add (GTK_CONTAINER (close_button), image);
 
         gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
 
diff --git a/src/gedit-close-button.c b/src/gedit-close-button.c
new file mode 100644
index 0000000..f99861c
--- /dev/null
+++ b/src/gedit-close-button.c
@@ -0,0 +1,82 @@
+/*
+ * gedit-close-button.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Paolo Borelli
+ * Copyright (C) 2011 - Ignacio Casal Quinteiro
+ *
+ * gedit is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gedit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "gedit-close-button.h"
+
+struct _GeditCloseButtonClassPrivate
+{
+       GtkCssProvider *css;
+};
+
+G_DEFINE_TYPE_WITH_CODE (GeditCloseButton, gedit_close_button, GTK_TYPE_BUTTON,
+                         g_type_add_class_private (g_define_type_id, sizeof (GeditCloseButtonClassPrivate)))
+
+static void
+gedit_close_button_class_init (GeditCloseButtonClass *klass)
+{
+       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"
+               "}";
+
+       klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButtonClassPrivate);
+
+       klass->priv->css = gtk_css_provider_new ();
+       gtk_css_provider_load_from_data (klass->priv->css, button_style, -1, NULL);
+}
+
+static void
+gedit_close_button_init (GeditCloseButton *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 (GEDIT_CLOSE_BUTTON_GET_CLASS (button)->priv->css),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
+GtkWidget *
+gedit_close_button_new ()
+{
+       return GTK_WIDGET (g_object_new (GEDIT_TYPE_CLOSE_BUTTON,
+                                        "relief", GTK_RELIEF_NONE,
+                                        "focus-on-click", FALSE,
+                                        NULL));
+}
+
+/* ex:set ts=8 noet: */
diff --git a/src/gedit-close-button.h b/src/gedit-close-button.h
new file mode 100644
index 0000000..791a730
--- /dev/null
+++ b/src/gedit-close-button.h
@@ -0,0 +1,60 @@
+/*
+ * gedit-close-button.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2010 - Paolo Borelli
+ *
+ * gedit is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * gedit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __GEDIT_CLOSE_BUTTON_H__
+#define __GEDIT_CLOSE_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_CLOSE_BUTTON                        (gedit_close_button_get_type ())
+#define GEDIT_CLOSE_BUTTON(obj)                        (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButton))
+#define GEDIT_CLOSE_BUTTON_CONST(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_CLOSE_BUTTON, 
GeditCloseButton const))
+#define GEDIT_CLOSE_BUTTON_CLASS(klass)                (G_TYPE_CHECK_CLASS_CAST ((klass), 
GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButtonClass))
+#define GEDIT_IS_CLOSE_BUTTON(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_CLOSE_BUTTON))
+#define GEDIT_IS_CLOSE_BUTTON_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_CLOSE_BUTTON))
+#define GEDIT_CLOSE_BUTTON_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_CLOSE_BUTTON, 
GeditCloseButtonClass))
+
+typedef struct _GeditCloseButton               GeditCloseButton;
+typedef struct _GeditCloseButtonClass          GeditCloseButtonClass;
+typedef struct _GeditCloseButtonClassPrivate   GeditCloseButtonClassPrivate;
+
+struct _GeditCloseButton
+{
+       GtkButton parent;
+};
+
+struct _GeditCloseButtonClass
+{
+       GtkButtonClass parent_class;
+
+       GeditCloseButtonClassPrivate *priv;
+};
+
+GType            gedit_close_button_get_type (void) G_GNUC_CONST;
+
+GtkWidget       *gedit_close_button_new      (void);
+
+G_END_DECLS
+
+#endif /* __GEDIT_CLOSE_BUTTON_H__ */
+/* ex:set ts=8 noet: */


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