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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines