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