1 /* Functions for default rendering of menus. Might become pluginnable */
5 #include "render/theme.h"
7 void menu_render_full(Menu
*self
);
9 void menu_render(Menu
*self
) {
12 } else if (self
->invalid
) {
13 menu_render_full(self
);
17 void menu_render_full(Menu
*self
) {
20 int nitems
= 0; /* each item, only one is used */
26 if (self
->a_title
== NULL
) {
27 XSetWindowBorderWidth(ob_display
, self
->frame
, ob_rr_theme
->bwidth
);
28 XSetWindowBackground(ob_display
, self
->frame
,
29 ob_rr_theme
->b_color
->pixel
);
30 XSetWindowBorderWidth(ob_display
, self
->title
, ob_rr_theme
->bwidth
);
31 XSetWindowBorder(ob_display
, self
->frame
, ob_rr_theme
->b_color
->pixel
);
32 XSetWindowBorder(ob_display
, self
->title
, ob_rr_theme
->b_color
->pixel
);
34 self
->a_title
= RrAppearanceCopy(ob_rr_theme
->a_menu_title
);
35 self
->a_items
= RrAppearanceCopy(ob_rr_theme
->a_menu
);
38 /* set texture data and size them mofos out */
40 self
->a_title
->texture
[0].data
.text
.string
= self
->label
;
41 RrMinsize(self
->a_title
, &self
->title_min_w
, &self
->title_h
);
42 self
->title_min_w
+= ob_rr_theme
->bevel
* 2;
43 self
->title_h
+= ob_rr_theme
->bevel
* 2;
44 self
->size
.width
= MAX(self
->size
.width
, self
->title_min_w
);
47 for (it
= self
->entries
; it
; it
= it
->next
) {
48 MenuEntry
*e
= it
->data
;
51 if (e
->a_item
== NULL
) {
52 e
->a_item
= RrAppearanceCopy(ob_rr_theme
->a_menu_item
);
53 e
->a_disabled
= RrAppearanceCopy(ob_rr_theme
->a_menu_disabled
);
54 e
->a_hilite
= RrAppearanceCopy(ob_rr_theme
->a_menu_hilite
);
57 e
->a_item
->texture
[0].data
.text
.string
= e
->label
;
58 RrMinsize(e
->a_item
, &e
->min_w
, &self
->item_h
);
59 self
->size
.width
= MAX(self
->size
.width
, e
->min_w
);
61 e
->a_disabled
->texture
[0].data
.text
.string
= e
->label
;
62 RrMinsize(e
->a_disabled
, &e
->min_w
, &h
);
63 self
->item_h
= MAX(self
->item_h
, h
);
64 self
->size
.width
= MAX(self
->size
.width
, e
->min_w
);
66 e
->a_hilite
->texture
[0].data
.text
.string
= e
->label
;
67 RrMinsize(e
->a_hilite
, &e
->min_w
, &h
);
68 self
->item_h
= MAX(self
->item_h
, h
);
69 self
->size
.width
= MAX(self
->size
.width
, e
->min_w
);
71 e
->min_w
+= ob_rr_theme
->bevel
* 2;
74 self
->bullet_w
= self
->item_h
+ ob_rr_theme
->bevel
;
75 self
->size
.width
+= 2 * self
->bullet_w
+ 2 * ob_rr_theme
->bevel
;
76 self
->item_h
+= ob_rr_theme
->bevel
* 2;
77 items_h
= self
->item_h
* MAX(nitems
, 1);
79 self
->size
.height
= MAX(self
->title_h
+ items_h
+ ob_rr_theme
->bwidth
, 1);
80 XResizeWindow(ob_display
, self
->frame
, self
->size
.width
,self
->size
.height
);
82 XMoveResizeWindow(ob_display
, self
->title
, -ob_rr_theme
->bwidth
,
84 self
->size
.width
, self
->title_h
);
86 XMoveResizeWindow(ob_display
, self
->items
, 0,
87 self
->title_h
+ ob_rr_theme
->bwidth
, self
->size
.width
,
91 RrPaint(self
->a_title
, self
->title
, self
->size
.width
, self
->title_h
);
92 RrPaint(self
->a_items
, self
->items
, self
->size
.width
, items_h
);
95 for (it
= self
->entries
; it
; it
= it
->next
) {
96 ((MenuEntry
*)it
->data
)->y
= item_y
;
97 menu_entry_render(it
->data
);
98 item_y
+= self
->item_h
;
101 self
->invalid
= FALSE
;
104 void menu_entry_render(MenuEntry
*self
)
106 Menu
*menu
= self
->parent
;
109 switch (self
->render_type
) {
110 case MenuEntryRenderType_Submenu
:
111 /* TODO: submenu mask */
112 case MenuEntryRenderType_Boolean
:
113 /* TODO: boolean check */
114 a
= self
->enabled
? (self
->hilite
? self
->a_hilite
: self
->a_item
)
117 case MenuEntryRenderType_None
:
118 a
= self
->enabled
? (self
->hilite
? self
->a_hilite
: self
->a_item
)
121 case MenuEntryRenderType_Separator
:
126 g_message("unhandled render_type");
127 a
= !self
->enabled
? self
->a_disabled
:
129 (self
->action
|| self
->render_type
== MenuEntryRenderType_Submenu
) ?
130 self
->a_hilite
: self
->a_item
);
133 g_message ("%s %d", self
->label
, self
->hilite
);
135 XMoveResizeWindow(ob_display
, self
->item
, 0, self
->y
,
136 menu
->size
.width
, menu
->item_h
);
138 a
->surface
.parent
= menu
->a_items
;
139 a
->surface
.parentx
= 0;
140 a
->surface
.parenty
= self
->y
;
142 RrPaint(a
, self
->item
, menu
->size
.width
, menu
->item_h
);