Progress.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. 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 = IsIndetermiateOperation(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 = 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. TDateTime N = Now();
  321. bool InstantUpdate = false;
  322. // workaround: to force displaing first file data immediately,
  323. // otherwise form dialog uses to be blank for first second
  324. // (until UpdateTimerTimer)
  325. if (FileLabel->Caption.IsEmpty() && !AData.FileName.IsEmpty())
  326. {
  327. InstantUpdate = true;
  328. }
  329. FData.AssignButKeepSuspendState(AData);
  330. FDataGot = true;
  331. if (!UpdateTimer->Enabled)
  332. {
  333. UpdateTimer->Interval = static_cast<int>(DelayStartInterval);
  334. UpdateTimer->Enabled = true;
  335. FSinceLastUpdate = 0;
  336. }
  337. if (ReceiveData(false, 0))
  338. {
  339. InstantUpdate = true;
  340. }
  341. if (InstantUpdate)
  342. {
  343. UpdateControls();
  344. Application->ProcessMessages();
  345. }
  346. if (ProcessGUI(FUpdateCounter % 5 == 0))
  347. {
  348. FUpdateCounter = 0;
  349. }
  350. FUpdateCounter++;
  351. AData.CPSLimit = FCPSLimit;
  352. }
  353. //---------------------------------------------------------------------------
  354. void __fastcall TProgressForm::UpdateTimerTimer(TObject * /*Sender*/)
  355. {
  356. // popup the progress window at least here, if SetProgressData is
  357. // not being called (typically this happens when using custom command
  358. // that launches long-lasting external process, such as visual diff)
  359. ReceiveData(false, 0);
  360. if (UpdateTimer->Interval == DelayStartInterval)
  361. {
  362. UpdateTimer->Interval = static_cast<int>(GUIUpdateInterval);
  363. }
  364. if (FDataReceived)
  365. {
  366. FSinceLastUpdate += UpdateTimer->Interval;
  367. if (FSinceLastUpdate >= UpdateInterval)
  368. {
  369. UpdateControls();
  370. FSinceLastUpdate = 0;
  371. }
  372. }
  373. }
  374. //---------------------------------------------------------------------------
  375. void __fastcall TProgressForm::FormShow(TObject * /*Sender*/)
  376. {
  377. CopySpeedLimits(CustomWinConfiguration->History[L"SpeedLimit"], SpeedComboBoxItem->Strings);
  378. ReceiveData(false, 0);
  379. if (FDataReceived)
  380. {
  381. UpdateControls();
  382. }
  383. // HACK: In command-line run (/upload), FormShow gets called twice,
  384. // leading to duplicate hook and memory leak. Make sure we unhook, just in case.
  385. // Calling unhook without hooking first is noop.
  386. UnhookFormActivation(this);
  387. HookFormActivation(this);
  388. }
  389. //---------------------------------------------------------------------------
  390. void __fastcall TProgressForm::FormHide(TObject * /*Sender*/)
  391. {
  392. UnhookFormActivation(this);
  393. // This is to counter the "infinite" timestamp in
  394. // TTerminalManager::ApplicationShowHint.
  395. // Because if form disappears on its own, hint is not hidden.
  396. Application->CancelHint();
  397. CustomWinConfiguration->History[L"SpeedLimit"] = SpeedComboBoxItem->Strings;
  398. UpdateTimer->Enabled = false;
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TProgressForm::CancelItemClick(TObject * /*Sender*/)
  402. {
  403. CancelOperation();
  404. }
  405. //---------------------------------------------------------------------------
  406. void __fastcall TProgressForm::Minimize(TObject * Sender)
  407. {
  408. CallGlobalMinimizeHandler(Sender);
  409. }
  410. //---------------------------------------------------------------------------
  411. void __fastcall TProgressForm::MinimizeItemClick(TObject * Sender)
  412. {
  413. Minimize(Sender);
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TProgressForm::CancelOperation()
  417. {
  418. DebugAssert(FDataReceived);
  419. if (!FData.Suspended)
  420. {
  421. // mostly useless, as suspend is called over copy of actual progress data
  422. FData.Suspend();
  423. UpdateControls();
  424. try
  425. {
  426. TCancelStatus ACancel;
  427. if (FData.TransferingFile &&
  428. (FData.TimeExpected() > GUIConfiguration->IgnoreCancelBeforeFinish))
  429. {
  430. int Result = MessageDialog(LoadStr(CANCEL_OPERATION_FATAL2), qtWarning,
  431. qaYes | qaNo | qaCancel, HELP_PROGRESS_CANCEL);
  432. switch (Result)
  433. {
  434. case qaYes:
  435. ACancel = csCancelTransfer; break;
  436. case qaNo:
  437. ACancel = csCancel; break;
  438. default:
  439. ACancel = csContinue; break;
  440. }
  441. }
  442. else
  443. {
  444. ACancel = csCancel;
  445. }
  446. if (FCancel < ACancel)
  447. {
  448. FCancel = ACancel;
  449. UpdateControls();
  450. }
  451. }
  452. __finally
  453. {
  454. FData.Resume();
  455. }
  456. }
  457. }
  458. //---------------------------------------------------------------------------
  459. void __fastcall TProgressForm::GlobalMinimize(TObject * /*Sender*/)
  460. {
  461. ApplicationMinimize();
  462. FMinimizedByMe = true;
  463. }
  464. //---------------------------------------------------------------------------
  465. TTBCustomItem * __fastcall TProgressForm::CurrentOnceDoneItem()
  466. {
  467. TOnceDoneItems::const_iterator Iterator = FOnceDoneItems.begin();
  468. while (Iterator != FOnceDoneItems.end())
  469. {
  470. if (Iterator->second->Checked)
  471. {
  472. return Iterator->second;
  473. }
  474. Iterator++;
  475. }
  476. DebugFail();
  477. return NULL;
  478. }
  479. //---------------------------------------------------------------------------
  480. TOnceDoneOperation __fastcall TProgressForm::GetOnceDoneOperation()
  481. {
  482. return FOnceDoneItems.LookupFirst(CurrentOnceDoneItem());
  483. }
  484. //---------------------------------------------------------------------------
  485. void __fastcall TProgressForm::SetOnceDoneItem(TTBCustomItem * Item)
  486. {
  487. TTBCustomItem * Current = CurrentOnceDoneItem();
  488. if (Current != Item)
  489. {
  490. Current->Checked = false;
  491. Item->Checked = true;
  492. // Not until we have any data to update.
  493. // Happens when set to odoDisconnect in command-line upload/download
  494. // mode from TCustomScpExplorerForm::FileOperationProgress.
  495. if (FDataGot)
  496. {
  497. UpdateControls();
  498. }
  499. }
  500. }
  501. //---------------------------------------------------------------------------
  502. void __fastcall TProgressForm::SetOnceDoneOperation(TOnceDoneOperation value)
  503. {
  504. SetOnceDoneItem(FOnceDoneItems.LookupSecond(value));
  505. }
  506. //---------------------------------------------------------------------------
  507. bool __fastcall TProgressForm::GetAllowMinimize()
  508. {
  509. return MinimizeItem->Visible;
  510. }
  511. //---------------------------------------------------------------------------
  512. void __fastcall TProgressForm::SetAllowMinimize(bool value)
  513. {
  514. MinimizeItem->Visible = value;
  515. }
  516. //---------------------------------------------------------------------------
  517. void __fastcall TProgressForm::SetReadOnly(bool value)
  518. {
  519. if (FReadOnly != value)
  520. {
  521. FReadOnly = value;
  522. if (!value)
  523. {
  524. ResetOnceDoneOperation();
  525. }
  526. UpdateControls();
  527. }
  528. }
  529. //---------------------------------------------------------------------------
  530. void __fastcall TProgressForm::ResetOnceDoneOperation()
  531. {
  532. SetOnceDoneOperation(odoIdle);
  533. }
  534. //---------------------------------------------------------------------------
  535. void __fastcall TProgressForm::Dispatch(void * AMessage)
  536. {
  537. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  538. if (Message.Msg == WM_CLOSE)
  539. {
  540. CancelOperation();
  541. }
  542. else
  543. {
  544. TForm::Dispatch(AMessage);
  545. }
  546. }
  547. //---------------------------------------------------------------------------
  548. void __fastcall TProgressForm::MoveToQueueItemClick(TObject * /*Sender*/)
  549. {
  550. FMoveToQueue = true;
  551. UpdateControls();
  552. }
  553. //---------------------------------------------------------------------------
  554. void __fastcall TProgressForm::OnceDoneItemClick(TObject * Sender)
  555. {
  556. SetOnceDoneItem(dynamic_cast<TTBCustomItem *>(Sender));
  557. }
  558. //---------------------------------------------------------------------------
  559. void __fastcall TProgressForm::CycleOnceDoneItemClick(TObject * /*Sender*/)
  560. {
  561. TTBCustomItem * Item = CurrentOnceDoneItem();
  562. int Index = Item->Parent->IndexOf(Item);
  563. DebugAssert(Index >= 0);
  564. if (Index < Item->Parent->Count - 1)
  565. {
  566. Index++;
  567. }
  568. else
  569. {
  570. Index = 0;
  571. }
  572. SetOnceDoneItem(Item->Parent->Items[Index]);
  573. }
  574. //---------------------------------------------------------------------------
  575. UnicodeString __fastcall TProgressForm::ItemSpeed(const UnicodeString & Text,
  576. TTBXComboBoxItem * Item)
  577. {
  578. // Keep in sync with TNonVisualDataModule::QueueItemSpeed
  579. FCPSLimit = GetSpeedLimit(Text);
  580. UnicodeString Result = SetSpeedLimit(FCPSLimit);
  581. SaveToHistory(Item->Strings, Result);
  582. CustomWinConfiguration->History[L"SpeedLimit"] = Item->Strings;
  583. return Result;
  584. }
  585. //---------------------------------------------------------------------------
  586. void __fastcall TProgressForm::SpeedComboBoxItemAcceptText(TObject * Sender,
  587. UnicodeString & NewText, bool & /*Accept*/)
  588. {
  589. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  590. NewText = ItemSpeed(NewText, Item);
  591. }
  592. //---------------------------------------------------------------------------
  593. void __fastcall TProgressForm::SpeedComboBoxItemItemClick(TObject * Sender)
  594. {
  595. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  596. Item->Text = ItemSpeed(Item->Text, Item);
  597. }
  598. //---------------------------------------------------------------------------
  599. void __fastcall TProgressForm::SpeedComboBoxItemAdjustImageIndex(
  600. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int /*AIndex*/, int & ImageIndex)
  601. {
  602. // Use fixed image (do not change image by item index)
  603. ImageIndex = Sender->ImageIndex;
  604. }
  605. //---------------------------------------------------------------------------
  606. void __fastcall TProgressForm::FormKeyDown(
  607. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  608. {
  609. // We do not have Cancel button, so we have to handle Esc key explicitly
  610. if (Key == VK_ESCAPE)
  611. {
  612. CancelOperation();
  613. Key = 0;
  614. }
  615. }
  616. //---------------------------------------------------------------------------