]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/menu_render.c
Menu uber patch
[mikachu/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_full(Menu *self);
8
9 void menu_render(Menu *self) {
10     if (self->invalid) {
11         if (self->update) {
12             self->update(self);
13         } else {
14             menu_render_full(self);
15         }
16     }
17 }
18             
19
20 void menu_render_full(Menu *self) {
21     GList *it;
22     int items_h = 0;
23     int nitems = 0; /* each item, only one is used */
24     int item_y;
25
26     self->size.width = 1;
27     self->item_h = 1;
28
29     /* set texture data and size them mofos out */
30     if (self->label) {
31         self->a_title->texture[0].data.text.string = self->label;
32         appearance_minsize(self->a_title, &self->title_min_w, &self->title_h);
33         self->title_min_w += theme_bevel * 2;
34         self->title_h += theme_bevel * 2;
35         self->size.width = MAX(self->size.width, self->title_min_w);
36     }
37
38     for (it = self->entries; it; it = it->next) {
39         MenuEntry *e = it->data;
40         int h;
41
42         e->a_item->texture[0].data.text.string = e->label;
43         appearance_minsize(e->a_item, &e->min_w, &self->item_h);
44         self->size.width = MAX(self->size.width, e->min_w);
45
46         e->a_disabled->texture[0].data.text.string = e->label;
47         appearance_minsize(e->a_disabled, &e->min_w, &h);
48         self->item_h = MAX(self->item_h, h);
49         self->size.width = MAX(self->size.width, e->min_w);
50         
51         e->a_hilite->texture[0].data.text.string = e->label;
52         appearance_minsize(e->a_hilite, &e->min_w, &h);
53         self->item_h = MAX(self->item_h, h);
54         self->size.width = MAX(self->size.width, e->min_w);
55
56         e->min_w += theme_bevel * 2;
57         ++nitems;
58     }
59     self->bullet_w = self->item_h + theme_bevel;
60     self->size.width += 2 * self->bullet_w + 2 * theme_bevel;
61     self->item_h += theme_bevel * 2;
62     items_h = self->item_h * MAX(nitems, 1);
63
64     if (self->label) {
65         RECT_SET(self->a_title->area, 0, 0, self->size.width, self->title_h);
66         RECT_SET(self->a_title->texture[0].position, 0, 0, self->size.width,
67                  self->title_h);
68     }
69
70     RECT_SET(self->a_items->area, 0, 0, self->size.width, items_h);
71
72     XResizeWindow(ob_display, self->frame, self->size.width,
73                   MAX(self->title_h + items_h, 1));
74     if (self->label)
75         XMoveResizeWindow(ob_display, self->title, -theme_bwidth,
76                           -theme_bwidth, self->size.width, self->title_h);
77     XMoveResizeWindow(ob_display, self->items, 0, self->title_h + theme_bwidth,
78                       self->size.width, items_h);
79
80     if (self->label)
81         paint(self->title, self->a_title);
82     paint(self->items, self->a_items);
83
84     item_y = 0;
85     for (it = self->entries; it; it = it->next) {
86         ((MenuEntry*)it->data)->y = item_y;
87         menu_entry_render(it->data);
88         item_y += self->item_h;
89     }
90     
91     self->size.height = item_y;
92     self->invalid = FALSE;
93 }
94
95 void menu_entry_render(MenuEntry *self)
96 {
97     Menu *menu = self->parent;
98     Appearance *a;
99     
100     switch (self->render_type) {
101     case MenuEntryRenderType_Submenu:
102         /* TODO: submenu mask */
103     case MenuEntryRenderType_Boolean:
104         /* TODO: boolean check */
105         a = self->enabled ? (self->hilite ? self->a_hilite : self->a_item) 
106             : self->a_disabled;
107         break;
108     case MenuEntryRenderType_None:
109         a = self->enabled ? (self->hilite ? self->a_hilite : self->a_item )
110             : self->a_disabled;
111         break;
112     case MenuEntryRenderType_Separator:
113         a = self->a_item;
114         break;
115
116     default:
117         g_message("unhandled render_type");
118         a = !self->enabled ? self->a_disabled :
119         (self->hilite && 
120          (self->action || self->render_type == MenuEntryRenderType_Submenu) ? 
121          self->a_hilite : self->a_item);
122         break;
123     }
124
125     RECT_SET(a->area, 0, 0, menu->size.width,
126              menu->item_h);
127     RECT_SET(a->texture[0].position, menu->bullet_w,
128              0, menu->size.width - 2 * menu->bullet_w,
129              menu->item_h);
130
131     XMoveResizeWindow(ob_display, self->item, 0, self->y,
132                       menu->size.width, menu->item_h);
133     a->surface.data.planar.parent = menu->a_items;
134     a->surface.data.planar.parentx = 0;
135     a->surface.data.planar.parenty = self->y;
136
137     paint(self->item, a);
138 }