Mercurial > geeqie
annotate src/ui_menu.c @ 1779:f64e346a3d9c
Move "Add Keyword" menu item at top of Keywords bar contextual menu.
Suggested by Lars T¸«£uber.
author | zas_ |
---|---|
date | Thu, 10 Dec 2009 17:48:43 +0000 |
parents | 0806ccdfe06b |
children | 956aab097ea7 |
rev | line source |
---|---|
9 | 1 /* |
2 * (SLIK) SimpLIstic sKin functions | |
3 * (C) 2004 John Ellis | |
1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
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 #ifdef HAVE_CONFIG_H | |
14 # include "config.h" | |
15 #endif | |
16 #include "intl.h" | |
17 | |
18 #include <stdio.h> | |
19 #include <stdlib.h> | |
20 #include <string.h> | |
21 | |
22 #include <gtk/gtk.h> | |
23 | |
24 #include "ui_menu.h" | |
25 | |
26 | |
27 /* | |
28 *----------------------------------------------------------------------------- | |
29 * menu items | |
30 *----------------------------------------------------------------------------- | |
442 | 31 */ |
9 | 32 |
33 static void menu_item_finish(GtkWidget *menu, GtkWidget *item, GCallback func, gpointer data) | |
34 { | |
35 if (func) g_signal_connect(G_OBJECT(item), "activate", func, data); | |
36 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); | |
37 gtk_widget_show(item); | |
38 } | |
39 | |
40 GtkWidget *menu_item_add(GtkWidget *menu, const gchar *label, | |
41 GCallback func, gpointer data) | |
42 { | |
43 GtkWidget *item; | |
44 | |
45 item = gtk_menu_item_new_with_mnemonic(label); | |
46 menu_item_finish(menu, item, func, data); | |
47 | |
48 return item; | |
49 } | |
50 | |
51 GtkWidget *menu_item_add_stock(GtkWidget *menu, const gchar *label, const gchar *stock_id, | |
52 GCallback func, gpointer data) | |
53 { | |
54 GtkWidget *item; | |
55 GtkWidget *image; | |
56 | |
57 item = gtk_image_menu_item_new_with_mnemonic(label); | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
475
diff
changeset
|
58 image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_MENU); |
9 | 59 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image); |
60 gtk_widget_show(image); | |
61 menu_item_finish(menu, item, func, data); | |
62 | |
63 return item; | |
64 } | |
65 | |
1448 | 66 GtkWidget *menu_item_add_sensitive(GtkWidget *menu, const gchar *label, gboolean sensitive, |
9 | 67 GCallback func, gpointer data) |
68 { | |
69 GtkWidget *item; | |
70 | |
71 item = menu_item_add(menu, label, func, data); | |
72 gtk_widget_set_sensitive(item, sensitive); | |
73 | |
74 return item; | |
75 } | |
76 | |
1448 | 77 GtkWidget *menu_item_add_stock_sensitive(GtkWidget *menu, const gchar *label, const gchar *stock_id, gboolean sensitive, |
9 | 78 GCallback func, gpointer data) |
79 { | |
80 GtkWidget *item; | |
81 | |
82 item = menu_item_add_stock(menu, label, stock_id, func, data); | |
83 gtk_widget_set_sensitive(item, sensitive); | |
442 | 84 |
9 | 85 return item; |
86 } | |
87 | |
1448 | 88 GtkWidget *menu_item_add_check(GtkWidget *menu, const gchar *label, gboolean active, |
9 | 89 GCallback func, gpointer data) |
90 { | |
91 GtkWidget *item; | |
92 | |
93 item = gtk_check_menu_item_new_with_mnemonic(label); | |
94 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), active); | |
95 menu_item_finish(menu, item, func, data); | |
96 | |
97 return item; | |
98 } | |
99 | |
1667 | 100 GtkWidget *menu_item_add_radio(GtkWidget *menu, const gchar *label, gpointer item_data, gboolean active, |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
88
diff
changeset
|
101 GCallback func, gpointer data) |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
88
diff
changeset
|
102 { |
1667 | 103 GtkWidget *item = menu_item_add_check(menu, label, active, func, data); |
104 g_object_set_data(G_OBJECT(item), "menu_item_radio_data", item_data); | |
105 g_object_set(G_OBJECT(item), "draw-as-radio", TRUE, NULL); | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
88
diff
changeset
|
106 |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
88
diff
changeset
|
107 return item; |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
88
diff
changeset
|
108 } |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
88
diff
changeset
|
109 |
9 | 110 void menu_item_add_divider(GtkWidget *menu) |
111 { | |
112 GtkWidget *item = gtk_menu_item_new(); | |
113 gtk_widget_set_sensitive(item, FALSE); | |
442 | 114 gtk_menu_shell_append(GTK_MENU_SHELL(menu),item); |
115 gtk_widget_show(item); | |
9 | 116 } |
117 | |
118 GtkWidget *menu_item_add_simple(GtkWidget *menu, const gchar *label, | |
119 GCallback func, gpointer data) | |
120 { | |
121 GtkWidget *item = gtk_menu_item_new_with_label(label); | |
122 menu_item_finish(menu, item, func, data); | |
123 | |
124 return item; | |
125 } | |
126 | |
127 /* | |
128 *----------------------------------------------------------------------------- | |
129 * popup menus | |
130 *----------------------------------------------------------------------------- | |
442 | 131 */ |
9 | 132 |
133 static void popup_menu_short_lived_cb(GtkWidget *widget, gpointer data) | |
134 { | |
135 /* destroy the menu */ | |
136 g_object_unref(G_OBJECT(data)); | |
137 } | |
138 | |
139 GtkWidget *popup_menu_short_lived(void) | |
140 { | |
141 GtkWidget *menu; | |
142 | |
143 menu = gtk_menu_new(); | |
88
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
144 |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
145 /* take ownership of menu */ |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
146 #ifdef GTK_OBJECT_FLOATING |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
147 /* GTK+ < 2.10 */ |
9 | 148 g_object_ref(G_OBJECT(menu)); |
149 gtk_object_sink(GTK_OBJECT(menu)); | |
88
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
150 #else |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
151 /* GTK+ >= 2.10 */ |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
152 g_object_ref_sink(G_OBJECT(menu)); |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
153 #endif |
2099ee3f9a8d
Fri Oct 27 19:45:32 2006 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
154 |
9 | 155 g_signal_connect(G_OBJECT(menu), "selection_done", |
156 G_CALLBACK(popup_menu_short_lived_cb), menu); | |
157 return menu; | |
158 } | |
159 | |
1448 | 160 gboolean popup_menu_position_clamp(GtkMenu *menu, gint *x, gint *y, gint height) |
9 | 161 { |
1437 | 162 gboolean adjusted = FALSE; |
9 | 163 gint w, h; |
164 gint xw, xh; | |
442 | 165 |
9 | 166 w = GTK_WIDGET(menu)->requisition.width; |
167 h = GTK_WIDGET(menu)->requisition.height; | |
168 xw = gdk_screen_width(); | |
169 xh = gdk_screen_height(); | |
170 | |
171 if (*x + w > xw) | |
172 { | |
173 *x = xw - w; | |
174 adjusted = TRUE; | |
175 } | |
176 if (*y + h > xh) | |
177 { | |
178 if (height) | |
179 { | |
180 *y = MAX(0, *y - h - height); | |
181 } | |
182 else | |
183 { | |
184 *y = xh - h; | |
185 } | |
186 adjusted = TRUE; | |
187 }; | |
188 | |
189 if (*x < 0) | |
190 { | |
191 *x = 0; | |
192 adjusted = TRUE; | |
193 } | |
194 if (*y < 0) | |
195 { | |
196 *y = 0; | |
197 adjusted = TRUE; | |
198 } | |
199 | |
200 return adjusted; | |
201 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
513
diff
changeset
|
202 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |