2009-02-02 20:28:53 +00:00
|
|
|
#include "mouseover.hh"
|
|
|
|
#include "utf8.hh"
|
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QDir>
|
2010-07-09 11:01:43 +00:00
|
|
|
#include <algorithm>
|
2009-02-02 20:28:53 +00:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
2011-07-09 19:26:30 +00:00
|
|
|
#undef WINVER
|
|
|
|
#define WINVER 0x0500
|
|
|
|
#include <sddl.h>
|
|
|
|
#include <accctrl.h>
|
|
|
|
#include <aclapi.h>
|
|
|
|
#include "wordbyauto.hh"
|
2012-01-24 12:39:23 +00:00
|
|
|
#include "x64.hh"
|
2009-02-02 20:28:53 +00:00
|
|
|
#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";
|
2013-08-04 19:19:57 +00:00
|
|
|
typedef BOOL ( WINAPI *ChangeWindowMessageFilterFunc )( UINT, DWORD );
|
2011-07-09 19:26:30 +00:00
|
|
|
|
2013-09-03 13:59:19 +00:00
|
|
|
#ifndef _MSC_VER
|
2011-07-09 19:26:30 +00:00
|
|
|
typedef struct tagCHANGEFILTERSTRUCT {
|
|
|
|
DWORD cbSize;
|
|
|
|
DWORD ExtStatus;
|
|
|
|
} CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT;
|
2009-02-02 20:28:53 +00:00
|
|
|
#endif
|
|
|
|
|
2013-08-04 19:19:57 +00:00
|
|
|
typedef BOOL ( WINAPI *ChangeWindowMessageFilterExFunc )( HWND, UINT, DWORD, PCHANGEFILTERSTRUCT );
|
2011-07-09 19:26:30 +00:00
|
|
|
|
|
|
|
#endif // Q_OS_WIN32
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
|
2012-10-31 13:58:35 +00:00
|
|
|
#ifndef ConvertStringSecurityDescriptorToSecurityDescriptor
|
|
|
|
|
2011-07-09 19:26:30 +00:00
|
|
|
extern "C" BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
|
|
|
LPCWSTR StringSecurityDescriptor,
|
|
|
|
DWORD StringSDRevision,
|
|
|
|
PSECURITY_DESCRIPTOR *SecurityDescriptor,
|
|
|
|
PULONG SecurityDescriptorSize );
|
|
|
|
|
2012-10-31 13:58:35 +00:00
|
|
|
#endif
|
2011-07-09 19:26:30 +00:00
|
|
|
|
|
|
|
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)"
|
2012-10-31 13:58:35 +00:00
|
|
|
// DWORD dwErr = ERROR_SUCCESS;
|
2011-07-09 19:26:30 +00:00
|
|
|
PSECURITY_DESCRIPTOR pSD = NULL;
|
|
|
|
|
|
|
|
PACL pSacl = NULL; // not allocated
|
|
|
|
BOOL fSaclPresent = FALSE;
|
|
|
|
BOOL fSaclDefaulted = FALSE;
|
2013-03-28 13:45:47 +00:00
|
|
|
#ifdef Q_OS_WIN64
|
|
|
|
LPCWSTR pwszMapFileName64 = L"GoldenDictTextOutHookSharedMem64";
|
|
|
|
#endif
|
2011-07-09 19:26:30 +00:00
|
|
|
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
|
|
|
|
|
2013-03-28 13:45:47 +00:00
|
|
|
#ifdef Q_OS_WIN64
|
|
|
|
/* dwErr = */ SetNamedSecurityInfoW( (LPWSTR)pwszMapFileName64,
|
|
|
|
SE_KERNEL_OBJECT, LABEL_SECURITY_INFORMATION, NULL, NULL, NULL, pSacl);
|
|
|
|
#endif
|
2012-10-31 13:58:35 +00:00
|
|
|
/* dwErr = */ SetNamedSecurityInfoW( (LPWSTR)pwszMapFileName,
|
2011-07-09 19:26:30 +00:00
|
|
|
SE_KERNEL_OBJECT, LABEL_SECURITY_INFORMATION, NULL, NULL, NULL, pSacl);
|
|
|
|
|
2012-10-31 13:58:35 +00:00
|
|
|
/* dwErr = */ SetNamedSecurityInfoW( (LPWSTR)pwszSpyMutexName,
|
2011-07-09 19:26:30 +00:00
|
|
|
SE_KERNEL_OBJECT, LABEL_SECURITY_INFORMATION, NULL, NULL, NULL, pSacl);
|
|
|
|
|
|
|
|
}
|
|
|
|
LocalFree(pSD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // Q_OS_WIN32
|
|
|
|
|
2011-07-28 13:04:06 +00:00
|
|
|
MouseOver::MouseOver() :
|
|
|
|
pPref(NULL)
|
2009-02-02 20:28:53 +00:00
|
|
|
{
|
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MouseOver::enableMouseOver()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
if ( !mouseOverEnabled && activateSpyFn )
|
|
|
|
{
|
|
|
|
activateSpyFn( true );
|
2012-01-24 12:39:23 +00:00
|
|
|
installx64Hooks();
|
2009-02-08 20:20:02 +00:00
|
|
|
mouseOverEnabled = true;
|
2009-02-02 20:28:53 +00:00
|
|
|
}
|
2009-02-08 20:20:02 +00:00
|
|
|
#endif
|
|
|
|
}
|
2009-02-02 20:28:53 +00:00
|
|
|
|
2009-02-08 20:20:02 +00:00
|
|
|
void MouseOver::disableMouseOver()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
if ( mouseOverEnabled && activateSpyFn )
|
|
|
|
{
|
|
|
|
activateSpyFn( false );
|
2012-01-24 12:39:23 +00:00
|
|
|
removex64Hooks();
|
2009-02-08 20:20:02 +00:00
|
|
|
mouseOverEnabled = false;
|
|
|
|
}
|
2009-02-02 20:28:53 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
|
2011-07-28 13:04:06 +00:00
|
|
|
LRESULT MouseOver::makeScanBitMask()
|
|
|
|
{
|
|
|
|
LRESULT res = 0;
|
|
|
|
if( pPref == NULL )
|
|
|
|
return 0;
|
2022-01-29 06:54:33 +00:00
|
|
|
|
2011-07-28 13:04:06 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-03-28 13:45:47 +00:00
|
|
|
LRESULT CALLBACK MouseOver::eventHandler( HWND hwnd_, UINT msg,
|
2009-02-02 20:28:53 +00:00
|
|
|
WPARAM wparam, LPARAM lparam )
|
|
|
|
{
|
|
|
|
if ( msg == WM_MY_SHOW_TRANSLATION )
|
|
|
|
{
|
2011-07-28 13:04:06 +00:00
|
|
|
LRESULT res = instance().makeScanBitMask();
|
|
|
|
|
2011-07-27 12:47:29 +00:00
|
|
|
if( res == 0 )
|
|
|
|
return 0; // Don't handle word without necessity
|
|
|
|
|
|
|
|
if( wparam != 0) //Ask for methods of word retrieving
|
|
|
|
return res;
|
2011-06-17 12:15:41 +00:00
|
|
|
|
2011-07-09 19:26:30 +00:00
|
|
|
int wordSeqPos = 0;
|
2009-02-02 20:28:53 +00:00
|
|
|
QString wordSeq;
|
|
|
|
|
|
|
|
// Now locate the word inside the sequence
|
|
|
|
|
|
|
|
QString word;
|
|
|
|
|
|
|
|
if ( wordSeq[ wordSeqPos ].isSpace() )
|
|
|
|
{
|
|
|
|
// Currently we ignore such cases
|
2011-07-09 19:26:30 +00:00
|
|
|
return 0;
|
2009-02-02 20:28:53 +00:00
|
|
|
}
|
|
|
|
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
|
2011-07-09 19:26:30 +00:00
|
|
|
return 0;
|
2009-02-02 20:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2010-07-09 11:01:43 +00:00
|
|
|
// See if we have an RTL char. Reverse the whole string if we do.
|
|
|
|
|
2014-03-17 13:46:50 +00:00
|
|
|
if( lparam == 0 )
|
2010-07-09 11:01:43 +00:00
|
|
|
{
|
2014-03-17 13:46:50 +00:00
|
|
|
for( int x = 0; x < word.size(); ++x )
|
2010-07-09 11:01:43 +00:00
|
|
|
{
|
2014-03-17 13:46:50 +00:00
|
|
|
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;
|
|
|
|
}
|
2010-07-09 11:01:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-24 13:20:58 +00:00
|
|
|
bool forcePopup = false;
|
|
|
|
emit instance().hovered( word, forcePopup );
|
2011-07-09 19:26:30 +00:00
|
|
|
return 0;
|
2009-02-02 20:28:53 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 13:45:47 +00:00
|
|
|
return DefWindowProc( hwnd_, msg, wparam, lparam );
|
2009-02-02 20:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MouseOver::~MouseOver()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|