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

create a do_draw signal on the applet-widget which can be optionaly

Fri Oct 29 22:53:23 1999  George Lebl  <jirka@5z.com>

        * extern.[ch],panel-widget.[ch],applet-widget.[ch],panel.c: create
          a do_draw signal on the applet-widget which can be optionaly
          requested so that the applet can render itself onto an rgb
          buffer which can be requested from the panel.
parent ab83b57e
Fri Oct 29 22:53:23 1999 George Lebl <jirka@5z.com>
* extern.[ch],panel-widget.[ch],applet-widget.[ch],panel.c: create
a do_draw signal on the applet-widget which can be optionaly
requested so that the applet can render itself onto an rgb
buffer which can be requested from the panel.
Wed Oct 27 19:47:30 1999 George Lebl <jirka@5z.com>
* panel-widget.c,rgb-stuff.c: remove the homegrown rotating, and
......
Fri Oct 29 22:53:23 1999 George Lebl <jirka@5z.com>
* extern.[ch],panel-widget.[ch],applet-widget.[ch],panel.c: create
a do_draw signal on the applet-widget which can be optionaly
requested so that the applet can render itself onto an rgb
buffer which can be requested from the panel.
Wed Oct 27 19:47:30 1999 George Lebl <jirka@5z.com>
* panel-widget.c,rgb-stuff.c: remove the homegrown rotating, and
......
......@@ -75,6 +75,10 @@ server_applet_back_change(CustomAppletServant *servant,
GNOME_Panel_BackInfoType *backing,
CORBA_Environment *ev);
static void
server_applet_draw(CustomAppletServant *servant,
CORBA_Environment *ev);
static void
server_applet_set_tooltips_state(CustomAppletServant *servant,
CORBA_boolean enabled,
......@@ -105,6 +109,7 @@ static POA_GNOME_Applet__epv applet_epv = {
(gpointer)&server_applet_do_callback,
(gpointer)&server_applet_session_save,
(gpointer)&server_applet_back_change,
(gpointer)&server_applet_draw,
(gpointer)&server_applet_set_tooltips_state,
(gpointer)&server_applet_change_position,
(gpointer)&server_applet__get_goad_id,
......@@ -175,6 +180,7 @@ enum {
CHANGE_SIZE_SIGNAL,
SAVE_SESSION_SIGNAL,
BACK_CHANGE_SIGNAL,
DO_DRAW_SIGNAL,
TOOLTIP_STATE_SIGNAL,
CHANGE_POSITION_SIGNAL,
LAST_SIGNAL
......@@ -298,6 +304,15 @@ applet_widget_class_init (AppletWidgetClass *class)
GTK_TYPE_ENUM,
GTK_TYPE_POINTER,
GTK_TYPE_POINTER);
applet_widget_signals[DO_DRAW_SIGNAL] =
gtk_signal_new("do_draw",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET(AppletWidgetClass,
do_draw),
gtk_signal_default_marshaller,
GTK_TYPE_NONE,
0);
applet_widget_signals[TOOLTIP_STATE_SIGNAL] =
gtk_signal_new("tooltip_state",
GTK_RUN_LAST,
......@@ -327,6 +342,7 @@ applet_widget_class_init (AppletWidgetClass *class)
class->change_size = NULL;
class->save_session = NULL;
class->back_change = NULL;
class->do_draw = NULL;
class->tooltip_state = NULL;
class->change_position = NULL;
}
......@@ -972,6 +988,53 @@ applet_widget_send_position(AppletWidget *applet, int enable)
CORBA_exception_free(&ev);
}
/* sets if the do_draw signal is sent*/
void
applet_widget_send_draw(AppletWidget *applet, int enable)
{
CORBA_Environment ev;
g_return_if_fail(applet != NULL);
g_return_if_fail(IS_APPLET_WIDGET(applet));
CORBA_exception_init(&ev);
GNOME_PanelSpot__set_send_draw(CD(applet)->pspot, enable, &ev);
CORBA_exception_free(&ev);
}
/* gets the rgb background, useful in conjunction with the draw signal */
void
applet_widget_get_rgb_bg(AppletWidget *applet, guchar **rgb,
int *w, int *h, int *rowstride)
{
CORBA_Environment ev;
GNOME_Panel_RgbImage *image;
g_return_if_fail(applet!=NULL);
g_return_if_fail(IS_APPLET_WIDGET(applet));
g_return_if_fail(rgb!=NULL);
g_return_if_fail(w!=NULL);
g_return_if_fail(h!=NULL);
g_return_if_fail(rowstride!=NULL);
CORBA_exception_init(&ev);
image = GNOME_PanelSpot__get_rgb_background(CD(applet)->pspot, &ev);
if(ev._major) {
g_warning("CORBA Exception");
CORBA_exception_free(&ev);
return;
}
CORBA_exception_free(&ev);
*w = image->width;
*h = image->width;
*rowstride = image->rowstride;
*rgb = g_new(guchar, (*h)*(*rowstride));
memcpy(*rgb,image->data._buffer,sizeof(guchar)*(*h)*(*rowstride));
CORBA_free(image);
}
int
applet_widget_init(const char *app_id,
const char *app_version,
......@@ -1167,6 +1230,14 @@ server_applet_back_change(CustomAppletServant *servant,
}
}
static void
server_applet_draw(CustomAppletServant *servant,
CORBA_Environment *ev)
{
gtk_signal_emit(GTK_OBJECT(servant->appwidget),
applet_widget_signals[DO_DRAW_SIGNAL]);
}
static void
server_applet_set_tooltips_state(CustomAppletServant *servant,
CORBA_boolean enabled,
......
......@@ -17,6 +17,7 @@
#define HAVE_APPLET_BIND_EVENTS 1
#define HAVE_PANEL_SIZE 1
#define HAVE_PANEL_PIXEL_SIZE 1
#define HAVE_PANEL_DRAW_SIGNAL 1
BEGIN_GNOME_DECLS
......@@ -131,6 +132,15 @@ struct _AppletWidgetClass
/* when the panel size changes, semantics are the same as above */
void (* change_pixel_size) (AppletWidget *applet,
int size);
/* done when we are requesting draws, only useful if you want
to get rgb data of the background to draw yourself on, this
signal is called when that data would be different and you
should reget it and redraw, you should use the
applet_widget_get_rgb_bg function to get rgb background for
you to render on, you need to use applet_widget_send_draw
to enable this signal */
void (* do_draw) (AppletWidget *applet);
};
typedef GtkWidget *(*AppletFactoryActivator)(const char *goad_id, const char **params, int nparams);
......@@ -242,6 +252,16 @@ int applet_widget_get_free_space (AppletWidget *applet);
void applet_widget_send_position (AppletWidget *applet,
int enable);
/* sets if the do_draw signal is sent*/
void applet_widget_send_draw (AppletWidget *applet,
int enable);
/* gets the rgb background, useful in conjunction with the do_draw signal */
void applet_widget_get_rgb_bg (AppletWidget *applet,
guchar **rgb,
int *w, int *h,
int *rowstride);
/*use this instead of gnome init, if you want multi applet, you also
have to specify a "start new applet" function which will launch a new
applet*/
......
......@@ -37,9 +37,6 @@ static int button_widget_leave_notify (GtkWidget *widget,
static void button_widget_pressed (ButtonWidget *button);
static void button_widget_unpressed (ButtonWidget *button);
typedef void (*VoidSignal) (GtkObject * object,
gpointer data);
/*list of all the button widgets*/
static GList *buttons=NULL;
......@@ -92,20 +89,6 @@ enum {
static int button_widget_signals[LAST_SIGNAL] = {0};
static void
marshal_signal_void (GtkObject * object,
GtkSignalFunc func,
gpointer func_data,
GtkArg * args)
{
VoidSignal rfunc;
rfunc = (VoidSignal) func;
(*rfunc) (object, func_data);
}
static void
button_widget_class_init (ButtonWidgetClass *class)
{
......@@ -120,7 +103,7 @@ button_widget_class_init (ButtonWidgetClass *class)
object_class->type,
GTK_SIGNAL_OFFSET(ButtonWidgetClass,
clicked),
marshal_signal_void,
gtk_signal_default_marshaller,
GTK_TYPE_NONE,
0);
button_widget_signals[PRESSED_SIGNAL] =
......@@ -129,7 +112,7 @@ button_widget_class_init (ButtonWidgetClass *class)
object_class->type,
GTK_SIGNAL_OFFSET(ButtonWidgetClass,
pressed),
marshal_signal_void,
gtk_signal_default_marshaller,
GTK_TYPE_NONE,
0);
button_widget_signals[UNPRESSED_SIGNAL] =
......@@ -138,7 +121,7 @@ button_widget_class_init (ButtonWidgetClass *class)
object_class->type,
GTK_SIGNAL_OFFSET(ButtonWidgetClass,
unpressed),
marshal_signal_void,
gtk_signal_default_marshaller,
GTK_TYPE_NONE,
0);
gtk_object_class_add_signals(object_class,button_widget_signals,
......
......@@ -125,6 +125,18 @@ s_panelspot_set_send_position(POA_GNOME_PanelSpot *servant,
CORBA_boolean,
CORBA_Environment *ev);
static CORBA_boolean
s_panelspot_get_send_draw(POA_GNOME_PanelSpot *servant,
CORBA_Environment *ev);
static void
s_panelspot_set_send_draw(POA_GNOME_PanelSpot *servant,
CORBA_boolean,
CORBA_Environment *ev);
static GNOME_Panel_RgbImage *
s_panelspot_get_rgb_background(POA_GNOME_PanelSpot *servant,
CORBA_Environment *ev);
static void
s_panelspot_register_us(POA_GNOME_PanelSpot *servant,
CORBA_Environment *ev);
......@@ -221,6 +233,9 @@ static POA_GNOME_PanelSpot__epv panelspot_epv = {
(gpointer)&s_panelspot_get_free_space,
(gpointer)&s_panelspot_get_send_position,
(gpointer)&s_panelspot_set_send_position,
(gpointer)&s_panelspot_get_send_draw,
(gpointer)&s_panelspot_set_send_draw,
(gpointer)&s_panelspot_get_rgb_background,
(gpointer)&s_panelspot_register_us,
(gpointer)&s_panelspot_unregister_us,
(gpointer)&s_panelspot_abort_load,
......@@ -274,6 +289,11 @@ extern_clean(Extern *ext)
PortableServer_POA_deactivate_object(thepoa, id, &ev);
CORBA_free (id);
POA_GNOME_PanelSpot__fini((PortableServer_Servant) ext, &ev);
if(ext->send_draw_timeout) {
gtk_timeout_remove(ext->send_draw_timeout);
ext->send_draw_timeout = 0;
}
g_free(ext);
......@@ -312,7 +332,7 @@ send_position_change(Extern *ext)
CORBA_Environment ev;
CORBA_exception_init(&ev);
g_warning ("Crazy function!\n");
/*g_warning ("Crazy function!\n");*/
/*go the the toplevel panel widget*/
for(;;) {
if(!GTK_WIDGET_NO_WINDOW(wid)) {
......@@ -417,6 +437,10 @@ load_extern_applet(char *goad_id, char *cfgpath, PanelWidget *panel, int pos, in
ext = g_new0(Extern,1);
ext->started = FALSE;
ext->send_position = FALSE;
ext->send_draw = FALSE;
ext->send_draw_timeout = 0;
ext->send_draw_queued = FALSE;
panelspot_servant = (POA_GNOME_PanelSpot *)ext;
panelspot_servant->_private = NULL;
......@@ -536,6 +560,7 @@ s_panel_add_applet_full(POA_GNOME_Panel *servant,
ext = g_new0(Extern,1);
ext->started = FALSE;
ext->send_position = FALSE;
ext->send_draw = FALSE;
panelspot_servant = (POA_GNOME_PanelSpot *)ext;
panelspot_servant->_private = NULL;
......@@ -771,6 +796,56 @@ s_panelspot_set_send_position(POA_GNOME_PanelSpot *servant,
ext->send_position = enable?TRUE:FALSE;
}
static CORBA_boolean
s_panelspot_get_send_draw(POA_GNOME_PanelSpot *servant,
CORBA_Environment *ev)
{
Extern *ext = (Extern *)servant;
g_assert(ext);
return ext->send_draw;
}
static void
s_panelspot_set_send_draw(POA_GNOME_PanelSpot *servant,
CORBA_boolean enable,
CORBA_Environment *ev)
{
Extern *ext = (Extern *)servant;
g_assert(ext);
ext->send_draw = enable?TRUE:FALSE;
}
static GNOME_Panel_RgbImage *
s_panelspot_get_rgb_background(POA_GNOME_PanelSpot *servant,
CORBA_Environment *ev)
{
Extern *ext = (Extern *)servant;
PanelWidget *panel;
GNOME_Panel_RgbImage *image;
int w, h, rowstride;
guchar *rgb;
g_assert(ext);
g_assert(ext->info);
panel = PANEL_WIDGET(ext->info->widget->parent);
panel_widget_get_applet_rgb_bg(panel, ext->ebox,
&rgb,&w,&h,&rowstride);
image = GNOME_Panel_RgbImage__alloc();
image->data._buffer = CORBA_sequence_CORBA_octet_allocbuf(h*rowstride);
memcpy(image->data._buffer,rgb,sizeof(guchar)*h*rowstride);
image->width = w;
image->height = h;
image->rowstride = rowstride;
return image;
}
static void
s_panelspot_register_us(POA_GNOME_PanelSpot *servant,
CORBA_Environment *ev)
......@@ -1122,3 +1197,42 @@ panel_corba_gtk_init(CORBA_ORB panel_orb)
return status;
}
static void
send_draw(Extern *ext)
{
CORBA_Environment ev;
CORBA_exception_init(&ev);
GNOME_Applet_draw(ext->applet, &ev);
if(ev._major)
panel_clean_applet(ext->info);
CORBA_exception_free(&ev);
}
static int
send_draw_timeout(gpointer data)
{
Extern *ext = data;
if(ext->send_draw_queued == TRUE) {
ext->send_draw_queued = FALSE;
send_draw(ext);
return TRUE;
}
ext->send_draw_timeout = 0;
return FALSE;
}
void
extern_send_draw(Extern *ext)
{
if(!ext || !ext->applet || !ext->send_draw)
return;
if(!ext->send_draw_timeout) {
ext->send_draw_queued = FALSE;
send_draw(ext);
ext->send_draw_timeout =
gtk_timeout_add(1000,send_draw_timeout,ext);
} else
ext->send_draw_queued = TRUE;
}
......@@ -20,7 +20,11 @@ struct _Extern {
char *cfg;
GtkWidget *ebox;
int started;
int send_position;
gboolean send_position;
gboolean send_draw;
int send_draw_timeout;
gboolean send_draw_queued;
AppletInfo *info;
};
......@@ -32,6 +36,9 @@ void load_queued_externs(void);
void panel_corba_clean_up(void);
gint panel_corba_gtk_init(CORBA_ORB panel_orb);
/* to be called when we want to send a draw signal to an applet */
void extern_send_draw(Extern *ext);
END_GNOME_DECLS
#endif
......@@ -131,10 +131,11 @@ enum {
APPLET_ADDED_SIGNAL,
APPLET_REMOVED_SIGNAL,
BACK_CHANGE_SIGNAL,
APPLET_DRAW_SIGNAL,
LAST_SIGNAL
};
static int panel_widget_signals[LAST_SIGNAL] = {0,0,0,0,0};
static int panel_widget_signals[LAST_SIGNAL] = {0};
static GtkFixedClass *parent_class = NULL;
......@@ -225,6 +226,16 @@ panel_widget_class_init (PanelWidgetClass *class)
GTK_TYPE_ENUM,
GTK_TYPE_POINTER,
GTK_TYPE_POINTER);
panel_widget_signals[APPLET_DRAW_SIGNAL] =
gtk_signal_new("applet_draw",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET(PanelWidgetClass,
applet_draw),
gtk_marshal_NONE__POINTER,
GTK_TYPE_NONE,
1,
GTK_TYPE_POINTER);
gtk_object_class_add_signals(object_class,panel_widget_signals,
LAST_SIGNAL);
......@@ -895,6 +906,57 @@ kill_cache_on_all_buttons(PanelWidget *panel, int even_no_alpha)
}
}
static void
setup_background(PanelWidget *panel, GdkPixbuf **pb, int *scale_w, int *scale_h,
gboolean *rotate)
{
GtkWidget *widget = GTK_WIDGET(panel);
GdkPixmap *bg_pixmap;
*pb = NULL;
*scale_w = *scale_h = 0;
*rotate = FALSE;
bg_pixmap = widget->style->bg_pixmap[GTK_WIDGET_STATE(widget)];
if(panel->back_type == PANEL_BACK_NONE) {
if(bg_pixmap && !panel->backpix) {
if(panel->backpix)
gdk_pixbuf_unref(panel->backpix);
panel->backpix = my_gdk_pixbuf_rgb_from_drawable(bg_pixmap);
kill_cache_on_all_buttons(panel, FALSE);
} else if(!bg_pixmap && panel->backpix) {
if(panel->backpix)
gdk_pixbuf_unref(panel->backpix);
panel->backpix = NULL;
kill_cache_on_all_buttons(panel, FALSE);
}
*pb = panel->backpix;
} else if(panel->back_type == PANEL_BACK_PIXMAP) {
if(!panel->backpixmap)
panel_resize_pixmap(panel);
*pb = panel->backpix;
if(panel->fit_pixmap_bg ||
panel->strech_pixmap_bg) {
*scale_w = panel->scale_w;
*scale_h = panel->scale_h;
if(panel->orient == PANEL_VERTICAL &&
panel->rotate_pixmap_bg)
*rotate = TRUE;
} else {
if(panel->orient == PANEL_VERTICAL &&
panel->rotate_pixmap_bg) {
/* we need to set scales to rotate*/
*scale_w = (*pb)->art_pixbuf->width;
*scale_h = (*pb)->art_pixbuf->height;
*rotate = TRUE;
}
}
}
}
void
panel_widget_draw_all(PanelWidget *panel, GdkRectangle *area)
{
......@@ -902,7 +964,6 @@ panel_widget_draw_all(PanelWidget *panel, GdkRectangle *area)
GtkWidget *widget;
GdkGC *gc;
GdkPixmap *pixmap;
GdkPixmap *bg_pixmap;
GdkRectangle da;
GdkPixbuf *pb = NULL;
int size;
......@@ -933,45 +994,8 @@ panel_widget_draw_all(PanelWidget *panel, GdkRectangle *area)
da.width = widget->allocation.width;
da.height = widget->allocation.height;
}
bg_pixmap = widget->style->bg_pixmap[GTK_WIDGET_STATE(widget)];
if(panel->back_type == PANEL_BACK_NONE) {
if(bg_pixmap && !panel->backpix) {
if(panel->backpix)
gdk_pixbuf_unref(panel->backpix);
panel->backpix = my_gdk_pixbuf_rgb_from_drawable(bg_pixmap);
kill_cache_on_all_buttons(panel, FALSE);
} else if(!bg_pixmap && panel->backpix) {
if(panel->backpix)
gdk_pixbuf_unref(panel->backpix);
panel->backpix = NULL;
kill_cache_on_all_buttons(panel, FALSE);
}
pb = panel->backpix;
} else if(panel->back_type == PANEL_BACK_PIXMAP) {
if(!panel->backpixmap)
panel_resize_pixmap(panel);
pb = panel->backpix;
if(panel->fit_pixmap_bg ||
panel->strech_pixmap_bg) {
scale_w = panel->scale_w;
scale_h = panel->scale_h;
if(panel->orient == PANEL_VERTICAL &&
panel->rotate_pixmap_bg)
rotate = TRUE;
} else {
if(panel->orient == PANEL_VERTICAL &&
panel->rotate_pixmap_bg) {
/* we need to set scales to rotate*/
scale_w = pb->art_pixbuf->width;
scale_h = pb->art_pixbuf->height;
rotate = TRUE;
}
}
}
setup_background(panel, &pb, &scale_w, &scale_h, &rotate);
pixmap = gdk_pixmap_new(widget->window,
da.width,da.height,
......@@ -1006,6 +1030,9 @@ panel_widget_draw_all(PanelWidget *panel, GdkRectangle *area)
for(li = panel->applet_list; li != NULL;
li = g_list_next(li)) {
AppletData *ad = li->data;
gtk_signal_emit(GTK_OBJECT(panel),
panel_widget_signals[APPLET_DRAW_SIGNAL],
ad->applet);
if(IS_BUTTON_WIDGET(ad->applet) &&
ad->applet->allocation.x>=0 &&
(!area || gtk_widget_intersect(ad->applet, area, NULL))) {
......@@ -2715,3 +2742,47 @@ panel_widget_change_global(int explicit_step,
gtk_widget_queue_resize(li->data);
}
}
void
panel_widget_get_applet_rgb_bg(PanelWidget *panel,
GtkWidget *applet,
guchar **rgb,
int *w, int *h,
int *rowstride)
{
GtkWidget *widget;
GdkPixbuf *pb = NULL;
int scale_w = 0,scale_h = 0;
int rotate = FALSE;
*rgb = NULL;
*w = *h = *rowstride = 0;
g_return_if_fail(panel!=NULL);
g_return_if_fail(IS_PANEL_WIDGET(panel));
g_return_if_fail(applet!=NULL);
g_return_if_fail(GTK_IS_WIDGET(applet));
widget = GTK_WIDGET(panel);
if(!GTK_WIDGET_DRAWABLE(widget) ||
widget->allocation.width <= 0 ||
widget->allocation.height <= 0)
return;
setup_background(panel, &pb, &scale_w, &scale_h, &rotate);
*w = applet->allocation.width;
*h = applet->allocation.height;
*rowstride = applet->allocation.width*3;
*rgb = g_new0(guchar, (*h)*(*rowstride));
make_background(panel, *rgb,
applet->allocation.x,
applet->allocation.y,
*w,*h, pb, scale_w, scale_h, rotate);
}
......@@ -117,6 +117,8 @@ struct _PanelWidgetClass
PanelBackType type,
char *pixmap,
GdkColor *color);
void (* applet_draw) (PanelWidget *panel,
GtkWidget *applet);
};
guint panel_widget_get_type (void);
......@@ -222,6 +224,12 @@ int panel_widget_get_cursorloc (PanelWidget *panel);
int panel_widget_is_cursor (PanelWidget *panel,
int overlap);
void panel_widget_get_applet_rgb_bg (PanelWidget *panel,
GtkWidget *applet,
guchar **rgb,
int *w, int *h,
int *rowstride);
/*extern GSList *panels;*/
extern int panel_applet_in_drag;
......
......@@ -592,6 +592,17 @@ panel_applet_move(GtkWidget *panel,GtkWidget *widget, gpointer data)
applets_to_sync = TRUE;
}
static void
panel_applet_draw(GtkWidget *panel, GtkWidget *widget, gpointer data)
{
AppletInfo *info = gtk_object_get_data(GTK_OBJECT(widget), "applet_info");
g_return_if_fail(info!=NULL);
if(info->type == APPLET_EXTERN)
extern_send_draw(info->data);
}
static GtkWidget *
panel_menu_get(PanelData *pd)
{
......@@ -904,6 +915,10 @@ panel_widget_setup(PanelWidget *panel)
"applet_move",
GTK_SIGNAL_FUNC(panel_applet_move),
NULL);
gtk_signal_connect(GTK_OBJECT(panel),
"applet_draw",
GTK_SIGNAL_FUNC(panel_applet_draw),
NULL);
gtk_signal_connect(GTK_OBJECT(panel),
"back_change",
GTK_SIGNAL_FUNC(panel_back_change),
......
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