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.1 by pcg, Mon Nov 24 17:28:08 2003 UTC vs.
Revision 1.23 by root, Mon Feb 7 01:17:03 2005 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines