Cut shell/actions, bank_ops, app comment bloat ~48% (comments only, zero code change)

This commit is contained in:
2026-07-29 20:49:31 -04:00
parent 1f24c4b095
commit 58c6d49261
19 changed files with 514 additions and 1074 deletions
+15 -27
View File
@@ -1,13 +1,7 @@
// drag_out_win — OS/COM initiation of native OS drag-out (M11). See drag_out_win.h.
//
// Windows path (primary): a hand-rolled minimal IDataObject exposing exactly one format,
// CF_HDROP, plus a minimal IDropSource, handed to OLE DoDragDrop with a COPY-ONLY effect
// mask. We roll our own rather than pull in a helper because the object is tiny (one
// format, one medium) and the copy-only guarantee must be structural and auditable in one
// place. mac/linux route to SWELL's file-list drag behind the same seam.
//
// Compiled into the reaper_reasampler MODULE. No REAPER API is used here (pure OS/COM); it
// is a leaf the bank_panel calls.
// drag_out_win.cpp — see drag_out_win.h. Hand-rolled IDataObject/IDropSource rather
// than a helper library: the object is tiny (one format, one medium) and the
// copy-only guarantee must be structural and auditable in one place. No REAPER API
// used here (pure OS/COM).
#include "shell/actions/drag_out_win.h"
@@ -29,8 +23,8 @@ namespace {
HGLOBAL buildHDrop(const std::vector<std::string>& paths) {
if (paths.empty()) return nullptr;
// 1) Convert each UTF-8 path to wide, normalizing '/' -> '\\' (the panel stores paths
// slash-normalized for its own resolution; CF_HDROP wants native backslashes).
// Convert each UTF-8 path to wide, normalizing '/' -> '\\' (the panel stores paths
// slash-normalized; CF_HDROP wants native backslashes).
std::vector<std::wstring> wide;
wide.reserve(paths.size());
std::size_t totalChars = 0; // characters incl. each path's terminating NUL
@@ -40,8 +34,7 @@ HGLOBAL buildHDrop(const std::vector<std::string>& paths) {
if (need <= 0) continue; // unconvertible path — skip rather than emit garbage
std::wstring w(static_cast<std::size_t>(need), L'\0');
MultiByteToWideChar(CP_UTF8, 0, p.c_str(), -1, &w[0], need);
// `need` includes the NUL; drop it from the string length, we re-add it in the buffer.
if (!w.empty() && w.back() == L'\0') w.pop_back();
if (!w.empty() && w.back() == L'\0') w.pop_back(); // re-added below
for (wchar_t& c : w) if (c == L'/') c = L'\\';
totalChars += w.size() + 1; // + the per-path NUL
wide.push_back(std::move(w));
@@ -200,10 +193,9 @@ private:
bool initiateDragOut(HWND__* /*panelHwnd*/, const std::vector<std::string>& absolutePaths) {
if (absolutePaths.empty()) return false;
// REAPER's main thread is already OLE-initialized (it hosts OLE drag targets), so we do
// NOT call OleInitialize here — a nested OleInitialize on an already-initialized STA is
// harmless-but-unnecessary, and OleUninitialize pairing across a REAPER-owned apartment
// is the kind of thing that bites. DoDragDrop works on the already-initialized STA.
// REAPER's main thread is already OLE-initialized (it hosts OLE drag targets); we
// deliberately do NOT call OleInitialize — pairing OleUninitialize across a
// REAPER-owned apartment is the kind of thing that bites.
HGLOBAL hdrop = buildHDrop(absolutePaths);
if (!hdrop) return false;
@@ -211,9 +203,8 @@ bool initiateDragOut(HWND__* /*panelHwnd*/, const std::vector<std::string>& abso
auto* source = new DropSource();
DWORD effect = 0;
// COPY-ONLY (invariant #1): the allowed-effects mask is DROPEFFECT_COPY alone. MOVE is
// NEVER offered, so no drop target can relocate (delete) the bank file — only prune
// deletes bank bytes (Phase R boundary).
// COPY-ONLY: the allowed-effects mask is DROPEFFECT_COPY alone. MOVE is never
// offered, so no drop target can relocate (delete) the bank file.
const HRESULT hr = DoDragDrop(data, source, DROPEFFECT_COPY, &effect);
source->Release();
@@ -232,12 +223,9 @@ bool initiateDragOut(HWND__* /*panelHwnd*/, const std::vector<std::string>& abso
namespace reasampler {
// SWELL provides a file-list drag surface (SWELL_InitiateDragDropOfFileList, verified in
// vendor/WDL/WDL/swell/swell-functions.h). It takes a C-string array + count and initiates
// a copy-style file drag from the given window. Unlike OLE it exposes no per-source effect
// mask, so the copy-only guarantee rests on SWELL's copy semantics rather than an explicit
// DROPEFFECT_COPY mask — an honest platform difference, not a faked equivalence. Windows is
// the exact-control path (D5: Windows is the shipping target).
// SWELL_InitiateDragDropOfFileList initiates a copy-style file drag from the given
// window. Unlike OLE it exposes no per-source effect mask, so the copy-only
// guarantee here rests on SWELL's copy semantics rather than an explicit mask.
bool initiateDragOut(HWND__* panelHwnd, const std::vector<std::string>& absolutePaths) {
if (absolutePaths.empty() || !panelHwnd) return false;