?? sglyphutils.pas
字號(hào):
unit sGlyphUtils;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
sConst, sStyleUtil, buttons, sUtils, sGraphUtils, sCustomButton, 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(s : string) : TBitmap;
var
DefBMP : TBitmap;
implementation
uses sCustomComboEdit, sCustomComboBox, sStyleSimply, sCurrencyEdit;
{$R SRES.RES}
var
BTN_OPENFILE, BTN_OPENFOLDER, BTN_DATE, BTN_ELLIPSIS, BTN_CALC, BTN_COM : TBitmap;
{ TsGlyphMode }
function GetResBmp(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 if s = 'SCO1' then begin
Result := BTN_COM;
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 := TsCustomComboBox(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;
GetsStyle(FOwner).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;
GetsStyle(FOwner).Invalidate;
end;
end;
procedure TsGlyphMode.SetGlyph(const Value: TBitmap);
begin
FGlyph.Assign(Value);
FUseDefaultGlyph := False;
GetsStyle(FOwner).Invalidate;
end;
procedure TsGlyphMode.SetUseDefaultGlyph(const Value: boolean);
begin
if FUseDefaultGlyph <> Value then begin
FUseDefaultGlyph := Value;
if Value then AssignDefaultBitmap;
GetsStyle(FOwner).Invalidate;
end;
end;
function TsGlyphMode.AssignDefaultBitmap: boolean;
begin
if FUseDefaultGlyph then begin
DefBmp := GetResBmp(TsCustomComboEdit(FOwner).FDefBmpName);
end
else begin
DefBmp := FGlyph;
end;
if FOwner is TsCustomComboEdit then begin
if Width > 0 then begin
TsCustomComboEdit(FOwner).Button.Width := Width + 2;
end
else begin
TsCustomComboEdit(FOwner).Button.Width := 0;
end;
TsCustomComboEdit(FOwner).UpdateBtnBounds;
end;
Result := Width <> 0;
end;
procedure TsGlyphMode.Invalidate;
begin
if FOwner is TsCustomComboEdit then begin
TsCustomComboEdit(FOwner).Button.Width := Width + 2;
TsCustomComboEdit(FOwner).UpdateBtnBounds;
TsCustomComboEdit(FOwner).Button.Invalidate;
end
else begin
TsCustomComboBox(FOwner).PaintButton;
end;
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) 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 begin
Result := DefBMP.Height div 2;
end
else if Assigned(FGlyph) then begin
Result := FGlyph.Height div 2;
end
else begin
Result := 16;
end;
end;
initialization
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');
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.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -