cximagecombobox.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,337 行 · 第 1/3 页
PAS
1,337 行
{********************************************************************}
{ }
{ 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 cxImageComboBox;
{$I cxVer.inc}
interface
uses
Windows, Messages, ComCtrls,
{$IFDEF DELPHI6}
Types, Variants,
{$ENDIF}
cxVariants, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls, ExtCtrls, Clipbrd,
ImgList, cxClasses, cxGraphics, cxControls, cxContainer, cxDataStorage, cxDataUtils,
cxEdit, cxDropDownEdit, cxTextEdit, cxFilterControlUtils;
type
{ TcxImageComboBoxItem }
TcxImageComboBoxItem = class(TCollectionItem)
private
FDescription: TCaption;
FImageIndex: TImageIndex;
FTag: TcxTag;
FValue: Variant;
function IsStoredValue: Boolean;
function IsTagStored: Boolean;
procedure SetDescription(const Value: TCaption);
procedure SetImageIndex(const Value: TImageIndex);
procedure SetValue(const AValue: Variant);
public
constructor Create(Collection: TCollection); override;
procedure Assign(Source: TPersistent); override;
published
property Description: TCaption read FDescription write SetDescription;
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
property Tag: TcxTag read FTag write FTag stored IsTagStored;
property Value: Variant read FValue write SetValue stored IsStoredValue;
end;
{ TcxImageComboBoxItems }
TcxImageComboBoxItems = class(TOwnedCollection)
private
function GetItems(Index: Integer): TcxImageComboBoxItem;
procedure SetItems(Index: Integer; const Value: TcxImageComboBoxItem);
protected
procedure InternalChanged;
procedure Update(Item: TCollectionItem); override;
public
constructor Create(AOwner: TPersistent);
function Add: TcxImageComboBoxItem;
{$IFNDEF DELPHI6}
function Owner: TPersistent;
{$ENDIF}
property Items[Index: Integer]: TcxImageComboBoxItem
read GetItems write SetItems; default;
end;
{ TcxImageComboBoxListBox }
TcxCustomImageComboBox = class;
TcxCustomImageComboBoxProperties = class;
TcxImageComboBoxListBox = class(TcxComboBoxListBox)
private
FClientWidth: Integer;
FHasScrollbar: Boolean;
function GetEdit: TcxCustomImageComboBox;
function GetProperties: TcxCustomImageComboBoxProperties;
protected
procedure DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState); override;
procedure MeasureItem(Index: Integer; var Height: Integer); override;
procedure RecreateWindow; override;
function GetImageRect(const R: TRect): TRect;
function GetImages: TCustomImageList;
function GetMaxItemWidth: Integer; virtual;
property Edit: TcxCustomImageComboBox read GetEdit;
property Properties: TcxCustomImageComboBoxProperties read GetProperties;
public
constructor Create(AOwner: TComponent); override;
function GetHeight(ARowCount: Integer; AMaxHeight: Integer): Integer; override;
function GetItemWidth(AIndex: Integer): Integer; override;
end;
{ TcxImageComboBoxLookupData }
TcxImageComboBoxLookupData = class(TcxComboBoxLookupData)
private
function GetList: TcxImageComboBoxListBox;
protected
function GetListBoxClass: TcxCustomEditListBoxClass; override;
function GetItem(Index: Integer): string; override;
function GetItemCount: Integer; override;
property List: TcxImageComboBoxListBox read GetList;
public
procedure TextChanged; override;
end;
{ TcxImageComboBoxViewData }
TcxImageComboBoxViewData = class(TcxCustomDropDownEditViewData)
private
function GetProperties: TcxCustomImageComboBoxProperties;
protected
function InternalEditValueToDisplayText(AEditValue: TcxEditValue): string; override;
function InternalGetEditConstantPartSize(ACanvas: TcxCanvas; AIsInplace: Boolean;
AEditSizeProperties: TcxEditSizeProperties; var MinContentSize: TSize;
AViewInfo: TcxCustomEditViewInfo): TSize; override;
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;
property Properties: TcxCustomImageComboBoxProperties read GetProperties;
end;
{ TcxImageComboBoxViewInfo }
TcxImageAlign = (iaLeft, iaRight);
TcxImageComboBoxViewInfo = class(TcxCustomTextEditViewInfo)
protected
procedure InternalPaint(ACanvas: TcxCanvas); override;
public
ImageRect: TRect;
ShowDescriptions: Boolean;
ImageAlign: TcxImageAlign;
ImageIndex: TImageIndex;
Images: TCustomImageList;
procedure Offset(DX, DY: Integer); override;
end;
{ TcxCustomImageComboBoxProperties }
TcxCustomImageComboBoxProperties = class(TcxCustomComboBoxProperties)
private
FDefaultDescription: string;
FDefaultImageIndex: TImageIndex;
FImageAlign: TcxImageAlign;
FImages: TCustomImageList;
FImagesChangeLink: TChangeLink;
FItems: TcxImageComboBoxItems;
FLargeImages: TCustomImageList;
FLargeImagesChangeLink: TChangeLink;
FMultiLineText: Boolean;
FShowDescriptions: Boolean;
procedure ImagesChange(Sender: TObject);
procedure LargeImagesChange(Sender: TObject);
procedure SetDefaultDescription(const Value: string);
procedure SetDefaultImageIndex(const Value: TImageIndex);
procedure SetImageAlign(const Value: TcxImageAlign);
procedure SetImages(Value: TCustomImageList);
procedure SetItems(const Value: TcxImageComboBoxItems);
procedure SetLargeImages(Value: TCustomImageList);
procedure SetMultiLineText(const Value: Boolean);
procedure SetShowDescriptions(const Value: Boolean);
protected
function FindItemByText(const AText: string): TcxImageComboBoxItem;
function FindLookupText(const AText: string): Boolean; override;
procedure FreeNotification(Sender: TComponent); override;
function GetDisplayFormatOptions: TcxEditDisplayFormatOptions; override;
class function GetLookupDataClass: TcxInterfacedPersistentClass; override;
class function GetViewDataClass: TcxCustomEditViewDataClass; override;
function HasDisplayValue: Boolean; override;
procedure InternalGetImageComboBoxDisplayValue(AItem: TcxImageComboBoxItem;
out AText: TCaption; out AImageIndex: TImageIndex;
AAlwaysShowDescription: Boolean = False); virtual;
public
constructor Create(AOwner: TPersistent); override;
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
function CompareDisplayValues(
const AEditValue1, AEditValue2: TcxEditValue): Boolean; override;
function FindItemByValue(const AValue: Variant): TcxImageComboBoxItem;
class function GetContainerClass: TcxContainerClass; override;
function GetDisplayText(const AEditValue: TcxEditValue;
AFullText: Boolean = False; AIsInplace: Boolean = True): WideString; override;
function GetEditValueSource(AEditFocused: Boolean): TcxDataEditValueSource; override;
procedure GetImageComboBoxDisplayValue(const AEditValue: TcxEditValue;
out AText: TCaption; out AImageIndex: TImageIndex);
function GetSupportedOperations: TcxEditSupportedOperations; override;
class function GetViewInfoClass: TcxContainerViewInfoClass; override;
function IsEditValueValid(var AEditValue: TcxEditValue; AEditFocused: Boolean): Boolean; override;
procedure PrepareDisplayValue(const AEditValue: TcxEditValue;
var DisplayValue: TcxEditValue; AEditFocused: Boolean); override;
// !!!
property DefaultDescription: string
read FDefaultDescription write SetDefaultDescription;
property DefaultImageIndex: TImageIndex
read FDefaultImageIndex write SetDefaultImageIndex default -1;
property ImageAlign: TcxImageAlign
read FImageAlign write SetImageAlign default iaLeft;
property Images: TCustomImageList read FImages write SetImages;
property Items: TcxImageComboBoxItems read FItems write SetItems;
property LargeImages: TCustomImageList read FLargeImages write SetLargeImages;
property MultiLineText: Boolean
read FMultiLineText write SetMultiLineText default False;
property ShowDescriptions: Boolean
read FShowDescriptions write SetShowDescriptions default True;
end;
{ TcxImageComboBoxProperties }
TcxImageComboBoxProperties = class(TcxCustomImageComboBoxProperties)
published
property Alignment;
property AssignedValues;
property ButtonGlyph;
property ClearKey;
property DefaultDescription;
property DefaultImageIndex;
property DropDownRows;
property ImageAlign;
property Images;
property ImeMode;
property ImeName;
property ImmediateDropDown;
property ImmediatePost;
property ImmediateUpdateText;
property Items;
property LargeImages;
property MultiLineText;
property PopupAlignment;
property PostPopupValueOnTab;
property ReadOnly;
property Revertable;
property ShowDescriptions;
property ValidateOnEnter;
property OnButtonClick;
property OnChange;
property OnCloseQuery;
property OnCloseUp;
property OnEditValueChanged;
property OnInitPopup;
property OnPopup;
property OnValidate;
end;
{ TcxCustomImageComboBox }
TcxCustomImageComboBox = class(TcxCustomComboBox)
private
function GetProperties: TcxCustomImageComboBoxProperties;
function GetActiveProperties: TcxCustomImageComboBoxProperties;
function GetLookupData: TcxImageComboBoxLookupData;
procedure SetProperties(const Value: TcxCustomImageComboBoxProperties);
protected
function GetItemObject: TObject; override;
function GetPopupWindowClientPreferredSize: TSize; override;
function InternalGetEditingValue: TcxEditValue; override;
function IsValidChar(AChar: Char): Boolean; override;
function LookupKeyToEditValue(const AKey: TcxEditValue): TcxEditValue; override;
procedure SynchronizeDisplayValue; override;
procedure UpdateDrawValue; override;
property LookupData: TcxImageComboBoxLookupData read GetLookupData;
public
class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
procedure PrepareEditValue(const ADisplayValue: TcxEditValue;
out EditValue: TcxEditValue; AEditFocused: Boolean); override;
property ActiveProperties: TcxCustomImageComboBoxProperties read GetActiveProperties;
property Properties: TcxCustomImageComboBoxProperties read GetProperties
write SetProperties;
end;
{ TcxImageComboBox }
TcxImageComboBox = class(TcxCustomImageComboBox)
private
function GetActiveProperties: TcxImageComboBoxProperties;
function GetProperties: TcxImageComboBoxProperties;
procedure SetProperties(Value: TcxImageComboBoxProperties);
public
class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
property ActiveProperties: TcxImageComboBoxProperties read GetActiveProperties;
published
property Anchors;
property AutoSize;
property BeepOnEnter;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property EditValue;
property Enabled;
property ImeMode;
property ImeName;
property ItemIndex;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property Properties: TcxImageComboBoxProperties read GetProperties write SetProperties;
property ShowHint;
property Style;
property StyleDisabled;
property StyleFocused;
property StyleHot;
property TabOrder;
property TabStop;
property Visible;
property OnClick;
{$IFDEF DELPHI5}
property OnContextPopup;
{$ENDIF}
property OnEditing;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
{ TcxFilterImageComboBoxHelper }
TcxFilterImageComboBoxHelper = class(TcxFilterComboBoxHelper)
public
class function GetFilterEditClass: TcxCustomEditClass; override;
class function GetSupportedFilterOperators(
AProperties: TcxCustomEditProperties;
AValueTypeClass: TcxValueTypeClass;
AExtendedSet: Boolean = False): TcxFilterControlOperators; override;
class procedure InitializeProperties(AProperties,
AEditProperties: TcxCustomEditProperties; AHasButtons: Boolean); override;
end;
implementation
uses
Dialogs, Math, cxGeometry, cxButtons, cxEditConsts, cxEditUtils, cxScrollBar,
cxDWMApi;
const
EmptyRect: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
type
TcxCustomTextEditAccess = class(TcxCustomTextEdit);
{ TcxImageComboBoxItem }
constructor TcxImageComboBoxItem.Create(Collection: TCollection);
var
AImages: TCustomImageList;
begin
FValue := Null; // for D5 variants
inherited Create(Collection);
AImages :=
TcxCustomImageComboBoxProperties(TcxImageComboBoxItems(Collection).Owner).Images;
if (AImages <> nil) and (AImages.Count >= Collection.Count) then
FImageIndex := Collection.Count - 1
else
FImageIndex := -1;
end;
function TcxImageComboBoxItem.IsStoredValue: Boolean;
begin
Result := not VarIsNull(FValue);
end;
function TcxImageComboBoxItem.IsTagStored: Boolean;
begin
Result := FTag <> 0;
end;
procedure TcxImageComboBoxItem.SetDescription(const Value: TCaption);
begin
if FDescription <> Value then
begin
FDescription := Value;
TcxImageComboBoxItems(Collection).InternalChanged;
end;
end;
procedure TcxImageComboBoxItem.SetImageIndex(const Value: TImageIndex);
begin
if FImageIndex <> Value then
begin
FImageIndex := Value;
TcxImageComboBoxItems(Collection).InternalChanged;
end;
end;
procedure TcxImageComboBoxItem.SetValue(const AValue: Variant);
begin
if not InternalVarEqualsExact(FValue, AValue) then
begin
FValue := AValue;
TcxImageComboBoxItems(Collection).InternalChanged;
end;
end;
procedure TcxImageComboBoxItem.Assign(Source: TPersistent);
begin
if Source is TcxImageComboBoxItem then
with TcxImageComboBoxItem(Source) do
begin
Self.Description := Description;
Self.ImageIndex := ImageIndex;
Self.Tag := Tag;
Self.Value := Value;
end
else
inherited Assign(Source);
end;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?