Răsfoiți Sursa

added option to paste as unicode and remove any null characters in string before pasting as string

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@465 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 16 ani în urmă
părinte
comite
11bf7faa5f

+ 2 - 0
Addins/DittoUtil/DittoUtil.rc

@@ -113,6 +113,8 @@ BEGIN
                     WS_VSCROLL | WS_TABSTOP
     LTEXT           "Select the clip to paste the clip data as text",
                     IDC_STATIC,9,8,335,15
+    CONTROL         "Paste as Unicode",IDC_CHECK_PASTE_AS_UNICODE,"Button",BS_AUTOCHECKBOX | 
+                    WS_TABSTOP,7,172,76,9
 END
 
 

+ 44 - 6
Addins/DittoUtil/PasteAnyAsText.cpp

@@ -33,15 +33,53 @@ bool PasteAnyAsText::SelectClipToPasteAsText(const CDittoInfo &DittoInfo, IClip
 				pText->AutoDeleteData(false);
 				HGLOBAL data = pText->Data();
 
-				//Remove all over formats and add the selected date back as CF_TEXT
-				pFormats->DeleteAll();
+				if(dlg.PasteAsUnicode() == false)
+				{
+					char * stringData = (char *)GlobalLock(data);
+					int size = (int)GlobalSize(data);
+					for(int i = 0; i < size; i++)
+					{
+						if(stringData[i] == 0)
+						{
+							stringData[i] = ' ';
+						}
+					}
+					GlobalUnlock(data);
+
+					//Remove all over formats and add the selected date back as CF_TEXT
+					pFormats->DeleteAll();
 
-				pFormats->AddNew(CF_TEXT, data);
+					pFormats->AddNew(CF_TEXT, data);
 
-				IClipFormat *pText = pFormats->FindFormatEx(CF_TEXT);
-				if(pText != NULL)
+					IClipFormat *pText = pFormats->FindFormatEx(CF_TEXT);
+					if(pText != NULL)
+					{
+						pText->AutoDeleteData(true);
+					}
+				}
+				else
 				{
-					pText->AutoDeleteData(true);
+					wchar_t * stringData = (wchar_t *)GlobalLock(data);
+					int size = (int)GlobalSize(data);
+					for(int i = 0; i < (int)(size/(sizeof(wchar_t))); i++)
+					{
+						if(stringData[i] == 0)
+						{
+							stringData[i] = ' ';
+						}
+					}
+					GlobalUnlock(data);
+
+					//Remove all over formats and add the selected date back as CF_TEXT
+					pFormats->DeleteAll();
+
+					pFormats->AddNew(CF_UNICODETEXT, data);
+
+					IClipFormat *pText = pFormats->FindFormatEx(CF_UNICODETEXT);
+					if(pText != NULL)
+					{
+						pText->AutoDeleteData(true);
+					}
 				}
 
 				ret = true;

+ 4 - 0
Addins/DittoUtil/SelectPasteFormat.cpp

@@ -15,6 +15,7 @@ CSelectPasteFormat::CSelectPasteFormat(CWnd* pParent, IClipFormats *clipFormats)
 {
 	m_pClipFormats = clipFormats;
 	m_selectedFormat = 0;
+	m_pasteAsUnicode = false;
 }
 
 CSelectPasteFormat::~CSelectPasteFormat()
@@ -53,6 +54,7 @@ BOOL CSelectPasteFormat::OnInitDialog()
 	m_Resize.AddControl(IDC_LIST1, DR_SizeHeight | DR_SizeWidth);
 	m_Resize.AddControl(IDOK, DR_MoveTop | DR_MoveLeft);
 	m_Resize.AddControl(IDCANCEL, DR_MoveTop | DR_MoveLeft);
+	m_Resize.AddControl(IDC_CHECK_PASTE_AS_UNICODE, DR_MoveTop);
 
 	return TRUE;
 }
@@ -65,6 +67,8 @@ void CSelectPasteFormat::OnOK()
 		m_selectedFormat = (CLIPFORMAT)m_Formats.GetItemData(pos);
 	}
 
+	m_pasteAsUnicode = (::IsDlgButtonChecked(m_hWnd, IDC_CHECK_PASTE_AS_UNICODE) == BST_CHECKED);
+
 	CDialog::OnOK();
 }
 

+ 2 - 0
Addins/DittoUtil/SelectPasteFormat.h

@@ -16,6 +16,7 @@ public:
 
 	CLIPFORMAT SelectedFormat() const { return m_selectedFormat; }
 	void SelectedFormat(CLIPFORMAT val) { m_selectedFormat = val; }
+	bool PasteAsUnicode() { return m_pasteAsUnicode; }
 
 // Dialog Data
 	enum { IDD = IDD_DIALOG_SELECT_FORMAT };
@@ -25,6 +26,7 @@ protected:
 	IClipFormats *m_pClipFormats;
 	CLIPFORMAT m_selectedFormat;
 	CDialogResizer m_Resize;
+	bool m_pasteAsUnicode;
 	
 	DECLARE_MESSAGE_MAP()
 	CListBox m_Formats;

+ 3 - 2
Addins/DittoUtil/resource.h

@@ -5,14 +5,15 @@
 #define IDC_LIST1                       1000
 #define IDC_CHECK_UNICODE               1001
 #define IDD_DIALOG_SELECT_FORMAT        2000
+#define IDC_CHECK_PASTE_AS_UNICODE      2001
 
 // Next default values for new objects
 // 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        2001
+#define _APS_NEXT_RESOURCE_VALUE        2002
 #define _APS_NEXT_COMMAND_VALUE         32771
-#define _APS_NEXT_CONTROL_VALUE         2000
+#define _APS_NEXT_CONTROL_VALUE         2001
 #define _APS_NEXT_SYMED_VALUE           2000
 #endif
 #endif