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

more work towards menu/panel integration

Thu Feb 12 00:04:39 1998  George Lebl  <jirka@5z.com>

        * panel.c, menu.c: more work towards menu/panel integration
parent e1362867
Thu Feb 12 00:04:39 1998 George Lebl <jirka@5z.com>
* panel.c, menu.c: more work towards menu/panel integration
Wed Feb 11 22:39:19 1998 George Lebl <jirka@5z.com> Wed Feb 11 22:39:19 1998 George Lebl <jirka@5z.com>
* panel.c: some preparations for menu integration, and internal * panel.c: some preparations for menu integration, and internal
......
Thu Feb 12 00:04:39 1998 George Lebl <jirka@5z.com>
* panel.c, menu.c: more work towards menu/panel integration
Wed Feb 11 22:39:19 1998 George Lebl <jirka@5z.com> Wed Feb 11 22:39:19 1998 George Lebl <jirka@5z.com>
* panel.c: some preparations for menu integration, and internal * panel.c: some preparations for menu integration, and internal
......
...@@ -24,9 +24,11 @@ ...@@ -24,9 +24,11 @@
#define MENU_PATH "menu_path" #define MENU_PATH "menu_path"
static char *gnome_folder; static char *gnome_folder = NULL;
static GList *small_icons = NULL; Menu *root_menu = NULL;
GList *small_icons = NULL;
int show_small_icons = TRUE; int show_small_icons = TRUE;
static PanelCmdFunc panel_cmd_func; static PanelCmdFunc panel_cmd_func;
...@@ -45,6 +47,12 @@ activate_app_def (GtkWidget *widget, void *data) ...@@ -45,6 +47,12 @@ activate_app_def (GtkWidget *widget, void *data)
gnome_desktop_entry_launch (item); gnome_desktop_entry_launch (item);
} }
static void
kill_small_icon(GtkWidget *widget, gpointer data)
{
if(small_icons) g_list_remove(small_icons,widget);
}
void void
setup_menuitem (GtkWidget *menuitem, GtkWidget *pixmap, char *title) setup_menuitem (GtkWidget *menuitem, GtkWidget *pixmap, char *title)
{ {
...@@ -71,6 +79,8 @@ setup_menuitem (GtkWidget *menuitem, GtkWidget *pixmap, char *title) ...@@ -71,6 +79,8 @@ setup_menuitem (GtkWidget *menuitem, GtkWidget *pixmap, char *title)
gtk_widget_set_usize (align, 22, 16); gtk_widget_set_usize (align, 22, 16);
*small_icons = g_list_prepend (*small_icons, align); *small_icons = g_list_prepend (*small_icons, align);
gtk_signal_object_connect(GTK_OBJECT(align),"destroy",
GTK_SIGNAL_FUNC(kill_small_icon),NULL);
gtk_widget_show (align); gtk_widget_show (align);
gtk_widget_show (hbox); gtk_widget_show (hbox);
...@@ -291,13 +301,13 @@ create_menu_at (GtkWidget *window, char *menudir, int create_app_menu); ...@@ -291,13 +301,13 @@ create_menu_at (GtkWidget *window, char *menudir, int create_app_menu);
void void
menu_position (GtkMenu *menu, gint *x, gint *y, gpointer data) menu_position (GtkMenu *menu, gint *x, gint *y, gpointer data)
{ {
Menu * menu = data; Menu * menup = data;
GtkWidget *widget = menu->button; GtkWidget *widget = menu->button;
int wx, wy; int wx, wy;
gdk_window_get_origin (widget->window, &wx, &wy); gdk_window_get_origin (widget->window, &wx, &wy);
switch(menu->oerientation) { switch(menup->orient) {
case MENU_DOWN: case MENU_DOWN:
*x = wx; *x = wx;
*y = wy + widget->allocation.height; *y = wy + widget->allocation.height;
...@@ -315,10 +325,14 @@ menu_position (GtkMenu *menu, gint *x, gint *y, gpointer data) ...@@ -315,10 +325,14 @@ menu_position (GtkMenu *menu, gint *x, gint *y, gpointer data)
*y = wy; *y = wy;
break; break;
} }
if(*x + GTK_WIDGET (menu)->allocation.width > gdk_screen_width()) if(*x + GTK_WIDGET (menu)->allocation.width > gdk_screen_width())
*x=gdk_screen_width() - GTK_WIDGET (menu)->allocation.width; *x=gdk_screen_width() - GTK_WIDGET (menu)->allocation.width;
if(*x < 0) *x =0;
if(*y + GTK_WIDGET (menu)->allocation.height > gdk_screen_height()) if(*y + GTK_WIDGET (menu)->allocation.height > gdk_screen_height())
*y=gdk_screen_height() - GTK_WIDGET (menu)->allocation.height; *y=gdk_screen_height() - GTK_WIDGET (menu)->allocation.height;
if(*y < 0) *y =0;
} }
void void
...@@ -550,29 +564,31 @@ add_special_entries (GtkWidget *menu, GtkWidget *app_menu) ...@@ -550,29 +564,31 @@ add_special_entries (GtkWidget *menu, GtkWidget *app_menu)
gtk_signal_connect (GTK_OBJECT (menuitem), "activate", (GtkSignalFunc) panel_logout, 0); gtk_signal_connect (GTK_OBJECT (menuitem), "activate", (GtkSignalFunc) panel_logout, 0);
} }
static GtkWidget * static Menu *
create_panel_menu (GtkWidget *window, char *menudir, int main_menu) create_panel_menu (GtkWidget *window, char *menudir, int main_menu,
MenuOrient orient)
{ {
GtkWidget *button; GtkWidget *button;
GtkWidget *pixmap; GtkWidget *pixmap;
GtkWidget *menu; Menu *menu;
GtkWidget *app_menu; GtkWidget *app_menu;
char *pixmap_name; char *pixmap_name;
menu = g_new(Menu,1);
if (main_menu) if (main_menu)
switch(panel_snapped) { switch(orient) {
case PANEL_TOP: case MENU_DOWN:
pixmap_name = gnome_unconditional_pixmap_file ("gnome-menu-down.xpm"); pixmap_name = gnome_unconditional_pixmap_file ("gnome-menu-down.xpm");
break; break;
case PANEL_FREE: case MENU_UP:
case PANEL_BOTTOM:
pixmap_name = gnome_unconditional_pixmap_file ("gnome-menu-up.xpm"); pixmap_name = gnome_unconditional_pixmap_file ("gnome-menu-up.xpm");
break; break;
case PANEL_LEFT: case MENU_RIGHT:
pixmap_name = gnome_unconditional_pixmap_file ("gnome-menu-right.xpm"); pixmap_name = gnome_unconditional_pixmap_file ("gnome-menu-right.xpm");
break; break;
case PANEL_RIGHT: case MENU_LEFT:
pixmap_name = gnome_unconditional_pixmap_file ("gnome-menu-left.xpm"); pixmap_name = gnome_unconditional_pixmap_file ("gnome-menu-left.xpm");
break; break;
} }
...@@ -580,146 +596,116 @@ create_panel_menu (GtkWidget *window, char *menudir, int main_menu) ...@@ -580,146 +596,116 @@ create_panel_menu (GtkWidget *window, char *menudir, int main_menu)
/*FIXME: these guys need arrows as well*/ /*FIXME: these guys need arrows as well*/
pixmap_name = gnome_unconditional_pixmap_file ("panel-folder.xpm"); pixmap_name = gnome_unconditional_pixmap_file ("panel-folder.xpm");
menu->orient = orient;
/* main button */ /* main button */
button = gtk_button_new (); menu->button = gtk_button_new ();
/*make the pixmap*/ /*make the pixmap*/
pixmap = gnome_create_pixmap_widget (window, button, pixmap_name); pixmap = gnome_create_pixmap_widget (window, menu->button, pixmap_name);
gtk_widget_show(pixmap); gtk_widget_show(pixmap);
gtk_widget_set_usize (button, pixmap->requisition.width, /*FIXME:this is not right, but it's how we can get the buttons to
be 48x48 (given the icons are 48x48)*/
gtk_widget_set_usize (menu->button, pixmap->requisition.width,
pixmap->requisition.height); pixmap->requisition.height);
/* put pixmap in button */ /* put pixmap in button */
gtk_container_add (GTK_CONTAINER(button), pixmap); gtk_container_add (GTK_CONTAINER(menu->button), pixmap);
gtk_widget_show (button); gtk_widget_show (menu->button);
menu = create_menu_at (window, menudir, 0);
if (main_menu) { if (main_menu) {
if(!root_menu)
root_menu = create_menu_at (window, menudir, 0);
menu->menu = root_menu;
app_menu = create_menu_at (window, menudir, 1); app_menu = create_menu_at (window, menudir, 1);
add_special_entries (menu, app_menu); add_special_entries (menu->menu, app_menu);
} else {
menu->menu = create_menu_at (window, menudir, 0);
} }
gtk_signal_connect (GTK_OBJECT (button), "clicked", gtk_signal_connect (GTK_OBJECT (menu->button), "clicked",
GTK_SIGNAL_FUNC (activate_menu), menu); GTK_SIGNAL_FUNC (activate_menu), menu);
g_free (pixmap_name); g_free (pixmap_name);
return button;
}
static GtkWidget *
create_menu_widget (GtkWidget *window, char *arguments, char *menudir)
{
GtkWidget *menu;
int main_menu;
main_menu = (strcmp (arguments, ".") == 0);
menu = create_panel_menu (window, menudir, main_menu);
return menu; return menu;
} }
static void Menu *
set_show_small_icons(gpointer data, gpointer user_data) create_menu(GtkWidget *window, char *arguments, char *menudir,
MenuOrient orient)
{ {
GtkWidget *w = data; Menu *menu;
if (!w) { int main_menu;
g_warning("Internal error in set_show_small_icons (!w)");
return;
}
if (*(int *)user_data)
gtk_widget_show(w);
else
gtk_widget_hide(w);
}
static void
create_instance (PanelWidget *panel, char *params, int pos, int panelnum)
{
char *menu_base = gnome_unconditional_datadir_file ("apps"); char *menu_base = gnome_unconditional_datadir_file ("apps");
char *this_menu; char *this_menu;
char *p;
Menu *menu;
PanelCommand cmd;
int show_small_icons;
if (!getenv ("PATH"))
return;
if(!params)
return;
/*parse up the params*/ if (*arguments == '/')
p = strchr(params,':'); this_menu = g_strdup (arguments);
show_small_icons = TRUE;
if (p) {
*(p++)='\0';
if(*(p++)=='0')
show_small_icons = FALSE;
}
if (*params == '/')
this_menu = strdup (params);
else else
this_menu = g_concat_dir_and_file (menu_base, params); this_menu = g_concat_dir_and_file (menu_base, arguments);
if (!g_file_exists (this_menu)) { if (!g_file_exists (this_menu)) {
g_free (menu_base); g_free (menu_base);
g_free (this_menu); g_free (this_menu);
return; return NULL;
} }
gnome_folder = gnome_unconditional_pixmap_file ("gnome-folder-small.xpm"); if(!gnome_folder) {
gnome_folder = gnome_unconditional_pixmap_file
("gnome-folder-small.xpm");
if (!g_file_exists (gnome_folder)) { if (!g_file_exists (gnome_folder)) {
free (gnome_folder); free (gnome_folder);
gnome_folder = NULL; gnome_folder = NULL;
} }
}
menu = g_new(Menu,1); main_menu = (strcmp (arguments, ".") == 0);
menu->button = create_menu_widget (GTK_WIDGET(panel), params,
this_menu);
menu->path = g_strdup(params);
g_list_foreach(small_icons,set_show_small_icons, &show_small_icons); menu = create_panel_menu (window, menudir, main_menu, orient);
gtk_object_set_user_data(GTK_OBJECT(menu->button),menu); gtk_object_set_user_data(GTK_OBJECT(menu->button),menu);
cmd.cmd = PANEL_CMD_REGISTER_TOY; return menu;
cmd.params.register_toy.applet = menu->button; }
cmd.params.register_toy.id = APPLET_ID;
cmd.params.register_toy.pos = pos;
cmd.params.register_toy.panel = panelnum;
cmd.params.register_toy.flags = APPLET_HAS_PROPERTIES;
(*panel_cmd_func) (&cmd); static void
set_show_small_icons(gpointer data, gpointer user_data)
{
GtkWidget *w = data;
if (!w) {
g_warning("Internal error in set_show_small_icons (!w)");
return;
}
if (*(int *)user_data)
gtk_widget_show(w);
else
gtk_widget_hide(w);
} }
static void static void
set_orientation(GtkWidget *applet, PanelWidget *panel, PanelSnapped snapped) set_orientation(Menu *menu)
{ {
GtkWidget *pixmap; GtkWidget *pixmap;
char *pixmap_name; char *pixmap_name;
Menu *menu;
panel_snapped = snapped; /*FIXME: this should probably be in the structure*/
menu = gtk_object_get_user_data(GTK_OBJECT(applet));
if(!menu || !menu->path) if(!menu || !menu->path)
return; return;
if (strcmp (menu->path, ".") == 0) if (strcmp (menu->path, ".") == 0)
switch (panel_snapped) { switch (menu->orient) {
case PANEL_TOP: case MENU_DOWN:
pixmap_name = gnome_unconditional_pixmap_file( pixmap_name = gnome_unconditional_pixmap_file(
"gnome-menu-down.xpm"); "gnome-menu-down.xpm");
break; break;
case PANEL_FREE: case MENU_UP:
case PANEL_BOTTOM:
pixmap_name = gnome_unconditional_pixmap_file( pixmap_name = gnome_unconditional_pixmap_file(
"gnome-menu-up.xpm"); "gnome-menu-up.xpm");
break; break;
case PANEL_LEFT: case MENU_RIGHT:
pixmap_name = gnome_unconditional_pixmap_file( pixmap_name = gnome_unconditional_pixmap_file(
"gnome-menu-right.xpm"); "gnome-menu-right.xpm");
break; break;
case PANEL_RIGHT: case MENU_LEFT:
pixmap_name = gnome_unconditional_pixmap_file( pixmap_name = gnome_unconditional_pixmap_file(
"gnome-menu-left.xpm"); "gnome-menu-left.xpm");
break; break;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "panel_cmds.h" #include "panel_cmds.h"
#include "applet_cmds.h" #include "applet_cmds.h"
#include "panel.h" #include "panel.h"
#include "menu.h"
#include "panel_config.h" #include "panel_config.h"
...@@ -43,6 +44,10 @@ extern GList *applets; ...@@ -43,6 +44,10 @@ extern GList *applets;
extern GtkTooltips *panel_tooltips; extern GtkTooltips *panel_tooltips;
extern gint tooltips_enabled; extern gint tooltips_enabled;
/*FIXME: integrate with menu.[ch]*/
/*extern GtkMenu *root_menu;
extern GList *small_icons;*/
/*FIXME: a hack for current code to work*/ /*FIXME: a hack for current code to work*/
#define the_panel (PANEL_WIDGET(panels->data)) #define the_panel (PANEL_WIDGET(panels->data))
...@@ -353,6 +358,19 @@ panel_session_save (gpointer client_data, ...@@ -353,6 +358,19 @@ panel_session_save (gpointer client_data,
g_hash_table_foreach(applet_files_ht, destroy_applet_module, NULL); g_hash_table_foreach(applet_files_ht, destroy_applet_module, NULL);
applet_files_destroy(); applet_files_destroy();
gtk_widget_unref(applet_menu);
gtk_widget_unref(panel_tooltips);
/*FIXME: integrate with menu.[ch]*/
/*small_icons = NULL;*/ /*prevent searches through the g_list to speed
up this thing*/
/*FIXME: integrate with menu.[ch]*/
/*gtk_widget_unref(root_menu);*/
/*FIXME: unref all menus here */
/* Always successful. */ /* Always successful. */
return 1; return 1;
} }
...@@ -363,8 +381,6 @@ panel_quit(void) ...@@ -363,8 +381,6 @@ panel_quit(void)
if (! gnome_session_connected_p ()) if (! gnome_session_connected_p ())
{ {
panel_session_save (NULL, GNOME_SAVE_BOTH, 1, GNOME_INTERACT_NONE, 0); panel_session_save (NULL, GNOME_SAVE_BOTH, 1, GNOME_INTERACT_NONE, 0);
gtk_widget_unref(applet_menu);
gtk_widget_unref(panel_tooltips);
gtk_main_quit (); gtk_main_quit ();
/* We don't want to return, because we've probably been called from an /* 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 * applet which has since been dlclose()'d, and we'd end up with a SEGV
...@@ -376,8 +392,6 @@ panel_quit(void) ...@@ -376,8 +392,6 @@ panel_quit(void)
/* We request a completely interactive, full, slow shutdown. */ /* We request a completely interactive, full, slow shutdown. */
gnome_session_request_save (GNOME_SAVE_BOTH, 1, GNOME_INTERACT_ANY, gnome_session_request_save (GNOME_SAVE_BOTH, 1, GNOME_INTERACT_ANY,
0, 1); 0, 1);
gtk_widget_unref(applet_menu);
gtk_widget_unref(panel_tooltips);
} }
} }
......
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