1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2003 Ximian, Inc. (www.ximian.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 #include "menu-utils.h"
36 make_item (GtkMenu
*menu
, GtkMenuItem
*item
, const char *name
, GtkWidget
*pixmap
)
44 * Ugh. This needs to go into Gtk+
46 label
= gtk_label_new_with_mnemonic (name
);
47 gtk_misc_set_alignment (GTK_MISC (label
), 0.0, 0.5);
48 gtk_widget_show (label
);
50 gtk_container_add (GTK_CONTAINER (item
), label
);
52 if (pixmap
&& GTK_IS_IMAGE_MENU_ITEM (item
)){
53 gtk_widget_show (pixmap
);
54 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), pixmap
);
60 menu_utils_construct_menu (GtkWidget
*menu
, struct _MenuItem
*items
, guint32 disable_mask
, void *user_data
)
62 GtkWidget
*item
, *image
;
66 for (i
= 0; items
[i
].label
; i
++) {
67 const char *label
, *stock_id
;
69 label
= items
[i
].label
;
70 stock_id
= items
[i
].stock_id
;
72 if (items
[i
].is_stock
) {
73 item
= gtk_image_menu_item_new_with_mnemonic (label
);
74 image
= gtk_image_new_from_stock (stock_id
, GTK_ICON_SIZE_MENU
);
75 gtk_widget_show (image
);
77 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
78 /*item = gtk_image_menu_item_new_from_stock (stock_id, NULL);*/
79 } else if (strcmp (label
, "") != 0) {
80 if (items
[i
].is_toggle
)
81 item
= gtk_check_menu_item_new_with_mnemonic (label
);
82 else if (items
[i
].is_radio
)
83 item
= gtk_radio_menu_item_new_with_mnemonic (group
, label
);
84 else if (items
[i
].stock_id
)
85 item
= gtk_image_menu_item_new_with_mnemonic (label
);
87 item
= gtk_menu_item_new_with_mnemonic (label
);
89 if (items
[i
].is_toggle
|| items
[i
].is_radio
)
90 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item
), items
[i
].is_active
);
91 if (items
[i
].is_radio
)
92 group
= gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item
));
93 if (items
[i
].stock_id
) {
94 if (stock_id
[0] != '/')
95 image
= gtk_image_new_from_stock (stock_id
, GTK_ICON_SIZE_MENU
);
97 image
= gtk_image_new_from_file (stock_id
);
99 gtk_widget_show (image
);
100 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item
), image
);
103 item
= gtk_separator_menu_item_new ();
106 if (items
[i
].callback
)
107 g_signal_connect (item
, "activate", items
[i
].callback
, user_data
);
108 else if (strcmp (label
, "") != 0) {
109 /* unimplemented menu item? */
110 gtk_widget_set_sensitive (item
, FALSE
);
113 if (items
[i
].disable_mask
& disable_mask
)
114 gtk_widget_set_sensitive (item
, FALSE
);
116 gtk_widget_show (item
);
117 gtk_menu_shell_append (GTK_MENU_SHELL (menu
), item
);