WinInterface.cpp 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <shlwapi.h>
  5. #include <Common.h>
  6. #include <Exceptions.h>
  7. #include <CoreMain.h>
  8. #include <TextsCore.h>
  9. #include <TextsWin.h>
  10. #include <HelpWin.h>
  11. #include <Interface.h>
  12. #include <VCLCommon.h>
  13. #include "WinInterface.h"
  14. #include "CustomWinConfiguration.h"
  15. #include "GUITools.h"
  16. //---------------------------------------------------------------------------
  17. #pragma package(smart_init)
  18. //---------------------------------------------------------------------------
  19. #define WM_TRAY_ICON (WM_WINSCP_USER + 5)
  20. //---------------------------------------------------------------------
  21. TNotifyEvent GlobalOnMinimize = NULL;
  22. //---------------------------------------------------------------------
  23. void __fastcall FormHelp(TForm * Form)
  24. {
  25. InvokeHelp(Form->ActiveControl != NULL ? Form->ActiveControl : Form);
  26. }
  27. //---------------------------------------------------------------------------
  28. TMessageParams::TMessageParams(unsigned int AParams)
  29. {
  30. Reset();
  31. Params = AParams;
  32. }
  33. //---------------------------------------------------------------------------
  34. TMessageParams::TMessageParams(const TQueryParams * AParams)
  35. {
  36. Reset();
  37. if (AParams != NULL)
  38. {
  39. Aliases = AParams->Aliases;
  40. AliasesCount = AParams->AliasesCount;
  41. Timer = AParams->Timer;
  42. TimerEvent = AParams->TimerEvent;
  43. TimerMessage = AParams->TimerMessage;
  44. TimerAnswers = AParams->TimerAnswers;
  45. Timeout = AParams->Timeout;
  46. TimeoutAnswer = AParams->TimeoutAnswer;
  47. if (FLAGSET(AParams->Params, qpNeverAskAgainCheck))
  48. {
  49. Params |= mpNeverAskAgainCheck;
  50. }
  51. if (FLAGSET(AParams->Params, qpAllowContinueOnError))
  52. {
  53. Params |= mpAllowContinueOnError;
  54. }
  55. }
  56. }
  57. //---------------------------------------------------------------------------
  58. inline void TMessageParams::Reset()
  59. {
  60. Params = 0;
  61. Aliases = NULL;
  62. AliasesCount = 0;
  63. Timer = 0;
  64. TimerEvent = NULL;
  65. TimerMessage = L"";
  66. TimerAnswers = 0;
  67. Timeout = 0;
  68. TimeoutAnswer = 0;
  69. NewerAskAgainTitle = L"";
  70. NewerAskAgainAnswer = 0;
  71. NewerAskAgainCheckedInitially = false;
  72. AllowHelp = true;
  73. }
  74. //---------------------------------------------------------------------------
  75. inline bool MapButton(unsigned int Answer, TMsgDlgBtn & Button)
  76. {
  77. bool Result = true;
  78. #define MAP_BUTTON(TYPE) if (Answer == qa ## TYPE) Button = mb ## TYPE; else
  79. MAP_BUTTON(Yes)
  80. MAP_BUTTON(No)
  81. MAP_BUTTON(OK)
  82. MAP_BUTTON(Cancel)
  83. MAP_BUTTON(Abort)
  84. MAP_BUTTON(Retry)
  85. MAP_BUTTON(Ignore)
  86. MAP_BUTTON(All)
  87. MAP_BUTTON(NoToAll)
  88. MAP_BUTTON(YesToAll)
  89. MAP_BUTTON(Help)
  90. #undef MAP_BUTTON
  91. if (Answer == qaSkip) Button = mbIgnore;
  92. else
  93. Result = false;
  94. return Result;
  95. }
  96. //---------------------------------------------------------------------------
  97. static void __fastcall NeverAskAgainCheckClick(void * /*Data*/, TObject * Sender)
  98. {
  99. TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(Sender);
  100. assert(CheckBox != NULL);
  101. TForm * Dialog = dynamic_cast<TForm *>(CheckBox->Owner);
  102. assert(Dialog != NULL);
  103. TModalResult PositiveAnswer = mrNone;
  104. if (CheckBox->Checked)
  105. {
  106. if (CheckBox->Tag > 0)
  107. {
  108. PositiveAnswer = CheckBox->Tag - 1;
  109. }
  110. else
  111. {
  112. TModalResult PositiveAnswers[] = { mrYes, mrOk, mrYesToAll };
  113. for (size_t i = 0; i < LENOF(PositiveAnswers); i++)
  114. {
  115. for (int ii = 0; ii < Dialog->ControlCount; ii++)
  116. {
  117. TButton * Button = dynamic_cast<TButton *>(Dialog->Controls[ii]);
  118. if (Button != NULL)
  119. {
  120. if (Button->ModalResult == PositiveAnswers[i])
  121. {
  122. PositiveAnswer = PositiveAnswers[i];
  123. break;
  124. }
  125. }
  126. }
  127. if (PositiveAnswer != mrNone)
  128. {
  129. break;
  130. }
  131. }
  132. }
  133. assert(PositiveAnswer != mrNone);
  134. }
  135. for (int ii = 0; ii < Dialog->ControlCount; ii++)
  136. {
  137. TButton * Button = dynamic_cast<TButton *>(Dialog->Controls[ii]);
  138. if ((Button != NULL) && (Button->ModalResult != mrNone) &&
  139. (Button->ModalResult != mrCancel))
  140. {
  141. Button->Enabled = !CheckBox->Checked || (Button->ModalResult == PositiveAnswer);
  142. }
  143. }
  144. }
  145. //---------------------------------------------------------------------------
  146. unsigned int MapResult(unsigned int Result, unsigned int Answers)
  147. {
  148. int Answer;
  149. switch (Result)
  150. {
  151. #define MAP_RESULT(RESULT) case mr ## RESULT: Answer = qa ## RESULT; break;
  152. MAP_RESULT(Abort);
  153. MAP_RESULT(All);
  154. MAP_RESULT(NoToAll);
  155. MAP_RESULT(YesToAll);
  156. MAP_RESULT(Yes);
  157. MAP_RESULT(No);
  158. MAP_RESULT(Retry);
  159. #undef MAP_RESULT
  160. case mrCancel:
  161. // mrCancel is returned always when X button is pressed, despite
  162. // no Cancel button was on the dialog. Find valid "cancel" answer.
  163. Answer = CancelAnswer(Answers);
  164. break;
  165. case mrOk:
  166. Answer = qaOK;
  167. break;
  168. case mrIgnore:
  169. Answer = (Answers & qaSkip) ? qaSkip : qaIgnore;
  170. break;
  171. default:
  172. assert(false);
  173. Answer = CancelAnswer(Answers);
  174. break;
  175. }
  176. return Answer;
  177. }
  178. //---------------------------------------------------------------------------
  179. TForm * __fastcall CreateMessageDialogEx(const UnicodeString Msg,
  180. TStrings * MoreMessages, TQueryType Type, unsigned int Answers, UnicodeString HelpKeyword,
  181. const TMessageParams * Params, TButton *& TimeoutButton)
  182. {
  183. TMsgDlgBtn TimeoutResult = mbHelp;
  184. TMsgDlgButtons Buttons;
  185. TMsgDlgType DlgType;
  186. switch (Type) {
  187. case qtConfirmation: DlgType = mtConfirmation; break;
  188. case qtInformation: DlgType = mtInformation; break;
  189. case qtError: DlgType = mtError; break;
  190. case qtWarning: DlgType = mtWarning; break;
  191. default: assert(false);
  192. }
  193. int AAnswers = Answers;
  194. unsigned int Answer = 0x01;
  195. while (AAnswers > 0)
  196. {
  197. if ((AAnswers & Answer) != 0)
  198. {
  199. TMsgDlgBtn Button;
  200. if (MapButton(Answer, Button))
  201. {
  202. Buttons << Button;
  203. if ((Params != NULL) && (Params->Timeout > 0) &&
  204. (Params->TimeoutAnswer == Answer))
  205. {
  206. TimeoutResult = Button;
  207. }
  208. }
  209. AAnswers &= ~Answer;
  210. }
  211. Answer <<= 1;
  212. }
  213. assert(!Buttons.Empty());
  214. if ((Params == NULL) || Params->AllowHelp)
  215. {
  216. Buttons << mbHelp;
  217. }
  218. if ((MoreMessages != NULL) && (MoreMessages->Count == 0))
  219. {
  220. MoreMessages = NULL;
  221. }
  222. TForm * Dialog;
  223. if ((Params == NULL) || (Params->Aliases == NULL))
  224. {
  225. Dialog = CreateMoreMessageDialog(Msg, MoreMessages, DlgType, Buttons,
  226. NULL, 0, TimeoutResult, &TimeoutButton);
  227. }
  228. else
  229. {
  230. TQueryButtonAlias * Aliases = new TQueryButtonAlias[Params->AliasesCount];
  231. try
  232. {
  233. for (unsigned int i = 0; i < Params->AliasesCount; i++)
  234. {
  235. TMsgDlgBtn Button;
  236. CHECK(MapButton(Params->Aliases[i].Button, Button));
  237. Aliases[i].Button = Button;
  238. Aliases[i].Alias = Params->Aliases[i].Alias;
  239. Aliases[i].OnClick = Params->Aliases[i].OnClick;
  240. }
  241. Dialog = CreateMoreMessageDialog(Msg, MoreMessages, DlgType, Buttons,
  242. Aliases, Params->AliasesCount, TimeoutResult, &TimeoutButton);
  243. }
  244. __finally
  245. {
  246. delete[] Aliases;
  247. }
  248. }
  249. try
  250. {
  251. if (Answers & qaSkip)
  252. {
  253. TButton * IgnoreButton = dynamic_cast<TButton *>(Dialog->FindComponent("Ignore"));
  254. assert(IgnoreButton);
  255. IgnoreButton->Caption = LoadStr(SKIP_BUTTON);
  256. }
  257. if ((Params != NULL) && (Params->Params & mpNeverAskAgainCheck))
  258. {
  259. static const int VertSpace = 20;
  260. Dialog->ClientHeight = Dialog->ClientHeight + VertSpace;
  261. for (int Index = 0; Index < Dialog->ControlCount; Index++)
  262. {
  263. TControl * Control = Dialog->Controls[Index];
  264. if (Control->Anchors.Contains(akBottom))
  265. {
  266. if (Control->Anchors.Contains(akTop))
  267. {
  268. Control->Height = Control->Height - VertSpace;
  269. }
  270. else
  271. {
  272. Control->Top = Control->Top - VertSpace;
  273. }
  274. }
  275. }
  276. TCheckBox * NeverAskAgainCheck = new TCheckBox(Dialog);
  277. NeverAskAgainCheck->Name = L"NeverAskAgainCheck";
  278. NeverAskAgainCheck->Parent = Dialog;
  279. NeverAskAgainCheck->BoundsRect = TRect(60, Dialog->ClientHeight - 27,
  280. Dialog->ClientWidth - 10, Dialog->ClientHeight - 5);
  281. NeverAskAgainCheck->Caption =
  282. !Params->NewerAskAgainTitle.IsEmpty() ?
  283. (UnicodeString)Params->NewerAskAgainTitle :
  284. // qaOK | qaIgnore is used, when custom "non-answer" button is required
  285. LoadStr(((Answers == qaOK) || (Answers == (qaOK | qaIgnore))) ?
  286. NEVER_SHOW_AGAIN : NEVER_ASK_AGAIN);
  287. NeverAskAgainCheck->Checked = Params->NewerAskAgainCheckedInitially;
  288. NeverAskAgainCheck->Anchors = TAnchors() << akBottom << akLeft;
  289. if (Params->NewerAskAgainAnswer > 0)
  290. {
  291. TMsgDlgBtn Button;
  292. if (MapButton(Params->NewerAskAgainAnswer, Button))
  293. {
  294. extern const int ModalResults[];
  295. NeverAskAgainCheck->Tag = ModalResults[Button] + 1;
  296. }
  297. }
  298. TNotifyEvent OnClick;
  299. ((TMethod*)&OnClick)->Code = NeverAskAgainCheckClick;
  300. NeverAskAgainCheck->OnClick = OnClick;
  301. }
  302. Dialog->HelpKeyword = HelpKeyword;
  303. ResetSystemSettings(Dialog);
  304. }
  305. catch(...)
  306. {
  307. delete Dialog;
  308. throw;
  309. }
  310. return Dialog;
  311. }
  312. //---------------------------------------------------------------------------
  313. unsigned int __fastcall ExecuteMessageDialog(TForm * Dialog, unsigned int Answers, const TMessageParams * Params)
  314. {
  315. FlashOnBackground();
  316. unsigned int Answer = MapResult(Dialog->ShowModal(), Answers);
  317. if ((Params != NULL) && (Params->Params & mpNeverAskAgainCheck))
  318. {
  319. TCheckBox * NeverAskAgainCheck =
  320. dynamic_cast<TCheckBox *>(Dialog->FindComponent(L"NeverAskAgainCheck"));
  321. assert(NeverAskAgainCheck);
  322. if (NeverAskAgainCheck->Checked)
  323. {
  324. bool PossitiveAnswer =
  325. (Params->NewerAskAgainAnswer > 0) ?
  326. (Answer == Params->NewerAskAgainAnswer) :
  327. (Answer == qaYes || Answer == qaOK || Answer == qaYesToAll);
  328. if (PossitiveAnswer)
  329. {
  330. Answer = qaNeverAskAgain;
  331. }
  332. }
  333. }
  334. return Answer;
  335. }
  336. //---------------------------------------------------------------------------
  337. class TMessageTimer : public TTimer
  338. {
  339. public:
  340. TQueryParamsTimerEvent Event;
  341. unsigned int Result;
  342. TForm * Dialog;
  343. __fastcall TMessageTimer(TComponent * AOwner);
  344. protected:
  345. void __fastcall DoTimer(TObject * Sender);
  346. };
  347. //---------------------------------------------------------------------------
  348. __fastcall TMessageTimer::TMessageTimer(TComponent * AOwner) : TTimer(AOwner)
  349. {
  350. Result = 0;
  351. Event = NULL;
  352. OnTimer = DoTimer;
  353. Dialog = NULL;
  354. }
  355. //---------------------------------------------------------------------------
  356. void __fastcall TMessageTimer::DoTimer(TObject * /*Sender*/)
  357. {
  358. if (Event != NULL)
  359. {
  360. Event(Result);
  361. if (Result != 0)
  362. {
  363. Dialog->ModalResult = mrCancel;
  364. }
  365. }
  366. }
  367. //---------------------------------------------------------------------------
  368. class TMessageTimeout : public TTimer
  369. {
  370. public:
  371. __fastcall TMessageTimeout(TComponent * AOwner, unsigned int Timeout,
  372. TButton * Button);
  373. protected:
  374. unsigned int FTimeout;
  375. TButton * FButton;
  376. UnicodeString FOrigCaption;
  377. void __fastcall DoTimer(TObject * Sender);
  378. void __fastcall UpdateButton();
  379. };
  380. //---------------------------------------------------------------------------
  381. __fastcall TMessageTimeout::TMessageTimeout(TComponent * AOwner,
  382. unsigned int Timeout, TButton * Button) :
  383. TTimer(AOwner), FTimeout(Timeout), FButton(Button)
  384. {
  385. OnTimer = DoTimer;
  386. Interval = MSecsPerSec;
  387. FOrigCaption = FButton->Caption;
  388. UpdateButton();
  389. }
  390. //---------------------------------------------------------------------------
  391. void __fastcall TMessageTimeout::UpdateButton()
  392. {
  393. assert(FButton != NULL);
  394. FButton->Caption = FMTLOAD(TIMEOUT_BUTTON, (FOrigCaption, int(FTimeout / MSecsPerSec)));
  395. }
  396. //---------------------------------------------------------------------------
  397. void __fastcall TMessageTimeout::DoTimer(TObject * /*Sender*/)
  398. {
  399. if (FTimeout <= MSecsPerSec)
  400. {
  401. assert(FButton != NULL);
  402. TForm * Dialog = dynamic_cast<TForm *>(FButton->Parent);
  403. assert(Dialog != NULL);
  404. Dialog->ModalResult = FButton->ModalResult;
  405. }
  406. else
  407. {
  408. FTimeout -= MSecsPerSec;
  409. UpdateButton();
  410. }
  411. }
  412. //---------------------------------------------------------------------------
  413. unsigned int __fastcall MoreMessageDialog(const UnicodeString Message, TStrings * MoreMessages,
  414. TQueryType Type, unsigned int Answers, UnicodeString HelpKeyword, const TMessageParams * Params)
  415. {
  416. unsigned int Result;
  417. TForm * Dialog = NULL;
  418. TMessageTimer * Timer = NULL;
  419. TMessageTimeout * Timeout = NULL;
  420. try
  421. {
  422. UnicodeString AMessage = Message;
  423. if ((Params != NULL) && (Params->Timer > 0))
  424. {
  425. Timer = new TMessageTimer(Application);
  426. Timer->Interval = Params->Timer;
  427. Timer->Event = Params->TimerEvent;
  428. if (Params->TimerAnswers > 0)
  429. {
  430. Answers = Params->TimerAnswers;
  431. }
  432. if (!Params->TimerMessage.IsEmpty())
  433. {
  434. AMessage = Params->TimerMessage;
  435. }
  436. }
  437. TButton * TimeoutButton = NULL;
  438. Dialog = CreateMessageDialogEx(AMessage, MoreMessages, Type, Answers,
  439. HelpKeyword, Params, TimeoutButton);
  440. if (Timer != NULL)
  441. {
  442. Timer->Dialog = Dialog;
  443. }
  444. if (Params != NULL)
  445. {
  446. if (Params->Timeout > 0)
  447. {
  448. Timeout = new TMessageTimeout(Application, Params->Timeout, TimeoutButton);
  449. }
  450. }
  451. Result = ExecuteMessageDialog(Dialog, Answers, Params);
  452. if ((Timer != NULL) && (Timer->Result != 0))
  453. {
  454. Result = Timer->Result;
  455. }
  456. }
  457. __finally
  458. {
  459. delete Dialog;
  460. delete Timer;
  461. delete Timeout;
  462. }
  463. return Result;
  464. }
  465. //---------------------------------------------------------------------------
  466. unsigned int __fastcall MessageDialog(const UnicodeString Msg, TQueryType Type,
  467. unsigned int Answers, UnicodeString HelpKeyword, const TMessageParams * Params)
  468. {
  469. return MoreMessageDialog(Msg, NULL, Type, Answers, HelpKeyword, Params);
  470. }
  471. //---------------------------------------------------------------------------
  472. unsigned int __fastcall SimpleErrorDialog(const UnicodeString Msg, const UnicodeString MoreMessages)
  473. {
  474. unsigned int Result;
  475. TStrings * More = NULL;
  476. try
  477. {
  478. if (!MoreMessages.IsEmpty())
  479. {
  480. More = new TStringList();
  481. More->Text = MoreMessages;
  482. }
  483. Result = MoreMessageDialog(Msg, More, qtError, qaOK, HELP_NONE);
  484. }
  485. __finally
  486. {
  487. delete More;
  488. }
  489. return Result;
  490. }
  491. //---------------------------------------------------------------------------
  492. unsigned int __fastcall ExceptionMessageDialog(Exception * E, TQueryType Type,
  493. const UnicodeString MessageFormat, unsigned int Answers, UnicodeString HelpKeyword,
  494. const TMessageParams * Params)
  495. {
  496. TStrings * MoreMessages = NULL;
  497. ExtException * EE = dynamic_cast<ExtException *>(E);
  498. if (EE != NULL)
  499. {
  500. MoreMessages = EE->MoreMessages;
  501. if (!EE->HelpKeyword.IsEmpty())
  502. {
  503. // we have to yet decide what to do now
  504. assert(HelpKeyword.IsEmpty());
  505. HelpKeyword = EE->HelpKeyword;
  506. }
  507. }
  508. UnicodeString Message;
  509. // this is always called from within ExceptionMessage check,
  510. // so it should never fail here
  511. CHECK(ExceptionMessage(E, Message));
  512. return MoreMessageDialog(
  513. FORMAT(MessageFormat.IsEmpty() ? UnicodeString(L"%s") : MessageFormat, (Message)),
  514. MoreMessages, Type, Answers, HelpKeyword, Params);
  515. }
  516. //---------------------------------------------------------------------------
  517. unsigned int __fastcall FatalExceptionMessageDialog(Exception * E, TQueryType Type,
  518. int SessionReopenTimeout, const UnicodeString MessageFormat, unsigned int Answers,
  519. UnicodeString HelpKeyword, const TMessageParams * Params)
  520. {
  521. assert(FLAGCLEAR(Answers, qaRetry));
  522. Answers |= qaRetry;
  523. TQueryButtonAlias Aliases[1];
  524. Aliases[0].Button = qaRetry;
  525. Aliases[0].Alias = LoadStr(RECONNECT_BUTTON);
  526. TMessageParams AParams;
  527. if (Params != NULL)
  528. {
  529. AParams = *Params;
  530. }
  531. assert(AParams.Timeout == 0);
  532. // the condition is de facto excess
  533. if (SessionReopenTimeout > 0)
  534. {
  535. AParams.Timeout = SessionReopenTimeout;
  536. AParams.TimeoutAnswer = qaRetry;
  537. }
  538. assert(AParams.Aliases == NULL);
  539. AParams.Aliases = Aliases;
  540. AParams.AliasesCount = LENOF(Aliases);
  541. return ExceptionMessageDialog(E, Type, MessageFormat, Answers, HelpKeyword, &AParams);
  542. }
  543. //---------------------------------------------------------------------------
  544. void __fastcall Busy(bool Start)
  545. {
  546. static int Busy = 0;
  547. static TCursor PrevCursor;
  548. if (Start)
  549. {
  550. if (!Busy)
  551. {
  552. PrevCursor = Screen->Cursor;
  553. Screen->Cursor = crHourGlass;
  554. }
  555. Busy++;
  556. assert(Busy < 10);
  557. }
  558. else
  559. {
  560. assert(Busy > 0);
  561. Busy--;
  562. if (!Busy)
  563. {
  564. Screen->Cursor = PrevCursor;
  565. }
  566. }
  567. }
  568. //---------------------------------------------------------------------------
  569. static void __fastcall CopyParamListSaveSettingsClick(TMenuItem * Item)
  570. {
  571. bool * SaveSettings = reinterpret_cast<bool *>(Item->Tag);
  572. *SaveSettings = !*SaveSettings;
  573. Item->Checked = *SaveSettings;
  574. }
  575. //---------------------------------------------------------------------------
  576. bool __fastcall DoRemoteMoveDialog(UnicodeString & Target, UnicodeString & FileMask)
  577. {
  578. UnicodeString Value = UnixIncludeTrailingBackslash(Target) + FileMask;
  579. TStrings * History = CustomWinConfiguration->History[L"RemoteTarget"];
  580. bool Result = InputDialog(
  581. LoadStr(REMOTE_MOVE_TITLE), LoadStr(REMOTE_TRANSFER_PROMPT),
  582. Value, HELP_REMOTE_MOVE, History, true);
  583. if (Result)
  584. {
  585. CustomWinConfiguration->History[L"RemoteTarget"] = History;
  586. Target = UnixExtractFilePath(Value);
  587. FileMask = UnixExtractFileName(Value);
  588. }
  589. return Result;
  590. }
  591. //---------------------------------------------------------------------------
  592. void __fastcall CopyParamListPopup(TPoint P, TPopupMenu * Menu,
  593. const TCopyParamType & Param, UnicodeString Preset, TNotifyEvent OnClick,
  594. int Options, bool * SaveSettings)
  595. {
  596. Menu->Items->Clear();
  597. bool AnyChecked = false;
  598. TMenuItem * Item = new TMenuItem(Menu);
  599. Item->Caption = LoadStr(COPY_PARAM_DEFAULT);
  600. Item->Tag = -1;
  601. Item->Checked =
  602. Preset.IsEmpty() && (GUIConfiguration->CopyParamPreset[L""] == Param);
  603. AnyChecked = AnyChecked || Item->Checked;
  604. Item->OnClick = OnClick;
  605. Menu->Items->Add(Item);
  606. const TCopyParamList * CopyParamList = GUIConfiguration->CopyParamList;
  607. for (int i = 0; i < CopyParamList->Count; i++)
  608. {
  609. Item = new TMenuItem(Menu);
  610. UnicodeString Name = CopyParamList->Names[i];
  611. Item->Caption = Name;
  612. Item->Tag = i;
  613. Item->Checked =
  614. (Preset == Name) && (GUIConfiguration->CopyParamPreset[Name] == Param);
  615. AnyChecked = AnyChecked || Item->Checked;
  616. Item->OnClick = OnClick;
  617. Menu->Items->Add(Item);
  618. }
  619. if (FLAGSET(Options, cplCustomize))
  620. {
  621. Item = new TMenuItem(Menu);
  622. Item->Caption = LoadStr(COPY_PARAM_CUSTOM);
  623. Item->Tag = -3;
  624. Item->Checked = !AnyChecked;
  625. Item->Default = FLAGSET(Options, cplCustomizeDefault);
  626. Item->OnClick = OnClick;
  627. Menu->Items->Add(Item);
  628. }
  629. if (FLAGSET(Options, cplSaveSettings))
  630. {
  631. assert(SaveSettings != NULL);
  632. Item = new TMenuItem(Menu);
  633. Item->Caption = LoadStr(COPY_PARAM_SAVE_SETTINGS);
  634. Item->Tag = int(SaveSettings);
  635. Item->Checked = *SaveSettings;
  636. TNotifyEvent SaveSettingsOnClick;
  637. ((TMethod*)&SaveSettingsOnClick)->Data = Item;
  638. ((TMethod*)&SaveSettingsOnClick)->Code = CopyParamListSaveSettingsClick;
  639. Item->OnClick = SaveSettingsOnClick;
  640. Menu->Items->Add(Item);
  641. }
  642. Item = new TMenuItem(Menu);
  643. Item->Caption = L"-";
  644. Menu->Items->Add(Item);
  645. Item = new TMenuItem(Menu);
  646. Item->Caption = LoadStr(COPY_PARAM_CONFIGURE);
  647. Item->Tag = -2;
  648. Item->OnClick = OnClick;
  649. Menu->Items->Add(Item);
  650. MenuPopup(Menu, P, NULL);
  651. }
  652. //---------------------------------------------------------------------------
  653. bool __fastcall CopyParamListPopupClick(TObject * Sender,
  654. TCopyParamType & Param, UnicodeString & Preset, int CopyParamAttrs)
  655. {
  656. TComponent * Item = dynamic_cast<TComponent *>(Sender);
  657. assert(Item != NULL);
  658. assert((Item->Tag >= -3) && (Item->Tag < GUIConfiguration->CopyParamList->Count));
  659. bool Result;
  660. if (Item->Tag == -2)
  661. {
  662. bool MatchedPreset = (GUIConfiguration->CopyParamPreset[Preset] == Param);
  663. DoPreferencesDialog(pmPresets);
  664. Result = (MatchedPreset && GUIConfiguration->HasCopyParamPreset[Preset]);
  665. if (Result)
  666. {
  667. Param = GUIConfiguration->CopyParamPreset[Preset];
  668. }
  669. }
  670. else if (Item->Tag == -3)
  671. {
  672. Result = DoCopyParamCustomDialog(Param, CopyParamAttrs);
  673. }
  674. else
  675. {
  676. Preset = (Item->Tag >= 0) ?
  677. GUIConfiguration->CopyParamList->Names[Item->Tag] : UnicodeString();
  678. Param = GUIConfiguration->CopyParamPreset[Preset];
  679. Result = true;
  680. }
  681. return Result;
  682. }
  683. //---------------------------------------------------------------------------
  684. TWinInteractiveCustomCommand::TWinInteractiveCustomCommand(
  685. TCustomCommand * ChildCustomCommand, const UnicodeString CustomCommandName) :
  686. TInteractiveCustomCommand(ChildCustomCommand)
  687. {
  688. FCustomCommandName = StripHotkey(CustomCommandName);
  689. }
  690. //---------------------------------------------------------------------------
  691. void __fastcall TWinInteractiveCustomCommand::Prompt(int /*Index*/,
  692. const UnicodeString & Prompt, UnicodeString & Value)
  693. {
  694. UnicodeString APrompt = Prompt;
  695. if (APrompt.IsEmpty())
  696. {
  697. APrompt = FMTLOAD(CUSTOM_COMMANDS_PARAM_PROMPT, (FCustomCommandName));
  698. }
  699. TStrings * History = CustomWinConfiguration->History[L"CustomCommandParam"];
  700. if (InputDialog(FMTLOAD(CUSTOM_COMMANDS_PARAM_TITLE, (FCustomCommandName)),
  701. APrompt, Value, HELP_CUSTOM_COMMAND_PARAM, History))
  702. {
  703. CustomWinConfiguration->History[L"CustomCommandParam"] = History;
  704. }
  705. else
  706. {
  707. Abort();
  708. }
  709. }
  710. //---------------------------------------------------------------------------
  711. static unsigned int __fastcall ShellDllVersion()
  712. {
  713. static unsigned int Result = 0;
  714. if (Result == 0)
  715. {
  716. Result = 4;
  717. HINSTANCE ShellDll = LoadLibrary(L"shell32.dll");
  718. if (ShellDll != NULL)
  719. {
  720. try
  721. {
  722. DLLGETVERSIONPROC DllGetVersion =
  723. (DLLGETVERSIONPROC)GetProcAddress(ShellDll, "DllGetVersion");
  724. if(DllGetVersion != NULL)
  725. {
  726. DLLVERSIONINFO VersionInfo;
  727. ZeroMemory(&VersionInfo, sizeof(VersionInfo));
  728. VersionInfo.cbSize = sizeof(VersionInfo);
  729. if (SUCCEEDED(DllGetVersion(&VersionInfo)))
  730. {
  731. Result = VersionInfo.dwMajorVersion;
  732. }
  733. }
  734. }
  735. __finally
  736. {
  737. FreeLibrary(ShellDll);
  738. }
  739. }
  740. }
  741. return Result;
  742. }
  743. //---------------------------------------------------------------------------
  744. void __fastcall MenuPopup(TPopupMenu * Menu, TButtonControl * Button)
  745. {
  746. TPoint Point = Button->ClientToScreen(TPoint(2, Button->Height));
  747. MenuPopup(Menu, Point, Button);
  748. }
  749. //---------------------------------------------------------------------------
  750. void __fastcall MenuPopup(TObject * Sender, const TPoint & MousePos, bool & Handled)
  751. {
  752. class TPublicControl : public TControl
  753. {
  754. friend void __fastcall MenuPopup(TObject * Sender, const TPoint & MousePos, bool & Handled);
  755. };
  756. TControl * Control = dynamic_cast<TControl *>(Sender);
  757. TPoint Point;
  758. if ((MousePos.x == -1) && (MousePos.y == -1))
  759. {
  760. Point = Control->ClientToScreen(TPoint(0, 0));
  761. }
  762. else
  763. {
  764. Point = Control->ClientToScreen(MousePos);
  765. }
  766. assert(Control != NULL);
  767. TPopupMenu * PopupMenu = (reinterpret_cast<TPublicControl *>(Control))->PopupMenu;
  768. assert(PopupMenu != NULL);
  769. MenuPopup(PopupMenu, Point, Control);
  770. Handled = true;
  771. }
  772. //---------------------------------------------------------------------------
  773. void __fastcall SetGlobalMinimizeHandler(TNotifyEvent OnMinimize)
  774. {
  775. GlobalOnMinimize = OnMinimize;
  776. }
  777. //---------------------------------------------------------------------------
  778. TNotifyEvent __fastcall GetGlobalMinimizeHandler()
  779. {
  780. return GlobalOnMinimize;
  781. }
  782. //---------------------------------------------------------------------------
  783. bool __fastcall IsGlobalMinimizeHandler()
  784. {
  785. return (GlobalOnMinimize != NULL);
  786. }
  787. //---------------------------------------------------------------------------
  788. bool __fastcall IsApplicationMinimized()
  789. {
  790. // VCL help recommends handling Application->OnMinimize/OnRestore
  791. // for tracking state, but OnRestore is actually not called
  792. // (OnMinimize is), when app is minimized from e.g. Progress window
  793. bool AppMinimized = IsIconic(Application->Handle);
  794. bool MainFormMinimized = IsIconic(Application->MainFormHandle);
  795. return AppMinimized || MainFormMinimized;
  796. }
  797. //---------------------------------------------------------------------------
  798. UnicodeString __fastcall TranslateDateFormat(UnicodeString FormatStr)
  799. {
  800. UnicodeString Result;
  801. CALTYPE CalendarType = StrToIntDef(GetLocaleStr(GetDefaultLCID(), LOCALE_ICALENDARTYPE, L"1"), 1);
  802. if ((CalendarType != CAL_JAPAN) && (CalendarType != CAL_TAIWAN) && (CalendarType != CAL_KOREA))
  803. {
  804. bool RemoveEra =
  805. (SysLocale.PriLangID == LANG_JAPANESE) ||
  806. (SysLocale.PriLangID == LANG_CHINESE) ||
  807. (SysLocale.PriLangID == LANG_KOREAN);
  808. if (RemoveEra)
  809. {
  810. int I = 1;
  811. while (I <= FormatStr.Length())
  812. {
  813. if ((FormatStr[I] != L'g') && (FormatStr[I] != L'G'))
  814. {
  815. Result += FormatStr[I];
  816. }
  817. I++;
  818. }
  819. }
  820. else
  821. {
  822. Result = FormatStr;
  823. }
  824. }
  825. else
  826. {
  827. int I = 1;
  828. while (I <= FormatStr.Length())
  829. {
  830. if (FormatStr.IsLeadSurrogate(I))
  831. {
  832. int L = CharLength(FormatStr, I);
  833. Result += FormatStr.SubString(I, L);
  834. I += L;
  835. }
  836. else
  837. {
  838. if (StrLIComp(FormatStr.c_str() + I - 1, L"gg", 2) == 0)
  839. {
  840. Result += L"ggg";
  841. I++;
  842. }
  843. else if (StrLIComp(FormatStr.c_str() + I - 1, L"yyyy", 4) == 0)
  844. {
  845. Result += L"eeee";
  846. I += 4 - 1;
  847. }
  848. else if (StrLIComp(FormatStr.c_str() + I - 1, L"yy", 2) == 0)
  849. {
  850. Result += L"ee";
  851. I += 2 - 1;
  852. }
  853. else if ((FormatStr[I] == L'y') || (FormatStr[I] == L'Y'))
  854. {
  855. Result += L"e";
  856. }
  857. else
  858. {
  859. Result += FormatStr[I];
  860. }
  861. I++;
  862. }
  863. }
  864. }
  865. return Result;
  866. }
  867. //---------------------------------------------------------------------------
  868. void __fastcall GetFormatSettingsFix()
  869. {
  870. // todo InitSysLocale
  871. // todo GetMonthDayNames
  872. // todo GetEraNamesAndYearOffsets
  873. LCID DefaultLCID = GetDefaultLCID();
  874. FormatSettings = TFormatSettings::Create(DefaultLCID);
  875. #pragma warn -8111
  876. CurrencyString = GetLocaleStr(DefaultLCID, LOCALE_SCURRENCY, L"");
  877. CurrencyFormat = (Byte) StrToIntDef(GetLocaleStr(DefaultLCID, LOCALE_ICURRENCY, L"0"), 0);
  878. NegCurrFormat = (Byte) StrToIntDef(GetLocaleStr(DefaultLCID, LOCALE_INEGCURR, L"0"), 0);
  879. ThousandSeparator = GetLocaleChar(DefaultLCID, LOCALE_STHOUSAND, L',');
  880. DecimalSeparator = GetLocaleChar(DefaultLCID, LOCALE_SDECIMAL, L'.');
  881. CurrencyDecimals = (Byte) StrToIntDef(GetLocaleStr(DefaultLCID, LOCALE_ICURRDIGITS, L"0"), 0);
  882. DateSeparator = GetLocaleChar(DefaultLCID, LOCALE_SDATE, L'/');
  883. ShortDateFormat = TranslateDateFormat(GetLocaleStr(DefaultLCID, LOCALE_SSHORTDATE, L"m/d/yy"));
  884. LongDateFormat = TranslateDateFormat(GetLocaleStr(DefaultLCID, LOCALE_SLONGDATE, L"mmmm d, yyyy"));
  885. TimeSeparator = GetLocaleChar(DefaultLCID, LOCALE_STIME, L':');
  886. TimeAMString = GetLocaleStr(DefaultLCID, LOCALE_S1159, L"am");
  887. TimePMString = GetLocaleStr(DefaultLCID, LOCALE_S2359, L"pm");
  888. UnicodeString HourFormat;
  889. if (StrToIntDef(GetLocaleStr(DefaultLCID, LOCALE_ITLZERO, L"0"), 0) == 0)
  890. {
  891. HourFormat = L"h";
  892. }
  893. else
  894. {
  895. HourFormat = L"hh";
  896. }
  897. UnicodeString TimePrefix, TimePostfix;
  898. if (StrToIntDef(GetLocaleStr(DefaultLCID, LOCALE_ITIME, L"0"), 0) == 0)
  899. {
  900. if (StrToIntDef(GetLocaleStr(DefaultLCID, LOCALE_ITIMEMARKPOSN, L"0"), 0) == 0)
  901. {
  902. TimePostfix = L" AMPM";
  903. }
  904. else
  905. {
  906. TimePrefix = L"AMPM ";
  907. }
  908. }
  909. ShortTimeFormat = TimePrefix + HourFormat + L":mm" + TimePostfix;
  910. LongTimeFormat = TimePrefix + HourFormat + L":mm:ss" + TimePostfix;
  911. ListSeparator = GetLocaleChar(DefaultLCID, LOCALE_SLIST, L',');
  912. #pragma warn .8111
  913. }
  914. //---------------------------------------------------------------------------
  915. void __fastcall WinInitialize()
  916. {
  917. if (IsWin7())
  918. {
  919. GetFormatSettingsFix();
  920. }
  921. #pragma warn -8111
  922. #pragma warn .8111
  923. }
  924. //---------------------------------------------------------------------------
  925. struct TNotifyIconData5
  926. {
  927. DWORD cbSize;
  928. HWND hWnd;
  929. UINT uID;
  930. UINT uFlags;
  931. UINT uCallbackMessage;
  932. HICON hIcon;
  933. TCHAR szTip[128];
  934. DWORD dwState;
  935. DWORD dwStateMask;
  936. TCHAR szInfo[256];
  937. union {
  938. UINT uTimeout;
  939. UINT uVersion;
  940. } DUMMYUNIONNAME;
  941. TCHAR szInfoTitle[64];
  942. DWORD dwInfoFlags;
  943. };
  944. //---------------------------------------------------------------------------
  945. #undef NOTIFYICONDATA_V1_SIZE
  946. #define NOTIFYICONDATA_V1_SIZE FIELD_OFFSET(TNotifyIconData5, szTip[64])
  947. //---------------------------------------------------------------------------
  948. __fastcall ::TTrayIcon::TTrayIcon(unsigned int Id)
  949. {
  950. FVisible = false;
  951. FOnClick = NULL;
  952. FTrayIcon = new TNotifyIconData5;
  953. memset(FTrayIcon, 0, sizeof(*FTrayIcon));
  954. FTrayIcon->cbSize = ((ShellDllVersion() >= 5) ? sizeof(*FTrayIcon) : NOTIFYICONDATA_V1_SIZE);
  955. FTrayIcon->uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
  956. FTrayIcon->hIcon = Application->Icon->Handle;
  957. FTrayIcon->uID = Id;
  958. FTrayIcon->hWnd = AllocateHWnd(WndProc);
  959. FTrayIcon->uCallbackMessage = WM_TRAY_ICON;
  960. FTaskbarCreatedMsg = RegisterWindowMessage(L"TaskbarCreated");
  961. }
  962. //---------------------------------------------------------------------------
  963. __fastcall ::TTrayIcon::~TTrayIcon()
  964. {
  965. // make sure we hide icon even in case it was shown just to pop up the balloon
  966. // (in which case Visible == false)
  967. CancelBalloon();
  968. Visible = false;
  969. DeallocateHWnd(FTrayIcon->hWnd);
  970. delete FTrayIcon;
  971. }
  972. //---------------------------------------------------------------------------
  973. bool __fastcall ::TTrayIcon::SupportsBalloons()
  974. {
  975. return (ShellDllVersion() >= 5);
  976. }
  977. //---------------------------------------------------------------------------
  978. void __fastcall ::TTrayIcon::PopupBalloon(UnicodeString Title,
  979. const UnicodeString & Str, TQueryType QueryType, unsigned int Timeout)
  980. {
  981. if (SupportsBalloons())
  982. {
  983. if (Timeout > 30000)
  984. {
  985. // this is probably system limit, do not try more, especially for
  986. // the timeout-driven hiding of the tray icon (for Win2k)
  987. Timeout = 30000;
  988. }
  989. FTrayIcon->uFlags |= NIF_INFO;
  990. Title = FORMAT(L"%s - %s", (Title, AppNameString()));
  991. StrPLCopy(FTrayIcon->szInfoTitle, Title, LENOF(FTrayIcon->szInfoTitle) - 1);
  992. StrPLCopy(FTrayIcon->szInfo, Str, LENOF(FTrayIcon->szInfo) - 1);
  993. FTrayIcon->uTimeout = Timeout;
  994. switch (QueryType)
  995. {
  996. case qtError:
  997. FTrayIcon->dwInfoFlags = NIIF_ERROR;
  998. break;
  999. case qtInformation:
  1000. case qtConfirmation:
  1001. FTrayIcon->dwInfoFlags = NIIF_INFO;
  1002. break;
  1003. case qtWarning:
  1004. default:
  1005. FTrayIcon->dwInfoFlags = NIIF_WARNING;
  1006. break;
  1007. }
  1008. KillTimer(FTrayIcon->hWnd, 1);
  1009. if (Visible)
  1010. {
  1011. Update();
  1012. }
  1013. else
  1014. {
  1015. Notify(NIM_ADD);
  1016. // can be 5 only anyway, no older version supports balloons
  1017. if (ShellDllVersion() <= 5)
  1018. {
  1019. // version 5 does not notify us when the balloon is hidden, so we must
  1020. // remove the icon ourselves after own timeout
  1021. SetTimer(FTrayIcon->hWnd, 1, Timeout, NULL);
  1022. }
  1023. }
  1024. // Clearing the flag ensures that subsequent updates does not hide the baloon
  1025. // unless CancelBalloon is called explicitly
  1026. FTrayIcon->uFlags = FTrayIcon->uFlags & ~NIF_INFO;
  1027. }
  1028. }
  1029. //---------------------------------------------------------------------------
  1030. void __fastcall ::TTrayIcon::CancelBalloon()
  1031. {
  1032. if (SupportsBalloons())
  1033. {
  1034. KillTimer(FTrayIcon->hWnd, 1);
  1035. if (Visible)
  1036. {
  1037. FTrayIcon->uFlags |= NIF_INFO;
  1038. FTrayIcon->szInfo[0] = L'\0';
  1039. Update();
  1040. FTrayIcon->uFlags = FTrayIcon->uFlags & ~NIF_INFO;
  1041. }
  1042. else
  1043. {
  1044. Notify(NIM_DELETE);
  1045. }
  1046. }
  1047. }
  1048. //---------------------------------------------------------------------------
  1049. bool __fastcall ::TTrayIcon::Notify(unsigned int Message)
  1050. {
  1051. bool Result = SUCCEEDED(Shell_NotifyIcon(Message, (NOTIFYICONDATA*)FTrayIcon));
  1052. if (Result && (Message == NIM_ADD))
  1053. {
  1054. UINT Timeout = FTrayIcon->uTimeout;
  1055. try
  1056. {
  1057. FTrayIcon->uVersion = NOTIFYICON_VERSION;
  1058. Result = SUCCEEDED(Shell_NotifyIcon(NIM_SETVERSION, (NOTIFYICONDATA*)FTrayIcon));
  1059. }
  1060. __finally
  1061. {
  1062. FTrayIcon->uTimeout = Timeout;
  1063. }
  1064. }
  1065. return Result;
  1066. }
  1067. //---------------------------------------------------------------------------
  1068. void __fastcall ::TTrayIcon::Update()
  1069. {
  1070. if (Visible)
  1071. {
  1072. Notify(NIM_MODIFY);
  1073. }
  1074. }
  1075. //---------------------------------------------------------------------------
  1076. void __fastcall ::TTrayIcon::SetVisible(bool value)
  1077. {
  1078. if (Visible != value)
  1079. {
  1080. if (value)
  1081. {
  1082. FVisible = Notify(NIM_ADD);
  1083. }
  1084. else
  1085. {
  1086. FVisible = false;
  1087. KillTimer(FTrayIcon->hWnd, 1);
  1088. Notify(NIM_DELETE);
  1089. }
  1090. }
  1091. }
  1092. //---------------------------------------------------------------------------
  1093. void __fastcall ::TTrayIcon::WndProc(TMessage & Message)
  1094. {
  1095. try
  1096. {
  1097. if (Message.Msg == WM_TRAY_ICON)
  1098. {
  1099. assert(Message.WParam == 0);
  1100. switch (Message.LParam)
  1101. {
  1102. // old shell32
  1103. case WM_LBUTTONUP:
  1104. case WM_RBUTTONUP:
  1105. // new shell32:
  1106. case WM_CONTEXTMENU:
  1107. case NIN_BALLOONUSERCLICK:
  1108. if (OnClick != NULL)
  1109. {
  1110. OnClick(NULL);
  1111. }
  1112. Message.Result = true;
  1113. break;
  1114. }
  1115. switch (Message.LParam)
  1116. {
  1117. case NIN_BALLOONHIDE:
  1118. case NIN_BALLOONTIMEOUT:
  1119. case NIN_BALLOONUSERCLICK:
  1120. KillTimer(FTrayIcon->hWnd, 1);
  1121. // if icon was shown just to display balloon, hide it with the balloon
  1122. if (!Visible)
  1123. {
  1124. Notify(NIM_DELETE);
  1125. }
  1126. break;
  1127. }
  1128. }
  1129. else if (Message.Msg == WM_TIMER)
  1130. {
  1131. // sanity check
  1132. Notify(NIM_DELETE);
  1133. }
  1134. else if (Message.Msg == FTaskbarCreatedMsg)
  1135. {
  1136. if (Visible)
  1137. {
  1138. // force recreation
  1139. Visible = false;
  1140. Visible = true;
  1141. }
  1142. }
  1143. else
  1144. {
  1145. Message.Result = DefWindowProc(FTrayIcon->hWnd, Message.Msg, Message.WParam, Message.LParam);
  1146. }
  1147. }
  1148. catch(Exception & E)
  1149. {
  1150. Application->HandleException(&E);
  1151. }
  1152. }
  1153. //---------------------------------------------------------------------------
  1154. UnicodeString __fastcall ::TTrayIcon::GetHint()
  1155. {
  1156. return FTrayIcon->szTip;
  1157. }
  1158. //---------------------------------------------------------------------------
  1159. void __fastcall ::TTrayIcon::SetHint(UnicodeString value)
  1160. {
  1161. if (Hint != value)
  1162. {
  1163. unsigned int Max = ((ShellDllVersion() >= 5) ? LENOF(FTrayIcon->szTip) : 64);
  1164. StrPLCopy(FTrayIcon->szTip, value, Max - 1);
  1165. Update();
  1166. }
  1167. }
  1168. //---------------------------------------------------------------------------