📄 sbutton.pas
字号:
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 not (csDesigning in ComponentState) and not (csAlignmentNeeded in ControlState) then begin // Set region
SetWindowRgn(Handle, FRegion, False); // Speed increased if repainting disabled
FRegion := 0;
RegionChanged := False;
end;
end;
BitBlt(DC, 0, 0, Width, Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
end;
finally
RestoreDC(DC, SavedDC);
if aDC = 0 then ReleaseDC(Handle, DC);
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 // v4.40
CtrlParentColor := ColorToRGB(TsHackedControl(Parent).Color);
ParentCenterColor := ColorToRGB(TsHackedControl(Parent).Color);//CI.Bmp.Canvas.Pixels[CI.Bmp.Width div 2, CI.Bmp.Height div 2];
end;
if CI.Ready and (Parent <> nil) and not SkinData.RepaintIfMoved and (ParentCenterColor = clFuchsia{ParentCenterColor may be already defined}) then begin
InitParentColor(Parent); // v4.40
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 RegionChanged and not (csDesigning in ComponentState) and not (csAlignmentNeeded in ControlState) then begin // Set region
SetWindowRgn(Handle, FRegion, False);//True);//v4.71
RegionChanged := False;
end;
}
if not Enabled then begin
ParentCenterColor := clFuchsia;
CI := GetParentCache(FCommonData);
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
if Assigned(FCommonData) and FCommonData.Skinned and Down and (Message.CharCode = 32) then begin
FDown := False;
RegionChanged := True;
FCommonData.BGChanged := True;
Repaint;
Click;
end;
inherited;
end;
procedure TsButton.WndProc(var Message: TMessage);
begin
{$IFDEF LOGGED}
if Message.Msg = WM_SETREDRAW then LogLines.Add('WM_SETREDRAW ' + IntToStr(Message.WParam))
else AddToLog(Message);
{$ENDIF}
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_REMOVESKIN : if LongWord(Message.LParam) = LongWord(SkinData.SkinManager) then begin
StopFading(FadeTimer, FCommonData);
CommonWndProc(Message, FCommonData);
SetWindowRgn(Handle, 0, False);
Repaint; // v4.31
exit
end;
AC_REFRESH : if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) then begin
StopFading(FadeTimer, FCommonData);
CommonWndProc(Message, FCommonData);
RegionChanged := True;
Repaint;
exit
end;
AC_PREPARECACHE : PrepareCache;
AC_DRAWANIMAGE : if FRegion <> 0 then DeleteObject(FRegion);
AC_STOPFADING : begin StopFading(FadeTimer, FCommonData); Exit end;
AC_SETNEWSKIN : if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) then begin
StopFading(FadeTimer, FCommonData);
RegionChanged := True;
CommonWndProc(Message, FCommonData);
exit
end
end;
if not ControlIsReady(Self) or not FCommonData.Skinned(True) then inherited 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 // v4.08
CommonWndProc(Message, FCommonData);
if FCommonData.UrgentPainting then PrepareCache;
Exit
end;
end
else case Message.Msg of
CM_FOCUSCHANGED : if Visible then begin
if FCommonData.Skinned and Default then with Message do begin
if (TCMFocusChanged(Message).Sender is TsButton) or (TCMFocusChanged(Message).Sender is TsBitBtn) then begin
if Active <> (TCMFocusChanged(Message).Sender = Self) then begin
Active := TCMFocusChanged(Message).Sender = Self;
FCommonData.Invalidate;
end;
end
else if Active <> Default then begin
Active := Default;
FCommonData.Invalidate;
end;
end;
// Perform(WM_SETREDRAW, 0, 0); v5.25
inherited;
// Perform(WM_SETREDRAW, 1, 0); v5.25
if (csDesigning in ComponentState) then begin
Active := False;
FCommonData.Invalidate;
end;
end;
WM_WINDOWPOSCHANGED : begin
RegionChanged := True;
SkinData.BGChanged := True;
end;
CM_UIACTIVATE : SkinData.Updating := False; // v4.51
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_TEXTCHANGED : begin
FCommonData.BGChanged := True;
Repaint;
Exit;
end;
CM_MOUSEENTER : if Enabled and not (csDesigning in ComponentState) then begin
if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
FCommonData.FMouseAbove := True;
// RegionChanged := True;
DoChangePaint(FadeTimer, FCommonData, False, EventEnabled(aeMouseEnter, FAnimatEvents));
end;
CM_MOUSELEAVE : if Enabled and not (csDesigning in ComponentState) then begin
if Assigned(FOnMouseLeave) then FOnMouseLeave(Self);
FCommonData.FMouseAbove := False;
// RegionChanged := True;
DoChangePaint(FadeTimer, FCommonData, False, EventEnabled(aeMouseLeave, FAnimatEvents));
end;
// WM_WINDOWPOSCHANGING,
WM_SIZE : RegionChanged := True;
BM_SETSTATE : begin exit end;
WM_UPDATEUISTATE, WM_ERASEBKGND : begin
Message.Result := 0;
Exit;
end;
CN_CTLCOLORBTN, CN_DRAWITEM : Exit; // v4.63
WM_PRINT : begin
OurPaintHandler(TWMPaint(Message).DC);
Exit;
end;
WM_PAINT : begin
OurPaintHandler(0);
if not (csDesigning in ComponentState) then 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 then begin
Perform(WM_SETREDRAW, 0, 0);
inherited;
Perform(WM_SETREDRAW, 1, 0);
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 then begin
if FadeTimer <> nil then StopFading(FadeTimer, FCommonData);
Perform(WM_SETREDRAW, 0, 0);
inherited;
Perform(WM_SETREDRAW, 1, 0);
FCommonData.FFocused := False;
RegionChanged := True;
FCommonData.Invalidate;
Exit
end;
end;
WM_ENABLE : Exit; // Disabling of blinking when switched
end;
CommonWndProc(Message, FCommonData);
inherited;
case Message.Msg of
CM_ENABLEDCHANGED : if Visible then begin
FCommonData.Updating := False;
FCommonData.Invalidate;
end;
CM_VISIBLECHANGED : begin
FCommonData.BGChanged := True;
Repaint;
end;
WM_SETFONT : 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 + -