cxImageComboBox.pas
Upload User: yyjgift
Upload Date: 2014-01-20
Package Size: 29104k
Code Size: 41k
Category:

Delphi VCL

Development Platform:

Delphi

  1. {********************************************************************}
  2. {                                                                    }
  3. {       Developer Express Visual Component Library                   }
  4. {       ExpressEditors                                               }
  5. {                                                                    }
  6. {       Copyright (c) 1998-2005 Developer Express Inc.               }
  7. {       ALL RIGHTS RESERVED                                          }
  8. {                                                                    }
  9. {   The entire contents of this file is protected by U.S. and        }
  10. {   International Copyright Laws. Unauthorized reproduction,         }
  11. {   reverse-engineering, and distribution of all or any portion of   }
  12. {   the code contained in this file is strictly prohibited and may   }
  13. {   result in severe civil and criminal penalties and will be        }
  14. {   prosecuted to the maximum extent possible under the law.         }
  15. {                                                                    }
  16. {   RESTRICTIONS                                                     }
  17. {                                                                    }
  18. {   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES            }
  19. {   (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE     }
  20. {   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS    }
  21. {   LICENSED TO DISTRIBUTE THE EXPRESSEDITORS AND ALL                }
  22. {   ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
  23. {                                                                    }
  24. {   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED       }
  25. {   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE         }
  26. {   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE        }
  27. {   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT   }
  28. {   AND PERMISSION FROM DEVELOPER EXPRESS INC.                       }
  29. {                                                                    }
  30. {   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON        }
  31. {   ADDITIONAL RESTRICTIONS.                                         }
  32. {                                                                    }
  33. {********************************************************************}
  34. unit cxImageComboBox;
  35. {$I cxVer.inc}
  36. interface
  37. uses
  38. {$IFDEF VCL}
  39.   Windows, Messages, ComCtrls,
  40. {$ELSE}
  41.   Qt, QTypes,
  42. {$ENDIF}
  43. {$IFDEF DELPHI6}
  44.   Types, Variants,
  45. {$ENDIF}
  46.   cxVariants, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls, ExtCtrls, Clipbrd,
  47.   ImgList, cxClasses, cxGraphics, cxControls, cxContainer, cxEdit, cxDropDownEdit,
  48.   cxTextEdit, cxDataUtils;
  49. type
  50.   { TcxImageComboBoxItem }
  51.   TcxImageComboBoxItem = class(TCollectionItem)
  52.   private
  53.     FDescription: TCaption;
  54.     FImageIndex: TImageIndex;
  55.     FTag: TTag;
  56.     FValue: Variant;
  57.     function IsStoredValue: Boolean;
  58.     function IsTagStored: Boolean;
  59.     procedure SetDescription(const Value: TCaption);
  60.     procedure SetImageIndex(const Value: TImageIndex);
  61.     procedure SetValue(const AValue: Variant);
  62.   public
  63.     constructor Create(Collection: TCollection); override;
  64.     procedure Assign(Source: TPersistent); override;
  65.   published
  66.     property Description: TCaption read FDescription write SetDescription;
  67.     property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
  68.     property Tag: TTag read FTag write FTag stored IsTagStored;
  69.     property Value: Variant read FValue write SetValue stored IsStoredValue;
  70.   end;
  71.   { TcxImageComboBoxItems }
  72.   TcxImageComboBoxItems = class(TOwnedCollection)
  73.   private
  74.     function GetItems(Index: Integer): TcxImageComboBoxItem;
  75.     procedure SetItems(Index: Integer; const Value: TcxImageComboBoxItem);
  76.   protected
  77.     procedure InternalChanged;
  78.     procedure Update(Item: TCollectionItem); override;
  79.   public
  80.     constructor Create(AOwner: TPersistent);
  81.     function Add: TcxImageComboBoxItem;
  82.   {$IFNDEF DELPHI6}
  83.     function Owner: TPersistent;
  84.   {$ENDIF}
  85.     property Items[Index: Integer]: TcxImageComboBoxItem
  86.       read GetItems write SetItems; default;
  87.   end;
  88.   { TcxImageComboBoxListBox }
  89.   TcxCustomImageComboBoxProperties = class;
  90.   TcxImageComboBoxListBox = class(TcxComboBoxListBox)
  91.   private
  92.     FClientWidth: Integer;
  93.     FHasScrollbar: Boolean;
  94.     function GetProperties: TcxCustomImageComboBoxProperties;
  95.   protected
  96.     procedure RecreateWindow; override;
  97.     function GetImageRect(const R: TRect): TRect;
  98.     function GetImages: TImageList;
  99.     function GetMaxItemWidth: Integer; virtual;
  100. {$IFDEF VCL}
  101.     procedure DrawItem(Index: Integer; Rect: TRect;
  102.       State: TOwnerDrawState); override;
  103.     procedure MeasureItem(Index: Integer; var Height: Integer); override;
  104. {$ELSE}
  105.     function DrawItem(Index: Integer; Rect: TRect;
  106.       State: TOwnerDrawState): Boolean; override;
  107.     procedure MeasureItem(Control: TWinControl;
  108.       {$IFDEF LINUX}item: QClxListBoxItemH{$ENDIF}
  109.       {$IFDEF MSWINDOWS}{$IFNDEF DELPHI7}Index: Integer{$ELSE}item: QClxListBoxItemH{$ENDIF}{$ENDIF};
  110.       var Height{$IFNDEF VCL}, Width{$ENDIF}: Integer); override;
  111. {$ENDIF}
  112.     property Properties: TcxCustomImageComboBoxProperties read GetProperties;
  113.   public
  114.     constructor Create(AOwner: TComponent); override;
  115.     function GetHeight(ARowCount: Integer; AMaxHeight: Integer): Integer; override;
  116.   end;
  117.   { TcxImageComboBoxLookupData }
  118.   TcxImageComboBoxLookupData = class(TcxComboBoxLookupData)
  119.   protected
  120.     function GetListBoxClass: TcxCustomEditListBoxClass; override;
  121.     function GetItem(Index: Integer): string; override;
  122.     function GetItemCount: Integer; override;
  123.   public
  124.     procedure TextChanged; override;
  125.   end;
  126.   { TcxImageComboBoxViewData }
  127.   TcxImageComboBoxViewData = class(TcxCustomDropDownEditViewData)
  128.   private
  129.     function GetProperties: TcxCustomImageComboBoxProperties;
  130.   protected
  131.     function InternalEditValueToDisplayText(AEditValue: TcxEditValue): string; override;
  132.     function InternalGetEditConstantPartSize(ACanvas: TcxCanvas; AIsInplace: Boolean;
  133.       const AEditSizeProperties: TcxEditSizeProperties; var MinContentSize: TSize;
  134.       AViewInfo: TcxCustomEditViewInfo): TSize; override;
  135.     function InternalGetEditContentSize(ACanvas: TcxCanvas; const AEditValue: TcxEditValue;
  136.       const AEditSizeProperties: TcxEditSizeProperties): TSize; override;
  137.   public
  138.     procedure Calculate(ACanvas: TcxCanvas; const ABounds: TRect;
  139.       const P: TPoint; Button: TcxMouseButton; Shift: TShiftState;
  140.       AViewInfo: TcxCustomEditViewInfo; AIsMouseEvent: Boolean); override;
  141.     procedure DisplayValueToDrawValue(const ADisplayValue: TcxEditValue;
  142.       AViewInfo: TcxCustomEditViewInfo); override;
  143.     procedure EditValueToDrawValue(ACanvas: TcxCanvas; const AEditValue: TcxEditValue;
  144.       AViewInfo: TcxCustomEditViewInfo); override;
  145.     property Properties: TcxCustomImageComboBoxProperties read GetProperties;
  146.   end;
  147.   { TcxImageComboBoxViewInfo }
  148.   TcxImageAlign = (iaLeft, iaRight);
  149.   TcxImageComboBoxViewInfo = class(TcxCustomTextEditViewInfo)
  150.   protected
  151.     procedure InternalPaint(ACanvas: TcxCanvas); override;
  152.   public
  153.     ImageRect: TRect;
  154.     ShowDescriptions: Boolean;
  155.     ImageAlign: TcxImageAlign;
  156.     ImageIndex: TImageIndex;
  157.     Images: TImageList;
  158.     procedure Offset(DX, DY: Integer); override;
  159.   end;
  160.   { TcxCustomImageComboBoxProperties }
  161.   TcxCustomImageComboBoxProperties = class(TcxCustomComboBoxProperties)
  162.   private
  163.     FDefaultDescription: string;
  164.     FDefaultImageIndex: TImageIndex;
  165.     FImageAlign: TcxImageAlign;
  166.     FImages: TImageList;
  167.     FImagesChangeLink: TChangeLink;
  168.     FItems: TcxImageComboBoxItems;
  169.     FLargeImages: TImageList;
  170.     FLargeImagesChangeLink: TChangeLink;
  171.     FMultiLineText: Boolean;
  172.     FShowDescriptions: Boolean;
  173.     procedure ImagesChange(Sender: TObject);
  174.     procedure LargeImagesChange(Sender: TObject);
  175.     procedure SetDefaultDescription(const Value: string);
  176.     procedure SetDefaultImageIndex(const Value: TImageIndex);
  177.     procedure SetImageAlign(const Value: TcxImageAlign);
  178.     procedure SetImages(const Value: TImageList);
  179.     procedure SetItems(const Value: TcxImageComboBoxItems);
  180.     procedure SetLargeImages(const Value: TImageList);
  181.     procedure SetMultiLineText(const Value: Boolean);
  182.     procedure SetShowDescriptions(const Value: Boolean);
  183.   protected
  184.     function GetDisplayFormatOptions: TcxEditDisplayFormatOptions; override;
  185.     class function GetLookupDataClass: TcxInterfacedPersistentClass; override;
  186.     class function GetViewDataClass: TcxCustomEditViewDataClass; override;
  187.     function FindItemByText(const AText: string): TcxImageComboBoxItem;
  188.     function FindLookupText(const AText: string): Boolean; override;
  189.     procedure FreeNotification(Sender: TComponent); override;
  190.     procedure InternalGetImageComboBoxDisplayValue(AItem: TcxImageComboBoxItem;
  191.       out AText: TCaption; out AImageIndex: TImageIndex);
  192.   public
  193.     constructor Create(AOwner: TPersistent); override;
  194.     destructor Destroy; override;
  195.     procedure Assign(Source: TPersistent); override;
  196.     function CompareDisplayValues(
  197.       const AEditValue1, AEditValue2: TcxEditValue): Boolean; override;
  198.     function FindItemByValue(const AValue: Variant): TcxImageComboBoxItem;
  199.     class function GetContainerClass: TcxContainerClass; override;
  200.     function GetDisplayText(const AEditValue: TcxEditValue;
  201.       AFullText: Boolean = False): WideString; override;
  202.     function GetEditValueSource(AEditFocused: Boolean): TcxDataEditValueSource; override;
  203.     procedure GetImageComboBoxDisplayValue(const AEditValue: TcxEditValue;
  204.       out AText: TCaption; out AImageIndex: TImageIndex);
  205.     function GetSupportedOperations: TcxEditSupportedOperations; override;
  206.     class function GetViewInfoClass: TcxContainerViewInfoClass; override;
  207.     function IsEditValueValid(var AEditValue: TcxEditValue; AEditFocused: Boolean): Boolean; override;
  208.     procedure PrepareDisplayValue(const AEditValue: TcxEditValue;
  209.       var DisplayValue: TcxEditValue; AEditFocused: Boolean); override;
  210.     // !!!
  211.     property DefaultDescription: string
  212.       read FDefaultDescription write SetDefaultDescription;
  213.     property DefaultImageIndex: TImageIndex
  214.       read FDefaultImageIndex write SetDefaultImageIndex default -1;
  215.     property ImageAlign: TcxImageAlign
  216.       read FImageAlign write SetImageAlign default iaLeft;
  217.     property Images: TImageList read FImages write SetImages;
  218.     property Items: TcxImageComboBoxItems read FItems write SetItems;
  219.     property LargeImages: TImageList read FLargeImages write SetLargeImages;
  220.     property MultiLineText: Boolean
  221.       read FMultiLineText write SetMultiLineText default False;
  222.     property ShowDescriptions: Boolean
  223.       read FShowDescriptions write SetShowDescriptions default True;
  224.   end;
  225.   { TcxImageComboBoxProperties }
  226.   TcxImageComboBoxProperties = class(TcxCustomImageComboBoxProperties)
  227.   published
  228.     property Alignment;
  229.     property AssignedValues;
  230.     property ButtonGlyph;
  231.     property DefaultDescription;
  232.     property DefaultImageIndex;
  233.     property DropDownRows;
  234.     property ImageAlign;
  235.     property Images;
  236. {$IFDEF VCL}
  237.     property ImeMode;
  238.     property ImeName;
  239. {$ENDIF}
  240.     property ImmediateDropDown;
  241.     property ImmediatePost;
  242.     property ImmediateUpdateText;
  243.     property Items;
  244.     property LargeImages;
  245.     property MultiLineText;
  246.     property PopupAlignment;
  247.     property PostPopupValueOnTab;
  248.     property ReadOnly;
  249.     property Revertable;
  250.     property ShowDescriptions;
  251.     property ValidateOnEnter;
  252.     property OnButtonClick;
  253.     property OnChange;
  254.     property OnCloseQuery;
  255.     property OnCloseUp;
  256.     property OnEditValueChanged;
  257.     property OnInitPopup;
  258.     property OnPopup;
  259.     property OnValidate;
  260.   end;
  261.   { TcxCustomImageComboBox }
  262.   TcxCustomImageComboBox = class(TcxCustomComboBox)
  263.   private
  264.     function GetProperties: TcxCustomImageComboBoxProperties;
  265.     function GetActiveProperties: TcxCustomImageComboBoxProperties;
  266.     procedure SetProperties(const Value: TcxCustomImageComboBoxProperties);
  267.   protected
  268.     function GetPopupWindowClientPreferredSize: TSize; override;
  269.     function IsValidChar(AChar: Char): Boolean; override;
  270.     function LookupKeyToEditValue(const AKey: TcxEditValue): TcxEditValue; override;
  271.     procedure SynchronizeDisplayValue; override;
  272.     procedure UpdateDrawValue; override;
  273.   public
  274.     class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
  275.     procedure PrepareEditValue(const ADisplayValue: TcxEditValue;
  276.       out EditValue: TcxEditValue; AEditFocused: Boolean); override;
  277.     property ActiveProperties: TcxCustomImageComboBoxProperties read GetActiveProperties;
  278.     property Properties: TcxCustomImageComboBoxProperties read GetProperties
  279.       write SetProperties;
  280.   end;
  281.   { TcxImageComboBox }
  282.   TcxImageComboBox = class(TcxCustomImageComboBox)
  283.   private
  284.     function GetActiveProperties: TcxImageComboBoxProperties;
  285.     function GetProperties: TcxImageComboBoxProperties;
  286.     procedure SetProperties(Value: TcxImageComboBoxProperties);
  287.   public
  288.     class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
  289.     property ActiveProperties: TcxImageComboBoxProperties read GetActiveProperties;
  290.     property ItemIndex;
  291.   published
  292.     property Anchors;
  293.     property AutoSize;
  294.     property BeepOnEnter;
  295.     property Constraints;
  296.     {$IFDEF VCL}
  297.     property DragCursor;
  298.     property DragKind;
  299.     {$ENDIF}
  300.     property DragMode;
  301.     property EditValue;
  302.     property Enabled;
  303.     {$IFDEF VCL}
  304.     property ImeMode;
  305.     property ImeName;
  306.     {$ENDIF}
  307.     property ParentColor;
  308.     property ParentFont;
  309.     property ParentShowHint;
  310.     property PopupMenu;
  311.     property Properties: TcxImageComboBoxProperties read GetProperties write SetProperties;
  312.     property ShowHint;
  313.     property Style;
  314.     property StyleDisabled;
  315.     property StyleFocused;
  316.     property StyleHot;
  317.     property TabOrder;
  318.     property TabStop;
  319.     property Visible;
  320.     property OnClick;
  321. {$IFDEF DELPHI5}
  322.     property OnContextPopup;
  323. {$ENDIF}
  324.     property OnEditing;
  325.     property OnEnter;
  326.     property OnExit;
  327.     property OnKeyDown;
  328.     property OnKeyPress;
  329.     property OnKeyUp;
  330.     property OnMouseDown;
  331.     property OnMouseMove;
  332.     property OnMouseUp;
  333.   end;
  334. implementation
  335. uses
  336.   Dialogs, Math, cxButtons, cxEditConsts, cxEditUtils;
  337. const
  338.   EmptyRect: TRect = (Left: 0; Top: 0; Right: 0; Bottom: 0);
  339. type
  340.   TcxCustomTextEditAccess = class(TcxCustomTextEdit);
  341. function Max(A, B: Integer): Integer;
  342. begin
  343.   Result := A;
  344.   if B > A then Result := B;
  345. end;
  346. { TcxImageComboBoxItem }
  347. constructor TcxImageComboBoxItem.Create(Collection: TCollection);
  348. var
  349.   AImages: TCustomImageList;
  350. begin
  351.   FValue := Null; // for D5 variants
  352.   inherited Create(Collection);
  353.   AImages :=
  354.     TcxCustomImageComboBoxProperties(TcxImageComboBoxItems(Collection).Owner).Images;
  355.   if (AImages <> nil) and (AImages.Count >= Collection.Count) then
  356.     FImageIndex := Collection.Count - 1
  357.   else
  358.     FImageIndex := -1;
  359. end;
  360. function TcxImageComboBoxItem.IsStoredValue: Boolean;
  361. begin
  362.   Result := not VarIsNull(FValue);
  363. end;
  364. function TcxImageComboBoxItem.IsTagStored: Boolean;
  365. begin
  366.   Result := FTag <> 0;
  367. end;
  368. procedure TcxImageComboBoxItem.SetDescription(const Value: TCaption);
  369. begin
  370.   if FDescription <> Value then
  371.   begin
  372.     FDescription := Value;
  373.     TcxImageComboBoxItems(Collection).InternalChanged;
  374.   end;
  375. end;
  376. procedure TcxImageComboBoxItem.SetImageIndex(const Value: TImageIndex);
  377. begin
  378.   if FImageIndex <> Value then
  379.   begin
  380.     FImageIndex := Value;
  381.     TcxImageComboBoxItems(Collection).InternalChanged;
  382.   end;
  383. end;
  384. procedure TcxImageComboBoxItem.SetValue(const AValue: Variant);
  385. begin
  386.   if not InternalVarEqualsExact(FValue, AValue) then
  387.   begin
  388.     FValue := AValue;
  389.     TcxImageComboBoxItems(Collection).InternalChanged;
  390.   end;
  391. end;
  392. procedure TcxImageComboBoxItem.Assign(Source: TPersistent);
  393. begin
  394.   if Source is TcxImageComboBoxItem then
  395.     with TcxImageComboBoxItem(Source) do
  396.     begin
  397.       Self.Description := Description;
  398.       Self.ImageIndex := ImageIndex;
  399.       Self.Tag := Tag;
  400.       Self.Value := Value;
  401.     end
  402.   else
  403.     inherited Assign(Source);
  404. end;
  405. { TcxImageComboBoxItems }
  406. function TcxImageComboBoxItems.GetItems(Index: Integer): TcxImageComboBoxItem;
  407. begin
  408.   Result := TcxImageComboBoxItem(inherited Items[Index]);
  409. end;
  410. procedure TcxImageComboBoxItems.SetItems(Index: Integer;
  411.   const Value: TcxImageComboBoxItem);
  412. begin
  413.   inherited Items[Index] := Value;
  414. end;
  415. procedure TcxImageComboBoxItems.InternalChanged;
  416. begin
  417.   Changed;
  418. end;
  419. procedure TcxImageComboBoxItems.Update(Item: TCollectionItem);
  420. begin
  421.   with TcxCustomImageComboBoxProperties(Owner) do
  422.     Changed;
  423. end;
  424. constructor TcxImageComboBoxItems.Create(AOwner: TPersistent);
  425. begin
  426.   inherited Create(AOwner, TcxImageComboBoxItem);
  427. end;
  428. function TcxImageComboBoxItems.Add: TcxImageComboBoxItem;
  429. begin
  430.   Result := TcxImageComboBoxItem(inherited Add);
  431. end;
  432. {$IFNDEF DELPHI6}
  433. function TcxImageComboBoxItems.Owner: TPersistent;
  434. begin
  435.   Result := GetOwner;
  436. end;
  437. {$ENDIF}
  438. { TcxImageComboBoxListBox }
  439. constructor TcxImageComboBoxListBox.Create(AOwner: TComponent);
  440. begin
  441.   inherited Create(AOwner);
  442.   BorderStyle := bsNone;
  443.   Style := lbOwnerDrawVariable;
  444. end;
  445. function TcxImageComboBoxListBox.GetHeight(ARowCount: Integer; AMaxHeight: Integer): Integer;
  446. var
  447.   I, H: Integer;
  448.   R: TRect;
  449. {$IFNDEF VCL}
  450.   W: Integer;
  451.   Size: TSize;
  452. {$ENDIF}
  453. begin
  454.   if Properties.MultiLineText then
  455.     with TcxCustomImageComboBox(Edit) do
  456.     begin
  457.       R := GetPopupWindowOwnerControlBounds;
  458.       FClientWidth := R.Right - R.Left;
  459.       R := PopupWindow.ViewInfo.GetClientExtent;
  460.       Dec(FClientWidth, R.Left + R.Right);
  461.     end
  462.     else
  463.       FClientWidth := 0;
  464.   Result := 0;
  465.   for I := 0 to ARowCount - 1 do
  466.   begin
  467.     H := 0;
  468. {$IFDEF VCL}
  469.     MeasureItem(I, H);
  470. {$ELSE}
  471.   {$IFDEF LINUX}
  472.       MeasureItem(Self, QClxListBoxItemH(QListBox_item(handle, I)), H, W);
  473.   {$ELSE}
  474.     {$IFNDEF DELPHI7}
  475.       MeasureItem(Self, I, H, W);
  476.     {$ELSE}
  477.       MeasureItem(Self, QClxListBoxItemH(QListBox_item(handle, I)), H, W);
  478.     {$ENDIF}
  479.   {$ENDIF}
  480. {$ENDIF}
  481.     Inc(Result, H);
  482.   end;
  483.   if Properties.MultiLineText then
  484.   begin
  485.     FHasScrollbar := (Result > AMaxHeight) or (ARowCount < Items.Count);
  486.     if FHasScrollbar then
  487.     begin
  488. {$IFDEF VCL}
  489.       Dec(FClientWidth, VScrollBar.Width);
  490. {$ELSE}
  491.       // TODO check calc
  492.       QStyle_scrollBarExtent(Application.Style.Handle, @Size);
  493.       Dec(FClientWidth, Size.cx);
  494. {$ENDIF}
  495.       Result := 0;
  496.       for I := 0 to ARowCount - 1 do
  497.       begin
  498.         H := 0;
  499. {$IFDEF VCL}
  500.         MeasureItem(I, H);
  501. {$ELSE}
  502.   {$IFDEF LINUX}
  503.         MeasureItem(Self, QClxListBoxItemH(QListBox_item(handle, I)), H, W);
  504.   {$ELSE}
  505.     {$IFNDEF DELPHI7}
  506.         MeasureItem(Self, I, H, W);
  507.     {$ELSE}
  508.         MeasureItem(Self, QClxListBoxItemH(QListBox_item(handle, I)), H, W);
  509.     {$ENDIF}
  510.   {$ENDIF}
  511. {$ENDIF}
  512.         Inc(Result, H);
  513.       end;
  514.     end;
  515.   end;
  516. end;
  517. procedure TcxImageComboBoxListBox.RecreateWindow;
  518. begin
  519.   InternalRecreateWindow;
  520. end;
  521. function TcxImageComboBoxListBox.GetImageRect(const R: TRect): TRect;
  522. var
  523.   AImages: TImageList;
  524. begin
  525.   AImages := GetImages;
  526.   if AImages <> nil then
  527.     with Properties do
  528.     begin
  529.       Result := R;
  530.       with Result do
  531.         if ImageAlign = iaLeft then
  532.           Right := Left + AImages.Width + 4
  533.         else
  534.           Left := Right - AImages.Width - 4;
  535.     end
  536.     else
  537.       Result := EmptyRect;
  538. end;
  539. function TcxImageComboBoxListBox.GetImages: TImageList;
  540. begin
  541.   Result := Properties.LargeImages;
  542.   if Result = nil then Result := Properties.Images;
  543. end;
  544. function TcxImageComboBoxListBox.GetMaxItemWidth: Integer;
  545. var
  546.   AImages: TImageList;
  547.   I, W, J: Integer;
  548. begin
  549.   AImages := GetImages;
  550.   if AImages <> nil then Result := AImages.Width + 8 else Result := 4;
  551.   with Properties do
  552.   begin
  553.     J := Result;
  554.     for I := 0 to Items.Count - 1 do
  555.     begin
  556.       W := Canvas.TextWidth(Items[I].Description) + J;
  557.       if W > Result then Result := W;
  558.     end;
  559.   end;
  560.   if Properties.DropDownRows < Items.Count then
  561.     Inc(Result, VScrollBar.Width);
  562. end;
  563. procedure TcxImageComboBoxListBox.DrawItem(Index: Integer; Rect: TRect;
  564.   State: TOwnerDrawState);
  565. var
  566.   Flags: Longint;
  567.   Data: string;
  568.   AImages: TImageList;
  569.   R: TRect;
  570.   AImageIndex: Integer;
  571. begin
  572.   if Assigned(OnDrawItem) then OnDrawItem(Self, Index, Rect, State) else
  573.   begin
  574.     Canvas.FillRect(Rect);
  575.     if (Index < Items.Count) and (Index > -1) then
  576.     begin
  577.       if Properties.MultiLineText then
  578.         Flags := DrawTextBiDiModeFlags(DT_LEFT or DT_EXPANDTABS or
  579.           DT_NOPREFIX or DT_WORDBREAK)
  580.       else
  581.         Flags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or
  582.           DT_NOPREFIX);
  583.       if not UseRightToLeftAlignment then
  584.         Inc(Rect.Left, 2)
  585.       else
  586.         Dec(Rect.Right, 2);
  587.       Data := Properties.Items[Index].Description;
  588.       AImages := GetImages;
  589.       if AImages <> nil then
  590.       begin
  591.         R := GetImageRect(Rect);
  592.         AImageIndex := Properties.Items[Index].ImageIndex;
  593.         if (AImageIndex > -1) and (AImageIndex < AImages.Count) then
  594.           with R do
  595.             AImages.Draw(Canvas.Canvas, Left + 1, (Bottom + Top - AImages.Height) div 2,
  596.               AImageIndex, Enabled);
  597.         if R.Left > Rect.Left then Rect.Right := R.Left;
  598.         if R.Right < Rect.Right then Rect.Left := R.Right;
  599.       end;
  600.       if not IsRectEmpty(Rect) then
  601.       begin
  602.         SetBkMode(Handle, TRANSPARENT);
  603.         DrawText(Canvas.Handle, PChar(Data), Length(Data), Rect, Flags);
  604.       end;
  605.     end;
  606.   end;
  607. end;
  608. {$IFDEF VCL}
  609. procedure TcxImageComboBoxListBox.MeasureItem(Index: Integer; var Height: Integer);
  610. {$ELSE}
  611. procedure TcxImageComboBoxListBox.MeasureItem(Control: TWinControl;
  612.   {$IFDEF LINUX}item: QClxListBoxItemH{$ENDIF}
  613.   {$IFDEF MSWINDOWS}{$IFNDEF DELPHI7}Index: Integer{$ELSE}item: QClxListBoxItemH{$ENDIF}{$ENDIF};
  614.   var Height{$IFNDEF VCL}, Width{$ENDIF}: Integer);
  615. {$ENDIF}
  616. var
  617.   AData: string;
  618.   AImages: TImageList;
  619.   W, H, AFlags: Integer;
  620.   R: TRect;
  621. {$IFNDEF VCL}
  622.   {$IFDEF MSWINDOWS}
  623.     {$IFDEF DELPHI7}
  624.   Index: Integer;
  625.     {$ENDIF}
  626.   {$ENDIF}
  627.   {$IFDEF LINUX}
  628.   Index: Integer;
  629.   {$ENDIF}
  630. {$ENDIF}
  631. begin
  632.   // TODO check Qt
  633.   W := FClientWidth - 2;
  634. {$IFNDEF VCL}
  635.   {$IFDEF MSWINDOWS}
  636.     {$IFDEF DELPHI7}
  637.   Index := QListBox_index(Handle, Item);
  638.     {$ENDIF}
  639.   {$ENDIF}
  640.   {$IFDEF LINUX}
  641.   Index := QListBox_index(Handle, Item);
  642.   {$ENDIF}
  643. {$ENDIF}
  644.   AImages := GetImages;
  645.   if AImages <> nil then
  646.   begin
  647.     Dec(W, AImages.Width + 4);
  648.     H := AImages.Height + 2;
  649.   end
  650.   else
  651.     H := 0;
  652.   if Properties.MultiLineText and (W > 0) then
  653.   begin
  654.     R := Rect(0, 0, W, H);
  655.     AData := Properties.Items[Index].Description;
  656.     AFlags := DT_LEFT or DT_EXPANDTABS or DT_NOPREFIX or DT_WORDBREAK or DT_CALCRECT;
  657.     DrawText(Canvas.Handle, PChar(AData), Length(AData), R, AFlags);
  658.     H := Max(H, R.Bottom - R.Top + 2);
  659.   end
  660.   else
  661.     H := Max(Canvas.TextHeight('Wg') + 2, H);
  662.   Height := H;
  663. end;
  664. function TcxImageComboBoxListBox.GetProperties: TcxCustomImageComboBoxProperties;
  665. begin
  666.   Result := TcxCustomImageComboBox(Edit).ActiveProperties;
  667. end;
  668. { TcxImageComboBoxLookupData }
  669. function TcxImageComboBoxLookupData.GetListBoxClass: TcxCustomEditListBoxClass;
  670. begin
  671.   Result := TcxImageComboBoxListBox;
  672. end;
  673. function TcxImageComboBoxLookupData.GetItem(Index: Integer): string;
  674. begin
  675.   with TcxCustomImageComboBox(Edit).ActiveProperties do
  676.     if (Index > -1) and (Index < Items.Count) then
  677.       Result := Items[Index].Description
  678.     else
  679.       Result := ''
  680. end;
  681. function TcxImageComboBoxLookupData.GetItemCount: Integer;
  682. begin
  683.   Result := TcxCustomImageComboBox(Edit).ActiveProperties.Items.Count;
  684. end;
  685. procedure TcxImageComboBoxLookupData.TextChanged;
  686. var
  687.   AItem: TcxImageComboBoxItem;
  688. begin
  689.   with TcxCustomImageComboBoxProperties(ActiveProperties) do
  690.     AItem := FindItemByValue(Edit.EditValue);
  691.   if AItem <> nil then
  692.     InternalSetCurrentKey(AItem.Index)
  693.   else
  694.     InternalSetCurrentKey(-1);
  695. end;
  696. { TcxImageComboBoxViewData }
  697. procedure TcxImageComboBoxViewData.Calculate(ACanvas: TcxCanvas;
  698.   const ABounds: TRect; const P: TPoint; Button: TcxMouseButton;
  699.   Shift: TShiftState; AViewInfo: TcxCustomEditViewInfo; AIsMouseEvent: Boolean);
  700. var
  701.   R: TRect;
  702. begin
  703.   inherited Calculate(ACanvas, ABounds, P, Button, Shift, AViewInfo,
  704.     AIsMouseEvent);
  705.   with TcxImageComboBoxViewInfo(AViewInfo) do
  706.   begin
  707.     ImageAlign := TcxCustomImageComboBoxProperties(Properties).ImageAlign;
  708.     Images := TcxCustomImageComboBoxProperties(Properties).Images;
  709.     ShowDescriptions := TcxCustomImageComboBoxProperties(Properties).ShowDescriptions;
  710.     R := ClientRect;
  711.     if Assigned(Images) then
  712.     begin
  713.       ImageRect := R;
  714.       with ImageRect do
  715.       begin
  716.         if ShowDescriptions then
  717.           if ImageAlign = iaLeft then
  718.           begin
  719.             Inc(Left, 2);
  720.             Right := Left + Images.Width;
  721.             R.Left := Right + 2;
  722.           end
  723.           else
  724.           begin
  725.             Right := Right - 2;
  726.             Left := Right - Images.Width;
  727.             R.Right := Left - 2;
  728.           end
  729.         else
  730.         begin
  731.           Left := Left + (Right - Left - Images.Width) div 2;
  732.           Right := Left + Images.Width;
  733.         end;
  734.         Top := Top + (Bottom - Top - Images.Height) div 2;
  735.         Bottom := Top + Images.Height;
  736.       end;
  737.     end;
  738.     if not IsInplace then
  739.       ClientRect := R;
  740.     InflateRect(R, -2, -1);
  741.     TextRect := R;
  742.     if not ShowDescriptions then
  743.       Text := '';
  744.     if not IsInplace then
  745.       DrawSelectionBar := False;
  746.   end;
  747. end;
  748. procedure TcxImageComboBoxViewData.EditValueToDrawValue(ACanvas: TcxCanvas;
  749.   const AEditValue: TcxEditValue; AViewInfo: TcxCustomEditViewInfo);
  750. var
  751.   AText: string;
  752.   ACaption: TCaption;
  753.   AImageIndex: TImageIndex;
  754. begin
  755.   PrepareSelection(AViewInfo);
  756.   Properties.GetImageComboBoxDisplayValue(AEditValue, ACaption, AImageIndex);
  757.   TcxImageComboBoxViewInfo(AViewInfo).ImageIndex := AImageIndex;
  758.   AText := ACaption;
  759.   DoOnGetDisplayText(AText);
  760.   TcxImageComboBoxViewInfo(AViewInfo).Text := AText;
  761. end;
  762. procedure TcxImageComboBoxViewData.DisplayValueToDrawValue(
  763.   const ADisplayValue: TcxEditValue; AViewInfo: TcxCustomEditViewInfo);
  764. var
  765.   ACurrentKey: TcxEditValue;
  766.   AItem: TcxImageComboBoxItem;
  767.   ACaption: TCaption;
  768.   AImageIndex: TImageIndex;
  769. begin
  770.   if Edit = nil then
  771.     Exit;
  772.   ACurrentKey := TcxCustomImageComboBox(Edit).ILookupData.CurrentKey;
  773.   if ACurrentKey = -1 then
  774.     AItem := Properties.FindItemByValue(Edit.EditValue)
  775.   else
  776.     AItem := Properties.Items[ACurrentKey];
  777.   Properties.InternalGetImageComboBoxDisplayValue(AItem, ACaption, AImageIndex);
  778.   TcxImageComboBoxViewInfo(AViewInfo).Text := ACaption;
  779.   TcxImageComboBoxViewInfo(AViewInfo).ImageIndex := AImageIndex;
  780. end;
  781. function TcxImageComboBoxViewData.InternalEditValueToDisplayText(
  782.   AEditValue: TcxEditValue): string;
  783. var
  784.   AIndex: TImageIndex;
  785.   ACaption: TCaption;
  786. begin
  787.   Properties.GetImageComboBoxDisplayValue(AEditValue,
  788.     ACaption, AIndex);
  789.   Result := ACaption;  
  790. end;
  791. function TcxImageComboBoxViewData.InternalGetEditConstantPartSize(
  792.   ACanvas: TcxCanvas; AIsInplace: Boolean;
  793.   const AEditSizeProperties: TcxEditSizeProperties; var MinContentSize: TSize;
  794.   AViewInfo: TcxCustomEditViewInfo): TSize;
  795. begin
  796.   Result := inherited InternalGetEditConstantPartSize(ACanvas, AIsInplace,
  797.     AEditSizeProperties, MinContentSize, AViewInfo);
  798.   with TcxCustomImageComboBoxProperties(Properties) do
  799.     if Assigned(Images) and (Images.Height > MinContentSize.cy) then
  800.       MinContentSize.cy := Images.Height;
  801. end;
  802. function TcxImageComboBoxViewData.InternalGetEditContentSize(ACanvas: TcxCanvas;
  803.   const AEditValue: TcxEditValue;
  804.   const AEditSizeProperties: TcxEditSizeProperties): TSize;
  805. begin
  806.   Result := inherited InternalGetEditContentSize(ACanvas, AEditValue,
  807.     AEditSizeProperties);
  808.   with TcxCustomImageComboBoxProperties(Properties) do
  809.   begin
  810.     if Images <> nil then
  811.       Result.cx := Result.cx + Images.Width + 5
  812.     else
  813.       Result.cx := Result.cx + 1;
  814.   end;
  815. end;
  816. function TcxImageComboBoxViewData.GetProperties: TcxCustomImageComboBoxProperties;
  817. begin
  818.   Result := TcxCustomImageComboBoxProperties(FProperties);
  819. end;
  820. { TcxImageComboBoxViewInfo }
  821. procedure TcxImageComboBoxViewInfo.Offset(DX, DY: Integer);
  822. begin
  823.   inherited Offset(DX, DY);
  824.   OffsetRect(ImageRect, DX, DY);
  825. end;
  826. procedure TcxImageComboBoxViewInfo.InternalPaint(ACanvas: TcxCanvas);
  827. var
  828.   AClipRgn, APrevClipRgn: TcxRegion;
  829.   R: TRect;
  830. begin
  831.   if not RectVisible(ACanvas.Handle, Bounds) then
  832.     Exit;
  833.   if Assigned(Images) and (ImageIndex > -1) and (ImageIndex < Images.Count) then
  834.   begin
  835.     APrevClipRgn := ACanvas.GetClipRegion;
  836.     try
  837.       IntersectRect(R, ImageRect, BorderRect);
  838.       AClipRgn := TcxRegion.Create(R);
  839.       ACanvas.SetClipRegion(AClipRgn, roIntersect);
  840.       if Transparent then
  841.         Images.Draw(ACanvas.Canvas, ImageRect.Left, ImageRect.Top,
  842.           ImageIndex, {$IFNDEF VCL}itImage, {$ENDIF}Enabled)
  843.       else
  844.         {$IFDEF VCL}cxEditUtils{$ELSE}QcxEditUtils{$ENDIF}.DrawGlyph(ACanvas,
  845.           Images, ImageIndex, ImageRect, BackgroundColor, Enabled);
  846.     finally
  847.       ACanvas.SetClipRegion(APrevClipRgn, roSet);
  848.     end;
  849.     if not Transparent then
  850.       ACanvas.ExcludeClipRect(R);
  851.   end;
  852.   inherited InternalPaint(ACanvas);
  853. end;
  854. { TcxCustomImageComboBoxProperties }
  855. constructor TcxCustomImageComboBoxProperties.Create(AOwner: TPersistent);
  856. begin
  857.   inherited Create(AOwner);
  858.   FShowDescriptions := True;
  859.   FDefaultImageIndex := -1;
  860.   FImageAlign := iaLeft;
  861.   FItems := TcxImageComboBoxItems.Create(Self);
  862.   DropDownListStyle := lsFixedList;
  863.   FImagesChangeLink := TChangeLink.Create;
  864.   FImagesChangeLink.OnChange := ImagesChange;
  865.   FLargeImagesChangeLink := TChangeLink.Create;
  866.   FLargeImagesChangeLink.OnChange := LargeImagesChange;
  867. end;
  868. destructor TcxCustomImageComboBoxProperties.Destroy;
  869. begin
  870.   FImagesChangeLink.Free;
  871.   FLargeImagesChangeLink.Free;
  872.   FItems.Free;
  873.   inherited Destroy;
  874. end;
  875. procedure TcxCustomImageComboBoxProperties.ImagesChange(Sender: TObject);
  876. begin
  877.   Changed;
  878. end;
  879. procedure TcxCustomImageComboBoxProperties.LargeImagesChange(Sender: TObject);
  880. begin
  881.   Changed;
  882. end;
  883. procedure TcxCustomImageComboBoxProperties.SetDefaultDescription(
  884.   const Value: string);
  885. begin
  886.   if FDefaultDescription <> Value then
  887.   begin
  888.     FDefaultDescription := Value;
  889.     Changed;
  890.   end;
  891. end;
  892. procedure TcxCustomImageComboBoxProperties.SetDefaultImageIndex(
  893.   const Value: TImageIndex);
  894. begin
  895.   if FDefaultImageIndex <> Value then
  896.   begin
  897.     FDefaultImageIndex := Value;
  898.     Changed;
  899.   end;
  900. end;
  901. procedure TcxCustomImageComboBoxProperties.SetImageAlign(
  902.   const Value: TcxImageAlign);
  903. begin
  904.   if FImageAlign <> Value then
  905.   begin
  906.     FImageAlign := Value;
  907.     Changed;
  908.   end;
  909. end;
  910. procedure TcxCustomImageComboBoxProperties.SetImages(const Value: TImageList);
  911. begin
  912.   if FImages <> Value then
  913.   begin
  914.     if FImages <> nil then
  915.     begin
  916.       FImages.UnRegisterChanges(FImagesChangeLink);
  917.       FreeNotificator.RemoveSender(FImages);
  918.     end;
  919.     FImages := Value;
  920.     if FImages <> nil then
  921.     begin
  922.       FImages.RegisterChanges(FImagesChangeLink);
  923.       FreeNotificator.AddSender(FImages);
  924.     end;
  925.     Changed;
  926.   end;
  927. end;
  928. procedure TcxCustomImageComboBoxProperties.SetLargeImages(
  929.   const Value: TImageList);
  930. begin
  931.   if FLargeImages <> Value then
  932.   begin
  933.     if FLargeImages <> nil then
  934.     begin
  935.       FLargeImages.UnRegisterChanges(FLargeImagesChangeLink);
  936.       FreeNotificator.RemoveSender(FLargeImages);
  937.     end;
  938.     FLargeImages := Value;
  939.     if FLargeImages <> nil then
  940.     begin
  941.       FLargeImages.RegisterChanges(FLargeImagesChangeLink);
  942.       FreeNotificator.AddSender(FLargeImages);
  943.     end;
  944.     Changed;
  945.   end;
  946. end;
  947. procedure TcxCustomImageComboBoxProperties.SetItems(
  948.   const Value: TcxImageComboBoxItems);
  949. begin
  950.   FItems.Assign(Value);
  951.   Changed;
  952. end;
  953. procedure TcxCustomImageComboBoxProperties.SetMultiLineText(
  954.   const Value: Boolean);
  955. begin
  956.   if FMultiLineText <> Value then
  957.   begin
  958.     FMultiLineText := Value;
  959.     Changed;
  960.   end;
  961. end;
  962. procedure TcxCustomImageComboBoxProperties.SetShowDescriptions(
  963.   const Value: Boolean);
  964. begin
  965.   if FShowDescriptions <> Value then
  966.   begin
  967.     FShowDescriptions := Value;
  968.     Changed;
  969.   end;
  970. end;
  971. function TcxCustomImageComboBoxProperties.GetDisplayFormatOptions: TcxEditDisplayFormatOptions;
  972. begin
  973.   Result := [];
  974. end;
  975. function TcxCustomImageComboBoxProperties.FindItemByText(const AText: string):
  976.   TcxImageComboBoxItem;
  977. var
  978.   I: Integer;
  979. begin
  980.   Result := nil;
  981.   if ShowDescriptions then
  982.     for I := 0 to Items.Count - 1 do
  983.       if InternalCompareString(Items[I].Description, AText, False) then
  984.       begin
  985.         Result := Items[I];
  986.         Break;
  987.       end;
  988. end;
  989. function TcxCustomImageComboBoxProperties.FindLookupText(const AText: string): Boolean;
  990. begin
  991.   Result := FindItemByText(AText) <> nil;
  992. end;
  993. procedure TcxCustomImageComboBoxProperties.FreeNotification(Sender: TComponent);
  994. begin
  995.   inherited FreeNotification(Sender);
  996.   if Sender = FImages then
  997.     FImages := nil;
  998.   if Sender = FLargeImages then
  999.     FLargeImages := nil;
  1000. end;
  1001. procedure TcxCustomImageComboBoxProperties.InternalGetImageComboBoxDisplayValue(
  1002.   AItem: TcxImageComboBoxItem; out AText: TCaption; out AImageIndex: TImageIndex);
  1003. begin
  1004.   if ShowDescriptions then
  1005.     if AItem = nil then
  1006.       AText := DefaultDescription
  1007.     else
  1008.       AText := AItem.Description
  1009.   else
  1010.     AText := '';
  1011.   if AItem = nil then
  1012.     AImageIndex := DefaultImageIndex
  1013.   else
  1014.     AImageIndex := AItem.ImageIndex;
  1015. end;
  1016. procedure TcxCustomImageComboBoxProperties.Assign(Source: TPersistent);
  1017. begin
  1018.   if Source is TcxCustomImageComboBoxProperties then
  1019.   begin
  1020.     BeginUpdate;
  1021.     try
  1022.       inherited Assign(Source);
  1023.       with TcxCustomImageComboBoxProperties(Source) do
  1024.       begin
  1025.         Self.DefaultDescription := DefaultDescription;
  1026.         Self.DefaultImageIndex := DefaultImageIndex;
  1027.         Self.ImageAlign := ImageAlign;
  1028.         Self.Images := Images;
  1029.         Self.Items.Assign(Items);
  1030.         Self.LargeImages := LargeImages;
  1031.         Self.MultiLineText := MultiLineText;
  1032.         Self.ShowDescriptions := ShowDescriptions;
  1033.       end;
  1034.     finally
  1035.       EndUpdate
  1036.     end
  1037.   end
  1038.   else
  1039.     inherited Assign(Source);
  1040. end;
  1041. function TcxCustomImageComboBoxProperties.CompareDisplayValues(
  1042.   const AEditValue1, AEditValue2: TcxEditValue): Boolean;
  1043. var
  1044.   AImageIndex1, AImageIndex2: TImageIndex;
  1045.   AText1, AText2: TCaption;
  1046. begin
  1047.   GetImageComboBoxDisplayValue(AEditValue1, AText1, AImageIndex1);
  1048.   GetImageComboBoxDisplayValue(AEditValue2, AText2, AImageIndex2);
  1049.   Result := InternalCompareString(AText1, AText2, True) and ((Images = nil) or
  1050.     (AImageIndex1 = AImageIndex2));
  1051. end;
  1052. function TcxCustomImageComboBoxProperties.FindItemByValue(
  1053.   const AValue: Variant): TcxImageComboBoxItem;
  1054. var
  1055.   I: Integer;
  1056. begin
  1057.   Result := nil;
  1058.   for I := 0 to Items.Count - 1 do
  1059.     with Items[I] do
  1060.       if VarEqualsExact(AValue, Value) then
  1061.       begin
  1062.         Result := Items[I];
  1063.         Break;
  1064.       end;
  1065. end;
  1066. class function TcxCustomImageComboBoxProperties.GetContainerClass: TcxContainerClass;
  1067. begin
  1068.   Result := TcxImageComboBox;
  1069. end;
  1070. function TcxCustomImageComboBoxProperties.GetDisplayText(
  1071.  const AEditValue: TcxEditValue; AFullText: Boolean = False): WideString;
  1072. var
  1073.   ADisplayValue: TcxEditValue;
  1074. begin
  1075.   PrepareDisplayValue(AEditValue, ADisplayValue, False);
  1076.   Result := ADisplayValue;
  1077. end;
  1078. function TcxCustomImageComboBoxProperties.GetEditValueSource(AEditFocused: Boolean): TcxDataEditValueSource;
  1079. begin
  1080.   Result := evsValue;
  1081. end;
  1082. procedure TcxCustomImageComboBoxProperties.GetImageComboBoxDisplayValue(
  1083.   const AEditValue: TcxEditValue; out AText: TCaption;
  1084.   out AImageIndex: TImageIndex);
  1085. begin
  1086.   InternalGetImageComboBoxDisplayValue(FindItemByValue(AEditValue), AText,
  1087.     AImageIndex);
  1088. end;
  1089. class function TcxCustomImageComboBoxProperties.GetLookupDataClass: TcxInterfacedPersistentClass;
  1090. begin
  1091.   Result := TcxImageComboBoxLookupData;
  1092. end;
  1093. function TcxCustomImageComboBoxProperties.GetSupportedOperations: TcxEditSupportedOperations;
  1094. begin
  1095.   Result := [esoFiltering, esoHorzAlignment, esoSorting, esoSortingByDisplayText];
  1096.   if Buttons.Count > 0 then
  1097.     Include(Result, esoHotTrack);
  1098.   if ShowDescriptions then
  1099.     Include(Result, esoIncSearch);
  1100. end;
  1101. class function TcxCustomImageComboBoxProperties.GetViewDataClass: TcxCustomEditViewDataClass;
  1102. begin
  1103.   Result := TcxImageComboBoxViewData;
  1104. end;
  1105. class function TcxCustomImageComboBoxProperties.GetViewInfoClass: TcxContainerViewInfoClass;
  1106. begin
  1107.   Result := TcxImageComboBoxViewInfo;
  1108. end;
  1109. function TcxCustomImageComboBoxProperties.IsEditValueValid(
  1110.   var AEditValue: TcxEditValue; AEditFocused: Boolean): Boolean;
  1111. begin
  1112.   Result := True;
  1113. end;
  1114. procedure TcxCustomImageComboBoxProperties.PrepareDisplayValue(
  1115.   const AEditValue: TcxEditValue; var DisplayValue: TcxEditValue;
  1116.   AEditFocused: Boolean);
  1117. var
  1118.   AItem: TcxImageComboBoxItem;
  1119. begin
  1120.   AItem := FindItemByValue(AEditValue);
  1121.   if AItem = nil then
  1122.     DisplayValue := DefaultDescription
  1123.   else
  1124.     DisplayValue := AItem.Description;
  1125. end;
  1126. { TcxCustomImageComboBox }
  1127. function TcxCustomImageComboBox.GetProperties: TcxCustomImageComboBoxProperties;
  1128. begin
  1129.   Result := TcxCustomImageComboBoxProperties(FProperties);
  1130. end;
  1131. function TcxCustomImageComboBox.GetActiveProperties: TcxCustomImageComboBoxProperties;
  1132. begin
  1133.   Result := TcxCustomImageComboBoxProperties(InternalGetActiveProperties);
  1134. end;
  1135. procedure TcxCustomImageComboBox.SetProperties(const Value: TcxCustomImageComboBoxProperties);
  1136. begin
  1137.   FProperties.Assign(Value);
  1138. end;
  1139. function TcxCustomImageComboBox.IsValidChar(AChar: Char): Boolean;
  1140. begin
  1141.   Result := IsTextChar(AChar);
  1142. end;
  1143. function TcxCustomImageComboBox.GetPopupWindowClientPreferredSize: TSize;
  1144. begin
  1145.   Result := inherited GetPopupWindowClientPreferredSize;
  1146.   if not ActiveProperties.MultiLineText then
  1147.   begin
  1148.     if (LookupData.ActiveControl <> nil) and (LookupData.ActiveControl is TcxImageComboBoxListBox) then
  1149.       with TcxImageComboBoxListBox(LookupData.ActiveControl) do
  1150.         Result.cx := Max(GetMaxItemWidth, Result.cx);
  1151.   end
  1152.   else
  1153.     Result.cx := 0;
  1154. end;
  1155. function TcxCustomImageComboBox.LookupKeyToEditValue(const AKey: TcxEditValue): TcxEditValue;
  1156. begin
  1157.   if not VarEqualsExact(AKey, -1) then
  1158.     Result := ActiveProperties.Items[AKey].Value
  1159.   else
  1160.     Result := Null;
  1161. end;
  1162. procedure TcxCustomImageComboBox.SynchronizeDisplayValue;
  1163. var
  1164.   APrevLookupKey: TcxEditValue;
  1165. begin
  1166.   SaveModified;
  1167.   try
  1168.     APrevLookupKey := ILookupData.CurrentKey;
  1169.     LockClick(True);
  1170.     try
  1171.       ILookupData.TextChanged;
  1172.     finally
  1173.       LockClick(False);
  1174.       if (*ModifiedAfterEnter and *)not VarEqualsExact(APrevLookupKey, ILookupData.CurrentKey) then
  1175.         DoClick;
  1176.     end;
  1177.   finally
  1178.     RestoreModified;
  1179.     ResetOnNewDisplayValue;
  1180.     UpdateDrawValue;
  1181.   end;
  1182. end;
  1183. procedure TcxCustomImageComboBox.UpdateDrawValue;
  1184. begin
  1185.   inherited UpdateDrawValue;
  1186.   SetInternalDisplayValue(ViewInfo.Text);
  1187. end;
  1188. class function TcxCustomImageComboBox.GetPropertiesClass: TcxCustomEditPropertiesClass;
  1189. begin
  1190.   Result := TcxCustomImageComboBoxProperties;
  1191. end;
  1192. procedure TcxCustomImageComboBox.PrepareEditValue(
  1193.   const ADisplayValue: TcxEditValue; out EditValue: TcxEditValue;
  1194.   AEditFocused: Boolean);
  1195. begin
  1196.   if VarEqualsExact(LookupData.CurrentKey, -1) then
  1197.     EditValue := Null
  1198.   else
  1199.     EditValue := ActiveProperties.Items[LookupData.CurrentKey].Value;
  1200. end;
  1201. { TcxImageComboBox }
  1202. class function TcxImageComboBox.GetPropertiesClass: TcxCustomEditPropertiesClass;
  1203. begin
  1204.   Result := TcxImageComboBoxProperties;
  1205. end;
  1206. function TcxImageComboBox.GetActiveProperties: TcxImageComboBoxProperties;
  1207. begin
  1208.   Result := TcxImageComboBoxProperties(InternalGetActiveProperties);
  1209. end;
  1210. function TcxImageComboBox.GetProperties: TcxImageComboBoxProperties;
  1211. begin
  1212.   Result := TcxImageComboBoxProperties(FProperties);
  1213. end;
  1214. procedure TcxImageComboBox.SetProperties(Value: TcxImageComboBoxProperties);
  1215. begin
  1216.   FProperties.Assign(Value);
  1217. end;
  1218. initialization
  1219.   GetRegisteredEditProperties.Register(TcxImageComboBoxProperties, scxSEditRepositoryImageComboBoxItem);
  1220. end.