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

added the plug-socket colde v0.1 (that's the newest I found:)

Mon Mar 16 23:23:26 1998  George Lebl  <jirka@5z.com>

        * gtkplug.[ch], gtksocket.[ch]: added the plug-socket
          colde v0.1 (that's the newest I found:)

        * applet-widget.[ch]: removed in favor of plugsocket code

        * gnome-panel.idl,panel.c,mico-glue.cc,applet-lib.cc:
          adapted to plugsocket code, slightly different calls
          and the registration of applets acts slightly differently

        * clock.c, logout.c, launcher.c: ported to plugsocket
parent 15bed4b1
Mon Mar 16 23:23:26 1998 George Lebl <jirka@5z.com>
* gtkplug.[ch], gtksocket.[ch]: added the plug-socket
colde v0.1 (that's the newest I found:)
* applet-widget.[ch]: removed in favor of plugsocket code
* gnome-panel.idl,panel.c,mico-glue.cc,applet-lib.cc:
adapted to plugsocket code, slightly different calls
and the registration of applets acts slightly differently
* clock.c, logout.c, launcher.c: ported to plugsocket
Mon Mar 16 17:56:08 1998 George Lebl <jirka@5z.com>
* panel.c,mico-glue.cc: implemented abort_applet_id
......
Mon Mar 16 23:23:26 1998 George Lebl <jirka@5z.com>
* gtkplug.[ch], gtksocket.[ch]: added the plug-socket
colde v0.1 (that's the newest I found:)
* applet-widget.[ch]: removed in favor of plugsocket code
* gnome-panel.idl,panel.c,mico-glue.cc,applet-lib.cc:
adapted to plugsocket code, slightly different calls
and the registration of applets acts slightly differently
* clock.c, logout.c, launcher.c: ported to plugsocket
Mon Mar 16 17:56:08 1998 George Lebl <jirka@5z.com>
* panel.c,mico-glue.cc: implemented abort_applet_id
......
......@@ -33,7 +33,7 @@ lib_LTLIBRARIES = libpanel_applet.la
libpanel_applet_la_SOURCES = \
applet-lib.cc \
applet-widget.c \
gtkplug.c \
mico-parse.cc \
$(CORBA_SOURCES)
......@@ -71,6 +71,7 @@ panel_SOURCES = \
panel_config_global.h \
panel-widget.c \
panel-widget.h \
gtksocket.c \
$(CORBA_SOURCES)
panel_LDADD = $(GNOME_LIBDIR) $(MICO_LIBS) -lXt $(GNOMEUI_LIBS) $(INTLLIBS)
......
......@@ -5,16 +5,23 @@
#include "panel.h"
#include "gnome-panel.h"
#include "applet-lib.h"
#include "applet-widget.h"
#include "gtkplug.h"
#include "panel-widget.h"
#include "mico-parse.h"
#define APPLET_EVENT_MASK (GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_POINTER_MOTION_MASK | \
GDK_POINTER_MOTION_HINT_MASK)
GNOME::Panel_var panel_client;
/*this might be done better but I doubt there will be more then one
drag at a time :) Blah blah */
static int currently_dragged_id = -1;
static GdkCursor *fleur_cursor=NULL;
typedef struct _CallbackInfo CallbackInfo;
struct _CallbackInfo {
gint applet_id;
......@@ -105,10 +112,8 @@ gnome_panel_applet_init_corba (void)
}
/*adds a callback to the callback hash*/
/*the interfacte to thsi should probably be in appletwidget*/
void
gnome_panel_applet_register_callback(AppletWidget *aw,
int id,
gnome_panel_applet_register_callback(int id,
char *name,
char *menutext,
AppletCallbackFunc func,
......@@ -148,14 +153,12 @@ applet_event(GtkWidget *widget, GdkEvent *event, gpointer data)
if(bevent->button == 2 && currently_dragged_id==-1) {
panel_client->applet_drag_start(ourid);
currently_dragged_id = ourid;
applet_widget_move_grab_add(
APPLET_WIDGET(widget));
move_grab_add(widget);
return TRUE;
} else if(currently_dragged_id > -1) {
panel_client->applet_drag_stop(ourid);
currently_dragged_id = -1;
applet_widget_move_grab_remove(
APPLET_WIDGET(widget));
move_grab_remove(widget);
return TRUE;
} else if(bevent->button == 3) {
gdk_pointer_ungrab(GDK_CURRENT_TIME);
......@@ -168,8 +171,7 @@ applet_event(GtkWidget *widget, GdkEvent *event, gpointer data)
if(currently_dragged_id > -1) {
panel_client->applet_drag_stop(ourid);
currently_dragged_id = -1;
applet_widget_move_grab_remove(
APPLET_WIDGET(widget));
move_grab_remove(widget);
return TRUE;
}
break;
......@@ -239,32 +241,22 @@ bind_top_applet_events(GtkWidget *widget, int id)
/*id will return a unique id for this applet for the applet to identify
itself as*/
char *
gnome_panel_applet_request_id (GtkWidget *widget,
char *path,
gnome_panel_applet_request_id (char *path,
int *id,
char **cfgpath,
char **globcfgpath)
char **globcfgpath,
guint32 *winid)
{
char *result;
char *ior;
char *cfg = NULL;
char *globcfg = NULL;
/* Create an applet object, I do pass the widget parameter to the
* constructor object to have a way of sort out to which object
* implementation the panel is talking to us about (ie, if an applet
* can implement various instances of some object, like say a bunch
* of "Swallow" applets
*/
GNOME::Applet_ptr applet = new Applet_impl (widget);
/* Now a way to find out the CORBA impl from the widget */
gtk_object_set_data (GTK_OBJECT (widget), "CORBA_object", applet);
ior = orb_ptr->object_to_string (applet);
guint32 wid;
/*reserve a spot and get an id for this applet*/
*id = panel_client->applet_request_id(ior,path,cfg,globcfg);
*id = panel_client->applet_request_id(path,cfg,globcfg,wid);
if(winid)
*winid = wid;
if(cfgpath==NULL) {
CORBA::string_free(cfg);
......@@ -286,6 +278,34 @@ gnome_panel_applet_request_id (GtkWidget *widget,
return 0;
}
/*this function will register the ior with the panel so it can call us*/
char *
gnome_panel_applet_register (GtkWidget *widget, int id)
{
char *result;
char *ior;
/* Create an applet object, I do pass the widget parameter to the
* constructor object to have a way of sort out to which object
* implementation the panel is talking to us about (ie, if an applet
* can implement various instances of some object, like say a bunch
* of "Swallow" applets
*/
GNOME::Applet_ptr applet = new Applet_impl (widget);
/* Now a way to find out the CORBA impl from the widget */
gtk_object_set_data (GTK_OBJECT (widget), "CORBA_object", applet);
ior = orb_ptr->object_to_string (applet);
panel_client->applet_register(ior,id);
bind_top_applet_events(widget,id);
return 0;
}
char *
gnome_panel_applet_abort_id (int id)
{
......@@ -316,27 +336,6 @@ gnome_panel_applet_request_glob_cfg (char **globcfgpath)
}
/*id will return a unique id for this applet for the applet to identify
itself as*/
char *
gnome_panel_prepare_and_transfer (GtkWidget *widget, int id)
{
char *result;
gtk_widget_realize(widget);
gtk_widget_show(widget);
/*printf ("Transfiriendo: %d\n", GDK_WINDOW_XWINDOW (widget->window));*/
/*reparent the window*/
panel_client->reparent_window_id (GDK_WINDOW_XWINDOW (widget->window),
id);
bind_top_applet_events(widget,id);
/*printf ("Transferido\n");*/
return 0;
}
char *
gnome_panel_quit (void)
{
......@@ -347,9 +346,30 @@ gnome_panel_quit (void)
return 0;
}
void
applet_corba_gtk_main (char *str)
{
boa_ptr->impl_is_ready (CORBA::ImplementationDef::_nil());
}
void
move_grab_add (GtkWidget *applet)
{
if(!fleur_cursor)
fleur_cursor = gdk_cursor_new(GDK_FLEUR);
gtk_grab_add(applet);
gdk_pointer_grab(applet->window,
TRUE,
APPLET_EVENT_MASK,
NULL,
fleur_cursor,
GDK_CURRENT_TIME);
}
void
move_grab_remove (GtkWidget *applet)
{
gdk_pointer_ungrab(GDK_CURRENT_TIME);
gtk_grab_remove(applet);
}
#include "applet-widget.h"
#ifndef APPLET_LIB_H
#define APPLET_LIB_H
......@@ -6,21 +5,24 @@ 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 **globcfgpath);
char *gnome_panel_applet_request_id (char *path, int *id,
char **cfgpath, char **globcfgpath,
guint32 *winid);
char *gnome_panel_applet_register (GtkWidget *widget, int id);
char *gnome_panel_applet_abort_id (int id);
char *gnome_panel_applet_request_glob_cfg (char **globcfgpath);
char *gnome_panel_prepare_and_transfer (GtkWidget *widget, int id);
char *gnome_panel_quit (void);
int gnome_panel_applet_init_corba (void);
void gnome_panel_applet_register_callback (AppletWidget *aw,
int id,
void gnome_panel_applet_register_callback (int id,
char *name,
char *menutext,
AppletCallbackFunc func,
gpointer data);
void applet_corba_gtk_main (char *str);
void move_grab_add (GtkWidget *applet);
void move_grab_remove (GtkWidget *applet);
END_GNOME_DECLS
#endif
#include <gtk/gtk.h>
#include <gnome.h>
#include "applet-widget.h"
static void applet_widget_class_init (AppletWidgetClass *klass);
static void applet_widget_init (AppletWidget *applet_widget);
static GdkCursor *fleur_cursor;
guint
applet_widget_get_type ()
{
static guint applet_widget_type = 0;
if (!applet_widget_type) {
GtkTypeInfo applet_widget_info = {
"AppletWidget",
sizeof (AppletWidget),
sizeof (AppletWidgetClass),
(GtkClassInitFunc) applet_widget_class_init,
(GtkObjectInitFunc) applet_widget_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
};
applet_widget_type = gtk_type_unique (gtk_window_get_type (),
&applet_widget_info);
}
return applet_widget_type;
}
static void
applet_widget_class_init (AppletWidgetClass *class)
{
}
static void
applet_widget_init (AppletWidget *applet_widget)
{
applet_widget->eb = gtk_event_box_new();
gtk_widget_show(applet_widget->eb);
GTK_WINDOW(applet_widget)->type = GTK_WINDOW_POPUP;
gtk_container_add(GTK_CONTAINER(applet_widget),applet_widget->eb);
gtk_window_set_policy (GTK_WINDOW (applet_widget), 1, 1, 1);
if(!fleur_cursor)
fleur_cursor = gdk_cursor_new(GDK_FLEUR);
}
GtkWidget*
applet_widget_new (void)
{
AppletWidget *applet;
applet = gtk_type_new(applet_widget_get_type());
return GTK_WIDGET(applet);
}
void
applet_widget_add (AppletWidget *applet, GtkWidget *widget)
{
g_return_if_fail(applet != NULL);
g_return_if_fail(widget != NULL);
gtk_container_add(GTK_CONTAINER(applet->eb),widget);
}
void
applet_widget_remove (AppletWidget *applet, GtkWidget *widget)
{
g_return_if_fail(applet != NULL);
g_return_if_fail(widget != NULL);
gtk_container_remove(GTK_CONTAINER(applet->eb),widget);
}
#define APPLET_EVENT_MASK (GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_POINTER_MOTION_MASK | \
GDK_POINTER_MOTION_HINT_MASK)
void
applet_widget_move_grab_add (AppletWidget *applet)
{
gtk_grab_add(GTK_WIDGET(applet));
gdk_pointer_grab(GTK_WIDGET(applet)->window,
TRUE,
APPLET_EVENT_MASK,
NULL,
fleur_cursor,
GDK_CURRENT_TIME);
}
void
applet_widget_move_grab_remove (AppletWidget *applet)
{
gdk_pointer_ungrab(GDK_CURRENT_TIME);
gtk_grab_remove(GTK_WIDGET(applet));
}
#ifndef __APPLET_WIDGET_H__
#define __APPLET_WIDGET_H__
#include <gtk/gtk.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define APPLET_WIDGET(obj) GTK_CHECK_CAST (obj, applet_widget_get_type (), AppletWidget)
#define APPLET_WIDGET_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, applet_widget_get_type (), AppletWidgetClass)
#define IS_APPLET_WIDGET(obj) GTK_CHECK_TYPE (obj, applet_widget_get_type ())
typedef struct _AppletWidget AppletWidget;
typedef struct _AppletWidgetClass AppletWidgetClass;
struct _AppletWidget
{
GtkWindow window;
GtkWidget *eb;
};
struct _AppletWidgetClass
{
GtkWindowClass parent_class;
};
guint applet_widget_get_type (void);
GtkWidget* applet_widget_new (void);
/*add a widget to the applet*/
void applet_widget_add (AppletWidget *applet,
GtkWidget *widget);
/*remove a widget from the applet*/
void applet_widget_remove (AppletWidget *applet,
GtkWidget *widget);
void applet_widget_move_grab_add (AppletWidget *applet);
void applet_widget_move_grab_remove (AppletWidget *applet);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __APPLET_WIDGET_H__ */
......@@ -20,7 +20,7 @@
#include <gnome.h>
#include <gdk/gdkx.h>
#include "applet-lib.h"
#include "applet-widget.h"
#include "gtkplug.h"
#include "panel.h"
#include "mico-parse.h"
......@@ -28,7 +28,7 @@
typedef void (*ClockUpdateFunc) (GtkWidget *clock, time_t current_time);
GtkWidget *aw;
GtkWidget *plug = NULL;
int applet_id=-1; /*this is our id we use to comunicate with the panel*/
......@@ -192,8 +192,8 @@ void
shutdown_applet(int id)
{
/*kill our window using destroy to avoid warnings we need to
kill the aw but we also need to return from this call*/
gtk_widget_destroy(aw);
kill the plug but we also need to return from this call*/
if(plug) gtk_widget_destroy(plug);
gtk_idle_add(quit_clock,NULL);
}
......@@ -214,6 +214,7 @@ main(int argc, char **argv)
char *mypath;
char *myinvoc;
guint32 winid;
panel_corba_register_arguments ();
gnome_init("clock_applet", NULL, argc, argv, 0, NULL);
......@@ -224,8 +225,6 @@ main(int argc, char **argv)
/*exit (1);*/
}
aw = applet_widget_new ();
if(argv[0][0] == '/')
myinvoc = g_strdup(argv[0]);
else {
......@@ -233,8 +232,10 @@ main(int argc, char **argv)
myinvoc = g_copy_strings(mypath,"/",argv[0],NULL);
free(mypath);
}
result = gnome_panel_applet_request_id(aw,myinvoc,&applet_id,
&cfgpath,&globcfgpath);
result = gnome_panel_applet_request_id(myinvoc,&applet_id,
&cfgpath,&globcfgpath,
&winid);
g_free(myinvoc);
if (result){
g_error ("Could not talk to the Panel: %s\n", result);
......@@ -246,25 +247,26 @@ main(int argc, char **argv)
g_free(globcfgpath);
g_free(cfgpath);
gnome_panel_applet_register_callback (APPLET_WIDGET(aw),
applet_id,
"test",
"TEST CALLBACK",
test_callback,
NULL);
plug = gtk_plug_new (winid);
clock = create_clock_widget (GTK_WIDGET(aw));
clock = create_clock_widget (plug);
gtk_widget_show(clock);
applet_widget_add (APPLET_WIDGET (aw), clock);
gtk_widget_show (aw);
gtk_container_add (GTK_CONTAINER (plug), clock);
gtk_widget_show (plug);
result = gnome_panel_prepare_and_transfer(aw,applet_id);
/*printf ("Done\n");*/
result = gnome_panel_applet_register(plug,applet_id);
if (result){
g_error ("Could not talk to the Panel: %s\n", result);
/*exit (1);*/
}
gnome_panel_applet_register_callback (applet_id,
"test",
"TEST CALLBACK",
test_callback,
NULL);
applet_corba_gtk_main ("IDL:GNOME/Applet:1.0");
return 0;
......
......@@ -2,11 +2,11 @@ module GNOME {
interface Panel {
/* Sends the object identifier for the Applet server that
contacts the Panel */
void reparent_window_id (in unsigned long wid, in short id);
short applet_request_id(in string ior,
in string path,
short applet_request_id(in string path,
out string cfgpath,
out string globcfgpath);
out string globcfgpath,
out unsigned long wid);
void applet_register(in string ior, in short id);
void applet_abort_id(in short id);
void applet_request_glob_cfg(out string globcfgpath);
void applet_remove_from_panel (in short id);
......
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
#include "gtkplug.h"
static void gtk_plug_class_init (GtkPlugClass *klass);
static void gtk_plug_init (GtkPlug *plug);
static void gtk_plug_realize (GtkWidget *widget);
static gint gtk_plug_key_press_event (GtkWidget *widget,
GdkEventKey *event);
static void gtk_plug_forward_key_press (GtkPlug *plug, GdkEventKey *event);
static gint gtk_plug_focus_in_event (GtkWidget *widget, GdkEventFocus *event);
static gint gtk_plug_focus_out_event (GtkWidget *widget, GdkEventFocus *event);
static void gtk_plug_set_focus (GtkWindow *window,
GtkWidget *focus);
/* From Tk */
#define EMBEDDED_APP_WANTS_FOCUS NotifyNormal+20
guint
gtk_plug_get_type ()
{
static guint plug_type = 0;
if (!plug_type)
{
GtkTypeInfo plug_info =
{
"GtkPlug",
sizeof (GtkPlug),
sizeof (GtkPlugClass),
(GtkClassInitFunc) gtk_plug_class_init,
(GtkObjectInitFunc) gtk_plug_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
};
plug_type = gtk_type_unique (gtk_window_get_type (), &plug_info);
}
return plug_type;
}
static void
gtk_plug_class_init (GtkPlugClass *class)
{
GtkWidgetClass *widget_class;
GtkWindowClass *window_class;
widget_class = (GtkWidgetClass *)class;
window_class = (GtkWindowClass *)class;
widget_class->realize = gtk_plug_realize;
widget_class->key_press_event = gtk_plug_key_press_event;
widget_class->focus_in_event = gtk_plug_focus_in_event;
widget_class->focus_out_event = gtk_plug_focus_out_event;
window_class->set_focus = gtk_plug_set_focus;
}
static void
gtk_plug_init (GtkPlug *plug)
{
GtkWindow *window;
window = GTK_WINDOW (plug);
window->type = GTK_WINDOW_TOPLEVEL;
window->auto_shrink = TRUE;
}
GtkWidget*
gtk_plug_new (guint32 socket_id)
{
GtkPlug *plug;
plug = GTK_PLUG (gtk_type_new (gtk_plug_get_type ()));
plug->socket_window = gdk_window_lookup (socket_id);
plug->same_app = TRUE;
if (plug->socket_window == NULL)
{
plug->socket_window = gdk_window_foreign_new (socket_id);
plug->same_app = FALSE;
}
return GTK_WIDGET (plug);
}
static void
gtk_plug_realize (GtkWidget *widget)
{
GtkWindow *window;
GtkPlug *plug;
GdkWindowAttr attributes;
gint attributes_mask;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_PLUG (widget));
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
window = GTK_WINDOW (widget);
plug = GTK_PLUG (widget);
attributes.window_type = GDK_WINDOW_CHILD; /* XXX GDK_WINDOW_PLUG ? */
attributes.title = window->title;
attributes.wmclass_name = window->wmclass_name;
attributes.wmclass_class = window->wmclass_class;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
/* this isn't right - we should match our parent's visual/colormap.
* though that will require handling "foreign" colormaps */
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = gtk_widget_get_events (widget);
attributes.event_mask |= (GDK_EXPOSURE_MASK |
GDK_KEY_PRESS_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK |
GDK_FOCUS_CHANGE_MASK |
GDK_STRUCTURE_MASK);
attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP;
attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
widget->window = gdk_window_new (plug->socket_window,
&attributes, attributes_mask);
((GdkWindowPrivate *)widget->window)->window_type = GDK_WINDOW_TOPLEVEL;
gdk_window_set_user_data (widget->window, window);
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
}
static gint
gtk_plug_key_press_event (GtkWidget *widget,
GdkEventKey *event)
{
GtkWindow *window;
GtkPlug *plug;
GtkDirectionType direction = 0;
gint return_val;
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_PLUG (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
window = GTK_WINDOW (widget);
plug = GTK_PLUG (widget);
if (!GTK_WIDGET_HAS_FOCUS(widget))
{
gtk_plug_forward_key_press (plug, event);
return TRUE;
}
return_val = FALSE;
if (window->focus_widget)
return_val = gtk_widget_event (window->focus_widget, (GdkEvent*) event);
#if 0
if (!return_val && gtk_window_check_accelerator (window, event->keyval, event->state))
return_val = TRUE;
#endif
if (!return_val)
{
switch (event->keyval)
{
case GDK_space:
if (window->focus_widget)
{
gtk_widget_activate (window->focus_widget);
return_val = TRUE;
}
break;
case GDK_Return:
case GDK_KP_Enter: