2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <gtk/gtkwidget.h>
26 #include <gtk/gtkmenu.h>
27 #include <gtk/gtkmenubar.h>
28 #include <gtk/gtkitemfactory.h>
29 #include <gtk/gtkcheckmenuitem.h>
30 #include <gtk/gtkbutton.h>
36 static gchar
*menu_translate(const gchar
*path
, gpointer data
);
38 GtkWidget
*menubar_create(GtkWidget
*window
, GtkItemFactoryEntry
*entries
,
39 guint n_entries
, const gchar
*path
, gpointer data
)
41 GtkItemFactory
*factory
;
42 GtkAccelGroup
*accel_group
;
44 accel_group
= gtk_accel_group_new();
45 factory
= gtk_item_factory_new(GTK_TYPE_MENU_BAR
, path
, accel_group
);
46 gtk_item_factory_set_translate_func(factory
, menu_translate
,
48 gtk_item_factory_create_items(factory
, n_entries
, entries
, data
);
49 gtk_accel_group_attach(accel_group
, GTK_OBJECT(window
));
51 return gtk_item_factory_get_widget(factory
, path
);
54 GtkWidget
*menu_create_items(GtkItemFactoryEntry
*entries
,
55 guint n_entries
, const gchar
*path
,
56 GtkItemFactory
**factory
, gpointer data
)
58 *factory
= gtk_item_factory_new(GTK_TYPE_MENU
, path
, NULL
);
59 gtk_item_factory_set_translate_func(*factory
, menu_translate
,
61 gtk_item_factory_create_items(*factory
, n_entries
, entries
, data
);
63 return gtk_item_factory_get_widget(*factory
, path
);
66 static gchar
*menu_translate(const gchar
*path
, gpointer data
)
70 retval
= gettext(path
);
75 void menu_set_sensitive(GtkItemFactory
*ifactory
, const gchar
*path
,
80 g_return_if_fail(ifactory
!= NULL
);
82 widget
= gtk_item_factory_get_item(ifactory
, path
);
83 gtk_widget_set_sensitive(widget
, sensitive
);
86 void menu_set_insensitive_all(GtkMenuShell
*menu_shell
)
90 for (cur
= menu_shell
->children
; cur
!= NULL
; cur
= cur
->next
)
91 gtk_widget_set_sensitive(GTK_WIDGET(cur
->data
), FALSE
);
94 void menu_set_toggle(GtkItemFactory
*ifactory
, const gchar
*path
,
99 g_return_if_fail(ifactory
!= NULL
);
101 widget
= gtk_item_factory_get_item(ifactory
, path
);
102 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(widget
), active
);
105 void menu_button_position(GtkMenu
*menu
, gint
*x
, gint
*y
, gpointer user_data
)
108 GtkRequisition requisition
;
109 gint button_xpos
, button_ypos
;
112 gint scr_width
, scr_height
;
114 g_return_if_fail(user_data
!= NULL
);
115 g_return_if_fail(GTK_IS_BUTTON(user_data
));
117 button
= GTK_WIDGET(user_data
);
119 gtk_widget_get_child_requisition(GTK_WIDGET(menu
), &requisition
);
120 width
= requisition
.width
;
121 height
= requisition
.height
;
122 gdk_window_get_origin(button
->window
, &button_xpos
, &button_ypos
);
125 ypos
= button_ypos
+ button
->allocation
.height
;
127 scr_width
= gdk_screen_width();
128 scr_height
= gdk_screen_height();
130 if (xpos
+ width
> scr_width
)
131 xpos
-= (xpos
+ width
) - scr_width
;
132 if (ypos
+ height
> scr_height
)
133 ypos
= button_ypos
- height
;