cxcheckbox.pas

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

PAS
1,873
字号

{********************************************************************}
{                                                                    }
{       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 cxCheckBox;

{$I cxVer.inc}

interface

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

const
  cxEditCheckBoxSingleBorderDefaultColor = clBtnShadow;

type
  TcxCheckBoxNullValueShowingStyle = (nssUnchecked, nssInactive, nssGrayedChecked);
  TcxCheckStatesValueFormat = (cvfCaptions, cvfIndices, cvfInteger,
    cvfStatesString);
  TcxCheckStates = array of TcxCheckBoxState;
  TcxEditCheckBoxBorderStyle = TcxEditBorderStyle;
  TcxEditCheckState = (ecsNormal, ecsHot, ecsPressed, ecsDisabled);

  TcxCheckStatesToValueEvent = procedure(Sender: TObject;
    const ACheckStates: TcxCheckStates; out AValue: TcxEditValue) of object;
  TcxValueToCheckStatesEvent = procedure(Sender: TObject;
    const AValue: TcxEditValue; var ACheckStates: TcxCheckStates) of object;

  { IcxCheckItems }

  IcxCheckItems = interface
  ['{5BF13228-CF05-4741-9833-F2B8FBFD57ED}']
    function GetCaption(Index: Integer): string;
    function GetCount: Integer;
    property Captions[Index: Integer]: string read GetCaption;
    property Count: Integer read GetCount;
  end;

  { TcxCustomCheckBoxViewInfo }

  TcxCustomCheckBox = class;

  TcxCustomCheckBoxViewInfo = class(TcxCustomTextEditViewInfo)
  private
    function GetEdit: TcxCustomCheckBox;
  protected
    function IsTextEnabled: Boolean;
    procedure InternalPaint(ACanvas: TcxCanvas); override;
  public
    Alignment: TAlignment;
    CheckBorderOffset: Integer;
    CheckBoxBorderStyle: TcxEditCheckBoxBorderStyle;
    CheckBoxGlyph: TBitmap;
    CheckBoxGlyphCount: Integer;
    CheckBoxRect: TRect;
    CheckBoxState: TcxEditCheckState;
    DrawCaptionFlags: Integer;
    FocusRect: TRect;
    HasGlyph: Boolean;
    IsTextColorAssigned: Boolean;
    NullValueShowingStyle: TcxCheckBoxNullValueShowingStyle;
    State: TcxCheckBoxState;
    procedure Assign(Source: TObject); override;
    procedure DrawText(ACanvas: TcxCanvas); override;
    function GetUpdateRegion(AViewInfo: TcxContainerViewInfo): TcxRegion; override;
    function IsHotTrack: Boolean; override;
    function IsHotTrack(P: TPoint): Boolean; override;
    function NeedShowHint(ACanvas: TcxCanvas; const P: TPoint; out AText: TCaption;
      out AIsMultiLine: Boolean; out ATextRect: TRect): Boolean; override;
    procedure Offset(DX, DY: Integer); override;
    function Repaint(AControl: TWinControl; const AInnerEditRect: TRect;
      AViewInfo: TcxContainerViewInfo = nil): Boolean; override;
    property Edit: TcxCustomCheckBox read GetEdit;
  end;

  { TcxCustomCheckBoxViewData }

  TcxCustomCheckBoxProperties = class;

  TcxCustomCheckBoxViewData = class(TcxCustomEditViewData)
  private
    function GetProperties: TcxCustomCheckBoxProperties;
  protected
    function InternalGetEditConstantPartSize(ACanvas: TcxCanvas; AIsInplace: Boolean;
      AEditSizeProperties: TcxEditSizeProperties;
      var MinContentSize: TSize; AViewInfo: TcxCustomEditViewInfo): TSize; override;
    function GetDrawTextFlags: Integer; virtual;
    function GetIsEditClass: Boolean;
    function IsCheckPressed: Boolean;
  public
    procedure Calculate(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;
    function GetBorderStyle: TcxEditBorderStyle; override;
    property Properties: TcxCustomCheckBoxProperties read GetProperties;
  end;

  { TcxCheckBoxStyle }

  TcxCheckBoxStyle = class(TcxEditStyle)
  public
    function HasBorder: Boolean; override;
  end;

  { TcxCustomCheckBoxProperties }

  TcxCustomCheckBoxProperties = class(TcxCustomEditProperties)
  private
    FAllowGrayed: Boolean;
    FCaption: TCaption; // obsolete
    FDisplayChecked: WideString;
    FDisplayGrayed: WideString;
    FDisplayUnchecked: WideString;
    FFullFocusRect: Boolean;
    FGlyph: TBitmap;
    FGlyphCount: Integer;
    FIsCaptionAssigned: Boolean; // obsolete
    FMultiLine: Boolean;
    FNullStyle: TcxCheckBoxNullValueShowingStyle;
    FUseAlignmentWhenInplace: Boolean;
    FValueChecked: TcxEditValue;
    FValueGrayed: TcxEditValue;
    FValueUnchecked: TcxEditValue;
    function GetAlignment: TAlignment;
    function GetGlyph: TBitmap;
    function GetInternalAlignment: TcxEditAlignment;
    procedure GlyphChanged(Sender: TObject);
    function IsAlignmentStored: Boolean;
    function IsDisplayCheckedStored: Boolean;
    function IsDisplayGrayedStored: Boolean;
    function IsDisplayUncheckedStored: Boolean;
    function IsLoading: Boolean;
    function IsValueCheckedStored: Boolean;
    function IsValueGrayedStored: Boolean;
    function IsValueUncheckedStored: Boolean;
    procedure ReadCaption(Reader: TReader); // obsolete
    procedure SetAlignment(Value: TAlignment);
    procedure SetCaption(const Value: TCaption); // obsolete
    procedure SetFullFocusRect(Value: Boolean);
    procedure SetGlyph(Value: TBitmap);
    procedure SetGlyphCount(Value: Integer);
    procedure SetMultiLine(Value: Boolean);
    procedure SetNullStyle(Value: TcxCheckBoxNullValueShowingStyle);
    procedure SetStateValues(const AValueChecked, AValueGrayed, AValueUnchecked: TcxEditValue);
    procedure SetUseAlignmentWhenInplace(Value: Boolean);
    procedure SetValueChecked(const Value: TcxEditValue);
    procedure SetValueGrayed(const Value: TcxEditValue);
    procedure SetValueUnchecked(const Value: TcxEditValue);
  protected
    function CanValidate: Boolean; override;
    procedure DefineProperties(Filer: TFiler); override;
    class function GetViewDataClass: TcxCustomEditViewDataClass; override;
    function HasDisplayValue: Boolean; override;
    function CheckValue(const AValue: TcxEditValue): Boolean;
    function GetState(const AEditValue: TcxEditValue): TcxCheckBoxState;
    function InternalGetGlyph: TBitmap; virtual;
    function IsEmbeddedEdit: Boolean; virtual;
    property InternalAlignment: TcxEditAlignment read GetInternalAlignment;
  public
    constructor Create(AOwner: TPersistent); override;
    destructor Destroy; override;
    procedure Assign(Source: TPersistent); override;
    function CanCompareEditValue: Boolean; override;
    function CompareDisplayValues(
      const AEditValue1, AEditValue2: TcxEditValue): Boolean; override;
    class function GetContainerClass: TcxContainerClass; override;
    function GetDisplayText(const AEditValue: TcxEditValue;
      AFullText: Boolean = False; AIsInplace: Boolean = True): WideString; override;
    class function GetStyleClass: TcxCustomEditStyleClass; override;
    function GetSpecialFeatures: TcxEditSpecialFeatures; override;
    function GetSupportedOperations: TcxEditSupportedOperations; override;
    class function GetViewInfoClass: TcxContainerViewInfoClass; override;
    function IsActivationKey(AKey: Char): Boolean; override;
    function IsEditValueValid(var EditValue: TcxEditValue; AEditFocused: Boolean): Boolean; override;
    function IsResetEditClass: Boolean; override;
    procedure PrepareDisplayValue(const AEditValue: TcxEditValue;
      var DisplayValue: TcxEditValue; AEditFocused: Boolean); override;
    // !!!
    property Alignment: TAlignment read GetAlignment write SetAlignment
      stored IsAlignmentStored;
//    property AlignmentVert: TcxAlignmentVert read GetAlignmentVert
//      write SetAlignmentVert stored IsAlignmentVertStored;
    property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default False;
    property Caption: TCaption read FCaption write SetCaption stored False; // obsolete
    property DisplayChecked: WideString read FDisplayChecked write FDisplayChecked
      stored IsDisplayCheckedStored;
    property DisplayGrayed: WideString read FDisplayGrayed write FDisplayGrayed
      stored IsDisplayGrayedStored;
    property DisplayUnchecked: WideString read FDisplayUnchecked write FDisplayUnchecked
      stored IsDisplayUncheckedStored;
    property FullFocusRect: Boolean read FFullFocusRect write SetFullFocusRect default False;
    property Glyph: TBitmap read GetGlyph write SetGlyph;
    property GlyphCount: Integer read FGlyphCount write SetGlyphCount default 6;
    property MultiLine: Boolean read FMultiLine write SetMultiLine default False;
    property NullStyle: TcxCheckBoxNullValueShowingStyle read FNullStyle write
      SetNullStyle default nssGrayedChecked;
    property UseAlignmentWhenInplace: Boolean read FUseAlignmentWhenInplace
      write SetUseAlignmentWhenInplace default False;
    property ValueChecked: TcxEditValue read FValueChecked write SetValueChecked
      stored IsValueCheckedStored;
    property ValueGrayed: TcxEditValue read FValueGrayed write SetValueGrayed
      stored IsValueGrayedStored;
    property ValueUnchecked: TcxEditValue read FValueUnchecked write SetValueUnchecked
      stored IsValueUncheckedStored;
  end;

  { TcxCheckBoxProperties }

  TcxCheckBoxProperties = class(TcxCustomCheckBoxProperties)
  published
    property Alignment;
    property AllowGrayed;
    property AssignedValues;
    property Caption; // obsolete
    property ClearKey;
    property DisplayChecked;
    property DisplayUnchecked;
    property DisplayGrayed;
    property FullFocusRect;
    property Glyph;
    property GlyphCount;
    property ImmediatePost;
    property MultiLine;
    property NullStyle;
    property ReadOnly;
    property UseAlignmentWhenInplace;
    property ValueChecked;
    property ValueGrayed;
    property ValueUnchecked;
    property OnChange;
    property OnEditValueChanged;
    property OnValidate;
  end;

  { TcxCustomCheckBox }

  TcxCustomCheckBox = class(TcxCustomEdit)
  private
    FIsCheckPressed: Boolean;
    FIsLoaded: Boolean;
    FIsLoadingStateAssigned: Boolean;
    FLoadingState: TcxCheckBoxState;
    function GetChecked: Boolean;
    function GetProperties: TcxCustomCheckBoxProperties;
    function GetActiveProperties: TcxCustomCheckBoxProperties;
    function GetState: TcxCheckBoxState;
    function GetStyle: TcxCheckBoxStyle;
    function GetViewInfo: TcxCustomCheckBoxViewInfo;
    function IsStateStored: Boolean;
    procedure SetChecked(Value: Boolean);
    procedure SetProperties(Value: TcxCustomCheckBoxProperties);
    procedure SetState(Value: TcxCheckBoxState);
    procedure SetStyle(Value: TcxCheckBoxStyle);
    procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
    procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
    procedure CMParentColorChanged(var Message: TMessage); message CM_PARENTCOLORCHANGED;
  protected
    procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
    function CanHaveTransparentBorder: Boolean; override;
    function DefaultParentColor: Boolean; override;
    procedure DoEditKeyDown(var Key: Word; Shift: TShiftState); override;
    procedure DoEditKeyPress(var Key: Char); override;
    procedure DoEditKeyUp(var Key: Word; Shift: TShiftState); override;
    procedure DoExit; override;
    procedure FillSizeProperties(var AEditSizeProperties: TcxEditSizeProperties); override;
    function GetActionLinkClass: TControlActionLinkClass; override;
    function GetShadowBounds: TRect; override;
    procedure Initialize; override;
    function InternalGetNotPublishedStyleValues: TcxEditStyleValues; override;
    procedure InternalSetEditValue(const Value: TcxEditValue;
      AValidateEditValue: Boolean); override;
    function IsClickEnabledDuringLoading: Boolean; override;
    function IsNativeBackground: Boolean; override;
    procedure Loaded; override;
    procedure ProcessViewInfoChanges(APrevViewInfo: TcxCustomEditViewInfo;
      AIsMouseDownUpEvent: Boolean); override;
    procedure PropertiesChanged(Sender: TObject); override;
    procedure TextChanged; override;
    procedure InvalidateCheckRect;
    procedure Toggle; virtual;
    property Caption;
    property Checked: Boolean read GetChecked write SetChecked stored False;
    property ViewInfo: TcxCustomCheckBoxViewInfo read GetViewInfo;
  public
    procedure Clear; override;
    class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
    procedure PrepareEditValue(const ADisplayValue: TcxEditValue;
      out EditValue: TcxEditValue; AEditFocused: Boolean); override;
    property ActiveProperties: TcxCustomCheckBoxProperties read GetActiveProperties;
    property Properties: TcxCustomCheckBoxProperties read GetProperties
      write SetProperties;
    property State: TcxCheckBoxState read GetState write SetState
      stored IsStateStored default cbsUnchecked;
    property Style: TcxCheckBoxStyle read GetStyle write SetStyle;
    property Transparent;
  end;

  { TcxCheckBox }

  TcxCheckBox = class(TcxCustomCheckBox)
  private
    function GetActiveProperties: TcxCheckBoxProperties;
    function GetProperties: TcxCheckBoxProperties;
    procedure SetProperties(Value: TcxCheckBoxProperties);
  public
    class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
    property ActiveProperties: TcxCheckBoxProperties read GetActiveProperties;
  published
    property Action;
    property Align;
    property Anchors;
    property AutoSize;
    property Caption;
    property Checked;
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property ParentBackground;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property Properties: TcxCheckBoxProperties read GetProperties
      write SetProperties;
    property ShowHint;
    property State;
    property Style;
    property StyleDisabled;
    property StyleFocused;
    property StyleHot;
    property TabOrder;
    property TabStop;
    property Transparent;

⌨️ 快捷键说明

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