[gtk+/wip/matthiasc/tab-strip: 4/10] Add a closable tab class



commit 2b0c34cbf8cd0c7c3e844cb8b2db28032b9042fe
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 20 21:42:45 2016 -0400

    Add a closable tab class
    
    This adds a close button to the tab in addition to the label.

 gtk/Makefile.am      |    2 +
 gtk/gtk.h            |    1 +
 gtk/gtkclosabletab.c |   81 ++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkclosabletab.h |   37 +++++++++++++++++++++++
 4 files changed, 121 insertions(+), 0 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index a1adbf0..beca7e8 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -304,6 +304,7 @@ gtk_public_h_sources =              \
        gtkswitch.h             \
        gtktab.h                \
        gtksimpletab.h          \
+       gtkclosabletab.h        \
        gtktabstrip.h           \
        gtktestutils.h          \
        gtktextattributes.h     \
@@ -905,6 +906,7 @@ gtk_base_c_sources =                \
        gtkswitch.c             \
        gtktab.c                \
        gtksimpletab.c          \
+       gtkclosabletab.c        \
        gtktabstrip.c           \
        gtktestutils.c          \
        gtktextattributes.c     \
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 9bccb68..488ad69 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -205,6 +205,7 @@
 #include <gtk/gtkswitch.h>
 #include <gtk/gtktab.h>
 #include <gtk/gtksimpletab.h>
+#include <gtk/gtkclosabletab.h>
 #include <gtk/gtktabstrip.h>
 #include <gtk/gtktextattributes.h>
 #include <gtk/gtktextbuffer.h>
diff --git a/gtk/gtkclosabletab.c b/gtk/gtkclosabletab.c
new file mode 100644
index 0000000..1c50731
--- /dev/null
+++ b/gtk/gtkclosabletab.c
@@ -0,0 +1,81 @@
+/* gtkclosabletab.c
+ *
+ * Copyright (C) 2016 Red Hat Inc.
+ *
+ * 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 of the License, or (at your
+ * option) any later version.
+ *
+ * This program 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtkclosabletab.h"
+#include "gtkintl.h"
+#include "gtkprivate.h"
+#include "gtkenums.h"
+#include "gtklabel.h"
+#include "gtkbox.h"
+#include "gtkbutton.h"
+
+struct _GtkClosableTab
+{
+  GtkTab parent;
+
+  GtkWidget *box;
+  GtkWidget *label;
+  GtkWidget *button;
+};
+
+typedef struct _GtkClosableTabClass GtkClosableTabClass;
+
+struct _GtkClosableTabClass
+{
+  GtkTabClass parent_class;
+};
+
+G_DEFINE_TYPE (GtkClosableTab, gtk_closable_tab, GTK_TYPE_TAB)
+
+static void
+gtk_closable_tab_class_init (GtkClosableTabClass *klass)
+{
+}
+
+static void
+close_tab (GtkClosableTab *tab)
+{
+  GtkWidget *widget;
+  GtkWidget *stack;
+
+  widget = gtk_tab_get_widget (GTK_TAB (tab));
+  stack = gtk_widget_get_parent (widget);
+  gtk_container_remove (GTK_CONTAINER (stack), widget);
+}
+
+static void
+gtk_closable_tab_init (GtkClosableTab *self)
+{
+  self->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
+  gtk_widget_show (self->box);
+  gtk_tab_set_child (GTK_TAB (self), self->box);
+
+  self->label = gtk_label_new ("");
+  gtk_widget_show (self->label);
+  gtk_box_set_center_widget (GTK_BOX (self->box), self->label);
+  g_object_bind_property (self, "title", self->label, "label", G_BINDING_DEFAULT);
+
+  self->button = gtk_button_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_MENU);
+  gtk_button_set_relief (GTK_BUTTON (self->button), GTK_RELIEF_NONE);
+  gtk_widget_show (self->button);
+  gtk_box_pack_end (GTK_BOX (self->box), self->button, FALSE, FALSE, 0);
+
+  g_signal_connect_swapped (self->button, "clicked", G_CALLBACK (close_tab), self);
+}
diff --git a/gtk/gtkclosabletab.h b/gtk/gtkclosabletab.h
new file mode 100644
index 0000000..b0db247
--- /dev/null
+++ b/gtk/gtkclosabletab.h
@@ -0,0 +1,37 @@
+/* gtkclosabletab.h
+ *
+ * Copyright (C) 2016 Red Hat Inc.
+ *
+ * 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 of the License, or (at your
+ * option) any later version.
+ *
+ * This program 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_CLOSABLE_TAB_H__
+#define __GTK_CLOSABLE_TAB_H__
+
+#include <gtk/gtktab.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CLOSABLE_TAB                 (gtk_closable_tab_get_type ())
+#define GTK_CLOSABLE_TAB(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CLOSABLE_TAB, 
GtkClosableTab))
+#define GTK_IS_CLOSABLE_TAB(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CLOSABLE_TAB))
+
+typedef struct _GtkClosableTab      GtkClosableTab;
+
+GDK_AVAILABLE_IN_3_22
+GType            gtk_closable_tab_get_type   (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __GTK_CLOSABLE_TAB_H__ */


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