GenerateUrl.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "VCLCommon.h"
  5. #include "GenerateUrl.h"
  6. #include "CoreMain.h"
  7. #include "WinConfiguration.h"
  8. #include <StrUtils.hpp>
  9. #include <Tools.h>
  10. #include <PuttyTools.h>
  11. #include <TextsWin.h>
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #ifndef NO_RESOURCES
  15. #pragma resource "*.dfm"
  16. #endif
  17. //---------------------------------------------------------------------------
  18. void __fastcall DoGenerateUrlDialog(TSessionData * Data, TStrings * Paths)
  19. {
  20. std::unique_ptr<TGenerateUrlDialog> Dialog(new TGenerateUrlDialog(GetFormOwner(), Data, Paths));
  21. Dialog->Execute();
  22. }
  23. //---------------------------------------------------------------------------
  24. // Rich edit 4.1 supports "Friendly name hyperlinks"
  25. class TRichEdit41 : public TRichEdit
  26. {
  27. public:
  28. virtual __fastcall TRichEdit41(TComponent * AOwner);
  29. protected:
  30. virtual void __fastcall CreateWnd();
  31. virtual void __fastcall CreateParams(TCreateParams & Params);
  32. virtual void __fastcall DestroyWnd();
  33. void __fastcall Dispatch(void * Message);
  34. private:
  35. HINSTANCE FLibrary;
  36. };
  37. //---------------------------------------------------------------------------
  38. __fastcall TRichEdit41::TRichEdit41(TComponent * AOwner) :
  39. TRichEdit(AOwner),
  40. FLibrary(0)
  41. {
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TRichEdit41::CreateParams(TCreateParams & Params)
  45. {
  46. UnicodeString RichEditModuleName(L"MSFTEDIT.DLL");
  47. long int OldError;
  48. OldError = SetErrorMode(SEM_NOOPENFILEERRORBOX);
  49. FLibrary = LoadLibrary(RichEditModuleName.c_str());
  50. SetErrorMode(OldError);
  51. TCustomMemo::CreateParams(Params);
  52. // Should not happen as
  53. if (FLibrary != 0)
  54. {
  55. // MSDN says that we should use MSFTEDIT_CLASS to load Rich Edit 4.1:
  56. // https://msdn.microsoft.com/en-us/library/windows/desktop/bb787873.aspx
  57. // But MSFTEDIT_CLASS is defined as "RICHEDIT50W",
  58. // so not sure what version we are loading.
  59. // Seem to work on Windows XP SP3.
  60. CreateSubClass(Params, MSFTEDIT_CLASS);
  61. }
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TRichEdit41::CreateWnd()
  65. {
  66. TRichEdit::CreateWnd();
  67. int Mask = SendMessage(Handle, EM_GETEVENTMASK, 0, 0);
  68. SendMessage(Handle, EM_SETEVENTMASK, 0, Mask | ENM_LINK);
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TRichEdit41::Dispatch(void * AMessage)
  72. {
  73. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  74. if (Message.Msg == CN_NOTIFY)
  75. {
  76. TWMNotify & WMNotify = *reinterpret_cast<TWMNotify *>(AMessage);
  77. if (WMNotify.NMHdr->code == EN_LINK)
  78. {
  79. TENLink & ENLink = *reinterpret_cast<TENLink *>(Message.LParam);
  80. if (ENLink.msg == WM_LBUTTONDOWN)
  81. {
  82. UnicodeString AText = Text;
  83. // The cpMin and cpMax refer to indexes in a script with a single-byte EOL,
  84. // while the Text (GetWindowText) uses two-byte EOL
  85. AText = ReplaceStr(AText, L"\r\n", L"\n");
  86. if (DebugAlwaysTrue(ENLink.chrg.cpMax < AText.Length()))
  87. {
  88. UnicodeString Url = AText.SubString(ENLink.chrg.cpMin + 1, ENLink.chrg.cpMax - ENLink.chrg.cpMin);
  89. ShowHelp(Url);
  90. }
  91. }
  92. }
  93. TRichEdit::Dispatch(AMessage);
  94. }
  95. else
  96. {
  97. TRichEdit::Dispatch(AMessage);
  98. }
  99. }
  100. //---------------------------------------------------------------------------
  101. void __fastcall TRichEdit41::DestroyWnd()
  102. {
  103. TRichEdit::DestroyWnd();
  104. if (FLibrary != 0)
  105. {
  106. FreeLibrary(FLibrary);
  107. }
  108. }
  109. //---------------------------------------------------------------------------
  110. //---------------------------------------------------------------------------
  111. __fastcall TGenerateUrlDialog::TGenerateUrlDialog(
  112. TComponent * Owner, TSessionData * Data, TStrings * Paths)
  113. : TForm(Owner)
  114. {
  115. UseSystemSettings(this);
  116. FData = Data;
  117. FPaths = Paths;
  118. FChanging = false;
  119. FResultMemo41 = new TRichEdit41(this);
  120. FResultMemo41->Parent = ResultMemo->Parent;
  121. FResultMemo41->SetBounds(ResultMemo->Left, ResultMemo->Top, ResultMemo->Width, ResultMemo->Height);
  122. FResultMemo41->Anchors = ResultMemo->Anchors;
  123. FResultMemo41->BevelInner = ResultMemo->BevelInner;
  124. FResultMemo41->BevelOuter = ResultMemo->BevelOuter;
  125. FResultMemo41->BorderStyle = ResultMemo->BorderStyle;
  126. FResultMemo41->PopupMenu = ResultMemo->PopupMenu;
  127. FResultMemo41->TabOrder = ResultMemo->TabOrder;
  128. FResultMemo41->PlainText = false;
  129. ResultMemo->Visible = false;
  130. ReadOnlyControl(FResultMemo41);
  131. }
  132. //---------------------------------------------------------------------------
  133. bool __fastcall TGenerateUrlDialog::IsFileUrl()
  134. {
  135. return (FPaths != NULL);
  136. }
  137. //---------------------------------------------------------------------------
  138. UnicodeString __fastcall TGenerateUrlDialog::GenerateUrl(UnicodeString Path)
  139. {
  140. UnicodeString Url =
  141. FData->GenerateSessionUrl(
  142. FLAGMASK(WinSCPSpecificCheck->Checked, sufSpecific) |
  143. FLAGMASK(UserNameCheck->Enabled && UserNameCheck->Checked, sufUserName) |
  144. FLAGMASK(PasswordCheck->Enabled && PasswordCheck->Checked, sufPassword) |
  145. FLAGMASK(HostKeyCheck->Enabled && HostKeyCheck->Checked, sufHostKey));
  146. if ((RemoteDirectoryCheck->Enabled && RemoteDirectoryCheck->Checked) ||
  147. IsFileUrl())
  148. {
  149. if (StartsStr(L"/", Path));
  150. {
  151. Path.Delete(1, 1);
  152. }
  153. Url += EncodeUrlPath(Path);
  154. }
  155. if (SaveExtensionCheck->Enabled && SaveExtensionCheck->Checked)
  156. {
  157. Url += UnicodeString(UrlParamSeparator) + UrlSaveParamName;
  158. }
  159. return Url;
  160. }
  161. //---------------------------------------------------------------------------
  162. static UnicodeString __fastcall RtfColorEntry(int Color)
  163. {
  164. return FORMAT(L"\\red%d\\green%d\\blue%d;", ((Color & 0xFF0000) >> 16, (Color & 0x00FF00) >> 8, (Color & 0x0000FF) >> 0));
  165. }
  166. //---------------------------------------------------------------------
  167. static UnicodeString __fastcall RtfScriptComment(const UnicodeString & Text)
  168. {
  169. return RtfColorItalicText(7, Text);
  170. }
  171. //---------------------------------------------------------------------
  172. static UnicodeString __fastcall RtfScriptPlaceholder(const UnicodeString & Text)
  173. {
  174. return RtfColorText(7, Text);
  175. }
  176. //---------------------------------------------------------------------
  177. static UnicodeString __fastcall RtfScriptCommand(const UnicodeString & Command)
  178. {
  179. return RtfLink(L"scriptcommand_" + Command, RtfKeyword(Command));
  180. }
  181. //---------------------------------------------------------------------------
  182. void __fastcall TGenerateUrlDialog::UpdateControls()
  183. {
  184. if (!FChanging)
  185. {
  186. UnicodeString ExeName = Application->ExeName;
  187. Caption = LoadStr(IsFileUrl() ? GENERATE_URL_FILE_TITLE : GENERATE_URL_SESSION_TITLE);
  188. ScriptSheet->TabVisible = !IsFileUrl();
  189. AssemblySheet->TabVisible = !IsFileUrl();
  190. bool HostKeyUnknown = FData->UsesSsh && FData->HostKey.IsEmpty();
  191. UnicodeString ResultGroupCaption;
  192. if (OptionsPageControl->ActivePage == UrlSheet)
  193. {
  194. ResultGroupCaption = LoadStr(GENERATE_URL_URL);
  195. }
  196. else if (OptionsPageControl->ActivePage == ScriptSheet)
  197. {
  198. UnicodeString ScriptDescription;
  199. if (ScriptFormatCombo->ItemIndex == sfCommandLine)
  200. {
  201. ResultGroupCaption = LoadStr(GENERATE_URL_COMMANDLINE_LABEL);
  202. ScriptDescription = FMTLOAD(GENERATE_URL_COMMANDLINE_DESC, (FORMAT("\"%s\"", (ExeName)))) + L"\n";
  203. }
  204. else
  205. {
  206. ResultGroupCaption = ScriptFormatCombo->Items->Strings[ScriptFormatCombo->ItemIndex];
  207. }
  208. if (HostKeyUnknown)
  209. {
  210. ScriptDescription += LoadStr(GENERATE_URL_HOSTKEY_UNKNOWN) + L"\n";
  211. }
  212. ScriptDescriptionLabel->Caption = ScriptDescription;
  213. }
  214. else if (DebugAlwaysTrue(OptionsPageControl->ActivePage == AssemblySheet))
  215. {
  216. ResultGroupCaption = LoadStr(GENERATE_URL_CODE);
  217. UnicodeString AssemblyDescription;
  218. if (HostKeyUnknown)
  219. {
  220. AssemblyDescription += LoadStr(GENERATE_URL_HOSTKEY_UNKNOWN) + L"\n";
  221. }
  222. AssemblyDescriptionLabel->Caption = AssemblyDescription;
  223. }
  224. ResultGroup->Caption = ResultGroupCaption;
  225. EnableControl(UserNameCheck, !FData->UserNameExpanded.IsEmpty());
  226. bool UserNameIncluded = UserNameCheck->Enabled && UserNameCheck->Checked;
  227. EnableControl(PasswordCheck, UserNameIncluded && FData->HasPassword());
  228. EnableControl(HostKeyCheck, UserNameIncluded && !FData->HostKey.IsEmpty());
  229. EnableControl(RemoteDirectoryCheck, !FData->RemoteDirectory.IsEmpty() && !IsFileUrl());
  230. EnableControl(SaveExtensionCheck, !IsFileUrl());
  231. UnicodeString Result;
  232. bool WordWrap = false;
  233. bool FixedWidth = false;
  234. if (OptionsPageControl->ActivePage == UrlSheet)
  235. {
  236. if (!IsFileUrl())
  237. {
  238. UnicodeString Path = FData->RemoteDirectory;
  239. if (!Path.IsEmpty() && !EndsStr(L"/", Path))
  240. {
  241. Path += L"/";
  242. }
  243. Result = RtfText(GenerateUrl(Path));
  244. }
  245. else
  246. {
  247. for (int Index = 0; Index < FPaths->Count; Index++)
  248. {
  249. UnicodeString Url = GenerateUrl(FPaths->Strings[Index]);
  250. Result += RtfText(Url) + RtfPara;
  251. }
  252. }
  253. WordWrap = true;
  254. }
  255. else if (OptionsPageControl->ActivePage == ScriptSheet)
  256. {
  257. UnicodeString BaseExeName = ExtractFileBaseName(ExeName);
  258. UnicodeString OpenCommand = FData->GenerateOpenCommandArgs();
  259. UnicodeString CommandPlaceholder1 = FMTLOAD(GENERATE_URL_COMMAND, (1));
  260. UnicodeString CommandPlaceholder2 = FMTLOAD(GENERATE_URL_COMMAND, (2));
  261. UnicodeString LogParameter =
  262. RtfParameter(L"/log") + RtfText(L"=") +
  263. RtfScriptPlaceholder(LoadStr(GENERATE_URL_WRITABLE_PATH_TO_LOG) + RtfText(BaseExeName + L".log"));
  264. if (ScriptFormatCombo->ItemIndex == sfScriptFile)
  265. {
  266. Result =
  267. FORMAT(
  268. RtfScriptCommand(L"open") + L" %s" + RtfPara +
  269. RtfPara +
  270. RtfScriptComment("# %s") + RtfPara +
  271. RtfScriptComment("# %s") + RtfPara +
  272. RtfPara +
  273. RtfScriptCommand(L"exit") + RtfPara,
  274. (OpenCommand, CommandPlaceholder1, CommandPlaceholder2));
  275. WordWrap = false;
  276. FixedWidth = true;
  277. }
  278. else if (ScriptFormatCombo->ItemIndex == sfBatchFile)
  279. {
  280. UnicodeString ComExeName = ChangeFileExt(ExeName, L".com");
  281. Result =
  282. RtfScriptPlaceholder(L"@echo off") + RtfPara +
  283. RtfPara +
  284. RtfText(L"\"" + ComExeName + "\" ^") + RtfPara +
  285. RtfText(L" ") + LogParameter + L" " + RtfParameter(L"/ini") + RtfText(L"=nul ^") + RtfPara +
  286. RtfText(L" ") + RtfParameter(L"/command") + RtfText(L" ^") + RtfPara +
  287. RtfText(L" \"") + RtfScriptCommand(L"open") + RtfText(L" ") + EscapeParam(ReplaceStr(OpenCommand, L"%", L"%%")) + RtfText(L"\" ^") + RtfPara +
  288. RtfText(L" \"") + RtfScriptPlaceholder(CommandPlaceholder1) + RtfText(L"\" ^") + RtfPara +
  289. RtfText(L" \"") + RtfScriptPlaceholder(CommandPlaceholder2) + RtfText(L"\" ^") + RtfPara +
  290. RtfText(L" \"") + RtfScriptCommand(L"exit") + RtfText(L"\"") + RtfPara +
  291. RtfPara +
  292. RtfKeyword(L"set") + RtfText(L" WINSCP_RESULT=%ERRORLEVEL%") + RtfPara +
  293. RtfKeyword(L"if") + RtfText(L" %WINSCP_RESULT% ") + RtfKeyword(L"equ") + RtfText(L" 0 (") + RtfPara +
  294. RtfText(L" ") + RtfKeyword(L"echo") + RtfText(L" Success") + RtfPara +
  295. RtfText(L") ") + RtfKeyword(L"else") + RtfText(L" (") + RtfPara +
  296. RtfText(L" ") + RtfKeyword(L"echo") + RtfText(L" Error") + RtfPara +
  297. RtfText(L")") + RtfPara +
  298. RtfPara +
  299. RtfKeyword(L"exit") + RtfText(L" /b %WINSCP_RESULT%") + RtfPara;
  300. WordWrap = false;
  301. FixedWidth = true;
  302. }
  303. else if (ScriptFormatCombo->ItemIndex == sfCommandLine)
  304. {
  305. Result =
  306. LogParameter + L" " +
  307. RtfParameter(L"/ini") + RtfText(L"=nul ") +
  308. RtfParameter(L"/command") + RtfText(L" ") +
  309. RtfText(L"\"") + RtfScriptCommand(L"open") + RtfText(L" ") + EscapeParam(OpenCommand) + RtfText(L"\" ") +
  310. RtfText(L"\"") + RtfScriptComment(CommandPlaceholder1) + RtfText(L"\" ") +
  311. RtfText(L"\"") + RtfScriptComment(CommandPlaceholder2) + RtfText(L"\" ") +
  312. RtfText(L"\"") + RtfScriptCommand(L"exit") + RtfText(L"\"");
  313. WordWrap = true;
  314. FixedWidth = false;
  315. }
  316. }
  317. else if (DebugAlwaysTrue(OptionsPageControl->ActivePage == AssemblySheet))
  318. {
  319. Result = FData->GenerateAssemblyCode(static_cast<TAssemblyLanguage>(AssemblyLanguageCombo->ItemIndex));
  320. WordWrap = false;
  321. FixedWidth = true;
  322. }
  323. if (FixedWidth)
  324. {
  325. FResultMemo41->Font->Name = CustomWinConfiguration->DefaultFixedWidthFontName;
  326. }
  327. else
  328. {
  329. FResultMemo41->ParentFont = true;
  330. }
  331. Result =
  332. L"{\\rtf1\n"
  333. "{\\colortbl ;" +
  334. // The same RGB as on wiki
  335. RtfColorEntry(0x010101) + // near-black fake color to be used with no-style link to ovreride the default blue underline
  336. RtfColorEntry(0x008000) + // code comment (green)
  337. RtfColorEntry(0x008080) + // class (teal)
  338. RtfColorEntry(0x800000) + // string (maroon)
  339. RtfColorEntry(0x0000FF) + // keyword (blue)
  340. RtfColorEntry(0x993333) + // command-line argument (reddish)
  341. RtfColorEntry(0x808080) + // script command (gray)
  342. L"}\n"
  343. "{\\fonttbl{\\f0\\fnil\\fcharset0 " + FResultMemo41->Font->Name + L";}}\n"
  344. "\\f0\\fs" + IntToStr(FResultMemo41->Font->Size * 2) + L" " +
  345. Result +
  346. "}";
  347. FResultMemo41->WordWrap = WordWrap;
  348. FResultMemo41->ScrollBars = WordWrap ? ssVertical : ssBoth;
  349. std::unique_ptr<TMemoryStream> Stream(new TMemoryStream());
  350. UTF8String ResultUtf = Result;
  351. Stream->Write(ResultUtf.c_str(), ResultUtf.Length());
  352. Stream->Position = 0;
  353. FResultMemo41->Lines->LoadFromStream(Stream.get(), TEncoding::UTF8);
  354. }
  355. }
  356. //---------------------------------------------------------------------------
  357. void __fastcall TGenerateUrlDialog::Execute()
  358. {
  359. int Components = WinConfiguration->GenerateUrlComponents;
  360. if (Components < 0)
  361. {
  362. Components = UserNameCheck->Tag | RemoteDirectoryCheck->Tag;
  363. }
  364. TGenerateUrlCodeTarget Target = WinConfiguration->GenerateUrlCodeTarget;
  365. {
  366. TAutoFlag ChangingFlag(FChanging);
  367. if (IsFileUrl())
  368. {
  369. OptionsPageControl->ActivePage = UrlSheet;
  370. }
  371. else
  372. {
  373. switch (Target)
  374. {
  375. case guctUrl:
  376. OptionsPageControl->ActivePage = UrlSheet;
  377. break;
  378. case guctScript:
  379. OptionsPageControl->ActivePage = ScriptSheet;
  380. break;
  381. case guctAssembly:
  382. OptionsPageControl->ActivePage = AssemblySheet;
  383. break;
  384. default:
  385. DebugFail();
  386. }
  387. }
  388. for (int Index = 0; Index < UrlSheet->ControlCount; Index++)
  389. {
  390. TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(UrlSheet->Controls[Index]);
  391. if (DebugAlwaysTrue((CheckBox != NULL) && (CheckBox->Tag != 0)))
  392. {
  393. CheckBox->Checked = FLAGSET(Components, CheckBox->Tag);
  394. }
  395. }
  396. ScriptFormatCombo->ItemIndex = WinConfiguration->GenerateUrlScriptFormat;
  397. AssemblyLanguageCombo->ItemIndex = WinConfiguration->GenerateUrlAssemblyLanguage;
  398. }
  399. UpdateControls();
  400. ShowModal();
  401. // Do not save the selection for files as the "URL" was selected implicitly
  402. if (!IsFileUrl())
  403. {
  404. if (OptionsPageControl->ActivePage == UrlSheet)
  405. {
  406. Target = guctUrl;
  407. }
  408. else if (OptionsPageControl->ActivePage == ScriptSheet)
  409. {
  410. Target = guctScript;
  411. }
  412. else if (OptionsPageControl->ActivePage == AssemblySheet)
  413. {
  414. Target = guctAssembly;
  415. }
  416. else
  417. {
  418. DebugFail();
  419. }
  420. WinConfiguration->GenerateUrlCodeTarget = Target;
  421. }
  422. if (Target == guctUrl)
  423. {
  424. Components = 0;
  425. for (int Index = 0; Index < UrlSheet->ControlCount; Index++)
  426. {
  427. TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(UrlSheet->Controls[Index]);
  428. if (DebugAlwaysTrue((CheckBox != NULL) && (CheckBox->Tag != 0)) &&
  429. CheckBox->Checked)
  430. {
  431. Components |= CheckBox->Tag;
  432. }
  433. }
  434. WinConfiguration->GenerateUrlComponents = Components;
  435. }
  436. else if (Target == guctScript)
  437. {
  438. WinConfiguration->GenerateUrlScriptFormat = static_cast<TScriptFormat>(ScriptFormatCombo->ItemIndex);
  439. }
  440. else if (Target == guctAssembly)
  441. {
  442. WinConfiguration->GenerateUrlAssemblyLanguage = static_cast<TAssemblyLanguage>(AssemblyLanguageCombo->ItemIndex);
  443. }
  444. }
  445. //---------------------------------------------------------------------------
  446. void __fastcall TGenerateUrlDialog::ControlChange(TObject * /*Sender*/)
  447. {
  448. UpdateControls();
  449. }
  450. //---------------------------------------------------------------------------
  451. void __fastcall TGenerateUrlDialog::ClipboardButtonClick(TObject * /*Sender*/)
  452. {
  453. TInstantOperationVisualizer Visualizer;
  454. // Cannot read the text from FResultMemo41->Lines as TRichEdit (as opposite to TMemo)
  455. // breaks wrapped lines
  456. UnicodeString Text = FResultMemo41->Text;
  457. UnicodeString EOL = sLineBreak;
  458. int P = Pos(EOL, Text);
  459. // Trim the EOL of the only string, what CopyToClipbaord(FResultMemo41->Lines) would have done.
  460. // It probably never happens as rich edit does not return EOL on the last line.
  461. if (DebugAlwaysFalse(P == Text.Length() - EOL.Length() + 1))
  462. {
  463. Text.SetLength(Text.Length() - EOL.Length());
  464. }
  465. // Add trailing EOL, if there are multiple lines (see above)
  466. else if ((P > 0) && !EndsStr(EOL, Text))
  467. {
  468. Text += EOL;
  469. }
  470. // Remove all tags HYPERLINK "http://www.example.com"
  471. int Index = 1;
  472. while ((P = PosFrom(RtfHyperlinkFieldPrefix, Text, Index)) > 0)
  473. {
  474. int Index2 = P + RtfHyperlinkFieldPrefix.Length();
  475. UnicodeString RtfHyperlinkFieldSuffix = L"\" ";
  476. int P2 = PosFrom(RtfHyperlinkFieldSuffix, Text, Index2);
  477. if (P2 > 0)
  478. {
  479. Text.Delete(P, P2 - P + RtfHyperlinkFieldSuffix.Length());
  480. }
  481. else
  482. {
  483. Index = Index2;
  484. }
  485. }
  486. CopyToClipboard(Text);
  487. }
  488. //---------------------------------------------------------------------------
  489. void __fastcall TGenerateUrlDialog::HelpButtonClick(TObject * /*Sender*/)
  490. {
  491. FormHelp(this);
  492. }
  493. //---------------------------------------------------------------------------
  494. void __fastcall TGenerateUrlDialog::WMNCCreate(TWMNCCreate & Message)
  495. {
  496. // bypass TForm::WMNCCreate to prevent disabling "resize"
  497. // (which is done for bsDialog, see comments in CreateParams)
  498. DefaultHandler(&Message);
  499. }
  500. //---------------------------------------------------------------------------
  501. void __fastcall TGenerateUrlDialog::Dispatch(void * AMessage)
  502. {
  503. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  504. if (Message.Msg == WM_NCCREATE)
  505. {
  506. WMNCCreate(*reinterpret_cast<TWMNCCreate *>(AMessage));
  507. }
  508. else
  509. {
  510. TForm::Dispatch(AMessage);
  511. }
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TGenerateUrlDialog::CreateParams(TCreateParams & Params)
  515. {
  516. TForm::CreateParams(Params);
  517. // Allow resizing of the window, even if this is bsDialog.
  518. // This makes it more close to bsSizeable, but bsSizeable cannot for some
  519. // reason receive focus, if window is shown atop non-main window
  520. // (like editor)
  521. Params.Style = Params.Style | WS_THICKFRAME;
  522. }
  523. //---------------------------------------------------------------------------
  524. void __fastcall TGenerateUrlDialog::ResultMemoContextPopup(TObject * Sender,
  525. TPoint & MousePos, bool & Handled)
  526. {
  527. MenuPopup(Sender, MousePos, Handled);
  528. }
  529. //---------------------------------------------------------------------------
  530. void __fastcall TGenerateUrlDialog::FormShow(TObject * /*Sender*/)
  531. {
  532. UpdateControls();
  533. }
  534. //---------------------------------------------------------------------------