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

clean up menu positioning code, so that there is only one function

Sat Aug 29 14:58:38 1998  George Lebl  <jirka@5z.com>

        * panel-util.[ch],menu.c,applet.c,panel.c: clean up menu
          positioning code, so that there is only one function
parent 0869f046
Sat Aug 29 14:58:38 1998 George Lebl <jirka@5z.com>
* panel-util.[ch],menu.c,applet.c,panel.c: clean up menu
positioning code, so that there is only one function
Sat Aug 29 02:13:50 1998 George Lebl <jirka@5z.com>
* menu.c: cleanup of orient stuff
......
Sat Aug 29 14:58:38 1998 George Lebl <jirka@5z.com>
* panel-util.[ch],menu.c,applet.c,panel.c: clean up menu
positioning code, so that there is only one function
Sat Aug 29 02:13:50 1998 George Lebl <jirka@5z.com>
* menu.c: cleanup of orient stuff
......
......@@ -366,97 +366,6 @@ create_applet_menu(AppletInfo *info)
info->widget);
}
void
applet_menu_position (GtkMenu *menu, int *x, int *y, gpointer data)
{
int wx, wy;
AppletInfo *info = get_applet_info(GPOINTER_TO_INT(data));
PanelWidget *panel;
GtkWidget *w; /*the panel window widget*/
g_return_if_fail(info != NULL);
g_return_if_fail(info->widget != NULL);
panel = gtk_object_get_data(GTK_OBJECT(info->widget),
PANEL_APPLET_PARENT_KEY);
g_return_if_fail(panel != NULL);
w = gtk_object_get_data(GTK_OBJECT(panel), PANEL_PARENT);
gdk_window_get_origin (info->widget->window, &wx, &wy);
if(GTK_WIDGET_NO_WINDOW(info->widget)) {
wx += info->widget->allocation.x;
wy += info->widget->allocation.y;
}
if(IS_DRAWER_WIDGET(w)) {
if(panel->orient==PANEL_VERTICAL) {
*x = wx + info->widget->allocation.width;
*y = wy;
} else {
*x = wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
}
} else if(IS_SNAPPED_WIDGET(w)) {
switch(SNAPPED_WIDGET(w)->pos) {
case SNAPPED_BOTTOM:
*x = wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
break;
case SNAPPED_TOP:
*x = wx;
*y = wy + info->widget->allocation.height;
break;
case SNAPPED_LEFT:
*x = wx + info->widget->allocation.width;
*y = wy;
break;
case SNAPPED_RIGHT:
*x = wx - GTK_WIDGET (menu)->requisition.width;
*y = wy;
break;
}
} else if(IS_CORNER_WIDGET(w)) {
if(panel->orient==PANEL_HORIZONTAL) {
switch(CORNER_WIDGET(w)->pos) {
case CORNER_SE:
case CORNER_SW:
*x = wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
break;
case CORNER_NE:
case CORNER_NW:
*x = wx;
*y = wy + info->widget->allocation.height;
break;
}
} else {
switch(CORNER_WIDGET(w)->pos) {
case CORNER_NW:
case CORNER_SW:
*x = wx + info->widget->allocation.width;
*y = wy;
break;
case CORNER_NE:
case CORNER_SE:
*x = wx - GTK_WIDGET (menu)->requisition.width;
*y = wy;
break;
}
}
}
if(*x + GTK_WIDGET (menu)->requisition.width > gdk_screen_width())
*x=gdk_screen_width() - GTK_WIDGET (menu)->requisition.width;
if(*x < 0) *x =0;
if(*y + GTK_WIDGET (menu)->requisition.height > gdk_screen_height())
*y=gdk_screen_height() - GTK_WIDGET (menu)->requisition.height;
if(*y < 0) *y =0;
}
void
show_applet_menu(int applet_id, GdkEventButton *event)
{
......
......@@ -64,8 +64,6 @@ void applet_add_callback(int applet_id,
char *menuitem_text);
void applet_remove_callback(int applet_id,
char *callback_name);
void applet_menu_position (GtkMenu *menu, int *x, int *y,
gpointer data);
void show_applet_menu(int applet_id, GdkEventButton *event);
#define get_applet_info(applet_id) \
......
......@@ -1024,43 +1024,6 @@ create_menu_at (GtkWidget *menu,
return menu;
}
void
menu_position (GtkMenu *menu, int *x, int *y, gpointer data)
{
Menu * menup = data;
GtkWidget *widget = menup->button;
int wx, wy;
gdk_window_get_origin (widget->window, &wx, &wy);
switch(BUTTON_WIDGET(widget)->orient) {
case ORIENT_DOWN:
*x = wx;
*y = wy + widget->allocation.height;
break;
case ORIENT_UP:
*x = wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
break;
case ORIENT_RIGHT:
*x = wx + widget->allocation.width;
*y = wy;
break;
case ORIENT_LEFT:
*x = wx - GTK_WIDGET (menu)->requisition.width;
*y = wy;
break;
}
if(*x + GTK_WIDGET (menu)->requisition.width > gdk_screen_width())
*x=gdk_screen_width() - GTK_WIDGET (menu)->requisition.width;
if(*x < 0) *x =0;
if(*y + GTK_WIDGET (menu)->requisition.height > gdk_screen_height())
*y=gdk_screen_height() - GTK_WIDGET (menu)->requisition.height;
if(*y < 0) *y =0;
}
static void
destroy_menu (GtkWidget *widget, gpointer data)
{
......@@ -1519,6 +1482,8 @@ menu_button_pressed(GtkWidget *widget, gpointer data)
Menu *menu = data;
GdkEventButton *bevent = (GdkEventButton*)gtk_get_current_event();
GtkWidget *wpanel = get_panel_parent(menu->button);
int applet_id = gtk_object_get_data(GTK_OBJECT(menu->button),
"applet_id");
int main_menu = (strcmp (menu->path, ".") == 0);
check_and_reread(menu->menu,menu,main_menu);
......@@ -1538,8 +1503,9 @@ menu_button_pressed(GtkWidget *widget, gpointer data)
BUTTON_WIDGET(menu->button)->ignore_leave = TRUE;
gtk_grab_remove(menu->button);
gtk_menu_popup(GTK_MENU(menu->menu), 0,0, menu_position,
data, bevent->button, bevent->time);
gtk_menu_popup(GTK_MENU(menu->menu), 0,0, applet_menu_position,
GINT_TO_POINTER(applet_id),
bevent->button, bevent->time);
}
static char *
......
......@@ -3,7 +3,10 @@
#include <glib.h>
#include <fcntl.h>
#include "panel-util.h"
#include "panel-include.h"
extern GArray *applets;
extern int applet_count;
/* this function might be a slight overkill, but it should work
perfect, hopefully it should be 100% buffer overrun safe too*/
......@@ -301,3 +304,123 @@ my_g_list_pop_first(GList *list)
g_list_free(list);
return r;
}
static void
get_menu_position (GtkMenu *menu, int *x, int *y,
int wx, int wy, int ww, int wh,
GtkWidget *pwidget)
{
if(IS_DRAWER_WIDGET(pwidget)) {
PanelWidget *panel =
PANEL_WIDGET(DRAWER_WIDGET(pwidget)->panel);
if(panel->orient==PANEL_VERTICAL) {
*x = wx + ww;
*y += wy;
} else {
*x += wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
}
} else if(IS_SNAPPED_WIDGET(pwidget)) {
switch(SNAPPED_WIDGET(pwidget)->pos) {
case SNAPPED_BOTTOM:
*x += wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
break;
case SNAPPED_TOP:
*x += wx;
*y = wy + wh;
break;
case SNAPPED_LEFT:
*x = wx + ww;
*y += wy;
break;
case SNAPPED_RIGHT:
*x = wx - GTK_WIDGET (menu)->requisition.width;
*y += wy;
break;
}
} else if(IS_CORNER_WIDGET(pwidget)) {
PanelWidget *panel =
PANEL_WIDGET(CORNER_WIDGET(pwidget)->panel);
if(panel->orient==PANEL_HORIZONTAL) {
switch(CORNER_WIDGET(pwidget)->pos) {
case CORNER_SE:
case CORNER_SW:
*x += wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
break;
case CORNER_NE:
case CORNER_NW:
*x += wx;
*y = wy + wh;
break;
}
} else {
switch(CORNER_WIDGET(pwidget)->pos) {
case CORNER_NW:
case CORNER_SW:
*x = wx + ww;
*y += wy;
break;
case CORNER_NE:
case CORNER_SE:
*x = wx - GTK_WIDGET (menu)->requisition.width;
*y += wy;
break;
}
}
}
if(*x + GTK_WIDGET (menu)->requisition.width > gdk_screen_width())
*x=gdk_screen_width() - GTK_WIDGET (menu)->requisition.width;
if(*x < 0) *x =0;
if(*y + GTK_WIDGET (menu)->requisition.height > gdk_screen_height())
*y=gdk_screen_height() - GTK_WIDGET (menu)->requisition.height;
if(*y < 0) *y =0;
}
void
panel_menu_position (GtkMenu *menu, int *x, int *y, gpointer data)
{
GtkWidget *w = data;
int wx, wy;
g_return_if_fail(w != NULL);
gdk_window_get_origin (w->window, &wx, &wy);
gtk_widget_get_pointer(w, x, y);
get_menu_position(menu,x,y,wx,wy,w->allocation.width,w->allocation.height,w);
}
void
applet_menu_position (GtkMenu *menu, int *x, int *y, gpointer data)
{
int wx, wy;
AppletInfo *info = get_applet_info(GPOINTER_TO_INT(data));
PanelWidget *panel;
GtkWidget *w; /*the panel window widget*/
g_return_if_fail(info != NULL);
g_return_if_fail(info->widget != NULL);
panel = gtk_object_get_data(GTK_OBJECT(info->widget),
PANEL_APPLET_PARENT_KEY);
g_return_if_fail(panel != NULL);
w = gtk_object_get_data(GTK_OBJECT(panel), PANEL_PARENT);
gdk_window_get_origin (info->widget->window, &wx, &wy);
if(GTK_WIDGET_NO_WINDOW(info->widget)) {
wx += info->widget->allocation.x;
wy += info->widget->allocation.y;
}
*x = *y = 0;
get_menu_position(menu,x,y,wx,wy,
info->widget->allocation.width,
info->widget->allocation.height,
w);
}
......@@ -39,6 +39,11 @@ void move_resize_window(GtkWidget *widget, int x, int y, int w, int h);
queues one*/
void resize_window(GtkWidget *widget, int w, int h);
void applet_menu_position (GtkMenu *menu, int *x, int *y, gpointer data);
void panel_menu_position (GtkMenu *menu, int *x, int *y, gpointer data);
END_GNOME_DECLS
#endif
......@@ -544,94 +544,6 @@ panel_applet_removed(GtkWidget *widget, GtkWidget *applet, gpointer data)
GINT_TO_POINTER(applet_id));
}
static void
panel_menu_position (GtkMenu *menu, int *x, int *y, gpointer data)
{
GtkWidget *w = data;
int wx, wy;
g_return_if_fail(w != NULL);
gdk_window_get_origin (w->window, &wx, &wy);
if(IS_DRAWER_WIDGET(w)) {
PanelWidget *panel = PANEL_WIDGET(DRAWER_WIDGET(w)->panel);
if(panel->orient==PANEL_VERTICAL) {
gtk_widget_get_pointer(w, NULL, y);
*x = wx + w->allocation.width;
*y += wy;
} else {
gtk_widget_get_pointer(w, x, NULL);
*x += wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
}
} else if(IS_SNAPPED_WIDGET(w)) {
switch(SNAPPED_WIDGET(w)->pos) {
case SNAPPED_BOTTOM:
gtk_widget_get_pointer(w, x, NULL);
*x += wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
break;
case SNAPPED_TOP:
gtk_widget_get_pointer(w, x, NULL);
*x += wx;
*y = wy + w->allocation.height;
break;
case SNAPPED_LEFT:
gtk_widget_get_pointer(w, NULL, y);
*x = wx + w->allocation.width;
*y += wy;
break;
case SNAPPED_RIGHT:
gtk_widget_get_pointer(w, NULL, y);
*x = wx - GTK_WIDGET (menu)->requisition.width;
*y += wy;
break;
}
} else if(IS_CORNER_WIDGET(w)) {
PanelWidget *panel = PANEL_WIDGET(CORNER_WIDGET(w)->panel);
if(panel->orient==PANEL_HORIZONTAL) {
switch(CORNER_WIDGET(w)->pos) {
case CORNER_NE:
case CORNER_NW:
gtk_widget_get_pointer(w, x, NULL);
*x += wx;
*y = wy + w->allocation.height;
break;
case CORNER_SE:
case CORNER_SW:
gtk_widget_get_pointer(w, x, NULL);
*x += wx;
*y = wy - GTK_WIDGET (menu)->requisition.height;
break;
}
} else { /*vertical*/
switch(CORNER_WIDGET(w)->pos) {
case CORNER_NE:
case CORNER_SE:
gtk_widget_get_pointer(w, NULL, y);
*x = wx - GTK_WIDGET (menu)->requisition.width;
*y += wy;
break;
case CORNER_SW:
case CORNER_NW:
gtk_widget_get_pointer(w, NULL, y);
*x = wx + w->allocation.width;
*y += wy;
break;
}
}
}
if(*x + GTK_WIDGET (menu)->requisition.width > gdk_screen_width())
*x=gdk_screen_width() - GTK_WIDGET (menu)->requisition.width;
if(*x < 0) *x =0;
if(*y + GTK_WIDGET (menu)->requisition.height > gdk_screen_height())
*y=gdk_screen_height() - GTK_WIDGET (menu)->requisition.height;
if(*y < 0) *y =0;
}
static void
menu_deactivate(GtkWidget *w, GtkWidget *panel)
{
......
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