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.6 by pcg, Sun Feb 1 01:34:41 2004 UTC vs.
Revision 1.21 by root, Sat Aug 21 05:32:00 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines