|
| 1 | + |
| 2 | +/* |
| 3 | +Copyright (c) 2009 [email protected] |
| 4 | +All rights reserved. |
| 5 | +
|
| 6 | +Redistribution and use in source and binary forms, with or without |
| 7 | +modification, are permitted provided that the following conditions |
| 8 | +are met: |
| 9 | +1. Redistributions of source code must retain the above copyright |
| 10 | +notice, this list of conditions and the following disclaimer. |
| 11 | +2. Redistributions in binary form must reproduce the above copyright |
| 12 | +notice, this list of conditions and the following disclaimer in the |
| 13 | +documentation and/or other materials provided with the distribution. |
| 14 | +3. The name of the authors may not be used to endorse or promote products |
| 15 | +derived from this software without specific prior written permission. |
| 16 | +
|
| 17 | +THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESS OR |
| 18 | +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | +*/ |
| 28 | + |
| 29 | +#include <windows.h> |
| 30 | +#include <crtdbg.h> |
| 31 | +#ifdef FAR_UNICODE |
| 32 | +#pragma message("FAR_UNICODE defined") |
| 33 | +#else |
| 34 | +#pragma message("FAR_UNICODE NOT defined") |
| 35 | +#endif |
| 36 | +#include "version.h" |
| 37 | +#include "../../common/plugin.h" |
| 38 | + |
| 39 | + |
| 40 | +struct PluginStartupInfo psi; |
| 41 | +struct FarStandardFunctions fsf; |
| 42 | + |
| 43 | +#ifdef FAR_UNICODE |
| 44 | +// {8F1F399D-1577-415A-9AC9-83B529F838DE} |
| 45 | +static GUID guid_PluginGuid = |
| 46 | +{ 0x8f1f399d, 0x1577, 0x415a, { 0x9a, 0xc9, 0x83, 0xb5, 0x29, 0xf8, 0x38, 0xde } }; |
| 47 | +// {35F0D0C8-FA74-42A2-92E8-15A47785BB0F} |
| 48 | +static GUID guid_PluginMenu = |
| 49 | +{ 0x35f0d0c8, 0xfa74, 0x42a2, { 0x92, 0xe8, 0x15, 0xa4, 0x77, 0x85, 0xbb, 0x0f } }; |
| 50 | +#endif |
| 51 | + |
| 52 | +BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) |
| 53 | +{ |
| 54 | + return TRUE; |
| 55 | +} |
| 56 | + |
| 57 | +#if defined(__GNUC__) |
| 58 | +#define CRTSTARTUP |
| 59 | +#else |
| 60 | +#define DllMainCRTStartup _DllMainCRTStartup |
| 61 | +#endif |
| 62 | + |
| 63 | +#if defined(CRTSTARTUP) |
| 64 | + |
| 65 | +#ifdef __cplusplus |
| 66 | +extern "C"{ |
| 67 | +#endif |
| 68 | + BOOL WINAPI DllMainCRTStartup(HANDLE hDll,DWORD dwReason,LPVOID lpReserved); |
| 69 | + #if defined(__GNUC__) |
| 70 | + void WINAPI SetStartupInfoW(struct PluginStartupInfo *aInfo); |
| 71 | + #endif |
| 72 | +#ifdef __cplusplus |
| 73 | +}; |
| 74 | +#endif |
| 75 | + |
| 76 | +BOOL WINAPI _DllMainCRTStartup(HANDLE hDll,DWORD dwReason,LPVOID lpReserved) |
| 77 | +{ |
| 78 | + return DllMain(hDll, dwReason,lpReserved); |
| 79 | +} |
| 80 | +#endif |
| 81 | + |
| 82 | + |
| 83 | +#if FAR_UNICODE>=1906 |
| 84 | +void WINAPI GetGlobalInfoW(struct GlobalInfo *Info) |
| 85 | +{ |
| 86 | + _ASSERTE(Info->StructSize == sizeof(GlobalInfo)); |
| 87 | + |
| 88 | + Info->MinFarVersion = /*FARMANAGERVERSION*/ |
| 89 | + MAKEFARVERSION( |
| 90 | + FARMANAGERVERSION_MAJOR, |
| 91 | + FARMANAGERVERSION_MINOR, |
| 92 | + FARMANAGERVERSION_REVISION, |
| 93 | + FARMANAGERVERSION_BUILD, |
| 94 | + FARMANAGERVERSION_STAGE); |
| 95 | + |
| 96 | + Info->Version = MAKEFARVERSION(MVV_1,MVV_2,MVV_3,FARMANAGERVERSION_BUILD,VS_RELEASE); |
| 97 | + |
| 98 | + Info->Guid = guid_PluginGuid; |
| 99 | + Info->Title = L"Clipboard fixer"; |
| 100 | + Info->Description = L"Clipboard fixer"; |
| 101 | + Info-> Author = L"[email protected]"; |
| 102 | +} |
| 103 | + |
| 104 | +#define MAKEFARVERSION2(major,minor,build) ( ((major)<<8) | (minor) | ((build)<<16)) |
| 105 | +#else |
| 106 | +void WINAPI GetGlobalInfoW(void *Info) |
| 107 | +{ |
| 108 | +} |
| 109 | +#endif |
| 110 | + |
| 111 | +// minimal(?) FAR version 2.0 alpha build 1587 |
| 112 | +int WINAPI GetMinFarVersionW(void) |
| 113 | +{ |
| 114 | + int nVer = |
| 115 | + #ifdef _UNICODE |
| 116 | + #if FAR_UNICODE>=1906 |
| 117 | + // ×òîáû â Far2 íå çàãðóæàëñÿ |
| 118 | + MAKEFARVERSION2(FARMANAGERVERSION_MAJOR,FARMANAGERVERSION_MINOR,FARMANAGERVERSION_BUILD) |
| 119 | + #else |
| 120 | + MAKEFARVERSION(FARMANAGERVERSION_MAJOR,FARMANAGERVERSION_MINOR,max(FARMANAGERVERSION_BUILD,1607)) |
| 121 | + #endif |
| 122 | + #else |
| 123 | + FARMANAGERVERSION |
| 124 | + #endif |
| 125 | + ; |
| 126 | + return nVer; |
| 127 | +} |
| 128 | + |
| 129 | +void WINAPI GetPluginInfoW(struct PluginInfo *pi) |
| 130 | +{ |
| 131 | + static WCHAR *szMenu[1], szMenu1[255]; |
| 132 | + szMenu[0] = szMenu1; |
| 133 | + lstrcpyW(szMenu[0], L"Clipboard fixer"); |
| 134 | + |
| 135 | + #ifndef FAR_UNICODE |
| 136 | + if (!pi->StructSize) |
| 137 | + pi->StructSize = sizeof(struct PluginInfo); |
| 138 | + #endif |
| 139 | + |
| 140 | + pi->Flags = PF_EDITOR | PF_DIALOG; |
| 141 | + |
| 142 | + #if FAR_UNICODE>=1906 |
| 143 | + pi->PluginMenu.Guids = &guid_PluginMenu; |
| 144 | + pi->PluginMenu.Strings = szMenu; |
| 145 | + pi->PluginMenu.Count = 1; |
| 146 | + #else |
| 147 | + pi->PluginMenuStrings = szMenu; |
| 148 | + pi->PluginMenuStringsNumber = 1; |
| 149 | + #endif |
| 150 | + |
| 151 | + #ifndef FAR_UNICODE |
| 152 | + // Far 2.x callplugin id |
| 153 | + pi->Reserved = 0x436C4678; |
| 154 | + #endif |
| 155 | +} |
| 156 | + |
| 157 | +void DoTheJob() |
| 158 | +{ |
| 159 | + if (OpenClipboard(NULL)) |
| 160 | + { |
| 161 | + if (CF_TEXT == EnumClipboardFormats(0)) |
| 162 | + { |
| 163 | + if (IsClipboardFormatAvailable(CF_UNICODETEXT)) |
| 164 | + { |
| 165 | + HANDLE hText = GetClipboardData(CF_TEXT); |
| 166 | + HANDLE hUText = GetClipboardData(CF_UNICODETEXT); |
| 167 | + if (hText && hUText) { |
| 168 | + LPCSTR pszText = (LPCSTR)GlobalLock(hText); |
| 169 | + LPCWSTR pwszText = (LPCWSTR)GlobalLock(hUText); |
| 170 | + if (pszText && pwszText) |
| 171 | + { |
| 172 | + BOOL lbNeedFix = FALSE; |
| 173 | + LPCSTR psz = pszText; |
| 174 | + LPCWSTR pwsz = pwszText; |
| 175 | + while (*psz && *pwsz) |
| 176 | + { |
| 177 | + if (*psz > 127 && *pwsz == *psz) |
| 178 | + { |
| 179 | + lbNeedFix = TRUE; |
| 180 | + break; |
| 181 | + } |
| 182 | + psz++; pwsz++; |
| 183 | + } |
| 184 | + if (lbNeedFix) |
| 185 | + { |
| 186 | + if (pwszText) { GlobalUnlock(hUText); pwszText = NULL; } |
| 187 | + size_t nLen = lstrlenA(pszText); |
| 188 | + if ((hUText = GlobalAlloc(GMEM_MOVEABLE, (nLen+1)*2)) != NULL) |
| 189 | + { |
| 190 | + wchar_t *pwszNew = (wchar_t*)GlobalLock(hUText); |
| 191 | + if (pwszNew) |
| 192 | + { |
| 193 | + MultiByteToWideChar(CP_ACP, 0, |
| 194 | + pszText, nLen+1, pwszNew, nLen+1); |
| 195 | + GlobalUnlock(hUText); |
| 196 | + SetClipboardData(CF_UNICODETEXT, hUText); |
| 197 | + } |
| 198 | + else |
| 199 | + { |
| 200 | + // íåóäà÷à |
| 201 | + GlobalUnlock(hUText); |
| 202 | + GlobalFree(hUText); |
| 203 | + } |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | + if (pszText) GlobalUnlock(hText); |
| 208 | + if (pwszText) GlobalUnlock(hUText); |
| 209 | + } |
| 210 | + } |
| 211 | + } |
| 212 | + CloseClipboard(); |
| 213 | + } |
| 214 | +} |
| 215 | + |
| 216 | +HANDLE WINAPI OpenPluginW(int OpenFrom,INT_PTR Item) |
| 217 | +{ |
| 218 | + DoTheJob(); |
| 219 | + return PANEL_STOP; |
| 220 | +} |
| 221 | + |
| 222 | +HANDLE WINAPI OpenW(const struct OpenInfo *Info) |
| 223 | +{ |
| 224 | + DoTheJob(); |
| 225 | + return NULL; |
| 226 | +} |
| 227 | + |
| 228 | +void WINAPI SetStartupInfoW(struct PluginStartupInfo *aInfo) |
| 229 | +{ |
| 230 | + ::psi = *((struct PluginStartupInfo*)aInfo); |
| 231 | + ::fsf = *((struct PluginStartupInfo*)aInfo)->FSF; |
| 232 | + ::psi.FSF = &::fsf; |
| 233 | +} |
0 commit comments