> Sent: Thursday, March 05, 2015 at 2:49 PM
> From: "Rob Kendrick" <r...@netsurf-browser.org>
> To: netsurf-dev@netsurf-browser.org
> Subject: Re: Re: Bug 2171
>
> On Thu, Mar 05, 2015 at 02:26:26PM -0000, WPB wrote:
> > Couldn't the messages in the UI messages file contain a special
> > character to denote the start of a keyboard shortcut? Something that
> > wouldn't make sense for a menu item, like a CR? I suppose that's not
> > very friendly in terms of the messages file itself, so maybe
> > something else, like a forward slash.
> > 
> > The ro_gui_translate() (if that is the right function - I haven't
> > looked) could be passed an extra parameter to either truncate the
> > string at that point, or remove the special character from the
> > string.
> 
> I think the strings are handed around as const char *; processing them
> would involve making copies in memory.
> 
> B.
> 
> 

This is basically how wxWidgets handles menu entries but to do so in NetSurf 
would require quite a function to parse each string and a flag to determine if 
the short-cut is actually required or not.  Something like:

char * menu_create_entry(char *entry, bool shortcut)  
{
  if (!shortcut)  {
    parse entry char to find special modifier character 
    and return char with everything after that chopped off
  }  else {
    parse entry char and return with just the modifier character
    deleted so it is a plain text string
  }
}


For reference here is an excerpt from the wxWidgets documentation 
http://docs.wxwidgets.org/trunk/classwx_menu_item.html#a6e9b0e1b786fa84250a42c88d84aed2b


"virtual void wxMenuItem::SetItemLabel (const wxString & label)" sets the label 
associated with the menu item.

The label string for the normal menu items (not separators) may include the 
accelerator which can be used to activate the menu item from keyboard. An 
accelerator key can be specified using the ampersand & character. In order to 
embed an ampersand character in the menu item text, the ampersand must be 
doubled.

Optionally you can specify also an accelerator string appending a tab character 
\t followed by a valid key combination (e.g. CTRL+V). Its general syntax is any 
combination of "CTRL", "RAWCTRL", "ALT" and "SHIFT" strings (case doesn't 
matter) separated by either '-' or '+' characters and followed by the 
accelerator itself. Notice that CTRL corresponds to the "Ctrl" key on most 
platforms but not under Mac OS where it is mapped to "Cmd" key on Mac keyboard. 
Usually this is exactly what you want in portable code but if you really need 
to use the (rarely used for this purpose) "Ctrl" key even under Mac, you may 
use RAWCTRL to prevent this mapping. Under the other platforms RAWCTRL is the 
same as plain CTRL.

The accelerator may be any alphanumeric character, any function key (from F1 to 
F12) or one of the special characters listed in the table below (again, case 
doesn't matter):

DEL or DELETE: Delete key
BACK : Backspace key
INS or INSERT: Insert key
ENTER or RETURN: Enter key
PGUP: PageUp key
PGDN: PageDown key
LEFT: Left cursor arrow key
RIGHT: Right cursor arrow key
UP: Up cursor arrow key
DOWN: Down cursor arrow key
HOME: Home key
END: End key
SPACE: Space
TAB: Tab key
ESC or ESCAPE: Escape key (Windows only)

Reply via email to