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

📄 sglyphutils.pas

📁 Alpha Controls.v5.46b Source
💻 PAS
字号:
unit sGlyphUtils;
{$I sDefs.inc}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  sConst, buttons, acntUtils, sGraphUtils, sDefaults;

type

  TsGlyphMode = class(TPersistent)
  private
    FOwner : TWinControl;
    FBlend: integer;
    FGrayed: boolean;
    FUseDefaultGlyph: boolean;
    FGlyph : TBitmap;
    procedure SetBlend(const Value: integer);
    function GetHint: string;
    procedure SetHint(const Value: string);
    procedure SetGrayed(const Value: boolean);
    procedure SetGlyph(const Value: TBitmap);
    procedure SetUseDefaultGlyph(const Value: boolean);
  public
    function AssignDefaultBitmap : boolean;
    constructor Create(AOwner: TWinControl);
    destructor Destroy; override;
    procedure Invalidate;
    function Width: Integer;
    function Height: Integer;
  published
    property UseDefaultGlyph : boolean read FUseDefaultGlyph write SetUseDefaultGlyph default True;
    property Blend : integer read FBlend write SetBlend default DefGlyphBlend;
    property Glyph: TBitmap read FGlyph write SetGlyph;
    property Grayed: boolean read FGrayed write SetGrayed;
    property Hint: string read GetHint write SetHint;
  end;

function GetResBmp(const s : string) : TBitmap;

var
  DefBMP : TBitmap;

implementation

uses sCustomComboEdit, sComboBox, sCurrencyEdit, sMessages;

{$R SRES.RES}

var
  BTN_OPENFILE, BTN_OPENFOLDER, BTN_DATE, BTN_ELLIPSIS, BTN_CALC{, BTN_COM} : TBitmap;

{ TsGlyphMode }

function GetResBmp(const s : string) : TBitmap;
begin
  if s = 'BTN_OPENFILE' then begin
    Result := BTN_OPENFILE;
  end
  else if s = 'BTN_OPENFOLDER' then begin
    Result := BTN_OPENFOLDER;
  end
  else if s = 'BTN_DATE' then begin
    Result := BTN_DATE;
  end
  else if s = 'BTN_ELLIPSIS' then begin
    Result := BTN_ELLIPSIS;
  end
  else if s = 'BTN_CALC' then begin
    Result := BTN_CALC;
  end
  else Result := nil;
end;

constructor TsGlyphMode.Create(AOwner: TWinControl);
begin
  FOwner := AOwner;
  FBlend := DefGlyphBlend;
  FUseDefaultGlyph := True;
  FGlyph := TBitmap.Create;
end;

function TsGlyphMode.GetHint: string;
begin
  if FOwner is TsCustomComboEdit then begin
    Result := TsCustomComboEdit(FOwner).Button.Hint;
  end
  else Result := TsComboBox(FOwner).Hint;
end;

procedure TsGlyphMode.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;
    Invalidate;
  end;
end;

procedure TsGlyphMode.SetHint(const Value: string);
begin
  if FOwner is TsCustomComboEdit then begin
    TsCustomComboEdit(FOwner).Button.Hint := Value;
  end;
end;

procedure TsGlyphMode.SetGrayed(const Value: boolean);
begin
  if FGrayed <> Value then begin
    FGrayed := Value;
    FOwner.Perform(SM_ALPHACMD, MakeWParam(0, AC_REFRESH), 0);
  end;
end;

procedure TsGlyphMode.SetGlyph(const Value: TBitmap);
begin
  FGlyph.Assign(Value);
  FUseDefaultGlyph := False;
  FOwner.Perform(SM_ALPHACMD, MakeWParam(0, AC_REFRESH), 0);
end;

procedure TsGlyphMode.SetUseDefaultGlyph(const Value: boolean);
begin
  if FUseDefaultGlyph <> Value then begin
    FUseDefaultGlyph := Value;
    if Value then AssignDefaultBitmap;
    FOwner.Perform(SM_ALPHACMD, MakeWParam(0, AC_REFRESH), 0);
  end;
end;

function TsGlyphMode.AssignDefaultBitmap: boolean;
begin
  if FUseDefaultGlyph or (FGlyph.Width < 1)
    then DefBmp := GetResBmp(TsCustomComboEdit(FOwner).FDefBmpName)
    else DefBmp := FGlyph;
  if FOwner is TsCustomComboEdit then begin
    if Width > 0 then TsCustomComboEdit(FOwner).Button.Width := Width + 2 else TsCustomComboEdit(FOwner).Button.Width := 0;
  end;
  Result := Width <> 0;
end;

procedure TsGlyphMode.Invalidate;
begin
  if FOwner is TsCustomComboEdit then begin
    TsCustomComboEdit(FOwner).Button.Width := Width + 2;
    TsCustomComboEdit(FOwner).Button.Invalidate;
  end
  else TsComboBox(FOwner).PaintButton;
end;

destructor TsGlyphMode.Destroy;
begin
  if Assigned(FGlyph) then FreeAndNil(FGlyph);
  inherited Destroy;
end;

function TsGlyphMode.Width: Integer;
begin
  if FOwner is TsCurrencyEdit then begin
    Result := 0;
    Exit;
  end;
  if FUseDefaultGlyph and Assigned(DefBMP) then begin
    Result := DefBMP.Width div 3;
  end
  else if Assigned(FGlyph) and (FGlyph.Width <> 0) then begin
    Result := FGlyph.Width div 3;
  end
  else begin
    Result := 16;
  end;
end;

function TsGlyphMode.Height: Integer;
begin
  if FUseDefaultGlyph and Assigned(DefBMP) then Result := DefBMP.Height div 2 else if Assigned(FGlyph) then Result := FGlyph.Height div 2 else Result := 16;
end;

initialization
  try
    BTN_OPENFILE := TBitmap.Create;
    BTN_OPENFILE.LoadFromResourceName(hInstance, 'SF');

    BTN_OPENFOLDER := TBitmap.Create;
    BTN_OPENFOLDER.LoadFromResourceName(hInstance, 'SR');

    BTN_DATE := TBitmap.Create;
    BTN_DATE.LoadFromResourceName(hInstance, 'SD');

    BTN_ELLIPSIS := TBitmap.Create;
    BTN_ELLIPSIS.LoadFromResourceName(hInstance, 'SE');

    BTN_CALC := TBitmap.Create;
    BTN_CALC.LoadFromResourceName(hInstance, 'SC');
  except
  end;

finalization

  if Assigned(BTN_OPENFILE) then FreeAndNil(BTN_OPENFILE);
  if Assigned(BTN_OPENFOLDER) then FreeAndNil(BTN_OPENFOLDER);
  if Assigned(BTN_DATE) then FreeAndNil(BTN_DATE);
  if Assigned(BTN_ELLIPSIS) then FreeAndNil(BTN_ELLIPSIS);
  if Assigned(BTN_CALC) then FreeAndNil(BTN_CALC);
//  if Assigned(BTN_COM) then FreeAndNil(BTN_COM);

end.

⌨️ 快捷键说明

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