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

Delphi VCL

Development Platform:

Delphi

  1. {********************************************************************}
  2. {                                                                    }
  3. {       Developer Express Visual Component Library                   }
  4. {       ExpressQuantumGrid                                           }
  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 EXPRESSQUANTUMGRID 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 cxDBExtLookupComboBox;
  35. {$I cxVer.inc}
  36. interface
  37. uses
  38. {$IFDEF DELPHI6}
  39.   Variants,
  40. {$ENDIF}
  41.   Windows, Classes, Controls, DB, Graphics, Messages, SysUtils, cxClasses,
  42.   cxContainer, cxControls, cxCustomData, cxDB, cxDBData, cxDBEdit,
  43.   cxDBLookupEdit, cxEditConsts, cxGrid, cxGridCustomTableView, cxEdit, 
  44.   cxGridCustomView, cxGridStrs, cxGridTableView, cxLookAndFeels, cxLookupEdit;
  45. type
  46.   { TcxExtLookupGrid }
  47.   TcxExtLookupGrid = class(TcxGrid)
  48.   private
  49.     FEditable: Boolean;
  50.     FMousePos: TPoint;
  51.     FPopupMouseMoveLocked: Boolean;
  52.     FPrevOnKeyDown: TKeyEvent;
  53.     FPrevOnMouseDown: TMouseEvent;
  54.     FPrevOnMouseMove: TMouseMoveEvent;
  55.     FPrevOnMouseUp: TMouseEvent;
  56.     FRowPressed: Boolean;
  57.     FOnCloseUp: TcxLookupGridCloseUpEvent;
  58.     function GetView: TcxCustomGridTableView;
  59.     procedure ViewKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  60.     procedure ViewMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  61.     procedure ViewMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  62.     procedure ViewMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  63.   protected
  64.     procedure DoCancelMode; override;
  65.     procedure DoCloseUp(AAccept: Boolean); virtual;
  66.     function IsDataRow(AHitTest: TcxCustomGridHitTest): Boolean;
  67.     property Editable: Boolean read FEditable write FEditable;
  68.     property PopupMouseMoveLocked: Boolean read FPopupMouseMoveLocked write FPopupMouseMoveLocked;
  69.     property OnCloseUp: TcxLookupGridCloseUpEvent read FOnCloseUp write FOnCloseUp;
  70.   public
  71.     property View: TcxCustomGridTableView read GetView;
  72.   end;
  73.   { TcxCustomExtLookupComboBoxProperties }
  74.   TcxCustomExtLookupComboBoxProperties = class(TcxCustomDBLookupEditProperties);
  75.   { TcxExtLookupComboBoxProperties }
  76.   TcxExtLookupComboBoxProperties = class(TcxCustomExtLookupComboBoxProperties)
  77.   private
  78.     FAutoSearchOnPopup: Boolean;
  79.     FFocusPopup: Boolean;
  80.     FGrid: TcxExtLookupGrid;
  81.     FInCheckListFieldItem: Boolean;
  82.     FListFieldItem: TcxCustomGridTableItem;
  83.     FPrevColumnFiltering: Boolean;
  84.     FPrevPullFocusing: Boolean;
  85.     FPrevImmediateEditor: Boolean;
  86.     FPrevIncSearch: Boolean;
  87.     FPrevMultiSelect: Boolean;
  88.     FView: TcxCustomGridTableView;
  89.     function GetGridMode: Boolean;
  90.     function GetListFieldIndex: Integer;
  91.     function GetListFieldItem: TcxCustomGridTableItem;
  92.     procedure SetGridMode(Value: Boolean);
  93.     procedure SetListFieldItem(Value: TcxCustomGridTableItem);
  94.     procedure SetView(Value: TcxCustomGridTableView);
  95.   protected
  96.     procedure CheckListFieldItem;
  97.     procedure DeinitializeDataController; override;
  98.     procedure FreeNotification(Sender: TComponent); override;
  99.     function GetIncrementalFiltering: Boolean; override;
  100.     function GetListIndex: Integer; override;
  101.     procedure InitializeDataController; override;
  102.     procedure LinkView(AView: TcxCustomGridTableView);
  103.     function PopupWindowCapturesFocus: Boolean; override;
  104.     procedure UnlinkView(AView: TcxCustomGridTableView);
  105.     // LookupGrid methods
  106.     function GetLookupGridActiveControl: TWinControl; override;
  107.     function GetLookupGridCanResize: Boolean; override;
  108.     function GetLookupGridColumnCount: Integer; override;
  109.     function GetLookupGridControl: TWinControl; override;
  110.     function GetLookupGridDataController: TcxCustomDataController; override;
  111.     function GetLookupGridVisualAreaPreferredWidth: Integer; override;
  112.     function GetLookupGridNearestPopupHeight(AHeight: Integer): Integer; override;
  113.     function GetLookupGridPopupHeight(ADropDownRowCount: Integer): Integer; override;
  114.     function IsLookupGridMouseOverList(const P: TPoint): Boolean; override;
  115.     procedure LookupGridDeinitialize; override;
  116.     procedure LookupGridDroppedDown(const AFindStr: string); override;
  117.     procedure LookupGridInitEvents(AOnClick, AOnFocusedRowChanged: TNotifyEvent;
  118.       AOnCloseUp: TcxLookupGridCloseUpEvent); override;
  119.     procedure LookupGridInitialize; override;
  120.     procedure LookupGridInitLookAndFeel(ALookAndFeel: TcxLookAndFeel;
  121.       AColor: TColor; AFont: TFont); override;
  122.     procedure LookupGridLockMouseMove; override;
  123.     procedure LookupGridMakeFocusedRowVisible; override;
  124.     procedure LookupGridUnlockMouseMove; override;
  125.     // DBLookupGrid methods
  126.     procedure DBLookupGridBeginUpdate; override;
  127.     procedure DBLookupGridCheckColumnByFieldName(const AFieldName: string); override;
  128.     procedure DBLookupGridCreateColumnsByFieldNames(const AFieldNames: string); override;
  129.     procedure DBLookupGridEndUpdate; override;
  130.     function GetDBLookupGridColumnField(AIndex: Integer): TField; override;
  131.     function GetDBLookupGridColumnFieldName(AIndex: Integer): string; override;
  132.     function GetDBLookupGridColumnIndexByFieldName(const AFieldName: string): Integer; override;
  133.     function GetDBLookupGridDataController: TcxDBDataController; override;
  134.   public
  135.     constructor Create(AOwner: TPersistent); override;
  136.     destructor Destroy; override;
  137.     procedure Assign(Source: TPersistent); override;
  138.     class function GetContainerClass: TcxContainerClass; override;
  139.     class function IsViewSupported(Value: TcxCustomGridTableView): Boolean;
  140.     property Grid: TcxExtLookupGrid read FGrid;
  141.     property ListFieldIndex: Integer read GetListFieldIndex;
  142.   published
  143.     property Alignment;
  144.     property AssignedValues;
  145.     property AutoSearchOnPopup: Boolean read FAutoSearchOnPopup write FAutoSearchOnPopup default True;
  146.     property AutoSelect;
  147.     property ButtonGlyph;
  148.     property CharCase;
  149.     property ClearKey;
  150.     property DropDownAutoSize;
  151.     property DropDownHeight;
  152.     property DropDownListStyle;
  153.     property DropDownRows;
  154.     property DropDownSizeable;
  155.     property DropDownWidth;
  156.     property FocusPopup: Boolean read FFocusPopup write FFocusPopup default False;
  157.     property GridMode: Boolean read GetGridMode write SetGridMode default False;
  158.     property HideSelection;
  159.     property ImeMode;
  160.     property ImeName;
  161.     property ImmediateDropDown;
  162.     property ImmediatePost;
  163.     property IncrementalFiltering;
  164.     property View: TcxCustomGridTableView read FView write SetView; // before
  165.     property KeyFieldNames;
  166.     property ListFieldItem: TcxCustomGridTableItem read GetListFieldItem write SetListFieldItem;
  167.     property MaxLength;
  168.     property OEMConvert;
  169.     property PopupAlignment;
  170.     property PostPopupValueOnTab;
  171.     property ReadOnly;
  172.     property Revertable;
  173.     property UseLeftAlignmentOnEditing;
  174.     property ValidateOnEnter;
  175.     property OnChange;
  176.     property OnCloseUp;
  177.     property OnEditValueChanged;
  178.     property OnInitPopup;
  179.     property OnNewLookupDisplayText;
  180.     property OnPopup;
  181.     property OnValidate;
  182.   end;
  183.   { TcxCustomExtLookupComboBox }
  184.   TcxCustomExtLookupComboBox = class(TcxCustomDBLookupEdit)
  185.   private
  186.     function GetActiveProperties: TcxExtLookupComboBoxProperties;
  187.     function GetProperties: TcxExtLookupComboBoxProperties;
  188.     procedure SetProperties(Value: TcxExtLookupComboBoxProperties);
  189.   protected
  190.     function CanDropDown: Boolean; override;
  191.   public
  192.     class function GetPropertiesClass: TcxCustomEditPropertiesClass; override;
  193.     property ActiveProperties: TcxExtLookupComboBoxProperties
  194.       read GetActiveProperties;
  195.     property EditValue;
  196.     property Properties: TcxExtLookupComboBoxProperties read GetProperties
  197.       write SetProperties;
  198.     property Text;
  199.   end;
  200.   { TcxExtLookupComboBox }
  201.   TcxExtLookupComboBox = class(TcxCustomExtLookupComboBox)
  202.   published
  203.     property Anchors;
  204.     property AutoSize;
  205.     property BeepOnEnter;
  206.     property Constraints;
  207.     property DragCursor;
  208.     property DragKind;
  209.     property DragMode;
  210.     property Enabled;
  211.     property ImeMode;
  212.     property ImeName;
  213.     property ParentColor;
  214.     property ParentFont;
  215.     property ParentShowHint;
  216.     property PopupMenu;
  217.     property Properties;
  218.     property EditValue;
  219.     property ShowHint;
  220.     property Style;
  221.     property StyleDisabled;
  222.     property StyleFocused;
  223.     property StyleHot;
  224.     property TabOrder;
  225.     property TabStop;
  226.     property Visible;
  227.     property OnClick;
  228.     property OnContextPopup;
  229.     property OnDblClick;
  230.     property OnEditing;
  231.     property OnEnter;
  232.     property OnExit;
  233.     property OnKeyDown;
  234.     property OnKeyPress;
  235.     property OnKeyUp;
  236.     property OnMouseDown;
  237.     property OnMouseMove;
  238.     property OnMouseUp;
  239.   end;
  240.   { TcxDBExtLookupComboBox }
  241.   TcxDBExtLookupComboBox = class(TcxCustomExtLookupComboBox
  242. )
  243.   private
  244.     function GetDataBinding: TcxDBTextEditDataBinding;
  245.     procedure SetDataBinding(Value: TcxDBTextEditDataBinding);
  246.     procedure CMGetDataLink(var Message: TMessage); message CM_GETDATALINK;
  247.   protected
  248.     class function GetDataBindingClass: TcxEditDataBindingClass; override;
  249.   published
  250.     property Anchors;
  251.     property AutoSize;
  252.     property BeepOnEnter;
  253.     property Constraints;
  254.     property DragCursor;
  255.     property DragKind;
  256.     property DataBinding: TcxDBTextEditDataBinding read GetDataBinding
  257.       write SetDataBinding;
  258.     property DragMode;
  259.     property Enabled;
  260.     property ImeMode;
  261.     property ImeName;
  262.     property ParentColor;
  263.     property ParentFont;
  264.     property ParentShowHint;
  265.     property PopupMenu;
  266.     property Properties;
  267.     property ShowHint;
  268.     property Style;
  269.     property StyleDisabled;
  270.     property StyleFocused;
  271.     property StyleHot;
  272.     property TabOrder;
  273.     property TabStop;
  274.     property Visible;
  275.     property OnClick;
  276.     property OnContextPopup;
  277.     property OnDblClick;
  278.     property OnEditing;
  279.     property OnEnter;
  280.     property OnExit;
  281.     property OnKeyDown;
  282.     property OnKeyPress;
  283.     property OnKeyUp;
  284.     property OnMouseDown;
  285.     property OnMouseMove;
  286.     property OnMouseUp;
  287.   end;
  288.   { TcxEditRepositoryExtLookupComboBoxItem }
  289.   TcxEditRepositoryExtLookupComboBoxItem = class(TcxEditRepositoryItem)
  290.   private
  291.     function GetProperties: TcxExtLookupComboBoxProperties;
  292.     procedure SetProperties(Value: TcxExtLookupComboBoxProperties);
  293.   public
  294.     class function GetEditPropertiesClass: TcxCustomEditPropertiesClass; override;
  295.   published
  296.     property Properties: TcxExtLookupComboBoxProperties read GetProperties write SetProperties;
  297.   end;
  298. implementation
  299. uses
  300.    cxGridFilterHelpers;
  301. type
  302.   TcxCustomGridTableOptionsBehaviorAccess = class(TcxCustomGridTableOptionsBehavior);
  303.   TcxCustomGridTableOptionsViewAccess = class(TcxCustomGridTableOptionsView);
  304. { TcxExtLookupGrid }
  305. procedure TcxExtLookupGrid.DoCancelMode;
  306. begin
  307.   FRowPressed := False;
  308.   inherited;
  309. end;
  310. procedure TcxExtLookupGrid.DoCloseUp(AAccept: Boolean);
  311. begin
  312.   if AAccept then
  313.     View.DataController.SyncSelected(True);
  314.   if Assigned(FOnCloseUp) then FOnCloseUp(Self, AAccept);
  315. end;
  316. function TcxExtLookupGrid.IsDataRow(AHitTest: TcxCustomGridHitTest): Boolean;
  317. begin
  318.   Result := (AHitTest is TcxGridRecordHitTest) and
  319.     TcxGridRecordHitTest(AHitTest).GridRecord.IsData; 
  320. end;
  321. function TcxExtLookupGrid.GetView: TcxCustomGridTableView;
  322. begin
  323.   Result := Levels[0].GridView as TcxCustomGridTableView;
  324. end;
  325. procedure TcxExtLookupGrid.ViewKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  326. begin
  327.   if Assigned(FPrevOnKeyDown) then
  328.     FPrevOnKeyDown(Self, Key, Shift);
  329.   if (View = nil) then Exit;
  330.   case Key of
  331.     VK_RETURN:
  332.       if not Editable or (ssCtrl in Shift) then
  333.       begin
  334.         if View.DataController.IsEditing then
  335.           View.DataController.Post;
  336.         DoCloseUp(View.DataController.FocusedRowIndex <> -1);
  337.       end;
  338.     VK_ESCAPE:
  339.       if Editable and not View.DataController.IsEditing then
  340.         DoCloseUp(False);
  341.   end;
  342. end;
  343. procedure TcxExtLookupGrid.ViewMouseDown(Sender: TObject; Button: TMouseButton;
  344.   Shift: TShiftState; X, Y: Integer);
  345. var
  346.   AHitTest: TcxCustomGridHitTest;
  347. begin
  348.   if Assigned(FPrevOnMouseDown) then
  349.     FPrevOnMouseDown(Sender, Button, Shift, X, Y);
  350.   AHitTest := View.ViewInfo.GetHitTest(X, Y);
  351.   if (Button = mbLeft) and IsDataRow(AHitTest) then
  352.   begin
  353.     if Editable then
  354.     begin
  355.       if ssDouble in Shift then
  356.         DoCloseUp(True);
  357.     end
  358.     else
  359.       FRowPressed := True;
  360.   end;
  361. end;
  362. procedure TcxExtLookupGrid.ViewMouseMove(Sender: TObject; Shift: TShiftState;
  363.   X, Y: Integer);
  364. var
  365.   AHitTest: TcxCustomGridHitTest;
  366. begin
  367.   if Assigned(FPrevOnMouseMove) then
  368.     FPrevOnMouseMove(Sender, Shift, X, Y);
  369.   if not MouseCapture and PopupMouseMoveLocked then
  370.   begin
  371.     PopupMouseMoveLocked := False;
  372.     Exit;
  373.   end;
  374.   // Hot Track
  375.   if (View = nil) or Editable then Exit;
  376.   AHitTest := View.ViewInfo.GetHitTest(X, Y);
  377.   if IsDataRow(AHitTest) and ((FMousePos.X <> X) or (FMousePos.Y <> Y)) then
  378.   begin
  379.     FMousePos.X := X;
  380.     FMousePos.Y := Y;
  381.     TcxGridRecordHitTest(AHitTest).GridRecord.Focused := True;
  382.   end;
  383. end;
  384. procedure TcxExtLookupGrid.ViewMouseUp(Sender: TObject; Button: TMouseButton;
  385.   Shift: TShiftState; X, Y: Integer);
  386. var
  387.   AHitTest: TcxCustomGridHitTest;
  388. begin
  389.   if Assigned(FPrevOnMouseUp) then
  390.     FPrevOnMouseUp(Sender, Button, Shift, X, Y);
  391.   AHitTest := View.ViewInfo.GetHitTest(X, Y);
  392.   if (Button = mbLeft) and FRowPressed then
  393.     DoCloseUp(IsDataRow(AHitTest));
  394.   FRowPressed := False;
  395. end;
  396. { TcxExtLookupComboBoxProperties }
  397. constructor TcxExtLookupComboBoxProperties.Create(AOwner: TPersistent);
  398. begin
  399.   inherited Create(AOwner);
  400.   FAutoSearchOnPopup := True;
  401.   FGrid := TcxExtLookupGrid.Create(nil);
  402.   FGrid.IsPopupControl := True;
  403.   FGrid.BorderStyle := cxcbsNone;
  404.   FGrid.Levels.Add;
  405. end;
  406. destructor TcxExtLookupComboBoxProperties.Destroy;
  407. begin
  408.   ListFieldItem := nil;
  409.   View := nil;
  410.   FGrid.Free;
  411.   FGrid := nil;
  412.   inherited Destroy;
  413. end;
  414. procedure TcxExtLookupComboBoxProperties.Assign(Source: TPersistent);
  415. begin
  416.   if Source is TcxExtLookupComboBoxProperties then
  417.   begin
  418.     BeginUpdate;
  419.     try
  420.       AutoSearchOnPopup := TcxExtLookupComboBoxProperties(Source).AutoSearchOnPopup;
  421.       FocusPopup := TcxExtLookupComboBoxProperties(Source).FocusPopup;
  422.       View := nil; //?
  423.       GridMode := TcxExtLookupComboBoxProperties(Source).GridMode;
  424.       View := TcxExtLookupComboBoxProperties(Source).View;
  425.       inherited Assign(Source);
  426.       ListFieldItem := TcxExtLookupComboBoxProperties(Source).ListFieldItem;
  427.     finally
  428.       EndUpdate;
  429.     end
  430.   end
  431.   else
  432.     inherited Assign(Source);
  433. end;
  434. class function TcxExtLookupComboBoxProperties.GetContainerClass: TcxContainerClass;
  435. begin
  436.   Result := TcxExtLookupComboBox;
  437. end;
  438. class function TcxExtLookupComboBoxProperties.IsViewSupported(Value: TcxCustomGridTableView): Boolean;
  439. begin
  440.   Result := Value.CanBeLookupList and
  441.     (TcxCustomGridView(Value).DataController is TcxDBDataController);
  442. end;
  443. procedure TcxExtLookupComboBoxProperties.CheckListFieldItem;
  444. begin
  445.   FInCheckListFieldItem := True;
  446.   try
  447.     if (View <> nil) and (ListFieldItem <> nil) and
  448.       (View.IndexOfItem(ListFieldItem) = -1) then
  449.       ListFieldItem := nil;
  450.   finally
  451.     FInCheckListFieldItem := False;
  452.   end;
  453. end;
  454. procedure TcxExtLookupComboBoxProperties.DeinitializeDataController;
  455. begin
  456.   inherited DeinitializeDataController;
  457.   if DataController <> nil then
  458.     DataController.RemoveDataChangeRefCount;
  459. end;
  460. procedure TcxExtLookupComboBoxProperties.FreeNotification(Sender: TComponent);
  461. begin
  462.   inherited FreeNotification(Sender);
  463.   if Sender = ListFieldItem then
  464.     ListFieldItem := nil;
  465.   if Sender = View then
  466.     View := nil;
  467. end;
  468. function TcxExtLookupComboBoxProperties.GetIncrementalFiltering: Boolean;
  469. begin
  470.   if FocusPopup then
  471.     Result := False
  472.   else
  473.     Result := inherited GetIncrementalFiltering;
  474. end;
  475. function TcxExtLookupComboBoxProperties.GetListIndex: Integer;
  476. begin
  477.   Result := Self.ListFieldIndex;
  478. end;
  479. procedure TcxExtLookupComboBoxProperties.InitializeDataController;
  480. begin
  481.   inherited InitializeDataController;
  482.   if DataController <> nil then
  483.     DataController.AddDataChangeRefCount;
  484. end;
  485. procedure TcxExtLookupComboBoxProperties.LinkView(AView: TcxCustomGridTableView);
  486. begin
  487.   CheckListFieldItem;
  488.   FreeNotificator.AddSender(AView);
  489.   InitializeDataController;
  490. end;
  491. function TcxExtLookupComboBoxProperties.PopupWindowCapturesFocus: Boolean;
  492. begin
  493.   Result := FocusPopup;
  494. end;
  495. procedure TcxExtLookupComboBoxProperties.UnlinkView(AView: TcxCustomGridTableView);
  496. begin
  497.   DeinitializeDataController;
  498.   FreeNotificator.RemoveSender(AView);
  499. end;
  500. // LookupGrid methods
  501. function TcxExtLookupComboBoxProperties.GetLookupGridActiveControl: TWinControl;
  502. begin
  503.   if View <> nil then
  504.     Result := View.Site
  505.   else
  506.     Result := inherited GetLookupGridActiveControl;
  507. end;
  508. function TcxExtLookupComboBoxProperties.GetLookupGridCanResize: Boolean;
  509. begin
  510.   if View <> nil then
  511.     Result := not TcxCustomGridTableOptionsViewAccess(View.OptionsView).CellAutoHeight
  512.   else
  513.     Result := False;
  514. end;
  515. function TcxExtLookupComboBoxProperties.GetLookupGridColumnCount: Integer;
  516. begin
  517.   if View <> nil then
  518.     Result := View.ItemCount
  519.   else
  520.     Result := 0;
  521. end;
  522. function TcxExtLookupComboBoxProperties.GetLookupGridControl: TWinControl;
  523. begin
  524.   Result := Grid;
  525. end;
  526. function TcxExtLookupComboBoxProperties.GetLookupGridDataController: TcxCustomDataController;
  527. begin
  528.   if View <> nil then
  529.     Result := View.DataController
  530.   else
  531.     Result := nil;
  532. end;
  533. function TcxExtLookupComboBoxProperties.GetLookupGridVisualAreaPreferredWidth: Integer;
  534. begin
  535.   Result := 0;
  536.   if View <> nil then
  537.     View.ViewInfo.GetWidth(Point(MaxInt, MaxInt), Result);
  538. end;
  539. function TcxExtLookupComboBoxProperties.GetLookupGridNearestPopupHeight(AHeight: Integer): Integer;
  540. begin
  541.   if View <> nil then
  542.     Result := View.ViewInfo.GetNearestPopupHeight(AHeight, FocusPopup)
  543.   else
  544.     Result := AHeight;
  545. end;
  546. function TcxExtLookupComboBoxProperties.GetLookupGridPopupHeight(ADropDownRowCount: Integer): Integer;
  547. begin
  548.   if View <> nil then
  549.   begin
  550.     if FocusPopup and (ADropDownRowCount < 2) then // TODO: Check New Item Row 
  551.       ADropDownRowCount := 2;
  552.     Result := View.ViewInfo.GetPopupHeight(ADropDownRowCount);
  553.   end
  554.   else
  555.     Result := 0;
  556. end;
  557. function TcxExtLookupComboBoxProperties.IsLookupGridMouseOverList(const P: TPoint): Boolean;
  558. var
  559.   AHitTest: TcxCustomGridHitTest;
  560. begin
  561.   Result := False;
  562.   if View <> nil then
  563.   begin
  564.     AHitTest := View.ViewInfo.GetHitTest(P);
  565.     Result := AHitTest is TcxGridRecordHitTest;
  566.   end;
  567. end;
  568. procedure TcxExtLookupComboBoxProperties.LookupGridDeinitialize;
  569. begin
  570.   Grid.Levels[0].GridView := nil;
  571.   // restore options
  572.   if (View <> nil) and not (csDestroying in View.ComponentState) then
  573.   begin
  574.     TcxCustomGridTableOptionsBehaviorAccess(View.OptionsBehavior).PullFocusing := FPrevPullFocusing;
  575.     View.OptionsSelection.MultiSelect := FPrevMultiSelect;
  576.     View.OptionsBehavior.ImmediateEditor := FPrevImmediateEditor;
  577.     if View is TcxGridTableView then
  578.       TcxGridTableView(View).OptionsCustomize.ColumnFiltering := FPrevColumnFiltering;
  579.     View.OptionsBehavior.IncSearch := FPrevIncSearch;
  580.     View.OnKeyDown := Grid.FPrevOnKeyDown;
  581.     View.OnMouseDown := Grid.FPrevOnMouseDown;
  582.     View.OnMouseMove := Grid.FPrevOnMouseMove;
  583.     View.OnMouseUp := Grid.FPrevOnMouseUp;
  584.   end;
  585. end;
  586. procedure TcxExtLookupComboBoxProperties.LookupGridDroppedDown(const AFindStr: string);
  587. begin
  588.   // Init Inc Search
  589.   // TODO: !!!
  590.   if FocusPopup and AutoSearchOnPopup and (ListFieldItem <> nil) then
  591.   begin
  592.     ListFieldItem.Focused := True;
  593.     View.DataController.Search.Locate(ListFieldItem.Index, AFindStr);
  594.   end;  
  595. end;
  596. procedure TcxExtLookupComboBoxProperties.LookupGridInitEvents(AOnClick, AOnFocusedRowChanged: TNotifyEvent;
  597.   AOnCloseUp: {$IFDEF VCL}cxLookupEdit{$ELSE}QcxLookupEdit{$ENDIF}.TcxLookupGridCloseUpEvent);
  598. begin
  599.   Grid.OnClick := AOnClick; // not impl
  600.   if View <> nil then
  601.   begin
  602. //    View.OnFocusedRecordChanged := AOnFocusedRowChanged;
  603.     Grid.OnCloseUp := AOnCloseUp; 
  604.   end;
  605. end;
  606. procedure TcxExtLookupComboBoxProperties.LookupGridInitialize;
  607. begin
  608.   if View = nil then Exit;
  609.   // save options
  610.   FPrevPullFocusing := TcxCustomGridTableOptionsBehaviorAccess(View.OptionsBehavior).PullFocusing;
  611.   TcxCustomGridTableOptionsBehaviorAccess(View.OptionsBehavior).PullFocusing := True;
  612.   FPrevMultiSelect := View.OptionsSelection.MultiSelect;
  613.   View.OptionsSelection.MultiSelect := False;
  614.   FPrevImmediateEditor := View.OptionsBehavior.ImmediateEditor;
  615.   View.OptionsBehavior.ImmediateEditor := False;
  616.   if View is TcxGridTableView then
  617.   begin
  618.     FPrevColumnFiltering := TcxGridTableView(View).OptionsCustomize.ColumnFiltering;
  619.     if not FocusPopup then
  620.       TcxGridTableView(View).OptionsCustomize.ColumnFiltering := False;
  621.   end;
  622.   Grid.FPrevOnKeyDown := View.OnKeyDown;
  623.   View.OnKeyDown := Grid.ViewKeyDown;
  624.   Grid.FPrevOnMouseDown := View.OnMouseDown;
  625.   View.OnMouseDown := Grid.ViewMouseDown;
  626.   Grid.FMousePos := Point(-1, -1);
  627.   Grid.FPrevOnMouseMove := View.OnMouseMove;
  628.   View.OnMouseMove := Grid.ViewMouseMove;
  629.   Grid.FPrevOnMouseUp := View.OnMouseUp;
  630.   View.OnMouseUp := Grid.ViewMouseUp;
  631.   Grid.Editable := FocusPopup;
  632.   Grid.Levels[0].GridView := View;
  633.   FPrevIncSearch := View.OptionsBehavior.IncSearch;
  634.   if FocusPopup and AutoSearchOnPopup then
  635.     View.OptionsBehavior.IncSearch := True;
  636.   View.DataController.Search.Cancel;  
  637. end;
  638. procedure TcxExtLookupComboBoxProperties.LookupGridInitLookAndFeel(ALookAndFeel: TcxLookAndFeel;
  639.   AColor: TColor; AFont: TFont);
  640. begin
  641.   Grid.LookAndFeel.MasterLookAndFeel := ALookAndFeel;
  642.   Grid.Color := AColor;
  643.   Grid.Font := AFont;
  644. end;
  645. procedure TcxExtLookupComboBoxProperties.LookupGridLockMouseMove;
  646. begin
  647.   Grid.PopupMouseMoveLocked := True;
  648. end;
  649. procedure TcxExtLookupComboBoxProperties.LookupGridMakeFocusedRowVisible;
  650. begin
  651.   if View <> nil then
  652.     View.Controller.MakeFocusedRecordVisible;
  653. end;
  654. procedure TcxExtLookupComboBoxProperties.LookupGridUnlockMouseMove;
  655. begin
  656.   Grid.MouseCapture := False;
  657.   Grid.PopupMouseMoveLocked := False;
  658. end;
  659. // DBLookupGrid methods
  660. procedure TcxExtLookupComboBoxProperties.DBLookupGridBeginUpdate;
  661. begin
  662.   if View <> nil then View.BeginUpdate;
  663. end;
  664. procedure TcxExtLookupComboBoxProperties.DBLookupGridCheckColumnByFieldName(const AFieldName: string);
  665. begin
  666.   if (View <> nil) and (DataController <> nil) then
  667.   begin
  668.     if (AFieldName <> '') and (DataController.GetItemByFieldName(AFieldName) = nil) then
  669.       with View.CreateItem do
  670.       begin
  671.         Index := 0;
  672.         DataController.ChangeFieldName(Index, AFieldName);
  673.       end;
  674.   end;
  675. end;
  676. procedure TcxExtLookupComboBoxProperties.DBLookupGridCreateColumnsByFieldNames(const AFieldNames: string);
  677. var
  678.   I: Integer;
  679.   AFieldNamesList: TStrings;
  680. begin
  681.   if View <> nil then
  682.   begin
  683.     View.ClearItems;
  684.     AFieldNamesList := TStringList.Create;
  685.     try
  686.       GetFieldNames(AFieldNames, AFieldNamesList);
  687.       View.BeginUpdate;
  688.       try
  689.         for I := 0 to AFieldNamesList.Count - 1 do
  690.           DataController.ChangeFieldName(View.CreateItem.Index, AFieldNamesList[I]);
  691.       finally
  692.         View.EndUpdate;
  693.       end;
  694.     finally
  695.       AFieldNamesList.Free;
  696.     end;
  697.   end;
  698. end;
  699. procedure TcxExtLookupComboBoxProperties.DBLookupGridEndUpdate;
  700. begin
  701.   if View <> nil then View.EndUpdate;
  702. end;
  703. function TcxExtLookupComboBoxProperties.GetDBLookupGridColumnField(AIndex: Integer): TField;
  704. begin
  705.   if DataController <> nil then
  706.     Result := DataController.GetItemField(AIndex)
  707.   else
  708.     Result := nil;
  709. end;
  710. function TcxExtLookupComboBoxProperties.GetDBLookupGridColumnFieldName(AIndex: Integer): string;
  711. begin
  712.   if DataController <> nil then
  713.     Result := DataController.GetItemFieldName(AIndex)
  714.   else
  715.     Result := '';
  716. end;
  717. function TcxExtLookupComboBoxProperties.GetDBLookupGridColumnIndexByFieldName(const AFieldName: string): Integer;
  718. var
  719.   AItem: TcxCustomGridTableItem;
  720. begin
  721.   if DataController <> nil then
  722.   begin
  723.     AItem := TcxCustomGridTableItem(DataController.GetItemByFieldName(AFieldName));
  724.     Result := AItem.Index;
  725.   end
  726.   else
  727.     Result := -1;
  728. end;
  729. function TcxExtLookupComboBoxProperties.GetDBLookupGridDataController: TcxDBDataController;
  730. begin
  731.   Result := TcxDBDataController(GetLookupGridDataController);
  732. end;
  733. function TcxExtLookupComboBoxProperties.GetGridMode: Boolean;
  734. begin
  735.   Result := inherited IsUseLookupList;
  736. end;
  737. function TcxExtLookupComboBoxProperties.GetListFieldIndex: Integer;
  738. var
  739.   AItem: TcxCustomGridTableItem;
  740. begin
  741.   if IsDefinedByLookup then
  742.     Result := GetDisplayColumnIndex
  743.   else
  744.   begin
  745.     AItem := ListFieldItem;
  746.     if AItem <> nil then
  747.       Result := AItem.Index
  748.     else
  749.       Result := -1;
  750.   end;  
  751. end;
  752. function TcxExtLookupComboBoxProperties.GetListFieldItem: TcxCustomGridTableItem;
  753. begin
  754.   if IsDefinedByLookup then
  755.     Result := nil
  756.   else
  757.     Result := FListFieldItem;
  758. end;
  759. procedure TcxExtLookupComboBoxProperties.SetGridMode(Value: Boolean);
  760. begin
  761.   inherited IsUseLookupList := Value;
  762. end;
  763. procedure TcxExtLookupComboBoxProperties.SetListFieldItem(Value: TcxCustomGridTableItem);
  764. begin
  765.   if (View <> nil) and (View.IndexOfItem(Value) = -1) then
  766.     Value := nil;
  767.   if FListFieldItem <> Value then
  768.   begin
  769.     if FListFieldItem <> nil then
  770.       FreeNotificator.RemoveSender(FListFieldItem);
  771.     FListFieldItem := Value;
  772.     if FListFieldItem <> nil then
  773.       FreeNotificator.AddSender(FListFieldItem);
  774.     if not FInCheckListFieldItem then
  775.       Changed;
  776.   end;
  777. end;
  778. procedure TcxExtLookupComboBoxProperties.SetView(Value: TcxCustomGridTableView);
  779. begin
  780.   if (Value <> nil) and not IsViewSupported(Value) then Exit;
  781.   if FView <> Value then
  782.   begin
  783.     if FView <> nil then
  784.       UnlinkView(FView);
  785.     FView := Value;
  786.     if FView <> nil then
  787.       LinkView(FView);
  788.     Changed;
  789.   end;
  790. end;
  791. { TcxCustomExtLookupComboBox }
  792. class function TcxCustomExtLookupComboBox.GetPropertiesClass: TcxCustomEditPropertiesClass;
  793. begin
  794.   Result := TcxExtLookupComboBoxProperties;
  795. end;
  796. function TcxCustomExtLookupComboBox.CanDropDown: Boolean;
  797. begin
  798.   if ActiveProperties.FocusPopup then
  799.     Result := True
  800.   else
  801.    Result := inherited CanDropDown;
  802. end;
  803. function TcxCustomExtLookupComboBox.GetActiveProperties: TcxExtLookupComboBoxProperties;
  804. begin
  805.   Result := TcxExtLookupComboBoxProperties(InternalGetActiveProperties);
  806. end;
  807. function TcxCustomExtLookupComboBox.GetProperties: TcxExtLookupComboBoxProperties;
  808. begin
  809.   Result := TcxExtLookupComboBoxProperties(FProperties);
  810. end;
  811. procedure TcxCustomExtLookupComboBox.SetProperties(Value: TcxExtLookupComboBoxProperties);
  812. begin
  813.   FProperties.Assign(Value);
  814. end;
  815. { TcxDBExtLookupComboBox }
  816. class function TcxDBExtLookupComboBox.GetDataBindingClass: TcxEditDataBindingClass;
  817. begin
  818.   Result := TcxDBLookupEditDataBinding;
  819. end;
  820. function TcxDBExtLookupComboBox.GetDataBinding: TcxDBTextEditDataBinding;
  821. begin
  822.   Result := TcxDBTextEditDataBinding(FDataBinding);
  823. end;
  824. procedure TcxDBExtLookupComboBox.SetDataBinding(Value: TcxDBTextEditDataBinding);
  825. begin
  826.   FDataBinding.Assign(Value);
  827. end;
  828. procedure TcxDBExtLookupComboBox.CMGetDataLink(var Message: TMessage);
  829. begin
  830.   Message.Result := Integer(GetcxDBEditDataLink(Self));
  831. end;
  832. { TcxEditRepositoryExtLookupComboBoxItem }
  833. class function TcxEditRepositoryExtLookupComboBoxItem.GetEditPropertiesClass: TcxCustomEditPropertiesClass;
  834. begin
  835.   Result := TcxExtLookupComboBoxProperties;
  836. end;
  837. function TcxEditRepositoryExtLookupComboBoxItem.GetProperties: TcxExtLookupComboBoxProperties;
  838. begin
  839.   Result := inherited Properties as TcxExtLookupComboBoxProperties;
  840. end;
  841. procedure TcxEditRepositoryExtLookupComboBoxItem.SetProperties(Value: TcxExtLookupComboBoxProperties);
  842. begin
  843.   inherited Properties := Value;
  844. end;
  845. initialization
  846.   RegisterClasses([TcxEditRepositoryExtLookupComboBoxItem]);
  847.   GetRegisteredEditProperties.Register(TcxExtLookupComboBoxProperties,
  848.     cxSEditRepositoryExtLookupComboBoxItem);
  849. end.