--- rxvt-unicode/src/menubar.C 2004/02/13 12:16:21 1.8 +++ rxvt-unicode/src/menubar.C 2006/01/04 04:42:45 1.30 @@ -1,8 +1,9 @@ /*--------------------------------*-C-*---------------------------------* - * File: menubar.c + * File: menubar.C *----------------------------------------------------------------------* * * Copyright (c) 1997,1998 mj olesen + * Copyright (c) 2004 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,19 +24,21 @@ *----------------------------------------------------------------------*/ #include "../config.h" /* NECESSARY */ + +#include + #include "rxvt.h" /* NECESSARY */ #ifdef MENUBAR #include "version.h" #include "menubar.h" -#include "menubar.intpro" /* PROTOS for internal routines */ #define Menu_PixelWidth(menu) \ - (2 * SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) + (2 * MENU_SHADOW + Width2Pixel ((menu)->width + 3 * HSPACE)) static const struct { - const char name; /* (l)eft, (u)p, (d)own, (r)ight */ - const unsigned char str[5]; /* str[0] = STRLEN (str+1) */ + const char name; /* (l)eft, (u)p, (d)own, (r)ight */ + const char str[5]; /* str[0] = strlen (str+1) */ } Arrows[NARROWS] = { { 'l', "\003\033[D" }, @@ -46,6 +49,30 @@ /*}}} */ +static void +draw_string (rxvt_drawable &d, GC gc, rxvt_fontset *fs, int x, int y, char *str, int len) +{ + mbstate mbs; + + while (len) + { + wchar_t w; + int l = mbrtowc (&w, str, len, mbs); + + if (l <= 0) + break; + + len -= l; + str += l; + + rxvt_font *font = (*fs)[fs->find_font (w)]; + text_t ch = w; + font->draw (d, x, y, &ch, 1, Color_bg, Color_scroll); + + x += font->width * wcwidth (w); + } +} + /* * find an item called NAME in MENU */ @@ -64,11 +91,11 @@ { if (item->entry.type == MenuSubMenu) { - if (!STRCMP (name, (item->entry.submenu.menu)->name)) + if (!strcmp (name, (item->entry.submenu.menu)->name)) break; } else if ((isSeparator (name) && isSeparator (item->name)) - || !STRCMP (name, item->name)) + || !strcmp (name, item->name)) break; } return item; @@ -122,12 +149,12 @@ * remove the first character of STR if it's '\0' */ int -rxvt_action_type (action_t *action, unsigned char *str) +rxvt_action_type (action_t *action, char *str) { unsigned int len; #if defined (DEBUG_MENU) || defined (DEBUG_MENUARROWS) - len = STRLEN (str); + len = strlen (str); fprintf (stderr, " (len %d) = %s\n", len, str); #else len = rxvt_Str_escaped ((char *)str); @@ -141,9 +168,9 @@ if (str[0] == '\0') { /* the functional equivalent: memmove (str, str+1, len); */ - unsigned char *dst = (str); - unsigned char *src = (str + 1); - unsigned char *end = (str + len); + char *dst = (str); + char *src = (str + 1); + char *end = (str + len); while (src <= end) *dst++ = *src++; @@ -152,6 +179,7 @@ if (str[0] != '\0') action->type = MenuTerminalAction; } + action->str = str; action->len = len; @@ -238,7 +266,7 @@ *cur, parse[NARROWS]; - MEMSET (parse, 0, sizeof (parse)); + memset (parse, 0, sizeof (parse)); /* fprintf (stderr, "add arrows = `%s'\n", string); */ for (p = string; p != NULL && *p; string = p) @@ -269,7 +297,7 @@ if (cur == &end) { - p = STRCHR (string, '\0'); + p = strchr (string, '\0'); } else { @@ -277,7 +305,7 @@ while (1) { - p = STRCHR (next, '<'); + p = strchr (next, '<'); if (p != NULL) { if (p[1] && p[2] == '>') @@ -287,7 +315,7 @@ else { if (beg.str == NULL) /* no end needed */ - p = STRCHR (next, '\0'); + p = strchr (next, '\0'); break; } next = (p + 1); @@ -324,26 +352,26 @@ for (i = 0; i < NARROWS; i++) { - unsigned char *str; - unsigned int len; + char *str; + unsigned int len; if (!parse[i].len) continue; - str = rxvt_malloc (parse[i].len + xtra_len + 1); + str = (char *)rxvt_malloc (parse[i].len + xtra_len + 1); len = 0; if (beg.len) { - STRNCPY (str + len, beg.str, beg.len); + strncpy (str + len, beg.str, beg.len); len += beg.len; } - STRNCPY (str + len, parse[i].str, parse[i].len); + strncpy (str + len, parse[i].str, parse[i].len); len += parse[i].len; if (end.len) { - STRNCPY (str + len, end.str, end.len); + strncpy (str + len, end.str, end.len); len += end.len; } str[len] = '\0'; @@ -407,9 +435,9 @@ item->len2 = 0; item->name2 = NULL; - len = STRLEN (name); - item->name = rxvt_malloc (len + 1); - STRCPY (item->name, name); + len = strlen (name); + item->name = (char *)rxvt_malloc (len + 1); + strcpy (item->name, name); if (name[0] == '.' && name[1] != '.') len = 0; /* hidden menu name */ item->len = len; @@ -431,18 +459,18 @@ Item_Found: if (name2 != NULL && item->name2 == NULL) { - len = STRLEN (name2); + len = strlen (name2); if (len == 0) item->name2 = NULL; else { - item->name2 = rxvt_malloc (len + 1); - STRCPY (item->name2, name2); + item->name2 = (char *)rxvt_malloc (len + 1); + strcpy (item->name2, name2); } item->len2 = len; } item->entry.type = MenuLabel; - len = STRLEN (action); + len = strlen (action); if (len == 0 && item->name2 != NULL) { @@ -451,9 +479,9 @@ } if (len) { - unsigned char *str = rxvt_malloc (len + 1); + char *str = (char *)rxvt_malloc (len + 1); - STRCPY (str, action); + strcpy (str, action); if (rxvt_action_type (& (item->entry.action), str) < 0) free (str); @@ -483,31 +511,34 @@ if (path[0] == '\0') return path; - if (STRCHR (path, '/') != NULL) + if (strchr (path, '/') != NULL) { char *p = path; - while ((p = STRCHR (p, '/')) != NULL) + while ((p = strchr (p, '/')) != NULL) { p++; if (*p == '/') path = p; } + if (path[0] == '/') { path++; *menu = NULL; } - while ((p = STRCHR (path, '/')) != NULL) + + while ((p = strchr (path, '/')) != NULL) { p[0] = '\0'; if (path[0] == '\0') return NULL; - if (!STRCMP (path, DOT)) + + if (!strcmp (path, DOT)) { /* nothing to do */ } - else if (!STRCMP (path, DOTS)) + else if (!strcmp (path, DOTS)) { if (*menu != NULL) *menu = (*menu)->parent; @@ -525,21 +556,21 @@ path = (p + 1); } } - if (!STRCMP (path, DOTS)) + + if (!strcmp (path, DOTS)) { - path += STRLEN (DOTS); + path += strlen (DOTS); if (*menu != NULL) *menu = (*menu)->parent; return path; } + /* find this menu */ if (*menu == NULL) { for (m = CurrentBar->tail; m != NULL; m = m->prev) - { - if (!STRCMP (path, m->name)) - break; - } + if (!strcmp (path, m->name)) + break; } else { @@ -547,18 +578,20 @@ for (item = (*menu)->tail; item != NULL; item = item->prev) { if (item->entry.type == MenuSubMenu - && !STRCMP (path, (item->entry.submenu.menu)->name)) + && !strcmp (path, (item->entry.submenu.menu)->name)) { m = (item->entry.submenu.menu); break; } } } + if (m != NULL) { *menu = m; - path += STRLEN (path); + path += strlen (path); } + return path; } @@ -570,7 +603,6 @@ { menu_t *parent = NULL, *prev, *next; menuitem_t *item; - bar_t *CurrentBar = CurrentBar; #ifdef DEBUG_STRICT assert (CurrentBar != NULL); @@ -620,14 +652,13 @@ item = menu->tail; while (item != NULL) { - menuitem_t *p = item->prev; + menuitem_t *p = item->prev; menuitem_free (menu, item); item = p; } - if (menu->name != NULL) - free (menu->name); + free (menu->name); free (menu); return parent; @@ -636,16 +667,15 @@ menu_t * rxvt_term::menu_add (menu_t *parent, char *path) { - menu_t *menu; - bar_t *CurrentBar = CurrentBar; + menu_t *menu; #ifdef DEBUG_STRICT assert (CurrentBar != NULL); #endif - if (STRCHR (path, '/') != NULL) + if (strchr (path, '/') != NULL) { - char *p; + char *p; if (path[0] == '/') { @@ -653,7 +683,7 @@ path++; parent = NULL; } - while ((p = STRCHR (path, '/')) != NULL) + while ((p = strchr (path, '/')) != NULL) { p[0] = '\0'; if (path[0] == '\0') @@ -663,10 +693,10 @@ path = (p + 1); } } - if (!STRCMP (path, DOTS)) + if (!strcmp (path, DOTS)) return (parent != NULL ? parent->parent : parent); - if (!STRCMP (path, DOT) || path[0] == '\0') + if (!strcmp (path, DOT) || path[0] == '\0') return parent; /* allocate a new menu */ @@ -674,15 +704,16 @@ menu->width = 0; menu->parent = parent; - menu->len = STRLEN (path); - menu->name = rxvt_malloc ((menu->len + 1)); - STRCPY (menu->name, path); + menu->len = strlen (path); + menu->name = (char *)rxvt_malloc ((menu->len + 1)); + strcpy (menu->name, path); /* initialize head/tail */ menu->head = menu->tail = NULL; menu->prev = menu->next = NULL; menu->win = None; + menu->drawable = 0; menu->x = menu->y = menu->w = menu->h = 0; menu->item = NULL; @@ -725,10 +756,10 @@ x = Width2Pixel (x); len = Width2Pixel (len + HSPACE); - if (x >= TermWin.width) + if (x >= width) return; - else if (x + len >= TermWin.width) - len = (TermWin_TotalWidth () - x); + else if (x + len >= width) + len = (this->width - x); #ifdef MENUBAR_SHADOW_IN state = -state; @@ -776,13 +807,12 @@ break; /* neutral */ } - w = Height2Pixel (1) - 2 * SHADOW; + w = Height2Pixel (1) - 2 * MENU_SHADOW; - x -= SHADOW + (3 * w / 2); - y += SHADOW * 3; + x -= MENU_SHADOW + (3 * w / 2); + y += MENU_SHADOW * 3; - rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, - 'r'); + rxvt_Draw_Triangle (display->display, ActiveMenu->win, top, bot, x, y, w, 'r'); } void @@ -809,9 +839,9 @@ } rxvt_Draw_Shadow (display->display, ActiveMenu->win, top, bot, - SHADOW + 0, SHADOW + y, - ActiveMenu->w - 2 * (SHADOW), - HEIGHT_TEXT + 2 * SHADOW); + MENU_SHADOW + 0, MENU_SHADOW + y, + ActiveMenu->w - 2 * (MENU_SHADOW), + HEIGHT_TEXT + 2 * MENU_SHADOW); XFlush (display->display); } @@ -824,6 +854,7 @@ fprintf (stderr, "Top Level menu\n"); return; } + fprintf (stderr, "menu %s ", menu->name); if (menu->parent != NULL) { @@ -837,12 +868,14 @@ break; } } + if (item == NULL) { fprintf (stderr, "is an orphan!\n"); return; } } + fprintf (stderr, "\n"); rxvt_print_menu_ancestors (menu->parent); } @@ -895,9 +928,8 @@ void rxvt_term::menu_show () { - int x, y, xright; - menu_t *ActiveMenu = ActiveMenu; - menuitem_t *item; + int x, y, xright; + menuitem_t *item; if (ActiveMenu == NULL) return; @@ -913,25 +945,28 @@ ActiveMenu->y = 1; ActiveMenu->w = Menu_PixelWidth (ActiveMenu); - if ((x + ActiveMenu->w) >= TermWin.width) - x = (TermWin_TotalWidth () - ActiveMenu->w); + if ((x + ActiveMenu->w) >= width) + x = (this->width - ActiveMenu->w); /* find the height */ for (h = 0, item = ActiveMenu->head; item != NULL; item = item->next) h += isSeparator (item->name) ? HEIGHT_SEPARATOR - : HEIGHT_TEXT + 2 * SHADOW; - ActiveMenu->h = h + 2 * SHADOW; + : HEIGHT_TEXT + 2 * MENU_SHADOW; + ActiveMenu->h = h + 2 * MENU_SHADOW; } + if (ActiveMenu->win == None) { - ActiveMenu->win = XCreateSimpleWindow (display->display, TermWin.vt, - x, ActiveMenu->y, - ActiveMenu->w, ActiveMenu->h, - 0, - PixColors[Color_fg], - PixColors[Color_scroll]); + ActiveMenu->win = XCreateSimpleWindow (display->display, vt, + x, ActiveMenu->y, + ActiveMenu->w, ActiveMenu->h, + 0, + pix_colors[Color_fg], + pix_colors[Color_scroll]); + ActiveMenu->drawable = new rxvt_drawable (display, ActiveMenu->win); XMapWindow (display->display, ActiveMenu->win); } + rxvt_Draw_Shadow (display->display, ActiveMenu->win, topShadowGC, botShadowGC, 0, 0, ActiveMenu->w, ActiveMenu->h); @@ -943,16 +978,16 @@ for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) { - const int xoff = (SHADOW + Width2Pixel (HSPACE) / 2); - register int h; - GC gc = menubarGC; + const int xoff = (MENU_SHADOW + Width2Pixel (HSPACE) / 2); + register int h; + GC gc = menubarGC; if (isSeparator (item->name)) { rxvt_Draw_Shadow (display->display, ActiveMenu->win, - topShadowGC, botShadowGC, - SHADOW, y + SHADOW + 1, - ActiveMenu->w - 2 * SHADOW, 0); + topShadowGC, botShadowGC, + MENU_SHADOW, y + MENU_SHADOW + 1, + ActiveMenu->w - 2 * MENU_SHADOW, 0); h = HEIGHT_SEPARATOR; } else @@ -961,9 +996,7 @@ int len = item->len; if (item->entry.type == MenuLabel) - { - gc = botShadowGC; - } + gc = botShadowGC; else if (item->entry.type == MenuSubMenu) { int x1, y1; @@ -988,70 +1021,46 @@ /* find the height of this submenu */ for (h = 0, it = menu->head; it != NULL; it = it->next) h += isSeparator (it->name) ? HEIGHT_SEPARATOR - : HEIGHT_TEXT + 2 * SHADOW; - menu->h = h + 2 * SHADOW; + : HEIGHT_TEXT + 2 * MENU_SHADOW; + menu->h = h + 2 * MENU_SHADOW; /* ensure menu is in window limits */ - if ((x1 + menu->w) >= TermWin.width) - x1 = (TermWin_TotalWidth () - menu->w); + if ((x1 + menu->w) >= width) + x1 = (this->width - menu->w); - if ((y1 + menu->h) >= TermWin.height) - y1 = (TermWin_TotalHeight () - menu->h); + if ((y1 + menu->h) >= height) + y1 = (this->height - menu->h); menu->x = (x1 < 0 ? 0 : x1); menu->y = (y1 < 0 ? 0 : y1); } - else if (item->name2 && !STRCMP (name, item->name2)) + else if (item->name2 && !strcmp (name, item->name2)) name = NULL; if (len && name) - { -#ifdef USE_XIM - if (TermWin.fontset) - XmbDrawString (display->display, - ActiveMenu->win, TermWin.fontset, - gc, xoff, - 2 * SHADOW + y + TermWin.font->ascent + 1, - name, len); - else -#endif - XDrawString (display->display, ActiveMenu->win, gc, xoff, - 2 * SHADOW + y + TermWin.font->ascent + 1, - name, len); - } + draw_string (*ActiveMenu->drawable, gc, fontset[0], + xoff, 2 * MENU_SHADOW + y, name, len); len = item->len2; name = item->name2; + if (len && name) - { -#ifdef USE_XIM - if (TermWin.fontset) - XmbDrawString (display->display, - ActiveMenu->win, TermWin.fontset, - gc, - ActiveMenu->w - (xoff + Width2Pixel (xright)), - 2 * SHADOW + y + TermWin.font->ascent + 1, - name, len); - else -#endif - XDrawString (display->display, ActiveMenu->win, gc, - ActiveMenu->w - (xoff + Width2Pixel (xright)), - 2 * SHADOW + y + TermWin.font->ascent + 1, - name, len); - } - h = HEIGHT_TEXT + 2 * SHADOW; + draw_string (*ActiveMenu->drawable, gc, fontset[0], + ActiveMenu->w - (xoff + Width2Pixel (xright)), 2 * MENU_SHADOW + y, name, len); + + h = HEIGHT_TEXT + 2 * MENU_SHADOW; } y += h; } } void -rxvt_term::menu_display (void (*update) (rxvt_t *)) +rxvt_term::menu_display (void (rxvt_term::*update) ()) { - menu_t *ActiveMenu = ActiveMenu; - if (ActiveMenu == NULL) return; + + delete ActiveMenu->drawable; if (ActiveMenu->win != None) XDestroyWindow (display->display, ActiveMenu->win); ActiveMenu->win = None; @@ -1059,20 +1068,21 @@ if (ActiveMenu->parent == NULL) drawbox_menubar (ActiveMenu->x, ActiveMenu->len, +1); + ActiveMenu = ActiveMenu->parent; - update (r); + (this->*update) (); } void rxvt_term::menu_hide_all () { - menu_display (rxvt_menu_hide_all); + menu_display (&rxvt_term::menu_hide_all); } void rxvt_term::menu_hide () { - menu_display (rxvt_menu_show); + menu_display (&rxvt_term::menu_show); } void @@ -1080,7 +1090,7 @@ { if (menu != NULL) { - menuitem_t *item = menu->tail; + menuitem_t *item = menu->tail; while (item != NULL) { @@ -1097,15 +1107,13 @@ void rxvt_term::menubar_clear () { - bar_t *CurrentBar = CurrentBar; - if (CurrentBar != NULL) { - menu_t *menu = CurrentBar->tail; + menu_t *menu = CurrentBar->tail; while (menu != NULL) { - menu_t *prev = menu->prev; + menu_t *prev = menu->prev; menu_delete (menu); menu = prev; @@ -1117,8 +1125,10 @@ free (CurrentBar->title); CurrentBar->title = NULL; } + menuarrow_free (0); /* remove all arrow functions */ } + ActiveMenu = NULL; } @@ -1127,7 +1137,7 @@ bar_t * rxvt_term::menubar_find (const char *name) { - bar_t *bar = CurrentBar; + bar_t *bar = CurrentBar; #ifdef DEBUG_MENUBAR_STACKING fprintf (stderr, "looking for [menu:%s] ...", name ? name : " (nil)"); @@ -1135,11 +1145,11 @@ if (bar == NULL || name == NULL) return NULL; - if (STRLEN (name) && STRCMP (name, "*")) + if (strlen (name) && strcmp (name, "*")) { do { - if (!STRCMP (bar->name, name)) + if (!strcmp (bar->name, name)) { #ifdef DEBUG_MENUBAR_STACKING fprintf (stderr, " found!\n"); @@ -1161,15 +1171,15 @@ int rxvt_term::menubar_push (const char *name) { - int ret = 1; - bar_t *bar; + int ret = 1; + bar_t *bar; if (CurrentBar == NULL) { /* allocate first one */ bar = (bar_t *) rxvt_malloc (sizeof (bar_t)); - MEMSET (bar, 0, sizeof (bar_t)); + memset (bar, 0, sizeof (bar_t)); /* circular linked-list */ bar->next = bar->prev = bar; bar->head = bar->tail = NULL; @@ -1220,12 +1230,13 @@ CurrentBar = bar; } + menubar_clear (); } } /* give menubar this name */ - STRNCPY (CurrentBar->name, name, MAXNAME); + strncpy (CurrentBar->name, name, MAXNAME); CurrentBar->name[MAXNAME - 1] = '\0'; return ret; @@ -1268,14 +1279,14 @@ CurrentBar = prev; } } - while (CurrentBar && !STRCMP (name, "*")); + while (CurrentBar && !strcmp (name, "*")); } void rxvt_action_decode (FILE *fp, action_t *act) { - unsigned char *str; - short len; + char *str; + short len; if (act == NULL || (len = act->len) == 0 || (str = act->str) == NULL) return; @@ -1308,6 +1319,7 @@ break; } } + /* * control character form is preferred, since backslash-escaping * can be really ugly looking when the backslashes themselves also @@ -1316,7 +1328,7 @@ */ while (len > 0) { - unsigned char ch = *str++; + char ch = *str++; switch (ch) { @@ -1337,14 +1349,16 @@ default: if (ch <= 31) fprintf (fp, "^%c", ('@' + ch)); - else if (ch > 127) + else if ((unsigned char)ch > 127) fprintf (fp, "\\%o", ch); else fprintf (fp, "%c", ch); break; } + len--; } + fprintf (fp, "\n"); } @@ -1368,13 +1382,13 @@ break; case MenuLabel: - fprintf (fp, "{%s}\n", (STRLEN (item->name) ? item->name : "-")); + fprintf (fp, "{%s}\n", (strlen (item->name) ? item->name : "-")); break; case MenuTerminalAction: case MenuAction: fprintf (fp, "{%s}", item->name); - if (item->name2 != NULL && STRLEN (item->name2)) + if (item->name2 != NULL && strlen (item->name2)) fprintf (fp, "{%s}", item->name2); fprintf (fp, "\t"); rxvt_action_decode (fp, & (item->entry.action)); @@ -1396,7 +1410,7 @@ time (&t); fprintf (fp, - "# " APL_SUBCLASS " (%s) Pid: %u\n# Date: %s\n\n", + "# " RESCLASS " (%s) Pid: %u\n# Date: %s\n\n", rs[Rs_name], (unsigned int)getpid (), ctime (&t)); /* dump in reverse order */ @@ -1460,6 +1474,7 @@ file = (char *)rxvt_File_find (filename, ".menu", rs[Rs_path]); if (file == NULL) return; + fp = fopen (file, "rb"); free (file); if (fp == NULL) @@ -1467,7 +1482,7 @@ #if (MENUBAR_MAX > 1) /* semi-colon delimited */ - if ((tag = STRCHR (filename, ';')) != NULL) + if ((tag = strchr (filename, ';')) != NULL) { tag++; if (*tag == '\0') @@ -1551,9 +1566,9 @@ } } } + /* * remove leading/trailing space - * and strip-off leading/trailing quotes * skip blank or comment lines */ rxvt_Str_trim (p); @@ -1575,10 +1590,10 @@ void rxvt_term::menubar_dispatch (char *str) { - int n, cmd; - char *path, *name, *name2; + int n, cmd; + char *path, *name, *name2; - if (menubar_visible (r) && ActiveMenu != NULL) + if (menubar_visible () && ActiveMenu != NULL) menubar_expose (); else ActiveMenu = NULL; @@ -1617,7 +1632,7 @@ do { next++; - if ((next = STRCHR (next, ':')) == NULL) + if ((next = strchr (next, ':')) == NULL) return; /* parse error */ } while (next[1] != ']'); @@ -1627,7 +1642,7 @@ } else { - if ((next = STRCHR (next, ']')) == NULL) + if ((next = strchr (next, ']')) == NULL) return; /* parse error */ /* remove and skip ']' */ *next = '\0'; @@ -1645,20 +1660,20 @@ menu_readonly = saved; } /* these ones don't require menu stacking */ - else if (!STRCMP (str, "clear")) + else if (!strcmp (str, "clear")) { menubar_clear (); } - else if (!STRCMP (str, "done") || rxvt_Str_match (str, "done:")) + else if (!strcmp (str, "done") || rxvt_Str_match (str, "done:")) { menu_readonly = 1; } - else if (!STRCMP (str, "show")) + else if (!strcmp (str, "show")) { map_menuBar (1); menu_readonly = 1; } - else if (!STRCMP (str, "hide")) + else if (!strcmp (str, "hide")) { map_menuBar (0); menu_readonly = 1; @@ -1676,11 +1691,10 @@ { if (*str) { - name = rxvt_realloc (CurrentBar->title, - STRLEN (str) + 1); + name = (char *)rxvt_realloc (CurrentBar->title, strlen (str) + 1); if (name != NULL) { - STRCPY (name, str); + strcpy (name, str); CurrentBar->title = name; } menubar_expose (); @@ -1695,7 +1709,7 @@ else if ((n = rxvt_Str_match (str, "pixmap:")) != 0) { str += n; - xterm_seq (XTerm_Pixmap, str, CHAR_ST); + process_xterm_seq (XTerm_Pixmap, str, CHAR_ST); } #if (MENUBAR_MAX > 1) else if ((n = rxvt_Str_match (str, "rm")) != 0) @@ -1735,7 +1749,7 @@ if (CurrentBar != NULL) menu_readonly = 0; /* allow menu build commands */ } - else if (!STRCMP (str, "dump")) + else if (!strcmp (str, "dump")) { /* dump current menubars to a file */ FILE *fp; @@ -1743,17 +1757,17 @@ /* enough space to hold the results */ char buffer[32]; - sprintf (buffer, "/tmp/" APL_SUBCLASS "-%u", + sprintf (buffer, "/tmp/" RESCLASS "-%u", (unsigned int)getpid ()); if ((fp = fopen (buffer, "wb")) != NULL) { - xterm_seq (XTerm_title, buffer, CHAR_ST); + process_xterm_seq (XTerm_title, buffer, CHAR_ST); menubar_dump (fp); fclose (fp); } } - else if (!STRCMP (str, "next")) + else if (!strcmp (str, "next")) { if (CurrentBar) { @@ -1761,7 +1775,7 @@ menu_readonly = 1; } } - else if (!STRCMP (str, "prev")) + else if (!strcmp (str, "prev")) { if (CurrentBar) { @@ -1769,7 +1783,7 @@ menu_readonly = 1; } } - else if (!STRCMP (str, "swap")) + else if (!strcmp (str, "swap")) { /* swap the top 2 menus */ if (CurrentBar) @@ -1828,24 +1842,24 @@ /* parse STR, allow spaces inside (name) */ if (path[0] != '\0') { - name = STRCHR (path, MENUITEM_BEG); - str = STRCHR (path, MENUITEM_END); + name = strchr (path, MENUITEM_BEG); + str = strchr (path, MENUITEM_END); if (name != NULL || str != NULL) { if (name == NULL || str == NULL || str <= (name + 1) || (name > path && name[-1] != '/')) { - rxvt_print_error ("menu error <%s>\n", path); + rxvt_warn ("menu error A<%s>, continuing.\n", path); break; } if (str[1] == MENUITEM_BEG) { name2 = (str + 2); - str = STRCHR (name2, MENUITEM_END); + str = strchr (name2, MENUITEM_END); if (str == NULL) { - rxvt_print_error ("menu error <%s>\n", path); + rxvt_warn ("menu error B<%s>, continuing.\n", path); break; } name2[-2] = '\0'; /* remove prev MENUITEM_END */ @@ -1877,7 +1891,7 @@ int len; path = menu_find_base (& (BuildMenu), path); - len = STRLEN (path); + len = strlen (path); /* don't allow menus called `*' */ if (path[0] == '*') @@ -1885,7 +1899,7 @@ menu_clear (BuildMenu); break; } - else if (len >= 2 && !STRCMP ((path + len - 2), "/*")) + else if (len >= 2 && !strcmp ((path + len - 2), "/*")) { path[len - 2] = '\0'; } @@ -1894,12 +1908,12 @@ } if (name != NULL && name[0] != '\0') rxvt_menuitem_add (BuildMenu, - (STRCMP (name, SEPARATOR_NAME) ? name : ""), + (strcmp (name, SEPARATOR_NAME) ? name : ""), name2, str); break; case '-': /* delete menu entry */ - if (!STRCMP (path, "/*") && (name == NULL || name[0] == '\0')) + if (!strcmp (path, "/*") && (name == NULL || name[0] == '\0')) { menubar_clear (); BuildMenu = NULL; @@ -1912,7 +1926,7 @@ menu_t *menu = BuildMenu; path = menu_find_base (&menu, path); - len = STRLEN (path); + len = strlen (path); /* submenu called `*' clears all menu items */ if (path[0] == '*') @@ -1920,7 +1934,7 @@ menu_clear (menu); break; /* done */ } - else if (len >= 2 && !STRCMP (&path[len - 2], "/*")) + else if (len >= 2 && !strcmp (&path[len - 2], "/*")) { /* done */ break; @@ -1933,6 +1947,7 @@ else BuildMenu = menu; } + if (BuildMenu != NULL) { if (name == NULL || name[0] == '\0') @@ -1941,9 +1956,8 @@ { const char *n1; menuitem_t *item; - menu_t *BuildMenu = BuildMenu; - n1 = STRCMP (name, SEPARATOR_NAME) ? name : ""; + n1 = strcmp (name, SEPARATOR_NAME) ? name : ""; item = rxvt_menuitem_find (BuildMenu, n1); if (item != NULL && item->entry.type != MenuSubMenu) { @@ -1956,10 +1970,11 @@ { short l = item->len + item->len2; - MAX_IT (BuildMenu->width, l); + max_it (BuildMenu->width, l); } } } + menubar_expose (); } break; @@ -1998,13 +2013,13 @@ for (i = 0; i < NARROWS; i++) { - const int w = Width2Pixel (1); - const int y = (menuBar_TotalHeight () - w) / 2; - int x = Arrows_x + (5 * Width2Pixel (i)) / 4; + const int w = Width2Pixel (1); + const int y = (menuBar_TotalHeight () - w) / 2; + int x = Arrows_x + (5 * Width2Pixel (i)) / 4; if (!name || name == Arrows[i].name) rxvt_Draw_Triangle (display->display, menuBar.win, top, bot, x, y, w, - Arrows[i].name); + Arrows[i].name); } XFlush (display->display); } @@ -2012,10 +2027,10 @@ void rxvt_term::menubar_expose () { - menu_t *menu; - int x; + menu_t *menu; + int x; - if (!menubar_visible (r) || menuBar.win == 0) + if (!menubar_visible () || menuBar.win == 0) return; if (menubarGC == None) @@ -2023,17 +2038,13 @@ /* Create the graphics context */ XGCValues gcvalue; - gcvalue.font = TermWin.font->fid; - - gcvalue.foreground = (XDEPTH <= 2 ? PixColors[Color_fg] - : PixColors[Color_Black]); + gcvalue.foreground = (display->depth <= 2 ? pix_colors[Color_fg] + : pix_colors[Color_Black]); menubarGC = XCreateGC (display->display, menuBar.win, - GCForeground | GCFont, &gcvalue); + GCForeground, &gcvalue); } /* make sure the font is correct */ - XSetFont (display->display, menubarGC, TermWin.font->fid); - XSetFont (display->display, botShadowGC, TermWin.font->fid); XClearWindow (display->display, menuBar.win); menu_hide_all (); @@ -2051,44 +2062,34 @@ rxvt_print_menu_descendants (menu); #endif - if (x >= TermWin.ncol) - len = (TermWin.ncol - (menu->x + HSPACE)); + if (x >= ncol) + len = (ncol - (menu->x + HSPACE)); drawbox_menubar (menu->x, len, +1); -#ifdef USE_XIM - if (TermWin.fontset) - XmbDrawString (display->display, - menuBar.win, TermWin.fontset, - menubarGC, - (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), - menuBar_height () - SHADOW, menu->name, len); - else -#endif - XDrawString (display->display, menuBar.win, menubarGC, - (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), - menuBar_height () - SHADOW, menu->name, len); + draw_string (*menuBar.drawable, menubarGC, fontset[0], + (Width2Pixel (menu->x) + Width2Pixel (HSPACE) / 2), + MENU_SHADOW, menu->name, len); - if (x >= TermWin.ncol) + if (x >= ncol) break; } } - drawbox_menubar (x, TermWin.ncol, (CurrentBar ? +1 : -1)); + drawbox_menubar (x, ncol, (CurrentBar ? +1 : -1)); /* add the menuBar title, if it exists and there's plenty of room */ Arrows_x = 0; - if (x < TermWin.ncol) + if (x < ncol) { const char *str; - int ncol; unsigned int len; char title[256]; - ncol = (int)TermWin.ncol; if (x < (ncol - (NARROWS + 1))) { ncol -= (NARROWS + 1); Arrows_x = Width2Pixel (ncol); } + draw_Arrows (0, +1); str = (CurrentBar @@ -2127,20 +2128,9 @@ ncol -= (x + len + HSPACE); if (len > 0 && ncol >= 0) - { -#ifdef USE_XIM - if (TermWin.fontset) - XmbDrawString (display->display, - menuBar.win, TermWin.fontset, - menubarGC, - Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, - menuBar_height () - SHADOW, title, len); - else -#endif - XDrawString (display->display, menuBar.win, menubarGC, - Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, - menuBar_height () - SHADOW, title, len); - } + draw_string (*menuBar.drawable, menubarGC, fontset[0], + Width2Pixel (x) + Width2Pixel (ncol + HSPACE) / 2, + MENU_SHADOW, title, len); } } @@ -2149,7 +2139,7 @@ { int change = 0; - if (map && !menubar_visible (r)) + if (map && !menubar_visible ()) { menuBar.state = 1; if (menuBar.win == 0) @@ -2157,7 +2147,7 @@ XMapWindow (display->display, menuBar.win); change = 1; } - else if (!map && menubar_visible (r)) + else if (!map && menubar_visible ()) { menubar_expose (); menuBar.state = 0; @@ -2171,61 +2161,63 @@ } int -rxvt_term::menu_select (XButtonEvent *ev) +rxvt_term::menu_select (XButtonEvent &ev) { - menuitem_t *thisitem, *item = NULL; - int this_y, y; - menu_t *ActiveMenu = ActiveMenu; - - Window unused_root, unused_child; - int unused_root_x, unused_root_y; - unsigned int unused_mask; + menuitem_t *thisitem, *item = NULL; + int this_y, y; + + Window unused_root, unused_child; + int unused_root_x, unused_root_y; + unsigned int unused_mask; if (ActiveMenu == NULL) return 0; XQueryPointer (display->display, ActiveMenu->win, - &unused_root, &unused_child, - &unused_root_x, &unused_root_y, - & (ev->x), & (ev->y), &unused_mask); + &unused_root, &unused_child, + &unused_root_x, &unused_root_y, + &ev.x, &ev.y, &unused_mask); - if (ActiveMenu->parent != NULL && (ev->x < 0 || ev->y < 0)) + if (ActiveMenu->parent != NULL && (ev.x < 0 || ev.y < 0)) { menu_hide (); return 1; } + /* determine the menu item corresponding to the Y index */ - y = SHADOW; - if (ev->x >= 0 && ev->x <= (ActiveMenu->w - SHADOW)) + y = MENU_SHADOW; + if (ev.x >= 0 && ev.x <= (ActiveMenu->w - MENU_SHADOW)) { for (item = ActiveMenu->head; item != NULL; item = item->next) { - int h = HEIGHT_TEXT + 2 * SHADOW; + int h = HEIGHT_TEXT + 2 * MENU_SHADOW; if (isSeparator (item->name)) h = HEIGHT_SEPARATOR; - else if (ev->y >= y && ev->y < (y + h)) + else if (ev.y >= y && ev.y < (y + h)) break; + y += h; } } - if (item == NULL && ev->type == ButtonRelease) + + if (item == NULL && ev.type == ButtonRelease) { menu_hide_all (); return 0; } + thisitem = item; - this_y = y - SHADOW; + this_y = y - MENU_SHADOW; /* erase the last item */ if (ActiveMenu->item != NULL) { if (ActiveMenu->item != thisitem) { - for (y = 0, item = ActiveMenu->head; item != NULL; - item = item->next) + for (y = 0, item = ActiveMenu->head; item != NULL; item = item->next) { - int h; + int h; if (isSeparator (item->name)) h = HEIGHT_SEPARATOR; @@ -2235,16 +2227,18 @@ drawbox_menuitem (y, 0); /* No Shadow */ if (item->entry.type == MenuSubMenu) drawtriangle (ActiveMenu->w, y, +1); + break; } else - h = HEIGHT_TEXT + 2 * SHADOW; + h = HEIGHT_TEXT + 2 * MENU_SHADOW; + y += h; } } else { - switch (ev->type) + switch (ev.type) { case ButtonRelease: switch (item->entry.type) @@ -2256,24 +2250,8 @@ case MenuAction: case MenuTerminalAction: - drawbox_menuitem (_y, -1); - { -#ifdef HAVE_NANOSLEEP - struct timespec rqt; - - rqt.tv_sec = 0; - rqt.tv_nsec = MENU_DELAY_USEC * 1000; - nanosleep (&rqt, NULL); -#else - /* use select for timing */ - struct timeval tv; - - tv.tv_sec = 0; - tv.tv_usec = MENU_DELAY_USEC; - select (0, NULL, NULL, NULL, &tv); -#endif - - } + drawbox_menuitem (this_y, -1); + rxvt_usleep (MENU_DELAY_USEC); /* remove menu before sending keys to the application */ menu_hide_all (); #ifndef DEBUG_MENU @@ -2294,21 +2272,24 @@ return 0; } } + DoMenu: ActiveMenu->item = thisitem; y = this_y; - if (item != NULL) + + if (thisitem != NULL) { item = ActiveMenu->item; if (item->entry.type != MenuLabel) drawbox_menuitem (y, +1); + if (item->entry.type == MenuSubMenu) { - int x; + int x; drawtriangle (ActiveMenu->w, y, -1); - x = ev->x + (ActiveMenu->parent + x = ev.x + (ActiveMenu->parent ? ActiveMenu->x : Width2Pixel (ActiveMenu->x)); @@ -2324,57 +2305,41 @@ } void -rxvt_term::menubar_select (XButtonEvent *ev) +rxvt_term::menubar_select (XButtonEvent &ev) { - menu_t *menu = NULL; + menu_t *menu = NULL; /* determine the pulldown menu corresponding to the X index */ - if (ev->y >= 0 && ev->y <= menuBar_height () && CurrentBar != NULL) + if (ev.y >= 0 && ev.y <= menuBar_height () && CurrentBar != NULL) { for (menu = CurrentBar->head; menu != NULL; menu = menu->next) { - int x = Width2Pixel (menu->x); - int w = Width2Pixel (menu->len + HSPACE); + int x = Width2Pixel (menu->x); + int w = Width2Pixel (menu->len + HSPACE); - if ((ev->x >= x && ev->x < x + w)) + if ((ev.x >= x && ev.x < x + w)) break; } } - switch (ev->type) + switch (ev.type) { case ButtonRelease: menu_hide_all (); break; case ButtonPress: - if (menu == NULL && Arrows_x && ev->x >= Arrows_x) + if (menu == NULL && Arrows_x && ev.x >= Arrows_x) { int i; for (i = 0; i < NARROWS; i++) { - if (ev->x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) - && ev->x < (Arrows_x + if (ev.x >= (Arrows_x + (Width2Pixel (4 * i + i)) / 4) + && ev.x < (Arrows_x + (Width2Pixel (4 * i + i + 4)) / 4)) { draw_Arrows (Arrows[i].name, -1); - { -#ifdef HAVE_NANOSLEEP - struct timespec rqt; - - rqt.tv_sec = 0; - rqt.tv_nsec = MENU_DELAY_USEC * 1000; - nanosleep (&rqt, NULL); -#else - /* use select for timing */ - struct timeval tv; - - tv.tv_sec = 0; - tv.tv_usec = MENU_DELAY_USEC; - select (0, NULL, NULL, NULL, &tv); -#endif - - } + rxvt_usleep (MENU_DELAY_USEC); draw_Arrows (Arrows[i].name, +1); #ifdef DEBUG_MENUARROWS fprintf (stderr, "'%c': ", Arrows[i].name); @@ -2394,10 +2359,7 @@ CurrentBar->arrows[i].str); } #else /* DEBUG_MENUARROWS */ - if (CurrentBar == NULL - || rxvt_action_dispatch (r, - & (CurrentBar->arrows[i])) - ) + if (CurrentBar == NULL || action_dispatch (&CurrentBar->arrows[i])) { if (Arrows[i].str != NULL && Arrows[i].str[0] != 0) tt_write ((Arrows[i].str + 1), @@ -2429,29 +2391,29 @@ * it would be nice to have `sticky' menus */ void -rxvt_term::menubar_control (XButtonEvent *ev) +rxvt_term::menubar_control (XButtonEvent &ev) { - switch (ev->type) + switch (ev.type) { case ButtonPress: - if (ev->button == Button1) + if (ev.button == Button1) menubar_select (ev); break; case ButtonRelease: - if (ev->button == Button1) + if (ev.button == Button1) menu_select (ev); break; case MotionNotify: - while (XCheckTypedWindowEvent (display->display, TermWin.parent[0], - MotionNotify, (XEvent *) ev)) ; + while (XCheckTypedWindowEvent (display->display, parent[0], + MotionNotify, (XEvent *)&ev)); if (ActiveMenu) while (menu_select (ev)) ; else - ev->y = -1; - if (ev->y < 0) + ev.y = -1; + if (ev.y < 0) { Window unused_root, unused_child; int unused_root_x, unused_root_y; @@ -2460,7 +2422,7 @@ XQueryPointer (display->display, menuBar.win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, - & (ev->x), & (ev->y), &unused_mask); + &ev.x, &ev.y, &unused_mask); menubar_select (ev); } break;