MessageDlg.cpp 40 KB

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