9
|
1 /*
|
|
2 * (SLIK) SimpLIstic sKin functions
|
|
3 * (C) 2004 John Ellis
|
|
4 *
|
|
5 * Author: John Ellis
|
|
6 *
|
|
7 * This software is released under the GNU General Public License (GNU GPL).
|
|
8 * Please read the included file COPYING for more information.
|
|
9 * This software comes with no warranty of any kind, use at your own risk!
|
|
10 */
|
|
11
|
|
12 #ifdef HAVE_CONFIG_H
|
|
13 # include "config.h"
|
|
14 #endif
|
|
15 #include "intl.h"
|
|
16
|
|
17 #include <stdio.h>
|
|
18 #include <stdlib.h>
|
|
19 #include <string.h>
|
|
20
|
|
21 #include <gtk/gtk.h>
|
|
22
|
|
23 #include "ui_menu.h"
|
|
24
|
|
25
|
|
26 /*
|
|
27 *-----------------------------------------------------------------------------
|
|
28 * menu items
|
|
29 *-----------------------------------------------------------------------------
|
|
30 */
|
|
31
|
|
32 static void menu_item_finish(GtkWidget *menu, GtkWidget *item, GCallback func, gpointer data)
|
|
33 {
|
|
34 if (func) g_signal_connect(G_OBJECT(item), "activate", func, data);
|
|
35 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
|
36 gtk_widget_show(item);
|
|
37 }
|
|
38
|
|
39 GtkWidget *menu_item_add(GtkWidget *menu, const gchar *label,
|
|
40 GCallback func, gpointer data)
|
|
41 {
|
|
42 GtkWidget *item;
|
|
43
|
|
44 item = gtk_menu_item_new_with_mnemonic(label);
|
|
45 menu_item_finish(menu, item, func, data);
|
|
46
|
|
47 return item;
|
|
48 }
|
|
49
|
|
50 GtkWidget *menu_item_add_stock(GtkWidget *menu, const gchar *label, const gchar *stock_id,
|
|
51 GCallback func, gpointer data)
|
|
52 {
|
|
53 GtkWidget *item;
|
|
54 GtkWidget *image;
|
|
55
|
|
56 item = gtk_image_menu_item_new_with_mnemonic(label);
|
|
57 image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
|
|
58 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
|
|
59 gtk_widget_show(image);
|
|
60 menu_item_finish(menu, item, func, data);
|
|
61
|
|
62 return item;
|
|
63 }
|
|
64
|
|
65 GtkWidget *menu_item_add_sensitive(GtkWidget *menu, const gchar *label, gint sensitive,
|
|
66 GCallback func, gpointer data)
|
|
67 {
|
|
68 GtkWidget *item;
|
|
69
|
|
70 item = menu_item_add(menu, label, func, data);
|
|
71 gtk_widget_set_sensitive(item, sensitive);
|
|
72
|
|
73 return item;
|
|
74 }
|
|
75
|
|
76 GtkWidget *menu_item_add_stock_sensitive(GtkWidget *menu, const gchar *label, const gchar *stock_id, gint sensitive,
|
|
77 GCallback func, gpointer data)
|
|
78 {
|
|
79 GtkWidget *item;
|
|
80
|
|
81 item = menu_item_add_stock(menu, label, stock_id, func, data);
|
|
82 gtk_widget_set_sensitive(item, sensitive);
|
|
83
|
|
84 return item;
|
|
85 }
|
|
86
|
|
87 GtkWidget *menu_item_add_check(GtkWidget *menu, const gchar *label, gint active,
|
|
88 GCallback func, gpointer data)
|
|
89 {
|
|
90 GtkWidget *item;
|
|
91
|
|
92 item = gtk_check_menu_item_new_with_mnemonic(label);
|
|
93 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), active);
|
|
94 menu_item_finish(menu, item, func, data);
|
|
95
|
|
96 return item;
|
|
97 }
|
|
98
|
|
99 void menu_item_add_divider(GtkWidget *menu)
|
|
100 {
|
|
101 GtkWidget *item = gtk_menu_item_new();
|
|
102 gtk_widget_set_sensitive(item, FALSE);
|
|
103 gtk_menu_shell_append(GTK_MENU_SHELL(menu),item);
|
|
104 gtk_widget_show(item);
|
|
105 }
|
|
106
|
|
107 GtkWidget *menu_item_add_simple(GtkWidget *menu, const gchar *label,
|
|
108 GCallback func, gpointer data)
|
|
109 {
|
|
110 GtkWidget *item = gtk_menu_item_new_with_label(label);
|
|
111 menu_item_finish(menu, item, func, data);
|
|
112
|
|
113 return item;
|
|
114 }
|
|
115
|
|
116 /*
|
|
117 *-----------------------------------------------------------------------------
|
|
118 * popup menus
|
|
119 *-----------------------------------------------------------------------------
|
|
120 */
|
|
121
|
|
122 static void popup_menu_short_lived_cb(GtkWidget *widget, gpointer data)
|
|
123 {
|
|
124 /* destroy the menu */
|
|
125 g_object_unref(G_OBJECT(data));
|
|
126 }
|
|
127
|
|
128 GtkWidget *popup_menu_short_lived(void)
|
|
129 {
|
|
130 GtkWidget *menu;
|
|
131
|
|
132 menu = gtk_menu_new();
|
|
133 g_object_ref(G_OBJECT(menu));
|
|
134 gtk_object_sink(GTK_OBJECT(menu));
|
|
135 g_signal_connect(G_OBJECT(menu), "selection_done",
|
|
136 G_CALLBACK(popup_menu_short_lived_cb), menu);
|
|
137 return menu;
|
|
138 }
|
|
139
|
|
140 gint popup_menu_position_clamp(GtkMenu *menu, gint *x, gint *y, gint height)
|
|
141 {
|
|
142 gint adjusted = FALSE;
|
|
143 gint w, h;
|
|
144 gint xw, xh;
|
|
145
|
|
146 w = GTK_WIDGET(menu)->requisition.width;
|
|
147 h = GTK_WIDGET(menu)->requisition.height;
|
|
148 xw = gdk_screen_width();
|
|
149 xh = gdk_screen_height();
|
|
150
|
|
151 if (*x + w > xw)
|
|
152 {
|
|
153 *x = xw - w;
|
|
154 adjusted = TRUE;
|
|
155 }
|
|
156 if (*y + h > xh)
|
|
157 {
|
|
158 if (height)
|
|
159 {
|
|
160 *y = MAX(0, *y - h - height);
|
|
161 }
|
|
162 else
|
|
163 {
|
|
164 *y = xh - h;
|
|
165 }
|
|
166 adjusted = TRUE;
|
|
167 };
|
|
168
|
|
169 if (*x < 0)
|
|
170 {
|
|
171 *x = 0;
|
|
172 adjusted = TRUE;
|
|
173 }
|
|
174 if (*y < 0)
|
|
175 {
|
|
176 *y = 0;
|
|
177 adjusted = TRUE;
|
|
178 }
|
|
179
|
|
180 return adjusted;
|
|
181 }
|
|
182
|