VirtualBox

Changeset 5132 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Oct 1, 2007 9:41:31 PM (17 years ago)
Author:
vboxsync
Message:

FE/Qt: OS/2: Implemented keyboard input to the VM.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/QIHotKeyEdit.h

    r4071 r5132  
    2828#endif
    2929
     30#if defined(Q_WS_PM)
     31/* Extra virtual keys returned by QIHotKeyEdit::virtualKey() */
     32#define VK_LSHIFT   VK_USERFIRST + 0
     33#define VK_LCTRL    VK_USERFIRST + 1
     34#define VK_LWIN     VK_USERFIRST + 2
     35#define VK_RWIN     VK_USERFIRST + 3
     36#define VK_WINMENU  VK_USERFIRST + 4
     37#define VK_FORWARD  VK_USERFIRST + 5
     38#define VK_BACKWARD VK_USERFIRST + 6
     39#endif
    3040
    3141class QIHotKeyEdit : public QLabel
     
    3545public:
    3646
    37     QIHotKeyEdit( QWidget * parent, const char * name = 0 );
     47    QIHotKeyEdit (QWidget *aParent, const char *aName = 0);
    3848    virtual ~QIHotKeyEdit();
    3949
    40     void setKey( int keyval );
    41     int key() const { return keyval; }
     50    void setKey (int aKeyVal);
     51    int key() const { return mKeyVal; }
    4252
    43     QString symbolicName() const { return symbname; }
     53    QString symbolicName() const { return mSymbName; }
    4454
    4555    QSize sizeHint() const;
    4656    QSize minimumSizeHint() const;
    4757
    48 #if defined(Q_WS_X11)
    49     static void languageChange(void);
     58#if defined (Q_WS_PM)
     59    static int virtualKey (QMSG *aMsg);
    5060#endif
    51     static QString keyName (int key);
    52     static bool isValidKey (int k);
     61
     62#if defined (Q_WS_PM) || defined (Q_WS_X11)
     63    static void languageChange();
     64#endif
     65    static QString keyName (int aKeyVal);
     66    static bool isValidKey (int aKeyVal);
    5367
    5468public slots:
     
    5872protected:
    5973
    60 #if defined(Q_WS_WIN32)
    61     bool winEvent( MSG *msg );
    62 #elif defined(Q_WS_X11)
    63     bool x11Event( XEvent *event );
    64 #elif defined(Q_WS_MAC)
    65     static pascal OSStatus darwinEventHandlerProc( EventHandlerCallRef inHandlerCallRef,
    66                                                    EventRef inEvent, void *inUserData );
    67     bool darwinKeyboardEvent( EventRef inEvent );
     74#if defined (Q_WS_WIN32)
     75    bool winEvent (MSG *msg);
     76#elif defined (Q_WS_PM)
     77    bool pmEvent (QMSG *aMsg);
     78#elif defined (Q_WS_X11)
     79    bool x11Event (XEvent *event);
     80#elif defined (Q_WS_MAC)
     81    static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
     82                                                   EventRef inEvent, void *inUserData);
     83    bool darwinKeyboardEvent (EventRef inEvent);
    6884#endif
    6985
    70     void focusInEvent( QFocusEvent * );
    71     void focusOutEvent( QFocusEvent * );
     86    void focusInEvent (QFocusEvent *);
     87    void focusOutEvent (QFocusEvent *);
    7288
    73     void drawContents( QPainter * p );
     89    void drawContents (QPainter *p);
    7490
    7591private:
     
    7793    void updateText();
    7894
    79     int keyval;
    80     QString symbname;
     95    int mKeyVal;
     96    QString mSymbName;
    8197
    82     QColorGroup true_acg;
     98    QColorGroup mTrueACG;
    8399
    84 #if defined(Q_WS_X11)
    85     static QMap<QString, QString> keyNames;
     100#if defined (Q_WS_PM)
     101    static QMap <int, QString> sKeyNames;
     102#elif defined (Q_WS_X11)
     103    static QMap <QString, QString> sKeyNames;
    86104#endif
    87105
    88 #if defined(Q_WS_MAC)
     106#if defined (Q_WS_MAC)
    89107    /** Event handler reference. NULL if the handler isn't installed. */
    90     EventHandlerRef m_darwinEventHandlerRef;
     108    EventHandlerRef mDarwinEventHandlerRef;
    91109    /** The current modifier key mask. Used to figure out which modifier
    92110     *  key was pressed when we get a kEventRawKeyModifiersChanged event. */
    93     UInt32 m_darwinKeyModifiers;
     111    UInt32 mDarwinKeyModifiers;
    94112#endif
    95113
    96     static const char *NoneSymbName;
     114    static const char *kNoneSymbName;
    97115};
    98116
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h

    r4514 r5132  
    110110
    111111    // events
    112     bool event( QEvent *e );
    113     bool eventFilter( QObject *watched, QEvent *e );
     112    bool event (QEvent *e);
     113    bool eventFilter (QObject *watched, QEvent *e);
    114114
    115115#if defined(Q_WS_WIN32)
    116116    bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event);
    117117    bool winEvent (MSG *msg);
     118#elif defined(Q_WS_PM)
     119    bool pmEvent (QMSG *aMsg);
    118120#elif defined(Q_WS_X11)
    119     bool x11Event (XEvent *event );
     121    bool x11Event (XEvent *event);
    120122#elif defined(Q_WS_MAC)
    121123    bool darwinKeyboardEvent (EventRef inEvent);
     
    125127private:
    126128
    127     // flags for keyEvent()
     129    /** Flags for keyEvent(). */
    128130    enum {
    129131        KeyExtended = 0x01,
     
    134136
    135137    void focusEvent (bool focus);
    136     bool keyEvent (int key, uint8_t scan, int flags, wchar_t *aUniKey = NULL);
     138    bool keyEvent (int aKey, uint8_t aScan, int aFlags,
     139                   wchar_t *aUniKey = NULL);
    137140    bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos,
    138141                     ButtonState aButton,
  • trunk/src/VBox/Frontends/VirtualBox/src/QIHotKeyEdit.cpp

    r4071 r5132  
    2626
    2727#ifdef Q_WS_WIN
    28 // VBox/cdefs.h defines these:
     28/* VBox/cdefs.h defines these: */
    2929#undef LOWORD
    3030#undef HIWORD
     
    3434#endif
    3535
     36#if defined (Q_WS_PM)
     37QMap <int, QString> QIHotKeyEdit::sKeyNames;
     38#endif
     39
    3640#ifdef Q_WS_X11
    37 // We need to capture some X11 events directly which
    38 // requires the XEvent structure to be defined. However,
    39 // including the Xlib header file will cause some nasty
    40 // conflicts with Qt. Therefore we use the following hack
    41 // to redefine those conflicting identifiers.
     41/* We need to capture some X11 events directly which
     42 * requires the XEvent structure to be defined. However,
     43 * including the Xlib header file will cause some nasty
     44 * conflicts with Qt. Therefore we use the following hack
     45 * to redefine those conflicting identifiers. */
    4246#define XK_XKB_KEYS
    4347#define XK_MISCELLANY
     
    5660#endif
    5761#include "XKeyboard.h"
    58 QMap<QString, QString> QIHotKeyEdit::keyNames;
     62QMap <QString, QString> QIHotKeyEdit::sKeyNames;
    5963#endif
    6064
     
    6468
    6569
    66 #ifdef Q_WS_WIN32
     70#if defined (Q_WS_WIN32)
    6771/**
    6872 *  Returns the correct modifier vkey for the *last* keyboard message,
     
    7175 *  unchanged.
    7276 */
    73 int qi_distinguish_modifier_vkey( WPARAM wParam )
     77int qi_distinguish_modifier_vkey (WPARAM wParam)
    7478{
    7579    int keyval = wParam;
    76     switch ( wParam ) {
     80    switch (wParam)
     81    {
    7782        case VK_SHIFT:
    78             if ( ::GetKeyState( VK_LSHIFT ) & 0x8000 ) keyval = VK_LSHIFT;
    79             else if ( ::GetKeyState( VK_RSHIFT ) & 0x8000 ) keyval = VK_RSHIFT;
     83            if (::GetKeyState (VK_LSHIFT) & 0x8000) keyval = VK_LSHIFT;
     84            else if (::GetKeyState (VK_RSHIFT) & 0x8000) keyval = VK_RSHIFT;
    8085            break;
    8186        case VK_CONTROL:
    82             if ( ::GetKeyState( VK_LCONTROL ) & 0x8000 ) keyval = VK_LCONTROL;
    83             else if ( ::GetKeyState( VK_RCONTROL ) & 0x8000 ) keyval = VK_RCONTROL;
     87            if (::GetKeyState (VK_LCONTROL) & 0x8000) keyval = VK_LCONTROL;
     88            else if (::GetKeyState (VK_RCONTROL) & 0x8000) keyval = VK_RCONTROL;
    8489            break;
    8590        case VK_MENU:
    86             if ( ::GetKeyState( VK_LMENU ) & 0x8000 ) keyval = VK_LMENU;
    87             else if ( ::GetKeyState( VK_RMENU ) & 0x8000 ) keyval = VK_RMENU;
     91            if (::GetKeyState (VK_LMENU) & 0x8000) keyval = VK_LMENU;
     92            else if (::GetKeyState (VK_RMENU) & 0x8000) keyval = VK_RMENU;
    8893            break;
    8994    }
     
    97102 */
    98103
    99 const char *QIHotKeyEdit::NoneSymbName = "<none>";
    100 
    101 QIHotKeyEdit::QIHotKeyEdit( QWidget * parent, const char * name ) :
    102     QLabel( parent, name )
     104const char *QIHotKeyEdit::kNoneSymbName = "<none>";
     105
     106QIHotKeyEdit::QIHotKeyEdit (QWidget *aParent, const char *aName) :
     107    QLabel (aParent, aName)
    103108{
    104109#ifdef Q_WS_X11
    105110    // initialize the X keyboard subsystem
    106     initXKeyboard( this->x11Display() );
     111    initXKeyboard (this->x11Display());
    107112#endif
    108113
    109114    clear();
    110115
    111     setFrameStyle( LineEditPanel | Sunken );
    112     setAlignment( AlignHCenter | AlignBottom );
    113     setFocusPolicy( StrongFocus );
     116    setFrameStyle (LineEditPanel | Sunken);
     117    setAlignment (AlignHCenter | AlignBottom);
     118    setFocusPolicy (StrongFocus);
    114119
    115120    QPalette p = palette();
    116     p.setColor( QPalette::Active, QColorGroup::Foreground,
    117         p.color( QPalette::Active, QColorGroup::HighlightedText )
    118     );
    119     p.setColor( QPalette::Active, QColorGroup::Background,
    120         p.color( QPalette::Active, QColorGroup::Highlight )
    121     );
    122     p.setColor( QPalette::Inactive, QColorGroup::Foreground,
    123         p.color( QPalette::Active, QColorGroup::Text )
    124     );
    125     p.setColor( QPalette::Inactive, QColorGroup::Background,
    126         p.color( QPalette::Active, QColorGroup::Base )
    127     );
    128 
    129     true_acg = p.active();
    130     p.setActive( p.inactive() );
    131     setPalette( p );
     121    p.setColor (QPalette::Active, QColorGroup::Foreground,
     122        p.color (QPalette::Active, QColorGroup::HighlightedText));
     123    p.setColor (QPalette::Active, QColorGroup::Background,
     124        p.color (QPalette::Active, QColorGroup::Highlight));
     125    p.setColor (QPalette::Inactive, QColorGroup::Foreground,
     126        p.color (QPalette::Active, QColorGroup::Text));
     127    p.setColor (QPalette::Inactive, QColorGroup::Background,
     128        p.color (QPalette::Active, QColorGroup::Base));
     129
     130    mTrueACG = p.active();
     131    p.setActive (p.inactive());
     132    setPalette (p);
    132133
    133134#ifdef Q_WS_MAC
    134     m_darwinKeyModifiers = GetCurrentEventKeyModifiers();
     135    mDarwinKeyModifiers = GetCurrentEventKeyModifiers();
    135136
    136137    EventTypeSpec eventTypes[4];
     
    144145    eventTypes[3].eventKind  = kEventRawKeyModifiersChanged;
    145146
    146     EventHandlerUPP eventHandler = ::NewEventHandlerUPP( QIHotKeyEdit::darwinEventHandlerProc );
    147 
    148     m_darwinEventHandlerRef = NULL;
    149     ::InstallApplicationEventHandler( eventHandler, RT_ELEMENTS( eventTypes ), &eventTypes[0],
    150                                       this, &m_darwinEventHandlerRef );
    151     ::DisposeEventHandlerUPP( eventHandler );
    152     ::DarwinGrabKeyboard( false /* just modifiers */ );
    153 
    154 #endif
    155 
     147    EventHandlerUPP eventHandler = ::NewEventHandlerUPP (QIHotKeyEdit::darwinEventHandlerProc);
     148
     149    mDarwinEventHandlerRef = NULL;
     150    ::InstallApplicationEventHandler (eventHandler, RT_ELEMENTS( eventTypes ), &eventTypes[0],
     151                                      this, &mDarwinEventHandlerRef);
     152    ::DisposeEventHandlerUPP (eventHandler);
     153    ::DarwinGrabKeyboard (false /* just modifiers */);
     154#endif
    156155}
    157156
     
    160159#ifdef Q_WS_MAC
    161160    ::DarwinReleaseKeyboard();
    162     ::RemoveEventHandler( m_darwinEventHandlerRef );
    163     m_darwinEventHandlerRef = NULL;
     161    ::RemoveEventHandler (mDarwinEventHandlerRef);
     162    mDarwinEventHandlerRef = NULL;
    164163#endif
    165164}
     
    176175 *      to the keycode.
    177176 */
    178 void QIHotKeyEdit::setKey (int k)
    179 {
    180     keyval = k;
    181     symbname = QIHotKeyEdit::keyName (k);
     177void QIHotKeyEdit::setKey (int aKeyVal)
     178{
     179    mKeyVal = aKeyVal;
     180    mSymbName = QIHotKeyEdit::keyName (aKeyVal);
    182181    updateText();
    183182}
     
    204203    int w = fm.width( 'x' ) * 17; // "some"
    205204    int m = frameWidth() * 2;
    206     return (style().sizeFromContents(QStyle::CT_LineEdit, this,
    207                                      QSize (w + m, h + m)
    208                                      .expandedTo(QApplication::globalStrut())));
     205    return (style().sizeFromContents (QStyle::CT_LineEdit, this,
     206                                      QSize (w + m, h + m)
     207                                      .expandedTo(QApplication::globalStrut())));
    209208}
    210209
     
    222221}
    223222
    224 #if defined(Q_WS_X11)
     223#if defined (Q_WS_PM)
     224/**
     225 *  Returns the virtual key extracted from the QMSG structure.
     226 *
     227 *  This function tries to detect some extra virtual keys definitions missing
     228 *  in PM (like Left Shift, Left Ctrl, Win keys). In all other cases it simply
     229 *  returns SHORT2FROMMP (aMsg->mp2).
     230 *
     231 *  @param aMsg  Pointer to the QMSG structure to extract the virtual key from.
     232 *  @return The extracted virtual key code or zero if there is no virtual key.
     233 */
     234/* static */
     235int QIHotKeyEdit::virtualKey (QMSG *aMsg)
     236{
     237    USHORT f = SHORT1FROMMP (aMsg->mp1);
     238    CHAR scan = CHAR4FROMMP (aMsg->mp1);
     239    USHORT ch = SHORT1FROMMP (aMsg->mp2);
     240    int vkey = (unsigned int) SHORT2FROMMP (aMsg->mp2);
     241
     242    if (f & KC_VIRTUALKEY)
     243    {
     244        /* distinguish Left Shift from Right Shift) */
     245        if (vkey == VK_SHIFT && scan == 0x2A)
     246            vkey = VK_LSHIFT;
     247        /* distinguish Left Ctrl from Right Ctrl */
     248        else if (vkey == VK_CTRL && scan == 0x1D)
     249            vkey = VK_LCTRL;
     250        /* distinguish Ctrl+ScrLock from Ctrl+Break */
     251        else if (vkey == VK_BREAK && scan == 0x46 && f & KC_CTRL)
     252            vkey = VK_SCRLLOCK;
     253    }
     254    else if (!(f & KC_CHAR))
     255    {
     256        /* detect some special keys that have a pseudo char code in the high
     257         * byte of ch (probably this is less device-dependent than
     258         * scancode) */
     259        switch (ch)
     260        {
     261            case 0xEC00: vkey = VK_LWIN; break;
     262            case 0xED00: vkey = VK_RWIN; break;
     263            case 0xEE00: vkey = VK_WINMENU; break;
     264            case 0xF900: vkey = VK_FORWARD; break;
     265            case 0xFA00: vkey = VK_BACKWARD; break;
     266            default: vkey = 0;
     267        }
     268    }
     269
     270    return vkey;
     271}
     272#endif
     273
     274#if defined (Q_WS_PM)
    225275/**
    226  * Updates the associative array containing the translations of X11 key strings to human
    227  * readable key names.
    228  */
    229 // static
    230 void QIHotKeyEdit::languageChange(void)
    231 {
    232     keyNames ["Shift_L"]          = tr ("Left Shift");
    233     keyNames ["Shift_R"]          = tr ("Right Shift");
    234     keyNames ["Control_L"]        = tr ("Left Ctrl");
    235     keyNames ["Control_R"]        = tr ("Right Ctrl");
    236     keyNames ["Alt_L"]            = tr ("Left Alt");
    237     keyNames ["Alt_R"]            = tr ("Right Alt");
    238     keyNames ["Super_L"]          = tr ("Left WinKey");
    239     keyNames ["Super_R"]          = tr ("Right WinKey");
    240     keyNames ["Menu"]             = tr ("Menu key");
    241     keyNames ["ISO_Level3_Shift"] = tr ("Alt Gr");
    242     keyNames ["Caps_Lock"]        = tr ("Caps Lock");
    243     keyNames ["Scroll_Lock"]      = tr ("Scroll Lock");
     276 *  Updates the associative array containing the translations of PM virtual
     277 *  keys to human readable key names.
     278 */
     279/* static */
     280void QIHotKeyEdit::languageChange()
     281{
     282    /* Note: strings for the same key must match strings in languageChange()
     283     * versions for all platforms, to keep translators happy. */
     284
     285    sKeyNames [VK_LSHIFT]        = tr ("Left Shift");
     286    sKeyNames [VK_SHIFT]         = tr ("Right Shift");
     287    sKeyNames [VK_LCTRL]         = tr ("Left Ctrl");
     288    sKeyNames [VK_CTRL]          = tr ("Right Ctrl");
     289    sKeyNames [VK_ALT]           = tr ("Left Alt");
     290    sKeyNames [VK_ALTGRAF]       = tr ("Right Alt");
     291    sKeyNames [VK_LWIN]          = tr ("Left WinKey");
     292    sKeyNames [VK_RWIN]          = tr ("Right WinKey");
     293    sKeyNames [VK_WINMENU]       = tr ("Menu key");
     294    sKeyNames [VK_CAPSLOCK]      = tr ("Caps Lock");
     295    sKeyNames [VK_SCRLLOCK]      = tr ("Scroll Lock");
     296
     297    sKeyNames [VK_PAUSE]         = tr ("Pause");
     298    sKeyNames [VK_PRINTSCRN]     = tr ("Print Screen");
     299
     300    sKeyNames [VK_F1]            = tr ("F1");
     301    sKeyNames [VK_F2]            = tr ("F2");
     302    sKeyNames [VK_F3]            = tr ("F3");
     303    sKeyNames [VK_F4]            = tr ("F4");
     304    sKeyNames [VK_F5]            = tr ("F5");
     305    sKeyNames [VK_F6]            = tr ("F6");
     306    sKeyNames [VK_F7]            = tr ("F7");
     307    sKeyNames [VK_F8]            = tr ("F8");
     308    sKeyNames [VK_F9]            = tr ("F9");
     309    sKeyNames [VK_F10]           = tr ("F10");
     310    sKeyNames [VK_F11]           = tr ("F11");
     311    sKeyNames [VK_F12]           = tr ("F12");
     312    sKeyNames [VK_F13]           = tr ("F13");
     313    sKeyNames [VK_F14]           = tr ("F14");
     314    sKeyNames [VK_F15]           = tr ("F15");
     315    sKeyNames [VK_F16]           = tr ("F16");
     316    sKeyNames [VK_F17]           = tr ("F17");
     317    sKeyNames [VK_F18]           = tr ("F18");
     318    sKeyNames [VK_F19]           = tr ("F19");
     319    sKeyNames [VK_F20]           = tr ("F20");
     320    sKeyNames [VK_F21]           = tr ("F21");
     321    sKeyNames [VK_F22]           = tr ("F22");
     322    sKeyNames [VK_F23]           = tr ("F23");
     323    sKeyNames [VK_F24]           = tr ("F24");
     324
     325    sKeyNames [VK_NUMLOCK]       = tr ("Num Lock");
     326    sKeyNames [VK_FORWARD]       = tr ("Forward");
     327    sKeyNames [VK_BACKWARD]      = tr ("Back");
     328}
     329#elif defined (Q_WS_X11)
     330/**
     331 *  Updates the associative array containing the translations of X11 key strings to human
     332 *  readable key names.
     333 */
     334/* static */
     335void QIHotKeyEdit::languageChange()
     336{
     337    /* Note: strings for the same key must match strings in languageChange()
     338     * versions for all platforms, to keep translators happy. */
     339
     340    sKeyNames ["Shift_L"]          = tr ("Left Shift");
     341    sKeyNames ["Shift_R"]          = tr ("Right Shift");
     342    sKeyNames ["Control_L"]        = tr ("Left Ctrl");
     343    sKeyNames ["Control_R"]        = tr ("Right Ctrl");
     344    sKeyNames ["Alt_L"]            = tr ("Left Alt");
     345    sKeyNames ["Alt_R"]            = tr ("Right Alt");
     346    sKeyNames ["Super_L"]          = tr ("Left WinKey");
     347    sKeyNames ["Super_R"]          = tr ("Right WinKey");
     348    sKeyNames ["Menu"]             = tr ("Menu key");
     349    sKeyNames ["ISO_Level3_Shift"] = tr ("Alt Gr");
     350    sKeyNames ["Caps_Lock"]        = tr ("Caps Lock");
     351    sKeyNames ["Scroll_Lock"]      = tr ("Scroll Lock");
    244352}
    245353#endif
     
    253361 *      to the keycode.
    254362 */
    255 // static
    256 QString QIHotKeyEdit::keyName (int key)
     363/* static */
     364QString QIHotKeyEdit::keyName (int aKeyVal)
    257365{
    258366    QString name;
    259367
    260     if ( !key )
    261     {
    262         name = tr (NoneSymbName);
     368    if (!aKeyVal)
     369    {
     370        name = tr (kNoneSymbName);
    263371    }
    264372    else
     
    269377         * hand. */
    270378        int scan;
    271         switch (key)
     379        switch (aKeyVal)
    272380        {
    273381            case VK_RSHIFT: scan = 0x36 << 16; break;
    274382            case VK_RCONTROL: scan = (0x1D << 16) | (1 << 24); break;
    275383            case VK_RMENU: scan = (0x38 << 16) | (1 << 24); break;
    276             default: scan = ::MapVirtualKey( key, 0 ) << 16;
     384            default: scan = ::MapVirtualKey (aKeyVal, 0) << 16;
    277385        }
    278386        TCHAR *str = new TCHAR[256];
    279387        if (::GetKeyNameText (scan, str, 256))
     388        {
    280389            name = QString::fromUcs2 (str);
     390        }
    281391        else
    282             name = QString (tr ("<key_%1>")).arg (key);
     392        {
     393            AssertFailed();
     394            name = QString (tr ("<key_%1>")).arg (aKeyVal);
     395        }
    283396        delete[] str;
     397#elif defined (Q_WS_PM)
     398        name = sKeyNames [aKeyVal];
     399        if (name.isNull())
     400        {
     401            AssertFailed();
     402            name = QString (tr ("<key_%1>")).arg (aKeyVal);
     403        }
    284404#elif defined (Q_WS_X11)
    285         char *sn = ::XKeysymToString( (KeySym) key );
     405        char *sn = ::XKeysymToString ((KeySym) aKeyVal);
    286406        if (sn)
    287407        {
    288             name = keyNames [sn];
     408            name = sKeyNames [sn];
    289409            if (name.isEmpty())
    290410                name = sn;
    291411        }
    292412        else
    293             name = QString (tr ("<key_%1>")).arg (key);
     413        {
     414            AssertFailed();
     415            name = QString (tr ("<key_%1>")).arg (aKeyVal);
     416        }
    294417#elif defined(Q_WS_MAC)
    295         UInt32 modMask = DarwinKeyCodeToDarwinModifierMask (key);
     418        UInt32 modMask = DarwinKeyCodeToDarwinModifierMask (aKeyVal);
    296419        switch (modMask)
    297420        {
     
    331454        }
    332455#else
    333         name = QString ("<key_%1>").arg (key);
     456        AssertFailed();
     457        name = QString (tr ("<key_%1>")).arg (aKeyVal);
    334458#endif
    335459    }
     
    338462}
    339463
    340 // static
    341 bool QIHotKeyEdit::isValidKey( int k )
     464/* static */
     465bool QIHotKeyEdit::isValidKey (int aKeyVal)
    342466{
    343467#if defined(Q_WS_WIN32)
    344468    return (
    345         (k >= VK_SHIFT && k <= VK_CAPITAL) ||
    346         k == VK_PRINT ||
    347         k == VK_LWIN || k == VK_RWIN ||
    348         k == VK_APPS ||
    349         (k >= VK_F1 && k <= VK_F24) ||
    350         k == VK_NUMLOCK || k == VK_SCROLL ||
    351         (k >= VK_LSHIFT && k <= VK_RMENU)
    352     );
     469        (aKeyVal >= VK_SHIFT && aKeyVal <= VK_CAPITAL) ||
     470        aKeyVal == VK_PRINT ||
     471        aKeyVal == VK_LWIN || aKeyVal == VK_RWIN ||
     472        aKeyVal == VK_APPS ||
     473        (aKeyVal >= VK_F1 && aKeyVal <= VK_F24) ||
     474        aKeyVal == VK_NUMLOCK || aKeyVal == VK_SCROLL ||
     475        (aKeyVal >= VK_LSHIFT && aKeyVal <= VK_RMENU));
     476#elif defined(Q_WS_PM)
     477    return (
     478        (aKeyVal >= VK_SHIFT && aKeyVal <= VK_CAPSLOCK) ||
     479        aKeyVal == VK_PRINTSCRN ||
     480        (aKeyVal >= VK_F1 && aKeyVal <= VK_F24) ||
     481        aKeyVal == VK_NUMLOCK || aKeyVal == VK_SCRLLOCK ||
     482        (aKeyVal >= VK_LSHIFT && aKeyVal <= VK_BACKWARD));
    353483#elif defined(Q_WS_X11)
    354     KeySym ks = (KeySym) k;
     484    KeySym ks = (KeySym) aKeyVal;
    355485    return
    356486        (
     
    359489        ) && (
    360490            ks == XK_Scroll_Lock ||
    361             IsModifierKey( ks ) ||
    362             IsFunctionKey( ks ) ||
    363             IsMiscFunctionKey( ks )
     491            IsModifierKey (ks) ||
     492            IsFunctionKey (ks) ||
     493            IsMiscFunctionKey (ks)
    364494        );
    365495#elif defined(Q_WS_MAC)
    366     UInt32 modMask = ::DarwinKeyCodeToDarwinModifierMask( k );
    367     switch ( modMask ) {
     496    UInt32 modMask = ::DarwinKeyCodeToDarwinModifierMask (aKeyVal);
     497    switch (modMask)
     498    {
    368499        case shiftKey:
    369500        case optionKey:
     
    379510    }
    380511#else
    381     Q_UNUSED( k );
     512    Q_UNUSED (aKeyVal);
    382513    return true;
    383514#endif
     
    389520void QIHotKeyEdit::clear()
    390521{
    391     keyval = 0;
    392     symbname = tr (NoneSymbName);
     522    mKeyVal = 0;
     523    mSymbName = tr (kNoneSymbName);
    393524    updateText();
    394525}
     
    400531/////////////////////////////////////////////////////////////////////////////
    401532
    402 #if defined(Q_WS_WIN32)
    403 
    404 bool QIHotKeyEdit::winEvent( MSG *msg )
    405 {
    406     if ( !(
    407         msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
    408         msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP ||
    409         msg->message == WM_CHAR || msg->message == WM_SYSCHAR ||
    410         msg->message == WM_DEADCHAR || msg->message == WM_SYSDEADCHAR ||
    411         msg->message == WM_CONTEXTMENU
    412     ) )
     533#if defined (Q_WS_WIN32)
     534
     535bool QIHotKeyEdit::winEvent (MSG *msg)
     536{
     537    if (!(msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
     538          msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP ||
     539          msg->message == WM_CHAR || msg->message == WM_SYSCHAR ||
     540          msg->message == WM_DEADCHAR || msg->message == WM_SYSDEADCHAR ||
     541          msg->message == WM_CONTEXTMENU))
    413542        return false;
    414543
    415     // ignore if not valid hot key
    416     if ( !isValidKey( msg->wParam ) )
     544    /* ignore if not a valid hot key */
     545    if (!isValidKey (msg->wParam))
    417546        return false;
    418547
    419 //    V_DEBUG((
    420 //        "%WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d rzv=%01X ctx=%01d prev=%01d tran=%01d",
    421 //        msg->message, msg->wParam,
    422 //        (msg->lParam & 0xFFFF),
    423 //        ((msg->lParam >> 16) & 0xFF),
    424 //        ((msg->lParam >> 24) & 0x1),
    425 //        ((msg->lParam >> 25) & 0xF),
    426 //        ((msg->lParam >> 29) & 0x1),
    427 //        ((msg->lParam >> 30) & 0x1),
    428 //        ((msg->lParam >> 31) & 0x1)
    429 //    ));
    430 
    431     if ( msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN) {
    432         // determine platform-dependent key
    433         keyval = qi_distinguish_modifier_vkey( msg->wParam );
    434         // determine symbolic name
    435         TCHAR *str = new TCHAR[256];
    436         if ( ::GetKeyNameText( msg->lParam, str, 256 ) )
    437             symbname = QString::fromUcs2( str );
     548#if 0
     549    LogFlow (("%WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d"
     550              "rzv=%01X ctx=%01d prev=%01d tran=%01d\n",
     551              msg->message, msg->wParam,
     552              (msg->lParam & 0xFFFF),
     553              ((msg->lParam >> 16) & 0xFF),
     554              ((msg->lParam >> 24) & 0x1),
     555              ((msg->lParam >> 25) & 0xF),
     556              ((msg->lParam >> 29) & 0x1),
     557              ((msg->lParam >> 30) & 0x1),
     558              ((msg->lParam >> 31) & 0x1)));
     559#endif
     560
     561    if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
     562    {
     563        /* determine platform-dependent key */
     564        mKeyVal = qi_distinguish_modifier_vkey (msg->wParam);
     565        /* determine symbolic name */
     566        TCHAR *str = new TCHAR [256];
     567        if (::GetKeyNameText (msg->lParam, str, 256))
     568        {
     569            mSymbName = QString::fromUcs2 (str);
     570        }
    438571        else
    439             symbname = QString( "<key_%1>" ).arg( keyval );
     572        {
     573            AssertFailed();
     574            mSymbName = QString (tr ("<key_%1>")).arg (mKeyVal);
     575        }
    440576        delete[] str;
    441         // update the display
     577        /* update the display */
    442578        updateText();
    443579    }
     
    446582}
    447583
    448 #elif defined(Q_WS_X11)
    449 
    450 bool QIHotKeyEdit::x11Event( XEvent *event )
    451 {
    452     switch ( event->type ) {
     584#elif defined (Q_WS_PM)
     585
     586bool QIHotKeyEdit::pmEvent (QMSG *aMsg)
     587{
     588    if (aMsg->msg != WM_CHAR)
     589        return false;
     590
     591    USHORT f = SHORT1FROMMP (aMsg->mp1);
     592
     593    int vkey = QIHotKeyEdit::virtualKey (aMsg);
     594
     595    /* ignore if not a valid hot key */
     596    if (!isValidKey (vkey))
     597        return false;
     598
     599    if (!(f & KC_KEYUP))
     600    {
     601        /* determine platform-dependent key */
     602        mKeyVal = vkey;
     603        /* determine symbolic name */
     604        mSymbName = QIHotKeyEdit::keyName (mKeyVal);
     605        /* update the display */
     606        updateText();
     607    }
     608
     609    return true;
     610}
     611
     612#elif defined (Q_WS_X11)
     613
     614bool QIHotKeyEdit::x11Event (XEvent *event)
     615{
     616    switch (event->type)
     617    {
    453618        case XKeyPress:
    454         case XKeyRelease: {
     619        case XKeyRelease:
     620        {
    455621            XKeyEvent *ke = (XKeyEvent *) event;
    456             KeySym ks = ::XKeycodeToKeysym( ke->display, ke->keycode, 0 );
    457             // ignore if not valid hot key
    458             if ( !isValidKey( (int) ks ) )
     622            KeySym ks = ::XKeycodeToKeysym (ke->display, ke->keycode, 0);
     623            /* ignore if not a valid hot key */
     624            if (!isValidKey ((int) ks))
    459625                return false;
    460626
    461             // skip key releases
    462             if ( event->type == XKeyRelease )
     627            /* skip key releases */
     628            if (event->type == XKeyRelease)
    463629                return true;
    464630
    465             // determine platform-dependent key
    466             keyval = (int) ks;
    467             // determine symbolic name
    468             char *name = ::XKeysymToString( ks );
    469             if ( name )
    470             {
    471                 if ( keyNames.contains(name) )
    472                     symbname = keyNames[name];
    473                 else
    474                     symbname = name;
    475             }
    476             else
    477                 symbname = QString( tr ("<key_%1>") ).arg( (int) ks );
    478             // update the display
     631            /* determine platform-dependent key */
     632            mKeyVal = (int) ks;
     633            /* determine symbolic name */
     634            mSymbName = QIHotKeyEdit::keyName (mKeyVal);
     635            /* update the display */
    479636            updateText();
    480 //V_DEBUG((
    481 //    "%s: state=%08X keycode=%08X keysym=%08X symb=%s",
    482 //    event->type == XKeyPress ? "XKeyPress" : "XKeyRelease",
    483 //    ke->state, ke->keycode, ks,
    484 //    symbname.latin1()
    485 //));
     637#if 0
     638            LogFlow (("%s: state=%08X keycode=%08X keysym=%08X symb=%s\n",
     639                      event->type == XKeyPress ? "XKeyPress" : "XKeyRelease",
     640                      ke->state, ke->keycode, ks,
     641                      symbname.latin1()));
     642#endif
    486643            return true;
    487644        }
     
    491648}
    492649
    493 #elif defined(Q_WS_MAC)
     650#elif defined (Q_WS_MAC)
    494651
    495652/* static */
    496 pascal OSStatus QIHotKeyEdit::darwinEventHandlerProc( EventHandlerCallRef inHandlerCallRef,
    497                                                       EventRef inEvent, void *inUserData )
    498 {
    499     QIHotKeyEdit *edit = (QIHotKeyEdit *)inUserData;
    500     UInt32 EventClass = ::GetEventClass( inEvent );
     653pascal OSStatus QIHotKeyEdit::darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,
     654                                                      EventRef inEvent, void *inUserData)
     655{
     656    QIHotKeyEdit *edit = (QIHotKeyEdit *) inUserData;
     657    UInt32 EventClass = ::GetEventClass (inEvent);
    501658    if (EventClass == kEventClassKeyboard)
    502659    {
    503         if (edit->darwinKeyboardEvent( inEvent ))
     660        if (edit->darwinKeyboardEvent (inEvent))
    504661            return 0;
    505662    }
     
    507664}
    508665
    509 bool QIHotKeyEdit::darwinKeyboardEvent( EventRef inEvent )
     666bool QIHotKeyEdit::darwinKeyboardEvent (EventRef inEvent)
    510667{
    511668    /* ignore key changes unless we're the focus widget */
     
    513670        return false;
    514671
    515     UInt32 eventKind = ::GetEventKind( inEvent );
    516     switch ( eventKind ) {
     672    UInt32 eventKind = ::GetEventKind (inEvent);
     673    switch (eventKind)
     674    {
    517675        /*case kEventRawKeyDown:
    518676        case kEventRawKeyUp:
    519677        case kEventRawKeyRepeat:*/
    520         case kEventRawKeyModifiersChanged: {
     678        case kEventRawKeyModifiersChanged:
     679        {
    521680            UInt32 modifierMask = 0;
    522             ::GetEventParameter( inEvent, kEventParamKeyModifiers, typeUInt32, NULL,
    523                                  sizeof( modifierMask ), NULL, &modifierMask );
    524 
    525             modifierMask = ::DarwinAdjustModifierMask(modifierMask);
    526             UInt32 changed = m_darwinKeyModifiers ^ modifierMask;
    527             m_darwinKeyModifiers = modifierMask;
    528 
    529             // skip key releases
    530             if ( changed && ( changed & modifierMask ) )
     681            ::GetEventParameter (inEvent, kEventParamKeyModifiers, typeUInt32, NULL,
     682                                 sizeof (modifierMask), NULL, &modifierMask);
     683
     684            modifierMask = ::DarwinAdjustModifierMask (modifierMask);
     685            UInt32 changed = mDarwinKeyModifiers ^ modifierMask;
     686            mDarwinKeyModifiers = modifierMask;
     687
     688            /* skip key releases */
     689            if (changed && (changed & modifierMask))
    531690                break;
    532691
    533             // convert to keycode and skip keycodes we don't care about.
    534             unsigned keyCode = ::DarwinModifierMaskToDarwinKeycode( changed );
    535             if ( !keyCode || keyCode == ~0U || !isValidKey( keyCode ) )
     692            /* convert to keycode and skip keycodes we don't care about. */
     693            unsigned keyCode = ::DarwinModifierMaskToDarwinKeycode (changed);
     694            if (!keyCode || keyCode == ~0U || !isValidKey (keyCode))
    536695                break;
    537696
    538             // update key current key.
    539             keyval = keyCode;
    540             symbname = QIHotKeyEdit::keyName( keyCode );
     697            /* update key current key. */
     698            mKeyVal = keyCode;
     699            mSymbName = QIHotKeyEdit::keyName (keyCode);
    541700            updateText();
    542701            break; //return true;
     
    551710#endif
    552711
    553 void QIHotKeyEdit::focusInEvent( QFocusEvent * ) {
     712void QIHotKeyEdit::focusInEvent (QFocusEvent *)
     713{
    554714    QPalette p = palette();
    555     p.setActive( true_acg );
    556     setPalette( p );
    557 }
    558 
    559 void QIHotKeyEdit::focusOutEvent( QFocusEvent * ) {
     715    p.setActive (mTrueACG);
     716    setPalette (p);
     717}
     718
     719void QIHotKeyEdit::focusOutEvent (QFocusEvent *)
     720{
    560721    QPalette p = palette();
    561     p.setActive( p.inactive() );
    562     setPalette( p );
    563 }
    564 
    565 void QIHotKeyEdit::drawContents( QPainter * p )
    566 {
    567     QLabel::drawContents( p );
    568     if ( hasFocus() ) {
    569         style().drawPrimitive(
     722    p.setActive (p.inactive());
     723    setPalette (p);
     724}
     725
     726void QIHotKeyEdit::drawContents (QPainter * p)
     727{
     728    QLabel::drawContents (p);
     729    if (hasFocus())
     730    {
     731        style().drawPrimitive (
    570732            QStyle::PE_FocusRect, p, contentsRect(), colorGroup(),
    571733            QStyle::Style_Default,
    572             QStyleOption( colorGroup().background() )
    573         );
     734            QStyleOption( colorGroup().background()));
    574735    }
    575736}
     
    580741void QIHotKeyEdit::updateText()
    581742{
    582     setText( QString( " %1 " ).arg( symbname ) );
    583 }
    584 
     743    setText (QString (" %1 ").arg (mSymbName));
     744}
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r4875 r5132  
    66
    77/*
    8  * Copyright (C) 2006-2007 innotek GmbH
     8 * Copyright (C) 22006-2007 innotek GmbH
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2323#include "VBoxGlobal.h"
    2424#include "VBoxProblemReporter.h"
     25
     26#ifdef Q_WS_PM
     27#include "QIHotKeyEdit.h"
     28#endif
    2529
    2630#include <qapplication.h>
     
    993997            case QEvent::FocusOut:
    994998            {
    995                 focusEvent (false);
     999                if (isRunning())
     1000                    focusEvent (false);
    9961001                break;
    9971002            }
     
    15031508 * Get Win32 messages before they are passed to Qt. This allows us to get
    15041509 * the keyboard events directly and bypass the harmful Qt translation. A
    1505  * return value of TRUE indicates to Qt that the event has been handled.
     1510 * return value of @c true indicates to Qt that the event has been handled.
    15061511 */
    15071512bool VBoxConsoleView::winEvent (MSG *msg)
     
    15181523
    15191524#if 0
    1520     LogFlow (("*** WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d rzv=%01X ctx=%01d prev=%01d tran=%01d",
    1521               msg->message, msg->wParam,
    1522               (msg->lParam & 0xFFFF),
    1523               ((msg->lParam >> 16) & 0xFF),
    1524               ((msg->lParam >> 24) & 0x1),
    1525               ((msg->lParam >> 25) & 0xF),
    1526               ((msg->lParam >> 29) & 0x1),
    1527               ((msg->lParam >> 30) & 0x1),
    1528               ((msg->lParam >> 31) & 0x1)));
    15291525    char buf [256];
    15301526    sprintf (buf, "WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d rzv=%01X ctx=%01d prev=%01d tran=%01d",
     
    15381534             ((msg->lParam >> 31) & 0x1));
    15391535    mainwnd->statusBar()->message (buf);
     1536    LogFlow (("%s\n", buf));
    15401537#endif
    15411538
     
    16041601        ::SendMessage (msg->hwnd, msg->message,
    16051602                       msg->wParam, msg->lParam | (0x1 << 25));
     1603        return true;
     1604    }
     1605    return result;
     1606}
     1607
     1608#elif defined (Q_WS_PM)
     1609
     1610/**
     1611 *  Get PM messages before they are passed to Qt. This allows us to get
     1612 *  the keyboard events directly and bypass the harmful Qt translation. A
     1613 *  return value of @c true indicates to Qt that the event has been handled.
     1614 */
     1615bool VBoxConsoleView::pmEvent (QMSG *aMsg)
     1616{
     1617    if (!attached || aMsg->msg != WM_CHAR)
     1618        return false;
     1619
     1620    /* check for the special flag possibly set at the end of this function */
     1621    if (SHORT2FROMMP (aMsg->mp2) & 0x8000)
     1622        return false;
     1623
     1624#if 0
     1625    {
     1626        char buf [256];
     1627        sprintf (buf, "*** WM_CHAR: f=%04X rep=%03d scan=%02X ch=%04X vk=%04X",
     1628                 SHORT1FROMMP (aMsg->mp1), CHAR3FROMMP (aMsg->mp1),
     1629                 CHAR4FROMMP (aMsg->mp1), SHORT1FROMMP (aMsg->mp2),
     1630                 SHORT2FROMMP (aMsg->mp2));
     1631        mainwnd->statusBar()->message (buf);
     1632        LogFlow (("%s\n", buf));
     1633    }
     1634#endif
     1635
     1636    USHORT ch = SHORT1FROMMP (aMsg->mp2);
     1637    USHORT f = SHORT1FROMMP (aMsg->mp1);
     1638
     1639    int scan = (unsigned int) CHAR4FROMMP (aMsg->mp1);
     1640    if (!scan || scan > 0x7F)
     1641        return true;
     1642
     1643    int vkey = QIHotKeyEdit::virtualKey (aMsg);
     1644
     1645    int flags = 0;
     1646
     1647    if ((ch & 0xFF) == 0xE0)
     1648    {
     1649        flags |= KeyExtended;
     1650        scan = ch >> 8;
     1651    }
     1652    else if (scan == 0x5C && (ch & 0xFF) == '/')
     1653    {
     1654        /* this is the '/' key on the keypad */
     1655        scan = 0x35;
     1656        flags |= KeyExtended;
     1657    }
     1658    else
     1659    {
     1660        /* For some keys, the scan code passed in QMSG is a pseudo scan
     1661         * code. We replace it with a real hardware scan code, according to
     1662         * http://www.computer-engineering.org/ps2keyboard/scancodes1.html.
     1663         * Also detect Pause and PrtScn and set flags. */
     1664        switch (vkey)
     1665        {
     1666            case VK_ENTER:     scan = 0x1C; flags |= KeyExtended; break;
     1667            case VK_CTRL:      scan = 0x1D; flags |= KeyExtended; break;
     1668            case VK_ALTGRAF:   scan = 0x38; flags |= KeyExtended; break;
     1669            case VK_LWIN:      scan = 0x5B; flags |= KeyExtended; break;
     1670            case VK_RWIN:      scan = 0x5C; flags |= KeyExtended; break;
     1671            case VK_WINMENU:   scan = 0x5D; flags |= KeyExtended; break;
     1672            case VK_FORWARD:   scan = 0x69; flags |= KeyExtended; break;
     1673            case VK_BACKWARD:  scan = 0x6A; flags |= KeyExtended; break;
     1674#if 0
     1675            /// @todo this would send 0xE0 0x46 0xE0 0xC6. It's not fully
     1676            // clear what is more correct
     1677            case VK_BREAK:     scan = 0x46; flags |= KeyExtended; break;
     1678#else
     1679            case VK_BREAK:     scan = 0;    flags |= KeyPause; break;
     1680#endif
     1681            case VK_PAUSE:     scan = 0;    flags |= KeyPause;    break;
     1682            case VK_PRINTSCRN: scan = 0;    flags |= KeyPrint;    break;
     1683            default:;
     1684        }
     1685    }
     1686
     1687    if (!(f & KC_KEYUP))
     1688        flags |= KeyPressed;
     1689
     1690    bool result = keyEvent (vkey, scan, flags);
     1691    if (!result && kbd_captured)
     1692    {
     1693        /* keyEvent() returned that it didn't process the message, but since the
     1694         * keyboard is captured, we don't want to pass it to PM. We just want
     1695         * to let Qt process the message (to handle non-alphanumeric <HOST>+key
     1696         * shortcuts for example). So send it direcltly to the window with the
     1697         * special flag in the reserved area of lParam (to avoid recursion). */
     1698        ::WinSendMsg (aMsg->hwnd, aMsg->msg,
     1699                      aMsg->mp1,
     1700                      MPFROM2SHORT (SHORT1FROMMP (aMsg->mp2),
     1701                                    SHORT2FROMMP (aMsg->mp2) | 0x8000));
    16061702        return true;
    16071703    }
     
    18291925}
    18301926
    1831 #endif
     1927#endif // defined (Q_WS_WIN)
    18321928
    18331929//
     
    19722068 *  @return     true to consume the event and false to pass it to Qt
    19732069 */
    1974 bool VBoxConsoleView::keyEvent (int key, uint8_t scan, int flags, wchar_t *aUniKey/* = NULL*/)
    1975 {
    1976 //    char bbbuf[256];
    1977 //    sprintf (bbbuf,
    1978 //             "key=%08X scan=%02X flags=%08X",
    1979 //             key, scan, flags);
    1980 //    ((QMainWindow*)mainwnd)->statusBar()->message (bbbuf);
    1981 
    1982     const bool is_hostkey = key == gs.hostKey();
     2070bool VBoxConsoleView::keyEvent (int aKey, uint8_t aScan, int aFlags,
     2071                                wchar_t *aUniKey/* = NULL*/)
     2072{
     2073#if 0
     2074    {
     2075        char buf [256];
     2076        sprintf (buf, "aKey=%08X aScan=%02X aFlags=%08X",
     2077                 aKey, aScan, aFlags);
     2078        mainwnd->statusBar()->message (buf);
     2079    }
     2080#endif
     2081
     2082    const bool isHostKey = aKey == gs.hostKey();
    19832083
    19842084    LONG buf [16];
    19852085    LONG *codes = buf;
    19862086    uint count = 0;
    1987     uint8_t what_pressed = 0;
    1988 
    1989     if (!is_hostkey)
    1990     {
    1991         if (flags & KeyPrint)
     2087    uint8_t whatPressed = 0;
     2088
     2089    if (!isHostKey)
     2090    {
     2091        if (aFlags & KeyPrint)
    19922092        {
    19932093            static LONG PrintMake[] = { 0xE0, 0x2A, 0xE0, 0x37 };
    19942094            static LONG PrintBreak[] = { 0xE0, 0xB7, 0xE0, 0xAA };
    1995             if (flags & KeyPressed)
     2095            if (aFlags & KeyPressed)
    19962096            {
    19972097                codes = PrintMake;
     
    20042104            }
    20052105        }
    2006         else if ((flags & (KeyPause | KeyPressed)) == (KeyPause | KeyPressed))
    2007         {
    2008             static LONG Pause[] = { 0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5 };
    2009             codes = Pause;
    2010             count = SIZEOF_ARRAY (Pause);
     2106        else if (aFlags & KeyPause)
     2107        {
     2108            if (aFlags & KeyPressed)
     2109            {
     2110                static LONG Pause[] = { 0xE1, 0x1D, 0x45, 0xE1, 0x9D, 0xC5 };
     2111                codes = Pause;
     2112                count = SIZEOF_ARRAY (Pause);
     2113            }
     2114            else
     2115            {
     2116                /* Pause shall not produce a break code */
     2117                return true;
     2118            }
    20112119        }
    20122120        else
    20132121        {
    2014             if (flags & KeyPressed)
    2015             {
    2016                 // Check if the guest has the same view on the modifier keys (NumLock,
    2017                 // CapsLock, ScrollLock) as the X server. If not, send KeyPress events
    2018                 // to synchronize the state.
     2122            if (aFlags & KeyPressed)
     2123            {
     2124                /* Check if the guest has the same view on the modifier keys (NumLock,
     2125                 * CapsLock, ScrollLock) as the X server. If not, send KeyPress events
     2126                 * to synchronize the state. */
    20192127                fixModifierState (codes, &count);
    20202128            }
    20212129
    2022             // process the scancode and update the table of pressed keys
    2023             what_pressed = IsKeyPressed;
    2024 
    2025             if (flags & KeyExtended)
     2130            /* process the scancode and update the table of pressed keys */
     2131            whatPressed = IsKeyPressed;
     2132
     2133            if (aFlags & KeyExtended)
    20262134            {
    20272135                codes [count++] = 0xE0;
    2028                 what_pressed = IsExtKeyPressed;
    2029             }
    2030 
    2031             if (flags & KeyPressed)
    2032             {
    2033                 codes [count++] = scan;
    2034                 keys_pressed [scan] |= what_pressed;
     2136                whatPressed = IsExtKeyPressed;
     2137            }
     2138
     2139            if (aFlags & KeyPressed)
     2140            {
     2141                codes [count++] = aScan;
     2142                keys_pressed [aScan] |= whatPressed;
    20352143            }
    20362144            else
    20372145            {
    2038                 // if we haven't got this key's press message, we ignore its release
    2039                 if (!(keys_pressed [scan] & what_pressed))
     2146                /* if we haven't got this key's press message, we ignore its
     2147                 * release */
     2148                if (!(keys_pressed [aScan] & whatPressed))
    20402149                    return true;
    2041                 codes [count++] = scan | 0x80;
    2042                 keys_pressed [scan] &= ~what_pressed;
     2150                codes [count++] = aScan | 0x80;
     2151                keys_pressed [aScan] &= ~whatPressed;
    20432152            }
    20442153
    20452154            if (kbd_captured)
    2046                 keys_pressed [scan] |= IsKbdCaptured;
     2155                keys_pressed [aScan] |= IsKbdCaptured;
    20472156            else
    2048                 keys_pressed [scan] &= ~IsKbdCaptured;
     2157                keys_pressed [aScan] &= ~IsKbdCaptured;
    20492158        }
    20502159    }
    20512160    else
    20522161    {
    2053         // currently this is used in winLowKeyboardEvent() only
     2162        /* currently this is used in winLowKeyboardEvent() only */
    20542163        hostkey_in_capture = kbd_captured;
    20552164    }
     
    20582167    int hotkey = 0;
    20592168
    2060     // process the host key
    2061     if (flags & KeyPressed)
    2062     {
    2063         if (is_hostkey)
     2169    /* process the host key */
     2170    if (aFlags & KeyPressed)
     2171    {
     2172        if (isHostKey)
    20642173        {
    20652174            if (!hostkey_pressed)
     
    20772186                if (hostkey_alone)
    20782187                {
    2079                     hotkey = key;
     2188                    hotkey = aKey;
    20802189                    hostkey_alone = false;
    20812190                }
     
    20852194    else
    20862195    {
    2087         if (is_hostkey)
     2196        if (isHostKey)
    20882197        {
    20892198            if (hostkey_pressed)
     
    21182227        }
    21192228    }
    2120     // emit the keyboard state change signal
     2229
     2230    /* emit the keyboard state change signal */
    21212231    if (emit_signal)
    21222232        emitKeyboardStateChanged();
    21232233
    2124     // process HOST+<key> shortcuts. currently, <key> is limited to
    2125     // alphanumeric chars.
     2234    /* process HOST+<key> shortcuts. currently, <key> is limited to
     2235     * alphanumeric chars. */
    21262236    if (hotkey)
    21272237    {
     
    21492259        Display *display = x11Display();
    21502260        int keysyms_per_keycode = getKeysymsPerKeycode();
    2151         KeyCode kc = XKeysymToKeycode (display, key);
     2261        KeyCode kc = XKeysymToKeycode (display, aKey);
    21522262        // iterate over the first level (not shifted) keysyms in every group
    21532263        for (int i = 0; i < keysyms_per_keycode && !processed; i += 2)
     
    21712281                                       mainwnd->menuBar());
    21722282
    2173         /* Don't consider the hot key as pressed since the guest never saw it. (probably a generic thing) */
    2174         keys_pressed [scan] &= ~what_pressed;
    2175 #endif
    2176 
    2177         // grab the key from Qt if processed, or pass it to Qt otherwise
    2178         // in order to process non-alphanumeric keys in event(), after they are
    2179         // converted to Qt virtual keys.
     2283        /* Don't consider the hot key as pressed since the guest never saw
     2284         * it. (probably a generic thing) */
     2285        keys_pressed [aScan] &= ~whatPressed;
     2286#endif
     2287
     2288        /* grab the key from Qt if processed, or pass it to Qt otherwise
     2289         * in order to process non-alphanumeric keys in event(), after they are
     2290         * converted to Qt virtual keys. */
    21802291        return processed;
    21812292    }
    21822293
    2183     // no more to do, if the host key is in action or the VM is paused
    2184     if (hostkey_pressed || is_hostkey || isPaused())
    2185     {
    2186         // grab the key from Qt and from VM if it's a host key,
    2187         // otherwise just pass it to Qt
    2188         return is_hostkey;
     2294    /* no more to do, if the host key is in action or the VM is paused */
     2295    if (hostkey_pressed || isHostKey || isPaused())
     2296    {
     2297        /* grab the key from Qt and from VM if it's a host key,
     2298         * otherwise just pass it to Qt */
     2299        return isHostKey;
    21892300    }
    21902301
     
    21932304
    21942305#if defined (Q_WS_WIN32)
    2195     // send pending WM_PAINT events
     2306    /* send pending WM_PAINT events */
    21962307    ::UpdateWindow (viewport()->winId());
    21972308#endif
    21982309
    2199 //    LogFlow (("*** Putting scan codes: "));
    2200 //    for (unsigned i = 0; i < count; i++)
    2201 //        LogFlow (("%02x ", codes [i]));
    2202 //    LogFlow (("\n"));
     2310#if 0
     2311    {
     2312        char buf [256];
     2313        sprintf (buf, "*** SCANS: ");
     2314        for (uint i = 0; i < count; ++ i)
     2315            sprintf (buf + strlen (buf), "%02X ", codes [i]);
     2316        mainwnd->statusBar()->message (buf);
     2317        LogFlow (("%s\n", buf));
     2318    }
     2319#endif
    22032320
    22042321    keyboard.PutScancodes (codes, count);
    22052322
    2206     // grab the key from Qt
     2323    /* grab the key from Qt */
    22072324    return true;
    22082325}
     
    22252342             aType, aPos.x(), aPos.y(), aButton, aState, aStateAfter,
    22262343             aWheelDelta, aWheelDir);
    2227     ((QMainWindow*)mainwnd)->statusBar()->message (buf);
     2344    mainwnd->statusBar()->message (buf);
    22282345#else
    22292346    Q_UNUSED (aButton);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r5128 r5132  
    21382138    detailReportTemplatesReady = false;
    21392139
    2140 #if defined (Q_WS_X11)
    2141     /* As X11 does not (to my knowledge) have functionality for providing
     2140#if defined (Q_WS_PM) || defined (Q_WS_X11)
     2141    /* As PM and X11 do not (to my knowledge) have functionality for providing
    21422142     * human readable key names, we keep a table of them, which must be
    21432143     * updated when the language is changed. */
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobalSettings.cpp

    r4071 r5132  
    3939    hostkey = 0xA3; // VK_RCONTROL
    4040//    hostkey = 165; // VK_RMENU
     41#elif defined (Q_WS_PM)
     42    hostkey = VK_CTRL;
    4143#elif defined (Q_WS_X11)
    4244    hostkey = 0xffe4; // XK_Control_R
     
    5658}
    5759
    58 VBoxGlobalSettingsData::VBoxGlobalSettingsData( const VBoxGlobalSettingsData &that ) {
     60VBoxGlobalSettingsData::VBoxGlobalSettingsData (const VBoxGlobalSettingsData &that)
     61{
    5962    hostkey = that.hostkey;
    6063    autoCapture = that.autoCapture;
     
    6770}
    6871
    69 bool VBoxGlobalSettingsData::operator==( const VBoxGlobalSettingsData &that ) const
    70 {
    71     return this == &that || (
    72         hostkey == that.hostkey &&
    73         autoCapture == that.autoCapture &&
    74         guiFeatures == that.guiFeatures &&
    75         languageId  == that.languageId
    76     );
     72bool VBoxGlobalSettingsData::operator== (const VBoxGlobalSettingsData &that) const
     73{
     74    return this == &that ||
     75        (hostkey == that.hostkey &&
     76         autoCapture == that.autoCapture &&
     77         guiFeatures == that.guiFeatures &&
     78         languageId  == that.languageId);
    7779}
    7880
     
    253255        if (ok)
    254256        {
     257            /* The individual setter may have set a specific error */
     258            if (!last_err.isNull())
     259                return;
     260
    255261            last_err = QString::null;
    256262            emit propertyChanged (gPropertyMap [index].publicName,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette