📄 jvqdesktopalert.pas
字号:
procedure FinalizeEndAnimation; override;
public
constructor Create(OwnerForm: TJvFormDesktopAlert); override;
procedure AbortAnimation; override;
published
property StartInterval default 25;
property StartSteps default 10;
property EndInterval default 50;
property EndSteps default 10;
property DisplayDuration default 1400;
property MinGrowthPercentage: Double read FMinGrowthPercentage write SetMinGrowthPercentage;
property MaxGrowthPercentage: Double read FMaxGrowthPercentage write SetMaxGrowthPercentage;
end;
function CreateHandlerForStyle(Style: TJvAlertStyle; OwnerForm: TJvFormDesktopAlert): TJvCustomDesktopAlertStyleHandler;
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
SysUtils,
JvQJVCLUtils, JvQTypes;
var
FGlobalStacker: TJvDesktopAlertStack = nil;
function CreateHandlerForStyle(Style: TJvAlertStyle; OwnerForm: TJvFormDesktopAlert): TJvCustomDesktopAlertStyleHandler;
begin
case Style of
asFade:
Result := TJvFadeAlertStyleHandler.Create(OwnerForm);
asCenterGrow:
Result := TJvCenterGrowAlertStyleHandler.Create(OwnerForm);
else
raise Exception.Create('');
end;
end;
function GlobalStacker: TJvDesktopAlertStack;
begin
if FGlobalStacker = nil then
FGlobalStacker := TJvDesktopAlertStack.Create(nil);
Result := FGlobalStacker;
end;
//=== { TJvDesktopAlertChangePersistent } ====================================
procedure TJvDesktopAlertChangePersistent.Change;
begin
if Assigned(FOnChange) then
FOnChange(Self);
end;
//=== { TJvDesktopAlertColors } ==============================================
constructor TJvDesktopAlertColors.Create;
begin
inherited Create;
FFrame := JvDefaultFrameColor;
FWindowFrom := JvDefaultWindowFromColor;
FWindowTo := JvDefaultWindowToColor;
FCaptionFrom := JvDefaultCaptionFromColor;
FCaptionTo := JvDefaultCaptionToColor;
end;
procedure TJvDesktopAlertColors.Assign(Source: TPersistent);
begin
if Source is TJvDesktopAlertColors then
begin
if Source <> Self then
begin
FFrame := TJvDesktopAlertColors(Source).Frame;
FWindowFrom := TJvDesktopAlertColors(Source).WindowFrom;
FWindowTo := TJvDesktopAlertColors(Source).WindowTo;
FCaptionFrom := TJvDesktopAlertColors(Source).CaptionFrom;
FCaptionTo := TJvDesktopAlertColors(Source).CaptionTo;
Change;
end;
end
else
inherited Assign(Source);
end;
procedure TJvDesktopAlertColors.SetCaptionFrom(const Value: TColor);
begin
if FCaptionFrom <> Value then
begin
FCaptionFrom := Value;
Change;
end;
end;
procedure TJvDesktopAlertColors.SetCaptionTo(const Value: TColor);
begin
if FCaptionTo <> Value then
begin
FCaptionTo := Value;
Change;
end;
end;
procedure TJvDesktopAlertColors.SetFrame(const Value: TColor);
begin
if FFrame <> Value then
begin
FFrame := Value;
Change;
end;
end;
procedure TJvDesktopAlertColors.SetWindowFrom(const Value: TColor);
begin
if FWindowFrom <> Value then
begin
FWindowFrom := Value;
Change;
end;
end;
procedure TJvDesktopAlertColors.SetWindowTo(const Value: TColor);
begin
if FWindowTo <> Value then
begin
FWindowTo := Value;
Change;
end;
end;
//=== { TJvDesktopAlertLocation } ============================================
constructor TJvDesktopAlertLocation.Create;
begin
inherited Create;
FPosition := dapBottomRight;
FAlwaysResetPosition := True;
end;
procedure TJvDesktopAlertLocation.SetHeight(const Value: Integer);
begin
if FHeight <> Value then
begin
FHeight := Value;
Change;
end;
end;
procedure TJvDesktopAlertLocation.SetLeft(const Value: Integer);
begin
if FLeft <> Value then
begin
FLeft := Value;
Change;
end;
end;
procedure TJvDesktopAlertLocation.SetPosition(const Value: TJvDesktopAlertPosition);
begin
// if FPosition <> Value then
begin
FPosition := Value;
Change;
end;
end;
procedure TJvDesktopAlertLocation.SetTop(const Value: Integer);
begin
if FTop <> Value then
begin
FTop := Value;
Change;
end;
end;
procedure TJvDesktopAlertLocation.SetWidth(const Value: Integer);
begin
if FWidth <> Value then
begin
FWidth := Value;
Change;
end;
end;
//=== { TJvDesktopAlertButtonItem } ==========================================
procedure TJvDesktopAlertButtonItem.Assign(Source: TPersistent);
begin
if Source is TJvDesktopAlertButtonItem then
begin
if Source <> Self then
begin
ImageIndex := TJvDesktopAlertButtonItem(Source).ImageIndex;
OnClick := TJvDesktopAlertButtonItem(Source).OnClick;
Tag := TJvDesktopAlertButtonItem(Source).Tag;
end;
end
else
inherited Assign(Source);
end;
//=== { TJvDesktopAlertButtons } =============================================
constructor TJvDesktopAlertButtons.Create(AOwner: TPersistent);
begin
inherited Create(AOwner, TJvDesktopAlertButtonItem);
end;
function TJvDesktopAlertButtons.Add: TJvDesktopAlertButtonItem;
begin
Result := TJvDesktopAlertButtonItem(inherited Add);
end;
procedure TJvDesktopAlertButtons.Assign(Source: TPersistent);
var
I: Integer;
begin
if Source is TJvDesktopAlertButtons then
begin
if Source <> Self then
begin
Clear;
for I := 0 to TJvDesktopAlertButtons(Source).Count - 1 do
Add.Assign(TJvDesktopAlertButtons(Source)[I]);
end;
end
else
inherited Assign(Source);
end;
function TJvDesktopAlertButtons.GetItem(Index: Integer): TJvDesktopAlertButtonItem;
begin
Result := TJvDesktopAlertButtonItem(inherited Items[Index]);
end;
procedure TJvDesktopAlertButtons.SetItem(Index: Integer; const Value: TJvDesktopAlertButtonItem);
begin
inherited Items[Index] := Value;
end;
//=== { TJvDesktopAlert } ====================================================
constructor TJvDesktopAlert.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FColors := TJvDesktopAlertColors.Create;
FButtons := TJvDesktopAlertButtons.Create(Self);
FLocation := TJvDesktopAlertLocation.Create;
FLocation.OnChange := DoLocationChange;
FDesktopForm := TJvFormDesktopAlert.Create(Self);
AlertStyle := asFade;
FOptions := [daoCanClick..daoCanClose];
end;
destructor TJvDesktopAlert.Destroy;
begin
// when AutoFreeing, Delphi doesn't like the component having an owner, so remove the Owner here
if FAutoFree and (Owner <> nil) and not (csDesigning in ComponentState) then
Owner.RemoveComponent(Self);
if (FDesktopForm <> nil) then
begin
if FDesktopForm.Showing then
FDesktopForm.Close;
FDesktopForm.OnClose := nil;
GetStacker.Remove(FDesktopForm);
FDesktopForm.Release;
FDesktopForm := nil;
end;
FreeAndNil(FColors);
FreeAndNil(FButtons);
FreeAndNil(FLocation);
FreeAndNil(FStyleHandler);
inherited Destroy;
end;
procedure TJvDesktopAlert.Close(Immediate: Boolean);
begin
if Showing then
begin
if Immediate then
FDesktopForm.Close
else
FStyleHandler.DoEndAnimation;
end;
end;
procedure TJvDesktopAlert.DoLocationChange(Sender: TObject);
begin
if GetStacker.Position <> Location.Position then
begin
if GetStacker = FGlobalStacker then
GetStacker.Position := Location.Position
else
Location.Position := GetStacker.Position;
end;
end;
procedure TJvDesktopAlert.Execute;
var
ARect: TRect;
I, X, Y: Integer;
FActiveWindow, FActiveFocus: HWND;
procedure CenterForm(AForm: TForm; ARect: TRect);
begin
AForm.Top := ARect.Top + ((ARect.Bottom - ARect.Top) - AForm.Height) div 2;
AForm.Left := ARect.Left + ((ARect.Right - ARect.Left) - AForm.Width) div 2;
end;
begin
Assert(FDesktopForm <> nil);
if FDesktopForm.Visible then
FDesktopForm.Close;
ARect := ScreenWorkArea;
if Location.Width <> 0 then
FDesktopForm.Width := Location.Width
else
FDesktopForm.Width := cDefaultAlertFormWidth;
if Location.Height <> 0 then
FDesktopForm.Height := Location.Height
else
FDesktopForm.Height := cDefaultAlertFormHeight;
case Location.Position of
dapTopLeft:
begin
FDesktopForm.Top := ARect.Top;
FDesktopForm.Left := ARect.Left;
end;
dapTopRight:
begin
FDesktopForm.Top := ARect.Top;
FDesktopForm.Left := ARect.Right - FDesktopForm.Width;
end;
dapBottomLeft:
begin
FDesktopForm.Top := ARect.Bottom - FDesktopForm.Height;
FDesktopForm.Left := ARect.Left;
end;
dapBottomRight:
begin
FDesktopForm.Top := ARect.Bottom - FDesktopForm.Height;
FDesktopForm.Left := ARect.Right - FDesktopForm.Width;
end;
dapCustom:
begin
FDesktopForm.Top := Location.Top;
FDesktopForm.Left := Location.Left;
end;
dapDesktopCenter, dapMainFormCenter, dapOwnerFormCenter, dapActiveFormCenter:
begin
CenterForm(FDesktopForm, ARect);
if (Location.Position = dapActiveFormCenter) and (Screen.ActiveForm <> nil) then
CenterForm(FDesktopForm, Screen.ActiveForm.BoundsRect)
else
if (Location.Position = dapMainFormCenter) and (Application <> nil) and (Application.MainForm <> nil) then
CenterForm(FDesktopForm, Application.MainForm.BoundsRect)
else
if (Location.Position = dapOwnerFormCenter) and (Owner is TCustomForm) then
CenterForm(FDesktopForm, TCustomForm(Owner).BoundsRect);
end;
end;
FDesktopForm.OnShow := InternalOnShow;
FDesktopForm.OnClose := InternalOnClose;
FDesktopForm.OnMouseEnter := InternalMouseEnter;
FDesktopForm.OnMouseLeave := InternalMouseLeave;
FDesktopForm.OnUserMove := InternalOnMove;
FDesktopForm.lblText.OnClick := InternalMessageClick;
FDesktopForm.Moveable := (daoCanMove in Options);
FDesktopForm.MoveAnywhere := (daoCanMoveAnywhere in Options);
FDesktopForm.Closeable := (daoCanClose in Options);
FDesktopForm.ClickableMessage := daoCanClick in Options;
if not Assigned(FDesktopForm.tbClose.OnClick) then
FDesktopForm.tbClose.OnClick := FDesktopForm.acCloseExecute;
FDesktopForm.tbDropDown.DropDownMenu := DropDownMenu;
FDesktopForm.imIcon.Picture := Image;
FDesktopForm.Font := Font;
FDesktopForm.lblHeader.Caption := HeaderText;
FDesktopForm.lblHeader.Font := HeaderFont;
FDesktopForm.lblText.Caption := MessageText;
FDesktopForm.WindowColorFrom := Colors.WindowFrom;
FDesktopForm.WindowColorTo := Colors.WindowTo;
FDesktopForm.CaptionColorFrom := Colors.CaptionFrom;
FDesktopForm.CaptionColorTo := Colors.CaptionTo;
FDesktopForm.FrameColor := Colors.Frame;
for I := 0 to Length(FFormButtons) - 1 do
FFormButtons[I].Free;
SetLength(FFormButtons, Buttons.Count);
X := 2;
Y := FDesktopForm.Height - 23;
for I := 0 to Length(FFormButtons) - 1 do
begin
FFormButtons[I] := TJvDesktopAlertButton.Create(FDesktopForm);
with TJvDesktopAlertButton(FFormButtons[I]) do
begin
SetBounds(X, Y, 21, 21);
ToolType := abtImage;
Images := Self.Images;
ImageIndex := Buttons[I].ImageIndex;
Tag := Buttons[I].Tag;
InternalClick := Buttons[I].OnClick;
OnClick := FDesktopForm.DoButtonClick;
Parent := FDesktopForm;
Inc(X, 22);
end;
end;
Location.Position := GetStacker.Position;
if not AutoFocus then
begin
FActiveFocus := GetFocus;
FActiveWindow := GetActiveWindow;
end
else
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -