]> Dogcows Code - chaz/openbox/blob - openbox/menu_render.c
use the new sm_client_id function so all windows who should save state do. session...
[chaz/openbox] / openbox / menu_render.c
1 /* Functions for default rendering of menus. Might become pluginnable */
2
3 #include "debug.h"
4 #include "menu.h"
5 #include "openbox.h"
6 #include "render/theme.h"
7
8 void menu_render(ObMenu *self) {
9 GList *it;
10 int items_h = 0;
11 int nitems = 0; /* each item, only one is used */
12 int item_y;
13
14 self->size.width = 1;
15 self->item_h = 1;
16
17 if (self->a_title == NULL) {
18 XSetWindowBorderWidth(ob_display, self->frame, ob_rr_theme->bwidth);
19 XSetWindowBackground(ob_display, self->frame,
20 RrColorPixel(ob_rr_theme->b_color));
21 XSetWindowBorderWidth(ob_display, self->title, ob_rr_theme->bwidth);
22 XSetWindowBorder(ob_display, self->frame,
23 RrColorPixel(ob_rr_theme->b_color));
24 XSetWindowBorder(ob_display, self->title,
25 RrColorPixel(ob_rr_theme->b_color));
26
27 self->a_title = RrAppearanceCopy(ob_rr_theme->a_menu_title);
28 self->a_items = RrAppearanceCopy(ob_rr_theme->a_menu);
29 }
30
31 /* set texture data and size them mofos out */
32 if (self->label) {
33 self->a_title->texture[0].data.text.string = self->label;
34 RrMinsize(self->a_title, &self->title_min_w, &self->title_h);
35 self->title_min_w += ob_rr_theme->bevel * 2;
36 self->title_h += ob_rr_theme->bevel * 2;
37 self->size.width = MAX(self->size.width, self->title_min_w);
38 }
39
40 for (it = self->entries; it; it = it->next) {
41 ObMenuEntry *e = it->data;
42 int h;
43
44 if (e->a_item == NULL) {
45 e->a_item = RrAppearanceCopy(ob_rr_theme->a_menu_item);
46 e->a_disabled = RrAppearanceCopy(ob_rr_theme->a_menu_disabled);
47 e->a_hilite = RrAppearanceCopy(ob_rr_theme->a_menu_hilite);
48 }
49
50 e->a_item->texture[0].data.text.string = e->label;
51 RrMinsize(e->a_item, &e->min_w, &self->item_h);
52 self->size.width = MAX(self->size.width, e->min_w);
53
54 e->a_disabled->texture[0].data.text.string = e->label;
55 RrMinsize(e->a_disabled, &e->min_w, &h);
56 self->item_h = MAX(self->item_h, h);
57 self->size.width = MAX(self->size.width, e->min_w);
58
59 e->a_hilite->texture[0].data.text.string = e->label;
60 RrMinsize(e->a_hilite, &e->min_w, &h);
61 self->item_h = MAX(self->item_h, h);
62 self->size.width = MAX(self->size.width, e->min_w);
63
64 e->min_w += ob_rr_theme->bevel * 2;
65 ++nitems;
66 }
67 self->bullet_w = self->item_h + ob_rr_theme->bevel;
68 self->size.width += 2 * self->bullet_w + 2 * ob_rr_theme->bevel;
69 self->item_h += ob_rr_theme->bevel * 2;
70 items_h = self->item_h * MAX(nitems, 1);
71
72 self->size.height = MAX(self->title_h + items_h + ob_rr_theme->bwidth, 1);
73 XResizeWindow(ob_display, self->frame, self->size.width,self->size.height);
74 if (self->label)
75 XMoveResizeWindow(ob_display, self->title, -ob_rr_theme->bwidth,
76 -ob_rr_theme->bwidth,
77 self->size.width, self->title_h);
78
79 XMoveResizeWindow(ob_display, self->items, 0,
80 self->title_h + ob_rr_theme->bwidth, self->size.width,
81 items_h);
82
83 if (self->label)
84 RrPaint(self->a_title, self->title, self->size.width, self->title_h);
85 RrPaint(self->a_items, self->items, self->size.width, items_h);
86
87 item_y = 0;
88 for (it = self->entries; it; it = it->next) {
89 ((ObMenuEntry*)it->data)->y = item_y;
90 menu_entry_render(it->data);
91 item_y += self->item_h;
92 }
93
94 self->invalid = FALSE;
95 }
96
97 void menu_entry_render(ObMenuEntry *self)
98 {
99 ObMenu *menu = self->parent;
100 RrAppearance *a;
101
102 switch (self->render_type) {
103 case OB_MENU_ENTRY_RENDER_TYPE_SUBMENU:
104 /* TODO: submenu mask */
105 case OB_MENU_ENTRY_RENDER_TYPE_BOOLEAN:
106 /* TODO: boolean check */
107 a = self->enabled ? (self->hilite ? self->a_hilite : self->a_item)
108 : self->a_disabled;
109 break;
110 case OB_MENU_ENTRY_RENDER_TYPE_NONE:
111 a = self->enabled ? (self->hilite ? self->a_hilite : self->a_item )
112 : self->a_disabled;
113 break;
114 case OB_MENU_ENTRY_RENDER_TYPE_SEPARATOR:
115 a = self->a_item;
116 break;
117
118 default:
119 g_assert_not_reached(); /* unhandled rendering type */
120 break;
121 }
122 ob_debug("%s %d\n", self->label, self->hilite);
123
124 XMoveResizeWindow(ob_display, self->item, 0, self->y,
125 menu->size.width, menu->item_h);
126
127 a->surface.parent = menu->a_items;
128 a->surface.parentx = 0;
129 a->surface.parenty = self->y;
130
131 RrPaint(a, self->item, menu->size.width, menu->item_h);
132 }
This page took 0.038393 seconds and 4 git commands to generate.