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

📄 ajtimeedit.pas

📁 FileBrowser, source code for delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
          ///////////////////////////////////////////////////////////////////////
          //                                                                   //
          //       SoftSpot Software Component Library                         //
          //       Key Maker software component                                //
          //                                                                   //
          //       Copyright (c) 1996 - 2002 SoftSpot Software Ltd.            //
          //       ALL RIGHTS RESERVED                                         //
          //                                                                   //
          //   The entire contents of this file is protected by U.S. and       //
          //   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.        //
          //                                                                   //
          //   RESTRICTIONS                                                    //
          //                                                                   //
          //   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      //
          //   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        //
          //   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       //
          //   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  //
          //   AND PERMISSION FROM SOFTSPOT SOFTWARE LTD.                      //
          //                                                                   //
          //   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       //
          //   ADDITIONAL RESTRICTIONS.                                        //
          //                                                                   //
          ///////////////////////////////////////////////////////////////////////

unit ajTimeEdit;

{                           -=< Key Maker File Browser Time Editor >=-
{
{ Copyright SoftSpot Software 2002 - All Rights Reserved
{
{ Author        : Andrew J Jameson
{
{ Web site      : www.softspotsoftware.com
{ e-mail        : contact@softspotsoftware.com
{
{ Creation Date : 01 March 2002
{
{ Version       : 1.00
{
{ Description   : Time editor component for Key Maker - edits milliseconds too !                   }

interface

uses
  StdCtrls, Messages, Controls, Classes, Windows, ExtCtrls;

type
  TajButtonType   = (tUpButton, tDownButton);

type
  TajButton = class(TObject)
  private
    fOwner      : TWinControl;                                            // Needed to get the owner's canvas.
    fButtonType : TajButtonType;                                          // Well it's either an up or down button.
    fDown       : boolean;                                                // And that button can be eith up or down.
    fRect       : TRect;                                                  // The button's bounds rect.
    fHasCapture : boolean;                                                // Hey ... we captured the mouse !
  protected
    procedure   SetfDown    (Value : boolean);                            // Set the button - up or down.
  public
    constructor Create      (AOwner : TWinControl; ButtonType : TajButtonType);
    procedure   Draw;
    property    ButtonType  : TajButtonType   read fButtonType    write fButtonType;
    property    Down        : boolean         read fDown          write SetfDown;
    property    HasCapture  : boolean         read fHasCapture    write fHasCapture;
    property    Bounds      : TRect           read fRect          write fRect;
  end;

type
  TajTimeEdit = class(TCustomEdit)
  private
    { Private declarations }
    fSelIndex       : integer;                                            // Index of the selected field - hr, min , sec or mSecs.
    fOldWindowProc  : TWndMethod;                                         // The TEdit's old WindowProc.
    fTimeChange     : TNotifyEvent;                                       // Time changed notify event.
    fDateTime       : TDateTime;                                          // The actual time value.
    fUpButton       : TajButton;                                          // The up button and it's brother ...
    fDownButton     : TajButton;                                          // the down button.
    fTimer          : TTimer;                                             // Auto repeat timer.
    procedure   NewWindowProc   (var Message : TMessage);                 // The new WindowProc.
    procedure   pWMChar         (Message : TWMChar);
    procedure   pWMKeyDown      (Message : TWMChar);
    procedure   pWMLButtonUp    (Message : TWMMouse);
    procedure   pWMMove         (Message : TWMMouse);
    procedure   pWMLButtonClick (Message : TWMMouse);
    procedure   pWMLButtonDown  (Message : TWMMouse);
    procedure   pWMPaint        (Message : TMessage);
    procedure   SetSelValue     (Value : integer);
    procedure   RepeatClick     (Sender : TObject);
  protected
    procedure   CreateWnd;                                override;
    function    GetTime         : TDateTime;
    procedure   SetTime         (Value : TDateTime);
  public
    { Public declarations }
    constructor Create          (AOwner : TComponent);    override;
    destructor  Destroy;                                  override;
    procedure   ClearTime;
    property    DateTime        : TDateTime     read GetTime      write SetTime;
    property    OnTimeChange    : TNotifyEvent  read fTimeChange  write fTimeChange;
  end;

implementation

uses
  SysUtils, Graphics;

type
  TSelPos = record                                                        // Used to set the selected
    SelStart  : integer;                                                  // text of the TEdit.
    SelLength : integer;
  end;

const
  cSelHours = 0;
  cSelMins  = 1;
  cSelSecs  = 2;
  cSelmSecs = 3;
  cSelText  : array[cSelHours..cSelmSecs] of TSelPos =
                                        ((SelStart : 0; SelLength : 2),   // The selected field constants
                                         (SelStart : 3; SelLength : 2),   // for hr, mins, secs and mSecs.
                                         (SelStart : 6; SelLength : 2),
                                         (SelStart : 9; SelLength : 3));

  cButtonWidth  = 17;                                                     // Guess !

{--------------------------------------------------------------------------------------------------}
{                                       TajButton                                                  }
{--------------------------------------------------------------------------------------------------}

constructor TajButton.Create(AOwner : TWinControl; ButtonType : TajButtonType);
begin
  fOwner      := AOwner;                                                  // Store the owner.
  fButtonType := ButtonType;                                              // I'm either an up or down button.
  fDown       := false;                                                   // And I'm not pressed.
  fHasCapture := false;                                                   // And I've not got the mouse yet.
end; {constructor}

{--------------------------------------------------------------------------------------------------}

procedure TajButton.SetfDown(Value : boolean);
begin
  if (fDown <> Value) then begin                                          // Looks as though I'm going up or
    fDown := Value;                                                       // down in the world ... so redraw
    Draw;                                                                 // me.
  end; {if}
end; {SetfDown}

{--------------------------------------------------------------------------------------------------}

procedure TajButton.Draw;
var
  cx, cy  : integer;
  aw, ah  : integer;
  Arrow   : array [0..2] of TPoint;
  DC      : HDC;
  lp1     : integer;
begin
  fRect := Rect(1, 0, cButtonWidth, fOwner.ClientHeight div 2);
  if (fButtonType = tUpButton) then begin
    OffSetRect(fRect, fOwner.ClientWidth - cButtonWidth, 0);
    with fRect do begin
      cx  := Left + cButtonWidth   div 2;
      cy  := Top  + (Bottom - Top) div 2;
      if fDown or not fOwner.Enabled then begin
        inc(cx);
        inc(cy);
      end; {if}
      if (cButtonWidth > Bottom - Top) then begin
        ah  := (Bottom - Top) div 2 - 2;
        aw  := ah * 2 - 1;
      end else begin
        aw  := cButtonWidth div 2 - 1;
        ah  := aw div 2 + 1;
      end; {if}
      Arrow[0]  := Point(cx,            cy - ah div 2 + 1);
      Arrow[1]  := Point(cx - aw div 2, cy + ah div 2    );
      Arrow[2]  := Point(cx + aw div 2, cy + ah div 2    );
    end; {with}
  end else begin
    OffSetRect(fRect, fOwner.ClientWidth - cButtonWidth, fOwner.ClientHeight div 2 + 1);
    with fRect do begin
      cx  := Left + cButtonWidth   div 2;
      cy  := Top  + (Bottom - Top) div 2;
      if fDown or not fOwner.Enabled then begin
        inc(cx);
        inc(cy);
      end; {if}
      if (cButtonWidth > Bottom - Top) then begin
        ah  := (Bottom - Top) div 2 - 2;
        aw  := ah * 2 - 1;
      end else begin
        aw  := cButtonWidth div 2 - 1;
        ah  := aw div 2 + 1;
      end; {if}
      Arrow[0]  := Point(cx - aw div 2, cy - ah div 2    );
      Arrow[1]  := Point(cx + aw div 2, cy - ah div 2    );
      Arrow[2]  := Point(cx,            cy + ah div 2 - 1);
    end; {with}
  end; {if}

  DC  := GetDC(fOwner.Handle);

  with TCanvas.Create, fRect do begin
    Handle      := DC;
    Brush.Color := clBtnFace;
    FillRect(fRect);
    if fOwner.Enabled then begin
      Brush.Color := clBlack;
      Pen.Color   := clBlack;
      Polygon(Arrow);
    end else begin
      Brush.Color := clBtnHighlight;
      Pen.Color   := clBtnHighlight;
      Polygon(Arrow);
      for lp1 := 0 to 2 do begin
        Arrow[lp1].x  := Arrow[lp1].x - 1;
        Arrow[lp1].y  := Arrow[lp1].y - 1;
      end; {for}
      Brush.Color := clBtnShadow;
      Pen.Color   := clBtnShadow;
      Polygon(Arrow);
    end; {if}
    if fDown then begin
      Pen.Color := clBtnShadow;
      Polyline([Point(Left,   Bottom-1), Point(Left,   Top  ), Point(Right,   Top  )]);
      Pen.Color := clBlack;
      Polyline([Point(Left+1, Bottom-2), Point(Left+1, Top+1), Point(Right-1, Top+1)]);
    end else begin
      Pen.Color := clBtnHighlight;
      Polyline([Point(Left+1, Bottom-2), Point(Left+1,  Top+1   ), Point(Right-1, Top+1)]);
      Pen.color := clBtnShadow;
      Polyline([Point(Left+1, Bottom-1), Point(Right-1, Bottom-1), Point(Right-1, Top  )]);
    end; {if}
    if (fButtonType = tUpButton) then begin
      if fDown then
        Pen.Color := clBtnHighlight
      else
        Pen.Color := clBlack;
      MoveTo(fOwner.ClientWidth - cButtonWidth + 1, fOwner.ClientHeight div 2);
        LineTo(fOwner.ClientWidth, fOwner.ClientHeight div 2);
    end; {if}
    ReleaseDC(Handle, DC);
    Free;

⌨️ 快捷键说明

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