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

fix #9

Wed Jun 03 03:13:44 1998  George Lebl  <jirka@5z.com>

        * panel-widget.c: fix #9

        * panel.c,mico-glue.cc,gnome-panel.idl,applet-lib.(cc|h),
          applet-widget.[ch]: more flexible menu handeling, but
          it doesn't break backwards compatibility, it allows for
          submenus, and menu destruction.
parent d3bdd67d
Wed Jun 03 03:13:44 1998 George Lebl <jirka@5z.com>
* panel-widget.c: fix #9
* panel.c,mico-glue.cc,gnome-panel.idl,applet-lib.(cc|h),
applet-widget.[ch]: more flexible menu handeling, but
it doesn't break backwards compatibility, it allows for
submenus, and menu destruction.
Tue Jun 02 01:39:30 1998 George Lebl <jirka@5z.com>
* panel_config.c: fixed up the fit to panel selection
......
Wed Jun 03 03:13:44 1998 George Lebl <jirka@5z.com>
* panel-widget.c: fix #9
* panel.c,mico-glue.cc,gnome-panel.idl,applet-lib.(cc|h),
applet-widget.[ch]: more flexible menu handeling, but
it doesn't break backwards compatibility, it allows for
submenus, and menu destruction.
Tue Jun 02 01:39:30 1998 George Lebl <jirka@5z.com>
* panel_config.c: fixed up the fit to panel selection
......
......@@ -176,6 +176,30 @@ gnome_panel_applet_reinit_corba (void)
return 1;
}
static CallbackInfo *
get_callback_info(gchar *name)
{
GList *list;
for(list=applet_callbacks;list!=NULL;list=g_list_next(list)) {
CallbackInfo *info = (CallbackInfo *)list->data;
if(strcmp(name,info->name)==0)
return info;
}
return NULL;
}
static gchar*
make_sane_name(gchar *name)
{
if(!name)
return NULL;
while(*name=='/')
name++;
if(*name)
return name;
return NULL;
}
/*adds a callback to the callback hash*/
void
gnome_panel_applet_register_callback(int applet_id,
......@@ -184,19 +208,80 @@ gnome_panel_applet_register_callback(int applet_id,
AppletCallbackFunc func,
gpointer data)
{
CallbackInfo *info = g_new(CallbackInfo,1);
GList *list;
CallbackInfo *info;
/*skip over leading '/'s*/
name = make_sane_name(name);
g_return_if_fail(name!=NULL);
info = get_callback_info(name);
if(!info) {
info = g_new(CallbackInfo,1);
applet_callbacks = g_list_prepend(applet_callbacks,info);
} else
g_free(info->name);
info->name = g_strdup(name);
info->applet_id = applet_id;
info->func = func;
info->data = data;
applet_callbacks = g_list_prepend(applet_callbacks,info);
/*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,menutext);
}
/*removes a callback from the callback hash*/
void
gnome_panel_applet_unregister_callback(int applet_id,
char *name)
{
/*skip over leading '/'s*/
name = make_sane_name(name);
g_return_if_fail(name!=NULL);
/*unregister the callback with the panel*/
panel_client->applet_remove_callback(cookie,applet_id,name);
}
void
gnome_panel_applet_register_callback_dir(int applet_id,
char *name,
char *menutext)
{
gchar *n;
/*skip over leading '/'s*/
name = make_sane_name(name);
g_return_if_fail(name!=NULL);
if(name[strlen(name)-1]!='/')
n = g_copy_strings(name,"/",NULL);
else
n = g_strdup(name);
/*unregister the dir with the panel*/
panel_client->applet_add_callback(cookie,applet_id,n,menutext);
g_free(n);
}
/*removes a callback dir from the callback menu*/
void
gnome_panel_applet_unregister_callback_dir(int applet_id,
char *name)
{
gchar *n;
/*skip over leading '/'s*/
name = make_sane_name(name);
if(name[strlen(name)-1]!='/')
n = g_copy_strings(name,"/",NULL);
else
n = g_strdup(name);
g_return_if_fail(name!=NULL);
/*unregister the callback with the panel*/
panel_client->applet_remove_callback(cookie,applet_id,n);
g_free(n);
}
/*catch events relevant to the panel and notify the panel*/
......
......@@ -32,6 +32,13 @@ void gnome_panel_applet_register_callback (gint applet_id,
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 *menutext);
void gnome_panel_applet_unregister_callback_dir(int applet_id, char *name);
void applet_corba_gtk_main (char *str);
void gnome_panel_applet_cleanup (gint applet_id);
......
#include <string.h>
#include <gtk/gtk.h>
#include <gnome.h>
#include <applet-widget.h>
......@@ -173,6 +174,26 @@ applet_widget_register_callback(AppletWidget *applet,
menutext,func,data);
}
void
applet_widget_unregister_callback(AppletWidget *applet,
char *name)
{
gnome_panel_applet_unregister_callback (applet->applet_id,name);
}
void
applet_widget_register_callback_dir(AppletWidget *applet, char *name, char *menutext)
{
gnome_panel_applet_register_callback_dir (applet->applet_id,name,menutext);
}
void
applet_widget_unregister_callback_dir(AppletWidget *applet, char *name)
{
gnome_panel_applet_unregister_callback_dir (applet->applet_id,name);
}
GtkWidget *
applet_widget_new_with_param(const gchar *param)
{
......
......@@ -85,15 +85,28 @@ void applet_widget_add (AppletWidget *applet,
/* remove the plug from the panel, this will destroy the applet */
void applet_widget_remove_from_panel (AppletWidget *applet);
/* Add a callback onto the applet's right click menu, use for properies
callback, help, etc... etc...
/* The callback functions control the applet's right click menu, the name is just a string, which has
to be unique and which controls the nesting, for example a name of "foo/bar" will add an item to the
submenu identified by "/foo" (which you should have created before with register_callback_dir,
use this for properies callback, help, about, etc... etc...
*/
/*add a callback onto the applet's right click menu*/
void applet_widget_register_callback (AppletWidget *applet,
gchar *name,
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);
/*remove a submenu*/
void applet_widget_unregister_callback_dir (AppletWidget *applet,
char *name);
/* get the applet widget with the id of applet_id */
AppletWidget* applet_widget_get_by_id (gint applet_id);
......
......@@ -34,6 +34,9 @@ module GNOME {
in short applet_id,
in string callback_name,
in string menuitem_text);
void applet_remove_callback (in string cookie,
in short applet_id,
in string callback_name);
void applet_add_tooltip (in string cookie, in short applet_id,
in string tooltip);
void applet_remove_tooltip (in string cookie,
......
......@@ -110,6 +110,13 @@ public:
(char *)callback_name,
(char *)menuitem_text);
}
void applet_remove_callback (const char *ccookie,
CORBA::Short applet_id,
const char *callback_name) {
CHECK_COOKIE ();
::applet_remove_callback(applet_id,
(char *)callback_name);
}
void applet_add_tooltip (const char *ccookie, CORBA::Short applet_id,
const char *tooltip) {
CHECK_COOKIE ();
......
......@@ -2215,7 +2215,7 @@ _panel_widget_applet_drag_start(PanelWidget *panel, GtkWidget *applet)
gtk_grab_add(applet);
gdk_pointer_grab(applet->window,
TRUE,
FALSE,
APPLET_EVENT_MASK,
NULL,
fleur_cursor,
......
......@@ -468,7 +468,7 @@ panel_clean_applet(gint applet_id)
info->assoc=NULL;
if(info->menu)
gtk_widget_unref(info->menu);
info->menu = NULL;
info->menu=NULL;
info->remove_item = NULL;
if(info->id_str) g_free(info->id_str);
......@@ -529,6 +529,158 @@ applet_menu_deactivate(GtkWidget *w, gpointer data)
panel->autohide_inhibit = FALSE;
}
static AppletUserMenu *
applet_get_callback(GList *user_menu, gchar *name)
{
GList *list;
for(list=user_menu;list!=NULL;list=g_list_next(list)) {
AppletUserMenu *menu = list->data;
if(strcmp(menu->name,name)==0)
return menu;
}
return NULL;
}
void
applet_add_callback(gint applet_id, char *callback_name, char *menuitem_text)
{
AppletUserMenu *menu;
AppletInfo *info = get_applet_info(applet_id);
g_return_if_fail(info != NULL);
if((menu=applet_get_callback(info->user_menu,callback_name))==NULL) {
menu = g_new(AppletUserMenu,1);
menu->name = g_strdup(callback_name);
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->text)
g_free(menu->text);
menu->text = g_strdup(menuitem_text);
}
/*make sure the menu is rebuilt*/
if(info->menu) {
GList *list;
for(list=info->user_menu;list!=NULL;list=g_list_next(list)) {
AppletUserMenu *menu = list->data;
menu->menuitem=NULL;
menu->submenu=NULL;
}
gtk_widget_unref(info->menu);
info->menu=NULL;
}
}
void
applet_remove_callback(gint applet_id, char *callback_name)
{
AppletUserMenu *menu;
AppletInfo *info = get_applet_info(applet_id);
g_return_if_fail(info != NULL);
if((menu=applet_get_callback(info->user_menu,callback_name))!=NULL) {
info->user_menu = g_list_remove(info->user_menu,menu);
if(menu->name)
g_free(menu->name);
if(menu->text)
g_free(menu->text);
g_free(menu);
}
/*make sure the menu is rebuilt*/
if(info->menu) {
GList *list;
for(list=info->user_menu;list!=NULL;list=g_list_next(list)) {
AppletUserMenu *menu = list->data;
menu->menuitem=NULL;
menu->submenu=NULL;
}
gtk_widget_unref(info->menu);
info->menu=NULL;
}
}
static AppletUserMenu *
find_sub_menu(GList *user_menu, gchar *name)
{
GList *list;
for(list=user_menu;list!=NULL;list=g_list_next(list)) {
AppletUserMenu *menu = list->data;
if(strcmp(menu->name,name)==0)
return menu;
}
return NULL;
}
static void
add_to_submenus(gint applet_id,char *path,char *name, AppletUserMenu *menu, GtkWidget *submenu,
GList *user_menu)
{
GList *list;
char *n = g_strdup(name);
char *p = strchr(n,'/');
char *t;
AppletUserMenu *s_menu;
/*this is the last one*/
if(p==NULL ||
p==(n + strlen(n) - 1)) {
g_free(n);
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);
if(submenu)
gtk_menu_append (GTK_MENU (submenu), menu->menuitem);
/*if an item not a submenu*/
if(p==NULL) {
gtk_signal_connect(GTK_OBJECT(menu->menuitem), "activate",
(GtkSignalFunc) applet_callback_callback,
menu);
/* if the item is a submenu and doesn't have it's menu created yet*/
} else if(!menu->submenu) {
menu->submenu = gtk_menu_new();
gtk_menu_item_set_submenu (GTK_MENU_ITEM(menu->menuitem), menu->submenu);
}
return;
}
*p = '\0';
p++;
t = g_copy_strings(path,n,"/",NULL);
s_menu = find_sub_menu(user_menu,t);
/*the user did not give us this sub menu, whoops, will create an empty one then*/
if(!s_menu) {
AppletInfo *info = get_applet_info(applet_id);
s_menu = g_new(AppletUserMenu,1);
s_menu->name = g_strdup(t);
s_menu->text = g_strdup(_("???"));
s_menu->applet_id = applet_id;
s_menu->menuitem = NULL;
s_menu->submenu = NULL;
info->user_menu = g_list_append(info->user_menu,s_menu);
user_menu = info->user_menu;
}
if(!s_menu->submenu)
s_menu->submenu = gtk_menu_new();
add_to_submenus(applet_id,t,p,menu,s_menu->submenu,user_menu);
g_free(t);
g_free(n);
}
static void
create_applet_menu(AppletInfo *info)
{
......@@ -560,12 +712,7 @@ create_applet_menu(AppletInfo *info)
for(;user_menu!=NULL;user_menu = g_list_next(user_menu)) {
AppletUserMenu *menu=user_menu->data;
menuitem = gtk_menu_item_new_with_label(menu->text);
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) applet_callback_callback,
menu);
gtk_menu_append(GTK_MENU(info->menu), menuitem);
gtk_widget_show(menuitem);
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
......@@ -832,27 +979,6 @@ applet_drag_stop(gint applet_id)
panel_widget_applet_drag_end(panel);
}
void
applet_add_callback(gint applet_id, char *callback_name, char *menuitem_text)
{
AppletUserMenu *menu = g_new(AppletUserMenu,1);
AppletInfo *info = get_applet_info(applet_id);
g_return_if_fail(info != NULL);
menu->name = g_strdup(callback_name);
menu->text = g_strdup(menuitem_text);
menu->applet_id = applet_id;
/*make sure the menu is rebuilt*/
if(info->menu) {
gtk_widget_unref(info->menu);
info->menu=NULL;
}
info->user_menu = g_list_append(info->user_menu,menu);
}
static gint
compare_params(const gchar *p1,const gchar *p2)
{
......
......@@ -65,6 +65,8 @@ struct _AppletUserMenu {
gchar *name;
gchar *text;
gint applet_id;
GtkWidget *menuitem;
GtkWidget *submenu;
};
struct _AppletInfo {
......@@ -136,6 +138,8 @@ void applet_drag_stop(gint applet_id);
void applet_add_callback(gint applet_id,
char *callback_name,
char *menuitem_text);
void applet_remove_callback(gint applet_id,
char *callback_name);
void applet_set_tooltip(gint applet_id, const char *tooltip);
void applet_remove_from_panel(gint applet_id);
......
......@@ -34,6 +34,9 @@ module GNOME {
in short applet_id,
in string callback_name,
in string menuitem_text);
void applet_remove_callback (in string cookie,
in short applet_id,
in string callback_name);
void applet_add_tooltip (in string cookie, in short applet_id,
in string tooltip);
void applet_remove_tooltip (in string cookie,
......
......@@ -34,6 +34,9 @@ module GNOME {
in short applet_id,
in string callback_name,
in string menuitem_text);
void applet_remove_callback (in string cookie,
in short applet_id,
in string callback_name);
void applet_add_tooltip (in string cookie, in short applet_id,
in string tooltip);
void applet_remove_tooltip (in string cookie,
......
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