diff --git a/collects/mred/private/mrmenu.ss b/collects/mred/private/mrmenu.ss index 27a765f70f..d271f2f05c 100644 --- a/collects/mred/private/mrmenu.ss +++ b/collects/mred/private/mrmenu.ss @@ -70,8 +70,13 @@ (lambda (s) (car (regexp-match #rx"^[^\t]*" s))) (lambda (s) - (regexp-replace* "&" - (regexp-replace* "&(.)" (car (regexp-match #rx"^[^\t]*" s)) "\\1") + (regexp-replace* #rx"&" + (regexp-replace* #rx"&(.)" + (regexp-replace* + #rx" *[(]&.[)] *" + (car (regexp-match #rx"^[^\t]*" s)) + "") + "\\1") "\\&\\&")))) (define basic-labelled-menu-item% diff --git a/collects/string-constants/simplified-chinese-string-constants.ss b/collects/string-constants/simplified-chinese-string-constants.ss index 8f85eec454..9a15e492fd 100644 --- a/collects/string-constants/simplified-chinese-string-constants.ss +++ b/collects/string-constants/simplified-chinese-string-constants.ss @@ -507,10 +507,10 @@ ;;; versions below, once the &s have been stripped. ;;; if they don't, DrScheme's menus will appear ;;; in the wrong order. - (file-menu "文件(F)") - (edit-menu "编辑(E)") - (help-menu "帮助(H)") - (windows-menu "窗口(W)") + (file-menu "文件") + (edit-menu "编辑") + (help-menu "帮助") + (windows-menu "窗口") ;;; menus ;;; - in menu labels, the & indicates a alt-key based shortcut. diff --git a/collects/string-constants/traditional-chinese-string-constants.ss b/collects/string-constants/traditional-chinese-string-constants.ss index 223d20d342..65c5ed0e1c 100644 --- a/collects/string-constants/traditional-chinese-string-constants.ss +++ b/collects/string-constants/traditional-chinese-string-constants.ss @@ -507,10 +507,10 @@ ;;; versions below, once the &s have been stripped. ;;; if they don't, DrScheme's menus will appear ;;; in the wrong order. - (file-menu "文件(F)") - (edit-menu "編輯(E)") - (help-menu "幫助(H)") - (windows-menu "窗口(W)") + (file-menu "文件") + (edit-menu "編輯") + (help-menu "幫助") + (windows-menu "窗口") ;;; menus ;;; - in menu labels, the & indicates a alt-key based shortcut. diff --git a/src/mred/wxs/wxscheme.cxx b/src/mred/wxs/wxscheme.cxx index 7bb3a324af..336e2342ae 100644 --- a/src/mred/wxs/wxscheme.cxx +++ b/src/mred/wxs/wxscheme.cxx @@ -2871,6 +2871,73 @@ int wxGetBoolPreference(const char *name, int *res) return 0; } +/***********************************************************************/ +/* strip menu codes */ +/***********************************************************************/ + +static int starts_paren_accel(char *label, int i) +{ + int cnt = 0; + while (label[i] == ' ') { + i++; + cnt++; + } + if ((label[i] == '(') + && (label[i+1] == '&') + && label[i+2] + && (label[i+3] == ')')) { + cnt += 4; + i += 4; + while (label[i] == ' ') { + i++; + cnt++; + } + return cnt; + } + + return 0; +} + +char *wxStripMenuCodes(char *label, char *target) +{ + int i, j, cnt; + char *naya; + + if (!label) + return NULL; + + for (i = 0; label[i]; i++) { + if ((label[i] == '&') + || (label[i] == '\t')) { + /* Strip it: */ + if (target) + naya = target; + else + naya = new WXGC_ATOMIC char[strlen(label) + 1]; + j = 0; + for (i = 0; label[i]; i++) { + if (label[i] == '&') { + if (label[i + 1]) { + naya[j++] = label[i + 1]; + i++; + } + } else if (label[i] == '\t') { + break; + } else if ((cnt = starts_paren_accel(label, i))) { + i += (cnt - 1); + } else { + naya[j++] = label[i]; + } + } + naya[j] = 0; + + return naya; + } + } + + return label; +} + /***********************************************************************/ /* initialization */ /***********************************************************************/ diff --git a/src/wxmac/src/base/wb_utils.cc b/src/wxmac/src/base/wb_utils.cc index a89dff14cb..638ef3d5c2 100644 --- a/src/wxmac/src/base/wb_utils.cc +++ b/src/wxmac/src/base/wb_utils.cc @@ -212,48 +212,6 @@ wxGetEmailAddress (char *address, int maxSize) return TRUE; } -/* - * Strip out any menu codes - */ - -char *wxStripMenuCodes (char *in, char *out) -{ - char *tmpOut; - - if (!in) - return NULL; - - if (!out) - out = copystring(in); - - tmpOut = out; - - while (*in) - { - if (*in == '&') - { - // Check && -> &, &x -> x - if (*++in == '&') - *out++ = *in++; - } - else if (*in == '\t') - { - // Remove all stuff after \t in X mode, and let the stuff as is - // in Windows mode. - // Accelerators are handled in wx_item.cc for Motif, and are not - // YET supported in XView - break; - } - else - *out++ = *in++; - } // while - - *out = '\0'; - - return tmpOut; -} - - // Returns menu item id or -1 if none. int wxFindMenuItemId (wxFrame * frame, char *menuString, char *itemString) diff --git a/src/wxmac/src/mac/wx_item.cc b/src/wxmac/src/mac/wx_item.cc index 76d1c43ac5..d2a5d0159d 100644 --- a/src/wxmac/src/mac/wx_item.cc +++ b/src/wxmac/src/mac/wx_item.cc @@ -23,6 +23,7 @@ #include "wx_item.h" #include "wx_gdi.h" +#include "wx_utils.h" extern Bool wx_ignore_key; Bool wx_propagate_key; @@ -177,33 +178,7 @@ void wxGetBestControlRect(ControlRef c, Rect *r, SInt16 *offset, char *wxItemStripLabel(char *label) { - int i, j; - char *naya; - - if (!label) - return NULL; - - for (i = 0; label[i]; i++) { - if (label[i] == '&') { - /* Strip it: */ - naya = new WXGC_ATOMIC char[strlen(label) + 1]; - j = 0; - for (i = 0; label[i]; i++) { - if (label[i] == '&') { - if (label[i + 1]) { - naya[j++] = label[i + 1]; - i++; - } - } else - naya[j++] = label[i]; - } - naya[j] = 0; - - return naya; - } - } - - return label; + return wxStripMenuCodes(label, NULL); } diff --git a/src/wxmac/src/mac/wx_menu.cc b/src/wxmac/src/mac/wx_menu.cc index 400c8b91e2..0818ff1463 100644 --- a/src/wxmac/src/mac/wx_menu.cc +++ b/src/wxmac/src/mac/wx_menu.cc @@ -231,13 +231,7 @@ char *wxBuildMacMenuString(StringPtr setupstr, char *itemName, Bool stripCmds) if (itemName[0] == '-') // Fix problem with leading hyphen showstr[d++] = ' '; for (s = 0; itemName[s] != '\0'; ) { - if (itemName[s] == '&') { - if (itemName[s+1] == '&') { - showstr[d++] = itemName[s++]; - } else { - // spc = itemName[s]; - } - } else if (itemName[s] == '\t') { + if (itemName[s] == '\t') { s++; if (strncmp("Cmd+", itemName + s, 4) == 0) spc = itemName[s+4]; @@ -249,6 +243,8 @@ char *wxBuildMacMenuString(StringPtr setupstr, char *itemName, Bool stripCmds) s++; } showstr[d] = 0; + /* Now remove ampersands, etc.: */ + showstr = wxItemStripLabel(showstr); if (setupstr) { setupstr[1] = 'X'; // temporary menu item name if (spc && !stripCmds) { diff --git a/src/wxwindow/src/base/wb_utils.cxx b/src/wxwindow/src/base/wb_utils.cxx index 28480cdc9c..ab1b1c7120 100644 --- a/src/wxwindow/src/base/wb_utils.cxx +++ b/src/wxwindow/src/base/wb_utils.cxx @@ -157,39 +157,3 @@ Bool wxGetEmailAddress (char *address, int maxSize) address[maxSize-1] = '\0'; return TRUE; } - -/* - * Strip out any menu codes - */ - -char *wxStripMenuCodes (char *in, char *out) -{ - int inp, outp; - - if (!in) - return NULL; - - if (!out) - out = copystring(in); - - inp = outp = 0; - - while (in[inp]) { - if (in[inp] == '&') { - // Check && -> &, &x -> x - if (in[++inp] == '&') - out[outp++] = in[inp++]; - } else if (in[inp] == '\t') { - // Remove all stuff after \t in X mode, and let the stuff as is - // in Windows mode. - // Accelerators are handled in wx_item.cc for Motif, and are not - // YET supported in XView - break; - } else - out[outp++] = in[inp++]; - } - - out[outp] = '\0'; - - return out; -} diff --git a/src/wxxt/src/Utilities/String.cc b/src/wxxt/src/Utilities/String.cc index c92db93956..7da297475c 100644 --- a/src/wxxt/src/Utilities/String.cc +++ b/src/wxxt/src/Utilities/String.cc @@ -74,33 +74,3 @@ void wxGetLabelAndKey(char *label, char **clean_label, char **clean_key) if (clean_key) *clean_key = key; // point to key binding in private copy } - -char *wxStripMenuCodes(char *in, char *out) -{ - char *tmpOut; - - if (!in) - return NULL; - if (!out) { - out = copystring(in); - } - tmpOut = out; - - while (*in) { - if (*in == '&') { - // Check && -> &, &x -> x - if (*++in == '&') - *out++ = *in++; - } else if (*in == '\t') { - // Remove all stuff after \t in X mode, and let the stuff as is - // in Windows mode. - // Accelerators are handled in wx_item.cc for Motif, and are not - // YET supported in XView - break; - } else - *out++ = *in++; - } - - *out = '\0'; - return tmpOut; -}