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

📄 dcedits.pas

📁 获取硬盘相关详细信息
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{*******************************************************************************

  Disk Controls pack v3.5
  FILE: dcEdits.pas - dcFileEdit and dcFolderEdit components.

  Copyright (c) 1999-2002 UtilMind Solutions
  All rights reserved.
  E-Mail: info@appcontrols.com, info@utilmind.com
  WWW: http://www.appcontrols.com, http://www.utilmind.com

  The entire contents of this file is protected by International Copyright
Laws. Unauthorized reproduction, reverse-engineering, and distribution of all
or any portion of the code contained in this file is strictly prohibited and
may result in severe civil and criminal penalties and will be prosecuted to
the maximum extent possible under the law.

*******************************************************************************}
{$I umDefines.inc}

unit dcEdits;

interface

uses
  Windows, Messages, SysUtils, StdCtrls, Classes, Controls,
  Buttons, Graphics, Forms, Dialogs {$IFDEF D3}, ExtDlgs, dcBrowseDialog {$ENDIF};

type
  TdcCustomEdit = class;

  { TdcEditButton }
  TdcEditButton = class(TPersistent)
  private
    { for internal use }
    Edit: TdcCustomEdit;
    Btn: TSpeedButton;

    function  GetCursor: TCursor;
    procedure SetCursor(Value: TCursor);
    {$IFDEF D3}
    function  GetFlat: Boolean;
    procedure SetFlat(Value: Boolean);
    {$ENDIF}
    function  GetGlyph: TBitmap;
    procedure SetGlyph(Value: TBitmap);
    function  GetNumGlyphs: TNumGlyphs;
    procedure SetNumGlyphs(Value: TNumGlyphs);
    function  GetHint: String;
    procedure SetHint(Value: String);
    function  GetWidth: Word;
    procedure SetWidth(Value: Word);
    function  GetVisible: Boolean;
    procedure SetVisible(Value: Boolean);
  public
    constructor Create(AEdit: TdcCustomEdit; ABtn: TSpeedButton);
  published
    property Cursor: TCursor read GetCursor write SetCursor;
    {$IFDEF D3}
    property Flat: Boolean read GetFlat write SetFlat;
    {$ENDIF}
    property Glyph: TBitmap read GetGlyph write SetGlyph;
    property NumGlyphs: TNumGlyphs read GetNumGlyphs write SetNumGlyphs;
    property Hint: String read GetHint write SetHint;
    property Width: Word read GetWidth write SetWidth default 20;
    property Visible: Boolean read GetVisible write SetVisible default False;
  end;

  TdcCustomEdit = class(TEdit)
  private
    FAbout: String;

    FAlignment: TAlignment;
    FAutoSelect: Boolean;
    FButton: TdcEditButton;
    FColor, FColorDisabled: TColor;
    FCursorBorder: TCursor;

    FOnButtonClick: TNotifyEvent;
    FOnMouseEnter, FOnMouseLeave: TNotifyEvent;

    { for internal use }
    FBtn: TSpeedButton;
    FBtnControl: TWinControl;
    FValidChars: String;
    FValidateChars: Boolean;

    procedure UpdateBtnBounds;
    procedure UpdateEditRect;
    procedure UpdateBkColor;

    procedure SetAlignment(Value: TAlignment);
    procedure SetColor(Value: TColor);
    procedure SetColorDisabled(Value: TColor);

    procedure WMChar(var Message: TWMChar); message WM_CHAR;
    procedure WMSize(var Message: TWMSize); message WM_SIZE;
    procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
    procedure CMExit(var Message: TCMExit); message CM_EXIT;
    procedure CMCtl3DChanged(var Message: TMessage); message CM_Ctl3DChanged;
    procedure CMEnableChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  protected
    procedure WndProc(var Message: TMessage); override;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure CreateWnd; override;
    procedure KeyPress(var Key: Char); override;

    procedure ButtonClick(Sender: TObject); virtual;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    property About: String read FAbout write FAbout stored False;
    property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
    property AutoSelect: Boolean read FAutoSelect write FAutoSelect default True;
    property Button: TdcEditButton read FButton write FButton;
    property Color: TColor read FColor write SetColor;
    property ColorDisabled: TColor read FColorDisabled write SetColorDisabled default clBtnFace;
    property CursorBorder: TCursor read FCursorBorder write FCursorBorder;
    property ValidChars: String read FValidChars write FValidChars;
    property ValidateChars: Boolean read FValidateChars write FValidateChars default True;

    { not for publishing }
    property EditButton: TSpeedButton read FBtn;

    property OnButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick;
    property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
    property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  end;

  { TdcFileEdit }
  TdcFileEditDlgTypes = (dtOpen, dtSave {$IFDEF D3}, dtOpenPicture, dtSavePicture {$ENDIF});
  TdcFileEdit = class(TdcCustomEdit)
  private
    FDlgType: TdcFileEditDlgTypes;
    FDlgDefaultExt, FDlgFilter, FDlgTitle: String;
    FDlgOptions: TOpenOptions;

    FOnDlgOk, FOnDlgCancel: TNotifyEvent;

    FOpenDialog: TOpenDialog;
    FSaveDialog: TSaveDialog;
{$IFDEF D3}
    FOpenPictureDialog: TOpenPictureDialog;
    FSavePictureDialog: TSavePictureDialog;
{$ENDIF}
  protected
    procedure ButtonClick(Sender: TObject); override;
  public
    constructor Create(aOwner: TComponent); override;
    destructor Destroy; override;

    property ODialog: TOpenDialog read FOpenDialog; 
  published
    property DlgType: TdcFileEditDlgTypes read FDlgType write FDlgType;
    property DlgDefaultExt: String read FDlgDefaultExt write FDlgDefaultExt;
    property DlgFilter: String read FDlgFilter write FDlgFilter;
    property DlgTitle: String read FDlgTitle write FDlgTitle;
    property DlgOptions: TOpenOptions read FDlgOptions write FDlgOptions;

    property OnDlgOk: TNotifyEvent read FOnDlgOk write FOnDlgOk;
    property OnDlgCancel: TNotifyEvent read FOnDlgCancel write FOnDlgCancel;

    property About;
    property Align;
    property Alignment;
    property AutoSelect;
    property Button;
    property Color;
    property ColorDisabled;
    property CursorBorder;
    property OnButtonClick;
    property OnMouseEnter;
    property OnMouseLeave;
  end;

{$IFDEF D3}
  { TdcFolderEdit }
  TdcFolderEdit = class(TdcCustomEdit)
  private
    FBrowseDialog: TdcBrowseDialog;
    FDlgOptions: TdcBrowseDialogOptions;
    FDlgSpecialLocation: TdcBrowseDialogSpecialLocation;
    FDlgStatusText, FDlgTitle: String;
    FNewFolder: TdcNewFolderBtn;

    FOnDlgOk, FOnDlgCancel: TNotifyEvent;
  protected
    procedure ButtonClick(Sender: TObject); override;
  public
    constructor Create(aOwner: TComponent); override;
    destructor Destroy; override;
  published
    property DlgOptions: TdcBrowseDialogOptions read FDlgOptions write FDlgOptions;
    property DlgSpecialLocation: TdcBrowseDialogSpecialLocation read FDlgSpecialLocation write FDlgSpecialLocation;
    property DlgStatusText: String read FDlgStatusText write FDlgStatusText;
    property DlgTitle: String read FDlgTitle write FDlgTitle;
    property NewFolder: TdcNewFolderBtn read FNewFolder write FNewFolder;

    property OnDlgOk: TNotifyEvent read FOnDlgOk write FOnDlgOk;
    property OnDlgCancel: TNotifyEvent read FOnDlgCancel write FOnDlgCancel;

    property About;
    property Align;
    property Alignment;
    property AutoSelect;
    property Button;
    property Color;
    property ColorDisabled;
    property CursorBorder;
    property OnButtonClick;
    property OnMouseEnter;
    property OnMouseLeave;
  end;
{$ENDIF}  

implementation

{$R *.res}

uses dcUtils;

{ TdcEditButton }
constructor TdcEditButton.Create(aEdit: TdcCustomEdit; aBtn: TSpeedButton);
begin
  inherited Create;
  Edit := aEdit;
  Btn := aBtn;
end;

function  TdcEditButton.GetCursor: TCursor;
begin
  Result := Btn.Cursor;
end;

procedure TdcEditButton.SetCursor(Value: TCursor);
begin
  Btn.Cursor := Value;
end;

{$IFDEF D3}
function  TdcEditButton.GetFlat: Boolean;
begin
  Result := Btn.Flat;
end;

procedure TdcEditButton.SetFlat(Value: Boolean);
begin
  Btn.Flat := Value;
end;
{$ENDIF}

function  TdcEditButton.GetGlyph: TBitmap;
begin
  Result := Btn.Glyph;
end;

procedure TdcEditButton.SetGlyph(Value: TBitmap);
begin
  Btn.Glyph := Value;
end;

function  TdcEditButton.GetNumGlyphs: TNumGlyphs;
begin
  Result := Btn.NumGlyphs;
end;

procedure TdcEditButton.SetNumGlyphs(Value: TNumGlyphs);
begin
  Btn.NumGlyphs := Value;
end;

function  TdcEditButton.GetHint: String;
begin
  Result := Btn.Hint;
end;

procedure TdcEditButton.SetHint(Value: String);
begin
  Btn.Hint := Value;
  Btn.ShowHint := Value <> '';
end;

function  TdcEditButton.GetWidth: Word;
begin
  Result := Btn.Width;
end;

procedure TdcEditButton.SetWidth(Value: Word);
begin
  if Btn.Width <> Value then
   with Edit do
    begin
     FBtnControl.Visible := Value > 1;
     Btn.Width := Value;
     if HandleAllocated then RecreateWnd;
   end;
end;

function  TdcEditButton.GetVisible: Boolean;
begin
  Result := Edit.FBtnControl.Visible;
end;

procedure TdcEditButton.SetVisible(Value: Boolean);
begin
  with Edit do
   begin
    FBtnControl.Visible := Value;
    UpdateBtnBounds;
    Invalidate;
   end;
end;


{ TdcCustomEdit }
constructor TdcCustomEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FBtnControl := TWinControl.Create(Self);
  with FBtnControl do
    ControlStyle := ControlStyle + [csReplicatable];
  FBtnControl.Height := 17;
  FBtnControl.Parent := Self;

  FBtn := TSpeedButton.Create(Self);
  FButton := TdcEditButton.Create(Self, FBtn);
  FBtn.Parent := FBtnControl;
  FBtn.OnClick := ButtonClick;
  FBtn.SetBounds(0, 0, 20, FBtnControl.Height);
  try
    FBtn.Glyph.Handle := LoadBitmap(hInstance, 'DC_ELLIPSIS');
  except
  end;

  FButton.Visible := False;
  FBtnControl.Width := 0;

  AutoSize := False;
  Height := 21;
  FAlignment := taLeftJustify;
  FAutoSelect := True;
  FColor := clWindow;
  FColorDisabled := clBtnFace;
end;

destructor TdcCustomEdit.Destroy;
begin
  FButton.Free;
  FBtn.Free;
  FBtnControl.Free;
  inherited Destroy;
end;

procedure TdcCustomEdit.CreateParams(var Params: TCreateParams);
const
  Alignments: Array[TAlignment] of DWord = (ES_LEFT, ES_RIGHT, ES_CENTER);
begin
  inherited CreateParams(Params);

  Params.Style := Params.Style or ES_MULTILINE or WS_CLIPCHILDREN
    or Alignments[FAlignment];
end;

procedure TdcCustomEdit.CreateWnd;
begin
  inherited CreateWnd;
  UpdateEditRect;
end;

procedure TdcCustomEdit.KeyPress(var Key: Char);

⌨️ 快捷键说明

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