From: sdottaka Date: Sun, 19 May 2013 14:12:03 +0000 (+0900) Subject: Move drag and drop helper code to DragDrop.* X-Git-Tag: 2.16.5~1628 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=4e521ef7ff036439f0e6667c04b00f4e244097d8;p=winmerge-jp%2Fwinmerge-jp.git Move drag and drop helper code to DragDrop.* --- diff --git a/Src/Common/DragDrop.cpp b/Src/Common/DragDrop.cpp new file mode 100644 index 000000000..2887b103e --- /dev/null +++ b/Src/Common/DragDrop.cpp @@ -0,0 +1,56 @@ +#include "DragDrop.h" +#include "paths.h" +#include + +// +// OnDropFiles code from CDropEdit +// Copyright 1997 Chris Losinger +// +// shortcut expansion code modified from : +// CShortcut, 1996 Rob Warner +// + +bool GetDroppedFiles(HDROP dropInfo, std::vector& files) +{ +// Get the number of pathnames that have been dropped + UINT wNumFilesDropped = DragQueryFile(dropInfo, 0xFFFFFFFF, NULL, 0); + UINT fileCount = 0; + + // get all file names. but we'll only need the first one. + for (WORD x = 0 ; x < wNumFilesDropped; x++) + { + // Get the number of bytes required by the file's full pathname + UINT wPathnameSize = DragQueryFile(dropInfo, x, NULL, 0); + + // Allocate memory to contain full pathname & zero byte + wPathnameSize += 1; + boost::scoped_array npszFile(new TCHAR[wPathnameSize]); + + // Copy the pathname into the buffer + DragQueryFile(dropInfo, x, npszFile.get(), wPathnameSize); + + if (x < 3) + { + files.resize(x + 1); + files[x] = npszFile.get(); + fileCount++; + } + } + + // Free the memory block containing the dropped-file information + DragFinish(dropInfo); + + for (UINT i = 0; i < fileCount; i++) + { + if (paths_IsShortcut(files[i])) + { + // if this was a shortcut, we need to expand it to the target path + String expandedFile = ExpandShortcut(files[i]); + + // if that worked, we should have a real file name + if (!expandedFile.empty()) + files[i] = expandedFile; + } + } + return true; +} diff --git a/Src/Common/DragDrop.h b/Src/Common/DragDrop.h new file mode 100644 index 000000000..d42930756 --- /dev/null +++ b/Src/Common/DragDrop.h @@ -0,0 +1,5 @@ +#include "UnicodeString.h" +#include +#include + +bool GetDroppedFiles(HDROP dropInfo, std::vector& files); diff --git a/Src/Common/SuperComboBox.cpp b/Src/Common/SuperComboBox.cpp index 4f49ecf0b..db6f5ba8b 100644 --- a/Src/Common/SuperComboBox.cpp +++ b/Src/Common/SuperComboBox.cpp @@ -3,10 +3,10 @@ #include "StdAfx.h" #include "SuperComboBox.h" +#include "DragDrop.h" #include #include -#include #ifdef _DEBUG #define new DEBUG_NEW @@ -456,42 +456,14 @@ int CSuperComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct) // void CSuperComboBox::OnDropFiles(HDROP dropInfo) { - // Get the number of pathnames that have been dropped - UINT wNumFilesDropped = DragQueryFile(dropInfo, 0xFFFFFFFF, NULL, 0); - - CString firstFile; - - // get all file names. but we'll only need the first one. - for (WORD x = 0 ; x < wNumFilesDropped; x++) { - - // Get the number of characters required by the file's full pathname - UINT wPathnameSize = DragQueryFile(dropInfo, x, NULL, 0); - - // Allocate memory to contain full pathname & zero byte - wPathnameSize += 1; - boost::scoped_array npszFile(new TCHAR[wPathnameSize]); - - // Copy the pathname into the buffer - DragQueryFile(dropInfo, x, npszFile.get(), wPathnameSize); - - // we only care about the first - if (firstFile==_T("")) - firstFile=npszFile.get(); - } - - // Free the memory block containing the dropped-file information - DragFinish(dropInfo); - - // if this was a shortcut, we need to expand it to the target path - CString expandedFile = ExpandShortcut(firstFile); - - // if that worked, we should have a real file name - if (!expandedFile.IsEmpty()) - firstFile=expandedFile; + std::vector files; + GetDroppedFiles(dropInfo, files); + if (files.size() == 0) + return; GetParent()->SendMessage(WM_COMMAND, GetDlgCtrlID() + (CBN_EDITUPDATE << 16), (LPARAM)m_hWnd); - SetWindowText(firstFile); + SetWindowText(files[0].c_str()); GetParent()->SendMessage(WM_COMMAND, GetDlgCtrlID() + (CBN_EDITCHANGE << 16), (LPARAM)m_hWnd); } @@ -553,63 +525,3 @@ void CSuperComboBox::OnGetDispInfo(NMHDR *pNotifyStruct, LRESULT *pResult) } *pResult = 0; } - -////////////////////////////////////////////////////////////////// -// use IShellLink to expand the shortcut -// returns the expanded file, or "" on error -// -// original code was part of CShortcut -// 1996 by Rob Warner -// rhwarner@southeast.net -// http://users.southeast.net/~rhwarner - -CString CSuperComboBox::ExpandShortcut(CString &inFile) -{ - CString outFile; - - // Make sure we have a path - ASSERT(!inFile.IsEmpty()); - - IShellLink* psl; - HRESULT hres; - LPTSTR lpsz = inFile.GetBuffer(MAX_PATH); - - // Create instance for shell link - hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, - IID_IShellLink, (LPVOID*) &psl); - if (SUCCEEDED(hres)) - { - // Get a pointer to the persist file interface - IPersistFile* ppf; - hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*) &ppf); - if (SUCCEEDED(hres)) - { - WCHAR wsz[MAX_PATH]; -#ifdef _UNICODE - wcsncpy((wchar_t *)wsz, lpsz, sizeof(wsz)/sizeof(WCHAR)); -#else - ::MultiByteToWideChar(CP_ACP, 0, lpsz, -1, wsz, MAX_PATH); -#endif - - // Load shortcut - hres = ppf->Load((LPCOLESTR)wsz, STGM_READ); - if (SUCCEEDED(hres)) { - WIN32_FIND_DATA wfd; - // find the path from that - HRESULT hres = psl->GetPath(outFile.GetBuffer(MAX_PATH), - MAX_PATH, - &wfd, - SLGP_UNCPRIORITY); - - outFile.ReleaseBuffer(); - } - ppf->Release(); - } - psl->Release(); - } - - inFile.ReleaseBuffer(); - - // if this fails, outFile == "" - return outFile; -} diff --git a/Src/Common/SuperComboBox.h b/Src/Common/SuperComboBox.h index 63cbf5583..75cc66e91 100644 --- a/Src/Common/SuperComboBox.h +++ b/Src/Common/SuperComboBox.h @@ -64,7 +64,6 @@ public: // Generated message map functions protected: CString m_strCurSel; - CString ExpandShortcut(CString &inFile); virtual BOOL OnAddTemplate(); CString m_strAutoAdd; BOOL m_bMustUninitOLE; diff --git a/Src/MainFrm.cpp b/Src/MainFrm.cpp index eba1a215f..4e6ededdd 100644 --- a/Src/MainFrm.cpp +++ b/Src/MainFrm.cpp @@ -30,7 +30,6 @@ #include #include // From HTMLHelp Workshop (incl. in Platform SDK) #include -#include #include "Constants.h" #include "Merge.h" #include "UnicodeString.h" @@ -81,6 +80,7 @@ #include "OptionsFont.h" #include "TFile.h" #include "JumpList.h" +#include "DragDrop.h" #include using std::vector; @@ -2102,57 +2102,12 @@ void CMainFrame::OnToolsGeneratePatch() } } -///////////////////////////////////////////////////////////////////////////// -// -// OnDropFiles code from CDropEdit -// Copyright 1997 Chris Losinger -// -// shortcut expansion code modified from : -// CShortcut, 1996 Rob Warner -// void CMainFrame::OnDropFiles(HDROP dropInfo) { - // Get the number of pathnames that have been dropped - UINT wNumFilesDropped = DragQueryFile(dropInfo, 0xFFFFFFFF, NULL, 0); - PathContext files; - UINT fileCount = 0; - - // get all file names. but we'll only need the first one. - for (WORD x = 0 ; x < wNumFilesDropped; x++) - { - // Get the number of bytes required by the file's full pathname - UINT wPathnameSize = DragQueryFile(dropInfo, x, NULL, 0); - - // Allocate memory to contain full pathname & zero byte - wPathnameSize += 1; - boost::scoped_array npszFile(new TCHAR[wPathnameSize]); - - // Copy the pathname into the buffer - DragQueryFile(dropInfo, x, npszFile.get(), wPathnameSize); - - if (x < 3) - { - files.SetSize(x + 1); - files[x] = npszFile.get(); - fileCount++; - } - } - - // Free the memory block containing the dropped-file information - DragFinish(dropInfo); - - for (UINT i = 0; i < fileCount; i++) - { - if (paths_IsShortcut(files[i])) - { - // if this was a shortcut, we need to expand it to the target path - CString expandedFile = ExpandShortcut(files[i]).c_str(); - - // if that worked, we should have a real file name - if (!expandedFile.IsEmpty()) - files[i] = expandedFile; - } - } + std::vector dropped_files; + GetDroppedFiles(dropInfo, dropped_files); + PathContext files(dropped_files); + const size_t fileCount = files.GetSize(); // If Ctrl pressed, do recursive compare bool ctrlKey = !!::GetAsyncKeyState(VK_CONTROL); @@ -2176,7 +2131,7 @@ void CMainFrame::OnDropFiles(HDROP dropInfo) // Check if they dropped a project file DWORD dwFlags[3] = {FFILEOPEN_NONE, FFILEOPEN_NONE, FFILEOPEN_NONE}; - if (wNumFilesDropped == 1) + if (fileCount == 1) { if (theApp.IsProjectFile(files[0].c_str())) { diff --git a/Src/Merge.vcproj b/Src/Merge.vcproj index 7d79d609c..b6e647eb8 100644 --- a/Src/Merge.vcproj +++ b/Src/Merge.vcproj @@ -5273,6 +5273,33 @@ + + + + + + + + + + + + + + @@ -7614,6 +7641,9 @@ RelativePath="DirViewColItems.h"> + + %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) + + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing @@ -8654,6 +8664,7 @@ + diff --git a/Src/Merge.vcxproj.filters b/Src/Merge.vcxproj.filters index 608d3c107..180fbf933 100644 --- a/Src/Merge.vcxproj.filters +++ b/Src/Merge.vcxproj.filters @@ -745,6 +745,9 @@ Source Files + + GUI\Source Files + @@ -1383,6 +1386,9 @@ Header Files + + GUI\Header Files + diff --git a/Src/OpenView.cpp b/Src/OpenView.cpp index 96e39c4b4..2fdd73d5c 100644 --- a/Src/OpenView.cpp +++ b/Src/OpenView.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include "UnicodeString.h" #include "Merge.h" #include "OpenDoc.h" @@ -45,6 +44,7 @@ #include "7zCommon.h" #include "Constants.h" #include "Picture.h" +#include "DragDrop.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -932,74 +932,37 @@ void COpenView::OnHelp() */ void COpenView::OnDropFiles(HDROP dropInfo) { - // Get the number of pathnames that have been dropped - UINT wNumFilesDropped = DragQueryFile(dropInfo, 0xFFFFFFFF, NULL, 0); - CString files[3]; - UINT fileCount = 0; - - // get all file names. but we'll only need the first one. - for (WORD x = 0 ; x < wNumFilesDropped; x++) - { - // Get the number of bytes required by the file's full pathname - UINT wPathnameSize = DragQueryFile(dropInfo, x, NULL, 0); - - // Allocate memory to contain full pathname & zero byte - wPathnameSize += 1; - boost::scoped_array npszFile(new TCHAR[wPathnameSize]); - - // Copy the pathname into the buffer - DragQueryFile(dropInfo, x, npszFile.get(), wPathnameSize); - - if (x < 3) - { - files[x] = npszFile.get(); - fileCount++; - } - } - - // Free the memory block containing the dropped-file information - DragFinish(dropInfo); - - for (UINT i = 0; i < fileCount; i++) - { - if (paths_IsShortcut((LPCTSTR)files[i])) - { - // if this was a shortcut, we need to expand it to the target path - CString expandedFile = ExpandShortcut((LPCTSTR)files[i]).c_str(); - - // if that worked, we should have a real file name - if (!expandedFile.IsEmpty()) - files[i] = expandedFile; - } - } + std::vector files; + GetDroppedFiles(dropInfo, files); + const size_t fileCount = files.size(); // Add dropped paths to the dialog UpdateData(TRUE); if (fileCount == 3) { - m_strPath[0] = files[0]; - m_strPath[1] = files[1]; - m_strPath[2] = files[2]; + m_strPath[0] = files[0].c_str(); + m_strPath[1] = files[1].c_str(); + m_strPath[2] = files[2].c_str(); UpdateData(FALSE); UpdateButtonStates(); } else if (fileCount == 2) { - m_strPath[0] = files[0]; - m_strPath[1] = files[1]; + m_strPath[0] = files[0].c_str(); + m_strPath[1] = files[1].c_str(); UpdateData(FALSE); UpdateButtonStates(); } else if (fileCount == 1) { if (m_strPath[0].IsEmpty()) - m_strPath[0] = files[0]; + m_strPath[0] = files[0].c_str(); else if (m_strPath[1].IsEmpty()) - m_strPath[1] = files[0]; + m_strPath[1] = files[0].c_str(); else if (m_strPath[2].IsEmpty()) - m_strPath[2] = files[0]; + m_strPath[2] = files[0].c_str(); else - m_strPath[0] = files[0]; + m_strPath[0] = files[0].c_str(); UpdateData(FALSE); UpdateButtonStates(); } diff --git a/Src/PathContext.cpp b/Src/PathContext.cpp index 6d017c930..8ab4abd73 100644 --- a/Src/PathContext.cpp +++ b/Src/PathContext.cpp @@ -97,6 +97,13 @@ PathContext::PathContext(const PathContext &paths) m_path[i].SetPath(paths[i]); } +PathContext::PathContext(const std::vector &paths) +{ + m_nFiles = paths.size(); + for (int i = 0; i < paths.size(); i++) + m_path[i].SetPath(paths[i]); +} + String PathContext::GetAt(int nIndex) const { assert(nIndex < m_nFiles); diff --git a/Src/PathContext.h b/Src/PathContext.h index 9be348ea0..4483005cf 100644 --- a/Src/PathContext.h +++ b/Src/PathContext.h @@ -11,6 +11,7 @@ #define _PATH_CONTEXT_H_ #include "UnicodeString.h" +#include class PathContext; @@ -47,6 +48,7 @@ public: PathContext(const String& sLeft, const String& sRight); PathContext(const String& sLeft, const String& sMiddle, const String& sRight); PathContext(const PathContext &paths); + PathContext(const std::vector& paths); String GetAt(int nIndex) const; String& GetElement(int nIndex);