void MCButton::SetAcceleratorKey(MCExecContext& ctxt, MCStringRef p_name) { if (p_name != nil) { accelkey = MCStringGetCharAtIndex(p_name, 0); if (MCStringGetLength(p_name) > 1) { uint4 t_accelkey = MCLookupAcceleratorKeysym(p_name); if (t_accelkey != 0) accelkey = t_accelkey; } } else accelkey = 0; MCstacks->changeaccelerator(this, accelkey, accelmods); }
bool ParseMenuItemAccelerator(char *p_string, char *&r_endstr, MCMenuItem *p_menuitem) { uint1 t_mods = 0; uint4 t_key = 0; const char *t_keyname = NULL; r_endstr[0] = '\0'; char *t_tag = strrchr(p_string, '|'); if (t_tag != NULL && r_endstr - t_tag > 1) { p_menuitem->tag = strclone(t_tag + 1); r_endstr = t_tag; r_endstr[0] = '\0'; } if (p_menuitem->menumode == WM_PULLDOWN || p_menuitem->menumode == WM_TOP_LEVEL) { uint4 t_accelstrlen = r_endstr - p_string; if (t_accelstrlen == 1) t_mods |= MS_CONTROL; while (r_endstr - p_string > 1) { if (p_string[0] == ' ') { p_string++; } else { uint4 i = 0; bool t_token_found = false; while (!t_token_found && modifier_tokens[i].token != NULL) { if (modifier_tokens[i].token_length == 1) { if (p_string[0] == modifier_tokens[i].token[0]) { if (!(t_mods & modifier_tokens[i].modifier)) { t_mods |= modifier_tokens[i].modifier; p_string++; t_token_found = true; } break; } } else if (modifier_tokens[i].token_length < r_endstr - p_string && (p_string[modifier_tokens[i].token_length] == ' ')) { if (MCU_strncasecmp(p_string, modifier_tokens[i].token, modifier_tokens[i].token_length) == 0) { t_mods |= modifier_tokens[i].modifier; p_string += modifier_tokens[i].token_length; t_token_found = true; } } i++; } if (!t_token_found) break; } } if (r_endstr - p_string == 1) { t_key = *p_string; } else if (r_endstr - p_string > 1) { MCString t_string(p_string, r_endstr - p_string); t_key = MCLookupAcceleratorKeysym(t_string); if (t_key != 0) t_keyname = p_string; else t_mods = 0; } if (t_key <= 255) { uint1 t_lowerkey = MCS_tolower((uint1)t_key); if (t_lowerkey < 'a' || t_lowerkey > 'z') t_mods &= ~MS_SHIFT; } p_menuitem->modifiers = t_mods; p_menuitem->accelerator = t_key; p_menuitem->accelerator_name = t_keyname; } return false; }