Render menus only when they are invalid.
[dana/openbox.git] / openbox / menu_render.c
1 // Functions for default rendering of menus. Might become pluginnable
2
3 #include "menu.h"
4 #include "openbox.h"
5 #include "render/theme.h"
6
7 void menu_render(Menu *self) {
8     GList *it;
9     int items_h;
10     int nitems = 0; /* each item, only one is used */
11     int item_y;
12
13     self->width = 1;
14     self->item_h = 0;
15
16     /* set texture data and size them mofos out */
17     self->a_title->texture[0].data.text.string = self->label;
18     appearance_minsize(self->a_title, &self->title_min_w, &self->title_h);
19     self->title_min_w += theme_bevel * 2;
20     self->title_h += theme_bevel * 2;
21     self->width = MAX(self->width, self->title_min_w);
22
23     for (it = self->entries; it; it = it->next) {
24         MenuEntry *e = it->data;
25         int h;
26
27         e->a_item->texture[0].data.text.string = e->label;
28         appearance_minsize(e->a_item, &e->min_w, &self->item_h);
29         self->width = MAX(self->width, e->min_w);
30
31         e->a_disabled->texture[0].data.text.string = e->label;
32         appearance_minsize(e->a_disabled, &e->min_w, &h);
33         self->item_h = MAX(self->item_h, h);
34         self->width = MAX(self->width, e->min_w);
35
36         e->a_hilite->texture[0].data.text.string = e->label;
37         appearance_minsize(e->a_hilite, &e->min_w, &h);
38         self->item_h = MAX(self->item_h, h);
39         self->width = MAX(self->width, e->min_w);
40
41         e->min_w += theme_bevel * 2;
42         ++nitems;
43     }
44     self->bullet_w = self->item_h + theme_bevel;
45     self->width += 2 * self->bullet_w;
46     self->item_h += theme_bevel * 2;
47     items_h = self->item_h * nitems;
48
49     RECT_SET(self->a_title->area, 0, 0, self->width, self->title_h);
50     RECT_SET(self->a_title->texture[0].position, 0, 0, self->width,
51              self->title_h);
52     RECT_SET(self->a_items->area, 0, 0, self->width, items_h);
53
54     XResizeWindow(ob_display, self->frame, self->width, 
55                   self->title_h + items_h);
56     XMoveResizeWindow(ob_display, self->title, -theme_bwidth, -theme_bwidth,
57                       self->width, self->title_h);
58     XMoveResizeWindow(ob_display, self->items, 0, self->title_h + theme_bwidth,
59                       self->width, items_h);
60
61     paint(self->title, self->a_title);
62     paint(self->items, self->a_items);
63
64     item_y = 0;
65     for (it = self->entries; it; it = it->next) {
66         ((MenuEntry*)it->data)->y = item_y;
67         menu_entry_render(it->data);
68         item_y += self->item_h;
69     }
70
71     self->invalid = FALSE;
72 }