home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / SRC / PROGRESS.PAS < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  4KB  |  147 lines

  1. {**************************************************************************}
  2. {                                                                          }
  3. {    Calmira shell for Microsoft« Windows(TM) 3.1                          }
  4. {    Source Release 1.0                                                    }
  5. {    Copyright (C) 1997  Li-Hsin Huang                                     }
  6. {                                                                          }
  7. {    This program is free software; you can redistribute it and/or modify  }
  8. {    it under the terms of the GNU General Public License as published by  }
  9. {    the Free Software Foundation; either version 2 of the License, or     }
  10. {    (at your option) any later version.                                   }
  11. {                                                                          }
  12. {    This program is distributed in the hope that it will be useful,       }
  13. {    but WITHOUT ANY WARRANTY; without even the implied warranty of        }
  14. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         }
  15. {    GNU General Public License for more details.                          }
  16. {                                                                          }
  17. {    You should have received a copy of the GNU General Public License     }
  18. {    along with this program; if not, write to the Free Software           }
  19. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             }
  20. {                                                                          }
  21. {**************************************************************************}
  22.  
  23. unit Progress;
  24.  
  25. interface
  26.  
  27. uses
  28.   SysUtils, Classes, Controls, Forms, StdCtrls, Buttons, ExtCtrls, BarGauge;
  29.  
  30. type
  31.   TFileOperation = (foCopy, foMove, foDelete);
  32.  
  33.   TProgressBox = class(TForm)
  34.     FileLabel: TLabel;
  35.     PercentLabel: TLabel;
  36.     CancelBtn: TBitBtn;
  37.     FromText: TLabel;
  38.     FromLabel: TLabel;
  39.     ToText: TLabel;
  40.     ToLabel: TLabel;
  41.     Gauge: TBarGauge;
  42.     procedure CancelBtnClick(Sender: TObject);
  43.     procedure FormShow(Sender: TObject);
  44.     procedure FormHide(Sender: TObject);
  45.   private
  46.     { Private declarations }
  47.     FAbortOp : Boolean;
  48.   public
  49.     { Public declarations }
  50.     property AbortOp : Boolean read FAbortOp;
  51.     procedure UpdateGauge;
  52.     procedure UpdateLabel(const source, dest : TFilename);
  53.     procedure Init(Op : TFileOperation; ACount: Integer);
  54.     procedure CheckForAbort;
  55.   end;
  56.  
  57.   const FileOpMessages : array[TFileOperation] of string[11] =
  58.     ('Copying...', 'Moving...', 'Deleting');
  59.  
  60. var
  61.   ProgressBox: TProgressBox;
  62.  
  63. implementation
  64.  
  65. {$R *.DFM}
  66.  
  67. uses FileCtrl, Settings, Strings, Desk, Replace;
  68.  
  69. procedure TProgressBox.UpdateGauge;
  70. begin
  71.   Gauge.AddProgress(1);
  72. end;
  73.  
  74.  
  75. procedure TProgressBox.UpdateLabel(const source, dest: TFilename);
  76. begin
  77.   FileLabel.Caption := Uppercase(ExtractFilename(source));
  78.  
  79.   with FromLabel do
  80.     Caption := MinimizeName(Uppercase(ExtractFileDir(source)), Canvas, Width);
  81.  
  82.   with ToLabel do
  83.     Caption := MinimizeName(Uppercase(ExtractFileDir(dest)), Canvas, Width);
  84.  
  85.   FromLabel.Update;
  86.   ToLabel.Update;
  87. end;
  88.  
  89.  
  90. procedure TProgressBox.Init(Op : TFileOperation; ACount: Integer);
  91. var i: Integer;
  92. begin
  93.   if Op in [foCopy, foMove] then begin
  94.     FileLabel.Caption := '';
  95.     FromText.Show;
  96.     ToText.Show;
  97.     FromLabel.Caption := '';  FromLabel.Show;
  98.     ToLabel.Caption := '';    ToLabel.Show;
  99.   end
  100.   else begin
  101.     FileLabel.Caption := 'Please wait...';
  102.     FromText.Hide;
  103.     FromLabel.Hide;
  104.     ToText.Hide;
  105.     ToLabel.Hide;
  106.   end;
  107.  
  108.   Caption := FileOpMessages[Op];
  109.  
  110.   FAbortOp := False;
  111.   Gauge.Progress := 0;
  112.   Gauge.MaxValue := ACount;
  113.   Show;
  114.   Update;
  115. end;
  116.  
  117.  
  118. procedure TProgressBox.CancelBtnClick(Sender: TObject);
  119. begin
  120.   FAbortOp := True;
  121. end;
  122.  
  123.  
  124. procedure TProgressBox.FormShow(Sender: TObject);
  125. begin
  126.   Gauge.ForeColor := Colors[ccPercent];
  127.   Gauge.Font.Color := Colors[ccPercentText];
  128.   Desktop.EnableForms(False);
  129. end;
  130.  
  131. procedure TProgressBox.FormHide(Sender: TObject);
  132. begin
  133.   FAbortOp := False;
  134.   Desktop.EnableForms(True);
  135.   ReplaceBox.Free;
  136.   ReplaceBox := nil;
  137. end;
  138.  
  139. procedure TProgressBox.CheckForAbort;
  140. begin
  141.   Application.ProcessMessages;
  142.   if FAbortOp then Abort;
  143. end;
  144.  
  145.  
  146. end.
  147.