Changeset 5132 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Oct 1, 2007 9:41:31 PM (17 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/QIHotKeyEdit.h
r4071 r5132 28 28 #endif 29 29 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 30 40 31 41 class QIHotKeyEdit : public QLabel … … 35 45 public: 36 46 37 QIHotKeyEdit ( QWidget * parent, const char * name = 0);47 QIHotKeyEdit (QWidget *aParent, const char *aName = 0); 38 48 virtual ~QIHotKeyEdit(); 39 49 40 void setKey ( int keyval);41 int key() const { return keyval; }50 void setKey (int aKeyVal); 51 int key() const { return mKeyVal; } 42 52 43 QString symbolicName() const { return symbname; }53 QString symbolicName() const { return mSymbName; } 44 54 45 55 QSize sizeHint() const; 46 56 QSize minimumSizeHint() const; 47 57 48 #if defined (Q_WS_X11)49 static void languageChange(void);58 #if defined (Q_WS_PM) 59 static int virtualKey (QMSG *aMsg); 50 60 #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); 53 67 54 68 public slots: … … 58 72 protected: 59 73 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); 68 84 #endif 69 85 70 void focusInEvent ( QFocusEvent *);71 void focusOutEvent ( QFocusEvent *);86 void focusInEvent (QFocusEvent *); 87 void focusOutEvent (QFocusEvent *); 72 88 73 void drawContents ( QPainter * p);89 void drawContents (QPainter *p); 74 90 75 91 private: … … 77 93 void updateText(); 78 94 79 int keyval;80 QString symbname;95 int mKeyVal; 96 QString mSymbName; 81 97 82 QColorGroup true_acg;98 QColorGroup mTrueACG; 83 99 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; 86 104 #endif 87 105 88 #if defined (Q_WS_MAC)106 #if defined (Q_WS_MAC) 89 107 /** Event handler reference. NULL if the handler isn't installed. */ 90 EventHandlerRef m _darwinEventHandlerRef;108 EventHandlerRef mDarwinEventHandlerRef; 91 109 /** The current modifier key mask. Used to figure out which modifier 92 110 * key was pressed when we get a kEventRawKeyModifiersChanged event. */ 93 UInt32 m _darwinKeyModifiers;111 UInt32 mDarwinKeyModifiers; 94 112 #endif 95 113 96 static const char * NoneSymbName;114 static const char *kNoneSymbName; 97 115 }; 98 116 -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h
r4514 r5132 110 110 111 111 // 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); 114 114 115 115 #if defined(Q_WS_WIN32) 116 116 bool winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event); 117 117 bool winEvent (MSG *msg); 118 #elif defined(Q_WS_PM) 119 bool pmEvent (QMSG *aMsg); 118 120 #elif defined(Q_WS_X11) 119 bool x11Event (XEvent *event 121 bool x11Event (XEvent *event); 120 122 #elif defined(Q_WS_MAC) 121 123 bool darwinKeyboardEvent (EventRef inEvent); … … 125 127 private: 126 128 127 / / flags for keyEvent()129 /** Flags for keyEvent(). */ 128 130 enum { 129 131 KeyExtended = 0x01, … … 134 136 135 137 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); 137 140 bool mouseEvent (int aType, const QPoint &aPos, const QPoint &aGlobalPos, 138 141 ButtonState aButton, -
trunk/src/VBox/Frontends/VirtualBox/src/QIHotKeyEdit.cpp
r4071 r5132 26 26 27 27 #ifdef Q_WS_WIN 28 / / VBox/cdefs.h defines these:28 /* VBox/cdefs.h defines these: */ 29 29 #undef LOWORD 30 30 #undef HIWORD … … 34 34 #endif 35 35 36 #if defined (Q_WS_PM) 37 QMap <int, QString> QIHotKeyEdit::sKeyNames; 38 #endif 39 36 40 #ifdef Q_WS_X11 37 / /We need to capture some X11 events directly which38 //requires the XEvent structure to be defined. However,39 //including the Xlib header file will cause some nasty40 //conflicts with Qt. Therefore we use the following hack41 // 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. */ 42 46 #define XK_XKB_KEYS 43 47 #define XK_MISCELLANY … … 56 60 #endif 57 61 #include "XKeyboard.h" 58 QMap <QString, QString> QIHotKeyEdit::keyNames;62 QMap <QString, QString> QIHotKeyEdit::sKeyNames; 59 63 #endif 60 64 … … 64 68 65 69 66 #if def Q_WS_WIN3270 #if defined (Q_WS_WIN32) 67 71 /** 68 72 * Returns the correct modifier vkey for the *last* keyboard message, … … 71 75 * unchanged. 72 76 */ 73 int qi_distinguish_modifier_vkey ( WPARAM wParam)77 int qi_distinguish_modifier_vkey (WPARAM wParam) 74 78 { 75 79 int keyval = wParam; 76 switch ( wParam ) { 80 switch (wParam) 81 { 77 82 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; 80 85 break; 81 86 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; 84 89 break; 85 90 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; 88 93 break; 89 94 } … … 97 102 */ 98 103 99 const char *QIHotKeyEdit:: NoneSymbName = "<none>";100 101 QIHotKeyEdit::QIHotKeyEdit ( QWidget * parent, const char * name) :102 QLabel ( parent, name)104 const char *QIHotKeyEdit::kNoneSymbName = "<none>"; 105 106 QIHotKeyEdit::QIHotKeyEdit (QWidget *aParent, const char *aName) : 107 QLabel (aParent, aName) 103 108 { 104 109 #ifdef Q_WS_X11 105 110 // initialize the X keyboard subsystem 106 initXKeyboard ( this->x11Display());111 initXKeyboard (this->x11Display()); 107 112 #endif 108 113 109 114 clear(); 110 115 111 setFrameStyle ( LineEditPanel | Sunken);112 setAlignment ( AlignHCenter | AlignBottom);113 setFocusPolicy ( StrongFocus);116 setFrameStyle (LineEditPanel | Sunken); 117 setAlignment (AlignHCenter | AlignBottom); 118 setFocusPolicy (StrongFocus); 114 119 115 120 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); 132 133 133 134 #ifdef Q_WS_MAC 134 m _darwinKeyModifiers = GetCurrentEventKeyModifiers();135 mDarwinKeyModifiers = GetCurrentEventKeyModifiers(); 135 136 136 137 EventTypeSpec eventTypes[4]; … … 144 145 eventTypes[3].eventKind = kEventRawKeyModifiersChanged; 145 146 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 156 155 } 157 156 … … 160 159 #ifdef Q_WS_MAC 161 160 ::DarwinReleaseKeyboard(); 162 ::RemoveEventHandler ( m_darwinEventHandlerRef);163 m _darwinEventHandlerRef = NULL;161 ::RemoveEventHandler (mDarwinEventHandlerRef); 162 mDarwinEventHandlerRef = NULL; 164 163 #endif 165 164 } … … 176 175 * to the keycode. 177 176 */ 178 void QIHotKeyEdit::setKey (int k)179 { 180 keyval = k;181 symbname = QIHotKeyEdit::keyName (k);177 void QIHotKeyEdit::setKey (int aKeyVal) 178 { 179 mKeyVal = aKeyVal; 180 mSymbName = QIHotKeyEdit::keyName (aKeyVal); 182 181 updateText(); 183 182 } … … 204 203 int w = fm.width( 'x' ) * 17; // "some" 205 204 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()))); 209 208 } 210 209 … … 222 221 } 223 222 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 */ 235 int 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) 225 275 /** 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 */ 280 void 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 */ 335 void 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"); 244 352 } 245 353 #endif … … 253 361 * to the keycode. 254 362 */ 255 / / static256 QString QIHotKeyEdit::keyName (int key)363 /* static */ 364 QString QIHotKeyEdit::keyName (int aKeyVal) 257 365 { 258 366 QString name; 259 367 260 if ( !key)261 { 262 name = tr ( NoneSymbName);368 if (!aKeyVal) 369 { 370 name = tr (kNoneSymbName); 263 371 } 264 372 else … … 269 377 * hand. */ 270 378 int scan; 271 switch ( key)379 switch (aKeyVal) 272 380 { 273 381 case VK_RSHIFT: scan = 0x36 << 16; break; 274 382 case VK_RCONTROL: scan = (0x1D << 16) | (1 << 24); break; 275 383 case VK_RMENU: scan = (0x38 << 16) | (1 << 24); break; 276 default: scan = ::MapVirtualKey ( key, 0) << 16;384 default: scan = ::MapVirtualKey (aKeyVal, 0) << 16; 277 385 } 278 386 TCHAR *str = new TCHAR[256]; 279 387 if (::GetKeyNameText (scan, str, 256)) 388 { 280 389 name = QString::fromUcs2 (str); 390 } 281 391 else 282 name = QString (tr ("<key_%1>")).arg (key); 392 { 393 AssertFailed(); 394 name = QString (tr ("<key_%1>")).arg (aKeyVal); 395 } 283 396 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 } 284 404 #elif defined (Q_WS_X11) 285 char *sn = ::XKeysymToString ( (KeySym) key);405 char *sn = ::XKeysymToString ((KeySym) aKeyVal); 286 406 if (sn) 287 407 { 288 name = keyNames [sn];408 name = sKeyNames [sn]; 289 409 if (name.isEmpty()) 290 410 name = sn; 291 411 } 292 412 else 293 name = QString (tr ("<key_%1>")).arg (key); 413 { 414 AssertFailed(); 415 name = QString (tr ("<key_%1>")).arg (aKeyVal); 416 } 294 417 #elif defined(Q_WS_MAC) 295 UInt32 modMask = DarwinKeyCodeToDarwinModifierMask ( key);418 UInt32 modMask = DarwinKeyCodeToDarwinModifierMask (aKeyVal); 296 419 switch (modMask) 297 420 { … … 331 454 } 332 455 #else 333 name = QString ("<key_%1>").arg (key); 456 AssertFailed(); 457 name = QString (tr ("<key_%1>")).arg (aKeyVal); 334 458 #endif 335 459 } … … 338 462 } 339 463 340 / / static341 bool QIHotKeyEdit::isValidKey ( int k)464 /* static */ 465 bool QIHotKeyEdit::isValidKey (int aKeyVal) 342 466 { 343 467 #if defined(Q_WS_WIN32) 344 468 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)); 353 483 #elif defined(Q_WS_X11) 354 KeySym ks = (KeySym) k;484 KeySym ks = (KeySym) aKeyVal; 355 485 return 356 486 ( … … 359 489 ) && ( 360 490 ks == XK_Scroll_Lock || 361 IsModifierKey ( ks) ||362 IsFunctionKey ( ks) ||363 IsMiscFunctionKey ( ks)491 IsModifierKey (ks) || 492 IsFunctionKey (ks) || 493 IsMiscFunctionKey (ks) 364 494 ); 365 495 #elif defined(Q_WS_MAC) 366 UInt32 modMask = ::DarwinKeyCodeToDarwinModifierMask( k ); 367 switch ( modMask ) { 496 UInt32 modMask = ::DarwinKeyCodeToDarwinModifierMask (aKeyVal); 497 switch (modMask) 498 { 368 499 case shiftKey: 369 500 case optionKey: … … 379 510 } 380 511 #else 381 Q_UNUSED ( k);512 Q_UNUSED (aKeyVal); 382 513 return true; 383 514 #endif … … 389 520 void QIHotKeyEdit::clear() 390 521 { 391 keyval = 0;392 symbname = tr (NoneSymbName);522 mKeyVal = 0; 523 mSymbName = tr (kNoneSymbName); 393 524 updateText(); 394 525 } … … 400 531 ///////////////////////////////////////////////////////////////////////////// 401 532 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 535 bool 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)) 413 542 return false; 414 543 415 / / ignore if not valid hot key416 if ( !isValidKey( msg->wParam ))544 /* ignore if not a valid hot key */ 545 if (!isValidKey (msg->wParam)) 417 546 return false; 418 547 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 } 438 571 else 439 symbname = QString( "<key_%1>" ).arg( keyval ); 572 { 573 AssertFailed(); 574 mSymbName = QString (tr ("<key_%1>")).arg (mKeyVal); 575 } 440 576 delete[] str; 441 / / update the display577 /* update the display */ 442 578 updateText(); 443 579 } … … 446 582 } 447 583 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 586 bool 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 614 bool QIHotKeyEdit::x11Event (XEvent *event) 615 { 616 switch (event->type) 617 { 453 618 case XKeyPress: 454 case XKeyRelease: { 619 case XKeyRelease: 620 { 455 621 XKeyEvent *ke = (XKeyEvent *) event; 456 KeySym ks = ::XKeycodeToKeysym ( ke->display, ke->keycode, 0);457 / / ignore if not valid hot key458 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)) 459 625 return false; 460 626 461 / / skip key releases462 if ( event->type == XKeyRelease)627 /* skip key releases */ 628 if (event->type == XKeyRelease) 463 629 return true; 464 630 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 */ 479 636 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 486 643 return true; 487 644 } … … 491 648 } 492 649 493 #elif defined (Q_WS_MAC)650 #elif defined (Q_WS_MAC) 494 651 495 652 /* static */ 496 pascal OSStatus QIHotKeyEdit::darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef,497 EventRef inEvent, void *inUserData 498 { 499 QIHotKeyEdit *edit = (QIHotKeyEdit *) inUserData;500 UInt32 EventClass = ::GetEventClass ( inEvent);653 pascal OSStatus QIHotKeyEdit::darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef, 654 EventRef inEvent, void *inUserData) 655 { 656 QIHotKeyEdit *edit = (QIHotKeyEdit *) inUserData; 657 UInt32 EventClass = ::GetEventClass (inEvent); 501 658 if (EventClass == kEventClassKeyboard) 502 659 { 503 if (edit->darwinKeyboardEvent ( inEvent))660 if (edit->darwinKeyboardEvent (inEvent)) 504 661 return 0; 505 662 } … … 507 664 } 508 665 509 bool QIHotKeyEdit::darwinKeyboardEvent ( EventRef inEvent)666 bool QIHotKeyEdit::darwinKeyboardEvent (EventRef inEvent) 510 667 { 511 668 /* ignore key changes unless we're the focus widget */ … … 513 670 return false; 514 671 515 UInt32 eventKind = ::GetEventKind( inEvent ); 516 switch ( eventKind ) { 672 UInt32 eventKind = ::GetEventKind (inEvent); 673 switch (eventKind) 674 { 517 675 /*case kEventRawKeyDown: 518 676 case kEventRawKeyUp: 519 677 case kEventRawKeyRepeat:*/ 520 case kEventRawKeyModifiersChanged: { 678 case kEventRawKeyModifiersChanged: 679 { 521 680 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 releases530 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)) 531 690 break; 532 691 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)) 536 695 break; 537 696 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); 541 700 updateText(); 542 701 break; //return true; … … 551 710 #endif 552 711 553 void QIHotKeyEdit::focusInEvent( QFocusEvent * ) { 712 void QIHotKeyEdit::focusInEvent (QFocusEvent *) 713 { 554 714 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 719 void QIHotKeyEdit::focusOutEvent (QFocusEvent *) 720 { 560 721 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 726 void QIHotKeyEdit::drawContents (QPainter * p) 727 { 728 QLabel::drawContents (p); 729 if (hasFocus()) 730 { 731 style().drawPrimitive ( 570 732 QStyle::PE_FocusRect, p, contentsRect(), colorGroup(), 571 733 QStyle::Style_Default, 572 QStyleOption( colorGroup().background() ) 573 ); 734 QStyleOption( colorGroup().background())); 574 735 } 575 736 } … … 580 741 void QIHotKeyEdit::updateText() 581 742 { 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 6 6 7 7 /* 8 * Copyright (C) 2 006-2007 innotek GmbH8 * Copyright (C) 22006-2007 innotek GmbH 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 23 23 #include "VBoxGlobal.h" 24 24 #include "VBoxProblemReporter.h" 25 26 #ifdef Q_WS_PM 27 #include "QIHotKeyEdit.h" 28 #endif 25 29 26 30 #include <qapplication.h> … … 993 997 case QEvent::FocusOut: 994 998 { 995 focusEvent (false); 999 if (isRunning()) 1000 focusEvent (false); 996 1001 break; 997 1002 } … … 1503 1508 * Get Win32 messages before they are passed to Qt. This allows us to get 1504 1509 * the keyboard events directly and bypass the harmful Qt translation. A 1505 * return value of TRUEindicates to Qt that the event has been handled.1510 * return value of @c true indicates to Qt that the event has been handled. 1506 1511 */ 1507 1512 bool VBoxConsoleView::winEvent (MSG *msg) … … 1518 1523 1519 1524 #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)));1529 1525 char buf [256]; 1530 1526 sprintf (buf, "WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d rzv=%01X ctx=%01d prev=%01d tran=%01d", … … 1538 1534 ((msg->lParam >> 31) & 0x1)); 1539 1535 mainwnd->statusBar()->message (buf); 1536 LogFlow (("%s\n", buf)); 1540 1537 #endif 1541 1538 … … 1604 1601 ::SendMessage (msg->hwnd, msg->message, 1605 1602 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 */ 1615 bool 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)); 1606 1702 return true; 1607 1703 } … … 1829 1925 } 1830 1926 1831 #endif 1927 #endif // defined (Q_WS_WIN) 1832 1928 1833 1929 // … … 1972 2068 * @return true to consume the event and false to pass it to Qt 1973 2069 */ 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(); 2070 bool 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(); 1983 2083 1984 2084 LONG buf [16]; 1985 2085 LONG *codes = buf; 1986 2086 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) 1992 2092 { 1993 2093 static LONG PrintMake[] = { 0xE0, 0x2A, 0xE0, 0x37 }; 1994 2094 static LONG PrintBreak[] = { 0xE0, 0xB7, 0xE0, 0xAA }; 1995 if ( flags & KeyPressed)2095 if (aFlags & KeyPressed) 1996 2096 { 1997 2097 codes = PrintMake; … … 2004 2104 } 2005 2105 } 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 } 2011 2119 } 2012 2120 else 2013 2121 { 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 events2018 // 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. */ 2019 2127 fixModifierState (codes, &count); 2020 2128 } 2021 2129 2022 / / process the scancode and update the table of pressed keys2023 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) 2026 2134 { 2027 2135 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; 2035 2143 } 2036 2144 else 2037 2145 { 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)) 2040 2149 return true; 2041 codes [count++] = scan | 0x80;2042 keys_pressed [ scan] &= ~what_pressed;2150 codes [count++] = aScan | 0x80; 2151 keys_pressed [aScan] &= ~whatPressed; 2043 2152 } 2044 2153 2045 2154 if (kbd_captured) 2046 keys_pressed [ scan] |= IsKbdCaptured;2155 keys_pressed [aScan] |= IsKbdCaptured; 2047 2156 else 2048 keys_pressed [ scan] &= ~IsKbdCaptured;2157 keys_pressed [aScan] &= ~IsKbdCaptured; 2049 2158 } 2050 2159 } 2051 2160 else 2052 2161 { 2053 / / currently this is used in winLowKeyboardEvent() only2162 /* currently this is used in winLowKeyboardEvent() only */ 2054 2163 hostkey_in_capture = kbd_captured; 2055 2164 } … … 2058 2167 int hotkey = 0; 2059 2168 2060 / / process the host key2061 if ( flags & KeyPressed)2062 { 2063 if (is _hostkey)2169 /* process the host key */ 2170 if (aFlags & KeyPressed) 2171 { 2172 if (isHostKey) 2064 2173 { 2065 2174 if (!hostkey_pressed) … … 2077 2186 if (hostkey_alone) 2078 2187 { 2079 hotkey = key;2188 hotkey = aKey; 2080 2189 hostkey_alone = false; 2081 2190 } … … 2085 2194 else 2086 2195 { 2087 if (is _hostkey)2196 if (isHostKey) 2088 2197 { 2089 2198 if (hostkey_pressed) … … 2118 2227 } 2119 2228 } 2120 // emit the keyboard state change signal 2229 2230 /* emit the keyboard state change signal */ 2121 2231 if (emit_signal) 2122 2232 emitKeyboardStateChanged(); 2123 2233 2124 / /process HOST+<key> shortcuts. currently, <key> is limited to2125 // alphanumeric chars.2234 /* process HOST+<key> shortcuts. currently, <key> is limited to 2235 * alphanumeric chars. */ 2126 2236 if (hotkey) 2127 2237 { … … 2149 2259 Display *display = x11Display(); 2150 2260 int keysyms_per_keycode = getKeysymsPerKeycode(); 2151 KeyCode kc = XKeysymToKeycode (display, key);2261 KeyCode kc = XKeysymToKeycode (display, aKey); 2152 2262 // iterate over the first level (not shifted) keysyms in every group 2153 2263 for (int i = 0; i < keysyms_per_keycode && !processed; i += 2) … … 2171 2281 mainwnd->menuBar()); 2172 2282 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. */ 2180 2291 return processed; 2181 2292 } 2182 2293 2183 / / no more to do, if the host key is in action or the VM is paused2184 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 Qt2188 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; 2189 2300 } 2190 2301 … … 2193 2304 2194 2305 #if defined (Q_WS_WIN32) 2195 / / send pending WM_PAINT events2306 /* send pending WM_PAINT events */ 2196 2307 ::UpdateWindow (viewport()->winId()); 2197 2308 #endif 2198 2309 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 2203 2320 2204 2321 keyboard.PutScancodes (codes, count); 2205 2322 2206 / / grab the key from Qt2323 /* grab the key from Qt */ 2207 2324 return true; 2208 2325 } … … 2225 2342 aType, aPos.x(), aPos.y(), aButton, aState, aStateAfter, 2226 2343 aWheelDelta, aWheelDir); 2227 ((QMainWindow*)mainwnd)->statusBar()->message (buf);2344 mainwnd->statusBar()->message (buf); 2228 2345 #else 2229 2346 Q_UNUSED (aButton); -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp
r5128 r5132 2138 2138 detailReportTemplatesReady = false; 2139 2139 2140 #if defined (Q_WS_ X11)2141 /* As X11 doesnot (to my knowledge) have functionality for providing2140 #if defined (Q_WS_PM) || defined (Q_WS_X11) 2141 /* As PM and X11 do not (to my knowledge) have functionality for providing 2142 2142 * human readable key names, we keep a table of them, which must be 2143 2143 * updated when the language is changed. */ -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobalSettings.cpp
r4071 r5132 39 39 hostkey = 0xA3; // VK_RCONTROL 40 40 // hostkey = 165; // VK_RMENU 41 #elif defined (Q_WS_PM) 42 hostkey = VK_CTRL; 41 43 #elif defined (Q_WS_X11) 42 44 hostkey = 0xffe4; // XK_Control_R … … 56 58 } 57 59 58 VBoxGlobalSettingsData::VBoxGlobalSettingsData( const VBoxGlobalSettingsData &that ) { 60 VBoxGlobalSettingsData::VBoxGlobalSettingsData (const VBoxGlobalSettingsData &that) 61 { 59 62 hostkey = that.hostkey; 60 63 autoCapture = that.autoCapture; … … 67 70 } 68 71 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 ); 72 bool 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); 77 79 } 78 80 … … 253 255 if (ok) 254 256 { 257 /* The individual setter may have set a specific error */ 258 if (!last_err.isNull()) 259 return; 260 255 261 last_err = QString::null; 256 262 emit propertyChanged (gPropertyMap [index].publicName,
Note:
See TracChangeset
for help on using the changeset viewer.