plain label strips parenthesized accelerators
svn: r983
This commit is contained in:
parent
fd3b20e901
commit
50a666ebd9
|
@ -70,8 +70,13 @@
|
||||||
(lambda (s)
|
(lambda (s)
|
||||||
(car (regexp-match #rx"^[^\t]*" s)))
|
(car (regexp-match #rx"^[^\t]*" s)))
|
||||||
(lambda (s)
|
(lambda (s)
|
||||||
(regexp-replace* "&"
|
(regexp-replace* #rx"&"
|
||||||
(regexp-replace* "&(.)" (car (regexp-match #rx"^[^\t]*" s)) "\\1")
|
(regexp-replace* #rx"&(.)"
|
||||||
|
(regexp-replace*
|
||||||
|
#rx" *[(]&.[)] *"
|
||||||
|
(car (regexp-match #rx"^[^\t]*" s))
|
||||||
|
"")
|
||||||
|
"\\1")
|
||||||
"\\&\\&"))))
|
"\\&\\&"))))
|
||||||
|
|
||||||
(define basic-labelled-menu-item%
|
(define basic-labelled-menu-item%
|
||||||
|
|
|
@ -507,10 +507,10 @@
|
||||||
;;; versions below, once the &s have been stripped.
|
;;; versions below, once the &s have been stripped.
|
||||||
;;; if they don't, DrScheme's menus will appear
|
;;; if they don't, DrScheme's menus will appear
|
||||||
;;; in the wrong order.
|
;;; in the wrong order.
|
||||||
(file-menu "文件(F)")
|
(file-menu "文件")
|
||||||
(edit-menu "编辑(E)")
|
(edit-menu "编辑")
|
||||||
(help-menu "帮助(H)")
|
(help-menu "帮助")
|
||||||
(windows-menu "窗口(W)")
|
(windows-menu "窗口")
|
||||||
|
|
||||||
;;; menus
|
;;; menus
|
||||||
;;; - in menu labels, the & indicates a alt-key based shortcut.
|
;;; - in menu labels, the & indicates a alt-key based shortcut.
|
||||||
|
|
|
@ -507,10 +507,10 @@
|
||||||
;;; versions below, once the &s have been stripped.
|
;;; versions below, once the &s have been stripped.
|
||||||
;;; if they don't, DrScheme's menus will appear
|
;;; if they don't, DrScheme's menus will appear
|
||||||
;;; in the wrong order.
|
;;; in the wrong order.
|
||||||
(file-menu "文件(F)")
|
(file-menu "文件")
|
||||||
(edit-menu "編輯(E)")
|
(edit-menu "編輯")
|
||||||
(help-menu "幫助(H)")
|
(help-menu "幫助")
|
||||||
(windows-menu "窗口(W)")
|
(windows-menu "窗口")
|
||||||
|
|
||||||
;;; menus
|
;;; menus
|
||||||
;;; - in menu labels, the & indicates a alt-key based shortcut.
|
;;; - in menu labels, the & indicates a alt-key based shortcut.
|
||||||
|
|
|
@ -2871,6 +2871,73 @@ int wxGetBoolPreference(const char *name, int *res)
|
||||||
return 0;
|
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 */
|
/* initialization */
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
|
|
|
@ -212,48 +212,6 @@ wxGetEmailAddress (char *address, int maxSize)
|
||||||
return TRUE;
|
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.
|
// Returns menu item id or -1 if none.
|
||||||
int
|
int
|
||||||
wxFindMenuItemId (wxFrame * frame, char *menuString, char *itemString)
|
wxFindMenuItemId (wxFrame * frame, char *menuString, char *itemString)
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "wx_item.h"
|
#include "wx_item.h"
|
||||||
#include "wx_gdi.h"
|
#include "wx_gdi.h"
|
||||||
|
#include "wx_utils.h"
|
||||||
|
|
||||||
extern Bool wx_ignore_key;
|
extern Bool wx_ignore_key;
|
||||||
Bool wx_propagate_key;
|
Bool wx_propagate_key;
|
||||||
|
@ -177,33 +178,7 @@ void wxGetBestControlRect(ControlRef c, Rect *r, SInt16 *offset,
|
||||||
|
|
||||||
char *wxItemStripLabel(char *label)
|
char *wxItemStripLabel(char *label)
|
||||||
{
|
{
|
||||||
int i, j;
|
return wxStripMenuCodes(label, NULL);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -231,13 +231,7 @@ char *wxBuildMacMenuString(StringPtr setupstr, char *itemName, Bool stripCmds)
|
||||||
if (itemName[0] == '-') // Fix problem with leading hyphen
|
if (itemName[0] == '-') // Fix problem with leading hyphen
|
||||||
showstr[d++] = ' ';
|
showstr[d++] = ' ';
|
||||||
for (s = 0; itemName[s] != '\0'; ) {
|
for (s = 0; itemName[s] != '\0'; ) {
|
||||||
if (itemName[s] == '&') {
|
if (itemName[s] == '\t') {
|
||||||
if (itemName[s+1] == '&') {
|
|
||||||
showstr[d++] = itemName[s++];
|
|
||||||
} else {
|
|
||||||
// spc = itemName[s];
|
|
||||||
}
|
|
||||||
} else if (itemName[s] == '\t') {
|
|
||||||
s++;
|
s++;
|
||||||
if (strncmp("Cmd+", itemName + s, 4) == 0)
|
if (strncmp("Cmd+", itemName + s, 4) == 0)
|
||||||
spc = itemName[s+4];
|
spc = itemName[s+4];
|
||||||
|
@ -249,6 +243,8 @@ char *wxBuildMacMenuString(StringPtr setupstr, char *itemName, Bool stripCmds)
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
showstr[d] = 0;
|
showstr[d] = 0;
|
||||||
|
/* Now remove ampersands, etc.: */
|
||||||
|
showstr = wxItemStripLabel(showstr);
|
||||||
if (setupstr) {
|
if (setupstr) {
|
||||||
setupstr[1] = 'X'; // temporary menu item name
|
setupstr[1] = 'X'; // temporary menu item name
|
||||||
if (spc && !stripCmds) {
|
if (spc && !stripCmds) {
|
||||||
|
|
|
@ -157,39 +157,3 @@ Bool wxGetEmailAddress (char *address, int maxSize)
|
||||||
address[maxSize-1] = '\0';
|
address[maxSize-1] = '\0';
|
||||||
return TRUE;
|
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)
|
if (clean_key)
|
||||||
*clean_key = key; // point to key binding in private copy
|
*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