diff --git a/Windows/W32Util/Misc.cpp b/Windows/W32Util/Misc.cpp index 604f270d29..a983506a7d 100644 --- a/Windows/W32Util/Misc.cpp +++ b/Windows/W32Util/Misc.cpp @@ -61,20 +61,24 @@ namespace W32Util BOOL CopyTextToClipboard(HWND hwnd, const char *text) { std::wstring wtext = ConvertUTF8ToWString(text); + return CopyTextToClipboard(hwnd, wtext); + } + + BOOL CopyTextToClipboard(HWND hwnd, const std::wstring &wtext) { OpenClipboard(hwnd); EmptyClipboard(); - HANDLE hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (wtext.size() + 1) * sizeof(wchar_t)); - if (hglbCopy == NULL) { - CloseClipboard(); - return FALSE; - } + HANDLE hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (wtext.size() + 1) * sizeof(wchar_t)); + if (hglbCopy == NULL) { + CloseClipboard(); + return FALSE; + } - // Lock the handle and copy the text to the buffer. + // Lock the handle and copy the text to the buffer. - wchar_t *lptstrCopy = (wchar_t *)GlobalLock(hglbCopy); - wcscpy(lptstrCopy, wtext.c_str()); - lptstrCopy[wtext.size()] = (wchar_t) 0; // null character - GlobalUnlock(hglbCopy); + wchar_t *lptstrCopy = (wchar_t *)GlobalLock(hglbCopy); + wcscpy(lptstrCopy, wtext.c_str()); + lptstrCopy[wtext.size()] = (wchar_t) 0; // null character + GlobalUnlock(hglbCopy); SetClipboardData(CF_UNICODETEXT, hglbCopy); CloseClipboard(); return TRUE; @@ -216,11 +220,53 @@ LRESULT CALLBACK GenericListControl::wndProc(HWND hwnd, UINT msg, WPARAM wParam, case WM_SIZE: list->ResizeColumns(); break; + + case WM_KEYDOWN: + switch (wParam) + { + case VK_INSERT: + case 'C': + if (KeyDownAsync(VK_CONTROL)) + list->ProcessCopy(); + break; + } + break; } return (LRESULT)CallWindowProc((WNDPROC)list->oldProc,hwnd,msg,wParam,lParam); } +void GenericListControl::ProcessCopy() +{ + int start = ListView_GetSelectionMark(handle); + int size; + if (start == -1) + size = GetRowCount(); + else + size = ListView_GetSelectedCount(handle); + + CopyRows(start, size); +} + +void GenericListControl::CopyRows(int start, int size) +{ + std::wstring data; + for (int r = start; r < start + size; ++r) + { + for (int c = 0; c < columnCount; ++c) + { + stringBuffer[0] = 0; + GetColumnText(stringBuffer, r, c); + data.append(stringBuffer); + if (c < columnCount - 1) + data.append(L"\t"); + else + data.append(L"\r\n"); + } + } + W32Util::CopyTextToClipboard(handle, data); +} + int GenericListControl::GetSelectedIndex() { return ListView_GetNextItem(handle, -1, LVNI_SELECTED); diff --git a/Windows/W32Util/Misc.h b/Windows/W32Util/Misc.h index 65c8e1616e..57d2ce6e46 100644 --- a/Windows/W32Util/Misc.h +++ b/Windows/W32Util/Misc.h @@ -8,6 +8,7 @@ namespace W32Util HBITMAP CreateBitmapFromARGB(HWND someHwnd, DWORD *image, int w, int h); void NiceSizeFormat(size_t size, char *out); BOOL CopyTextToClipboard(HWND hwnd, const char *text); + BOOL CopyTextToClipboard(HWND hwnd, const std::wstring &wtext); void MakeTopMost(HWND hwnd, bool topMost); } @@ -41,9 +42,11 @@ protected: virtual int GetRowCount() = 0; virtual void OnDoubleClick(int itemIndex, int column) { }; virtual void OnRightClick(int itemIndex, int column, const POINT& point) { }; + virtual void CopyRows(int start, int size); private: static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); void ResizeColumns(); + void ProcessCopy(); HWND handle; WNDPROC oldProc;