[anjuta] libanjuta: bgo #697030 - Add close button widget



commit ea3531da6a5e88f81c518fa8453d1e623b902a05
Author: Arnel A. Borja <kyoushuu yahoo com>
Date:   Mon Apr 8 10:45:42 2013 +0800

    libanjuta: bgo #697030 - Add close button widget

 libanjuta/Makefile.am           |    7 ++-
 libanjuta/anjuta-close-button.c |   81 +++++++++++++++++++++++++++++++++++++++
 libanjuta/anjuta-close-button.h |   59 ++++++++++++++++++++++++++++
 libanjuta/libanjuta.h           |    1 +
 4 files changed, 146 insertions(+), 2 deletions(-)
---
diff --git a/libanjuta/Makefile.am b/libanjuta/Makefile.am
index 2b53c13..d6a1ad7 100644
--- a/libanjuta/Makefile.am
+++ b/libanjuta/Makefile.am
@@ -134,7 +134,9 @@ libanjuta_3_la_SOURCES= \
        anjuta-autogen.h \
        anjuta-autogen.c \
        anjuta-completion.h \
-       anjuta-completion.c
+       anjuta-completion.c \
+       anjuta-close-button.c \
+       anjuta-close-button.h
 
 # Glade module
 if ENABLE_GLADE_CATALOG
@@ -210,7 +212,8 @@ libanjuta_include = \
        anjuta-token-file.h \
        anjuta-token-list.h \
        anjuta-token-stream.h \
-       anjuta-tree-combo.h
+       anjuta-tree-combo.h \
+       anjuta-close-button.h
 
 libanjutainclude_HEADERS = \
        $(libanjuta_include) \
diff --git a/libanjuta/anjuta-close-button.c b/libanjuta/anjuta-close-button.c
new file mode 100644
index 0000000..ff8f787
--- /dev/null
+++ b/libanjuta/anjuta-close-button.c
@@ -0,0 +1,81 @@
+/*
+ * anjuta-close-button.c
+ *
+ * Copyright (C) 2010 - Paolo Borelli
+ * Copyright (C) 2011 - Ignacio Casal Quinteiro
+ *
+ * This library 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.
+ *
+ * This library 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 "anjuta-close-button.h"
+
+struct _AnjutaCloseButtonClassPrivate
+{
+       GtkCssProvider *css;
+};
+
+G_DEFINE_TYPE_WITH_CODE (AnjutaCloseButton, anjuta_close_button, GTK_TYPE_BUTTON,
+                         g_type_add_class_private (g_define_type_id, sizeof (AnjutaCloseButtonClassPrivate)))
+
+static void
+anjuta_close_button_class_init (AnjutaCloseButtonClass *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, ANJUTA_TYPE_CLOSE_BUTTON, 
AnjutaCloseButtonClassPrivate);
+
+       klass->priv->css = gtk_css_provider_new ();
+       gtk_css_provider_load_from_data (klass->priv->css, button_style, -1, NULL);
+}
+
+static void
+anjuta_close_button_init (AnjutaCloseButton *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 (ANJUTA_CLOSE_BUTTON_GET_CLASS 
(button)->priv->css),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
+GtkWidget *
+anjuta_close_button_new ()
+{
+       return GTK_WIDGET (g_object_new (ANJUTA_TYPE_CLOSE_BUTTON,
+                                        "relief", GTK_RELIEF_NONE,
+                                        "focus-on-click", FALSE,
+                                        NULL));
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libanjuta/anjuta-close-button.h b/libanjuta/anjuta-close-button.h
new file mode 100644
index 0000000..4cb03e9
--- /dev/null
+++ b/libanjuta/anjuta-close-button.h
@@ -0,0 +1,59 @@
+/*
+ * anjuta-close-button.h
+ *
+ * Copyright (C) 2010 - Paolo Borelli
+ *
+ * This library 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.
+ *
+ * This library 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 __ANJUTA_CLOSE_BUTTON_H__
+#define __ANJUTA_CLOSE_BUTTON_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define ANJUTA_TYPE_CLOSE_BUTTON               (anjuta_close_button_get_type ())
+#define ANJUTA_CLOSE_BUTTON(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANJUTA_TYPE_CLOSE_BUTTON, 
AnjutaCloseButton))
+#define ANJUTA_CLOSE_BUTTON_CONST(obj)         (G_TYPE_CHECK_INSTANCE_CAST ((obj), ANJUTA_TYPE_CLOSE_BUTTON, 
AnjutaCloseButton const))
+#define ANJUTA_CLOSE_BUTTON_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), ANJUTA_TYPE_CLOSE_BUTTON, 
AnjutaCloseButtonClass))
+#define ANJUTA_IS_CLOSE_BUTTON(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ANJUTA_TYPE_CLOSE_BUTTON))
+#define ANJUTA_IS_CLOSE_BUTTON_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), ANJUTA_TYPE_CLOSE_BUTTON))
+#define ANJUTA_CLOSE_BUTTON_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), ANJUTA_TYPE_CLOSE_BUTTON, 
AnjutaCloseButtonClass))
+
+typedef struct _AnjutaCloseButton              AnjutaCloseButton;
+typedef struct _AnjutaCloseButtonClass         AnjutaCloseButtonClass;
+typedef struct _AnjutaCloseButtonClassPrivate  AnjutaCloseButtonClassPrivate;
+
+struct _AnjutaCloseButton
+{
+       GtkButton parent;
+};
+
+struct _AnjutaCloseButtonClass
+{
+       GtkButtonClass parent_class;
+
+       AnjutaCloseButtonClassPrivate *priv;
+};
+
+GType            anjuta_close_button_get_type (void) G_GNUC_CONST;
+
+GtkWidget       *anjuta_close_button_new      (void);
+
+G_END_DECLS
+
+#endif /* __ANJUTA_CLOSE_BUTTON_H__ */
+/* ex:set ts=8 noet: */
diff --git a/libanjuta/libanjuta.h b/libanjuta/libanjuta.h
index 1d7206f..faf2f24 100644
--- a/libanjuta/libanjuta.h
+++ b/libanjuta/libanjuta.h
@@ -74,5 +74,6 @@
 #include <libanjuta/anjuta-token-stream.h>
 #include <libanjuta/anjuta-tree-combo.h>
 #include <libanjuta/anjuta-vcs-status.h>
+#include <libanjuta/anjuta-close-button.h>
 
 #endif


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