~noskcaj/ubuntu/utopic/libfm/merge

« back to all changes in this revision

Viewing changes to src/gtk/fm-tab-label.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Lee (李健秋)
  • Date: 2010-04-29 03:52:06 UTC
  • Revision ID: james.westby@ubuntu.com-20100429035206-qlj1jwsfcgr5mdx3
Tags: upstream-0.1.11
Import upstream version 0.1.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      fm-tab-label.c
 
3
 *
 
4
 *      Copyright 2010 PCMan <pcman.tw@gmail.com>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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,
 
19
 *      MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "fm-tab-label.h"
 
23
 
 
24
typedef struct _FmTabLabelPrivate                       FmTabLabelPrivate;
 
25
 
 
26
#define FM_TAB_LABEL_GET_PRIVATE(obj)           (G_TYPE_INSTANCE_GET_PRIVATE((obj),\
 
27
                        FM_TYPE_TAB_LABEL, FmTabLabelPrivate))
 
28
 
 
29
static void fm_tab_label_finalize                       (GObject *object);
 
30
 
 
31
G_DEFINE_TYPE(FmTabLabel, fm_tab_label, GTK_TYPE_EVENT_BOX);
 
32
 
 
33
static void fm_tab_label_class_init(FmTabLabelClass *klass)
 
34
{
 
35
        GObjectClass *g_object_class;
 
36
        g_object_class = G_OBJECT_CLASS(klass);
 
37
        g_object_class->finalize = fm_tab_label_finalize;
 
38
 
 
39
    /* special style used by close button */
 
40
        gtk_rc_parse_string(
 
41
                "style \"close-btn-style\" {\n"
 
42
            "GtkWidget::focus-padding = 0\n"
 
43
            "GtkWidget::focus-line-width = 0\n"
 
44
            "xthickness = 0\n"
 
45
            "ythickness = 0\n"
 
46
                "}\n"
 
47
                "widget \"*.tab-close-btn\" style \"close-btn-style\""
 
48
        );
 
49
}
 
50
 
 
51
static void fm_tab_label_finalize(GObject *object)
 
52
{
 
53
        FmTabLabel *self;
 
54
 
 
55
        g_return_if_fail(object != NULL);
 
56
        g_return_if_fail(FM_IS_TAB_LABEL(object));
 
57
 
 
58
        self = FM_TAB_LABEL(object);
 
59
 
 
60
        G_OBJECT_CLASS(fm_tab_label_parent_class)->finalize(object);
 
61
}
 
62
 
 
63
static void on_close_btn_style_set(GtkWidget *btn, GtkRcStyle *prev, gpointer data)
 
64
{
 
65
        gint w, h;
 
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);
 
68
}
 
69
 
 
70
static void fm_tab_label_init(FmTabLabel *self)
 
71
{
 
72
    GtkWidget* hbox;
 
73
 
 
74
    gtk_event_box_set_visible_window(GTK_EVENT_BOX(self), FALSE);
 
75
    hbox = gtk_hbox_new( FALSE, 0 );
 
76
 
 
77
    self->label = gtk_label_new("");
 
78
    gtk_box_pack_start(GTK_BOX(hbox), self->label, FALSE, FALSE, 4 );
 
79
 
 
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);
 
88
 
 
89
    gtk_box_pack_end( GTK_BOX( hbox ), self->close_btn, FALSE, FALSE, 0 );
 
90
 
 
91
    gtk_container_add(GTK_CONTAINER(self), hbox);
 
92
    gtk_widget_show_all(hbox);
 
93
 
 
94
/*
 
95
    gtk_drag_dest_set ( GTK_WIDGET( evt_box ), GTK_DEST_DEFAULT_ALL,
 
96
                        drag_targets,
 
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 ),
 
101
                       file_browser );
 
102
*/
 
103
}
 
104
 
 
105
GtkWidget *fm_tab_label_new(const char* text)
 
106
{
 
107
    FmTabLabel* label = (FmTabLabel*)g_object_new(FM_TYPE_TAB_LABEL, NULL);
 
108
    gtk_label_set_text(label->label, text);
 
109
        return (GtkWidget*)label;
 
110
}
 
111
 
 
112
void fm_tab_label_set_text(FmTabLabel* label, const char* text)
 
113
{
 
114
    gtk_label_set_text(label->label, text);
 
115
}