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.3 by pcg, Tue Nov 25 11:52:42 2003 UTC vs.
Revision 1.9 by pcg, Tue Feb 24 00:02:44 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines