ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/menubar.C
(Generate patch)

Comparing rxvt-unicode/src/menubar.C (file contents):
Revision 1.4 by pcg, Sat Jan 31 00:20:21 2004 UTC vs.
Revision 1.9 by pcg, Tue Feb 24 00:02:44 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines