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

📄 sedit.pas

📁 Alpha Controls 界面控件包
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit sEdit;
{$I sDefs.inc}
{.$DEFINE LOGGED}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  {$IFDEF TNTUNICODE}TntControls, TntActnList, TntStdCtrls, TntClasses, {$ENDIF}
  StdCtrls, sCommonData, sConst, sDefaults{$IFDEF LOGGED}, sDebugMsgs{$ENDIF};

type
  TsEdit = class(TEdit)
{$IFNDEF NOTFORHELP}
  private
    FCommonData: TsCommonData;
    FDisabledKind: TsDisabledKind;
    FBoundLabel: TsBoundLabel;
{$IFDEF TNTUNICODE}
    FPasswordChar: WideChar;
    procedure SetSelText(const Value: WideString);
    function GetText: WideString;
    procedure SetText(const Value: WideString);
    function GetHint: WideString;
    procedure SetHint(const Value: WideString);
    function IsHintStored: Boolean;
    function GetPasswordChar: WideChar;
    procedure SetPasswordChar(const Value: WideChar);
{$ENDIF}
    procedure SetDisabledKind(const Value: TsDisabledKind);
  protected
    procedure PaintBorder;
    procedure PrepareCache;
    procedure PaintText; virtual;
    procedure OurPaintHandler(aDC : hdc = 0);
{$IFDEF TNTUNICODE}
    procedure CreateWindowHandle(const Params: TCreateParams); override;
    procedure CreateWnd; override;
    procedure DefineProperties(Filer: TFiler); override;
    function GetActionLinkClass: TControlActionLinkClass; override;
    procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
    function GetSelStart: Integer; reintroduce; virtual;
    procedure SetSelStart(const Value: Integer); reintroduce; virtual;
    function GetSelLength: Integer; reintroduce; virtual;
    procedure SetSelLength(const Value: Integer); reintroduce; virtual;
    function GetSelText: WideString; reintroduce; virtual;
    property PasswordChar: WideChar read GetPasswordChar write SetPasswordChar default #0;
{$ENDIF}
  public
    procedure AfterConstruction; override;
    constructor Create(AOwner: TComponent); override;
    procedure CreateParams(var Params: TCreateParams); override;
    destructor Destroy; override;
    procedure Loaded; override;
    procedure WndProc (var Message: TMessage); override;
{$IFDEF TNTUNICODE}
    property SelText: WideString read GetSelText write SetSelText;
    property SelStart: Integer read GetSelStart write SetSelStart;
    property SelLength: Integer read GetSelLength write SetSelLength;
{$ENDIF}
  published
    property Align;
{$IFDEF TNTUNICODE}
    property Text: WideString read GetText write SetText;
    property Hint: WideString read GetHint write SetHint stored IsHintStored;
{$ENDIF}
{$ENDIF} // NOTFORHELP
    property DisabledKind : TsDisabledKind read FDisabledKind write SetDisabledKind default DefDisabledKind;
    property SkinData : TsCommonData read FCommonData write FCommonData;
    property BoundLabel : TsBoundLabel read FBoundLabel write FBoundLabel;
  end;

implementation

uses sStyleSimply, sMaskData, sVCLUtils, sMessages, sGraphUtils, sAlphaGraph, acUtils, sSKinProps, sSkinManager;

{ TsEdit }

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

constructor TsEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
//  ControlStyle := ControlStyle + [csOpaque];
  FCommonData := TsCommonData.Create(Self, {$IFDEF DYNAMICCACHE} False {$ELSE} True {$ENDIF});
  FCommonData.COC := COC_TsEdit;
  FDisabledKind := DefDisabledKind;
  FBoundLabel := TsBoundLabel.Create(Self, FCommonData);
end;

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

procedure TsEdit.Loaded;
begin
  inherited Loaded;
  FCommonData.Loaded;
end;

procedure TsEdit.OurPaintHandler(aDC : hdc = 0);
var
  DC, SavedDC : hdc;
  PS : TPaintStruct;
begin
  BeginPaint(Handle, PS);
  SavedDC := 0;
  if aDC = 0 then begin
    DC := GetWindowDC(Handle);
    SavedDC := SaveDC(DC);
  end
  else DC := aDC;
  FCommonData.Updating := FCommonData.Updating;
  try
    if not FCommonData.Updating then begin
      FCommonData.BGChanged := FCommonData.BGChanged or FCommonData.HalfVisible or GetBoolMsg(Parent, AC_GETHALFVISIBLE);
      FCommonData.HalfVisible := not RectInRect(Parent.ClientRect, BoundsRect);

      if FCommonData.BGChanged and not FCommonData.UrgentPainting then PrepareCache;
      UpdateCorners(FCommonData, 0);
      BitBlt(DC, 0, 0, Width{ - 3}, Height {- 3}, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
    end;
  finally
    if aDC = 0 then begin
      RestoreDC(DC, SavedDC);
      ReleaseDC(Handle, DC);
    end;
    EndPaint(Handle, PS);
  end;
end;

procedure TsEdit.PrepareCache;
begin
  FCommonData.InitCacheBmp;
  PaintItem(FCommonData,
            GetParentCache(SkinData), True,
            integer(ControlIsActive(FCommonData)),
            Rect(0, 0, Width, Height),
            Point(Left, top), FCommonData.FCacheBmp, False);
  PaintText;

  if not Enabled then BmpDisabledKind(FCommonData.FCacheBmp, FDisabledKind, Parent, GetParentCache(FCommonData), Point(Left, Top));
  FCommonData.BGChanged := False;
end;

procedure TsEdit.PaintBorder;
var
  DC, SavedDC: HDC;
  BordWidth : integer;
begin
  FCommonData.Updating := FCommonData.Updating;
  if SkinData.Updating then Exit;
  DC := GetWindowDC(Handle);
  SavedDC := SaveDC(DC);
  try
    if FCommonData.BGChanged then PrepareCache;
    BordWidth := integer(BorderStyle <> bsNone) * (1 + integer(Ctl3d));
{$IFDEF DELPHI7UP}
    if BordWidth = 0 then begin
      if BevelInner <> bvNone then inc(BordWidth);
      if BevelOuter <> bvNone then inc(BordWidth);
    end;
{$ENDIF}
    UpdateCorners(FCommonData, 0);
    BitBltBorder(DC, 0, 0, Width, Height, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, BordWidth);
{    BitBlt(DC, 0, 0, Width, BordWidth, FCommonData.FCacheBmp.Canvas.Handle, 0, 0, SRCCOPY);
    BitBlt(DC, 0, BordWidth, BordWidth, Height, FCommonData.FCacheBmp.Canvas.Handle, 0, BordWidth, SRCCOPY);
    BitBlt(DC, BordWidth, Height - BordWidth, Width - BordWidth * 2, BordWidth, FCommonData.FCacheBmp.Canvas.Handle, BordWidth, Height - BordWidth, SRCCOPY);
    BitBlt(DC, Width - BordWidth, BordWidth, BordWidth, Height - BordWidth, FCommonData.FCacheBmp.Canvas.Handle, Width - BordWidth, BordWidth, SRCCOPY);
}
{$IFDEF DYNAMICCACHE}
    if Assigned(FCommonData.FCacheBmp) then FreeAndNil(FCommonData.FCacheBmp);
{$ENDIF}
  finally
    RestoreDC(DC, SavedDC);
    ReleaseDC(Handle, DC);
  end;
end;

procedure TsEdit.PaintText;
var
  R : TRect;
{$IFDEF TNTUNICODE}
  s : WideString;
{$ELSE}
  s : string;
{$ENDIF}
  i : integer;
  BordWidth : integer;
begin
  FCommonData.FCacheBMP.Canvas.Font.Assign(Font);
  if BorderStyle <> bsNone then BordWidth := 1 + integer(Ctl3D) else BordWidth := 0;
  BordWidth := BordWidth {$IFDEF DELPHI7UP} + integer(BevelKind <> bkNone) * (integer(BevelOuter <> bvNone) + integer(BevelInner <> bvNone)) {$ENDIF};
  R := Rect(BordWidth + 1, BordWidth + 1, Width - BordWidth, Height - BordWidth);
{$IFDEF TNTUNICODE}
  if PasswordChar <> #0 then begin
    for i := 1 to Length(Text) do s := s + PasswordChar;
  end
  else s := Text;
  dec(R.Bottom);
  dec(R.Top);
  sGraphUtils.WriteUniCode(FCommonData.FCacheBmp.Canvas, s, True, R, DT_TOP or DT_NOPREFIX, FCommonData, ControlIsActive(FCommonData) and not ReadOnly);
{$ELSE}
  if PasswordChar <> #0 then begin
    for i := 1 to Length(Text) do s := s + PasswordChar;
  end
  else s := Text;
  WriteTextEx(FCommonData.FCacheBMP.Canvas, PChar(s), True, R, DT_TOP or DT_SINGLELINE or DT_WORDBREAK or DT_NOPREFIX,
              FCommonData, ControlIsActive(FCommonData));
{$ENDIF}
end;

procedure TsEdit.SetDisabledKind(const Value: TsDisabledKind);
begin
  if FDisabledKind <> Value then begin
    FDisabledKind := Value;
    FCommonData.Invalidate;
  end;
end;

procedure TsEdit.WndProc(var Message: TMessage);
var
  DC : hdc;
  bw : integer;
  PS: TPaintStruct;
begin

⌨️ 快捷键说明

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