Skip to content

Commit c4b2866

Browse files
authored
Merge pull request sabrogden#1011 from sabrogden/ignore-formats
Support not saving clips because of the clipboard formats, ExcludeCli…
2 parents bce0b14 + b0533af commit c4b2866

5 files changed

Lines changed: 67 additions & 5 deletions

File tree

src/CP_Main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ CCP_MainApp::CCP_MainApp()
174174
m_DittoFileData = ::RegisterClipboardFormat(_T("Ditto File Data"));
175175
m_PNG_Format = GetFormatID(_T("PNG"));
176176

177+
//https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats
178+
m_excludeClipboardContentFromMonitorProcessing = RegisterClipboardFormat(L"ExcludeClipboardContentFromMonitorProcessing");
179+
180+
//https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats
181+
m_canIncludeInClipboardHistory = RegisterClipboardFormat(L"CanIncludeInClipboardHistory");
182+
177183
m_pNoDbMainFrame = NULL;
178184
m_databaseOnNetworkShare = false;
179185

src/CP_Main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ class CCP_MainApp : public CWinApp
164164
long m_lLastGoodIndexForNextworkPassword;
165165

166166
CLIPFORMAT m_cfIgnoreClipboard; // used by CClip::LoadFromClipboard
167+
CLIPFORMAT m_excludeClipboardContentFromMonitorProcessing;
168+
CLIPFORMAT m_canIncludeInClipboardHistory;
167169
CLIPFORMAT m_cfDelaySavingData;
168170
CLIPFORMAT m_PingFormat;
169171
CLIPFORMAT m_HTML_Format;

src/Clip.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,21 @@ int CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore,
368368
return FALSE;
369369
}
370370

371+
//https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats
372+
if (::IsClipboardFormatAvailable(theApp.m_excludeClipboardContentFromMonitorProcessing))
373+
{
374+
Log(_T("ExcludeClipboardContentFromMonitorProcessing type is on the clipboard, skipping this clipboard change"));
375+
return FALSE;
376+
}
377+
371378
//If we are saving a multi paste then delay us connecting to the clipboard
372379
//to allow the ctrl-v to do a paste
373380
if(::IsClipboardFormatAvailable(theApp.m_cfDelaySavingData))
374381
{
375382
Log(_T("Delay clipboard type is on the clipboard, delaying 1500 ms to allow ctrl-v to work"));
376383
Sleep(1500);
377384
}
378-
385+
379386
//Attach to the clipboard
380387
if(!oleData.AttachClipboard())
381388
{
@@ -385,8 +392,36 @@ int CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore,
385392
}
386393

387394
oleData.EnsureClipboardObject();
388-
389-
395+
396+
//https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats
397+
if (oleData.IsDataAvailable(theApp.m_canIncludeInClipboardHistory))
398+
{
399+
HGLOBAL includeInHistory = oleData.GetGlobalData(theApp.m_canIncludeInClipboardHistory);
400+
if (includeInHistory != nullptr)
401+
{
402+
bool doReturn = false;
403+
404+
DWORD* data = static_cast<DWORD*>(GlobalLock(includeInHistory));
405+
if (data != nullptr)
406+
{
407+
if(*data == 0)
408+
{
409+
Log(_T("CanIncludeInClipboardHistory is 0, skipping this clipboard change"));
410+
doReturn = true;
411+
}
412+
413+
GlobalUnlock(includeInHistory);
414+
}
415+
416+
GlobalFree(includeInHistory);
417+
if (doReturn)
418+
{
419+
oleData.Release();
420+
return FALSE;
421+
}
422+
}
423+
}
424+
390425
m_Desc = "[Ditto Error] BAD DESCRIPTION";
391426

392427
// Get Description String

src/ClipboardViewer.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,23 @@ LRESULT CClipboardViewer::OnClipboardChange(WPARAM wParam, LPARAM lPara)
246246
return TRUE;
247247
}
248248

249+
bool CClipboardViewer::GetIgnoreClipboardChange()
250+
{
251+
if(::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
252+
{
253+
Log(_T("Clipboard Viewer Ignore clipboard format is on the clipboard, ignoring change"));
254+
return true;
255+
}
256+
257+
//https://learn.microsoft.com/en-us/windows/win32/dataxchg/clipboard-formats
258+
if (::IsClipboardFormatAvailable(theApp.m_excludeClipboardContentFromMonitorProcessing))
259+
{
260+
Log(_T("ExcludeClipboardContentFromMonitorProcessing clipboard format is on the clipboard, ignoring change"));
261+
return true;
262+
}
263+
return false;
264+
}
265+
249266
//Message that the clipboard data has changed
250267
void CClipboardViewer::OnDrawClipboard()
251268
{
@@ -260,7 +277,7 @@ void CClipboardViewer::OnDrawClipboard()
260277
{
261278
if(m_bIsConnected)
262279
{
263-
if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
280+
if(GetIgnoreClipboardChange() == false)
264281
{
265282
if(ValidActiveWnd())
266283
{
@@ -391,7 +408,7 @@ void CClipboardViewer::OnTimer(UINT_PTR nIDEvent)
391408

392409
if(dwNow - m_dwLastCopy > CGetSetOptions::m_dwSaveClipDelay || m_dwLastCopy > dwNow)
393410
{
394-
if(!::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
411+
if (GetIgnoreClipboardChange() == false)
395412
{
396413
Log(StrF(_T("OnDrawClipboard::OnTimer %d"), dwNow));
397414

src/ClipboardViewer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class CClipboardViewer : public CWnd
4848
void SetEnsureConnectedTimer();
4949
bool ValidActiveWnd();
5050

51+
bool GetIgnoreClipboardChange();
52+
5153
DWORD m_dwLastCopy;
5254

5355
// Generated message map functions

0 commit comments

Comments
 (0)