[gnome-terminal] Borrow gedit-close-button class and use it.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal] Borrow gedit-close-button class and use it.
- Date: Sun, 20 Feb 2011 21:22:03 +0000 (UTC)
commit c3a3e0600edbcbb51a5cb7489269e8afb6e48262
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Sun Feb 20 19:25:09 2011 +0100
Borrow gedit-close-button class and use it.
This is a subclass of GtkButton special theming for the close button.
src/Makefile.am | 2 +
src/terminal-close-button.c | 116 +++++++++++++++++++++++++++++++++++++++++++
src/terminal-close-button.h | 59 ++++++++++++++++++++++
src/terminal-tab-label.c | 30 +----------
src/terminal-window.c | 9 ---
5 files changed, 180 insertions(+), 36 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 17c1dd4..789e48d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -19,6 +19,8 @@ gnome_terminal_SOURCES= \
terminal-accels.h \
terminal-app.c \
terminal-app.h \
+ terminal-close-button.h \
+ terminal-close-button.c \
terminal-debug.c \
terminal-debug.h \
terminal-encoding.c \
diff --git a/src/terminal-close-button.c b/src/terminal-close-button.c
new file mode 100644
index 0000000..2d9792a
--- /dev/null
+++ b/src/terminal-close-button.c
@@ -0,0 +1,116 @@
+/*
+ * terminal-close-button.c
+ *
+ * Copyright © 2010 - Paolo Borelli
+ * Copyright © 2011 - Ignacio Casal Quinteiro
+ *
+ * Gnome-terminal is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome-terminal 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "terminal-close-button.h"
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+struct _TerminalCloseButtonClassPrivate {
+ GtkCssProvider *css;
+};
+
+G_DEFINE_TYPE_WITH_CODE (TerminalCloseButton, terminal_close_button, GTK_TYPE_BUTTON,
+ g_type_add_class_private (g_define_type_id, sizeof (TerminalCloseButtonClassPrivate)))
+#else
+G_DEFINE_TYPE (TerminalCloseButton, terminal_close_button, GTK_TYPE_BUTTON)
+
+static void
+terminal_close_button_style_set (GtkWidget *button,
+ GtkStyle *previous_style)
+{
+ gint h, w;
+
+ gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
+ GTK_ICON_SIZE_MENU, &w, &h);
+
+ gtk_widget_set_size_request (button, w + 2, h + 2);
+
+ GTK_WIDGET_CLASS (gedit_close_button_parent_class)->style_set (button, previous_style);
+}
+#endif
+
+static void
+terminal_close_button_class_init (TerminalCloseButtonClass *klass)
+{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ 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, TERMINAL_TYPE_CLOSE_BUTTON, TerminalCloseButtonClassPrivate);
+
+ klass->priv->css = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (klass->priv->css, button_style, -1, NULL);
+#else
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ widget_class->style_set = terminal_close_button_style_set;
+
+ gtk_rc_parse_string ("style \"gnome-terminal-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 \"*.gnome-terminal-tab-close-button\" style \"gnome-terminal-tab-close-button-style\"");
+#endif
+}
+
+static void
+terminal_close_button_init (TerminalCloseButton *button)
+{
+ GtkWidget *image;
+
+ image = gtk_image_new_from_stock (GTK_STOCK_CLOSE,
+ GTK_ICON_SIZE_MENU);
+ gtk_widget_show (image);
+
+ gtk_container_add (GTK_CONTAINER (button), image);
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (button));
+ gtk_style_context_add_provider (context,
+ GTK_STYLE_PROVIDER (TERMINAL_CLOSE_BUTTON_GET_CLASS (button)->priv->css),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+#else
+ gtk_widget_set_name (GTK_WIDGET (button), "gnome-terminal-tab-close-button");
+#endif
+}
+
+GtkWidget *
+terminal_close_button_new ()
+{
+ return GTK_WIDGET (g_object_new (TERMINAL_TYPE_CLOSE_BUTTON,
+ "relief", GTK_RELIEF_NONE,
+ "focus-on-click", FALSE,
+ NULL));
+}
+
+/* ex:set ts=8 noet: */
diff --git a/src/terminal-close-button.h b/src/terminal-close-button.h
new file mode 100644
index 0000000..695169b
--- /dev/null
+++ b/src/terminal-close-button.h
@@ -0,0 +1,59 @@
+/*
+ * terminal-close-button.h
+ *
+ * Copyright © 2010 - Paolo Borelli
+ *
+ * Gnome-terminal is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome-terminal 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __TERMINAL_CLOSE_BUTTON_H__
+#define __TERMINAL_CLOSE_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define TERMINAL_TYPE_CLOSE_BUTTON (terminal_close_button_get_type ())
+#define TERMINAL_CLOSE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TERMINAL_TYPE_CLOSE_BUTTON, TerminalCloseButton))
+#define TERMINAL_CLOSE_BUTTON_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TERMINAL_TYPE_CLOSE_BUTTON, TerminalCloseButton const))
+#define TERMINAL_CLOSE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TERMINAL_TYPE_CLOSE_BUTTON, TerminalCloseButtonClass))
+#define TERMINAL_IS_CLOSE_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TERMINAL_TYPE_CLOSE_BUTTON))
+#define TERMINAL_IS_CLOSE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TERMINAL_TYPE_CLOSE_BUTTON))
+#define TERMINAL_CLOSE_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TERMINAL_TYPE_CLOSE_BUTTON, TerminalCloseButtonClass))
+
+typedef struct _TerminalCloseButton TerminalCloseButton;
+typedef struct _TerminalCloseButtonPrivate TerminalCloseButtonPrivate;
+typedef struct _TerminalCloseButtonClass TerminalCloseButtonClass;
+typedef struct _TerminalCloseButtonClassPrivate TerminalCloseButtonClassPrivate;
+
+struct _TerminalCloseButton
+{
+ GtkButton parent;
+};
+
+struct _TerminalCloseButtonClass
+{
+ GtkButtonClass parent_class;
+
+ TerminalCloseButtonClassPrivate *priv;
+};
+
+GType terminal_close_button_get_type (void) G_GNUC_CONST;
+
+GtkWidget *terminal_close_button_new (void);
+
+G_END_DECLS
+
+#endif /* __TERMINAL_CLOSE_BUTTON_H__ */
+/* ex:set ts=8 noet: */
diff --git a/src/terminal-tab-label.c b/src/terminal-tab-label.c
index 82cb062..24ecbeb 100644
--- a/src/terminal-tab-label.c
+++ b/src/terminal-tab-label.c
@@ -23,6 +23,7 @@
#include "terminal-intl.h"
#include "terminal-tab-label.h"
+#include "terminal-close-button.h"
#define TERMINAL_TAB_LABEL_GET_PRIVATE(tab_label)(G_TYPE_INSTANCE_GET_PRIVATE ((tab_label), TERMINAL_TYPE_TAB_LABEL, TerminalTabLabelPrivate))
@@ -92,23 +93,6 @@ terminal_tab_label_parent_set (GtkWidget *widget,
}
static void
-terminal_tab_label_style_set (GtkWidget *widget,
- GtkStyle *previous_style)
-{
- TerminalTabLabel *tab_label = TERMINAL_TAB_LABEL (widget);
- TerminalTabLabelPrivate *priv = tab_label->priv;
- void (* style_set) (GtkWidget *, GtkStyle *) = GTK_WIDGET_CLASS (terminal_tab_label_parent_class)->style_set;
- int h, w;
-
- if (style_set)
- style_set (widget, previous_style);
-
- gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (widget),
- GTK_ICON_SIZE_MENU, &w, &h);
- gtk_widget_set_size_request (priv->close_button, w + 2, h + 2);
-}
-
-static void
terminal_tab_label_init (TerminalTabLabel *tab_label)
{
tab_label->priv = TERMINAL_TAB_LABEL_GET_PRIVATE (tab_label);
@@ -122,7 +106,7 @@ terminal_tab_label_constructor (GType type,
GObject *object;
TerminalTabLabel *tab_label;
TerminalTabLabelPrivate *priv;
- GtkWidget *hbox, *label, *close_button, *image;
+ GtkWidget *hbox, *label, *close_button;
object = G_OBJECT_CLASS (terminal_tab_label_parent_class)->constructor
(type, n_construct_properties, construct_params);
@@ -143,15 +127,8 @@ terminal_tab_label_constructor (GType type,
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- priv->close_button = 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_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
- gtk_widget_set_name (close_button, "gnome-terminal-tab-close-button");
+ priv->close_button = close_button = terminal_close_button_new ();
gtk_widget_set_tooltip_text (close_button, _("Close tab"));
-
- image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
- gtk_container_add (GTK_CONTAINER (close_button), image);
gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
sync_tab_label (priv->screen, NULL, label);
@@ -204,7 +181,6 @@ terminal_tab_label_class_init (TerminalTabLabelClass *klass)
gobject_class->set_property = terminal_tab_label_set_property;
widget_class->parent_set = terminal_tab_label_parent_set;
- widget_class->style_set = terminal_tab_label_style_set;
signals[CLOSE_BUTTON_CLICKED] =
g_signal_new (I_("close-button-clicked"),
diff --git a/src/terminal-window.c b/src/terminal-window.c
index e33628a..d98d44a 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -2170,15 +2170,6 @@ terminal_window_class_init (TerminalWindowClass *klass)
g_type_class_add_private (object_class, sizeof (TerminalWindowPrivate));
- gtk_rc_parse_string ("style \"gnome-terminal-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 \"*.gnome-terminal-tab-close-button\" style \"gnome-terminal-tab-close-button-style\"");
-
#if !GTK_CHECK_VERSION (2, 90, 8)
gtk_notebook_set_window_creation_hook (handle_tab_droped_on_desktop, NULL, NULL);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]