GUITools.cpp 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <shlobj.h>
  5. #include <Common.h>
  6. #include "GUITools.h"
  7. #include "GUIConfiguration.h"
  8. #include <TextsCore.h>
  9. #include <CoreMain.h>
  10. #include <SessionData.h>
  11. #include <WinInterface.h>
  12. #include <TbxUtils.hpp>
  13. #include <Math.hpp>
  14. #include <WebBrowserEx.hpp>
  15. #include <Tools.h>
  16. #include "PngImageList.hpp"
  17. #include <StrUtils.hpp>
  18. #include <limits>
  19. #include <Glyphs.h>
  20. #include <PasTools.hpp>
  21. #include <VCLCommon.h>
  22. #include <WinApi.h>
  23. #include <Vcl.ScreenTips.hpp>
  24. #include <vssym32.h>
  25. #include "Animations96.h"
  26. #include "Animations120.h"
  27. #include "Animations144.h"
  28. #include "Animations192.h"
  29. //---------------------------------------------------------------------------
  30. #pragma package(smart_init)
  31. //---------------------------------------------------------------------------
  32. extern const UnicodeString PageantTool = L"pageant.exe";
  33. extern const UnicodeString PuttygenTool = L"puttygen.exe";
  34. //---------------------------------------------------------------------------
  35. bool __fastcall FindFile(UnicodeString & Path)
  36. {
  37. bool Result = FileExists(ApiPath(Path));
  38. if (!Result)
  39. {
  40. UnicodeString ProgramFiles32 = IncludeTrailingBackslash(GetEnvironmentVariable(L"ProgramFiles"));
  41. UnicodeString ProgramFiles64 = IncludeTrailingBackslash(GetEnvironmentVariable(L"ProgramW6432"));
  42. if (!ProgramFiles32.IsEmpty() &&
  43. SameText(Path.SubString(1, ProgramFiles32.Length()), ProgramFiles32) &&
  44. !ProgramFiles64.IsEmpty())
  45. {
  46. UnicodeString Path64 =
  47. ProgramFiles64 + Path.SubString(ProgramFiles32.Length() + 1, Path.Length() - ProgramFiles32.Length());
  48. if (FileExists(ApiPath(Path64)))
  49. {
  50. Path = Path64;
  51. Result = true;
  52. }
  53. }
  54. }
  55. if (!Result)
  56. {
  57. UnicodeString Paths = GetEnvironmentVariable(L"PATH");
  58. if (!Paths.IsEmpty())
  59. {
  60. UnicodeString NewPath = FileSearch(ExtractFileName(Path), Paths);
  61. Result = !NewPath.IsEmpty();
  62. if (Result)
  63. {
  64. Path = NewPath;
  65. }
  66. }
  67. }
  68. return Result;
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall OpenSessionInPutty(const UnicodeString PuttyPath,
  72. TSessionData * SessionData)
  73. {
  74. UnicodeString Program, AParams, Dir;
  75. SplitCommand(PuttyPath, Program, AParams, Dir);
  76. Program = ExpandEnvironmentVariables(Program);
  77. if (FindFile(Program))
  78. {
  79. AParams = ExpandEnvironmentVariables(AParams);
  80. UnicodeString Password = GUIConfiguration->PuttyPassword ? SessionData->Password : UnicodeString();
  81. TCustomCommandData Data(SessionData, SessionData->UserName, Password);
  82. TRemoteCustomCommand RemoteCustomCommand(Data, SessionData->RemoteDirectory);
  83. TWinInteractiveCustomCommand InteractiveCustomCommand(
  84. &RemoteCustomCommand, L"PuTTY", UnicodeString());
  85. UnicodeString Params =
  86. RemoteCustomCommand.Complete(InteractiveCustomCommand.Complete(AParams, false), true);
  87. UnicodeString PuttyParams;
  88. if (!RemoteCustomCommand.IsSiteCommand(AParams))
  89. {
  90. {
  91. bool SessionList = false;
  92. std::unique_ptr<THierarchicalStorage> SourceHostKeyStorage(Configuration->CreateScpStorage(SessionList));
  93. std::unique_ptr<THierarchicalStorage> TargetHostKeyStorage(new TRegistryStorage(Configuration->PuttyRegistryStorageKey));
  94. TargetHostKeyStorage->Explicit = true;
  95. TargetHostKeyStorage->AccessMode = smReadWrite;
  96. std::unique_ptr<TStoredSessionList> HostKeySessionList(new TStoredSessionList());
  97. HostKeySessionList->OwnsObjects = false;
  98. HostKeySessionList->Add(SessionData);
  99. TStoredSessionList::ImportHostKeys(SourceHostKeyStorage.get(), TargetHostKeyStorage.get(), HostKeySessionList.get(), false);
  100. }
  101. if (IsUWP())
  102. {
  103. bool Telnet = (SessionData->FSProtocol == fsFTP) && GUIConfiguration->TelnetForFtpInPutty;
  104. if (Telnet)
  105. {
  106. AddToList(PuttyParams, L"-telnet", L" ");
  107. // PuTTY does not allow -pw for telnet
  108. Password = L"";
  109. }
  110. AddToList(PuttyParams, EscapePuttyCommandParam(SessionData->HostName), L" ");
  111. if (!SessionData->UserName.IsEmpty())
  112. {
  113. AddToList(PuttyParams, FORMAT(L"-l %s", (EscapePuttyCommandParam(SessionData->UserName))), L" ");
  114. }
  115. if ((SessionData->FSProtocol != fsFTP) && (SessionData->PortNumber != SshPortNumber))
  116. {
  117. AddToList(PuttyParams, FORMAT(L"-P %d", (SessionData->PortNumber)), L" ");
  118. }
  119. if (!Telnet)
  120. {
  121. if (!SessionData->PublicKeyFile.IsEmpty())
  122. {
  123. AddToList(PuttyParams, FORMAT(L"-i \"%s\"", (SessionData->PublicKeyFile)), L" ");
  124. }
  125. AddToList(PuttyParams, (SessionData->TryAgent ? L"-agent" : L"-noagent"), L" ");
  126. if (SessionData->TryAgent)
  127. {
  128. AddToList(PuttyParams, (SessionData->AgentFwd ? L"-A" : L"-a"), L" ");
  129. }
  130. if (SessionData->Compression)
  131. {
  132. AddToList(PuttyParams, L"-C", L" ");
  133. }
  134. AddToList(PuttyParams,
  135. ((SessionData->SshProt == ssh1only || SessionData->SshProt == ssh1deprecated) ? L"-1" : L"-2"), L" ");
  136. if (!SessionData->LogicalHostName.IsEmpty())
  137. {
  138. AddToList(PuttyParams, FORMAT(L"-loghost \"%s\"", (SessionData->LogicalHostName)), L" ");
  139. }
  140. }
  141. if (SessionData->AddressFamily == afIPv4)
  142. {
  143. AddToList(PuttyParams, L"-4", L" ");
  144. }
  145. else if (SessionData->AddressFamily == afIPv6)
  146. {
  147. AddToList(PuttyParams, L"-6", L" ");
  148. }
  149. }
  150. else
  151. {
  152. UnicodeString SessionName;
  153. TRegistryStorage * Storage = NULL;
  154. TSessionData * ExportData = NULL;
  155. TRegistryStorage * SourceStorage = NULL;
  156. try
  157. {
  158. Storage = new TRegistryStorage(Configuration->PuttySessionsKey);
  159. Storage->AccessMode = smReadWrite;
  160. // make it compatible with putty
  161. Storage->MungeStringValues = false;
  162. Storage->ForceAnsi = true;
  163. if (Storage->OpenRootKey(true))
  164. {
  165. if (Storage->KeyExists(SessionData->StorageKey))
  166. {
  167. SessionName = SessionData->SessionName;
  168. }
  169. else
  170. {
  171. SourceStorage = new TRegistryStorage(Configuration->PuttySessionsKey);
  172. SourceStorage->MungeStringValues = false;
  173. SourceStorage->ForceAnsi = true;
  174. if (SourceStorage->OpenSubKey(StoredSessions->DefaultSettings->Name, false) &&
  175. Storage->OpenSubKey(GUIConfiguration->PuttySession, true))
  176. {
  177. Storage->Copy(SourceStorage);
  178. Storage->CloseSubKey();
  179. }
  180. ExportData = new TSessionData(L"");
  181. ExportData->Assign(SessionData);
  182. ExportData->Modified = true;
  183. ExportData->Name = GUIConfiguration->PuttySession;
  184. ExportData->WinTitle = SessionData->SessionName;
  185. ExportData->Password = L"";
  186. if (SessionData->FSProtocol == fsFTP)
  187. {
  188. if (GUIConfiguration->TelnetForFtpInPutty)
  189. {
  190. ExportData->PuttyProtocol = PuttyTelnetProtocol;
  191. ExportData->PortNumber = TelnetPortNumber;
  192. // PuTTY does not allow -pw for telnet
  193. Password = L"";
  194. }
  195. else
  196. {
  197. ExportData->PuttyProtocol = PuttySshProtocol;
  198. ExportData->PortNumber = SshPortNumber;
  199. }
  200. }
  201. ExportData->Save(Storage, true);
  202. SessionName = GUIConfiguration->PuttySession;
  203. }
  204. }
  205. }
  206. __finally
  207. {
  208. delete Storage;
  209. delete ExportData;
  210. delete SourceStorage;
  211. }
  212. UnicodeString LoadSwitch = L"-load";
  213. int P = Params.LowerCase().Pos(LoadSwitch + L" ");
  214. if ((P == 0) || ((P > 1) && (Params[P - 1] != L' ')))
  215. {
  216. AddToList(PuttyParams, FORMAT(L"%s %s", (LoadSwitch, EscapePuttyCommandParam(SessionName))), L" ");
  217. }
  218. }
  219. }
  220. if (!Password.IsEmpty() && !RemoteCustomCommand.IsPasswordCommand(AParams))
  221. {
  222. Password = NormalizeString(Password); // if password is empty, we should quote it always
  223. AddToList(PuttyParams, FORMAT(L"-pw %s", (EscapePuttyCommandParam(Password))), L" ");
  224. }
  225. AddToList(PuttyParams, Params, L" ");
  226. // PuTTY is started in its binary directory to allow relative paths in private key,
  227. // when opening PuTTY's own stored session.
  228. ExecuteShellChecked(Program, PuttyParams, true);
  229. }
  230. else
  231. {
  232. throw Exception(FMTLOAD(FILE_NOT_FOUND, (Program)));
  233. }
  234. }
  235. //---------------------------------------------------------------------------
  236. bool __fastcall FindTool(const UnicodeString & Name, UnicodeString & Path)
  237. {
  238. UnicodeString AppPath = IncludeTrailingBackslash(ExtractFilePath(Application->ExeName));
  239. Path = AppPath + Name;
  240. bool Result = true;
  241. if (!FileExists(ApiPath(Path)))
  242. {
  243. Path = AppPath + L"PuTTY\\" + Name;
  244. if (!FileExists(ApiPath(Path)))
  245. {
  246. Path = Name;
  247. if (!FindFile(Path))
  248. {
  249. Result = false;
  250. }
  251. }
  252. }
  253. return Result;
  254. }
  255. //---------------------------------------------------------------------------
  256. void __fastcall ExecuteTool(const UnicodeString & Name)
  257. {
  258. UnicodeString Path;
  259. if (!FindTool(Name, Path))
  260. {
  261. throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Name)));
  262. }
  263. ExecuteShellChecked(Path, L"");
  264. }
  265. //---------------------------------------------------------------------------
  266. TObjectList * StartCreationDirectoryMonitorsOnEachDrive(unsigned int Filter, TFileChangedEvent OnChanged)
  267. {
  268. std::unique_ptr<TObjectList> Result(new TObjectList());
  269. for (char Drive = FirstDrive; Drive <= LastDrive; Drive++)
  270. {
  271. std::unique_ptr<TDirectoryMonitor> Monitor(new TDirectoryMonitor(Application));
  272. TDriveInfoRec * DriveInfoRec = DriveInfo->Get(Drive);
  273. if (DriveInfoRec->Valid &&
  274. (DriveInfoRec->DriveType != DRIVE_CDROM) &&
  275. ((DriveInfoRec->DriveType != DRIVE_REMOVABLE) || (Drive >= FirstFixedDrive)))
  276. {
  277. try
  278. {
  279. Monitor->Path = DriveInfo->GetDriveRoot(Drive);
  280. Monitor->WatchSubtree = true;
  281. Monitor->WatchFilters = Filter;
  282. Monitor->OnCreated = OnChanged;
  283. Monitor->OnModified = OnChanged;
  284. Monitor->Active = true;
  285. Result->Add(Monitor.release());
  286. }
  287. catch (Exception & E)
  288. {
  289. // Ignore errors watching not-ready drives
  290. }
  291. }
  292. }
  293. return Result.release();
  294. }
  295. //---------------------------------------------------------------------------
  296. bool __fastcall CopyCommandToClipboard(const UnicodeString & Command)
  297. {
  298. bool Result = UseAlternativeFunction() && IsKeyPressed(VK_CONTROL);
  299. if (Result)
  300. {
  301. TInstantOperationVisualizer Visualizer;
  302. CopyToClipboard(Command);
  303. }
  304. return Result;
  305. }
  306. //---------------------------------------------------------------------------
  307. static bool __fastcall DoExecuteShell(const UnicodeString Path, const UnicodeString Params,
  308. bool ChangeWorkingDirectory, HANDLE * Handle)
  309. {
  310. bool Result = CopyCommandToClipboard(FormatCommand(Path, Params));
  311. if (Result)
  312. {
  313. if (Handle != NULL)
  314. {
  315. *Handle = NULL;
  316. }
  317. }
  318. else
  319. {
  320. UnicodeString Directory = ExtractFilePath(Path);
  321. TShellExecuteInfoW ExecuteInfo;
  322. memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));
  323. ExecuteInfo.cbSize = sizeof(ExecuteInfo);
  324. ExecuteInfo.fMask =
  325. SEE_MASK_FLAG_NO_UI |
  326. FLAGMASK((Handle != NULL), SEE_MASK_NOCLOSEPROCESS);
  327. ExecuteInfo.hwnd = Application->Handle;
  328. ExecuteInfo.lpFile = (wchar_t*)Path.data();
  329. ExecuteInfo.lpParameters = (wchar_t*)Params.data();
  330. ExecuteInfo.lpDirectory = (ChangeWorkingDirectory ? Directory.c_str() : NULL);
  331. ExecuteInfo.nShow = SW_SHOW;
  332. Result = (ShellExecuteEx(&ExecuteInfo) != 0);
  333. if (Result)
  334. {
  335. if (Handle != NULL)
  336. {
  337. *Handle = ExecuteInfo.hProcess;
  338. }
  339. }
  340. }
  341. return Result;
  342. }
  343. //---------------------------------------------------------------------------
  344. void __fastcall ExecuteShellChecked(const UnicodeString Path, const UnicodeString Params, bool ChangeWorkingDirectory)
  345. {
  346. if (!DoExecuteShell(Path, Params, ChangeWorkingDirectory, NULL))
  347. {
  348. throw EOSExtException(FMTLOAD(EXECUTE_APP_ERROR, (Path)));
  349. }
  350. }
  351. //---------------------------------------------------------------------------
  352. void __fastcall ExecuteShellChecked(const UnicodeString Command)
  353. {
  354. UnicodeString Program, Params, Dir;
  355. SplitCommand(Command, Program, Params, Dir);
  356. ExecuteShellChecked(Program, Params);
  357. }
  358. //---------------------------------------------------------------------------
  359. bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params,
  360. HANDLE & Handle)
  361. {
  362. return DoExecuteShell(Path, Params, false, &Handle);
  363. }
  364. //---------------------------------------------------------------------------
  365. void __fastcall ExecuteShellCheckedAndWait(const UnicodeString Command,
  366. TProcessMessagesEvent ProcessMessages)
  367. {
  368. UnicodeString Program, Params, Dir;
  369. SplitCommand(Command, Program, Params, Dir);
  370. HANDLE ProcessHandle;
  371. bool Result = DoExecuteShell(Program, Params, false, &ProcessHandle);
  372. if (!Result)
  373. {
  374. throw EOSExtException(FMTLOAD(EXECUTE_APP_ERROR, (Program)));
  375. }
  376. else
  377. {
  378. if (ProcessHandle != NULL) // only if command was copied to clipboard only
  379. {
  380. if (ProcessMessages != NULL)
  381. {
  382. unsigned long WaitResult;
  383. do
  384. {
  385. // Same as in ExecuteProcessAndReadOutput
  386. WaitResult = WaitForSingleObject(ProcessHandle, 200);
  387. if (WaitResult == WAIT_FAILED)
  388. {
  389. throw Exception(LoadStr(DOCUMENT_WAIT_ERROR));
  390. }
  391. ProcessMessages();
  392. }
  393. while (WaitResult == WAIT_TIMEOUT);
  394. }
  395. else
  396. {
  397. WaitForSingleObject(ProcessHandle, INFINITE);
  398. }
  399. }
  400. }
  401. }
  402. //---------------------------------------------------------------------------
  403. bool __fastcall SpecialFolderLocation(int PathID, UnicodeString & Path)
  404. {
  405. LPITEMIDLIST Pidl;
  406. wchar_t Buf[256];
  407. if (SHGetSpecialFolderLocation(NULL, PathID, &Pidl) == NO_ERROR &&
  408. SHGetPathFromIDList(Pidl, Buf))
  409. {
  410. Path = UnicodeString(Buf);
  411. return true;
  412. }
  413. return false;
  414. }
  415. //---------------------------------------------------------------------------
  416. UnicodeString __fastcall UniqTempDir(const UnicodeString BaseDir, const UnicodeString Identity,
  417. bool Mask)
  418. {
  419. DebugAssert(!BaseDir.IsEmpty());
  420. UnicodeString TempDir;
  421. do
  422. {
  423. TempDir = IncludeTrailingBackslash(BaseDir) + Identity;
  424. if (Mask)
  425. {
  426. TempDir += L"?????";
  427. }
  428. else
  429. {
  430. TempDir += IncludeTrailingBackslash(FormatDateTime(L"nnzzz", Now()));
  431. }
  432. }
  433. while (!Mask && DirectoryExists(ApiPath(TempDir)));
  434. return TempDir;
  435. }
  436. //---------------------------------------------------------------------------
  437. bool __fastcall DeleteDirectory(const UnicodeString DirName)
  438. {
  439. TSearchRecOwned sr;
  440. bool retval = true;
  441. if (FindFirstUnchecked(DirName + L"\\*", faAnyFile, sr) == 0) // VCL Function
  442. {
  443. if (sr.IsDirectory())
  444. {
  445. if (sr.IsRealFile())
  446. retval = DeleteDirectory(DirName + L"\\" + sr.Name);
  447. }
  448. else
  449. {
  450. retval = DeleteFile(ApiPath(DirName + L"\\" + sr.Name));
  451. }
  452. if (retval)
  453. {
  454. while (FindNextChecked(sr) == 0)
  455. { // VCL Function
  456. if (sr.IsDirectory())
  457. {
  458. if (sr.IsRealFile())
  459. retval = DeleteDirectory(DirName + L"\\" + sr.Name);
  460. }
  461. else
  462. {
  463. retval = DeleteFile(ApiPath(DirName + L"\\" + sr.Name));
  464. }
  465. if (!retval) break;
  466. }
  467. }
  468. }
  469. sr.Close();
  470. if (retval) retval = RemoveDir(ApiPath(DirName)); // VCL function
  471. return retval;
  472. }
  473. //---------------------------------------------------------------------------
  474. void __fastcall AddSessionColorImage(
  475. TCustomImageList * ImageList, TColor Color, int MaskIndex)
  476. {
  477. // This overly complex drawing is here to support color button on SiteAdvanced
  478. // dialog. There we use plain TImageList, instead of TPngImageList,
  479. // TButton does not work with transparent images
  480. // (not even TBitmap with Transparent = true)
  481. std::unique_ptr<TBitmap> MaskBitmap(new TBitmap());
  482. ImageList->GetBitmap(MaskIndex, MaskBitmap.get());
  483. std::unique_ptr<TPngImage> MaskImage(new TPngImage());
  484. MaskImage->Assign(MaskBitmap.get());
  485. std::unique_ptr<TPngImage> ColorImage(new TPngImage(COLOR_RGB, 16, ImageList->Width, ImageList->Height));
  486. TColor MaskTransparentColor = MaskImage->Pixels[0][0];
  487. TColor TransparentColor = MaskTransparentColor;
  488. // Expecting that the color to be replaced is in the centre of the image (HACK)
  489. TColor MaskColor = MaskImage->Pixels[ImageList->Width / 2][ImageList->Height / 2];
  490. for (int Y = 0; Y < ImageList->Height; Y++)
  491. {
  492. for (int X = 0; X < ImageList->Width; X++)
  493. {
  494. TColor SourceColor = MaskImage->Pixels[X][Y];
  495. TColor DestColor;
  496. // this branch is pointless as long as MaskTransparentColor and
  497. // TransparentColor are the same
  498. if (SourceColor == MaskTransparentColor)
  499. {
  500. DestColor = TransparentColor;
  501. }
  502. else if (SourceColor == MaskColor)
  503. {
  504. DestColor = Color;
  505. }
  506. else
  507. {
  508. DestColor = SourceColor;
  509. }
  510. ColorImage->Pixels[X][Y] = DestColor;
  511. }
  512. }
  513. std::unique_ptr<TBitmap> Bitmap(new TBitmap());
  514. Bitmap->SetSize(ImageList->Width, ImageList->Height);
  515. ColorImage->AssignTo(Bitmap.get());
  516. ImageList->AddMasked(Bitmap.get(), TransparentColor);
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall SetSubmenu(TTBXCustomItem * Item)
  520. {
  521. class TTBXPublicItem : public TTBXCustomItem
  522. {
  523. public:
  524. __property ItemStyle;
  525. };
  526. TTBXPublicItem * PublicItem = reinterpret_cast<TTBXPublicItem *>(Item);
  527. DebugAssert(PublicItem != NULL);
  528. // See TTBItemViewer.IsPtInButtonPart (called from TTBItemViewer.MouseDown)
  529. PublicItem->ItemStyle = PublicItem->ItemStyle << tbisSubmenu;
  530. }
  531. //---------------------------------------------------------------------------
  532. bool __fastcall IsEligibleForApplyingTabs(
  533. UnicodeString Line, int & TabPos, UnicodeString & Start, UnicodeString & Remaining)
  534. {
  535. bool Result = false;
  536. TabPos = Line.Pos(L"\t");
  537. if (TabPos > 0)
  538. {
  539. Remaining = Line.SubString(TabPos + 1, Line.Length() - TabPos);
  540. // WORKAROUND
  541. // Some translations still use obsolete hack of consecutive tabs to aling the contents.
  542. // Delete these, so that the following check does not fail on this
  543. while (Remaining.SubString(1, 1) == L"\t")
  544. {
  545. Remaining.Delete(1, 1);
  546. }
  547. // We do not have, not support, mutiple tabs on a single line
  548. if (DebugAlwaysTrue(Remaining.Pos(L"\t") == 0))
  549. {
  550. Start = Line.SubString(1, TabPos - 1);
  551. // WORKAROUND
  552. // Previously we padded the string before tab with spaces,
  553. // to aling the contents across multiple lines
  554. Start = Start.TrimRight();
  555. // at least two normal spaces for separation
  556. Start += L" ";
  557. Result = true;
  558. }
  559. }
  560. return Result;
  561. }
  562. //---------------------------------------------------------------------------
  563. static int __fastcall CalculateWidthByLength(UnicodeString Text, void * /*Arg*/)
  564. {
  565. return Text.Length();
  566. }
  567. //---------------------------------------------------------------------------
  568. void __fastcall ApplyTabs(
  569. UnicodeString & Text, wchar_t Padding,
  570. TCalculateWidth CalculateWidth, void * CalculateWidthArg)
  571. {
  572. if (CalculateWidth == NULL)
  573. {
  574. DebugAssert(CalculateWidthArg == NULL);
  575. CalculateWidth = CalculateWidthByLength;
  576. }
  577. std::unique_ptr<TStringList> Lines(TextToStringList(Text));
  578. int MaxWidth = -1;
  579. for (int Index = 0; Index < Lines->Count; Index++)
  580. {
  581. UnicodeString Line = Lines->Strings[Index];
  582. int TabPos;
  583. UnicodeString Start;
  584. UnicodeString Remaining;
  585. if (IsEligibleForApplyingTabs(Line, TabPos, Start, Remaining))
  586. {
  587. int Width = CalculateWidth(Start, CalculateWidthArg);
  588. MaxWidth = Max(MaxWidth, Width);
  589. }
  590. }
  591. // Optimization and also to prevent potential regression for texts without tabs
  592. if (MaxWidth >= 0)
  593. {
  594. for (int Index = 0; Index < Lines->Count; Index++)
  595. {
  596. UnicodeString Line = Lines->Strings[Index];
  597. int TabPos;
  598. UnicodeString Start;
  599. UnicodeString Remaining;
  600. if (IsEligibleForApplyingTabs(Line, TabPos, Start, Remaining))
  601. {
  602. int Width;
  603. int Iterations = 0;
  604. while ((Width = CalculateWidth(Start, CalculateWidthArg)) < MaxWidth)
  605. {
  606. int Wider = CalculateWidth(Start + Padding, CalculateWidthArg);
  607. // If padded string is wider than max width by more pixels
  608. // than non-padded string is shorter than max width
  609. if ((Wider > MaxWidth) && ((Wider - MaxWidth) > (MaxWidth - Width)))
  610. {
  611. break;
  612. }
  613. Start += Padding;
  614. Iterations++;
  615. // In rare case a tab is zero-width with some strange font (like HYLE)
  616. if (Iterations > 100)
  617. {
  618. break;
  619. }
  620. }
  621. Lines->Strings[Index] = Start + Remaining;
  622. }
  623. }
  624. Text = Lines->Text;
  625. // remove trailing newline
  626. Text = Text.TrimRight();
  627. }
  628. }
  629. //---------------------------------------------------------------------------
  630. static void __fastcall DoSelectScaledImageList(TImageList * ImageList)
  631. {
  632. TImageList * MatchingList = NULL;
  633. int MachingPixelsPerInch = 0;
  634. int PixelsPerInch = GetComponentPixelsPerInch(ImageList);
  635. for (int Index = 0; Index < ImageList->Owner->ComponentCount; Index++)
  636. {
  637. TImageList * OtherList = dynamic_cast<TImageList *>(ImageList->Owner->Components[Index]);
  638. if ((OtherList != NULL) &&
  639. (OtherList != ImageList) &&
  640. StartsStr(ImageList->Name, OtherList->Name))
  641. {
  642. UnicodeString OtherListPixelsPerInchStr =
  643. OtherList->Name.SubString(
  644. ImageList->Name.Length() + 1, OtherList->Name.Length() - ImageList->Name.Length());
  645. int OtherListPixelsPerInch = StrToInt(OtherListPixelsPerInchStr);
  646. if ((OtherListPixelsPerInch <= PixelsPerInch) &&
  647. ((MatchingList == NULL) ||
  648. (MachingPixelsPerInch < OtherListPixelsPerInch)))
  649. {
  650. MatchingList = OtherList;
  651. MachingPixelsPerInch = OtherListPixelsPerInch;
  652. }
  653. }
  654. }
  655. if (MatchingList != NULL)
  656. {
  657. UnicodeString ImageListBackupName = ImageList->Name + IntToStr(USER_DEFAULT_SCREEN_DPI);
  658. if (ImageList->Owner->FindComponent(ImageListBackupName) == NULL)
  659. {
  660. TImageList * ImageListBackup;
  661. TPngImageList * PngImageList = dynamic_cast<TPngImageList *>(ImageList);
  662. if (PngImageList != NULL)
  663. {
  664. ImageListBackup = new TPngImageList(ImageList->Owner);
  665. }
  666. else
  667. {
  668. ImageListBackup = new TImageList(ImageList->Owner);
  669. }
  670. ImageListBackup->Name = ImageListBackupName;
  671. ImageList->Owner->InsertComponent(ImageListBackup);
  672. CopyImageList(ImageListBackup, ImageList);
  673. }
  674. CopyImageList(ImageList, MatchingList);
  675. }
  676. }
  677. //---------------------------------------------------------------------------
  678. static void __fastcall ImageListRescale(TComponent * Sender, TObject * /*Token*/)
  679. {
  680. TImageList * ImageList = DebugNotNull(dynamic_cast<TImageList *>(Sender));
  681. DoSelectScaledImageList(ImageList);
  682. }
  683. //---------------------------------------------------------------------------
  684. void __fastcall SelectScaledImageList(TImageList * ImageList)
  685. {
  686. DoSelectScaledImageList(ImageList);
  687. SetRescaleFunction(ImageList, ImageListRescale);
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall CopyImageList(TImageList * TargetList, TImageList * SourceList)
  691. {
  692. // Maybe this is not necessary, once the TPngImageList::Assign was fixed
  693. TPngImageList * PngTargetList = dynamic_cast<TPngImageList *>(TargetList);
  694. TPngImageList * PngSourceList = dynamic_cast<TPngImageList *>(SourceList);
  695. TargetList->Clear();
  696. TargetList->Height = SourceList->Height;
  697. TargetList->Width = SourceList->Width;
  698. if ((PngTargetList != NULL) && (PngSourceList != NULL))
  699. {
  700. // AddImages won't copy the names and we need them for
  701. // LoadDialogImage and TFrameAnimation
  702. PngTargetList->PngImages->Assign(PngSourceList->PngImages);
  703. }
  704. else
  705. {
  706. TargetList->AddImages(SourceList);
  707. }
  708. }
  709. //---------------------------------------------------------------------------
  710. static bool __fastcall DoLoadDialogImage(TImage * Image, const UnicodeString & ImageName)
  711. {
  712. bool Result = false;
  713. if (GlyphsModule != NULL)
  714. {
  715. TPngImageList * DialogImages = GetDialogImages(Image);
  716. int Index;
  717. for (Index = 0; Index < DialogImages->PngImages->Count; Index++)
  718. {
  719. TPngImageCollectionItem * PngItem = DialogImages->PngImages->Items[Index];
  720. if (SameText(PngItem->Name, ImageName))
  721. {
  722. Image->Picture->Assign(PngItem->PngImage);
  723. break;
  724. }
  725. }
  726. DebugAssert(Index < DialogImages->PngImages->Count);
  727. Result = true;
  728. }
  729. // When showing an exception from wWinMain, the images are released already.
  730. // Non-existence of the glyphs module is just a good indication of that.
  731. // We expect errors only.
  732. else if (ImageName == L"Error")
  733. {
  734. Image->Picture->Icon->Handle = LoadIcon(0, IDI_HAND);
  735. }
  736. // For showing an information about trace files
  737. else if (DebugAlwaysTrue(ImageName == L"Information"))
  738. {
  739. Image->Picture->Icon->Handle = LoadIcon(0, IDI_APPLICATION);
  740. }
  741. return Result;
  742. }
  743. //---------------------------------------------------------------------------
  744. class TDialogImageName : public TObject
  745. {
  746. public:
  747. UnicodeString ImageName;
  748. };
  749. //---------------------------------------------------------------------------
  750. static void __fastcall DialogImageRescale(TComponent * Sender, TObject * Token)
  751. {
  752. TImage * Image = DebugNotNull(dynamic_cast<TImage *>(Sender));
  753. TDialogImageName * DialogImageName = DebugNotNull(dynamic_cast<TDialogImageName *>(Token));
  754. DoLoadDialogImage(Image, DialogImageName->ImageName);
  755. }
  756. //---------------------------------------------------------------------------
  757. void __fastcall LoadDialogImage(TImage * Image, const UnicodeString & ImageName)
  758. {
  759. if (DoLoadDialogImage(Image, ImageName))
  760. {
  761. TDialogImageName * DialogImageName = new TDialogImageName();
  762. DialogImageName->ImageName = ImageName;
  763. SetRescaleFunction(Image, DialogImageRescale, DialogImageName, true);
  764. }
  765. }
  766. //---------------------------------------------------------------------------
  767. int __fastcall DialogImageSize(TForm * Form)
  768. {
  769. return ScaleByPixelsPerInch(32, Form);
  770. }
  771. //---------------------------------------------------------------------------
  772. void __fastcall HideComponentsPanel(TForm * Form)
  773. {
  774. TComponent * Component = DebugNotNull(Form->FindComponent(L"ComponentsPanel"));
  775. TPanel * Panel = DebugNotNull(dynamic_cast<TPanel *>(Component));
  776. DebugAssert(Panel->Align == alBottom);
  777. int Offset = Panel->Height;
  778. Panel->Visible = false;
  779. Panel->Height = 0;
  780. Form->Height -= Offset;
  781. for (int Index = 0; Index < Form->ControlCount; Index++)
  782. {
  783. TControl * Control = Form->Controls[Index];
  784. // Shift back bottom-anchored controls
  785. // (needed for toolbar panel on Progress window and buttons on Preferences dialog),
  786. if ((Control->Align == alNone) &&
  787. Control->Anchors.Contains(akBottom) &&
  788. !Control->Anchors.Contains(akTop))
  789. {
  790. Control->Top += Offset;
  791. }
  792. // Resize back all-anchored controls
  793. // (needed for main panel on Preferences dialog),
  794. if (Control->Anchors.Contains(akBottom) &&
  795. Control->Anchors.Contains(akTop))
  796. {
  797. Control->Height += Offset;
  798. }
  799. }
  800. }
  801. //---------------------------------------------------------------------------
  802. class TBrowserViewer : public TWebBrowserEx
  803. {
  804. public:
  805. __fastcall virtual TBrowserViewer(TComponent* AOwner);
  806. void __fastcall AddLinkHandler(
  807. const UnicodeString & Url, TNotifyEvent Handler);
  808. void __fastcall NavigateToUrl(const UnicodeString & Url);
  809. TControl * LoadingPanel;
  810. protected:
  811. DYNAMIC void __fastcall DoContextPopup(const TPoint & MousePos, bool & Handled);
  812. void __fastcall DocumentComplete(
  813. TObject * Sender, const _di_IDispatch Disp, const OleVariant & URL);
  814. void __fastcall BeforeNavigate2(
  815. TObject * Sender, const _di_IDispatch Disp, const OleVariant & URL,
  816. const OleVariant & Flags, const OleVariant & TargetFrameName,
  817. const OleVariant & PostData, const OleVariant & Headers, WordBool & Cancel);
  818. bool FComplete;
  819. std::map<UnicodeString, TNotifyEvent> FHandlers;
  820. };
  821. //---------------------------------------------------------------------------
  822. __fastcall TBrowserViewer::TBrowserViewer(TComponent* AOwner) :
  823. TWebBrowserEx(AOwner)
  824. {
  825. FComplete = false;
  826. OnDocumentComplete = DocumentComplete;
  827. OnBeforeNavigate2 = BeforeNavigate2;
  828. LoadingPanel = NULL;
  829. }
  830. //---------------------------------------------------------------------------
  831. void __fastcall TBrowserViewer::AddLinkHandler(
  832. const UnicodeString & Url, TNotifyEvent Handler)
  833. {
  834. FHandlers.insert(std::make_pair(Url, Handler));
  835. }
  836. //---------------------------------------------------------------------------
  837. void __fastcall TBrowserViewer::DoContextPopup(const TPoint & MousePos, bool & Handled)
  838. {
  839. // suppress built-in context menu
  840. Handled = true;
  841. TWebBrowserEx::DoContextPopup(MousePos, Handled);
  842. }
  843. //---------------------------------------------------------------------------
  844. void __fastcall TBrowserViewer::DocumentComplete(
  845. TObject * /*Sender*/, const _di_IDispatch /*Disp*/, const OleVariant & /*URL*/)
  846. {
  847. SetBrowserDesignModeOff(this);
  848. FComplete = true;
  849. if (LoadingPanel != NULL)
  850. {
  851. LoadingPanel->Visible = false;
  852. }
  853. }
  854. //---------------------------------------------------------------------------
  855. void __fastcall TBrowserViewer::BeforeNavigate2(
  856. TObject * /*Sender*/, const _di_IDispatch /*Disp*/, const OleVariant & AURL,
  857. const OleVariant & /*Flags*/, const OleVariant & /*TargetFrameName*/,
  858. const OleVariant & /*PostData*/, const OleVariant & /*Headers*/, WordBool & Cancel)
  859. {
  860. // If OnDocumentComplete was not called yet, is has to be our initial message URL,
  861. // opened using TWebBrowserEx::Navigate(), allow it.
  862. // Otherwise it's user navigating, block that and open link
  863. // in an external browser, possibly adding campaign parameters on the way.
  864. if (FComplete)
  865. {
  866. Cancel = 1;
  867. UnicodeString URL = AURL;
  868. if (FHandlers.count(URL) > 0)
  869. {
  870. FHandlers[URL](this);
  871. }
  872. else
  873. {
  874. OpenBrowser(URL);
  875. }
  876. }
  877. }
  878. //---------------------------------------------------------------------------
  879. void __fastcall TBrowserViewer::NavigateToUrl(const UnicodeString & Url)
  880. {
  881. FComplete = false;
  882. Navigate(Url.c_str());
  883. }
  884. //---------------------------------------------------------------------------
  885. TPanel * __fastcall CreateLabelPanel(TPanel * Parent, const UnicodeString & Label)
  886. {
  887. TPanel * Result = CreateBlankPanel(Parent);
  888. Result->Parent = Parent;
  889. Result->Align = alClient;
  890. Result->Caption = Label;
  891. return Result;
  892. }
  893. //---------------------------------------------------------------------------
  894. TWebBrowserEx * __fastcall CreateBrowserViewer(TPanel * Parent, const UnicodeString & LoadingLabel)
  895. {
  896. TBrowserViewer * Result = new TBrowserViewer(Parent);
  897. // TWebBrowserEx has its own unrelated Name and Parent properties.
  898. // The name is used in DownloadUpdate().
  899. static_cast<TWinControl *>(Result)->Name = L"BrowserViewer";
  900. static_cast<TWinControl *>(Result)->Parent = Parent;
  901. Result->Align = alClient;
  902. Result->ControlBorder = cbNone;
  903. Result->LoadingPanel = CreateLabelPanel(Parent, LoadingLabel);
  904. return Result;
  905. }
  906. //---------------------------------------------------------------------------
  907. void __fastcall SetBrowserDesignModeOff(TWebBrowserEx * WebBrowser)
  908. {
  909. if (DebugAlwaysTrue(WebBrowser->Document2 != NULL))
  910. {
  911. WebBrowser->Document2->designMode = L"Off";
  912. }
  913. }
  914. //---------------------------------------------------------------------------
  915. void __fastcall AddBrowserLinkHandler(TWebBrowserEx * WebBrowser,
  916. const UnicodeString & Url, TNotifyEvent Handler)
  917. {
  918. TBrowserViewer * BrowserViewer = dynamic_cast<TBrowserViewer *>(WebBrowser);
  919. if (DebugAlwaysTrue(BrowserViewer != NULL))
  920. {
  921. BrowserViewer->AddLinkHandler(Url, Handler);
  922. }
  923. }
  924. //---------------------------------------------------------------------------
  925. void __fastcall NavigateBrowserToUrl(TWebBrowserEx * WebBrowser, const UnicodeString & Url)
  926. {
  927. TBrowserViewer * BrowserViewer = dynamic_cast<TBrowserViewer *>(WebBrowser);
  928. if (DebugAlwaysTrue(BrowserViewer != NULL))
  929. {
  930. BrowserViewer->NavigateToUrl(Url);
  931. }
  932. }
  933. //---------------------------------------------------------------------------
  934. TComponent * __fastcall FindComponentRecursively(TComponent * Root, const UnicodeString & Name)
  935. {
  936. for (int Index = 0; Index < Root->ComponentCount; Index++)
  937. {
  938. TComponent * Component = Root->Components[Index];
  939. if (CompareText(Component->Name, Name) == 0)
  940. {
  941. return Component;
  942. }
  943. Component = FindComponentRecursively(Component, Name);
  944. if (Component != NULL)
  945. {
  946. return Component;
  947. }
  948. }
  949. return NULL;
  950. }
  951. //---------------------------------------------------------------------------
  952. void __fastcall GetInstrutionsTheme(
  953. TColor & MainInstructionColor, HFONT & MainInstructionFont, HFONT & InstructionFont)
  954. {
  955. MainInstructionColor = Graphics::clNone;
  956. MainInstructionFont = 0;
  957. InstructionFont = 0;
  958. HTHEME Theme = OpenThemeData(0, L"TEXTSTYLE");
  959. if (Theme != NULL)
  960. {
  961. LOGFONT AFont;
  962. COLORREF AColor;
  963. memset(&AFont, 0, sizeof(AFont));
  964. // Using Canvas->Handle in the 2nd argument we can get scaled font,
  965. // but at this point the form is sometime not scaled yet (difference is particularly for standalone messages like
  966. // /UninstallCleanup), so the results are inconsistent.
  967. if (GetThemeFont(Theme, NULL, TEXT_MAININSTRUCTION, 0, TMT_FONT, &AFont) == S_OK)
  968. {
  969. MainInstructionFont = CreateFontIndirect(&AFont);
  970. }
  971. if (GetThemeColor(Theme, TEXT_MAININSTRUCTION, 0, TMT_TEXTCOLOR, &AColor) == S_OK)
  972. {
  973. MainInstructionColor = (TColor)AColor;
  974. }
  975. memset(&AFont, 0, sizeof(AFont));
  976. if (GetThemeFont(Theme, NULL, TEXT_INSTRUCTION, 0, TMT_FONT, &AFont) == S_OK)
  977. {
  978. InstructionFont = CreateFontIndirect(&AFont);
  979. }
  980. CloseThemeData(Theme);
  981. }
  982. }
  983. //---------------------------------------------------------------------------
  984. TLocalCustomCommand::TLocalCustomCommand()
  985. {
  986. }
  987. //---------------------------------------------------------------------------
  988. TLocalCustomCommand::TLocalCustomCommand(
  989. const TCustomCommandData & Data, const UnicodeString & RemotePath, const UnicodeString & LocalPath) :
  990. TFileCustomCommand(Data, RemotePath)
  991. {
  992. FLocalPath = LocalPath;
  993. }
  994. //---------------------------------------------------------------------------
  995. TLocalCustomCommand::TLocalCustomCommand(const TCustomCommandData & Data,
  996. const UnicodeString & RemotePath, const UnicodeString & LocalPath, const UnicodeString & FileName,
  997. const UnicodeString & LocalFileName, const UnicodeString & FileList) :
  998. TFileCustomCommand(Data, RemotePath, FileName, FileList)
  999. {
  1000. FLocalPath = LocalPath;
  1001. FLocalFileName = LocalFileName;
  1002. }
  1003. //---------------------------------------------------------------------------
  1004. int __fastcall TLocalCustomCommand::PatternLen(const UnicodeString & Command, int Index)
  1005. {
  1006. int Len;
  1007. if ((Index < Command.Length()) && (Command[Index + 1] == L'\\'))
  1008. {
  1009. Len = 2;
  1010. }
  1011. else if ((Index < Command.Length()) && (Command[Index + 1] == L'^'))
  1012. {
  1013. Len = 3;
  1014. }
  1015. else
  1016. {
  1017. Len = TFileCustomCommand::PatternLen(Command, Index);
  1018. }
  1019. return Len;
  1020. }
  1021. //---------------------------------------------------------------------------
  1022. bool __fastcall TLocalCustomCommand::PatternReplacement(
  1023. int Index, const UnicodeString & Pattern, UnicodeString & Replacement, bool & Delimit)
  1024. {
  1025. bool Result;
  1026. if (Pattern == L"!\\")
  1027. {
  1028. // When used as "!\" in an argument to PowerShell, the trailing \ would escpae the ",
  1029. // so we exclude it
  1030. Replacement = ExcludeTrailingBackslash(FLocalPath);
  1031. Result = true;
  1032. }
  1033. else if (Pattern == L"!^!")
  1034. {
  1035. Replacement = FLocalFileName;
  1036. Result = true;
  1037. }
  1038. else
  1039. {
  1040. Result = TFileCustomCommand::PatternReplacement(Index, Pattern, Replacement, Delimit);
  1041. }
  1042. return Result;
  1043. }
  1044. //---------------------------------------------------------------------------
  1045. void __fastcall TLocalCustomCommand::DelimitReplacement(
  1046. UnicodeString & /*Replacement*/, wchar_t /*Quote*/)
  1047. {
  1048. // never delimit local commands
  1049. }
  1050. //---------------------------------------------------------------------------
  1051. bool __fastcall TLocalCustomCommand::HasLocalFileName(const UnicodeString & Command)
  1052. {
  1053. return FindPattern(Command, L'^');
  1054. }
  1055. //---------------------------------------------------------------------------
  1056. bool __fastcall TLocalCustomCommand::IsFileCommand(const UnicodeString & Command)
  1057. {
  1058. return TFileCustomCommand::IsFileCommand(Command) || HasLocalFileName(Command);
  1059. }
  1060. //---------------------------------------------------------------------------
  1061. //---------------------------------------------------------------------------
  1062. typedef std::set<TDataModule *> TImagesModules;
  1063. static TImagesModules ImagesModules;
  1064. static std::map<int, TPngImageList *> AnimationsImages;
  1065. static std::map<int, TImageList *> ButtonImages;
  1066. static std::map<int, TPngImageList *> DialogImages;
  1067. //---------------------------------------------------------------------------
  1068. int __fastcall NormalizePixelsPerInch(int PixelsPerInch)
  1069. {
  1070. if (PixelsPerInch >= 192)
  1071. {
  1072. PixelsPerInch = 192;
  1073. }
  1074. else if (PixelsPerInch >= 144)
  1075. {
  1076. PixelsPerInch = 144;
  1077. }
  1078. else if (PixelsPerInch >= 120)
  1079. {
  1080. PixelsPerInch = 120;
  1081. }
  1082. else
  1083. {
  1084. PixelsPerInch = 96;
  1085. }
  1086. return PixelsPerInch;
  1087. }
  1088. //---------------------------------------------------------------------------
  1089. static int __fastcall NeedImagesModule(TControl * Control)
  1090. {
  1091. int PixelsPerInch = NormalizePixelsPerInch(GetControlPixelsPerInch(Control));
  1092. if (AnimationsImages.find(PixelsPerInch) == AnimationsImages.end())
  1093. {
  1094. TDataModule * ImagesModule;
  1095. HANDLE ResourceModule = GUIConfiguration->ChangeToDefaultResourceModule();
  1096. try
  1097. {
  1098. if (PixelsPerInch == 192)
  1099. {
  1100. ImagesModule = new TAnimations192Module(Application);
  1101. }
  1102. else if (PixelsPerInch == 144)
  1103. {
  1104. ImagesModule = new TAnimations144Module(Application);
  1105. }
  1106. else if (PixelsPerInch == 120)
  1107. {
  1108. ImagesModule = new TAnimations120Module(Application);
  1109. }
  1110. else
  1111. {
  1112. DebugAssert(PixelsPerInch == 96);
  1113. ImagesModule = new TAnimations96Module(Application);
  1114. }
  1115. ImagesModules.insert(ImagesModule);
  1116. TPngImageList * AAnimationImages =
  1117. DebugNotNull(dynamic_cast<TPngImageList *>(ImagesModule->FindComponent(L"AnimationImages")));
  1118. AnimationsImages.insert(std::make_pair(PixelsPerInch, AAnimationImages));
  1119. TImageList * AButtonImages =
  1120. DebugNotNull(dynamic_cast<TImageList *>(ImagesModule->FindComponent(L"ButtonImages")));
  1121. ButtonImages.insert(std::make_pair(PixelsPerInch, AButtonImages));
  1122. TPngImageList * ADialogImages =
  1123. DebugNotNull(dynamic_cast<TPngImageList *>(ImagesModule->FindComponent(L"DialogImages")));
  1124. DialogImages.insert(std::make_pair(PixelsPerInch, ADialogImages));
  1125. }
  1126. __finally
  1127. {
  1128. GUIConfiguration->ChangeResourceModule(ResourceModule);
  1129. }
  1130. }
  1131. return PixelsPerInch;
  1132. }
  1133. //---------------------------------------------------------------------------
  1134. TPngImageList * __fastcall GetAnimationsImages(TControl * Control)
  1135. {
  1136. int PixelsPerInch = NeedImagesModule(Control);
  1137. return DebugNotNull(AnimationsImages[PixelsPerInch]);
  1138. }
  1139. //---------------------------------------------------------------------------
  1140. TImageList * __fastcall GetButtonImages(TControl * Control)
  1141. {
  1142. int PixelsPerInch = NeedImagesModule(Control);
  1143. return DebugNotNull(ButtonImages[PixelsPerInch]);
  1144. }
  1145. //---------------------------------------------------------------------------
  1146. TPngImageList * __fastcall GetDialogImages(TControl * Control)
  1147. {
  1148. int PixelsPerInch = NeedImagesModule(Control);
  1149. return DebugNotNull(DialogImages[PixelsPerInch]);
  1150. }
  1151. //---------------------------------------------------------------------------
  1152. void __fastcall ReleaseImagesModules()
  1153. {
  1154. TImagesModules::iterator i = ImagesModules.begin();
  1155. while (i != ImagesModules.end())
  1156. {
  1157. delete (*i);
  1158. i++;
  1159. }
  1160. ImagesModules.clear();
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. __fastcall TFrameAnimation::TFrameAnimation()
  1164. {
  1165. FFirstFrame = -1;
  1166. }
  1167. //---------------------------------------------------------------------------
  1168. void __fastcall TFrameAnimation::Init(TPaintBox * PaintBox, const UnicodeString & Name)
  1169. {
  1170. FName = Name;
  1171. FPaintBox = PaintBox;
  1172. FPaintBox->ControlStyle = FPaintBox->ControlStyle << csOpaque;
  1173. DebugAssert((FPaintBox->OnPaint == NULL) || (FPaintBox->OnPaint == PaintBoxPaint));
  1174. FPaintBox->OnPaint = PaintBoxPaint;
  1175. SetRescaleFunction(FPaintBox, PaintBoxRescale, reinterpret_cast<TObject *>(this));
  1176. DoInit();
  1177. }
  1178. //---------------------------------------------------------------------------
  1179. void __fastcall TFrameAnimation::DoInit()
  1180. {
  1181. FImageList = GetAnimationsImages(FPaintBox);
  1182. FFirstFrame = -1;
  1183. FFirstLoopFrame = -1;
  1184. FPaintBox->Width = FImageList->Width;
  1185. FPaintBox->Height = FImageList->Height;
  1186. if (!FName.IsEmpty())
  1187. {
  1188. int Frame = 0;
  1189. while (Frame < FImageList->PngImages->Count)
  1190. {
  1191. UnicodeString FrameData = FImageList->PngImages->Items[Frame]->Name;
  1192. UnicodeString FrameName;
  1193. FrameName = CutToChar(FrameData, L'_', false);
  1194. if (SameText(FName, FrameName))
  1195. {
  1196. int FrameIndex = StrToInt(CutToChar(FrameData, L'_', false));
  1197. if (FFirstFrame < 0)
  1198. {
  1199. FFirstFrame = Frame;
  1200. }
  1201. if ((FFirstLoopFrame < 0) && (FrameIndex > 0))
  1202. {
  1203. FFirstLoopFrame = Frame;
  1204. }
  1205. FLastFrame = Frame;
  1206. }
  1207. else
  1208. {
  1209. if (FFirstFrame >= 0)
  1210. {
  1211. // optimization
  1212. break;
  1213. }
  1214. }
  1215. Frame++;
  1216. }
  1217. DebugAssert(FFirstFrame >= 0);
  1218. DebugAssert(FFirstLoopFrame >= 0);
  1219. }
  1220. Stop();
  1221. }
  1222. //---------------------------------------------------------------------------
  1223. void __fastcall TFrameAnimation::PaintBoxRescale(TComponent * /*Sender*/, TObject * Token)
  1224. {
  1225. TFrameAnimation * FrameAnimation = reinterpret_cast<TFrameAnimation *>(Token);
  1226. FrameAnimation->Rescale();
  1227. }
  1228. //---------------------------------------------------------------------------
  1229. void __fastcall TFrameAnimation::Rescale()
  1230. {
  1231. bool Started = (FTimer != NULL) && FTimer->Enabled;
  1232. DoInit();
  1233. if (Started)
  1234. {
  1235. Start();
  1236. }
  1237. }
  1238. //---------------------------------------------------------------------------
  1239. void __fastcall TFrameAnimation::Start()
  1240. {
  1241. if (FFirstFrame >= 0)
  1242. {
  1243. FNextFrameTick = GetTickCount();
  1244. CalculateNextFrameTick();
  1245. if (FTimer == NULL)
  1246. {
  1247. FTimer = new TTimer(GetParentForm(FPaintBox));
  1248. FTimer->Interval = static_cast<int>(GUIUpdateInterval);
  1249. FTimer->OnTimer = Timer;
  1250. }
  1251. else
  1252. {
  1253. // reset timer
  1254. FTimer->Enabled = false;
  1255. FTimer->Enabled = true;
  1256. }
  1257. }
  1258. }
  1259. //---------------------------------------------------------------------------
  1260. void __fastcall TFrameAnimation::Timer(TObject * /*Sender*/)
  1261. {
  1262. Animate();
  1263. }
  1264. //---------------------------------------------------------------------------
  1265. void __fastcall TFrameAnimation::PaintBoxPaint(TObject * Sender)
  1266. {
  1267. if (FFirstFrame >= 0)
  1268. {
  1269. // Double-buffered drawing to prevent flicker (as the images are transparent)
  1270. DebugUsedParam(Sender);
  1271. DebugAssert(FPaintBox == Sender);
  1272. DebugAssert(FPaintBox->ControlStyle.Contains(csOpaque));
  1273. std::unique_ptr<TBitmap> Bitmap(new TBitmap());
  1274. Bitmap->SetSize(FPaintBox->Width, FPaintBox->Height);
  1275. Bitmap->Canvas->Brush->Color = FPaintBox->Color;
  1276. TRect Rect(0, 0, Bitmap->Width, Bitmap->Height);
  1277. Bitmap->Canvas->FillRect(Rect);
  1278. TGraphic * Graphic = GetCurrentImage()->PngImage;
  1279. DebugAssert(Graphic->Width == FPaintBox->Width);
  1280. DebugAssert(Graphic->Height == FPaintBox->Height);
  1281. Bitmap->Canvas->Draw(0, 0, Graphic);
  1282. FPaintBox->Canvas->Draw(0, 0, Bitmap.get());
  1283. }
  1284. FPainted = true;
  1285. }
  1286. //---------------------------------------------------------------------------
  1287. void __fastcall TFrameAnimation::Repaint()
  1288. {
  1289. FPainted = false;
  1290. // If the form is not showing yet, the Paint() is not even called
  1291. FPaintBox->Repaint();
  1292. if (!FPainted)
  1293. {
  1294. // Paint later, alternativelly we may keep trying Repaint() in Animate().
  1295. // See also a hack in TAuthenticateForm::Log.
  1296. FPaintBox->Invalidate();
  1297. }
  1298. }
  1299. //---------------------------------------------------------------------------
  1300. void __fastcall TFrameAnimation::Stop()
  1301. {
  1302. FNextFrameTick = std::numeric_limits<DWORD>::max();
  1303. FCurrentFrame = FFirstFrame;
  1304. Repaint();
  1305. if (FTimer != NULL)
  1306. {
  1307. FTimer->Enabled = false;
  1308. }
  1309. }
  1310. //---------------------------------------------------------------------------
  1311. void __fastcall TFrameAnimation::Animate()
  1312. {
  1313. if (FFirstFrame >= 0)
  1314. {
  1315. // UPGRADE: Use GetTickCount64() when we stop supporting Windows XP.
  1316. DWORD TickCount = GetTickCount();
  1317. // Keep in sync with an opposite condition at the end of the loop.
  1318. // We may skip some frames if we got stalled for a while
  1319. while (TickCount >= FNextFrameTick)
  1320. {
  1321. if (FCurrentFrame >= FLastFrame)
  1322. {
  1323. FCurrentFrame = FFirstLoopFrame;
  1324. }
  1325. else
  1326. {
  1327. FCurrentFrame++;
  1328. }
  1329. CalculateNextFrameTick();
  1330. Repaint();
  1331. }
  1332. }
  1333. }
  1334. //---------------------------------------------------------------------------
  1335. TPngImageCollectionItem * __fastcall TFrameAnimation::GetCurrentImage()
  1336. {
  1337. return FImageList->PngImages->Items[FCurrentFrame];
  1338. }
  1339. //---------------------------------------------------------------------------
  1340. void __fastcall TFrameAnimation::CalculateNextFrameTick()
  1341. {
  1342. TPngImageCollectionItem * ImageItem = GetCurrentImage();
  1343. UnicodeString Duration = ImageItem->Name;
  1344. CutToChar(Duration, L'_', false);
  1345. // skip index (is not really used)
  1346. CutToChar(Duration, L'_', false);
  1347. // This should overflow, when tick count wraps.
  1348. FNextFrameTick += StrToInt(Duration) * 10;
  1349. }
  1350. //---------------------------------------------------------------------------
  1351. //---------------------------------------------------------------------------
  1352. // Hints use:
  1353. // - Cleanup list tooltip (multi line)
  1354. // - Combo edit button
  1355. // - Transfer settings label (multi line, follows label size and font)
  1356. // - HintLabel (hint and persistent hint, multipline)
  1357. // - status bar hints
  1358. //---------------------------------------------------------------------------
  1359. __fastcall TScreenTipHintWindow::TScreenTipHintWindow(TComponent * Owner) :
  1360. THintWindow(Owner)
  1361. {
  1362. FParentPainting = false;
  1363. }
  1364. //---------------------------------------------------------------------------
  1365. int __fastcall TScreenTipHintWindow::GetTextFlags(TControl * Control)
  1366. {
  1367. return DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | Control->DrawTextBiDiModeFlagsReadingOnly();
  1368. }
  1369. //---------------------------------------------------------------------------
  1370. bool __fastcall TScreenTipHintWindow::UseBoldShortHint(TControl * HintControl)
  1371. {
  1372. return
  1373. (dynamic_cast<TTBCustomDockableWindow *>(HintControl) != NULL) ||
  1374. (dynamic_cast<TTBPopupWindow *>(HintControl) != NULL);
  1375. }
  1376. //---------------------------------------------------------------------------
  1377. bool __fastcall TScreenTipHintWindow::IsPathLabel(TControl * HintControl)
  1378. {
  1379. return (dynamic_cast<TPathLabel *>(HintControl) != NULL);
  1380. }
  1381. //---------------------------------------------------------------------------
  1382. int __fastcall TScreenTipHintWindow::GetMargin(TControl * HintControl, const UnicodeString & Hint)
  1383. {
  1384. int Result;
  1385. if (HasLabelHintPopup(HintControl, Hint) || IsPathLabel(HintControl))
  1386. {
  1387. Result = 3;
  1388. }
  1389. else
  1390. {
  1391. Result = 6;
  1392. }
  1393. Result = ScaleByTextHeight(HintControl, Result);
  1394. return Result;
  1395. }
  1396. //---------------------------------------------------------------------------
  1397. TFont * __fastcall TScreenTipHintWindow::GetFont(TControl * HintControl, const UnicodeString & Hint)
  1398. {
  1399. TFont * Result;
  1400. if (HasLabelHintPopup(HintControl, Hint) || IsPathLabel(HintControl))
  1401. {
  1402. Result = reinterpret_cast<TLabel *>(dynamic_cast<TCustomLabel *>(HintControl))->Font;
  1403. }
  1404. else
  1405. {
  1406. FScaledHintFont.reset(new TFont());
  1407. FScaledHintFont->Assign(Screen->HintFont);
  1408. FScaledHintFont->Size = ScaleByPixelsPerInchFromSystem(FScaledHintFont->Size, HintControl);
  1409. Result = FScaledHintFont.get();
  1410. }
  1411. return Result;
  1412. }
  1413. //---------------------------------------------------------------------------
  1414. void __fastcall TScreenTipHintWindow::CalcHintTextRect(TControl * Control, TCanvas * Canvas, TRect & Rect, const UnicodeString & Hint)
  1415. {
  1416. const int Flags = DT_CALCRECT | GetTextFlags(Control);
  1417. DrawText(Canvas->Handle, Hint.c_str(), -1, &Rect, Flags);
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. TRect __fastcall TScreenTipHintWindow::CalcHintRect(int MaxWidth, const UnicodeString AHint, void * AData)
  1421. {
  1422. TControl * HintControl = GetHintControl(AData);
  1423. int Margin = GetMargin(HintControl, AHint);
  1424. UnicodeString ShortHint;
  1425. UnicodeString LongHint;
  1426. SplitHint(HintControl, AHint, ShortHint, LongHint);
  1427. Canvas->Font->Assign(GetFont(HintControl, AHint));
  1428. const int ScreenTipTextOnlyWidth = ScaleByTextHeight(HintControl, cScreenTipTextOnlyWidth);
  1429. if (!LongHint.IsEmpty())
  1430. {
  1431. // double-margin on the right
  1432. MaxWidth = ScreenTipTextOnlyWidth - (3 * Margin);
  1433. }
  1434. // Multi line short hints can be twice as wide, to not break the individual lines unless really necessary.
  1435. // (login site tree, clean up dialog list, preferences custom command list, persistent hint, etc).
  1436. // And they also can be twice as wide, to not break the individual lines unless really necessary.
  1437. if (ShortHint.Pos(L"\n") > 0)
  1438. {
  1439. MaxWidth *= 2;
  1440. }
  1441. bool HintPopup = HasLabelHintPopup(HintControl, AHint);
  1442. if (HintPopup)
  1443. {
  1444. MaxWidth = HintControl->Width;
  1445. }
  1446. if (UseBoldShortHint(HintControl))
  1447. {
  1448. Canvas->Font->Style = TFontStyles() << fsBold;
  1449. }
  1450. TRect ShortRect(0, 0, MaxWidth, 0);
  1451. CalcHintTextRect(this, Canvas, ShortRect, ShortHint);
  1452. Canvas->Font->Style = TFontStyles();
  1453. TRect Result;
  1454. if (LongHint.IsEmpty())
  1455. {
  1456. Result = ShortRect;
  1457. if (HintPopup)
  1458. {
  1459. Result.Right = MaxWidth + 2 * Margin;
  1460. }
  1461. else
  1462. {
  1463. Result.Right += 3 * Margin;
  1464. }
  1465. Result.Bottom += 2 * Margin;
  1466. }
  1467. else
  1468. {
  1469. const int LongIndentation = Margin * 3 / 2;
  1470. TRect LongRect(0, 0, MaxWidth - LongIndentation, 0);
  1471. CalcHintTextRect(this, Canvas, LongRect, LongHint);
  1472. Result.Right = ScreenTipTextOnlyWidth;
  1473. Result.Bottom = Margin + ShortRect.Height() + (Margin / 3 * 5) + LongRect.Height() + Margin;
  1474. }
  1475. // VCLCOPY: To counter the increase in THintWindow::ActivateHintData
  1476. Result.Bottom -= 4;
  1477. return Result;
  1478. }
  1479. //---------------------------------------------------------------------------
  1480. void __fastcall TScreenTipHintWindow::SplitHint(
  1481. TControl * HintControl, const UnicodeString & Hint, UnicodeString & ShortHint, UnicodeString & LongHint)
  1482. {
  1483. if (HasLabelHintPopup(HintControl, Hint))
  1484. {
  1485. ShortHint = HintControl->Hint;
  1486. }
  1487. else
  1488. {
  1489. ShortHint = GetShortHint(Hint);
  1490. LongHint = GetLongHintIfAny(Hint);
  1491. }
  1492. }
  1493. //---------------------------------------------------------------------------
  1494. void __fastcall TScreenTipHintWindow::ActivateHintData(const TRect & ARect, const UnicodeString AHint, void * AData)
  1495. {
  1496. FHintControl = GetHintControl(AData);
  1497. SplitHint(FHintControl, AHint, FShortHint, FLongHint);
  1498. FMargin = GetMargin(FHintControl, AHint);
  1499. FHintPopup = HasLabelHintPopup(FHintControl, AHint);
  1500. Canvas->Font->Assign(GetFont(FHintControl, AHint));
  1501. TRect Rect = ARect;
  1502. if (FHintPopup)
  1503. {
  1504. Rect.SetLocation(FHintControl->ClientToScreen(TPoint(-FMargin, -FMargin)));
  1505. }
  1506. if (IsPathLabel(FHintControl))
  1507. {
  1508. Rect.Offset(-FMargin, -FMargin);
  1509. }
  1510. THintWindow::ActivateHintData(Rect, FShortHint, AData);
  1511. }
  1512. //---------------------------------------------------------------------------
  1513. TControl * __fastcall TScreenTipHintWindow::GetHintControl(void * Data)
  1514. {
  1515. return reinterpret_cast<TControl *>(DebugNotNull(Data));
  1516. }
  1517. //---------------------------------------------------------------------------
  1518. UnicodeString __fastcall TScreenTipHintWindow::GetLongHintIfAny(const UnicodeString & AHint)
  1519. {
  1520. UnicodeString Result;
  1521. int P = Pos(L"|", AHint);
  1522. if (P > 0)
  1523. {
  1524. Result = GetLongHint(AHint);
  1525. }
  1526. return Result;
  1527. }
  1528. //---------------------------------------------------------------------------
  1529. void __fastcall TScreenTipHintWindow::Dispatch(void * AMessage)
  1530. {
  1531. TMessage * Message = static_cast<TMessage*>(AMessage);
  1532. switch (Message->Msg)
  1533. {
  1534. case WM_GETTEXTLENGTH:
  1535. if (FParentPainting)
  1536. {
  1537. // make THintWindow::Paint() not paint the Caption
  1538. Message->Result = 0;
  1539. }
  1540. else
  1541. {
  1542. THintWindow::Dispatch(AMessage);
  1543. }
  1544. break;
  1545. default:
  1546. THintWindow::Dispatch(AMessage);
  1547. break;
  1548. }
  1549. }
  1550. //---------------------------------------------------------------------------
  1551. void __fastcall TScreenTipHintWindow::Paint()
  1552. {
  1553. // paint frame/background
  1554. {
  1555. TAutoFlag ParentPaintingFlag(FParentPainting);
  1556. THintWindow::Paint();
  1557. }
  1558. const int Flags = GetTextFlags(this);
  1559. const int Margin = FMargin - 1; // 1 = border
  1560. TRect Rect = ClientRect;
  1561. Rect.Inflate(-Margin, -Margin);
  1562. if (!FHintPopup)
  1563. {
  1564. Rect.Right -= FMargin;
  1565. }
  1566. if (UseBoldShortHint(FHintControl))
  1567. {
  1568. Canvas->Font->Style = TFontStyles() << fsBold;
  1569. }
  1570. DrawText(Canvas->Handle, FShortHint.c_str(), -1, &Rect, Flags);
  1571. TRect ShortRect = Rect;
  1572. DrawText(Canvas->Handle, FShortHint.c_str(), -1, &ShortRect, DT_CALCRECT | Flags);
  1573. Canvas->Font->Style = TFontStyles();
  1574. if (!FLongHint.IsEmpty())
  1575. {
  1576. Rect.Left += FMargin * 3 / 2;
  1577. Rect.Top += ShortRect.Height() + (FMargin / 3 * 5);
  1578. DrawText(Canvas->Handle, FLongHint.c_str(), -1, &Rect, Flags);
  1579. }
  1580. }
  1581. //---------------------------------------------------------------------------
  1582. //---------------------------------------------------------------------------
  1583. __fastcall TNewRichEdit::TNewRichEdit(TComponent * AOwner) :
  1584. TRichEdit(AOwner),
  1585. FLibrary(0)
  1586. {
  1587. }
  1588. //---------------------------------------------------------------------------
  1589. void __fastcall TNewRichEdit::CreateParams(TCreateParams & Params)
  1590. {
  1591. UnicodeString RichEditModuleName(L"MSFTEDIT.DLL");
  1592. long int OldError;
  1593. OldError = SetErrorMode(SEM_NOOPENFILEERRORBOX);
  1594. FLibrary = LoadLibrary(RichEditModuleName.c_str());
  1595. SetErrorMode(OldError);
  1596. // No fallback, MSFTEDIT.DLL is available since Windows XP
  1597. // https://blogs.msdn.microsoft.com/murrays/2006/10/13/richedit-versions/
  1598. if (FLibrary == 0)
  1599. {
  1600. throw Exception(FORMAT(L"Cannot load %s", (RichEditModuleName)));
  1601. }
  1602. TCustomMemo::CreateParams(Params);
  1603. // MSDN says that we should use MSFTEDIT_CLASS to load Rich Edit 4.1:
  1604. // https://docs.microsoft.com/en-us/windows/desktop/controls/about-rich-edit-controls
  1605. // But MSFTEDIT_CLASS is defined as "RICHEDIT50W",
  1606. // so not sure what version we are loading.
  1607. // Seem to work on Windows XP SP3.
  1608. CreateSubClass(Params, MSFTEDIT_CLASS);
  1609. }
  1610. //---------------------------------------------------------------------------
  1611. void __fastcall TNewRichEdit::CreateWnd()
  1612. {
  1613. TRichEdit::CreateWnd();
  1614. SendMessage(Handle, EM_SETEDITSTYLEEX, 0, SES_EX_HANDLEFRIENDLYURL);
  1615. }
  1616. //---------------------------------------------------------------------------
  1617. void __fastcall TNewRichEdit::DestroyWnd()
  1618. {
  1619. TRichEdit::DestroyWnd();
  1620. if (FLibrary != 0)
  1621. {
  1622. FreeLibrary(FLibrary);
  1623. }
  1624. }