From a11774483d6561d508d71c55fe33b129f68da7e4 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Thu, 28 Jul 2011 17:04:06 +0400 Subject: [PATCH] Move some checks from ScanPopup into MouseOver --- mouseover.cc | 24 +++++++++++++++++++++--- mouseover.hh | 19 +++++++++++-------- scanpopup.cc | 29 +---------------------------- scanpopup.hh | 8 -------- 4 files changed, 33 insertions(+), 47 deletions(-) diff --git a/mouseover.cc b/mouseover.cc index 193f0bc4..e0a9caad 100644 --- a/mouseover.cc +++ b/mouseover.cc @@ -83,7 +83,8 @@ static void SetLowLabelToGDSynchroObjects() #endif // Q_OS_WIN32 -MouseOver::MouseOver() +MouseOver::MouseOver() : + pPref(NULL) { #ifdef Q_OS_WIN32 HMODULE hm; @@ -167,13 +168,30 @@ void MouseOver::disableMouseOver() #ifdef Q_OS_WIN32 +LRESULT MouseOver::makeScanBitMask() +{ +LRESULT res = 0; + if( pPref == NULL ) + return 0; + if( !pPref->enableScanPopupModifiers || checkModifiersPressed( pPref->scanPopupModifiers ) ) { + res = GD_FLAG_METHOD_STANDARD; + if( pPref->scanPopupUseUIAutomation !=0 ) + res |= GD_FLAG_METHOD_UI_AUTOMATION; + if( pPref->scanPopupUseIAccessibleEx !=0 ) + res |= GD_FLAG_METHOD_IACCESSIBLEEX; + if( pPref->scanPopupUseGDMessage !=0 ) + res |= GD_FLAG_METHOD_GD_MESSAGE; + } + return res; +} + LRESULT CALLBACK MouseOver::eventHandler( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { if ( msg == WM_MY_SHOW_TRANSLATION ) { - LRESULT res = 0; - emit instance().getScanBitMask( &res ); + LRESULT res = instance().makeScanBitMask(); + if( res == 0 ) return 0; // Don't handle word without necessity diff --git a/mouseover.hh b/mouseover.hh index 2c76b4e8..9b0d6acb 100644 --- a/mouseover.hh +++ b/mouseover.hh @@ -2,6 +2,8 @@ #define __MOUSEOVER_HH_INCLUDED__ #include +#include "config.hh" +#include "keyboardstate.hh" #ifdef Q_OS_WIN32 #include @@ -15,7 +17,7 @@ /// /// The Windows platform is the only one supported; it works with the help of /// two external .dll files, -class MouseOver: public QObject +class MouseOver: public QObject, public KeyboardState { Q_OBJECT @@ -28,24 +30,22 @@ public: void enableMouseOver(); /// Disables mouseover. void disableMouseOver(); + + /// Set pointer to program configuration + void setPreferencesPtr( Config::Preferences const *ppref ) { pPref = ppref; }; signals: /// Emitted when there was some text under cursor which was hovered over. void hovered( QString const & ); -#ifdef Q_OS_WIN32 - - /// Ask mask for scan methods - void getScanBitMask( LRESULT * ); - -#endif - private: MouseOver(); ~MouseOver(); + Config::Preferences const *pPref; + #ifdef Q_OS_WIN32 static LRESULT CALLBACK eventHandler( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ); @@ -55,6 +55,9 @@ private: HINSTANCE spyDll; bool mouseOverEnabled; + /// Create mask for scan methods + LRESULT makeScanBitMask(); + #endif }; diff --git a/scanpopup.cc b/scanpopup.cc index 76574e64..3f8f794a 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -153,12 +153,7 @@ ScanPopup::ScanPopup( QWidget * parent, connect( &mouseGrabPollTimer, SIGNAL( timeout() ), this, SLOT(mouseGrabPoll()) ); -#ifdef Q_OS_WIN32 - - connect( &MouseOver::instance(), SIGNAL( getScanBitMask( LRESULT * ) ), - this, SLOT( makeScanBitMask( LRESULT * ) ), Qt::DirectConnection ); - -#endif + MouseOver::instance().setPreferencesPtr( &( cfg.preferences ) ); } ScanPopup::~ScanPopup() @@ -771,25 +766,3 @@ void ScanPopup::mutedDictionariesChanged() if ( dictionaryBar.toggleViewAction()->isChecked() ) definition->updateMutedContents(); } - -#ifdef Q_OS_WIN32 - -void ScanPopup::makeScanBitMask( LRESULT *pMask ) -{ - if( cfg.preferences.enableScanPopupModifiers && !checkModifiersPressed( cfg.preferences.scanPopupModifiers ) ) - { - *pMask = 0; - } - else - { - *pMask = GD_FLAG_METHOD_STANDARD; - if( cfg.preferences.scanPopupUseUIAutomation != 0 ) - *pMask |= GD_FLAG_METHOD_UI_AUTOMATION; - if( cfg.preferences.scanPopupUseIAccessibleEx != 0 ) - *pMask |= GD_FLAG_METHOD_IACCESSIBLEEX; - if( cfg.preferences.scanPopupUseGDMessage != 0 ) - *pMask |= GD_FLAG_METHOD_GD_MESSAGE; - } -} - -#endif // Q_OS_WIN32 diff --git a/scanpopup.hh b/scanpopup.hh index 61789d35..be435664 100644 --- a/scanpopup.hh +++ b/scanpopup.hh @@ -15,10 +15,6 @@ #include "history.hh" #include "dictionarybar.hh" -#ifdef Q_OS_WIN32 -#include "mouseover_win32/ThTypes.h" -#endif - /// This is a popup dialog to show translations when clipboard scanning mode /// is enabled. class ScanPopup: public QMainWindow, KeyboardState @@ -138,10 +134,6 @@ private slots: void altModeExpired(); void altModePoll(); -#ifdef Q_OS_WIN32 - void makeScanBitMask( LRESULT *pMask ); -#endif - /// Called repeatedly once the popup is initially engaged and we monitor the /// mouse as it may move away from the window. This simulates mouse grab, in /// essense, but seems more reliable. Once the mouse enters the window, the