cxedit.pas

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

PAS
1,387
字号
{********************************************************************}
{                                                                    }
{       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 cxEdit;

{$I cxVer.inc}

interface

uses
  Windows, Messages,
{$IFDEF DELPHI6}
  Variants,
{$ENDIF}
  ComCtrls, Classes, Controls, Forms, Graphics, Menus, StdCtrls, SysUtils,
  cxClasses, cxContainer, cxControls, cxDataStorage, cxDataUtils,
  cxEditPaintUtils, cxGraphics, cxLookAndFeels, cxVariants, cxLookAndFeelPainters;

type
  TcxBlobKind = (bkNone, bkBlob, bkGraphic, bkMemo, bkOle);
  TcxEditBorderStyle = (ebsNone, ebsSingle, ebsThick, ebsFlat, ebs3D,
    ebsUltraFlat, ebsOffice11);
  TcxEditButtonKind = (bkEllipsis, bkDown, bkGlyph, bkText);
  TcxEditButtonState = (ebsDisabled, ebsNormal, ebsPressed, ebsSelected);
  TcxEditButtonStyle = (btsDefault, bts3D, btsFlat, btsSimple, btsHotFlat,
    btsUltraFlat, btsOffice11);
  TcxEditButtonsViewStyle = (bvsNormal, bvsButtonsOnly, bvsButtonsAutoWidth);
  TcxEditButtonTransparency = (ebtNone, ebtInactive, ebtAlways, ebtHideInactive,
    ebtHideUnselected);
  TcxEditGradientDirection = dirLeft..dirDown;
  TcxEditPopupBorderStyle = (epbsDefault, epbsSingle, epbsFrame3D, epbsFlat);

  TcxEditStyleValue = TcxContainerStyleValue;
  TcxEditStyleValues = TcxContainerStyleValues;

  TcxEditHorzAlignment = TAlignment;
  TcxEditVertAlignment = (taTopJustify, taBottomJustify, taVCenter);

const
  cxEditDefaultPrecision = 15;
  cxEditDefaultUseLeftAlignmentOnEditing = True;
  cxEditDefaultHorzAlignment: TcxEditHorzAlignment = taLeftJustify;
  cxEditDefaultVertAlignment: TcxEditVertAlignment = taTopJustify;
  cxInplaceEditOffset = 1;

  ekDefault = 0;

  svBorderColor        = csvBorderColor;
  svBorderStyle        = csvBorderStyle;
  svColor              = csvColor;
  svEdges              = csvEdges;
  svFont               = csvFont;
  svHotTrack           = csvHotTrack;
  svShadow             = csvShadow;
  svTextColor          = csvTextColor;
  svTextStyle          = csvTextStyle;
  svTransparentBorder  = csvTransparentBorder;
  svButtonStyle        = cxContainerStyleValueCount;
  svButtonTransparency = cxContainerStyleValueCount + 1;
  svPopupBorderStyle   = cxContainerStyleValueCount + 2;
  svGradientButtons    = cxContainerStyleValueCount + 3;
  svGradient           = cxContainerStyleValueCount + 4;
  svGradientDirection  = cxContainerStyleValueCount + 5;

  cxEditStyleValueCount = cxContainerStyleValueCount + 6;

  cxEditStyleValueNameA: array[0..cxEditStyleValueCount - cxContainerStyleValueCount - 1] of string = (
    'ButtonStyle',
    'ButtonTransparency',
    'PopupBorderStyle',
    'GradientButtons',
    'Gradient',
    'GradientDirection'
  );

  EditContentDefaultOffsets: array [Boolean] of TRect = (
    (Left: 1; Top: 1; Right: 1; Bottom: 3),
    (Left: 1; Top: 1; Right: 1; Bottom: 1)
  );

  EditBtnState2ButtonState: array[TcxEditButtonState] of TcxButtonState =
      (cxbsDisabled, cxbsNormal, cxbsPressed, cxbsHot);
type
  TcxEditDisplayFormatOption = (dfoSupports, dfoNoCurrencyValue);
  TcxEditDisplayFormatOptions = set of TcxEditDisplayFormatOption;
  TcxEditBackgroundPaintingStyle = (bpsSolid, bpsComboEdit, bpsComboListEdit);
  TcxEditEditingStyle = (esEdit, esEditList, esFixedList, esNoEdit);
  TcxEditPaintOption = (epoAllowZeroHeight, epoAutoHeight, epoHasExternalBorder,
    epoShowEndEllipsis, epoShowFocusRectWhenInplace);
  TcxEditPaintOptions = set of TcxEditPaintOption;
  TcxEditSpecialFeatures = set of (esfBlobEditValue, esfMinSize,
    esfNoContentPart);
  TcxEditSupportedOperation = (esoAlwaysHotTrack, esoAutoHeight, esoEditing,
    esoFiltering, esoHorzAlignment, esoHotTrack, esoIncSearch,
    esoShowingCaption, esoSorting, esoSortingByDisplayText, esoTransparency);
  TcxEditSupportedOperations = set of TcxEditSupportedOperation;
  TcxEditValue = Variant;
  PcxEditValue = ^TcxEditValue;
  TcxEditValidateEvent = procedure(Sender: TObject; var DisplayValue: TcxEditValue;
    var ErrorText: TCaption; var Error: Boolean) of object;
  TcxEditErrorKind = Integer;
  TcxCustomEdit = class;
  TcxCustomEditStyle = class;

  EcxEditError = class(Exception);
  EcxEditValidationError = class(EcxEditError);

  { IcxCustomInnerEdit }

  IcxCustomInnerEdit = interface(IcxContainerInnerControl)
  ['{468D21B5-48AA-4077-8ED5-4C6112D460B1}']
    function CallDefWndProc(AMsg: UINT; WParam: WPARAM;
      LParam: LPARAM): LRESULT;
    function GetEditValue: TcxEditValue;
    function GetOnChange: TNotifyEvent;
    function GetReadOnly: Boolean;
    procedure LockBounds(ALock: Boolean);
    procedure SafelySetFocus;
    procedure SetEditValue(const Value: TcxEditValue);
    procedure SetParent(Value: TWinControl);
    procedure SetOnChange(Value: TNotifyEvent);
    procedure SetReadOnly(Value: Boolean);
    property EditValue: TcxEditValue read GetEditValue write SetEditValue;
    property Parent: TWinControl write SetParent;
    property ReadOnly: Boolean read GetReadOnly write SetReadOnly;
    property OnChange: TNotifyEvent read GetOnChange write SetOnChange;
  end;

  IcxInnerEditHelper = interface
  ['{35667555-6DC8-40D5-B705-B08D5697C621}']
    function GetHelper: IcxCustomInnerEdit;
  end;

  TcxCustomEditProperties = class;
  TcxCustomEditPropertiesClass = class of TcxCustomEditProperties;
  TcxEditRepository = class;
  TcxEditRepositoryItem = class;

  { IcxEditRepositoryItemListener }

  IcxEditRepositoryItemListener = interface
    ['{4E27D642-022B-4CD2-AB96-64C7CF9B3299}']
    procedure ItemRemoved(Sender: TcxEditRepositoryItem);
    procedure PropertiesChanged(Sender: TcxEditRepositoryItem);
  end;

  { TcxEditRepositoryItem }

  TcxEditRepositoryItem = class(TComponent)
  private
    FListenerList: IInterfaceList;
    FProperties: TcxCustomEditProperties;
    FPropertiesEvents: TNotifyEvent;
    FRepository: TcxEditRepository;
    procedure SetProperties(Value: TcxCustomEditProperties);
    procedure SetRepository(Value: TcxEditRepository);
  protected
    procedure PropertiesChanged(Sender: TObject); virtual;
    procedure ReadState(Reader: TReader); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure AddListener(AListener: IcxEditRepositoryItemListener); virtual;
    class function GetEditPropertiesClass: TcxCustomEditPropertiesClass; virtual;
    function GetBaseName: string; virtual;
    function GetParentComponent: TComponent; override;
    function HasParent: Boolean; override;
    procedure RemoveListener(AListener: IcxEditRepositoryItemListener); virtual;
    procedure SetParentComponent(AParent: TComponent); override;
    property Properties: TcxCustomEditProperties read FProperties
      write SetProperties;
    property Repository: TcxEditRepository read FRepository write SetRepository;
  published
    property PropertiesEvents: TNotifyEvent read FPropertiesEvents
      write FPropertiesEvents;
  end;

  TcxEditRepositoryItemClass = class of TcxEditRepositoryItem;

  IcxEditDefaultValuesProvider = interface
    ['{AE727882-6FDF-4E3A-AB35-E58AB28EFE7B}']
    function CanSetEditMode: Boolean;
    procedure ClearUsers;
    function DefaultAlignment: TAlignment;
    function DefaultBlobKind: TcxBlobKind;
    function DefaultCanModify: Boolean;
    function DefaultDisplayFormat: string;
    function DefaultEditFormat: string;
    function DefaultEditMask: string;
    function DefaultIsFloatValue: Boolean;
    function DefaultMaxLength: Integer;
    function DefaultMaxValue: Double;
    function DefaultMinValue: Double;
    function DefaultPrecision: Integer;
    function DefaultReadOnly: Boolean;
    function DefaultRequired: Boolean;
    function GetInstance: TObject;
    function IsDataStorage: Boolean;
    function IsBlob: Boolean;
    function IsCurrency: Boolean;
    function IsDataAvailable: Boolean;
    function IsDisplayFormatDefined(AIsCurrencyValueAccepted: Boolean): Boolean;
    function IsOnGetTextAssigned: Boolean;
    function IsOnSetTextAssigned: Boolean;
    function IsValidChar(AChar: Char): Boolean;
  end;

  { TcxEditRepository }

  TcxEditRepository = class(TComponent)
  private
    FItems: TList;
    function GetCount: Integer;
    function GetItem(Index: Integer): TcxEditRepositoryItem;
  protected
    procedure AddItem(AItem: TcxEditRepositoryItem);
    procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
    procedure RemoveItem(AItem: TcxEditRepositoryItem);
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Clear;
    function CreateItem(ARepositoryItemClass: TcxEditRepositoryItemClass): TcxEditRepositoryItem; virtual;
    function CreateItemEx(ARepositoryItemClass: TcxEditRepositoryItemClass; AOwner: TComponent): TcxEditRepositoryItem; virtual;
    function ItemByName(ARepositoryItemName: string): TcxEditRepositoryItem;
    property Count: Integer read GetCount;
    property Items[Index: Integer]: TcxEditRepositoryItem read GetItem; default;
  end;

  { TcxEditButtonViewInfo }

  TcxEditButtonViewInfoData = record
    BackgroundColor: TColor;
    Caption: string;
    ContentAlignment: TAlignment;
    Default: Boolean;
    Gradient: Boolean;
    IsInplace: Boolean;
    Kind: TcxEditButtonKind;
    LeftAlignment: Boolean;
    Leftmost: Boolean;
    NativeStyle: Boolean;
    Rightmost: Boolean;
    State: TcxEditButtonState;
    Style: TcxEditButtonStyle;
    TextColor: TColor;
    Transparent: Boolean;

⌨️ 快捷键说明

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