~vcs-imports/gthumb/main

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  GThumb
 *
 *  Copyright (C) 2001, 2003 Free Software Foundation, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 */

#include "gthumb-info-bar.h"

#define X_PADDING 5
#define Y_PADDING 2

static GtkEventBoxClass *parent_class = NULL;

struct _GThumbInfoBarPrivate {
	gboolean     focused;
	char        *tooltip;

	GtkWidget   *hbox;
	GtkWidget   *label;
	GtkTooltips *tooltips;
};


static void
gthumb_info_bar_destroy (GtkObject *object)
{
	GThumbInfoBar *info_bar = GTHUMB_INFO_BAR (object);

	if (info_bar->priv != NULL) {
		if (info_bar->priv->tooltip) {
			g_free (info_bar->priv->tooltip);
			info_bar->priv->tooltip = NULL;
		}

		gtk_object_destroy (GTK_OBJECT (info_bar->priv->tooltips));

		g_free (info_bar->priv);
		info_bar->priv = NULL;
	}

	if (GTK_OBJECT_CLASS (parent_class)->destroy)
		GTK_OBJECT_CLASS (parent_class)->destroy (object);
}


static void
gthumb_info_bar_size_request (GtkWidget      *widget,
			      GtkRequisition *requisition)
{	
	if (GTK_WIDGET_CLASS (parent_class)->size_request)
		(* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition);
	requisition->width = 0;
}


static void
gthumb_info_bar_style_set (GtkWidget *widget,
			   GtkStyle  *previous_style)
{
        static int  in_style_set = 0;
	GtkStyle   *style = widget->style;
	GtkRcStyle *rc_style;

        if (in_style_set > 0)
                return;

        in_style_set++;

	rc_style = gtk_widget_get_modifier_style (widget);

	rc_style->color_flags[GTK_STATE_NORMAL] |= GTK_RC_TEXT;
	rc_style->text[GTK_STATE_NORMAL] = style->light[GTK_STATE_NORMAL];

	gtk_widget_modify_style (widget, rc_style);

        in_style_set--;

        (* GTK_WIDGET_CLASS (parent_class)->style_set) (widget, previous_style);
}


static void
gthumb_info_bar_class_init (GThumbInfoBarClass *class)
{
	GtkObjectClass *object_class;
	GtkWidgetClass *widget_class;

	parent_class = g_type_class_peek_parent (class);
	object_class = (GtkObjectClass*) class;
	widget_class = (GtkWidgetClass*) class;

	object_class->destroy       = gthumb_info_bar_destroy;
	widget_class->size_request  = gthumb_info_bar_size_request;
	widget_class->style_set     = gthumb_info_bar_style_set;
}


static void
gthumb_info_bar_init (GThumbInfoBar *info_bar)
{
	GThumbInfoBarPrivate *priv;

	GTK_WIDGET_UNSET_FLAGS (info_bar, GTK_CAN_FOCUS);

	priv = g_new0 (GThumbInfoBarPrivate, 1);
	info_bar->priv = priv;

	priv->hbox = gtk_hbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (info_bar), priv->hbox);

	priv->label = gtk_label_new ("");
	gtk_box_pack_start (GTK_BOX (priv->hbox), priv->label, TRUE, TRUE, 0);
	gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
	gtk_misc_set_padding   (GTK_MISC (priv->label), X_PADDING, Y_PADDING);
	gtk_label_set_line_wrap (GTK_LABEL (priv->label), FALSE);

	info_bar->priv->tooltips = gtk_tooltips_new ();
	info_bar->priv->tooltip = NULL;
}


void
gthumb_info_bar_add_button (GThumbInfoBar *info_bar,
			    GtkWidget     *button,
			    int            padding)
{
	gtk_box_pack_end (GTK_BOX (info_bar->priv->hbox), button, FALSE, FALSE, padding);
}


GType
gthumb_info_bar_get_type (void)
{
	static GType type = 0;

	if (! type) {
		static const GTypeInfo info =
		{
			sizeof (GThumbInfoBarClass),
			NULL,
			NULL,
			(GClassInitFunc) gthumb_info_bar_class_init,
			NULL,
			NULL,
			sizeof (GThumbInfoBar),
			0,
			(GInstanceInitFunc) gthumb_info_bar_init
		};

		type = g_type_register_static (GTK_TYPE_EVENT_BOX, 
					       "GThumbInfoBar",
					       &info,
					       0);
	}
	
	return type;
}


GtkWidget*
gthumb_info_bar_new ()
{
	GtkWidget *widget;
	widget = GTK_WIDGET (g_object_new (GTHUMB_TYPE_INFO_BAR, NULL));
	return widget;
}


void
gthumb_info_bar_set_focused (GThumbInfoBar *info_bar,
			     gboolean       focused)
{
	GtkWidget  *widget = GTK_WIDGET (info_bar);

	info_bar->priv->focused = focused;
	if (focused)
		gtk_widget_set_state (widget, GTK_STATE_SELECTED);
	else
		gtk_widget_set_state (widget, GTK_STATE_NORMAL);

	gtk_widget_queue_draw (info_bar->priv->hbox);
}


static void
set_tooltip (GThumbInfoBar *info_bar,
	     const gchar   *tooltip)
{
	if (info_bar->priv->tooltip) {
		g_free (info_bar->priv->tooltip);
		info_bar->priv->tooltip = NULL;
	}

	if (tooltip != NULL) {
		info_bar->priv->tooltip = g_strdup (tooltip);
		gtk_tooltips_set_tip (info_bar->priv->tooltips,
				      GTK_WIDGET (info_bar),
				      info_bar->priv->tooltip,
				      NULL);
		gtk_tooltips_enable (info_bar->priv->tooltips);
	} else 
		gtk_tooltips_disable (info_bar->priv->tooltips);
}


void
gthumb_info_bar_set_text (GThumbInfoBar *info_bar,
			  const char    *text,
			  const char    *tooltip)
{
	gtk_label_set_markup (GTK_LABEL (info_bar->priv->label), text);
	set_tooltip (info_bar, tooltip);
}