From: <ah...@us...> - 2009-01-07 18:11:48
|
Revision: 12134 http://jvcl.svn.sourceforge.net/jvcl/?rev=12134&view=rev Author: ahuser Date: 2009-01-07 18:11:38 +0000 (Wed, 07 Jan 2009) Log Message: ----------- Improved ProgressBar Dialog functionality - new public property Form: TForm that is valid in OnShow - ScreenPosition now defaults to ScreenCenter instead of DesktopCenter that could be between two monitors. Modified Paths: -------------- trunk/jvcl/run/JvProgressDialog.pas trunk/jvcl/run/JvProgressForm.dfm trunk/jvcl/run/JvProgressForm.pas Modified: trunk/jvcl/run/JvProgressDialog.pas =================================================================== --- trunk/jvcl/run/JvProgressDialog.pas 2009-01-07 15:33:53 UTC (rev 12133) +++ trunk/jvcl/run/JvProgressDialog.pas 2009-01-07 18:11:38 UTC (rev 12134) @@ -59,7 +59,7 @@ auto-adjusts to it's size but you should keep them fairly small (say, less than 160x100 something) as large images doesn't look too good (IMO) Transparent - set to true if Image should be rendered transparently (this value cannot be changed in OnProgress) -ScreenPosition - Position of the dialog form (initially set to poDesktopCenter), added 28/05/2004, RK +ScreenPosition - Position of the dialog form (is now initially set to poScreenCenter), added 07/01/2009 Events: OnProgress: TJvProgressDialogEvent = procedure(Sender: TObject; var AContinue: Boolean) of object; @@ -154,6 +154,7 @@ procedure Hide; // set most values at once property Cancelled: Boolean read FCancelled; + property Form: TForm read FForm; published property Caption: string read FCaption write SetCaption; property Image: TPicture read FImage write SetPicture; @@ -165,7 +166,7 @@ property Smooth: Boolean read FSmooth write FSmooth default False; property Text: string read FText write SetText; property Transparent: Boolean read FTransparent write FTransparent default False; - property ScreenPosition: TPosition read FScreenPosition write FScreenPosition; // added 28/05/2004, RK + property ScreenPosition: TPosition read FScreenPosition write FScreenPosition default poScreenCenter; property OnCancel: TNotifyEvent read FOnCancel write FOnCancel; property OnClose: TNotifyEvent read FOnClose write FOnClose; property OnProgress: TJvProgressDialogEvent read FOnProgress write FOnProgress; @@ -198,12 +199,11 @@ FInterval := 200; FTransparent := False; FShowCancel := True; - FScreenPosition := poDesktopCenter; // added 28/05/2004, RK + FScreenPosition := poScreenCenter; end; destructor TJvProgressDialog.Destroy; begin - // Hide; if Assigned(FForm) then FForm.Close; // OnClose sets CloseAction:=caFree and FForm = nil FreeAndNil(FImage); @@ -274,19 +274,23 @@ Result := mrCancel; FCancelled := False; FreeAndNil(FForm); - DoShow; - StoreValues; + FForm := TfrmProgress.Create(nil); try -// asn: commented out 24-06-2004, -// you cannot assign to a nil fform -// FForm.Position := FScreenPosition; // added 28/05/2004, RK -// - if TfrmProgress.Execute(TfrmProgress(FForm), Caption, Text, Image, Transparent, Min, Max, Position, Interval, - ShowCancel or (csDesigning in ComponentState), Smooth, InternalDoProgress, InternalDoCancel) then - Result := mrOK; + FForm.Position := FScreenPosition; + TfrmProgress(FForm).Init(Caption, Text, Image, Transparent, Min, Max, Position, Interval, + ShowCancel or (csDesigning in ComponentState), Smooth, InternalDoProgress, InternalDoCancel); + + DoShow; + StoreValues; + try + if FForm.ShowModal <> mrCancel then + Result := mrOK; + finally + RestoreValues; + DoClose; + end; finally - RestoreValues; - DoClose; + FreeAndNil(FForm); end; end; @@ -306,13 +310,13 @@ FForm.Release; FForm := nil; end; - FForm := TfrmProgress.Create(Application); + FForm := TfrmProgress.Create(nil); FForm.OnClose := InternalDoClose; - FForm.Position := FScreenPosition; // added 28/05/2004, RK + FForm.Position := FScreenPosition; FCancelled := False; DoShow; StoreValues; - TfrmProgress.Execute(TfrmProgress(FForm), Caption, Text, Image, Transparent, Min, Max, Position, + TfrmProgress(FForm).Init(Caption, Text, Image, Transparent, Min, Max, Position, Interval, ShowCancel, Smooth, InternalDoProgress, InternalDoCancel); end; @@ -389,7 +393,7 @@ begin if FForm <> nil then begin - TfrmProgress(FForm).Label1.Caption := Value; + TfrmProgress(FForm).lblStatus.Caption := Value; TfrmProgress(FForm).Update; end; FText := Value; Modified: trunk/jvcl/run/JvProgressForm.dfm =================================================================== --- trunk/jvcl/run/JvProgressForm.dfm 2009-01-07 15:33:53 UTC (rev 12133) +++ trunk/jvcl/run/JvProgressForm.dfm 2009-01-07 18:11:38 UTC (rev 12134) @@ -27,7 +27,7 @@ IncrementalDisplay = True Visible = False end - object Label1: TLabel + object lblStatus: TLabel Left = 16 Top = 70 Width = 26 Modified: trunk/jvcl/run/JvProgressForm.pas =================================================================== --- trunk/jvcl/run/JvProgressForm.pas 2009-01-07 15:33:53 UTC (rev 12133) +++ trunk/jvcl/run/JvProgressForm.pas 2009-01-07 18:11:38 UTC (rev 12134) @@ -49,7 +49,7 @@ TfrmProgress = class(TJvForm) pbProgress: TProgressBar; imProgress: TImage; - Label1: TLabel; + lblStatus: TLabel; btnCancel: TButton; tmProgress: TTimer; ActionList1: TActionList; @@ -68,12 +68,30 @@ procedure RemoveCaption; procedure AddCaption; public + class function Execute(const ACaption, ALabel: string; + AImage: TPicture = nil; ATransparent: Boolean = False; + AMin: Integer = 0; AMax: Integer = 100; APosition: Integer = 0; + AInterval: Integer = 200; ShowCancel: Boolean = False; Smooth: Boolean = False; + AOnProgress: TJvPrivateProgressUpdate = nil; + AOnCancel: TNotifyEvent = nil): Boolean; overload; + class function Execute(Frm: TfrmProgress; const ACaption, ALabel: string; AImage: TPicture = nil; ATransparent: Boolean = False; AMin: Integer = 0; AMax: Integer = 100; APosition: Integer = 0; AInterval: Integer = 200; ShowCancel: Boolean = False; Smooth: Boolean = False; AOnProgress: TJvPrivateProgressUpdate = nil; - AOnCancel: TNotifyEvent = nil): Boolean; + AOnCancel: TNotifyEvent = nil): Boolean; overload; + {$IFDEF SUPPORTS_DEPRECATED} + deprecated {$IFDEF SUPPORTS_DEPRECATED_DETAILS}'Use Execute(ACaption...) instead'{$ENDIF}; + {$ENDIF SUPPORTS_DEPRECATED} + + procedure Init(const ACaption, ALabel: string; + AImage: TPicture = nil; ATransparent: Boolean = False; + AMin: Integer = 0; AMax: Integer = 100; APosition: Integer = 0; + AInterval: Integer = 200; ShowCancel: Boolean = False; Smooth: Boolean = False; + AOnProgress: TJvPrivateProgressUpdate = nil; + AOnCancel: TNotifyEvent = nil); + function ShowModal: Integer; override; end; @@ -94,6 +112,22 @@ {$R *.dfm} +class function TfrmProgress.Execute(const ACaption, ALabel: string; + AImage: TPicture; ATransparent: Boolean; AMin, AMax, APosition, AInterval: Integer; + ShowCancel, Smooth: Boolean; AOnProgress: TJvPrivateProgressUpdate; AOnCancel: TNotifyEvent): Boolean; +var + Frm: TfrmProgress; +begin + Frm := Self.Create(nil); + try + Frm.Init(ACaption, ALabel, AImage, ATransparent, AMin, AMax, APosition, AInterval, + ShowCancel, Smooth, AOnProgress, AOnCancel); + Result := Frm.ShowModal <> mrCancel + finally + Frm.Free; + end; +end; + class function TfrmProgress.Execute(Frm: TfrmProgress; const ACaption, ALabel: string; AImage: TPicture; ATransparent: Boolean; AMin, AMax, APosition, AInterval: Integer; ShowCancel, Smooth: Boolean; AOnProgress: TJvPrivateProgressUpdate; AOnCancel: TNotifyEvent): Boolean; @@ -102,31 +136,15 @@ begin if Frm = nil then begin - Frm := Self.Create(Application); + Frm := Self.Create(nil); DoModal := True; end else DoModal := False; try - with Frm do - begin - Caption := ACaption; - Label1.Caption := ALabel; - pbProgress.Min := AMin; - pbProgress.Max := AMax; - pbProgress.Position := APosition; - pbProgress.Smooth := Smooth; - FOnProgress := AOnProgress; - imProgress.Picture := AImage; - imProgress.Transparent := ATransparent; - tmProgress.Interval := AInterval; - tmProgress.Enabled := AInterval > 0; - btnCancel.Visible := ShowCancel; - FCanClose := ShowCancel; - btnCancel.Caption := SCancelButton; - FOnCancel := AOnCancel; - AdjustComponents; - end; + Frm.Init(ACaption, ALabel, AImage, ATransparent, AMin, AMax, APosition, AInterval, + ShowCancel, Smooth, AOnProgress, AOnCancel); + if DoModal then Result := Frm.ShowModal <> mrCancel else @@ -136,10 +154,32 @@ end; finally if DoModal then - FreeAndNil(Frm); + Frm.Free; end; end; +procedure TfrmProgress.Init(const ACaption, ALabel: string; + AImage: TPicture; ATransparent: Boolean; AMin, AMax, APosition, AInterval: Integer; + ShowCancel, Smooth: Boolean; AOnProgress: TJvPrivateProgressUpdate; AOnCancel: TNotifyEvent); +begin + Caption := ACaption; + lblStatus.Caption := ALabel; + pbProgress.Min := AMin; + pbProgress.Max := AMax; + pbProgress.Position := APosition; + pbProgress.Smooth := Smooth; + FOnProgress := AOnProgress; + imProgress.Picture := AImage; + imProgress.Transparent := ATransparent; + tmProgress.Interval := AInterval; + tmProgress.Enabled := AInterval > 0; + btnCancel.Visible := ShowCancel; + FCanClose := ShowCancel; + btnCancel.Caption := SCancelButton; + FOnCancel := AOnCancel; + AdjustComponents; +end; + function TfrmProgress.DoProgress: Boolean; var AMin, AMax, APosition, AInterval: Integer; @@ -157,7 +197,7 @@ APosition := pbProgress.Position; AInterval := tmProgress.Interval; ACaption := Caption; - ALabel := Label1.Caption; + ALabel := lblStatus.Caption; FOnProgress(Self, AMin, AMax, APosition, AInterval, ACaption, ALabel, imProgress.Picture, Result); pbProgress.Min := AMin; pbProgress.Max := AMax; @@ -165,7 +205,7 @@ tmProgress.Interval := AInterval; tmProgress.Enabled := AInterval > 0; Caption := ACaption; - Label1.Caption := ALabel; + lblStatus.Caption := ALabel; AdjustComponents; Update; end; @@ -176,8 +216,6 @@ end; end; - - procedure TfrmProgress.AddCaption; var WindowLong: Cardinal; @@ -211,9 +249,10 @@ function TfrmProgress.ShowModal: Integer; begin // (p3) put topmost but only if not debugging - {$IFNDEF DEBUGINFO_ON} - SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); - {$ENDIF !DEBUGINFO_ON} + {$WARNINGS OFF} + if DebugHook = 0 then + {$WARNINGS ON} + SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE); if not tmProgress.Enabled then DoProgress; // call at least once Result := inherited ShowModal; @@ -221,9 +260,7 @@ procedure TfrmProgress.tmProgressTimer(Sender: TObject); begin - if FCancelled then - Exit; - if not DoProgress or not tmProgress.Enabled then + if not FCancelled and not DoProgress or not tmProgress.Enabled then begin ModalResult := mrOk; Close; @@ -253,8 +290,8 @@ if ClientWidth - imProgress.Left * 2 < imProgress.Width then ClientWidth := imProgress.Width + imProgress.Left * 2; end; - Label1.Top := Offset; - Offset := Label1.Top + Label1.Height + 8; + lblStatus.Top := Offset; + Offset := lblStatus.Top + lblStatus.Height + 8; pbProgress.Top := Offset; Offset := pbProgress.Top + pbProgress.Height + 16; if btnCancel.Visible then This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |