panel.c 17.5 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4 5 6 7
/* Gnome panel: panel functionality
 * (C) 1997 the Free Software Foundation
 *
 * Authors: Federico Mena
 *          Miguel de Icaza
 */

8
#include <config.h>
Elliot Lee's avatar
Elliot Lee committed
9 10
#include <string.h>
#include "gnome.h"
11

12
#include "panel-widget.h"
13

Elliot Lee's avatar
Elliot Lee committed
14 15 16 17 18
#include "applet_files.h"
#include "gdkextra.h"
#include "panel_cmds.h"
#include "applet_cmds.h"
#include "panel.h"
19
#include "panel_config.h"
Elliot Lee's avatar
Elliot Lee committed
20 21 22 23 24 25


#define APPLET_CMD_FUNC "panel_applet_cmd_func"
#define APPLET_FLAGS    "panel_applet_flags"

static GtkWidget *applet_menu;
26
static GtkWidget *applet_menu_remove_item;
Elliot Lee's avatar
Elliot Lee committed
27 28 29
static GtkWidget *applet_menu_prop_separator;
static GtkWidget *applet_menu_prop_item;

30
/*FIXME: get rid of this, menu will be part of panel not an applet*/
31
static menu_count=0; /*how many "menu" applets we have ....*/
32
			/*FIXME: this should only count "main" menus!*/
33

34 35 36 37
#define APPLET_EVENT_MASK (GDK_BUTTON_PRESS_MASK |		\
			   GDK_BUTTON_RELEASE_MASK |		\
			   GDK_POINTER_MOTION_MASK |		\
			   GDK_POINTER_MOTION_HINT_MASK)
38

39
extern GList *panels;
40
extern GList *drawers;
41
extern GList *applets;
Elliot Lee's avatar
Elliot Lee committed
42

43
extern GtkTooltips *panel_tooltips;
44
extern gint tooltips_enabled;	
45

46 47
/*FIXME: a hack for current code to work*/
#define the_panel (PANEL_WIDGET(panels->data))
48

Elliot Lee's avatar
Elliot Lee committed
49

50
/* some prototypes */
51
static void properties(PanelWidget *panel);
Elliot Lee's avatar
Elliot Lee committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88


static AppletCmdFunc
applet_cmd_func(GtkWidget *applet)
{
	return gtk_object_get_data(GTK_OBJECT(applet), APPLET_CMD_FUNC);
}


static long
applet_flags(GtkWidget *applet)
{
	return (long) gtk_object_get_data(GTK_OBJECT(applet), APPLET_FLAGS);
}


static void
get_applet_geometry(GtkWidget *applet, int *x, int *y, int *width, int *height)
{
	if (x)
		*x = applet->allocation.x;

	if (y)
		*y = applet->allocation.y;

	if (width)
		*width = applet->allocation.width;

	if (height)
		*height = applet->allocation.height;
}

static gpointer
call_applet(GtkWidget *applet, AppletCommand *cmd)
{
	AppletCmdFunc cmd_func;
	
89
	cmd->panel  = the_panel;
Elliot Lee's avatar
Elliot Lee committed
90 91 92 93 94 95 96
	cmd->applet = GTK_BIN(applet)->child;

	cmd_func = applet_cmd_func(applet);

	return (*cmd_func) (cmd);
}

97
/*FIXME this should be somehow done through signals and panel-widget*/
98 99 100 101 102 103
static void
applet_orientation_notify(GtkWidget *widget, gpointer data)
{
	AppletCommand  cmd;

	cmd.cmd = APPLET_CMD_ORIENTATION_CHANGE_NOTIFY;
104 105
	cmd.params.orientation_change_notify.snapped = the_panel->snapped;
	cmd.params.orientation_change_notify.orient = the_panel->orient;
106

107 108
	call_applet(widget, &cmd);
}
Elliot Lee's avatar
Elliot Lee committed
109 110

static void
111
save_applet_configuration(gpointer data, gpointer user_data)
Elliot Lee's avatar
Elliot Lee committed
112 113 114 115
{
	char          *id;
	char          *params;
	char          *path;
116
	char          *fullpath;
Elliot Lee's avatar
Elliot Lee committed
117
	char           buf[256];
118 119 120 121 122
	GtkWidget     *widget = data;
	int           *num = user_data;
	int            pos;
	int            panel;
	GList         *list;
Elliot Lee's avatar
Elliot Lee committed
123 124
	AppletCommand  cmd;

125 126 127 128 129 130 131 132 133 134
	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),
	    				     widget))!=-1)
			break; 

	/*not found*/
	if(pos == -1)
		return;

Elliot Lee's avatar
Elliot Lee committed
135 136 137 138 139 140
	cmd.cmd = APPLET_CMD_QUERY;
	id      = call_applet(widget, &cmd);

	cmd.cmd = APPLET_CMD_GET_INSTANCE_PARAMS;
	params  = call_applet(widget, &cmd);

141 142 143 144 145 146 147
	sprintf(buf, "_%d/", (*num)++);
	path = g_copy_strings("/panel/Applet", buf, NULL);

	fullpath = g_copy_strings(path,"id",NULL);
	gnome_config_set_string(fullpath, id);
	g_free(fullpath);

148
	fullpath = g_copy_strings(path,"position",NULL);
149
	gnome_config_set_int(fullpath, pos);
150 151
	g_free(fullpath);

152 153 154 155
	fullpath = g_copy_strings(path,"panel",NULL);
	gnome_config_set_int(fullpath, panel);
	g_free(fullpath);

156 157 158 159
	fullpath = g_copy_strings(path,"parameters",NULL);
	gnome_config_set_string(fullpath, params);
	g_free(fullpath);

Elliot Lee's avatar
Elliot Lee committed
160 161 162 163 164

	g_free(params);
	g_free(path);
}

165 166
static void
save_panel_configuration(gpointer data, gpointer user_data)
167 168 169 170
{
	char          *path;
	char          *fullpath;
	char           buf[256];
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
	int           *num = user_data;
	PanelWidget   *panel = data;

	sprintf(buf, "_%d/", (*num)++);
	path = g_copy_strings("/panel/Panel", buf, NULL);

	fullpath = g_copy_strings(path,"orient",NULL);
	gnome_config_set_int(fullpath,panel->orient);
	g_free(fullpath);

	fullpath = g_copy_strings(path,"snapped",NULL);
	gnome_config_set_int(fullpath,panel->snapped);
	g_free(fullpath);

	fullpath = g_copy_strings(path,"mode",NULL);
	gnome_config_set_int(fullpath,panel->mode);
	g_free(fullpath);

	fullpath = g_copy_strings(path,"state",NULL);
	gnome_config_set_int(fullpath,panel->state);
	g_free(fullpath);

	fullpath = g_copy_strings(path,"step_size",NULL);
	gnome_config_set_int(fullpath,panel->step_size);
	g_free(fullpath);

	fullpath = g_copy_strings(path,"minimized_size",NULL);
	gnome_config_set_int(fullpath,panel->minimized_size);
	g_free(fullpath);

	fullpath = g_copy_strings(path,"minimize_delay",NULL);
	gnome_config_set_int(fullpath,panel->minimize_delay);
	g_free(fullpath);

	g_free(path);
}

static void
save_drawer_configuration(gpointer data, gpointer user_data)
{
	/*FIXME: drawers*/
	/*char          *path;
	char          *fullpath;
	char           buf[256];
	GtkWidget     *widget = data;
	int           *num = user_data;
217
	
218
	sprintf(buf, "_%d/", (*num)++);
219 220 221 222 223 224
	path = g_copy_strings("/panel/Drawer", buf, NULL);

	fullpath = g_copy_strings(path,"name",NULL);
	gnome_config_set_string(fullpath, drawer->name);
	g_free(fullpath);

225 226 227 228 229 230
	fullpath = g_copy_strings(path,"iconopen",NULL);
	gnome_config_set_string(fullpath, drawer->iconopen);
	g_free(fullpath);

	fullpath = g_copy_strings(path,"iconclosed",NULL);
	gnome_config_set_string(fullpath, drawer->iconclosed);
231 232 233 234 235 236 237 238 239 240
	g_free(fullpath);

	fullpath = g_copy_strings(path,"geometry",NULL);
	gnome_config_set_int(fullpath, pos);
	g_free(fullpath);

	fullpath = g_copy_strings(path,"step_size",NULL);
	gnome_config_set_int(fullpath, drawer->panel->step_size);
	g_free(fullpath);

241
	g_free(path);*/
242
}
243

244

Elliot Lee's avatar
Elliot Lee committed
245 246 247 248 249 250 251 252

static void
destroy_applet_module(gpointer key, gpointer value, gpointer user_data)
{
	AppletCommand  cmd;
	AppletFile    *af;

	cmd.cmd    = APPLET_CMD_DESTROY_MODULE;
253
	cmd.panel  = NULL; /*the_panel;*/
Elliot Lee's avatar
Elliot Lee committed
254 255 256 257 258 259 260
	cmd.applet = NULL;

	af = value;

	(*af->cmd_func) (&cmd);
}

261 262
static void
destroy_widget_list(gpointer data, gpointer user_data)
263
{
264 265
	gtk_widget_destroy(GTK_WIDGET(data));
}
Elliot Lee's avatar
Elliot Lee committed
266

267 268 269 270 271 272 273 274 275 276
/* This is called when the session manager requests a shutdown.  It
   can also be run directly when we don't detect a session manager.
   We assume no interaction is done by the applets.  And we ignore the
   other arguments for now.  Yes, this is lame.  */
int
panel_session_save (gpointer client_data,
		    GnomeSaveStyle save_style,
		    int is_shutdown,
		    GnomeInteractStyle interact_style,
		    int is_fast)
Elliot Lee's avatar
Elliot Lee committed
277
{
278 279
	gint num;
	gint drawernum;
280
	char buf[256];
281

282
	for(num=gnome_config_get_int("/panel/Config/applet_count=0");
283 284 285 286
		num>0;num--) {
		sprintf(buf,"/panel/Applet_%d",num);
		gnome_config_clean_section(buf);
	}
287 288 289 290 291 292 293 294
	for(num=gnome_config_get_int("/panel/Config/drawer_count=0");
		num>0;num--) {
		sprintf(buf,"/panel/Drawer_%d",num);
		gnome_config_clean_section(buf);
	}
	for(num=gnome_config_get_int("/panel/Config/panel_count=0");
		num>0;num--) {
		sprintf(buf,"/panel/Panel_%d",num);
295 296
		gnome_config_clean_section(buf);
	}
297 298

	num = 1;
299
	g_list_foreach(applets,save_applet_configuration,&num);
300
	gnome_config_set_int("/panel/Config/applet_count",num-1);
301 302 303 304 305 306 307 308
	num = 1;
	/* g_list_foreach(drawers,save_drawer_configuration,&num); */
	gnome_config_set_int("/panel/Config/drawer_count",num-1);
	num = 1;
	g_list_foreach(panels,save_panel_configuration,&num);
	gnome_config_set_int("/panel/Config/panel_count",num-1);

	/*global options*/
Jiri (George) Lebl's avatar
Jiri (George) Lebl committed
309
	gnome_config_set_bool("/panel/Config/tooltips_enabled",
310 311
			      tooltips_enabled);

Elliot Lee's avatar
Elliot Lee committed
312 313
	gnome_config_sync();

314 315
	g_list_foreach(drawers,destroy_widget_list,NULL);
	g_list_foreach(panels,destroy_widget_list,NULL);
Elliot Lee's avatar
Elliot Lee committed
316 317 318

	g_hash_table_foreach(applet_files_ht, destroy_applet_module, NULL);
	applet_files_destroy();
319 320 321 322 323 324 325 326 327 328 329 330

	/* Always successful.  */
	return 1;
}

static void
panel_quit(void)
{
  if (! gnome_session_connected_p ())
    {
      panel_session_save (NULL, GNOME_SAVE_BOTH, 1, GNOME_INTERACT_NONE, 0);
      gtk_main_quit ();
331 332 333 334
      /* We don't want to return, because we've probably been called from an
       * applet which has since been dlclose()'d, and we'd end up with a SEGV
       * when we tried to return to the now-nonexistent code page. */
      exit(0);
335 336 337 338 339 340 341
    }
  else
    {
      /* We request a completely interactive, full, slow shutdown.  */
      gnome_session_request_save (GNOME_SAVE_BOTH, 1, GNOME_INTERACT_ANY,
				  0, 1);
    }
Elliot Lee's avatar
Elliot Lee committed
342 343
}

344
static void
345
create_applet(char *id, char *params, int pos, int panel)
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
{
	AppletCommand cmd;
	AppletCmdFunc cmd_func;
	int           requested;
	
	g_assert(id != NULL);
	
	cmd_func = get_applet_cmd_func(id);
	if (!cmd_func) {
		fprintf(stderr, "create_applet: could not find applet \"%s\"\n", id);
		return;
	}

	requested = FALSE;
	
	if (!params) {
		cmd.cmd    = APPLET_CMD_GET_DEFAULT_PARAMS;
363
		cmd.panel  = the_panel;
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
		cmd.applet = NULL;
		
		params = (*cmd_func) (&cmd);

		if (!params) {
			fprintf(stderr,
				"create_applet: warning: applet \"%s\" returned NULL default parameters\n"
				"               using empty parameter string \"\"\n",
				id);
			params = g_strdup("");
		}

		requested = TRUE;
	}

	cmd.cmd    = APPLET_CMD_CREATE_INSTANCE;
380
	cmd.panel  = PANEL_WIDGET(g_list_nth(panels,panel)->data);
381 382
	cmd.applet = NULL;
	cmd.params.create_instance.params = params;
383 384
	cmd.params.create_instance.pos    = pos;
	cmd.params.create_instance.panel  = panel;
385 386 387 388 389 390 391

	(*cmd_func) (&cmd);

	if (requested)
		g_free(params);
}

392
/*FIXME:applet menu!*/
393

394
#if 0
Elliot Lee's avatar
Elliot Lee committed
395 396 397 398 399 400 401 402 403 404 405 406 407 408
static void
move_applet_callback(GtkWidget *widget, gpointer data)
{
	GtkWidget      *applet;

	applet = gtk_object_get_user_data(GTK_OBJECT(applet_menu));
	applet_drag_start(applet, TRUE);
}


static void
remove_applet_callback(GtkWidget *widget, gpointer data)
{
	GtkWidget *applet;
409 410
	AppletCommand  cmd;
	gchar *id;
411
	gint pos;
Elliot Lee's avatar
Elliot Lee committed
412 413

	applet = gtk_object_get_user_data(GTK_OBJECT(applet_menu));
414 415 416 417

	cmd.cmd = APPLET_CMD_QUERY;
	id      = call_applet(applet, &cmd);

418
	if(strcmp(id,"Menu")==0) {
419 420 421 422
		if(menu_count<=1)
			return;
		/*FIXME: do something to make the user aware that this was
		  wrong ... a message box maybe ... or a beep*/
423 424
		menu_count--;
	}
425

426
	pos = find_applet(the_panel->panel,applet);
Elliot Lee's avatar
Elliot Lee committed
427
	gtk_widget_destroy(applet);
428

429
	/*FIMXE: no placeholders in drawers!*/
430 431 432
	the_panel->panel->applets[pos]->applet = gtk_event_box_new();
	gtk_widget_show(the_panel->panel->applets[pos]->applet);
	the_panel->panel->applets[pos]->type = APPLET_PLACEHOLDER;
433 434 435

	put_applet_in_slot(the_panel->panel,
			   the_panel->panel->applets[pos],pos);
Elliot Lee's avatar
Elliot Lee committed
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
}


static void
applet_properties_callback(GtkWidget *widget, gpointer data)
{
	GtkWidget     *applet;
	AppletCommand  cmd;

	applet = gtk_object_get_user_data(GTK_OBJECT(applet_menu));

	cmd.cmd = APPLET_CMD_PROPERTIES;

	call_applet(applet, &cmd);
}

452
#endif
Elliot Lee's avatar
Elliot Lee committed
453 454 455 456

static void
create_applet_menu(void)
{
457
	/*GtkWidget *menuitem;
458

Elliot Lee's avatar
Elliot Lee committed
459 460
	applet_menu = gtk_menu_new();

461
	menuitem = gtk_menu_item_new_with_label(_("Remove from panel"));
Elliot Lee's avatar
Elliot Lee committed
462
	gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
463
			   (GtkSignalFunc) remove_applet_callback,
Elliot Lee's avatar
Elliot Lee committed
464 465 466
			   NULL);
	gtk_menu_append(GTK_MENU(applet_menu), menuitem);
	gtk_widget_show(menuitem);
467
	applet_menu_remove_item = menuitem;
Elliot Lee's avatar
Elliot Lee committed
468

469
	menuitem = gtk_menu_item_new_with_label(_("Move applet"));
470
	gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
471
			   (GtkSignalFunc) move_applet_callback,
Elliot Lee's avatar
Elliot Lee committed
472
			   NULL);
473 474
	gtk_menu_append(GTK_MENU(applet_menu), menuitem);
	gtk_widget_show(menuitem);
Elliot Lee's avatar
Elliot Lee committed
475 476 477 478 479 480 481 482 483 484 485 486

	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);
487
	applet_menu_prop_item = menuitem;*/
Elliot Lee's avatar
Elliot Lee committed
488 489 490 491 492 493 494
}


static void
show_applet_menu(GtkWidget *applet)
{
	long flags;
495 496
	AppletCommand  cmd;
	gchar *id;
Elliot Lee's avatar
Elliot Lee committed
497

498 499
	/*FIXME: DRAWERS crash on this, fix that */

Elliot Lee's avatar
Elliot Lee committed
500 501 502 503 504 505 506 507 508 509
	flags = applet_flags(applet);

	if (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);
	}

510 511 512 513 514 515 516
	cmd.cmd = APPLET_CMD_QUERY;
	id      = call_applet(applet, &cmd);

	if(strcmp(id,"Menu")!=0 || menu_count>1)
		gtk_widget_show(applet_menu_remove_item);
	else
		gtk_widget_hide(applet_menu_remove_item);
Elliot Lee's avatar
Elliot Lee committed
517 518 519
	gtk_object_set_user_data(GTK_OBJECT(applet_menu), applet);

	gtk_menu_popup(GTK_MENU(applet_menu), NULL, NULL, NULL, NULL, 3, time(NULL));
520 521
	/*FIXME: make it pop-up on some title bar of the applet menu or
	  somehow avoid pressing remove applet being under the cursor!*/
Elliot Lee's avatar
Elliot Lee committed
522 523
}

524 525 526
static void
panel_properties_callback(GtkWidget *widget, gpointer data)
{
527
	properties(PANEL_WIDGET(data));
528 529 530 531 532 533 534 535
}

static void
panel_log_out_callback(GtkWidget *widget, gpointer data)
{
	panel_quit();
}

536 537 538
static void
add_main_menu(GtkWidget *widget, gpointer data)
{
539
	PanelWidget *panel = data;
540 541
	/*FIXME: 1) doesn't work at all, 2)should add to current panel*/
	create_applet("Menu",".:1",PANEL_UNKNOWN_APPLET_POSITION,1);
542
}
543

544 545
GtkWidget *
create_panel_root_menu(PanelWidget *panel)
546 547
{
	GtkWidget *menuitem;
548
	GtkWidget *panel_menu;
549 550 551 552 553 554

	panel_menu = gtk_menu_new();

	menuitem = gtk_menu_item_new_with_label(_("Panel properties..."));
	gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
			   (GtkSignalFunc) panel_properties_callback,
555
			   panel);
556 557 558
	gtk_menu_append(GTK_MENU(panel_menu), menuitem);
	gtk_widget_show(menuitem);

559 560 561
	menuitem = gtk_menu_item_new_with_label(_("Add main menu applet"));
	gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
			   (GtkSignalFunc) add_main_menu,
562
			   panel);
563 564 565
	gtk_menu_append(GTK_MENU(panel_menu), menuitem);
	gtk_widget_show(menuitem);

566 567 568 569 570 571 572 573 574 575 576
	menuitem = gtk_menu_item_new();
	gtk_menu_append(GTK_MENU(panel_menu), menuitem);
	gtk_widget_show(menuitem);
	
	menuitem = gtk_menu_item_new_with_label(_("Log out"));
	gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
			   (GtkSignalFunc) panel_log_out_callback,
			   NULL);
	gtk_menu_append(GTK_MENU(panel_menu), menuitem);
	gtk_widget_show(menuitem);

577
	return panel_menu;
578 579
}

580

Elliot Lee's avatar
Elliot Lee committed
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
static void
get_applet_type(gpointer key, gpointer value, gpointer user_data)
{
	GList **list = user_data;

	*list = g_list_prepend(*list, g_strdup(key));
}


GList *
get_applet_types(void)
{
	GList *list = NULL;

	g_hash_table_foreach(applet_files_ht, get_applet_type, &list);
	return list;
}

static void
init_applet_module(gpointer key, gpointer value, gpointer user_data)
{
	AppletCommand  cmd;
	AppletFile    *af;

	cmd.cmd    = APPLET_CMD_INIT_MODULE;
606
	cmd.panel  = the_panel;
Elliot Lee's avatar
Elliot Lee committed
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
	cmd.applet = NULL;
	cmd.params.init_module.cmd_func = panel_command;

	af = value;

	(*af->cmd_func) (&cmd);
}


void
panel_init_applet_modules(void)
{
	g_hash_table_foreach(applet_files_ht, init_applet_module, NULL);
}

622 623 624 625 626 627 628 629
static void
set_tooltip(GtkWidget *applet, char *tooltip)
{
	if(!applet)
		return;
	gtk_tooltips_set_tips(panel_tooltips,applet,tooltip);
}

630

Elliot Lee's avatar
Elliot Lee committed
631
static void
632
register_toy(GtkWidget *applet, char *id, int pos, int panel, long flags)
Elliot Lee's avatar
Elliot Lee committed
633
{
634
	GtkWidget     *eventbox;
Elliot Lee's avatar
Elliot Lee committed
635 636 637 638 639 640 641
	
	g_assert(applet != NULL);
	g_assert(id != NULL);

	/* We wrap the applet in a GtkEventBox so that we can capture events over it */

	eventbox = gtk_event_box_new();
642 643
	gtk_widget_set_events(eventbox, gtk_widget_get_events(eventbox) |
			      APPLET_EVENT_MASK);
Elliot Lee's avatar
Elliot Lee committed
644 645
	gtk_container_add(GTK_CONTAINER(eventbox), applet);

646
	/* FIXME:get rid of this*/
Elliot Lee's avatar
Elliot Lee committed
647
	/* Attach our private data to the applet */
648 649 650 651
	gtk_object_set_data(GTK_OBJECT(eventbox), APPLET_CMD_FUNC,
			    get_applet_cmd_func(id));
	gtk_object_set_data(GTK_OBJECT(eventbox), APPLET_FLAGS,
			    (gpointer) flags);
Elliot Lee's avatar
Elliot Lee committed
652

653
	if(pos==PANEL_UNKNOWN_APPLET_POSITION)
654
		pos = 0;
655
	panel_widget_add(PANEL_WIDGET(g_list_nth(panels,panel)->data),
656
			 eventbox, pos);
Elliot Lee's avatar
Elliot Lee committed
657 658

	gtk_widget_show(applet);
659
	gtk_widget_show(eventbox);
660

661 662
	applets = g_list_append(applets,eventbox);

663 664
	/*notify the applet of the orientation of the panel!*/
	applet_orientation_notify(eventbox,NULL);
665 666 667

	if(strcmp(id,"Menu")==0)
		menu_count++;
Elliot Lee's avatar
Elliot Lee committed
668 669
}

670
static void
671
create_drawer(char *name, char *iconopen, char* iconclosed, int step_size,
672
	int pos, int drawer)
673
{
674 675
	/*FIXME: add drawers*/
	return;
676
}
Elliot Lee's avatar
Elliot Lee committed
677 678

static void
679
properties(PanelWidget *panel)
Elliot Lee's avatar
Elliot Lee committed
680
{
681
	panel_config(panel);
Elliot Lee's avatar
Elliot Lee committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
}

gpointer
panel_command(PanelCommand *cmd)
{
	g_assert(cmd != NULL);
	
	switch (cmd->cmd) {
		case PANEL_CMD_QUIT:
			panel_quit();
			return NULL;

		case PANEL_CMD_GET_APPLET_TYPES:
			return get_applet_types();

		case PANEL_CMD_GET_APPLET_CMD_FUNC:
			return get_applet_cmd_func(cmd->params.get_applet_cmd_func.id);

		case PANEL_CMD_CREATE_APPLET:
			create_applet(cmd->params.create_applet.id,
				      cmd->params.create_applet.params,
703 704
				      cmd->params.create_applet.pos,
				      cmd->params.create_applet.panel);
Elliot Lee's avatar
Elliot Lee committed
705 706 707
			break;
			
		case PANEL_CMD_REGISTER_TOY:
708
			/*FIXME: fix it so that applets pass panel*/
709
			cmd->params.register_toy.panel = 0;
Elliot Lee's avatar
Elliot Lee committed
710 711
			register_toy(cmd->params.register_toy.applet,
				     cmd->params.register_toy.id,
712
				     cmd->params.register_toy.pos,
713
				     cmd->params.register_toy.panel,
Elliot Lee's avatar
Elliot Lee committed
714 715 716
				     cmd->params.register_toy.flags);
			break;

717
		case PANEL_CMD_CREATE_DRAWER:
718
			create_drawer(cmd->params.create_drawer.name,
719 720 721
				      cmd->params.create_drawer.iconopen,
				      cmd->params.create_drawer.iconclosed,
				      cmd->params.create_drawer.step_size,
722 723
				      cmd->params.create_drawer.pos,
				      cmd->params.create_drawer.panel);
724 725
			break;

726 727 728 729 730
		case PANEL_CMD_SET_TOOLTIP:
			set_tooltip(cmd->params.set_tooltip.applet,
				    cmd->params.set_tooltip.tooltip);
			break;

Elliot Lee's avatar
Elliot Lee committed
731
		case PANEL_CMD_PROPERTIES:
732 733 734
			/*FIXME: this gotta be fixed, but we'll do it after
			  move dl -> CORBA*/
			properties(the_panel);
Elliot Lee's avatar
Elliot Lee committed
735 736 737 738 739 740 741 742 743 744
			break;

		default:
			fprintf(stderr, "panel_command: Oops, unknown command type %d\n",
				(int) cmd->cmd);
			break;
	}

	return NULL;
}