MessageDlg.cpp 41 KB

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