cxfontnamecombobox.pas

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

PAS
2,058
字号

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

interface

{$I cxVer.inc}

uses
{$IFDEF DELPHI6}
  Variants,
{$ENDIF}
  Windows, Classes, Controls, Dialogs, Forms, Graphics, Messages, Printers,
  SysUtils, cxClasses, cxContainer, cxControls, cxGraphics, cxButtons,
  cxDataStorage, cxVariants,
  cxEdit, cxTextEdit, cxDropDownEdit, cxEditUtils, cxExtEditConsts, cxExtEditUtils,
  cxImageComboBox, cxLookAndFeels, cxMaskEdit, cxFilterControlUtils;

const
  SYMBOL_FONTTYPE = 256;
  FIXEDPITCH_FONTTYPE = 512;

type
  TcxFontType = (cxftTTF, cxftRaster, cxftDevice, cxftFixed, cxftSymbol);
  TcxFontTypes = set of TcxFontType;
  TcxShowFontIconType = (ftiShowInCombo, ftiShowInList);
  TcxShowFontIconTypes = set of TcxShowFontIconType;
  TcxMRUFontNameAction = (mfaInvalidFontName, mfaNone, mfaMoved, mfaAdded, mfaDeleted);
  TcxFontPreviewType = (cxfpFontName, cxfpCustom, cxfpFullAlphabet);
  TcxDeleteMRUFontEvent = procedure(Sender: TObject; const DeletedMRUFontName: string) of object;

  { TcxMRUFontNameItem }

  TcxMRUFontNameItem = class(TCollectionItem)
  private
    FFontName: TFontName;
    FTag: TcxTag;
    function IsTagStored: Boolean;
    procedure SetFontName(const Value: TFontName);
  public
    procedure Assign(Source: TPersistent); override;
  published
    property FontName: TFontName read FFontName write SetFontName;
    property Tag: TcxTag read FTag write FTag stored IsTagStored;
  end;

  { TcxMRUFontNameItems }

  TcxMRUFontNameItems = class(TOwnedCollection)
  private
    function GetItems(Index: Integer): TcxMRUFontNameItem;
    procedure SetItems(Index: Integer; const Value: TcxMRUFontNameItem);
  protected
    procedure Update(Item: TCollectionItem); override;
    function Add: TcxMRUFontNameItem;
    function Insert(Index: Integer): TcxMRUFontNameItem;
    function AddMRUFontName(const AFontName: TFontName): TcxMRUFontNameItem; virtual;
    function InsertMRUFontName(Index: Integer; const AFontName: TFontName): TcxMRUFontNameItem; virtual;
    procedure Move(CurIndex, NewIndex: Integer); virtual;
  public
    constructor Create(AOwner: TPersistent; ItemClass: TCollectionItemClass);
    destructor Destroy; override;
  {$IFNDEF DELPHI6}
    function Owner: TPersistent;
  {$ENDIF}
    property Items[Index: Integer]: TcxMRUFontNameItem read GetItems write SetItems; default;
    function FindFontName(const AFontName: TFontName): TcxMRUFontNameItem; virtual;
  end;

  { TcxFontLoader }
  
  TcxFontLoader = class(TThread)
  private
    FFontTypes: TcxFontTypes;
    procedure DoCompleteEvent;
    procedure DoDestroyEvent;
  protected
    procedure Execute; override;
  public
    OnCompleteThread: TNotifyEvent;
    OnDestroyThread: TNotifyEvent;
    FontList: TStringList;
    constructor Create(const AFontTypes: TcxFontTypes); virtual;
    destructor Destroy; override;
  end;

  TcxFontButtonType = (cxfbtBold, cxfbtItalic, cxfbtUnderline, cxfbtStrikeOut);
  TcxFontButtonClickEvent = procedure(Sender: TObject; ButtonType: TcxFontButtonType) of Object;

  { TcxFontPreview }

  TcxFontPreview = class(TPersistent)
  private
    FOwner: TPersistent;
    FUpdateCount: Integer;
    FOnChanged: TNotifyEvent;
    FFontStyle: TFontStyles;
    FModified: Boolean;
    FIsDestroying: Boolean;
    FVisible: Boolean;
    FPreviewType: TcxFontPreviewType;
    FPreviewText: TCaption;
    FAlignment: TAlignment;
    FShowEndEllipsis: Boolean;
    FColor: TColor;
    FWordWrap: Boolean;
    FShowButtons: Boolean;
    FOnButtonClick: TcxFontButtonClickEvent;
    procedure BeginUpdate;
    procedure EndUpdate;
    function IsDestroying: Boolean;
    procedure SetFontStyle(Value: TFontStyles);
    procedure SetVisible(Value: Boolean);
    procedure SetPreviewType(Value: TcxFontPreviewType);
    procedure SetPreviewText(Value: TCaption);
    procedure SetAlignment(Value: TAlignment);
    procedure SetShowEndEllipsis(Value: Boolean);
    procedure SetColor(Value: TColor);
    procedure SetWordWrap(Value: Boolean);
    procedure SetShowButtons(Value: Boolean);
  protected
    function GetOwner: TPersistent; override;
    procedure Changed; virtual;
  public
    constructor Create(AOwner: TPersistent); virtual;
    destructor Destroy; override;
    procedure Assign(Source: TPersistent); override;
  published
    property FontStyle: TFontStyles read FFontStyle write SetFontStyle default [];
    property Visible: Boolean read FVisible write SetVisible default True;
    property PreviewType: TcxFontPreviewType read FPreviewType write SetPreviewType default cxfpFontName;
    property PreviewText: TCaption read FPreviewText write SetPreviewText;
    property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
    property ShowButtons: Boolean read FShowButtons write SetShowButtons default True;
    property ShowEndEllipsis: Boolean read FShowEndEllipsis write SetShowEndEllipsis default True;
    property Color: TColor read FColor write SetColor default clWindow;
    property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
    property OnButtonClick: TcxFontButtonClickEvent read FOnButtonClick write FOnButtonClick;
  end;

  { TcxFontPanelButton }

  TcxFontPanelButton = class(TcxButton)
  protected
    procedure WndProc(var Message: TMessage); override;
  end;

  { TFontPreviewPanel }

  TFontPreviewPanel = class(TCustomControl)
  private
    FLocked: Boolean;
    FcxCanvas: TcxCanvas;
    FFontStyle: TFontStyles;
    FAlignment: TAlignment;
    FShowEndEllipsis: Boolean;
    FEdges: TcxBorders;
    FBorderColor: TColor;
    FFontName: string;
    FWordWrap: Boolean;
    FShowButtons: Boolean;
    FLookAndFeel: TcxLookAndFeel;
    FBoldButton: TcxFontPanelButton;
    FItalicButton: TcxFontPanelButton;
    FUnderLineButton: TcxFontPanelButton;
    FStrikeOutButton: TcxFontPanelButton;
    procedure SetLocked(Value: Boolean);
    procedure SetAlignment(Value: TAlignment);
    procedure SetShowEndEllipsis(Value: Boolean);
    procedure SetEdges(Value: TcxBorders);
    procedure SetFontName(Value: string);
    procedure SetFontStyle(Value: TFontStyles);
    procedure SetWordWrap(Value: Boolean);
    procedure SetShowButtons(Value: Boolean);
    procedure SetLookAndFeel(Value: TcxLookAndFeel);
    function GetTextFlag(const AStartFlag: Longint): Longint;
    procedure CreateButtons;
    procedure SetFontStyleButtonsState;
    procedure FontButtonsClickHandler(Sender: TObject);
  protected
    FontPreview: TcxFontPreview;
    procedure Paint; override;
    procedure CalculateFont(const ARect: TRect); virtual;
    function CalculateFontStyle: TFontStyles; virtual;
    property cxCanvas: TcxCanvas read FcxCanvas write FcxCanvas;
    property Locked: Boolean read FLocked write SetLocked default False;
  public
    property BorderColor: TColor read FBorderColor write FBorderColor;
    property Color default clWindow;
    property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
    property ShowEndEllipsis: Boolean read FShowEndEllipsis write SetShowEndEllipsis default True;
    property Edges: TcxBorders read FEdges write SetEdges default [bLeft, bTop, bRight, bBottom];
    property FontStyle: TFontStyles read FFontStyle write SetFontStyle default [];
    property FontName: string read FFontName write SetFontName;
    property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
    property ShowButtons: Boolean read FShowButtons write SetShowButtons default True;
    property LookAndFeel: TcxLookAndFeel read FLookAndFeel write SetLookAndFeel;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure RealignButtons;
  end;

  { TcxCustomFontNameComboBoxViewInfo }
  
  TcxCustomFontNameComboBoxViewInfo = class(TcxCustomTextEditViewInfo)
  private
    FCurrentIndex: Integer;
    FIsTrueTypeFont: Boolean;
    ImageRect: TRect;
    FShowFontTypeIcon: TcxShowFontIconTypes;
  protected
    SaveClient: TRect;
    property IsTrueTypeFont: Boolean read FIsTrueTypeFont write FIsTrueTypeFont;
    property ShowFontTypeIcon: TcxShowFontIconTypes read FShowFontTypeIcon write FShowFontTypeIcon;
  public
    procedure Paint(ACanvas: TcxCanvas); override;
    procedure Offset(DX, DY: Integer); override;
  end;

  { TcxCustomFontNameComboBoxViewData }

  TcxCustomFontNameComboBoxProperties = class;

  TcxCustomFontNameComboBoxViewData = class(TcxCustomDropDownEditViewData)
  private
    function GetProperties: TcxCustomFontNameComboBoxProperties;
  protected
    function IsComboBoxStyle: Boolean; override;
  public
    procedure Calculate(ACanvas: TcxCanvas; const ABounds: TRect;
      const P: TPoint; Button: TcxMouseButton; Shift: TShiftState;
      AViewInfo: TcxCustomEditViewInfo; AIsMouseEvent: Boolean); override;
    procedure DisplayValueToDrawValue(const ADisplayValue: TcxEditValue;
      AViewInfo: TcxCustomEditViewInfo); override;
    procedure EditValueToDrawValue(ACanvas: TcxCanvas; const AEditValue: TcxEditValue;
      AViewInfo: TcxCustomEditViewInfo); override;
    function GetEditContentSize(ACanvas: TcxCanvas;
      const AEditValue: TcxEditValue;
      const AEditSizeProperties: TcxEditSizeProperties): TSize; override;
    property Properties: TcxCustomFontNameComboBoxProperties
      read GetProperties;
  end;

  { TcxFontNameComboBoxListBox }

  TcxCustomFontNameComboBox = class;

  TcxFontNameComboBoxListBox = class(TcxCustomComboBoxListBox)
  private
    function GetEdit: TcxCustomFontNameComboBox;
    function IsSymbolFontType(AItemIndex: Integer): Boolean;
  protected
    function GetItem(Index: Integer): string; override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
    property Edit: TcxCustomFontNameComboBox read GetEdit;
  public
    function GetItemHeight(AIndex: Integer = -1): Integer; override;
    function GetItemWidth(AIndex: Integer): Integer; override;
  end;

  { TcxFontNameComboBoxLookupData }
  
  TcxFontNameComboBoxLookupData = class(TcxComboBoxLookupData)
  private
    FPanel: TFontPreviewPanel;
    function GetFontName: string;
    function GetPreviewText: string;
  protected
    function GetListBoxClass: TcxCustomEditListBoxClass; override;
    procedure HandleSelectItem(Sender: TObject); override;
    procedure InternalChangeCurrentMRUFontNamePosition; virtual;
  public
    destructor Destroy; override;
    function CanResizeVisualArea(var NewSize: TSize;
      AMaxHeight: Integer = 0; AMaxWidth: Integer = 0): Boolean; override;
    function GetVisualAreaPreferredSize(AMaxHeight: Integer; AWidth: Integer = 0): TSize; override;
    procedure Initialize(AVisualControlsParent: TWinControl); override;
    procedure PositionVisualArea(const AClientRect: TRect); override;
  end;

  { TcxCustomFontNameComboBoxProperties }

  TcxCustomFontNameComboBoxProperties = class(TcxCustomComboBoxProperties)
  private
    FFontLoader: TcxFontLoader;
    FFontPreview: TcxFontPreview;
    FFontTypes: TcxFontTypes;
    FLoadFontComplete: Boolean;
    FMaxMRUFonts: Byte;
    FMRUFontNames: TcxMRUFontNameItems;
    FShowFontTypeIcon: TcxShowFontIconTypes;
    FUseOwnFont: Boolean;
    FOnAddedMRUFont: TNotifyEvent;
    FOnDeletedMRUFont: TcxDeleteMRUFontEvent;
    FOnInternalLoadFontComplete: TNotifyEvent;
    FOnLoadFontComplete: TNotifyEvent;
    FOnMovedMRUFont: TNotifyEvent;
    function GetFontItems: TStrings;
    function GetFontTypes: TcxFontTypes;
    function GetUseOwnFont: Boolean;
    procedure SetMaxMRUFonts(Value: Byte);
    procedure SetFontTypes(Value: TcxFontTypes);
    procedure SetUseOwnFont(Value: Boolean);
    procedure SetShowFontTypeIcon(Value: TcxShowFontIconTypes);
    function FindItemByValue(const AEditValue: TcxEditValue): Integer;
    procedure DeleteOverMRUFonts;
    procedure FontLoaderCompleteHandler(Sender: TObject);
    procedure FontLoaderDestroyHandler(Sender: TObject);
    function GetItemTypes(Index: Integer): TcxFontTypes;
    procedure SetFontPreview(Value: TcxFontPreview);
    procedure ShutDownFontLoader;
  protected
    function FindLookupText(const AText: string): Boolean; override;
    class function GetLookupDataClass: TcxInterfacedPersistentClass; override;
    class function GetViewDataClass: TcxCustomEditViewDataClass; override;
    function AddMRUFontName(
      const AFontName: TFontName): TcxMRUFontNameAction; virtual;
    function DelMRUFontName(
      const AFontName: TFontName): TcxMRUFontNameAction; virtual;
    property ItemTypes[Index: Integer]: TcxFontTypes read GetItemTypes;
  public
    constructor Create(AOwner: TPersistent); override;
    destructor Destroy; override;
    procedure Assign(Source: TPersistent); override;
    function CompareDisplayValues(
      const AEditValue1, AEditValue2: TcxEditValue): Boolean; override;
    class function GetContainerClass: TcxContainerClass; override;
    procedure GetFontNameComboBoxDisplayValue(const AEditValue: TcxEditValue;
      out AItemIndex: Integer; out AText: string);
    class function GetViewInfoClass: TcxContainerViewInfoClass; override;
    property LoadFontComplete: Boolean read FLoadFontComplete;
    procedure LoadFontNames; virtual;
    procedure Update(AProperties: TcxCustomEditProperties); override;
    property FontItems: TStrings read GetFontItems;
    property MRUFontNames: TcxMRUFontNameItems read FMRUFontNames;
    // !!!
    property FontPreview: TcxFontPreview read FFontPreview write SetFontPreview;
    property FontTypes: TcxFontTypes read GetFontTypes write SetFontTypes
      default [cxftTTF, cxftRaster, cxftDevice, cxftFixed, cxftSymbol];
    property MaxMRUFonts: Byte read FMaxMRUFonts write SetMaxMRUFonts
      default 10;
    property ShowFontTypeIcon: TcxShowFontIconTypes read FShowFontTypeIcon
      write SetShowFontTypeIcon default [ftiShowInCombo, ftiShowInList];
    property UseOwnFont: Boolean read GetUseOwnFont write SetUseOwnFont
      default False;
    property OnAddedMRUFont: TNotifyEvent read FOnAddedMRUFont
      write FOnAddedMRUFont;
    property OnDeletedMRUFont: TcxDeleteMRUFontEvent read FOnDeletedMRUFont
      write FOnDeletedMRUFont;
    property OnLoadFontComplete: TNotifyEvent read FOnLoadFontComplete
      write FOnLoadFontComplete;
    property OnMovedMRUFont: TNotifyEvent read FOnMovedMRUFont
      write FOnMovedMRUFont;
  end;

  { TcxFontNameComboBoxProperties }

  TcxFontNameComboBoxProperties = class(TcxCustomFontNameComboBoxProperties)
  published
    property Alignment;
    property AssignedValues;
    property BeepOnError;
    property ButtonGlyph;
    property CharCase;
    property ClearKey;
    property DropDownAutoWidth;
    property DropDownRows;
    property DropDownSizeable;
    property DropDownWidth;
    property FontPreview;
    property FontTypes;
    property HideSelection;
    property ImeMode;
    property ImeName;
    property ImmediateDropDown;
    property ImmediatePost;
    property ImmediateUpdateText;
    property ItemHeight;

⌨️ 快捷键说明

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