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

Permit stock menu items on the applet menus

Sun Jun 07 18:33:56 1998  George Lebl  <jirka@5z.com>

        * gnome-panel.idl,mico-glue.cc,applet-lib.(cc|h),applet-widget.c[ch],
          panel.c: Permit stock menu items on the applet menus
parent 88325a7e
......@@ -134,6 +134,49 @@ 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.
Advanced Menu Stuff:
====================
It is also possible to have submenus, remove menus and use
gnome-stock icons on the menus.
Submenus:
To do submenus, you have to first call applet_widget_register_callback_dir,
which only takes the callback name and the menu text. The callback name should
end with '/'. The callback name works as a "path" for the submenus.
So to add a submenu "Foo" and in item "Bar" (into the submenu "Foo")
you would do
applet_widget_register_callback_dir(APPLET_WIDGET(applet),
"foo/",
_("Foo"));
applet_widget_register_callback(APPLET_WIDGET(applet),
"foo/bar",
_("Bar"),
bar_callback,
NULL);
Deleting:
To delete a menu item, just call applet_widget_unregister_callback or
applet_widget_unregister_callback_dir, with the proper callback name.
Stock Icons:
You use the _stock derivatives of the callback functions and pass an
extra argument with the GNOME_STOCK_MENU_* type. For example to add an
about menu item:
applet_widget_register_stock_callback(APPLET_WIDGET(applet),
"about",
GNOME_STOCK_MENU_ABOUT,
_("About..."),
about_cb,
NULL);
Session Saving:
===============
......
Sun Jun 07 18:33:56 1998 George Lebl <jirka@5z.com>
* gnome-panel.idl,mico-glue.cc,applet-lib.(cc|h),applet-widget.c[ch],
panel.c: Permit stock menu items on the applet menus
Sun Jun 07 00:23:16 1998 George Lebl <jirka@5z.com>
* *.[ch]: cleaned up compilation with -Wall
......
Sun Jun 07 18:33:56 1998 George Lebl <jirka@5z.com>
* gnome-panel.idl,mico-glue.cc,applet-lib.(cc|h),applet-widget.c[ch],
panel.c: Permit stock menu items on the applet menus
Sun Jun 07 00:23:16 1998 George Lebl <jirka@5z.com>
* *.[ch]: cleaned up compilation with -Wall
......
......@@ -4,7 +4,9 @@
AUTOMAKE_OPTIONS = 1.2f
#enable swallows for testing only, not for release!
#CFLAGS += -D_SWALLOW_
#(it's after 0.20 so I guess swallows can be enabled,
#maybe someone will fix it up)
CFLAGS += -D_SWALLOW_
CFLAGS += -D_DRAWER_
CXX = mico-c++
......
......@@ -232,6 +232,7 @@ make_sane_name(gchar *name)
void
gnome_panel_applet_register_callback(int applet_id,
char *name,
char *stock_item,
char *menutext,
AppletCallbackFunc func,
gpointer data)
......@@ -255,7 +256,8 @@ gnome_panel_applet_register_callback(int applet_id,
info->data = data;
/*register the callback with the panel*/
panel_client->applet_add_callback(cookie,applet_id,name,menutext);
panel_client->applet_add_callback(cookie,applet_id,name,
stock_item,menutext);
}
/*removes a callback from the callback hash*/
......@@ -275,6 +277,7 @@ gnome_panel_applet_unregister_callback(int applet_id,
void
gnome_panel_applet_register_callback_dir(int applet_id,
char *name,
char *stock_item,
char *menutext)
{
gchar *n;
......@@ -287,7 +290,7 @@ gnome_panel_applet_register_callback_dir(int applet_id,
else
n = g_strdup(name);
/*unregister the dir with the panel*/
panel_client->applet_add_callback(cookie,applet_id,n,menutext);
panel_client->applet_add_callback(cookie,applet_id,n,stock_item,menutext);
g_free(n);
}
......
......@@ -30,12 +30,14 @@ int gnome_panel_applet_init_corba (void);
int gnome_panel_applet_reinit_corba (void);
void gnome_panel_applet_register_callback (gint applet_id,
char *name,
char *stock_item,
char *menutext,
AppletCallbackFunc func,
gpointer data);
void gnome_panel_applet_unregister_callback(int applet_id, char *name);
void gnome_panel_applet_register_callback_dir (gint applet_id,
char *name,
char *stock_item,
char *menutext);
void gnome_panel_applet_unregister_callback_dir(int applet_id, char *name);
......
......@@ -238,30 +238,53 @@ applet_widget_sync_config(void)
void
applet_widget_register_callback(AppletWidget *applet,
char *name,
char *menutext,
gchar *name,
gchar *menutext,
AppletCallbackFunc func,
gpointer data)
{
gnome_panel_applet_register_callback (applet->applet_id,name,
menutext,func,data);
"",menutext,func,data);
}
void
applet_widget_register_stock_callback(AppletWidget *applet,
gchar *name,
gchar *stock_type,
gchar *menutext,
AppletCallbackFunc func,
gpointer data)
{
gnome_panel_applet_register_callback (applet->applet_id,name,
stock_type,menutext,func,data);
}
void
applet_widget_unregister_callback(AppletWidget *applet,
char *name)
gchar *name)
{
gnome_panel_applet_unregister_callback (applet->applet_id,name);
}
void
applet_widget_register_callback_dir(AppletWidget *applet, char *name, char *menutext)
applet_widget_register_callback_dir(AppletWidget *applet,
gchar *name,
gchar *menutext)
{
gnome_panel_applet_register_callback_dir (applet->applet_id,name,
"",menutext);
}
void
applet_widget_register_stock_callback_dir(AppletWidget *applet,
gchar *name,
gchar *stock_type,
gchar *menutext)
{
gnome_panel_applet_register_callback_dir (applet->applet_id,name,menutext);
gnome_panel_applet_register_callback_dir (applet->applet_id,name,
stock_type,menutext);
}
void
applet_widget_unregister_callback_dir(AppletWidget *applet, char *name)
applet_widget_unregister_callback_dir(AppletWidget *applet, gchar *name)
{
gnome_panel_applet_unregister_callback_dir (applet->applet_id,name);
}
......
......@@ -122,16 +122,26 @@ void applet_widget_register_callback (AppletWidget *applet,
gchar *menutext,
AppletCallbackFunc func,
gpointer data);
void applet_widget_register_stock_callback (AppletWidget *applet,
gchar *name,
gchar *stock_type,
gchar *menutext,
AppletCallbackFunc func,
gpointer data);
/*remove a menuitem*/
void applet_widget_unregister_callback (AppletWidget *applet,
gchar *name);
/*add a submenu*/
void applet_widget_register_callback_dir (AppletWidget *applet,
char *name,
char *menutext);
gchar *name,
gchar *menutext);
void applet_widget_register_stock_callback_dir (AppletWidget *applet,
gchar *name,
gchar *stock_type,
gchar *menutext);
/*remove a submenu*/
void applet_widget_unregister_callback_dir (AppletWidget *applet,
char *name);
gchar *name);
/* get the applet widget with the id of applet_id */
......
......@@ -35,6 +35,7 @@ module GNOME {
void applet_add_callback (in string cookie,
in short applet_id,
in string callback_name,
in string stock_item,
in string menuitem_text);
void applet_remove_callback (in string cookie,
in short applet_id,
......
......@@ -428,6 +428,7 @@ load_applet(gchar *id_str, gchar *path, gchar *params,
launcher->dentry->comment,NULL);
applet_add_callback(applet_count-1,"properties",
GNOME_STOCK_MENU_PROP,
_("Properties..."));
} else if(strcmp(id_str,DRAWER_ID) == 0) {
Drawer *drawer;
......
......@@ -104,10 +104,12 @@ public:
void applet_add_callback (const char *ccookie,
CORBA::Short applet_id,
const char *callback_name,
const char *stock_item,
const char *menuitem_text) {
CHECK_COOKIE ();
::applet_add_callback(applet_id,
(char *)callback_name,
(char *)stock_item,
(char *)menuitem_text);
}
void applet_remove_callback (const char *ccookie,
......
......@@ -538,6 +538,8 @@ panel_clean_applet(gint applet_id)
AppletUserMenu *umenu = info->user_menu->data;
if(umenu->name)
g_free(umenu->name);
if(umenu->stock_item)
g_free(umenu->stock_item);
if(umenu->text)
g_free(umenu->text);
g_free(umenu);
......@@ -593,7 +595,10 @@ applet_get_callback(GList *user_menu, gchar *name)
}
void
applet_add_callback(gint applet_id, char *callback_name, char *menuitem_text)
applet_add_callback(gint applet_id,
char *callback_name,
char *stock_item,
char *menuitem_text)
{
AppletUserMenu *menu;
AppletInfo *info = get_applet_info(applet_id);
......@@ -603,15 +608,19 @@ applet_add_callback(gint applet_id, char *callback_name, char *menuitem_text)
if((menu=applet_get_callback(info->user_menu,callback_name))==NULL) {
menu = g_new(AppletUserMenu,1);
menu->name = g_strdup(callback_name);
menu->stock_item = g_strdup(stock_item);
menu->text = g_strdup(menuitem_text);
menu->applet_id = applet_id;
menu->menuitem = NULL;
menu->submenu = NULL;
info->user_menu = g_list_append(info->user_menu,menu);
} else {
if(menu->stock_item)
g_free(menu->stock_item);
if(menu->text)
g_free(menu->text);
menu->text = g_strdup(menuitem_text);
menu->stock_item = g_strdup(stock_item);
}
/*make sure the menu is rebuilt*/
......@@ -639,6 +648,8 @@ applet_remove_callback(gint applet_id, char *callback_name)
info->user_menu = g_list_remove(info->user_menu,menu);
if(menu->name)
g_free(menu->name);
if(menu->stock_item)
g_free(menu->stock_item);
if(menu->text)
g_free(menu->text);
g_free(menu);
......@@ -684,7 +695,11 @@ add_to_submenus(gint applet_id,char *path,char *name, AppletUserMenu *menu, GtkW
p==(n + strlen(n) - 1)) {
g_free(n);
menu->menuitem = gtk_menu_item_new_with_label(menu->text);
if(menu->stock_item && *(menu->stock_item))
menu->menuitem = gnome_stock_menu_item(menu->stock_item,
menu->text);
else
menu->menuitem = gtk_menu_item_new_with_label(menu->text);
gtk_widget_show(menu->menuitem);
if(menu->submenu)
gtk_menu_item_set_submenu (GTK_MENU_ITEM(menu->menuitem), menu->submenu);
......@@ -715,6 +730,7 @@ add_to_submenus(gint applet_id,char *path,char *name, AppletUserMenu *menu, GtkW
s_menu = g_new(AppletUserMenu,1);
s_menu->name = g_strdup(t);
s_menu->text = g_strdup(_("???"));
s_menu->stock_item = NULL;
s_menu->applet_id = applet_id;
s_menu->menuitem = NULL;
s_menu->submenu = NULL;
......@@ -762,7 +778,8 @@ create_applet_menu(AppletInfo *info)
for(;user_menu!=NULL;user_menu = g_list_next(user_menu)) {
AppletUserMenu *menu=user_menu->data;
add_to_submenus(info->applet_id,"",menu->name,menu,info->menu,info->user_menu);
add_to_submenus(info->applet_id,"",menu->name,menu,info->menu,
info->user_menu);
}
/*connect the deactivate signal, so that we can "re-allow" autohide
......
......@@ -53,6 +53,7 @@ typedef struct _AppletInfo AppletInfo;
struct _AppletUserMenu {
gchar *name;
gchar *stock_item;
gchar *text;
gint applet_id;
GtkWidget *menuitem;
......@@ -129,6 +130,7 @@ void applet_drag_start(gint applet_id);
void applet_drag_stop(gint applet_id);
void applet_add_callback(gint applet_id,
char *callback_name,
char *stock_item,
char *menuitem_text);
void applet_remove_callback(gint applet_id,
char *callback_name);
......
......@@ -35,6 +35,7 @@ module GNOME {
void applet_add_callback (in string cookie,
in short applet_id,
in string callback_name,
in string stock_item,
in string menuitem_text);
void applet_remove_callback (in string cookie,
in short applet_id,
......
......@@ -35,6 +35,7 @@ module GNOME {
void applet_add_callback (in string cookie,
in short applet_id,
in string callback_name,
in string stock_item,
in string menuitem_text);
void applet_remove_callback (in string cookie,
in short applet_id,
......
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