📄 bscalc.pas
字号:
begin
if ValueType = vtFloat
then TmpValue := StrToFloat(Text)
else TmpValue := StrToInt(Text);
NewValue := CheckValue(TmpValue);
if NewValue <> FValue
then
begin
FValue := NewValue;
end;
if NewValue <> TmpValue
then
begin
FromEdit := True;
if ValueType = vtFloat
then Text := FloatToStrF(NewValue, ffFixed, 15, FDecimal)
else Text := IntToStr(Round(FValue));
FromEdit := False;
end;
end;
inherited;
end;
procedure TbsSkinCalcEdit.CMTextChanged;
begin
inherited;
end;
procedure TbsSkinCalcEdit.SetValue;
begin
FValue := CheckValue(AValue);
StopCheck := True;
if ValueType = vtFloat
then
Text := FloatToStrF(CheckValue(AValue), ffFixed, 15, FDecimal)
else
Text := IntToStr(Round(CheckValue(AValue)));
StopCheck := False;
end;
procedure TbsSkinCalcEdit.KeyPress(var Key: Char);
begin
if not IsValidChar(Key) then
begin
Key := #0;
MessageBeep(0)
end;
if Key <> #0 then
if FCalc.Visible
then
CloseUp
else
inherited KeyPress(Key);
end;
function TbsSkinCalcEdit.IsValidChar(Key: Char): Boolean;
begin
if ValueType = vtInteger
then
Result := (Key in ['-', '0'..'9']) or
((Key < #32) and (Key <> Chr(VK_RETURN)))
else
Result := (Key in [DecimalSeparator, '-', '0'..'9']) or
((Key < #32) and (Key <> Chr(VK_RETURN)));
if ReadOnly and Result and ((Key >= #32) or
(Key = Char(VK_BACK)) or (Key = Char(VK_DELETE)))
then
Result := False;
if (Key = DecimalSeparator) and (Pos(DecimalSeparator, Text) <> 0)
then
Result := False
else
if (Key = '-') and (Pos('-', Text) <> 0)
then
Result := False;
end;
procedure TbsSkinCalcEdit.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
CloseUp;
end;
constructor TbsPopupCalculatorForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
BorderStyle := bvFrame;
ControlStyle := ControlStyle + [csNoDesignVisible, csReplicatable];
CalcEdit := nil;
{ DisplayPanel }
FDisplayLabel := TbsSkinLabel.Create(Self);
with FDisplayLabel do begin
Align := alTop;
Parent := Self;
AutoSize := False;
Alignment := taRightJustify;
Caption := '0';
BorderStyle := bvNone;
DefaultHeight := 20;
Visible := True;
end;
{ CalcPanel }
FCalcPanel := TCalculatorPanel.CreateLayout(Self);
with TCalculatorPanel(FCalcPanel) do begin
Align := alTop;
Parent := Self;
FControl := FDisplayLabel;
BorderStyle := bvNone;
OnOkClick := OkClick;
OnCancelClick := CancelClick;
Visible := True;
end;
end;
destructor TbsPopupCalculatorForm.Destroy;
begin
FDisplayLabel.Free;
FCalcPanel.Free;
inherited;
end;
procedure TbsPopupCalculatorForm.Show(X, Y: Integer);
begin
SetWindowPos(Handle, HWND_TOP, X, Y, 0, 0,
SWP_NOSIZE or SWP_NOACTIVATE or SWP_SHOWWINDOW);
Visible := True;
end;
procedure TbsPopupCalculatorForm.Hide;
begin
SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or
SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
Visible := False;
end;
procedure TbsPopupCalculatorForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
Style := WS_POPUP;
ExStyle := WS_EX_TOOLWINDOW;
AddBiDiModeExStyle(ExStyle);
WindowClass.Style := CS_SAVEBITS;
if CheckWXP then
WindowClass.Style := WindowClass.style or CS_DROPSHADOW_;
end;
end;
procedure TbsPopupCalculatorForm.WMMouseActivate(var Message: TMessage);
begin
Message.Result := MA_NOACTIVATE;
end;
procedure TbsPopupCalculatorForm.OkClick(Sender: TObject);
begin
if CalcEdit <> nil
then
begin
CalcEdit.Value := TCalculatorPanel(FCalcPanel).DisplayValue;
CalcEdit.CloseUp;
end;
end;
procedure TbsPopupCalculatorForm.CancelClick(Sender: TObject);
begin
if CalcEdit <> nil then CalcEdit.CloseUp;
end;
// Currency calcdit
constructor TbsSkinCalcCurrencyEdit.Create(AOwner: TComponent);
begin
inherited;
ButtonMode := True;
FSkinDataName := 'buttonedit';
OnButtonClick := ButtonClick;
FCalc := TbsCurrencyPopupCalculatorForm.Create(Self);
FCalc.Visible := False;
FCalc.CalcEdit := Self;
FCalc.Parent := Self;
FMemory := 0.0;
FPrecision := DefCalcPrecision;
FCalcButtonSkinDataName := 'toolbutton';
FCalcDisplayLabelSkinDataName := 'label';
FAlphaBlend := False;
FAlphaBlendValue := 0;
end;
destructor TbsSkinCalcCurrencyEdit.Destroy;
begin
FCalc.Free;
inherited;
end;
procedure TbsSkinCalcCurrencyEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
if (Key = VK_ESCAPE) and FCalc.Visible then CloseUp;
inherited;
end;
procedure TbsSkinCalcCurrencyEdit.CMCancelMode(var Message: TCMCancelMode);
begin
if (Message.Sender <> FCalc) and
not FCalc.ContainsControl(Message.Sender)
then
CloseUp;
end;
procedure TbsSkinCalcCurrencyEdit.CloseUp;
begin
if FCalc.Visible then FCalc.Hide;
if CheckW2KWXP and FAlphaBlend
then
SetWindowLong(FCalc.Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) and not WS_EX_LAYERED);
end;
procedure TbsSkinCalcCurrencyEdit.DropDown;
var
i, Y: Integer;
P: TPoint;
begin
with FCalc do
begin
SkinData := Self.SkinData;
FCalcPanel.SkinData := Self.SkinData;
FDisplayLabel.DefaultFont := FDefaultFont;
FDisplayLabel.SkinDataName := FCalcDisplayLabelSkinDataName;
FDisplayLabel.SkinData := Self.SkinData;
for i := 0 to FCalcPanel.ControlCount - 1 do
if FCalcPanel.Controls[i] is TbsSkinSpeedButton then
with TbsSkinSpeedButton(FCalcPanel.Controls[i]) do
begin
DefaultFont := Self.DefaultFont;
DefaultHeight := 25;
SkinDataName := FCalcButtonSkinDataName;
SkinData := Self.SkinData;
end
else
if FCalcPanel.Controls[i] is TbsSkinStdLabel then
with TbsSkinStdLabel(FCalcPanel.Controls[i]) do
begin
DefaultFont := Self.DefaultFont;
SkinData := Self.SkinData;
end;
TCalculatorPanel(FCalcPanel).FMemory := Self.FMemory;
TCalculatorPanel(FCalcPanel).UpdateMemoryLabel;
TCalculatorPanel(FCalcPanel).FPrecision := Max(2, Self.Precision);
TCalculatorPanel(FCalcPanel).FBeepOnError := False;
if Self.Value <> 0 then begin
TCalculatorPanel(FCalcPanel).DisplayValue := Self.Value;
TCalculatorPanel(FCalcPanel).FStatus := csFirst;
TCalculatorPanel(FCalcPanel).FOperator := '=';
end;
Width := 210 + BtnOffset * 2;
//
if FIndex = -1
then
Height := FCalcPanel.Height + FDisplayLabel.Height + 2
else
Height := FCalcPanel.Height + FDisplayLabel.Height +
(RectHeight(SkinRect) - RectHeight(ClRect));
//
Height := Height + BtnOffset;
P := Self.Parent.ClientToScreen(Point(Self.Left, Self.Top));
Y := P.Y + Self.Height;
if Y + FCalc.Height > Screen.Height then Y := P.Y - FCalc.Height;
if P.X + FCalc.Width > Screen.Width
then P.X := Screen.Width - FCalc.Width;
if P.X < 0 then P.X := 0;
FCalc.Left := P.X;
FCalc.Top := Y;
//
if CheckW2KWXP and FAlphaBlend
then
begin
SetWindowLong(FCalc.Handle, GWL_EXSTYLE,
GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
SetAlphaBlendTransparent(FCalc.Handle, 0)
end;
FCalc.Show(P.X, Y);
//
if FAlphaBlend and not FAlphaBlendAnimation and CheckW2KWXP
then
begin
Application.ProcessMessages;
SetAlphaBlendTransparent(FCalc.Handle, FAlphaBlendValue)
end
else
if CheckW2KWXP and FAlphaBlend and FAlphaBlendAnimation
then
begin
Application.ProcessMessages;
I := 0;
repeat
Inc(i, 2);
if i > FAlphaBlendValue then i := FAlphaBlendValue;
SetAlphaBlendTransparent(FCalc.Handle, i);
until i >= FAlphaBlendValue;
end;
end;
end;
procedure TbsSkinCalcCurrencyEdit.ButtonClick(Sender: TObject);
begin
if FCalc.Visible then CloseUp else DropDown;
end;
procedure TbsSkinCalcCurrencyEdit.KeyPress(var Key: Char);
begin
if FCalc.Visible
then
CloseUp;
inherited KeyPress(Key);
end;
procedure TbsSkinCalcCurrencyEdit.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
CloseUp;
end;
constructor TbsCurrencyPopupCalculatorForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
BorderStyle := bvFrame;
ControlStyle := ControlStyle + [csNoDesignVisible, csReplicatable];
CalcEdit := nil;
{ DisplayPanel }
FDisplayLabel := TbsSkinLabel.Create(Self);
with FDisplayLabel do begin
Align := alTop;
Parent := Self;
AutoSize := False;
Alignment := taRightJustify;
Caption := '0';
BorderStyle := bvNone;
DefaultHeight := 20;
Visible := True;
end;
{ CalcPanel }
FCalcPanel := TCalculatorPanel.CreateLayout(Self);
with TCalculatorPanel(FCalcPanel) do begin
Align := alTop;
Parent := Self;
FControl := FDisplayLabel;
BorderStyle := bvNone;
OnOkClick := OkClick;
OnCancelClick := CancelClick;
Visible := True;
end;
end;
destructor TbsCurrencyPopupCalculatorForm.Destroy;
begin
FDisplayLabel.Free;
FCalcPanel.Free;
inherited;
end;
procedure TbsCurrencyPopupCalculatorForm.Show(X, Y: Integer);
begin
SetWindowPos(Handle, HWND_TOP, X, Y, 0, 0,
SWP_NOSIZE or SWP_NOACTIVATE or SWP_SHOWWINDOW);
Visible := True;
end;
procedure TbsCurrencyPopupCalculatorForm.Hide;
begin
SetWindowPos(Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or
SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
Visible := False;
end;
procedure TbsCurrencyPopupCalculatorForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
Style := WS_POPUP;
ExStyle := WS_EX_TOOLWINDOW;
AddBiDiModeExStyle(ExStyle);
WindowClass.Style := CS_SAVEBITS;
if CheckWXP then
WindowClass.Style := WindowClass.style or CS_DROPSHADOW_;
end;
end;
procedure TbsCurrencyPopupCalculatorForm.WMMouseActivate(var Message: TMessage);
begin
Message.Result := MA_NOACTIVATE;
end;
procedure TbsCurrencyPopupCalculatorForm.OkClick(Sender: TObject);
begin
if CalcEdit <> nil
then
begin
CalcEdit.Value := TCalculatorPanel(FCalcPanel).DisplayValue;
CalcEdit.CloseUp;
end;
end;
procedure TbsCurrencyPopupCalculatorForm.CancelClick(Sender: TObject);
begin
if CalcEdit <> nil then CalcEdit.CloseUp;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -