📄 jvqdesktopalert.pas
字号:
FActiveWindow := NullHandle;
FActiveFocus := NullHandle;
end;
FDesktopForm.AllowFocus := AutoFocus;
FDesktopForm.Show;
if not AutoFocus and (FActiveFocus <> GetFocus) then
begin
if (FActiveFocus <> NullHandle) then
SetFocus(FActiveFocus)
else
if (FActiveWindow <> NullHandle) then
SetActiveWindow(FActiveWindow);
end;
GetStacker.Add(FDesktopForm);
end;
function TJvDesktopAlert.GetAlertStack: TJvDesktopAlertStack;
begin
if FStacker = GlobalStacker then
Result := nil
else
Result := FStacker;
end;
function TJvDesktopAlert.GetDropDownMenu: TPopupMenu;
begin
Result := FDesktopForm.tbDropDown.DropDownMenu;
end;
function TJvDesktopAlert.GetFont: TFont;
begin
Result := FDesktopForm.lblText.Font;
end;
function TJvDesktopAlert.GetHeaderFont: TFont;
begin
Result := FDesktopForm.lblHeader.Font;
end;
function TJvDesktopAlert.GetHeaderText: string;
begin
Result := FDesktopForm.lblHeader.Caption;
end;
function TJvDesktopAlert.GetImage: TPicture;
begin
Result := FDesktopForm.imIcon.Picture;
end;
function TJvDesktopAlert.GetMessageText: string;
begin
Result := FDesktopForm.lblText.Caption;
end;
function TJvDesktopAlert.GetParentFont: Boolean;
begin
Result := FDesktopForm.ParentFont;
end;
function TJvDesktopAlert.GetPopupMenu: TPopupMenu;
begin
Result := FDesktopForm.PopupMenu;
end;
function TJvDesktopAlert.GetShowHint: Boolean;
begin
Result := FDesktopForm.ShowHint;
end;
function TJvDesktopAlert.GetStacker: TJvDesktopAlertStack;
begin
if FStacker = nil then
Result := GlobalStacker
else
Result := FStacker;
end;
function TJvDesktopAlert.GetHint: string;
begin
Result := FDesktopForm.Hint;
end;
procedure TJvDesktopAlert.InternalMessageClick(Sender: TObject);
var
FEndInterval:Cardinal;
begin
if Assigned(FOnMessageClick) and (daoCanClick in Options) then
begin
FEndInterval := StyleHandler.EndInterval;
try
StyleHandler.EndInterval := 0;
FOnMessageClick(Self); // (p3) should this be Sender instead?
finally
StyleHandler.EndInterval := FEndInterval;
end;
if not Form.MouseInControl then
StyleHandler.DoEndAnimation;
end;
end;
procedure TJvDesktopAlert.InternalMouseEnter(Sender: TObject);
begin
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;
procedure TJvDesktopAlert.InternalMouseLeave(Sender: TObject);
begin
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
procedure TJvDesktopAlert.InternalOnClose(Sender: TObject;
var Action: TCloseAction);
begin
if (csDestroying in ComponentState) then
Exit;
if Location.Position = dapCustom then
begin
Location.Top := FDesktopForm.Top;
Location.Left := FDesktopForm.Left;
end;
if Assigned(FOnClose) then
FOnClose(Self);
GetStacker.Remove(FDesktopForm);
if AutoFree and (FDesktopForm <> nil) and not (csDesigning in ComponentState) then
begin
FDesktopForm.OnClose := nil;
// post a message to the form so we have time to finish off all event handlers and
// timers before the form and component are freed
PostMessage(FDesktopForm.Handle, JVDESKTOPALERT_AUTOFREE, WPARAM(FDesktopForm), LPARAM(Self));
FDesktopForm := nil;
end;
end;
procedure TJvDesktopAlert.InternalOnMove(Sender: TObject);
begin
if not (csDesigning in ComponentState) and not Location.AlwaysResetPosition and
(Location.Position <> dapCustom) then
begin
GetStacker.Remove(FDesktopForm);
Location.Position := dapCustom;
end;
end;
procedure TJvDesktopAlert.InternalOnShow(Sender: TObject);
begin
if Assigned(FOnShow) then
FOnShow(Self);
end;
procedure TJvDesktopAlert.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation = opRemove then
begin
if AComponent = FStacker then
AlertStack := nil;
end;
end;
procedure TJvDesktopAlert.SetAlertStack(const Value: TJvDesktopAlertStack);
begin
if FStacker <> Value then
begin
FStacker := Value;
if FStacker <> nil then
begin
Location.Position := FStacker.Position;
FStacker.FreeNotification(Self);
end;
end;
end;
procedure TJvDesktopAlert.SetButtons(const Value: TJvDesktopAlertButtons);
begin
FButtons.Assign(Value);
end;
procedure TJvDesktopAlert.SetColors(const Value: TJvDesktopAlertColors);
begin
FColors.Assign(Value);
end;
procedure TJvDesktopAlert.SetDropDownMenu(const Value: TPopupMenu);
begin
FDesktopForm.tbDropDown.DropDownMenu := Value;
end;
procedure TJvDesktopAlert.SetFont(const Value: TFont);
begin
FDesktopForm.lblText.Font := Value;
end;
procedure TJvDesktopAlert.SetHeaderFont(const Value: TFont);
begin
FDesktopForm.lblHeader.Font := Value;
end;
procedure TJvDesktopAlert.SetHeaderText(const Value: string);
begin
FDesktopForm.lblHeader.Caption := Value;
end;
procedure TJvDesktopAlert.SetHint(const Value: string);
begin
FDesktopForm.Hint := Value;
end;
procedure TJvDesktopAlert.SetImage(const Value: TPicture);
begin
FDesktopForm.imIcon.Picture := Value;
end;
procedure TJvDesktopAlert.SetImages(const Value: TCustomImageList);
begin
if FImages <> Value then
begin
FImages := Value;
if FImages <> nil then
FImages.FreeNotification(Self);
end;
end;
procedure TJvDesktopAlert.SetLocation(const Value: TJvDesktopAlertLocation);
begin
//
end;
procedure TJvDesktopAlert.SetMessageText(const Value: string);
begin
FDesktopForm.lblText.Caption := Value;
FDesktopForm.lblText.Update;
end;
procedure TJvDesktopAlert.SetParentFont(const Value: Boolean);
begin
FDesktopForm.ParentFont := Value;
end;
procedure TJvDesktopAlert.SetPopupMenu(const Value: TPopupMenu);
begin
FDesktopForm.PopupMenu := Value;
end;
procedure TJvDesktopAlert.SetShowHint(const Value: Boolean);
begin
FDesktopForm.ShowHint := Value;
end;
function TJvDesktopAlert.Showing: Boolean;
begin
Result := (FDesktopForm <> nil) and FDesktopForm.Showing;
end;
procedure TJvDesktopAlert.SetOptions(const Value: TJvDesktopAlertOptions);
begin
if FOptions <> Value then
begin
FOptions := Value;
if not (daoCanMove in FOptions) then
Exclude(FOptions, daoCanMoveAnywhere);
end;
end;
function TJvDesktopAlert.GetCloseButtonClick: TNotifyEvent;
begin
Result := FDesktopForm.tbClose.OnClick;
end;
procedure TJvDesktopAlert.SetCloseButtonClick(const Value: TNotifyEvent);
begin
FDesktopForm.tbClose.OnClick := Value;
end;
procedure TJvDesktopAlert.SetAlertStyle(const Value: TJvAlertStyle);
begin
if (FAlertStyle <> Value) or (FStyleHandler = nil) then
begin
FAlertStyle := Value;
FStyleHandler.Free;
FStyleHandler := CreateHandlerForStyle(AlertStyle, FDesktopForm);
end;
end;
//=== { TJvDesktopAlertStack } ===============================================
constructor TJvDesktopAlertStack.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FItems := TList.Create;
FPosition := dapBottomRight;
end;
destructor TJvDesktopAlertStack.Destroy;
begin
FItems.Free;
inherited Destroy;
end;
procedure TJvDesktopAlertStack.Add(AForm: TForm);
begin
FItems.Add(AForm);
UpdatePositions;
end;
function TJvDesktopAlertStack.GetCount: Integer;
begin
Result := FItems.Count;
end;
function TJvDesktopAlertStack.GetItems(Index: Integer): TJvFormDesktopAlert;
begin
Result := TJvFormDesktopAlert(FItems[Index]);
Assert((Result = nil) or (Result is TJvFormDesktopAlert));
end;
procedure TJvDesktopAlertStack.Remove(AForm: TForm);
var
Index, PrevNilSlot: Integer;
Form: TJvFormDesktopAlert;
begin
if (AForm <> nil) and (AForm is TJvFormDesktopAlert) then
begin
// The basic trick here is to push piling forms down in the list, while keeping the
// static ones (i.e. a form that has the mouse pointer over it) in place.
Index := FItems.IndexOf(AForm);
if Index >= 0 then
begin
FItems[Index] := nil;
Inc(Index);
while Index < FItems.Count do
begin
Form := Items[Index];
if Assigned(Form) and (not Form.MouseInControl) then
begin
PrevNilSlot := Pred(Index);
while FItems[PrevNilSlot] <> nil do
Dec(PrevNilSlot);
FItems[PrevNilSlot] := FItems[Index];
FItems[Index] := nil;
end;
Inc(Index);
end;
while (Pred(FItems.Count) >= 0) and (FItems[Pred(FItems.Count)] = nil) do
FItems.Delete(Pred(FItems.Count));
UpdatePositions;
end;
end;
end;
procedure TJvDesktopAlertStack.SetPosition(const Value: TJvDesktopAlertPosition);
begin
if FPosition <> Value then
begin
// if Value = dapCustom then raise
// Exception.Create('TJvDesktopAlertStack does not handle dapCustom alerts!');
// FItems.Clear;
FPosition := Value;
end;
end;
procedure TJvDesktopAlertStack.UpdatePositions;
var
C, I: Integer;
Form: TJvFormDesktopAlert;
X, Y: Integer;
R: TRect;
begin
C := Count;
if C > 0 then
begin
R := ScreenWorkArea;
case Position of
dapBottomRight:
begin
Y := R.Bottom;
for I := 0 to Pred(C) do
begin
Form := Items[I];
if Assigned(Form) and Form.Visible then
begin
X := R.Right - Form.Width;
Dec(Y, Form.Height);
Form.SetNewOrigin(X, Y);
end;
end;
end;
dapBottomLeft:
begin
X := R.Left;
Y := R.Bottom;
for I := 0 to Pred(C) do
begin
Form := Items[I];
if Assigned(Form) and Form.Visible then
begin
Dec(Y, Form.Height);
Form.SetNewOrigin(X, Y);
end;
end;
end;
dapTopRight:
begin
Y := R.Top;
for I := 0 to Pred(C) do
begin
Form := Items[I];
if Assigned(Form) and Form.Visible then
begin
X := R.Right - Form.Width;
Form.SetNewOrigin(X, Y);
Inc(Y, Form.Height);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -