[gedit] Factor out GeditSmallButton
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Factor out GeditSmallButton
- Date: Tue, 29 Oct 2013 14:41:04 +0000 (UTC)
commit 5b246cd249852ce6a15e5c76cb120bb466e9ebcb
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Tue Oct 29 15:12:40 2013 +0100
Factor out GeditSmallButton
gedit/Makefile.am | 4 +-
gedit/gedit-close-button.h | 60 --------------
gedit/gedit-panel.c | 2 +-
.../{gedit-close-button.c => gedit-small-button.c} | 59 ++++++++++++--
gedit/gedit-small-button.h | 86 ++++++++++++++++++++
gedit/gedit-tab-label.c | 2 +-
6 files changed, 141 insertions(+), 72 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index 743ce39..9ce957c 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -97,7 +97,6 @@ BUILT_SOURCES = \
NOINST_H_FILES = \
gedit-cell-renderer-button.h \
- gedit-close-button.h \
gedit-close-confirmation-dialog.h \
gedit-dirs.h \
gedit-document-input-stream.h \
@@ -120,6 +119,7 @@ NOINST_H_FILES = \
gedit-print-preview.h \
gedit-replace-dialog.h \
gedit-settings.h \
+ gedit-small-button.h \
gedit-status-menu-button.h \
gedit-tab-label.h \
gedit-ui.h \
@@ -167,7 +167,6 @@ libgedit_private_la_SOURCES = \
libgedit_c_files = \
gedit-app.c \
gedit-cell-renderer-button.c \
- gedit-close-button.c \
gedit-close-confirmation-dialog.c \
gedit-commands-documents.c \
gedit-commands-edit.c \
@@ -205,6 +204,7 @@ libgedit_c_files = \
gedit-progress-info-bar.c \
gedit-replace-dialog.c \
gedit-settings.c \
+ gedit-small-button.c \
gedit-statusbar.c \
gedit-status-menu-button.c \
gedit-tab.c \
diff --git a/gedit/gedit-panel.c b/gedit/gedit-panel.c
index 1eafa71..0ac28d5 100644
--- a/gedit/gedit-panel.c
+++ b/gedit/gedit-panel.c
@@ -39,7 +39,7 @@
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
-#include "gedit-close-button.h"
+#include "gedit-small-button.h"
#include "gedit-window.h"
#include "gedit-debug.h"
diff --git a/gedit/gedit-close-button.c b/gedit/gedit-small-button.c
similarity index 65%
rename from gedit/gedit-close-button.c
rename to gedit/gedit-small-button.c
index f99861c..4247f13 100644
--- a/gedit/gedit-close-button.c
+++ b/gedit/gedit-small-button.c
@@ -1,5 +1,5 @@
/*
- * gedit-close-button.c
+ * gedit-small-button.c
* This file is part of gedit
*
* Copyright (C) 2010 - Paolo Borelli
@@ -20,18 +20,18 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "gedit-close-button.h"
+#include "gedit-small-button.h"
-struct _GeditCloseButtonClassPrivate
+struct _GeditSmallButtonClassPrivate
{
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)))
+G_DEFINE_TYPE_WITH_CODE (GeditSmallButton, gedit_small_button, GTK_TYPE_BUTTON,
+ g_type_add_class_private (g_define_type_id, sizeof (GeditSmallButtonClassPrivate)))
static void
-gedit_close_button_class_init (GeditCloseButtonClass *klass)
+gedit_small_button_class_init (GeditSmallButtonClass *klass)
{
static const gchar button_style[] =
"* {\n"
@@ -40,7 +40,50 @@ gedit_close_button_class_init (GeditCloseButtonClass *klass)
"-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_SMALL_BUTTON, GeditSmallButtonClassPrivate);
+
+ klass->priv->css = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (klass->priv->css, button_style, -1, NULL);
+}
+
+static void
+gedit_small_button_init (GeditSmallButton *button)
+{
+ GtkStyleContext *context;
+
+ /* make it small */
+ context = gtk_widget_get_style_context (GTK_WIDGET (button));
+ gtk_style_context_add_provider (context,
+ GTK_STYLE_PROVIDER (GEDIT_SMALL_BUTTON_GET_CLASS (button)->priv->css),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
+GtkWidget *
+gedit_small_button_new ()
+{
+ return GTK_WIDGET (g_object_new (GEDIT_TYPE_SMALL_BUTTON,
+ "relief", GTK_RELIEF_NONE,
+ "focus-on-click", FALSE,
+ NULL));
+}
+
+struct _GeditCloseButtonClassPrivate
+{
+ GtkCssProvider *css;
+};
+
+G_DEFINE_TYPE_WITH_CODE (GeditCloseButton, gedit_close_button, GEDIT_TYPE_SMALL_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"
+ "padding : 0;\n"
"}";
klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GEDIT_TYPE_CLOSE_BUTTON, GeditCloseButtonClassPrivate);
@@ -63,7 +106,7 @@ gedit_close_button_init (GeditCloseButton *button)
gtk_container_add (GTK_CONTAINER (button), image);
- /* make it small */
+ /* remove padding */
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),
diff --git a/gedit/gedit-small-button.h b/gedit/gedit-small-button.h
new file mode 100644
index 0000000..c2f872c
--- /dev/null
+++ b/gedit/gedit-small-button.h
@@ -0,0 +1,86 @@
+/*
+ * gedit-small-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_SMALL_BUTTON_H__
+#define __GEDIT_SMALL_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_SMALL_BUTTON (gedit_small_button_get_type ())
+#define GEDIT_SMALL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEDIT_TYPE_SMALL_BUTTON, GeditSmallButton))
+#define GEDIT_SMALL_BUTTON_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_SMALL_BUTTON,
GeditSmallButton const))
+#define GEDIT_SMALL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GEDIT_TYPE_SMALL_BUTTON, GeditSmallButtonClass))
+#define GEDIT_IS_SMALL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_SMALL_BUTTON))
+#define GEDIT_IS_SMALL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_SMALL_BUTTON))
+#define GEDIT_SMALL_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_SMALL_BUTTON,
GeditSmallButtonClass))
+
+typedef struct _GeditSmallButton GeditSmallButton;
+typedef struct _GeditSmallButtonClass GeditSmallButtonClass;
+typedef struct _GeditSmallButtonClassPrivate GeditSmallButtonClassPrivate;
+
+struct _GeditSmallButton
+{
+ GtkButton parent;
+};
+
+struct _GeditSmallButtonClass
+{
+ GtkButtonClass parent_class;
+
+ GeditSmallButtonClassPrivate *priv;
+};
+
+#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
+{
+ GeditSmallButton parent;
+};
+
+struct _GeditCloseButtonClass
+{
+ GeditSmallButtonClass parent_class;
+
+ GeditCloseButtonClassPrivate *priv;
+};
+
+GType gedit_small_button_get_type (void) G_GNUC_CONST;
+GtkWidget *gedit_small_button_new (void);
+
+GType gedit_close_button_get_type (void) G_GNUC_CONST;
+GtkWidget *gedit_close_button_new (void);
+
+G_END_DECLS
+
+#endif /* __GEDIT_SMALL_BUTTON_H__ */
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-tab-label.c b/gedit/gedit-tab-label.c
index bc344e1..f701457 100644
--- a/gedit/gedit-tab-label.c
+++ b/gedit/gedit-tab-label.c
@@ -27,7 +27,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "gedit-tab-label.h"
-#include "gedit-close-button.h"
+#include "gedit-small-button.h"
/* Signals */
enum
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]