VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h@ 35740

Last change on this file since 35740 was 35730, checked in by vboxsync, 13 years ago

FE/Qt: 5245: GUI support for complex host-key combinations. Initial build for Win/X11.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
RevLine 
[382]1/** @file
2 *
3 * VBox frontends: Qt GUI ("VirtualBox"):
[30637]4 * UIKeyboardHandler class declaration
[382]5 */
6
7/*
[28800]8 * Copyright (C) 2010 Oracle Corporation
[382]9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
[5999]13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
[382]17 */
18
[30637]19#ifndef ___UIKeyboardHandler_h___
20#define ___UIKeyboardHandler_h___
[382]21
[26637]22/* Global includes */
[30637]23#include <QObject>
24#include <QMap>
[382]25
[26637]26/* Local includes */
[30637]27#include "UIMachineDefs.h"
[26816]28#include "COMDefs.h"
[6467]29
[30641]30#ifdef Q_WS_MAC
31# include <CoreFoundation/CFBase.h>
[30645]32# include <Carbon/Carbon.h>
[30641]33#endif /* Q_WS_MAC */
34
[30637]35/* Global forwards */
36class QWidget;
[26699]37
[26754]38/* Local forwards */
[30637]39class CSession;
[26815]40class UISession;
[30637]41class UIMachineLogic;
[26815]42class UIMachineWindow;
[30637]43class UIMachineView;
[26815]44class VBoxGlobalSettings;
[30637]45#ifdef Q_WS_X11
46typedef union _XEvent XEvent;
47#endif /* Q_WS_X11 */
[26699]48
[30637]49/* Delegate to control VM keyboard functionality: */
50class UIKeyboardHandler : public QObject
[382]51{
[26637]52 Q_OBJECT;
[382]53
54public:
55
[30637]56 /* Factory functions to create/destroy keyboard-handler: */
57 static UIKeyboardHandler* create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType);
58 static void destroy(UIKeyboardHandler *pKeyboardHandler);
[26889]59
[30637]60 /* Prepare/cleanup listeners: */
61 void prepareListener(ulong uIndex, UIMachineWindow *pMachineWindow);
62 void cleanupListener(ulong uIndex);
[382]63
[30637]64 /* Commands to capture/release keyboard: */
65 void captureKeyboard(ulong uScreenId);
66 void releaseKeyboard();
[35686]67 void releaseAllPressedKeys(bool aReleaseHostKey = true);
[30637]68
69 /* Current keyboard state: */
[26773]70 int keyboardState() const;
71
[30637]72 /* Some getters required by side-code: */
[35730]73 bool isHostKeyPressed() const { return m_bIsHostComboPressed; }
[30408]74#ifdef Q_WS_MAC
[35730]75 bool isHostKeyAlone() const { return m_bIsHostComboAlone; }
[30408]76 bool isKeyboardGrabbed() const { return m_fKeyboardGrabbed; }
77#endif /* Q_WS_MAC */
[26929]78
[30637]79 /* External event-filters: */
80#if defined(Q_WS_WIN)
81 bool winEventFilter(MSG *pMsg, ulong uScreenId);
82#elif defined(Q_WS_X11)
83 bool x11EventFilter(XEvent *pEvent, ulong uScreenId);
84#endif
[26754]85
[30637]86signals:
[26878]87
[30637]88 /* Notifies listeners about keyboard state-change: */
89 void keyboardStateChanged(int iNewState);
[27215]90
[30637]91protected slots:
[26730]92
[30637]93 /* Machine state-change handler: */
94 virtual void sltMachineStateChanged();
[26730]95
[30637]96protected:
[26878]97
[30637]98 /* Keyboard-handler constructor/destructor: */
99 UIKeyboardHandler(UIMachineLogic *pMachineLogic);
100 virtual ~UIKeyboardHandler();
[27237]101
[30637]102 /* Prepare helpers: */
103 virtual void prepareCommon();
104 virtual void loadSettings();
[26773]105
[30637]106 /* Cleanup helpers: */
107 //virtual void saveSettings() {}
108 virtual void cleanupCommon();
[26773]109
[30637]110 /* Common getters: */
111 UIMachineLogic* machineLogic() const;
112 UISession* uisession() const;
113 CSession& session() const;
[28239]114
[30637]115 /* Event handler for registered machine-view(s): */
116 bool eventFilter(QObject *pWatchedObject, QEvent *pEvent);
117#if defined(Q_WS_WIN)
[26754]118 static LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
[26637]119 bool winLowKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event);
[1285]120#elif defined(Q_WS_MAC)
[30637]121 void darwinGrabKeyboardEvents(bool fGrab);
[26699]122 bool darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent);
[26637]123 static bool darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
124#endif
[382]125
[30637]126 /* Separate function to handle most of existing keyboard-events: */
127 bool keyEvent(int iKey, uint8_t uScan, int fFlags, ulong uScreenId, wchar_t *pUniKey = 0);
[35730]128 bool processHotKey(int iHotKey, wchar_t *pUniKey);
[30637]129
[26754]130 /* Private helpers: */
[26998]131 void fixModifierState(LONG *piCodes, uint *puCount);
[26754]132 void saveKeyStates();
[382]133 void sendChangedKeyStates();
134
[30637]135 UIMachineWindow* isItListenedWindow(QObject *pWatchedObject) const;
136 UIMachineView* isItListenedView(QObject *pWatchedObject) const;
[382]137
[30637]138 /* Machine logic parent: */
139 UIMachineLogic *m_pMachineLogic;
140
141 /* Registered machine-window(s): */
142 QMap<ulong, UIMachineWindow*> m_windows;
143 /* Registered machine-view(s): */
144 QMap<ulong, UIMachineView*> m_views;
145
146 /* Other keyboard variables: */
147 int m_iKeyboardCaptureViewIndex;
[26637]148 const VBoxGlobalSettings &m_globalSettings;
[382]149
[26754]150 uint8_t m_pressedKeys[128];
151 uint8_t m_pressedKeysCopy[128];
[382]152
[35730]153 QMap<int, uint8_t> m_pressedHostComboKeys;
154
[30637]155 bool m_fIsKeyboardCaptured : 1;
[35730]156 bool m_bIsHostComboPressed : 1;
157 bool m_bIsHostComboAlone : 1;
[29410]158 bool m_fPassCAD : 1;
[896]159
[30637]160#if defined(Q_WS_WIN)
[35730]161 /* Currently this is used in winLowKeyboardEvent() only: */
162 bool m_bIsHostkeyInCapture;
[30637]163 /* Keyboard hook required to capture keyboard event under windows. */
[35730]164 static UIKeyboardHandler *m_spKeyboardHandler;
[30637]165 HHOOK m_keyboardHook;
166 int m_iKeyboardHookViewIndex;
167#elif defined(Q_WS_MAC)
168 /* The current modifier key mask. Used to figure out which modifier
169 * key was pressed when we get a kEventRawKeyModifiersChanged event. */
[26754]170 UInt32 m_darwinKeyModifiers;
171 bool m_fKeyboardGrabbed;
[30642]172 int m_iKeyboardGrabViewIndex;
[30637]173#endif
[382]174};
175
[30637]176#endif // !___UIKeyboardHandler_h___
[27124]177
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use