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

📄 accoolbar.pas

📁 Alpha Controls 5.40,delphi上的alpha开发源码控件包。没有密码。5.40版的最新版。
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit acCoolBar;
{$I sDefs.inc}
{.$DEFINE LOGGED}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ToolWin, ComCtrls, sCommonData, Commctrl;

type
  TsCoolBar = class(TCoolBar)
{$IFNDEF NOTFORHELP}
  private
    FGripIndex : integer;
    FGripMask : integer;
    FGripsection : string;
    FGripTexture : integer;
    FCommonData: TsCommonData;
    procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
    procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
    procedure WMNCPaint (var Message: TWMNCPaint); message WM_NCPAINT;
    procedure ACPaint(DC : HDC = 0; SendUpdated : boolean = True); virtual;
    procedure PrepareCache;
    function GetCaptionSize(Band: TCoolBand): Integer;
    function GetCaptionFontHeight: Integer;
    function GetGripSize(Band: TCoolBand) : integer;
    procedure UpdateGripIndex;
  public
    constructor Create(AOwner:TComponent); override;
    destructor Destroy; override;
    procedure AfterConstruction; override;
    procedure Loaded; override;
    procedure WndProc (var Message: TMessage); override;
  published
{$ENDIF} // NOTFORHELP
    property SkinData : TsCommonData read FCommonData write FCommonData;
  end;

implementation

uses acntUtils, sGraphUtils, sAlphaGraph, sVCLUtils, sMessages, ImgList, math, sConst,
  sStyleSimply, sSkinProps;

{ TsCoolBar }

procedure TsCoolBar.ACPaint;
var
  b : boolean;
  NewDC : HDC;
  RW, RC : TRect;
  i : integer;
  SavedDC : hdc;
  R, CaptRect : TRect;
  CaptSize : integer;
  procedure PaintGrips;
  var
    i : integer;
    Band: TCoolBand;
    CI : TCacheInfo;
    DesignText : boolean;
    TempBmp : TBitmap;
    rText : TRect;
    GripSize : integer;
  begin
    CI := MakeCacheInfo(FCommonData.FCacheBmp, ACClientRect(Handle).Left, ACClientRect(Handle).Top);
    for i := 0 to Bands.Count - 1 do if Assigned(Bands[i].Control) and ((csDesigning in ComponentState) or Bands[i].Visible) then begin
      Band := Bands[I];
      CaptSize := GetCaptionSize(Band);
      GripSize := GetGripSize(Band);
      if Vertical then begin
        CaptRect.TopLeft := Point(min(Band.Control.Left - (Band.Height - Band.Control.Width) div 2, Band.Control.Left),
                                  Band.Control.Top - CaptSize);
        CaptRect.BottomRight := Point(CaptRect.Left + Band.Height, CaptRect.Top + CaptSize);
        TempBmp := CreateBmp24(Band.Height, CaptSize);
        BitBlt(TempBmp.Canvas.Handle, 0, 0, TempBmp.Width, TempBmp.Height, FCommonData.FCacheBmp.Canvas.Handle, CaptRect.Left + CI.X, CaptRect.Top + CI.Y, SRCCOPY);
        if FGripIndex <> -1 then begin
          PaintItem(FGripIndex, FGripsection, Ci, True, 0,
                    Rect(0, 0, Band.Height, GripSize - 2), Point(CaptRect.Left, CaptRect.Top),
                    TempBmp, SkinData.SkinManager, FGripTexture);
        end;
        rText := CaptRect;
        OffsetRect(rText, -rText.Left, -rText.Top);
        inc(rText.Top, GripSize);
        if Assigned(Images) and (Band.ImageIndex > -1) then begin
          Images.DrawingStyle := dsTransparent;
          Images.Draw(TempBmp.Canvas, (WidthOf(CaptRect) - Images.Width) div 2, GripSize, Band.ImageIndex);
          inc(rText.Top, Images.Height + 2);
        end;

        DesignText := (csDesigning in ComponentState) and (Band.Control = nil) and (Band.Text = '');
        if ShowText or DesignText then begin
          if DesignText then Text := Band.DisplayName else Text := Band.Text;
          if Text <> '' then begin
            TempBMP.Canvas.Font.Assign(Font);
            WriteTextEx(TempBMP.Canvas, PChar(Text), True, rText, DT_EXPANDTABS or DT_SINGLELINE or DT_VCENTER, FCommonData, False);
          end;
        end;
      end
      else begin
        CaptRect.TopLeft := Point(Band.Control.Left - CaptSize,
                                  min(Band.Control.Top - (Band.Height - Band.Control.Height) div 2, Band.Control.Top));
        CaptRect.BottomRight := Point(CaptRect.Left + CaptSize, CaptRect.Top + Band.Height);
        TempBmp := CreateBmp24(CaptSize, Band.Height);
        BitBlt(TempBmp.Canvas.Handle, 0, 0, TempBmp.Width, TempBmp.Height, FCommonData.FCacheBmp.Canvas.Handle, CaptRect.Left + CI.X, CaptRect.Top + CI.Y, SRCCOPY);
        if FGripIndex <> -1 then begin
          PaintItem(FGripIndex, FGripsection, Ci, True, 0,
                    Rect(0, 0, GripSize - 2, Band.Height), Point(CaptRect.Left, CaptRect.Top),
                    TempBmp, SkinData.SkinManager, FGripTexture);
        end;
        rText := CaptRect;
        OffsetRect(rText, -rText.Left, -rText.Top);
        inc(rText.Left, GripSize);
        if Assigned(Images) and (Band.ImageIndex > -1) then begin
          Images.DrawingStyle := dsTransparent;
          Images.Draw(TempBmp.Canvas, GripSize, (Band.Height - Images.Height) div 2, Band.ImageIndex);
          inc(rText.Left, Images.Width + 2);
        end;

        DesignText := (csDesigning in ComponentState) and (Band.Control = nil) and (Band.Text = '');
        if ShowText or DesignText then begin
          if DesignText then Text := Band.DisplayName else Text := Band.Text;
          if Text <> '' then begin
            TempBMP.Canvas.Font.Assign(Font);
            WriteTextEx(TempBMP.Canvas, PChar(Text), True, rText, DT_EXPANDTABS or DT_SINGLELINE or DT_VCENTER, FCommonData, False);
          end;
        end;
      end;

      R := Rect(1, 1, 1, 1);
      GetClipBox(NewDC, R);
      BitBlt(NewDC, CaptRect.Left, CaptRect.Top, TempBmp.Width, TempBmp.Height, TempBmp.Canvas.Handle, 0, 0, SRCCOPY);
      FreeAndNil(TempBmp);
    end;
  end;
begin
  if (csDestroying in ComponentState) or
       (csCreating in Parent.ControlState) or
         not Assigned(FCommonData) or not FCommonData.Skinned or not FCommonData.SkinManager.SkinData.Active then Exit;
  FCommonData.Updating := FCommonData.Updating;
  if not FCommonData.Updating then begin
    // If transparent and form resizing processed
    b := FCommonData.HalfVisible or FCommonData.BGChanged;// or GetBoolMsg(Parent.Handle, AC_GETHALFVISIBLE);

    if SkinData.RepaintIfMoved then begin
      FCommonData.HalfVisible := not (PtInRect(Parent.ClientRect, Point(Left + 1, Top + 1)));
      FCommonData.HalfVisible := FCommonData.HalfVisible or not PtInRect(Parent.ClientRect, Point(Left + Width - 1, Top + Height - 1));
    end else FCommonData.HalfVisible := False;

    if b and not FCommonData.UrgentPainting then PrepareCache;
    UpdateCorners(FCommonData, 0);
    if DC <> 0 then NewDC := DC else Exit;
    Windows.GetClientRect(Handle, RC);
    GetWindowRect(Handle, RW);
    MapWindowPoints(0, Handle, RW, 2);
    OffsetRect(RC, -RW.Left, -RW.Top);


    SavedDC := SaveDC(NewDC);
    for i := 0 to Bands.Count - 1 do if Assigned(Bands[i].Control) and (Bands[i].Visible or (csDesigning in ComponentState)) then begin
      CaptSize := GetCaptionSize(Bands[i]);
      if Vertical then begin
        CaptRect.TopLeft := Point(min(Bands[i].Control.Left - (Bands[i].Height - Bands[i].Control.Width) div 2, Bands[i].Control.Left),
                                  Bands[i].Control.Top - CaptSize);
        CaptRect.BottomRight := Point(CaptRect.Left + Bands[i].Height, CaptRect.Top + CaptSize);
      end
      else begin
        CaptRect.TopLeft := Point(Bands[i].Control.Left - CaptSize,
                                  min(Bands[i].Control.Top - (Bands[i].Height - Bands[i].Control.Height) div 2, Bands[i].Control.Top));
        CaptRect.BottomRight := Point(CaptRect.Left + CaptSize, CaptRect.Top + Bands[i].Height);
      end;
      ExcludeClipRect(NewDC, CaptRect.Left, CaptRect.Top, CaptRect.Right, CaptRect.Bottom);
    end;
    R := Rect(1, 1, 1, 1);
    GetClipBox(DC, R);
    CopyWinControlCache(Self, FCommonData, Rect(RC.Left, RC.Top, 0, 0), Rect(0, 0, WidthOf(RC), HeightOf(RC)), NewDC, True);
    R := Rect(1, 1, 1, 1);
    GetClipBox(DC, R);
    RestoreDC(NewDC, SavedDC);
    R := Rect(1, 1, 1, 1);
    GetClipBox(DC, R);
    sVCLUtils.PaintControls(NewDC, Self, b and SkinData.RepaintIfMoved, Point(0, 0)); // Painting of the skinned TGraphControls !!!!!!!
    PaintGrips;
    if SendUpdated then SetParentUpdated(Self);
  end;
end;

procedure TsCoolBar.AfterConstruction;
begin
  inherited;
  FCommonData.Loaded;
end;

{function TsCoolBar.GripRect(Band: TCoolBand): TRect;
begin
  if Vertical then begin
    Result.Left := min(Band.Control.Left - (Band.Width - Band.Control.Width) div 2, Band.Control.Left);
    Result.Top := Band.Control.Top - GetCaptionSize(Band);
    Result.Right := Band.Control.Left + Band.Width;
    Result.Bottom := Result.Top + GetGripSize(Band) - 2;
  end
  else begin
    Result.Left := Band.Control.Left - GetCaptionSize(Band);
    Result.Top := min(Band.Control.Top - (Band.Height - Band.Control.Height) div 2, Band.Control.Top);
    Result.Right := Result.Left + GetGripSize(Band) - 2;
    Result.Bottom := Band.Control.Top + Band.Height;
  end;
end;
}
constructor TsCoolBar.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
//  ControlStyle := ControlStyle + [csOpaque]; //v4.44
  UpdateGripIndex;
  FCommonData := TsCommonData.Create(Self, True);
  FCommonData.COC := COC_TsCoolBar;
end;

destructor TsCoolBar.Destroy;
begin
  if Assigned(FCommonData) then FreeAndNil(FCommonData);
  inherited Destroy;
end;

function TsCoolBar.GetCaptionFontHeight: Integer;
var
  TxtMetric: TTextMetric;
begin
  Result := 0;
  if HandleAllocated then
    with TControlCanvas.Create do
    try
      Control := Self;
//      Font := FCaptionFont;
      if (GetTextMetrics(Handle, TxtMetric)) then
        Result := TxtMetric.tmHeight;
    finally
      Free;
    end;
end;

const
  GripSizeIE3 = 8;
  GripSizeIE4 = 5;
  ControlMargin = 4;
  IDMask = $7FFFFFFF;

function TsCoolBar.GetCaptionSize(Band: TCoolBand): Integer;
var
  Text: string;
  Adjust, DesignText: Boolean;
begin
  Result := 0;
  Adjust := False;
  if (Band <> nil) and ((csDesigning in ComponentState) or Band.Visible) then begin
    DesignText := (csDesigning in ComponentState) and (Band.Control = nil) and (Band.Text = '');
    if ShowText or DesignText then begin
      if DesignText then Text := Band.DisplayName else Text := Band.Text;
      if Text <> '' then begin
        Adjust := True;
        if Vertical then Result := GetCaptionFontHeight else
          with TControlCanvas.Create do try
            Control := Self;
            Result := TextWidth(Text)
          finally
            Free;
          end;
      end;
    end;
    if Band.ImageIndex >= 0 then begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -