cxprogressbar.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,716 行 · 第 1/5 页

PAS
1,716
字号
{********************************************************************}
{                                                                    }
{       Developer Express Visual Component Library                   }
{       ExpressEditors                                               }
{                                                                    }
{       Copyright (c) 1998-2008 Developer Express Inc.               }
{       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                                                     }
{                                                                    }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES            }
{   (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE     }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS    }
{   LICENSED TO DISTRIBUTE THE EXPRESSEDITORS AND ALL                }
{   ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{                                                                    }
{   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 DEVELOPER EXPRESS INC.                       }
{                                                                    }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON        }
{   ADDITIONAL RESTRICTIONS.                                         }
{                                                                    }
{********************************************************************}

unit cxProgressBar;

{$I cxVer.inc}

interface

uses
{$IFDEF DELPHI6}
  Types, Variants,
{$ENDIF}
  Windows, Classes, Controls, Forms, Graphics, Messages, SysUtils, cxClasses,
  cxContainer, cxControls, cxCustomData, cxEdit, cxExtEditConsts,
  cxFilterControlUtils, cxGraphics, cxTextEdit, cxVariants;

const
  cxProgressBarDefaultAnimationSpeed = 10;
  cxProgressBarDefaultAnimationRestartDelay = 0;
type
  TcxBorderWidth = 0..MaxWord;
  TcxProgressBarAnimationSpeed = 0..20;
  TcxProgressBarBevelOuter = (cxbvNone, cxbvLowered, cxbvRaised);
  TcxProgressBarOrientation = (cxorHorizontal, cxorVertical);
  TcxProgressBarTextStyle = (cxtsPercent, cxtsPosition, cxtsText);
  TcxProgressBarBarStyle = (cxbsSolid, cxbsLEDs, cxbsGradient,
    cxbsGradientLEDs, cxbsBitmap, cxbsBitmapLEDs, cxbsAnimation,
    cxbsAnimationLEDs);
  TcxProgressBarAnimationPath = (cxapCycle, cxapPingPong);

const
  cxDefaultShowTextStyle = cxtsPercent;

type
  { TcxCustomProgressBarViewInfo }

  TcxCustomProgressBar = class;

  TcxCustomProgressBarViewInfo = class(TcxCustomTextEditViewInfo)
  private
    FAnimationPath: TcxProgressBarAnimationPath;
    FAnimationRestartDelay: Cardinal;
    FAnimationPosition: Integer;
    FAnimationDirection: Integer;
    FAnimationSpeed: Cardinal;
    FAnimationTimer: TcxTimer;
    FAnimationRestartDelayTimer: TcxTimer;
    FBeginColor: TColor;
    FBarBevelOuter: TcxProgressBarBevelOuter;
    FUsualBitmap: TcxBitmap;
    FPainterBitmap: TcxBitmap;
    FEndColor: TColor;
    FMarquee: Boolean;
    FMax: Double;
    FMin: Double;
    FNativeBitmap: TBitmap;
    FPosition: Double;
    FForegroundImage: TBitmap;
    FOrientation: TcxProgressBarOrientation;
    FShowText: Boolean;
    FShowTextStyle: TcxProgressBarTextStyle;
    FTextOrientation: TcxProgressBarOrientation;
    FSolidTextColor: Boolean;
    FBarStyle: TcxProgressBarBarStyle;
    FOverloadValue: Double;
    FOverloadBeginColor: TColor;
    FOverloadEndColor: TColor;
    FShowOverload: Boolean;
    FPeakValue: Double;
    FPeakColor: TColor;
    FPeakSize: TcxNaturalNumber;
    FShowPeak: Boolean;
    FRealShowOverload: Boolean;
    FRealShowPeak: Boolean;
    FPropTransparent: Boolean;
    procedure CalcDrawingParams(out ADrawProgressBarRect, ADrawOverloadBarRect,
      ADrawPeakBarRect, ADrawAnimationBarRect, ASolidRect: TRect; out ALEDsWidth: Integer);
    function CanAnimationBarShow: Boolean;
    procedure CreateBarBmp;
    procedure CreateNativeBitmap(const ASize: TSize);
    procedure CreatePainterBitmap;
    procedure ExcludeRects(ACanvas: TcxCanvas; const ABounds: TRect);
    procedure ExcludeLEDRects(ACanvas: TcxCanvas; const ABounds: TRect);
    function GetAnimationTimerInterval: Cardinal;
    function GetAnimationOffset: Integer;
    function GetMaxMinDiff: Double;
    function GetRelativeOverloadValue: Double;
    function GetRelativePeakValue: Double;
    function GetRelativePosition: Double;
    function IsLEDStyle: Boolean;
    procedure DrawBackground(ACanvas: TcxCanvas; const ACanvasParent: TcxCanvas; const ABounds: TRect);
    function GetDrawDelta: Integer;
    function GetDrawText: string;
    procedure DrawBarCaption(ACanvas: TcxCanvas);
    procedure PaintBarBevelOuter(ACanvas: TcxCanvas; ABBORect: TRect);
    procedure DrawBarBitmap(ACanvas: TcxCanvas; ARect: TRect);
    procedure DrawGradientBar(ACanvas: TcxCanvas; const ANormalRect, AOverloadRect, ABarRect: TRect);
    procedure DrawSolidBar(ACanvas: TcxCanvas; const ANormalRect, AOverloadRect: TRect);
    procedure DrawAnimationBar(ACanvas: TcxCanvas; const ABar, ASolidRect: TRect);
    procedure DrawAnimationBarBackground(ACanvas: TcxCanvas; const ASolidRect: TRect; ASolidColor: TColor; ADrawBar: Boolean);
    function CalcLEDsWidth: Integer;
    procedure AdjustForLEDsBarBounds(var ABarRect, AOverloadBarRect: TRect; const ALEDsWidth: Integer);
    procedure DrawPeak(ACanvas: TcxCanvas; const APeakRect: TRect);
    procedure DrawBorderLEDs(ACanvas: TcxCanvas; const ABarRect: TRect; ALEDsWidth: Integer);
    procedure DoAnimationTimer(Sender: TObject);
    procedure DoAnimationRestartDelayTimer(Sender: TObject);
    procedure StartAnimationTimer;
    procedure StartAnimationRestartDelayTimer;
    procedure StopAnimationTimer;
    procedure StopAnimationRestartDelayTimer;
    procedure SetAnimationPath(AValue: TcxProgressBarAnimationPath);
    procedure SetAnimationSpeed(AValue: Cardinal);
    procedure SetMarquee(AValue: Boolean);
    procedure SetBarStyle(AValue: TcxProgressBarBarStyle);
    procedure SetAnimationFirstPosition;
    procedure CalcAnimationCurrentPosition;
    function GetCorrectAnimationBarRect: TRect;
    function GetMinPositionInBounds: Integer;
    function GetMaxPositionInBounds: Integer;
    procedure SetOrientation(AValue: TcxProgressBarOrientation);
  protected
    ChangedBounds: Boolean;
    ChangedBoundsBarRect: Boolean;
    BarRect: TRect;
    ProgressBarRect: TRect;
    OverloadBarRect: TRect;
    PeakBarRect: TRect;
    AnimationBarRect: TRect;
    procedure PaintProgressBarByPainter(ACanvas: TcxCanvas);
    function GetAnimationBarDimension: Integer; virtual;
    function GetAnimationDerection: Integer; virtual;

    property AnimationPath: TcxProgressBarAnimationPath read FAnimationPath
      write SetAnimationPath;
    property AnimationRestartDelay: Cardinal read FAnimationRestartDelay write FAnimationRestartDelay;
    property AnimationSpeed: Cardinal read FAnimationSpeed write SetAnimationSpeed;
    property BeginColor: TColor read FBeginColor write FBeginColor;
    property BarBevelOuter: TcxProgressBarBevelOuter read FBarBevelOuter
      write FBarBevelOuter;
    property EndColor: TColor read FEndColor write FEndColor;
    property Marquee: Boolean read FMarquee write SetMarquee;
    property Min: Double read FMin write FMin;
    property Max: Double read FMax write FMax;
    property MaxMinDiff: Double read GetMaxMinDiff;
    property OverloadValue: Double read FOverloadValue write FOverloadValue;
    property PeakValue: Double read FPeakValue write FPeakValue;
    property Position: Double read FPosition write FPosition;
    property RelativePeakValue: Double read GetRelativePeakValue;
    property RelativeOverloadValue: Double read GetRelativeOverloadValue;
    property RelativePosition: Double read GetRelativePosition;

    property ForegroundImage: TBitmap read FForegroundImage write FForegroundImage;
    property Orientation: TcxProgressBarOrientation read FOrientation write SetOrientation;
    property ShowText: Boolean read FShowText write FShowText;
    property ShowTextStyle: TcxProgressBarTextStyle read FShowTextStyle write FShowTextStyle;
    property TextOrientation: TcxProgressBarOrientation read FTextOrientation
      write FTextOrientation;
    property SolidTextColor: Boolean read FSolidTextColor write FSolidTextColor;
    property BarStyle: TcxProgressBarBarStyle read FBarStyle write SetBarStyle;
    property OverloadBeginColor: TColor read FOverloadBeginColor write FOverloadBeginColor;
    property OverloadEndColor: TColor read FOverloadEndColor write FOverloadEndColor;
    property PeakColor: TColor read FPeakColor write FPeakColor;
    property PeakSize: TcxNaturalNumber read FPeakSize write FPeakSize;
    property ShowOverload: Boolean read FShowOverload write FShowOverload;
    property ShowPeak: Boolean read FShowPeak write FShowPeak;
    property PropTransparent: Boolean read FPropTransparent write FPropTransparent;
  public
    FocusRect: TRect;
    HasForegroundImage: Boolean;
    constructor Create; override;
    destructor Destroy; override;
    procedure DrawText(ACanvas: TcxCanvas); override;
    function GetPercentDone: Integer;
    function GetUpdateRegion(AViewInfo: TcxContainerViewInfo): TcxRegion; override;
    function NeedShowHint(ACanvas: TcxCanvas; const P: TPoint; out AText: TCaption;
      out AIsMultiLine: Boolean; out ATextRect: TRect): Boolean; override;
    procedure Paint(ACanvas: TcxCanvas); override;
    procedure PaintProgressBar(ACanvas: TcxCanvas); virtual;
    procedure Offset(DX: Integer; DY: Integer); override;
  end;

  { TcxCustomProgressBarViewData }

  TcxCustomProgressBarProperties = class;

  TcxCustomProgressBarViewData = class(TcxCustomEditViewData)
  private
    function GetProperties: TcxCustomProgressBarProperties;
  protected
    procedure CalculateViewInfoProperties(AViewInfo: TcxCustomEditViewInfo); virtual;
    function InternalGetEditConstantPartSize(ACanvas: TcxCanvas; AIsInplace: Boolean;
      AEditSizeProperties: TcxEditSizeProperties;
      var MinContentSize: TSize; AViewInfo: TcxCustomEditViewInfo): TSize; override;
    function GetDrawTextFlags: Integer; virtual;
    function GetIsEditClass: Boolean;
  public
    procedure Calculate(ACanvas: TcxCanvas; const ABounds: TRect; const P: TPoint;
      Button: TcxMouseButton; Shift: TShiftState; AViewInfo: TcxCustomEditViewInfo;
      AIsMouseEvent: Boolean); override;
    procedure CalculateButtonsViewInfo(ACanvas: TcxCanvas; const ABounds: TRect; const P: TPoint;
      Button: TcxMouseButton; Shift: TShiftState; AViewInfo: TcxCustomEditViewInfo;
      AIsMouseEvent: Boolean); override;
    procedure EditValueToDrawValue(ACanvas: TcxCanvas; const AEditValue: TcxEditValue;
      AViewInfo: TcxCustomEditViewInfo); override;
    property Properties: TcxCustomProgressBarProperties read GetProperties;
  end;

  { TcxProgressBarPropertiesValues }

  TcxProgressBarPropertiesValues = class(TcxCustomEditPropertiesValues)
  private
    function GetMax: Boolean;
    function GetMin: Boolean;
    function IsMaxStored: Boolean;
    function IsMinStored: Boolean;
    procedure SetMax(Value: Boolean);
    procedure SetMin(Value: Boolean);
  published
    property Max: Boolean read GetMax write SetMax stored IsMaxStored;
    property Min: Boolean read GetMin write SetMin stored IsMinStored;
  end;

  { TcxCustomProgressBarProperties }

  TcxCustomProgressBarProperties = class(TcxCustomEditProperties)
  private
    FAnimationPath: TcxProgressBarAnimationPath;
    FAnimationRestartDelay: Cardinal;
    FAnimationSpeed: TcxProgressBarAnimationSpeed;
    FBeginColor: TColor;
    FBarBevelOuter: TcxProgressBarBevelOuter;
    FChangedForegroundImage: Boolean;
    FChangedPosition: Boolean;
    FEndColor: TColor;
    FForegroundImage: TBitmap;
    FMarquee: Boolean;
    FOrientation: TcxProgressBarOrientation;
    FShowText: Boolean;
    FShowTextStyle: TcxProgressBarTextStyle;
    FText: string;
    FTextOrientation: TcxProgressBarOrientation;
    FSolidTextColor: Boolean;
    FBarStyle: TcxProgressBarBarStyle;
    FTransparentImage: Boolean;
    FBorderWidth: TcxBorderWidth;
    FOverloadValue: Double;
    FShowOverload: Boolean;
    FOverloadBeginColor: TColor;
    FOverloadEndColor: TColor;
    FPeakValue: Double;
    FShowPeak: Boolean;
    FPeakColor: TColor;
    FPeakSize: TcxNaturalNumber;
    function GetAssignedValues: TcxProgressBarPropertiesValues;
    function GetForegroundImage: TBitmap;
    procedure ForegroundImageChanged(Sender: TObject);
    function GetMax: Double;
    function GetMin: Double;
    function GetOverloadValueStored: Boolean;
    function GetPeakValueStored: Boolean;
    function GetRealPeakValue(APosition: Double): Double;
    function IsMaxStored: Boolean;
    function IsMinStored: Boolean;
    function IsShowTextStyleStored: Boolean;
    procedure SetAnimationPath(AValue: TcxProgressBarAnimationPath);
    procedure SetAnimationRestartDelay(AValue: Cardinal);
    procedure SetAnimationSpeed(AValue: TcxProgressBarAnimationSpeed);
    procedure SetAssignedValues(Value: TcxProgressBarPropertiesValues);
    procedure SetBeginColor(Value: TColor);
    procedure SetBarBevelOuter(Value: TcxProgressBarBevelOuter);
    procedure SetColorVista;
    procedure SetEndColor(Value: TColor);
    procedure SetForegroundImage(Value: TBitmap);
    procedure SetMarquee(Value: Boolean);
    procedure SetMax(Value: Double);
    procedure SetMin(Value: Double);
    procedure SetOrientation(Value: TcxProgressBarOrientation);
    procedure SetShowText(Value: Boolean);
    procedure SetShowTextStyle(Value: TcxProgressBarTextStyle);
    procedure SetTextOrientation(Value: TcxProgressBarOrientation);
    procedure SetSolidTextColor(Value: Boolean);
    procedure SetBarStyle(Value: TcxProgressBarBarStyle);
    procedure SetText(const AValue: string);
    procedure SetTransparentImage(Value: Boolean);
    procedure SetBorderWidth(Value: TcxBorderWidth);
    procedure SetOverloadValue(Value: Double);
    procedure SetShowOverload(Value: Boolean);
    procedure SetOverloadBeginColor(Value: TColor);
    procedure SetOverloadEndColor(Value: TColor);
    procedure SetPeakValue(Value: Double);
    procedure SetShowPeak(Value: Boolean);
    procedure SetPeakColor(Value: TColor);
    procedure SetPeakSize(Value: TcxNaturalNumber);
    procedure PostMinValue;
    procedure PostMaxValue;
    procedure PostOverloadValue;
  protected
    procedure CorrectPositionWithMaxMin(
      AViewInfo: TcxCustomProgressBarViewInfo); virtual;
    class function GetAssignedValuesClass: TcxCustomEditPropertiesValuesClass; override;
    function GetMaxValue: Double; override;
    function GetMinValue: Double; override;
    class function GetViewDataClass: TcxCustomEditViewDataClass; override;
    function HasDisplayValue: Boolean; override;
    property AssignedValues: TcxProgressBarPropertiesValues read GetAssignedValues
      write SetAssignedValues;
    property ChangedForegroundImage: Boolean read FChangedForegroundImage
      write FChangedForegroundImage default False;
    property ChangedPosition: Boolean read FChangedPosition
      write FChangedPosition default False;
  public
    constructor Create(AOwner: TPersistent); override;

⌨️ 快捷键说明

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