Beispiel #1
0
/*

	Processes WM_KEYDOWN messages related to special keys

*/
bool ev_Win32Keyboard::onKeyDown(AV_View * pView,
                                 HWND /*hWnd*/, UINT /*iMsg*/, WPARAM nVirtKey, LPARAM keyData)
{

    m_bWasAnAbiCommand = false;

    EV_EditMethod * pEM;

    EV_EditModifierState ems = _getModifierState();
    EV_EditBits nvk;

    int						charLen;
    UT_UCSChar				charData[2];

    UT_DEBUGMSG(("WIN32KEY_DEBUG->onKeyDown %x, %x\n", nVirtKey, keyData));

    // ALT key for windows {menus, ... }, ALT+XXX for special chars, etc
    if (((ems & EV_EMS_ALT) != 0) && ((ems & EV_EMS_CONTROL) == 0))
    {
#ifdef  _WIN32KEY_DEBUG
        UT_DEBUGMSG(("WIN32KEY_DEBUG->onKeyDown return true (EV_EMS_CONTROL)\n"));
#endif
        return true;
    }

    /*
    	This is a Alt+gr combination in an international keyboard
    */
    if (GetKeyState(VK_RMENU) & 0x8000)
    {
#ifdef  _WIN32KEY_DEBUG
        UT_DEBUGMSG(("WIN32KEY_DEBUG->Alt+gr (EV_EMS_CONTROL)\n"));
#endif
        return true;
    }

    // Get abiword keyid
    nvk = s_mapVirtualKeyCodeToNVK(nVirtKey);

    // If it is not a special key or a CTRL combination, there is nothing to do
    if (nvk == EV_NVK__IGNORE__ || (nvk == 0  && ((ems & EV_EMS_CONTROL) == 0)))
    {
#ifdef  _WIN32KEY_DEBUG
        UT_DEBUGMSG(("WIN32KEY_DEBUG->onKeyDown return true (IGNORE)\n"));
#endif
        return true;
    }

    if (nvk != 0)
    {   // Special key
        charLen = 0;
        charData[0] = nvk;
    }
    else
    {   // Non-special key with CTRL

#if 0
        // this causes bug 9618
        WCHAR	char_value[2];
        BYTE	keyboardState[256];

        ::GetKeyboardState(keyboardState);

        // Here we pretend the CTRL key is not pressed, otherwise windows will try and convert it
        // into a control code, this is not what we want
        keyboardState[VK_CONTROL] &= 0x7F;		// mask off high bit

        if (ToAsciiEx(nVirtKey, keyData & 0x00FF0000, keyboardState, (unsigned short*) &char_value[0], 0,
                      m_hKeyboardLayout)==0)
            return true;
        charLen		= 1;
        charData[0]	= UT_UCSChar(char_value [0] & 0x000000FF);
        charData[1]	= 0;
#else
        charLen = 1;
        charData[0] = (UT_UCS4Char)MapVirtualKeyEx(nVirtKey, 2, m_hKeyboardLayout);

        if(!charData[0]) // no mapping
            return true;

        charData[1]	= 0;

        if((ems & EV_EMS_SHIFT) == 0)
        {
            // shift not pressed; MapVirtualKeyEx() always returns capital letter, so we
            // have to lowercase it
            charData[0] = UT_UCS4_tolower(charData[0]);
        }

#endif
    }


    switch (m_pEEM->Keystroke(EV_EKP_PRESS | ems | charData[0], &pEM)) //#define EV_EKP_PRESS			((EV_EditKeyPress)		0x00800000)
    {

    case EV_EEMR_BOGUS_START:
    case EV_EEMR_BOGUS_CONT:
    case EV_EEMR_INCOMPLETE:		// a non-terminal node in state machine
        return false;

    case EV_EEMR_COMPLETE:			// a terminal node in state machine
        UT_ASSERT(pEM);
        invokeKeyboardMethod(pView, pEM, charData, charLen);
        m_bWasAnAbiCommand = true;
        return true;

    default:
        UT_ASSERT(0);
        return false;
    }

    return 	true;
}
Beispiel #2
0
bool ev_UnixKeyboard::keyPressEvent(AV_View* pView, GdkEventKey* e)
{
    EV_EditBits state = 0;
    EV_EditEventMapperResult result;
    EV_EditMethod * pEM;

    UT_uint32 charData = e->keyval;

    if (e->state & GDK_SHIFT_MASK)
        state |= EV_EMS_SHIFT;
    if (e->state & GDK_CONTROL_MASK)
    {
        state |= EV_EMS_CONTROL;

        // Gdk does us the favour of working out a translated keyvalue for us,
        // but with the Ctrl keys, we do not want that -- see bug 9545
        Display * display = GDK_DISPLAY_XDISPLAY(gdk_window_get_display(e->window));
        KeySym sym = XKeycodeToKeysym(display,
                                      e->hardware_keycode,
                                      e->state & GDK_SHIFT_MASK ? 1 : 0);
        xxx_UT_DEBUGMSG(("ev_UnixKeyboard::keyPressEvent: keyval %d, hardware_keycode %d\n"
                         "                                sym: 0x%x\n",
                         e->keyval, e->hardware_keycode, sym));

        charData = sym;
    }
    if (e->state & (s_alt_mask))
        state |= EV_EMS_ALT;

    if (s_isVirtualKeyCode(charData))
    {
        EV_EditBits nvk = s_mapVirtualKeyCodeToNVK(charData);

        switch (nvk)
        {
        case EV_NVK__IGNORE__:
            return false;
        default:

            result = m_pEEM->Keystroke(static_cast<UT_uint32>(EV_EKP_PRESS|state|nvk),&pEM);

            switch (result)
            {
            case EV_EEMR_BOGUS_START:
                // If it is a bogus key and we don't have a sequence in
                // progress, we should let the system handle it
                // (this lets things like ALT-F4 work).
                return false;

            case EV_EEMR_BOGUS_CONT:
                // If it is a bogus key but in the middle of a sequence,
                // we should silently eat it (this is to prevent things
                // like Control-X ALT-F4 from killing us -- if they want
                // to kill us, fine, but they shouldn't be in the middle
                // of a sequence).
                return true;

            case EV_EEMR_COMPLETE:
                UT_ASSERT(pEM);
                invokeKeyboardMethod(pView,pEM,0,0); // no char data to offer
                return true;

            case EV_EEMR_INCOMPLETE:
                return true;

            default:
                UT_ASSERT(0);
                return true;
            }
        }
    }
    else
    {
        // TODO: is this necessary?
        charData = gdk_keyval_to_unicode (charData);
        UT_UTF8String utf8 (static_cast<const UT_UCS4Char *>(&charData), 1);
        return charDataEvent (pView, state, utf8.utf8_str(), utf8.byteLength());
    }

    return false;
}