comparison src/bar.c @ 1291:50ae02a4a675

replaced bar_info with an universal bar, restored the original functionality (more or less) bar configuration is not yet saved
author nadvornik
date Sat, 14 Feb 2009 19:50:54 +0000
parents
children 4a3ae0e6f1eb
comparison
equal deleted inserted replaced
1290:0c918f8b1f51 1291:50ae02a4a675
1 /*
2 * Geeqie
3 * (C) 2004 John Ellis
4 * Copyright (C) 2008 - 2009 The Geeqie Team
5 *
6 * Author: Vladimir Nadvornik
7 *
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
11 */
12
13
14 #include "main.h"
15 #include "bar.h"
16
17 #include "filedata.h"
18 #include "history_list.h"
19 #include "info.h"
20 #include "metadata.h"
21 #include "misc.h"
22 #include "ui_fileops.h"
23 #include "ui_misc.h"
24 #include "ui_utildlg.h"
25
26 #include "ui_menu.h"
27 #include "bar_comment.h"
28 #include "bar_keywords.h"
29
30 #define BAR_SIZE_INCREMENT 48
31 #define BAR_ARROW_SIZE 7
32
33
34 typedef struct _BarData BarData;
35 struct _BarData
36 {
37 GtkWidget *widget;
38 GtkWidget *vbox;
39 FileData *fd;
40 GtkWidget *label_file_name;
41
42 GList *(*list_func)(gpointer);
43 gpointer list_data;
44 };
45
46 static void bar_expander_move(GtkWidget *widget, gpointer data, gboolean up)
47 {
48 GtkWidget *expander = data;
49 GtkWidget *box;
50 gint pos;
51 if (!expander) return;
52 box = gtk_widget_get_ancestor(expander, GTK_TYPE_BOX);
53 if (!box) return;
54
55 gtk_container_child_get(GTK_CONTAINER(box), expander, "position", &pos, NULL);
56
57 pos = up ? (pos - 1) : (pos + 1);
58 if (pos < 0) pos = 0;
59
60 gtk_box_reorder_child(GTK_BOX(box), expander, pos);
61 }
62
63
64 static void bar_expander_move_up_cb(GtkWidget *widget, gpointer data)
65 {
66 bar_expander_move(widget, data, TRUE);
67 }
68
69 static void bar_expander_move_down_cb(GtkWidget *widget, gpointer data)
70 {
71 bar_expander_move(widget, data, FALSE);
72 }
73
74
75 static void bar_expander_menu_popup(GtkWidget *data)
76 {
77 GtkWidget *menu;
78
79 menu = popup_menu_short_lived();
80
81 menu_item_add_stock(menu, _("Move _up"), GTK_STOCK_GO_UP, G_CALLBACK(bar_expander_move_up_cb), data);
82 menu_item_add_stock(menu, _("Move _down"), GTK_STOCK_GO_DOWN, G_CALLBACK(bar_expander_move_down_cb), data);
83 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, data, 0, GDK_CURRENT_TIME);
84 }
85
86
87 static gboolean bar_expander_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
88 {
89 if (bevent->button == MOUSE_BUTTON_RIGHT)
90 {
91 bar_expander_menu_popup(widget);
92 return TRUE;
93 }
94 return FALSE;
95 }
96
97
98 void bar_pane_set_fd_cb(GtkWidget *expander, gpointer data)
99 {
100 GtkWidget *widget = gtk_bin_get_child(GTK_BIN(expander));
101 PaneData *pd = g_object_get_data(G_OBJECT(widget), "pane_data");
102 if (!pd) return;
103 if (pd->pane_set_fd) pd->pane_set_fd(widget, data);
104 }
105
106 void bar_set_fd(GtkWidget *bar, FileData *fd)
107 {
108 BarData *bd;
109 bd = g_object_get_data(G_OBJECT(bar), "bar_data");
110 if (!bd) return;
111
112 file_data_unref(bd->fd);
113 bd->fd = file_data_ref(fd);
114
115 gtk_container_foreach(GTK_CONTAINER(bd->vbox), bar_pane_set_fd_cb, fd);
116
117 gtk_label_set_text(GTK_LABEL(bd->label_file_name), (bd->fd) ? bd->fd->name : "");
118
119 }
120
121 gint bar_event(GtkWidget *bar, GdkEvent *event)
122 {
123 BarData *bd;
124 GList *list, *work;
125 gint ret = FALSE;
126 bd = g_object_get_data(G_OBJECT(bar), "bar_data");
127 if (!bd) return FALSE;
128
129 list = gtk_container_get_children(GTK_CONTAINER(bd->vbox));
130
131 work = list;
132 while (work)
133 {
134 GtkWidget *widget = gtk_bin_get_child(GTK_BIN(work->data));
135 PaneData *pd = g_object_get_data(G_OBJECT(widget), "pane_data");
136 if (!pd) continue;
137
138 if (pd->pane_event && pd->pane_event(widget, event))
139 {
140 ret = TRUE;
141 break;
142 }
143 work = work->next;
144 }
145 g_list_free(list);
146 return ret;
147 }
148
149 void bar_pane_set_selection_func(GtkWidget *pane, GList *(*list_func)(gpointer data), gpointer data)
150 {
151 PaneData *pd;
152
153 pd = g_object_get_data(G_OBJECT(pane), "pane_data");
154 if (!pd) return;
155
156 pd->list_func = list_func;
157 pd->list_data = data;
158 }
159
160 void bar_set_selection_func(GtkWidget *bar, GList *(*list_func)(gpointer data), gpointer data)
161 {
162 BarData *bd;
163 GList *list, *work;
164 bd = g_object_get_data(G_OBJECT(bar), "bar_data");
165 if (!bd) return;
166
167 bd->list_func = list_func;
168 bd->list_data = data;
169
170 list = gtk_container_get_children(GTK_CONTAINER(bd->vbox));
171
172 work = list;
173 while (work)
174 {
175 GtkWidget *widget = gtk_bin_get_child(GTK_BIN(work->data));
176
177 bar_pane_set_selection_func(widget, list_func, data);
178
179 work = work->next;
180 }
181 g_list_free(list);
182 return;
183 }
184
185
186
187
188
189 static void bar_add(GtkWidget *bar, GtkWidget *pane)
190 {
191 GtkWidget *expander;
192 GtkWidget *label;
193 BarData *bd = g_object_get_data(G_OBJECT(bar), "bar_data");
194 PaneData *pd = g_object_get_data(G_OBJECT(pane), "pane_data");
195
196
197 if (!bd) return;
198
199 expander = gtk_expander_new(pd ? pd->title : "");
200 gtk_box_pack_start(GTK_BOX(bd->vbox), expander, FALSE, TRUE, 0);
201
202 g_signal_connect(expander, "button_press_event", G_CALLBACK(bar_expander_menu_cb), bd);
203
204 label = gtk_expander_get_label_widget(GTK_EXPANDER(expander));
205 // gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
206 pref_label_bold(label, TRUE, FALSE);
207
208 gtk_container_add(GTK_CONTAINER(expander), pane);
209
210 gtk_expander_set_expanded(GTK_EXPANDER(expander), TRUE);
211
212 gtk_widget_show(expander);
213
214 if (bd->list_func) bar_pane_set_selection_func(pane, bd->list_func, bd->list_data);
215 if (bd->fd && pd && pd->pane_set_fd) pd->pane_set_fd(pane, bd->fd);
216
217 }
218
219 static void bar_width(BarData *bd, gint val)
220 {
221 gint size;
222
223 size = bd->widget->allocation.width;
224 size = CLAMP(size + val, BAR_SIZE_INCREMENT * 2, BAR_SIZE_INCREMENT * 16);
225
226 gtk_widget_set_size_request(bd->widget, size, -1);
227 options->panels.info.width = bd->widget->allocation.width;
228 }
229
230 static void bar_larger(GtkWidget *widget, gpointer data)
231 {
232 BarData *bd = data;
233
234 bar_width(bd, BAR_SIZE_INCREMENT);
235 }
236
237 static void bar_smaller(GtkWidget *widget, gpointer data)
238 {
239 BarData *bd = data;
240
241 bar_width(bd, -BAR_SIZE_INCREMENT);
242 }
243
244 void bar_close(GtkWidget *bar)
245 {
246 BarData *bd;
247
248 bd = g_object_get_data(G_OBJECT(bar), "bar_data");
249 if (!bd) return;
250
251 gtk_widget_destroy(bd->widget);
252 }
253
254 static void bar_destroy(GtkWidget *widget, gpointer data)
255 {
256 BarData *bd = data;
257
258 file_data_unref(bd->fd);
259 g_free(bd);
260 }
261
262 GtkWidget *bar_new(GtkWidget *bounding_widget)
263 {
264 BarData *bd;
265 GtkWidget *box;
266 GtkWidget *sizer;
267 GtkWidget *label;
268 GtkWidget *button;
269 GtkWidget *arrow;
270 GtkWidget *scrolled;
271 GtkWidget *widget;
272
273 bd = g_new0(BarData, 1);
274
275 bd->widget = gtk_vbox_new(FALSE, PREF_PAD_GAP);
276 g_object_set_data(G_OBJECT(bd->widget), "bar_data", bd);
277 g_signal_connect(G_OBJECT(bd->widget), "destroy",
278 G_CALLBACK(bar_destroy), bd);
279
280 box = gtk_hbox_new(FALSE, 0);
281
282 sizer = sizer_new(bd->widget, bounding_widget, SIZER_POS_LEFT);
283 sizer_set_limits(sizer, BAR_SIZE_INCREMENT * 2, -1, -1 , -1);
284 gtk_box_pack_start(GTK_BOX(box), sizer, FALSE, FALSE, 0);
285 gtk_widget_show(sizer);
286
287 label = gtk_label_new(_("Filename:"));
288 gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.0);
289 gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
290 gtk_widget_show(label);
291
292 bd->label_file_name = gtk_label_new("");
293 pref_label_bold(bd->label_file_name, TRUE, FALSE);
294 gtk_misc_set_alignment(GTK_MISC(bd->label_file_name), 0.0, 0.0);
295 gtk_box_pack_start(GTK_BOX(box), bd->label_file_name, TRUE, TRUE, 0);
296 gtk_widget_show(bd->label_file_name);
297
298 button = gtk_button_new();
299 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
300 g_signal_connect(G_OBJECT(button), "clicked",
301 G_CALLBACK(bar_smaller), bd);
302 gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0);
303 arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
304 gtk_widget_set_size_request(arrow, BAR_ARROW_SIZE, BAR_ARROW_SIZE);
305 gtk_container_add(GTK_CONTAINER(button), arrow);
306 gtk_widget_show(arrow);
307 gtk_widget_show(button);
308
309 button = gtk_button_new();
310 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
311 g_signal_connect(G_OBJECT(button), "clicked",
312 G_CALLBACK(bar_larger), bd);
313 gtk_box_pack_end(GTK_BOX(box), button, FALSE, FALSE, 0);
314 arrow = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_NONE);
315 gtk_widget_set_size_request(arrow, BAR_ARROW_SIZE, BAR_ARROW_SIZE);
316 gtk_container_add(GTK_CONTAINER(button), arrow);
317 gtk_widget_show(arrow);
318 gtk_widget_show(button);
319
320 gtk_box_pack_start(GTK_BOX(bd->widget), box, FALSE, FALSE, 0);
321 gtk_widget_show(box);
322
323 scrolled = gtk_scrolled_window_new(NULL, NULL);
324 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
325 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
326 gtk_box_pack_start(GTK_BOX(bd->widget), scrolled, TRUE, TRUE, 0);
327 gtk_widget_show(scrolled);
328
329
330 bd->vbox = gtk_vbox_new(FALSE, 0);
331 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled), bd->vbox);
332 gtk_viewport_set_shadow_type(GTK_VIEWPORT(gtk_bin_get_child(GTK_BIN(scrolled))), GTK_SHADOW_NONE);
333
334 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_NONE);
335 gtk_widget_show(bd->vbox);
336
337
338 widget = bar_pane_comment_new(_("Title"), "Xmp.dc.title", 40);
339 bar_add(bd->widget, widget);
340
341 widget = bar_pane_keywords_new(_("Keywords"), KEYWORD_KEY);
342 bar_add(bd->widget, widget);
343
344 widget = bar_pane_comment_new(_("Comment"), "Xmp.dc.description", 150);
345 bar_add(bd->widget, widget);
346
347 return bd->widget;
348 }
349
350
351
352 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */