COSXKeyState::COSXKeyState() : m_deadKeyState(0) { // enable input in scripts other that roman KeyScript(smKeyEnableKybds); // build virtual key map for (size_t i = 0; i < sizeof(s_controlKeys) / sizeof(s_controlKeys[0]); ++i) { m_virtualKeyMap[s_controlKeys[i].m_virtualKey] = s_controlKeys[i].m_keyID; } }
static PyObject *Evt_KeyScript(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; short code; #ifndef KeyScript PyMac_PRECHECK(KeyScript); #endif if (!PyArg_ParseTuple(_args, "h", &code)) return NULL; KeyScript(code); Py_INCREF(Py_None); _res = Py_None; return _res; }
OP_STATUS UKeyTranslate::GetUnicharFromVirtualKey(UInt32 virtualKeyCode, uni_char &outUniChar, UInt8 modifierKeyState) { #ifdef SIXTY_FOUR_BIT UInt32 deadKeyState = 0; OP_STATUS result = OpStatus::ERR; TISInputSourceRef kbInputSourceRef = TISCopyCurrentKeyboardLayoutInputSource(); CFDataRef uchrDataRef = (CFDataRef)TISGetInputSourceProperty(kbInputSourceRef, kTISPropertyUnicodeKeyLayoutData); Boolean existsUchr = ((uchrDataRef != NULL) && (CFDataGetBytePtr(uchrDataRef) != NULL) && (CFDataGetLength(uchrDataRef) != 0)); if (existsUchr) { UniCharCount actualLength = 0; UniChar outChar[2] = {0,0}; OSStatus status = UCKeyTranslate((const UCKeyboardLayout *)CFDataGetBytePtr(uchrDataRef), virtualKeyCode, kUCKeyActionDown, modifierKeyState, LMGetKbdType(), kNilOptions, &deadKeyState, 2, &actualLength, outChar); if (status == noErr && actualLength && outChar[0] != kFunctionKeyCharCode) { outUniChar = outChar[0]; result = OpStatus::OK; } } CFRelease(kbInputSourceRef); return result; #else // !SIXTY_FOUR_BIT static KeyboardLayoutRef lastKbdLayout = 0; static const UCKeyboardLayout* ucharData = NULL; static const void* charData = NULL; KeyboardLayoutRef currentKbdLayout = 0; if (noErr != KLGetCurrentKeyboardLayout(¤tKbdLayout) || !currentKbdLayout) { return OpStatus::ERR; } short keyCode; OSStatus error = noErr; UInt32 deadKeyState = 0; OP_STATUS result = OpStatus::ERR; keyCode = virtualKeyCode; if (!ucharData || (currentKbdLayout != lastKbdLayout)) { // Don't fetch this unless we have to: Because of the KeyScript issue handled below this may in some cases return 0 // KeyScript is an EXPENSIVE call, so by caching ucharData as long as possible we minimise the number of times // we need to call it. error = KLGetKeyboardLayoutProperty(currentKbdLayout, kKLuchrData, (const void**)&ucharData); } if (!ucharData) { static Boolean try_again = true; if (try_again && (smRoman == GetScriptManagerVariable(smKeyScript))) { // This is required for roman scripts in order to get something from KLGetCurrentKeyboardLayout KeyScript(smRoman | smKeyForceKeyScriptMask); error = KLGetKeyboardLayoutProperty(currentKbdLayout, kKLuchrData, (const void**)&ucharData); if (error || !ucharData) try_again = false; } } if ((error == noErr) && (ucharData != 0)) { UniCharCount actualLength = 0; UniChar outChar[2] = {0,0}; charData = NULL; error = UCKeyTranslate(ucharData, (unsigned short)keyCode, kUCKeyActionDown, modifierKeyState, LMGetKbdType(), 0, &deadKeyState, 2, &actualLength, outChar); if (error == noErr && actualLength && outChar[0] != kFunctionKeyCharCode) { outUniChar = outChar[0]; result = OpStatus::OK; #ifdef DEBUG_UNI_KEYSTROKES // if (outUniChar & 0xff00) // fprintf(stderr, "UKC:%x\n", outChar[0]); #endif } #ifdef DEBUG_UNI_KEYSTROKES else { fprintf(stderr, "UKCe:%li-%x-%lu-%x\n", error, outChar[0], virtualKeyCode, modifierKeyState); } if (actualLength != 1) fprintf(stderr, "UKCl:%lu-%x-%x-%lu-%x\n", actualLength, outChar[0], outChar[1], virtualKeyCode, modifierKeyState); #endif } else { #ifdef DEBUG_UNI_KEYSTROKES fprintf(stderr, "KLP:%li\n", error); #endif error = noErr; if (!charData || (currentKbdLayout != lastKbdLayout)) { error = KLGetKeyboardLayoutProperty(currentKbdLayout, kKLKCHRData, &charData); } if ((error == noErr) && (charData != 0)) { unsigned long charcs = KeyTranslate(charData, (keyCode & 0xFF) | (modifierKeyState << 8), &deadKeyState); if (charcs & 0xFF) { char src = charcs & 0x00FF; gTextConverter->ConvertBufferFromMac(&src, 1, &outUniChar, 1); result = OpStatus::OK; } #ifdef DEBUG_UNI_KEYSTROKES else { fprintf(stderr, "KTe\n", outUniChar); } if (charcs & 0xFF0000) { fprintf(stderr, "KTe:%x-%lu-%x\n", charcs, virtualKeyCode, modifierKeyState); } #endif } else { #ifdef DEBUG_UNI_KEYSTROKES fprintf(stderr, "KLPe:%li\n", error); #endif } } lastKbdLayout = currentKbdLayout; return result; #endif // SIXTY_FOUR_BIT }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ WEFastSetStyle // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Sets the style without making an undo entry and can effect any text range, not just the selection OSErr WEFastSetStyle( WEStyleMode mode, const TextStyle *ts, SInt32 inStart, SInt32 inEnd, WEHandle hWE) { WEPtr pWE; WEActionHandle hAction; ScriptCode fontScript; Boolean saveWELock; OSErr err; // lock the WE record saveWELock = _WESetHandleLock((Handle) hWE, true); pWE = *hWE; // return an error code if this instance is read-only err = weReadOnlyErr; if (BTST(pWE->features, weFReadOnly)) { goto cleanup; } // stop any ongoing inline input session WEStopInlineSession(hWE); if (BTST(pWE->features, weFMonoStyled)) { // MONOSTYLED TEXT // apply the change to the whole text, not just to the selection range if ((err = _WESetStyleRange(0, pWE->textLength, mode, (WETextStyle *) ts, hWE)) != noErr) { goto cleanup; } // invalidate the null style record BCLR(pWE->flags, weFUseNullStyle); // redraw the text if ((err = _WERedraw(0, pWE->textLength, hWE)) != noErr) { goto cleanup; } } else if (inStart == inEnd) { // MULTISTYLED TEXT; NULL SELECTION // first make sure the nullStyle field contains valid information _WESynchNullStyle(hWE); // apply style changes to the nullStyle record _WECopyStyle((WETextStyle *) ts, &pWE->nullStyle.runStyle, pWE->nullStyle.runStyle.tsFace, mode); // special case: if this instance is empty, propagate the // change to the style table (this avoids some subtle problems) if (pWE->textLength == 0) { if ((err = _WESetStyleRange(0, 0, weDoAll + weDoReplaceFace, &pWE->nullStyle.runStyle, hWE)) != noErr) { goto cleanup; } } #if !WASTE_NO_SYNCH // if the font was altered, synchronize the keyboard script if (BTST(pWE->flags, weFNonRoman) && (mode & weDoFont)) { fontScript = FontToScript(pWE->nullStyle.runStyle.tsFont); if (fontScript != GetScriptManagerVariable(smKeyScript)) { KeyScript(fontScript); } } #endif } else { // MULTISTYLED TEXT; NON-EMPTY SELECTION // increment modification count pWE->modCount++; // check for "smart" font modes if (BTST(pWE->flags, weFNonRoman) && ((mode & weDoSmartFont) == weDoSmartFont)) { if ((err = _WESmartSetFont(mode, ts, hWE)) != noErr) { goto cleanup; } mode &= ~weDoFont; } // set the style of the selection range if ((err = _WESetStyleRange(inStart,inEnd, mode, (WETextStyle *) ts, hWE)) != noErr) { goto cleanup; } // and redraw the text if ((err = _WERedraw(inStart,inEnd, hWE)) != noErr) { goto cleanup; } } // clear the result code err = noErr; cleanup: // unlock the WE record _WESetHandleLock((Handle) hWE, saveWELock); // return result code return err; }