Commit c2a10b6a authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

reposition menu after hiding an item

Wed Dec 12 12:47:38 2001  George Lebl <jirka@5z.com>

	* foobar-widget.c: reposition menu after hiding an item

	* menu.[ch]: the keys for icons and tearoffs are now defined in the
	  menu.h as a define.  Also setup keys on the menu to display
	  the current state of the icons/tearoffs key at the time the menu
	  was created so that we can recreate it if it changes.  Doesn't yet
	  work everywhere, only for menus that use check_reread

	* panel-gconf.[ch]: notify_add returns an id, and add a _while_alive
	  version as well
parent f0c41103
Wed Dec 12 12:47:38 2001 George Lebl <jirka@5z.com>
* foobar-widget.c: reposition menu after hiding an item
* menu.[ch]: the keys for icons and tearoffs are now defined in the
menu.h as a define. Also setup keys on the menu to display
the current state of the icons/tearoffs key at the time the menu
was created so that we can recreate it if it changes. Doesn't yet
work everywhere, only for menus that use check_reread
* panel-gconf.[ch]: notify_add returns an id, and add a _while_alive
version as well
2001-12-12 Mark McLoughlin <mark@skynet.ie>
Bit of renaming for Glynn.
......
......@@ -896,6 +896,7 @@ window_closed (WnckScreen *screen,
if (item != NULL) {
g_hash_table_remove (foo->windows, window);
gtk_widget_hide (item);
gtk_menu_reposition (GTK_MENU (item->parent));
} else {
g_warning ("Could not find item for task '%s'",
sure_string (wnck_window_get_name (window)));
......
......@@ -183,7 +183,7 @@ panel_menu_have_icons (void)
if (!notify_id) {
GConfClient *client = panel_gconf_get_client ();
gchar *key = "/desktop/gnome/interface/menus-have-icons";
gchar *key = PANEL_MENU_HAVE_ICONS_KEY;
GError *error = NULL;
notify_id = gconf_client_notify_add (client, key,
......@@ -218,7 +218,7 @@ panel_menu_have_tearoff (void)
if (!notify_id) {
GConfClient *client = panel_gconf_get_client ();
gchar *key = "/desktop/gnome/interface/menus-have-tearoff";
gchar *key = PANEL_MENU_HAVE_TEAROFF_KEY;
GError *error = NULL;
notify_id = gconf_client_notify_add (client, key,
......@@ -1912,6 +1912,34 @@ menu_destroy(GtkWidget *menu, gpointer data)
gtk_object_set_data (GTK_OBJECT (menu), "mf", NULL);
}
static void
setup_menu_with_current_setting_state (GtkWidget *menu)
{
g_object_set_data (G_OBJECT (menu),
"MenusHaveIcons",
GINT_TO_POINTER (panel_menu_have_icons ()));
g_object_set_data (G_OBJECT (menu),
"MenusHaveTearoffs",
GINT_TO_POINTER (panel_menu_have_tearoff ()));
}
static gboolean
check_menu_against_current_setting_state (GtkWidget *menu)
{
gboolean icons = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu),
"MenusHaveIcons"));
gboolean tearoffs = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu),
"MenusHaveTearoffs"));
if ((icons && panel_menu_have_icons ()) ||
( ! icons && ! panel_menu_have_icons ()) ||
(tearoffs && panel_menu_have_tearoff ()) ||
( ! tearoffs && ! panel_menu_have_tearoff ()))
/* state is OK */
return TRUE;
else
return FALSE; /* reread! perhaps too drastic, well whatever */
}
/*reread the applet menu, not a submenu*/
static void
check_and_reread_applet (Menu *menu)
......@@ -2201,6 +2229,7 @@ tearoff_new_menu(GtkWidget *item, GtkWidget *menuw)
return;
menu = menu_new();
setup_menu_with_current_setting_state (menu);
menu_panel = get_panel_from_menu_data(menuw, TRUE);
......@@ -2292,9 +2321,13 @@ menu_need_reread(GtkWidget *menuw)
/*if(!mfl)
g_warning("Weird menu doesn't have mf entry");*/
/* FIXME: figure out how to update tornoff menus */
if (GTK_MENU(menuw)->torn_off)
return FALSE;
if ( ! check_menu_against_current_setting_state (menuw))
return TRUE;
if (gtk_object_get_data(GTK_OBJECT(menuw), "need_reread")) {
need_reread = TRUE;
gtk_object_remove_data(GTK_OBJECT(menuw), "need_reread");
......@@ -2390,6 +2423,7 @@ create_fake_menu_at (const char *menudir,
GSList *list;
menu = menu_new ();
setup_menu_with_current_setting_state (menu);
mf = g_new0 (MenuFinfo, 1);
mf->menudir = g_strdup (menudir);
......@@ -2607,6 +2641,8 @@ create_menu_at_fr (GtkWidget *menu,
TEAROFF_IS_ITEM(GTK_MENU_SHELL(menu)->children->data)))
add_separator = TRUE;
}
setup_menu_with_current_setting_state (menu);
if (fr != NULL) {
/* Last added points to the last fr list item that was successfuly
......@@ -2800,6 +2836,7 @@ create_applets_menu ()
}
menu = menu_new ();
setup_menu_with_current_setting_state (menu);
menu_add_tearoff (GTK_MENU (menu), G_CALLBACK (tearoff_new_menu), menu);
......@@ -2834,6 +2871,7 @@ create_applets_menu ()
prev_category = category;
prev_menu = menu_new ();
setup_menu_with_current_setting_state (prev_menu);
cat_icon = applet_menu_get_category_icon (category);
......@@ -3112,6 +3150,8 @@ create_add_panel_submenu (gboolean tearoff)
GtkWidget *menu, *menuitem;
menu = menu_new ();
/* FIXME: this probably doesn't do us any good */
setup_menu_with_current_setting_state (menu);
if (tearoff)
menu_add_tearoff (GTK_MENU (menu),
......@@ -3276,6 +3316,7 @@ create_add_launcher_menu (GtkWidget *menu, gboolean fake_submenus)
{
if (menu == NULL)
menu = menu_new ();
setup_menu_with_current_setting_state (menu);
/* Eeeek, a hack, if this is set then the reloading
* function will use create_add_launcher_menu, rather then
......@@ -3602,6 +3643,9 @@ make_add_submenu (GtkWidget *menu, gboolean fake_submenus)
/* Add Menu */
/* FIXME: probably does us no good */
setup_menu_with_current_setting_state (menu);
m = create_applets_menu(NULL, fake_submenus, TRUE);
if (m) {
menuitem = gtk_image_menu_item_new ();
......@@ -3614,6 +3658,8 @@ make_add_submenu (GtkWidget *menu, gboolean fake_submenus)
g_signal_connect (G_OBJECT (m), "show",
G_CALLBACK (submenu_to_display),
NULL);
setup_menu_with_current_setting_state (m);
}
menuitem = gtk_image_menu_item_new ();
......@@ -3623,6 +3669,8 @@ make_add_submenu (GtkWidget *menu, gboolean fake_submenus)
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
submenu = menu_new ();
/* FIXME: probably does us no good */
setup_menu_with_current_setting_state (submenu);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
submenuitem = gtk_image_menu_item_new ();
......@@ -3822,6 +3870,8 @@ make_panel_submenu (GtkWidget *menu, gboolean fake_submenus, gboolean is_basep)
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
submenu = menu_new ();
/* FIXME: probably does us no good */
setup_menu_with_current_setting_state (submenu);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem),
submenu);
......@@ -3988,6 +4038,9 @@ create_panel_submenu(GtkWidget *menu, gboolean fake_submenus, gboolean tearoff,
menu = menu_new();
}
/* FIXME: probably does us no good */
setup_menu_with_current_setting_state (menu);
menu_add_tearoff (GTK_MENU (menu),
G_CALLBACK (panel_menu_tearoff_new_menu),
NULL);
......@@ -4038,6 +4091,9 @@ create_desktop_menu (GtkWidget *menu, gboolean fake_submenus, gboolean tearoff)
menu = menu_new ();
}
/* FIXME: probably does us no good */
setup_menu_with_current_setting_state (menu);
if (tearoff)
menu_add_tearoff (GTK_MENU (menu),
G_CALLBACK (desktop_menu_tearoff_new_menu),
......@@ -4162,10 +4218,11 @@ create_root_menu (GtkWidget *root_menu,
has_subs |= (flags & (MAIN_MENU_DISTRIBUTION_SUB));
}
if(!root_menu)
root_menu = menu_new ();
setup_menu_with_current_setting_state (root_menu);
if (tearoff)
menu_add_tearoff (GTK_MENU (root_menu),
G_CALLBACK (panel_tearoff_new_menu),
......
......@@ -121,7 +121,9 @@ enum {
HIDEBUTTONS_NONE
};
#define PANEL_MENU_HAVE_ICONS_KEY "/desktop/gnome/interface/menus-have-icons"
gboolean panel_menu_have_icons (void);
#define PANEL_MENU_HAVE_TEAROFF_KEY "/desktop/gnome/interface/menus-have-tearoff"
gboolean panel_menu_have_tearoff (void);
......
......@@ -149,15 +149,49 @@ panel_gconf_global_config_set_string (const gchar *key, const gchar *value) {
return;
}
void
guint
panel_gconf_notify_add (const gchar *key, GConfClientNotifyFunc notify_func, gpointer user_data) {
gconf_client_notify_add (panel_gconf_get_client (),
key,
notify_func,
user_data,
NULL,
NULL);
return;
guint notify_id;
notify_id = gconf_client_notify_add (panel_gconf_get_client (),
key,
notify_func,
user_data,
NULL,
NULL);
return notify_id;
}
static void
panel_notify_object_dead (gpointer data)
{
guint notify_id = GPOINTER_TO_UINT (data);
gconf_client_notify_remove (panel_gconf_get_client (),
notify_id);
}
guint
panel_gconf_notify_add_while_alive (const gchar *key,
GConfClientNotifyFunc notify_func,
GObject *alive_object)
{
guint notify_id;
g_return_val_if_fail (G_IS_OBJECT (alive_object), 0);
notify_id = panel_gconf_notify_add (key, notify_func, alive_object);
if (notify_id > 0) {
static int cookie = 0;
char *str;
/* eek a hack, we want a unique key each time,
* how else do we hook into the destruction of an object?? */
str = g_strdup_printf ("PanelGConfNotify-%d", cookie++);
g_object_set_data_full (alive_object,
str,
GUINT_TO_POINTER (notify_id),
panel_notify_object_dead);
g_free (str);
}
return notify_id;
}
void
......
......@@ -23,9 +23,12 @@ void panel_gconf_global_config_set_bool (const gchar *key,
void panel_gconf_global_config_set_string (const gchar *key,
const gchar *value);
void panel_gconf_notify_add (const gchar *key,
guint panel_gconf_notify_add (const gchar *key,
GConfClientNotifyFunc notify_func,
gpointer user_data);
guint panel_gconf_notify_add_while_alive (const gchar *key,
GConfClientNotifyFunc notify_func,
GObject *alive_object);
void panel_gconf_add_dir (const gchar *key);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment