Progress.cpp 21 KB

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