Quellcode durchsuchen

CProcessPaste::DoPaste - fixed "unable to open clipboard" errors.

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@61 595ec19a-5cb4-439b-94a8-42fb3063c22c
ingenuus vor 22 Jahren
Ursprung
Commit
decdccbaf9
2 geänderte Dateien mit 18 neuen und 26 gelöschten Zeilen
  1. 17 21
      ProcessPaste.cpp
  2. 1 5
      ProcessPaste.h

+ 17 - 21
ProcessPaste.cpp

@@ -779,7 +779,7 @@ BOOL COleClipSource::OnRenderGlobalData(LPFORMATETC lpFormatEtc, HGLOBAL* phGlob
 	CProcessPaste
 \*------------------------------------------------------------------*/
 
-CProcessPaste::CProcessPaste() : m_bDeleteOle(true)
+CProcessPaste::CProcessPaste()
 {
 	m_pOle = new COleClipSource;
 	m_bSendPaste = true;
@@ -787,36 +787,32 @@ CProcessPaste::CProcessPaste() : m_bDeleteOle(true)
 
 CProcessPaste::~CProcessPaste()
 {	
-	if( m_bDeleteOle )
-		delete m_pOle;
+	DELETE_PTR(m_pOle);
 }
 
 BOOL CProcessPaste::DoPaste()
 {
 	if( m_pOle->DoImmediateRender() )
 	{
-		// if we are pasting a single element, do not handle clipboard data change
-		// (the element is already in the db and its lDate is updated by MarkAsPasted())
-		if( GetClipIDs().GetSize() == 1 )
-		{
+		// MarkAsPasted() must be done first since it makes use of
+		//  m_pOle->m_ClipIDs and m_pOle is inaccessible after
+		//  SetClipboard is called.
+		MarkAsPasted();
+
+		// Ignore the clipboard change that we will cause IF:
+		// 1) we are pasting a single element, since the element is already
+		//    in the db and its lDate was updated by MarkAsPasted().
+		// OR
+		// 2) we are pasting multiple, but g_Opt.m_bSaveMultiPaste is false
+		if( GetClipIDs().GetSize() == 1 || !g_Opt.m_bSaveMultiPaste )
 			m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
-			m_pOle->SetClipboard();
-		}
-		else // we are pasting a new aggregate text
-		{
-			if( g_Opt.m_bSaveMultiPaste )
-				m_pOle->SetClipboard();
-			else
-			{
-				m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
-				m_pOle->SetClipboard();
-			}
-		}
 
-		m_bDeleteOle = false; // m_pOle is managed by the OLE clipboard now
+		m_pOle->SetClipboard(); // m_pOle is now managed by the OLE clipboard
+		m_pOle = NULL; // m_pOle should not be accessed past this point
+
 		if(m_bSendPaste)
 			theApp.SendPaste();
-		MarkAsPasted();
+
 		return TRUE;
 	}
 	return FALSE;

+ 1 - 5
ProcessPaste.h

@@ -111,10 +111,8 @@ public:
 class CProcessPaste
 {
 public:
-	// true if we should delete m_pOle,
-	// false if it will be automatically deleted
-	bool	m_bDeleteOle;
 	COleClipSource*	m_pOle;
+	bool m_bSendPaste;
 
 	CProcessPaste();
 	~CProcessPaste();
@@ -125,8 +123,6 @@ public:
 	BOOL DoDrag();
 
 	void MarkAsPasted();
-
-	bool m_bSendPaste;
 };
 
 #endif // !defined(AFX_PROCESSPASTE_H__185CBB6F_4B63_4397_8FF9_E18D777DA506__INCLUDED_)