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