⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sbitbtn.pas

📁 Alpha Controls 界面控件包
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    if not FCommonData.Updating and not (Assigned(FadeTimer) and FadeTimer.Enabled {and (FadeTimer.Iterations > FadeTimer.FadeLevel)}) then begin
      FCommonData.BGChanged := FCommonData.BGChanged or FCommonData.HalfVisible or GetBoolMsg(Parent, AC_GETHALFVISIBLE);
      FCommonData.HalfVisible := not RectInRect(Parent.ClientRect, BoundsRect);

      if not FCommonData.BGChanged then begin
        if (FOldSpacing <> Spacing) then begin
          FCommonData.BGChanged := True;
          FOldSpacing := Spacing;
        end;
      end;

      if (FCommonData.BGChanged or (csDesigning in ComponentState {for glyph changing})) and (not FCommonData.UrgentPainting or (CurrentState <> 0)) 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 not (csDesigning in ComponentState) and not (csAlignmentNeeded in ControlState) then begin // Set region
          SetWindowRgn(Handle, FRegion, False); //True //v4.71 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 TsBitBtn.PrepareCache;
var
  CI : TCacheInfo;
begin
  CI := GetParentCache(FCommonData);
  FCommonData.InitCacheBmp;

  ParentCenterColor := clFuchsia; // v4.42
  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 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 RegionChanged and not (csDesigning in ComponentState) and not (csAlignmentNeeded in ControlState) then begin // Set region
    SetWindowRgn(Handle, FRegion, True);
    RegionChanged := False;
  end;}
  if not Enabled or ((Action <> nil) and not TAction(Action).Enabled) then begin
    CI := GetParentCache(FCommonData);
    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
  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 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_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_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; // v4.31
      Exit;
    end
  end;
  if not ControlIsReady(Self) or not FCommonData.Skinned 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
        if FCommonData.UrgentPainting then PrepareCache;
        CommonWndProc(Message, FCommonData);
        Exit
      end;
    end
    else case Message.Msg of
      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 FCommonData.BGChanged and} not MouseForbidden then begin
          if Assigned(FOnMouseEnter) then FOnMouseEnter(Self);
          FCommonData.FMouseAbove := True;
          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;
        DoChangePaint(FadeTimer, FCommonData, False, EventEnabled(aeMouseLeave, FAnimatEvents));
      end;
      WM_SIZE : RegionChanged := True;
      CM_TEXTCHANGED : if not (csDestroying in ComponentState) then begin
        FCommonData.Invalidate;
        Exit;
      end;
      WM_UPDATEUISTATE, BM_SETSTATE, WM_ERASEBKGND : Exit;
      WM_PAINT : begin
        if (Parent = nil) then Exit;
        OurPaintHandler(TWMPaint(Message).DC);
        if not (csDesigning in ComponentState) then Exit;
      end;
      WM_PRINT : begin
//        RegionChanged := True;
        OurPaintHandler(TWMPaint(Message).DC);
        Exit;
      end;
      CN_CTLCOLORBTN, CN_DRAWITEM : Exit; // v4.63
      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) then begin
        if Enabled and not (csDestroying in ComponentState) 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) then begin
        FDown := False;
        if Enabled and not (csDestroying in ComponentState) then begin
          if FadeTimer <> nil then StopFading(FadeTimer, FCommonData);
          Perform(WM_SETREDRAW, 0, 0);
          inherited;
          Perform(WM_SETREDRAW, 1, 0);
          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.BGChanged := True;
        Repaint;
      end;
      CM_VISIBLECHANGED : if not (csDestroying in ComponentState) then begin
        FCommonData.BGChanged := True;
        FCommonData.Updating := False;
        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); // v4.43
  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 + -