1 /* Functions for default rendering of menus. Might become pluginnable */
6 #include "render/theme.h"
8 void menu_render(ObMenu
*self
) {
11 int nitems
= 0; /* each item, only one is used */
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
));
27 self
->a_title
= RrAppearanceCopy(ob_rr_theme
->a_menu_title
);
28 self
->a_items
= RrAppearanceCopy(ob_rr_theme
->a_menu
);
31 /* set texture data and size them mofos out */
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
);
40 for (it
= self
->entries
; it
; it
= it
->next
) {
41 ObMenuEntry
*e
= it
->data
;
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
);
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
);
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
);
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
);
64 e
->min_w
+= ob_rr_theme
->bevel
* 2;
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);
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
);
75 XMoveResizeWindow(ob_display
, self
->title
, -ob_rr_theme
->bwidth
,
77 self
->size
.width
, self
->title_h
);
79 XMoveResizeWindow(ob_display
, self
->items
, 0,
80 self
->title_h
+ ob_rr_theme
->bwidth
, self
->size
.width
,
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
);
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
;
94 self
->invalid
= FALSE
;
97 void menu_entry_render(ObMenuEntry
*self
)
99 ObMenu
*menu
= self
->parent
;
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
)
110 case OB_MENU_ENTRY_RENDER_TYPE_NONE
:
111 a
= self
->enabled
? (self
->hilite
? self
->a_hilite
: self
->a_item
)
114 case OB_MENU_ENTRY_RENDER_TYPE_SEPARATOR
:
119 g_assert_not_reached(); /* unhandled rendering type */
122 ob_debug("%s %d\n", self
->label
, self
->hilite
);
124 XMoveResizeWindow(ob_display
, self
->item
, 0, self
->y
,
125 menu
->size
.width
, menu
->item_h
);
127 a
->surface
.parent
= menu
->a_items
;
128 a
->surface
.parentx
= 0;
129 a
->surface
.parenty
= self
->y
;
131 RrPaint(a
, self
->item
, menu
->size
.width
, menu
->item_h
);