📄 sbitbtn.pas
字号:
if RegionChanged then FCommonData.BGChanged := True;
if (FCommonData.BGChanged or (csDesigning in ComponentState {for glyph changing})) 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 TsBitBtn.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 FDrawOverBorder and FCommonData.SkinManager.IsValidImgIndex(FCommonData.BorderIndex) then
PaintRgnBorder(FCommonData.FCacheBmp, FRegion, True, FCommonData.SkinManager.ma[FCommonData.BorderIndex], CurrentState);
if ShowCaption then DrawCaption;
DrawBitBtnGlyph(Self);
if not FDrawOverBorder and FCommonData.SkinManager.IsValidImgIndex(FCommonData.BorderIndex) then
PaintRgnBorder(FCommonData.FCacheBmp, FRegion, True, FCommonData.SkinManager.ma[FCommonData.BorderIndex], CurrentState);
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;
if Assigned(FOnPaint) then FOnPaint(Self, FCommonData.FCacheBmp);
CtrlParentColor := clFuchsia;
ParentCenterColor := clFuchsia;
FCommonData.BGChanged := False;
end;
procedure TsBitBtn.SetAlignment(const Value: TAlignment);
begin
if FAlignment <> Value then begin
FAlignment := Value;
FCommonData.Invalidate;
end;
end;
procedure TsBitBtn.SetBlend(const Value: integer);
begin
if FBlend <> Value then begin
if Value < 0 then FBlend := 0 else if Value > 100 then FBlend := 100 else FBlend := Value;
FCommonData.Invalidate;
end;
end;
procedure TsBitBtn.SetDisabledGlyphKind(const Value: TsDisabledGlyphKind);
var
n : integer;
begin
if FDisabledGlyphKind <> Value then begin
FDisabledGlyphKind := Value;
if not FCommonData.Skinned then begin
if Assigned(Images) and (GetImageCount(Images) > 0) then begin
n := NumGlyphs;
CopyGlyph(Self, FCommonData, FImageIndex, Images, Glyph, DisabledGlyphKind, n);
NumGlyphs := n;
end;
end;
FCommonData.Invalidate;
end;
end;
procedure TsBitBtn.SetDisabledKind(const Value: TsDisabledKind);
begin
if FDisabledKind <> Value then begin
FDisabledKind := Value;
FCommonData.Invalidate;
end;
end;
{$IFNDEF DELPHI7UP}
procedure TsBitBtn.SetWordWrap(const Value: boolean);
begin
if FWordWrap <> Value then begin
FWordWrap := Value;
FCommonData.BGChanged := True;
Repaint;
end;
end;
{$ENDIF}
procedure TsBitBtn.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 TsBitBtn.SetFocusMargin(const Value: integer);
begin
if (FFocusMargin <> Value) then begin
FFocusMargin := Value;
end;
end;
procedure TsBitBtn.SetGrayed(const Value: boolean);
begin
if FGrayed <> Value then begin
FGrayed := Value;
FCommonData.Invalidate;
end;
end;
procedure TsBitBtn.SetImageIndex(const Value: integer);
var
n : integer;
begin
if FImageIndex <> Value then begin
FImageIndex := Value;
if Assigned(Images) then begin
n := NumGlyphs;
CopyGlyph(Self, FCommonData, FImageIndex, Images, Glyph, DisabledGlyphKind, n);
NumGlyphs := n;
end;
FCommonData.Invalidate;
end;
end;
procedure TsBitBtn.SetImages(const Value: TCustomImageList);
var
n : integer;
begin
if Images <> Value then begin
FImages := Value;
if Assigned(Images) then begin
n := NumGlyphs;
CopyGlyph(Self, FCommonData, FImageIndex, Images, Glyph, DisabledGlyphKind, n);
NumGlyphs := n;
end;
FCommonData.Invalidate;
end;
end;
procedure TsBitBtn.SetOffset(const Value: Integer);
begin
if (FOffset <> Value) then begin
FOffset := Value;
FCommonData.Invalidate;
end;
end;
procedure TsBitBtn.SetShowCaption(const Value: boolean);
begin
if FShowCaption <> Value then begin
FShowCaption := Value;
FCommonData.Invalidate;
end;
end;
procedure TsBitBtn.SetShowFocus(const Value: boolean);
begin
if FShowFocus <> Value then begin
FShowFocus := Value;
FCommonData.Invalidate;
end;
end;
procedure TsBitBtn.SetDrawOverBorder(const Value: boolean);
begin
if FDrawOverBorder <> Value then begin
FDrawOverBorder := Value;
FCommonData.Invalidate;
end;
end;
function TsBitBtn.TextRectSize: TSize;
var
R : TRect;
DrawStyle : longint;
begin
R := Rect(0, 0, MaxCaptionWidth(Self), 0);
DrawStyle := DT_EXPANDTABS or GetStringFlags(Self, FTextAlignment) or DT_CALCRECT;
if WordWrap then DrawStyle := DrawStyle or DT_WORDBREAK;
{$IFDEF TNTUNICODE}
DrawTextW(FCommonData.FCacheBMP.Canvas.Handle, PWideChar(Caption), Length(Caption), R, DrawStyle);
{$ELSE}
DrawText(FCommonData.FCacheBMP.Canvas.Handle, PChar(Caption), Length(Caption), R, DrawStyle);
{$ENDIF}
Result.cy := HeightOf(R);
Result.cx := WidthOf(R);
end;
procedure TsBitBtn.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;
// Click;
end;
end;
procedure TsBitBtn.WndProc(var Message: TMessage);
var
n : integer;
begin
{$IFDEF LOGGED}
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_SETNEWSKIN : if (LongWord(Message.LParam) = LongWord(SkinData.SkinManager)) then begin
RegionChanged := True;
StopFading(FadeTimer, FCommonData);
if Assigned(Images) and (GetImageCount(Images) > 0) and (Glyph <> nil) then Glyph.Assign(nil);
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);
if Assigned(Images) and (GetImageCount(Images) > 0) then begin
n := NumGlyphs;
CopyGlyph(Self, FCommonData, FImageIndex, Images, Glyph, DisabledGlyphKind, n);
NumGlyphs := n;
end;
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
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;
procedure TsBitBtn.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
Glyph.Assign(nil);
inherited ActionChange(Sender, CheckDefaults);
if Sender is TCustomAction then DoActionChanging(Self, TCustomAction(Sender));
if not (csDestroying in ComponentState) then FCommonData.Invalidate;
end;
procedure TsBitBtn.SetTextAlignment(const Value: TAlignment);
begin
if FTextAlignment <> Value then begin
FTextAlignment := Value;
FCommonData.Invalidate
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -