plain label strips parenthesized accelerators
svn: r983
This commit is contained in:
parent
fd3b20e901
commit
50a666ebd9
|
@ -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%
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 */
|
||||
/***********************************************************************/
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user