Changeset 63578 in vbox
- Timestamp:
- Aug 17, 2016 1:51:53 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
r63567 r63578 58 58 59 59 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 60 61 /* Qt includes: */62 #if QT_VERSION >= 0x05000063 # include <QAbstractNativeEventFilter>64 #endif /* QT_VERSION >= 0x050000 */65 60 66 61 /* GUI includes: */ … … 100 95 enum { KeyExtended = 0x01, KeyPressed = 0x02, KeyPause = 0x04, KeyPrint = 0x08 }; 101 96 enum { IsKeyPressed = 0x01, IsExtKeyPressed = 0x02, IsKbdCaptured = 0x80 }; 102 103 104 #if QT_VERSION >= 0x050000105 /** QAbstractNativeEventFilter extension106 * allowing to pre-process native platform events. */107 class KeyboardHandlerEventFilter : public QAbstractNativeEventFilter108 {109 public:110 111 /** Constructor which takes the passed @a pParent to redirect events to. */112 KeyboardHandlerEventFilter(UIKeyboardHandler *pParent)113 : m_pParent(pParent)114 {}115 116 /** Handles all native events. */117 bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long *pResult)118 {119 /* Redirect event to parent: */120 Q_UNUSED(pResult);121 return m_pParent->nativeEventPreprocessor(eventType, pMessage);122 }123 124 private:125 126 /** Holds the passed parent reference. */127 UIKeyboardHandler *m_pParent;128 };129 #endif /* QT_VERSION >= 0x050000 */130 97 131 98 … … 1060 1027 #else /* QT_VERSION >= 0x050000 */ 1061 1028 1062 bool UIKeyboardHandler::nativeEventPreprocessor(const QByteArray &eventType, void *pMessage) 1063 { 1064 /* Redirect event to machine-view: */ 1065 return m_views.contains(m_iKeyboardHookViewIndex) ? m_views.value(m_iKeyboardHookViewIndex)->nativeEventPreprocessor(eventType, pMessage) : false; 1066 } 1067 1068 bool UIKeyboardHandler::nativeEventPostprocessor(void *pMessage, ulong uScreenId) 1069 { 1029 bool UIKeyboardHandler::nativeEventFilter(void *pMessage, ulong uScreenId) 1030 { 1031 /* Make sure view with passed index exists: */ 1032 if (!m_views.contains(uScreenId)) 1033 return false; 1034 1070 1035 /* Check if some system event should be filtered out. 1071 1036 * Returning @c true means filtering-out, … … 1586 1551 , m_pAltGrMonitor(0) 1587 1552 #endif /* VBOX_WS_WIN */ 1588 #if QT_VERSION >= 0x0500001589 , m_pPrivateEventFilter(0)1590 #endif /* QT_VERSION >= 0x050000 */1591 1553 , m_cMonitors(1) 1592 1554 { … … 1667 1629 1668 1630 #endif /* VBOX_WS_WIN */ 1669 1670 #if QT_VERSION >= 0x0500001671 /* If private event-filter is installed: */1672 if (m_pPrivateEventFilter)1673 {1674 /* Uninstall existing private event-filter: */1675 qApp->removeNativeEventFilter(m_pPrivateEventFilter);1676 delete m_pPrivateEventFilter;1677 m_pPrivateEventFilter = 0;1678 }1679 #endif /* QT_VERSION >= 0x050000 */1680 1631 1681 1632 /* Update keyboard hook view index: */ … … 1765 1716 1766 1717 #endif /* VBOX_WS_WIN */ 1767 1768 #if QT_VERSION >= 0x0500001769 # if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)1770 /* If private event-filter is NOT installed;1771 * Or installed but NOT for that view: */1772 if (!m_pPrivateEventFilter || (int)uScreenId != m_iKeyboardHookViewIndex)1773 {1774 /* If private event-filter is installed: */1775 if (m_pPrivateEventFilter)1776 {1777 /* Uninstall existing private event-filter: */1778 qApp->removeNativeEventFilter(m_pPrivateEventFilter);1779 delete m_pPrivateEventFilter;1780 m_pPrivateEventFilter = 0;1781 }1782 /* Install new private event-filter: */1783 m_pPrivateEventFilter = new KeyboardHandlerEventFilter(this);1784 qApp->installNativeEventFilter(m_pPrivateEventFilter);1785 }1786 # endif /* VBOX_WS_WIN || VBOX_WS_X11 */1787 #endif /* QT_VERSION >= 0x050000 */1788 1718 1789 1719 /* Update keyboard hook view index: */ … … 1835 1765 1836 1766 #endif /* VBOX_WS_WIN */ 1837 1838 #if QT_VERSION >= 0x0500001839 # if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11)1840 /* If private event-filter is installed: */1841 if (m_pPrivateEventFilter)1842 {1843 /* Uninstall existing private event-filter: */1844 qApp->removeNativeEventFilter(m_pPrivateEventFilter);1845 delete m_pPrivateEventFilter;1846 m_pPrivateEventFilter = 0;1847 }1848 # endif /* VBOX_WS_WIN || VBOX_WS_X11 */1849 #endif /* QT_VERSION >= 0x050000 */1850 1767 1851 1768 /* Update keyboard hook view index: */ … … 1945 1862 #else /* QT_VERSION >= 0x050000 */ 1946 1863 Q_UNUSED(event); 1947 QByteArray eventType("mac_generic_NSEvent"); 1948 return m_views[m_iKeyboardHookViewIndex]->nativeEventPreprocessor(eventType, unconst(pvCocoaEvent)); 1864 return nativeEventFilter(unconst(pvCocoaEvent), m_iKeyboardHookViewIndex); 1949 1865 #endif /* QT_VERSION >= 0x050000 */ 1950 1866 } … … 2011 1927 return m_views[m_iKeyboardHookViewIndex]->winEvent(&message, &dummyResult); 2012 1928 #else /* QT_VERSION >= 0x050000 */ 2013 QByteArray eventType("windows_generic_MSG"); 2014 return m_views[m_iKeyboardHookViewIndex]->nativeEventPreprocessor(eventType, &message); 1929 return nativeEventFilter(&message, m_iKeyboardHookViewIndex); 2015 1930 #endif /* QT_VERSION >= 0x050000 */ 2016 1931 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h
r62493 r63578 52 52 # endif /* QT_VERSION < 0x050000 */ 53 53 #endif /* VBOX_WS_X11 */ 54 #if QT_VERSION >= 0x05000055 class KeyboardHandlerEventFilter;56 #endif /* QT_VERSION >= 0x050000 */57 54 58 55 … … 111 108 #if QT_VERSION < 0x050000 112 109 # if defined(VBOX_WS_MAC) 113 /** Qt4: Mac: Performs finalpre-processing of all the native events. */110 /** Qt4: Mac: Performs pre-processing of all the native events. */ 114 111 bool macEventFilter(const void *pvCocoaEvent, EventRef event, ulong uScreenId); 115 112 # elif defined(VBOX_WS_WIN) 116 /** Qt4: Win: Performs finalpre-processing of all the native events. */113 /** Qt4: Win: Performs pre-processing of all the native events. */ 117 114 bool winEventFilter(MSG *pMsg, ulong uScreenId); 118 115 # elif defined(VBOX_WS_X11) 119 /** Qt4: X11: Performs finalpre-processing of all the native events. */116 /** Qt4: X11: Performs pre-processing of all the native events. */ 120 117 bool x11EventFilter(XEvent *pEvent, ulong uScreenId); 121 118 # endif /* VBOX_WS_X11 */ 122 #else /* QT_VERSION >= 0x050000 */119 #else 123 120 /** Qt5: Performs pre-processing of all the native events. */ 124 bool nativeEventPreprocessor(const QByteArray &eventType, void *pMessage); 125 /** Qt5: Performs post-processing of all the native events. */ 126 bool nativeEventPostprocessor(void *pMessage, ulong uScreenId); 127 #endif /* QT_VERSION >= 0x050000 */ 121 bool nativeEventFilter(void *pMessage, ulong uScreenId); 122 #endif 128 123 129 124 protected slots: … … 240 235 #endif /* VBOX_WS_WIN */ 241 236 242 #if QT_VERSION >= 0x050000243 /** Win: Holds the native event filter instance. */244 KeyboardHandlerEventFilter *m_pPrivateEventFilter;245 /** Win: Allows the native event filter to246 * redirect events directly to nativeEventPreprocessor handler. */247 friend class KeyboardHandlerEventFilter;248 #endif /* QT_VERSION >= 0x050000 */249 250 237 ULONG m_cMonitors; 251 238 }; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
r63567 r63578 71 71 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 72 72 73 /* Qt includes: */ 74 #if QT_VERSION >= 0x050000 75 # include <QAbstractNativeEventFilter> 76 #endif 77 73 78 /* GUI includes: */ 74 79 #ifdef VBOX_WS_MAC … … 123 128 124 129 130 #if QT_VERSION >= 0x050000 131 /** QAbstractNativeEventFilter extension 132 * allowing to pre-process native platform events. */ 133 class UINativeEventFilter : public QAbstractNativeEventFilter 134 { 135 public: 136 137 /** Constructs native event filter storing @a pParent to redirect events to. */ 138 UINativeEventFilter(UIMachineView *pParent) 139 : m_pParent(pParent) 140 {} 141 142 /** Redirects all the native events to parent. */ 143 bool nativeEventFilter(const QByteArray &eventType, void *pMessage, long * /* pResult */) 144 { 145 return m_pParent->nativeEventPreprocessor(eventType, pMessage); 146 } 147 148 private: 149 150 /** Holds the passed parent reference. */ 151 UIMachineView *m_pParent; 152 }; 153 #endif 154 155 125 156 /* static */ 126 157 UIMachineView* UIMachineView::create( UIMachineWindow *pMachineWindow … … 214 245 if (!pMachineView) 215 246 return; 247 248 /* Cleanup filters: */ 249 pMachineView->cleanupFilters(); 216 250 217 251 /* Cleanup frame-buffer: */ … … 622 656 , m_fIsDraggingFromGuest(false) 623 657 #endif 658 #if QT_VERSION >= 0x050000 659 , m_pNativeEventFilter(0) 660 #endif 624 661 { 625 662 } … … 823 860 /* Machine state-change updater: */ 824 861 connect(uisession(), SIGNAL(sigMachineStateChange()), this, SLOT(sltMachineStateChanged())); 862 } 863 864 void UIMachineView::cleanupFilters() 865 { 866 #if QT_VERSION >= 0x050000 867 /* If native event filter exists: */ 868 if (m_pNativeEventFilter) 869 { 870 /* Uninstall/destroy existing native event filter: */ 871 qApp->removeNativeEventFilter(m_pNativeEventFilter); 872 delete m_pNativeEventFilter; 873 m_pNativeEventFilter = 0; 874 } 875 #endif 825 876 } 826 877 … … 1511 1562 } 1512 1563 1564 #if QT_VERSION >= 0x050000 1565 void UIMachineView::focusInEvent(QFocusEvent *pEvent) 1566 { 1567 /* Call to base-class: */ 1568 QAbstractScrollArea::focusInEvent(pEvent); 1569 1570 /* If native event filter isn't exists: */ 1571 if (!m_pNativeEventFilter) 1572 { 1573 /* Create/install new native event filter: */ 1574 m_pNativeEventFilter = new UINativeEventFilter(this); 1575 qApp->installNativeEventFilter(m_pNativeEventFilter); 1576 } 1577 } 1578 1579 void UIMachineView::focusOutEvent(QFocusEvent *pEvent) 1580 { 1581 /* If native event filter exists: */ 1582 if (m_pNativeEventFilter) 1583 { 1584 /* Uninstall/destroy existing native event filter: */ 1585 qApp->removeNativeEventFilter(m_pNativeEventFilter); 1586 delete m_pNativeEventFilter; 1587 m_pNativeEventFilter = 0; 1588 } 1589 1590 /* Call to base-class: */ 1591 QAbstractScrollArea::focusOutEvent(pEvent); 1592 } 1593 #endif 1594 1513 1595 #ifdef VBOX_WITH_DRAG_AND_DROP 1514 1596 bool UIMachineView::dragAndDropCanAccept(void) const … … 1822 1904 bool UIMachineView::nativeEventPreprocessor(const QByteArray &eventType, void *pMessage) 1823 1905 { 1906 /* Check if some event should be filtered out. 1907 * Returning @c true means filtering-out, 1908 * Returning @c false means passing event to Qt. */ 1909 1824 1910 # if defined(VBOX_WS_MAC) 1825 1911 … … 1829 1915 EventRef event = static_cast<EventRef>(darwinCocoaToCarbonEvent(pMessage)); 1830 1916 1831 /* Check if some NSEvent should be filtered out.1832 * Returning @c true means filtering-out,1833 * Returning @c false means passing event to Qt. */1834 1917 switch(::GetEventClass(event)) 1835 1918 { … … 1846 1929 { 1847 1930 /* Delegate key-event handling to the keyboard-handler: */ 1848 return machineLogic()->keyboardHandler()->nativeEvent Postprocessor(pMessage, screenId());1931 return machineLogic()->keyboardHandler()->nativeEventFilter(pMessage, screenId()); 1849 1932 } 1850 1933 default: … … 1864 1947 MSG *pEvent = static_cast<MSG*>(pMessage); 1865 1948 1866 /* Check if some MSG event should be filtered out.1867 * Returning @c true means filtering-out,1868 * Returning @c false means passing event to Qt. */1869 1949 switch (pEvent->message) 1870 1950 { … … 1875 1955 case WM_SYSKEYUP: 1876 1956 { 1877 /* Can't do COM inter-process calls from a SendMessage handler, 1878 * see http://support.microsoft.com/kb/131056. */ 1957 // WORKAROUND: 1958 // Can't do COM inter-process calls from a SendMessage handler, 1959 // see http://support.microsoft.com/kb/131056. 1879 1960 if (vboxGlobal().isSeparateProcess() && InSendMessage()) 1880 1961 { … … 1896 1977 1897 1978 /* Delegate key-event handling to the keyboard-handler: */ 1898 return machineLogic()->keyboardHandler()->nativeEvent Postprocessor(pMessage, screenId());1979 return machineLogic()->keyboardHandler()->nativeEventFilter(pMessage, screenId()); 1899 1980 } 1900 1981 default: … … 1909 1990 xcb_generic_event_t *pEvent = static_cast<xcb_generic_event_t*>(pMessage); 1910 1991 1911 /* Check if some XCB event should be filtered out.1912 * Returning @c true means filtering-out,1913 * Returning @c false means passing event to Qt. */1914 1992 switch (pEvent->response_type & ~0x80) 1915 1993 { … … 1917 1995 case XCB_KEY_PRESS: 1918 1996 case XCB_KEY_RELEASE: 1919 case XCB_BUTTON_PRESS: 1920 { 1921 /* Delegate key-event handling to the keyboard-handler and let it 1922 * filter out button presses out of the view windows: */ 1923 return machineLogic()->keyboardHandler()->nativeEventPostprocessor(pMessage, screenId()); 1997 case XCB_BUTTON_PRESS: // TODO: Move to mouse-filter case! 1998 { 1999 /* Delegate key-event handling to the keyboard-handler: */ 2000 return machineLogic()->keyboardHandler()->nativeEventFilter(pMessage, screenId()); 1924 2001 } 1925 2002 default: -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h
r62493 r63578 65 65 class CDnDTarget; 66 66 #endif /* VBOX_WITH_DRAG_AND_DROP */ 67 #if QT_VERSION >= 0x050000 68 class UINativeEventFilter; 69 #endif 67 70 68 71 … … 186 189 //virtual void cleanupConsoleConnections() {} 187 190 //virtual void cleanupConnections() {} 188 //virtual void cleanupFilters() {}191 virtual void cleanupFilters(); 189 192 //virtual void cleanupCommon() {} 190 193 virtual void cleanupFrameBuffer(); … … 280 283 void moveEvent(QMoveEvent *pEvent); 281 284 void paintEvent(QPaintEvent *pEvent); 285 286 #if QT_VERSION >= 0x050000 287 /** Handles focus-in @a pEvent. */ 288 void focusInEvent(QFocusEvent *pEvent); 289 /** Handles focus-out @a pEvent. */ 290 void focusOutEvent(QFocusEvent *pEvent); 291 #endif 282 292 283 293 #ifdef VBOX_WITH_DRAG_AND_DROP … … 427 437 #endif 428 438 439 #if QT_VERSION >= 0x050000 440 /** Holds the native event filter instance. */ 441 UINativeEventFilter *m_pNativeEventFilter; 442 /** Allows the native event filter to redirect 443 * events directly to nativeEventPreprocessor(). */ 444 friend class UINativeEventFilter; 445 #endif 446 429 447 /* Friend classes: */ 430 448 friend class UIKeyboardHandler;
Note:
See TracChangeset
for help on using the changeset viewer.