Merge pull request #2212 from unxed/ctrl_yo
[far2l.git] / incsrch / clip.c
blobcd19b6df13225cb0d74d788ae825bad41e26f4b2
1 /*
2 FAR manager incremental search plugin, search as you type in editor.
3 Copyright (C) 1999-2019, Stanislav V. Mekhanoshin
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
18 #include "incsrch.h"
20 void PasteSearchText(void)
22 TCHAR *p;
23 size_t len = 0, i;
24 TCHAR pData[MAX_STR];
26 pData[0] = 0;
27 if (!OpenClipboard(NULL))
28 return;
29 #if defined(WINPORT_DIRECT)
30 p = GetClipboardData(CF_UNICODETEXT);
31 len = _tstrnlen(p, MAX_STR);
32 memcpy(pData, p, len * sizeof(pData[0]));
33 #else
34 for (nFmt = 0; (nFmt = EnumClipboardFormats(nFmt)) != 0;) {
35 switch (nFmt) {
36 case CF_TEXT:
37 p = GetClipboardData(CF_TEXT);
38 if (p) {
39 len = _tstrnlen(p, MAX_STR);
40 CharToOemBuff(p, pData, len);
41 goto Ok;
43 continue;
44 case CF_OEMTEXT:
45 p = GetClipboardData(CF_OEMTEXT);
46 if (p) {
47 OEM:
48 len = _tstrnlen(p, MAX_STR);
49 memcpy(pData, p, len * sizeof(pData[0]));
50 goto Ok;
52 continue;
53 case CF_UNICODETEXT:
54 p = GetClipboardData(CF_UNICODETEXT);
55 if (p) {
56 WideCharToMultiByte(CP_OEMCP, WC_COMPOSITECHECK, (LPCWSTR)p, -1, pData, MAX_STR, NULL,
57 NULL);
58 len = _tstrnlen(pData, MAX_STR);
59 goto Ok;
61 continue;
64 p = GetClipboardData(CF_OEMTEXT);
65 if (p)
66 goto OEM;
67 #endif
68 CloseClipboard();
69 for (i = 0; i < len; i++) {
70 if (nEvents == PREVIEW_EVENTS) {
71 #if defined(WINPORT_DIRECT)
72 putwchar('\007');
73 #else
74 MessageBeep((UINT)-1);
75 #endif
76 break;
78 aEvents[nEvents].Flags = (unsigned char)(i ? KC_CHAR | KC_FAILKILL : KC_CHAR);
79 aEvents[nEvents].AsciiChar = pData[i];
80 nEvents++;