char* iupKeyCodeToName(int code) { unsigned char mod = 0; const char* base_name; if (code <= 0) return NULL; base_name = iKeyBaseCodeToName(iup_XkeyBase(code), &mod); if (!base_name) { static char code_name[30]; sprintf(code_name, "K_0x%X", iup_XkeyBase(code)); base_name = code_name; } if (iup_XkeyBase(code)==code) /* no modifiers */ return (char*)base_name; if (iup_isShiftXkey(code) && mod==0) iKeyReturnXName("K_s", base_name); if (mod==1) return (char*)base_name; if (iup_isCtrlXkey(code)) iKeyReturnXName("K_c", base_name); if (iup_isAltXkey(code)) iKeyReturnXName("K_m", base_name); if (iup_isSysXkey(code)) iKeyReturnXName("K_y", base_name); return (char*)base_name; }
void iupdrvKeyEncode(int code, unsigned int *keyval, unsigned int *state) { *keyval = (unsigned int)iup_XkeyBase(code); /* Only need to un-remap these */ if (*keyval == K_BS) *keyval = GDK_BackSpace; if (*keyval == K_TAB) *keyval = GDK_Tab; if (*keyval == K_CR) *keyval = GDK_Return; *state = 0; if (iup_isCtrlXkey(code)) *state |= GDK_CONTROL_MASK; if (iup_isAltXkey(code)) *state |= GDK_MOD1_MASK; if (iup_isSysXkey(code)) *state |= GDK_MOD4_MASK; if (iup_isShiftXkey(code)) *state |= GDK_SHIFT_MASK; }
void iupdrvKeyEncode(int code, unsigned int *keycode, unsigned int *state) { KeySym motcode = (KeySym)iup_XkeyBase(code); /* Only need to un-remap these */ if (motcode == K_BS) motcode = XK_BackSpace; else if (motcode == K_TAB) motcode = XK_Tab; else if (motcode == K_CR) motcode = XK_Return; *keycode = (unsigned int)XKeysymToKeycode(iupmot_display, motcode); *state = 0; if (iup_isCtrlXkey(code)) *state |= ControlMask; if (iup_isAltXkey(code)) *state |= Mod1Mask; if (iup_isSysXkey(code)) *state |= Mod4Mask; if (iup_isShiftXkey(code)) *state |= ShiftMask; }
static int cf_XkeyBase(lua_State *L) { int value = (int)luaL_checkinteger(L, 1); lua_pushinteger(L, iup_XkeyBase(value)); return 1; }
int iupKeyProcessNavigation(Ihandle* ih, int code, int shift) { /* this is called after K_ANY is processed, so the user may change its behavior */ if (code == K_cTAB) { int is_multiline = iupAttribGetInt(ih, "_IUP_MULTILINE_TEXT"); if (is_multiline) { if (shift) IupPreviousField(ih); else IupNextField(ih); return 1; } } else if (code == K_TAB || code == K_sTAB) { int is_multiline = iupAttribGetInt(ih, "_IUP_MULTILINE_TEXT"); if (!is_multiline) { if (code == K_sTAB || shift) IupPreviousField(ih); else IupNextField(ih); return 1; } } else if (code == K_UP || code == K_DOWN) { int is_button = (IupClassMatch(ih, "button") || IupClassMatch(ih, "toggle")); if (is_button) { if (code == K_UP) iupFocusPrevious(ih); else iupFocusNext(ih); return 1; } } else if (code==K_ESC) { Ihandle* bt = IupGetAttributeHandle(IupGetDialog(ih), "DEFAULTESC"); if (iupObjectCheck(bt) && IupClassMatch(bt, "button")) iupdrvActivate(bt); return 1; } else if (code==K_CR || code==K_cCR) { int is_multiline = iupAttribGetInt(ih, "_IUP_MULTILINE_TEXT"); if ((code==K_CR && !is_multiline) || (code==K_cCR && is_multiline)) { Ihandle* bt = IupGetAttributeHandle(IupGetDialog(ih), "DEFAULTENTER"); if (iupObjectCheck(bt) && IupClassMatch(bt, "button")) iupdrvActivate(bt); return 1; } } else if (iup_isCtrlXkey(code) && iup_isShiftXkey(code) && iup_isAltXkey(code) && iup_XkeyBase(code) == K_L) { /* Ctrl+Shift+Alt+L */ IupShow(IupLayoutDialog(IupGetDialog(ih))); } return 0; }