Skip to content

Commit

Permalink
[共通] makeDragDrop を複数ファイルに対応 #1218
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Mar 16, 2024
1 parent 1db75d7 commit cc791eb
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 24 deletions.
4 changes: 4 additions & 0 deletions Siv3D/include/Siv3D/DragDrop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ namespace s3d
/// @brief 指定したファイルのドラッグを開始します。
/// @param path ファイルパス
void MakeDragDrop(FilePathView path);

/// @brief 指定したファイルのドラッグを開始します。
/// @param paths ファイルパスの配列
void MakeDragDrop(const Array<FilePath>& paths);
}

# endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace s3d
return dropped;
}

void CDragDrop::makeDragDrop(const FilePathView)
void CDragDrop::makeDragDrop(const Array<FilePath>&)
{
// [Siv3D ToDo]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace s3d

Array<DroppedText> getDroppedText() override;

void makeDragDrop(FilePathView path) override;
void makeDragDrop(const Array<FilePath>& paths) override;

//
// Linux
Expand Down
2 changes: 1 addition & 1 deletion Siv3D/src/Siv3D-Platform/Web/Siv3D/DragDrop/CDragDrop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ namespace s3d
return dropped;
}

void CDragDrop::makeDragDrop(const FilePathView path)
void CDragDrop::makeDragDrop(const Array<FilePath>&)
{
// [Siv3D ToDo]
}
Expand Down
2 changes: 1 addition & 1 deletion Siv3D/src/Siv3D-Platform/Web/Siv3D/DragDrop/CDragDrop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace s3d

Array<DroppedText> getDroppedText() override;

void makeDragDrop(FilePathView path) override;
void makeDragDrop(const Array<FilePath>& paths) override;

//
// Linux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,21 @@ namespace s3d
}
};

static void BeginDrop(IDataObject** lpDataObejct, IDropSource** lpDropSource, const FilePath& path)
static void BeginDrop(IDataObject** lpDataObejct, IDropSource** lpDropSource, const Array<FilePath>& paths)
{
std::wstring pathW = (FileSystem::FullPath(path)).toWstr();
pathW.push_back(L'\0');
pathW.push_back(L'\0');
const size_t path_size_bytes = (sizeof(wchar_t) * pathW.size());
// must be double null terminated
std::wstring data;
{
for (const auto& path : paths)
{
data += (FileSystem::FullPath(path)).toWstr();
data.push_back(L'\0');
}

data.push_back(L'\0');
}

const size_t data_size_bytes = (sizeof(wchar_t) * data.size());

FORMATETC formatetc;
formatetc.cfFormat = CF_HDROP;
Expand All @@ -687,14 +696,14 @@ namespace s3d
STGMEDIUM medium
{
.tymed = TYMED_HGLOBAL,
.hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, sizeof(DROPFILES) + path_size_bytes)
.hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, sizeof(DROPFILES) + data_size_bytes)
};

if (void* p = ::GlobalLock(medium.hGlobal))
{
((DROPFILES*)p)->pFiles = sizeof(DROPFILES);
((DROPFILES*)p)->fWide = true;
std::memcpy((char*)p + sizeof(DROPFILES), pathW.data(), path_size_bytes);
std::memcpy((char*)p + sizeof(DROPFILES), data.data(), data_size_bytes);
::GlobalUnlock(medium.hGlobal);
}

Expand Down Expand Up @@ -818,27 +827,27 @@ namespace s3d
return dropped;
}

void CDragDrop::makeDragDrop(const FilePathView path)
void CDragDrop::makeDragDrop(const Array<FilePath>& paths)
{
std::lock_guard lock{ m_mutex };

m_newDragPath = path;
m_newDragPaths = paths;
}

void CDragDrop::process()
{
FilePath path;
Array<FilePath> paths;

{
std::lock_guard lock{ m_mutex };

if (m_newDragPath)
if (m_newDragPaths)
{
path.swap(m_newDragPath);
paths.swap(m_newDragPaths);
}
}

if (not path)
if (not paths)
{
return;
}
Expand All @@ -847,7 +856,7 @@ namespace s3d
ComPtr<IDataObject> dataObject;
ComPtr<IDropSource> dropSource;

detail::BeginDrop(&dataObject, &dropSource, path);
detail::BeginDrop(&dataObject, &dropSource, paths);

DWORD dropEffect;
HRESULT hr = ::DoDragDrop(dataObject.Get(), dropSource.Get(), DROPEFFECT_MOVE | DROPEFFECT_COPY, &dropEffect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace s3d

Array<DroppedText> getDroppedText() override;

void makeDragDrop(FilePathView path) override;
void makeDragDrop(const Array<FilePath>& paths) override;

void process();

Expand All @@ -73,7 +73,7 @@ namespace s3d
//
std::mutex m_mutex;

FilePath m_newDragPath;
Array<FilePath> m_newDragPaths;
//
//////////
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace s3d
return dropped;
}

void CDragDrop::makeDragDrop(const FilePathView)
void CDragDrop::makeDragDrop(const Array<FilePath>&)
{
// [Siv3D ToDo]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace s3d

Array<DroppedText> getDroppedText() override;

void makeDragDrop(FilePathView path) override;
void makeDragDrop(const Array<FilePath>& paths) override;

//
// macOS
Expand Down
2 changes: 1 addition & 1 deletion Siv3D/src/Siv3D/DragDrop/IDragDrop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ namespace s3d

virtual Array<DroppedText> getDroppedText() = 0;

virtual void makeDragDrop(FilePathView path) = 0;
virtual void makeDragDrop(const Array<FilePath>& paths) = 0;
};
}
9 changes: 8 additions & 1 deletion Siv3D/src/Siv3D/DragDrop/SivDragDrop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ namespace s3d
{
void MakeDragDrop(const FilePathView path)
{
SIV3D_ENGINE(DragDrop)->makeDragDrop(path);
const Array<FilePath> paths = { FilePath{ path } };

SIV3D_ENGINE(DragDrop)->makeDragDrop(paths);
}

void MakeDragDrop(const Array<FilePath>& paths)
{
SIV3D_ENGINE(DragDrop)->makeDragDrop(paths);
}
}

Expand Down

0 comments on commit cc791eb

Please sign in to comment.