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

implemented the callbacks, right now menu is built on the applet side and

Thu Mar 12 02:01:30 1998  George Lebl  <jirka@5z.com>

        * applet-lib.cc, panel.c: implemented the callbacks, right now
          menu is built on the applet side and code is there to do a
          unified applet menu stuff on the panel side, but I'd have to
          find a sane way of sending the button press event so that the
          menu would work, probably some hacking on teh grabs could make
          it work (release grab on the applet side, add grab on the panel
          side...)

        * panel.c: a bunch of fixes
parent 54360a14
Thu Mar 12 02:01:30 1998 George Lebl <jirka@5z.com>
* applet-lib.cc, panel.c: implemented the callbacks, right now
menu is built on the applet side and code is there to do a
unified applet menu stuff on the panel side, but I'd have to
find a sane way of sending the button press event so that the
menu would work, probably some hacking on teh grabs could make
it work (release grab on the applet side, add grab on the panel
side...)
* panel.c: a bunch of fixes
Wed Mar 11 22:42:39 1998 George Lebl <jirka@5z.com>
* menu.c: fixed a cpl of warnings
......
Thu Mar 12 02:01:30 1998 George Lebl <jirka@5z.com>
* applet-lib.cc, panel.c: implemented the callbacks, right now
menu is built on the applet side and code is there to do a
unified applet menu stuff on the panel side, but I'd have to
find a sane way of sending the button press event so that the
menu would work, probably some hacking on teh grabs could make
it work (release grab on the applet side, add grab on the panel
side...)
* panel.c: a bunch of fixes
Wed Mar 11 22:42:39 1998 George Lebl <jirka@5z.com>
* menu.c: fixed a cpl of warnings
......
......@@ -15,12 +15,19 @@ GNOME::Panel_var panel_client;
drag at a time :) Blah blah */
static int currently_dragged_id = -1;
static GtkWidget *applet_menu;
static GtkWidget *applet_menu_prop_separator;
static GtkWidget *applet_menu_prop_item;
typedef struct _CallbackInfo CallbackInfo;
struct _CallbackInfo {
gint applet_id;
gchar *menutext;
AppletCallbackFunc func;
gpointer data;
};
GHashTable *applet_callbacks=NULL;
#define APPLET_ID_KEY "applet_id_key"
#define APPLET_WIDGET_KEY "applet_widget_key"
#define APPLET_MENU_KEY "applet_menu_key"
CORBA::ORB_ptr orb_ptr;
static CORBA::BOA_ptr boa_ptr;
......@@ -49,7 +56,23 @@ public:
void do_callback (CORBA::Short id,
const char *callback_name)
{
/*FIXME: run the proper function that the applet registered*/
GList *list;
if(!applet_callbacks)
return;
list = (GList *)g_hash_table_lookup(applet_callbacks,
(char *)callback_name);
if(list) {
for(;list!=NULL;list = g_list_next(list)) {
CallbackInfo *info = (CallbackInfo *)list->data;
if(info->applet_id == id) {
(*(info->func))(id,info->data);
return;
}
}
}
}
};
......@@ -84,14 +107,46 @@ gnome_panel_applet_init_corba (void)
return 1;
}
/*adds a callback to the callback hash*/
/*the interfacte to thsi should probably be in appletwidget*/
void
gnome_panel_applet_register_callback(int id,
gnome_panel_applet_register_callback(AppletWidget *aw,
int id,
char *name,
char *menutext,
GFunc func,
AppletCallbackFunc func,
gpointer data)
{
/*FIXME: do callbacks*/
CallbackInfo *info = g_new(CallbackInfo,1);
GList *list;
if(!applet_callbacks)
applet_callbacks = g_hash_table_new (g_str_hash, g_str_equal);
info->applet_id = id;
info->menutext = g_strdup(menutext);
info->func = func;
info->data = data;
aw->menu_items = g_list_append(aw->menu_items,info);
list = (GList *)g_hash_table_lookup(applet_callbacks,name);
if(list) {
g_hash_table_remove(applet_callbacks,name);
list = g_list_prepend(list,info);
}
g_hash_table_insert(applet_callbacks,name,info);
/*make sure the menu is rebuilt*/
if(aw->applet_menu) {
gtk_widget_unref(aw->applet_menu);
aw->applet_menu = NULL;
}
/*register the callback with the panel since it might want to use
it*/
panel_client->applet_add_callback(id,name,menutext);
}
static void
......@@ -124,19 +179,19 @@ remove_applet_callback(GtkWidget *widget, gpointer data)
static void
applet_properties_callback(GtkWidget *widget, gpointer data)
applet_callback_callback(GtkWidget *widget, gpointer data)
{
GtkWidget *applet_menu = GTK_WIDGET(data);
int ourid = (int)gtk_object_get_data(GTK_OBJECT(applet_menu),
APPLET_ID_KEY);
CallbackInfo *info = (CallbackInfo *)data;
puts("Properties ... we don't need no stinkin' properties ...!");
(*(info->func))(info->applet_id,info->data);
}
static void
create_applet_menu(void)
GtkWidget *
create_applet_menu(AppletWidget *aw)
{
GtkWidget *menuitem;
GtkWidget *applet_menu;
GList *list;
applet_menu = gtk_menu_new();
......@@ -155,39 +210,41 @@ create_applet_menu(void)
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
menuitem = gtk_menu_item_new();
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
applet_menu_prop_separator = menuitem;
menuitem = gtk_menu_item_new_with_label(_("Applet properties..."));
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) applet_properties_callback,
applet_menu);
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
applet_menu_prop_item = menuitem;
if(aw->menu_items) {
menuitem = gtk_menu_item_new();
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
}
for(list = aw->menu_items;list!=NULL;list=g_list_next(list)) {
CallbackInfo *info = (CallbackInfo *)list->data;
menuitem = gtk_menu_item_new_with_label(info->menutext);
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) applet_callback_callback,
info);
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
}
return applet_menu;
}
static void
show_applet_menu(GtkWidget *widget, int id)
{
/*FIXME: only if applet has properties*/
if (1) {
gtk_widget_show(applet_menu_prop_separator);
gtk_widget_show(applet_menu_prop_item);
} else {
gtk_widget_hide(applet_menu_prop_separator);
gtk_widget_hide(applet_menu_prop_item);
}
gtk_object_set_data(GTK_OBJECT(applet_menu), APPLET_ID_KEY,
AppletWidget *aw = APPLET_WIDGET(widget);
if (!aw->applet_menu)
aw->applet_menu = create_applet_menu(aw);
gtk_object_set_data(GTK_OBJECT(aw->applet_menu), APPLET_ID_KEY,
(gpointer)id);
gtk_object_set_data(GTK_OBJECT(applet_menu), APPLET_WIDGET_KEY,
gtk_object_set_data(GTK_OBJECT(aw->applet_menu), APPLET_WIDGET_KEY,
(gpointer)widget);
gtk_menu_popup(GTK_MENU(applet_menu), NULL, NULL, NULL, NULL, 0/*3*/, time(NULL));
gtk_menu_popup(GTK_MENU(aw->applet_menu), NULL, NULL, NULL, NULL, 0/*3*/, time(NULL));
/*FIXME: make it pop-up on some title bar of the applet menu or
somehow avoid pressing remove applet being under the cursor!*/
}
......@@ -216,8 +273,6 @@ applet_event(GtkWidget *widget, GdkEvent *event, gpointer data)
APPLET_WIDGET(widget));
return TRUE;
} else if(bevent->button == 3) {
if(!applet_menu)
create_applet_menu();
show_applet_menu(widget,ourid);
return TRUE;
}
......
#include "applet-widget.h"
#ifndef APPLET_LIB_H
#define APPLET_LIB_H
BEGIN_GNOME_DECLS
typedef void (*AppletCallbackFunc)(int id, gpointer data);
char *gnome_panel_applet_request_id (GtkWidget *widget, char *path, int *id,
char **cfgpath);
char *gnome_panel_prepare_and_transfer (GtkWidget *widget, int id);
int gnome_panel_applet_init_corba (void);
void gnome_panel_applet_register_callback (int id,
void gnome_panel_applet_register_callback (AppletWidget *aw,
int id,
char *name,
char *menutext,
GFunc func,
AppletCallbackFunc func,
gpointer data);
void applet_corba_gtk_main (char *str);
......
......@@ -48,6 +48,10 @@ applet_widget_init (AppletWidget *applet_widget)
if(!fleur_cursor)
fleur_cursor = gdk_cursor_new(GDK_FLEUR);
/*FIXME: add some code to destroy this on exit*/
applet_widget->applet_menu = NULL;
applet_widget->menu_items = NULL;
}
GtkWidget*
......
......@@ -21,6 +21,9 @@ struct _AppletWidget
GtkWindow window;
GtkWidget *eb;
GtkWidget *applet_menu;
GList *menu_items;
};
struct _AppletWidgetClass
......
......@@ -200,6 +200,12 @@ shutdown_applet(int id)
//gtk_timeout_add(100,applet_die,NULL);
}
void
test_callback(int id, gpointer data)
{
puts("TEST");
}
int
main(int argc, char **argv)
......@@ -233,12 +239,15 @@ main(int argc, char **argv)
/*use cfg path for loading up data!*/
/*puts("CONFIG PATH");
puts(cfgpath);
puts("-----------");*/
g_free(cfgpath);
gnome_panel_applet_register_callback (aw,
applet_id,
"test",
"TEST CALLBACK",
test_callback,
NULL);
clock = create_clock_widget (GTK_WIDGET(aw));
gtk_widget_show(clock);
applet_widget_add (APPLET_WIDGET (aw), clock);
......
......@@ -474,8 +474,6 @@ main(int argc, char **argv)
gnome_init("panel", NULL, argc, argv, 0, NULL);
create_applet_menu();
/*set up global options*/
global_config.tooltips_enabled =
gnome_config_get_bool("/panel/Config/tooltips_enabled=TRUE");
......
......@@ -17,15 +17,6 @@
#include "panel_config_global.h"
#include <gdk/gdkx.h>
static GtkWidget *applet_menu;
static GtkWidget *applet_menu_remove_item;
static GtkWidget *applet_menu_prop_separator;
static GtkWidget *applet_menu_prop_item;
/*FIXME: get rid of this, menu will be part of panel not an applet*/
static menu_count=0; /*how many "menu" applets we have ....*/
/*FIXME: this should only count "main" menus!*/
#define APPLET_EVENT_MASK (GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_POINTER_MOTION_MASK | \
......@@ -110,6 +101,10 @@ save_applet_configuration(gpointer data, gpointer user_data)
int panel;
GList *list;
/*obviously no need for saving*/
if(info->type==APPLET_EXTERN_PENDING && info->type==APPLET_EMPTY)
return;
pos = -1;
for(panel=0,list=panels;list!=NULL;list=g_list_next(list),panel++)
if((pos=panel_widget_get_pos(PANEL_WIDGET(list->data),
......@@ -302,16 +297,13 @@ panel_session_save (GnomeClient *client,
printf("SHUTTING DOWN EXTERN (%d)\n",i);
send_applet_shutdown_applet(info->id,i);
puts("DONE");
} else if(info->type != APPLET_EXTERN_PENDING) {
puts("SHUTTING DOWN INTERNAL");
//gtk_widget_unref(info->widget);
puts("DONE");
}
if(info->menu)
gtk_widget_unref(info->menu);
}
g_list_foreach(panels,destroy_widget_list,NULL);
gtk_widget_unref(applet_menu);
gtk_object_unref(GTK_OBJECT (panel_tooltips));
small_icons = NULL;
......@@ -372,7 +364,7 @@ move_applet_callback(GtkWidget *widget, gpointer data)
AppletInfo *info;
PanelWidget *panel;
info = gtk_object_get_user_data(GTK_OBJECT(applet_menu));
info = data;
if(!(panel = find_applet_panel(info->widget)))
return;
......@@ -389,99 +381,102 @@ remove_applet_callback(GtkWidget *widget, gpointer data)
gint pos;
PanelWidget *panel;
info = gtk_object_get_user_data(GTK_OBJECT(applet_menu));
info = data;
/*FIXME: this will have to go menu can be accessed from right click*/
if(strcmp(info->id,"Menu")==0) {
if(menu_count<=1)
return;
/*FIXME: do something to make the user aware that this was
wrong ... a message box maybe ... or a beep*/
menu_count--;
}
applets=g_list_remove(applets,info);
if(info->type == APPLET_EXTERN)
send_applet_shutdown_applet(info->id,info->applet_id);
info->type = APPLET_EMPTY;
if(!(panel = find_applet_panel(info->widget)))
return;
panel_widget_remove(panel,info->widget);
gtk_widget_unref(info->widget);
/* this should be handeled by the applet itself (hopefully)
if(info->assoc)
gtk_widget_unref(info->assoc);
*/
if(info->menu)
gtk_widget_unref(info->menu);
g_free(info->id);
info->id=NULL;
if(info->params) g_free(info->params);
g_free(info);
info->params=NULL;
}
/*replace with corba applet callbacks*/
static void
applet_properties_callback(GtkWidget *widget, gpointer data)
applet_callback_callback(GtkWidget *widget, gpointer data)
{
AppletUserMenu *menu = data;
if(menu->info->type == APPLET_EXTERN) {
send_applet_do_callback(menu->info->id,
menu->info->applet_id,
menu->name);
} else if(menu->info->type != APPLET_EXTERN_PENDING &&
menu->info->type != APPLET_EMPTY) {
/*handle internal applet callbacks here*/
;
}
}
void
create_applet_menu(void)
/*the menu is not used for corba applets right now, but it might be used
if invoked from some other place*/
static GtkWidget *
create_applet_menu(AppletInfo *info, GList *user_menu)
{
GtkWidget *menuitem;
GtkWidget *applet_menu;
applet_menu = gtk_menu_new();
menuitem = gtk_menu_item_new_with_label(_("Remove from panel"));
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) remove_applet_callback,
NULL);
info);
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
applet_menu_remove_item = menuitem;
menuitem = gtk_menu_item_new_with_label(_("Move applet"));
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) move_applet_callback,
NULL);
info);
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
if(user_menu) {
menuitem = gtk_menu_item_new();
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
}
menuitem = gtk_menu_item_new();
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
applet_menu_prop_separator = menuitem;
menuitem = gtk_menu_item_new_with_label(_("Applet properties..."));
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) applet_properties_callback,
NULL);
gtk_menu_append(GTK_MENU(applet_menu), menuitem);
gtk_widget_show(menuitem);
applet_menu_prop_item = menuitem;
}
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(applet_menu), menuitem);
gtk_widget_show(menuitem);
}
return applet_menu;
}
static void
show_applet_menu(AppletInfo *info)
{
if (info->flags & APPLET_HAS_PROPERTIES) {
gtk_widget_show(applet_menu_prop_separator);
gtk_widget_show(applet_menu_prop_item);
} else {
gtk_widget_hide(applet_menu_prop_separator);
gtk_widget_hide(applet_menu_prop_item);
}
if (!info->menu)
info->menu = create_applet_menu(info,info->user_menu);
/*FIMXE: this should go*/
if(strcmp(info->id,"Menu")!=0 || menu_count>1)
gtk_widget_show(applet_menu_remove_item);
else
gtk_widget_hide(applet_menu_remove_item);
gtk_object_set_user_data(GTK_OBJECT(applet_menu), info);
gtk_menu_popup(GTK_MENU(applet_menu), NULL, NULL, NULL, NULL, 0/*3*/, time(NULL));
gtk_menu_popup(GTK_MENU(info->menu), NULL, NULL, NULL, NULL, 0/*3*/, time(NULL));
/*FIXME: make it pop-up on some title bar of the applet menu or
somehow avoid pressing remove applet being under the cursor!*/
}
static gint
applet_button_press(GtkWidget *widget,GdkEventButton *event, gpointer data)
{
......@@ -510,16 +505,24 @@ panel_log_out_callback(GtkWidget *widget, gpointer data)
panel_quit();
}
void
applet_show_menu(int id)
{
AppletInfo *info = g_list_nth(applets,id)->data;
show_applet_menu(info);
}
int
applet_get_panel(int id)
{
return 0;
return 0; /*FIXME*/
}
int
applet_get_pos(int id)
{
return 0;
return 0; /*FIXME*/
}
void
......@@ -544,7 +547,20 @@ applet_drag_stop(int id)
void
applet_add_callback(short id, char *callback_name, char *menuitem_text)
{
g_warning("Unimplemented\n");
AppletUserMenu *menu = g_new(AppletUserMenu,1);
AppletInfo *info = g_list_nth(applets,id)->data;
menu->name = g_strdup(callback_name);
menu->text = g_strdup(menuitem_text);
menu->info = info;
/*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);
}
int
......@@ -706,6 +722,8 @@ register_toy(GtkWidget *applet,
GtkWidget *eventbox;
AppletInfo *info;
PanelWidget *panelw;
GList *list;
int i;
g_assert(applet != NULL);
g_assert(id != NULL);
......@@ -722,13 +740,17 @@ register_toy(GtkWidget *applet,
info = g_new(AppletInfo,1);
for(i=0,list=applets;list!=NULL;list = g_list_next(list),i++)
;
info->applet_id = i;
info->type = type;
info->widget = eventbox;
info->assoc = assoc;
info->menu = NULL;
info->data = data;
info->id = g_strdup(id);
info->params = g_strdup(params);
info->flags = flags;
info->user_menu = NULL;
gtk_object_set_user_data(GTK_OBJECT(eventbox),info);
......@@ -748,8 +770,5 @@ register_toy(GtkWidget *applet,
orientation_change(info,panelw);
if(strcmp(id,"Menu")==0)
menu_count++;
printf ("The window id for %s is: %d\n",id, GDK_WINDOW_XWINDOW (eventbox->window));
}
......@@ -10,6 +10,7 @@ BEGIN_GNOME_DECLS
filemanager*/
/*#define LAUNCHER_ID "Launcher"*/
#define DRAWER_ID "Drawer"
#define LOGOUT_ID "Logout"
#define EXTERN_ID "Extern"
#define DEFAULT_AUTO_HIDE_STEP_SIZE 10
......@@ -44,7 +45,8 @@ typedef enum {
APPLET_EXTERN_PENDING,
APPLET_DRAWER,
APPLET_MENU,
APPLET_LOGOUT
APPLET_LOGOUT,
APPLET_EMPTY
} AppletType;
typedef enum {
......@@ -54,15 +56,27 @@ typedef enum {
ORIENT_RIGHT
} PanelOrientType;
typedef struct _AppletUserMenu AppletUserMenu;
typedef struct _AppletInfo AppletInfo;
struct _AppletUserMenu {
gchar *name;
gchar *text;
AppletInfo *info;
};
struct _AppletInfo {
AppletType type;
int applet_id;
GtkWidget *widget;
GtkWidget *assoc; /*associated widget, e.g. a drawer or a menu*/
GtkWidget *menu; /*the applet menu*/
gpointer data;
AppletFlags flags; /*flags: probably obscolete*/
gchar *id;
gchar *params;
gchar *id; /*used for IOR or string Id, and also for passing around
the config path*/
gchar *params; /*used for parameters to internal applets and for path
for external applets*/
GList *user_menu; /*list of AppletUserMenu items for callbacks*/
};
......@@ -76,8 +90,6 @@ gint panel_session_save (GnomeClient *client,
GtkWidget * create_panel_root_menu(PanelWidget *panel);
void create_applet_menu(void);
void register_toy(GtkWidget *applet,
GtkWidget *assoc,
gpointer data,
......
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