Progress.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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) && DebugAlwaysTrue(!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 && DebugAlwaysTrue(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. // HACK: In command-line run (/upload), FormShow gets called twice,
  396. // leading to duplicate hook and memory leak. Make sure we unhook, just in case.
  397. // Calling unhook without hooking first is noop.
  398. UnhookFormActivation(this);
  399. HookFormActivation(this);
  400. }
  401. //---------------------------------------------------------------------------
  402. void __fastcall TProgressForm::FormHide(TObject * /*Sender*/)
  403. {
  404. UnhookFormActivation(this);
  405. // This is to counter the "infinite" timestamp in
  406. // TTerminalManager::ApplicationShowHint.
  407. // Because if form disappears on its own, hint is not hidden.
  408. Application->CancelHint();
  409. CustomWinConfiguration->History[L"SpeedLimit"] = SpeedComboBoxItem->Strings;
  410. UpdateTimer->Enabled = false;
  411. }
  412. //---------------------------------------------------------------------------
  413. void __fastcall TProgressForm::CancelItemClick(TObject * /*Sender*/)
  414. {
  415. CancelOperation();
  416. }
  417. //---------------------------------------------------------------------------
  418. void __fastcall TProgressForm::Minimize(TObject * Sender)
  419. {
  420. CallGlobalMinimizeHandler(Sender);
  421. }
  422. //---------------------------------------------------------------------------
  423. void __fastcall TProgressForm::MinimizeItemClick(TObject * Sender)
  424. {
  425. Minimize(Sender);
  426. }
  427. //---------------------------------------------------------------------------
  428. void __fastcall TProgressForm::CancelOperation()
  429. {
  430. DebugAssert(FDataReceived);
  431. if (!FData.Suspended)
  432. {
  433. // mostly useless, as suspend is called over copy of actual progress data
  434. FData.Suspend();
  435. UpdateControls();
  436. try
  437. {
  438. TCancelStatus ACancel;
  439. if (FData.TransferingFile &&
  440. (FData.TimeExpected() > GUIConfiguration->IgnoreCancelBeforeFinish))
  441. {
  442. int Result = MessageDialog(LoadStr(CANCEL_OPERATION_FATAL2), qtWarning,
  443. qaYes | qaNo | qaCancel, HELP_PROGRESS_CANCEL);
  444. switch (Result)
  445. {
  446. case qaYes:
  447. ACancel = csCancelTransfer; break;
  448. case qaNo:
  449. ACancel = csCancel; break;
  450. default:
  451. ACancel = csContinue; break;
  452. }
  453. }
  454. else
  455. {
  456. ACancel = csCancel;
  457. }
  458. if (FCancel < ACancel)
  459. {
  460. FCancel = ACancel;
  461. UpdateControls();
  462. }
  463. }
  464. __finally
  465. {
  466. FData.Resume();
  467. }
  468. }
  469. }
  470. //---------------------------------------------------------------------------
  471. void __fastcall TProgressForm::GlobalMinimize(TObject * /*Sender*/)
  472. {
  473. ApplicationMinimize();
  474. FMinimizedByMe = true;
  475. }
  476. //---------------------------------------------------------------------------
  477. TTBCustomItem * __fastcall TProgressForm::CurrentOnceDoneItem()
  478. {
  479. TOnceDoneItems::const_iterator Iterator = FOnceDoneItems.begin();
  480. while (Iterator != FOnceDoneItems.end())
  481. {
  482. if (Iterator->second->Checked)
  483. {
  484. return Iterator->second;
  485. }
  486. Iterator++;
  487. }
  488. DebugFail();
  489. return NULL;
  490. }
  491. //---------------------------------------------------------------------------
  492. TOnceDoneOperation __fastcall TProgressForm::GetOnceDoneOperation()
  493. {
  494. return FOnceDoneItems.LookupFirst(CurrentOnceDoneItem());
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TProgressForm::SetOnceDoneItem(TTBCustomItem * Item)
  498. {
  499. TTBCustomItem * Current = CurrentOnceDoneItem();
  500. if (Current != Item)
  501. {
  502. Current->Checked = false;
  503. Item->Checked = true;
  504. // Not until we have any data to update.
  505. // Happens when set to odoDisconnect in command-line upload/download
  506. // mode from TCustomScpExplorerForm::FileOperationProgress.
  507. if (FDataGot)
  508. {
  509. UpdateControls();
  510. }
  511. }
  512. }
  513. //---------------------------------------------------------------------------
  514. void __fastcall TProgressForm::SetOnceDoneOperation(TOnceDoneOperation value)
  515. {
  516. SetOnceDoneItem(FOnceDoneItems.LookupSecond(value));
  517. }
  518. //---------------------------------------------------------------------------
  519. bool __fastcall TProgressForm::GetAllowMinimize()
  520. {
  521. return MinimizeItem->Visible;
  522. }
  523. //---------------------------------------------------------------------------
  524. void __fastcall TProgressForm::SetAllowMinimize(bool value)
  525. {
  526. MinimizeItem->Visible = value;
  527. }
  528. //---------------------------------------------------------------------------
  529. void __fastcall TProgressForm::SetReadOnly(bool value)
  530. {
  531. if (FReadOnly != value)
  532. {
  533. FReadOnly = value;
  534. if (!value)
  535. {
  536. ResetOnceDoneOperation();
  537. }
  538. UpdateControls();
  539. }
  540. }
  541. //---------------------------------------------------------------------------
  542. void __fastcall TProgressForm::ResetOnceDoneOperation()
  543. {
  544. SetOnceDoneOperation(odoIdle);
  545. }
  546. //---------------------------------------------------------------------------
  547. void __fastcall TProgressForm::Dispatch(void * AMessage)
  548. {
  549. TMessage & Message = *reinterpret_cast<TMessage *>(AMessage);
  550. if (Message.Msg == WM_CLOSE)
  551. {
  552. CancelOperation();
  553. }
  554. else
  555. {
  556. TForm::Dispatch(AMessage);
  557. }
  558. }
  559. //---------------------------------------------------------------------------
  560. void __fastcall TProgressForm::MoveToQueueItemClick(TObject * /*Sender*/)
  561. {
  562. FMoveToQueue = true;
  563. UpdateControls();
  564. }
  565. //---------------------------------------------------------------------------
  566. void __fastcall TProgressForm::OnceDoneItemClick(TObject * Sender)
  567. {
  568. SetOnceDoneItem(dynamic_cast<TTBCustomItem *>(Sender));
  569. }
  570. //---------------------------------------------------------------------------
  571. void __fastcall TProgressForm::CycleOnceDoneItemClick(TObject * /*Sender*/)
  572. {
  573. TTBCustomItem * Item = CurrentOnceDoneItem();
  574. int Index = Item->Parent->IndexOf(Item);
  575. DebugAssert(Index >= 0);
  576. if (Index < Item->Parent->Count - 1)
  577. {
  578. Index++;
  579. }
  580. else
  581. {
  582. Index = 0;
  583. }
  584. SetOnceDoneItem(Item->Parent->Items[Index]);
  585. }
  586. //---------------------------------------------------------------------------
  587. UnicodeString __fastcall TProgressForm::ItemSpeed(const UnicodeString & Text,
  588. TTBXComboBoxItem * Item)
  589. {
  590. // Keep in sync with TNonVisualDataModule::QueueItemSpeed
  591. FCPSLimit = GetSpeedLimit(Text);
  592. UnicodeString Result = SetSpeedLimit(FCPSLimit);
  593. SaveToHistory(Item->Strings, Result);
  594. CustomWinConfiguration->History[L"SpeedLimit"] = Item->Strings;
  595. return Result;
  596. }
  597. //---------------------------------------------------------------------------
  598. void __fastcall TProgressForm::SpeedComboBoxItemAcceptText(TObject * Sender,
  599. UnicodeString & NewText, bool & /*Accept*/)
  600. {
  601. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  602. NewText = ItemSpeed(NewText, Item);
  603. }
  604. //---------------------------------------------------------------------------
  605. void __fastcall TProgressForm::SpeedComboBoxItemItemClick(TObject * Sender)
  606. {
  607. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  608. Item->Text = ItemSpeed(Item->Text, Item);
  609. }
  610. //---------------------------------------------------------------------------
  611. void __fastcall TProgressForm::SpeedComboBoxItemAdjustImageIndex(
  612. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int /*AIndex*/, int & ImageIndex)
  613. {
  614. // Use fixed image (do not change image by item index)
  615. ImageIndex = Sender->ImageIndex;
  616. }
  617. //---------------------------------------------------------------------------
  618. void __fastcall TProgressForm::FormKeyDown(
  619. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  620. {
  621. // We do not have Cancel button, so we have to handle Esc key explicitly
  622. if (Key == VK_ESCAPE)
  623. {
  624. CancelOperation();
  625. Key = 0;
  626. }
  627. }
  628. //---------------------------------------------------------------------------