📄 sbutton.pas
字号:
FRegion := 0;
if RegionChanged then FCommonData.BGChanged := True;
if (FCommonData.BGChanged) then begin
PrepareCache;
end;
if RegionChanged then begin
UpdateCorners(FCommonData, CurrentState);
if FCommonData.BorderIndex > 0 then begin
// Top Left
BitBlt(DC, 0, 0, FCommonData.SkinManager.MaskWidthLeft(FCommonData.BorderIndex), FCommonData.SkinManager.MaskWidthTop(FCommonData.BorderIndex), FCommonData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
// Bottom Left
BitBlt(DC, 0, Height - FCommonData.SkinManager.MaskWidthBottom(FCommonData.BorderIndex), Width, FCommonData.SkinManager.MaskWidthTop(FCommonData.BorderIndex), FCommonData.FCacheBmp.Canvas.Handle, 0, Height - FCommonData.SkinManager.MaskWidthBottom(FCommonData.BorderIndex), SRCCOPY);
// Bottom Right
BitBlt(DC, Width - FCommonData.SkinManager.MaskWidthRight(FCommonData.BorderIndex), Height - FCommonData.SkinManager.MaskWidthBottom(FCommonData.BorderIndex), FCommonData.SkinManager.MaskWidthRight(FCommonData.BorderIndex), FCommonData.SkinManager.MaskWidthTop(FCommonData.BorderIndex), FCommonData.FCacheBmp.Canvas.Handle, Width - FCommonData.SkinManager.MaskWidthRight(FCommonData.BorderIndex), Height - FCommonData.SkinManager.MaskWidthBottom(FCommonData.BorderIndex), SRCCOPY);
// Top Right
BitBlt(DC, Width - FCommonData.SkinManager.MaskWidthRight(FCommonData.BorderIndex), 0, FCommonData.SkinManager.MaskWidthRight(FCommonData.BorderIndex), FCommonData.SkinManager.MaskWidthTop(FCommonData.BorderIndex), FCommonData.FCacheBmp.Canvas.Handle, Width - FCommonData.SkinManager.MaskWidthRight(FCommonData.BorderIndex), 0, SRCCOPY);
end;
if (DC <> acPrintDC) and not (csDesigning in ComponentState) and not (csAlignmentNeeded in ControlState) then begin // Set region
SetWindowRgn(Handle, FRegion, b); // Speed increased if repainting is disabled
FRegion := 0;
// RegionChanged := False;
end;
end;
if aDC = 0 then DC := GetDC(Handle) else DC := aDC;
SavedDC := SaveDC(DC);
try
BitBlt(DC, 0, 0, Width, Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
finally
RestoreDC(DC, SavedDC);
if aDC = 0 then ReleaseDC(Handle, DC);
end;
end;
finally
EndPaint(Handle, PS);
end;
end;
procedure TsButton.PrepareCache;
var
CI : TCacheInfo;
begin
CI := GetParentCache(FCommonData);
FCommonData.InitCacheBmp;
ParentCenterColor := clFuchsia;
if not CI.Ready and (Parent <> nil) then begin
CtrlParentColor := ColorToRGB(TsHackedControl(Parent).Color);
ParentCenterColor := ColorToRGB(TsHackedControl(Parent).Color);
end;
if CI.Ready and (Parent <> nil) and not SkinData.RepaintIfMoved and (ParentCenterColor = clFuchsia{ParentCenterColor may be already defined}) then begin
InitParentColor(Parent);
end;
PaintItemBG(FCommonData, CI, CurrentState, Rect(0, 0, Width, Height), Point(Left, Top), FCommonData.FCacheBMP, integer(Down), integer(Down));
if RegionChanged then begin FRegion := 0; FRegion := CreateRectRgn(0, 0, Width, Height); end; // Empty region
if FCommonData.SkinManager.IsValidImgIndex(FCommonData.BorderIndex) then
PaintRgnBorder(FCommonData.FCacheBmp, FRegion, True, FCommonData.SkinManager.ma[FCommonData.BorderIndex], CurrentState);
DrawCaption;
if not Enabled or ((Action <> nil) and not TAction(Action).Enabled) then begin
CI := GetParentCache(FCommonData);
ParentCenterColor := clFuchsia;
BmpDisabledKind(FCommonData.FCacheBmp, FDisabledKind, Parent, CI, Point(Left, Top));
end;
CtrlParentColor := clFuchsia;
ParentCenterColor := clFuchsia;
FCommonData.BGChanged := False;
end;
procedure TsButton.SetDisabledKind(const Value: TsDisabledKind);
begin
if FDisabledKind <> Value then begin
FDisabledKind := Value;
FCommonData.Invalidate;
end;
end;
{$IFNDEF DELPHI7UP}
procedure TsButton.SetWordWrap(const Value: boolean);
begin
if FWordWrap <> Value then begin
FWordWrap := Value;
FCommonData.BGChanged := True;
Repaint;
end;
end;
{$ENDIF}
procedure TsButton.SetDown(const Value: boolean);
begin
if FPressed <> Value then begin
FPressed := Value;
if FDown <> Value then FDown := Value;
RegionChanged := True;
FCommonData.BGChanged := True;
Repaint;
end;
end;
procedure TsButton.SetFocusMargin(const Value: integer);
begin
if (FFocusMargin <> Value) then begin
FFocusMargin := Value;
end;
end;
function TsButton.TextRectSize: TSize;
var
R : TRect;
DrawStyle: Longint;
begin
R := Rect(0, 0, MaxCaptionWidth(Self), 0);
DrawStyle := DT_EXPANDTABS or DT_CENTER or DT_CALCRECT;
if WordWrap
then DrawStyle := DrawStyle or DT_WORDBREAK
else DrawStyle := DrawStyle or DT_SINGLELINE;
AcDrawText(FCommonData.FCacheBMP.Canvas.Handle, Caption, R, DrawStyle);
Result.cy := HeightOf(R);
Result.cx := WidthOf(R);
end;
procedure TsButton.WMKeyUp(var Message: TWMKey);
begin
inherited;
if Assigned(FCommonData) and FCommonData.Skinned and (Message.CharCode = 32) then begin
FDown := False;
RegionChanged := True;
FCommonData.BGChanged := True;
Repaint;
end;
end;
procedure TsButton.WndProc(var Message: TMessage);
begin
{$IFDEF LOGGED}
AddToLog(Message);
{$ENDIF}
//inherited;exit;
//if Message.Msg = CN_DRAWITEM then Alert;
if (Message.Msg = WM_KILLFOCUS) and (csDestroying in ComponentState) then Exit;
if Message.Msg = SM_ALPHACMD then case Message.WParamHi of
AC_CTRLHANDLED : begin Message.LParam := 1; Exit end; // AlphaSkins supported
AC_GETAPPLICATION : begin Message.Result := longint(Application); Exit end;
AC_SETNEWSKIN : if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) then begin
RegionChanged := True;
StopFading(FadeTimer, FCommonData);
CommonWndProc(Message, FCommonData);
exit
end;
AC_REMOVESKIN : if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) and not (csDestroying in ComponentState) then begin
StopFading(FadeTimer, FCommonData);
CommonWndProc(Message, FCommonData);
SendMessage(Handle, BM_SETSTYLE, (GetWindowLong(Handle, GWL_STYLE) and not BS_OWNERDRAW), 1);
FRegion := 0;
SetWindowRgn(Handle, 0, False);
Repaint;
Exit;
end;
AC_REFRESH : if LongWord(Message.LParam) = LongWord(SkinData.SkinManager) then begin
StopFading(FadeTimer, FCommonData);
CommonWndProc(Message, FCommonData);
RegionChanged := True;
if acPrintDC = 0 then Repaint;
exit
end;
AC_PREPARECACHE : PrepareCache;
AC_DRAWANIMAGE : if FRegion <> 0 then DeleteObject(FRegion);
AC_STOPFADING : begin StopFading(FadeTimer, FCommonData); Exit end;
end;
if not ControlIsReady(Self) or not FCommonData.Skinned(True) then begin
case Message.Msg of
CM_MOUSEENTER : if Assigned(FOnMouseEnter) and Enabled and not (csDesigning in ComponentState) then FOnMouseEnter(Self);
CM_MOUSELEAVE : if Assigned(FOnMouseLeave) and Enabled and not (csDesigning in ComponentState) then FOnMouseLeave(Self);
end;
inherited
end
else begin
if Message.Msg = SM_ALPHACMD then case Message.WParamHi of
AC_ENDPARENTUPDATE : if FCommonData.Updating then begin
FCommonData.Updating := False;
Repaint;
Exit
end;
AC_URGENTPAINT : begin
if FCommonData.UrgentPainting then PrepareCache;
CommonWndProc(Message, FCommonData);
Exit
end;
end
else case Message.Msg of
WM_WINDOWPOSCHANGING : RegionChanged := True;
WM_WINDOWPOSCHANGED : begin
RegionChanged := True;
SkinData.BGChanged := True;
end;
CM_UIACTIVATE : SkinData.Updating := False;
CM_DIALOGCHAR : if (Enabled and Focused and (TCMDialogChar(Message).CharCode = VK_SPACE)) then begin
StopFading(FadeTimer, FCommonData);
FDown := True;
RegionChanged := True;
FCommonData.BGChanged := True;
Repaint;
end;
CM_MOUSEENTER : if Enabled and not (csDesigning in ComponentState) then begin
if not FCommonData.FMouseAbove and not MouseForbidden then begin
if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
FCommonData.FMouseAbove := True;
FCommonData.BGChanged := False;
DoChangePaint(FadeTimer, FCommonData, False, EventEnabled(aeMouseEnter, FAnimatEvents));
end;
end;
CM_MOUSELEAVE : if Enabled and not (csDesigning in ComponentState) then begin
if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
FCommonData.FMouseAbove := False;
FCommonData.BGChanged := False;
DoChangePaint(FadeTimer, FCommonData, False, EventEnabled(aeMouseLeave, FAnimatEvents));
end;
WM_SIZE : RegionChanged := True;
WM_UPDATEUISTATE, WM_ERASEBKGND : begin
Message.Result := 1;
Exit;
end;
CM_TEXTCHANGED : if not (csDestroying in ComponentState) then begin
FCommonData.Invalidate;
Exit;
end;
WM_PRINT : begin
RegionChanged := True;
OurPaintHandler(TWMPaint(Message).DC);
Exit;
end;
WM_PAINT : begin
SendMessage(Handle, BM_SETSTYLE, (GetWindowLong(Handle, GWL_STYLE) {and $000F }or BS_OWNERDRAW), 1); // ???
if (Parent = nil) then Exit;
OurPaintHandler(TWMPaint(Message).DC);
if not (csDesigning in ComponentState) then Exit;
end;
CN_DRAWITEM : begin Message.WParam := 0; Message.LParam := 0; Message.Result := 1; Exit; end;
WM_MOVE : if (FCommonData.SkinManager.gd[FCommonData.SkinIndex].Transparency > 0) or ((FCommonData.SkinManager.gd[FCommonData.SkinIndex].HotTransparency > 0) and ControlIsActive(FCommonData)) then begin
FCommonData.BGChanged := True;
Repaint
end;
WM_SETFOCUS, CM_ENTER : if not (csDesigning in ComponentState) and Visible then begin
if Enabled and not (csDestroying in ComponentState) then begin
inherited;
if FadeTimer <> nil then FadeTimer.Change {Fast repaint} else FCommonData.Invalidate;
end;
Exit;
end;
WM_KILLFOCUS, CM_EXIT: if not (csDesigning in ComponentState) and Visible then begin
FDown := False;
if Enabled and not (csDestroying in ComponentState) then begin
if FadeTimer <> nil then StopFading(FadeTimer, FCommonData);
inherited;
if FCommonData.Skinned then begin
FCommonData.FFocused := False;
RegionChanged := True;
FCommonData.Invalidate;
end;
end;
Exit
end;
WM_ENABLE : Exit; // Disabling of blinking when switched
end;
CommonWndProc(Message, FCommonData);
inherited;
case Message.Msg of
CM_ENABLEDCHANGED : if Visible and not (csDestroying in ComponentState) then begin
FCommonData.Updating := False;
FCommonData.Invalidate;
end;
CM_VISIBLECHANGED : if not (csDestroying in ComponentState) then begin
FCommonData.BGChanged := True;
FCommonData.Updating := False;
if Visible then Repaint;
end;
WM_SETFONT : if Visible then begin
FCommonData.Updating := False;
FCommonData.Invalidate;
end;
CM_ACTIONUPDATE : begin
if (Action <> nil) then Enabled := TCustomAction(Action).Enabled;
end;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -