void iupmotKeyPressEvent(Widget w, Ihandle *ih, XEvent *evt, Boolean *cont) { int result; int code = iupmotKeyDecode((XKeyEvent*)evt); if (code == 0) return; result = iupKeyCallKeyCb(ih, code); if (result == IUP_CLOSE) { IupExitLoop(); return; } if (result == IUP_IGNORE) { *cont = False; return; } /* in the previous callback the dialog could be destroyed */ if (iupObjectCheck(ih)) { /* this is called only for canvas */ if (ih->iclass->nativetype==IUP_TYPECANVAS) { result = iupKeyCallKeyPressCb(ih, code, 1); if (result == IUP_CLOSE) { IupExitLoop(); return; } if (result == IUP_IGNORE) { *cont = False; return; } } if ((((XKeyEvent*)evt)->state & Mod1Mask || ((XKeyEvent*)evt)->state & Mod5Mask)) /* Alt + mnemonic */ { KeySym motcode = iupmotKeycodeToKeysym((XKeyEvent*)evt); if (motcode < 128) { if (iupKeyProcessMnemonic(ih, motcode)) { *cont = False; return; } } } if (iupKeyProcessNavigation(ih, code, ((XKeyEvent*)evt)->state & ShiftMask)) { *cont = False; return; } } (void)w; }
static void motTextKeyPressEvent(Widget w, Ihandle *ih, XKeyEvent *evt, Boolean *cont) { Widget spinbox; *cont = True; iupmotKeyPressEvent(w, ih, (XEvent*)evt, cont); if (*cont == False) return; if (evt->state & ControlMask && !(state & Mod1Mask || state & Mod5Mask)) /* Ctrl but NOT Alt */ { KeySym motcode = iupmotKeycodeToKeysym(evt); if (motcode == XK_c || motcode == XK_x || motcode == XK_v || motcode == XK_a) { ih->data->disable_callbacks = -1; /* let callbacks be processed in motTextSetClipboardAttrib */ if (motcode == XK_c) motTextSetClipboardAttrib(ih, "COPY"); else if (motcode == XK_x) motTextSetClipboardAttrib(ih, "CUT"); else if (motcode == XK_v) motTextSetClipboardAttrib(ih, "PASTE"); else if (motcode == XK_a) XmTextSetSelection(ih->handle, 0, XmTextGetLastPosition(ih->handle), CurrentTime); ih->data->disable_callbacks = 0; *cont = False; return; } } spinbox = (Widget)iupAttribGet(ih, "_IUP_EXTRAPARENT"); if (spinbox && XmIsSpinBox(spinbox)) { KeySym motcode = iupmotKeycodeToKeysym(evt); if (motcode == XK_Left || motcode == XK_Right) { /* avoid spin increment using Left/Right arrows, but must manually handle the new cursor position */ XmTextPosition caret_pos = XmTextGetInsertionPosition(ih->handle); XmTextSetInsertionPosition(ih->handle, (motcode == XK_Left)? caret_pos-1: caret_pos+1); *cont = False; } } }
static void motListEditModifyVerifyCallback(Widget cbedit, Ihandle *ih, XmTextVerifyPtr text) { int start, end, remove_dir = 0, ret; char *insert_value; KeySym motcode = 0; IFnis cb; if (iupAttribGet(ih, "_IUPMOT_DISABLE_TEXT_CB")) return; if (text->event && text->event->type == KeyPress) { unsigned int state = ((XKeyEvent*)text->event)->state; if (state & ControlMask || /* Ctrl */ state & Mod1Mask || state & Mod5Mask || /* Alt */ state & Mod4Mask) /* Apple/Win */ { text->doit = False; /* abort processing */ return; } motcode = iupmotKeycodeToKeysym((XKeyEvent*)text->event); } cb = (IFnis)IupGetCallback(ih, "EDIT_CB"); if (!cb && !ih->data->mask) return; start = text->startPos; end = text->endPos; insert_value = text->text->ptr; if (motcode == XK_Delete) { insert_value = NULL; remove_dir = 1; } else if (motcode == XK_BackSpace) { insert_value = NULL; remove_dir = -1; } ret = iupEditCallActionCb(ih, cb, insert_value, start, end, ih->data->mask, ih->data->nc, remove_dir, 0); /* TODO: UTF8 support */ if (ret == 0) { text->doit = False; /* abort processing */ return; } if (ret != -1) { insert_value = text->text->ptr; insert_value[0] = (char)ret; /* replace key */ } (void)cbedit; }
int iupmotKeyDecode(XKeyEvent *evt) { int i; KeySym motcode = iupmotKeycodeToKeysym(evt); { /* Other maps */ int count = sizeof(other_remap)/sizeof(other_remap[0]); for (i = 0; i < count; i++) { if (other_remap[i].motcode == motcode) { motcode = (KeySym)other_remap[i].iupcode; break; } } } return motKeyMap2Iup(motcode, evt->state); }
static void motListEditKeyPressEvent(Widget cbedit, Ihandle *ih, XKeyEvent *evt, Boolean *cont) { *cont = True; iupmotKeyPressEvent(cbedit, ih, (XEvent*)evt, cont); if (*cont == False) return; if (evt->state & ControlMask) /* Ctrl */ { KeySym motcode = iupmotKeycodeToKeysym(evt); if (motcode == XK_c) { motListSetClipboardAttrib(ih, "COPY"); *cont = False; return; } else if (motcode == XK_x) { motListSetClipboardAttrib(ih, "CUT"); *cont = False; return; } else if (motcode == XK_v) { motListSetClipboardAttrib(ih, "PASTE"); *cont = False; return; } else if (motcode == XK_a) { XmTextFieldSetSelection(cbedit, 0, XmTextFieldGetLastPosition(cbedit), CurrentTime); *cont = False; return; } } }
static void motListEditModifyVerifyCallback(Widget cbedit, Ihandle *ih, XmTextVerifyPtr text) { int start, end, key = 0; char *value, *new_value, *insert_value; KeySym motcode = 0; IFnis cb; if (iupAttribGet(ih, "_IUPMOT_DISABLE_TEXT_CB")) return; if (text->event && text->event->type == KeyPress) { unsigned int state = ((XKeyEvent*)text->event)->state; if (state & ControlMask || /* Ctrl */ state & Mod1Mask || state & Mod5Mask || /* Alt */ state & Mod4Mask) /* Apple/Win */ { text->doit = False; /* abort processing */ return; } motcode = iupmotKeycodeToKeysym(((XKeyEvent*)text->event)->keycode); } cb = (IFnis)IupGetCallback(ih, "EDIT_CB"); if (!cb && !ih->data->mask) return; value = XmTextFieldGetString(cbedit); start = text->startPos; end = text->endPos; insert_value = text->text->ptr; if (motcode == XK_Delete) { new_value = value; iupStrRemove(value, start, end, 1); } else if (motcode == XK_BackSpace) { new_value = value; iupStrRemove(value, start, end, -1); } else { if (!value) new_value = iupStrDup(insert_value); else if (insert_value) new_value = iupStrInsert(value, insert_value, start, end); else new_value = value; } if (insert_value && insert_value[0]!=0 && insert_value[1]==0) key = insert_value[0]; if (ih->data->mask && iupMaskCheck(ih->data->mask, new_value)==0) { if (new_value != value) free(new_value); XtFree(value); text->doit = False; /* abort processing */ return; } if (cb) { int cb_ret = cb(ih, key, (char*)new_value); if (cb_ret==IUP_IGNORE) text->doit = False; /* abort processing */ else if (cb_ret==IUP_CLOSE) { IupExitLoop(); text->doit = False; /* abort processing */ } else if (cb_ret!=0 && key!=0 && cb_ret != IUP_DEFAULT && cb_ret != IUP_CONTINUE) { insert_value[0] = (char)cb_ret; /* replace key */ } } if (new_value != value) free(new_value); XtFree(value); }
static void motTextModifyVerifyCallback(Widget w, Ihandle *ih, XmTextVerifyPtr text) { int start, end, remove_dir = 0, ret; char *insert_value; KeySym motcode = 0; IFnis cb; if (ih->data->disable_callbacks) return; if (iupAttribGet(ih, "_IUPMOT_SPIN_DISABLE_TEXT_CB")) { if (iupAttribGet(ih, "_IUPMOT_SPIN_NOAUTO")) text->doit = False; iupAttribSet(ih, "_IUPMOT_SPIN_DISABLE_TEXT_CB", NULL); return; } if (text->event && text->event->type == KeyPress) { unsigned int state = ((XKeyEvent*)text->event)->state; int has_ctrl = state & ControlMask; /* Ctrl */ int has_alt = state & Mod1Mask || state & Mod5Mask; /* Alt */ int has_sys = state & Mod4Mask; /* Apple/Win */ /* only process when no modifiers are used */ /* except when Ctrl and Alt are pressed at the same time */ if (has_sys || (!has_ctrl && has_alt) || (has_ctrl && !has_alt)) { text->doit = False; /* abort processing */ return; } motcode = iupmotKeycodeToKeysym((XKeyEvent*)(text->event)); } cb = (IFnis)IupGetCallback(ih, "ACTION"); start = text->startPos; end = text->endPos; insert_value = text->text->ptr; if (motcode == XK_Delete) { insert_value = NULL; remove_dir = 1; } else if (motcode == XK_BackSpace) { insert_value = NULL; remove_dir = -1; } ret = iupEditCallActionCb(ih, cb, insert_value, start, end, ih->data->mask, ih->data->nc, remove_dir, 0); /* TODO: UTF8 support */ if (ret == 0) { text->doit = False; /* abort processing */ return; } if (ret != -1) { insert_value = text->text->ptr; insert_value[0] = (char)ret; /* replace key */ } if (text->doit) { /* Spin is not automatically updated when you directly edit the text */ Widget spinbox = (Widget)iupAttribGet(ih, "_IUP_EXTRAPARENT"); if (spinbox && XmIsSpinBox(spinbox) && !iupAttribGet(ih, "_IUPMOT_SPIN_NOAUTO")) { XmTextPosition caret_pos = text->currInsert; /* do not handle all situations, but handle the basic ones */ if (text->startPos == text->endPos) /* insert */ caret_pos++; else if (text->startPos < text->endPos && text->startPos < text->currInsert) /* backspace */ caret_pos--; XmTextSetInsertionPosition(ih->handle, caret_pos); text->doit = False; iupAttribSet(ih, "_IUPMOT_UPDATESPIN", "1"); } } (void)w; }