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

fixes for size changes, performance improvements

Thu Apr 16 21:19:38 1998  George Lebl  <jirka@5z.com>

        * panel-widget.c: fixes for size changes, performance
          improvements
parent cb6674f4
Thu Apr 16 21:19:38 1998 George Lebl <jirka@5z.com>
* panel-widget.c: fixes for size changes, performance
improvements
1998-04-16 Miguel de Icaza <miguel@nuclecu.unam.mx>
* menu.c (create_menu_applet): Removed memory leak.
......
Thu Apr 16 21:19:38 1998 George Lebl <jirka@5z.com>
* panel-widget.c: fixes for size changes, performance
improvements
1998-04-16 Miguel de Icaza <miguel@nuclecu.unam.mx>
* menu.c (create_menu_applet): Removed memory leak.
......
......@@ -294,6 +294,8 @@ drawer_resize_drop_zone(PanelWidget *panel)
static void
panel_widget_set_size(PanelWidget *panel, gint size)
{
gint i;
if(size == 0)
size = panel->size;
switch(panel->snapped) {
......@@ -324,6 +326,18 @@ panel_widget_set_size(PanelWidget *panel, gint size)
gdk_screen_height());
break;
}
for(i=0;i<panel->size;i+=panel->applets[i].cells) {
if(panel->applets[i].applet) {
AppletData *ad = gtk_object_get_data(
GTK_OBJECT(panel->applets[i].applet),
PANEL_APPLET_DATA);
if(ad) {
/*postion now unknown*/
ad->prevx = -1;
ad->prevy = -1;
}
}
}
}
static void
......@@ -707,6 +721,36 @@ panel_widget_switch_move(PanelWidget *panel, gint pos, gint moveby)
return pos;
}
static gint
panel_widget_get_thick(PanelWidget *panel)
{
gint i;
gint thick=0;
g_return_if_fail(panel);
if(panel->orient==PANEL_HORIZONTAL) {
for(i=0;i<panel->size;i += panel->applets[i].cells)
if(panel->applets[i].applet &&
panel->applets[i].applet!=panel->drawer_drop_zone) {
int height = panel->applets[i].applet->
allocation.height;
if(height > thick)
thick = height;
}
} else { /* panel->orient==PANEL_VERTICAL */
for(i=0;i<panel->size;i += panel->applets[i].cells)
if(panel->applets[i].applet &&
panel->applets[i].applet!=panel->drawer_drop_zone) {
int width = panel->applets[i].applet->
allocation.width;
if(width > thick)
thick = width;
}
}
return thick;
}
static gint
......@@ -715,13 +759,32 @@ panel_widget_applet_size_allocate (GtkWidget *widget,
gpointer data)
{
PanelWidget *panel;
AppletData *ad;
gint thick;
panel = gtk_object_get_data(GTK_OBJECT(widget),PANEL_APPLET_PARENT_KEY);
panel_widget_adjust_applet(panel,widget);
ad = gtk_object_get_data(GTK_OBJECT(widget),PANEL_APPLET_DATA);
if(ad->prevwidth!=widget->allocation.width ||
ad->prevheight!=widget->allocation.height||
ad->prevx!=widget->allocation.x||
ad->prevy!=widget->allocation.y) {
thick = panel_widget_get_thick(panel);
if(panel->thick != thick) {
panel->thick = thick;
panel_widget_set_size(panel, panel->size);
}
panel_widget_adjust_applet(panel,widget);
gtk_signal_emit(GTK_OBJECT(panel),
panel_widget_signals[APPLET_MOVE_SIGNAL],
widget);
gtk_signal_emit(GTK_OBJECT(panel),
panel_widget_signals[APPLET_MOVE_SIGNAL],
widget);
}
ad->prevwidth = widget->allocation.width;
ad->prevheight = widget->allocation.height;
ad->prevx = widget->allocation.x;
ad->prevy = widget->allocation.y;
return TRUE;
}
......@@ -1802,6 +1865,50 @@ bind_applet_events(GtkWidget *widget, gpointer data)
bind_applet_events, 0);
}
static gint
panel_widget_applet_destroy(GtkWidget *applet, gpointer data)
{
PanelWidget *panel;
AppletData *ad;
int i,w,n;
panel = gtk_object_get_data(GTK_OBJECT(applet),PANEL_APPLET_PARENT_KEY);
g_return_val_if_fail(panel!=NULL,FALSE);
for(i=0;i<panel->size;i++)
if(panel->applets[i].applet == applet)
break;
/*applet found*/
if(i!=panel->size) {
w = panel->applets[i].cells;
for(n=0;n<w;n++) {
panel->applets[i+n].applet = NULL;
panel->applets[i+n].cells = 1;
}
if(panel->snapped==PANEL_DRAWER)
panel_widget_pack_applets(panel);
gtk_signal_emit(GTK_OBJECT(panel),
panel_widget_signals[APPLET_REMOVED_SIGNAL]);
}
ad = gtk_object_get_data(GTK_OBJECT(applet), PANEL_APPLET_DATA);
if(ad) g_free(ad);
/*this will trigger size_allocate of all applets and thus the
panel will again be set to the largest thickness*/
panel->thick = PANEL_MINIMUM_WIDTH;
panel_widget_set_size(panel,panel->size);
return FALSE;
}
static void
bind_top_applet_events(GtkWidget *widget)
{
......@@ -1811,6 +1918,10 @@ bind_top_applet_events(GtkWidget *widget)
panel_widget_applet_size_allocate),
NULL);
gtk_signal_connect(GTK_OBJECT(widget), "destroy",
GTK_SIGNAL_FUNC(panel_widget_applet_destroy),
NULL);
gtk_signal_connect(GTK_OBJECT(widget),
"event",
GTK_SIGNAL_FUNC(panel_widget_applet_event),
......@@ -1878,10 +1989,11 @@ panel_widget_find_empty_pos(PanelWidget *panel, gint pos)
return i;
}
gint
panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos)
{
AppletData *ad;
g_return_val_if_fail(panel!=NULL,-1);
g_return_val_if_fail(applet!=NULL,-1);
g_return_val_if_fail(pos>=0,-1);
......@@ -1895,6 +2007,12 @@ panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos)
panel->applets[pos].cells = 1;
gtk_object_set_data(GTK_OBJECT(applet),PANEL_APPLET_PARENT_KEY,panel);
ad = g_new(AppletData,1);
ad->prevwidth = -1;
ad->prevheight = -1;
ad->prevx = -1;
ad->prevx = -1;
gtk_object_set_data(GTK_OBJECT(applet),PANEL_APPLET_DATA,ad);
bind_top_applet_events(applet);
......@@ -1912,6 +2030,7 @@ panel_widget_reparent (PanelWidget *old_panel,
gint pos)
{
int i,w,n;
AppletData *ad;
g_return_val_if_fail(old_panel!=NULL,-1);
g_return_val_if_fail(new_panel!=NULL,-1);
......@@ -1960,6 +2079,14 @@ panel_widget_reparent (PanelWidget *old_panel,
PANEL_APPLET_PARENT_KEY,
new_panel);
ad = gtk_object_get_data(GTK_OBJECT(applet), PANEL_APPLET_DATA);
if(ad) {
ad->prevwidth = -1;
ad->prevheight = -1;
ad->prevx = -1;
ad->prevy = -1;
}
gtk_signal_emit(GTK_OBJECT(old_panel),
panel_widget_signals[APPLET_REMOVED_SIGNAL]);
......@@ -2017,6 +2144,7 @@ gint
panel_widget_remove (PanelWidget *panel, GtkWidget *applet)
{
gint i,n,w;
AppletData *ad;
g_return_val_if_fail(panel,-1);
g_return_val_if_fail(applet,-1);
......@@ -2046,6 +2174,9 @@ panel_widget_remove (PanelWidget *panel, GtkWidget *applet)
panel->thick = PANEL_MINIMUM_WIDTH;
panel_widget_set_size(panel,panel->size);
ad = gtk_object_get_data(GTK_OBJECT(applet), PANEL_APPLET_DATA);
if(ad) g_free(ad);
gtk_signal_emit(GTK_OBJECT(panel),
panel_widget_signals[APPLET_REMOVED_SIGNAL]);
......
......@@ -22,11 +22,13 @@ extern "C" {
#define PANEL_APPLET_PARENT_KEY "panel_applet_parent_key"
#define PANEL_APPLET_ASSOC_PANEL_KEY "panel_applet_assoc_panel_key"
#define PANEL_APPLET_DATA "panel_applet_data"
typedef struct _PanelWidget PanelWidget;
typedef struct _PanelWidgetClass PanelWidgetClass;
typedef struct _AppletRecord AppletRecord;
typedef struct _AppletData AppletData;
typedef struct _DNDRecord DNDRecord;
typedef enum {
PANEL_HORIZONTAL,
......@@ -62,6 +64,14 @@ struct _AppletRecord
gint cells;
};
struct _AppletData
{
gint prevx;
gint prevy;
gint prevwidth;
gint prevheight;
};
struct _DNDRecord
{
AppletRecord *applet;
......
......@@ -852,8 +852,8 @@ register_toy(GtkWidget *applet,
g_return_val_if_fail(panelw != NULL, FALSE);
/* We wrap the applet in a GtkEventBox so that we can capture events over it */
/* We wrap the applet in a GtkEventBox so that we can capture
events over it */
eventbox = gtk_event_box_new();
gtk_widget_set_events(eventbox, gtk_widget_get_events(eventbox) |
APPLET_EVENT_MASK);
......
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