Commit 2b0c34cb authored by Matthias Clasen's avatar Matthias Clasen

Add a closable tab class

This adds a close button to the tab in addition to the label.
parent 941f1ad1
......@@ -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 \
......
......@@ -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>
......
/* 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);
}
/* 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__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment