The GNOME Panel Libraries | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
When the user right clicks on the applet, a menu appears, this is all handeled by the panel, so in order to add items to it you use a special interface to "add callbacks" to the menu. A very simple example would be (making our hello applet even more feature full):
Example 4. hello_applet with menu items
#include <config.h> #include <applet-widget.h> static void hello_there (AppletWidget *applet, gpointer data) { g_print(_("Hello There")); } int main (int argc, char **argv) { GtkWidget *applet; GtkWidget *label; /* Initialize the i18n stuff */ bindtextdomain (PACKAGE, GNOMELOCALEDIR); textdomain (PACKAGE); /* intialize, this will basically set up the applet, corba and call gnome_init */ applet_widget_init("hello_applet", NULL, argc, argv, NULL, 0, NULL); /* create a new applet_widget */ applet = applet_widget_new("hello_applet"); /* in the rare case that the communication with the panel failed, error out */ if (!applet) g_error("Can't create applet!\n"); /* create the widget we are going to put on the applet */ label = gtk_label_new(_("Hello There!")); gtk_widget_show(label); /* add the widget to the applet-widget, and thereby actually putting it "onto" the panel */ applet_widget_add (APPLET_WIDGET (applet), label); gtk_widget_show (applet); /* add an item to the applet menu */ applet_widget_register_callback(APPLET_WIDGET(applet), "hello", _("Hello There"), hello_there, NULL); /* special corba main loop */ applet_widget_gtk_main (); return 0; } |
Now the user will see a "Hello There" menu item on the applet menu, and when selected, the applet will print "Hello There". Useful huh?
Note that the second argument to the register_callback is just a string identifier of this callback, and can really be whatever you want. But it should NOT be translated as the label (the 3rd argument) should be.