UserInterface.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "ScpCommander.h"
  5. #include "ScpExplorer.h"
  6. #include <CoreMain.h>
  7. #include <Common.h>
  8. #include <Exceptions.h>
  9. #include <Cryptography.h>
  10. #include "ProgParams.h"
  11. #include "VCLCommon.h"
  12. #include "WinConfiguration.h"
  13. #include "TerminalManager.h"
  14. #include "TextsWin.h"
  15. #include "TBXThemes.hpp"
  16. #include "TBXOfficeXPTheme.hpp"
  17. #include "TBXOffice2003Theme.hpp"
  18. #include "PasswordEdit.hpp"
  19. #include "ProgParams.h"
  20. #include "Tools.h"
  21. #include "Custom.h"
  22. #include "HelpWin.h"
  23. #include <Math.hpp>
  24. //---------------------------------------------------------------------------
  25. #pragma package(smart_init)
  26. //---------------------------------------------------------------------------
  27. const UnicodeString AppName = L"WinSCP";
  28. //---------------------------------------------------------------------------
  29. TConfiguration * __fastcall CreateConfiguration()
  30. {
  31. TConfiguration * Configuration = new TWinConfiguration();
  32. TProgramParams * Params = TProgramParams::Instance();
  33. UnicodeString IniFileName = Params->SwitchValue(L"ini");
  34. if (!IniFileName.IsEmpty())
  35. {
  36. if (AnsiSameText(IniFileName, L"nul"))
  37. {
  38. Configuration->SetNulStorage();
  39. }
  40. else
  41. {
  42. IniFileName = ExpandFileName(ExpandEnvironmentVariables(IniFileName));
  43. Configuration->IniFileStorageName = IniFileName;
  44. }
  45. }
  46. return Configuration;
  47. }
  48. //---------------------------------------------------------------------------
  49. TCustomScpExplorerForm * __fastcall CreateScpExplorer()
  50. {
  51. TCustomScpExplorerForm * ScpExplorer;
  52. if (WinConfiguration->Interface == ifExplorer)
  53. {
  54. ScpExplorer = SafeFormCreate<TScpExplorerForm>();
  55. }
  56. else
  57. {
  58. ScpExplorer = SafeFormCreate<TScpCommanderForm>();
  59. }
  60. return ScpExplorer;
  61. }
  62. //---------------------------------------------------------------------------
  63. UnicodeString __fastcall SshVersionString()
  64. {
  65. return FORMAT(L"WinSCP-release-%s", (Configuration->Version));
  66. }
  67. //---------------------------------------------------------------------------
  68. UnicodeString __fastcall AppNameString()
  69. {
  70. return L"WinSCP";
  71. }
  72. //---------------------------------------------------------------------------
  73. UnicodeString __fastcall GetCompanyRegistryKey()
  74. {
  75. return L"Software\\Martin Prikryl";
  76. }
  77. //---------------------------------------------------------------------------
  78. UnicodeString __fastcall GetRegistryKey()
  79. {
  80. return GetCompanyRegistryKey() + L"\\WinSCP 2";
  81. }
  82. //---------------------------------------------------------------------------
  83. static bool ForcedOnForeground = false;
  84. void __fastcall SetOnForeground(bool OnForeground)
  85. {
  86. ForcedOnForeground = OnForeground;
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall FlashOnBackground()
  90. {
  91. assert(Application);
  92. if (!ForcedOnForeground && !ForegroundTask())
  93. {
  94. FlashWindow(Application->MainFormHandle, true);
  95. }
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall LocalSystemSettings(TCustomForm * /*Control*/)
  99. {
  100. // noop
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall ShowExtendedException(Exception * E)
  104. {
  105. ShowExtendedExceptionEx(NULL, E);
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall ShowExtendedExceptionEx(TTerminal * Terminal,
  109. Exception * E)
  110. {
  111. bool Show = ShouldDisplayException(E);
  112. TTerminalManager * Manager = TTerminalManager::Instance(false);
  113. TQueryType Type;
  114. ESshTerminate * Terminate = dynamic_cast<ESshTerminate*>(E);
  115. bool CloseOnCompletion = (Terminate != NULL);
  116. Type = CloseOnCompletion ? qtInformation : qtError;
  117. bool ConfirmExitOnCompletion =
  118. CloseOnCompletion &&
  119. (Terminate->Operation == odoDisconnect) &&
  120. WinConfiguration->ConfirmExitOnCompletion;
  121. if (E->InheritsFrom(__classid(EFatal)) && (Terminal != NULL) &&
  122. (Manager != NULL) && (Manager->ActiveTerminal == Terminal))
  123. {
  124. if (CloseOnCompletion)
  125. {
  126. Manager->DisconnectActiveTerminal();
  127. }
  128. int SessionReopenTimeout = 0;
  129. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  130. if ((ManagedTerminal != NULL) &&
  131. ((Configuration->SessionReopenTimeout == 0) ||
  132. ((double)ManagedTerminal->ReopenStart == 0) ||
  133. (int(double(Now() - ManagedTerminal->ReopenStart) * MSecsPerDay) < Configuration->SessionReopenTimeout)))
  134. {
  135. SessionReopenTimeout = GUIConfiguration->SessionReopenAutoIdle;
  136. }
  137. unsigned int Result;
  138. if (CloseOnCompletion)
  139. {
  140. assert(Show);
  141. if (ConfirmExitOnCompletion)
  142. {
  143. TMessageParams Params(mpNeverAskAgainCheck);
  144. UnicodeString MessageFormat =
  145. MainInstructions((Manager->Count > 1) ?
  146. FMTLOAD(DISCONNECT_ON_COMPLETION, (Manager->Count - 1)) :
  147. LoadStr(EXIT_ON_COMPLETION));
  148. Result = FatalExceptionMessageDialog(E, Type, 0,
  149. MessageFormat,
  150. qaYes | qaNo, HELP_NONE, &Params);
  151. if (Result == qaNeverAskAgain)
  152. {
  153. Result = qaYes;
  154. WinConfiguration->ConfirmExitOnCompletion = false;
  155. }
  156. }
  157. else
  158. {
  159. Result = qaYes;
  160. }
  161. }
  162. else
  163. {
  164. if (Show)
  165. {
  166. Result = FatalExceptionMessageDialog(E, Type, SessionReopenTimeout);
  167. }
  168. else
  169. {
  170. Result = qaOK;
  171. }
  172. }
  173. if (Result == qaYes)
  174. {
  175. assert(Terminate != NULL);
  176. assert(Terminate->Operation != odoIdle);
  177. Application->Terminate();
  178. switch (Terminate->Operation)
  179. {
  180. case odoDisconnect:
  181. break;
  182. case odoShutDown:
  183. ShutDownWindows();
  184. break;
  185. default:
  186. assert(false);
  187. }
  188. }
  189. else if (Result == qaRetry)
  190. {
  191. Manager->ReconnectActiveTerminal();
  192. }
  193. else
  194. {
  195. Manager->FreeActiveTerminal();
  196. }
  197. }
  198. else
  199. {
  200. // this should not happen as we never use Terminal->CloseOnCompletion
  201. // on inactive terminal
  202. if (CloseOnCompletion)
  203. {
  204. assert(Show);
  205. if (ConfirmExitOnCompletion)
  206. {
  207. TMessageParams Params(mpNeverAskAgainCheck);
  208. if (ExceptionMessageDialog(E, Type, L"", qaOK, HELP_NONE, &Params) ==
  209. qaNeverAskAgain)
  210. {
  211. WinConfiguration->ConfirmExitOnCompletion = false;
  212. }
  213. }
  214. }
  215. else
  216. {
  217. if (Show)
  218. {
  219. ExceptionMessageDialog(E, Type);
  220. }
  221. }
  222. }
  223. }
  224. //---------------------------------------------------------------------------
  225. void __fastcall ShowNotification(TTerminal * Terminal, const UnicodeString & Str,
  226. TQueryType Type)
  227. {
  228. TTerminalManager * Manager = TTerminalManager::Instance(false);
  229. assert(Manager != NULL);
  230. Manager->ScpExplorer->PopupTrayBalloon(Terminal, Str, Type);
  231. }
  232. //---------------------------------------------------------------------------
  233. void __fastcall ConfigureInterface()
  234. {
  235. UnicodeString S;
  236. S = LoadStr(MIDDLE_EAST);
  237. if (!S.IsEmpty())
  238. {
  239. SysLocale.MiddleEast = static_cast<bool>(StrToInt(S));
  240. }
  241. else
  242. {
  243. SysLocale.MiddleEast = false;
  244. }
  245. S = LoadStr(BIDI_MODE);
  246. if (!S.IsEmpty())
  247. {
  248. Application->BiDiMode = static_cast<TBiDiMode>(StrToInt(bdRightToLeft));
  249. }
  250. else
  251. {
  252. Application->BiDiMode = bdLeftToRight;
  253. }
  254. SetTBXSysParam(TSP_XPVISUALSTYLE, XPVS_AUTOMATIC);
  255. // Can be called during configuration creation.
  256. // Skip now, will be called again later.
  257. if (Configuration != NULL)
  258. {
  259. TBXSetTheme(WinConfiguration->Theme);
  260. }
  261. }
  262. //---------------------------------------------------------------------------
  263. // dummy function to force linking of TBXOfficeXPTheme.pas
  264. void __fastcall CreateThemes()
  265. {
  266. new TTBXOfficeXPTheme(L"OfficeXP");
  267. new TTBXOffice2003Theme(L"Office2003");
  268. }
  269. //---------------------------------------------------------------------------
  270. void __fastcall DoAboutDialog(TConfiguration *Configuration)
  271. {
  272. DoAboutDialog(Configuration, true, NULL);
  273. }
  274. //---------------------------------------------------------------------
  275. void __fastcall DoProductLicense()
  276. {
  277. DoLicenseDialog(lcWinScp);
  278. }
  279. //---------------------------------------------------------------------------
  280. const UnicodeString PixelsPerInchKey = L"PixelsPerInch";
  281. //---------------------------------------------------------------------
  282. int __fastcall GetToolbarLayoutPixelsPerInch(TStrings * Storage)
  283. {
  284. int Result;
  285. if (Storage->IndexOfName(PixelsPerInchKey))
  286. {
  287. Result = LoadPixelsPerInch(Storage->Values[PixelsPerInchKey]);
  288. }
  289. else
  290. {
  291. Result = -1;
  292. }
  293. return Result;
  294. }
  295. //---------------------------------------------------------------------
  296. static inline void __fastcall GetToolbarKey(const UnicodeString & ToolbarName,
  297. const UnicodeString & Value, UnicodeString & ToolbarKey)
  298. {
  299. int ToolbarNameLen;
  300. if ((ToolbarName.Length() > 7) &&
  301. (ToolbarName.SubString(ToolbarName.Length() - 7 + 1, 7) == L"Toolbar"))
  302. {
  303. ToolbarNameLen = ToolbarName.Length() - 7;
  304. }
  305. else
  306. {
  307. ToolbarNameLen = ToolbarName.Length();
  308. }
  309. ToolbarKey = ToolbarName.SubString(1, ToolbarNameLen) + L"_" + Value;
  310. }
  311. //---------------------------------------------------------------------------
  312. static int __fastcall ToolbarReadInt(const UnicodeString ToolbarName,
  313. const UnicodeString Value, const int Default, const void * ExtraData)
  314. {
  315. int Result;
  316. if (Value == L"Rev")
  317. {
  318. Result = 2000;
  319. }
  320. else
  321. {
  322. TStrings * Storage = static_cast<TStrings *>(const_cast<void*>(ExtraData));
  323. UnicodeString ToolbarKey;
  324. GetToolbarKey(ToolbarName, Value, ToolbarKey);
  325. if (Storage->IndexOfName(ToolbarKey) >= 0)
  326. {
  327. Result = StrToIntDef(Storage->Values[ToolbarKey], Default);
  328. #if 0
  329. // this does not work well, as it scales down the stretched
  330. // toolbars (path toolbars) too much, it has to be reimplemented smarter
  331. if (Value == L"DockPos")
  332. {
  333. int PixelsPerInch = GetToolbarLayoutPixelsPerInch(Storage);
  334. // When DPI has decreased since the last time, scale down
  335. // toolbar position to get rid of gaps caused by smaller labels.
  336. // Do not do this when DPI has increased as it would introduce gaps,
  337. // as toolbars consists mostly of icons only, that do not scale.
  338. // The toolbars shift themselves anyway, when other toolbars to the left
  339. // get wider. We also risk a bit that toolbar order changes,
  340. // as with very small toolbars (History) we can get scaled down position
  341. // of the following toolbar to the left of it.
  342. // There's special handling (also for scaling-up) stretched toolbars
  343. // in LoadToolbarsLayoutStr
  344. if ((PixelsPerInch > 0) && (Screen->PixelsPerInch < PixelsPerInch))
  345. {
  346. Result = LoadDimension(Result, PixelsPerInch);
  347. }
  348. }
  349. #endif
  350. }
  351. else
  352. {
  353. Result = Default;
  354. }
  355. }
  356. return Result;
  357. }
  358. //---------------------------------------------------------------------------
  359. static UnicodeString __fastcall ToolbarReadString(const UnicodeString ToolbarName,
  360. const UnicodeString Value, const UnicodeString Default, const void * ExtraData)
  361. {
  362. UnicodeString Result;
  363. TStrings * Storage = static_cast<TStrings *>(const_cast<void*>(ExtraData));
  364. UnicodeString ToolbarKey;
  365. GetToolbarKey(ToolbarName, Value, ToolbarKey);
  366. if (Storage->IndexOfName(ToolbarKey) >= 0)
  367. {
  368. Result = Storage->Values[ToolbarKey];
  369. }
  370. else
  371. {
  372. Result = Default;
  373. }
  374. return Result;
  375. }
  376. //---------------------------------------------------------------------------
  377. static void __fastcall ToolbarWriteInt(const UnicodeString ToolbarName,
  378. const UnicodeString Value, const int Data, const void * ExtraData)
  379. {
  380. if (Value != L"Rev")
  381. {
  382. TStrings * Storage = static_cast<TStrings *>(const_cast<void*>(ExtraData));
  383. UnicodeString ToolbarKey;
  384. GetToolbarKey(ToolbarName, Value, ToolbarKey);
  385. assert(Storage->IndexOfName(ToolbarKey) < 0);
  386. Storage->Values[ToolbarKey] = IntToStr(Data);
  387. }
  388. }
  389. //---------------------------------------------------------------------------
  390. static void __fastcall ToolbarWriteString(const UnicodeString ToolbarName,
  391. const UnicodeString Value, const UnicodeString Data, const void * ExtraData)
  392. {
  393. TStrings * Storage = static_cast<TStrings *>(const_cast<void*>(ExtraData));
  394. UnicodeString ToolbarKey;
  395. GetToolbarKey(ToolbarName, Value, ToolbarKey);
  396. assert(Storage->IndexOfName(ToolbarKey) < 0);
  397. Storage->Values[ToolbarKey] = Data;
  398. }
  399. //---------------------------------------------------------------------------
  400. UnicodeString __fastcall GetToolbarsLayoutStr(const TComponent * OwnerComponent)
  401. {
  402. UnicodeString Result;
  403. TStrings * Storage = new TStringList();
  404. try
  405. {
  406. TBCustomSavePositions(OwnerComponent, ToolbarWriteInt, ToolbarWriteString,
  407. Storage);
  408. Storage->Values[PixelsPerInchKey] = SavePixelsPerInch();
  409. Result = Storage->CommaText;
  410. }
  411. __finally
  412. {
  413. delete Storage;
  414. }
  415. return Result;
  416. }
  417. //---------------------------------------------------------------------------
  418. void __fastcall LoadToolbarsLayoutStr(TComponent * OwnerComponent, UnicodeString LayoutStr)
  419. {
  420. TStrings * Storage = new TStringList();
  421. try
  422. {
  423. Storage->CommaText = LayoutStr;
  424. TBCustomLoadPositions(OwnerComponent, ToolbarReadInt, ToolbarReadString,
  425. Storage);
  426. int PixelsPerInch = GetToolbarLayoutPixelsPerInch(Storage);
  427. // Scale toolbars stretched to the first other toolbar to the right
  428. if ((PixelsPerInch > 0) && (PixelsPerInch != Screen->PixelsPerInch)) // optimization
  429. {
  430. for (int Index = 0; Index < OwnerComponent->ComponentCount; Index++)
  431. {
  432. TTBXToolbar * Toolbar =
  433. dynamic_cast<TTBXToolbar *>(OwnerComponent->Components[Index]);
  434. if ((Toolbar != NULL) && Toolbar->Stretch &&
  435. (Toolbar->OnGetBaseSize != NULL) &&
  436. // we do not support floating of stretched toolbars
  437. ALWAYS_TRUE(!Toolbar->Floating))
  438. {
  439. TTBXToolbar * FollowingToolbar = NULL;
  440. for (int Index2 = 0; Index2 < OwnerComponent->ComponentCount; Index2++)
  441. {
  442. TTBXToolbar * Toolbar2 =
  443. dynamic_cast<TTBXToolbar *>(OwnerComponent->Components[Index2]);
  444. if ((Toolbar2 != NULL) && !Toolbar2->Floating &&
  445. (Toolbar2->Parent == Toolbar->Parent) &&
  446. (Toolbar2->DockRow == Toolbar->DockRow) &&
  447. (Toolbar2->DockPos > Toolbar->DockPos) &&
  448. ((FollowingToolbar == NULL) || (FollowingToolbar->DockPos > Toolbar2->DockPos)))
  449. {
  450. FollowingToolbar = Toolbar2;
  451. }
  452. }
  453. if (FollowingToolbar != NULL)
  454. {
  455. int NewWidth = LoadDimension(Toolbar->Width, PixelsPerInch);
  456. FollowingToolbar->DockPos += NewWidth - Toolbar->Width;
  457. }
  458. }
  459. }
  460. }
  461. }
  462. __finally
  463. {
  464. delete Storage;
  465. }
  466. }
  467. //---------------------------------------------------------------------------
  468. void __fastcall AddMenuSeparator(TTBCustomItem * Menu)
  469. {
  470. TTBXSeparatorItem * Item = new TTBXSeparatorItem(Menu);
  471. Menu->Add(Item);
  472. }
  473. //---------------------------------------------------------------------------
  474. static TComponent * LastPopupComponent = NULL;
  475. static TRect LastPopupRect(-1, -1, -1, -1);
  476. static TDateTime LastCloseUp;
  477. //---------------------------------------------------------------------------
  478. void __fastcall MenuPopup(TPopupMenu * AMenu, TRect Rect,
  479. TComponent * PopupComponent)
  480. {
  481. // Pressing the same button within 200ms after closing its popup menu
  482. // does nothing.
  483. // It is to immitate close-by-click behaviour. Note that menu closes itself
  484. // before onclick handler of button occurs.
  485. // To support content menu popups, we have to check for the popup location too,
  486. // to allow poping menu on different location (such as different node of TTreeView),
  487. // even if there's another popup opened already (so that the time interval
  488. // below does not elapse).
  489. TDateTime N = Now();
  490. TDateTime Diff = N - LastCloseUp;
  491. if ((PopupComponent == LastPopupComponent) &&
  492. (Rect == LastPopupRect) &&
  493. (Diff < TDateTime(0, 0, 0, 200)))
  494. {
  495. LastPopupComponent = NULL;
  496. }
  497. else
  498. {
  499. TTBXPopupMenu * Menu = dynamic_cast<TTBXPopupMenu *>(AMenu);
  500. if (Menu == NULL)
  501. {
  502. Menu = CreateTBXPopupMenu(AMenu->Owner);
  503. Menu->OnPopup = AMenu->OnPopup;
  504. Menu->Items->SubMenuImages = AMenu->Images;
  505. for (int Index = 0; Index < AMenu->Items->Count; Index++)
  506. {
  507. TMenuItem * AItem = AMenu->Items->Items[Index];
  508. TTBCustomItem * Item;
  509. // recurse not implemented yet
  510. assert(AItem->Count == 0);
  511. if (!AItem->Enabled && !AItem->Visible && (AItem->Action == NULL) && (AItem->OnClick == NULL))
  512. {
  513. TTBXLabelItem * LabelItem = new TTBXLabelItem(Menu);
  514. // TTBXLabelItem has it's own Caption
  515. LabelItem->Caption = AItem->Caption;
  516. LabelItem->SectionHeader = true;
  517. Item = LabelItem;
  518. }
  519. else
  520. {
  521. // see TB2DsgnConverter.pas DoConvert
  522. if (AItem->Caption == L"-")
  523. {
  524. Item = new TTBXSeparatorItem(Menu);
  525. }
  526. else
  527. {
  528. Item = new TTBXItem(Menu);
  529. Item->Action = AItem->Action;
  530. Item->AutoCheck = AItem->AutoCheck;
  531. Item->Caption = AItem->Caption;
  532. Item->Checked = AItem->Checked;
  533. if (AItem->Default)
  534. {
  535. Item->Options = Item->Options << tboDefault;
  536. }
  537. Item->Enabled = AItem->Enabled;
  538. Item->GroupIndex = AItem->GroupIndex;
  539. Item->HelpContext = AItem->HelpContext;
  540. Item->ImageIndex = AItem->ImageIndex;
  541. Item->RadioItem = AItem->RadioItem;
  542. Item->ShortCut = AItem->ShortCut;
  543. Item->SubMenuImages = AItem->SubMenuImages;
  544. Item->OnClick = AItem->OnClick;
  545. }
  546. Item->Hint = AItem->Hint;
  547. Item->Tag = AItem->Tag;
  548. Item->Visible = AItem->Visible;
  549. }
  550. Menu->Items->Add(Item);
  551. }
  552. }
  553. Menu->PopupComponent = PopupComponent;
  554. Menu->PopupEx(Rect);
  555. LastPopupComponent = PopupComponent;
  556. LastPopupRect = Rect;
  557. LastCloseUp = Now();
  558. }
  559. }
  560. //---------------------------------------------------------------------------
  561. const int ColorCols = 8;
  562. const int StandardColorRows = 2;
  563. const int StandardColorCount = ColorCols * StandardColorRows;
  564. const int UserColorRows = 1;
  565. const int UserColorCount = UserColorRows * ColorCols;
  566. const wchar_t ColorSeparator = L',';
  567. //---------------------------------------------------------------------------
  568. static void __fastcall GetStandardSessionColorInfo(
  569. int Col, int Row, TColor & Color, UnicodeString & Name)
  570. {
  571. #define COLOR_INFO(COL, ROW, NAME, COLOR) \
  572. if ((Col == COL) && (Row == ROW)) { Name = NAME; Color = TColor(COLOR); } else
  573. // bottom row of default TBX color set
  574. COLOR_INFO(0, 0, L"Rose", 0xCC99FF)
  575. COLOR_INFO(1, 0, L"Tan", 0x99CCFF)
  576. COLOR_INFO(2, 0, L"Light Yellow", 0x99FFFF)
  577. COLOR_INFO(3, 0, L"Light Green", 0xCCFFCC)
  578. COLOR_INFO(4, 0, L"Light Turquoise", 0xFFFFCC)
  579. COLOR_INFO(5, 0, L"Pale Blue", 0xFFCC99)
  580. COLOR_INFO(6, 0, L"Lavender", 0xFF99CC)
  581. // second row of Excel 2010 palette with second color (Lighter Black) skipped
  582. COLOR_INFO(7, 0, L"Light Orange", 0xB5D5FB)
  583. COLOR_INFO(0, 1, L"Darker White", 0xD8D8D8)
  584. COLOR_INFO(1, 1, L"Darker Tan", 0x97BDC4)
  585. COLOR_INFO(2, 1, L"Lighter Blue", 0xE2B38D)
  586. COLOR_INFO(3, 1, L"Light Blue", 0xE4CCB8)
  587. COLOR_INFO(4, 1, L"Lighter Red", 0xB7B9E5)
  588. COLOR_INFO(5, 1, L"Light Olive Green", 0xBCE3D7)
  589. COLOR_INFO(6, 1, L"Light Purple", 0xD9C1CC)
  590. COLOR_INFO(7, 1, L"Light Aqua", 0xE8DDB7)
  591. FAIL;
  592. #undef COLOR_INFO
  593. }
  594. //---------------------------------------------------------------------------
  595. static void __fastcall SessionColorSetGetColorInfo(
  596. void * /*Data*/, TTBXCustomColorSet * /*Sender*/, int Col, int Row, TColor & Color, UnicodeString & Name)
  597. {
  598. GetStandardSessionColorInfo(Col, Row, Color, Name);
  599. }
  600. //---------------------------------------------------------------------------
  601. static TColor __fastcall RestoreColor(UnicodeString CStr)
  602. {
  603. return TColor(StrToInt(UnicodeString(L"$") + CStr));
  604. }
  605. //---------------------------------------------------------------------------
  606. static UnicodeString __fastcall StoreColor(TColor Color)
  607. {
  608. return IntToHex(Color, 6);
  609. }
  610. //---------------------------------------------------------------------------
  611. static UnicodeString __fastcall ExtractColorStr(UnicodeString & Colors)
  612. {
  613. return ::CutToChar(Colors, ColorSeparator, true);
  614. }
  615. //---------------------------------------------------------------------------
  616. static bool __fastcall IsStandardColor(TColor Color)
  617. {
  618. for (int Row = 0; Row < StandardColorRows; Row++)
  619. {
  620. for (int Col = 0; Col < ColorCols; Col++)
  621. {
  622. TColor StandardColor;
  623. UnicodeString Name; // unused
  624. GetStandardSessionColorInfo(Col, Row, StandardColor, Name);
  625. if (StandardColor == Color)
  626. {
  627. return true;
  628. }
  629. }
  630. }
  631. return false;
  632. }
  633. //---------------------------------------------------------------------------
  634. class TColorChangeData : public TComponent
  635. {
  636. public:
  637. __fastcall TColorChangeData(TColorChangeEvent OnColorChange, TColor Color);
  638. static TColorChangeData * __fastcall Retrieve(TObject * Object);
  639. void __fastcall ColorChange(TColor Color);
  640. __property TColor Color = { read = FColor };
  641. private:
  642. TColorChangeEvent FOnColorChange;
  643. TColor FColor;
  644. };
  645. //---------------------------------------------------------------------------
  646. __fastcall TColorChangeData::TColorChangeData(TColorChangeEvent OnColorChange, TColor Color) :
  647. TComponent(NULL)
  648. {
  649. Name = QualifiedClassName();
  650. FOnColorChange = OnColorChange;
  651. FColor = Color;
  652. }
  653. //---------------------------------------------------------------------------
  654. TColorChangeData * __fastcall TColorChangeData::Retrieve(TObject * Object)
  655. {
  656. TComponent * Component = NOT_NULL(dynamic_cast<TComponent *>(Object));
  657. TComponent * ColorChangeDataComponent = Component->FindComponent(QualifiedClassName());
  658. return NOT_NULL(dynamic_cast<TColorChangeData *>(ColorChangeDataComponent));
  659. }
  660. //---------------------------------------------------------------------------
  661. void __fastcall TColorChangeData::ColorChange(TColor Color)
  662. {
  663. if ((Color != TColor(0)) &&
  664. !IsStandardColor(Color))
  665. {
  666. UnicodeString SessionColors = StoreColor(Color);
  667. UnicodeString Temp = CustomWinConfiguration->SessionColors;
  668. while (!Temp.IsEmpty())
  669. {
  670. UnicodeString CStr = ExtractColorStr(Temp);
  671. if (RestoreColor(CStr) != Color)
  672. {
  673. SessionColors += UnicodeString(ColorSeparator) + CStr;
  674. }
  675. }
  676. CustomWinConfiguration->SessionColors = SessionColors;
  677. }
  678. FOnColorChange(Color);
  679. }
  680. //---------------------------------------------------------------------------
  681. static void __fastcall ColorDefaultClick(void * /*Data*/, TObject * Sender)
  682. {
  683. TColorChangeData::Retrieve(Sender)->ColorChange(TColor(0));
  684. }
  685. //---------------------------------------------------------------------------
  686. static void __fastcall ColorPaletteChange(void * /*Data*/, TObject * Sender)
  687. {
  688. TTBXColorPalette * ColorPalette = NOT_NULL(dynamic_cast<TTBXColorPalette *>(Sender));
  689. TColor Color = (ColorPalette->Color != Vcl::Graphics::clNone ? ColorPalette->Color : (TColor)0);
  690. TColorChangeData::Retrieve(Sender)->ColorChange(Color);
  691. }
  692. //---------------------------------------------------------------------------
  693. static UnicodeString __fastcall CustomColorName(int Index)
  694. {
  695. return UnicodeString(L"Color") + wchar_t(L'A' + Index);
  696. }
  697. //---------------------------------------------------------------------------
  698. static void __fastcall ColorPickClick(void * /*Data*/, TObject * Sender)
  699. {
  700. TColorChangeData * ColorChangeData = TColorChangeData::Retrieve(Sender);
  701. std::unique_ptr<TColorDialog> Dialog(new TColorDialog(Application));
  702. Dialog->Options = Dialog->Options << cdFullOpen << cdAnyColor;
  703. Dialog->Color = (ColorChangeData->Color != 0 ? ColorChangeData->Color : clSkyBlue);
  704. UnicodeString Temp = CustomWinConfiguration->SessionColors;
  705. int StandardColorIndex = 0;
  706. int CustomColors = Min(MaxCustomColors, StandardColorCount);
  707. for (int Index = 0; Index < CustomColors; Index++)
  708. {
  709. TColor CustomColor;
  710. if (!Temp.IsEmpty())
  711. {
  712. CustomColor = RestoreColor(ExtractColorStr(Temp));
  713. }
  714. else
  715. {
  716. UnicodeString Name; // not used
  717. assert(StandardColorIndex < StandardColorCount);
  718. GetStandardSessionColorInfo(
  719. StandardColorIndex % ColorCols, StandardColorIndex / ColorCols,
  720. CustomColor, Name);
  721. StandardColorIndex++;
  722. }
  723. Dialog->CustomColors->Values[CustomColorName(Index)] = StoreColor(CustomColor);
  724. }
  725. if (Dialog->Execute())
  726. {
  727. // so that we do not have to try to preserve the excess colors
  728. assert(UserColorCount <= MaxCustomColors);
  729. UnicodeString SessionColors;
  730. for (int Index = 0; Index < MaxCustomColors; Index++)
  731. {
  732. UnicodeString CStr = Dialog->CustomColors->Values[CustomColorName(Index)];
  733. if (!CStr.IsEmpty())
  734. {
  735. TColor CustomColor = RestoreColor(CStr);
  736. if (!IsStandardColor(CustomColor))
  737. {
  738. AddToList(SessionColors, StoreColor(CustomColor), ColorSeparator);
  739. }
  740. }
  741. }
  742. CustomWinConfiguration->SessionColors = SessionColors;
  743. // call color change only after copying custom colors back,
  744. // so that it can add selected color to the user list
  745. ColorChangeData->ColorChange(Dialog->Color);
  746. }
  747. }
  748. //---------------------------------------------------------------------------
  749. TPopupMenu * __fastcall CreateSessionColorPopupMenu(TColor Color,
  750. TColorChangeEvent OnColorChange)
  751. {
  752. std::unique_ptr<TTBXPopupMenu> PopupMenu(new TTBXPopupMenu(Application));
  753. CreateSessionColorMenu(PopupMenu->Items, Color, OnColorChange);
  754. return PopupMenu.release();
  755. }
  756. //---------------------------------------------------------------------------
  757. static void __fastcall UserSessionColorSetGetColorInfo(
  758. void * /*Data*/, TTBXCustomColorSet * Sender, int Col, int Row, TColor & Color, UnicodeString & /*Name*/)
  759. {
  760. int Index = (Row * Sender->ColCount) + Col;
  761. UnicodeString Temp = CustomWinConfiguration->SessionColors;
  762. while ((Index > 0) && !Temp.IsEmpty())
  763. {
  764. ExtractColorStr(Temp);
  765. Index--;
  766. }
  767. if (!Temp.IsEmpty())
  768. {
  769. Color = RestoreColor(ExtractColorStr(Temp));
  770. }
  771. else
  772. {
  773. // hide the trailing cells
  774. Color = Vcl::Graphics::clNone;
  775. }
  776. }
  777. //---------------------------------------------------------------------------
  778. void __fastcall CreateColorPalette(TTBCustomItem * Owner, TColor Color, int Rows,
  779. TCSGetColorInfo OnGetColorInfo, TColorChangeEvent OnColorChange)
  780. {
  781. TTBXCustomColorSet * ColorSet = new TTBXCustomColorSet(Owner);
  782. TTBXColorPalette * ColorPalette = new TTBXColorPalette(Owner);
  783. ColorPalette->InsertComponent(ColorSet);
  784. ColorPalette->ColorSet = ColorSet;
  785. // has to be set only after it's assigned to color palette
  786. ColorSet->ColCount = ColorCols;
  787. ColorSet->RowCount = Rows;
  788. ColorSet->OnGetColorInfo = OnGetColorInfo;
  789. ColorPalette->Color = (Color != 0) ? Color : Vcl::Graphics::clNone;
  790. ColorPalette->OnChange = MakeMethod<TNotifyEvent>(NULL, ColorPaletteChange);
  791. ColorPalette->InsertComponent(new TColorChangeData(OnColorChange, Color));
  792. Owner->Add(ColorPalette);
  793. Owner->Add(new TTBXSeparatorItem(Owner));
  794. }
  795. //---------------------------------------------------------------------------
  796. void __fastcall CreateSessionColorMenu(TComponent * AOwner, TColor Color,
  797. TColorChangeEvent OnColorChange)
  798. {
  799. TTBCustomItem * Owner = dynamic_cast<TTBCustomItem *>(AOwner);
  800. if (ALWAYS_TRUE(Owner != NULL))
  801. {
  802. Owner->Clear();
  803. TTBCustomItem * Item;
  804. Item = new TTBXItem(Owner);
  805. Item->Caption = LoadStr(COLOR_DEFAULT_CAPTION);
  806. Item->Hint = LoadStr(COLOR_DEFAULT_HINT);
  807. Item->HelpKeyword = HELP_COLOR;
  808. Item->OnClick = MakeMethod<TNotifyEvent>(NULL, ColorDefaultClick);
  809. Item->Checked = (Color == TColor(0));
  810. Item->InsertComponent(new TColorChangeData(OnColorChange, Color));
  811. Owner->Add(Item);
  812. Owner->Add(new TTBXSeparatorItem(Owner));
  813. int SessionColorCount = 0;
  814. UnicodeString Temp = CustomWinConfiguration->SessionColors;
  815. while (!Temp.IsEmpty())
  816. {
  817. SessionColorCount++;
  818. ExtractColorStr(Temp);
  819. }
  820. if (SessionColorCount > 0)
  821. {
  822. SessionColorCount = Min(SessionColorCount, UserColorCount);
  823. int RowCount = ((SessionColorCount + ColorCols - 1) / ColorCols);
  824. assert(RowCount <= UserColorRows);
  825. CreateColorPalette(Owner, Color, RowCount,
  826. MakeMethod<TCSGetColorInfo>(NULL, UserSessionColorSetGetColorInfo),
  827. OnColorChange);
  828. }
  829. CreateColorPalette(Owner, Color, StandardColorRows,
  830. MakeMethod<TCSGetColorInfo>(NULL, SessionColorSetGetColorInfo),
  831. OnColorChange);
  832. Owner->Add(new TTBXSeparatorItem(Owner));
  833. Item = new TTBXItem(Owner);
  834. Item->Caption = LoadStr(COLOR_PICK_CAPTION);
  835. Item->Hint = LoadStr(COLOR_PICK_HINT);
  836. Item->HelpKeyword = HELP_COLOR;
  837. Item->OnClick = MakeMethod<TNotifyEvent>(NULL, ColorPickClick);
  838. Item->InsertComponent(new TColorChangeData(OnColorChange, Color));
  839. Owner->Add(Item);
  840. }
  841. }
  842. //---------------------------------------------------------------------------
  843. void __fastcall UpgradeSpeedButton(TSpeedButton * /*Button*/)
  844. {
  845. // no-op yet
  846. }
  847. //---------------------------------------------------------------------------
  848. struct TThreadParam
  849. {
  850. TThreadFunc ThreadFunc;
  851. void * Parameter;
  852. };
  853. //---------------------------------------------------------------------------
  854. static int __fastcall ThreadProc(void * AParam)
  855. {
  856. TThreadParam * Param = reinterpret_cast<TThreadParam *>(AParam);
  857. unsigned int Result = Param->ThreadFunc(Param->Parameter);
  858. delete Param;
  859. EndThread(Result);
  860. return Result;
  861. }
  862. //---------------------------------------------------------------------------
  863. int __fastcall StartThread(void * SecurityAttributes, unsigned StackSize,
  864. TThreadFunc ThreadFunc, void * Parameter, unsigned CreationFlags,
  865. TThreadID & ThreadId)
  866. {
  867. TThreadParam * Param = new TThreadParam;
  868. Param->ThreadFunc = ThreadFunc;
  869. Param->Parameter = Parameter;
  870. return BeginThread(SecurityAttributes, StackSize, ThreadProc, Param,
  871. CreationFlags, ThreadId);
  872. }
  873. //---------------------------------------------------------------------------
  874. static TShortCut FirstCtrlNumberShortCut = ShortCut(L'0', TShiftState() << ssCtrl);
  875. static TShortCut LastCtrlNumberShortCut = ShortCut(L'9', TShiftState() << ssCtrl);
  876. static TShortCut FirstShiftCtrlAltLetterShortCut = ShortCut(L'A', TShiftState() << ssShift << ssCtrl << ssAlt);
  877. static TShortCut LastShiftCtrlAltLetterShortCut = ShortCut(L'Z', TShiftState() << ssShift << ssCtrl << ssAlt);
  878. //---------------------------------------------------------------------------
  879. void __fastcall InitializeShortCutCombo(TComboBox * ComboBox,
  880. const TShortCuts & ShortCuts)
  881. {
  882. ComboBox->Items->BeginUpdate();
  883. try
  884. {
  885. ComboBox->Items->Clear();
  886. ComboBox->Items->AddObject(LoadStr(SHORTCUT_NONE), reinterpret_cast<TObject* >(0));
  887. for (TShortCut AShortCut = FirstCtrlNumberShortCut; AShortCut <= LastCtrlNumberShortCut; AShortCut++)
  888. {
  889. if (!ShortCuts.Has(AShortCut))
  890. {
  891. ComboBox->Items->AddObject(ShortCutToText(AShortCut), reinterpret_cast<TObject* >(AShortCut));
  892. }
  893. }
  894. for (TShortCut AShortCut = FirstShiftCtrlAltLetterShortCut; AShortCut <= LastShiftCtrlAltLetterShortCut; AShortCut++)
  895. {
  896. if (!ShortCuts.Has(AShortCut))
  897. {
  898. ComboBox->Items->AddObject(ShortCutToText(AShortCut), reinterpret_cast<TObject* >(AShortCut));
  899. }
  900. }
  901. }
  902. __finally
  903. {
  904. ComboBox->Items->EndUpdate();
  905. }
  906. ComboBox->Style = csDropDownList;
  907. ComboBox->DropDownCount = 16;
  908. }
  909. //---------------------------------------------------------------------------
  910. void __fastcall SetShortCutCombo(TComboBox * ComboBox, TShortCut Value)
  911. {
  912. for (int Index = ComboBox->Items->Count - 1; Index >= 0; Index--)
  913. {
  914. TShortCut AShortCut = TShortCut(ComboBox->Items->Objects[Index]);
  915. if (AShortCut == Value)
  916. {
  917. ComboBox->ItemIndex = Index;
  918. break;
  919. }
  920. else if (AShortCut < Value)
  921. {
  922. assert(Value != 0);
  923. ComboBox->Items->InsertObject(Index + 1, ShortCutToText(Value),
  924. reinterpret_cast<TObject* >(Value));
  925. ComboBox->ItemIndex = Index + 1;
  926. break;
  927. }
  928. assert(Index > 0);
  929. }
  930. }
  931. //---------------------------------------------------------------------------
  932. TShortCut __fastcall GetShortCutCombo(TComboBox * ComboBox)
  933. {
  934. return TShortCut(ComboBox->Items->Objects[ComboBox->ItemIndex]);
  935. }
  936. //---------------------------------------------------------------------------
  937. bool __fastcall IsCustomShortCut(TShortCut ShortCut)
  938. {
  939. return
  940. ((FirstCtrlNumberShortCut <= ShortCut) && (ShortCut <= LastCtrlNumberShortCut)) ||
  941. ((FirstShiftCtrlAltLetterShortCut <= ShortCut) && (ShortCut <= LastShiftCtrlAltLetterShortCut));
  942. }
  943. //---------------------------------------------------------------------------
  944. //---------------------------------------------------------------------------
  945. class TMasterPasswordDialog : public TCustomDialog
  946. {
  947. public:
  948. __fastcall TMasterPasswordDialog(bool Current);
  949. bool __fastcall Execute(UnicodeString & CurrentPassword, UnicodeString & NewPassword);
  950. protected:
  951. virtual void __fastcall DoValidate();
  952. virtual void __fastcall DoChange(bool & CanSubmit);
  953. private:
  954. TPasswordEdit * CurrentEdit;
  955. TPasswordEdit * NewEdit;
  956. TPasswordEdit * ConfirmEdit;
  957. };
  958. //---------------------------------------------------------------------------
  959. __fastcall TMasterPasswordDialog::TMasterPasswordDialog(bool Current) :
  960. TCustomDialog(Current ? HELP_MASTER_PASSWORD_CURRENT : HELP_MASTER_PASSWORD_CHANGE)
  961. {
  962. Caption = LoadStr(MASTER_PASSWORD_CAPTION);
  963. CurrentEdit = new TPasswordEdit(this);
  964. AddEdit(CurrentEdit, CreateLabel(LoadStr(MASTER_PASSWORD_CURRENT)));
  965. EnableControl(CurrentEdit, Current || WinConfiguration->UseMasterPassword);
  966. CurrentEdit->MaxLength = PasswordMaxLength();
  967. if (!Current)
  968. {
  969. NewEdit = new TPasswordEdit(this);
  970. AddEdit(NewEdit, CreateLabel(LoadStr(MASTER_PASSWORD_NEW)));
  971. NewEdit->MaxLength = CurrentEdit->MaxLength;
  972. if (!WinConfiguration->UseMasterPassword)
  973. {
  974. ActiveControl = NewEdit;
  975. }
  976. ConfirmEdit = new TPasswordEdit(this);
  977. AddEdit(ConfirmEdit, CreateLabel(LoadStr(MASTER_PASSWORD_CONFIRM)));
  978. ConfirmEdit->MaxLength = CurrentEdit->MaxLength;
  979. }
  980. else
  981. {
  982. NewEdit = NULL;
  983. ConfirmEdit = NULL;
  984. }
  985. }
  986. //---------------------------------------------------------------------------
  987. bool __fastcall TMasterPasswordDialog::Execute(
  988. UnicodeString & CurrentPassword, UnicodeString & NewPassword)
  989. {
  990. bool Result = TCustomDialog::Execute();
  991. if (Result)
  992. {
  993. if (CurrentEdit->Enabled)
  994. {
  995. CurrentPassword = CurrentEdit->Text;
  996. }
  997. if (NewEdit != NULL)
  998. {
  999. NewPassword = NewEdit->Text;
  1000. }
  1001. }
  1002. return Result;
  1003. }
  1004. //---------------------------------------------------------------------------
  1005. void __fastcall TMasterPasswordDialog::DoChange(bool & CanSubmit)
  1006. {
  1007. CanSubmit =
  1008. (!WinConfiguration->UseMasterPassword || (IsValidPassword(CurrentEdit->Text) >= 0)) &&
  1009. ((NewEdit == NULL) || (IsValidPassword(NewEdit->Text) >= 0)) &&
  1010. ((ConfirmEdit == NULL) || (IsValidPassword(ConfirmEdit->Text) >= 0));
  1011. TCustomDialog::DoChange(CanSubmit);
  1012. }
  1013. //---------------------------------------------------------------------------
  1014. void __fastcall TMasterPasswordDialog::DoValidate()
  1015. {
  1016. TCustomDialog::DoValidate();
  1017. if (WinConfiguration->UseMasterPassword &&
  1018. !WinConfiguration->ValidateMasterPassword(CurrentEdit->Text))
  1019. {
  1020. CurrentEdit->SetFocus();
  1021. CurrentEdit->SelectAll();
  1022. throw Exception(MainInstructions(LoadStr(MASTER_PASSWORD_INCORRECT)));
  1023. }
  1024. if (NewEdit != NULL)
  1025. {
  1026. if (NewEdit->Text != ConfirmEdit->Text)
  1027. {
  1028. ConfirmEdit->SetFocus();
  1029. ConfirmEdit->SelectAll();
  1030. throw Exception(MainInstructions(LoadStr(MASTER_PASSWORD_DIFFERENT)));
  1031. }
  1032. int Valid = IsValidPassword(NewEdit->Text);
  1033. if (Valid <= 0)
  1034. {
  1035. assert(Valid == 0);
  1036. if (MessageDialog(LoadStr(MASTER_PASSWORD_SIMPLE2), qtWarning,
  1037. qaOK | qaCancel, HELP_MASTER_PASSWORD_SIMPLE) == qaCancel)
  1038. {
  1039. NewEdit->SetFocus();
  1040. NewEdit->SelectAll();
  1041. Abort();
  1042. }
  1043. }
  1044. }
  1045. }
  1046. //---------------------------------------------------------------------------
  1047. static bool __fastcall DoMasterPasswordDialog(bool Current,
  1048. UnicodeString & NewPassword)
  1049. {
  1050. bool Result;
  1051. TMasterPasswordDialog * Dialog = new TMasterPasswordDialog(Current);
  1052. try
  1053. {
  1054. UnicodeString CurrentPassword;
  1055. Result = Dialog->Execute(CurrentPassword, NewPassword);
  1056. if (Result)
  1057. {
  1058. if ((Current || WinConfiguration->UseMasterPassword) &&
  1059. ALWAYS_TRUE(!CurrentPassword.IsEmpty()))
  1060. {
  1061. WinConfiguration->SetMasterPassword(CurrentPassword);
  1062. }
  1063. }
  1064. }
  1065. __finally
  1066. {
  1067. delete Dialog;
  1068. }
  1069. return Result;
  1070. }
  1071. //---------------------------------------------------------------------------
  1072. bool __fastcall DoMasterPasswordDialog()
  1073. {
  1074. UnicodeString NewPassword;
  1075. bool Result = DoMasterPasswordDialog(true, NewPassword);
  1076. assert(NewPassword.IsEmpty());
  1077. return Result;
  1078. }
  1079. //---------------------------------------------------------------------------
  1080. bool __fastcall DoChangeMasterPasswordDialog(UnicodeString & NewPassword)
  1081. {
  1082. bool Result = DoMasterPasswordDialog(false, NewPassword);
  1083. return Result;
  1084. }
  1085. //---------------------------------------------------------------------------
  1086. void __fastcall MessageWithNoHelp(const UnicodeString & Message)
  1087. {
  1088. TMessageParams Params;
  1089. Params.AllowHelp = false; // to avoid recursion
  1090. if (MessageDialog(LoadStr(HELP_SEND_MESSAGE2), qtConfirmation,
  1091. qaOK | qaCancel, HELP_NONE, &Params) == qaOK)
  1092. {
  1093. SearchHelp(Message);
  1094. }
  1095. }