mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
clean:remove win32 mouse over function.
this function only work on windows and text . can be replace with ocr(with the help of Capture2Text etc.).
This commit is contained in:
parent
d341a64569
commit
b7b347ec0e
|
@ -268,7 +268,6 @@ HEADERS += folding.hh \
|
|||
wordfinder.hh \
|
||||
groupcombobox.hh \
|
||||
keyboardstate.hh \
|
||||
mouseover.hh \
|
||||
preferences.hh \
|
||||
mutex.hh \
|
||||
mediawiki.hh \
|
||||
|
@ -404,7 +403,6 @@ SOURCES += folding.cc \
|
|||
wordfinder.cc \
|
||||
groupcombobox.cc \
|
||||
keyboardstate.cc \
|
||||
mouseover.cc \
|
||||
preferences.cc \
|
||||
mutex.cc \
|
||||
mediawiki.cc \
|
||||
|
@ -483,13 +481,11 @@ win32 {
|
|||
FORMS += texttospeechsource.ui
|
||||
SOURCES += wordbyauto.cc \
|
||||
guids.c \
|
||||
x64.cc \
|
||||
speechclient_win.cc \
|
||||
texttospeechsource.cc \
|
||||
speechhlp.cc
|
||||
HEADERS += wordbyauto.hh \
|
||||
uiauto.hh \
|
||||
x64.hh \
|
||||
texttospeechsource.hh \
|
||||
sapi.hh \
|
||||
sphelper.hh \
|
||||
|
|
239
mouseover.cc
239
mouseover.cc
|
@ -1,239 +0,0 @@
|
|||
#include "mouseover.hh"
|
||||
#include "utf8.hh"
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#undef WINVER
|
||||
#define WINVER 0x0500
|
||||
#include <sddl.h>
|
||||
#include <accctrl.h>
|
||||
#include <aclapi.h>
|
||||
#include "wordbyauto.hh"
|
||||
#include "x64.hh"
|
||||
#endif
|
||||
|
||||
MouseOver & MouseOver::instance()
|
||||
{
|
||||
static MouseOver m;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
const UINT WM_MY_SHOW_TRANSLATION = WM_USER + 301;
|
||||
static wchar_t className[] = L"GoldenDictMouseover";
|
||||
typedef BOOL ( WINAPI *ChangeWindowMessageFilterFunc )( UINT, DWORD );
|
||||
|
||||
#ifndef _MSC_VER
|
||||
typedef struct tagCHANGEFILTERSTRUCT {
|
||||
DWORD cbSize;
|
||||
DWORD ExtStatus;
|
||||
} CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT;
|
||||
#endif
|
||||
|
||||
typedef BOOL ( WINAPI *ChangeWindowMessageFilterExFunc )( HWND, UINT, DWORD, PCHANGEFILTERSTRUCT );
|
||||
|
||||
#endif // Q_OS_WIN32
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
|
||||
#ifndef ConvertStringSecurityDescriptorToSecurityDescriptor
|
||||
|
||||
extern "C" BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||
LPCWSTR StringSecurityDescriptor,
|
||||
DWORD StringSDRevision,
|
||||
PSECURITY_DESCRIPTOR *SecurityDescriptor,
|
||||
PULONG SecurityDescriptorSize );
|
||||
|
||||
#endif
|
||||
|
||||
static void SetLowLabelToGDSynchroObjects()
|
||||
{
|
||||
// The LABEL_SECURITY_INFORMATION SDDL SACL to be set for low integrity
|
||||
#define LOW_INTEGRITY_SDDL_SACL_W L"S:(ML;;NW;;;LW)"
|
||||
// DWORD dwErr = ERROR_SUCCESS;
|
||||
PSECURITY_DESCRIPTOR pSD = NULL;
|
||||
|
||||
PACL pSacl = NULL; // not allocated
|
||||
BOOL fSaclPresent = FALSE;
|
||||
BOOL fSaclDefaulted = FALSE;
|
||||
#ifdef Q_OS_WIN64
|
||||
LPCWSTR pwszMapFileName64 = L"GoldenDictTextOutHookSharedMem64";
|
||||
#endif
|
||||
LPCWSTR pwszMapFileName = L"GoldenDictTextOutHookSharedMem";
|
||||
LPCWSTR pwszSpyMutexName = L"GoldenDictTextOutSpyMutex";
|
||||
|
||||
if( ConvertStringSecurityDescriptorToSecurityDescriptorW( LOW_INTEGRITY_SDDL_SACL_W, 1 /* SDDL_REVISION_1 */, &pSD, NULL ) )
|
||||
{
|
||||
if( GetSecurityDescriptorSacl(pSD, &fSaclPresent, &pSacl, &fSaclDefaulted))
|
||||
{
|
||||
// Note that psidOwner, psidGroup, and pDacl are
|
||||
// all NULL and set the new LABEL_SECURITY_INFORMATION
|
||||
|
||||
#ifdef Q_OS_WIN64
|
||||
/* dwErr = */ SetNamedSecurityInfoW( (LPWSTR)pwszMapFileName64,
|
||||
SE_KERNEL_OBJECT, LABEL_SECURITY_INFORMATION, NULL, NULL, NULL, pSacl);
|
||||
#endif
|
||||
/* dwErr = */ SetNamedSecurityInfoW( (LPWSTR)pwszMapFileName,
|
||||
SE_KERNEL_OBJECT, LABEL_SECURITY_INFORMATION, NULL, NULL, NULL, pSacl);
|
||||
|
||||
/* dwErr = */ SetNamedSecurityInfoW( (LPWSTR)pwszSpyMutexName,
|
||||
SE_KERNEL_OBJECT, LABEL_SECURITY_INFORMATION, NULL, NULL, NULL, pSacl);
|
||||
|
||||
}
|
||||
LocalFree(pSD);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // Q_OS_WIN32
|
||||
|
||||
MouseOver::MouseOver() :
|
||||
pPref(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MouseOver::enableMouseOver()
|
||||
{
|
||||
#ifdef Q_OS_WIN32
|
||||
if ( !mouseOverEnabled && activateSpyFn )
|
||||
{
|
||||
activateSpyFn( true );
|
||||
installx64Hooks();
|
||||
mouseOverEnabled = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void MouseOver::disableMouseOver()
|
||||
{
|
||||
#ifdef Q_OS_WIN32
|
||||
if ( mouseOverEnabled && activateSpyFn )
|
||||
{
|
||||
activateSpyFn( false );
|
||||
removex64Hooks();
|
||||
mouseOverEnabled = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
|
||||
LRESULT MouseOver::makeScanBitMask()
|
||||
{
|
||||
LRESULT res = 0;
|
||||
if( pPref == NULL )
|
||||
return 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK MouseOver::eventHandler( HWND hwnd_, UINT msg,
|
||||
WPARAM wparam, LPARAM lparam )
|
||||
{
|
||||
if ( msg == WM_MY_SHOW_TRANSLATION )
|
||||
{
|
||||
LRESULT res = instance().makeScanBitMask();
|
||||
|
||||
if( res == 0 )
|
||||
return 0; // Don't handle word without necessity
|
||||
|
||||
if( wparam != 0) //Ask for methods of word retrieving
|
||||
return res;
|
||||
|
||||
int wordSeqPos = 0;
|
||||
QString wordSeq;
|
||||
|
||||
// Now locate the word inside the sequence
|
||||
|
||||
QString word;
|
||||
|
||||
if ( wordSeq[ wordSeqPos ].isSpace() )
|
||||
{
|
||||
// Currently we ignore such cases
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
if ( !wordSeq[ wordSeqPos ].isLetterOrNumber() )
|
||||
{
|
||||
// Special case: the cursor points to something which doesn't look like a
|
||||
// middle of the word -- assume that it's something that joins two words
|
||||
// together.
|
||||
|
||||
int begin = wordSeqPos;
|
||||
|
||||
for( ; begin; --begin )
|
||||
if ( !wordSeq[ begin - 1 ].isLetterOrNumber() )
|
||||
break;
|
||||
|
||||
int end = wordSeqPos;
|
||||
|
||||
while( ++end < wordSeq.size() )
|
||||
if ( !wordSeq[ end ].isLetterOrNumber() )
|
||||
break;
|
||||
|
||||
if ( end - begin == 1 )
|
||||
{
|
||||
// Well, turns out it was just a single non-letter char, discard it
|
||||
return 0;
|
||||
}
|
||||
|
||||
word = wordSeq.mid( begin, end - begin );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cursor points to a letter -- cut the word it points to
|
||||
|
||||
int begin = wordSeqPos;
|
||||
|
||||
for( ; begin; --begin )
|
||||
if ( !wordSeq[ begin - 1 ].isLetterOrNumber() )
|
||||
break;
|
||||
|
||||
int end = wordSeqPos;
|
||||
|
||||
while( ++end < wordSeq.size() )
|
||||
{
|
||||
if ( !wordSeq[ end ].isLetterOrNumber() )
|
||||
break;
|
||||
}
|
||||
word = wordSeq.mid( begin, end - begin );
|
||||
}
|
||||
|
||||
// See if we have an RTL char. Reverse the whole string if we do.
|
||||
|
||||
if( lparam == 0 )
|
||||
{
|
||||
for( int x = 0; x < word.size(); ++x )
|
||||
{
|
||||
QChar::Direction d = word[ x ].direction();
|
||||
|
||||
if ( d == QChar::DirR || d == QChar::DirAL ||
|
||||
d == QChar::DirRLE || d == QChar::DirRLO )
|
||||
{
|
||||
std::reverse( word.begin(), word.end() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool forcePopup = false;
|
||||
emit instance().hovered( word, forcePopup );
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc( hwnd_, msg, wparam, lparam );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
MouseOver::~MouseOver()
|
||||
{
|
||||
#ifdef Q_OS_WIN32
|
||||
|
||||
|
||||
#endif
|
||||
}
|
||||
|
71
mouseover.hh
71
mouseover.hh
|
@ -1,71 +0,0 @@
|
|||
#ifndef __MOUSEOVER_HH_INCLUDED__
|
||||
#define __MOUSEOVER_HH_INCLUDED__
|
||||
|
||||
#include <QObject>
|
||||
#include "config.hh"
|
||||
#include "keyboardstate.hh"
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/// This is a mouseover feature interface, where you can point your mouse at
|
||||
/// any word in any window and wait a little, and it would provide that word
|
||||
/// for the translation.
|
||||
/// This interface always exists, even on platforms that don't support that
|
||||
/// feature -- it just remains dormant on them.
|
||||
///
|
||||
/// The Windows platform is the only one supported; it works with the help of
|
||||
/// two external .dll files,
|
||||
class MouseOver: public QObject, public KeyboardState
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
/// The class is a singleton.
|
||||
static MouseOver & instance();
|
||||
|
||||
/// Enables mouseover. The mouseover is initially disabled.
|
||||
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 &, bool forcePopup );
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
/// Ask for source window is GoldenDict window
|
||||
bool isGoldenDictWindow( HWND hwnd );
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
MouseOver();
|
||||
~MouseOver();
|
||||
|
||||
Config::Preferences const *pPref;
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
|
||||
static LRESULT CALLBACK eventHandler( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam );
|
||||
|
||||
typedef void ( *ActivateSpyFn )( bool );
|
||||
ActivateSpyFn activateSpyFn;
|
||||
HINSTANCE spyDll;
|
||||
bool mouseOverEnabled;
|
||||
|
||||
/// Create mask for scan methods
|
||||
LRESULT makeScanBitMask();
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
11
scanpopup.cc
11
scanpopup.cc
|
@ -15,8 +15,6 @@
|
|||
#ifdef Q_OS_MAC
|
||||
#include "macmouseover.hh"
|
||||
#define MouseOver MacMouseOver
|
||||
#else
|
||||
#include "mouseover.hh"
|
||||
#endif
|
||||
|
||||
using std::wstring;
|
||||
|
@ -279,9 +277,10 @@ ScanPopup::ScanPopup( QWidget * parent,
|
|||
this, SLOT( clipboardChanged( QClipboard::Mode ) ) );
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
connect( &MouseOver::instance(), SIGNAL( hovered( QString const &, bool ) ),
|
||||
this, SLOT( mouseHovered( QString const &, bool ) ) );
|
||||
|
||||
#endif
|
||||
|
||||
hideTimer.setSingleShot( true );
|
||||
hideTimer.setInterval( 400 );
|
||||
|
@ -305,9 +304,9 @@ ScanPopup::ScanPopup( QWidget * parent,
|
|||
mouseGrabPollTimer.setInterval( 10 );
|
||||
connect( &mouseGrabPollTimer, SIGNAL( timeout() ),
|
||||
this, SLOT(mouseGrabPoll()) );
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
MouseOver::instance().setPreferencesPtr( &( cfg.preferences ) );
|
||||
|
||||
#endif
|
||||
ui.goBackButton->setEnabled( false );
|
||||
ui.goForwardButton->setEnabled( false );
|
||||
|
||||
|
@ -361,7 +360,6 @@ void ScanPopup::enableScanning()
|
|||
if ( !isScanningEnabled )
|
||||
{
|
||||
isScanningEnabled = true;
|
||||
MouseOver::instance().enableMouseOver();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -369,7 +367,6 @@ void ScanPopup::disableScanning()
|
|||
{
|
||||
if ( isScanningEnabled )
|
||||
{
|
||||
MouseOver::instance().disableMouseOver();
|
||||
isScanningEnabled = false;
|
||||
}
|
||||
}
|
||||
|
|
73
x64.cc
73
x64.cc
|
@ -1,73 +0,0 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
|
||||
#ifndef _UNICODE
|
||||
#define _UNICODE
|
||||
#endif
|
||||
|
||||
#include "x64.hh"
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
|
||||
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
|
||||
PROCESS_INFORMATION pInfo;
|
||||
|
||||
#ifndef Q_OS_WIN64
|
||||
bool isWow64()
|
||||
{
|
||||
static LPFN_ISWOW64PROCESS fnIsWow64Process;
|
||||
BOOL bIsWow64 = FALSE;
|
||||
|
||||
if( NULL == fnIsWow64Process )
|
||||
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress( GetModuleHandle( _T("kernel32") ), "IsWow64Process" );
|
||||
if( NULL != fnIsWow64Process )
|
||||
{
|
||||
if ( !fnIsWow64Process( GetCurrentProcess(), &bIsWow64 ) )
|
||||
return false;
|
||||
}
|
||||
return bIsWow64;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool installx64Hooks()
|
||||
{
|
||||
STARTUPINFO startup;
|
||||
#ifndef Q_OS_WIN64
|
||||
if( !isWow64() )
|
||||
return false;
|
||||
#endif
|
||||
if( pInfo.hProcess != NULL )
|
||||
removex64Hooks();
|
||||
QDir dir = QCoreApplication::applicationDirPath();
|
||||
#ifdef Q_OS_WIN64
|
||||
if( !dir.cd("x86") )
|
||||
return false;
|
||||
QString starterProc = QDir::toNativeSeparators( dir.filePath( "x86helper.exe" ) );
|
||||
#else
|
||||
if( !dir.cd("x64") )
|
||||
return false;
|
||||
QString starterProc = QDir::toNativeSeparators( dir.filePath( "x64helper.exe" ) );
|
||||
#endif
|
||||
|
||||
memset( &startup, 0, sizeof(startup) );
|
||||
startup.cb = sizeof(startup);
|
||||
|
||||
BOOL b = CreateProcess( starterProc.toStdWString().c_str(), NULL, NULL, NULL, FALSE, CREATE_NO_WINDOW | DETACHED_PROCESS, NULL, NULL, &startup, &pInfo );
|
||||
if( !b )
|
||||
pInfo.hProcess = NULL;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void removex64Hooks()
|
||||
{
|
||||
if( pInfo.hProcess == NULL )
|
||||
return;
|
||||
PostThreadMessage( pInfo.dwThreadId, WM_QUIT, 0, 0 );
|
||||
DWORD res = WaitForSingleObject( pInfo.hProcess, 3000 );
|
||||
if( res == WAIT_TIMEOUT )
|
||||
TerminateProcess( pInfo.hProcess, 1 );
|
||||
CloseHandle( pInfo.hProcess );
|
||||
CloseHandle( pInfo.hThread );
|
||||
pInfo.hProcess = NULL;
|
||||
}
|
Loading…
Reference in a new issue