Commit 407043ca authored by George Lebl's avatar George Lebl

updated panel-widget .. it's theoretically complete now (for simple

non-drawer type panels), but I haven't even compiled it yet - George
parent 3cf49408
#include <gtk/gtk.h> #include <gtk/gtk.h>
char *possible_drag_types[] = {"application/panel-applet-pointer"};
char *accepted_drop_types[] = {"application/panel-applet-pointer"};
static void panel_widget_class_init (PanelWidgetClass *klass); static void panel_widget_class_init (PanelWidgetClass *klass);
static void panel_widget_init (PanelWidget *panel_widget); static void panel_widget_init (PanelWidget *panel_widget);
...@@ -68,18 +70,69 @@ panel_widget_place_applet(PanelWidget *panel, AppletRecord *applet, int pos) ...@@ -68,18 +70,69 @@ panel_widget_place_applet(PanelWidget *panel, AppletRecord *applet, int pos)
0,0); 0,0);
} }
static void
panel_widget_dnd_drop (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
GtkWidget *dragfrom;
PanelWidget *panel;
AppletRecord *tmp;
gint from,to;
dragfrom = *(GtkWidget **)event->dropdataavailable.data;
panel = (PanelWidget *)user_data;
from = panel_widget_get_pos(panel,dragfrom);
to = panel_widget_get_pos(panel,widget);
gtk_container_remove(GTK_CONTAINER(panel->table), dragfrom);
gtk_container_remove(GTK_CONTAINER(panel->table), widget);
tmp = panel->applets[from];
panel->applets[from] = panel->applets[to];
panel->applets[to] = tmp;
panel_widget_place_applet(panel,panel->applets[from],to);
panel_widget_place_applet(panel,panel->applets[to],from);
/*we know that widget is a placeholder and fromdrag is an applet*/
gtk_widget_dnd_drag_set (widget, TRUE, possible_drag_types, 1);
gtk_widget_dnd_drop_set (button, FALSE, accepted_drop_types, 1, FALSE);
}
void
panel_widget_dnd_drag_request (GtkWidget *widget, GdkEvent *event)
{
gtk_widget_dnd_data_set (widget, event, &widget, sizeof(GtkWidget *));
/*we know that widget is an applet*/
gtk_widget_dnd_drag_set (button, FALSE, possible_drag_types, 1);
gtk_widget_dnd_drop_set (button, TRUE, accepted_drop_types, 1, FALSE);
}
GtkWidget* GtkWidget*
panel_widget_new (gint size, PanelOrientation orient) panel_widget_new (gint size, PanelOrientation orient)
{ {
PanelWidget *panel; PanelWidget *panel;
gint i; gint i;
g_return_val_if_fail(size>0,NULL);
g_return_val_if_fail(
(orientation==PANEL_HORIZONTAL || orientation==PANEL_VERTICAL),
NULL);
panel = gtk_type_new(panel_widget_get_type()); panel = gtk_type_new(panel_widget_get_type());
if(orient == PANEL_HORIZONTAL) if(orient == PANEL_HORIZONTAL)
panel->table = gtk_table_new(1,size,TRUE); panel->table = gtk_table_new(1,size,TRUE);
else else
panel->table = gtk_table_new(size,1,TRUE); panel->table = gtk_table_new(size,1,TRUE);
gtk_container_add(GTK_CONTAINER(panel),panel->table);
panel->size = size; panel->size = size;
panel->orientation = orient; panel->orientation = orient;
...@@ -89,16 +142,39 @@ panel_widget_new (gint size, PanelOrientation orient) ...@@ -89,16 +142,39 @@ panel_widget_new (gint size, PanelOrientation orient)
panel->applets[i]->widget = gtk_event_box(); panel->applets[i]->widget = gtk_event_box();
panel->applets[i]->is_applet = FALSE; panel->applets[i]->is_applet = FALSE;
panel_widget_place_applet(panel,panel->applets[i],i); panel_widget_place_applet(panel,panel->applets[i],i);
/*widget needs to be resized*/
gtk_widget_realize(panel->applets[i]->widget);
gtk_signal_connect(GTK_OBJECT (panel->applets[i]->widget),
"drag_request_event",
GTK_SIGNAL_FUNC(panel_widget_dnd_drag_request),
panel);
gtk_signal_connect(GTK_OBJECT (panel->applets[i]->widget),
"drop_data_available_event",
GTK_SIGNAL_FUNC(panel_widget_dnd_drop),
panel);
gtk_widget_dnd_drop_set(panel->applets[i]->widget, TRUE,
accepted_drop_types, 1, FALSE);
gtk_widget_dnd_drag_set(panel->applets[i]->widget, FALSE,
possible_drag_types, 1);
gtk_widget_show(panel->applets[i]->widget); gtk_widget_show(panel->applets[i]->widget);
} }
return GTK_WIDGET(panel); return GTK_WIDGET(panel);
} }
gint gint
panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos) panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos)
{ {
gint i; gint i;
gtk_widget_dnd_drag_set (w, TRUE, possible_drag_types, 1);
g_return_val_if_fail(panel,-1);
g_return_val_if_fail(applet,-1);
g_return_val_if_fail(pos>=0,-1);
g_return_val_if_fail(pos<panel->size,-1);
for(i=pos;i<panel->size;i++) for(i=pos;i<panel->size;i++)
if(!panel->applets[i]->is_applet) if(!panel->applets[i]->is_applet)
...@@ -125,49 +201,52 @@ panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos) ...@@ -125,49 +201,52 @@ panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos)
panel->applets[i]->is_applet = TRUE; panel->applets[i]->is_applet = TRUE;
panel_widget_place_applet(panel,panel->applets[i],i); panel_widget_place_applet(panel,panel->applets[i],i);
gtk_widget_dnd_drag_set(applet, TRUE, possible_drag_types, 1);
gtk_widget_dnd_drop_set(applet, FALSE, possible_drag_types, 1);
return i; return i;
} }
gint gint
panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos) panel_widget_remove (PanelWidget *panel, GtkWidget *applet)
{ {
gint i; gint i;
for(i=pos;i<panel->size;i++) g_return_val_if_fail(panel,-1);
if(!panel->applets[i]->is_applet) g_return_val_if_fail(applet,-1);
for(i=0;i<panel->size;i++)
if(panel->applets[i]->widget == applet)
break; break;
/*panel is full to the right*/ /*applet not found*/
if(i==panel->size) { if(i==panel->size)
for(i=pos-1;i>=0;i--) return -1;
if(!panel->applets[i]->is_applet)
break;
/*panel is full!*/
if(i<=0)
return -1;
}
if(panel->applets[i]->widget) { /*remove applet*/
/*remove placeholder*/ gtk_container_remove(GTK_CONTAINER(panel->table),
gtk_container_remove(GTK_CONTAINER(panel->table), panel->applets[i]->widget);
panel->applets[i]->widget); gtk_widget_destroy(panel->applets[i]->widget);
gtk_widget_destroy(panel->applets[i]->widget);
}
panel->applets[i]->widget = applet; /*put placeholder in place*/
panel->applets[i]->is_applet = TRUE; panel->applets[i]->widget = gtk_event_box();
panel->applets[i]->is_applet = FALSE;
panel_widget_place_applet(panel,panel->applets[i],i); panel_widget_place_applet(panel,panel->applets[i],i);
gtk_widget_show(panel->applets[i]->widget);
gtk_widget_dnd_drag_set(applet, FALSE, possible_drag_types, 1);
gtk_widget_dnd_drop_set(applet, TRUE, possible_drag_types, 1);
return i; return i;
} }
gint gint
panel_widget_remove (PanelWidget *panel, GtkWidget *applet) panel_widget_get_pos(PanelWidget *panel, GtkWidget *applet)
{ {
gint i; gint i;
if(!panel || !applet) g_return_val_if_fail(panel,-1);
return -1; g_return_val_if_fail(applet,-1);
for(i=0;i<panel->size;i++) for(i=0;i<panel->size;i++)
if(panel->applets[i]->widget == applet) if(panel->applets[i]->widget == applet)
...@@ -177,16 +256,33 @@ panel_widget_remove (PanelWidget *panel, GtkWidget *applet) ...@@ -177,16 +256,33 @@ panel_widget_remove (PanelWidget *panel, GtkWidget *applet)
if(i==panel->size) if(i==panel->size)
return -1; return -1;
/*remove applet*/ return i;
gtk_container_remove(GTK_CONTAINER(panel->table), }
panel->applets[i]->widget);
gtk_widget_destroy(panel->applets[i]->widget);
/*put placeholder in place*/ GList*
panel->applets[i]->widget = gtk_event_box(); panel_widget_get_applets(PanelWidget *panel)
panel->applets[i]->is_applet = FALSE; {
panel_widget_place_applet(panel,panel->applets[i],i); GList *list=NULL;
gtk_widget_show(panel->applets[i]->widget); gint i;
return i; g_return_val_if_fail(panel,NULL);
for(i=0;i<panel->size;i++)
if(panel->applets[i]->widget != NULL)
list = g_list_prepend(list,panel->applets[i]->widget);
return list;
}
void
panel_widget_foreach(PanelWidget *panel, GFunc func, gpointer user_data)
{
gint i;
g_return_val_if_fail(panel,NULL);
g_return_val_if_fail(func,NULL);
for(i=0;i<panel->size;i++)
if(panel->applets[i]->widget != NULL)
(*func)(panel->applets[i]->widget,user_data);
} }
...@@ -15,6 +15,8 @@ extern "C" { ...@@ -15,6 +15,8 @@ extern "C" {
#define PANEL_WIDGET_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, panel_widget_get_type (), PanelWidgetClass) #define PANEL_WIDGET_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, panel_widget_get_type (), PanelWidgetClass)
#define IS_PANEL_WIDGET(obj) GTK_CHECK_TYPE (obj, panel_widget_get_type ()) #define IS_PANEL_WIDGET(obj) GTK_CHECK_TYPE (obj, panel_widget_get_type ())
/*this is not actually used in this code, but is a constant one should
use when calculating how many cells a panel should have*/
#define PANEL_CELL_SIZE 48 #define PANEL_CELL_SIZE 48
typedef struct _PanelWidget PanelWidget; typedef struct _PanelWidget PanelWidget;
...@@ -52,13 +54,22 @@ struct _PanelWidgetClass ...@@ -52,13 +54,22 @@ struct _PanelWidgetClass
guint panel_widget_get_type (void); guint panel_widget_get_type (void);
GtkWidget* panel_widget_new (gint size, GtkWidget* panel_widget_new (gint size,
PanelOrientation orient); PanelOrientation orient);
/*add an applet to the panel, preferably at position pos*/
gint panel_widget_add (PanelWidget *panel, gint panel_widget_add (PanelWidget *panel,
GtkWidget *applet, GtkWidget *applet,
gint pos); gint pos);
/*remove an applet from the panel*/
gint panel_widget_remove (PanelWidget *panel, gint panel_widget_remove (PanelWidget *panel,
GtkWidget *applet); GtkWidget *applet);
gint panel_widget_getpos (PanelWidget *panel, /*return position of an applet*/
gint panel_widget_get_pos (PanelWidget *panel,
GtkWidget *applet); GtkWidget *applet);
/*return a list of all applets*/
GList* panel_widget_get_applets (PanelWidget *panel);
/*run func for each applet*/
void panel_widget_foreach (PanelWidget *panel,
GFunc func,
gpointer user_data);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
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