[Xfce4-commits] [apps/mousepad] 07/11: Fix the little notebook tab close button

noreply at xfce.org noreply at xfce.org
Sat Jul 19 13:54:49 CEST 2014


This is an automated email from the git hooks/post-receive script.

mbrush pushed a commit to branch master
in repository apps/mousepad.

commit 3631db27c244503ddc9dc6b3b026a714a19a307b
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Thu Jul 17 19:08:28 2014 -0700

    Fix the little notebook tab close button
    
    For GTK3 it's basically copied from GeditCloseButton, for GTK2
    it's inspired by Geany's notebook.c.
---
 mousepad/Makefile.am             |    2 +
 mousepad/mousepad-close-button.c |  107 ++++++++++++++++++++++++++++++++++++++
 mousepad/mousepad-close-button.h |   23 ++++++++
 mousepad/mousepad-document.c     |   30 ++++-------
 4 files changed, 141 insertions(+), 21 deletions(-)

diff --git a/mousepad/Makefile.am b/mousepad/Makefile.am
index d9cf129..d6cb75c 100644
--- a/mousepad/Makefile.am
+++ b/mousepad/Makefile.am
@@ -25,6 +25,8 @@ mousepad_SOURCES = \
 	mousepad-action-group.h \
 	mousepad-application.c \
 	mousepad-application.h \
+	mousepad-close-button.c \
+	mousepad-close-button.h \
 	mousepad-dialogs.c \
 	mousepad-dialogs.h \
 	mousepad-document.c \
diff --git a/mousepad/mousepad-close-button.c b/mousepad/mousepad-close-button.c
new file mode 100644
index 0000000..6405fae
--- /dev/null
+++ b/mousepad/mousepad-close-button.c
@@ -0,0 +1,107 @@
+#include <mousepad/mousepad-close-button.h>
+
+
+
+struct MousepadCloseButton_
+{
+  GtkButton parent;
+};
+
+struct MousepadCloseButtonClass_
+{
+  GtkButtonClass  parent_class;
+#if GTK_CHECK_VERSION(3, 0, 0)
+  GtkCssProvider *css_provider;
+#endif
+};
+
+
+
+G_DEFINE_TYPE (MousepadCloseButton, mousepad_close_button, GTK_TYPE_BUTTON)
+
+
+
+#if ! GTK_CHECK_VERSION(3, 0, 0)
+static void
+mousepad_close_button_style_set (GtkWidget *widget,
+                                 GtkStyle  *previous_style)
+{
+  GtkSettings *settings;
+  gint         w, h;
+
+  settings = gtk_widget_get_settings (widget);
+  gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &w, &h);
+  gtk_widget_set_size_request(widget, w + 2, h + 2);
+}
+#endif
+
+
+
+static void
+mousepad_close_button_class_init (MousepadCloseButtonClass *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"
+    "}\n";
+
+  klass->css_provider = gtk_css_provider_new ();
+  gtk_css_provider_load_from_data (klass->css_provider, button_style, -1, NULL);
+#else
+  GtkWidgetClass *widget_class;
+
+  gtk_rc_parse_string (
+    "style \"mousepad-close-button-style\" {\n"
+    "  GtkWidget::focus-padding = 0\n"
+    "  GtkWidget::focus-line-width = 0\n"
+    "  xthickness = 0\n"
+    "  ythickness = 0\n"
+    "}\n"
+    "widget \"*.mousepad-close-button\" style \"mousepad-close-button-style\"\n");
+
+  widget_class = GTK_WIDGET_CLASS (klass);
+  widget_class->style_set = mousepad_close_button_style_set;
+#endif
+}
+
+
+
+static void
+mousepad_close_button_init (MousepadCloseButton *button)
+{
+  GtkWidget *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 (MOUSEPAD_CLOSE_BUTTON_GET_CLASS(button)->css_provider),
+                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+#else
+  gtk_widget_set_name (GTK_WIDGET (button), "mousepad-close-button");
+#endif
+
+  image = gtk_image_new_from_icon_name ("gtk-close", GTK_ICON_SIZE_MENU);
+  gtk_container_add (GTK_CONTAINER (button), image);
+  gtk_widget_show (image);
+
+  g_object_set (G_OBJECT (button),
+                "relief", GTK_RELIEF_NONE,
+                "focus-on-click", FALSE,
+                NULL);
+}
+
+
+
+GtkWidget *
+mousepad_close_button_new (void)
+{
+  return g_object_new (MOUSEPAD_TYPE_CLOSE_BUTTON, NULL);
+}
diff --git a/mousepad/mousepad-close-button.h b/mousepad/mousepad-close-button.h
new file mode 100644
index 0000000..0771107
--- /dev/null
+++ b/mousepad/mousepad-close-button.h
@@ -0,0 +1,23 @@
+#ifndef __MOUSEPAD_CLOSE_BUTTON_H__
+#define __MOUSEPAD_CLOSE_BUTTON_H__ 1
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define MOUSEPAD_TYPE_CLOSE_BUTTON            (mousepad_close_button_get_type ())
+#define MOUSEPAD_CLOSE_BUTTON(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOUSEPAD_TYPE_CLOSE_BUTTON, MousepadCloseButton))
+#define MOUSEPAD_CLOSE_BUTTON_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), MOUSEPAD_TYPE_CLOSE_BUTTON, MousepadCloseButtonClass))
+#define MOUSEPAD_IS_CLOSE_BUTTON(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOUSEPAD_TYPE_CLOSE_BUTTON))
+#define MOUSEPAD_IS_CLOSE_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOUSEPAD_TYPE_CLOSE_BUTTON))
+#define MOUSEPAD_CLOSE_BUTTON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), MOUSEPAD_TYPE_CLOSE_BUTTON, MousepadCloseButtonClass))
+
+typedef struct MousepadCloseButton_      MousepadCloseButton;
+typedef struct MousepadCloseButtonClass_ MousepadCloseButtonClass;
+
+GType      mousepad_close_button_get_type (void);
+GtkWidget *mousepad_close_button_new      (void);
+
+G_END_DECLS
+
+#endif /* __MOUSEPAD_CLOSE_BUTTON_H__ */
diff --git a/mousepad/mousepad-document.c b/mousepad/mousepad-document.c
index 1c6a636..8591b48 100644
--- a/mousepad/mousepad-document.c
+++ b/mousepad/mousepad-document.c
@@ -16,6 +16,7 @@
 
 #include <mousepad/mousepad-private.h>
 #include <mousepad/mousepad-gtkcompat.h>
+#include <mousepad/mousepad-close-button.h>
 #include <mousepad/mousepad-settings.h>
 #include <mousepad/mousepad-util.h>
 #include <mousepad/mousepad-document.h>
@@ -470,9 +471,8 @@ mousepad_document_send_signals (MousepadDocument *document)
 GtkWidget *
 mousepad_document_get_tab_label (MousepadDocument *document)
 {
-  GtkWidget  *hbox;
-  GtkWidget  *button, *image;
-  GtkRcStyle *style;
+  GtkWidget  *hbox, *align;
+  GtkWidget  *button;
 
   /* create the box */
   hbox = gtk_hbox_new (FALSE, 0);
@@ -493,28 +493,16 @@ mousepad_document_get_tab_label (MousepadDocument *document)
   mousepad_document_label_color (document);
 
   /* create the button */
-  button = gtk_button_new ();
-  gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
-  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
-  gtk_widget_set_can_default(GTK_WIDGET(button), FALSE);
-  gtk_widget_set_can_focus(GTK_WIDGET(button), FALSE);
-
-  /* make button a bit smaller */
-  style = gtk_rc_style_new ();
-  style->xthickness = style->ythickness = 0;
-  gtk_widget_modify_style (button, style);
-  g_object_unref (G_OBJECT (style));
+  align = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
+  button = mousepad_close_button_new ();
+  gtk_container_add (GTK_CONTAINER (align), button);
+  gtk_widget_show (button);
 
   /* pack button, add signal and tooltip */
   gtk_widget_set_tooltip_text (button, _("Close this tab"));
-  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), align, FALSE, FALSE, 0);
   g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (mousepad_document_tab_button_clicked), document);
-  gtk_widget_show (button);
-
-  /* button image */
-  image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
-  gtk_container_add (GTK_CONTAINER (button), image);
-  gtk_widget_show (image);
+  gtk_widget_show (align);
 
   return hbox;
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list