Skip to content

Commit e109356

Browse files
authored
Merge pull request #1044 from sabrogden/enforce-clipboard-ignore
Added option to enforce clipboard ignore formats or not
2 parents 5491961 + 105f198 commit e109356

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

src/AdvGeneral.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ END_MESSAGE_MAP()
162162
#define SETTING_DO_NOT_HIDE_ON_DEACTIVATE 108
163163
#define SETTING_HIDE_TASKBAR_ICON_ON_CLOSE 109
164164
#define SETTING_USE_MODERN_SCROLLBAR 110
165+
#define SETTING_ENFORCE_CLIPBOARD_IGNORE_FORMATS 111
165166

166167
BOOL CAdvGeneral::OnInitDialog()
167168
{
@@ -235,6 +236,7 @@ BOOL CAdvGeneral::OnInitDialog()
235236

236237
AddTrueFalse(pGroupTest, _T("Draw RTF text in list (for RTF types) (could increase memory usage an display speed)"), CGetSetOptions::GetDrawRTF(), SETTING_DRAW_RTF);
237238
pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Editor default font size"), (long)CGetSetOptions::GetEditorDefaultFontSize(), _T(""), SETTING_EDITOR_FONT_SIZE));
239+
AddTrueFalse(pGroupTest, _T("Enforce clipboard ignore formats"), CGetSetOptions::GetEnforceClipboardIgnoreFormats(), SETTING_ENFORCE_CLIPBOARD_IGNORE_FORMATS);
238240
AddTrueFalse(pGroupTest, _T("Elevated privileges to paste into elevated apps"), CGetSetOptions::GetPasteAsAdmin(), SETTING_PASTE_AS_ADMIN);
239241
AddTrueFalse(pGroupTest, _T("Ensure Ditto is always connected to the clipboard"), CGetSetOptions::GetEnsureConnectToClipboard(), SETTING_ENSURE_CONNECTED);
240242
AddTrueFalse(pGroupTest, _T("Ensure entire window is visible"), CGetSetOptions::GetEnsureEntireWindowCanBeSeen(), SETTING_ENSURE_WINDOW_IS_VISIBLE);
@@ -280,7 +282,8 @@ BOOL CAdvGeneral::OnInitDialog()
280282
CMFCPropertyGridFileProperty* pTextEditorProp = new CMFCPropertyGridFileProperty(_T("Text editor path (empty for system mapping)"), TRUE, CGetSetOptions::GetTextEditorPath(), _T("exe"), 0, szTextEditorFilter, (LPCTSTR)0, SETTING_TEXT_EDITOR_PATH);
281283
pGroupTest->AddSubItem(pTextEditorProp);
282284

283-
AddTrueFalse(pGroupTest, _T("Paste clip in active window after selection"), CGetSetOptions::GetSendPasteAfterSelection(), SETTING_PASTE_IN_ACTIVE_WINDOW);
285+
AddTrueFalse(pGroupTest, _T("Paste clip in active window after selection"), CGetSetOptions::GetSendPasteAfterSelection(), SETTING_PASTE_IN_ACTIVE_WINDOW);
286+
284287
AddTrueFalse(pGroupTest, _T("Prompt when deleting clips"), CGetSetOptions::GetPromptWhenDeletingClips(), SETTING_PROMPT_ON_DELETE);
285288

286289
AddTrueFalse(pGroupTest, _T("Revert to top level group on close"), CGetSetOptions::GetRevertToTopLevelGroup(), SETTING_REVERT_TO_TOP_LEVEL_GROUP);
@@ -989,6 +992,13 @@ void CAdvGeneral::OnBnClickedOk()
989992
CGetSetOptions::SetHideTaskbarIconOnClose(val);
990993
}
991994
break;
995+
case SETTING_ENFORCE_CLIPBOARD_IGNORE_FORMATS:
996+
if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
997+
{
998+
BOOL val = wcscmp(pNewValue->bstrVal, L"True") == 0;
999+
CGetSetOptions::SetEnforceClipboardIgnoreFormats(val);
1000+
}
1001+
break;
9921002
}
9931003
}
9941004
}

src/Clip.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,22 @@ int CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore,
360360

361361
// m_Formats should be empty when this is called.
362362
ASSERT(m_Formats.GetSize() == 0);
363-
363+
364364
// If the data is supposed to be private, then return
365-
if(::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
365+
if (::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
366366
{
367367
Log(_T("Clipboard ignore type is on the clipboard, skipping this clipboard change"));
368368
return FALSE;
369369
}
370-
371-
//https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats
372-
if (::IsClipboardFormatAvailable(theApp.m_excludeClipboardContentFromMonitorProcessing))
370+
371+
if (CGetSetOptions::m_enforceClipboardIgnoreFormats)
373372
{
374-
Log(_T("ExcludeClipboardContentFromMonitorProcessing type is on the clipboard, skipping this clipboard change"));
375-
return FALSE;
373+
//https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats
374+
if (::IsClipboardFormatAvailable(theApp.m_excludeClipboardContentFromMonitorProcessing))
375+
{
376+
Log(_T("ExcludeClipboardContentFromMonitorProcessing type is on the clipboard, skipping this clipboard change"));
377+
return FALSE;
378+
}
376379
}
377380

378381
//If we are saving a multi paste then delay us connecting to the clipboard
@@ -394,7 +397,8 @@ int CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore,
394397
oleData.EnsureClipboardObject();
395398

396399
//https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats
397-
if (oleData.IsDataAvailable(theApp.m_canIncludeInClipboardHistory))
400+
if (CGetSetOptions::m_enforceClipboardIgnoreFormats &&
401+
oleData.IsDataAvailable(theApp.m_canIncludeInClipboardHistory))
398402
{
399403
HGLOBAL includeInHistory = oleData.GetGlobalData(theApp.m_canIncludeInClipboardHistory);
400404
if (includeInHistory != nullptr)

src/ClipboardViewer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,18 @@ bool CClipboardViewer::GetIgnoreClipboardChange()
254254
return true;
255255
}
256256

257+
if (CGetSetOptions::m_enforceClipboardIgnoreFormats == false)
258+
{
259+
return false;
260+
}
261+
257262
//https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats
258263
if (::IsClipboardFormatAvailable(theApp.m_excludeClipboardContentFromMonitorProcessing))
259264
{
260265
Log(_T("ExcludeClipboardContentFromMonitorProcessing clipboard format is on the clipboard, ignoring change"));
261266
return true;
262267
}
268+
263269
return false;
264270
}
265271

src/Options.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ BOOL CGetSetOptions::m_supportAllTypes = FALSE;
9393
int CGetSetOptions::m_clipEditSaveDelayAfterLoadSeconds = 3;
9494
int CGetSetOptions::m_clipEditSaveDelayAfterSaveSeconds = 3;
9595
BOOL CGetSetOptions::m_bDoNotHideOnDeactivate = FALSE;
96+
BOOL CGetSetOptions::m_enforceClipboardIgnoreFormats = TRUE;
9697

9798

9899
CGetSetOptions::CGetSetOptions()
@@ -300,6 +301,7 @@ void CGetSetOptions::LoadSettings()
300301
m_clipEditSaveDelayAfterLoadSeconds = GetClipEditSaveDelayAfterLoadSeconds();
301302
m_clipEditSaveDelayAfterSaveSeconds = GetClipEditSaveDelayAfterSaveSeconds();
302303
m_bDoNotHideOnDeactivate = GetDoNotHideOnDeactivate();
304+
m_enforceClipboardIgnoreFormats = GetEnforceClipboardIgnoreFormats();
303305

304306
GetExtraNetworkPassword(true);
305307

@@ -3272,4 +3274,15 @@ void CGetSetOptions::SetDoNotHideOnDeactivate(BOOL val)
32723274
BOOL CGetSetOptions::GetDoNotHideOnDeactivate()
32733275
{
32743276
return GetProfileLong("DoNotHideOnDeactivate", FALSE);
3277+
}
3278+
3279+
void CGetSetOptions::SetEnforceClipboardIgnoreFormats(BOOL val)
3280+
{
3281+
SetProfileLong("EnforceClipboardIgnoreFormats", val);
3282+
m_enforceClipboardIgnoreFormats = val;
3283+
}
3284+
3285+
BOOL CGetSetOptions::GetEnforceClipboardIgnoreFormats()
3286+
{
3287+
return GetProfileLong("EnforceClipboardIgnoreFormats", TRUE);
32753288
}

src/Options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,10 @@ class CGetSetOptions
739739

740740
static BOOL SetEditWndPoint(CPoint point);
741741
static void GetEditWndPoint(CPoint& point);
742+
743+
static BOOL m_enforceClipboardIgnoreFormats;
744+
static void SetEnforceClipboardIgnoreFormats(BOOL val);
745+
static BOOL GetEnforceClipboardIgnoreFormats();
742746
};
743747

744748
// global for easy access and for initialization of fast access variables

0 commit comments

Comments
 (0)