1 | /* Gnome panel: border widget |
---|
2 | * (C) 1999 the Free Software Foundation |
---|
3 | * |
---|
4 | * Authors: Jacob Berkman |
---|
5 | * George Lebl |
---|
6 | */ |
---|
7 | |
---|
8 | #include "config.h" |
---|
9 | |
---|
10 | #include "border-widget.h" |
---|
11 | #include "panel_config_global.h" |
---|
12 | #include "multiscreen-stuff.h" |
---|
13 | |
---|
14 | extern GlobalConfig global_config; |
---|
15 | extern int pw_minimized_size; |
---|
16 | |
---|
17 | static void border_pos_class_init (BorderPosClass *klass); |
---|
18 | static void border_pos_init (BorderPos *pos); |
---|
19 | |
---|
20 | static void border_pos_set_hidebuttons (BasePWidget *basep); |
---|
21 | static PanelOrientType border_pos_get_applet_orient (BasePWidget *basep); |
---|
22 | |
---|
23 | static PanelOrientType border_pos_get_hide_orient (BasePWidget *basep); |
---|
24 | |
---|
25 | static void border_pos_get_menu_pos (BasePWidget *basep, |
---|
26 | GtkWidget *widget, |
---|
27 | GtkRequisition *mreq, |
---|
28 | int *x, int *y, |
---|
29 | int wx, int wy, |
---|
30 | int ww, int wh); |
---|
31 | |
---|
32 | static void border_pos_show_hide_left (BasePWidget *basep); |
---|
33 | static void border_pos_show_hide_right (BasePWidget *basep); |
---|
34 | |
---|
35 | static void border_pos_pre_convert_hook (BasePWidget *basep); |
---|
36 | |
---|
37 | static BasePPosClass *parent_class; |
---|
38 | |
---|
39 | GtkType |
---|
40 | border_pos_get_type (void) |
---|
41 | { |
---|
42 | static GtkType border_pos_type = 0; |
---|
43 | |
---|
44 | if (!border_pos_type) { |
---|
45 | GtkTypeInfo border_pos_info = { |
---|
46 | "BorderPos", |
---|
47 | sizeof (BorderPos), |
---|
48 | sizeof (BorderPosClass), |
---|
49 | (GtkClassInitFunc) border_pos_class_init, |
---|
50 | (GtkObjectInitFunc) border_pos_init, |
---|
51 | NULL, NULL |
---|
52 | }; |
---|
53 | |
---|
54 | border_pos_type = gtk_type_unique (TYPE_BASEP_POS, |
---|
55 | &border_pos_info); |
---|
56 | } |
---|
57 | |
---|
58 | return border_pos_type; |
---|
59 | } |
---|
60 | |
---|
61 | enum { |
---|
62 | EDGE_CHANGE_SIGNAL, |
---|
63 | LAST_SIGNAL |
---|
64 | }; |
---|
65 | |
---|
66 | static guint border_pos_signals[LAST_SIGNAL] = { 0 }; |
---|
67 | |
---|
68 | static void |
---|
69 | border_pos_class_init (BorderPosClass *klass) |
---|
70 | { |
---|
71 | GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); |
---|
72 | BasePPosClass *pos_class = BASEP_POS_CLASS(klass); |
---|
73 | |
---|
74 | parent_class = gtk_type_class(TYPE_BASEP_POS); |
---|
75 | |
---|
76 | /* set up signals */ |
---|
77 | border_pos_signals[EDGE_CHANGE_SIGNAL] = |
---|
78 | gtk_signal_new("edge_change", |
---|
79 | GTK_RUN_LAST, |
---|
80 | object_class->type, |
---|
81 | GTK_SIGNAL_OFFSET(BorderPosClass, |
---|
82 | edge_change), |
---|
83 | gtk_marshal_NONE__ENUM, |
---|
84 | GTK_TYPE_NONE, 1, |
---|
85 | GTK_TYPE_ENUM); |
---|
86 | |
---|
87 | gtk_object_class_add_signals (object_class, |
---|
88 | border_pos_signals, |
---|
89 | LAST_SIGNAL); |
---|
90 | |
---|
91 | /* fill out the virtual funcs */ |
---|
92 | pos_class->set_hidebuttons = border_pos_set_hidebuttons; |
---|
93 | pos_class->get_applet_orient = border_pos_get_applet_orient; |
---|
94 | pos_class->get_hide_orient = border_pos_get_hide_orient; |
---|
95 | pos_class->get_menu_pos = border_pos_get_menu_pos; |
---|
96 | |
---|
97 | pos_class->north_clicked = pos_class->west_clicked = |
---|
98 | border_pos_show_hide_left; |
---|
99 | pos_class->south_clicked = pos_class->east_clicked = |
---|
100 | border_pos_show_hide_right; |
---|
101 | pos_class->pre_convert_hook = border_pos_pre_convert_hook; |
---|
102 | } |
---|
103 | |
---|
104 | static void |
---|
105 | border_pos_init (BorderPos *pos) |
---|
106 | { |
---|
107 | pos->edge = BORDER_TOP; |
---|
108 | } |
---|
109 | |
---|
110 | static void |
---|
111 | border_pos_set_hidebuttons (BasePWidget *basep) |
---|
112 | { |
---|
113 | if (PANEL_WIDGET(basep->panel)->orient == PANEL_HORIZONTAL) { |
---|
114 | gtk_widget_hide(basep->hidebutton_n); |
---|
115 | gtk_widget_show(basep->hidebutton_e); |
---|
116 | gtk_widget_show(basep->hidebutton_w); |
---|
117 | gtk_widget_hide(basep->hidebutton_s); |
---|
118 | } else { /*vertical*/ |
---|
119 | gtk_widget_show(basep->hidebutton_n); |
---|
120 | gtk_widget_hide(basep->hidebutton_e); |
---|
121 | gtk_widget_hide(basep->hidebutton_w); |
---|
122 | gtk_widget_show(basep->hidebutton_s); |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | static PanelOrientType |
---|
127 | border_pos_get_applet_orient (BasePWidget *basep) |
---|
128 | { |
---|
129 | BorderPos *pos = BORDER_POS(basep->pos); |
---|
130 | |
---|
131 | switch (pos->edge) { |
---|
132 | case BORDER_TOP: return ORIENT_DOWN; |
---|
133 | case BORDER_RIGHT: return ORIENT_LEFT; |
---|
134 | case BORDER_BOTTOM: return ORIENT_UP; |
---|
135 | case BORDER_LEFT: return ORIENT_RIGHT; |
---|
136 | default: return ORIENT_UP; |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | static PanelOrientType |
---|
141 | border_pos_get_hide_orient (BasePWidget *basep) |
---|
142 | { |
---|
143 | BorderPos *pos = BORDER_POS (basep->pos); |
---|
144 | PanelWidget *panel = PANEL_WIDGET (basep->panel); |
---|
145 | |
---|
146 | switch (basep->state) { |
---|
147 | case BASEP_AUTO_HIDDEN: |
---|
148 | switch (pos->edge) { |
---|
149 | case BORDER_TOP: return ORIENT_UP; |
---|
150 | case BORDER_RIGHT: return ORIENT_RIGHT; |
---|
151 | case BORDER_LEFT: return ORIENT_LEFT; |
---|
152 | case BORDER_BOTTOM: return ORIENT_DOWN; |
---|
153 | } |
---|
154 | g_assert_not_reached (); |
---|
155 | break; |
---|
156 | case BASEP_HIDDEN_LEFT: |
---|
157 | return (panel->orient == PANEL_HORIZONTAL) |
---|
158 | ? ORIENT_LEFT : ORIENT_UP; |
---|
159 | case BASEP_HIDDEN_RIGHT: |
---|
160 | return (panel->orient == PANEL_HORIZONTAL) |
---|
161 | ? ORIENT_RIGHT : ORIENT_DOWN; |
---|
162 | default: |
---|
163 | g_assert_not_reached (); |
---|
164 | break; |
---|
165 | } |
---|
166 | g_assert_not_reached (); |
---|
167 | return ORIENT_LEFT; |
---|
168 | } |
---|
169 | |
---|
170 | static void |
---|
171 | border_pos_get_menu_pos (BasePWidget *basep, |
---|
172 | GtkWidget *widget, |
---|
173 | GtkRequisition *mreq, |
---|
174 | int *x, int *y, |
---|
175 | int wx, int wy, |
---|
176 | int ww, int wh) |
---|
177 | { |
---|
178 | switch (BORDER_POS(basep->pos)->edge) { |
---|
179 | case BORDER_TOP: |
---|
180 | *x += wx; |
---|
181 | *y = wy + wh; |
---|
182 | break; |
---|
183 | case BORDER_RIGHT: |
---|
184 | *x = wx - mreq->width; |
---|
185 | *y += wy; |
---|
186 | break; |
---|
187 | case BORDER_BOTTOM: |
---|
188 | *x += wx; |
---|
189 | *y = wy - mreq->height; |
---|
190 | break; |
---|
191 | case BORDER_LEFT: |
---|
192 | *x = wx + ww; |
---|
193 | *y += wy; |
---|
194 | break; |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | void |
---|
199 | border_widget_change_params (BorderWidget *border, |
---|
200 | int screen, |
---|
201 | BorderEdge edge, |
---|
202 | int sz, |
---|
203 | BasePMode mode, |
---|
204 | BasePState state, |
---|
205 | BasePLevel level, |
---|
206 | gboolean avoid_on_maximize, |
---|
207 | gboolean hidebuttons_enabled, |
---|
208 | gboolean hidebutton_pixmaps_enabled, |
---|
209 | PanelBackType back_type, |
---|
210 | char *pixmap_name, |
---|
211 | gboolean fit_pixmap_bg, |
---|
212 | gboolean strech_pixmap_bg, |
---|
213 | gboolean rotate_pixmap_bg, |
---|
214 | GdkColor *back_color) |
---|
215 | { |
---|
216 | PanelOrientation new_orient; |
---|
217 | g_return_if_fail (GTK_WIDGET_REALIZED (GTK_WIDGET (border))); |
---|
218 | |
---|
219 | new_orient = (edge == BORDER_TOP || |
---|
220 | edge == BORDER_BOTTOM) |
---|
221 | ? PANEL_HORIZONTAL |
---|
222 | : PANEL_VERTICAL; |
---|
223 | |
---|
224 | if (edge != BORDER_POS (border->pos)->edge) { |
---|
225 | BORDER_POS(border->pos)->edge = edge; |
---|
226 | gtk_signal_emit (GTK_OBJECT (border->pos), |
---|
227 | border_pos_signals[EDGE_CHANGE_SIGNAL], |
---|
228 | edge); |
---|
229 | } |
---|
230 | |
---|
231 | basep_widget_change_params (BASEP_WIDGET (border), |
---|
232 | screen, |
---|
233 | new_orient, |
---|
234 | sz, |
---|
235 | mode, |
---|
236 | state, |
---|
237 | level, |
---|
238 | avoid_on_maximize, |
---|
239 | hidebuttons_enabled, |
---|
240 | hidebutton_pixmaps_enabled, |
---|
241 | back_type, |
---|
242 | pixmap_name, |
---|
243 | fit_pixmap_bg, |
---|
244 | strech_pixmap_bg, |
---|
245 | rotate_pixmap_bg, |
---|
246 | back_color); |
---|
247 | } |
---|
248 | |
---|
249 | static void |
---|
250 | border_pos_show_hide_left (BasePWidget *basep) |
---|
251 | { |
---|
252 | switch (basep->state) { |
---|
253 | case BASEP_SHOWN: |
---|
254 | basep_widget_explicit_hide (basep, BASEP_HIDDEN_LEFT); |
---|
255 | break; |
---|
256 | case BASEP_HIDDEN_RIGHT: |
---|
257 | basep_widget_explicit_show (basep); |
---|
258 | break; |
---|
259 | default: |
---|
260 | break; |
---|
261 | } |
---|
262 | } |
---|
263 | |
---|
264 | |
---|
265 | static void |
---|
266 | border_pos_show_hide_right (BasePWidget *basep) |
---|
267 | { |
---|
268 | switch (basep->state) { |
---|
269 | case BASEP_SHOWN: |
---|
270 | basep_widget_explicit_hide (basep, BASEP_HIDDEN_RIGHT); |
---|
271 | break; |
---|
272 | case BASEP_HIDDEN_LEFT: |
---|
273 | basep_widget_explicit_show (basep); |
---|
274 | break; |
---|
275 | default: |
---|
276 | break; |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | static void |
---|
281 | border_pos_pre_convert_hook (BasePWidget *basep) |
---|
282 | { |
---|
283 | basep->keep_in_screen = TRUE; |
---|
284 | PANEL_WIDGET (basep->panel)->packed = TRUE; |
---|
285 | } |
---|
286 | |
---|
287 | void |
---|
288 | border_widget_change_edge (BorderWidget *border, BorderEdge edge) |
---|
289 | { |
---|
290 | BasePWidget *basep = BASEP_WIDGET (border); |
---|
291 | PanelWidget *panel = PANEL_WIDGET (basep->panel); |
---|
292 | |
---|
293 | if (BORDER_POS (border->pos)->edge == edge) |
---|
294 | return; |
---|
295 | |
---|
296 | border_widget_change_params (border, |
---|
297 | basep->screen, |
---|
298 | edge, |
---|
299 | panel->sz, |
---|
300 | basep->mode, |
---|
301 | basep->state, |
---|
302 | basep->level, |
---|
303 | basep->avoid_on_maximize, |
---|
304 | basep->hidebuttons_enabled, |
---|
305 | basep->hidebutton_pixmaps_enabled, |
---|
306 | panel->back_type, |
---|
307 | panel->back_pixmap, |
---|
308 | panel->fit_pixmap_bg, |
---|
309 | panel->strech_pixmap_bg, |
---|
310 | panel->rotate_pixmap_bg, |
---|
311 | &panel->back_color); |
---|
312 | |
---|
313 | } |
---|
314 | |
---|
315 | GtkWidget * |
---|
316 | border_widget_construct (BorderWidget *border, |
---|
317 | int screen, |
---|
318 | BorderEdge edge, |
---|
319 | gboolean packed, |
---|
320 | gboolean reverse_arrows, |
---|
321 | int sz, |
---|
322 | BasePMode mode, |
---|
323 | BasePState state, |
---|
324 | BasePLevel level, |
---|
325 | gboolean avoid_on_maximize, |
---|
326 | gboolean hidebuttons_enabled, |
---|
327 | gboolean hidebutton_pixmaps_enabled, |
---|
328 | PanelBackType back_type, |
---|
329 | char *back_pixmap, |
---|
330 | gboolean fit_pixmap_bg, |
---|
331 | gboolean strech_pixmap_bg, |
---|
332 | gboolean rotate_pixmap_bg, |
---|
333 | GdkColor *back_color) |
---|
334 | { |
---|
335 | BasePWidget *basep = BASEP_WIDGET (border); |
---|
336 | PanelOrientation orient; |
---|
337 | |
---|
338 | if (edge == BORDER_TOP || |
---|
339 | edge == BORDER_BOTTOM) |
---|
340 | orient = PANEL_HORIZONTAL; |
---|
341 | else |
---|
342 | orient = PANEL_VERTICAL; |
---|
343 | |
---|
344 | BORDER_POS (basep->pos)->edge = edge; |
---|
345 | basep->keep_in_screen = TRUE; |
---|
346 | |
---|
347 | basep_widget_construct (basep, |
---|
348 | packed, |
---|
349 | reverse_arrows, |
---|
350 | screen, |
---|
351 | orient, |
---|
352 | sz, |
---|
353 | mode, |
---|
354 | state, |
---|
355 | level, |
---|
356 | avoid_on_maximize, |
---|
357 | hidebuttons_enabled, |
---|
358 | hidebutton_pixmaps_enabled, |
---|
359 | back_type, |
---|
360 | back_pixmap, |
---|
361 | fit_pixmap_bg, |
---|
362 | strech_pixmap_bg, |
---|
363 | rotate_pixmap_bg, |
---|
364 | back_color); |
---|
365 | |
---|
366 | return GTK_WIDGET (basep); |
---|
367 | } |
---|