1 /* Functions for default rendering of menus. Might become pluginnable */
5 #include "render/theme.h"
7 void menu_render_full(ObMenu
*self
);
9 void menu_render(ObMenu
*self
) {
12 } else if (self
->invalid
) {
13 menu_render_full(self
);
17 void menu_render_full(ObMenu
*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 RrColorPixel(ob_rr_theme
->b_color
));
30 XSetWindowBorderWidth(ob_display
, self
->title
, ob_rr_theme
->bwidth
);
31 XSetWindowBorder(ob_display
, self
->frame
,
32 RrColorPixel(ob_rr_theme
->b_color
));
33 XSetWindowBorder(ob_display
, self
->title
,
34 RrColorPixel(ob_rr_theme
->b_color
));
36 self
->a_title
= RrAppearanceCopy(ob_rr_theme
->a_menu_title
);
37 self
->a_items
= RrAppearanceCopy(ob_rr_theme
->a_menu
);
40 /* set texture data and size them mofos out */
42 self
->a_title
->texture
[0].data
.text
.string
= self
->label
;
43 RrMinsize(self
->a_title
, &self
->title_min_w
, &self
->title_h
);
44 self
->title_min_w
+= ob_rr_theme
->bevel
* 2;
45 self
->title_h
+= ob_rr_theme
->bevel
* 2;
46 self
->size
.width
= MAX(self
->size
.width
, self
->title_min_w
);
49 for (it
= self
->entries
; it
; it
= it
->next
) {
50 ObMenuEntry
*e
= it
->data
;
53 if (e
->a_item
== NULL
) {
54 e
->a_item
= RrAppearanceCopy(ob_rr_theme
->a_menu_item
);
55 e
->a_disabled
= RrAppearanceCopy(ob_rr_theme
->a_menu_disabled
);
56 e
->a_hilite
= RrAppearanceCopy(ob_rr_theme
->a_menu_hilite
);
59 e
->a_item
->texture
[0].data
.text
.string
= e
->label
;
60 RrMinsize(e
->a_item
, &e
->min_w
, &self
->item_h
);
61 self
->size
.width
= MAX(self
->size
.width
, e
->min_w
);
63 e
->a_disabled
->texture
[0].data
.text
.string
= e
->label
;
64 RrMinsize(e
->a_disabled
, &e
->min_w
, &h
);
65 self
->item_h
= MAX(self
->item_h
, h
);
66 self
->size
.width
= MAX(self
->size
.width
, e
->min_w
);
68 e
->a_hilite
->texture
[0].data
.text
.string
= e
->label
;
69 RrMinsize(e
->a_hilite
, &e
->min_w
, &h
);
70 self
->item_h
= MAX(self
->item_h
, h
);
71 self
->size
.width
= MAX(self
->size
.width
, e
->min_w
);
73 e
->min_w
+= ob_rr_theme
->bevel
* 2;
76 self
->bullet_w
= self
->item_h
+ ob_rr_theme
->bevel
;
77 self
->size
.width
+= 2 * self
->bullet_w
+ 2 * ob_rr_theme
->bevel
;
78 self
->item_h
+= ob_rr_theme
->bevel
* 2;
79 items_h
= self
->item_h
* MAX(nitems
, 1);
81 self
->size
.height
= MAX(self
->title_h
+ items_h
+ ob_rr_theme
->bwidth
, 1);
82 XResizeWindow(ob_display
, self
->frame
, self
->size
.width
,self
->size
.height
);
84 XMoveResizeWindow(ob_display
, self
->title
, -ob_rr_theme
->bwidth
,
86 self
->size
.width
, self
->title_h
);
88 XMoveResizeWindow(ob_display
, self
->items
, 0,
89 self
->title_h
+ ob_rr_theme
->bwidth
, self
->size
.width
,
93 RrPaint(self
->a_title
, self
->title
, self
->size
.width
, self
->title_h
);
94 RrPaint(self
->a_items
, self
->items
, self
->size
.width
, items_h
);
97 for (it
= self
->entries
; it
; it
= it
->next
) {
98 ((ObMenuEntry
*)it
->data
)->y
= item_y
;
99 menu_entry_render(it
->data
);
100 item_y
+= self
->item_h
;
103 self
->invalid
= FALSE
;
106 void menu_entry_render(ObMenuEntry
*self
)
108 ObMenu
*menu
= self
->parent
;
111 switch (self
->render_type
) {
112 case OB_MENU_ENTRY_RENDER_TYPE_SUBMENU
:
113 /* TODO: submenu mask */
114 case OB_MENU_ENTRY_RENDER_TYPE_BOOLEAN
:
115 /* TODO: boolean check */
116 a
= self
->enabled
? (self
->hilite
? self
->a_hilite
: self
->a_item
)
119 case OB_MENU_ENTRY_RENDER_TYPE_NONE
:
120 a
= self
->enabled
? (self
->hilite
? self
->a_hilite
: self
->a_item
)
123 case OB_MENU_ENTRY_RENDER_TYPE_SEPARATOR
:
128 g_message("unhandled render_type");
129 a
= !self
->enabled
? self
->a_disabled
:
132 self
->render_type
== OB_MENU_ENTRY_RENDER_TYPE_SUBMENU
) ?
133 self
->a_hilite
: self
->a_item
);
136 g_message ("%s %d", self
->label
, self
->hilite
);
138 XMoveResizeWindow(ob_display
, self
->item
, 0, self
->y
,
139 menu
->size
.width
, menu
->item_h
);
141 a
->surface
.parent
= menu
->a_items
;
142 a
->surface
.parentx
= 0;
143 a
->surface
.parenty
= self
->y
;
145 RrPaint(a
, self
->item
, menu
->size
.width
, menu
->item_h
);