1
0

Progress.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include <CoreMain.h>
  6. #include <TextsWin.h>
  7. #include <HelpWin.h>
  8. #include <WinInterface.h>
  9. #include <VCLCommon.h>
  10. #include <CustomWinConfiguration.h>
  11. #include <GUITools.h>
  12. #include <BaseUtils.hpp>
  13. #include <DateUtils.hpp>
  14. #include <Consts.hpp>
  15. #include <HistoryComboBox.hpp>
  16. #include "Progress.h"
  17. //---------------------------------------------------------------------
  18. #pragma link "PathLabel"
  19. #pragma link "PngImageList"
  20. #pragma link "TB2Dock"
  21. #pragma link "TB2Item"
  22. #pragma link "TB2Toolbar"
  23. #pragma link "TBX"
  24. #pragma link "TB2ExtItems"
  25. #pragma link "TBXExtItems"
  26. #ifndef NO_RESOURCES
  27. #pragma resource "*.dfm"
  28. #endif
  29. //---------------------------------------------------------------------
  30. bool __fastcall TProgressForm::IsIndetermiateOperation(TFileOperation Operation)
  31. {
  32. return (Operation == foCalculateSize);
  33. }
  34. //---------------------------------------------------------------------
  35. UnicodeString __fastcall TProgressForm::ProgressStr(TFileOperationProgressType * ProgressData)
  36. {
  37. static const int Captions[] = { 0, 0, PROGRESS_DELETE,
  38. PROGRESS_SETPROPERTIES, 0, PROGRESS_CUSTOM_COMAND, PROGRESS_CALCULATE_SIZE,
  39. PROGRESS_REMOTE_MOVE, PROGRESS_REMOTE_COPY, PROGRESS_GETPROPERTIES,
  40. PROGRESS_CALCULATE_CHECKSUM, PROGRESS_LOCK, PROGRESS_UNLOCK };
  41. DebugAssert((unsigned int)ProgressData->Operation >= 1 && ((unsigned int)ProgressData->Operation - 1) < LENOF(Captions));
  42. int Id;
  43. if ((ProgressData->Operation == foCopy) || (ProgressData->Operation == foMove))
  44. {
  45. Id = (ProgressData->Side == osLocal) ? PROGRESS_UPLOAD : PROGRESS_DOWNLOAD;
  46. }
  47. else
  48. {
  49. Id = Captions[(int)ProgressData->Operation - 1];
  50. DebugAssert(Id != 0);
  51. }
  52. UnicodeString Result = LoadStr(Id);
  53. if (!IsIndetermiateOperation(ProgressData->Operation))
  54. {
  55. Result = FORMAT(L"%d%% %s", (ProgressData->OverallProgress(), Result));
  56. }
  57. return Result;
  58. }
  59. //---------------------------------------------------------------------
  60. __fastcall TProgressForm::TProgressForm(TComponent * AOwner, bool AllowMoveToQueue)
  61. : FData(), TForm(AOwner)
  62. {
  63. FLastOperation = foNone;
  64. FLastTotalSizeSet = false;
  65. FDataGot = false;
  66. FDataReceived = false;
  67. FCancel = csContinue;
  68. FMoveToQueue = false;
  69. FMinimizedByMe = false;
  70. FUpdateCounter = 0;
  71. FDeleteToRecycleBin = false;
  72. FReadOnly = false;
  73. FShowAsModalStorage = NULL;
  74. FStarted = Now();
  75. FModalBeginHooked = false;
  76. FPrevApplicationModalBegin = NULL;
  77. FModalLevel = -1;
  78. UseSystemSettings(this);
  79. if (CustomWinConfiguration->OperationProgressOnTop)
  80. {
  81. FOperationProgress = TopProgress;
  82. FFileProgress = BottomProgress;
  83. }
  84. else
  85. {
  86. FOperationProgress = BottomProgress;
  87. FFileProgress = TopProgress;
  88. }
  89. FOnceDoneItems.Add(odoIdle, IdleOnceDoneItem);
  90. FOnceDoneItems.Add(odoDisconnect, DisconnectOnceDoneItem);
  91. FOnceDoneItems.Add(odoSuspend, SuspendOnceDoneItem);
  92. FOnceDoneItems.Add(odoShutDown, ShutDownOnceDoneItem);
  93. ResetOnceDoneOperation();
  94. HideComponentsPanel(this);
  95. SelectScaledImageList(ImageList);
  96. SetGlobalMinimizeHandler(this, GlobalMinimize);
  97. MoveToQueueItem->Visible = AllowMoveToQueue;
  98. }
  99. //---------------------------------------------------------------------------
  100. __fastcall TProgressForm::~TProgressForm()
  101. {
  102. // to prevent raising assertion (e.g. IsProgress == True)
  103. FData.Clear();
  104. ClearGlobalMinimizeHandler(GlobalMinimize);
  105. if (IsApplicationMinimized() && FMinimizedByMe)
  106. {
  107. ShowNotification(
  108. NULL, MainInstructions(LoadStr(BALLOON_OPERATION_COMPLETE)),
  109. qtInformation);
  110. }
  111. if (FModalBeginHooked)
  112. {
  113. DebugAssert(Application->OnModalBegin == ApplicationModalBegin);
  114. Application->OnModalBegin = FPrevApplicationModalBegin;
  115. FModalBeginHooked = false;
  116. }
  117. ReleaseAsModal(this, FShowAsModalStorage);
  118. }
  119. //---------------------------------------------------------------------
  120. void __fastcall TProgressForm::UpdateControls()
  121. {
  122. DebugAssert((FData.Operation >= foCopy) && (FData.Operation <= foUnlock) &&
  123. (FData.Operation != foRename));
  124. bool TransferOperation =
  125. ((FData.Operation == foCopy) || (FData.Operation == foMove));
  126. CancelItem->Enabled = !FReadOnly && (FCancel == csContinue);
  127. MoveToQueueItem->Enabled = !FMoveToQueue && (FCancel == csContinue);
  128. CycleOnceDoneItem->Visible =
  129. !FReadOnly &&
  130. (FData.Operation != foCalculateSize) &&
  131. (FData.Operation != foGetProperties) &&
  132. (FData.Operation != foCalculateChecksum);
  133. CycleOnceDoneItem->ImageIndex = CurrentOnceDoneItem()->ImageIndex;
  134. SpeedComboBoxItem->Visible = TransferOperation;
  135. if (FData.Operation != FLastOperation)
  136. {
  137. UnicodeString Animation;
  138. UnicodeString CancelCaption = Vcl_Consts_SMsgDlgCancel;
  139. int MoveToQueueImageIndex = -1;
  140. int MoveTransferToQueueImageIndex;
  141. if (FData.Side == osRemote)
  142. {
  143. MoveTransferToQueueImageIndex = 7;
  144. }
  145. else
  146. {
  147. MoveTransferToQueueImageIndex = 8;
  148. }
  149. switch (FData.Operation)
  150. {
  151. case foCopy:
  152. if (FData.Side == osRemote)
  153. {
  154. Animation = L"CopyRemote";
  155. }
  156. else
  157. {
  158. Animation = L"CopyLocal";
  159. }
  160. MoveToQueueImageIndex = MoveTransferToQueueImageIndex;
  161. break;
  162. case foMove:
  163. if (FData.Side == osRemote)
  164. {
  165. Animation = L"MoveRemote";
  166. }
  167. else
  168. {
  169. Animation = L"MoveLocal";
  170. }
  171. MoveToQueueImageIndex = MoveTransferToQueueImageIndex;
  172. break;
  173. case foDelete:
  174. Animation = DeleteToRecycleBin ? L"Recycle" : L"Delete";
  175. break;
  176. case foCalculateSize:
  177. Animation = L"CalculateSize";
  178. CancelCaption = LoadStr(SKIP_BUTTON);
  179. MoveToQueueImageIndex = MoveTransferToQueueImageIndex;
  180. break;
  181. case foSetProperties:
  182. Animation = "SetProperties";
  183. break;
  184. default:
  185. DebugAssert(
  186. (FData.Operation == foCustomCommand) ||
  187. (FData.Operation == foGetProperties) ||
  188. (FData.Operation == foCalculateChecksum) ||
  189. (FData.Operation == foLock) ||
  190. (FData.Operation == foUnlock) ||
  191. (FData.Operation == foRemoteCopy) ||
  192. (FData.Operation == foRemoteMove));
  193. break;
  194. }
  195. CancelItem->Caption = CancelCaption;
  196. TopProgress->Style = IsIndetermiateOperation(FData.Operation) ? pbstMarquee : pbstNormal;
  197. FFrameAnimation.Init(AnimationPaintBox, Animation);
  198. FFrameAnimation.Start();
  199. int Delta = 0;
  200. if (TransferOperation && !TransferPanel->Visible) Delta += TransferPanel->Height;
  201. else
  202. if (!TransferOperation && TransferPanel->Visible) Delta += -TransferPanel->Height;
  203. TransferPanel->Visible = TransferOperation;
  204. ClientHeight = ClientHeight + Delta;
  205. TargetLabel->Visible = TransferOperation;
  206. TargetPathLabel->Visible = TransferOperation;
  207. TargetPathLabel->UnixPath = (FData.Side == osLocal);
  208. FileLabel->UnixPath = (FData.Side == osRemote);
  209. PathLabel->Caption =
  210. LoadStr((FData.Operation == foCalculateSize) ? PROGRESS_PATH_LABEL : PROGRESS_FILE_LABEL);
  211. MoveToQueueItem->ImageIndex = MoveToQueueImageIndex;
  212. FLastOperation = FData.Operation;
  213. FLastTotalSizeSet = !FData.TotalSizeSet;
  214. }
  215. if (FLastTotalSizeSet != FData.TotalSizeSet)
  216. {
  217. StartTimeLabelLabel->Visible = !FData.TotalSizeSet;
  218. StartTimeLabel->Visible = !FData.TotalSizeSet;
  219. TimeLeftLabelLabel->Visible = FData.TotalSizeSet;
  220. TimeLeftLabel->Visible = FData.TotalSizeSet;
  221. FLastTotalSizeSet = FData.TotalSizeSet;
  222. }
  223. if ((FData.Operation == foCalculateSize) && ALWAYS_TRUE(!FData.Temp))
  224. {
  225. if (FData.Side == osRemote)
  226. {
  227. FileLabel->Caption = UnixExtractFileDir(FData.FullFileName);
  228. }
  229. else
  230. {
  231. FileLabel->Caption = ExtractFileDir(FData.FullFileName);
  232. }
  233. }
  234. else if ((FData.Side == osRemote) || !FData.Temp)
  235. {
  236. FileLabel->Caption = FData.FileName;
  237. }
  238. else
  239. {
  240. FileLabel->Caption = ExtractFileName(FData.FileName);
  241. }
  242. int OverallProgress = FData.OverallProgress();
  243. FOperationProgress->Position = OverallProgress;
  244. FOperationProgress->Hint = FORMAT(L"%d%%", (OverallProgress));
  245. Caption = FormatFormCaption(this, ProgressStr(&FData));
  246. if (TransferOperation)
  247. {
  248. if ((FData.Side == osLocal) || !FData.Temp)
  249. {
  250. TargetPathLabel->Caption = FData.Directory;
  251. }
  252. else
  253. {
  254. TargetPathLabel->Caption = LoadStr(PROGRESS_TEMP_DIR);
  255. }
  256. StartTimeLabel->Caption = FData.StartTime.TimeString();
  257. if (FData.TotalSizeSet)
  258. {
  259. TimeLeftLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat,
  260. FData.TotalTimeLeft());
  261. }
  262. TimeElapsedLabel->Caption = FormatDateTimeSpan(Configuration->TimeFormat, FData.TimeElapsed());
  263. BytesTransferedLabel->Caption = FormatBytes(FData.TotalTransfered);
  264. CPSLabel->Caption = FORMAT(L"%s/s", (FormatBytes(FData.CPS())));
  265. FFileProgress->Position = FData.TransferProgress();
  266. FFileProgress->Hint = FORMAT(L"%d%%", (FFileProgress->Position));
  267. }
  268. }
  269. //---------------------------------------------------------------------
  270. static __int64 DelayStartInterval = MSecsPerSec / 2;
  271. static __int64 UpdateInterval = 1 * MSecsPerSec;
  272. //---------------------------------------------------------------------
  273. bool __fastcall TProgressForm::ReceiveData(bool Force, int ModalLevelOffset)
  274. {
  275. bool Result = false;
  276. if (FDataGot && !FDataReceived)
  277. {
  278. // CPS limit is set set only once from TFileOperationProgressType::Start.
  279. // Needs to be set even when data are not accepted yet, otherwise we would
  280. // write default value to FData in TProgressForm::SetProgressData
  281. FCPSLimit = FData.CPSLimit;
  282. // Never popup over dialog that appeared later than we started
  283. // (this can happen from UpdateTimerTimer when application is
  284. // restored while overwrite confirmation dialog [or any other]
  285. // is already shown).
  286. // TODO We should probably take as-modal windows into account too
  287. // (for extreme cases like restoring while reconnecting [as-modal TAuthenticateForm]).
  288. if ((FModalLevel < 0) || (Application->ModalLevel + ModalLevelOffset <= FModalLevel))
  289. {
  290. // Delay showing the progress until the application is restored,
  291. // otherwise the form popups up unminimized.
  292. // See solution in TMessageForm::CMShowingChanged.
  293. if (!IsApplicationMinimized() &&
  294. (Force || (MilliSecondsBetween(Now(), FStarted) > DelayStartInterval)))
  295. {
  296. FDataReceived = true;
  297. SpeedComboBoxItem->Text = SetSpeedLimit(FCPSLimit);
  298. ShowAsModal(this, FShowAsModalStorage);
  299. // particularly needed for the case, when we are showing the form delayed
  300. // because application was minimized when operation started
  301. Result = true;
  302. }
  303. else if (!FModalBeginHooked && ALWAYS_TRUE(FModalLevel < 0))
  304. {
  305. // record state as of time, the window should be shown,
  306. // had not we implemented delayed show
  307. FPrevApplicationModalBegin = Application->OnModalBegin;
  308. Application->OnModalBegin = ApplicationModalBegin;
  309. FModalBeginHooked = true;
  310. FModalLevel = Application->ModalLevel;
  311. }
  312. }
  313. }
  314. return Result;
  315. }
  316. //---------------------------------------------------------------------------
  317. void __fastcall TProgressForm::ApplicationModalBegin(TObject * Sender)
  318. {
  319. // Popup before any modal dialog shows (typically overwrite confirmation,
  320. // as that popups nearly instantly, i.e. less than DelayStartInterval).
  321. // The Application->ModalLevel is already incremented, but we should treat it as
  322. // if it were not as the dialog is not created yet (so we can popup if we are not yet).
  323. ReceiveData(true, -1);
  324. if (FPrevApplicationModalBegin != NULL)
  325. {
  326. FPrevApplicationModalBegin(Sender);
  327. }
  328. }
  329. //---------------------------------------------------------------------
  330. void __fastcall TProgressForm::SetProgressData(TFileOperationProgressType & AData)
  331. {
  332. TDateTime N = Now();
  333. bool InstantUpdate = false;
  334. // workaround: to force displaing first file data immediately,
  335. // otherwise form dialog uses to be blank for first second
  336. // (until UpdateTimerTimer)
  337. if (FileLabel->Caption.IsEmpty() && !AData.FileName.IsEmpty())
  338. {
  339. InstantUpdate = true;
  340. }
  341. FData.AssignButKeepSuspendState(AData);
  342. FDataGot = true;
  343. if (!UpdateTimer->Enabled)
  344. {
  345. UpdateTimer->Interval = static_cast<int>(DelayStartInterval);
  346. UpdateTimer->Enabled = true;
  347. FSinceLastUpdate = 0;
  348. }
  349. if (ReceiveData(false, 0))
  350. {
  351. InstantUpdate = true;
  352. }
  353. if (InstantUpdate)
  354. {
  355. UpdateControls();
  356. Application->ProcessMessages();
  357. }
  358. if (ProcessGUI(FUpdateCounter % 5 == 0))
  359. {
  360. FUpdateCounter = 0;
  361. }
  362. FUpdateCounter++;
  363. AData.CPSLimit = FCPSLimit;
  364. }
  365. //---------------------------------------------------------------------------
  366. void __fastcall TProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  367. {
  368. // popup the progress window at least here, if SetProgressData is
  369. // not being called (typically this happens when using custom command
  370. // that launches long-lasting external process, such as visual diff)
  371. ReceiveData(false, 0);
  372. if (UpdateTimer->Interval == DelayStartInterval)
  373. {
  374. UpdateTimer->Interval = static_cast<int>(GUIUpdateInterval);
  375. }
  376. if (FDataReceived)
  377. {
  378. FSinceLastUpdate += UpdateTimer->Interval;
  379. if (FSinceLastUpdate >= UpdateInterval)
  380. {
  381. UpdateControls();
  382. FSinceLastUpdate = 0;
  383. }
  384. }
  385. }
  386. //---------------------------------------------------------------------------
  387. void __fastcall TProgressForm::FormShow(TObject * /*Sender*/)
  388. {
  389. CopySpeedLimits(CustomWinConfiguration->History[L"SpeedLimit"], SpeedComboBoxItem->Strings);
  390. ReceiveData(false, 0);
  391. if (FDataReceived)
  392. {
  393. UpdateControls();
  394. }
  395. HookFormActivation(this);
  396. }
  397. //---------------------------------------------------------------------------
  398. void __fastcall TProgressForm::FormHide(TObject * /*Sender*/)
  399. {
  400. UnhookFormActivation(this);
  401. // This is to counter the "infinite" timestamp in
  402. // TTerminalManager::ApplicationShowHint.
  403. // Because if form disappears on its own, hint is not hidden.
  404. Application->CancelHint();
  405. CustomWinConfiguration->History[L"SpeedLimit"] = SpeedComboBoxItem->Strings;
  406. UpdateTimer->Enabled = false;
  407. }
  408. //---------------------------------------------------------------------------
  409. void __fastcall TProgressForm::CancelItemClick(TObject * /*Sender*/)
  410. {
  411. CancelOperation();
  412. }
  413. //---------------------------------------------------------------------------
  414. void __fastcall TProgressForm::Minimize(TObject * Sender)
  415. {
  416. CallGlobalMinimizeHandler(Sender);
  417. }
  418. //---------------------------------------------------------------------------
  419. void __fastcall TProgressForm::MinimizeItemClick(TObject * Sender)
  420. {
  421. Minimize(Sender);
  422. }
  423. //---------------------------------------------------------------------------
  424. void __fastcall TProgressForm::CancelOperation()
  425. {
  426. DebugAssert(FDataReceived);
  427. if (!FData.Suspended)
  428. {
  429. // mostly useless, as suspend is called over copy of actual progress data
  430. FData.Suspend();
  431. UpdateControls();
  432. try
  433. {
  434. TCancelStatus ACancel;
  435. if (FData.TransferingFile &&
  436. (FData.TimeExpected() > GUIConfiguration->IgnoreCancelBeforeFinish))
  437. {
  438. int Result = MessageDialog(LoadStr(CANCEL_OPERATION_FATAL2), qtWarning,
  439. qaYes | qaNo | qaCancel, HELP_PROGRESS_CANCEL);
  440. switch (Result)
  441. {
  442. case qaYes:
  443. ACancel = csCancelTransfer; break;
  444. case qaNo:
  445. ACancel = csCancel; break;
  446. default:
  447. ACancel = csContinue; break;
  448. }
  449. }
  450. else
  451. {
  452. ACancel = csCancel;
  453. }
  454. if (FCancel < ACancel)
  455. {
  456. FCancel = ACancel;
  457. UpdateControls();
  458. }
  459. }
  460. __finally
  461. {
  462. FData.Resume();
  463. }
  464. }
  465. }
  466. //---------------------------------------------------------------------------
  467. void __fastcall TProgressForm::GlobalMinimize(TObject * /*Sender*/)
  468. {
  469. ApplicationMinimize();
  470. FMinimizedByMe = true;
  471. }
  472. //---------------------------------------------------------------------------
  473. TTBCustomItem * __fastcall TProgressForm::CurrentOnceDoneItem()
  474. {
  475. TOnceDoneItems::const_iterator Iterator = FOnceDoneItems.begin();
  476. while (Iterator != FOnceDoneItems.end())
  477. {
  478. if (Iterator->second->Checked)
  479. {
  480. return Iterator->second;
  481. }
  482. Iterator++;
  483. }
  484. FAIL;
  485. return NULL;
  486. }
  487. //---------------------------------------------------------------------------
  488. TOnceDoneOperation __fastcall TProgressForm::GetOnceDoneOperation()
  489. {
  490. return FOnceDoneItems.LookupFirst(CurrentOnceDoneItem());
  491. }
  492. //---------------------------------------------------------------------------
  493. void __fastcall TProgressForm::SetOnceDoneItem(TTBCustomItem * Item)
  494. {
  495. TTBCustomItem * Current = CurrentOnceDoneItem();
  496. if (Current != Item)
  497. {
  498. Current->Checked = false;
  499. Item->Checked = true;
  500. UpdateControls();
  501. }
  502. }
  503. //---------------------------------------------------------------------------
  504. void __fastcall TProgressForm::SetOnceDoneOperation(TOnceDoneOperation value)
  505. {
  506. SetOnceDoneItem(FOnceDoneItems.LookupSecond(value));
  507. }
  508. //---------------------------------------------------------------------------
  509. bool __fastcall TProgressForm::GetAllowMinimize()
  510. {
  511. return MinimizeItem->Visible;
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TProgressForm::SetAllowMinimize(bool value)
  515. {
  516. MinimizeItem->Visible = value;
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TProgressForm::SetReadOnly(bool value)
  520. {
  521. if (FReadOnly != value)
  522. {
  523. FReadOnly = value;
  524. if (!value)
  525. {
  526. ResetOnceDoneOperation();
  527. }
  528. UpdateControls();
  529. }
  530. }
  531. //---------------------------------------------------------------------------
  532. void __fastcall TProgressForm::ResetOnceDoneOperation()
  533. {
  534. SetOnceDoneOperation(odoIdle);
  535. }
  536. //---------------------------------------------------------------------------
  537. void __fastcall TProgressForm::Dispatch(void * AMessage)
  538. {
  539. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  540. if (Message.Msg == WM_CLOSE)
  541. {
  542. CancelOperation();
  543. }
  544. else
  545. {
  546. TForm::Dispatch(AMessage);
  547. }
  548. }
  549. //---------------------------------------------------------------------------
  550. void __fastcall TProgressForm::MoveToQueueItemClick(TObject * /*Sender*/)
  551. {
  552. FMoveToQueue = true;
  553. UpdateControls();
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TProgressForm::OnceDoneItemClick(TObject * Sender)
  557. {
  558. SetOnceDoneItem(dynamic_cast<TTBCustomItem *>(Sender));
  559. }
  560. //---------------------------------------------------------------------------
  561. void __fastcall TProgressForm::CycleOnceDoneItemClick(TObject * /*Sender*/)
  562. {
  563. TTBCustomItem * Item = CurrentOnceDoneItem();
  564. int Index = Item->Parent->IndexOf(Item);
  565. DebugAssert(Index >= 0);
  566. if (Index < Item->Parent->Count - 1)
  567. {
  568. Index++;
  569. }
  570. else
  571. {
  572. Index = 0;
  573. }
  574. SetOnceDoneItem(Item->Parent->Items[Index]);
  575. }
  576. //---------------------------------------------------------------------------
  577. UnicodeString __fastcall TProgressForm::ItemSpeed(const UnicodeString & Text,
  578. TTBXComboBoxItem * Item)
  579. {
  580. // Keep in sync with TNonVisualDataModule::QueueItemSpeed
  581. FCPSLimit = GetSpeedLimit(Text);
  582. UnicodeString Result = SetSpeedLimit(FCPSLimit);
  583. SaveToHistory(Item->Strings, Result);
  584. CustomWinConfiguration->History[L"SpeedLimit"] = Item->Strings;
  585. return Result;
  586. }
  587. //---------------------------------------------------------------------------
  588. void __fastcall TProgressForm::SpeedComboBoxItemAcceptText(TObject * Sender,
  589. UnicodeString & NewText, bool & /*Accept*/)
  590. {
  591. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  592. NewText = ItemSpeed(NewText, Item);
  593. }
  594. //---------------------------------------------------------------------------
  595. void __fastcall TProgressForm::SpeedComboBoxItemItemClick(TObject * Sender)
  596. {
  597. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  598. Item->Text = ItemSpeed(Item->Text, Item);
  599. }
  600. //---------------------------------------------------------------------------
  601. void __fastcall TProgressForm::SpeedComboBoxItemAdjustImageIndex(
  602. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int /*AIndex*/, int & ImageIndex)
  603. {
  604. // Use fixed image (do not change image by item index)
  605. ImageIndex = Sender->ImageIndex;
  606. }
  607. //---------------------------------------------------------------------------
  608. void __fastcall TProgressForm::FormKeyDown(
  609. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  610. {
  611. // We do not have Cancel button, so we have to handle Esc key explicitly
  612. if (Key == VK_ESCAPE)
  613. {
  614. CancelOperation();
  615. Key = 0;
  616. }
  617. }
  618. //---------------------------------------------------------------------------