Skip to content

Commit

Permalink
Feat/ignore annoying cfdib (sabrogden#599)
Browse files Browse the repository at this point in the history
* add IGNORE_ANNOYING_CF_DIB advanced feature

* fix to call GetAvailableTypes only if needed

* fix oleacc.dll loading to be once explicitly.
  • Loading branch information
PzaThief authored Jan 8, 2024
1 parent 206a7b5 commit e64d993
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 39 deletions.
13 changes: 10 additions & 3 deletions AdvGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ END_MESSAGE_MAP()
#define SETTING_FAST_THUMBNAIL_MODE 91
#define SETTING_CLIPBOARD_RESTORE_AFTER_COPY_BUFFER_DELAY 92
#define SETTING_SUPPORT_ALL_TYPES 93
#define SETTING_IGNORE_ANNOYING_CF_DIB 94

BOOL CAdvGeneral::OnInitDialog()
{
Expand Down Expand Up @@ -181,7 +182,7 @@ BOOL CAdvGeneral::OnInitDialog()
AddTrueFalse(pGroupTest, _T("Always show scroll bar"), CGetSetOptions::GetShowScrollBar(), SETTING_ALWAYS_SHOW_SCROLL_BAR);
pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Amount of text to save for description"), g_Opt.m_bDescTextSize, _T(""), SETTING_DESC_SIZE));
pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Copy and save clipboard delay (ms)"), (long)CGetSetOptions::GetCopyAndSveDelay(), _T(""), SETTING_COPY_SAVE_DELAY));
pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Clipboard restore delay after copy buffer sent paste (ms, default: 750))"), (long)(CGetSetOptions::GetDittoRestoreClipboardDelay()), _T(""), SETTING_CLIPBOARD_RESTORE_AFTER_COPY_BUFFER_DELAY));
pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Clipboard restore delay after copy buffer sent paste (ms, default: 750)"), (long)(CGetSetOptions::GetDittoRestoreClipboardDelay()), _T(""), SETTING_CLIPBOARD_RESTORE_AFTER_COPY_BUFFER_DELAY));

pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Default paste string"), CGetSetOptions::GetDefaultPasteString(), _T(""), SETTING_DEFAULT_PASTE_STRING));
pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Default copy string"), CGetSetOptions::GetDefaultCopyString(), _T(""), SETTING_DEFAULT_COPY_STRING));
Expand Down Expand Up @@ -213,6 +214,7 @@ BOOL CAdvGeneral::OnInitDialog()
AddTrueFalse(pGroupTest, _T("Hide Ditto on hot key if Ditto is visible"), CGetSetOptions::GetHideDittoOnHotKeyIfAlreadyShown(), SETTING_HIDE_ON_HOTKEY_IF_VISIBLE);

pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Ignore copies faster than (ms) (default: 500)"), (long)CGetSetOptions::GetSaveClipDelay(), _T(""), SETTING_IGNORE_FALSE_COPIES_DELAY));
pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Ignore annoying CF_DIB when a clip is detected as text content"), CGetSetOptions::GetIgnoreAnnoyingCFDIB(), _T("Case insensitive. Recommended option is \"excel.exe; onenote.exe; powerpnt.exe\" "), SETTING_IGNORE_ANNOYING_CF_DIB));

pGroupTest->AddSubItem( new CMFCPropertyGridProperty(_T("Maximum clip size in bytes (0 for no limit)"), g_Opt.m_lMaxClipSizeInBytes, _T(""), SETTING_MAX_CLIP_SIZE));

Expand Down Expand Up @@ -240,7 +242,7 @@ BOOL CAdvGeneral::OnInitDialog()

AddTrueFalse(pGroupTest, _T("Refresh view after paste"), CGetSetOptions::GetRefreshViewAfterPasting(), SETTING_REFRESH_VIEW_AFTER_PASTE);

pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Save clipboard delay (ms, default: 100))"), (long)(CGetSetOptions::GetProcessDrawClipboardDelay()), _T(""), SETTING_CLIPBOARD_SAVE_DELAY));
pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Save clipboard delay (ms, default: 100)"), (long)(CGetSetOptions::GetProcessDrawClipboardDelay()), _T(""), SETTING_CLIPBOARD_SAVE_DELAY));

AddTrueFalse(pGroupTest, _T("Save multi-pastes"), CGetSetOptions::GetSaveMultiPaste(), SETTING_SAVE_MULTI_PASTE);

Expand Down Expand Up @@ -821,7 +823,12 @@ void CAdvGeneral::OnBnClickedOk()
CGetSetOptions::SetSupportAllTypes(val);
}
break;

case SETTING_IGNORE_ANNOYING_CF_DIB:
if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
{
CGetSetOptions::SetIgnoreAnnoyingCFDIB(pNewValue->bstrVal);
}
break;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions Clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,10 @@ int CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore,
cf.m_cfType = pTypes->ElementAt(i);

if (cf.m_cfType == CF_DIB &&
g_Opt.m_excludeCF_DIBInExcel &&
activeApp.MakeLower() == _T("excel.exe"))
oleData.IsDataAvailable(CF_TEXT) &&
g_Opt.GetIgnoreAnnoyingCFDIBSet(TRUE).count(activeApp.MakeLower()))
{
Log(StrF(_T("Ignore CF_DIB from %s"), activeApp));
continue;
}

Expand Down
15 changes: 6 additions & 9 deletions CopyThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,15 @@ void CCopyThread::OnClipboardChange(CString activeWindow, CString activeWindowTi
pClip->m_copyReason = theApp.GetCopyReason();

COleDataObjectEx oleData;
std::shared_ptr<CClipTypes> availableTypes = oleData.GetAvailableTypes();
CClipTypes* pSupportedTypes = m_LocalConfig.m_pSupportedTypes;

//If we are copying from a Ditto Buffer then save all to the database, so when we paste this it will paste
//just like you were using Ctrl-V
if(theApp.m_CopyBuffer.Active())
// If we are copying from a Ditto Buffer or use advanced option
// then save all to the database, so when we paste this it will paste
// just like you were using Ctrl-V
std::shared_ptr<CClipTypes> availableTypes;
if (theApp.m_CopyBuffer.Active() || CGetSetOptions::GetSupportAllTypes())
{
Log(_T("LoadFromClipboard - Copy buffer Active Start"));
pSupportedTypes = availableTypes.get();
Log(_T("LoadFromClipboard - Copy buffer Active End"));
}
else if (CGetSetOptions::GetSupportAllTypes()) {
availableTypes = oleData.GetAvailableTypes();
pSupportedTypes = availableTypes.get();
}

Expand Down
20 changes: 12 additions & 8 deletions ExternalWindowTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ ExternalWindowTracker::ExternalWindowTracker(void)
m_focusWnd = NULL;
m_dittoHasFocus = false;
m_desktopHasFocus = false;

m_hOleacc = LoadLibrary(_T("oleacc.dll"));
if (m_hOleacc)
m_AccessibleObjectFromWindow = (AccessibleObjectFromWindow)GetProcAddress(m_hOleacc, "AccessibleObjectFromWindow");
}

ExternalWindowTracker::~ExternalWindowTracker(void)
{
if (m_hOleacc)
{
FreeLibrary(m_hOleacc);
m_hOleacc = NULL;
m_AccessibleObjectFromWindow = NULL;
}
}

bool ExternalWindowTracker::TrackActiveWnd(bool force)
Expand Down Expand Up @@ -479,17 +489,11 @@ CPoint ExternalWindowTracker::FocusCaret()
return pt;

// trying to get caret for some hard applications like Chrome.
HMODULE hOleacc = LoadLibrary(_T("oleacc.dll"));
if (!hOleacc)
return pt;

typedef HRESULT(__stdcall *AccessibleObjectFromWindow)(_In_ HWND hwnd, _In_ DWORD dwId, _In_ REFIID riid, _Outptr_ void** ppvObject);
AccessibleObjectFromWindow getObject = (AccessibleObjectFromWindow)GetProcAddress(hOleacc, "AccessibleObjectFromWindow");
if (!getObject)
if (!m_AccessibleObjectFromWindow)
return pt;

IAccessible* pIAccessible = NULL;
HRESULT hr = getObject(m_activeWnd, OBJID_CARET, __uuidof(IAccessible), (void**)&pIAccessible);
HRESULT hr = m_AccessibleObjectFromWindow(m_activeWnd, OBJID_CARET, __uuidof(IAccessible), (void**)&pIAccessible);
if(hr != S_OK)
return pt;

Expand Down
4 changes: 4 additions & 0 deletions ExternalWindowTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ class ExternalWindowTracker
bool NotifyTrayhWnd(HWND hWnd);

protected:
typedef HRESULT(__stdcall *AccessibleObjectFromWindow)(_In_ HWND hwnd, _In_ DWORD dwId, _In_ REFIID riid, _Outptr_ void** ppvObject);

HWND m_activeWnd;
HWND m_focusWnd;
bool m_dittoHasFocus;
bool m_desktopHasFocus;
HMODULE m_hOleacc;
AccessibleObjectFromWindow m_AccessibleObjectFromWindow;

protected:
bool WaitForActiveWnd(HWND hwndToHaveFocus, int timeout);
Expand Down
47 changes: 34 additions & 13 deletions Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "Path.h"
#include "CP_Main.h"
#include "ActionEnums.h"
#include "Shared/Tokenizer.h"
#include <set>

using namespace nsPath;

Expand Down Expand Up @@ -69,7 +71,7 @@ BOOL CGetSetOptions::m_showScrollBar = false;
CGetSetOptions g_Opt;
BOOL CGetSetOptions::m_bShowAlwaysOnTopWarning = TRUE;
CRegExFilterHelper CGetSetOptions::m_regexHelper;
BOOL CGetSetOptions::m_excludeCF_DIBInExcel = TRUE;
CString CGetSetOptions::m_ignoreAnnoyingCFDIB = "";
CChaiScriptXml CGetSetOptions::m_copyScripts;
CChaiScriptXml CGetSetOptions::m_pasteScripts;
long CGetSetOptions::m_tooltipTimeout;
Expand Down Expand Up @@ -204,7 +206,7 @@ void CGetSetOptions::LoadSettings()
m_bEnsureConnectToClipboard = GetEnsureConnectToClipboard();
m_showScrollBar = GetShowScrollBar();
m_bShowAlwaysOnTopWarning = GetShowAlwaysOnTopWarning();
m_excludeCF_DIBInExcel = GetExcludeCF_DIBInExcel();
m_ignoreAnnoyingCFDIB = GetIgnoreAnnoyingCFDIB();
m_doubleKeyStrokeTimeout = GetDoubleKeyStrokeTimeout();
m_firstTenHotKeysStart = GetFirstTenHotKeysStart();
m_firstTenHotKeysFontSize = GetFirstTenHotKeysFontSize();
Expand Down Expand Up @@ -2700,17 +2702,6 @@ void CGetSetOptions::SetOpenToGroupByActiveExe(int val)
SetProfileLong(_T("OpenToGroupByActiveExe"), val);
}

BOOL CGetSetOptions::GetExcludeCF_DIBInExcel()
{
return GetProfileLong(_T("ExcludeCF_DIBInExcel"), TRUE);
}

void CGetSetOptions::SetExcludeCF_DIBInExcel(int val)
{
m_excludeCF_DIBInExcel = val;
SetProfileLong(_T("ExcludeCF_DIBInExcel"), val);
}

BOOL CGetSetOptions::GetShowStartupMessage()
{
return GetProfileLong(_T("ShowStartupMessage"), TRUE);
Expand Down Expand Up @@ -2993,3 +2984,33 @@ void CGetSetOptions::SetSupportAllTypes(BOOL val)
m_refreshViewAfterPasting = val;
SetProfileLong("SupportAllTypes", val);
}

CString CGetSetOptions::GetIgnoreAnnoyingCFDIB(BOOL useCache)
{
if (useCache)
return m_ignoreAnnoyingCFDIB;
else
return GetProfileString("IgnoreAnnoyingCFDIB", _T(""));
}

void CGetSetOptions::SetIgnoreAnnoyingCFDIB(CString val)
{
m_ignoreAnnoyingCFDIB = val;
SetProfileString("IgnoreAnnoyingCFDIB", val);
}

std::set<CString> CGetSetOptions::GetIgnoreAnnoyingCFDIBSet(BOOL useCache)
{
CString rawString = CGetSetOptions::GetIgnoreAnnoyingCFDIB(useCache);
std:set<CString> processSet;
CTokenizer token(rawString, _T(";"));
CString process;
while (token.Next(process))
{
if (process == "")
continue;
processSet.insert(process.MakeLower());
}

return processSet;
}
10 changes: 6 additions & 4 deletions Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Theme.h"
#include "RegExFilterHelper.h"
#include "ChaiScriptXml.h"
#include <set>

#define MAX_SEND_CLIENTS 15
class CSendClients
Expand Down Expand Up @@ -585,10 +586,6 @@ class CGetSetOptions
static BOOL GetOpenToGroupByActiveExe();
static void SetOpenToGroupByActiveExe(int val);

static BOOL m_excludeCF_DIBInExcel;
static BOOL GetExcludeCF_DIBInExcel();
static void SetExcludeCF_DIBInExcel(int val);

static BOOL GetShowStartupMessage();
static void SetShowStartupMessage(int val);

Expand Down Expand Up @@ -680,6 +677,11 @@ class CGetSetOptions
static BOOL m_supportAllTypes;
static BOOL GetSupportAllTypes();
static void SetSupportAllTypes(BOOL val);

static CString GetIgnoreAnnoyingCFDIB(BOOL useCache = FALSE);
static CString m_ignoreAnnoyingCFDIB;
static void SetIgnoreAnnoyingCFDIB(CString val);
static std::set<CString> GetIgnoreAnnoyingCFDIBSet(BOOL useCache = FALSE);
};

// global for easy access and for initialization of fast access variables
Expand Down

0 comments on commit e64d993

Please sign in to comment.