Re: [gtk-list] Re: enter_notify_event and leave_notify_event onmenus?




On Tue, 20 Apr 1999, Federico Mena Quintero wrote:
> 
> Use the "select" and "deselect" signals from GtkItem (which is the
> parent class of GtkMenuItem) when you want to update the status bar.
> 
> Of course, if you were using the Gnome libraries, all of this would be
> handled automagically for you :-)
> 

If you insist on not using them, at least cut-and-paste the code!

:-)

Havoc

Here's the relevant code, I already cut-and-pasted it into Guppi to use
with a non-gnome-app-helper menu. You'll probably want to change it to use
GtkStatusbar or whatever your statusbar is. (GtkStatusbar variant is in
gnome-libs/libgnomeui/gnome-app.c)

/* Callback to display hint in the statusbar when a menu item is 
 * activated. For GnomeAppBar.
 */

static void
put_hint_in_appbar(GtkWidget* menuitem, gpointer data)
{
  gchar* hint =(char*)gtk_object_get_data (GTK_OBJECT(menuitem),
                                           "guppi_appbar_hint");
  GtkWidget* bar = (GtkWidget*)data;

  g_return_if_fail (hint != NULL);
  g_return_if_fail (bar != NULL);
  g_return_if_fail (GNOME_IS_APPBAR(bar));

  gnome_appbar_set_status (GNOME_APPBAR(bar), hint);
}

/* Callback to remove hint when the menu item is deactivated.
 * For GnomeAppBar.
 */
static void
remove_hint_from_appbar(GtkWidget* menuitem, gpointer data)
{
  GtkWidget* bar = (GtkWidget*)data;

  g_return_if_fail (bar != NULL);
  g_return_if_fail (GNOME_IS_APPBAR(bar));

  gnome_appbar_refresh (GNOME_APPBAR(bar));
}

/* Install a hint for a menu item
 */
void
guppi_install_menuitem_hint(GtkWidget* menuitem, GnomeAppBar* bar, 
                            const string& hint)
{
  /* This is mildly fragile; if someone destroys the appbar
     but not the menu, chaos will ensue. */

  gtk_object_set_data_full (GTK_OBJECT(menuitem),
                            "guppi_appbar_hint",
                            g_strdup(hint.c_str()),
                            g_free);
  
  gtk_signal_connect (GTK_OBJECT (menuitem),
                      "select",
                      GTK_SIGNAL_FUNC(put_hint_in_appbar),
                      bar);
  
  gtk_signal_connect (GTK_OBJECT (menuitem),
                      "deselect",
                      GTK_SIGNAL_FUNC(remove_hint_from_appbar),
                      bar);
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]