whitespace
[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_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, 
66                  self->title_h);
67         RECT_SET(self->a_title->texture[0].position, 0, 0, self->size.width,
68                  self->title_h);
69     }
70
71     RECT_SET(self->a_items->area, 0, 0, self->size.width, items_h);
72
73     XResizeWindow(ob_display, self->frame, self->size.width,
74                   MAX(self->title_h + items_h, 1));
75     if (self->label)
76         XMoveResizeWindow(ob_display, self->title, -theme_bwidth,
77                           -theme_bwidth, self->size.width, self->title_h);
78
79     XMoveResizeWindow(ob_display, self->items, 0, 
80                       self->title_h + theme_bwidth, self->size.width, 
81                       items_h);
82
83     if (self->label)
84         paint(self->title, self->a_title);
85     paint(self->items, self->a_items);
86
87     item_y = 0;
88     for (it = self->entries; it; it = it->next) {
89         ((MenuEntry*)it->data)->y = item_y;
90         menu_entry_render(it->data);
91         item_y += self->item_h;
92     }
93     
94     self->size.height = item_y;
95     self->invalid = FALSE;
96 }
97
98 void menu_entry_render(MenuEntry *self)
99 {
100     Menu *menu = self->parent;
101     Appearance *a;
102     
103     switch (self->render_type) {
104     case MenuEntryRenderType_Submenu:
105         /* TODO: submenu mask */
106     case MenuEntryRenderType_Boolean:
107         /* TODO: boolean check */
108         a = self->enabled ? (self->hilite ? self->a_hilite : self->a_item) 
109             : self->a_disabled;
110         break;
111     case MenuEntryRenderType_None:
112         a = self->enabled ? (self->hilite ? self->a_hilite : self->a_item )
113             : self->a_disabled;
114         break;
115     case MenuEntryRenderType_Separator:
116         a = self->a_item;
117         break;
118
119     default:
120         g_message("unhandled render_type");
121         a = !self->enabled ? self->a_disabled :
122         (self->hilite && 
123          (self->action || self->render_type == MenuEntryRenderType_Submenu) ? 
124          self->a_hilite : self->a_item);
125         break;
126     }
127
128     RECT_SET(a->area, 0, 0, menu->size.width,
129              menu->item_h);
130     RECT_SET(a->texture[0].position, menu->bullet_w,
131              0, menu->size.width - 2 * menu->bullet_w,
132              menu->item_h);
133
134     XMoveResizeWindow(ob_display, self->item, 0, self->y,
135                       menu->size.width, menu->item_h);
136     a->surface.data.planar.parent = menu->a_items;
137     a->surface.data.planar.parentx = 0;
138     a->surface.data.planar.parenty = self->y;
139
140     paint(self->item, a);
141 }