1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: menubar.c |
2 | * File: menubar.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: menubar.C,v 1.2 2003/11/24 17:31:27 pcg Exp $ |
|
|
5 | * |
4 | * |
6 | * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA> |
5 | * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA> |
7 | * |
6 | * |
8 | * This program is free software; you can redistribute it and/or modify |
7 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
8 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
31 | #include "menubar.intpro" /* PROTOS for internal routines */ |
30 | #include "menubar.intpro" /* PROTOS for internal routines */ |
32 | |
31 | |
33 | #define Menu_PixelWidth(menu) \ |
32 | #define Menu_PixelWidth(menu) \ |
34 | (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) |
33 | (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) |
35 | |
34 | |
36 | static const struct { |
35 | static const struct |
|
|
36 | { |
37 | const char name; /* (l)eft, (u)p, (d)own, (r)ight */ |
37 | const char name; /* (l)eft, (u)p, (d)own, (r)ight */ |
38 | const unsigned char str[5]; /* str[0] = STRLEN (str+1) */ |
38 | const unsigned char str[5]; /* str[0] = STRLEN (str+1) */ |
|
|
39 | } |
39 | } Arrows[NARROWS] = { |
40 | Arrows[NARROWS] = { |
40 | { 'l', "\003\033[D" }, |
41 | { 'l', "\003\033[D" }, |
41 | { 'u', "\003\033[A" }, |
42 | { 'u', "\003\033[A" }, |
42 | { 'd', "\003\033[B" }, |
43 | { 'd', "\003\033[B" }, |
43 | { 'r', "\003\033[C" } |
44 | { 'r', "\003\033[C" } |
44 | }; |
45 | }; |
45 | |
46 | |
46 | /*}}} */ |
47 | /*}}} */ |
47 | |
48 | |
48 | /* |
49 | /* |
49 | * find an item called NAME in MENU |
50 | * find an item called NAME in MENU |
50 | */ |
51 | */ |
51 | /* INTPROTO */ |
|
|
52 | menuitem_t * |
52 | menuitem_t * |
53 | rxvt_menuitem_find(const menu_t *menu, const char *name) |
53 | rxvt_menuitem_find(const menu_t *menu, const char *name) |
54 | { |
54 | { |
55 | menuitem_t *item; |
55 | menuitem_t *item; |
56 | |
56 | |
57 | #ifdef DEBUG_STRICT |
57 | #ifdef DEBUG_STRICT |
58 | assert(name != NULL); |
58 | assert(name != NULL); |
59 | assert(menu != NULL); |
59 | assert(menu != NULL); |
60 | #endif |
60 | #endif |
61 | |
61 | |
62 | /* find the last item in the menu, this is good for separators */ |
62 | /* find the last item in the menu, this is good for separators */ |
63 | for (item = menu->tail; item != NULL; item = item->prev) { |
63 | for (item = menu->tail; item != NULL; item = item->prev) |
|
|
64 | { |
64 | if (item->entry.type == MenuSubMenu) { |
65 | if (item->entry.type == MenuSubMenu) |
|
|
66 | { |
65 | if (!STRCMP(name, (item->entry.submenu.menu)->name)) |
67 | if (!STRCMP(name, (item->entry.submenu.menu)->name)) |
66 | break; |
68 | break; |
|
|
69 | } |
67 | } else if ((isSeparator(name) && isSeparator(item->name)) |
70 | else if ((isSeparator(name) && isSeparator(item->name)) |
68 | || !STRCMP(name, item->name)) |
71 | || !STRCMP(name, item->name)) |
69 | break; |
72 | break; |
70 | } |
73 | } |
71 | return item; |
74 | return item; |
72 | } |
75 | } |
73 | |
76 | |
74 | /* |
77 | /* |
75 | * unlink ITEM from its MENU and free its memory |
78 | * unlink ITEM from its MENU and free its memory |
76 | */ |
79 | */ |
77 | /* INTPROTO */ |
|
|
78 | void |
80 | void |
79 | rxvt_menuitem_free(pR_ menu_t *menu, menuitem_t *item) |
81 | rxvt_term::menuitem_free (menu_t *menu, menuitem_t *item) |
80 | { |
82 | { |
81 | /* disconnect */ |
83 | /* disconnect */ |
82 | menuitem_t *prev, *next; |
84 | menuitem_t *prev, *next; |
83 | |
85 | |
84 | #ifdef DEBUG_STRICT |
86 | #ifdef DEBUG_STRICT |
85 | assert(menu != NULL); |
87 | assert(menu != NULL); |
86 | #endif |
88 | #endif |
87 | |
89 | |
88 | prev = item->prev; |
90 | prev = item->prev; |
89 | next = item->next; |
91 | next = item->next; |
90 | if (prev != NULL) |
92 | if (prev != NULL) |
91 | prev->next = next; |
93 | prev->next = next; |
92 | if (next != NULL) |
94 | if (next != NULL) |
93 | next->prev = prev; |
95 | next->prev = prev; |
94 | |
96 | |
95 | /* new head, tail */ |
97 | /* new head, tail */ |
96 | if (menu->tail == item) |
98 | if (menu->tail == item) |
97 | menu->tail = prev; |
99 | menu->tail = prev; |
98 | if (menu->head == item) |
100 | if (menu->head == item) |
99 | menu->head = next; |
101 | menu->head = next; |
100 | |
102 | |
101 | switch (item->entry.type) { |
103 | switch (item->entry.type) |
|
|
104 | { |
102 | case MenuAction: |
105 | case MenuAction: |
103 | case MenuTerminalAction: |
106 | case MenuTerminalAction: |
104 | free(item->entry.action.str); |
107 | free(item->entry.action.str); |
105 | break; |
108 | break; |
106 | case MenuSubMenu: |
109 | case MenuSubMenu: |
107 | rxvt_menu_delete(aR_ item->entry.submenu.menu); |
110 | menu_delete (item->entry.submenu.menu); |
108 | break; |
111 | break; |
109 | } |
112 | } |
110 | if (item->name != NULL) |
113 | if (item->name != NULL) |
111 | free(item->name); |
114 | free(item->name); |
112 | if (item->name2 != NULL) |
115 | if (item->name2 != NULL) |
113 | free(item->name2); |
116 | free(item->name2); |
114 | free(item); |
117 | free(item); |
115 | } |
118 | } |
116 | |
119 | |
117 | /* |
120 | /* |
118 | * sort command vs. terminal actions and |
121 | * sort command vs. terminal actions and |
119 | * remove the first character of STR if it's '\0' |
122 | * remove the first character of STR if it's '\0' |
120 | */ |
123 | */ |
121 | /* INTPROTO */ |
|
|
122 | int |
124 | int |
123 | rxvt_action_type(action_t *action, unsigned char *str) |
125 | rxvt_action_type(action_t *action, unsigned char *str) |
124 | { |
126 | { |
125 | unsigned int len; |
127 | unsigned int len; |
126 | |
128 | |
127 | #if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS) |
129 | #if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS) |
128 | len = STRLEN(str); |
130 | len = STRLEN(str); |
129 | fprintf(stderr, "(len %d) = %s\n", len, str); |
131 | fprintf(stderr, "(len %d) = %s\n", len, str); |
130 | #else |
132 | #else |
131 | len = rxvt_Str_escaped((char *)str); |
133 | len = rxvt_Str_escaped((char *)str); |
132 | #endif |
134 | #endif |
133 | |
135 | |
134 | if (!len) |
136 | if (!len) |
135 | return -1; |
137 | return -1; |
136 | |
138 | |
137 | /* sort command vs. terminal actions */ |
139 | /* sort command vs. terminal actions */ |
138 | action->type = MenuAction; |
140 | action->type = MenuAction; |
139 | if (str[0] == '\0') { |
141 | if (str[0] == '\0') |
|
|
142 | { |
140 | /* the functional equivalent: memmove (str, str+1, len); */ |
143 | /* the functional equivalent: memmove (str, str+1, len); */ |
141 | unsigned char *dst = (str); |
144 | unsigned char *dst = (str); |
142 | unsigned char *src = (str + 1); |
145 | unsigned char *src = (str + 1); |
143 | unsigned char *end = (str + len); |
146 | unsigned char *end = (str + len); |
144 | |
147 | |
145 | while (src <= end) |
148 | while (src <= end) |
146 | *dst++ = *src++; |
149 | *dst++ = *src++; |
147 | |
150 | |
148 | len--; /* decrement length */ |
151 | len--; /* decrement length */ |
149 | if (str[0] != '\0') |
152 | if (str[0] != '\0') |
150 | action->type = MenuTerminalAction; |
153 | action->type = MenuTerminalAction; |
151 | } |
154 | } |
152 | action->str = str; |
155 | action->str = str; |
153 | action->len = len; |
156 | action->len = len; |
154 | |
157 | |
155 | return 0; |
158 | return 0; |
156 | } |
159 | } |
157 | |
160 | |
158 | /* INTPROTO */ |
|
|
159 | int |
161 | int |
160 | rxvt_action_dispatch(pR_ action_t *action) |
162 | rxvt_term::action_dispatch (action_t *action) |
161 | { |
163 | { |
162 | switch (action->type) { |
164 | switch (action->type) |
|
|
165 | { |
163 | case MenuTerminalAction: |
166 | case MenuTerminalAction: |
164 | rxvt_cmd_write(aR_ action->str, action->len); |
167 | cmd_write (action->str, action->len); |
165 | break; |
168 | break; |
166 | |
169 | |
167 | case MenuAction: |
170 | case MenuAction: |
168 | rxvt_tt_write(aR_ action->str, action->len); |
171 | tt_write (action->str, action->len); |
169 | break; |
172 | break; |
170 | |
173 | |
171 | default: |
174 | default: |
172 | return -1; |
175 | return -1; |
173 | break; |
176 | break; |
174 | } |
177 | } |
175 | return 0; |
178 | return 0; |
176 | } |
179 | } |
177 | |
180 | |
178 | /* return the arrow index corresponding to NAME */ |
181 | /* return the arrow index corresponding to NAME */ |
179 | /* INTPROTO */ |
|
|
180 | int |
182 | int |
181 | rxvt_menuarrow_find(char name) |
183 | rxvt_menuarrow_find(char name) |
182 | { |
184 | { |
183 | int i; |
185 | int i; |
184 | |
186 | |
185 | for (i = 0; i < NARROWS; i++) |
187 | for (i = 0; i < NARROWS; i++) |
186 | if (name == Arrows[i].name) |
188 | if (name == Arrows[i].name) |
187 | return i; |
189 | return i; |
188 | return -1; |
190 | return -1; |
189 | } |
191 | } |
190 | |
192 | |
191 | /* free the memory associated with arrow NAME of the current menubar */ |
193 | /* free the memory associated with arrow NAME of the current menubar */ |
192 | /* INTPROTO */ |
|
|
193 | void |
194 | void |
194 | rxvt_menuarrow_free(pR_ char name) |
195 | rxvt_term::menuarrow_free (char name) |
195 | { |
196 | { |
196 | int i; |
197 | int i; |
197 | |
198 | |
198 | if (name) { |
199 | if (name) |
|
|
200 | { |
199 | i = rxvt_menuarrow_find(name); |
201 | i = rxvt_menuarrow_find(name); |
200 | if (i >= 0) { |
202 | if (i >= 0) |
|
|
203 | { |
201 | action_t *act = &(R->h->CurrentBar->arrows[i]); |
204 | action_t *act = &(CurrentBar->arrows[i]); |
202 | |
205 | |
203 | switch (act->type) { |
206 | switch (act->type) |
|
|
207 | { |
204 | case MenuAction: |
208 | case MenuAction: |
205 | case MenuTerminalAction: |
209 | case MenuTerminalAction: |
206 | free(act->str); |
210 | free(act->str); |
207 | act->str = NULL; |
211 | act->str = NULL; |
208 | act->len = 0; |
212 | act->len = 0; |
209 | break; |
213 | break; |
|
|
214 | } |
|
|
215 | act->type = MenuLabel; |
|
|
216 | } |
210 | } |
217 | } |
211 | act->type = MenuLabel; |
218 | else |
212 | } |
219 | { |
213 | } else { |
|
|
214 | for (i = 0; i < NARROWS; i++) |
220 | for (i = 0; i < NARROWS; i++) |
215 | rxvt_menuarrow_free(aR_ Arrows[i].name); |
221 | menuarrow_free (Arrows[i].name); |
216 | } |
222 | } |
217 | } |
223 | } |
218 | |
224 | |
219 | /* INTPROTO */ |
|
|
220 | void |
225 | void |
221 | rxvt_menuarrow_add(pR_ char *string) |
226 | rxvt_term::menuarrow_add (char *string) |
222 | { |
227 | { |
223 | int i; |
228 | int i; |
224 | unsigned xtra_len; |
229 | unsigned xtra_len; |
225 | char *p; |
230 | char *p; |
226 | struct { |
231 | struct |
|
|
232 | { |
227 | char *str; |
233 | char *str; |
228 | int len; |
234 | int len; |
229 | } |
235 | } |
230 | beg = { NULL, 0 }, |
236 | beg = { NULL, 0 }, |
231 | end = { NULL, 0 }, |
237 | end = { NULL, 0 }, |
232 | *cur, |
238 | *cur, |
233 | parse[NARROWS]; |
239 | parse[NARROWS]; |
234 | |
240 | |
235 | MEMSET(parse, 0, sizeof(parse)); |
241 | MEMSET(parse, 0, sizeof(parse)); |
236 | |
242 | |
237 | /* fprintf(stderr, "add arrows = `%s'\n", string); */ |
243 | /* fprintf(stderr, "add arrows = `%s'\n", string); */ |
238 | for (p = string; p != NULL && *p; string = p) { |
244 | for (p = string; p != NULL && *p; string = p) |
|
|
245 | { |
239 | p = (string + 3); |
246 | p = (string + 3); |
240 | /* fprintf(stderr, "parsing at %s\n", string); */ |
247 | /* fprintf(stderr, "parsing at %s\n", string); */ |
241 | switch (string[1]) { |
248 | switch (string[1]) |
242 | case 'b': |
249 | { |
|
|
250 | case 'b': |
243 | cur = &beg; |
251 | cur = &beg; |
244 | break; |
252 | break; |
245 | case 'e': |
253 | case 'e': |
246 | cur = &end; |
254 | cur = &end; |
247 | break; |
255 | break; |
248 | |
256 | |
249 | default: |
257 | default: |
250 | i = rxvt_menuarrow_find(string[1]); |
258 | i = rxvt_menuarrow_find(string[1]); |
251 | if (i >= 0) |
259 | if (i >= 0) |
252 | cur = &(parse[i]); |
260 | cur = &(parse[i]); |
253 | else |
261 | else |
254 | continue; /* not found */ |
262 | continue; /* not found */ |
255 | break; |
263 | break; |
256 | } |
264 | } |
257 | |
265 | |
258 | string = p; |
266 | string = p; |
259 | cur->str = string; |
267 | cur->str = string; |
260 | cur->len = 0; |
268 | cur->len = 0; |
261 | |
269 | |
262 | if (cur == &end) { |
270 | if (cur == &end) |
|
|
271 | { |
263 | p = STRCHR(string, '\0'); |
272 | p = STRCHR(string, '\0'); |
264 | } else { |
273 | } |
|
|
274 | else |
|
|
275 | { |
265 | char *next = string; |
276 | char *next = string; |
266 | |
277 | |
267 | while (1) { |
278 | while (1) |
268 | p = STRCHR(next, '<'); |
279 | { |
269 | if (p != NULL) { |
280 | p = STRCHR(next, '<'); |
|
|
281 | if (p != NULL) |
|
|
282 | { |
270 | if (p[1] && p[2] == '>') |
283 | if (p[1] && p[2] == '>') |
271 | break; |
284 | break; |
272 | /* parsed */ |
285 | /* parsed */ |
273 | } else { |
286 | } |
|
|
287 | else |
|
|
288 | { |
274 | if (beg.str == NULL) /* no end needed */ |
289 | if (beg.str == NULL) /* no end needed */ |
275 | p = STRCHR(next, '\0'); |
290 | p = STRCHR(next, '\0'); |
276 | break; |
291 | break; |
277 | } |
292 | } |
278 | next = (p + 1); |
293 | next = (p + 1); |
279 | } |
294 | } |
280 | } |
295 | } |
281 | |
296 | |
282 | if (p == NULL) |
297 | if (p == NULL) |
283 | return; |
298 | return; |
284 | cur->len = (p - string); |
299 | cur->len = (p - string); |
285 | } |
300 | } |
286 | |
301 | |
287 | #ifdef DEBUG_MENUARROWS |
302 | #ifdef DEBUG_MENUARROWS |
288 | cur = &beg; |
303 | cur = &beg; |
289 | fprintf(stderr, "<b>(len %d) = %.*s\n", |
304 | fprintf(stderr, "<b>(len %d) = %.*s\n", |
290 | cur->len, cur->len, (cur->str ? cur->str : "")); |
305 | cur->len, cur->len, (cur->str ? cur->str : "")); |
291 | for (i = 0; i < NARROWS; i++) { |
306 | for (i = 0; i < NARROWS; i++) |
|
|
307 | { |
292 | cur = &(parse[i]); |
308 | cur = &(parse[i]); |
293 | fprintf(stderr, "<%c>(len %d) = %.*s\n", |
309 | fprintf(stderr, "<%c>(len %d) = %.*s\n", |
294 | Arrows[i].name, |
310 | Arrows[i].name, |
295 | cur->len, cur->len, (cur->str ? cur->str : "")); |
311 | cur->len, cur->len, (cur->str ? cur->str : "")); |
296 | } |
312 | } |
297 | cur = &end; |
313 | cur = &end; |
298 | fprintf(stderr, "<e>(len %d) = %.*s\n", |
314 | fprintf(stderr, "<e>(len %d) = %.*s\n", |
299 | cur->len, cur->len, (cur->str ? cur->str : "")); |
315 | cur->len, cur->len, (cur->str ? cur->str : "")); |
300 | #endif |
316 | #endif |
301 | |
317 | |
302 | xtra_len = (beg.len + end.len); |
318 | xtra_len = (beg.len + end.len); |
303 | for (i = 0; i < NARROWS; i++) { |
319 | for (i = 0; i < NARROWS; i++) |
|
|
320 | { |
304 | if (xtra_len || parse[i].len) |
321 | if (xtra_len || parse[i].len) |
305 | rxvt_menuarrow_free(aR_ Arrows[i].name); |
322 | menuarrow_free (Arrows[i].name); |
306 | } |
323 | } |
307 | |
324 | |
308 | for (i = 0; i < NARROWS; i++) { |
325 | for (i = 0; i < NARROWS; i++) |
|
|
326 | { |
309 | unsigned char *str; |
327 | unsigned char *str; |
310 | unsigned int len; |
328 | unsigned int len; |
311 | |
329 | |
312 | if (!parse[i].len) |
330 | if (!parse[i].len) |
313 | continue; |
331 | continue; |
314 | |
332 | |
315 | str = rxvt_malloc(parse[i].len + xtra_len + 1); |
333 | str = rxvt_malloc(parse[i].len + xtra_len + 1); |
316 | |
334 | |
317 | len = 0; |
335 | len = 0; |
318 | if (beg.len) { |
336 | if (beg.len) |
|
|
337 | { |
319 | STRNCPY(str + len, beg.str, beg.len); |
338 | STRNCPY(str + len, beg.str, beg.len); |
320 | len += beg.len; |
339 | len += beg.len; |
321 | } |
340 | } |
322 | STRNCPY(str + len, parse[i].str, parse[i].len); |
341 | STRNCPY(str + len, parse[i].str, parse[i].len); |
323 | len += parse[i].len; |
342 | len += parse[i].len; |
324 | |
343 | |
325 | if (end.len) { |
344 | if (end.len) |
|
|
345 | { |
326 | STRNCPY(str + len, end.str, end.len); |
346 | STRNCPY(str + len, end.str, end.len); |
327 | len += end.len; |
347 | len += end.len; |
328 | } |
348 | } |
329 | str[len] = '\0'; |
349 | str[len] = '\0'; |
330 | |
350 | |
331 | #ifdef DEBUG_MENUARROWS |
351 | #ifdef DEBUG_MENUARROWS |
332 | fprintf(stderr, "<%c>(len %d) = %s\n", Arrows[i].name, len, str); |
352 | fprintf(stderr, "<%c>(len %d) = %s\n", Arrows[i].name, len, str); |
333 | #endif |
353 | #endif |
334 | if (rxvt_action_type(&(R->h->CurrentBar->arrows[i]), str) < 0) |
354 | if (rxvt_action_type(&(CurrentBar->arrows[i]), str) < 0) |
335 | free(str); |
355 | free(str); |
336 | } |
356 | } |
337 | } |
357 | } |
338 | |
358 | |
339 | /* INTPROTO */ |
|
|
340 | menuitem_t * |
359 | menuitem_t * |
341 | rxvt_menuitem_add(menu_t *menu, const char *name, const char *name2, const char *action) |
360 | rxvt_menuitem_add(menu_t *menu, const char *name, const char *name2, const char *action) |
342 | { |
361 | { |
343 | menuitem_t *item; |
362 | menuitem_t *item; |
344 | unsigned int len; |
363 | unsigned int len; |
345 | |
364 | |
346 | #ifdef DEBUG_STRICT |
365 | #ifdef DEBUG_STRICT |
347 | assert(name != NULL); |
366 | assert(name != NULL); |
348 | assert(action != NULL); |
367 | assert(action != NULL); |
349 | #endif |
368 | #endif |
350 | |
369 | |
351 | if (menu == NULL) |
370 | if (menu == NULL) |
352 | return NULL; |
371 | return NULL; |
353 | |
372 | |
354 | if (isSeparator(name)) { |
373 | if (isSeparator(name)) |
|
|
374 | { |
355 | /* add separator, no action */ |
375 | /* add separator, no action */ |
356 | name = ""; |
376 | name = ""; |
357 | action = ""; |
377 | action = ""; |
358 | } else { |
378 | } |
359 | /* |
379 | else |
|
|
380 | { |
|
|
381 | /* |
360 | * add/replace existing menu item |
382 | * add/replace existing menu item |
361 | */ |
383 | */ |
362 | item = rxvt_menuitem_find(menu, name); |
384 | item = rxvt_menuitem_find(menu, name); |
363 | if (item != NULL) { |
385 | if (item != NULL) |
|
|
386 | { |
364 | if (item->name2 != NULL && name2 != NULL) { |
387 | if (item->name2 != NULL && name2 != NULL) |
365 | free(item->name2); |
388 | { |
366 | item->len2 = 0; |
389 | free(item->name2); |
367 | item->name2 = NULL; |
390 | item->len2 = 0; |
|
|
391 | item->name2 = NULL; |
|
|
392 | } |
|
|
393 | switch (item->entry.type) |
|
|
394 | { |
|
|
395 | case MenuAction: |
|
|
396 | case MenuTerminalAction: |
|
|
397 | free(item->entry.action.str); |
|
|
398 | item->entry.action.str = NULL; |
|
|
399 | break; |
|
|
400 | } |
|
|
401 | goto Item_Found; |
|
|
402 | } |
368 | } |
403 | } |
369 | switch (item->entry.type) { |
|
|
370 | case MenuAction: |
|
|
371 | case MenuTerminalAction: |
|
|
372 | free(item->entry.action.str); |
|
|
373 | item->entry.action.str = NULL; |
|
|
374 | break; |
|
|
375 | } |
|
|
376 | goto Item_Found; |
|
|
377 | } |
|
|
378 | } |
|
|
379 | /* allocate a new itemect */ |
404 | /* allocate a new itemect */ |
380 | item = (menuitem_t *) rxvt_malloc(sizeof(menuitem_t)); |
405 | item = (menuitem_t *) rxvt_malloc(sizeof(menuitem_t)); |
381 | |
406 | |
382 | item->len2 = 0; |
407 | item->len2 = 0; |
383 | item->name2 = NULL; |
408 | item->name2 = NULL; |
384 | |
409 | |
385 | len = STRLEN(name); |
410 | len = STRLEN(name); |
386 | item->name = rxvt_malloc(len + 1); |
411 | item->name = rxvt_malloc(len + 1); |
387 | STRCPY(item->name, name); |
412 | STRCPY(item->name, name); |
388 | if (name[0] == '.' && name[1] != '.') |
413 | if (name[0] == '.' && name[1] != '.') |
389 | len = 0; /* hidden menu name */ |
414 | len = 0; /* hidden menu name */ |
390 | item->len = len; |
415 | item->len = len; |
391 | |
416 | |
392 | /* add to tail of list */ |
417 | /* add to tail of list */ |
393 | item->prev = menu->tail; |
418 | item->prev = menu->tail; |
394 | item->next = NULL; |
419 | item->next = NULL; |
395 | |
420 | |
396 | if (menu->tail != NULL) |
421 | if (menu->tail != NULL) |
397 | (menu->tail)->next = item; |
422 | (menu->tail)->next = item; |
398 | menu->tail = item; |
423 | menu->tail = item; |
399 | /* fix head */ |
424 | /* fix head */ |
400 | if (menu->head == NULL) |
425 | if (menu->head == NULL) |
401 | menu->head = item; |
426 | menu->head = item; |
402 | |
427 | |
403 | /* |
428 | /* |
404 | * add action |
429 | * add action |
405 | */ |
430 | */ |
406 | Item_Found: |
431 | Item_Found: |
407 | if (name2 != NULL && item->name2 == NULL) { |
432 | if (name2 != NULL && item->name2 == NULL) |
|
|
433 | { |
408 | len = STRLEN(name2); |
434 | len = STRLEN(name2); |
409 | if (len == 0) |
435 | if (len == 0) |
410 | item->name2 = NULL; |
436 | item->name2 = NULL; |
411 | else { |
437 | else |
|
|
438 | { |
412 | item->name2 = rxvt_malloc(len + 1); |
439 | item->name2 = rxvt_malloc(len + 1); |
413 | STRCPY(item->name2, name2); |
440 | STRCPY(item->name2, name2); |
414 | } |
441 | } |
415 | item->len2 = len; |
442 | item->len2 = len; |
416 | } |
443 | } |
417 | item->entry.type = MenuLabel; |
444 | item->entry.type = MenuLabel; |
418 | len = STRLEN(action); |
445 | len = STRLEN(action); |
419 | |
446 | |
420 | if (len == 0 && item->name2 != NULL) { |
447 | if (len == 0 && item->name2 != NULL) |
|
|
448 | { |
421 | action = item->name2; |
449 | action = item->name2; |
422 | len = item->len2; |
450 | len = item->len2; |
423 | } |
451 | } |
424 | if (len) { |
452 | if (len) |
|
|
453 | { |
425 | unsigned char *str = rxvt_malloc(len + 1); |
454 | unsigned char *str = rxvt_malloc(len + 1); |
426 | |
455 | |
427 | STRCPY(str, action); |
456 | STRCPY(str, action); |
428 | |
457 | |
429 | if (rxvt_action_type(&(item->entry.action), str) < 0) |
458 | if (rxvt_action_type(&(item->entry.action), str) < 0) |
430 | free(str); |
459 | free(str); |
431 | } |
460 | } |
432 | /* new item and a possible increase in width */ |
461 | /* new item and a possible increase in width */ |
433 | if (menu->width < (item->len + item->len2)) |
462 | if (menu->width < (item->len + item->len2)) |
434 | menu->width = (item->len + item->len2); |
463 | menu->width = (item->len + item->len2); |
435 | |
464 | |
436 | return item; |
465 | return item; |
437 | } |
466 | } |
438 | |
467 | |
439 | /* |
468 | /* |
440 | * search for the base starting menu for NAME. |
469 | * search for the base starting menu for NAME. |
441 | * return a pointer to the portion of NAME that remains |
470 | * return a pointer to the portion of NAME that remains |
442 | */ |
471 | */ |
443 | /* INTPROTO */ |
|
|
444 | char * |
472 | char * |
445 | rxvt_menu_find_base(pR_ menu_t **menu, char *path) |
473 | rxvt_term::menu_find_base (menu_t **menu, char *path) |
446 | { |
474 | { |
447 | menu_t *m = NULL; |
475 | menu_t *m = NULL; |
448 | menuitem_t *item; |
476 | menuitem_t *item; |
449 | |
477 | |
450 | #ifdef DEBUG_STRICT |
478 | #ifdef DEBUG_STRICT |
451 | assert(menu != NULL); |
479 | assert(menu != NULL); |
452 | assert(R->h->CurrentBar != NULL); |
480 | assert(CurrentBar != NULL); |
453 | #endif |
481 | #endif |
454 | |
482 | |
455 | if (path[0] == '\0') |
483 | if (path[0] == '\0') |
456 | return path; |
|
|
457 | |
|
|
458 | if (STRCHR(path, '/') != NULL) { |
|
|
459 | char *p = path; |
|
|
460 | |
|
|
461 | while ((p = STRCHR(p, '/')) != NULL) { |
|
|
462 | p++; |
|
|
463 | if (*p == '/') |
|
|
464 | path = p; |
|
|
465 | } |
|
|
466 | if (path[0] == '/') { |
|
|
467 | path++; |
|
|
468 | *menu = NULL; |
|
|
469 | } |
|
|
470 | while ((p = STRCHR(path, '/')) != NULL) { |
|
|
471 | p[0] = '\0'; |
|
|
472 | if (path[0] == '\0') |
|
|
473 | return NULL; |
|
|
474 | if (!STRCMP(path, DOT)) { |
|
|
475 | /* nothing to do */ |
|
|
476 | } else if (!STRCMP(path, DOTS)) { |
|
|
477 | if (*menu != NULL) |
|
|
478 | *menu = (*menu)->parent; |
|
|
479 | } else { |
|
|
480 | path = rxvt_menu_find_base(aR_ menu, path); |
|
|
481 | if (path[0] != '\0') { /* not found */ |
|
|
482 | p[0] = '/'; /* fix-up name again */ |
|
|
483 | return path; |
|
|
484 | } |
|
|
485 | } |
|
|
486 | |
|
|
487 | path = (p + 1); |
|
|
488 | } |
|
|
489 | } |
|
|
490 | if (!STRCMP(path, DOTS)) { |
|
|
491 | path += STRLEN(DOTS); |
|
|
492 | if (*menu != NULL) |
|
|
493 | *menu = (*menu)->parent; |
|
|
494 | return path; |
|
|
495 | } |
|
|
496 | /* find this menu */ |
|
|
497 | if (*menu == NULL) { |
|
|
498 | for (m = R->h->CurrentBar->tail; m != NULL; m = m->prev) { |
|
|
499 | if (!STRCMP(path, m->name)) |
|
|
500 | break; |
|
|
501 | } |
|
|
502 | } else { |
|
|
503 | /* find this menu */ |
|
|
504 | for (item = (*menu)->tail; item != NULL; item = item->prev) { |
|
|
505 | if (item->entry.type == MenuSubMenu |
|
|
506 | && !STRCMP(path, (item->entry.submenu.menu)->name)) { |
|
|
507 | m = (item->entry.submenu.menu); |
|
|
508 | break; |
|
|
509 | } |
|
|
510 | } |
|
|
511 | } |
|
|
512 | if (m != NULL) { |
|
|
513 | *menu = m; |
|
|
514 | path += STRLEN(path); |
|
|
515 | } |
|
|
516 | return path; |
484 | return path; |
|
|
485 | |
|
|
486 | if (STRCHR(path, '/') != NULL) |
|
|
487 | { |
|
|
488 | char *p = path; |
|
|
489 | |
|
|
490 | while ((p = STRCHR(p, '/')) != NULL) |
|
|
491 | { |
|
|
492 | p++; |
|
|
493 | if (*p == '/') |
|
|
494 | path = p; |
|
|
495 | } |
|
|
496 | if (path[0] == '/') |
|
|
497 | { |
|
|
498 | path++; |
|
|
499 | *menu = NULL; |
|
|
500 | } |
|
|
501 | while ((p = STRCHR(path, '/')) != NULL) |
|
|
502 | { |
|
|
503 | p[0] = '\0'; |
|
|
504 | if (path[0] == '\0') |
|
|
505 | return NULL; |
|
|
506 | if (!STRCMP(path, DOT)) |
|
|
507 | { |
|
|
508 | /* nothing to do */ |
|
|
509 | } |
|
|
510 | else if (!STRCMP(path, DOTS)) |
|
|
511 | { |
|
|
512 | if (*menu != NULL) |
|
|
513 | *menu = (*menu)->parent; |
|
|
514 | } |
|
|
515 | else |
|
|
516 | { |
|
|
517 | path = menu_find_base (menu, path); |
|
|
518 | if (path[0] != '\0') |
|
|
519 | { /* not found */ |
|
|
520 | p[0] = '/'; /* fix-up name again */ |
|
|
521 | return path; |
|
|
522 | } |
|
|
523 | } |
|
|
524 | |
|
|
525 | path = (p + 1); |
|
|
526 | } |
|
|
527 | } |
|
|
528 | if (!STRCMP(path, DOTS)) |
|
|
529 | { |
|
|
530 | path += STRLEN(DOTS); |
|
|
531 | if (*menu != NULL) |
|
|
532 | *menu = (*menu)->parent; |
|
|
533 | return path; |
|
|
534 | } |
|
|
535 | /* find this menu */ |
|
|
536 | if (*menu == NULL) |
|
|
537 | { |
|
|
538 | for (m = CurrentBar->tail; m != NULL; m = m->prev) |
|
|
539 | { |
|
|
540 | if (!STRCMP(path, m->name)) |
|
|
541 | break; |
|
|
542 | } |
|
|
543 | } |
|
|
544 | else |
|
|
545 | { |
|
|
546 | /* find this menu */ |
|
|
547 | for (item = (*menu)->tail; item != NULL; item = item->prev) |
|
|
548 | { |
|
|
549 | if (item->entry.type == MenuSubMenu |
|
|
550 | && !STRCMP(path, (item->entry.submenu.menu)->name)) |
|
|
551 | { |
|
|
552 | m = (item->entry.submenu.menu); |
|
|
553 | break; |
|
|
554 | } |
|
|
555 | } |
|
|
556 | } |
|
|
557 | if (m != NULL) |
|
|
558 | { |
|
|
559 | *menu = m; |
|
|
560 | path += STRLEN(path); |
|
|
561 | } |
|
|
562 | return path; |
517 | } |
563 | } |
518 | |
564 | |
519 | /* |
565 | /* |
520 | * delete this entire menu |
566 | * delete this entire menu |
521 | */ |
567 | */ |
522 | /* INTPROTO */ |
|
|
523 | menu_t * |
568 | menu_t * |
524 | rxvt_menu_delete(pR_ menu_t *menu) |
569 | rxvt_term::menu_delete (menu_t *menu) |
525 | { |
570 | { |
526 | menu_t *parent = NULL, *prev, *next; |
571 | menu_t *parent = NULL, *prev, *next; |
527 | menuitem_t *item; |
572 | menuitem_t *item; |
528 | bar_t *CurrentBar = R->h->CurrentBar; |
573 | bar_t *CurrentBar = CurrentBar; |
529 | |
574 | |
530 | #ifdef DEBUG_STRICT |
575 | #ifdef DEBUG_STRICT |
531 | assert(CurrentBar != NULL); |
576 | assert(CurrentBar != NULL); |
532 | #endif |
577 | #endif |
533 | |
578 | |
534 | /* delete the entire menu */ |
579 | /* delete the entire menu */ |
535 | if (menu == NULL) |
580 | if (menu == NULL) |
536 | return NULL; |
581 | return NULL; |
537 | |
582 | |
538 | parent = menu->parent; |
583 | parent = menu->parent; |
539 | |
584 | |
540 | /* unlink MENU */ |
585 | /* unlink MENU */ |
541 | prev = menu->prev; |
586 | prev = menu->prev; |
542 | next = menu->next; |
587 | next = menu->next; |
543 | if (prev != NULL) |
588 | if (prev != NULL) |
544 | prev->next = next; |
589 | prev->next = next; |
545 | if (next != NULL) |
590 | if (next != NULL) |
546 | next->prev = prev; |
591 | next->prev = prev; |
547 | |
592 | |
548 | /* fix the index */ |
593 | /* fix the index */ |
549 | if (parent == NULL) { |
594 | if (parent == NULL) |
|
|
595 | { |
550 | const int len = (menu->len + HSPACE); |
596 | const int len = (menu->len + HSPACE); |
551 | |
597 | |
552 | if (CurrentBar->tail == menu) |
598 | if (CurrentBar->tail == menu) |
553 | CurrentBar->tail = prev; |
599 | CurrentBar->tail = prev; |
554 | if (CurrentBar->head == menu) |
600 | if (CurrentBar->head == menu) |
555 | CurrentBar->head = next; |
601 | CurrentBar->head = next; |
556 | |
602 | |
557 | for (next = menu->next; next != NULL; next = next->next) |
603 | for (next = menu->next; next != NULL; next = next->next) |
558 | next->x -= len; |
604 | next->x -= len; |
559 | } else { |
605 | } |
|
|
606 | else |
|
|
607 | { |
560 | for (item = parent->tail; item != NULL; item = item->prev) { |
608 | for (item = parent->tail; item != NULL; item = item->prev) |
|
|
609 | { |
561 | if (item->entry.type == MenuSubMenu |
610 | if (item->entry.type == MenuSubMenu |
562 | && item->entry.submenu.menu == menu) { |
611 | && item->entry.submenu.menu == menu) |
|
|
612 | { |
563 | item->entry.submenu.menu = NULL; |
613 | item->entry.submenu.menu = NULL; |
564 | rxvt_menuitem_free(aR_ menu->parent, item); |
614 | menuitem_free (menu->parent, item); |
565 | break; |
615 | break; |
|
|
616 | } |
|
|
617 | } |
566 | } |
618 | } |
567 | } |
|
|
568 | } |
|
|
569 | |
619 | |
570 | item = menu->tail; |
620 | item = menu->tail; |
571 | while (item != NULL) { |
621 | while (item != NULL) |
|
|
622 | { |
572 | menuitem_t *p = item->prev; |
623 | menuitem_t *p = item->prev; |
573 | |
624 | |
574 | rxvt_menuitem_free(aR_ menu, item); |
625 | menuitem_free (menu, item); |
575 | item = p; |
626 | item = p; |
576 | } |
627 | } |
577 | |
628 | |
578 | if (menu->name != NULL) |
629 | if (menu->name != NULL) |
579 | free(menu->name); |
630 | free(menu->name); |
580 | free(menu); |
631 | free(menu); |
581 | |
632 | |
|
|
633 | return parent; |
|
|
634 | } |
|
|
635 | |
|
|
636 | menu_t * |
|
|
637 | rxvt_term::menu_add (menu_t *parent, char *path) |
|
|
638 | { |
|
|
639 | menu_t *menu; |
|
|
640 | bar_t *CurrentBar = CurrentBar; |
|
|
641 | |
|
|
642 | #ifdef DEBUG_STRICT |
|
|
643 | assert(CurrentBar != NULL); |
|
|
644 | #endif |
|
|
645 | |
|
|
646 | if (STRCHR(path, '/') != NULL) |
|
|
647 | { |
|
|
648 | char *p; |
|
|
649 | |
|
|
650 | if (path[0] == '/') |
|
|
651 | { |
|
|
652 | /* shouldn't happen */ |
|
|
653 | path++; |
|
|
654 | parent = NULL; |
|
|
655 | } |
|
|
656 | while ((p = STRCHR(path, '/')) != NULL) |
|
|
657 | { |
|
|
658 | p[0] = '\0'; |
|
|
659 | if (path[0] == '\0') |
|
|
660 | return NULL; |
|
|
661 | |
|
|
662 | parent = menu_add (parent, path); |
|
|
663 | path = (p + 1); |
|
|
664 | } |
|
|
665 | } |
|
|
666 | if (!STRCMP(path, DOTS)) |
|
|
667 | return (parent != NULL ? parent->parent : parent); |
|
|
668 | |
|
|
669 | if (!STRCMP(path, DOT) || path[0] == '\0') |
582 | return parent; |
670 | return parent; |
583 | } |
|
|
584 | |
671 | |
585 | /* INTPROTO */ |
672 | /* allocate a new menu */ |
586 | menu_t * |
673 | menu = (menu_t *) rxvt_malloc(sizeof(menu_t)); |
587 | rxvt_menu_add(pR_ menu_t *parent, char *path) |
|
|
588 | { |
|
|
589 | menu_t *menu; |
|
|
590 | bar_t *CurrentBar = R->h->CurrentBar; |
|
|
591 | |
674 | |
|
|
675 | menu->width = 0; |
|
|
676 | menu->parent = parent; |
|
|
677 | menu->len = STRLEN(path); |
|
|
678 | menu->name = rxvt_malloc((menu->len + 1)); |
|
|
679 | STRCPY(menu->name, path); |
|
|
680 | |
|
|
681 | /* initialize head/tail */ |
|
|
682 | menu->head = menu->tail = NULL; |
|
|
683 | menu->prev = menu->next = NULL; |
|
|
684 | |
|
|
685 | menu->win = None; |
|
|
686 | menu->x = menu->y = menu->w = menu->h = 0; |
|
|
687 | menu->item = NULL; |
|
|
688 | |
|
|
689 | /* add to tail of list */ |
|
|
690 | if (parent == NULL) |
|
|
691 | { |
|
|
692 | menu->prev = CurrentBar->tail; |
|
|
693 | if (CurrentBar->tail != NULL) |
|
|
694 | CurrentBar->tail->next = menu; |
|
|
695 | CurrentBar->tail = menu; |
|
|
696 | if (CurrentBar->head == NULL) |
|
|
697 | CurrentBar->head = menu; /* fix head */ |
|
|
698 | if (menu->prev) |
|
|
699 | menu->x = (menu->prev->x + menu->prev->len + HSPACE); |
|
|
700 | } |
|
|
701 | else |
|
|
702 | { |
|
|
703 | menuitem_t *item; |
|
|
704 | |
|
|
705 | item = rxvt_menuitem_add(parent, path, "", ""); |
|
|
706 | if (item == NULL) |
|
|
707 | { |
|
|
708 | free(menu); |
|
|
709 | return parent; |
|
|
710 | } |
592 | #ifdef DEBUG_STRICT |
711 | #ifdef DEBUG_STRICT |
593 | assert(CurrentBar != NULL); |
|
|
594 | #endif |
|
|
595 | |
|
|
596 | if (STRCHR(path, '/') != NULL) { |
|
|
597 | char *p; |
|
|
598 | |
|
|
599 | if (path[0] == '/') { |
|
|
600 | /* shouldn't happen */ |
|
|
601 | path++; |
|
|
602 | parent = NULL; |
|
|
603 | } |
|
|
604 | while ((p = STRCHR(path, '/')) != NULL) { |
|
|
605 | p[0] = '\0'; |
|
|
606 | if (path[0] == '\0') |
|
|
607 | return NULL; |
|
|
608 | |
|
|
609 | parent = rxvt_menu_add(aR_ parent, path); |
|
|
610 | path = (p + 1); |
|
|
611 | } |
|
|
612 | } |
|
|
613 | if (!STRCMP(path, DOTS)) |
|
|
614 | return (parent != NULL ? parent->parent : parent); |
|
|
615 | |
|
|
616 | if (!STRCMP(path, DOT) || path[0] == '\0') |
|
|
617 | return parent; |
|
|
618 | |
|
|
619 | /* allocate a new menu */ |
|
|
620 | menu = (menu_t *) rxvt_malloc(sizeof(menu_t)); |
|
|
621 | |
|
|
622 | menu->width = 0; |
|
|
623 | menu->parent = parent; |
|
|
624 | menu->len = STRLEN(path); |
|
|
625 | menu->name = rxvt_malloc((menu->len + 1)); |
|
|
626 | STRCPY(menu->name, path); |
|
|
627 | |
|
|
628 | /* initialize head/tail */ |
|
|
629 | menu->head = menu->tail = NULL; |
|
|
630 | menu->prev = menu->next = NULL; |
|
|
631 | |
|
|
632 | menu->win = None; |
|
|
633 | menu->x = menu->y = menu->w = menu->h = 0; |
|
|
634 | menu->item = NULL; |
|
|
635 | |
|
|
636 | /* add to tail of list */ |
|
|
637 | if (parent == NULL) { |
|
|
638 | menu->prev = CurrentBar->tail; |
|
|
639 | if (CurrentBar->tail != NULL) |
|
|
640 | CurrentBar->tail->next = menu; |
|
|
641 | CurrentBar->tail = menu; |
|
|
642 | if (CurrentBar->head == NULL) |
|
|
643 | CurrentBar->head = menu; /* fix head */ |
|
|
644 | if (menu->prev) |
|
|
645 | menu->x = (menu->prev->x + menu->prev->len + HSPACE); |
|
|
646 | } else { |
|
|
647 | menuitem_t *item; |
|
|
648 | |
|
|
649 | item = rxvt_menuitem_add(parent, path, "", ""); |
|
|
650 | if (item == NULL) { |
|
|
651 | free(menu); |
|
|
652 | return parent; |
|
|
653 | } |
|
|
654 | #ifdef DEBUG_STRICT |
|
|
655 | assert(item->entry.type == MenuLabel); |
712 | assert(item->entry.type == MenuLabel); |
656 | #endif |
713 | #endif |
657 | item->entry.type = MenuSubMenu; |
714 | item->entry.type = MenuSubMenu; |
658 | item->entry.submenu.menu = menu; |
715 | item->entry.submenu.menu = menu; |
659 | } |
716 | } |
660 | |
717 | |
661 | return menu; |
718 | return menu; |
662 | } |
719 | } |
663 | |
720 | |
664 | /* INTPROTO */ |
|
|
665 | void |
721 | void |
666 | rxvt_drawbox_menubar(pR_ int x, int len, int state) |
722 | rxvt_term::drawbox_menubar (int x, int len, int state) |
667 | { |
723 | { |
668 | GC top, bot; |
724 | GC top, bot; |
669 | |
725 | |
670 | x = Width2Pixel(x); |
726 | x = Width2Pixel(x); |
671 | len = Width2Pixel(len + HSPACE); |
727 | len = Width2Pixel(len + HSPACE); |
672 | if (x >= R->TermWin.width) |
728 | if (x >= TermWin.width) |
673 | return; |
729 | return; |
674 | else if (x + len >= R->TermWin.width) |
730 | else if (x + len >= TermWin.width) |
675 | len = (TermWin_TotalWidth() - x); |
731 | len = (TermWin_TotalWidth() - x); |
676 | |
732 | |
677 | #ifdef MENUBAR_SHADOW_IN |
733 | #ifdef MENUBAR_SHADOW_IN |
678 | state = -state; |
734 | state = -state; |
679 | #endif |
735 | #endif |
680 | switch (state) { |
736 | switch (state) |
|
|
737 | { |
681 | case +1: |
738 | case +1: |
682 | top = R->h->topShadowGC; |
739 | top = topShadowGC; |
683 | bot = R->h->botShadowGC; |
740 | bot = botShadowGC; |
684 | break; /* SHADOW_OUT */ |
741 | break; /* SHADOW_OUT */ |
685 | case -1: |
742 | case -1: |
686 | top = R->h->botShadowGC; |
743 | top = botShadowGC; |
687 | bot = R->h->topShadowGC; |
744 | bot = topShadowGC; |
688 | break; /* SHADOW_IN */ |
745 | break; /* SHADOW_IN */ |
689 | default: |
746 | default: |
690 | top = bot = R->h->scrollbarGC; |
747 | top = bot = scrollbarGC; |
691 | break; /* neutral */ |
748 | break; /* neutral */ |
692 | } |
749 | } |
693 | |
750 | |
694 | rxvt_Draw_Shadow(R->Xdisplay, R->menuBar.win, top, bot, |
751 | rxvt_Draw_Shadow(Xdisplay, menuBar.win, top, bot, |
695 | x, 0, len, menuBar_TotalHeight()); |
752 | x, 0, len, menuBar_TotalHeight()); |
696 | } |
753 | } |
697 | |
754 | |
698 | /* INTPROTO */ |
|
|
699 | void |
755 | void |
700 | rxvt_drawtriangle(pR_ int x, int y, int state) |
756 | rxvt_term::drawtriangle (int x, int y, int state) |
701 | { |
757 | { |
702 | GC top, bot; |
758 | GC top, bot; |
703 | int w; |
759 | int w; |
704 | |
760 | |
705 | #ifdef MENU_SHADOW_IN |
761 | #ifdef MENU_SHADOW_IN |
706 | state = -state; |
762 | state = -state; |
707 | #endif |
763 | #endif |
708 | switch (state) { |
764 | switch (state) |
|
|
765 | { |
709 | case +1: |
766 | case +1: |
710 | top = R->h->topShadowGC; |
767 | top = topShadowGC; |
711 | bot = R->h->botShadowGC; |
768 | bot = botShadowGC; |
712 | break; /* SHADOW_OUT */ |
769 | break; /* SHADOW_OUT */ |
713 | case -1: |
770 | case -1: |
714 | top = R->h->botShadowGC; |
771 | top = botShadowGC; |
715 | bot = R->h->topShadowGC; |
772 | bot = topShadowGC; |
716 | break; /* SHADOW_IN */ |
773 | break; /* SHADOW_IN */ |
717 | default: |
774 | default: |
718 | top = bot = R->h->scrollbarGC; |
775 | top = bot = scrollbarGC; |
719 | break; /* neutral */ |
776 | break; /* neutral */ |
720 | } |
777 | } |
721 | |
778 | |
722 | w = Height2Pixel(1) - 2 * SHADOW; |
779 | w = Height2Pixel(1) - 2 * SHADOW; |
723 | |
780 | |
724 | x -= SHADOW + (3 * w / 2); |
781 | x -= SHADOW + (3 * w / 2); |
725 | y += SHADOW * 3; |
782 | y += SHADOW * 3; |
726 | |
783 | |
727 | rxvt_Draw_Triangle(R->Xdisplay, R->h->ActiveMenu->win, top, bot, x, y, w, |
784 | rxvt_Draw_Triangle(Xdisplay, ActiveMenu->win, top, bot, x, y, w, |
728 | 'r'); |
785 | 'r'); |
729 | } |
786 | } |
730 | |
787 | |
731 | /* INTPROTO */ |
|
|
732 | void |
788 | void |
733 | rxvt_drawbox_menuitem(pR_ int y, int state) |
789 | rxvt_term::drawbox_menuitem (int y, int state) |
734 | { |
790 | { |
735 | GC top, bot; |
791 | GC top, bot; |
736 | |
792 | |
737 | #ifdef MENU_SHADOW_IN |
793 | #ifdef MENU_SHADOW_IN |
738 | state = -state; |
794 | state = -state; |
739 | #endif |
795 | #endif |
740 | switch (state) { |
796 | switch (state) |
|
|
797 | { |
741 | case +1: |
798 | case +1: |
742 | top = R->h->topShadowGC; |
799 | top = topShadowGC; |
743 | bot = R->h->botShadowGC; |
800 | bot = botShadowGC; |
744 | break; /* SHADOW_OUT */ |
801 | break; /* SHADOW_OUT */ |
745 | case -1: |
802 | case -1: |
746 | top = R->h->botShadowGC; |
803 | top = botShadowGC; |
747 | bot = R->h->topShadowGC; |
804 | bot = topShadowGC; |
748 | break; /* SHADOW_IN */ |
805 | break; /* SHADOW_IN */ |
749 | default: |
806 | default: |
750 | top = bot = R->h->scrollbarGC; |
807 | top = bot = scrollbarGC; |
751 | break; /* neutral */ |
808 | break; /* neutral */ |
752 | } |
809 | } |
753 | |
810 | |
754 | rxvt_Draw_Shadow(R->Xdisplay, R->h->ActiveMenu->win, top, bot, |
811 | rxvt_Draw_Shadow(Xdisplay, ActiveMenu->win, top, bot, |
755 | SHADOW + 0, SHADOW + y, |
812 | SHADOW + 0, SHADOW + y, |
756 | R->h->ActiveMenu->w - 2 * (SHADOW), |
813 | ActiveMenu->w - 2 * (SHADOW), |
757 | HEIGHT_TEXT + 2 * SHADOW); |
814 | HEIGHT_TEXT + 2 * SHADOW); |
758 | XFlush(R->Xdisplay); |
815 | XFlush(Xdisplay); |
759 | } |
816 | } |
760 | |
817 | |
761 | #ifdef DEBUG_MENU_LAYOUT |
818 | #ifdef DEBUG_MENU_LAYOUT |
762 | /* INTPROTO */ |
|
|
763 | void |
819 | void |
764 | rxvt_print_menu_ancestors(menu_t *menu) |
820 | rxvt_print_menu_ancestors(menu_t *menu) |
765 | { |
821 | { |
766 | if (menu == NULL) { |
822 | if (menu == NULL) |
|
|
823 | { |
767 | fprintf(stderr, "Top Level menu\n"); |
824 | fprintf(stderr, "Top Level menu\n"); |
768 | return; |
825 | return; |
769 | } |
826 | } |
770 | fprintf(stderr, "menu %s ", menu->name); |
827 | fprintf(stderr, "menu %s ", menu->name); |
771 | if (menu->parent != NULL) { |
828 | if (menu->parent != NULL) |
|
|
829 | { |
772 | menuitem_t *item; |
830 | menuitem_t *item; |
773 | |
831 | |
774 | for (item = menu->parent->head; item != NULL; item = item->next) { |
832 | for (item = menu->parent->head; item != NULL; item = item->next) |
|
|
833 | { |
775 | if (item->entry.type == MenuSubMenu |
834 | if (item->entry.type == MenuSubMenu |
776 | && item->entry.submenu.menu == menu) { |
835 | && item->entry.submenu.menu == menu) |
777 | break; |
836 | { |
778 | } |
837 | break; |
779 | } |
838 | } |
|
|
839 | } |
780 | if (item == NULL) { |
840 | if (item == NULL) |
|
|
841 | { |
781 | fprintf(stderr, "is an orphan!\n"); |
842 | fprintf(stderr, "is an orphan!\n"); |
782 | return; |
843 | return; |
783 | } |
844 | } |
784 | } |
845 | } |
785 | fprintf(stderr, "\n"); |
846 | fprintf(stderr, "\n"); |
786 | rxvt_print_menu_ancestors(menu->parent); |
847 | rxvt_print_menu_ancestors(menu->parent); |
787 | } |
848 | } |
788 | |
849 | |
789 | /* INTPROTO */ |
|
|
790 | void |
850 | void |
791 | rxvt_print_menu_descendants(menu_t *menu) |
851 | rxvt_print_menu_descendants(menu_t *menu) |
792 | { |
852 | { |
793 | menuitem_t *item; |
853 | menuitem_t *item; |
794 | menu_t *parent; |
854 | menu_t *parent; |
795 | int i, level = 0; |
855 | int i, level = 0; |
796 | |
856 | |
797 | parent = menu; |
857 | parent = menu; |
|
|
858 | do |
798 | do { |
859 | { |
799 | level++; |
860 | level++; |
800 | parent = parent->parent; |
861 | parent = parent->parent; |
801 | } |
862 | } |
802 | while (parent != NULL); |
863 | while (parent != NULL); |
803 | |
864 | |
804 | for (i = 0; i < level; i++) |
865 | for (i = 0; i < level; i++) |
805 | fprintf(stderr, ">"); |
866 | fprintf(stderr, ">"); |
806 | fprintf(stderr, "%s\n", menu->name); |
867 | fprintf(stderr, "%s\n", menu->name); |
807 | |
868 | |
808 | for (item = menu->head; item != NULL; item = item->next) { |
869 | for (item = menu->head; item != NULL; item = item->next) |
|
|
870 | { |
809 | if (item->entry.type == MenuSubMenu) { |
871 | if (item->entry.type == MenuSubMenu) |
|
|
872 | { |
810 | if (item->entry.submenu.menu == NULL) |
873 | if (item->entry.submenu.menu == NULL) |
811 | fprintf(stderr, "> %s == NULL\n", item->name); |
874 | fprintf(stderr, "> %s == NULL\n", item->name); |
812 | else |
875 | else |
813 | rxvt_print_menu_descendants(item->entry.submenu.menu); |
876 | rxvt_print_menu_descendants(item->entry.submenu.menu); |
814 | } else { |
877 | } |
|
|
878 | else |
|
|
879 | { |
815 | for (i = 0; i < level; i++) |
880 | for (i = 0; i < level; i++) |
816 | fprintf(stderr, "+"); |
881 | fprintf(stderr, "+"); |
817 | if (item->entry.type == MenuLabel) |
882 | if (item->entry.type == MenuLabel) |
818 | fprintf(stderr, "label: "); |
883 | fprintf(stderr, "label: "); |
819 | fprintf(stderr, "%s\n", item->name); |
884 | fprintf(stderr, "%s\n", item->name); |
820 | } |
885 | } |
821 | } |
886 | } |
822 | |
887 | |
823 | for (i = 0; i < level; i++) |
888 | for (i = 0; i < level; i++) |
824 | fprintf(stderr, "<"); |
889 | fprintf(stderr, "<"); |
825 | fprintf(stderr, "\n"); |
890 | fprintf(stderr, "\n"); |
826 | } |
891 | } |
827 | #endif |
892 | #endif |
828 | |
893 | |
829 | /* pop up/down the current menu and redraw the menuBar button */ |
894 | /* pop up/down the current menu and redraw the menuBar button */ |
830 | /* INTPROTO */ |
|
|
831 | void |
895 | void |
832 | rxvt_menu_show(pR) |
896 | rxvt_term::menu_show () |
833 | { |
897 | { |
834 | int x, y, xright; |
898 | int x, y, xright; |
835 | menu_t *ActiveMenu = R->h->ActiveMenu; |
899 | menu_t *ActiveMenu = ActiveMenu; |
836 | menuitem_t *item; |
900 | menuitem_t *item; |
837 | |
901 | |
838 | if (ActiveMenu == NULL) |
902 | if (ActiveMenu == NULL) |
839 | return; |
903 | return; |
840 | |
904 | |
841 | x = ActiveMenu->x; |
905 | x = ActiveMenu->x; |
842 | if (ActiveMenu->parent == NULL) { |
906 | if (ActiveMenu->parent == NULL) |
|
|
907 | { |
843 | register int h; |
908 | register int h; |
844 | |
909 | |
845 | rxvt_drawbox_menubar(aR_ x, ActiveMenu->len, -1); |
910 | drawbox_menubar (x, ActiveMenu->len, -1); |
846 | x = Width2Pixel(x); |
911 | x = Width2Pixel(x); |
847 | |
912 | |
848 | ActiveMenu->y = 1; |
913 | ActiveMenu->y = 1; |
849 | ActiveMenu->w = Menu_PixelWidth(ActiveMenu); |
914 | ActiveMenu->w = Menu_PixelWidth(ActiveMenu); |
850 | |
915 | |
851 | if ((x + ActiveMenu->w) >= R->TermWin.width) |
916 | if ((x + ActiveMenu->w) >= TermWin.width) |
852 | x = (TermWin_TotalWidth() - ActiveMenu->w); |
917 | x = (TermWin_TotalWidth() - ActiveMenu->w); |
853 | |
918 | |
854 | /* find the height */ |
919 | /* find the height */ |
855 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
920 | for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
856 | h += isSeparator(item->name) ? HEIGHT_SEPARATOR |
921 | h += isSeparator(item->name) ? HEIGHT_SEPARATOR |
857 | : HEIGHT_TEXT + 2 * SHADOW; |
922 | : HEIGHT_TEXT + 2 * SHADOW; |
858 | ActiveMenu->h = h + 2 * SHADOW; |
923 | ActiveMenu->h = h + 2 * SHADOW; |
859 | } |
924 | } |
860 | if (ActiveMenu->win == None) { |
925 | if (ActiveMenu->win == None) |
|
|
926 | { |
861 | ActiveMenu->win = XCreateSimpleWindow(R->Xdisplay, R->TermWin.vt, |
927 | ActiveMenu->win = XCreateSimpleWindow(Xdisplay, TermWin.vt, |
862 | x, ActiveMenu->y, |
928 | x, ActiveMenu->y, |
863 | ActiveMenu->w, ActiveMenu->h, |
929 | ActiveMenu->w, ActiveMenu->h, |
864 | 0, |
930 | 0, |
865 | R->PixColors[Color_fg], |
931 | PixColors[Color_fg], |
866 | R->PixColors[Color_scroll]); |
932 | PixColors[Color_scroll]); |
867 | XMapWindow(R->Xdisplay, ActiveMenu->win); |
933 | XMapWindow(Xdisplay, ActiveMenu->win); |
868 | } |
934 | } |
869 | rxvt_Draw_Shadow(R->Xdisplay, ActiveMenu->win, |
935 | rxvt_Draw_Shadow(Xdisplay, ActiveMenu->win, |
870 | R->h->topShadowGC, R->h->botShadowGC, |
936 | topShadowGC, botShadowGC, |
871 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
937 | 0, 0, ActiveMenu->w, ActiveMenu->h); |
872 | |
938 | |
873 | /* determine the correct right-alignment */ |
939 | /* determine the correct right-alignment */ |
874 | for (xright = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
940 | for (xright = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
875 | if (item->len2 > xright) |
941 | if (item->len2 > xright) |
876 | xright = item->len2; |
942 | xright = item->len2; |
877 | |
943 | |
878 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) { |
944 | for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) |
|
|
945 | { |
879 | const int xoff = (SHADOW + Width2Pixel(HSPACE) / 2); |
946 | const int xoff = (SHADOW + Width2Pixel(HSPACE) / 2); |
880 | register int h; |
947 | register int h; |
881 | GC gc = R->h->menubarGC; |
948 | GC gc = menubarGC; |
882 | |
949 | |
883 | if (isSeparator(item->name)) { |
950 | if (isSeparator(item->name)) |
|
|
951 | { |
884 | rxvt_Draw_Shadow(R->Xdisplay, ActiveMenu->win, |
952 | rxvt_Draw_Shadow(Xdisplay, ActiveMenu->win, |
885 | R->h->topShadowGC, R->h->botShadowGC, |
953 | topShadowGC, botShadowGC, |
886 | SHADOW, y + SHADOW + 1, |
954 | SHADOW, y + SHADOW + 1, |
887 | ActiveMenu->w - 2 * SHADOW, 0); |
955 | ActiveMenu->w - 2 * SHADOW, 0); |
888 | h = HEIGHT_SEPARATOR; |
956 | h = HEIGHT_SEPARATOR; |
889 | } else { |
957 | } |
|
|
958 | else |
|
|
959 | { |
890 | char *name = item->name; |
960 | char *name = item->name; |
891 | int len = item->len; |
961 | int len = item->len; |
892 | |
962 | |
893 | if (item->entry.type == MenuLabel) { |
963 | if (item->entry.type == MenuLabel) |
894 | gc = R->h->botShadowGC; |
964 | { |
|
|
965 | gc = botShadowGC; |
|
|
966 | } |
895 | } else if (item->entry.type == MenuSubMenu) { |
967 | else if (item->entry.type == MenuSubMenu) |
896 | int x1, y1; |
968 | { |
897 | menuitem_t *it; |
969 | int x1, y1; |
|
|
970 | menuitem_t *it; |
898 | menu_t *menu = item->entry.submenu.menu; |
971 | menu_t *menu = item->entry.submenu.menu; |
899 | |
972 | |
900 | rxvt_drawtriangle(aR_ ActiveMenu->w, y, +1); |
973 | drawtriangle (ActiveMenu->w, y, +1); |
901 | |
974 | |
902 | name = menu->name; |
975 | name = menu->name; |
903 | len = menu->len; |
976 | len = menu->len; |
904 | |
977 | |
905 | y1 = ActiveMenu->y + y; |
978 | y1 = ActiveMenu->y + y; |
906 | |
979 | |
907 | menu->w = Menu_PixelWidth(menu); |
980 | menu->w = Menu_PixelWidth(menu); |
908 | |
981 | |
909 | /* place sub-menu at midpoint of parent menu */ |
982 | /* place sub-menu at midpoint of parent menu */ |
910 | x1 = ActiveMenu->w / 2; |
983 | x1 = ActiveMenu->w / 2; |
911 | if (x1 > menu->w) /* right-flush menu if too small */ |
984 | if (x1 > menu->w) /* right-flush menu if too small */ |
912 | x1 += (x1 - menu->w); |
985 | x1 += (x1 - menu->w); |
913 | x1 += x; |
986 | x1 += x; |
914 | |
987 | |
915 | /* find the height of this submenu */ |
988 | /* find the height of this submenu */ |
916 | for (h = 0, it = menu->head; it != NULL; it = it->next) |
989 | for (h = 0, it = menu->head; it != NULL; it = it->next) |
917 | h += isSeparator(it->name) ? HEIGHT_SEPARATOR |
990 | h += isSeparator(it->name) ? HEIGHT_SEPARATOR |
918 | : HEIGHT_TEXT + 2 * SHADOW; |
991 | : HEIGHT_TEXT + 2 * SHADOW; |
919 | menu->h = h + 2 * SHADOW; |
992 | menu->h = h + 2 * SHADOW; |
920 | |
993 | |
921 | /* ensure menu is in window limits */ |
994 | /* ensure menu is in window limits */ |
922 | if ((x1 + menu->w) >= R->TermWin.width) |
995 | if ((x1 + menu->w) >= TermWin.width) |
923 | x1 = (TermWin_TotalWidth() - menu->w); |
996 | x1 = (TermWin_TotalWidth() - menu->w); |
924 | |
997 | |
925 | if ((y1 + menu->h) >= R->TermWin.height) |
998 | if ((y1 + menu->h) >= TermWin.height) |
926 | y1 = (TermWin_TotalHeight() - menu->h); |
999 | y1 = (TermWin_TotalHeight() - menu->h); |
927 | |
1000 | |
928 | menu->x = (x1 < 0 ? 0 : x1); |
1001 | menu->x = (x1 < 0 ? 0 : x1); |
929 | menu->y = (y1 < 0 ? 0 : y1); |
1002 | menu->y = (y1 < 0 ? 0 : y1); |
|
|
1003 | } |
930 | } else if (item->name2 && !STRCMP(name, item->name2)) |
1004 | else if (item->name2 && !STRCMP(name, item->name2)) |
931 | name = NULL; |
1005 | name = NULL; |
932 | |
1006 | |
933 | if (len && name) { |
1007 | if (len && name) |
|
|
1008 | { |
934 | #ifdef USE_XIM |
1009 | #ifdef USE_XIM |
935 | if (R->TermWin.fontset) |
1010 | if (TermWin.fontset) |
936 | XmbDrawString(R->Xdisplay, |
1011 | XmbDrawString(Xdisplay, |
937 | ActiveMenu->win, R->TermWin.fontset, |
1012 | ActiveMenu->win, TermWin.fontset, |
938 | gc, xoff, |
1013 | gc, xoff, |
939 | 2 * SHADOW + y + R->TermWin.font->ascent + 1, |
1014 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
940 | name, len); |
1015 | name, len); |
941 | else |
1016 | else |
942 | #endif |
1017 | #endif |
943 | XDrawString(R->Xdisplay, ActiveMenu->win, gc, xoff, |
1018 | XDrawString(Xdisplay, ActiveMenu->win, gc, xoff, |
944 | 2 * SHADOW + y + R->TermWin.font->ascent + 1, |
1019 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
945 | name, len); |
1020 | name, len); |
946 | } |
1021 | } |
947 | |
1022 | |
948 | len = item->len2; |
1023 | len = item->len2; |
949 | name = item->name2; |
1024 | name = item->name2; |
950 | if (len && name) { |
1025 | if (len && name) |
|
|
1026 | { |
951 | #ifdef USE_XIM |
1027 | #ifdef USE_XIM |
952 | if (R->TermWin.fontset) |
1028 | if (TermWin.fontset) |
953 | XmbDrawString(R->Xdisplay, |
1029 | XmbDrawString(Xdisplay, |
954 | ActiveMenu->win, R->TermWin.fontset, |
1030 | ActiveMenu->win, TermWin.fontset, |
955 | gc, |
1031 | gc, |
956 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
1032 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
957 | 2 * SHADOW + y + R->TermWin.font->ascent + 1, |
1033 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
958 | name, len); |
1034 | name, len); |
959 | else |
1035 | else |
960 | #endif |
1036 | #endif |
961 | XDrawString(R->Xdisplay, ActiveMenu->win, gc, |
1037 | XDrawString(Xdisplay, ActiveMenu->win, gc, |
962 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
1038 | ActiveMenu->w - (xoff + Width2Pixel(xright)), |
963 | 2 * SHADOW + y + R->TermWin.font->ascent + 1, |
1039 | 2 * SHADOW + y + TermWin.font->ascent + 1, |
964 | name, len); |
1040 | name, len); |
|
|
1041 | } |
|
|
1042 | h = HEIGHT_TEXT + 2 * SHADOW; |
|
|
1043 | } |
|
|
1044 | y += h; |
965 | } |
1045 | } |
966 | h = HEIGHT_TEXT + 2 * SHADOW; |
|
|
967 | } |
|
|
968 | y += h; |
|
|
969 | } |
|
|
970 | } |
1046 | } |
971 | |
1047 | |
972 | /* INTPROTO */ |
|
|
973 | void |
1048 | void |
974 | rxvt_menu_display(pR_ void (*update)(rxvt_t *)) |
1049 | rxvt_term::menu_display (void (*update)(rxvt_t *)) |
975 | { |
1050 | { |
976 | menu_t *ActiveMenu = R->h->ActiveMenu; |
1051 | menu_t *ActiveMenu = ActiveMenu; |
977 | |
1052 | |
978 | if (ActiveMenu == NULL) |
1053 | if (ActiveMenu == NULL) |
979 | return; |
1054 | return; |
980 | if (ActiveMenu->win != None) |
1055 | if (ActiveMenu->win != None) |
981 | XDestroyWindow(R->Xdisplay, ActiveMenu->win); |
1056 | XDestroyWindow(Xdisplay, ActiveMenu->win); |
982 | ActiveMenu->win = None; |
1057 | ActiveMenu->win = None; |
983 | ActiveMenu->item = NULL; |
1058 | ActiveMenu->item = NULL; |
984 | |
1059 | |
985 | if (ActiveMenu->parent == NULL) |
1060 | if (ActiveMenu->parent == NULL) |
986 | rxvt_drawbox_menubar(aR_ ActiveMenu->x, ActiveMenu->len, +1); |
1061 | drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); |
987 | R->h->ActiveMenu = ActiveMenu->parent; |
1062 | ActiveMenu = ActiveMenu->parent; |
988 | update(r); |
1063 | update(r); |
989 | } |
1064 | } |
990 | |
1065 | |
991 | /* INTPROTO */ |
|
|
992 | void |
1066 | void |
993 | rxvt_menu_hide_all(pR) |
1067 | rxvt_term::menu_hide_all () |
994 | { |
1068 | { |
995 | rxvt_menu_display(aR_ rxvt_menu_hide_all); |
1069 | menu_display (rxvt_menu_hide_all); |
996 | } |
1070 | } |
997 | |
1071 | |
998 | /* INTPROTO */ |
|
|
999 | void |
1072 | void |
1000 | rxvt_menu_hide(pR) |
1073 | rxvt_term::menu_hide () |
1001 | { |
1074 | { |
1002 | rxvt_menu_display(aR_ rxvt_menu_show); |
1075 | menu_display (rxvt_menu_show); |
1003 | } |
1076 | } |
1004 | |
1077 | |
1005 | /* INTPROTO */ |
|
|
1006 | void |
1078 | void |
1007 | rxvt_menu_clear(pR_ menu_t *menu) |
1079 | rxvt_term::menu_clear (menu_t *menu) |
1008 | { |
1080 | { |
1009 | if (menu != NULL) { |
1081 | if (menu != NULL) |
|
|
1082 | { |
1010 | menuitem_t *item = menu->tail; |
1083 | menuitem_t *item = menu->tail; |
1011 | |
1084 | |
1012 | while (item != NULL) { |
1085 | while (item != NULL) |
1013 | rxvt_menuitem_free(aR_ menu, item); |
1086 | { |
|
|
1087 | menuitem_free (menu, item); |
1014 | /* it didn't get freed ... why? */ |
1088 | /* it didn't get freed ... why? */ |
1015 | if (item == menu->tail) |
1089 | if (item == menu->tail) |
1016 | return; |
1090 | return; |
1017 | item = menu->tail; |
1091 | item = menu->tail; |
1018 | } |
1092 | } |
1019 | menu->width = 0; |
1093 | menu->width = 0; |
1020 | } |
1094 | } |
1021 | } |
1095 | } |
1022 | |
1096 | |
1023 | /* INTPROTO */ |
|
|
1024 | void |
1097 | void |
1025 | rxvt_menubar_clear(pR) |
1098 | rxvt_term::menubar_clear () |
1026 | { |
1099 | { |
1027 | bar_t *CurrentBar = R->h->CurrentBar; |
1100 | bar_t *CurrentBar = CurrentBar; |
1028 | |
1101 | |
1029 | if (CurrentBar != NULL) { |
1102 | if (CurrentBar != NULL) |
|
|
1103 | { |
1030 | menu_t *menu = CurrentBar->tail; |
1104 | menu_t *menu = CurrentBar->tail; |
1031 | |
1105 | |
1032 | while (menu != NULL) { |
1106 | while (menu != NULL) |
|
|
1107 | { |
1033 | menu_t *prev = menu->prev; |
1108 | menu_t *prev = menu->prev; |
1034 | |
1109 | |
1035 | rxvt_menu_delete(aR_ menu); |
1110 | menu_delete (menu); |
1036 | menu = prev; |
1111 | menu = prev; |
1037 | } |
1112 | } |
1038 | CurrentBar->head = CurrentBar->tail = NULL; |
1113 | CurrentBar->head = CurrentBar->tail = NULL; |
1039 | |
1114 | |
1040 | if (CurrentBar->title) { |
1115 | if (CurrentBar->title) |
|
|
1116 | { |
1041 | free(CurrentBar->title); |
1117 | free(CurrentBar->title); |
1042 | CurrentBar->title = NULL; |
1118 | CurrentBar->title = NULL; |
1043 | } |
1119 | } |
1044 | rxvt_menuarrow_free(aR_ 0); /* remove all arrow functions */ |
1120 | menuarrow_free (0); /* remove all arrow functions */ |
1045 | } |
1121 | } |
1046 | R->h->ActiveMenu = NULL; |
1122 | ActiveMenu = NULL; |
1047 | } |
1123 | } |
1048 | |
1124 | |
1049 | #if (MENUBAR_MAX > 1) |
1125 | #if (MENUBAR_MAX > 1) |
1050 | /* find if menu already exists */ |
1126 | /* find if menu already exists */ |
1051 | /* INTPROTO */ |
|
|
1052 | bar_t * |
1127 | bar_t * |
1053 | rxvt_menubar_find(pR_ const char *name) |
1128 | rxvt_term::menubar_find (const char *name) |
1054 | { |
1129 | { |
1055 | bar_t *bar = R->h->CurrentBar; |
1130 | bar_t *bar = CurrentBar; |
1056 | |
1131 | |
1057 | #ifdef DEBUG_MENUBAR_STACKING |
1132 | #ifdef DEBUG_MENUBAR_STACKING |
1058 | fprintf(stderr, "looking for [menu:%s] ...", name ? name : "(nil)"); |
1133 | fprintf(stderr, "looking for [menu:%s] ...", name ? name : "(nil)"); |
1059 | #endif |
1134 | #endif |
1060 | if (bar == NULL || name == NULL) |
1135 | if (bar == NULL || name == NULL) |
1061 | return NULL; |
1136 | return NULL; |
1062 | |
1137 | |
1063 | if (STRLEN(name) && STRCMP(name, "*")) { |
1138 | if (STRLEN(name) && STRCMP(name, "*")) |
1064 | do { |
1139 | { |
|
|
1140 | do |
|
|
1141 | { |
1065 | if (!STRCMP(bar->name, name)) { |
1142 | if (!STRCMP(bar->name, name)) |
|
|
1143 | { |
1066 | #ifdef DEBUG_MENUBAR_STACKING |
1144 | #ifdef DEBUG_MENUBAR_STACKING |
1067 | fprintf(stderr, " found!\n"); |
1145 | fprintf(stderr, " found!\n"); |
1068 | #endif |
1146 | #endif |
1069 | return bar; |
1147 | return bar; |
1070 | } |
1148 | } |
1071 | bar = bar->next; |
1149 | bar = bar->next; |
1072 | } |
1150 | } |
1073 | while (bar != R->h->CurrentBar); |
1151 | while (bar != CurrentBar); |
1074 | bar = NULL; |
1152 | bar = NULL; |
1075 | } |
1153 | } |
1076 | #ifdef DEBUG_MENUBAR_STACKING |
1154 | #ifdef DEBUG_MENUBAR_STACKING |
1077 | fprintf(stderr, "%s found!\n", (bar ? "" : " NOT")); |
1155 | fprintf(stderr, "%s found!\n", (bar ? "" : " NOT")); |
1078 | #endif |
1156 | #endif |
1079 | |
1157 | |
1080 | return bar; |
1158 | return bar; |
1081 | } |
1159 | } |
1082 | |
1160 | |
1083 | /* INTPROTO */ |
|
|
1084 | int |
1161 | int |
1085 | rxvt_menubar_push(pR_ const char *name) |
1162 | rxvt_term::menubar_push (const char *name) |
1086 | { |
1163 | { |
1087 | int ret = 1; |
1164 | int ret = 1; |
1088 | bar_t *bar; |
1165 | bar_t *bar; |
1089 | |
1166 | |
1090 | if (R->h->CurrentBar == NULL) { |
1167 | if (CurrentBar == NULL) |
|
|
1168 | { |
1091 | /* allocate first one */ |
1169 | /* allocate first one */ |
1092 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
|
|
1093 | |
|
|
1094 | MEMSET(bar, 0, sizeof(bar_t)); |
|
|
1095 | /* circular linked-list */ |
|
|
1096 | bar->next = bar->prev = bar; |
|
|
1097 | bar->head = bar->tail = NULL; |
|
|
1098 | bar->title = NULL; |
|
|
1099 | R->h->CurrentBar = bar; |
|
|
1100 | R->h->Nbars++; |
|
|
1101 | |
|
|
1102 | rxvt_menubar_clear(aR); |
|
|
1103 | } else { |
|
|
1104 | /* find if menu already exists */ |
|
|
1105 | bar = rxvt_menubar_find(aR_ name); |
|
|
1106 | if (bar != NULL) { |
|
|
1107 | /* found it, use it */ |
|
|
1108 | R->h->CurrentBar = bar; |
|
|
1109 | } else { |
|
|
1110 | /* create if needed, or reuse the existing empty menubar */ |
|
|
1111 | if (R->h->CurrentBar->head != NULL) { |
|
|
1112 | /* need to malloc another one */ |
|
|
1113 | if (R->h->Nbars < MENUBAR_MAX) |
|
|
1114 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1170 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
1115 | else |
|
|
1116 | bar = NULL; |
|
|
1117 | |
1171 | |
1118 | /* malloc failed or too many menubars, reuse another */ |
1172 | MEMSET(bar, 0, sizeof(bar_t)); |
1119 | if (bar == NULL) { |
1173 | /* circular linked-list */ |
1120 | bar = R->h->CurrentBar->next; |
1174 | bar->next = bar->prev = bar; |
1121 | ret = -1; |
|
|
1122 | } else { |
|
|
1123 | bar->head = bar->tail = NULL; |
1175 | bar->head = bar->tail = NULL; |
1124 | bar->title = NULL; |
1176 | bar->title = NULL; |
|
|
1177 | CurrentBar = bar; |
|
|
1178 | Nbars++; |
1125 | |
1179 | |
1126 | bar->next = R->h->CurrentBar->next; |
1180 | menubar_clear (); |
1127 | R->h->CurrentBar->next = bar; |
|
|
1128 | bar->prev = R->h->CurrentBar; |
|
|
1129 | bar->next->prev = bar; |
|
|
1130 | |
|
|
1131 | R->h->Nbars++; |
|
|
1132 | } |
|
|
1133 | R->h->CurrentBar = bar; |
|
|
1134 | |
|
|
1135 | } |
1181 | } |
1136 | rxvt_menubar_clear(aR); |
1182 | else |
1137 | } |
|
|
1138 | } |
1183 | { |
|
|
1184 | /* find if menu already exists */ |
|
|
1185 | bar = menubar_find (name); |
|
|
1186 | if (bar != NULL) |
|
|
1187 | { |
|
|
1188 | /* found it, use it */ |
|
|
1189 | CurrentBar = bar; |
|
|
1190 | } |
|
|
1191 | else |
|
|
1192 | { |
|
|
1193 | /* create if needed, or reuse the existing empty menubar */ |
|
|
1194 | if (CurrentBar->head != NULL) |
|
|
1195 | { |
|
|
1196 | /* need to malloc another one */ |
|
|
1197 | if (Nbars < MENUBAR_MAX) |
|
|
1198 | bar = (bar_t *) rxvt_malloc(sizeof(bar_t)); |
|
|
1199 | else |
|
|
1200 | bar = NULL; |
1139 | |
1201 | |
|
|
1202 | /* malloc failed or too many menubars, reuse another */ |
|
|
1203 | if (bar == NULL) |
|
|
1204 | { |
|
|
1205 | bar = CurrentBar->next; |
|
|
1206 | ret = -1; |
|
|
1207 | } |
|
|
1208 | else |
|
|
1209 | { |
|
|
1210 | bar->head = bar->tail = NULL; |
|
|
1211 | bar->title = NULL; |
|
|
1212 | |
|
|
1213 | bar->next = CurrentBar->next; |
|
|
1214 | CurrentBar->next = bar; |
|
|
1215 | bar->prev = CurrentBar; |
|
|
1216 | bar->next->prev = bar; |
|
|
1217 | |
|
|
1218 | Nbars++; |
|
|
1219 | } |
|
|
1220 | CurrentBar = bar; |
|
|
1221 | |
|
|
1222 | } |
|
|
1223 | menubar_clear (); |
|
|
1224 | } |
|
|
1225 | } |
|
|
1226 | |
1140 | /* give menubar this name */ |
1227 | /* give menubar this name */ |
1141 | STRNCPY(R->h->CurrentBar->name, name, MAXNAME); |
1228 | STRNCPY(CurrentBar->name, name, MAXNAME); |
1142 | R->h->CurrentBar->name[MAXNAME - 1] = '\0'; |
1229 | CurrentBar->name[MAXNAME - 1] = '\0'; |
1143 | |
1230 | |
1144 | return ret; |
1231 | return ret; |
1145 | } |
1232 | } |
1146 | |
1233 | |
1147 | /* switch to a menu called NAME and remove it */ |
1234 | /* switch to a menu called NAME and remove it */ |
1148 | /* INTPROTO */ |
|
|
1149 | void |
1235 | void |
1150 | rxvt_menubar_remove(pR_ const char *name) |
1236 | rxvt_term::menubar_remove (const char *name) |
1151 | { |
1237 | { |
1152 | bar_t *bar; |
1238 | bar_t *bar; |
1153 | |
1239 | |
1154 | if ((bar = rxvt_menubar_find(aR_ name)) == NULL) |
1240 | if ((bar = menubar_find (name)) == NULL) |
1155 | return; |
1241 | return; |
1156 | R->h->CurrentBar = bar; |
1242 | CurrentBar = bar; |
1157 | |
1243 | |
|
|
1244 | do |
1158 | do { |
1245 | { |
1159 | rxvt_menubar_clear(aR); |
1246 | menubar_clear (); |
1160 | /* |
1247 | /* |
1161 | * pop a menubar, clean it up first |
1248 | * pop a menubar, clean it up first |
1162 | */ |
1249 | */ |
1163 | if (R->h->CurrentBar != NULL) { |
1250 | if (CurrentBar != NULL) |
|
|
1251 | { |
1164 | bar_t *prev = R->h->CurrentBar->prev; |
1252 | bar_t *prev = CurrentBar->prev; |
1165 | bar_t *next = R->h->CurrentBar->next; |
1253 | bar_t *next = CurrentBar->next; |
1166 | |
1254 | |
1167 | if (prev == next && prev == R->h->CurrentBar) { /* only 1 left */ |
1255 | if (prev == next && prev == CurrentBar) |
1168 | prev = NULL; |
1256 | { /* only 1 left */ |
1169 | R->h->Nbars = 0; /* safety */ |
1257 | prev = NULL; |
1170 | } else { |
1258 | Nbars = 0; /* safety */ |
1171 | next->prev = prev; |
1259 | } |
1172 | prev->next = next; |
1260 | else |
1173 | R->h->Nbars--; |
1261 | { |
|
|
1262 | next->prev = prev; |
|
|
1263 | prev->next = next; |
|
|
1264 | Nbars--; |
|
|
1265 | } |
|
|
1266 | |
|
|
1267 | free(CurrentBar); |
|
|
1268 | CurrentBar = prev; |
|
|
1269 | } |
1174 | } |
1270 | } |
1175 | |
|
|
1176 | free(R->h->CurrentBar); |
|
|
1177 | R->h->CurrentBar = prev; |
|
|
1178 | } |
|
|
1179 | } |
|
|
1180 | while (R->h->CurrentBar && !STRCMP(name, "*")); |
1271 | while (CurrentBar && !STRCMP(name, "*")); |
1181 | } |
1272 | } |
1182 | |
1273 | |
1183 | /* INTPROTO */ |
|
|
1184 | void |
1274 | void |
1185 | rxvt_action_decode(FILE *fp, action_t *act) |
1275 | rxvt_action_decode(FILE *fp, action_t *act) |
1186 | { |
1276 | { |
1187 | unsigned char *str; |
1277 | unsigned char *str; |
1188 | short len; |
1278 | short len; |
1189 | |
1279 | |
1190 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1280 | if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) |
1191 | return; |
1281 | return; |
1192 | |
1282 | |
1193 | if (act->type == MenuTerminalAction) { |
1283 | if (act->type == MenuTerminalAction) |
|
|
1284 | { |
1194 | fprintf(fp, "^@"); |
1285 | fprintf(fp, "^@"); |
1195 | /* can strip trailing ^G from XTerm sequence */ |
1286 | /* can strip trailing ^G from XTerm sequence */ |
1196 | if (str[0] == C0_ESC && str[1] == ']' && str[len - 1] == C0_BEL) |
1287 | if (str[0] == C0_ESC && str[1] == ']' && str[len - 1] == C0_BEL) |
1197 | len--; |
1288 | len--; |
|
|
1289 | } |
1198 | } else if (str[0] == C0_ESC) { |
1290 | else if (str[0] == C0_ESC) |
|
|
1291 | { |
1199 | switch (str[1]) { |
1292 | switch (str[1]) |
1200 | case '[': |
1293 | { |
1201 | case ']': |
1294 | case '[': |
1202 | break; |
1295 | case ']': |
|
|
1296 | break; |
1203 | |
1297 | |
1204 | case 'x': |
1298 | case 'x': |
1205 | /* can strip trailing '\r' from M-x sequence */ |
1299 | /* can strip trailing '\r' from M-x sequence */ |
1206 | if (str[len - 1] == '\r') |
1300 | if (str[len - 1] == '\r') |
1207 | len--; |
1301 | len--; |
1208 | /* FALLTHROUGH */ |
1302 | /* FALLTHROUGH */ |
1209 | |
1303 | |
1210 | default: |
1304 | default: |
1211 | fprintf(fp, "M-"); /* meta prefix */ |
1305 | fprintf(fp, "M-"); /* meta prefix */ |
1212 | str++; |
1306 | str++; |
1213 | len--; |
1307 | len--; |
1214 | break; |
1308 | break; |
1215 | } |
1309 | } |
1216 | } |
1310 | } |
1217 | /* |
1311 | /* |
1218 | * control character form is preferred, since backslash-escaping |
1312 | * control character form is preferred, since backslash-escaping |
1219 | * can be really ugly looking when the backslashes themselves also |
1313 | * can be really ugly looking when the backslashes themselves also |
1220 | * have to be escaped to avoid Shell (or whatever scripting |
1314 | * have to be escaped to avoid Shell (or whatever scripting |
1221 | * language) interpretation |
1315 | * language) interpretation |
1222 | */ |
1316 | */ |
1223 | while (len > 0) { |
1317 | while (len > 0) |
|
|
1318 | { |
1224 | unsigned char ch = *str++; |
1319 | unsigned char ch = *str++; |
1225 | |
1320 | |
1226 | switch (ch) { |
1321 | switch (ch) |
1227 | case C0_ESC: |
1322 | { |
|
|
1323 | case C0_ESC: |
1228 | fprintf(fp, "\\E"); |
1324 | fprintf(fp, "\\E"); |
1229 | break; /* escape */ |
1325 | break; /* escape */ |
1230 | case '\r': |
1326 | case '\r': |
1231 | fprintf(fp, "\\r"); |
1327 | fprintf(fp, "\\r"); |
1232 | break; /* carriage-return */ |
1328 | break; /* carriage-return */ |
1233 | case '\\': |
1329 | case '\\': |
1234 | fprintf(fp, "\\\\"); |
1330 | fprintf(fp, "\\\\"); |
1235 | break; /* backslash */ |
1331 | break; /* backslash */ |
1236 | case '^': |
1332 | case '^': |
1237 | fprintf(fp, "\\^"); |
1333 | fprintf(fp, "\\^"); |
1238 | break; /* caret */ |
1334 | break; /* caret */ |
1239 | case 127: |
1335 | case 127: |
1240 | fprintf(fp, "^?"); |
1336 | fprintf(fp, "^?"); |
1241 | default: |
1337 | default: |
1242 | if (ch <= 31) |
1338 | if (ch <= 31) |
1243 | fprintf(fp, "^%c", ('@' + ch)); |
1339 | fprintf(fp, "^%c", ('@' + ch)); |
1244 | else if (ch > 127) |
1340 | else if (ch > 127) |
1245 | fprintf(fp, "\\%o", ch); |
1341 | fprintf(fp, "\\%o", ch); |
1246 | else |
1342 | else |
1247 | fprintf(fp, "%c", ch); |
1343 | fprintf(fp, "%c", ch); |
1248 | break; |
1344 | break; |
1249 | } |
1345 | } |
1250 | len--; |
1346 | len--; |
1251 | } |
1347 | } |
1252 | fprintf(fp, "\n"); |
1348 | fprintf(fp, "\n"); |
1253 | } |
1349 | } |
1254 | |
1350 | |
1255 | /* INTPROTO */ |
|
|
1256 | void |
1351 | void |
1257 | rxvt_menu_dump(FILE *fp, menu_t *menu) |
1352 | rxvt_menu_dump(FILE *fp, menu_t *menu) |
1258 | { |
1353 | { |
1259 | menuitem_t *item; |
1354 | menuitem_t *item; |
1260 | |
1355 | |
1261 | /* create a new menu and clear it */ |
1356 | /* create a new menu and clear it */ |
1262 | fprintf(fp, (menu->parent ? "./%s/*\n" : "/%s/*\n"), menu->name); |
1357 | fprintf(fp, (menu->parent ? "./%s/*\n" : "/%s/*\n"), menu->name); |
1263 | |
1358 | |
1264 | for (item = menu->head; item != NULL; item = item->next) { |
1359 | for (item = menu->head; item != NULL; item = item->next) |
|
|
1360 | { |
1265 | switch (item->entry.type) { |
1361 | switch (item->entry.type) |
|
|
1362 | { |
1266 | case MenuSubMenu: |
1363 | case MenuSubMenu: |
1267 | if (item->entry.submenu.menu == NULL) |
1364 | if (item->entry.submenu.menu == NULL) |
1268 | fprintf(fp, "> %s == NULL\n", item->name); |
1365 | fprintf(fp, "> %s == NULL\n", item->name); |
1269 | else |
1366 | else |
1270 | rxvt_menu_dump(fp, item->entry.submenu.menu); |
1367 | rxvt_menu_dump(fp, item->entry.submenu.menu); |
1271 | break; |
1368 | break; |
1272 | |
1369 | |
1273 | case MenuLabel: |
1370 | case MenuLabel: |
1274 | fprintf(fp, "{%s}\n", (STRLEN(item->name) ? item->name : "-")); |
1371 | fprintf(fp, "{%s}\n", (STRLEN(item->name) ? item->name : "-")); |
1275 | break; |
1372 | break; |
1276 | |
1373 | |
1277 | case MenuTerminalAction: |
1374 | case MenuTerminalAction: |
1278 | case MenuAction: |
1375 | case MenuAction: |
1279 | fprintf(fp, "{%s}", item->name); |
1376 | fprintf(fp, "{%s}", item->name); |
1280 | if (item->name2 != NULL && STRLEN(item->name2)) |
1377 | if (item->name2 != NULL && STRLEN(item->name2)) |
1281 | fprintf(fp, "{%s}", item->name2); |
1378 | fprintf(fp, "{%s}", item->name2); |
1282 | fprintf(fp, "\t"); |
1379 | fprintf(fp, "\t"); |
1283 | rxvt_action_decode(fp, &(item->entry.action)); |
1380 | rxvt_action_decode(fp, &(item->entry.action)); |
1284 | break; |
1381 | break; |
1285 | } |
1382 | } |
1286 | } |
1383 | } |
1287 | |
1384 | |
1288 | fprintf(fp, (menu->parent ? "../\n" : "/\n\n")); |
1385 | fprintf(fp, (menu->parent ? "../\n" : "/\n\n")); |
1289 | } |
1386 | } |
1290 | |
1387 | |
1291 | /* INTPROTO */ |
|
|
1292 | void |
1388 | void |
1293 | rxvt_menubar_dump(pR_ FILE *fp) |
1389 | rxvt_term::menubar_dump (FILE *fp) |
1294 | { |
1390 | { |
1295 | bar_t *bar = R->h->CurrentBar; |
1391 | bar_t *bar = CurrentBar; |
1296 | time_t t; |
1392 | time_t t; |
1297 | |
1393 | |
1298 | if (bar == NULL || fp == NULL) |
1394 | if (bar == NULL || fp == NULL) |
1299 | return; |
1395 | return; |
1300 | time(&t); |
1396 | time(&t); |
1301 | |
1397 | |
1302 | fprintf(fp, |
1398 | fprintf(fp, |
1303 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1399 | "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", |
1304 | R->h->rs[Rs_name], (unsigned int)getpid(), ctime(&t)); |
1400 | rs[Rs_name], (unsigned int)getpid(), ctime(&t)); |
1305 | |
1401 | |
1306 | /* dump in reverse order */ |
1402 | /* dump in reverse order */ |
1307 | bar = R->h->CurrentBar->prev; |
1403 | bar = CurrentBar->prev; |
|
|
1404 | do |
1308 | do { |
1405 | { |
1309 | menu_t *menu; |
1406 | menu_t *menu; |
1310 | int i; |
1407 | int i; |
1311 | |
1408 | |
1312 | fprintf(fp, "[menu:%s]\n", bar->name); |
1409 | fprintf(fp, "[menu:%s]\n", bar->name); |
1313 | |
1410 | |
1314 | if (bar->title != NULL) |
1411 | if (bar->title != NULL) |
1315 | fprintf(fp, "[title:%s]\n", bar->title); |
1412 | fprintf(fp, "[title:%s]\n", bar->title); |
1316 | |
1413 | |
1317 | for (i = 0; i < NARROWS; i++) { |
1414 | for (i = 0; i < NARROWS; i++) |
|
|
1415 | { |
1318 | switch (bar->arrows[i].type) { |
1416 | switch (bar->arrows[i].type) |
|
|
1417 | { |
1319 | case MenuTerminalAction: |
1418 | case MenuTerminalAction: |
1320 | case MenuAction: |
1419 | case MenuAction: |
1321 | fprintf(fp, "<%c>", Arrows[i].name); |
1420 | fprintf(fp, "<%c>", Arrows[i].name); |
1322 | rxvt_action_decode(fp, &(bar->arrows[i])); |
1421 | rxvt_action_decode(fp, &(bar->arrows[i])); |
1323 | break; |
1422 | break; |
1324 | } |
1423 | } |
1325 | } |
1424 | } |
1326 | fprintf(fp, "\n"); |
1425 | fprintf(fp, "\n"); |
1327 | |
1426 | |
1328 | for (menu = bar->head; menu != NULL; menu = menu->next) |
1427 | for (menu = bar->head; menu != NULL; menu = menu->next) |
1329 | rxvt_menu_dump(fp, menu); |
1428 | rxvt_menu_dump(fp, menu); |
1330 | |
1429 | |
1331 | fprintf(fp, "\n[done:%s]\n\n", bar->name); |
1430 | fprintf(fp, "\n[done:%s]\n\n", bar->name); |
1332 | bar = bar->prev; |
1431 | bar = bar->prev; |
1333 | } |
1432 | } |
1334 | while (bar != R->h->CurrentBar->prev); |
1433 | while (bar != CurrentBar->prev); |
1335 | } |
1434 | } |
1336 | #endif /* (MENUBAR_MAX > 1) */ |
1435 | #endif /* (MENUBAR_MAX > 1) */ |
1337 | |
1436 | |
1338 | /* |
1437 | /* |
1339 | * read in menubar commands from FILENAME |
1438 | * read in menubar commands from FILENAME |
… | |
… | |
1348 | * read `file' starting with first [menu] or [menu:???] line |
1447 | * read `file' starting with first [menu] or [menu:???] line |
1349 | * |
1448 | * |
1350 | * FILENAME = "file;tag" |
1449 | * FILENAME = "file;tag" |
1351 | * read `file' starting with [menu:tag] |
1450 | * read `file' starting with [menu:tag] |
1352 | */ |
1451 | */ |
1353 | /* EXTPROTO */ |
|
|
1354 | void |
1452 | void |
1355 | rxvt_menubar_read(pR_ const char *filename) |
1453 | rxvt_term::menubar_read (const char *filename) |
1356 | { |
1454 | { |
1357 | /* read in a menu from a file */ |
1455 | /* read in a menu from a file */ |
1358 | FILE *fp; |
1456 | FILE *fp; |
1359 | char buffer[256]; |
1457 | char buffer[256]; |
1360 | char *p, *file, *tag = NULL; |
1458 | char *p, *file, *tag = NULL; |
1361 | |
1459 | |
1362 | file = (char *)rxvt_File_find(filename, ".menu", R->h->rs[Rs_path]); |
1460 | file = (char *)rxvt_File_find(filename, ".menu", rs[Rs_path]); |
1363 | if (file == NULL) |
1461 | if (file == NULL) |
1364 | return; |
1462 | return; |
1365 | fp = fopen(file, "rb"); |
1463 | fp = fopen(file, "rb"); |
1366 | free(file); |
1464 | free(file); |
1367 | if (fp == NULL) |
1465 | if (fp == NULL) |
1368 | return; |
1466 | return; |
1369 | |
1467 | |
1370 | #if (MENUBAR_MAX > 1) |
1468 | #if (MENUBAR_MAX > 1) |
1371 | /* semi-colon delimited */ |
1469 | /* semi-colon delimited */ |
1372 | if ((tag = STRCHR(filename, ';')) != NULL) { |
1470 | if ((tag = STRCHR(filename, ';')) != NULL) |
1373 | tag++; |
1471 | { |
|
|
1472 | tag++; |
1374 | if (*tag == '\0') |
1473 | if (*tag == '\0') |
1375 | tag = NULL; |
1474 | tag = NULL; |
1376 | } |
1475 | } |
1377 | #endif /* (MENUBAR_MAX > 1) */ |
1476 | #endif /* (MENUBAR_MAX > 1) */ |
1378 | #ifdef DEBUG_MENU |
1477 | #ifdef DEBUG_MENU |
1379 | fprintf(stderr, "[read:%s]\n", p); |
1478 | fprintf(stderr, "[read:%s]\n", p); |
1380 | if (tag) |
1479 | if (tag) |
1381 | fprintf(stderr, "looking for [menu:%s]\n", tag); |
1480 | fprintf(stderr, "looking for [menu:%s]\n", tag); |
1382 | #endif |
1481 | #endif |
1383 | |
1482 | |
1384 | while ((p = fgets(buffer, sizeof(buffer), fp)) != NULL) { |
1483 | while ((p = fgets(buffer, sizeof(buffer), fp)) != NULL) |
|
|
1484 | { |
1385 | int n; |
1485 | int n; |
1386 | |
1486 | |
1387 | if ((n = rxvt_Str_match(p, "[menu")) != 0) { |
1487 | if ((n = rxvt_Str_match(p, "[menu")) != 0) |
1388 | if (tag) { |
1488 | { |
|
|
1489 | if (tag) |
|
|
1490 | { |
1389 | /* looking for [menu:tag] */ |
1491 | /* looking for [menu:tag] */ |
1390 | if (p[n] == ':' && p[n + 1] != ']') { |
1492 | if (p[n] == ':' && p[n + 1] != ']') |
1391 | n++; |
1493 | { |
|
|
1494 | n++; |
1392 | n += rxvt_Str_match(p + n, tag); |
1495 | n += rxvt_Str_match(p + n, tag); |
1393 | if (p[n] == ']') { |
1496 | if (p[n] == ']') |
|
|
1497 | { |
1394 | #ifdef DEBUG_MENU |
1498 | #ifdef DEBUG_MENU |
1395 | fprintf(stderr, "[menu:%s]\n", tag); |
1499 | fprintf(stderr, "[menu:%s]\n", tag); |
1396 | #endif |
1500 | #endif |
1397 | break; |
1501 | break; |
|
|
1502 | } |
|
|
1503 | } |
|
|
1504 | } |
|
|
1505 | else if (p[n] == ':' || p[n] == ']') |
|
|
1506 | break; |
|
|
1507 | } |
1398 | } |
1508 | } |
1399 | } |
|
|
1400 | } else if (p[n] == ':' || p[n] == ']') |
|
|
1401 | break; |
|
|
1402 | } |
|
|
1403 | } |
|
|
1404 | |
1509 | |
1405 | /* found [menu], [menu:???] tag */ |
1510 | /* found [menu], [menu:???] tag */ |
1406 | while (p != NULL) { |
1511 | while (p != NULL) |
|
|
1512 | { |
1407 | int n; |
1513 | int n; |
1408 | |
1514 | |
1409 | #ifdef DEBUG_MENU |
1515 | #ifdef DEBUG_MENU |
1410 | fprintf(stderr, "read line = %s\n", p); |
1516 | fprintf(stderr, "read line = %s\n", p); |
1411 | #endif |
1517 | #endif |
1412 | |
1518 | |
1413 | /* looking for [done:tag] or [done:] */ |
1519 | /* looking for [done:tag] or [done:] */ |
1414 | if ((n = rxvt_Str_match(p, "[done")) != 0) { |
1520 | if ((n = rxvt_Str_match(p, "[done")) != 0) |
|
|
1521 | { |
1415 | if (p[n] == ']') { |
1522 | if (p[n] == ']') |
1416 | R->h->menu_readonly = 1; |
1523 | { |
1417 | break; |
1524 | menu_readonly = 1; |
1418 | } else if (p[n] == ':') { |
1525 | break; |
1419 | n++; |
1526 | } |
1420 | if (p[n] == ']') { |
1527 | else if (p[n] == ':') |
1421 | R->h->menu_readonly = 1; |
1528 | { |
1422 | break; |
1529 | n++; |
1423 | } else if (tag) { |
1530 | if (p[n] == ']') |
|
|
1531 | { |
|
|
1532 | menu_readonly = 1; |
|
|
1533 | break; |
|
|
1534 | } |
|
|
1535 | else if (tag) |
|
|
1536 | { |
1424 | n += rxvt_Str_match(p + n, tag); |
1537 | n += rxvt_Str_match(p + n, tag); |
1425 | if (p[n] == ']') { |
1538 | if (p[n] == ']') |
|
|
1539 | { |
1426 | #ifdef DEBUG_MENU |
1540 | #ifdef DEBUG_MENU |
1427 | fprintf(stderr, "[done:%s]\n", tag); |
1541 | fprintf(stderr, "[done:%s]\n", tag); |
1428 | #endif |
1542 | #endif |
1429 | R->h->menu_readonly = 1; |
1543 | menu_readonly = 1; |
1430 | break; |
1544 | break; |
1431 | } |
1545 | } |
1432 | } else { |
1546 | } |
|
|
1547 | else |
|
|
1548 | { |
1433 | /* what? ... skip this line */ |
1549 | /* what? ... skip this line */ |
1434 | p[0] = COMMENT_CHAR; |
1550 | p[0] = COMMENT_CHAR; |
1435 | } |
1551 | } |
1436 | } |
1552 | } |
1437 | } |
1553 | } |
1438 | /* |
1554 | /* |
1439 | * remove leading/trailing space |
1555 | * remove leading/trailing space |
1440 | * and strip-off leading/trailing quotes |
1556 | * and strip-off leading/trailing quotes |
1441 | * skip blank or comment lines |
1557 | * skip blank or comment lines |
1442 | */ |
1558 | */ |
1443 | rxvt_Str_trim(p); |
1559 | rxvt_Str_trim(p); |
1444 | if (*p && *p != '#') { |
1560 | if (*p && *p != '#') |
|
|
1561 | { |
1445 | R->h->menu_readonly = 0; /* if case we read another file */ |
1562 | menu_readonly = 0; /* if case we read another file */ |
1446 | rxvt_menubar_dispatch(aR_ p); |
1563 | menubar_dispatch (p); |
1447 | } |
1564 | } |
1448 | /* get another line */ |
1565 | /* get another line */ |
1449 | p = fgets(buffer, sizeof(buffer), fp); |
1566 | p = fgets(buffer, sizeof(buffer), fp); |
1450 | } |
1567 | } |
1451 | |
1568 | |
1452 | fclose(fp); |
1569 | fclose(fp); |
1453 | } |
1570 | } |
1454 | |
1571 | |
1455 | /* |
1572 | /* |
1456 | * user interface for building/deleting and otherwise managing menus |
1573 | * user interface for building/deleting and otherwise managing menus |
1457 | */ |
1574 | */ |
1458 | /* EXTPROTO */ |
|
|
1459 | void |
1575 | void |
1460 | rxvt_menubar_dispatch(pR_ char *str) |
1576 | rxvt_term::menubar_dispatch (char *str) |
1461 | { |
1577 | { |
1462 | int n, cmd; |
1578 | int n, cmd; |
1463 | char *path, *name, *name2; |
1579 | char *path, *name, *name2; |
1464 | |
1580 | |
1465 | if (menubar_visible(r) && R->h->ActiveMenu != NULL) |
1581 | if (menubar_visible(r) && ActiveMenu != NULL) |
1466 | rxvt_menubar_expose(aR); |
1582 | menubar_expose (); |
1467 | else |
1583 | else |
1468 | R->h->ActiveMenu = NULL; |
1584 | ActiveMenu = NULL; |
1469 | |
1585 | |
1470 | cmd = *str; |
1586 | cmd = *str; |
1471 | switch (cmd) { |
1587 | switch (cmd) |
|
|
1588 | { |
1472 | case '.': |
1589 | case '.': |
1473 | case '/': /* absolute & relative path */ |
1590 | case '/': /* absolute & relative path */ |
1474 | case MENUITEM_BEG: /* menuitem */ |
1591 | case MENUITEM_BEG: /* menuitem */ |
1475 | /* add `+' prefix for these cases */ |
1592 | /* add `+' prefix for these cases */ |
1476 | cmd = '+'; |
1593 | cmd = '+'; |
1477 | break; |
1594 | break; |
1478 | |
1595 | |
1479 | case '+': |
1596 | case '+': |
1480 | case '-': |
1597 | case '-': |
1481 | str++; /* skip cmd character */ |
1598 | str++; /* skip cmd character */ |
1482 | break; |
1599 | break; |
1483 | |
1600 | |
1484 | case '<': |
1601 | case '<': |
1485 | #if (MENUBAR_MAX > 1) |
1602 | #if (MENUBAR_MAX > 1) |
1486 | if (R->h->CurrentBar == NULL) |
1603 | if (CurrentBar == NULL) |
1487 | break; |
1604 | break; |
1488 | #endif /* (MENUBAR_MAX > 1) */ |
1605 | #endif /* (MENUBAR_MAX > 1) */ |
1489 | if (str[1] && str[2] == '>') /* arrow commands */ |
1606 | if (str[1] && str[2] == '>') /* arrow commands */ |
1490 | rxvt_menuarrow_add(aR_ str); |
1607 | menuarrow_add (str); |
1491 | break; |
1608 | break; |
1492 | |
1609 | |
1493 | case '[': /* extended command */ |
1610 | case '[': /* extended command */ |
1494 | while (str[0] == '[') { |
1611 | while (str[0] == '[') |
|
|
1612 | { |
1495 | char *next = (++str); /* skip leading '[' */ |
1613 | char *next = (++str); /* skip leading '[' */ |
1496 | |
1614 | |
1497 | if (str[0] == ':') { /* [:command:] */ |
1615 | if (str[0] == ':') |
1498 | do { |
1616 | { /* [:command:] */ |
1499 | next++; |
1617 | do |
|
|
1618 | { |
|
|
1619 | next++; |
|
|
1620 | if ((next = STRCHR(next, ':')) == NULL) |
|
|
1621 | return; /* parse error */ |
|
|
1622 | } |
|
|
1623 | while (next[1] != ']'); |
|
|
1624 | /* remove and skip ':]' */ |
|
|
1625 | *next = '\0'; |
|
|
1626 | next += 2; |
|
|
1627 | } |
|
|
1628 | else |
|
|
1629 | { |
1500 | if ((next = STRCHR(next, ':')) == NULL) |
1630 | if ((next = STRCHR(next, ']')) == NULL) |
1501 | return; /* parse error */ |
|
|
1502 | } |
|
|
1503 | while (next[1] != ']'); |
|
|
1504 | /* remove and skip ':]' */ |
|
|
1505 | *next = '\0'; |
|
|
1506 | next += 2; |
|
|
1507 | } else { |
|
|
1508 | if ((next = STRCHR(next, ']')) == NULL) |
|
|
1509 | return; /* parse error */ |
1631 | return; /* parse error */ |
1510 | /* remove and skip ']' */ |
1632 | /* remove and skip ']' */ |
1511 | *next = '\0'; |
1633 | *next = '\0'; |
1512 | next++; |
1634 | next++; |
1513 | } |
1635 | } |
1514 | |
1636 | |
1515 | if (str[0] == ':') { |
1637 | if (str[0] == ':') |
1516 | int saved; |
1638 | { |
|
|
1639 | int saved; |
1517 | |
1640 | |
1518 | /* try and dispatch it, regardless of read/write status */ |
1641 | /* try and dispatch it, regardless of read/write status */ |
1519 | saved = R->h->menu_readonly; |
1642 | saved = menu_readonly; |
1520 | R->h->menu_readonly = 0; |
1643 | menu_readonly = 0; |
1521 | rxvt_menubar_dispatch(aR_ str + 1); |
1644 | menubar_dispatch (str + 1); |
1522 | R->h->menu_readonly = saved; |
1645 | menu_readonly = saved; |
1523 | } |
1646 | } |
1524 | /* these ones don't require menu stacking */ |
1647 | /* these ones don't require menu stacking */ |
1525 | else if (!STRCMP(str, "clear")) { |
1648 | else if (!STRCMP(str, "clear")) |
1526 | rxvt_menubar_clear(aR); |
1649 | { |
|
|
1650 | menubar_clear (); |
|
|
1651 | } |
1527 | } else if (!STRCMP(str, "done") || rxvt_Str_match(str, "done:")) { |
1652 | else if (!STRCMP(str, "done") || rxvt_Str_match(str, "done:")) |
1528 | R->h->menu_readonly = 1; |
1653 | { |
|
|
1654 | menu_readonly = 1; |
|
|
1655 | } |
1529 | } else if (!STRCMP(str, "show")) { |
1656 | else if (!STRCMP(str, "show")) |
1530 | rxvt_map_menuBar(aR_ 1); |
1657 | { |
1531 | R->h->menu_readonly = 1; |
1658 | map_menuBar (1); |
|
|
1659 | menu_readonly = 1; |
|
|
1660 | } |
1532 | } else if (!STRCMP(str, "hide")) { |
1661 | else if (!STRCMP(str, "hide")) |
1533 | rxvt_map_menuBar(aR_ 0); |
1662 | { |
1534 | R->h->menu_readonly = 1; |
1663 | map_menuBar (0); |
|
|
1664 | menu_readonly = 1; |
|
|
1665 | } |
1535 | } else if ((n = rxvt_Str_match(str, "read:")) != 0) { |
1666 | else if ((n = rxvt_Str_match(str, "read:")) != 0) |
|
|
1667 | { |
1536 | /* read in a menu from a file */ |
1668 | /* read in a menu from a file */ |
1537 | str += n; |
1669 | str += n; |
1538 | rxvt_menubar_read(aR_ str); |
1670 | menubar_read (str); |
|
|
1671 | } |
1539 | } else if ((n = rxvt_Str_match(str, "title:")) != 0) { |
1672 | else if ((n = rxvt_Str_match(str, "title:")) != 0) |
1540 | str += n; |
1673 | { |
1541 | if (R->h->CurrentBar != NULL && !R->h->menu_readonly) { |
1674 | str += n; |
1542 | if (*str) { |
1675 | if (CurrentBar != NULL && !menu_readonly) |
1543 | name = rxvt_realloc(R->h->CurrentBar->title, |
1676 | { |
1544 | STRLEN(str) + 1); |
1677 | if (*str) |
1545 | if (name != NULL) { |
1678 | { |
1546 | STRCPY(name, str); |
1679 | name = rxvt_realloc(CurrentBar->title, |
1547 | R->h->CurrentBar->title = name; |
1680 | STRLEN(str) + 1); |
1548 | } |
1681 | if (name != NULL) |
1549 | rxvt_menubar_expose(aR); |
1682 | { |
1550 | } else { |
1683 | STRCPY(name, str); |
1551 | free(R->h->CurrentBar->title); |
1684 | CurrentBar->title = name; |
1552 | R->h->CurrentBar->title = NULL; |
1685 | } |
1553 | } |
1686 | menubar_expose (); |
1554 | } |
1687 | } |
|
|
1688 | else |
|
|
1689 | { |
|
|
1690 | free(CurrentBar->title); |
|
|
1691 | CurrentBar->title = NULL; |
|
|
1692 | } |
|
|
1693 | } |
|
|
1694 | } |
1555 | } else if ((n = rxvt_Str_match(str, "pixmap:")) != 0) { |
1695 | else if ((n = rxvt_Str_match(str, "pixmap:")) != 0) |
1556 | str += n; |
1696 | { |
1557 | rxvt_xterm_seq(aR_ XTerm_Pixmap, str, CHAR_ST); |
1697 | str += n; |
1558 | } |
1698 | xterm_seq (XTerm_Pixmap, str, CHAR_ST); |
|
|
1699 | } |
1559 | #if (MENUBAR_MAX > 1) |
1700 | #if (MENUBAR_MAX > 1) |
1560 | else if ((n = rxvt_Str_match(str, "rm")) != 0) { |
1701 | else if ((n = rxvt_Str_match(str, "rm")) != 0) |
1561 | str += n; |
1702 | { |
1562 | switch (str[0]) { |
1703 | str += n; |
1563 | case ':': |
1704 | switch (str[0]) |
1564 | str++; |
1705 | { |
1565 | /* FALLTHROUGH */ |
1706 | case ':': |
1566 | case '\0': |
1707 | str++; |
1567 | /* FALLTHROUGH */ |
1708 | /* FALLTHROUGH */ |
1568 | case '*': |
1709 | case '\0': |
1569 | rxvt_menubar_remove(aR_ str); |
1710 | /* FALLTHROUGH */ |
1570 | break; |
1711 | case '*': |
1571 | } |
1712 | menubar_remove (str); |
1572 | R->h->menu_readonly = 1; |
1713 | break; |
|
|
1714 | } |
|
|
1715 | menu_readonly = 1; |
|
|
1716 | } |
1573 | } else if ((n = rxvt_Str_match(str, "menu")) != 0) { |
1717 | else if ((n = rxvt_Str_match(str, "menu")) != 0) |
1574 | str += n; |
1718 | { |
1575 | switch (str[0]) { |
1719 | str += n; |
1576 | case ':': |
1720 | switch (str[0]) |
1577 | str++; |
1721 | { |
1578 | /* add/access menuBar */ |
1722 | case ':': |
|
|
1723 | str++; |
|
|
1724 | /* add/access menuBar */ |
1579 | if (*str != '\0' && *str != '*') |
1725 | if (*str != '\0' && *str != '*') |
1580 | rxvt_menubar_push(aR_ str); |
1726 | menubar_push (str); |
1581 | break; |
1727 | break; |
1582 | default: |
1728 | default: |
1583 | if (R->h->CurrentBar == NULL) { |
1729 | if (CurrentBar == NULL) |
1584 | rxvt_menubar_push(aR_ "default"); |
1730 | { |
1585 | } |
1731 | menubar_push ("default"); |
1586 | } |
1732 | } |
|
|
1733 | } |
1587 | |
1734 | |
1588 | if (R->h->CurrentBar != NULL) |
1735 | if (CurrentBar != NULL) |
1589 | R->h->menu_readonly = 0; /* allow menu build commands */ |
1736 | menu_readonly = 0; /* allow menu build commands */ |
|
|
1737 | } |
1590 | } else if (!STRCMP(str, "dump")) { |
1738 | else if (!STRCMP(str, "dump")) |
|
|
1739 | { |
1591 | /* dump current menubars to a file */ |
1740 | /* dump current menubars to a file */ |
1592 | FILE *fp; |
1741 | FILE *fp; |
1593 | |
1742 | |
1594 | /* enough space to hold the results */ |
1743 | /* enough space to hold the results */ |
1595 | char buffer[32]; |
1744 | char buffer[32]; |
1596 | |
1745 | |
1597 | sprintf(buffer, "/tmp/" APL_SUBCLASS "-%u", |
1746 | sprintf(buffer, "/tmp/" APL_SUBCLASS "-%u", |
1598 | (unsigned int)getpid()); |
1747 | (unsigned int)getpid()); |
1599 | |
1748 | |
1600 | if ((fp = fopen(buffer, "wb")) != NULL) { |
1749 | if ((fp = fopen(buffer, "wb")) != NULL) |
1601 | rxvt_xterm_seq(aR_ XTerm_title, buffer, CHAR_ST); |
1750 | { |
1602 | rxvt_menubar_dump(aR_ fp); |
1751 | xterm_seq (XTerm_title, buffer, CHAR_ST); |
1603 | fclose(fp); |
1752 | menubar_dump (fp); |
1604 | } |
1753 | fclose(fp); |
|
|
1754 | } |
|
|
1755 | } |
1605 | } else if (!STRCMP(str, "next")) { |
1756 | else if (!STRCMP(str, "next")) |
1606 | if (R->h->CurrentBar) { |
1757 | { |
1607 | R->h->CurrentBar = R->h->CurrentBar->next; |
1758 | if (CurrentBar) |
1608 | R->h->menu_readonly = 1; |
1759 | { |
1609 | } |
1760 | CurrentBar = CurrentBar->next; |
|
|
1761 | menu_readonly = 1; |
|
|
1762 | } |
|
|
1763 | } |
1610 | } else if (!STRCMP(str, "prev")) { |
1764 | else if (!STRCMP(str, "prev")) |
1611 | if (R->h->CurrentBar) { |
1765 | { |
1612 | R->h->CurrentBar = R->h->CurrentBar->prev; |
1766 | if (CurrentBar) |
1613 | R->h->menu_readonly = 1; |
1767 | { |
1614 | } |
1768 | CurrentBar = CurrentBar->prev; |
|
|
1769 | menu_readonly = 1; |
|
|
1770 | } |
|
|
1771 | } |
1615 | } else if (!STRCMP(str, "swap")) { |
1772 | else if (!STRCMP(str, "swap")) |
1616 | /* swap the top 2 menus */ |
1773 | { |
1617 | if (R->h->CurrentBar) { |
1774 | /* swap the top 2 menus */ |
|
|
1775 | if (CurrentBar) |
|
|
1776 | { |
1618 | bar_t *cbprev = R->h->CurrentBar->prev; |
1777 | bar_t *cbprev = CurrentBar->prev; |
1619 | bar_t *cbnext = R->h->CurrentBar->next; |
1778 | bar_t *cbnext = CurrentBar->next; |
1620 | |
1779 | |
1621 | cbprev->next = cbnext; |
1780 | cbprev->next = cbnext; |
1622 | cbnext->prev = cbprev; |
1781 | cbnext->prev = cbprev; |
1623 | |
1782 | |
1624 | R->h->CurrentBar->next = cbprev; |
1783 | CurrentBar->next = cbprev; |
1625 | R->h->CurrentBar->prev = cbprev->prev; |
1784 | CurrentBar->prev = cbprev->prev; |
1626 | |
1785 | |
1627 | cbprev->prev->next = R->h->CurrentBar; |
1786 | cbprev->prev->next = CurrentBar; |
1628 | cbprev->prev = R->h->CurrentBar; |
1787 | cbprev->prev = CurrentBar; |
1629 | |
1788 | |
1630 | R->h->CurrentBar = cbprev; |
1789 | CurrentBar = cbprev; |
1631 | R->h->menu_readonly = 1; |
1790 | menu_readonly = 1; |
1632 | } |
1791 | } |
1633 | } |
1792 | } |
1634 | #endif /* (MENUBAR_MAX > 1) */ |
1793 | #endif /* (MENUBAR_MAX > 1) */ |
1635 | str = next; |
1794 | str = next; |
1636 | |
1795 | |
1637 | R->h->BuildMenu = R->h->ActiveMenu = NULL; |
1796 | BuildMenu = ActiveMenu = NULL; |
1638 | rxvt_menubar_expose(aR); |
1797 | menubar_expose (); |
1639 | #ifdef DEBUG_MENUBAR_STACKING |
1798 | #ifdef DEBUG_MENUBAR_STACKING |
1640 | fprintf(stderr, "menus are read%s\n", |
1799 | fprintf(stderr, "menus are read%s\n", |
1641 | R->h->menu_readonly ? "only" : "/write"); |
1800 | menu_readonly ? "only" : "/write"); |
1642 | #endif |
1801 | #endif |
1643 | } |
1802 | |
1644 | return; |
1803 | } |
1645 | break; |
1804 | return; |
|
|
1805 | break; |
1646 | } |
1806 | } |
1647 | |
1807 | |
1648 | #if (MENUBAR_MAX > 1) |
1808 | #if (MENUBAR_MAX > 1) |
1649 | if (R->h->CurrentBar == NULL) |
1809 | if (CurrentBar == NULL) |
1650 | return; |
1810 | return; |
1651 | if (R->h->menu_readonly) { |
1811 | if (menu_readonly) |
|
|
1812 | { |
1652 | #ifdef DEBUG_MENUBAR_STACKING |
1813 | #ifdef DEBUG_MENUBAR_STACKING |
1653 | fprintf(stderr, "menus are read%s\n", |
1814 | fprintf(stderr, "menus are read%s\n", |
1654 | R->h->menu_readonly ? "only" : "/write"); |
1815 | menu_readonly ? "only" : "/write"); |
1655 | #endif |
1816 | #endif |
1656 | return; |
1817 | return; |
1657 | } |
1818 | } |
1658 | #endif /* (MENUBAR_MAX > 1) */ |
1819 | #endif /* (MENUBAR_MAX > 1) */ |
1659 | |
1820 | |
1660 | switch (cmd) { |
1821 | switch (cmd) |
|
|
1822 | { |
1661 | case '+': |
1823 | case '+': |
1662 | case '-': |
1824 | case '-': |
1663 | path = name = str; |
1825 | path = name = str; |
1664 | |
1826 | |
1665 | name2 = NULL; |
1827 | name2 = NULL; |
1666 | /* parse STR, allow spaces inside (name) */ |
1828 | /* parse STR, allow spaces inside (name) */ |
1667 | if (path[0] != '\0') { |
1829 | if (path[0] != '\0') |
|
|
1830 | { |
1668 | name = STRCHR(path, MENUITEM_BEG); |
1831 | name = STRCHR(path, MENUITEM_BEG); |
1669 | str = STRCHR(path, MENUITEM_END); |
1832 | str = STRCHR(path, MENUITEM_END); |
1670 | if (name != NULL || str != NULL) { |
1833 | if (name != NULL || str != NULL) |
|
|
1834 | { |
1671 | if (name == NULL || str == NULL || str <= (name + 1) |
1835 | if (name == NULL || str == NULL || str <= (name + 1) |
1672 | || (name > path && name[-1] != '/')) { |
1836 | || (name > path && name[-1] != '/')) |
|
|
1837 | { |
1673 | rxvt_print_error("menu error <%s>\n", path); |
1838 | rxvt_print_error("menu error <%s>\n", path); |
1674 | break; |
1839 | break; |
1675 | } |
1840 | } |
1676 | if (str[1] == MENUITEM_BEG) { |
1841 | if (str[1] == MENUITEM_BEG) |
1677 | name2 = (str + 2); |
1842 | { |
|
|
1843 | name2 = (str + 2); |
1678 | str = STRCHR(name2, MENUITEM_END); |
1844 | str = STRCHR(name2, MENUITEM_END); |
1679 | |
1845 | |
1680 | if (str == NULL) { |
1846 | if (str == NULL) |
|
|
1847 | { |
1681 | rxvt_print_error("menu error <%s>\n", path); |
1848 | rxvt_print_error("menu error <%s>\n", path); |
1682 | break; |
1849 | break; |
1683 | } |
1850 | } |
1684 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1851 | name2[-2] = '\0'; /* remove prev MENUITEM_END */ |
1685 | } |
1852 | } |
1686 | if (name > path && name[-1] == '/') |
1853 | if (name > path && name[-1] == '/') |
1687 | name[-1] = '\0'; |
1854 | name[-1] = '\0'; |
1688 | |
1855 | |
1689 | *name++ = '\0'; /* delimit */ |
1856 | *name++ = '\0'; /* delimit */ |
1690 | *str++ = '\0'; /* delimit */ |
1857 | *str++ = '\0'; /* delimit */ |
1691 | |
1858 | |
1692 | while (isspace(*str)) |
1859 | while (isspace(*str)) |
1693 | str++; /* skip space */ |
1860 | str++; /* skip space */ |
1694 | } |
1861 | } |
1695 | #ifdef DEBUG_MENU |
1862 | #ifdef DEBUG_MENU |
1696 | fprintf(stderr, |
1863 | fprintf(stderr, |
1697 | "`%c' path = <%s>, name = <%s>, name2 = <%s>, action = <%s>\n", |
1864 | "`%c' path = <%s>, name = <%s>, name2 = <%s>, action = <%s>\n", |
1698 | cmd, (path ? path : "(nil)"), (name ? name : "(nil)"), |
1865 | cmd, (path ? path : "(nil)"), (name ? name : "(nil)"), |
1699 | (name2 ? name2 : "(nil)"), (str ? str : "(nil)") |
1866 | (name2 ? name2 : "(nil)"), (str ? str : "(nil)") |
1700 | ); |
1867 | ); |
1701 | #endif |
1868 | #endif |
1702 | } |
1869 | |
|
|
1870 | } |
1703 | /* process the different commands */ |
1871 | /* process the different commands */ |
1704 | switch (cmd) { |
1872 | switch (cmd) |
|
|
1873 | { |
1705 | case '+': /* add/replace existing menu or menuitem */ |
1874 | case '+': /* add/replace existing menu or menuitem */ |
1706 | if (path[0] != '\0') { |
1875 | if (path[0] != '\0') |
1707 | int len; |
1876 | { |
|
|
1877 | int len; |
1708 | |
1878 | |
1709 | path = rxvt_menu_find_base(aR_ &(R->h->BuildMenu), path); |
1879 | path = menu_find_base (&(BuildMenu), path); |
1710 | len = STRLEN(path); |
1880 | len = STRLEN(path); |
1711 | |
1881 | |
1712 | /* don't allow menus called `*' */ |
1882 | /* don't allow menus called `*' */ |
1713 | if (path[0] == '*') { |
1883 | if (path[0] == '*') |
1714 | rxvt_menu_clear(aR_ R->h->BuildMenu); |
1884 | { |
1715 | break; |
1885 | menu_clear (BuildMenu); |
|
|
1886 | break; |
|
|
1887 | } |
1716 | } else if (len >= 2 && !STRCMP((path + len - 2), "/*")) { |
1888 | else if (len >= 2 && !STRCMP((path + len - 2), "/*")) |
1717 | path[len - 2] = '\0'; |
1889 | { |
1718 | } |
1890 | path[len - 2] = '\0'; |
1719 | if (path[0] != '\0') |
1891 | } |
1720 | R->h->BuildMenu = rxvt_menu_add(aR_ R->h->BuildMenu, path); |
1892 | if (path[0] != '\0') |
1721 | } |
1893 | BuildMenu = menu_add (BuildMenu, path); |
|
|
1894 | } |
1722 | if (name != NULL && name[0] != '\0') |
1895 | if (name != NULL && name[0] != '\0') |
1723 | rxvt_menuitem_add(R->h->BuildMenu, |
1896 | rxvt_menuitem_add(BuildMenu, |
1724 | (STRCMP(name, SEPARATOR_NAME) ? name : ""), |
1897 | (STRCMP(name, SEPARATOR_NAME) ? name : ""), |
1725 | name2, str); |
1898 | name2, str); |
1726 | break; |
1899 | break; |
1727 | |
1900 | |
1728 | case '-': /* delete menu entry */ |
1901 | case '-': /* delete menu entry */ |
1729 | if (!STRCMP(path, "/*") && (name == NULL || name[0] == '\0')) { |
1902 | if (!STRCMP(path, "/*") && (name == NULL || name[0] == '\0')) |
1730 | rxvt_menubar_clear(aR); |
1903 | { |
1731 | R->h->BuildMenu = NULL; |
1904 | menubar_clear (); |
1732 | rxvt_menubar_expose(aR); |
1905 | BuildMenu = NULL; |
1733 | break; |
1906 | menubar_expose (); |
1734 | } else if (path[0] != '\0') { |
1907 | break; |
1735 | int len; |
1908 | } |
1736 | menu_t *menu = R->h->BuildMenu; |
1909 | else if (path[0] != '\0') |
|
|
1910 | { |
|
|
1911 | int len; |
|
|
1912 | menu_t *menu = BuildMenu; |
1737 | |
1913 | |
1738 | path = rxvt_menu_find_base(aR_ &menu, path); |
1914 | path = menu_find_base (&menu, path); |
1739 | len = STRLEN(path); |
1915 | len = STRLEN(path); |
1740 | |
1916 | |
1741 | /* submenu called `*' clears all menu items */ |
1917 | /* submenu called `*' clears all menu items */ |
1742 | if (path[0] == '*') { |
1918 | if (path[0] == '*') |
1743 | rxvt_menu_clear(aR_ menu); |
1919 | { |
1744 | break; /* done */ |
1920 | menu_clear (menu); |
|
|
1921 | break; /* done */ |
|
|
1922 | } |
1745 | } else if (len >= 2 && !STRCMP(&path[len - 2], "/*")) { |
1923 | else if (len >= 2 && !STRCMP(&path[len - 2], "/*")) |
1746 | /* done */ |
1924 | { |
|
|
1925 | /* done */ |
|
|
1926 | break; |
|
|
1927 | } |
|
|
1928 | else if (path[0] != '\0') |
|
|
1929 | { |
|
|
1930 | BuildMenu = NULL; |
|
|
1931 | break; |
|
|
1932 | } |
|
|
1933 | else |
|
|
1934 | BuildMenu = menu; |
|
|
1935 | } |
|
|
1936 | if (BuildMenu != NULL) |
|
|
1937 | { |
|
|
1938 | if (name == NULL || name[0] == '\0') |
|
|
1939 | BuildMenu = menu_delete (BuildMenu); |
|
|
1940 | else |
|
|
1941 | { |
|
|
1942 | const char *n1; |
|
|
1943 | menuitem_t *item; |
|
|
1944 | menu_t *BuildMenu = BuildMenu; |
|
|
1945 | |
|
|
1946 | n1 = STRCMP(name, SEPARATOR_NAME) ? name : ""; |
|
|
1947 | item = rxvt_menuitem_find(BuildMenu, n1); |
|
|
1948 | if (item != NULL && item->entry.type != MenuSubMenu) |
|
|
1949 | { |
|
|
1950 | menuitem_free (BuildMenu, item); |
|
|
1951 | |
|
|
1952 | /* fix up the width */ |
|
|
1953 | BuildMenu->width = 0; |
|
|
1954 | for (item = BuildMenu->head; item != NULL; |
|
|
1955 | item = item->next) |
|
|
1956 | { |
|
|
1957 | short l = item->len + item->len2; |
|
|
1958 | |
|
|
1959 | MAX_IT(BuildMenu->width, l); |
|
|
1960 | } |
|
|
1961 | } |
|
|
1962 | } |
|
|
1963 | menubar_expose (); |
|
|
1964 | } |
|
|
1965 | break; |
|
|
1966 | } |
1747 | break; |
1967 | break; |
1748 | } else if (path[0] != '\0') { |
|
|
1749 | R->h->BuildMenu = NULL; |
|
|
1750 | break; |
|
|
1751 | } else |
|
|
1752 | R->h->BuildMenu = menu; |
|
|
1753 | } |
1968 | } |
1754 | if (R->h->BuildMenu != NULL) { |
|
|
1755 | if (name == NULL || name[0] == '\0') |
|
|
1756 | R->h->BuildMenu = rxvt_menu_delete(aR_ R->h->BuildMenu); |
|
|
1757 | else { |
|
|
1758 | const char *n1; |
|
|
1759 | menuitem_t *item; |
|
|
1760 | menu_t *BuildMenu = R->h->BuildMenu; |
|
|
1761 | |
|
|
1762 | n1 = STRCMP(name, SEPARATOR_NAME) ? name : ""; |
|
|
1763 | item = rxvt_menuitem_find(BuildMenu, n1); |
|
|
1764 | if (item != NULL && item->entry.type != MenuSubMenu) { |
|
|
1765 | rxvt_menuitem_free(aR_ BuildMenu, item); |
|
|
1766 | |
|
|
1767 | /* fix up the width */ |
|
|
1768 | BuildMenu->width = 0; |
|
|
1769 | for (item = BuildMenu->head; item != NULL; |
|
|
1770 | item = item->next) { |
|
|
1771 | short l = item->len + item->len2; |
|
|
1772 | |
|
|
1773 | MAX_IT(BuildMenu->width, l); |
|
|
1774 | } |
|
|
1775 | } |
|
|
1776 | } |
|
|
1777 | rxvt_menubar_expose(aR); |
|
|
1778 | } |
|
|
1779 | break; |
|
|
1780 | } |
|
|
1781 | break; |
|
|
1782 | } |
|
|
1783 | } |
1969 | } |
1784 | |
1970 | |
1785 | /* INTPROTO */ |
|
|
1786 | void |
1971 | void |
1787 | rxvt_draw_Arrows(pR_ int name, int state) |
1972 | rxvt_term::draw_Arrows (int name, int state) |
1788 | { |
1973 | { |
1789 | GC top, bot; |
1974 | GC top, bot; |
1790 | |
1975 | |
1791 | int i; |
1976 | int i; |
1792 | |
1977 | |
1793 | #ifdef MENU_SHADOW_IN |
1978 | #ifdef MENU_SHADOW_IN |
1794 | state = -state; |
1979 | state = -state; |
1795 | #endif |
1980 | #endif |
1796 | switch (state) { |
1981 | switch (state) |
|
|
1982 | { |
1797 | case +1: |
1983 | case +1: |
1798 | top = R->h->topShadowGC; |
1984 | top = topShadowGC; |
1799 | bot = R->h->botShadowGC; |
1985 | bot = botShadowGC; |
1800 | break; /* SHADOW_OUT */ |
1986 | break; /* SHADOW_OUT */ |
1801 | case -1: |
1987 | case -1: |
1802 | top = R->h->botShadowGC; |
1988 | top = botShadowGC; |
1803 | bot = R->h->topShadowGC; |
1989 | bot = topShadowGC; |
1804 | break; /* SHADOW_IN */ |
1990 | break; /* SHADOW_IN */ |
1805 | default: |
1991 | default: |
1806 | top = bot = R->h->scrollbarGC; |
1992 | top = bot = scrollbarGC; |
1807 | break; /* neutral */ |
1993 | break; /* neutral */ |
1808 | } |
1994 | } |
1809 | |
1995 | |
1810 | if (!R->h->Arrows_x) |
1996 | if (!Arrows_x) |
1811 | return; |
1997 | return; |
1812 | |
1998 | |
1813 | for (i = 0; i < NARROWS; i++) { |
1999 | for (i = 0; i < NARROWS; i++) |
|
|
2000 | { |
1814 | const int w = Width2Pixel(1); |
2001 | const int w = Width2Pixel(1); |
1815 | const int y = (menuBar_TotalHeight() - w) / 2; |
2002 | const int y = (menuBar_TotalHeight() - w) / 2; |
1816 | int x = R->h->Arrows_x + (5 * Width2Pixel(i)) / 4; |
2003 | int x = Arrows_x + (5 * Width2Pixel(i)) / 4; |
1817 | |
2004 | |
1818 | if (!name || name == Arrows[i].name) |
2005 | if (!name || name == Arrows[i].name) |
1819 | rxvt_Draw_Triangle(R->Xdisplay, R->menuBar.win, top, bot, x, y, w, |
2006 | rxvt_Draw_Triangle(Xdisplay, menuBar.win, top, bot, x, y, w, |
1820 | Arrows[i].name); |
2007 | Arrows[i].name); |
1821 | } |
2008 | } |
1822 | XFlush(R->Xdisplay); |
2009 | XFlush(Xdisplay); |
1823 | } |
2010 | } |
1824 | |
2011 | |
1825 | /* EXTPROTO */ |
|
|
1826 | void |
2012 | void |
1827 | rxvt_menubar_expose(pR) |
2013 | rxvt_term::menubar_expose () |
1828 | { |
2014 | { |
1829 | menu_t *menu; |
2015 | menu_t *menu; |
1830 | int x; |
2016 | int x; |
1831 | |
2017 | |
1832 | if (!menubar_visible(r) || R->menuBar.win == 0) |
2018 | if (!menubar_visible(r) || menuBar.win == 0) |
1833 | return; |
2019 | return; |
1834 | |
2020 | |
1835 | if (R->h->menubarGC == None) { |
2021 | if (menubarGC == None) |
|
|
2022 | { |
1836 | /* Create the graphics context */ |
2023 | /* Create the graphics context */ |
1837 | XGCValues gcvalue; |
2024 | XGCValues gcvalue; |
1838 | |
2025 | |
1839 | gcvalue.font = R->TermWin.font->fid; |
2026 | gcvalue.font = TermWin.font->fid; |
1840 | |
2027 | |
1841 | gcvalue.foreground = (XDEPTH <= 2 ? R->PixColors[Color_fg] |
2028 | gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] |
1842 | : R->PixColors[Color_Black]); |
2029 | : PixColors[Color_Black]); |
1843 | R->h->menubarGC = XCreateGC(R->Xdisplay, R->menuBar.win, |
2030 | menubarGC = XCreateGC(Xdisplay, menuBar.win, |
1844 | GCForeground | GCFont, &gcvalue); |
2031 | GCForeground | GCFont, &gcvalue); |
1845 | |
2032 | |
1846 | } |
2033 | } |
1847 | /* make sure the font is correct */ |
2034 | /* make sure the font is correct */ |
1848 | XSetFont(R->Xdisplay, R->h->menubarGC, R->TermWin.font->fid); |
2035 | XSetFont(Xdisplay, menubarGC, TermWin.font->fid); |
1849 | XSetFont(R->Xdisplay, R->h->botShadowGC, R->TermWin.font->fid); |
2036 | XSetFont(Xdisplay, botShadowGC, TermWin.font->fid); |
1850 | XClearWindow(R->Xdisplay, R->menuBar.win); |
2037 | XClearWindow(Xdisplay, menuBar.win); |
1851 | |
2038 | |
1852 | rxvt_menu_hide_all(aR); |
2039 | menu_hide_all (); |
1853 | |
2040 | |
1854 | x = 0; |
2041 | x = 0; |
1855 | if (R->h->CurrentBar != NULL) { |
2042 | if (CurrentBar != NULL) |
|
|
2043 | { |
1856 | for (menu = R->h->CurrentBar->head; menu != NULL; menu = menu->next) { |
2044 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
|
|
2045 | { |
1857 | int len = menu->len; |
2046 | int len = menu->len; |
1858 | |
2047 | |
1859 | x = (menu->x + menu->len + HSPACE); |
2048 | x = (menu->x + menu->len + HSPACE); |
1860 | |
2049 | |
1861 | #ifdef DEBUG_MENU_LAYOUT |
2050 | #ifdef DEBUG_MENU_LAYOUT |
1862 | rxvt_print_menu_descendants(menu); |
2051 | rxvt_print_menu_descendants(menu); |
1863 | #endif |
2052 | #endif |
1864 | |
2053 | |
1865 | if (x >= R->TermWin.ncol) |
2054 | if (x >= TermWin.ncol) |
1866 | len = (R->TermWin.ncol - (menu->x + HSPACE)); |
2055 | len = (TermWin.ncol - (menu->x + HSPACE)); |
1867 | |
2056 | |
1868 | rxvt_drawbox_menubar(aR_ menu->x, len, +1); |
2057 | drawbox_menubar (menu->x, len, +1); |
1869 | #ifdef USE_XIM |
2058 | #ifdef USE_XIM |
1870 | if (R->TermWin.fontset) |
2059 | if (TermWin.fontset) |
1871 | XmbDrawString(R->Xdisplay, |
2060 | XmbDrawString(Xdisplay, |
1872 | R->menuBar.win, R->TermWin.fontset, |
2061 | menuBar.win, TermWin.fontset, |
1873 | R->h->menubarGC, |
2062 | menubarGC, |
|
|
2063 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
|
|
2064 | menuBar_height() - SHADOW, menu->name, len); |
|
|
2065 | else |
|
|
2066 | #endif |
|
|
2067 | XDrawString(Xdisplay, menuBar.win, menubarGC, |
1874 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
2068 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
1875 | menuBar_height() - SHADOW, menu->name, len); |
2069 | menuBar_height() - SHADOW, menu->name, len); |
1876 | else |
|
|
1877 | #endif |
|
|
1878 | XDrawString(R->Xdisplay, R->menuBar.win, R->h->menubarGC, |
|
|
1879 | (Width2Pixel(menu->x) + Width2Pixel(HSPACE) / 2), |
|
|
1880 | menuBar_height() - SHADOW, menu->name, len); |
|
|
1881 | |
2070 | |
1882 | if (x >= R->TermWin.ncol) |
2071 | if (x >= TermWin.ncol) |
1883 | break; |
2072 | break; |
1884 | } |
2073 | } |
1885 | } |
2074 | } |
1886 | rxvt_drawbox_menubar(aR_ x, R->TermWin.ncol, (R->h->CurrentBar ? +1 : -1)); |
2075 | drawbox_menubar (x, TermWin.ncol, (CurrentBar ? +1 : -1)); |
1887 | |
2076 | |
1888 | /* add the menuBar title, if it exists and there's plenty of room */ |
2077 | /* add the menuBar title, if it exists and there's plenty of room */ |
1889 | R->h->Arrows_x = 0; |
2078 | Arrows_x = 0; |
1890 | if (x < R->TermWin.ncol) { |
2079 | if (x < TermWin.ncol) |
|
|
2080 | { |
1891 | const char *str; |
2081 | const char *str; |
1892 | int ncol; |
2082 | int ncol; |
1893 | unsigned int len; |
2083 | unsigned int len; |
1894 | char title[256]; |
2084 | char title[256]; |
1895 | |
2085 | |
1896 | ncol = (int)R->TermWin.ncol; |
2086 | ncol = (int)TermWin.ncol; |
1897 | if (x < (ncol - (NARROWS + 1))) { |
2087 | if (x < (ncol - (NARROWS + 1))) |
|
|
2088 | { |
1898 | ncol -= (NARROWS + 1); |
2089 | ncol -= (NARROWS + 1); |
1899 | R->h->Arrows_x = Width2Pixel(ncol); |
2090 | Arrows_x = Width2Pixel(ncol); |
1900 | } |
2091 | } |
1901 | rxvt_draw_Arrows(aR_ 0, +1); |
2092 | draw_Arrows (0, +1); |
1902 | |
2093 | |
1903 | str = (R->h->CurrentBar |
2094 | str = (CurrentBar |
1904 | && R->h->CurrentBar->title) ? R->h->CurrentBar->title : "%n-%v"; |
2095 | && CurrentBar->title) ? CurrentBar->title : "%n-%v"; |
1905 | for (len = 0; str[0] && len < sizeof(title) - 1; str++) { |
2096 | for (len = 0; str[0] && len < sizeof(title) - 1; str++) |
|
|
2097 | { |
1906 | const char *s = NULL; |
2098 | const char *s = NULL; |
1907 | |
2099 | |
1908 | switch (str[0]) { |
2100 | switch (str[0]) |
1909 | case '%': |
2101 | { |
1910 | str++; |
2102 | case '%': |
1911 | switch (str[0]) { |
2103 | str++; |
1912 | case 'n': |
2104 | switch (str[0]) |
1913 | s = R->h->rs[Rs_name]; |
2105 | { |
|
|
2106 | case 'n': |
|
|
2107 | s = rs[Rs_name]; |
1914 | break; /* resource name */ |
2108 | break; /* resource name */ |
1915 | case 'v': |
2109 | case 'v': |
1916 | s = VERSION; |
2110 | s = VERSION; |
1917 | break; /* version number */ |
2111 | break; /* version number */ |
1918 | case '%': |
2112 | case '%': |
1919 | s = "%"; |
2113 | s = "%"; |
1920 | break; /* literal '%' */ |
2114 | break; /* literal '%' */ |
1921 | } |
2115 | } |
1922 | if (s != NULL) |
2116 | if (s != NULL) |
1923 | while (*s && len < sizeof(title) - 1) |
2117 | while (*s && len < sizeof(title) - 1) |
1924 | title[len++] = *s++; |
2118 | title[len++] = *s++; |
1925 | break; |
2119 | break; |
1926 | |
2120 | |
1927 | default: |
2121 | default: |
1928 | title[len++] = str[0]; |
2122 | title[len++] = str[0]; |
1929 | break; |
2123 | break; |
1930 | } |
2124 | } |
1931 | } |
2125 | } |
1932 | title[len] = '\0'; |
2126 | title[len] = '\0'; |
1933 | |
2127 | |
1934 | ncol -= (x + len + HSPACE); |
2128 | ncol -= (x + len + HSPACE); |
1935 | if (len > 0 && ncol >= 0) { |
2129 | if (len > 0 && ncol >= 0) |
|
|
2130 | { |
1936 | #ifdef USE_XIM |
2131 | #ifdef USE_XIM |
1937 | if (R->TermWin.fontset) |
2132 | if (TermWin.fontset) |
1938 | XmbDrawString(R->Xdisplay, |
2133 | XmbDrawString(Xdisplay, |
1939 | R->menuBar.win, R->TermWin.fontset, |
2134 | menuBar.win, TermWin.fontset, |
1940 | R->h->menubarGC, |
2135 | menubarGC, |
|
|
2136 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
|
|
2137 | menuBar_height() - SHADOW, title, len); |
|
|
2138 | else |
|
|
2139 | #endif |
|
|
2140 | XDrawString(Xdisplay, menuBar.win, menubarGC, |
1941 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
2141 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
1942 | menuBar_height() - SHADOW, title, len); |
2142 | menuBar_height() - SHADOW, title, len); |
1943 | else |
2143 | } |
1944 | #endif |
|
|
1945 | XDrawString(R->Xdisplay, R->menuBar.win, R->h->menubarGC, |
|
|
1946 | Width2Pixel(x) + Width2Pixel(ncol + HSPACE) / 2, |
|
|
1947 | menuBar_height() - SHADOW, title, len); |
|
|
1948 | } |
|
|
1949 | } |
2144 | } |
1950 | } |
2145 | } |
1951 | |
2146 | |
1952 | /* INTPROTO */ |
|
|
1953 | int |
2147 | int |
1954 | rxvt_menubar_mapping(pR_ int map) |
2148 | rxvt_term::menubar_mapping (int map) |
1955 | { |
2149 | { |
1956 | int change = 0; |
2150 | int change = 0; |
1957 | |
2151 | |
1958 | if (map && !menubar_visible(r)) { |
2152 | if (map && !menubar_visible(r)) |
|
|
2153 | { |
1959 | R->menuBar.state = 1; |
2154 | menuBar.state = 1; |
1960 | if (R->menuBar.win == 0) |
2155 | if (menuBar.win == 0) |
1961 | return 0; |
2156 | return 0; |
1962 | XMapWindow(R->Xdisplay, R->menuBar.win); |
2157 | XMapWindow(Xdisplay, menuBar.win); |
1963 | change = 1; |
2158 | change = 1; |
|
|
2159 | } |
1964 | } else if (!map && menubar_visible(r)) { |
2160 | else if (!map && menubar_visible(r)) |
1965 | rxvt_menubar_expose(aR); |
2161 | { |
|
|
2162 | menubar_expose (); |
1966 | R->menuBar.state = 0; |
2163 | menuBar.state = 0; |
1967 | XUnmapWindow(R->Xdisplay, R->menuBar.win); |
2164 | XUnmapWindow(Xdisplay, menuBar.win); |
1968 | change = 1; |
2165 | change = 1; |
|
|
2166 | } |
1969 | } else |
2167 | else |
1970 | rxvt_menubar_expose(aR); |
2168 | menubar_expose (); |
1971 | |
2169 | |
1972 | return change; |
2170 | return change; |
1973 | } |
2171 | } |
1974 | |
2172 | |
1975 | /* INTPROTO */ |
|
|
1976 | int |
2173 | int |
1977 | rxvt_menu_select(pR_ XButtonEvent *ev) |
2174 | rxvt_term::menu_select (XButtonEvent *ev) |
1978 | { |
2175 | { |
1979 | menuitem_t *thisitem, *item = NULL; |
2176 | menuitem_t *thisitem, *item = NULL; |
1980 | int this_y, y; |
2177 | int this_y, y; |
1981 | menu_t *ActiveMenu = R->h->ActiveMenu; |
2178 | menu_t *ActiveMenu = ActiveMenu; |
1982 | |
2179 | |
1983 | Window unused_root, unused_child; |
2180 | Window unused_root, unused_child; |
1984 | int unused_root_x, unused_root_y; |
2181 | int unused_root_x, unused_root_y; |
1985 | unsigned int unused_mask; |
2182 | unsigned int unused_mask; |
1986 | |
2183 | |
1987 | if (ActiveMenu == NULL) |
2184 | if (ActiveMenu == NULL) |
1988 | return 0; |
2185 | return 0; |
1989 | |
2186 | |
1990 | XQueryPointer(R->Xdisplay, ActiveMenu->win, |
2187 | XQueryPointer(Xdisplay, ActiveMenu->win, |
1991 | &unused_root, &unused_child, |
2188 | &unused_root, &unused_child, |
1992 | &unused_root_x, &unused_root_y, |
2189 | &unused_root_x, &unused_root_y, |
1993 | &(ev->x), &(ev->y), &unused_mask); |
2190 | &(ev->x), &(ev->y), &unused_mask); |
1994 | |
2191 | |
1995 | if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) { |
2192 | if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) |
1996 | rxvt_menu_hide(aR); |
|
|
1997 | return 1; |
|
|
1998 | } |
2193 | { |
|
|
2194 | menu_hide (); |
|
|
2195 | return 1; |
|
|
2196 | } |
1999 | /* determine the menu item corresponding to the Y index */ |
2197 | /* determine the menu item corresponding to the Y index */ |
2000 | y = SHADOW; |
2198 | y = SHADOW; |
2001 | if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) { |
2199 | if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) |
|
|
2200 | { |
2002 | for (item = ActiveMenu->head; item != NULL; item = item->next) { |
2201 | for (item = ActiveMenu->head; item != NULL; item = item->next) |
|
|
2202 | { |
2003 | int h = HEIGHT_TEXT + 2 * SHADOW; |
2203 | int h = HEIGHT_TEXT + 2 * SHADOW; |
2004 | |
2204 | |
2005 | if (isSeparator(item->name)) |
2205 | if (isSeparator(item->name)) |
2006 | h = HEIGHT_SEPARATOR; |
2206 | h = HEIGHT_SEPARATOR; |
2007 | else if (ev->y >= y && ev->y < (y + h)) |
2207 | else if (ev->y >= y && ev->y < (y + h)) |
2008 | break; |
2208 | break; |
2009 | y += h; |
2209 | y += h; |
2010 | } |
2210 | } |
2011 | } |
2211 | } |
2012 | if (item == NULL && ev->type == ButtonRelease) { |
2212 | if (item == NULL && ev->type == ButtonRelease) |
2013 | rxvt_menu_hide_all(aR); |
|
|
2014 | return 0; |
|
|
2015 | } |
2213 | { |
|
|
2214 | menu_hide_all (); |
|
|
2215 | return 0; |
|
|
2216 | } |
2016 | thisitem = item; |
2217 | thisitem = item; |
2017 | this_y = y - SHADOW; |
2218 | this_y = y - SHADOW; |
2018 | |
2219 | |
2019 | /* erase the last item */ |
2220 | /* erase the last item */ |
2020 | if (ActiveMenu->item != NULL) { |
2221 | if (ActiveMenu->item != NULL) |
|
|
2222 | { |
2021 | if (ActiveMenu->item != thisitem) { |
2223 | if (ActiveMenu->item != thisitem) |
|
|
2224 | { |
2022 | for (y = 0, item = ActiveMenu->head; item != NULL; |
2225 | for (y = 0, item = ActiveMenu->head; item != NULL; |
2023 | item = item->next) { |
2226 | item = item->next) |
2024 | int h; |
2227 | { |
|
|
2228 | int h; |
2025 | |
2229 | |
2026 | if (isSeparator(item->name)) |
2230 | if (isSeparator(item->name)) |
2027 | h = HEIGHT_SEPARATOR; |
2231 | h = HEIGHT_SEPARATOR; |
2028 | else if (item == ActiveMenu->item) { |
2232 | else if (item == ActiveMenu->item) |
|
|
2233 | { |
2029 | /* erase old menuitem */ |
2234 | /* erase old menuitem */ |
2030 | rxvt_drawbox_menuitem(aR_ y, 0); /* No Shadow */ |
2235 | drawbox_menuitem (y, 0); /* No Shadow */ |
2031 | if (item->entry.type == MenuSubMenu) |
2236 | if (item->entry.type == MenuSubMenu) |
2032 | rxvt_drawtriangle(aR_ ActiveMenu->w, y, +1); |
2237 | drawtriangle (ActiveMenu->w, y, +1); |
2033 | break; |
2238 | break; |
2034 | } else |
2239 | } |
|
|
2240 | else |
2035 | h = HEIGHT_TEXT + 2 * SHADOW; |
2241 | h = HEIGHT_TEXT + 2 * SHADOW; |
2036 | y += h; |
2242 | y += h; |
2037 | } |
2243 | } |
2038 | } else { |
2244 | } |
|
|
2245 | else |
|
|
2246 | { |
2039 | switch (ev->type) { |
2247 | switch (ev->type) |
|
|
2248 | { |
2040 | case ButtonRelease: |
2249 | case ButtonRelease: |
2041 | switch (item->entry.type) { |
2250 | switch (item->entry.type) |
2042 | case MenuLabel: |
2251 | { |
2043 | case MenuSubMenu: |
2252 | case MenuLabel: |
2044 | rxvt_menu_hide_all(aR); |
2253 | case MenuSubMenu: |
2045 | break; |
2254 | menu_hide_all (); |
|
|
2255 | break; |
2046 | |
2256 | |
2047 | case MenuAction: |
2257 | case MenuAction: |
2048 | case MenuTerminalAction: |
2258 | case MenuTerminalAction: |
2049 | rxvt_drawbox_menuitem(aR_ this_y, -1); |
2259 | drawbox_menuitem (_y, -1); |
2050 | { |
2260 | { |
2051 | #ifdef HAVE_NANOSLEEP |
2261 | #ifdef HAVE_NANOSLEEP |
2052 | struct timespec rqt; |
2262 | struct timespec rqt; |
2053 | |
2263 | |
2054 | rqt.tv_sec = 0; |
2264 | rqt.tv_sec = 0; |
2055 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2265 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2056 | nanosleep(&rqt, NULL); |
2266 | nanosleep(&rqt, NULL); |
2057 | #else |
2267 | #else |
2058 | /* use select for timing */ |
2268 | /* use select for timing */ |
2059 | struct timeval tv; |
2269 | struct timeval tv; |
2060 | |
2270 | |
2061 | tv.tv_sec = 0; |
2271 | tv.tv_sec = 0; |
2062 | tv.tv_usec = MENU_DELAY_USEC; |
2272 | tv.tv_usec = MENU_DELAY_USEC; |
2063 | select(0, NULL, NULL, NULL, &tv); |
2273 | select(0, NULL, NULL, NULL, &tv); |
2064 | #endif |
2274 | #endif |
2065 | } |
2275 | |
|
|
2276 | } |
2066 | /* remove menu before sending keys to the application */ |
2277 | /* remove menu before sending keys to the application */ |
2067 | rxvt_menu_hide_all(aR); |
2278 | menu_hide_all (); |
2068 | #ifndef DEBUG_MENU |
2279 | #ifndef DEBUG_MENU |
2069 | rxvt_action_dispatch(aR_ &(item->entry.action)); |
2280 | action_dispatch (&(item->entry.action)); |
2070 | #else /* DEBUG_MENU */ |
2281 | #else /* DEBUG_MENU */ |
2071 | fprintf(stderr, "%s: %s\n", item->name, |
2282 | fprintf(stderr, "%s: %s\n", item->name, |
2072 | item->entry.action.str); |
2283 | item->entry.action.str); |
2073 | #endif /* DEBUG_MENU */ |
2284 | #endif /* DEBUG_MENU */ |
2074 | break; |
2285 | break; |
2075 | } |
2286 | } |
2076 | break; |
2287 | break; |
2077 | |
2288 | |
2078 | default: |
2289 | default: |
2079 | if (item->entry.type == MenuSubMenu) |
2290 | if (item->entry.type == MenuSubMenu) |
2080 | goto DoMenu; |
2291 | goto DoMenu; |
2081 | break; |
2292 | break; |
|
|
2293 | } |
|
|
2294 | return 0; |
|
|
2295 | } |
2082 | } |
2296 | } |
2083 | return 0; |
|
|
2084 | } |
|
|
2085 | } |
|
|
2086 | DoMenu: |
2297 | DoMenu: |
2087 | ActiveMenu->item = thisitem; |
2298 | ActiveMenu->item = thisitem; |
2088 | y = this_y; |
2299 | y = this_y; |
2089 | if (thisitem != NULL) { |
2300 | if (item != NULL) |
|
|
2301 | { |
2090 | item = ActiveMenu->item; |
2302 | item = ActiveMenu->item; |
2091 | if (item->entry.type != MenuLabel) |
2303 | if (item->entry.type != MenuLabel) |
2092 | rxvt_drawbox_menuitem(aR_ y, +1); |
2304 | drawbox_menuitem (y, +1); |
2093 | if (item->entry.type == MenuSubMenu) { |
2305 | if (item->entry.type == MenuSubMenu) |
|
|
2306 | { |
2094 | int x; |
2307 | int x; |
2095 | |
2308 | |
2096 | rxvt_drawtriangle(aR_ ActiveMenu->w, y, -1); |
2309 | drawtriangle (ActiveMenu->w, y, -1); |
2097 | |
2310 | |
2098 | x = ev->x + (ActiveMenu->parent |
2311 | x = ev->x + (ActiveMenu->parent |
2099 | ? ActiveMenu->x |
2312 | ? ActiveMenu->x |
2100 | : Width2Pixel(ActiveMenu->x)); |
2313 | : Width2Pixel(ActiveMenu->x)); |
2101 | |
2314 | |
2102 | if (x >= item->entry.submenu.menu->x) { |
2315 | if (x >= item->entry.submenu.menu->x) |
|
|
2316 | { |
2103 | R->h->ActiveMenu = item->entry.submenu.menu; |
2317 | ActiveMenu = item->entry.submenu.menu; |
2104 | rxvt_menu_show(aR); |
2318 | menu_show (); |
2105 | return 1; |
2319 | return 1; |
|
|
2320 | } |
|
|
2321 | } |
2106 | } |
2322 | } |
2107 | } |
|
|
2108 | } |
|
|
2109 | return 0; |
2323 | return 0; |
2110 | } |
2324 | } |
2111 | |
2325 | |
2112 | /* INTPROTO */ |
|
|
2113 | void |
2326 | void |
2114 | rxvt_menubar_select(pR_ XButtonEvent *ev) |
2327 | rxvt_term::menubar_select (XButtonEvent *ev) |
2115 | { |
2328 | { |
2116 | menu_t *menu = NULL; |
2329 | menu_t *menu = NULL; |
2117 | |
2330 | |
2118 | /* determine the pulldown menu corresponding to the X index */ |
2331 | /* determine the pulldown menu corresponding to the X index */ |
2119 | if (ev->y >= 0 && ev->y <= menuBar_height() && R->h->CurrentBar != NULL) { |
2332 | if (ev->y >= 0 && ev->y <= menuBar_height() && CurrentBar != NULL) |
|
|
2333 | { |
2120 | for (menu = R->h->CurrentBar->head; menu != NULL; menu = menu->next) { |
2334 | for (menu = CurrentBar->head; menu != NULL; menu = menu->next) |
|
|
2335 | { |
2121 | int x = Width2Pixel(menu->x); |
2336 | int x = Width2Pixel(menu->x); |
2122 | int w = Width2Pixel(menu->len + HSPACE); |
2337 | int w = Width2Pixel(menu->len + HSPACE); |
2123 | |
2338 | |
2124 | if ((ev->x >= x && ev->x < x + w)) |
2339 | if ((ev->x >= x && ev->x < x + w)) |
2125 | break; |
2340 | break; |
2126 | } |
2341 | } |
2127 | } |
2342 | } |
2128 | switch (ev->type) { |
2343 | switch (ev->type) |
|
|
2344 | { |
2129 | case ButtonRelease: |
2345 | case ButtonRelease: |
2130 | rxvt_menu_hide_all(aR); |
2346 | menu_hide_all (); |
2131 | break; |
2347 | break; |
2132 | |
2348 | |
2133 | case ButtonPress: |
2349 | case ButtonPress: |
2134 | if (menu == NULL && R->h->Arrows_x && ev->x >= R->h->Arrows_x) { |
2350 | if (menu == NULL && Arrows_x && ev->x >= Arrows_x) |
|
|
2351 | { |
2135 | int i; |
2352 | int i; |
2136 | |
2353 | |
2137 | for (i = 0; i < NARROWS; i++) { |
2354 | for (i = 0; i < NARROWS; i++) |
|
|
2355 | { |
2138 | if (ev->x >= (R->h->Arrows_x + (Width2Pixel(4 * i + i)) / 4) |
2356 | if (ev->x >= (Arrows_x + (Width2Pixel(4 * i + i)) / 4) |
2139 | && ev->x < (R->h->Arrows_x |
2357 | && ev->x < (Arrows_x |
2140 | + (Width2Pixel(4 * i + i + 4)) / 4)) { |
2358 | + (Width2Pixel(4 * i + i + 4)) / 4)) |
2141 | rxvt_draw_Arrows(aR_ Arrows[i].name, -1); |
2359 | { |
2142 | { |
2360 | draw_Arrows (Arrows[i].name, -1); |
|
|
2361 | { |
2143 | #ifdef HAVE_NANOSLEEP |
2362 | #ifdef HAVE_NANOSLEEP |
2144 | struct timespec rqt; |
2363 | struct timespec rqt; |
2145 | |
2364 | |
2146 | rqt.tv_sec = 0; |
2365 | rqt.tv_sec = 0; |
2147 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2366 | rqt.tv_nsec = MENU_DELAY_USEC * 1000; |
2148 | nanosleep(&rqt, NULL); |
2367 | nanosleep(&rqt, NULL); |
2149 | #else |
2368 | #else |
2150 | /* use select for timing */ |
2369 | /* use select for timing */ |
2151 | struct timeval tv; |
2370 | struct timeval tv; |
2152 | |
2371 | |
2153 | tv.tv_sec = 0; |
2372 | tv.tv_sec = 0; |
2154 | tv.tv_usec = MENU_DELAY_USEC; |
2373 | tv.tv_usec = MENU_DELAY_USEC; |
2155 | select(0, NULL, NULL, NULL, &tv); |
2374 | select(0, NULL, NULL, NULL, &tv); |
2156 | #endif |
2375 | #endif |
2157 | } |
2376 | |
2158 | rxvt_draw_Arrows(aR_ Arrows[i].name, +1); |
2377 | } |
|
|
2378 | draw_Arrows (Arrows[i].name, +1); |
2159 | #ifdef DEBUG_MENUARROWS |
2379 | #ifdef DEBUG_MENUARROWS |
2160 | fprintf(stderr, "'%c': ", Arrows[i].name); |
2380 | fprintf(stderr, "'%c': ", Arrows[i].name); |
2161 | |
2381 | |
2162 | if (R->h->CurrentBar == NULL |
2382 | if (CurrentBar == NULL |
2163 | || (R->h->CurrentBar->arrows[i].type != MenuAction |
2383 | || (CurrentBar->arrows[i].type != MenuAction |
2164 | && R->h->CurrentBar->arrows[i].type != |
2384 | && CurrentBar->arrows[i].type != |
2165 | MenuTerminalAction)) { |
2385 | MenuTerminalAction)) |
|
|
2386 | { |
2166 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2387 | if (Arrows[i].str != NULL && Arrows[i].str[0]) |
2167 | fprintf(stderr, "(default) \\033%s\n", |
2388 | fprintf(stderr, "(default) \\033%s\n", |
2168 | &(Arrows[i].str[2])); |
2389 | &(Arrows[i].str[2])); |
2169 | } else { |
2390 | } |
2170 | fprintf(stderr, "%s\n", |
2391 | else |
2171 | R->h->CurrentBar->arrows[i].str); |
2392 | { |
2172 | } |
2393 | fprintf(stderr, "%s\n", |
|
|
2394 | CurrentBar->arrows[i].str); |
|
|
2395 | } |
2173 | #else /* DEBUG_MENUARROWS */ |
2396 | #else /* DEBUG_MENUARROWS */ |
2174 | if (R->h->CurrentBar == NULL |
2397 | if (CurrentBar == NULL |
2175 | || rxvt_action_dispatch(r, |
2398 | || rxvt_action_dispatch(r, |
2176 | &(R->h->CurrentBar->arrows[i])) |
2399 | &(CurrentBar->arrows[i])) |
2177 | ) { |
2400 | ) |
|
|
2401 | { |
2178 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2402 | if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) |
2179 | rxvt_tt_write(aR_ (Arrows[i].str + 1), |
2403 | tt_write ((Arrows[i].str + 1), |
2180 | Arrows[i].str[0]); |
2404 | Arrows[i].str[0]); |
2181 | } |
2405 | } |
2182 | #endif /* DEBUG_MENUARROWS */ |
2406 | #endif /* DEBUG_MENUARROWS */ |
2183 | return; |
2407 | return; |
2184 | } |
2408 | } |
2185 | } |
2409 | } |
2186 | } |
2410 | } |
2187 | /* FALLTHROUGH */ |
2411 | /* FALLTHROUGH */ |
2188 | |
2412 | |
2189 | default: |
2413 | default: |
2190 | /* |
2414 | /* |
2191 | * press menubar or move to a new entry |
2415 | * press menubar or move to a new entry |
2192 | */ |
2416 | */ |
2193 | if (menu != NULL && menu != R->h->ActiveMenu) { |
2417 | if (menu != NULL && menu != ActiveMenu) |
|
|
2418 | { |
2194 | rxvt_menu_hide_all(aR); /* pop down old menu */ |
2419 | menu_hide_all (); /* pop down old menu */ |
2195 | R->h->ActiveMenu = menu; |
2420 | ActiveMenu = menu; |
2196 | rxvt_menu_show(aR); /* pop up new menu */ |
2421 | menu_show (); /* pop up new menu */ |
2197 | } |
2422 | } |
2198 | break; |
2423 | break; |
2199 | } |
2424 | } |
2200 | } |
2425 | } |
2201 | |
2426 | |
2202 | /* |
2427 | /* |
2203 | * general dispatch routine, |
2428 | * general dispatch routine, |
2204 | * it would be nice to have `sticky' menus |
2429 | * it would be nice to have `sticky' menus |
2205 | */ |
2430 | */ |
2206 | /* EXTPROTO */ |
|
|
2207 | void |
2431 | void |
2208 | rxvt_menubar_control(pR_ XButtonEvent *ev) |
2432 | rxvt_term::menubar_control (XButtonEvent *ev) |
2209 | { |
2433 | { |
2210 | switch (ev->type) { |
2434 | switch (ev->type) |
|
|
2435 | { |
2211 | case ButtonPress: |
2436 | case ButtonPress: |
2212 | if (ev->button == Button1) |
2437 | if (ev->button == Button1) |
2213 | rxvt_menubar_select(aR_ ev); |
2438 | menubar_select (ev); |
2214 | break; |
2439 | break; |
2215 | |
2440 | |
2216 | case ButtonRelease: |
2441 | case ButtonRelease: |
2217 | if (ev->button == Button1) |
2442 | if (ev->button == Button1) |
2218 | rxvt_menu_select(aR_ ev); |
2443 | menu_select (ev); |
2219 | break; |
2444 | break; |
2220 | |
2445 | |
2221 | case MotionNotify: |
2446 | case MotionNotify: |
2222 | while (XCheckTypedWindowEvent(R->Xdisplay, R->TermWin.parent[0], |
2447 | while (XCheckTypedWindowEvent(Xdisplay, TermWin.parent[0], |
2223 | MotionNotify, (XEvent *) ev)) ; |
2448 | MotionNotify, (XEvent *) ev)) ; |
2224 | |
2449 | |
2225 | if (R->h->ActiveMenu) |
2450 | if (ActiveMenu) |
2226 | while (rxvt_menu_select(aR_ ev)) ; |
2451 | while (menu_select (ev)) ; |
2227 | else |
2452 | else |
2228 | ev->y = -1; |
2453 | ev->y = -1; |
2229 | if (ev->y < 0) { |
2454 | if (ev->y < 0) |
|
|
2455 | { |
2230 | Window unused_root, unused_child; |
2456 | Window unused_root, unused_child; |
2231 | int unused_root_x, unused_root_y; |
2457 | int unused_root_x, unused_root_y; |
2232 | unsigned int unused_mask; |
2458 | unsigned int unused_mask; |
2233 | |
2459 | |
2234 | XQueryPointer(R->Xdisplay, R->menuBar.win, |
2460 | XQueryPointer(Xdisplay, menuBar.win, |
2235 | &unused_root, &unused_child, |
2461 | &unused_root, &unused_child, |
2236 | &unused_root_x, &unused_root_y, |
2462 | &unused_root_x, &unused_root_y, |
2237 | &(ev->x), &(ev->y), &unused_mask); |
2463 | &(ev->x), &(ev->y), &unused_mask); |
2238 | rxvt_menubar_select(aR_ ev); |
2464 | menubar_select (ev); |
2239 | } |
2465 | } |
2240 | break; |
2466 | break; |
2241 | } |
2467 | } |
2242 | } |
2468 | } |
2243 | |
2469 | |
2244 | /* EXTPROTO */ |
|
|
2245 | void |
2470 | void |
2246 | rxvt_map_menuBar(pR_ int map) |
2471 | rxvt_term::map_menuBar (int map) |
2247 | { |
2472 | { |
2248 | if (rxvt_menubar_mapping(aR_ map)) |
2473 | if (menubar_mapping (map)) |
2249 | rxvt_resize_all_windows(aR_ 0, 0, 0); |
2474 | resize_all_windows (0, 0, 0); |
2250 | } |
2475 | } |
2251 | #endif |
2476 | #endif |
2252 | /*----------------------- end-of-file (C source) -----------------------*/ |
2477 | /*----------------------- end-of-file (C source) -----------------------*/ |