add suppot for showing pixmap masks in menus where the rgba icons go too
[dana/openbox.git] / openbox / menuframe.c
1 #include "menuframe.h"
2 #include "client.h"
3 #include "menu.h"
4 #include "screen.h"
5 #include "grab.h"
6 #include "openbox.h"
7 #include "render/theme.h"
8
9 #define PADDING 2
10 #define SEPARATOR_HEIGHT 5
11
12 #define FRAME_EVENTMASK (ButtonPressMask |ButtonMotionMask | EnterWindowMask |\
13                          LeaveWindowMask)
14 #define TITLE_EVENTMASK (ButtonPressMask | ButtonMotionMask)
15 #define ENTRY_EVENTMASK (EnterWindowMask | LeaveWindowMask | \
16                          ButtonPressMask | ButtonReleaseMask)
17
18 GList *menu_frame_visible;
19
20 static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
21                                               ObMenuFrame *frame);
22 static void menu_entry_frame_free(ObMenuEntryFrame *self);
23 static void menu_frame_render(ObMenuFrame *self);
24 static void menu_frame_update(ObMenuFrame *self);
25
26 static Window createWindow(Window parent, unsigned long mask,
27                            XSetWindowAttributes *attrib)
28 {
29     return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0,
30                          RrDepth(ob_rr_inst), InputOutput,
31                          RrVisual(ob_rr_inst), mask, attrib);
32                        
33 }
34
35 ObMenuFrame* menu_frame_new(ObMenu *menu, ObClient *client)
36 {
37     ObMenuFrame *self;
38     XSetWindowAttributes attr;
39
40     self = g_new0(ObMenuFrame, 1);
41     self->type = Window_Menu;
42     self->menu = menu;
43     self->selected = NULL;
44     self->show_title = TRUE;
45     self->client = client;
46
47     attr.event_mask = FRAME_EVENTMASK;
48     self->window = createWindow(RootWindow(ob_display, ob_screen),
49                                    CWEventMask, &attr);
50     attr.event_mask = TITLE_EVENTMASK;
51     self->title = createWindow(self->window, CWEventMask, &attr);
52     self->items = createWindow(self->window, 0, NULL);
53
54     XMapWindow(ob_display, self->items);
55
56     self->a_title = RrAppearanceCopy(ob_rr_theme->a_menu_title);
57     self->a_items = RrAppearanceCopy(ob_rr_theme->a_menu);
58
59     stacking_add(MENU_AS_WINDOW(self));
60
61     return self;
62 }
63
64 void menu_frame_free(ObMenuFrame *self)
65 {
66     if (self) {
67         while (self->entries) {
68             menu_entry_frame_free(self->entries->data);
69             self->entries = g_list_delete_link(self->entries, self->entries);
70         }
71
72         stacking_remove(MENU_AS_WINDOW(self));
73
74         XDestroyWindow(ob_display, self->items);
75         XDestroyWindow(ob_display, self->title);
76         XDestroyWindow(ob_display, self->window);
77
78         RrAppearanceFree(self->a_items);
79         RrAppearanceFree(self->a_title);
80
81         g_free(self);
82     }
83 }
84
85 static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
86                                               ObMenuFrame *frame)
87 {
88     ObMenuEntryFrame *self;
89     XSetWindowAttributes attr;
90
91     self = g_new0(ObMenuEntryFrame, 1);
92     self->entry = entry;
93     self->frame = frame;
94
95     attr.event_mask = ENTRY_EVENTMASK;
96     self->window = createWindow(self->frame->items, CWEventMask, &attr);
97     self->icon = createWindow(self->window, 0, NULL);
98     self->text = createWindow(self->window, 0, NULL);
99     self->bullet = createWindow(self->window, 0, NULL);
100
101     XMapWindow(ob_display, self->window);
102     XMapWindow(ob_display, self->text);
103
104     self->a_normal = RrAppearanceCopy(ob_rr_theme->a_menu_item);
105     self->a_disabled = RrAppearanceCopy(ob_rr_theme->a_menu_disabled);
106     self->a_selected = RrAppearanceCopy(ob_rr_theme->a_menu_hilite);
107
108     self->a_icon = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
109     self->a_icon->texture[0].type = RR_TEXTURE_RGBA;
110     self->a_mask = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
111     self->a_mask->texture[0].type = RR_TEXTURE_MASK;
112     self->a_bullet = RrAppearanceCopy(ob_rr_theme->a_menu_bullet);
113
114     self->a_text_normal =
115         RrAppearanceCopy(ob_rr_theme->a_menu_text_item);
116     self->a_text_disabled =
117         RrAppearanceCopy(ob_rr_theme->a_menu_text_disabled);
118     self->a_text_selected =
119         RrAppearanceCopy(ob_rr_theme->a_menu_text_hilite);
120
121     return self;
122 }
123
124 static void menu_entry_frame_free(ObMenuEntryFrame *self)
125 {
126     if (self) {
127         XDestroyWindow(ob_display, self->icon);
128         XDestroyWindow(ob_display, self->text);
129         XDestroyWindow(ob_display, self->bullet);
130         XDestroyWindow(ob_display, self->window);
131
132         RrAppearanceFree(self->a_normal);
133         RrAppearanceFree(self->a_disabled);
134         RrAppearanceFree(self->a_selected);
135
136         RrAppearanceFree(self->a_icon);
137         RrAppearanceFree(self->a_mask);
138         RrAppearanceFree(self->a_text_normal);
139         RrAppearanceFree(self->a_text_disabled);
140         RrAppearanceFree(self->a_text_selected);
141         RrAppearanceFree(self->a_bullet);
142
143         g_free(self);
144     }
145 }
146
147 void menu_frame_move(ObMenuFrame *self, gint x, gint y)
148 {
149     RECT_SET_POINT(self->area, x, y);
150     XMoveWindow(ob_display, self->window, self->area.x, self->area.y);
151 }
152
153 void menu_frame_move_on_screen(ObMenuFrame *self)
154 {
155     Rect *a;
156     guint i;
157     gint dx = 0, dy = 0;
158
159     for (i = 0; i < screen_num_monitors; ++i) {
160         a = screen_physical_area_monitor(i);
161         if (RECT_INTERSECTS_RECT(*a, self->area))
162             break;
163     }
164     if (a) a = screen_physical_area_monitor(0);
165
166     dx = MIN(0, (a->x + a->width) - (self->area.x + self->area.width));
167     dy = MIN(0, (a->y + a->height) - (self->area.y + self->area.height));
168     if (!dx) dx = MAX(0, a->x - self->area.x);
169     if (!dy) dy = MAX(0, a->y - self->area.y);
170
171     if (dx || dy) {
172         ObMenuFrame *f;
173
174         for (f = self; f; f = f->parent)
175             menu_frame_move(f, f->area.x + dx, f->area.y + dy);
176         for (f = self->child; f; f = f->child)
177             menu_frame_move(f, f->area.x + dx, f->area.y + dy);
178         XWarpPointer(ob_display, None, None, 0, 0, 0, 0, dx, dy);
179     }
180 }
181
182 static void menu_entry_frame_render(ObMenuEntryFrame *self)
183 {
184     RrAppearance *item_a, *text_a;
185     gint th; /* temp */
186     ObMenu *sub;
187
188     item_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
189                !self->entry->data.normal.enabled) ?
190               self->a_disabled :
191               (self == self->frame->selected ?
192                self->a_selected :
193                self->a_normal));
194     switch (self->entry->type) {
195     case OB_MENU_ENTRY_TYPE_NORMAL:
196     case OB_MENU_ENTRY_TYPE_SUBMENU:
197         th = self->frame->item_h;
198         break;
199     case OB_MENU_ENTRY_TYPE_SEPARATOR:
200         th = SEPARATOR_HEIGHT;
201         break;
202     }
203     RECT_SET_SIZE(self->area, self->frame->inner_w, th);
204     XResizeWindow(ob_display, self->window,
205                   self->area.width, self->area.height);
206     item_a->surface.parent = self->frame->a_items;
207     item_a->surface.parentx = self->area.x;
208     item_a->surface.parenty = self->area.y;
209     RrPaint(item_a, self->window, self->area.width, self->area.height);
210
211     text_a = ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
212                !self->entry->data.normal.enabled) ?
213               self->a_text_disabled :
214               (self == self->frame->selected ?
215                self->a_text_selected :
216                self->a_text_normal));
217     switch (self->entry->type) {
218     case OB_MENU_ENTRY_TYPE_NORMAL:
219         text_a->texture[0].data.text.string = self->entry->data.normal.label;
220         break;
221     case OB_MENU_ENTRY_TYPE_SUBMENU:
222         sub = self->entry->data.submenu.submenu;
223         text_a->texture[0].data.text.string = sub ? sub->title : "";
224         break;
225     case OB_MENU_ENTRY_TYPE_SEPARATOR:
226         break;
227     }
228
229     switch (self->entry->type) {
230     case OB_MENU_ENTRY_TYPE_NORMAL:
231         XMoveResizeWindow(ob_display, self->text,
232                           self->frame->text_x, PADDING,
233                           self->frame->text_w,
234                           self->frame->item_h - 2*PADDING);
235         text_a->surface.parent = item_a;
236         text_a->surface.parentx = self->frame->text_x;
237         text_a->surface.parenty = PADDING;
238         RrPaint(text_a, self->text, self->frame->text_w,
239                 self->frame->item_h - 2*PADDING);
240         XMapWindow(ob_display, self->text);
241         break;
242     case OB_MENU_ENTRY_TYPE_SUBMENU:
243         XMoveResizeWindow(ob_display, self->text,
244                           self->frame->text_x, PADDING,
245                           self->frame->text_w - self->frame->item_h,
246                           self->frame->item_h - 2*PADDING);
247         text_a->surface.parent = item_a;
248         text_a->surface.parentx = self->frame->text_x;
249         text_a->surface.parenty = PADDING;
250         RrPaint(text_a, self->text, self->frame->text_w - self->frame->item_h,
251                 self->frame->item_h - 2*PADDING);
252         XMapWindow(ob_display, self->text);
253         break;
254     case OB_MENU_ENTRY_TYPE_SEPARATOR:
255         XUnmapWindow(ob_display, self->text);
256         break;
257     }
258
259     if (self->entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR &&
260         self->entry->data.normal.icon_data)
261     {
262         XMoveResizeWindow(ob_display, self->icon, PADDING, 0,
263                           self->frame->item_h,
264                           self->frame->item_h);
265         self->a_icon->texture[0].data.rgba.width =
266             self->entry->data.normal.icon_width;
267         self->a_icon->texture[0].data.rgba.height =
268             self->entry->data.normal.icon_height;
269         self->a_icon->texture[0].data.rgba.data =
270             self->entry->data.normal.icon_data;
271         self->a_icon->surface.parent = item_a;
272         self->a_icon->surface.parentx = PADDING;
273         self->a_icon->surface.parenty = 0;
274         RrPaint(self->a_icon, self->icon,
275                 self->frame->item_h, self->frame->item_h);
276         XMapWindow(ob_display, self->icon);
277     } else if (self->entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR &&
278                self->entry->data.normal.mask)
279     {
280         XMoveResizeWindow(ob_display, self->icon, PADDING, 0,
281                           self->frame->item_h,
282                           self->frame->item_h);
283         self->a_mask->texture[0].data.mask.mask =
284             self->entry->data.normal.mask;
285         self->a_mask->texture[0].data.mask.color =
286             self->entry->data.normal.mask_color;
287         self->a_mask->surface.parent = item_a;
288         self->a_mask->surface.parentx = PADDING;
289         self->a_mask->surface.parenty = 0;
290         RrPaint(self->a_mask, self->icon,
291                 self->frame->item_h, self->frame->item_h);
292         XMapWindow(ob_display, self->icon);
293     } else
294         XUnmapWindow(ob_display, self->icon);
295
296     if (self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU) {
297         XMoveResizeWindow(ob_display, self->bullet,
298                           self->frame->text_x + self->frame->text_w
299                           - self->frame->item_h + PADDING, PADDING,
300                           self->frame->item_h - 2*PADDING,
301                           self->frame->item_h - 2*PADDING);
302         self->a_bullet->surface.parent = item_a;
303         self->a_bullet->surface.parentx =
304             self->frame->text_x + self->frame->text_w - self->frame->item_h
305             - PADDING;
306         self->a_bullet->surface.parenty = PADDING;
307         RrPaint(self->a_bullet, self->bullet,
308                 self->frame->item_h - 2*PADDING,
309                 self->frame->item_h - 2*PADDING);
310         XMapWindow(ob_display, self->bullet);
311     } else
312         XUnmapWindow(ob_display, self->bullet);
313 }
314
315 static void menu_frame_render(ObMenuFrame *self)
316 {
317     gint w = 0, h = 0;
318     gint allitems_h = 0;
319     gint tw, th; /* temps */
320     GList *it;
321     gboolean has_icon = FALSE;
322     ObMenu *sub;
323
324     XSetWindowBorderWidth(ob_display, self->window, ob_rr_theme->bwidth);
325     XSetWindowBorder(ob_display, self->window,
326                      RrColorPixel(ob_rr_theme->b_color));
327
328     if (!self->parent && self->show_title) {
329         XMoveWindow(ob_display, self->title, 
330                     -ob_rr_theme->bwidth, h - ob_rr_theme->bwidth);
331
332         self->a_title->texture[0].data.text.string = self->menu->title;
333         RrMinsize(self->a_title, &tw, &th);
334         tw += 2*PADDING;
335         th += 2*PADDING;
336         w = MAX(w, tw);
337         h += (self->title_h = th + ob_rr_theme->bwidth);
338
339         XSetWindowBorderWidth(ob_display, self->title, ob_rr_theme->bwidth);
340         XSetWindowBorder(ob_display, self->title,
341                          RrColorPixel(ob_rr_theme->b_color));
342     }
343
344     XMoveWindow(ob_display, self->items, 0, h);
345
346     if (self->entries) {
347         ObMenuEntryFrame *e = self->entries->data;
348         e->a_text_normal->texture[0].data.text.string = "";
349         RrMinsize(e->a_text_normal, &tw, &th);
350         tw += 2*PADDING;
351         th += 2*PADDING;
352         self->item_h = th;
353     } else
354         self->item_h = 0;
355
356     for (it = self->entries; it; it = g_list_next(it)) {
357         RrAppearance *text_a;
358         ObMenuEntryFrame *e = it->data;
359
360         RECT_SET_POINT(e->area, 0, allitems_h);
361         XMoveWindow(ob_display, e->window, 0, e->area.y);
362
363         text_a = ((e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
364                    !e->entry->data.normal.enabled) ?
365                   e->a_text_disabled :
366                   (e == self->selected ?
367                    e->a_text_selected :
368                    e->a_text_normal));
369         switch (e->entry->type) {
370         case OB_MENU_ENTRY_TYPE_NORMAL:
371             text_a->texture[0].data.text.string = e->entry->data.normal.label;
372             RrMinsize(text_a, &tw, &th);
373
374             if (e->entry->data.normal.icon_data ||
375                 e->entry->data.normal.mask)
376                 has_icon = TRUE;
377             break;
378         case OB_MENU_ENTRY_TYPE_SUBMENU:
379             sub = e->entry->data.submenu.submenu;
380             text_a->texture[0].data.text.string = sub ? sub->title : "";
381             RrMinsize(text_a, &tw, &th);
382
383             if (e->entry->data.normal.icon_data ||
384                 e->entry->data.normal.mask)
385                 has_icon = TRUE;
386
387             tw += self->item_h - PADDING;
388             break;
389         case OB_MENU_ENTRY_TYPE_SEPARATOR:
390             tw = 0;
391             th = SEPARATOR_HEIGHT;
392             break;
393         }
394         tw += 2*PADDING;
395         th += 2*PADDING;
396         w = MAX(w, tw);
397         h += th;
398         allitems_h += th;
399     }
400
401     self->text_x = PADDING;
402     self->text_w = w;
403
404     if (self->entries) {
405         if (has_icon) {
406             w += self->item_h + PADDING;
407             self->text_x += self->item_h + PADDING;
408         }
409     }
410
411     if (!w) w = 10;
412     if (!allitems_h) {
413         allitems_h = 3;
414         h += 3;
415     }
416
417     XResizeWindow(ob_display, self->window, w, h);
418     XResizeWindow(ob_display, self->items, w, allitems_h);
419
420     self->inner_w = w;
421
422     if (!self->parent && self->show_title) {
423         XResizeWindow(ob_display, self->title,
424                       w, self->title_h - ob_rr_theme->bwidth);
425         RrPaint(self->a_title, self->title,
426                 w, self->title_h - ob_rr_theme->bwidth);
427         XMapWindow(ob_display, self->title);
428     } else
429         XUnmapWindow(ob_display, self->title);
430
431     RrPaint(self->a_items, self->items, w, allitems_h);
432
433     for (it = self->entries; it; it = g_list_next(it))
434         menu_entry_frame_render(it->data);
435
436     w += ob_rr_theme->bwidth * 2;
437     h += ob_rr_theme->bwidth * 2;
438
439     RECT_SET_SIZE(self->area, w, h);
440 }
441
442 static void menu_frame_update(ObMenuFrame *self)
443 {
444     GList *mit, *fit;
445
446     menu_pipe_execute(self->menu);
447     menu_find_submenus(self->menu);
448
449     self->selected = NULL;
450
451     for (mit = self->menu->entries, fit = self->entries; mit && fit;
452          mit = g_list_next(mit), fit = g_list_next(fit))
453     {
454         ObMenuEntryFrame *f = fit->data;
455         f->entry = mit->data;
456     }
457
458     while (mit) {
459         ObMenuEntryFrame *e = menu_entry_frame_new(mit->data, self);
460         self->entries = g_list_append(self->entries, e);
461         mit = g_list_next(mit);
462     }
463     
464     while (fit) {
465         GList *n = g_list_next(fit);
466         menu_entry_frame_free(fit->data);
467         self->entries = g_list_delete_link(self->entries, fit);
468         fit = n;
469     }
470
471     menu_frame_render(self);
472 }
473
474 void menu_frame_show(ObMenuFrame *self, ObMenuFrame *parent)
475 {
476     GList *it;
477
478     if (g_list_find(menu_frame_visible, self))
479         return;
480
481     if (parent) {
482         if (parent->child)
483             menu_frame_hide(parent->child);
484         parent->child = self;
485     }
486     self->parent = parent;
487
488     if (menu_frame_visible == NULL) {
489         /* no menus shown yet */
490         grab_pointer(TRUE, None);
491         grab_keyboard(TRUE);
492     }
493
494     /* determine if the underlying menu is already visible */
495     for (it = menu_frame_visible; it; it = g_list_next(it)) {
496         ObMenuFrame *f = it->data;
497         if (f->menu == self->menu)
498             break;
499     }
500     if (!it) {
501         if (self->menu->update_func)
502             self->menu->update_func(self, self->menu->data);
503     }
504
505     menu_frame_visible = g_list_prepend(menu_frame_visible, self);
506     menu_frame_update(self);
507
508     menu_frame_move_on_screen(self);
509
510     XMapWindow(ob_display, self->window);
511 }
512
513 void menu_frame_hide(ObMenuFrame *self)
514 {
515     GList *it = g_list_find(menu_frame_visible, self);
516
517     if (!it)
518         return;
519
520     if (self->child)
521         menu_frame_hide(self->child);
522
523     if (self->parent)
524         self->parent->child = NULL;
525     self->parent = NULL;
526
527     menu_frame_visible = g_list_delete_link(menu_frame_visible, it);
528
529     if (menu_frame_visible == NULL) {
530         /* last menu shown */
531         grab_pointer(FALSE, None);
532         grab_keyboard(FALSE);
533     }
534
535     XUnmapWindow(ob_display, self->window);
536
537     menu_frame_free(self);
538 }
539
540 void menu_frame_hide_all()
541 {
542     GList *it = g_list_last(menu_frame_visible);
543     if (it) 
544         menu_frame_hide(it->data);
545 }
546
547 void menu_frame_hide_all_client(ObClient *client)
548 {
549     GList *it = g_list_last(menu_frame_visible);
550     if (it) {
551         ObMenuFrame *f = it->data;
552         if (f->client == client)
553             menu_frame_hide(f);
554     }
555 }
556
557
558 ObMenuFrame* menu_frame_under(gint x, gint y)
559 {
560     ObMenuFrame *ret = NULL;
561     GList *it;
562
563     for (it = menu_frame_visible; it; it = g_list_next(it)) {
564         ObMenuFrame *f = it->data;
565
566         if (RECT_CONTAINS(f->area, x, y)) {
567             ret = f;
568             break;
569         }
570     }
571     return ret;
572 }
573
574 ObMenuEntryFrame* menu_entry_frame_under(gint x, gint y)
575 {
576     ObMenuFrame *frame;
577     ObMenuEntryFrame *ret = NULL;
578     GList *it;
579
580     if ((frame = menu_frame_under(x, y))) {
581         x -= ob_rr_theme->bwidth + frame->area.x;
582         y -= frame->title_h + ob_rr_theme->bwidth + frame->area.y;
583
584         for (it = frame->entries; it; it = g_list_next(it)) {
585             ObMenuEntryFrame *e = it->data;
586
587             if (RECT_CONTAINS(e->area, x, y)) {
588                 ret = e;            
589                 break;
590             }
591         }
592     }
593     return ret;
594 }
595
596 void menu_frame_select(ObMenuFrame *self, ObMenuEntryFrame *entry)
597 {
598     ObMenuEntryFrame *old = self->selected;
599     ObMenuFrame *oldchild = self->child;
600
601     if (old == entry) return;
602
603     if (entry && entry->entry->type != OB_MENU_ENTRY_TYPE_SEPARATOR)
604         self->selected = entry;
605     else
606         self->selected = NULL;
607
608     if (old)
609         menu_entry_frame_render(old);
610     if (oldchild)
611         menu_frame_hide(oldchild);
612
613     if (self->selected) {
614         menu_entry_frame_render(self->selected);
615
616         if (self->selected->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
617             menu_entry_frame_show_submenu(self->selected);
618     }
619 }
620
621 void menu_entry_frame_show_submenu(ObMenuEntryFrame *self)
622 {
623     ObMenuFrame *f;
624
625     if (!self->entry->data.submenu.submenu) return;
626
627     f = menu_frame_new(self->entry->data.submenu.submenu,
628                        self->frame->client);
629     menu_frame_move(f,
630                     self->frame->area.x + self->frame->area.width
631                     - ob_rr_theme->menu_overlap - ob_rr_theme->bwidth,
632                     self->frame->area.y + self->frame->title_h +
633                     self->area.y + ob_rr_theme->menu_overlap);
634     menu_frame_show(f, self->frame);
635 }
636
637 void menu_entry_frame_execute(ObMenuEntryFrame *self, gboolean hide)
638 {
639     if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
640         self->entry->data.normal.enabled)
641     {
642         /* grab all this shizzle, cuz when the menu gets hidden, 'self'
643            gets freed */
644         ObMenuEntry *entry = self->entry;
645         ObMenuExecuteFunc func = self->frame->menu->execute_func;
646         gpointer data = self->frame->menu->data;
647         GSList *acts = self->entry->data.normal.actions;
648         ObClient *client = self->frame->client;
649
650         /* release grabs before executing the shit */
651         menu_frame_hide_all();
652
653         if (func)
654             func(entry, data);
655         else {
656             GSList *it;
657
658             for (it = acts; it; it = g_slist_next(it))
659             {
660                 ObAction *act = it->data;
661                 act->data.any.c = client;
662
663                 if (act->func == action_moveresize)
664                     screen_pointer_pos(&act->data.moveresize.x,
665                                        &act->data.moveresize.y);
666
667                 if (!(act->func == action_cycle_windows ||
668                       act->func == action_desktop_dir ||
669                       act->func == action_send_to_desktop_dir ||
670                       act->func == action_showmenu))
671                 {
672                     act->func(&act->data);
673                 }
674             }
675         }
676     }
677 }
678
679 void menu_frame_select_previous(ObMenuFrame *self)
680 {
681     GList *it = NULL, *start;
682
683     if (self->entries) {
684         start = it = g_list_find(self->entries, self->selected);
685         while (TRUE) {
686             ObMenuEntryFrame *e;
687
688             it = it ? g_list_previous(it) : g_list_last(self->entries);
689             if (it == start)
690                 break;
691
692             if (it) {
693                 e = it->data;
694                 if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
695                     break;
696                 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
697                     e->entry->data.normal.enabled)
698                     break;
699             }
700         }
701     }
702     menu_frame_select(self, it ? it->data : NULL);
703 }
704
705 void menu_frame_select_next(ObMenuFrame *self)
706 {
707     GList *it = NULL, *start;
708
709     if (self->entries) {
710         start = it = g_list_find(self->entries, self->selected);
711         while (TRUE) {
712             ObMenuEntryFrame *e;
713
714             it = it ? g_list_next(it) : self->entries;
715             if (it == start)
716                 break;
717
718             if (it) {
719                 e = it->data;
720                 if (e->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)
721                     break;
722                 if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
723                     e->entry->data.normal.enabled)
724                     break;
725             }
726         }
727     }
728     menu_frame_select(self, it ? it->data : NULL);
729 }