GenerateUrl.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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 Text;
  83. for (int Index = 0; Index < Lines->Count; Index++)
  84. {
  85. Text += Lines->Strings[Index] + L"\n";
  86. }
  87. UnicodeString Url = Text.SubString(ENLink.chrg.cpMin + 1, ENLink.chrg.cpMax - ENLink.chrg.cpMin);
  88. ShowHelp(Url);
  89. }
  90. }
  91. TRichEdit::Dispatch(AMessage);
  92. }
  93. else
  94. {
  95. TRichEdit::Dispatch(AMessage);
  96. }
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TRichEdit41::DestroyWnd()
  100. {
  101. TRichEdit::DestroyWnd();
  102. if (FLibrary != 0)
  103. {
  104. FreeLibrary(FLibrary);
  105. }
  106. }
  107. //---------------------------------------------------------------------------
  108. //---------------------------------------------------------------------------
  109. __fastcall TGenerateUrlDialog::TGenerateUrlDialog(
  110. TComponent * Owner, TSessionData * Data, TStrings * Paths)
  111. : TForm(Owner)
  112. {
  113. UseSystemSettings(this);
  114. FData = Data;
  115. FPaths = Paths;
  116. FChanging = false;
  117. FResultMemo41 = new TRichEdit41(this);
  118. FResultMemo41->Parent = ResultMemo->Parent;
  119. FResultMemo41->SetBounds(ResultMemo->Left, ResultMemo->Top, ResultMemo->Width, ResultMemo->Height);
  120. FResultMemo41->Anchors = ResultMemo->Anchors;
  121. FResultMemo41->BevelInner = ResultMemo->BevelInner;
  122. FResultMemo41->BevelOuter = ResultMemo->BevelOuter;
  123. FResultMemo41->BorderStyle = ResultMemo->BorderStyle;
  124. FResultMemo41->PopupMenu = ResultMemo->PopupMenu;
  125. FResultMemo41->TabOrder = ResultMemo->TabOrder;
  126. FResultMemo41->PlainText = false;
  127. ResultMemo->Visible = false;
  128. ReadOnlyControl(FResultMemo41);
  129. }
  130. //---------------------------------------------------------------------------
  131. bool __fastcall TGenerateUrlDialog::IsFileUrl()
  132. {
  133. return (FPaths != NULL);
  134. }
  135. //---------------------------------------------------------------------------
  136. UnicodeString __fastcall TGenerateUrlDialog::GenerateUrl(UnicodeString Path)
  137. {
  138. UnicodeString Url =
  139. FData->GenerateSessionUrl(
  140. FLAGMASK(WinSCPSpecificCheck->Checked, sufSpecific) |
  141. FLAGMASK(UserNameCheck->Enabled && UserNameCheck->Checked, sufUserName) |
  142. FLAGMASK(PasswordCheck->Enabled && PasswordCheck->Checked, sufPassword) |
  143. FLAGMASK(HostKeyCheck->Enabled && HostKeyCheck->Checked, sufHostKey));
  144. if ((RemoteDirectoryCheck->Enabled && RemoteDirectoryCheck->Checked) ||
  145. IsFileUrl())
  146. {
  147. if (StartsStr(L"/", Path));
  148. {
  149. Path.Delete(1, 1);
  150. }
  151. Url += EncodeUrlPath(Path);
  152. }
  153. if (SaveExtensionCheck->Enabled && SaveExtensionCheck->Checked)
  154. {
  155. Url += UnicodeString(UrlParamSeparator) + UrlSaveParamName;
  156. }
  157. return Url;
  158. }
  159. //---------------------------------------------------------------------------
  160. static UnicodeString __fastcall RtfColorEntry(int Color)
  161. {
  162. return FORMAT(L"\\red%d\\green%d\\blue%d;", ((Color & 0xFF0000) >> 16, (Color & 0x00FF00) >> 8, (Color & 0x0000FF) >> 0));
  163. }
  164. //---------------------------------------------------------------------
  165. static UnicodeString __fastcall RtfScriptComment(const UnicodeString & Text)
  166. {
  167. return RtfColorItalicText(7, Text);
  168. }
  169. //---------------------------------------------------------------------
  170. static UnicodeString __fastcall RtfScriptCommand(const UnicodeString & Command)
  171. {
  172. return RtfLink(L"scriptcommand_" + Command, RtfKeyword(Command));
  173. }
  174. //---------------------------------------------------------------------------
  175. void __fastcall TGenerateUrlDialog::UpdateControls()
  176. {
  177. if (!FChanging)
  178. {
  179. UnicodeString ExeName = Application->ExeName;
  180. Caption = LoadStr(IsFileUrl() ? GENERATE_URL_FILE_TITLE : GENERATE_URL_SESSION_TITLE);
  181. ScriptSheet->TabVisible = !IsFileUrl();
  182. AssemblySheet->TabVisible = !IsFileUrl();
  183. bool HostKeyUnknown = FData->UsesSsh && FData->HostKey.IsEmpty();
  184. UnicodeString ResultGroupCaption;
  185. if (OptionsPageControl->ActivePage == UrlSheet)
  186. {
  187. ResultGroupCaption = LoadStr(GENERATE_URL_URL);
  188. }
  189. else if (OptionsPageControl->ActivePage == ScriptSheet)
  190. {
  191. UnicodeString ScriptDescription;
  192. if (ScriptFormatCombo->ItemIndex == sfCommandLine)
  193. {
  194. ResultGroupCaption = LoadStr(GENERATE_URL_COMMANDLINE_LABEL);
  195. ScriptDescription = FMTLOAD(GENERATE_URL_COMMANDLINE_DESC, (FORMAT("\"%s\"", (ExeName)))) + L"\n";
  196. }
  197. else
  198. {
  199. ResultGroupCaption = ScriptFormatCombo->Items->Strings[ScriptFormatCombo->ItemIndex];
  200. }
  201. if (HostKeyUnknown)
  202. {
  203. ScriptDescription += LoadStr(GENERATE_URL_HOSTKEY_UNKNOWN) + L"\n";
  204. }
  205. ScriptDescriptionLabel->Caption = ScriptDescription;
  206. }
  207. else if (DebugAlwaysTrue(OptionsPageControl->ActivePage == AssemblySheet))
  208. {
  209. ResultGroupCaption = LoadStr(GENERATE_URL_CODE);
  210. UnicodeString AssemblyDescription;
  211. if (HostKeyUnknown)
  212. {
  213. AssemblyDescription += LoadStr(GENERATE_URL_HOSTKEY_UNKNOWN) + L"\n";
  214. }
  215. AssemblyDescriptionLabel->Caption = AssemblyDescription;
  216. }
  217. ResultGroup->Caption = ResultGroupCaption;
  218. EnableControl(UserNameCheck, !FData->UserNameExpanded.IsEmpty());
  219. bool UserNameIncluded = UserNameCheck->Enabled && UserNameCheck->Checked;
  220. EnableControl(PasswordCheck, UserNameIncluded && FData->HasPassword());
  221. EnableControl(HostKeyCheck, UserNameIncluded && !FData->HostKey.IsEmpty());
  222. EnableControl(RemoteDirectoryCheck, !FData->RemoteDirectory.IsEmpty() && !IsFileUrl());
  223. EnableControl(SaveExtensionCheck, !IsFileUrl());
  224. UnicodeString Result;
  225. bool WordWrap = false;
  226. bool FixedWidth = false;
  227. FPlainResult = L"";
  228. if (OptionsPageControl->ActivePage == UrlSheet)
  229. {
  230. if (!IsFileUrl())
  231. {
  232. UnicodeString Path = FData->RemoteDirectory;
  233. if (!Path.IsEmpty() && !EndsStr(L"/", Path))
  234. {
  235. Path += L"/";
  236. }
  237. FPlainResult = GenerateUrl(Path);
  238. Result = RtfText(FPlainResult);
  239. }
  240. else
  241. {
  242. for (int Index = 0; Index < FPaths->Count; Index++)
  243. {
  244. UnicodeString Url = GenerateUrl(FPaths->Strings[Index]);
  245. Result += RtfText(Url) + RtfPara;
  246. FPlainResult +=
  247. Url +
  248. // What CopyToClipboard would have done could we pass in FResultMemo41->Lines
  249. ((FPaths->Count > 0) ? L"\n" : L"");
  250. }
  251. }
  252. WordWrap = true;
  253. }
  254. else if (OptionsPageControl->ActivePage == ScriptSheet)
  255. {
  256. UnicodeString BaseExeName = ExtractFileBaseName(ExeName);
  257. UnicodeString OpenCommand = FData->GenerateOpenCommandArgs();
  258. UnicodeString CommandPlaceholder1 = FMTLOAD(GENERATE_URL_COMMAND, (1));
  259. UnicodeString CommandPlaceholder2 = FMTLOAD(GENERATE_URL_COMMAND, (2));
  260. if (ScriptFormatCombo->ItemIndex == sfScriptFile)
  261. {
  262. Result =
  263. FORMAT(
  264. RtfScriptCommand(L"open") + L" %s" + RtfPara +
  265. RtfPara +
  266. RtfScriptComment("# %s") + RtfPara +
  267. RtfScriptComment("# %s") + RtfPara +
  268. RtfPara +
  269. RtfScriptCommand(L"exit") + RtfPara,
  270. (OpenCommand, CommandPlaceholder1, CommandPlaceholder2));
  271. WordWrap = false;
  272. FixedWidth = true;
  273. }
  274. else if (ScriptFormatCombo->ItemIndex == sfBatchFile)
  275. {
  276. UnicodeString ComExeName = ChangeFileExt(ExeName, L".com");
  277. Result =
  278. RtfScriptComment(L"@echo off") + RtfPara +
  279. RtfPara +
  280. RtfText(L"\"" + ComExeName + "\" ") + RtfParameter(L"/log") + RtfText(L"=" + BaseExeName + L".log ") + RtfParameter(L"/ini") + RtfText(L"=nul ") + RtfParameter(L"/command") + RtfText(L" ^") + RtfPara +
  281. RtfText(L" \"") + RtfScriptCommand(L"open") + RtfText(L" ") + EscapeParam(ReplaceStr(OpenCommand, L"%", L"%%")) + RtfText(L"\" ^") + RtfPara +
  282. RtfText(L" \"") + RtfScriptComment(CommandPlaceholder1) + RtfText(L"\" ^") + RtfPara +
  283. RtfText(L" \"") + RtfScriptComment(CommandPlaceholder2) + RtfText(L"\" ^") + RtfPara +
  284. RtfText(L" \"") + RtfScriptCommand(L"exit") + RtfText(L"\"") + RtfPara +
  285. RtfPara +
  286. RtfKeyword(L"set") + RtfText(L" WINSCP_RESULT=%ERRORLEVEL%") + RtfPara +
  287. RtfKeyword(L"if") + RtfText(L" %WINSCP_RESULT% ") + RtfKeyword(L"equ") + RtfText(L" 0 (") + RtfPara +
  288. RtfText(L" ") + RtfKeyword(L"echo") + RtfText(L" Success") + RtfPara +
  289. RtfText(L") ") + RtfKeyword(L"else") + RtfText(L" (") + RtfPara +
  290. RtfText(L" ") + RtfKeyword(L"echo") + RtfText(L" Error") + RtfPara +
  291. RtfText(L")") + RtfPara +
  292. RtfPara +
  293. RtfKeyword(L"exit") + RtfText(L" /b %WINSCP_RESULT%") + RtfPara;
  294. WordWrap = false;
  295. FixedWidth = true;
  296. }
  297. else if (ScriptFormatCombo->ItemIndex == sfCommandLine)
  298. {
  299. Result =
  300. RtfParameter(L"/log") + RtfText(L"=" + BaseExeName + L".log ") +
  301. RtfParameter(L"/ini") + RtfText(L"=nul ") +
  302. RtfParameter(L"/command") + RtfText(L" ") +
  303. RtfText(L"\"") + RtfScriptCommand(L"open") + RtfText(L" ") + EscapeParam(OpenCommand) + RtfText(L"\" ") +
  304. RtfText(L"\"") + RtfScriptComment(CommandPlaceholder1) + RtfText(L"\" ") +
  305. RtfText(L"\"") + RtfScriptComment(CommandPlaceholder2) + RtfText(L"\" ") +
  306. RtfText(L"\"") + RtfScriptCommand(L"exit") + RtfText(L"\"");
  307. WordWrap = true;
  308. FixedWidth = false;
  309. }
  310. }
  311. else if (DebugAlwaysTrue(OptionsPageControl->ActivePage == AssemblySheet))
  312. {
  313. Result = FData->GenerateAssemblyCode(static_cast<TAssemblyLanguage>(AssemblyLanguageCombo->ItemIndex));
  314. WordWrap = false;
  315. FixedWidth = true;
  316. }
  317. if (FixedWidth)
  318. {
  319. FResultMemo41->Font->Name = CustomWinConfiguration->DefaultFixedWidthFontName;
  320. }
  321. else
  322. {
  323. FResultMemo41->ParentFont = true;
  324. }
  325. Result =
  326. L"{\\rtf1\n"
  327. "{\\colortbl ;" +
  328. // The same RGB as on wiki
  329. RtfColorEntry(0x010101) + // near-black fake color to be used with no-style link to ovreride the default blue underline
  330. RtfColorEntry(0x008000) + // code comment (green)
  331. RtfColorEntry(0x008080) + // class (teal)
  332. RtfColorEntry(0x800000) + // string (maroon)
  333. RtfColorEntry(0x0000FF) + // keyword (blue)
  334. RtfColorEntry(0x993333) + // command-line argument (reddish)
  335. RtfColorEntry(0x808080) + // script command (gray)
  336. L"}\n"
  337. "{\\fonttbl{\\f0\\fnil\\fcharset0 " + FResultMemo41->Font->Name + L";}}\n"
  338. "\\f0\\fs" + IntToStr(FResultMemo41->Font->Size * 2) + L" " +
  339. Result +
  340. "}";
  341. FResultMemo41->WordWrap = WordWrap;
  342. FResultMemo41->ScrollBars = WordWrap ? ssVertical : ssBoth;
  343. std::unique_ptr<TMemoryStream> Stream(new TMemoryStream());
  344. UTF8String ResultUtf = Result;
  345. Stream->Write(ResultUtf.c_str(), ResultUtf.Length());
  346. Stream->Position = 0;
  347. FResultMemo41->Lines->LoadFromStream(Stream.get(), TEncoding::UTF8);
  348. }
  349. }
  350. //---------------------------------------------------------------------------
  351. void __fastcall TGenerateUrlDialog::Execute()
  352. {
  353. int Components = WinConfiguration->GenerateUrlComponents;
  354. if (Components < 0)
  355. {
  356. Components = UserNameCheck->Tag | RemoteDirectoryCheck->Tag;
  357. }
  358. TGenerateUrlCodeTarget Target = WinConfiguration->GenerateUrlCodeTarget;
  359. {
  360. TAutoFlag ChangingFlag(FChanging);
  361. if (IsFileUrl())
  362. {
  363. OptionsPageControl->ActivePage = UrlSheet;
  364. }
  365. else
  366. {
  367. switch (Target)
  368. {
  369. case guctUrl:
  370. OptionsPageControl->ActivePage = UrlSheet;
  371. break;
  372. case guctScript:
  373. OptionsPageControl->ActivePage = ScriptSheet;
  374. break;
  375. case guctAssembly:
  376. OptionsPageControl->ActivePage = AssemblySheet;
  377. break;
  378. default:
  379. DebugFail();
  380. }
  381. }
  382. for (int Index = 0; Index < UrlSheet->ControlCount; Index++)
  383. {
  384. TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(UrlSheet->Controls[Index]);
  385. if (DebugAlwaysTrue((CheckBox != NULL) && (CheckBox->Tag != 0)))
  386. {
  387. CheckBox->Checked = FLAGSET(Components, CheckBox->Tag);
  388. }
  389. }
  390. ScriptFormatCombo->ItemIndex = WinConfiguration->GenerateUrlScriptFormat;
  391. AssemblyLanguageCombo->ItemIndex = WinConfiguration->GenerateUrlAssemblyLanguage;
  392. }
  393. UpdateControls();
  394. ShowModal();
  395. // Do not save the selection for files as the "URL" was selected implicitly
  396. if (!IsFileUrl())
  397. {
  398. if (OptionsPageControl->ActivePage == UrlSheet)
  399. {
  400. Target = guctUrl;
  401. }
  402. else if (OptionsPageControl->ActivePage == ScriptSheet)
  403. {
  404. Target = guctScript;
  405. }
  406. else if (OptionsPageControl->ActivePage == AssemblySheet)
  407. {
  408. Target = guctAssembly;
  409. }
  410. else
  411. {
  412. DebugFail();
  413. }
  414. WinConfiguration->GenerateUrlCodeTarget = Target;
  415. }
  416. if (Target == guctUrl)
  417. {
  418. Components = 0;
  419. for (int Index = 0; Index < UrlSheet->ControlCount; Index++)
  420. {
  421. TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(UrlSheet->Controls[Index]);
  422. if (DebugAlwaysTrue((CheckBox != NULL) && (CheckBox->Tag != 0)) &&
  423. CheckBox->Checked)
  424. {
  425. Components |= CheckBox->Tag;
  426. }
  427. }
  428. WinConfiguration->GenerateUrlComponents = Components;
  429. }
  430. else if (Target == guctScript)
  431. {
  432. WinConfiguration->GenerateUrlScriptFormat = static_cast<TScriptFormat>(ScriptFormatCombo->ItemIndex);
  433. }
  434. else if (Target == guctAssembly)
  435. {
  436. WinConfiguration->GenerateUrlAssemblyLanguage = static_cast<TAssemblyLanguage>(AssemblyLanguageCombo->ItemIndex);
  437. }
  438. }
  439. //---------------------------------------------------------------------------
  440. void __fastcall TGenerateUrlDialog::ControlChange(TObject * /*Sender*/)
  441. {
  442. UpdateControls();
  443. }
  444. //---------------------------------------------------------------------------
  445. void __fastcall TGenerateUrlDialog::ClipboardButtonClick(TObject * /*Sender*/)
  446. {
  447. TInstantOperationVisualizer Visualizer;
  448. UnicodeString Text;
  449. if (FResultMemo41->WordWrap)
  450. {
  451. // Cannot read the text from FResultMemo41->Lines as TRichEdit (as opposite to TMemo)
  452. // breaks wrapped lines
  453. if (!FPlainResult.IsEmpty())
  454. {
  455. Text = FPlainResult;
  456. }
  457. else
  458. {
  459. // We get here with command-line only,
  460. // where we know to have a single line only
  461. DebugAssert((OptionsPageControl->ActivePage == ScriptSheet) && (ScriptFormatCombo->ItemIndex == sfCommandLine));
  462. for (int Index = 0; Index < FResultMemo41->Lines->Count; Index++)
  463. {
  464. Text += FResultMemo41->Lines->Strings[Index];
  465. }
  466. }
  467. }
  468. else
  469. {
  470. // On the other hand, the FResult contains RTF markup
  471. // in which case we want to use FResultMemo41->Lines
  472. Text = StringsToText(FResultMemo41->Lines);
  473. }
  474. int P;
  475. int Index = 1;
  476. while ((P = PosFrom(RtfHyperlinkFieldPrefix, Text, Index)) > 0)
  477. {
  478. int Index2 = P + RtfHyperlinkFieldPrefix.Length();
  479. UnicodeString RtfHyperlinkFieldSuffix = L"\" ";
  480. int P2 = PosFrom(RtfHyperlinkFieldSuffix, Text, Index2);
  481. if (P2 > 0)
  482. {
  483. Text.Delete(P, P2 - P + RtfHyperlinkFieldSuffix.Length());
  484. }
  485. else
  486. {
  487. Index = Index2;
  488. }
  489. }
  490. CopyToClipboard(Text);
  491. }
  492. //---------------------------------------------------------------------------
  493. void __fastcall TGenerateUrlDialog::HelpButtonClick(TObject * /*Sender*/)
  494. {
  495. FormHelp(this);
  496. }
  497. //---------------------------------------------------------------------------
  498. void __fastcall TGenerateUrlDialog::WMNCCreate(TWMNCCreate & Message)
  499. {
  500. // bypass TForm::WMNCCreate to prevent disabling "resize"
  501. // (which is done for bsDialog, see comments in CreateParams)
  502. DefaultHandler(&Message);
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TGenerateUrlDialog::Dispatch(void * AMessage)
  506. {
  507. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  508. if (Message.Msg == WM_NCCREATE)
  509. {
  510. WMNCCreate(*reinterpret_cast<TWMNCCreate *>(AMessage));
  511. }
  512. else
  513. {
  514. TForm::Dispatch(AMessage);
  515. }
  516. }
  517. //---------------------------------------------------------------------------
  518. void __fastcall TGenerateUrlDialog::CreateParams(TCreateParams & Params)
  519. {
  520. TForm::CreateParams(Params);
  521. // Allow resizing of the window, even if this is bsDialog.
  522. // This makes it more close to bsSizeable, but bsSizeable cannot for some
  523. // reason receive focus, if window is shown atop non-main window
  524. // (like editor)
  525. Params.Style = Params.Style | WS_THICKFRAME;
  526. }
  527. //---------------------------------------------------------------------------
  528. void __fastcall TGenerateUrlDialog::ResultMemoContextPopup(TObject * Sender,
  529. TPoint & MousePos, bool & Handled)
  530. {
  531. MenuPopup(Sender, MousePos, Handled);
  532. }
  533. //---------------------------------------------------------------------------
  534. void __fastcall TGenerateUrlDialog::FormShow(TObject * /*Sender*/)
  535. {
  536. UpdateControls();
  537. }
  538. //---------------------------------------------------------------------------