MessageDlg.cpp 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Consts.hpp>
  5. #include <GUITools.h>
  6. #include <Common.h>
  7. #include <VCLCommon.h>
  8. #include <CoreMain.h>
  9. #include <WinInterface.h>
  10. #include <Tools.h>
  11. #include <TextsWin.h>
  12. #include <TextsCore.h>
  13. #include <Vcl.Imaging.pngimage.hpp>
  14. #include <StrUtils.hpp>
  15. #include <PasTools.hpp>
  16. #include <Math.hpp>
  17. #include <vssym32.h>
  18. #include <WebBrowserEx.hpp>
  19. #include <Setup.h>
  20. //---------------------------------------------------------------------------
  21. #pragma package(smart_init)
  22. //---------------------------------------------------------------------------
  23. const UnicodeString MessagePanelName(L"Panel");
  24. const UnicodeString MainMessageLabelName(L"MainMessage");
  25. const UnicodeString MessageLabelName(L"Message");
  26. const UnicodeString YesButtonName(L"Yes");
  27. const UnicodeString OKButtonName(L"OK");
  28. //---------------------------------------------------------------------------
  29. class TMessageButton : public TButton
  30. {
  31. public:
  32. __fastcall TMessageButton(TComponent * Owner);
  33. protected:
  34. virtual void __fastcall Dispatch(void * Message);
  35. private:
  36. void __fastcall WMGetDlgCode(TWMGetDlgCode & Message);
  37. };
  38. //---------------------------------------------------------------------------
  39. __fastcall TMessageButton::TMessageButton(TComponent * Owner) :
  40. TButton(Owner)
  41. {
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TMessageButton::Dispatch(void * Message)
  45. {
  46. TMessage * M = reinterpret_cast<TMessage*>(Message);
  47. if (M->Msg == WM_GETDLGCODE)
  48. {
  49. WMGetDlgCode(*((TWMGetDlgCode *)Message));
  50. }
  51. else
  52. {
  53. TButton::Dispatch(Message);
  54. }
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TMessageButton::WMGetDlgCode(TWMGetDlgCode & Message)
  58. {
  59. TButton::Dispatch(&Message);
  60. // WORKAROUND
  61. // Windows default handler returns DLGC_WANTARROWS for split buttons,
  62. // what prevent left/right keys from being used for focusing next/previous buttons/controls.
  63. // Overrwide that. Though note that we need to pass the up/down keys back to button
  64. // to allow drop down, see TMessageForm::CMDialogKey
  65. Message.Result = Message.Result & ~DLGC_WANTARROWS;
  66. }
  67. //---------------------------------------------------------------------------
  68. class TMessageForm : public TForm
  69. {
  70. public:
  71. static TForm * __fastcall Create(const UnicodeString & Msg, TStrings * MoreMessages,
  72. TMsgDlgType DlgType, unsigned int Answers,
  73. const TQueryButtonAlias * Aliases, unsigned int AliasesCount,
  74. unsigned int TimeoutAnswer, TButton ** TimeoutButton, const UnicodeString & ImageName,
  75. const UnicodeString & NeverAskAgainCaption, const UnicodeString & MoreMessagesUrl,
  76. TSize MoreMessagesSize, const UnicodeString & CustomCaption);
  77. virtual int __fastcall ShowModal();
  78. void __fastcall InsertPanel(TPanel * Panel);
  79. void __fastcall NavigateToUrl(const UnicodeString & Url);
  80. protected:
  81. __fastcall TMessageForm(TComponent * AOwner);
  82. virtual __fastcall ~TMessageForm();
  83. DYNAMIC void __fastcall KeyDown(Word & Key, TShiftState Shift);
  84. DYNAMIC void __fastcall KeyUp(Word & Key, TShiftState Shift);
  85. UnicodeString __fastcall GetFormText();
  86. UnicodeString __fastcall GetReportText();
  87. UnicodeString __fastcall NormalizeNewLines(UnicodeString Text);
  88. virtual void __fastcall CreateParams(TCreateParams & Params);
  89. DYNAMIC void __fastcall DoShow();
  90. virtual void __fastcall Dispatch(void * Message);
  91. void __fastcall MenuItemClick(TObject * Sender);
  92. void __fastcall ButtonDropDownClick(TObject * Sender);
  93. void __fastcall UpdateForShiftStateTimer(TObject * Sender);
  94. DYNAMIC void __fastcall SetZOrder(bool TopMost);
  95. private:
  96. typedef std::map<unsigned int, TButton *> TAnswerButtons;
  97. UnicodeString MessageText;
  98. TPanel * ContentsPanel;
  99. TMemo * MessageMemo;
  100. TPanel * MessageBrowserPanel;
  101. TWebBrowserEx * MessageBrowser;
  102. UnicodeString MessageBrowserUrl;
  103. TShiftState FShiftState;
  104. TTimer * FUpdateForShiftStateTimer;
  105. TForm * FDummyForm;
  106. bool FShowNoActivate;
  107. void __fastcall HelpButtonClick(TObject * Sender);
  108. void __fastcall ReportButtonClick(TObject * Sender);
  109. void __fastcall CMDialogKey(TWMKeyDown & Message);
  110. void __fastcall CMShowingChanged(TMessage & Message);
  111. void __fastcall UpdateForShiftState();
  112. TButton * __fastcall CreateButton(
  113. UnicodeString Name, UnicodeString Caption, unsigned int Answer,
  114. TNotifyEvent OnClick, bool IsTimeoutButton,
  115. int GroupWith, TShiftState GrouppedShiftState, bool ElevationRequired,
  116. TAnswerButtons & AnswerButtons, bool HasMoreMessages, int & ButtonWidths);
  117. };
  118. //---------------------------------------------------------------------------
  119. __fastcall TMessageForm::TMessageForm(TComponent * AOwner) : TForm(AOwner, 0)
  120. {
  121. FShowNoActivate = false;
  122. MessageMemo = NULL;
  123. MessageBrowserPanel = NULL;
  124. MessageBrowser = NULL;
  125. FUpdateForShiftStateTimer = NULL;
  126. Position = poOwnerFormCenter;
  127. UseSystemSettingsPre(this);
  128. FDummyForm = new TForm(this);
  129. UseSystemSettings(FDummyForm);
  130. }
  131. //---------------------------------------------------------------------------
  132. __fastcall TMessageForm::~TMessageForm()
  133. {
  134. SAFE_DESTROY(FDummyForm);
  135. SAFE_DESTROY(FUpdateForShiftStateTimer);
  136. }
  137. //---------------------------------------------------------------------------
  138. void __fastcall TMessageForm::HelpButtonClick(TObject * /*Sender*/)
  139. {
  140. if (HelpKeyword != HELP_NONE)
  141. {
  142. FormHelp(this);
  143. }
  144. else
  145. {
  146. MessageWithNoHelp(GetReportText());
  147. }
  148. }
  149. //---------------------------------------------------------------------------
  150. void __fastcall TMessageForm::ReportButtonClick(TObject * /*Sender*/)
  151. {
  152. // Report text goes last, as it may exceed URL parameters limit (2048) and get truncated.
  153. // And we need to preserve the other parameters.
  154. UnicodeString Url =
  155. FMTLOAD(ERROR_REPORT_URL2,
  156. (Configuration->ProductVersion, GUIConfiguration->AppliedLocaleHex,
  157. EncodeUrlString(GetReportText())));
  158. OpenBrowser(Url);
  159. }
  160. //---------------------------------------------------------------------------
  161. void __fastcall TMessageForm::UpdateForShiftState()
  162. {
  163. TShiftState ShiftState =
  164. KeyboardStateToShiftState() * AllKeyShiftStates();
  165. if (FShiftState != ShiftState)
  166. {
  167. FShiftState = ShiftState;
  168. for (int ComponentIndex = 0; ComponentIndex < ComponentCount - 1; ComponentIndex++)
  169. {
  170. TButton * Button = dynamic_cast<TButton*>(Components[ComponentIndex]);
  171. if ((Button != NULL) && (Button->DropDownMenu != NULL))
  172. {
  173. TMenuItem * MenuItems = Button->DropDownMenu->Items;
  174. for (int ItemIndex = 0; ItemIndex < MenuItems->Count; ItemIndex++)
  175. {
  176. TMenuItem * Item = MenuItems->Items[ItemIndex];
  177. TShiftState GrouppedShiftState(Item->Tag >> 16);
  178. if (Item->Enabled &&
  179. ((ShiftState.Empty() && Item->Default) ||
  180. (!ShiftState.Empty() && (ShiftState == GrouppedShiftState))))
  181. {
  182. Button->Caption = CopyToChar(Item->Caption, L'\t', false);
  183. Button->ModalResult = Item->Tag & 0xFFFF;
  184. DebugAssert(Button->OnClick == NULL);
  185. DebugAssert(Item->OnClick == MenuItemClick);
  186. break;
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. //---------------------------------------------------------------------------
  194. void __fastcall TMessageForm::KeyUp(Word & Key, TShiftState Shift)
  195. {
  196. UpdateForShiftState();
  197. TForm::KeyUp(Key, Shift);
  198. }
  199. //---------------------------------------------------------------------------
  200. void __fastcall TMessageForm::KeyDown(Word & Key, TShiftState Shift)
  201. {
  202. if (Shift.Contains(ssCtrl) && (Key == L'C'))
  203. {
  204. TInstantOperationVisualizer Visualizer;
  205. CopyToClipboard(GetFormText());
  206. }
  207. else
  208. {
  209. if (!Shift.Contains(ssCtrl))
  210. {
  211. for (int ComponentIndex = 0; ComponentIndex < ComponentCount - 1; ComponentIndex++)
  212. {
  213. TButton * Button = dynamic_cast<TButton*>(Components[ComponentIndex]);
  214. if ((Button != NULL) && (Button->DropDownMenu != NULL))
  215. {
  216. TMenuItem * MenuItems = Button->DropDownMenu->Items;
  217. for (int ItemIndex = 0; ItemIndex < MenuItems->Count; ItemIndex++)
  218. {
  219. TMenuItem * Item = MenuItems->Items[ItemIndex];
  220. if (IsAccel(Key, MenuItems->Items[ItemIndex]->Caption))
  221. {
  222. Item->OnClick(Item);
  223. Key = 0;
  224. break;
  225. }
  226. }
  227. }
  228. if (Key == 0)
  229. {
  230. break;
  231. }
  232. }
  233. }
  234. UpdateForShiftState();
  235. TForm::KeyDown(Key, Shift);
  236. }
  237. }
  238. //---------------------------------------------------------------------------
  239. UnicodeString __fastcall TMessageForm::NormalizeNewLines(UnicodeString Text)
  240. {
  241. Text = ReplaceStr(Text, L"\r", L"");
  242. Text = ReplaceStr(Text, L"\n", L"\r\n");
  243. return Text;
  244. }
  245. //---------------------------------------------------------------------------
  246. UnicodeString __fastcall TMessageForm::GetFormText()
  247. {
  248. UnicodeString DividerLine, ButtonCaptions;
  249. DividerLine = UnicodeString::StringOfChar(L'-', 27) + sLineBreak;
  250. for (int i = 0; i < ComponentCount - 1; i++)
  251. {
  252. if (dynamic_cast<TButton*>(Components[i]) != NULL)
  253. {
  254. ButtonCaptions += dynamic_cast<TButton*>(Components[i])->Caption +
  255. UnicodeString::StringOfChar(L' ', 3);
  256. }
  257. }
  258. ButtonCaptions = ReplaceStr(ButtonCaptions, L"&", L"");
  259. UnicodeString MoreMessages;
  260. if (MessageMemo != NULL)
  261. {
  262. MoreMessages = MessageMemo->Text + DividerLine;
  263. }
  264. else if (MessageBrowser != NULL)
  265. {
  266. MessageBrowser->SelectAll();
  267. MessageBrowser->CopyToClipBoard();
  268. if (NonEmptyTextFromClipboard(MoreMessages))
  269. {
  270. if (!EndsStr(sLineBreak, MoreMessages))
  271. {
  272. MoreMessages += sLineBreak;
  273. }
  274. MoreMessages += DividerLine;
  275. }
  276. // http://www.ssicom.org/js/x277333.htm
  277. MessageBrowser->DoCommand(L"UNSELECT");
  278. }
  279. UnicodeString MessageCaption = NormalizeNewLines(MessageText);
  280. UnicodeString Result = FORMAT(L"%s%s%s%s%s%s%s%s%s%s%s", (DividerLine, Caption, sLineBreak,
  281. DividerLine, MessageCaption, sLineBreak, DividerLine, MoreMessages,
  282. ButtonCaptions, sLineBreak, DividerLine));
  283. return Result;
  284. }
  285. //---------------------------------------------------------------------------
  286. UnicodeString __fastcall TMessageForm::GetReportText()
  287. {
  288. UnicodeString Text = MessageText;
  289. Text = Text.TrimRight();
  290. if (MessageMemo != NULL)
  291. {
  292. Text += L"\n\n" + MessageMemo->Text;
  293. }
  294. // Currently we use browser for updates box only and it has help context,
  295. // and does not have Report button, so we cannot get here.
  296. DebugAssert(MessageBrowser == NULL);
  297. Text = NormalizeNewLines(Text);
  298. UnicodeString ReportErrorText = NormalizeNewLines(FMTLOAD(REPORT_ERROR, (L"")));
  299. Text = ReplaceStr(Text, ReportErrorText, L"");
  300. Text = Trim(Text);
  301. return Text;
  302. }
  303. //---------------------------------------------------------------------------
  304. void __fastcall TMessageForm::CMDialogKey(TWMKeyDown & Message)
  305. {
  306. // this gets used in WinInterface.cpp SetTimeoutEvents
  307. if (OnKeyDown != NULL)
  308. {
  309. OnKeyDown(this, Message.CharCode, KeyDataToShiftState(Message.KeyData));
  310. }
  311. if (Message.CharCode == VK_MENU)
  312. {
  313. bool AnyButtonWithGrouppedCommandsWithShiftState = false;
  314. for (int ComponentIndex = 0; ComponentIndex < ComponentCount - 1; ComponentIndex++)
  315. {
  316. TButton * Button = dynamic_cast<TButton*>(Components[ComponentIndex]);
  317. if ((Button != NULL) && (Button->DropDownMenu != NULL))
  318. {
  319. // we should check if there are any commands with shift state,
  320. // but it's bit overkill
  321. AnyButtonWithGrouppedCommandsWithShiftState = true;
  322. break;
  323. }
  324. }
  325. // this is to make Alt only alter button meaning (if there is any
  326. // alternable button) and not popup system menu
  327. if (AnyButtonWithGrouppedCommandsWithShiftState)
  328. {
  329. Message.Result = 1;
  330. UpdateForShiftState();
  331. }
  332. else
  333. {
  334. TForm::Dispatch(&Message);
  335. }
  336. }
  337. else if ((Message.CharCode == VK_UP) || (Message.CharCode == VK_DOWN))
  338. {
  339. // WORKAROUND
  340. // noop to make up/down be passed back to button to allow drop down,
  341. // see TMessageButton::WMGetDlgCode
  342. }
  343. else
  344. {
  345. TForm::Dispatch(&Message);
  346. }
  347. }
  348. //---------------------------------------------------------------------------
  349. int __fastcall TMessageForm::ShowModal()
  350. {
  351. if (IsApplicationMinimized())
  352. {
  353. FShowNoActivate = true;
  354. }
  355. int Result = TForm::ShowModal();
  356. UnhookFormActivation(this);
  357. return Result;
  358. }
  359. //---------------------------------------------------------------------------
  360. void __fastcall TMessageForm::SetZOrder(bool TopMost)
  361. {
  362. // WORKAROUND: If application is minimized,
  363. // swallow call to BringToFront() from TForm::ShowModal()
  364. if (FShowNoActivate && TopMost)
  365. {
  366. // noop
  367. }
  368. else
  369. {
  370. TForm::SetZOrder(TopMost);
  371. }
  372. }
  373. //---------------------------------------------------------------------------
  374. void __fastcall TMessageForm::CMShowingChanged(TMessage & Message)
  375. {
  376. if (Showing && FShowNoActivate)
  377. {
  378. ShowFormNoActivate(this);
  379. }
  380. else
  381. {
  382. TForm::Dispatch(&Message);
  383. }
  384. }
  385. //---------------------------------------------------------------------------
  386. void __fastcall TMessageForm::Dispatch(void * Message)
  387. {
  388. TMessage * M = reinterpret_cast<TMessage*>(Message);
  389. if (M->Msg == CM_DIALOGKEY)
  390. {
  391. CMDialogKey(*((TWMKeyDown *)Message));
  392. }
  393. else if (M->Msg == CM_SHOWINGCHANGED)
  394. {
  395. CMShowingChanged(*M);
  396. }
  397. else
  398. {
  399. TForm::Dispatch(Message);
  400. }
  401. }
  402. //---------------------------------------------------------------------------
  403. void __fastcall TMessageForm::CreateParams(TCreateParams & Params)
  404. {
  405. TForm::CreateParams(Params);
  406. if ((Screen != NULL) && (Screen->ActiveForm != NULL) &&
  407. Screen->ActiveForm->HandleAllocated())
  408. {
  409. Params.WndParent = Screen->ActiveForm->Handle;
  410. }
  411. }
  412. //---------------------------------------------------------------------------
  413. void __fastcall TMessageForm::DoShow()
  414. {
  415. UseSystemSettingsPost(this);
  416. if (!MessageBrowserUrl.IsEmpty() &&
  417. // Guard against repeated calls to DoOpen()
  418. (MessageBrowser == NULL))
  419. {
  420. // Web Browser component does not seem to work,
  421. // when created before any window is shown.
  422. // I.e. when the message dialog is the first window (like when /update is used).
  423. // So we have to delay its creation until at least the dialog box is shown.
  424. MessageBrowser = CreateBrowserViewer(MessageBrowserPanel, LoadStr(MESSAGE_LOADING));
  425. MessageBrowser->SendToBack();
  426. MessageBrowser->Navigate(MessageBrowserUrl.c_str());
  427. }
  428. // Need OnShow to be called only after MessageBrowser is created,
  429. // so that the implementation (InsertDonateLink) can call InsertPanelToMessageDialog
  430. TForm::DoShow();
  431. }
  432. //---------------------------------------------------------------------------
  433. void __fastcall TMessageForm::MenuItemClick(TObject * Sender)
  434. {
  435. TMenuItem * Item = DebugNotNull(dynamic_cast<TMenuItem *>(Sender));
  436. ModalResult = (Item->Tag & 0xFFFF);
  437. }
  438. //---------------------------------------------------------------------------
  439. void __fastcall TMessageForm::UpdateForShiftStateTimer(TObject * /*Sender*/)
  440. {
  441. // this is needed to reflect shift state, even when we do not have a keyboard
  442. // focus, what happens when drop down menu is popped up
  443. UpdateForShiftState();
  444. }
  445. //---------------------------------------------------------------------------
  446. void __fastcall TMessageForm::ButtonDropDownClick(TObject * /*Sender*/)
  447. {
  448. // as optimization, do not waste time running timer, unless
  449. // user pops up drop down menu. we do not have a way to stop timer, once
  450. // it closes, but functionaly it does not matter
  451. if (FUpdateForShiftStateTimer == NULL)
  452. {
  453. FUpdateForShiftStateTimer = new TTimer(this);
  454. FUpdateForShiftStateTimer->Interval = 50;
  455. FUpdateForShiftStateTimer->OnTimer = UpdateForShiftStateTimer;
  456. }
  457. }
  458. //---------------------------------------------------------------------------
  459. const ResourceString * Captions[] = { &_SMsgDlgWarning, &_SMsgDlgError, &_SMsgDlgInformation,
  460. &_SMsgDlgConfirm, NULL };
  461. const wchar_t * ImageNames[] = { L"Warning", L"Error", L"Information",
  462. L"Help Blue", NULL };
  463. const int mcHorzMargin = 10;
  464. const int mcVertMargin = 13;
  465. const int mcHorzSpacing = 12;
  466. const int mcButtonVertMargin = 7;
  467. const int mcButtonSpacing = 5;
  468. // includes mcVertMargin
  469. const int mcMoreMessageHeight = 86;
  470. // approximately what Windows Vista task dialogs use,
  471. // actually they probably has fixed width
  472. const int mcMaxDialogWidth = 340;
  473. const int mcMinDialogWidth = 310;
  474. const int mcMinDialogwithMoreMessagesWidth = 400;
  475. //---------------------------------------------------------------------------
  476. static UnicodeString __fastcall GetKeyNameStr(int Key)
  477. {
  478. wchar_t Buf[MAX_PATH];
  479. LONG VirtualKey = MapVirtualKey(Key, MAPVK_VK_TO_VSC);
  480. VirtualKey <<= 16;
  481. if (GetKeyNameText(VirtualKey, Buf, LENOF(Buf)) > 0)
  482. {
  483. NULL_TERMINATE(Buf);
  484. }
  485. else
  486. {
  487. Buf[0] = L'\0';
  488. }
  489. return Buf;
  490. }
  491. //---------------------------------------------------------------------------
  492. TButton * __fastcall TMessageForm::CreateButton(
  493. UnicodeString Name, UnicodeString Caption, unsigned int Answer,
  494. TNotifyEvent OnClick, bool IsTimeoutButton,
  495. int GroupWith, TShiftState GrouppedShiftState, bool ElevationRequired,
  496. TAnswerButtons & AnswerButtons, bool HasMoreMessages, int & ButtonWidths)
  497. {
  498. UnicodeString MeasureCaption = Caption;
  499. if (IsTimeoutButton)
  500. {
  501. MeasureCaption = FMTLOAD(TIMEOUT_BUTTON, (MeasureCaption, 99));
  502. }
  503. TRect TextRect;
  504. DrawText(Canvas->Handle,
  505. UnicodeString(MeasureCaption).c_str(), -1,
  506. &TextRect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE |
  507. DrawTextBiDiModeFlagsReadingOnly());
  508. int CurButtonWidth = TextRect.Right - TextRect.Left + ScaleByTextHeightRunTime(this, 16);
  509. if (ElevationRequired && IsVista())
  510. {
  511. // Elevation icon
  512. CurButtonWidth += ScaleByTextHeightRunTime(this, 16);
  513. }
  514. TButton * Button = NULL;
  515. if (SupportsSplitButton() &&
  516. (GroupWith >= 0) &&
  517. DebugAlwaysTrue(AnswerButtons.find(GroupWith) != AnswerButtons.end()))
  518. {
  519. TButton * GroupWithButton = AnswerButtons[GroupWith];
  520. if (GroupWithButton->DropDownMenu == NULL)
  521. {
  522. GroupWithButton->Style = TCustomButton::bsSplitButton;
  523. GroupWithButton->DropDownMenu = new TPopupMenu(this);
  524. // cannot handle subitems with shift state,
  525. // if the button has its own handler
  526. // (though it may not be the case still here)
  527. DebugAssert(GroupWithButton->OnClick == NULL);
  528. TMenuItem * Item = new TMenuItem(GroupWithButton->DropDownMenu);
  529. GroupWithButton->DropDownMenu->Items->Add(Item);
  530. GroupWithButton->OnDropDownClick = ButtonDropDownClick;
  531. Item->Caption = GroupWithButton->Caption;
  532. Item->OnClick = MenuItemClick;
  533. DebugAssert(GroupWithButton->ModalResult <= 0xFFFF);
  534. Item->Tag = GroupWithButton->ModalResult;
  535. Item->Default = true;
  536. }
  537. TMenuItem * Item = new TMenuItem(GroupWithButton->DropDownMenu);
  538. GroupWithButton->DropDownMenu->Items->Add(Item);
  539. // See ShortCutToText in Vcl.Menus.pas
  540. if (GrouppedShiftState == (TShiftState() << ssAlt))
  541. {
  542. Caption = Caption + L"\t" + GetKeyNameStr(VK_MENU);
  543. }
  544. else if (GrouppedShiftState == (TShiftState() << ssCtrl))
  545. {
  546. Caption = Caption + L"\t" + GetKeyNameStr(VK_CONTROL);
  547. }
  548. else if (GrouppedShiftState == (TShiftState() << ssShift))
  549. {
  550. Caption = Caption + L"\t" + GetKeyNameStr(VK_SHIFT);
  551. }
  552. else
  553. {
  554. // do not support combined shift states yet
  555. DebugAssert(GrouppedShiftState == TShiftState());
  556. }
  557. Item->Caption = Caption;
  558. if (OnClick != NULL)
  559. {
  560. Item->OnClick = OnClick;
  561. }
  562. else
  563. {
  564. Item->OnClick = MenuItemClick;
  565. DebugAssert((Answer <= 0xFFFF) && (GrouppedShiftState.ToInt() <= 0xFFFF));
  566. Item->Tag = Answer + (GrouppedShiftState.ToInt() << 16);
  567. }
  568. // Hard-coded drop down button width (do not know how to ask for system width).
  569. // Also we do not update the max button width for the default groupped
  570. // button caption. We just blindly hope that captions of advanced commands
  571. // are always longer than the caption of simple default command
  572. CurButtonWidth += ScaleByTextHeightRunTime(this, 15);
  573. // never shrink buttons below their default width
  574. if (GroupWithButton->Width < CurButtonWidth)
  575. {
  576. ButtonWidths += CurButtonWidth - GroupWithButton->Width;
  577. GroupWithButton->Width = CurButtonWidth;
  578. }
  579. DebugAssert(!ElevationRequired);
  580. }
  581. else
  582. {
  583. Button = new TMessageButton(this);
  584. Button->Name = Name;
  585. Button->Parent = this;
  586. Button->Caption = Caption;
  587. // Scale buttons using regular font, so that they are as large as buttons
  588. // on other dialogs (note that they are still higher than Windows Task dialog
  589. // buttons)
  590. Button->Height = ScaleByTextHeightRunTime(FDummyForm, Button->Height);
  591. Button->Width = ScaleByTextHeightRunTime(FDummyForm, Button->Width);
  592. if (OnClick != NULL)
  593. {
  594. Button->OnClick = OnClick;
  595. }
  596. else
  597. {
  598. Button->ModalResult = Answer;
  599. }
  600. if (HasMoreMessages)
  601. {
  602. Button->Anchors = TAnchors() << akBottom << akLeft;
  603. }
  604. // never shrink buttons below their default width
  605. if (Button->Width < CurButtonWidth)
  606. {
  607. Button->Width = CurButtonWidth;
  608. }
  609. Button->ElevationRequired = ElevationRequired;
  610. ButtonWidths += Button->Width;
  611. }
  612. return Button;
  613. }
  614. //---------------------------------------------------------------------------
  615. void __fastcall TMessageForm::InsertPanel(TPanel * Panel)
  616. {
  617. if (DebugAlwaysTrue(MessageBrowser != NULL))
  618. {
  619. // we currently use this for updates message box only
  620. TControl * ContentsControl = static_cast<TControl *>(DebugNotNull(MessageBrowser))->Parent;
  621. Panel->Width = ContentsControl->Width;
  622. Panel->Left = ContentsControl->Left;
  623. int ContentsBottom = ContentsControl->Top + ContentsControl->Height;
  624. Panel->Top = ContentsBottom + ((ContentsPanel->Height - ContentsBottom) / 2);
  625. Height = Height + Panel->Height;
  626. ContentsPanel->Height = ContentsPanel->Height + Panel->Height;
  627. Panel->Parent = ContentsPanel;
  628. // The panel itself does not need this, as the ParentBackground (true by default)
  629. // has the same effect, but an eventual TStaticText on the panel
  630. // uses a wrong background color, if panel's ParentColor is not set.
  631. Panel->ParentColor = true;
  632. }
  633. }
  634. //---------------------------------------------------------------------------
  635. void __fastcall TMessageForm::NavigateToUrl(const UnicodeString & Url)
  636. {
  637. if (DebugAlwaysTrue(MessageBrowser != NULL))
  638. {
  639. NavigateBrowserToUrl(MessageBrowser, Url);
  640. }
  641. }
  642. //---------------------------------------------------------------------------
  643. void __fastcall AnswerNameAndCaption(
  644. unsigned int Answer, UnicodeString & Name, UnicodeString & Caption)
  645. {
  646. switch (Answer)
  647. {
  648. case qaYes:
  649. Caption = LoadStr(_SMsgDlgYes.Identifier);
  650. Name = YesButtonName;
  651. break;
  652. case qaNo:
  653. Caption = LoadStr(_SMsgDlgNo.Identifier);
  654. Name = L"No";
  655. break;
  656. case qaOK:
  657. Caption = LoadStr(_SMsgDlgOK.Identifier);
  658. Name = OKButtonName;
  659. break;
  660. case qaCancel:
  661. Caption = LoadStr(_SMsgDlgCancel.Identifier);
  662. Name = L"Cancel";
  663. break;
  664. case qaAbort:
  665. Caption = LoadStr(_SMsgDlgAbort.Identifier);
  666. Name = L"Abort";
  667. break;
  668. case qaRetry:
  669. Caption = LoadStr(_SMsgDlgRetry.Identifier);
  670. Name = L"Retry";
  671. break;
  672. case qaIgnore:
  673. Caption = LoadStr(_SMsgDlgIgnore.Identifier);
  674. Name = L"Ignore";
  675. break;
  676. // Own variant to avoid accelerator conflict with "Abort" button.
  677. // Note that as of now, ALL_BUTTON is never actually used,
  678. // because qaAll is always aliased
  679. case qaAll:
  680. Caption = LoadStr(ALL_BUTTON);
  681. Name = L"All";
  682. break;
  683. case qaNoToAll:
  684. Caption = LoadStr(_SMsgDlgNoToAll.Identifier);
  685. Name = L"NoToAll";
  686. break;
  687. // Own variant to avoid accelerator conflict with "Abort" button.
  688. case qaYesToAll:
  689. Caption = LoadStr(YES_TO_ALL_BUTTON);
  690. Name = L"YesToAll";
  691. break;
  692. case qaHelp:
  693. Caption = LoadStr(_SMsgDlgHelp.Identifier);
  694. Name = L"Help";
  695. break;
  696. case qaSkip:
  697. Caption = LoadStr(SKIP_BUTTON);
  698. Name = L"Skip";
  699. break;
  700. case qaReport:
  701. Caption = LoadStr(REPORT_BUTTON);
  702. Name = L"Report";
  703. break;
  704. default:
  705. DebugFail();
  706. throw Exception(L"Undefined answer");
  707. }
  708. }
  709. //---------------------------------------------------------------------------
  710. static int __fastcall CalculateWidthOnCanvas(UnicodeString Text, void * Arg)
  711. {
  712. TCanvas * Canvas = static_cast<TCanvas *>(Arg);
  713. return Canvas->TextWidth(Text);
  714. }
  715. //---------------------------------------------------------------------------
  716. TForm * __fastcall TMessageForm::Create(const UnicodeString & Msg,
  717. TStrings * MoreMessages, TMsgDlgType DlgType, unsigned int Answers,
  718. const TQueryButtonAlias * Aliases, unsigned int AliasesCount,
  719. unsigned int TimeoutAnswer, TButton ** TimeoutButton, const UnicodeString & AImageName,
  720. const UnicodeString & NeverAskAgainCaption, const UnicodeString & MoreMessagesUrl,
  721. TSize MoreMessagesSize, const UnicodeString & CustomCaption)
  722. {
  723. unsigned int DefaultAnswer;
  724. if (FLAGSET(Answers, qaOK))
  725. {
  726. DefaultAnswer = qaOK;
  727. }
  728. else if (FLAGSET(Answers, qaYes))
  729. {
  730. DefaultAnswer = qaYes;
  731. }
  732. else
  733. {
  734. DefaultAnswer = qaRetry;
  735. }
  736. unsigned int CancelAnswer = ::CancelAnswer(Answers);
  737. if (TimeoutButton != NULL)
  738. {
  739. *TimeoutButton = NULL;
  740. }
  741. TColor MainInstructionColor = Graphics::clNone;
  742. HFONT MainInstructionFont = 0;
  743. HFONT InstructionFont = 0;
  744. HTHEME Theme = OpenThemeData(0, L"TEXTSTYLE");
  745. if (Theme != NULL)
  746. {
  747. LOGFONT AFont;
  748. COLORREF AColor;
  749. memset(&AFont, 0, sizeof(AFont));
  750. if (GetThemeFont(Theme, NULL, TEXT_MAININSTRUCTION, 0, TMT_FONT, &AFont) == S_OK)
  751. {
  752. MainInstructionFont = CreateFontIndirect(&AFont);
  753. }
  754. if (GetThemeColor(Theme, TEXT_MAININSTRUCTION, 0, TMT_TEXTCOLOR, &AColor) == S_OK)
  755. {
  756. MainInstructionColor = (TColor)AColor;
  757. }
  758. memset(&AFont, 0, sizeof(AFont));
  759. if (GetThemeFont(Theme, NULL, TEXT_INSTRUCTION, 0, TMT_FONT, &AFont) == S_OK)
  760. {
  761. InstructionFont = CreateFontIndirect(&AFont);
  762. }
  763. CloseThemeData(Theme);
  764. }
  765. TMessageForm * Result = SafeFormCreate<TMessageForm>();
  766. if (InstructionFont != 0)
  767. {
  768. Result->Font->Handle = InstructionFont;
  769. }
  770. else
  771. {
  772. Result->Font->Assign(Screen->MessageFont);
  773. }
  774. // Can be possibly nul when error occurs before configuration is created
  775. if (Configuration != NULL)
  776. {
  777. Configuration->Usage->Set(L"ThemeMessageFontSize", Result->Font->Size);
  778. }
  779. // make sure we consider sizes of the monitor,
  780. // that is set in DoFormWindowProc(CM_SHOWINGCHANGED) later.
  781. Forms::TMonitor * Monitor = FormMonitor(Result);
  782. bool HasMoreMessages = (MoreMessages != NULL) || !MoreMessagesUrl.IsEmpty();
  783. Result->BiDiMode = Application->BiDiMode;
  784. Result->BorderStyle = bsDialog;
  785. Result->Canvas->Font = Result->Font;
  786. Result->KeyPreview = true;
  787. int HorzMargin = ScaleByTextHeightRunTime(Result, mcHorzMargin);
  788. int VertMargin = ScaleByTextHeightRunTime(Result, mcVertMargin);
  789. int HorzSpacing = ScaleByTextHeightRunTime(Result, mcHorzSpacing);
  790. int ButtonVertMargin = ScaleByTextHeightRunTime(Result, mcButtonVertMargin);
  791. int ButtonWidths = 0;
  792. int ButtonHeight = -1;
  793. std::vector<TButton *> ButtonControls;
  794. TAnswerButtons AnswerButtons;
  795. for (unsigned int Answer = qaFirst; Answer <= qaLast; Answer = Answer << 1)
  796. {
  797. if (FLAGSET(Answers, Answer))
  798. {
  799. DebugAssert(Answer != mrCancel);
  800. UnicodeString Caption;
  801. UnicodeString Name;
  802. AnswerNameAndCaption(Answer, Name, Caption);
  803. TNotifyEvent OnClick = NULL;
  804. int GroupWith = -1;
  805. TShiftState GrouppedShiftState;
  806. bool ElevationRequired = false;
  807. if (Aliases != NULL)
  808. {
  809. for (unsigned int i = 0; i < AliasesCount; i++)
  810. {
  811. if (Answer == Aliases[i].Button)
  812. {
  813. if (!Aliases[i].Alias.IsEmpty())
  814. {
  815. Caption = Aliases[i].Alias;
  816. }
  817. OnClick = Aliases[i].OnClick;
  818. GroupWith = Aliases[i].GroupWith;
  819. GrouppedShiftState = Aliases[i].GrouppedShiftState;
  820. ElevationRequired = Aliases[i].ElevationRequired;
  821. DebugAssert((OnClick == NULL) || (GrouppedShiftState == TShiftState()));
  822. break;
  823. }
  824. }
  825. }
  826. // we hope that all grouped-with buttons are for answer with greater
  827. // value that the answer to be grouped with
  828. if (GroupWith >= 0)
  829. {
  830. if (DebugAlwaysFalse(GroupWith >= static_cast<int>(Answer)) ||
  831. DebugAlwaysFalse(Answer == TimeoutAnswer) &&
  832. DebugAlwaysFalse(Answer == DefaultAnswer) &&
  833. DebugAlwaysFalse(Answer == CancelAnswer))
  834. {
  835. GroupWith = -1;
  836. }
  837. }
  838. bool IsTimeoutButton = (TimeoutButton != NULL) && (Answer == TimeoutAnswer);
  839. if (Answer == qaHelp)
  840. {
  841. DebugAssert(OnClick == NULL);
  842. OnClick = Result->HelpButtonClick;
  843. }
  844. if (Answer == qaReport)
  845. {
  846. DebugAssert(OnClick == NULL);
  847. OnClick = Result->ReportButtonClick;
  848. }
  849. TButton * Button = Result->CreateButton(
  850. Name, Caption, Answer,
  851. OnClick, IsTimeoutButton, GroupWith, GrouppedShiftState, ElevationRequired,
  852. AnswerButtons, HasMoreMessages, ButtonWidths);
  853. if (Button != NULL)
  854. {
  855. ButtonControls.push_back(Button);
  856. Button->Default = (Answer == DefaultAnswer);
  857. Button->Cancel = (Answer == CancelAnswer);
  858. if (ButtonHeight < 0)
  859. {
  860. ButtonHeight = Button->Height;
  861. }
  862. DebugAssert(ButtonHeight == Button->Height);
  863. AnswerButtons.insert(TAnswerButtons::value_type(Answer, Button));
  864. if (IsTimeoutButton)
  865. {
  866. *TimeoutButton = Button;
  867. }
  868. }
  869. }
  870. }
  871. int NeverAskAgainWidth = 0;
  872. if (!NeverAskAgainCaption.IsEmpty())
  873. {
  874. NeverAskAgainWidth =
  875. ScaleByTextHeightRunTime(Result, 16) + // checkbox
  876. Result->Canvas->TextWidth(NeverAskAgainCaption) +
  877. ScaleByTextHeightRunTime(Result, 16); // margin
  878. }
  879. int ButtonSpacing = ScaleByTextHeightRunTime(Result, mcButtonSpacing);
  880. int ButtonGroupWidth = NeverAskAgainWidth;
  881. if (!ButtonControls.empty())
  882. {
  883. ButtonGroupWidth += ButtonWidths +
  884. ButtonSpacing * (ButtonControls.size() - 1);
  885. }
  886. DebugAssert((ButtonHeight > 0) && (ButtonWidths > 0));
  887. TPanel * Panel = CreateBlankPanel(Result);
  888. Result->ContentsPanel = Panel;
  889. Panel->Name = MessagePanelName;
  890. Panel->Parent = Result;
  891. Panel->Color = clWindow;
  892. Panel->ParentBackground = false;
  893. Panel->Anchors = TAnchors() << akLeft << akRight << akTop;
  894. Panel->Caption = L"";
  895. int IconWidth = 0;
  896. int IconHeight = 0;
  897. UnicodeString ImageName = AImageName;
  898. if (ImageName.IsEmpty() &&
  899. DebugAlwaysTrue(ImageNames[DlgType] != NULL))
  900. {
  901. ImageName = ImageNames[DlgType];
  902. }
  903. if (DebugAlwaysTrue(!ImageName.IsEmpty()))
  904. {
  905. TImage * Image = new TImage(Panel);
  906. Image->Name = L"Image";
  907. Image->Parent = Panel;
  908. LoadDialogImage(Image, ImageName);
  909. Image->SetBounds(HorzMargin, VertMargin, Image->Picture->Width, Image->Picture->Height);
  910. IconWidth = Image->Width + HorzSpacing;
  911. IconHeight = Image->Height;
  912. }
  913. int MaxTextWidth = ScaleByTextHeightRunTime(Result, mcMaxDialogWidth);
  914. // if the dialog would be wide anyway (overwrite confirmation on Windows XP),
  915. // to fit the buttons, do not restrict the text
  916. if (MaxTextWidth < ButtonGroupWidth - IconWidth)
  917. {
  918. MaxTextWidth = ButtonGroupWidth - IconWidth;
  919. }
  920. UnicodeString BodyMsg = Msg;
  921. BodyMsg = RemoveInteractiveMsgTag(BodyMsg);
  922. UnicodeString MainMsg;
  923. if (ExtractMainInstructions(BodyMsg, MainMsg))
  924. {
  925. Result->MessageText = MainMsg + BodyMsg;
  926. BodyMsg = BodyMsg.TrimLeft();
  927. }
  928. else
  929. {
  930. Result->MessageText = BodyMsg;
  931. }
  932. ApplyTabs(Result->MessageText, L' ', NULL, NULL);
  933. // Windows XP (not sure about Vista) does not support Hair space.
  934. // For Windows XP, we still keep the existing hack by using hard-coded spaces
  935. // in resource string
  936. if (CheckWin32Version(6, 1))
  937. {
  938. // Have to be padding with spaces (the smallest space defined, hair space = 1px),
  939. // as tabs actually do not tab, just expand to 8 spaces.
  940. // Otherwise we would have to do custom drawing
  941. // (using GetTabbedTextExtent and TabbedTextOut)
  942. const wchar_t HairSpace = L'\x200A';
  943. ApplyTabs(BodyMsg, HairSpace, CalculateWidthOnCanvas, Result->Canvas);
  944. }
  945. DebugAssert(MainMsg.Pos(L"\t") == 0);
  946. int IconTextWidth = -1;
  947. int IconTextHeight = 0;
  948. int ALeft = IconWidth + HorzMargin;
  949. for (int MessageIndex = 0; MessageIndex <= 1; MessageIndex++)
  950. {
  951. UnicodeString LabelMsg;
  952. UnicodeString LabelName;
  953. TColor LabelColor = Graphics::clNone;
  954. HFONT LabelFont = 0;
  955. switch (MessageIndex)
  956. {
  957. case 0:
  958. LabelMsg = MainMsg;
  959. LabelName = MainMessageLabelName;
  960. LabelColor = MainInstructionColor;
  961. LabelFont = MainInstructionFont;
  962. break;
  963. case 1:
  964. LabelMsg = BodyMsg;
  965. LabelName = MessageLabelName;
  966. break;
  967. default:
  968. DebugFail();
  969. break;
  970. }
  971. if (!LabelMsg.IsEmpty())
  972. {
  973. TLabel * Message = new TLabel(Panel);
  974. Message->Name = LabelName;
  975. Message->Parent = Panel;
  976. Message->WordWrap = true;
  977. Message->Caption = LabelMsg;
  978. Message->BiDiMode = Result->BiDiMode;
  979. // added to show & as & for messages containing !& pattern of custom commands
  980. // (suppose that we actually never want to use & as accel in message text)
  981. Message->ShowAccelChar = false;
  982. if (LabelFont != 0)
  983. {
  984. Message->Font->Handle = LabelFont;
  985. if (DebugAlwaysTrue(LabelFont == MainInstructionFont) &&
  986. // When showing an early error message
  987. (Configuration != NULL))
  988. {
  989. Configuration->Usage->Set(L"ThemeMainInstructionFontSize", Message->Font->Size);
  990. }
  991. }
  992. if (LabelColor != Graphics::clNone)
  993. {
  994. Message->Font->Color = LabelColor;
  995. }
  996. TRect TextRect;
  997. SetRect(&TextRect, 0, 0, MaxTextWidth, 0);
  998. DrawText(Message->Canvas->Handle, LabelMsg.c_str(), LabelMsg.Length() + 1, &TextRect,
  999. DT_EXPANDTABS | DT_CALCRECT | DT_WORDBREAK | DT_NOPREFIX |
  1000. Result->DrawTextBiDiModeFlagsReadingOnly());
  1001. int MaxWidth = Monitor->Width - HorzMargin * 2 - IconWidth - 30;
  1002. if (TextRect.right > MaxWidth)
  1003. {
  1004. // this will truncate the text, we should implement something smarter eventually
  1005. TextRect.right = MaxWidth;
  1006. }
  1007. IconTextWidth = Max(IconTextWidth, IconWidth + TextRect.Right);
  1008. if (IconTextHeight > 0)
  1009. {
  1010. IconTextHeight += VertMargin;
  1011. }
  1012. Message->SetBounds(ALeft, VertMargin + IconTextHeight, TextRect.Right, TextRect.Bottom);
  1013. IconTextHeight += TextRect.Bottom;
  1014. }
  1015. }
  1016. DebugAssert((IconTextWidth > 0) && (IconTextHeight > 0));
  1017. IconTextHeight = Max(IconTextHeight, IconHeight);
  1018. int MoreMessageHeight =
  1019. (HasMoreMessages ?
  1020. ScaleByTextHeightRunTime(Result, (MoreMessagesSize.Height > 0 ? MoreMessagesSize.Height : mcMoreMessageHeight)) : 0);
  1021. Panel->SetBounds(0, 0, Result->ClientWidth, VertMargin + IconTextHeight + VertMargin + MoreMessageHeight);
  1022. TControl * MoreMessagesControl = NULL;
  1023. if (HasMoreMessages)
  1024. {
  1025. if (MoreMessages != NULL)
  1026. {
  1027. DebugAssert(MoreMessagesUrl.IsEmpty());
  1028. TMemo * MessageMemo = new TMemo(Panel);
  1029. MoreMessagesControl = MessageMemo;
  1030. MessageMemo->Name = L"MessageMemo";
  1031. MessageMemo->Parent = Panel;
  1032. MessageMemo->ReadOnly = true;
  1033. MessageMemo->WantReturns = False;
  1034. MessageMemo->ScrollBars = ssVertical;
  1035. MessageMemo->Anchors = TAnchors() << akLeft << akRight << akTop;
  1036. MessageMemo->Lines->Text = MoreMessages->Text;
  1037. Result->MessageMemo = MessageMemo;
  1038. }
  1039. else if (DebugAlwaysTrue(!MoreMessagesUrl.IsEmpty()))
  1040. {
  1041. TPanel * MessageBrowserPanel = CreateBlankPanel(Panel);
  1042. MessageBrowserPanel->Parent = Panel;
  1043. MessageBrowserPanel->Anchors = TAnchors() << akLeft << akRight << akTop;
  1044. MessageBrowserPanel->BevelKind = bkTile; // flat border
  1045. Result->MessageBrowserPanel = MessageBrowserPanel;
  1046. MoreMessagesControl = Result->MessageBrowserPanel;
  1047. UnicodeString FontSizeParam = FORMAT(L"fontsize=%d", (Result->Font->Size));
  1048. UnicodeString Url = AppendUrlParams(CampaignUrl(MoreMessagesUrl), FontSizeParam);
  1049. Result->MessageBrowserUrl = Url;
  1050. }
  1051. }
  1052. int MinClientWidth =
  1053. ScaleByTextHeightRunTime(Result,
  1054. HasMoreMessages ? (MoreMessagesSize.Width > 0 ? MoreMessagesSize.Width : mcMinDialogwithMoreMessagesWidth) : mcMinDialogWidth);
  1055. int AClientWidth =
  1056. Max(
  1057. (IconTextWidth > ButtonGroupWidth ? IconTextWidth : ButtonGroupWidth) +
  1058. HorzMargin * 2,
  1059. MinClientWidth);
  1060. Result->ClientWidth = AClientWidth;
  1061. Result->ClientHeight =
  1062. Panel->Height + ButtonVertMargin + ButtonHeight + ButtonVertMargin;
  1063. Result->Left = (Monitor->Width / 2) - (Result->Width / 2);
  1064. Result->Top = (Monitor->Height / 2) - (Result->Height / 2);
  1065. if (!CustomCaption.IsEmpty())
  1066. {
  1067. Result->Caption = CustomCaption;
  1068. }
  1069. else if (DebugAlwaysTrue(DlgType != mtCustom))
  1070. {
  1071. Result->Caption = LoadResourceString(Captions[DlgType]);
  1072. }
  1073. else
  1074. {
  1075. Result->Caption = Application->Title;
  1076. }
  1077. if (MoreMessagesControl != NULL)
  1078. {
  1079. MoreMessagesControl->SetBounds(
  1080. ALeft,
  1081. Panel->Height - MoreMessageHeight,
  1082. Result->ClientWidth - ALeft - HorzMargin,
  1083. MoreMessageHeight - VertMargin);
  1084. }
  1085. int ButtonTop = Panel->Height + ButtonVertMargin;
  1086. int X = Result->ClientWidth - ButtonGroupWidth + NeverAskAgainWidth - HorzMargin;
  1087. for (unsigned int i = 0; i < ButtonControls.size(); i++)
  1088. {
  1089. ButtonControls[i]->SetBounds(
  1090. X, ButtonTop, ButtonControls[i]->Width, ButtonControls[i]->Height);
  1091. X += ButtonControls[i]->Width + ButtonSpacing;
  1092. }
  1093. if (!NeverAskAgainCaption.IsEmpty() &&
  1094. !ButtonControls.empty())
  1095. {
  1096. TCheckBox * NeverAskAgainCheck = new TCheckBox(Result);
  1097. NeverAskAgainCheck->Name = L"NeverAskAgainCheck";
  1098. NeverAskAgainCheck->Parent = Result;
  1099. NeverAskAgainCheck->Caption = NeverAskAgainCaption;
  1100. NeverAskAgainCheck->Anchors = TAnchors() << akBottom << akLeft;
  1101. TButton * FirstButton = ButtonControls[0];
  1102. int NeverAskAgainHeight = ScaleByTextHeightRunTime(Result, NeverAskAgainCheck->Height);
  1103. int NeverAskAgainTop = FirstButton->Top + ((FirstButton->Height - NeverAskAgainHeight) / 2);
  1104. int NeverAskAgainLeft = HorzMargin;
  1105. NeverAskAgainCheck->SetBounds(
  1106. NeverAskAgainLeft, NeverAskAgainTop, NeverAskAgainWidth, NeverAskAgainHeight);
  1107. }
  1108. return Result;
  1109. }
  1110. //---------------------------------------------------------------------------
  1111. TForm * __fastcall CreateMoreMessageDialog(const UnicodeString & Msg,
  1112. TStrings * MoreMessages, TMsgDlgType DlgType, unsigned int Answers,
  1113. const TQueryButtonAlias * Aliases, unsigned int AliasesCount,
  1114. unsigned int TimeoutAnswer, TButton ** TimeoutButton, const UnicodeString & ImageName,
  1115. const UnicodeString & NeverAskAgainCaption, const UnicodeString & MoreMessagesUrl,
  1116. TSize MoreMessagesSize, const UnicodeString & CustomCaption)
  1117. {
  1118. return TMessageForm::Create(Msg, MoreMessages, DlgType, Answers,
  1119. Aliases, AliasesCount, TimeoutAnswer, TimeoutButton, ImageName,
  1120. NeverAskAgainCaption, MoreMessagesUrl, MoreMessagesSize, CustomCaption);
  1121. }
  1122. //---------------------------------------------------------------------------
  1123. void __fastcall InsertPanelToMessageDialog(TCustomForm * Form, TPanel * Panel)
  1124. {
  1125. TMessageForm * MessageForm = DebugNotNull(dynamic_cast<TMessageForm *>(Form));
  1126. MessageForm->InsertPanel(Panel);
  1127. }
  1128. //---------------------------------------------------------------------------
  1129. void __fastcall NavigateMessageDialogToUrl(TCustomForm * Form, const UnicodeString & Url)
  1130. {
  1131. TMessageForm * MessageForm = DebugNotNull(dynamic_cast<TMessageForm *>(Form));
  1132. MessageForm->NavigateToUrl(Url);
  1133. }