1 | /* |
---|
2 | * GNOME panel menu module. |
---|
3 | * (C) 1997 The Free Software Foundation |
---|
4 | * |
---|
5 | * Authors: Miguel de Icaza |
---|
6 | * Federico Mena |
---|
7 | */ |
---|
8 | |
---|
9 | #include <config.h> |
---|
10 | #include <gnome.h> |
---|
11 | |
---|
12 | #include "panel-include.h" |
---|
13 | #include "multiscreen-stuff.h" |
---|
14 | |
---|
15 | /*#define PANEL_DEBUG 1*/ |
---|
16 | |
---|
17 | extern char *kde_menudir; |
---|
18 | extern char *kde_icondir; |
---|
19 | extern char *kde_mini_icondir; |
---|
20 | |
---|
21 | extern GlobalConfig global_config; |
---|
22 | |
---|
23 | GtkWidget * |
---|
24 | add_menu_separator (GtkWidget *menu) |
---|
25 | { |
---|
26 | GtkWidget *menuitem; |
---|
27 | |
---|
28 | menuitem = gtk_menu_item_new (); |
---|
29 | gtk_widget_set_sensitive (menuitem, FALSE); |
---|
30 | gtk_widget_show (menuitem); |
---|
31 | gtk_menu_append (GTK_MENU (menu), menuitem); |
---|
32 | |
---|
33 | return menuitem; |
---|
34 | } |
---|
35 | |
---|
36 | static void |
---|
37 | panel_standard_menu_pos (GtkMenu *menu, gint *x, gint *y, gpointer data) |
---|
38 | { |
---|
39 | gint screen_width; |
---|
40 | gint screen_height; |
---|
41 | int screen_basex, screen_basey; |
---|
42 | int screen; |
---|
43 | GtkRequisition requisition; |
---|
44 | |
---|
45 | gtk_widget_get_child_requisition (GTK_WIDGET (menu), |
---|
46 | &requisition); |
---|
47 | |
---|
48 | screen = multiscreen_screen_from_pos (*x, *y); |
---|
49 | |
---|
50 | if (screen < 0) { |
---|
51 | screen_width = gdk_screen_width (); |
---|
52 | screen_height = gdk_screen_height (); |
---|
53 | screen_basex = 0; |
---|
54 | screen_basey = 0; |
---|
55 | } else { |
---|
56 | screen_width = multiscreen_width (screen); |
---|
57 | screen_height = multiscreen_height (screen); |
---|
58 | screen_basex = multiscreen_x (screen); |
---|
59 | screen_basey = multiscreen_y (screen); |
---|
60 | } |
---|
61 | |
---|
62 | *x -= screen_basex; |
---|
63 | *y -= screen_basey; |
---|
64 | |
---|
65 | *x -= 2; |
---|
66 | *y -= 2; |
---|
67 | |
---|
68 | if ((*x + requisition.width) > screen_width) |
---|
69 | *x -= ((*x + requisition.width) - screen_width); |
---|
70 | if (*x < 0) |
---|
71 | *x = 0; |
---|
72 | if ((*y + requisition.height) > screen_height) |
---|
73 | *y -= ((*y + requisition.height) - screen_height); |
---|
74 | if (*y < 0) |
---|
75 | *y = 0; |
---|
76 | |
---|
77 | *x += screen_basex; |
---|
78 | *y += screen_basey; |
---|
79 | } |
---|
80 | |
---|
81 | void |
---|
82 | panel_menu_position (GtkMenu *menu, gint *x, gint *y, gpointer data) |
---|
83 | { |
---|
84 | GtkWidget *w = data; |
---|
85 | gint wx, wy; |
---|
86 | |
---|
87 | g_return_if_fail (w != NULL); |
---|
88 | |
---|
89 | if ( ! global_config.off_panel_popups) { |
---|
90 | panel_standard_menu_pos (menu, x, y, data); |
---|
91 | return; |
---|
92 | } |
---|
93 | |
---|
94 | gdk_window_get_origin (w->window, &wx, &wy); |
---|
95 | |
---|
96 | gtk_widget_get_pointer(w, x, y); |
---|
97 | if (IS_BASEP_WIDGET (w)) { |
---|
98 | basep_widget_get_menu_pos(BASEP_WIDGET(w), |
---|
99 | GTK_WIDGET(menu), |
---|
100 | x,y,wx,wy, |
---|
101 | w->allocation.width, |
---|
102 | w->allocation.height); |
---|
103 | } else if (IS_FOOBAR_WIDGET (w)) { |
---|
104 | GtkRequisition req; |
---|
105 | FoobarWidget *foo = FOOBAR_WIDGET (w); |
---|
106 | gtk_widget_get_child_requisition (GTK_WIDGET (menu), &req); |
---|
107 | *x = MIN (*x, |
---|
108 | multiscreen_width (foo->screen) + |
---|
109 | multiscreen_x (foo->screen) - req.width); |
---|
110 | *y = w->allocation.height + multiscreen_y (foo->screen); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | void |
---|
115 | applet_menu_position (GtkMenu *menu, gint *x, gint *y, gpointer data) |
---|
116 | { |
---|
117 | AppletInfo *info = data; |
---|
118 | int wx, wy; |
---|
119 | PanelWidget *panel; |
---|
120 | GtkWidget *w; /*the panel window widget*/ |
---|
121 | |
---|
122 | g_return_if_fail(info != NULL); |
---|
123 | g_return_if_fail(info->widget != NULL); |
---|
124 | |
---|
125 | panel = PANEL_WIDGET(info->widget->parent); |
---|
126 | g_return_if_fail(panel != NULL); |
---|
127 | |
---|
128 | w = panel->panel_parent; |
---|
129 | |
---|
130 | gdk_window_get_origin (info->widget->window, &wx, &wy); |
---|
131 | if(GTK_WIDGET_NO_WINDOW(info->widget)) { |
---|
132 | wx += info->widget->allocation.x; |
---|
133 | wy += info->widget->allocation.y; |
---|
134 | } |
---|
135 | if (IS_BASEP_WIDGET (w)) { |
---|
136 | *x = *y = 0; |
---|
137 | basep_widget_get_menu_pos(BASEP_WIDGET(w), |
---|
138 | GTK_WIDGET(menu), |
---|
139 | x,y,wx,wy, |
---|
140 | info->widget->allocation.width, |
---|
141 | info->widget->allocation.height); |
---|
142 | } else if (IS_FOOBAR_WIDGET (w)) { |
---|
143 | GtkRequisition req; |
---|
144 | FoobarWidget *foo = FOOBAR_WIDGET (w); |
---|
145 | gtk_widget_get_child_requisition (GTK_WIDGET (menu), &req); |
---|
146 | *x = MIN (*x, |
---|
147 | multiscreen_width (foo->screen) + |
---|
148 | multiscreen_x (foo->screen) - req.width); |
---|
149 | *y = w->allocation.height + multiscreen_y (foo->screen); |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | /* This function is marked as const as get_distribution_type is const and |
---|
154 | * it would never change while the program is running. If you change this |
---|
155 | * do remember to take out the G_GNUC_CONST in menu-util.h */ |
---|
156 | int |
---|
157 | get_default_menu_flags (void) |
---|
158 | { |
---|
159 | DistributionType distribution = get_distribution_type(); |
---|
160 | |
---|
161 | int flags = MAIN_MENU_SYSTEM_SUB | MAIN_MENU_USER_SUB | |
---|
162 | MAIN_MENU_APPLETS_SUB | MAIN_MENU_PANEL_SUB | |
---|
163 | MAIN_MENU_DESKTOP; |
---|
164 | |
---|
165 | /*guess distribution menus*/ |
---|
166 | if(distribution != DISTRIBUTION_UNKNOWN) |
---|
167 | flags |= MAIN_MENU_DISTRIBUTION_SUB; |
---|
168 | |
---|
169 | /*guess KDE menus*/ |
---|
170 | if (panel_file_exists (kde_menudir)) |
---|
171 | flags |= MAIN_MENU_KDE_SUB; |
---|
172 | |
---|
173 | return flags; |
---|
174 | } |
---|