4
* Copyright 2010 PCMan <pcman.tw@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22
#include "fm-tab-label.h"
24
typedef struct _FmTabLabelPrivate FmTabLabelPrivate;
26
#define FM_TAB_LABEL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),\
27
FM_TYPE_TAB_LABEL, FmTabLabelPrivate))
29
static void fm_tab_label_finalize (GObject *object);
31
G_DEFINE_TYPE(FmTabLabel, fm_tab_label, GTK_TYPE_EVENT_BOX);
33
static void fm_tab_label_class_init(FmTabLabelClass *klass)
35
GObjectClass *g_object_class;
36
g_object_class = G_OBJECT_CLASS(klass);
37
g_object_class->finalize = fm_tab_label_finalize;
39
/* special style used by close button */
41
"style \"close-btn-style\" {\n"
42
"GtkWidget::focus-padding = 0\n"
43
"GtkWidget::focus-line-width = 0\n"
47
"widget \"*.tab-close-btn\" style \"close-btn-style\""
51
static void fm_tab_label_finalize(GObject *object)
55
g_return_if_fail(object != NULL);
56
g_return_if_fail(FM_IS_TAB_LABEL(object));
58
self = FM_TAB_LABEL(object);
60
G_OBJECT_CLASS(fm_tab_label_parent_class)->finalize(object);
63
static void on_close_btn_style_set(GtkWidget *btn, GtkRcStyle *prev, gpointer data)
66
gtk_icon_size_lookup_for_settings(gtk_widget_get_settings(btn), GTK_ICON_SIZE_MENU, &w, &h);
67
gtk_widget_set_size_request(btn, w + 2, h + 2);
70
static void fm_tab_label_init(FmTabLabel *self)
74
gtk_event_box_set_visible_window(GTK_EVENT_BOX(self), FALSE);
75
hbox = gtk_hbox_new( FALSE, 0 );
77
self->label = gtk_label_new("");
78
gtk_box_pack_start(GTK_BOX(hbox), self->label, FALSE, FALSE, 4 );
80
self->close_btn = gtk_button_new();
81
gtk_button_set_focus_on_click ( GTK_BUTTON ( self->close_btn ), FALSE );
82
gtk_button_set_relief( GTK_BUTTON ( self->close_btn ), GTK_RELIEF_NONE );
83
gtk_container_add ( GTK_CONTAINER ( self->close_btn ),
84
gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
85
gtk_container_set_border_width(GTK_CONTAINER(self->close_btn), 0);
86
gtk_widget_set_name(self->close_btn, "tab-close-btn");
87
g_signal_connect(self->close_btn, "style-set", G_CALLBACK(on_close_btn_style_set), NULL);
89
gtk_box_pack_end( GTK_BOX( hbox ), self->close_btn, FALSE, FALSE, 0 );
91
gtk_container_add(GTK_CONTAINER(self), hbox);
92
gtk_widget_show_all(hbox);
95
gtk_drag_dest_set ( GTK_WIDGET( evt_box ), GTK_DEST_DEFAULT_ALL,
97
sizeof( drag_targets ) / sizeof( GtkTargetEntry ),
98
GDK_ACTION_DEFAULT | GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK );
99
g_signal_connect ( ( gpointer ) evt_box, "drag-motion",
100
G_CALLBACK ( on_tab_drag_motion ),
105
GtkWidget *fm_tab_label_new(const char* text)
107
FmTabLabel* label = (FmTabLabel*)g_object_new(FM_TYPE_TAB_LABEL, NULL);
108
gtk_label_set_text(label->label, text);
109
return (GtkWidget*)label;
112
void fm_tab_label_set_text(FmTabLabel* label, const char* text)
114
gtk_label_set_text(label->label, text);