DBGridEh.pas
上传用户:lxdzzlq
上传日期:2013-01-26
资源大小:347k
文件大小:673k
源码类别:

Windows编程

开发平台:

C++ Builder

  1. {*******************************************************}
  2. {                                                       }
  3. {                    EhLib v4.1                         }
  4. {                                                       }
  5. {                  TDBGridEh component                  }
  6. {               with support of IMemTableEh             }
  7. {                      Build 4.1.27                     }
  8. {                                                       }
  9. {   Copyright (c) 1998-2005 by Dmitry V. Bolshakov      }
  10. {                                                       }
  11. {*******************************************************}
  12. {$I EhLib.Inc}
  13. {$IFDEF EH_LIB_VCL}
  14. unit DBGridEh{$IFDEF CIL}platform{$ENDIF};
  15. {$ELSE}
  16. unit QDBGridEh;
  17. {$ENDIF}
  18. //{$R-}
  19. interface
  20. {$IFDEF EH_LIB_VCL}
  21. uses Windows, SysUtils, Messages, Classes, Controls, Forms, StdCtrls,
  22.   {$IFDEF EH_LIB_5}Contnrs, {$ENDIF}
  23.   {$IFDEF EH_LIB_6}Variants, Types, {$ENDIF}
  24.   {$IFDEF CIL}
  25.   EhLibVCLNET,
  26.   WinUtils,
  27.   {$ELSE}
  28.   EhLibVCL,
  29.   {$ENDIF}
  30.   Graphics, GridsEh, DBCtrls, Db, Menus, Registry, DBSumLst, DBCtrlsEh,
  31.   IniFiles, ToolCtrlsEh, ImgList, StdActns, PropFilerEh     //The PropStorage
  32.   {,dbugintf};
  33. {$ELSE}
  34. uses SysUtils, Classes, Types, QControls, QForms, QStdCtrls,
  35.   Variants, QGraphics, QGrids, QDBCtrls, Db, QMenus, QDBGrids, QDBSumLst, QDBCtrlsEh,
  36.   IniFiles, QToolCtrlsEh, QImgList, QStdActns, Qt;
  37. {$ENDIF}
  38. type
  39.   TDBGridColumnsState = (csDefault, csCustomized);
  40.   TDrawDataCellEvent = procedure(Sender: TObject; const Rect: TRect; Field: TField;
  41.     State: TGridDrawState) of object;
  42.   TDBGridOption = (dgEditing, dgAlwaysShowEditor, dgTitles, dgIndicator,
  43.     dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect,
  44.     dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgMultiSelect);
  45.   TDBGridOptions = set of TDBGridOption;
  46.   TColumnEhValue = (cvColor, cvWidth, cvFont, cvAlignment, cvReadOnly, cvTitleColor,
  47.     cvTitleCaption, cvTitleAlignment, cvTitleFont, cvTitleButton, cvTitleEndEllipsis,
  48.     cvTitleToolTips, cvTitleOrientation, cvImeMode, cvImeName, cvWordWrap,
  49.     cvLookupDisplayFields, cvCheckboxes, cvAlwaysShowEditButton, cvEndEllipsis,
  50.     cvAutoDropDown, cvDblClickNextVal, cvToolTips, cvDropDownSizing,
  51.     cvDropDownShowTitles, cvLayout, cvHighlightRequired, cvBiDiMode);
  52.   TColumnEhValues = set of TColumnEhValue;
  53.   TColumnFooterEhValue = (cvFooterAlignment, cvFooterFont, cvFooterColor, cvFooterToolTips);
  54.   TColumnFooterValues = set of TColumnFooterEhValue;
  55.   TColumnEhRestoreParam = (crpColIndexEh, crpColWidthsEh, crpSortMarkerEh, crpColVisibleEh,
  56.     crpDropDownRowsEh, crpDropDownWidthEh);
  57.   TColumnEhRestoreParams = set of TColumnEhRestoreParam;
  58.   TDBGridEhRestoreParam = (grpColIndexEh, grpColWidthsEh, grpSortMarkerEh, grpColVisibleEh,
  59.     grpRowHeightEh, grpDropDownRowsEh, grpDropDownWidthEh);
  60.   TDBGridEhRestoreParams = set of TDBGridEhRestoreParam;
  61. const
  62.   /// 赖-2008-03-13 字段值为空
  63.   CS_NULLVALUE = '<NULL>';
  64.   cm_DeferLayout = WM_USER + 100;
  65.   IndicatorWidth = 11;
  66.   ColumnEhTitleValues = [cvTitleColor..cvTitleOrientation];
  67.   ColumnEhFooterValues = [cvFooterAlignment..cvFooterColor];
  68.   (*  cm_DeferLayout = WM_USER + 100; *)
  69.   { TColumnEh defines internal storage for column attributes.  If IsStored is
  70.     True, values assigned to properties are stored in this object, the grid-
  71.     or field-based default sources are not modified.  Values read from
  72.     properties are the previously assigned value, if any, or the grid- or
  73.     field-based default values if nothing has been assigned to that property.
  74.     This class also publishes the column attribute properties for persistent
  75.     storage.
  76.     If IsStored is True, the column does not maintain local storage of
  77.     property values.  Assignments to column properties are passed through to
  78.     the underlying grid- or field-based default sources.  }
  79. type
  80.   TColumnEh = class;
  81.   TCustomDBGridEh = class;
  82.   TColumnDropDownBoxEh = class;
  83.   TDBGridEhStyle = class;
  84.   {    for lookup drop-down grid    }
  85.   TDBLookupGridEhOption = (dlgColumnResizeEh, dlgColLinesEh, dlgRowLinesEh,
  86.     dlgAutoSortMarkingEh, dlgMultiSortMarkingEh);
  87.   TDBLookupGridEhOptions = set of TDBLookupGridEhOption;
  88.   TCheckTitleEhBtnEvent = procedure(Sender: TObject; ACol: Longint;
  89.     Column: TColumnEh; var Enabled: Boolean) of object;
  90.   TDrawColumnEhCellEvent = procedure(Sender: TObject; const Rect: TRect;
  91.     DataCol: Integer; Column: TColumnEh; State: TGridDrawState) of object;
  92.   TGetCellEhParamsEvent = procedure(Sender: TObject; Column: TColumnEh;
  93.     AFont: TFont; var Background: TColor; State: TGridDrawState) of object;
  94.   TTitleEhClickEvent = procedure(Sender: TObject; ACol: Longint;
  95.     Column: TColumnEh) of object;
  96.   TOnColumnCheckDrawRequiredStateEventEh = procedure(Sender: TObject;
  97.     Text: string; var DrawState: Boolean) of object;
  98.   TGridMoveRecordsEventEh = function(Sender: TObject; BookmarkList: TStrings;
  99.     ToRecNo: Longint; TreeLevel: Integer; CheckOnly: Boolean): Boolean of object;
  100.   { ILookupGridOwner interface }
  101.   ILookupGridOwner = interface
  102.     ['{2A1F4552-15C3-4359-ADAB-F2F6719FAA97}']
  103.     procedure SetListSource(AListSource: TDataSource);
  104.     function GetLookupGrid: TCustomDBGridEh;
  105.     function GetOptions: TDBLookupGridEhOptions;
  106.     procedure SetOptions(Value: TDBLookupGridEhOptions);
  107.     property Options: TDBLookupGridEhOptions read GetOptions write SetOptions;
  108.   end;
  109.   TSortMarkerEh = (smNoneEh, smDownEh, smUpEh);
  110.   TTextOrientationEh = (tohHorizontal, tohVertical);
  111.   { TColumnTitleEh }
  112.   TColumnTitleEh = class(TPersistent)
  113.   private
  114.     FAlignment: TAlignment;
  115.     FCaption: string;
  116.     FColor: TColor;
  117.     FColumn: TColumnEh;
  118.     FEndEllipsis: Boolean;
  119.     FFont: TFont;
  120.     FHint: string;
  121.     FImageIndex: Integer;
  122.     FOrientation: TTextOrientationEh;
  123.     FSortIndex: Integer;
  124.     FToolTips: Boolean;
  125.     function GetAlignment: TAlignment;
  126.     function GetCaption: string;
  127.     function GetColor: TColor;
  128.     function GetEndEllipsis: Boolean;
  129.     function GetFont: TFont;
  130.     function GetOrientation: TTextOrientationEh;
  131.     function GetTitleButton: Boolean;
  132.     function GetToolTips: Boolean;
  133.     function IsAlignmentStored: Boolean;
  134.     function IsCaptionStored: Boolean;
  135.     function IsColorStored: Boolean;
  136.     function IsEndEllipsisStored: Boolean;
  137.     function IsFontStored: Boolean;
  138.     function IsOrientationStored: Boolean;
  139.     function IsTitleButtonStored: Boolean;
  140.     function IsToolTipsStored: Boolean;
  141.     procedure FontChanged(Sender: TObject);
  142.     procedure SetAlignment(Value: TAlignment);
  143.     procedure SetCaption(const Value: string); virtual;
  144.     procedure SetColor(Value: TColor);
  145.     procedure SetEndEllipsis(const Value: Boolean);
  146.     procedure SetFont(Value: TFont);
  147.     procedure SetImageIndex(const Value: Integer);
  148.     procedure SetOrientation(const Value: TTextOrientationEh);
  149.     procedure SetSortIndex(Value: Integer);
  150.     procedure SetToolTips(const Value: Boolean);
  151.   protected
  152.     FSortMarker: TSortMarkerEh;
  153.     FTitleButton: Boolean;
  154.     function GetSortMarkingWidth: Integer;
  155.     procedure RefreshDefaultFont;
  156.     procedure SetSortMarker(Value: TSortMarkerEh);
  157.     procedure SetTitleButton(Value: Boolean);
  158.   public
  159.     constructor Create(Column: TColumnEh);
  160.     destructor Destroy; override;
  161.     function DefaultAlignment: TAlignment;
  162.     function DefaultCaption: string;
  163.     function DefaultColor: TColor;
  164.     function DefaultEndEllipsis: Boolean;
  165.     function DefaultFont: TFont;
  166.     function DefaultOrientation: TTextOrientationEh;
  167.     function DefaultTitleButton: Boolean;
  168.     function DefaultToolTips: Boolean;
  169.     procedure Assign(Source: TPersistent); override;
  170.     procedure RestoreDefaults; virtual;
  171.     procedure SetNextSortMarkerValue(KeepMulti: Boolean);
  172.     property Column: TColumnEh read FColumn;
  173.   published
  174.     property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
  175.     property Caption: string read GetCaption write SetCaption stored IsCaptionStored;
  176.     property Color: TColor read GetColor write SetColor stored IsColorStored;
  177.     property EndEllipsis: Boolean read GetEndEllipsis write SetEndEllipsis stored IsEndEllipsisStored;
  178.     property Font: TFont read GetFont write SetFont stored IsFontStored;
  179.     property Hint: string read FHint write FHint;
  180.     property ImageIndex: Integer read FImageIndex write SetImageIndex default -1;
  181.     property Orientation: TTextOrientationEh read GetOrientation write SetOrientation stored IsOrientationStored;
  182.     property SortIndex: Integer read FSortIndex write SetSortIndex default 0;
  183.     property SortMarker: TSortMarkerEh read FSortMarker write SetSortMarker default smNoneEh;
  184.     property TitleButton: Boolean read GetTitleButton write SetTitleButton stored IsTitleButtonStored;
  185.     property ToolTips: Boolean read GetToolTips write SetToolTips stored IsToolTipsStored;
  186.   end;
  187.   { TColumnFooterEh }
  188.   TFooterValueType = (fvtNon, fvtSum, fvtAvg, fvtCount, fvtFieldValue, fvtStaticText);
  189.   TColumnFooterEh = class(TCollectionItem)
  190.   private
  191.     FAlignment: TAlignment;
  192.     FAssignedValues: TColumnFooterValues;
  193.     FColor: TColor;
  194.     FColumn: TColumnEh;
  195.     FDisplayFormat: string;
  196.     FEndEllipsis: Boolean;
  197.     FFieldName: string;
  198.     FFont: TFont;
  199.     FToolTips: Boolean;
  200.     FValue: string;
  201.     FValueType: TFooterValueType;
  202.     FWordWrap: Boolean;
  203.     function GetAlignment: TAlignment;
  204.     function GetColor: TColor;
  205.     function GetFont: TFont;
  206.     function GetSumValue: Variant;
  207.     function GetToolTips: Boolean;
  208.     function IsAlignmentStored: Boolean;
  209.     function IsColorStored: Boolean;
  210.     function IsFontStored: Boolean;
  211.     function IsToolTipsStored: Boolean;
  212.     procedure FontChanged(Sender: TObject);
  213.     procedure SetAlignment(Value: TAlignment);
  214.     procedure SetColor(Value: TColor);
  215.     procedure SetDisplayFormat(const Value: string);
  216.     procedure SetEndEllipsis(const Value: Boolean);
  217.     procedure SetFieldName(const Value: string);
  218.     procedure SetFont(Value: TFont);
  219.     procedure SetToolTips(const Value: Boolean);
  220.     procedure SetValue(const Value: string);
  221.     procedure SetValueType(const Value: TFooterValueType);
  222.     procedure SetWordWrap(const Value: Boolean);
  223.   protected
  224.     FDBSum: TDBSum;
  225.     procedure RefreshDefaultFont;
  226.   public
  227.     constructor Create(Collection: TCollection); override;
  228.     constructor CreateApart(Column: TColumnEh);
  229.     destructor Destroy; override;
  230.     function DefaultAlignment: TAlignment;
  231.     function DefaultColor: TColor;
  232.     function DefaultFont: TFont;
  233.     function DefaultToolTips: Boolean;
  234.     procedure Assign(Source: TPersistent); override;
  235.     procedure EnsureSumValue;
  236.     procedure RestoreDefaults; virtual;
  237.     property AssignedValues: TColumnFooterValues read FAssignedValues;
  238.     property Column: TColumnEh read FColumn;
  239.     property SumValue: Variant read GetSumValue;
  240.   published
  241.     property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
  242.     property Color: TColor read GetColor write SetColor stored IsColorStored;
  243.     property DisplayFormat: string read FDisplayFormat write SetDisplayFormat;
  244.     property EndEllipsis: Boolean read FEndEllipsis write SetEndEllipsis default False;
  245.     property FieldName: string read FFieldName write SetFieldName;
  246.     property Font: TFont read GetFont write SetFont stored IsFontStored;
  247.     property ToolTips: Boolean read GetToolTips write SetToolTips stored IsToolTipsStored;
  248.     property Value: string read FValue write SetValue;
  249.     property ValueType: TFooterValueType read FValueType write SetValueType default fvtNon;
  250.     property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
  251.   end;
  252.   TColumnFooterEhClass = class of TColumnFooterEh;
  253.   { TColumnFootersEh }
  254.   TColumnFootersEh = class(TCollection)
  255.   private
  256.     FColumn: TColumnEh;
  257.     function GetFooter(Index: Integer): TColumnFooterEh;
  258.     procedure SetFooter(Index: Integer; Value: TColumnFooterEh);
  259.   protected
  260.     function GetOwner: TPersistent; override;
  261.     procedure Update(Item: TCollectionItem); override;
  262.   public
  263.     constructor Create(Column: TColumnEh; FooterClass: TColumnFooterEhClass);
  264.     function Add: TColumnFooterEh;
  265.     property Column: TColumnEh read FColumn;
  266.     property Items[Index: Integer]: TColumnFooterEh read GetFooter write SetFooter; default;
  267.   end;
  268.   TColumnEhType = (ctCommon, ctPickList, ctLookupField, ctKeyPickList, ctKeyImageList,
  269.     ctCheckboxes);
  270.   TColumnButtonStyleEh = (cbsAuto, cbsEllipsis, cbsNone, cbsUpDown, cbsDropDown);
  271.   { TColumnTitleDefValuesEh }
  272.   TColumnDefValuesEh = class;
  273.   TColumnTitleDefValuesEhValue = (cvdpTitleColorEh, cvdpTitleAlignmentEh);
  274.   TColumnTitleDefValuesEhValues = set of TColumnTitleDefValuesEhValue;
  275.   TColumnTitleDefValuesEh = class(TPersistent)
  276.   private
  277.     FAlignment: TAlignment;
  278.     FAssignedValues: TColumnTitleDefValuesEhValues;
  279.     FColor: TColor;
  280.     FColumnDefValues: TColumnDefValuesEh;
  281.     FEndEllipsis: Boolean;
  282.     FOrientation: TTextOrientationEh;
  283.     FTitleButton: Boolean;
  284.     FToolTips: Boolean;
  285.     function DefaultAlignment: TAlignment;
  286.     function DefaultColor: TColor;
  287.     function GetAlignment: TAlignment;
  288.     function GetColor: TColor;
  289.     function IsAlignmentStored: Boolean;
  290.     function IsColorStored: Boolean;
  291.     procedure SetAlignment(const Value: TAlignment);
  292.     procedure SetColor(const Value: TColor);
  293.     procedure SetEndEllipsis(const Value: Boolean);
  294.     procedure SetOrientation(const Value: TTextOrientationEh);
  295.   public
  296.     procedure Assign(Source: TPersistent); override;
  297.     property AssignedValues: TColumnTitleDefValuesEhValues read FAssignedValues;
  298.   published
  299.     constructor Create(ColumnDefValues: TColumnDefValuesEh);
  300.     property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
  301.     property Color: TColor read GetColor write SetColor stored IsColorStored;
  302.     property EndEllipsis: Boolean read FEndEllipsis write SetEndEllipsis default False;
  303.     property Orientation: TTextOrientationEh read FOrientation write SetOrientation default tohHorizontal;
  304.     property TitleButton: Boolean read FTitleButton write FTitleButton default False;
  305.     property ToolTips: Boolean read FToolTips write FToolTips default False;
  306.   end;
  307.   { TColumnFooterDefValuesEh }
  308.   TColumnFooterDefValuesEh = class(TPersistent)
  309.   private
  310.     FToolTips: Boolean;
  311.   public
  312.     procedure Assign(Source: TPersistent); override;
  313.   published
  314.     property ToolTips: Boolean read FToolTips write FToolTips default False;
  315.   end;
  316.   { TColumnDefValuesEh }
  317.   TColumnDefValuesEh = class(TPersistent)
  318.   private
  319.     FAlwaysShowEditButton: Boolean;
  320.     FAutoDropDown: Boolean;
  321.     FDblClickNextVal: Boolean;
  322.     FDropDownShowTitles: Boolean;
  323.     FDropDownSizing: Boolean;
  324.     FEndEllipsis: Boolean;
  325.     FLayout: TTextLayout;
  326.     FHighlightRequired: Boolean;
  327.     FGrid: TCustomDBGridEh;
  328.     FTitle: TColumnTitleDefValuesEh;
  329.     FFooter: TColumnFooterDefValuesEh;
  330.     FToolTips: Boolean;
  331.     procedure SetAlwaysShowEditButton(const Value: Boolean);
  332.     procedure SetEndEllipsis(const Value: Boolean);
  333.     procedure SetFooter(const Value: TColumnFooterDefValuesEh);
  334.     procedure SetHighlightRequired(Value: Boolean);
  335.     procedure SetLayout(Value: TTextLayout);
  336.     procedure SetTitle(const Value: TColumnTitleDefValuesEh);
  337.   public
  338.     procedure Assign(Source: TPersistent); override;
  339.   public
  340.     constructor Create(Grid: TCustomDBGridEh);
  341.     destructor Destroy; override;
  342.     property AlwaysShowEditButton: Boolean read FAlwaysShowEditButton write SetAlwaysShowEditButton default False;
  343.     property AutoDropDown: Boolean read FAutoDropDown write FAutoDropDown default False;
  344.     property DblClickNextVal: Boolean read FDblClickNextVal write FDblClickNextVal default False;
  345.     property DropDownShowTitles: Boolean read FDropDownShowTitles write FDropDownShowTitles default False;
  346.     property DropDownSizing: Boolean read FDropDownSizing write FDropDownSizing default False;
  347.     property EndEllipsis: Boolean read FEndEllipsis write SetEndEllipsis default False;
  348.     property Footer: TColumnFooterDefValuesEh read FFooter write SetFooter;
  349.     property HighlightRequired: Boolean read FHighlightRequired write SetHighlightRequired default False;
  350.     property Layout: TTextLayout read FLayout write SetLayout default tlTop;
  351.     property Title: TColumnTitleDefValuesEh read FTitle write SetTitle;
  352.     property ToolTips: Boolean read FToolTips write FToolTips default False;
  353.   end;
  354.   TDBGridEhColumnDefValuesEh = class(TColumnDefValuesEh)
  355.   published
  356.     property AlwaysShowEditButton;
  357.     property AutoDropDown;
  358.     property DblClickNextVal;
  359.     property DropDownShowTitles;
  360.     property DropDownSizing;
  361.     property EndEllipsis;
  362.     property Footer;
  363.     property HighlightRequired;
  364.     property Layout;
  365.     property Title;
  366.     property ToolTips;
  367.   end;
  368.   { TSTColumnFilterEh }
  369.   TSTFilterOperatorEh = (
  370.     foNon, foEqual, foNotEqual,
  371.     foGreaterThan, foLessThan, foGreaterOrEqual, foLessOrEqual,
  372.     foLike, foNotLike,
  373.     foIn, foNotIn,
  374.     foNull, foNotNull,
  375.     foAND, foOR,
  376.     foValue);
  377.   TSTOperandTypeEh = (botNon, botString, botNumber, botDateTime, botBoolean);
  378.   TSTFilterExpressionEh = record
  379.     ExpressionType: TSTOperandTypeEh;
  380.     Operator1: TSTFilterOperatorEh;
  381.     Operand1: Variant;
  382.     Relation: TSTFilterOperatorEh;                          // foAND, foOR, foNon
  383.     Operator2: TSTFilterOperatorEh;
  384.     Operand2: Variant;
  385.   end;
  386.   TSTColumnFilterEh = class(TPersistent)
  387.   private
  388.     FColumn: TColumnEh;
  389.     FDataField: string;
  390.     FKeyCommaText: string;
  391.     FKeyField: string;
  392.     FKeys: TStrings;
  393.     FKeyValues: Variant;
  394.     FList: TStrings;
  395.     FListField: string;
  396.     FListLink: TFieldDataLink;
  397.     FVisible: Boolean;
  398.     FDropDownListWidth: Integer;
  399.     FDropDownListRows: Integer;
  400.     function GetExpression: TSTFilterExpressionEh;
  401.     function GetGrid: TCustomDBGridEh;
  402.     function GetListSource: TDataSource;
  403.     function ParseExpression(Exp: string): string;
  404.     procedure ListLinkActiveChange(Sender: TObject);
  405.     procedure SetExpression(const Value: TSTFilterExpressionEh);
  406.     procedure SetExpressionStr(const Value: string);
  407.     procedure SetListSource(const Value: TDataSource);
  408.     procedure SetVisible(const Value: Boolean);
  409.   protected
  410.     FExpression: TSTFilterExpressionEh;
  411.     FExpressionStr: string;
  412.     function GetExpressionAsString: string; virtual;
  413.     function DropDownButtonVisible: Boolean; virtual;
  414.     procedure InternalSetExpressionStr(const Value: string);
  415.     procedure CheckRecodeKeyList(var FExpression: TSTFilterExpressionEh); virtual;
  416.   public
  417.     constructor Create(AColumn: TColumnEh);
  418.     destructor Destroy; override;
  419.     function GetFieldValueList: IMemTableDataFieldValueListEh;
  420.     function GetFilterFieldName: string; virtual;
  421.     function GetOperand1: Variant; virtual;
  422.     function GetOperand2: Variant; virtual;
  423.     function CurrentKeyField: string;
  424.     function CurrentDataField: string;
  425.     function CurrentListDataSet: TDataSet;
  426.     function CurrentListField: string;
  427.     procedure Assign(Source: TPersistent); override;
  428.     procedure Clear;
  429.     procedure SetKeyListValues(AText: string; KeyVals: Variant);
  430.     procedure SetKeysFromListValues(ss: TStrings);
  431.     property DropDownListWidth: Integer read FDropDownListWidth write FDropDownListWidth default 0;
  432.     property DropDownListRows: Integer read FDropDownListRows write FDropDownListRows default 0;
  433.     property Column: TColumnEh read FColumn;
  434.     property Expression: TSTFilterExpressionEh read GetExpression write SetExpression;
  435.     property ExpressionStr: string read FExpressionStr write SetExpressionStr;
  436.     property Grid: TCustomDBGridEh read GetGrid;
  437.     property KeyCommaText: string read FKeyCommaText write FKeyCommaText;
  438.   published
  439.     property DataField: string read FDataField write FDataField;
  440.     property KeyField: string read FKeyField write FKeyField;
  441.     property ListField: string read FListField write FListField;
  442.     property ListSource: TDataSource read GetListSource write SetListSource;
  443.     property Visible: Boolean read FVisible write SetVisible default True;
  444.   end;
  445.   { TColumnEh }
  446.   TColCellParamsEh = class(TObject)
  447.   protected
  448.     FAlignment: TAlignment;
  449.     FBackground: TColor;
  450.     FCheckboxState: TCheckBoxState;
  451.     FCol: Longint;
  452.     FFont: TFont;
  453.     FImageIndex: Integer;
  454.     FReadOnly: Boolean;
  455.     FRow: Longint;
  456.     FState: TGridDrawState;
  457.     FText: string;
  458.   public
  459.     property Alignment: TAlignment read FAlignment write FAlignment;
  460.     property Background: TColor read FBackground write FBackground;
  461.     property CheckboxState: TCheckBoxState read FCheckboxState write FCheckboxState;
  462.     property Col: Longint read FCol write FCol;
  463.     property Font: TFont read FFont write FFont;
  464.     property ImageIndex: Integer read FImageIndex write FImageIndex;
  465.     property ReadOnly: Boolean read FReadOnly write FReadOnly;
  466.     property Row: Longint read FRow write FRow;
  467.     property State: TGridDrawState read FState write FState;
  468.     property Text: string read FText write FText;
  469.   end;
  470.   TGetColCellParamsEventEh = procedure(Sender: TObject; EditMode: Boolean;
  471.     Params: TColCellParamsEh) of object;
  472.   TColCellUpdateDataEventEh = procedure(Sender: TObject; var Text: string;
  473.     var Value: Variant; var UseText: Boolean; var Handled: Boolean) of object;
  474.   TColumnEh = class(TCollectionItem, ILookupGridOwner{$IFNDEF CIL}, IUnknown{$ENDIF})
  475.   private
  476.     FAlignment: TAlignment;
  477.     FAssignedValues: TColumnEhValues;
  478.     FBiDiMode: TBiDiMode;
  479.     FButtonStyle: TColumnButtonStyleEh;
  480.     FCheckboxes: Boolean;
  481.     FColor: TColor;
  482.     FDblClickNextVal: Boolean;
  483.     FDisplayFormat: string;
  484.     FDropDownBox: TColumnDropDownBoxEh;
  485.     FDropDownRows: Cardinal;
  486.     FDropDownShowTitles: Boolean;
  487.     FDropDownSizing: Boolean;
  488.     FDropDownSpecRow: TSpecRowEh;
  489.     FEditButtons: TEditButtonsEh;
  490.     FEditMask: string;
  491.     FField: TField;
  492.     FFieldName: string;
  493.     FFont: TFont;
  494.     FFooter: TColumnFooterEh;
  495.     FFooters: TColumnFootersEh;
  496.     FHideDuplicates: Boolean;
  497.     FHighlightRequired: Boolean;
  498.     FImageList: TCustomImageList;
  499.     FImageChangeLink: TChangeLink;
  500.     {$IFDEF EH_LIB_VCL}
  501.     FImeMode: TImeMode;
  502.     FImeName: TImeName;
  503.     {$ENDIF}
  504.     FIncrement: Extended;
  505.     FLayout: TTextLayout;
  506.     FKeyList: TStrings;
  507.     FMaxWidth: Integer;
  508.     FMinWidth: Integer;
  509.     FMRUList: TMRUListEh;
  510.     FNotInKeyListIndex: Integer;
  511.     FNotInWidthRange: Boolean;
  512.     FOnButtonClick: TButtonClickEventEh;
  513.     FOnButtonDown: TButtonDownEventEh;
  514.     FOnGetCellParams: TGetColCellParamsEventEh;
  515.     //    FOnGetItemImageIndex: TListGetImageIndexEventEh;
  516.     FOnNotInList: TNotInListEventEh;
  517.     FPickList: TStrings;
  518.     FPopupMenu: TPopupMenu;
  519.     FReadonly: Boolean;
  520.     FStored: Boolean;
  521.     FShowImageAndText: Boolean;
  522.     FTag: Longint;
  523.     FTitle: TColumnTitleEh;
  524.     FToolTips: Boolean;
  525.     FUpdateData: TColCellUpdateDataEventEh;
  526.     FVisible: Boolean;
  527.     FWidth: Integer;
  528.     FSTFilter: TSTColumnFilterEh;
  529.     FFieldValueList: IMemTableDataFieldValueListEh;
  530.     FOnCheckDrawRequiredState: TOnColumnCheckDrawRequiredStateEventEh;
  531.     function DefaultCheckboxes: Boolean;
  532.     function GetAlignment: TAlignment;
  533.     function GetAlwaysShowEditButton: Boolean;
  534.     function GetAutoDropDown: Boolean;
  535.     function GetBiDiMode: TBiDiMode;
  536.     function GetCheckboxes: Boolean;
  537.     function GetCheckboxState: TCheckBoxState;
  538.     function GetColor: TColor;
  539.     function GetDataList: TCustomDBGridEh;
  540.     function GetDblClickNextVal: Boolean;
  541.     function GetDropDownShowTitles: Boolean;
  542.     function GetDropDownSizing: Boolean;
  543.     function GetEndEllipsis: Boolean;
  544.     function GetField: TField;
  545.     function GetFont: TFont;
  546.     {$IFDEF EH_LIB_VCL}
  547.     function GetImeMode: TImeMode;
  548.     function GetImeName: TImeName;
  549.     {$ENDIF}
  550.     function GetHighlightRequired: Boolean;
  551.     function GetKeykList: TStrings;
  552.     function GetLayout: TTextLayout;
  553.     function GetOnDropDownBoxCheckButton: TCheckTitleEhBtnEvent;
  554.     function GetOnDropDownBoxDrawColumnCell: TDrawColumnEhCellEvent;
  555.     function GetOnDropDownBoxGetCellParams: TGetCellEhParamsEvent;
  556.     function GetOnDropDownBoxSortMarkingChanged: TNotifyEvent;
  557.     function GetOnDropDownBoxTitleBtnClick: TTitleEhClickEvent;
  558.     function GetPickList: TStrings;
  559.     function GetReadOnly: Boolean;
  560.     function GetShowImageAndText: Boolean;
  561.     function GetToolTips: Boolean;
  562.     function GetWidth: Integer;
  563.     function IsAlignmentStored: Boolean;
  564.     function IsAlwaysShowEditButtonStored: Boolean;
  565.     function IsAutoDropDownStored: Boolean;
  566.     function IsBiDiModeStored: Boolean;
  567.     function IsCheckboxesStored: Boolean;
  568.     function IsColorStored: Boolean;
  569.     function IsDblClickNextValStored: Boolean;
  570.     function IsDropDownShowTitlesStored: Boolean;
  571.     function IsDropDownSizingStored: Boolean;
  572.     function IsEndEllipsisStored: Boolean;
  573.     function IsFontStored: Boolean;
  574.     function IsImeModeStored: Boolean;
  575.     function IsImeNameStored: Boolean;
  576.     function IsIncrementStored: Boolean;
  577.     function IsReadOnlyStored: Boolean;
  578.     function IsToolTipsStored: Boolean;
  579.     function IsWidthStored: Boolean;
  580.     procedure EditButtonChanged(Sender: TObject);
  581.     procedure ImageListChange(Sender: TObject);
  582.     procedure FontChanged(Sender: TObject);
  583.     procedure SetBiDiMode(Value: TBiDiMode);
  584.     procedure SetButtonStyle(Value: TColumnButtonStyleEh);
  585.     procedure SetCheckboxes(const Value: Boolean);
  586.     procedure SetCheckboxState(const Value: TCheckBoxState);
  587.     procedure SetColor(Value: TColor);
  588.     procedure SetDblClickNextVal(const Value: Boolean);
  589.     procedure SetDisplayFormat(const Value: string);
  590.     procedure SetDropDownBox(const Value: TColumnDropDownBoxEh);
  591.     procedure SetDropDownShowTitles(const Value: Boolean);
  592.     procedure SetDropDownSizing(const Value: Boolean);
  593.     procedure SetDropDownSpecRow(const Value: TSpecRowEh);
  594.     procedure SetEditButtons(const Value: TEditButtonsEh);
  595.     procedure SetEditMask(const Value: string);
  596.     procedure SetFieldName(const Value: string);
  597.     procedure SetFont(Value: TFont);
  598.     procedure SetFooter(const Value: TColumnFooterEh);
  599.     procedure SetFooters(const Value: TColumnFootersEh);
  600.     procedure SetImageList(const Value: TCustomImageList);
  601.     procedure SetKeykList(const Value: TStrings);
  602.     procedure SetLayout(Value: TTextLayout);
  603.     procedure SetMaxWidth(const Value: Integer);
  604.     procedure SetMinWidth(const Value: Integer);
  605.     procedure SetMRUList(const Value: TMRUListEh);
  606.     procedure SetNotInKeyListIndex(const Value: Integer);
  607.     procedure SetOnDropDownBoxCheckButton(const Value: TCheckTitleEhBtnEvent);
  608.     procedure SetOnDropDownBoxDrawColumnCell(const Value: TDrawColumnEhCellEvent);
  609.     procedure SetOnDropDownBoxGetCellParams(const Value: TGetCellEhParamsEvent);
  610.     procedure SetOnDropDownBoxSortMarkingChanged(const Value: TNotifyEvent);
  611.     procedure SetOnDropDownBoxTitleBtnClick(const Value: TTitleEhClickEvent);
  612.     procedure SetOnGetCellParams(const Value: TGetColCellParamsEventEh);
  613.     procedure SetPickList(Value: TStrings);
  614.     procedure SetPopupMenu(Value: TPopupMenu);
  615.     procedure SetShowImageAndText(const Value: Boolean);
  616.     procedure SetSTFilter(const Value: TSTColumnFilterEh);
  617.     procedure SetTitle(Value: TColumnTitleEh);
  618.     procedure SetToolTips(const Value: Boolean);
  619.     procedure SetVisible(const Value: Boolean);
  620.   protected
  621.     FAlwaysShowEditButton: Boolean;
  622.     FAutoDropDown: Boolean;
  623.     FAutoFitColWidth: Boolean;
  624.     FDataList: TCustomDBGridEh;
  625.     FDropDownWidth: Integer;
  626.     FDTListSource: TDataSource;
  627.     FEndEllipsis: Boolean;
  628.     FInitWidth: Integer;
  629.     FLookupDisplayFields: string;
  630.     FWordWrap: Boolean;
  631.     function AllowableWidth(TryWidth: Integer): Integer;
  632.     function CreateEditButtons: TEditButtonsEh; virtual;
  633.     function CreateFooter: TColumnFooterEh; virtual;
  634.     function CreateFooters: TColumnFootersEh; virtual;
  635.     function CreateSTFilter: TSTColumnFilterEh; virtual;
  636.     function CreateTitle: TColumnTitleEh; virtual;
  637.     function DefaultAlwaysShowEditButton: Boolean;
  638.     function DefaultAutoDropDown: Boolean;
  639.     function DefaultDblClickNextVal: Boolean;
  640.     function DefaultDropDownShowTitles: Boolean;
  641.     function DefaultDropDownSizing: Boolean;
  642.     function DefaultEndEllipsis: Boolean;
  643.     function DefaultHighlightRequired: Boolean;
  644.     function DefaultLayout: TTextLayout;
  645.     function DefaultLookupDisplayFields: string;
  646.     function DefaultToolTips: Boolean;
  647.     function DefaultWordWrap: Boolean;
  648.     function GetAutoFitColWidth: Boolean;
  649.     function GetDisplayName: string; override;
  650.     function GetGrid: TCustomDBGridEh;
  651.     function GetLookupDisplayFields: string;
  652.     function GetWordWrap: Boolean;
  653.     function IsHighlightRequiredStored: Boolean;
  654.     function IsLayoutStored: Boolean;
  655.     function IsLookupDisplayFieldsStored: Boolean;
  656.     function IsWordWrapStored: Boolean;
  657.     function SeenPassthrough: Boolean; virtual;
  658.     function UsedLookupDataSet: TDataSet;
  659.     procedure Changed(AllItems: Boolean);
  660.     function FullListDataSet: TDataSet;
  661.     procedure EnsureSumValue;
  662.     procedure RefreshDefaultFont;
  663.     procedure SetAlignment(Value: TAlignment); virtual;
  664.     procedure SetAlwaysShowEditButton(Value: Boolean);
  665.     procedure SetAutoDropDown(Value: Boolean);
  666.     procedure SetAutoFitColWidth(Value: Boolean); virtual;
  667.     procedure SetDropDownWidth(Value: Integer);
  668.     procedure SetEndEllipsis(const Value: Boolean);
  669.     procedure SetField(Value: TField); virtual;
  670.     procedure SetHideDuplicates(Value: Boolean); virtual;
  671.     procedure SetHighlightRequired(Value: Boolean); virtual;
  672.     {$IFDEF EH_LIB_VCL}
  673.     procedure SetImeMode(Value: TImeMode); virtual;
  674.     procedure SetImeName(Value: TImeName); virtual;
  675.     {$ENDIF}
  676.     procedure SetIndex(Value: Integer); override;
  677.     procedure SetLookupDisplayFields(Value: string); virtual;
  678.     procedure SetNextFieldValue(Increment: Extended);
  679.     procedure SetReadOnly(Value: Boolean); virtual;
  680.     procedure SetWidth(Value: Integer); virtual;
  681.     procedure SetWordWrap(Value: Boolean); virtual;
  682.     procedure SpecRowChanged(Sender: TObject); virtual;
  683.     procedure UpdateDataValues(Text: string; Value: Variant; UseText: Boolean);
  684.     property IsStored: Boolean read FStored write FStored default True;
  685.     property FieldValueList: IMemTableDataFieldValueListEh read FFieldValueList write FFieldValueList;
  686.   protected
  687.     { ILookupGridOwner }
  688.     procedure SetDropDownBoxListSource(AListSource: TDataSource);
  689.     procedure ILookupGridOwner.SetListSource = SetDropDownBoxListSource;
  690.     function GetLookupGrid: TCustomDBGridEh;
  691.     function GetOptions: TDBLookupGridEhOptions;
  692.     procedure SetOptions(Value: TDBLookupGridEhOptions);
  693.     {$IFNDEF CIL}
  694.     { IInterface }
  695.     function QueryInterface(const IID: TGUID; out Obj): HResult; virtual; stdcall;
  696.     function _AddRef: Integer; stdcall;
  697.     function _Release: Integer; stdcall;
  698.     {$ENDIF}
  699.   public
  700.     constructor Create(Collection: TCollection); override;
  701.     destructor Destroy; override;
  702.     function CanModify(TryEdit: Boolean): Boolean;
  703.     function DefaultAlignment: TAlignment;
  704.     function DefaultColor: TColor;
  705.     function DefaultFont: TFont;
  706.     {$IFDEF EH_LIB_VCL}
  707.     function DefaultImeMode: TImeMode;
  708.     function DefaultImeName: TImeName;
  709.     {$ENDIF}
  710.     function DefaultReadOnly: Boolean;
  711.     function DefaultWidth: Integer;
  712.     function DisplayText: string;
  713.     function DrawTextBiDiModeFlagsReadingOnly: Longint;
  714.     function UseRightToLeftAlignment: Boolean; virtual;
  715.     function UseRightToLeftReading: Boolean;
  716.     function UseRightToLeftScrollBar: Boolean;
  717.     function EditButtonsWidth: Integer;
  718.     function GetColumnType: TColumnEhType;
  719.     function GetImageIndex: Integer;
  720.     function UsedFooter(Index: Integer): TColumnFooterEh;
  721.     procedure Assign(Source: TPersistent); override;
  722.     procedure DropDown;
  723.     procedure FillColCellParams(ColCellParamsEh: TColCellParamsEh);
  724.     procedure GetColCellParams(EditMode: Boolean; ColCellParamsEh: TColCellParamsEh); virtual;
  725.     procedure OptimizeWidth; virtual;
  726.     procedure RestoreDefaults; virtual;
  727.     property AssignedValues: TColumnEhValues read FAssignedValues;
  728.     property CheckboxState: TCheckBoxState read GetCheckboxState write SetCheckboxState;
  729.     property DataList: TCustomDBGridEh read GetDataList;
  730.     property Field: TField read GetField write SetField;
  731.     property Grid: TCustomDBGridEh read GetGrid;
  732.   public
  733.     property Alignment: TAlignment read GetAlignment write SetAlignment stored IsAlignmentStored;
  734.     property AlwaysShowEditButton: Boolean read GetAlwaysShowEditButton write SetAlwaysShowEditButton stored IsAlwaysShowEditButtonStored;
  735.     property AutoDropDown: Boolean read GetAutoDropDown write SetAutoDropDown stored IsAutoDropDownStored;
  736.     property AutoFitColWidth: Boolean read GetAutoFitColWidth write SetAutoFitColWidth default True;
  737.     property ButtonStyle: TColumnButtonStyleEh read FButtonStyle write SetButtonStyle default cbsAuto;
  738.     property Checkboxes: Boolean read GetCheckboxes write SetCheckboxes stored IsCheckboxesStored;
  739.     property Color: TColor read GetColor write SetColor stored IsColorStored;
  740.     property BiDiMode: TBiDiMode read GetBiDiMode write SetBiDiMode stored IsBiDiModeStored;
  741.     property DblClickNextVal: Boolean read GetDblClickNextVal write SetDblClickNextVal stored IsDblClickNextValStored;
  742.     property DisplayFormat: string read FDisplayFormat write SetDisplayFormat;
  743.     property DropDownBox: TColumnDropDownBoxEh read FDropDownBox write SetDropDownBox;
  744.     property DropDownRows: Cardinal read FDropDownRows write FDropDownRows default 7; // obsolete
  745.     property DropDownShowTitles: Boolean read GetDropDownShowTitles write SetDropDownShowTitles stored IsDropDownShowTitlesStored;
  746.     property DropDownSizing: Boolean read GetDropDownSizing write SetDropDownSizing stored IsDropDownSizingStored;
  747.     property DropDownSpecRow: TSpecRowEh read FDropDownSpecRow write SetDropDownSpecRow;
  748.     property DropDownWidth: Integer read FDropDownWidth write SetDropDownWidth default 0;
  749.     property EditButtons: TEditButtonsEh read FEditButtons write SetEditButtons;
  750.     property EditMask: string read FEditMask write SetEditMask;
  751.     property EndEllipsis: Boolean read GetEndEllipsis write SetEndEllipsis stored IsEndEllipsisStored;
  752.     property FieldName: string read FFieldName write SetFieldName;
  753.     property Font: TFont read GetFont write SetFont stored IsFontStored;
  754.     property Footer: TColumnFooterEh read FFooter write SetFooter;
  755.     property Footers: TColumnFootersEh read FFooters write SetFooters;
  756.     property HideDuplicates: Boolean read FHideDuplicates write SetHideDuplicates default False;
  757.     property HighlightRequired: Boolean read GetHighlightRequired write SetHighlightRequired stored IsHighlightRequiredStored;
  758.     property ImageList: TCustomImageList read FImageList write SetImageList;
  759.     {$IFDEF EH_LIB_VCL}
  760.     property ImeMode: TImeMode read GetImeMode write SetImeMode stored IsImeModeStored;
  761.     property ImeName: TImeName read GetImeName write SetImeName stored IsImeNameStored;
  762.     {$ENDIF}
  763.     property Increment: Extended read FIncrement write FIncrement stored IsIncrementStored;
  764.     property KeyList: TStrings read GetKeykList write SetKeykList;
  765.     property LookupDisplayFields: string read GetLookupDisplayFields write SetLookupDisplayFields stored IsLookupDisplayFieldsStored;
  766.     property Layout: TTextLayout read GetLayout write SetLayout stored IsLayoutStored;
  767.     property MaxWidth: Integer read FMaxWidth write SetMaxWidth default 0;
  768.     property MinWidth: Integer read FMinWidth write SetMinWidth default 0;
  769.     property MRUList: TMRUListEh read FMRUList write SetMRUList;
  770.     property NotInKeyListIndex: Integer read FNotInKeyListIndex write SetNotInKeyListIndex default -1;
  771.     property PickList: TStrings read GetPickList write SetPickList;
  772.     property PopupMenu: TPopupMenu read FPopupMenu write SetPopupMenu;
  773.     property ReadOnly: Boolean read GetReadOnly write SetReadOnly stored IsReadOnlyStored;
  774.     property STFilter: TSTColumnFilterEh read FSTFilter write SetSTFilter;
  775.     property ShowImageAndText: Boolean read GetShowImageAndText write SetShowImageAndText default False;
  776.     property Tag: Longint read FTag write FTag default 0;
  777.     property Title: TColumnTitleEh read FTitle write SetTitle;
  778.     property ToolTips: Boolean read GetToolTips write SetToolTips stored IsToolTipsStored;
  779.     property Visible: Boolean read FVisible write SetVisible default True;
  780.     property Width: Integer read GetWidth write SetWidth stored IsWidthStored;
  781.     property WordWrap: Boolean read GetWordWrap write SetWordWrap stored IsWordWrapStored;
  782.     property OnCheckDrawRequiredState: TOnColumnCheckDrawRequiredStateEventEh read FOnCheckDrawRequiredState write FOnCheckDrawRequiredState;
  783.     property OnDropDownBoxCheckButton: TCheckTitleEhBtnEvent
  784.       read GetOnDropDownBoxCheckButton write SetOnDropDownBoxCheckButton;
  785.     property OnDropDownBoxDrawColumnCell: TDrawColumnEhCellEvent
  786.       read GetOnDropDownBoxDrawColumnCell write SetOnDropDownBoxDrawColumnCell;
  787.     property OnDropDownBoxGetCellParams: TGetCellEhParamsEvent
  788.       read GetOnDropDownBoxGetCellParams write SetOnDropDownBoxGetCellParams;
  789.     property OnDropDownBoxSortMarkingChanged: TNotifyEvent
  790.       read GetOnDropDownBoxSortMarkingChanged write SetOnDropDownBoxSortMarkingChanged;
  791.     property OnDropDownBoxTitleBtnClick: TTitleEhClickEvent
  792.       read GetOnDropDownBoxTitleBtnClick write SetOnDropDownBoxTitleBtnClick;
  793.     property OnEditButtonClick: TButtonClickEventEh read FOnButtonClick write FOnButtonClick;
  794.     property OnEditButtonDown: TButtonDownEventEh read FOnButtonDown write FOnButtonDown;
  795.     property OnGetCellParams: TGetColCellParamsEventEh read FOnGetCellParams write SetOnGetCellParams;
  796.     //    property OnGetItemImageIndex: TListGetImageIndexEventEh read FOnGetItemImageIndex write FOnGetItemImageIndex;
  797.     property OnNotInList: TNotInListEventEh read FOnNotInList write FOnNotInList;
  798.     property OnUpdateData: TColCellUpdateDataEventEh read FUpdateData write FUpdateData;
  799.   end;
  800.   TColumnEhClass = class of TColumnEh;
  801.   TDBGridColumnEh = class(TColumnEh)
  802.   published
  803.     property Alignment;
  804.     property AlwaysShowEditButton;
  805.     property AutoDropDown;
  806.     property AutoFitColWidth;
  807.     property BiDiMode;
  808.     property ButtonStyle;
  809.     property Checkboxes;
  810.     property Color;
  811.     property DblClickNextVal;
  812.     property DisplayFormat;
  813.     property DropDownBox;
  814.     property DropDownRows;
  815.     property DropDownShowTitles;
  816.     property DropDownSizing;
  817.     property DropDownSpecRow;
  818.     property DropDownWidth;
  819.     property EditButtons;
  820.     property EditMask;
  821.     property EndEllipsis;
  822.     property FieldName;
  823.     property Font;
  824.     property Footer;
  825.     property Footers;
  826.     property HideDuplicates;
  827.     property HighlightRequired;
  828.     property ImageList;
  829.     {$IFDEF EH_LIB_VCL}
  830.     property ImeMode;
  831.     property ImeName;
  832.     {$ENDIF}
  833.     property Increment;
  834.     property KeyList;
  835.     property Layout;
  836.     property LookupDisplayFields;
  837.     property MaxWidth;
  838.     property MinWidth;
  839.     property MRUList;
  840.     property NotInKeyListIndex;
  841.     property PickList;
  842.     property PopupMenu;
  843.     property ReadOnly;
  844.     property ShowImageAndText;
  845.     property STFilter;
  846.     property Tag;
  847.     property Title;
  848.     property ToolTips;
  849.     property Visible;
  850.     property Width;
  851.     property WordWrap;
  852.     property OnCheckDrawRequiredState;
  853.     property OnDropDownBoxCheckButton;
  854.     property OnDropDownBoxDrawColumnCell;
  855.     property OnDropDownBoxGetCellParams;
  856.     property OnDropDownBoxSortMarkingChanged;
  857.     property OnDropDownBoxTitleBtnClick;
  858.     property OnEditButtonClick;
  859.     property OnEditButtonDown;
  860.     property OnGetCellParams;
  861.     //    property OnGetItemImageIndex;
  862.     property OnNotInList;
  863.     property OnUpdateData;
  864.   end;
  865.   { TDBGridColumnsEh }
  866.   TDBGridColumnsEh = class(TCollection)
  867.   private
  868.     FGrid: TCustomDBGridEh;
  869.     function GetColumn(Index: Integer): TColumnEh;
  870.     function GetState: TDBGridColumnsState;
  871.     function InternalAdd: TColumnEh;
  872.     procedure SetColumn(Index: Integer; Value: TColumnEh);
  873.     procedure SetState(NewState: TDBGridColumnsState);
  874.   protected
  875.     function GetUpdateCount: Integer;
  876.   protected
  877.     function GetOwner: TPersistent; override;
  878.     procedure Update(Item: TCollectionItem); override;
  879.     property UpdateCount: Integer read GetUpdateCount;
  880.   public
  881.     constructor Create(Grid: TCustomDBGridEh; ColumnClass: TColumnEhClass);
  882.     function Add: TColumnEh;
  883.     function ExistFooterValueType(AFooterValueType: TFooterValueType): Boolean;
  884.     procedure AddAllColumns(DeleteExisting: Boolean);
  885.     procedure ActiveChanged;
  886.     procedure LoadFromFile(const Filename: string);
  887.     procedure LoadFromStream(S: TStream);
  888.     procedure RebuildColumns;
  889.     procedure RestoreDefaults;
  890.     procedure SaveToFile(const Filename: string);
  891.     procedure SaveToStream(S: TStream);
  892.     property Grid: TCustomDBGridEh read FGrid;
  893.     property Items[Index: Integer]: TColumnEh read GetColumn write SetColumn; default;
  894.     property State: TDBGridColumnsState read GetState write SetState;
  895.   end;
  896.   { TColumnsEhList }
  897.   TColumnsEhList = class(TObjectList)
  898.   private
  899.     function GetColumn(Index: Integer): TColumnEh;
  900.     procedure SetColumn(Index: Integer; const Value: TColumnEh);
  901.   public
  902.     constructor Create; overload;
  903.     property Items[Index: Integer]: TColumnEh read GetColumn write SetColumn; default;
  904.   end;
  905.   { TGridDataLinkEh }
  906.   TGridDataLinkEh = class(TDataLink)
  907.   private
  908.     FFieldCount: Integer;
  909.     FFieldMap: array of Integer;
  910.     FFieldMapSize: Integer;
  911.     FGrid: TCustomDBGridEh;
  912.     FInUpdateData: Boolean;
  913.     FModified: Boolean;
  914.     FSparseMap: Boolean;
  915.     function GetDefaultFields: Boolean;
  916.     function GetFields(I: Integer): TField;
  917.   protected
  918.     function GetMappedIndex(ColIndex: Integer): Integer;
  919.     function MoveBy(Distance: Integer): Integer; override;
  920.     procedure ActiveChanged; override;
  921.     {$IFDEF CIL}
  922.     procedure DataEvent(Event: TDataEvent; Info: TObject); override;
  923.     {$ELSE}
  924.     procedure DataEvent(Event: TDataEvent; Info: Integer); override;
  925.     {$ENDIF}
  926.     procedure DataSetChanged; override;
  927.     procedure DataSetScrolled(Distance: Integer); override;
  928.     procedure EditingChanged; override;
  929.     {$IFDEF CIL}
  930.     procedure FocusControl(const Field: TField); override;
  931.     {$ELSE}
  932.     procedure FocusControl(Field: TFieldRef); override;
  933.     {$ENDIF}
  934.     procedure LayoutChanged; override;
  935.     procedure RecordChanged(Field: TField); override;
  936.     procedure UpdateData; override;
  937.   public
  938.     constructor Create(AGrid: TCustomDBGridEh);
  939.     destructor Destroy; override;
  940.     function AddMapping(const FieldName: string): Boolean;
  941.     procedure ClearMapping;
  942.     procedure Modified;
  943.     procedure Reset;
  944.     property DefaultFields: Boolean read GetDefaultFields;
  945.     property FieldCount: Integer read FFieldCount;
  946.     property Fields[I: Integer]: TField read GetFields;
  947.     property SparseMap: Boolean read FSparseMap write FSparseMap;
  948.   end;
  949.   { TBookmarkListEh }
  950.   TBookmarkListEh = class(TBMListEh)
  951.   private
  952.     FGrid: TCustomDBGridEh;
  953.   protected
  954.     function GetDataSet: TDataSet; override;
  955.     procedure Invalidate; override;
  956.     procedure SetCurrentRowSelected(Value: Boolean); override;
  957.     procedure UpdateState; override;
  958.   public
  959.     constructor Create(AGrid: TCustomDBGridEh);
  960.     function SelectionToGridRect: TGridRect;
  961.     procedure Clear; override;
  962.   end;
  963.   { THeadTreeNode }
  964.   THeadTreeNode = class;
  965.   TDBGridEh = class;
  966.   LeafCol = record
  967.     FLeaf: THeadTreeNode;
  968.     FColumn: TColumnEh;
  969.   end;
  970.   PLeafCol = ^LeafCol;
  971.   TLeafCol = array[0..MaxListSize - 1] of LeafCol;
  972.   //  PTLeafCol = ^TLeafCol;
  973.   PTLeafCol = array of LeafCol;
  974.   THeadTreeProc = procedure(node: THeadTreeNode) of object;
  975.   THeadTreeNode = class(TObject)
  976.   public
  977.     Child: THeadTreeNode;
  978.     Column: TColumnEh;
  979.     Drawed: Boolean;
  980.     Height: Integer;
  981.     HeightPrn: Integer;
  982.     Host: THeadTreeNode;
  983.     Next: THeadTreeNode;
  984.     Text: string;
  985.     VLineWidth: Integer;
  986.     Width: Integer;
  987.     WidthPrn: Integer;
  988.     WIndent: Integer;
  989.     constructor Create;
  990.     constructor CreateText(AText: string; AHeight, AWidth: Integer);
  991.     destructor Destroy; override;
  992.     function Add(AAfter: THeadTreeNode; AText: string; AHeight, AWidth: Integer): THeadTreeNode;
  993.     function AddChild(ANode: THeadTreeNode; AText: string; AHeight, AWidth: Integer): THeadTreeNode;
  994.     function Find(ANode: THeadTreeNode): Boolean;
  995.     function GetLevel: Integer;
  996.     procedure CreateFieldTree(AGrid: TCustomDBGridEh);
  997.     procedure DoForAllNode(proc: THeadTreeProc);
  998.     procedure FreeAllChild;
  999.     procedure Union(AFrom, ATo: THeadTreeNode; AText: string; AHeight: Integer);
  1000.   end;
  1001.   { TDBGridEhSumList }
  1002.   TDBGridEhSumList = class(TDBSumListProducer)
  1003.   private
  1004.     function GetActive: Boolean;
  1005.     procedure SetActive(const Value: Boolean);
  1006.   protected
  1007.     procedure ReturnEvents; override;
  1008.   public
  1009.     constructor Create(AOwner: TComponent);
  1010.     procedure SetDataSetEvents; override;
  1011.   published
  1012.     property Active: Boolean read GetActive write SetActive default False;
  1013.     property ExternalRecalc default False;
  1014.     property OnRecalcAll;
  1015.     property OnAfterRecalcAll;
  1016.     property SumListChanged;
  1017.     property VirtualRecords default False;
  1018.   end;
  1019.   {TDBGridEhScrollBar}
  1020.   TScrollBarVisibleModeEh = (sbAlwaysShowEh, sbNeverShowEh, sbAutoShowEh);
  1021.   TDBGridEhScrollBar = class(TPersistent)
  1022.   private
  1023.     FDBGridEh: TCustomDBGridEh;
  1024.     FExtScrollBar: TScrollBar;
  1025.     FKind: TScrollBarKind;
  1026.     FTracking: Boolean;
  1027.     FVisibleMode: TScrollBarVisibleModeEh;
  1028.     function GetVisible: Boolean;
  1029.     procedure ExtScrollWindowProc(var Message: TMessage);
  1030.     procedure SetExtScrollBar(const Value: TScrollBar);
  1031.     procedure SetVisible(Value: Boolean);
  1032.     procedure SetVisibleMode(const Value: TScrollBarVisibleModeEh);
  1033.   public
  1034.     constructor Create(AGrid: TCustomDBGridEh; AKind: TScrollBarKind);
  1035.     destructor Destroy; override;
  1036.     function GetScrollInfo(var ScrollInfo: TScrollInfo): Boolean;
  1037.     function IsScrollBarVisible: Boolean;
  1038.     procedure Assign(Source: TPersistent); override;
  1039.     procedure UpdateExtScrollBar;
  1040.     property Kind: TScrollBarKind read FKind;
  1041.     property VisibleMode: TScrollBarVisibleModeEh read FVisibleMode write SetVisibleMode default sbAutoShowEh;
  1042.   published
  1043.     property ExtScrollBar: TScrollBar read FExtScrollBar write SetExtScrollBar;
  1044.     property Tracking: Boolean read FTracking write FTracking default False;
  1045.     property Visible: Boolean read GetVisible write SetVisible default True;
  1046.   end;
  1047.   TVertDBGridEhScrollBar = class(TDBGridEhScrollBar)
  1048.   published
  1049.     property Visible stored False;
  1050.     property VisibleMode;
  1051.   end;
  1052.   TDBGridEhSelectionType = (gstNon, gstRecordBookmarks, gstRectangle, gstColumns, gstAll);
  1053.   TDBGridEhAllowedSelection = gstRecordBookmarks..gstAll;
  1054.   TDBGridEhAllowedSelections = set of TDBGridEhAllowedSelection;
  1055.   TDBCell = record
  1056.     Col: Longint;
  1057.     Row: TBookmarkStr;
  1058.   end;
  1059.   { TDBGridEhSelectionRect }
  1060.   TDBGridEhSelectionRect = class(TObject)
  1061.   private
  1062.     FAnchor: TDBCell;
  1063.     FGrid: TCustomDBGridEh;
  1064.     FShiftCell: TDBCell;
  1065.     function BoxRect(ALeft: Longint; ATop: TBookmarkStr; ARight: Longint; ABottom: TBookmarkStr): TRect;
  1066.     function CheckState: Boolean;
  1067.     function GetBottomRow: TBookmarkStr;
  1068.     function GetLeftCol: Longint;
  1069.     function GetRightCol: Longint;
  1070.     function GetTopRow: TBookmarkStr;
  1071.   public
  1072.     constructor Create(AGrid: TCustomDBGridEh);
  1073.     function DataCellSelected(DataCol: Longint; DataRow: TBookmarkStr): Boolean;
  1074.     function SelectionToGridRect: TGridRect;
  1075.     procedure Clear;
  1076.     procedure Select(ACol: Longint; ARow: TBookmarkStr; AddSel: Boolean);
  1077.     property BottomRow: TBookmarkStr read GetBottomRow;
  1078.     property LeftCol: Longint read GetLeftCol;
  1079.     property RightCol: Longint read GetRightCol;
  1080.     property TopRow: TBookmarkStr read GetTopRow;
  1081.   end;
  1082.   { TDBGridEhSelectionCols }
  1083.   TDBGridEhSelectionCols = class(TColumnsEhList)
  1084.   private
  1085.     FAnchor: TColumnEh;
  1086.     FGrid: TCustomDBGridEh;
  1087.     FShiftCol: TColumnEh;
  1088.     FShiftSelectedCols: TColumnsEhList;
  1089.     procedure Add(ACol: TColumnEh);
  1090.   public
  1091.     constructor Create(AGrid: TCustomDBGridEh);
  1092.     destructor Destroy; override;
  1093.     function SelectionToGridRect: TGridRect;
  1094.     procedure Clear; override;
  1095.     procedure InvertSelect(ACol: TColumnEh);
  1096.     procedure Refresh;
  1097.     procedure Select(ACol: TColumnEh; AddSel: Boolean);
  1098.     procedure SelectShift(ACol: TColumnEh {; Clear:Boolean});
  1099.   end;
  1100.   { TDBGridEhSelection }
  1101.   TDBGridEhSelection = class
  1102.   private
  1103.     FColumns: TDBGridEhSelectionCols;
  1104.     FGrid: TCustomDBGridEh;
  1105.     FRect: TDBGridEhSelectionRect;
  1106.     FSelectionType: TDBGridEhSelectionType;
  1107.     function GetRows: TBookmarkListEh;
  1108.     procedure LinkActive(Value: Boolean);
  1109.     procedure SetSelectionType(ASelType: TDBGridEhSelectionType);
  1110.   protected
  1111.     procedure SelectionChanged; virtual;
  1112.   public
  1113.     constructor Create(AGrid: TCustomDBGridEh);
  1114.     destructor Destroy; override;
  1115.     function DataCellSelected(DataCol: Longint; DataRow: TBookmarkStr): Boolean;
  1116.     function SelectionToGridRect: TGridRect;
  1117.     procedure Clear;
  1118.     procedure Refresh;
  1119.     procedure SelectAll;
  1120.     procedure UpdateState;
  1121.     property Columns: TDBGridEhSelectionCols read FColumns;
  1122.     property Rect: TDBGridEhSelectionRect read FRect;
  1123.     property Rows: TBookmarkListEh read GetRows;
  1124.     property SelectionType: TDBGridEhSelectionType read FSelectionType;
  1125.   end;
  1126.   { TSTDBGridEhFilter }
  1127.   TSTDBGridEhFilter = class(TPersistent)
  1128.   private
  1129.     FGrid: TCustomDBGridEh;
  1130.     FLocal: Boolean;
  1131.     FUpateCount: Integer;
  1132.     FVisible: Boolean;
  1133.     procedure SetLocal(const Value: Boolean);
  1134.     procedure SetVisible(const Value: Boolean);
  1135.   public
  1136.     constructor Create(AGrid: TCustomDBGridEh);
  1137.     procedure Assign(Source: TPersistent); override;
  1138.     procedure BeginUpdate;
  1139.     procedure EndUpdate;
  1140.     property UpdateCount: Integer read FUpateCount;
  1141.   published
  1142.     property Local: Boolean read FLocal write SetLocal default False;
  1143.     property Visible: Boolean read FVisible write SetVisible default False;
  1144.   end;
  1145.   { TCustomDBGridEh }
  1146.   THorzCellTypeEh = (hctIndicatorEh, hctDataEh);
  1147.   TVertCellTypeEh = (vctTitleEh, vctSubTitleEh, vctDataEh, vctAboveFooterEh, vctFooterEh);
  1148.   TCellTypeEh = record
  1149.     HorzType: THorzCellTypeEh;
  1150.     VertType: TVertCellTypeEh;
  1151.   end;
  1152.   TDBGridEhOption = (dghFixed3D, dghFrozen3D, dghFooter3D, dghData3D, dghResizeWholeRightPart,
  1153.     dghHighlightFocus, dghClearSelection, dghFitRowHeightToText, dghAutoSortMarking,
  1154.     dghMultiSortMarking, dghEnterAsTab, dghTraceColSizing, dghIncSearch,
  1155.     dghPreferIncSearch, dghRowHighlight, dghDblClickOptimizeColWidth, dghDialogFind,
  1156.     dghRecordMoving);
  1157.   TDBGridEhOptions = set of TDBGridEhOption;
  1158.   TDBGridEhState = (dgsNormal, dgsRowSelecting, dgsColSelecting, dgsRectSelecting,
  1159.     dgsPosTracing, dgsTitleDown, dgsColSizing, dgsRowMoving);
  1160.   TDBGridEhAllowedOperation = (alopInsertEh, alopUpdateEh, alopDeleteEh, alopAppendEh);
  1161.   TDBGridEhAllowedOperations = set of TDBGridEhAllowedOperation;
  1162.   TDBGridEhEditAction = (geaCutEh, geaCopyEh, geaPasteEh, geaDeleteEh, geaSelectAllEh);
  1163.   TDBGridEhEditActions = set of TDBGridEhEditAction;
  1164.   //  TInpsDirectionEh = (inpsFromFirstEh, inpsToNextEh, inpsToPriorEh);
  1165.     { The DBGridEh's DrawDataCell virtual method and OnDrawDataCell event are only
  1166.       called when the grid's Columns.State is csDefault.  This is for compatibility
  1167.       with existing code. These routines don't provide sufficient information to
  1168.       determine which column is being drawn, so the column attributes aren't
  1169.       easily accessible in these routines.  Column attributes also introduce the
  1170.       possibility that a column's field may be nil, which would break existing
  1171.       DrawDataCell code.   DrawDataCell, OnDrawDataCell, and DefaultDrawDataCell
  1172.       are obsolete, retained for compatibility purposes. }
  1173.   (*  TDrawDataCellEvent = procedure (Sender: TObject; const Rect: TRect; Field: TField;
  1174.       State: TGridDrawState) of object; *)
  1175.     { The DBGridEh's DrawColumnCell virtual method and OnDrawColumnCell event are
  1176.       always called, when the grid has defined column attributes as well as when
  1177.       it is in default mode.  These new routines provide the additional
  1178.       information needed to access the column attributes for the cell being
  1179.       drawn, and must support nil fields.  }
  1180.   TDBGridEhClickEvent = procedure(Column: TColumnEh) of object;
  1181.   TDrawFooterCellEvent = procedure(Sender: TObject; DataCol, Row: Longint;
  1182.     Column: TColumnEh; Rect: TRect; State: TGridDrawState) of object;
  1183.   TGetFooterParamsEvent = procedure(Sender: TObject; DataCol, Row: Longint;
  1184.     Column: TColumnEh; AFont: TFont; var Background: TColor;
  1185.     var Alignment: TAlignment; State: TGridDrawState; var Text: string) of object;
  1186.   TGetBtnEhParamsEvent = procedure(Sender: TObject; Column: TColumnEh;
  1187.     AFont: TFont; var Background: TColor; var SortMarker: TSortMarkerEh;
  1188.     IsDown: Boolean) of object;
  1189.   (*
  1190.     { Internal grid types }
  1191.     TGridAxisDrawInfoEh = record
  1192.       EffectiveLineWidth: Integer;
  1193.       FirstGridCell: Integer;
  1194.       FixedBoundary: Integer;
  1195.       FixedCellCount: Integer;
  1196.       FooterExtent: Integer;
  1197.       FrozenExtent: Integer;
  1198.       FullVisBoundary: Integer;
  1199.       GetExtent: TGetExtentsFunc;
  1200.       GridBoundary: Integer;
  1201.       GridCellCount: Integer;
  1202.       GridExtent: Integer;
  1203.       LastFullVisibleCell: Longint;
  1204.     end;
  1205.     TGridDrawInfoEh = record
  1206.       Horz, Vert: TGridAxisDrawInfoEh;
  1207.     end;
  1208.   *)
  1209.   TCustomDBGridEh = class(TCustomGridEh, IInplaceEditHolderEh{$IFNDEF CIL}, IUnknown{$ENDIF})
  1210.   private
  1211.     FAllowedOperations: TDBGridEhAllowedOperations;
  1212.     FAllowedSelections: TDBGridEhAllowedSelections;
  1213.     FAutoDrag, FSelectedCellPressed: Boolean;
  1214.     FBookmarks: TBookmarkListEh;
  1215.     FCanvasHandleAllocated: Boolean;
  1216.     FColumnDefValues: TColumnDefValuesEh;
  1217.     FColumns: TDBGridColumnsEh;
  1218.     FCompleteKeyPress: string;
  1219.     FDataLink: TGridDataLinkEh;
  1220.     FDefaultDrawing: Boolean;
  1221.     FEditActions: TDBGridEhEditActions;
  1222.     FEditKeyValue: Variant;                                 // For lookup fields and KeyList based column
  1223.     FEditText: string;
  1224.     //gridseh    FFlat: Boolean;
  1225.     FFooterColor: TColor;
  1226.     FFooterFont: TFont;
  1227.     FHintFont: TFont;
  1228.     FHorzScrollBar: TDBGridEhScrollBar;
  1229.     FInColExit: Boolean;
  1230.     FInterlinear: Integer;
  1231.     FLayoutFromDataset: Boolean;
  1232.     FLayoutLock: Byte;
  1233.     FOnCellClick: TDBGridEhClickEvent;
  1234.     FOnColEnter: TNotifyEvent;
  1235.     FOnColExit: TNotifyEvent;
  1236.     FOnColumnMoved: TMovedEvent;
  1237.     FOnColWidthsChanged: TNotifyEvent;
  1238.     FOnDrawColumnCell: TDrawColumnEhCellEvent;
  1239.     FOnDrawDataCell: TDrawDataCellEvent;
  1240.     FOnEditButtonClick: TNotifyEvent;
  1241.     FOnGetCellParams: TGetCellEhParamsEvent;
  1242.     FOnGetFooterParams: TGetFooterParamsEvent;
  1243.     FOnSelectionChanged: TNotifyEvent;
  1244.     FOnSortMarkingChanged: TNotifyEvent;
  1245.     FOnSumListAfterRecalcAll: TNotifyEvent;
  1246.     FOnSumListRecalcAll: TNotifyEvent;
  1247.     FOnTitleClick: TDBGridEhClickEvent;
  1248.     FOptions: TDBGridOptions;
  1249.     FOptionsEh: TDBGridEhOptions;
  1250.     {$IFDEF EH_LIB_VCL}
  1251.     FOriginalImeMode: TImeMode;
  1252.     FOriginalImeName: TImeName;
  1253.     {$ENDIF}
  1254.     FReadOnly: Boolean;
  1255.     FSelecting: Boolean;
  1256.     FSelection: TDBGridEhSelection;
  1257.     FSelectionAnchor: TBookmarkStr;
  1258.     FSelfChangingFooterFont: Boolean;
  1259.     FSelfChangingTitleFont: Boolean;
  1260.     FSelRow: Integer;
  1261.     FSizingIndex: Longint;
  1262.     FSizingPos, FSizingOfs: Integer;
  1263.     FSortLocal: Boolean;
  1264.     FSortMarking: Boolean;
  1265.     FStyle: TDBGridEhStyle;
  1266.     FSumListRecalcing: Boolean;
  1267.     FThumbTracked: Boolean;
  1268.     FTitleFont: TFont;
  1269.     FTitleImages: TCustomImageList;
  1270.     FTitleImageChangeLink: TChangeLink;
  1271.     FTitleOffset: Byte;
  1272.     FIndicatorOffset: Byte;
  1273.     FTopDataOffset: Byte;
  1274.     FTopLeftVisible: Boolean;
  1275.     FUpdateLock: Byte;
  1276.     FUserChange: Boolean;
  1277.     FVertScrollBar: TDBGridEhScrollBar;
  1278.     FIntMemTable: IMemTableEh;
  1279.     FOldActiveRecord: Integer;
  1280.     FLockAutoShowCurCell: Boolean;
  1281.     FFetchingRecords: Boolean;
  1282.     FTryUseMemTableInt: Boolean;
  1283.     FSTFilter: TSTDBGridEhFilter;
  1284.     FFilterCol: Integer;
  1285.     FFilterEditMode: Boolean;
  1286.     FFilterEdit: TCustomDBEditEh;
  1287.     FOnApplyFilter: TNotifyEvent;
  1288.     FDownMouseMessageTime: LongInt;
  1289.     FBufferedPaint: Boolean;
  1290.     FSizeChanged: Boolean;
  1291.     FEvenRowColorStored: Boolean;
  1292.     FOddRowColorStored: Boolean;
  1293.     FEvenRowColor: TColor;
  1294.     FOddRowColor: TColor;
  1295.     FContraColCount: Integer;
  1296.     procedure CheckIMemTable;
  1297.     procedure MTUpdateRowCount;
  1298.     procedure MTScroll(Distance: Integer);
  1299.     function IsCurrentRow(DataRowNum: Integer): Boolean;
  1300.     procedure FetchRecordsInView;
  1301.     procedure InstantReadRecordEnter(DataRowNum: Integer);
  1302.     procedure InstantReadRecordLeave;
  1303.     function InstantReadRecordCount: Integer;
  1304.     procedure MTUpdateVertScrollBar;
  1305.     procedure MTUpdateTopRow;
  1306.     procedure MTWMVScroll(var Message: TWMVScroll);
  1307.     function GetCol: Longint;
  1308.     function GetContraColCount: Longint;
  1309.     function GetDataSource: TDataSource;
  1310.     function GetEvenRowColor: TColor;
  1311.     function GetFieldColumns(const FieldName: string): TColumnEh;
  1312.     function GetFieldCount: Integer;
  1313.     function GetFields(FieldIndex: Integer): TField;
  1314.     function GetOddRowColor: TColor;
  1315.     //    function GetRowHeights(Index: Longint): Integer;
  1316.     function GetSelectedField: TField;
  1317.     function GetSelectedIndex: Integer;
  1318.     function GetTopDataOffset: Byte;
  1319.     //    function IsActiveControl: Boolean;
  1320.     function IsEvenRowColorStored: Boolean;
  1321.     function IsOddRowColorStored: Boolean;
  1322.     //      procedure CalcDrawInfoXYEh(var DrawInfo: TGridDrawInfoEh; UseWidth, UseHeight: Integer);
  1323.     procedure ChangeGridOrientation(RightToLeftOrientation: Boolean);
  1324.     procedure ClearSelection;
  1325.     {$IFDEF EH_LIB_VCL}
  1326.     procedure CMCancelMode(var Message: TCMCancelMode); message CM_CancelMode;
  1327.     procedure CMDeferLayout(var Message: TMessage); message cm_DeferLayout;
  1328.     procedure CMDesignHitTest(var Msg: TCMDesignHitTest); message CM_DESIGNHITTEST;
  1329.     procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  1330.     procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
  1331.     procedure CMHintsShowPause(var Message: TCMHintShowPause); message CM_HINTSHOWPAUSE;
  1332.     procedure CMMouseWheel(var Message: TCMMouseWheel); message CM_MOUSEWHEEL;
  1333.     procedure CMParentColorChanged(var Message: TMessage); message CM_PARENTCOLORCHANGED;
  1334.     procedure CMParentFontChanged(var Message: TCMParentFontChanged); message CM_PARENTFONTCHANGED;
  1335.     procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  1336.     {$ENDIF}
  1337.     procedure DoSelection(Select: Boolean; Direction: Integer; MaxDirection, RowOnly: Boolean);
  1338.     procedure DrawEdgeEh(ACanvas: TCanvas; qrc: TRect; IsDown, IsSelected: Boolean; NeedLeft, NeedRight: Boolean);
  1339.     procedure EditingChanged;
  1340.     procedure FooterFontChanged(Sender: TObject);
  1341.     procedure InternalLayout;
  1342.     procedure MoveCol(RawCol, Direction: Integer; Select: Boolean);
  1343.     procedure ReadColumns(Reader: TReader);
  1344.     procedure RecordChanged(Field: TField);
  1345.     procedure SetAllowedSelections(const Value: TDBGridEhAllowedSelections);
  1346.     procedure SetCol(Value: Longint);
  1347.     procedure SetColumnDefValues(const Value: TColumnDefValuesEh);
  1348.     procedure SetColumns(Value: TDBGridColumnsEh);
  1349.     procedure SetContraColCount(const Value: Longint);
  1350.     procedure SetDataSource(Value: TDataSource);
  1351.     procedure SetDrawMemoText(const Value: Boolean);
  1352.     procedure SetEvenRowColor(const Value: TColor);
  1353.     procedure SetFilterEditMode(const Value: Boolean);
  1354.     //gridseh    procedure SetFlat(const Value: Boolean);
  1355.     procedure SetFooterColor(Value: TColor);
  1356.     procedure SetFooterFont(Value: TFont);
  1357.     procedure SetHorzScrollBar(const Value: TDBGridEhScrollBar);
  1358.     procedure SetIme;
  1359.     procedure SetOddRowColor(const Value: TColor);
  1360.     procedure SetOptions(Value: TDBGridOptions);
  1361.     procedure SetOptionsEh(const Value: TDBGridEhOptions);
  1362.     procedure SetReadOnly(const Value: Boolean);
  1363.     procedure SetSelectedField(Value: TField);
  1364.     procedure SetSelectedIndex(Value: Integer);
  1365.     procedure SetSTFilter(const Value: TSTDBGridEhFilter);
  1366.     procedure SetStyle(const Value: TDBGridEhStyle);
  1367.     procedure SetSumList(const Value: TDBGridEhSumList);
  1368.     procedure SetTitleFont(Value: TFont);
  1369.     procedure SetTitleImages(const Value: TCustomImageList);
  1370.     procedure SetVertScrollBar(const Value: TDBGridEhScrollBar);
  1371.     procedure TitleFontChanged(Sender: TObject);
  1372.     procedure TitleImageListChange(Sender: TObject);
  1373.     procedure UpdateData;
  1374.     procedure UpdateIme;
  1375.     {$IFDEF EH_LIB_VCL}
  1376.     procedure WMCancelMode(var Message: TWMCancelMode); message WM_CANCELMODE;
  1377.     procedure WMChar(var Message: TWMChar); message WM_CHAR;
  1378.     procedure WMCommand(var Message: TWMCommand); message WM_COMMAND;
  1379.     procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND; //tmp
  1380.     procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message WM_GETDLGCODE;
  1381.     procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL;
  1382.     procedure WMIMEStartComp(var Message: TMessage); message WM_IME_STARTCOMPOSITION;
  1383.     procedure WMKillFocus(var Message: TWMKillFocus); message WM_KillFocus;
  1384.     procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
  1385.     procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
  1386.     procedure WMNCPaint(var Message: TWMNCPaint); message WM_NCPAINT;
  1387.     procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  1388.     procedure WMRButtonDown(var Message: TWMRButtonDown); message WM_RBUTTONDOWN;
  1389.     procedure WMSetCursor(var Msg: TWMSetCursor); message WM_SETCURSOR;
  1390.     procedure WMSetFocus(var Message: TWMSetFocus); message WM_SetFOCUS;
  1391.     procedure WMSize(var Message: TWMSize); message WM_SIZE;
  1392.     procedure WMTimer(var Message: TWMTimer); message WM_TIMER;
  1393.     procedure WMVScroll(var Message: TWMVScroll); message WM_VSCROLL;
  1394.     /// 赖-2008-01-18 加入对 Ctrl+C 的处理
  1395.     procedure WMKeyDown(var vMsg: TWMKeyDown); message WM_KEYDOWN;
  1396.     {$ENDIF}
  1397.     procedure WriteColumns(Writer: TWriter);
  1398.     procedure PaintInplaceButton(Column: TColumnEh; Canvas: TCanvas;
  1399.       ButtonStyle: TEditButtonStyleEh; Rect, ClipRect: TRect;
  1400.       DownButton: Integer; Active, Flat, Enabled: Boolean;
  1401.       ParentColor: TColor; Bitmap: TBitmap);
  1402.   protected
  1403.     { IInplaceEditHolderEh }
  1404.     function InplaceEditCanModify(Control: TWinControl): Boolean;
  1405.     procedure GetMouseDownInfo(var Pos: TPoint; var Time: LongInt);
  1406.     procedure InplaceEditKeyDown(Control: TWinControl; var Key: Word; Shift: TShiftState);
  1407.     procedure InplaceEditKeyPress(Control: TWinControl; var Key: Char);
  1408.     procedure InplaceEditKeyUp(Control: TWinControl; var Key: Word; Shift: TShiftState);
  1409.     procedure InplaceEditWndProc(Control: TWinControl; var Message: TMessage);
  1410.   protected
  1411.     //    FSortMarkerImages: TImageList;
  1412.     FAcquireFocus: Boolean;
  1413.     FAllowWordWrap: Boolean;                                // True if RowHeight + 3 > TextHeight
  1414.     FAntiSelection: Boolean;
  1415.     FAutoFitColWidths: Boolean;
  1416.     FBorderWidth: Integer;
  1417.     FColCellParamsEh: TColCellParamsEh;
  1418.     FDataTracking: Boolean;
  1419.     FDBGridEhState: TDBGridEhState;
  1420.     FDefaultRowChanged: Boolean;
  1421.     FDownMousePos: TPoint;
  1422.     FDrawMemoText: Boolean;
  1423.     FFooterRowCount: Integer;
  1424.     FFrozenCols: Integer;
  1425.     FHeadTree: THeadTreeNode;
  1426.     FHTitleMargin: Integer;
  1427.     FIndicatorPressed: Boolean;
  1428.     FInplaceEditorButtonHeight: Integer;
  1429.     FInplaceEditorButtonWidth: Integer;
  1430.     FInplaceSearching: Boolean;
  1431.     FInplaceSearchingInProcess: Boolean;
  1432.     FInplaceSearchText: string;
  1433.     FInplaceSearchTimeOut: Integer;
  1434.     FInplaceSearchTimerActive: Boolean;
  1435.     FLeafFieldArr: PTLeafCol;
  1436.     FLockedBookmark: TBookmarkStr;
  1437.     //    FLockPaint: Boolean;
  1438.     FLookedOffset: Integer;
  1439.     FMinAutoFitWidth: Integer;
  1440.     FMouseShift: TShiftState;
  1441.     FMoveMousePos: TPoint;
  1442.     FNewRowHeight: Integer;
  1443.     FOnCheckButton: TCheckTitleEhBtnEvent;
  1444.     FOnDrawFooterCell: TDrawFooterCellEvent;
  1445.     FOnGetBtnParams: TGetBtnEhParamsEvent;
  1446.     FOnMoveRecords: TGridMoveRecordsEventEh;
  1447.     FOnTitleBtnClick: TTitleEhClickEvent;
  1448.     FOnTopLeftChanged: TNotifyEvent;
  1449.     FPressed: Boolean;
  1450.     FPressedCell: TGridCoord;
  1451.     FPressedCol: Longint;
  1452.     FRowLines: Integer;
  1453.     FRowSizingAllowed: Boolean;
  1454.     FSelectionActive: Boolean;
  1455.     FSelectionAnchorSelected: Boolean;
  1456.     FSortMarkedColumns: TColumnsEhList;
  1457.     FSumList: TDBGridEhSumList;
  1458.     FSwapButtons: Boolean;
  1459.     FTimerActive: Boolean;
  1460.     FTimerInterval: Integer;
  1461.     FTitleHeight: Integer;
  1462.     FTitleHeightFull: Integer;
  1463.     FTitleLines: Integer;
  1464.     FTracking: Boolean;
  1465.     FUpdateFields: Boolean;
  1466.     FUseMultiTitle: Boolean;
  1467.     FVertScrollBarVisibleMode: TScrollBarVisibleModeEh;
  1468.     FVisibleColumns: TColumnsEhList;
  1469.     FVTitleMargin: Integer;
  1470.     FMoveRowSour: Integer;                                  //Index
  1471.     FMoveBookmarkSour: string;
  1472.     FMoveRowDest: Integer;                                  //Pos
  1473.     FMoveRowSourLevel: Integer;
  1474.     FMoveRowDestLevel: Integer;
  1475.     FMoveRowLeftBounds: Integer;
  1476.     FDataRowMoveLeftBoundary: Integer;
  1477.     FDataRowMoveRightBoundary: Integer;
  1478.     FDataRowMoveVisible: Boolean;
  1479.     function AcquireFocus: Boolean; virtual;
  1480.     function AcquireLayoutLock: Boolean;
  1481.     function AllowedOperationUpdate: Boolean;
  1482.     function BeginDataRowDrag(var Origin, Destination: Integer; const MousePt: TPoint): Boolean; virtual;
  1483.     function BoxRect(ALeft, ATop, ARight, ABottom: Longint): TRect;
  1484.     function CalcLeftMoveLine(ARow: Integer; const MousePt: TPoint; var TreeLevel: Integer): Integer; virtual;
  1485.     function CanDrawFocusRowRect: Boolean; virtual;
  1486.     function CanEditAcceptKey(Key: Char): Boolean; override;
  1487.     function CanEditModify: Boolean; override;
  1488.     function CanEditModifyColumn(Index: Integer): Boolean;
  1489.     function CanEditModifyText: Boolean;
  1490.     function CanEditorMode: Boolean; virtual;
  1491.     function CanEditShow: Boolean; override;
  1492.     function CanFilterCol(DCol: Longint): Boolean;
  1493.     function CanFilterEditShow: Boolean; virtual;
  1494.     function CanSelectType(const Value: TDBGridEhSelectionType): Boolean;
  1495.     function CellHave3DRect(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState): Boolean; virtual;
  1496.     function CellIsMultiSelected(ACol, ARow: Integer; DataCol: Integer; DataRowBkmrk: TBookmarkStr): Boolean; virtual;
  1497.     function CellTreeElementMouseDown(MouseX, MouseY: Integer; CheckInOnly: Boolean): Boolean; virtual;
  1498.     function CheckBeginRowMoving(MouseX, MouseY: Integer; CheckInOnly: Boolean): Boolean; virtual;
  1499.     function CheckCellFilter(ACol, ARow: Integer; P: TPoint): Boolean;
  1500.     function CreateColumnDefValues: TColumnDefValuesEh; dynamic;
  1501.     function CreateColumns: TDBGridColumnsEh; dynamic;
  1502.     function CreateEditor: TInplaceEdit; override;
  1503.     function CreateFilterEditor: TCustomDBEditEh; virtual;
  1504.     function CreateScrollBar(AKind: TScrollBarKind): TDBGridEhScrollBar; dynamic;
  1505.     function DataToRawColumn(ACol: Integer): Integer;
  1506.     {$IFDEF EH_LIB_VCL}
  1507.     function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
  1508.     function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
  1509.     {$ENDIF}
  1510.     function DrawTitleByThemes: Boolean;
  1511.     function FrozenSizing(X, Y: Integer): Boolean;
  1512.     function GetCellType(ACol, ARow: Integer; var DataCol, DataRow: Integer): TCellTypeEh;
  1513.     function GetColField(DataCol: Integer): TField;
  1514.     function GetColWidths(Index: Longint): Integer;
  1515.     function GetEditLimit: Integer; override;
  1516.     {$IFDEF EH_LIB_VCL}
  1517.     function GetEditMask(ACol, ARow: Longint): string; override;
  1518.     function GetEditText(ACol, ARow: Longint): string; override;
  1519.     {$ENDIF}
  1520.     function GetFieldValue(ACol: Integer): string;
  1521.     function GetFilterValue(DCol: Longint): string;
  1522.     function GetFooterRowCount: Integer;
  1523.     function GetRowHeight: Integer;
  1524.     function GetRowLines: Integer;
  1525.     function GetSubTitleRowHeights(ASubTitleRow: Integer): Integer;
  1526.     function GetSubTitleRows: Integer; virtual;
  1527.     function GetTitleRows: Integer; virtual;
  1528.     function HaveHideDuplicates: Boolean;
  1529.     function HighlightNoDataCellColor(ACol, ARow: Integer; DataCol, DataRow: Integer;
  1530.       CellType: TCellTypeEh; AState: TGridDrawState; InMultiSelect: Boolean; var AColor: TColor;
  1531.       AFont: TFont): Boolean; virtual;
  1532.     function HighlightDataCellColor(DataCol, DataRow: Integer; const Value: string;
  1533.       AState: TGridDrawState; var AColor: TColor; AFont: TFont): Boolean; virtual;
  1534.     function InplaceEditorVisible: Boolean;
  1535.     function IsSelectionActive: Boolean; virtual;
  1536.     function MemTableSupport: Boolean;
  1537.     function MoveDataRows(BookmarkList: TStrings; ToIndex: Longint;
  1538.       TreeLevel: Integer; CheckOnly: Boolean): Boolean; virtual;
  1539.     function MoveSelectedDataRows(ToIndex: Longint; TreeLevel: Integer;
  1540.       CheckOnly: Boolean): Boolean; virtual;
  1541.     function NeedBufferedPaint: Boolean; virtual;
  1542.     function ViewScroll: Boolean;
  1543.     function RawToDataColumn(ACol: Integer): Integer;
  1544.     function ReadTitleHeight: Integer;
  1545.     function ReadTitleLines: Integer;
  1546.     function SafeMoveTop(ATop: Integer; CheckOnly: Boolean = False): Integer;
  1547.     function SetChildTreeHeight(ANode: THeadTreeNode): Integer;
  1548.     function StdDefaultRowHeight: Integer;
  1549.     function StoreColumns: Boolean;
  1550.     function VisibleDataRowCount: Integer;
  1551.     procedure BeginLayout;
  1552.     procedure BeginUpdate;
  1553.     //    procedure CalcDrawInfoEh(var DrawInfo: TGridDrawInfoEh);
  1554.     //    procedure CalcFixedInfoEh(var DrawInfo: TGridDrawInfoEh);
  1555.     procedure CalcFrozenSizingState(X, Y: Integer; var State: TDBGridEhState;
  1556.       var Index: Longint; var SizingPos, SizingOfs: Integer);
  1557.     procedure CalcSizingState(X, Y: Integer; var State: TGridState;
  1558.       var Index: Longint; var SizingPos, SizingOfs: Integer;
  1559.       var FixedInfo: TGridDrawInfoEh); override;
  1560.     procedure CancelLayout;
  1561.     procedure CellClick(Column: TColumnEh); dynamic;
  1562.     {$IFDEF EH_LIB_VCL}
  1563.     procedure ChangeScale(M, D: Integer); override;
  1564.     {$ENDIF}
  1565.     procedure CheckTitleButton(ACol: Longint; var Enabled: Boolean); dynamic;
  1566.     procedure ClearPainted(node: THeadTreeNode);
  1567.     procedure ColEnter; dynamic;
  1568.     procedure ColExit; dynamic;
  1569.     procedure ColumnMoved(FromIndex, ToIndex: Longint); override;
  1570.     procedure ColWidthsChanged; override;
  1571.     {$IFDEF EH_LIB_VCL}
  1572.     procedure CreateParams(var Params: TCreateParams); override;
  1573.     procedure CreateWnd; override;
  1574.     {$ENDIF}
  1575.     procedure DataChanged; virtual;
  1576.     procedure DeferLayout;
  1577.     procedure DefineFieldMap; virtual;
  1578.     procedure DefineProperties(Filer: TFiler); override;
  1579.     procedure DoExit; override;
  1580.     procedure DoAfterSizeChanged; virtual;
  1581.     procedure DoSortMarkingChanged; dynamic;
  1582.     procedure DoTitleClick(ACol: Longint; AColumn: TColumnEh); dynamic;
  1583.     procedure DrawBorder; virtual;
  1584.     procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
  1585.     procedure DrawCellTreeArea(DataCol, DataRow: Integer; AState: TGridDrawState; ARect: TRect; Draw3DRect: Boolean); virtual;
  1586.     procedure DrawDataRowMove(LeftBoundary, RightBoundary: Integer);
  1587.     procedure DrawTreeArea(Canvas: TCanvas; ARect: TRect; IsDrawEdge: Boolean);
  1588.     procedure DrawColumnCell(const Rect: TRect; DataCol: Integer;
  1589.       Column: TColumnEh; State: TGridDrawState); dynamic;
  1590.     procedure DrawDataCell(const Rect: TRect; Field: TField; State: TGridDrawState); dynamic; { obsolete }
  1591.     procedure DrawSubTitleCell(ACol, ARow: Longint; DataCol, DataRow: Integer;
  1592.       CellType: TCellTypeEh; ARect: TRect; AState: TGridDrawState; var Highlighted: Boolean); virtual;
  1593.     procedure DrawSizingLine(HorzGridBoundary, VertGridBoundary: Integer);
  1594.     procedure EditButtonClick; dynamic;
  1595.     procedure EndLayout;
  1596.     procedure EndRowMoving(MouseX, MouseY: Integer; Accept: Boolean); virtual;
  1597.     procedure EndUpdate;
  1598.     procedure ExecuteFindDialog(Text, FieldName: string; Modal: Boolean);
  1599.     procedure FilterButtonClick(Sender: TObject; var Handled: Boolean);
  1600.     procedure FilterExit(Sender: TObject);
  1601.     procedure FlatChanged; override;
  1602.     procedure GetCellParams(Column: TColumnEh; AFont: TFont;
  1603.       var Background: TColor; State: TGridDrawState); dynamic;
  1604.     procedure GetDatasetFieldList(FieldList: TList); virtual;
  1605.     procedure GetFooterParams(DataCol, Row: Longint; Column: TColumnEh; AFont: TFont;
  1606.       var Background: TColor; var Alignment: TAlignment; State: TGridDrawState; var Text: string); dynamic;
  1607.     procedure HideFilterEdit;
  1608.     procedure HideDataRowMove;
  1609.     procedure InvalidateCol(ACol: Longint);
  1610.     procedure InvalidateRow(ARow: Longint);
  1611.     procedure InvalidateCell(ACol, ARow: Longint);
  1612.     procedure InvalidateEditor;
  1613.     procedure InvalidateGridRect(ARect: TGridRect);
  1614.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  1615.     procedure KeyPress(var Key: Char); override;
  1616.     procedure KeyUp(var Key: Word; Shift: TShiftState); override;
  1617.     procedure LayoutChanged; virtual;
  1618.     procedure LinkActive(Value: Boolean); virtual;
  1619.     procedure Loaded; override;
  1620.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1621.     procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  1622.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1623.     procedure MoveDataRowAndScroll(Mouse, CellHit: Integer; var DrawInfo: TGridDrawInfoEh; var Axis: TGridAxisDrawInfoEh; ScrollBar: Integer; const MousePt: TPoint); virtual;
  1624.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  1625.     procedure OnFilterChange(Sender: TObject);
  1626.     procedure OnFilterCloseUp(Sender: TObject; Accept: Boolean);
  1627.     procedure OnFilterClosingUp(Sender: TObject; var Accept: Boolean);
  1628.     procedure OnFilterEditButtonClick(Sender: TObject; var Handled: Boolean);
  1629.     procedure OnFilterGetItemsList(Sender: TObject);
  1630.     procedure OnFilterKeyPress(Sender: TObject; var Key: Char);
  1631.     procedure OptimizeColsWidth(ColumnsList: TColumnsEhList);
  1632.     procedure OptimizeSelectedColsWidth(WithColumn: TColumnEh);
  1633.     procedure Paint; override;
  1634.     {$IFDEF EH_LIB_VCL}
  1635.     procedure PaintButtonControl(DC: HDC; ARect: TRect; ParentColor: TColor;
  1636.       Style: TDrawButtonControlStyleEh; DownButton: Integer;
  1637.       Flat, Active, Enabled: Boolean; State: TCheckBoxState);
  1638.     {$ENDIF}
  1639.     //    procedure RecreateInplaceSearchIndicator;
  1640.     procedure RegetDefaultStyle;
  1641.     procedure ResetTimer(Interval: Integer);
  1642.     procedure RestoreColumnsLayoutProducer(ARegIni: TObject; Section: string;
  1643.       RestoreParams: TColumnEhRestoreParams);
  1644.     procedure RestoreGridLayoutProducer(ARegIni: TObject; Section: string;
  1645.       RestoreParams: TDBGridEhRestoreParams);
  1646.     procedure RowHeightsChanged; override;
  1647.     procedure SaveColumnsLayoutProducer(ARegIni: TObject; Section: string; DeleteSection: Boolean);
  1648.     procedure SaveGridLayoutProducer(ARegIni: TObject; Section: string; DeleteSection: Boolean);
  1649.     procedure Scroll(Distance: Integer); virtual;
  1650.     procedure SelectionActiveChanged; virtual;
  1651.     procedure SetColumnAttributes; virtual;
  1652.     procedure SetColWidths(Index: Longint; Value: Integer);
  1653.     {$IFDEF EH_LIB_VCL}
  1654.     procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
  1655.     {$ENDIF}
  1656.     procedure SetDataFilter;
  1657.     procedure SetFilterValue(DCol: Longint); virtual;
  1658.     procedure SetFooterRowCount(Value: Integer);
  1659.     procedure SetFrozenCols(Value: Integer);
  1660.     procedure SetRowHeight(Value: Integer);
  1661.     procedure SetRowLines(Value: Integer);
  1662.     procedure SetRowSizingAllowed(Value: Boolean);
  1663.     procedure ShowEditor; virtual;
  1664.     procedure ShowFilterEditorChar(Ch: Char);
  1665.     procedure StartEditFilter(DCol: Longint);
  1666.     procedure StartInplaceSearchTimer;
  1667.     procedure StopEditFilter;
  1668.     procedure StopInplaceSearchTimer;
  1669.     procedure StopTimer;
  1670.     procedure StopTracking;
  1671.     procedure StyleEhChanged;
  1672.     procedure SumListAfterRecalcAll(Sender: TObject);
  1673.     procedure SumListChanged(Sender: TObject);
  1674.     procedure SumListRecalcAll(Sender: TObject);
  1675.     procedure TimedScroll(Direction: TGridScrollDirection); override;
  1676.     procedure TimerScroll; virtual;
  1677.     procedure TitleClick(Column: TColumnEh); dynamic;
  1678.     procedure TopLeftChanged; override;
  1679.     procedure TrackButton(X, Y: Integer);
  1680.     procedure UpdateActive; virtual;
  1681.     procedure UpdateEditorMode;
  1682.     procedure UpdateFilterEdit(UpdateData: Boolean);
  1683.     procedure UpdateFilterEditProps(DataCol: Longint); virtual;
  1684.     procedure UpdateHorzExtScrollBar; virtual;
  1685.     procedure UpdateRowCount; virtual;
  1686.     procedure UpdateScrollBar; virtual;
  1687.     {$IFDEF EH_LIB_VCL}
  1688.     procedure WndProc(var Message: TMessage); override;
  1689.     {$ENDIF}
  1690.     procedure WriteAutoFitColWidths(Value: Boolean);
  1691.     procedure WriteCellText(Column: TColumnEh; ACanvas: TCanvas; ARect: TRect;
  1692.       FillRect: Boolean; DX, DY: Integer; Text: string; Alignment: TAlignment;
  1693.       Layout: TTextLayout; MultyL: Boolean;
  1694.       EndEllipsis: Boolean; LeftMarg, RightMarg: Integer);
  1695.     procedure WriteHTitleMargin(Value: Integer);
  1696.     procedure WriteMinAutoFitWidth(Value: Integer);
  1697.     procedure WriteTitleHeight(th: Integer);
  1698.     procedure WriteTitleLines(tl: Integer);
  1699.     procedure WriteUseMultiTitle(Value: Boolean);
  1700.     procedure WriteVTitleMargin(Value: Integer);
  1701.     property ColCount;
  1702.     property Color;
  1703.     property ColWidths;
  1704.     property DataLink: TGridDataLinkEh read FDataLink;
  1705.     property DefaultColWidth;
  1706.     property DefaultDrawing: Boolean read FDefaultDrawing write FDefaultDrawing default True;
  1707.     property FilterEdit: TCustomDBEditEh read FFilterEdit;
  1708.     property FilterEditMode: Boolean read FFilterEditMode write SetFilterEditMode;
  1709.     property FooterColor: TColor read FFooterColor write SetFooterColor;
  1710.     property FooterFont: TFont read FFooterFont write SetFooterFont;
  1711.     property ImeMode;
  1712.     property ImeName;
  1713.     property LayoutLock: Byte read FLayoutLock;
  1714.     property OnApplyFilter: TNotifyEvent read FOnApplyFilter write FOnApplyFilter;
  1715.     property OnCellClick: TDBGridEhClickEvent read FOnCellClick write FOnCellClick;
  1716.     property OnColEnter: TNotifyEvent read FOnColEnter write FOnColEnter;
  1717.     property OnColExit: TNotifyEvent read FOnColExit write FOnColExit;
  1718.     property OnColumnMoved: TMovedEvent read FOnColumnMoved write FOnColumnMoved;
  1719.     property OnDrawColumnCell: TDrawColumnEhCellEvent read FOnDrawColumnCell write FOnDrawColumnCell;
  1720.     property OnDrawDataCell: TDrawDataCellEvent read FOnDrawDataCell write FOnDrawDataCell; { obsolete }
  1721.     property OnEditButtonClick: TNotifyEvent read FOnEditButtonClick write FOnEditButtonClick;
  1722.     property OnTitleClick: TDBGridEhClickEvent read FOnTitleClick write FOnTitleClick;
  1723.     property ParentColor default False;
  1724.     property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
  1725.     property RowCount;
  1726.     property RowHeights;
  1727.     property SelectedRows: TBookmarkListEh read FBookmarks;
  1728.     property STFilter: TSTDBGridEhFilter read FSTFilter write SetSTFilter;
  1729.     property TopRow;
  1730.     property UpdateLock: Byte read FUpdateLock;
  1731.     property ContraColCount: Longint read GetContraColCount write SetContraColCount default 0;
  1732.   public
  1733.     constructor Create(AOwner: TComponent); override;
  1734.     destructor Destroy; override;
  1735.     function CellRect(ACol, ARow: Longint): TRect;
  1736.     function CheckCopyAction: Boolean;
  1737.     function CheckCutAction: Boolean;
  1738.     function CheckDeleteAction: Boolean;
  1739.     function CheckPasteAction: Boolean;
  1740.     function CheckSelectAllAction: Boolean;
  1741.     function DataBox: TGridRect;
  1742.     function DataRect: TRect;
  1743.     function DataRowCount: Integer;
  1744.     function DataRowToRecNo(DataRow: Integer): Integer;
  1745.     function DefaultMoveDataRows(BookmarkList: TStrings; ToRecNo: Longint;
  1746.       TreeLevel: Integer; CheckOnly: Boolean): Boolean; virtual;
  1747.     function ExecuteAction(Action: TBasicAction): Boolean; override;
  1748.     function LocateText(AGrid: TCustomDBGridEh; const FieldName: string;
  1749.       const Text: string; Options: TLocateTextOptionsEh; Direction: TLocateTextDirectionEh;
  1750.       Matching: TLocateTextMatchingEh; TreeFindRange: TLocateTextTreeFindRangeEh): Boolean; virtual;
  1751.     function GetCellTreeElmentsAreaWidth: Integer;
  1752.     function GetCompleteKeyPress: string;
  1753.     function GetFooterValue(Row: Integer; Column: TColumnEh): string; virtual;
  1754.     function UpdateAction(Action: TBasicAction): Boolean; override;
  1755.     function ValidFieldIndex(FieldIndex: Integer): Boolean;
  1756.     function IsFindDialogShowAsModal: Boolean; virtual;
  1757.     procedure ApplyFilter;
  1758.     procedure ClearFilter;
  1759.     procedure DefaultDrawColumnCell(const Rect: TRect; DataCol: Integer;
  1760.       Column: TColumnEh; State: TGridDrawState);
  1761.     procedure DefaultApplyFilter; virtual;
  1762.     procedure DefaultApplySorting; virtual;
  1763.     procedure DefaultDrawDataCell(const Rect: TRect; Field: TField; State: TGridDrawState); { obsolete }
  1764.     procedure DefaultDrawFooterCell(const Rect: TRect; DataCol, Row: Integer;
  1765.       Column: TColumnEh; State: TGridDrawState);
  1766.     procedure DefaultHandler(var Message); override;
  1767.     procedure InvalidateFooter;
  1768.     procedure RestoreBookmark;
  1769.     procedure RestoreColumnsLayout(ACustIni: TCustomIniFile; Section: string;
  1770.       RestoreParams: TColumnEhRestoreParams); overload;
  1771.     {$IFDEF EH_LIB_VCL}
  1772.     procedure RestoreColumnsLayout(ARegIni: TRegIniFile; RestoreParams: TColumnEhRestoreParams); overload;
  1773.     {$ENDIF}
  1774.     procedure RestoreColumnsLayoutIni(IniFileName: string; Section: string;
  1775.       RestoreParams: TColumnEhRestoreParams);
  1776.     procedure RestoreGridLayout(ARegIni: TCustomIniFile; Section: string;
  1777.       RestoreParams: TDBGridEhRestoreParams); overload;
  1778.     {$IFDEF EH_LIB_VCL}
  1779.     procedure RestoreGridLayout(ARegIni: TRegIniFile; RestoreParams: TDBGridEhRestoreParams); overload;
  1780.     {$ENDIF}
  1781.     procedure RestoreGridLayoutIni(IniFileName: string; Section: string;
  1782.       RestoreParams: TDBGridEhRestoreParams);
  1783.     procedure SaveBookmark;
  1784.     procedure SaveColumnsLayout(ACustIni: TCustomIniFile; Section: string); overload;
  1785.     {$IFDEF EH_LIB_VCL}
  1786.     procedure SaveColumnsLayout(ARegIni: TRegIniFile); overload;
  1787.     {$ENDIF}
  1788.     procedure SaveColumnsLayoutIni(IniFileName: string; Section: string; DeleteSection: Boolean);
  1789.     procedure SaveGridLayout(ACustIni: TCustomIniFile; Section: string); overload;
  1790.     {$IFDEF EH_LIB_VCL}
  1791.     procedure SaveGridLayout(ARegIni: TRegIniFile); overload;
  1792.     {$ENDIF}
  1793.     procedure SaveGridLayoutIni(IniFileName: string; Section: string; DeleteSection: Boolean);
  1794.     procedure SetSortMarkedColumns;
  1795.     procedure SetValueFromPrevRecord;
  1796.     procedure StartInplaceSearch(ss: string; TimeOut: Integer; InpsDirection: TLocateTextDirectionEh);
  1797.     procedure StopInplaceSearch;
  1798.     property AllowedOperations: TDBGridEhAllowedOperations read FAllowedOperations
  1799.       write FAllowedOperations default [alopInsertEh, alopUpdateEh, alopDeleteEh, alopAppendEh];
  1800.     property AllowedSelections: TDBGridEhAllowedSelections read FAllowedSelections
  1801.       write SetAllowedSelections default [gstRecordBookmarks..gstAll];
  1802.     property AutoFitColWidths: Boolean read FAutoFitColWidths
  1803.       write WriteAutoFitColWidths default False;
  1804.     property BufferedPaint: Boolean read FBufferedPaint write FBufferedPaint;
  1805.     property Canvas;
  1806.     property Col read GetCol write SetCol;
  1807.     property ColumnDefValues: TColumnDefValuesEh read FColumnDefValues write SetColumnDefValues;
  1808.     property Columns: TDBGridColumnsEh read FColumns write SetColumns;
  1809.     {$IFDEF EH_LIB_VCL}
  1810.     property Ctl3D;
  1811.     {$ENDIF}
  1812.     property DataSource: TDataSource read GetDataSource write SetDataSource;
  1813.     property DrawMemoText: Boolean read FDrawMemoText write SetDrawMemoText default false;
  1814.     property EvenRowColor: TColor read GetEvenRowColor write SetEvenRowColor stored IsEvenRowColorStored;
  1815.     property EditActions: TDBGridEhEditActions read FEditActions write FEditActions default [];
  1816.     property EditorMode;
  1817.     property FieldColumns[const FieldName: string]: TColumnEh read GetFieldColumns; default;
  1818.     property FieldCount: Integer read GetFieldCount;
  1819.     property Fields[FieldIndex: Integer]: TField read GetFields;
  1820.     property FixedColor;
  1821.     //gridseh    property Flat: Boolean read FFlat write SetFlat default False;
  1822.     property Font;
  1823.     property FooterRowCount: Integer read GetFooterRowCount write SetFooterRowCount default 0;
  1824.     property FrozenCols: Integer read FFrozenCols write SetFrozenCols default 0;
  1825.     property HeadTree: THeadTreeNode read FHeadTree;
  1826.     property HorzScrollBar: TDBGridEhScrollBar read FHorzScrollBar write SetHorzScrollBar;
  1827.     property IndicatorOffset: Byte read FIndicatorOffset;
  1828.     property InplaceEditor;
  1829.     property InplaceSearching: Boolean read FInplaceSearching;
  1830.     property LeafFieldArr: PTLeafCol read FLeafFieldArr;
  1831.     property LeftCol;
  1832.     property MinAutoFitWidth: Integer read FMinAutoFitWidth write WriteMinAutoFitWidth default 0;
  1833.     property OnCheckButton: TCheckTitleEhBtnEvent read FOnCheckButton write FOnCheckButton;
  1834.     property OnColWidthsChanged: TNotifyEvent read FOnColWidthsChanged write FOnColWidthsChanged;
  1835.     property OnDrawFooterCell: TDrawFooterCellEvent read FOnDrawFooterCell write FOnDrawFooterCell;
  1836.     property OnGetBtnParams: TGetBtnEhParamsEvent read FOnGetBtnParams write FOnGetBtnParams;
  1837.     property OnGetCellParams: TGetCellEhParamsEvent read FOnGetCellParams write FOnGetCellParams;
  1838.     property OnGetFooterParams: TGetFooterParamsEvent read FOnGetFooterParams write FOnGetFooterParams;
  1839.     property OnSelectionChanged: TNotifyEvent read FOnSelectionChanged write FOnSelectionChanged;
  1840.     property OnSortMarkingChanged: TNotifyEvent read FOnSortMarkingChanged write FOnSortMarkingChanged;
  1841.     property OnSumListAfterRecalcAll: TNotifyEvent read FOnSumListAfterRecalcAll write FOnSumListAfterRecalcAll;
  1842.     property OnSumListRecalcAll: TNotifyEvent read FOnSumListRecalcAll write FOnSumListRecalcAll;
  1843.     property OnTitleBtnClick: TTitleEhClickEvent read FOnTitleBtnClick write FOnTitleBtnClick;
  1844.     property OnTopLeftChanged: TNotifyEvent read FOnTopLeftChanged write FOnTopLeftChanged;
  1845.     property OnMoveRecords: TGridMoveRecordsEventEh read FOnMoveRecords write FOnMoveRecords;
  1846.     property Options: TDBGridOptions read FOptions write SetOptions
  1847.       default [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColLines,
  1848.       dgRowLines, dgTabs, dgConfirmDelete, dgCancelOnExit];
  1849.     property OptionsEh: TDBGridEhOptions read FOptionsEh write SetOptionsEh
  1850.       default [dghFixed3D, dghHighlightFocus, dghClearSelection, dghDialogFind];
  1851.     property OddRowColor: TColor read GetOddRowColor write SetOddRowColor stored IsOddRowColorStored;
  1852.     property Row;
  1853.     property RowHeight: Integer read GetRowHeight write SetRowHeight default 0;
  1854.     property RowLines: Integer read GetRowLines write SetRowLines default 0;
  1855.     property RowSizingAllowed: Boolean read FRowSizingAllowed write SetRowSizingAllowed default False;
  1856.     property SelectedField: TField read GetSelectedField write SetSelectedField;
  1857.     property SelectedIndex: Integer read GetSelectedIndex write SetSelectedIndex;
  1858.     property Selection: TDBGridEhSelection read FSelection;
  1859.     property SortLocal: Boolean read FSortLocal write FSortLocal default False;
  1860.     property SortMarkedColumns: TColumnsEhList read FSortMarkedColumns write FSortMarkedColumns;
  1861.     property Style: TDBGridEhStyle read FStyle write SetStyle;
  1862.     property SumList: TDBGridEhSumList read FSumList write SetSumList;
  1863.     property TimerActive: Boolean read FTimerActive;
  1864.     property TitleFont: TFont read FTitleFont write SetTitleFont;
  1865.     property TitleHeight: Integer read ReadTitleHeight write WriteTitleHeight default 0;
  1866.     property TitleImages: TCustomImageList read FTitleImages write SetTitleImages;
  1867.     property TitleLines: Integer read ReadTitleLines write WriteTitleLines default 0;
  1868.     property TitleOffset: Byte read FTitleOffset;
  1869.     property TopDataOffset: Byte read FTopDataOffset;
  1870.     property TryUseMemTableInt: Boolean read FTryUseMemTableInt write FTryUseMemTableInt;
  1871.     property UseMultiTitle: Boolean read FUseMultiTitle write WriteUseMultiTitle default False;
  1872.     property VertScrollBar: TDBGridEhScrollBar read FVertScrollBar write SetVertScrollBar;
  1873.     property VisibleColCount;
  1874.     property VisibleColumns: TColumnsEhList read FVisibleColumns write FVisibleColumns;
  1875.     property VisibleRowCount;
  1876.     property VTitleMargin: Integer read FVTitleMargin write WriteVTitleMargin default 10;
  1877.     property GridLineColors;
  1878.     //    property HTitleMargin: Integer read FHTitleMargin write WritEhTitleMargin default 0;
  1879.   end;
  1880.   { TDBGridEh }
  1881.   TDBGridEh = class(TCustomDBGridEh)
  1882.   public
  1883.     property Canvas;
  1884.     property GridHeight;
  1885.     property RowCount;
  1886.     property SelectedRows;
  1887.   published
  1888.     property Align;
  1889.     property AllowedOperations;
  1890.     property AllowedSelections;
  1891.     property Anchors;
  1892.     property AutoFitColWidths;
  1893.     {$IFDEF EH_LIB_VCL}
  1894.     property BiDiMode;
  1895.     {$ENDIF}
  1896.     property BorderStyle;
  1897.     property Color;
  1898.     property ColumnDefValues;
  1899.     property Columns stored False;                          //StoreColumns;
  1900.     property Constraints;
  1901.     property ContraColCount;
  1902.     {$IFDEF EH_LIB_VCL}
  1903.     property Ctl3D;
  1904.     {$ENDIF}
  1905.     property DataSource;
  1906.     property DefaultDrawing;
  1907.     {$IFDEF EH_LIB_VCL}
  1908.     property DragCursor;
  1909.     property DragKind;
  1910.     {$ENDIF}
  1911.     property DragMode;
  1912.     property DrawMemoText;
  1913.     property EditActions;
  1914.     property Enabled;
  1915.     property EvenRowColor;
  1916.     property FixedColor;
  1917.     property Flat;
  1918.     property Font;
  1919.     property FooterColor;
  1920.     property FooterFont;
  1921.     property FooterRowCount;
  1922.     property FrozenCols;
  1923.     property HorzScrollBar;
  1924.     {$IFDEF EH_LIB_VCL}
  1925.     property ImeMode;
  1926.     property ImeName;
  1927.     {$ENDIF}
  1928.     property MinAutoFitWidth;
  1929.     property OddRowColor;
  1930.     property Options;
  1931.     property OptionsEh;
  1932.     {$IFDEF EH_LIB_VCL}
  1933.     property ParentBiDiMode;
  1934.     property ParentCtl3D;
  1935.     {$ENDIF}
  1936.     property ParentColor;
  1937.     property ParentFont;
  1938.     property ParentShowHint;
  1939.     property PopupMenu;
  1940.     property ReadOnly;
  1941.     property RowHeight;
  1942.     property RowLines;
  1943.     property RowSizingAllowed;
  1944.     property ShowHint;
  1945.     property SortLocal;
  1946.     property STFilter;
  1947.     property SumList;
  1948.     property TabOrder;
  1949.     property TabStop;
  1950.     property TitleFont;
  1951.     property TitleHeight;
  1952.     property TitleImages;
  1953.     property TitleLines;
  1954.     property UseMultiTitle;
  1955.     property VertScrollBar;
  1956.     property Visible;
  1957.     property VTitleMargin;
  1958.     //    property HTitleMargin;
  1959.     property OnApplyFilter;
  1960.     property OnCellClick;
  1961.     property OnCheckButton;
  1962.     property OnColEnter;
  1963.     property OnColExit;
  1964.     property OnColumnMoved;
  1965.     property OnColWidthsChanged;
  1966.     {$IFDEF EH_LIB_5}
  1967.     property OnContextPopup;
  1968.     {$ENDIF}
  1969.     property OnDblClick;
  1970.     property OnDragDrop;
  1971.     property OnDragOver;
  1972.     property OnDrawColumnCell;
  1973.     property OnDrawDataCell;                                { obsolete }
  1974.     property OnDrawFooterCell;
  1975.     property OnEditButtonClick;
  1976.     {$IFDEF EH_LIB_VCL}
  1977.     property OnEndDock;
  1978.     {$ENDIF}
  1979.     property OnEndDrag;
  1980.     property OnEnter;
  1981.     property OnExit;
  1982.     property OnGetBtnParams;
  1983.     property OnGetCellParams;
  1984.     property OnGetFooterParams;
  1985.     property OnKeyDown;
  1986.     property OnKeyPress;
  1987.     property OnKeyUp;
  1988.     property OnMouseDown;
  1989.     property OnMouseMove;
  1990.     property OnMouseUp;
  1991.     property OnMoveRecords;
  1992.     property OnSelectionChanged;
  1993.     property OnSortMarkingChanged;
  1994.     {$IFDEF EH_LIB_VCL}
  1995.     property OnStartDock;
  1996.     {$ENDIF}
  1997.     property OnStartDrag;
  1998.     property OnSumListAfterRecalcAll;
  1999.     property OnSumListRecalcAll;
  2000.     property OnTitleBtnClick;
  2001.     property OnTitleClick;
  2002.   end;
  2003.   { TColumnDropDownBoxEh }
  2004.   TColumnDropDownBoxEh = class(TPersistent)
  2005.   private
  2006.     FAlign: TDropDownAlign;
  2007.     FAutoDrop: Boolean;
  2008.     FAutoFitColWidths: Boolean;
  2009.     FListSource: TDataSource;
  2010.     FOwner: TPersistent;
  2011.     FRows: Integer;
  2012.     FShowTitles: Boolean;
  2013.     FSizable: Boolean;
  2014.     FSpecRow: TSpecRowEh;
  2015.     FUseMultiTitle: Boolean;
  2016.     FWidth: Integer;
  2017.     function GetAutoFitColWidths: Boolean;
  2018.     function GetColumnDefValues: TColumnDefValuesEh;
  2019.     function GetColumns: TDBGridColumnsEh;
  2020.     function GetListSource: TDataSource;
  2021.     function GetOptions: TDBLookupGridEhOptions;
  2022.     function StoreColumns: Boolean;
  2023.     procedure SetAutoFitColWidths(const Value: Boolean);
  2024.     procedure SetColumnDefValues(const Value: TColumnDefValuesEh);
  2025.     procedure SetColumns(const Value: TDBGridColumnsEh);
  2026.     procedure SetListSource(const Value: TDataSource);
  2027.     procedure SetOptions(const Value: TDBLookupGridEhOptions);
  2028.     procedure SetSpecRow(const Value: TSpecRowEh);
  2029.   protected
  2030.     property Align: TDropDownAlign read FAlign write FAlign default daLeft;
  2031.     property AutoDrop: Boolean read FAutoDrop write FAutoDrop default False;
  2032.     property Rows: Integer read FRows write FRows default 7;
  2033.     property ShowTitles: Boolean read FShowTitles write FShowTitles default False;
  2034.     property Sizable: Boolean read FSizable write FSizable default False;
  2035.     property SpecRow: TSpecRowEh read FSpecRow write SetSpecRow;
  2036.     property Width: Integer read FWidth write FWidth default 0;
  2037.   public
  2038.     constructor Create(Owner: TPersistent);
  2039.     destructor Destroy; override;
  2040.     function GetOwner: TPersistent; override;
  2041.     procedure Assign(Source: TPersistent); override;
  2042.   published
  2043.     property AutoFitColWidths: Boolean read GetAutoFitColWidths write SetAutoFitColWidths default True;
  2044.     property ColumnDefValues: TColumnDefValuesEh read GetColumnDefValues write SetColumnDefValues;
  2045.     property Columns: TDBGridColumnsEh read GetColumns write SetColumns stored StoreColumns;
  2046.     property ListSource: TDataSource read GetListSource write SetListSource;
  2047.     property Options: TDBLookupGridEhOptions read GetOptions write SetOptions default [dlgColLinesEh];
  2048.     property UseMultiTitle: Boolean read FUseMultiTitle write FUseMultiTitle default False;
  2049.   end;
  2050.   TDBGridEhStyle = class(TPersistent)
  2051.   private
  2052.     FGrids: TObjectList;
  2053.     FLuminateSelection: Boolean;
  2054.     FScreenNumColors: Integer;
  2055.     FWindowHandle: HWND;
  2056.     FFilterEditCloseUpApplyFilter: Boolean;
  2057.     FIsDrawFocusRect: Boolean;
  2058.     procedure SetLuminateSelection(const Value: Boolean);
  2059.   protected
  2060.     function HighlightDataCellColor(AGrid: TCustomDBGridEh; ACol, ARow: Integer;
  2061.       DataCol, DataRow: Integer; const Value: string; AState: TGridDrawState;
  2062.       InMultiSelect: Boolean; var AColor: TColor; AFont: TFont): Boolean; virtual;
  2063.     function HighlightNoDataCellColor(AGrid: TCustomDBGridEh; ACol, ARow: Integer;
  2064.       DataCol, DataRow: Integer; CellType: TCellTypeEh; AState: TGridDrawState;
  2065.       InMultiSelect: Boolean; var AColor: TColor; AFont: TFont): Boolean; virtual;
  2066.     procedure RemoveAllChangeNotification;
  2067.     procedure StyleWndProc(var Msg: TMessage); virtual;
  2068.     procedure SysColorChanged; virtual;
  2069.   public
  2070.     constructor Create;
  2071.     destructor Destroy; override;
  2072.     function GridInChangeNotification(Grid: TCustomDBGridEh): Boolean;
  2073.     function LightenColor(AColor: TColor; GlassColor: TColor; Ungray: Boolean): TColor;
  2074.     procedure AddChangeNotification(Grid: TCustomDBGridEh);
  2075.     procedure Changed;
  2076.     procedure RemoveChangeNotification(Grid: TCustomDBGridEh);
  2077.     property LuminateSelection: Boolean read FLuminateSelection write SetLuminateSelection default True;
  2078.     property FilterEditCloseUpApplyFilter: Boolean
  2079.       read FFilterEditCloseUpApplyFilter write FFilterEditCloseUpApplyFilter default False;
  2080.     property IsDrawFocusRect: Boolean read FIsDrawFocusRect write FIsDrawFocusRect default True;
  2081.   end;
  2082. function SetDBGridEhDefaultStyle(NewGridDefaultStyle: TDBGridEhStyle): TDBGridEhStyle;
  2083. function DBGridEhDefaultStyle: TDBGridEhStyle;
  2084. type
  2085.   { TDBGridEhDataService }
  2086.   TDBGridEhDataService = class(TPersistent)
  2087.   private
  2088.     FOnApplySorting: TNotifyEvent;
  2089.     FOnApplyFilter: TNotifyEvent;
  2090.     FOnLocateText: TLocateTextEventEh;
  2091.   protected
  2092.     function DefaultLocateText(AGrid: TCustomDBGridEh; const FieldName: string;
  2093.       const Text: string; Options: TLocateTextOptionsEh; Direction: TLocateTextDirectionEh;
  2094.       Matching: TLocateTextMatchingEh; TreeFindRange: TLocateTextTreeFindRangeEh): Boolean; virtual;
  2095.     function DefaultMoveRecords(AGrid: TCustomDBGridEh; BookmarkList: TStrings; ToRecNo: Longint; CheckOnly: Boolean): Boolean; virtual;
  2096.     function LocateText(AGrid: TCustomDBGridEh; const FieldName: string;
  2097.       const Text: string; Options: TLocateTextOptionsEh; Direction: TLocateTextDirectionEh;
  2098.       Matching: TLocateTextMatchingEh; TreeFindRange: TLocateTextTreeFindRangeEh): Boolean; virtual;
  2099.     function MoveRecords(AGrid: TCustomDBGridEh; BookmarkList: TStrings; ToRecNo: Longint; CheckOnly: Boolean): Boolean; virtual;
  2100.     procedure ApplyFilter(AGrid: TCustomDBGridEh); virtual;
  2101.     procedure ApplySorting(AGrid: TCustomDBGridEh); virtual;
  2102.     procedure DefaultApplyFilter(AGrid: TCustomDBGridEh); virtual;
  2103.     procedure DefaultApplySorting(AGrid: TCustomDBGridEh); virtual;
  2104.     procedure ExecuteFindDialog(AGrid: TCustomDBGridEh; Text, FieldName: string; Modal: Boolean); virtual;
  2105.   public
  2106.     property OnApplyFilter: TNotifyEvent read FOnApplyFilter write FOnApplyFilter;
  2107.     property OnApplySorting: TNotifyEvent read FOnApplySorting write FOnApplySorting;
  2108.     property OnLocateText: TLocateTextEventEh read FOnLocateText write FOnLocateText;
  2109.   end;
  2110.   {const
  2111.     IndicatorWidth = 11;}
  2112. var
  2113.   DBGridEhDataService: TDBGridEhDataService;
  2114.   SortMarkerFont: TFont;
  2115.   DBGridEhIndicators: TImageList;
  2116.   DBGridEhSortMarkerImages: TImageList;
  2117.   DBGridEhInplaceSearchKey: TShortCut;
  2118.   DBGridEhInplaceSearchNextKey: TShortCut;
  2119.   DBGridEhInplaceSearchPriorKey: TShortCut;
  2120.   DBGridEhInplaceSearchTimeOut: Integer;                    // in millisecond
  2121.   DBGridEhInplaceSearchColor: TColor;
  2122.   DBGridEhInplaceSearchTextColor: TColor;
  2123.   DBGridEhSetValueFromPrevRecordKey: TShortCut;
  2124.   DBGridEhFindDialogKey: TShortCut;
  2125.   DBGridEhDebugDraw: Boolean;
  2126. const
  2127.   ColSelectionAreaHeight: Integer = 7;
  2128. procedure RecreateInplaceSearchIndicator;
  2129. procedure WriteTextEh(ACanvas: TCanvas;                     // Canvas
  2130.   ARect: TRect;                                             // Draw rect and ClippingRect
  2131.   FillRect: Boolean;                                        // Fill rect Canvas.Brash.Color
  2132.   DX, DY: Integer;                                          // InflateRect(Rect, -DX, -DY) for text
  2133.   Text: string;                                             // Draw text
  2134.   Alignment: TAlignment;                                    // Text alignment
  2135.   Layout: TTextLayout;                                      // Text layout
  2136.   MultyL: Boolean;                                          // Word break
  2137.   EndEllipsis: Boolean;                                     // Truncate long text by ellipsis
  2138.   LeftMarg,                                                 // Left margin
  2139.   RightMarg: Integer;                                       // Right margin
  2140.   RightToLeftReading: Boolean);
  2141. function WriteTextVerticalEh(ACanvas: TCanvas;
  2142.   ARect: TRect;                                             // Draw rect and ClippingRect
  2143.   FillRect: Boolean;                                        // Fill rect Canvas.Brash.Color
  2144.   DX, DY: Integer;                                          // InflateRect(Rect, -DX, -DY) for text
  2145.   Text: string;                                             // Draw text
  2146.   Alignment: TAlignment;                                    // Text alignment
  2147.   Layout: TTextLayout;                                      // Text layout
  2148.   EndEllipsis: Boolean;                                     // Truncate long text by ellipsis
  2149.   CalcTextExtent: Boolean                                   //
  2150.   ): Integer;
  2151. implementation
  2152. {$IFDEF EH_LIB_VCL}
  2153. uses DBConsts, Dialogs, Comctrls, CommCtrl, DBGridEhImpExp, Clipbrd, ExtCtrls,
  2154.   {$IFDEF EH_LIB_6}MaskUtils, {$ELSE}Mask, {$ENDIF}
  2155.   {$IFDEF EH_LIB_7}Themes, UxTheme, {$ENDIF}
  2156.   EhLibConsts, DBLookupGridsEh, CalculatorEh, DBGridEhFindDlgs, DBUtilsEh,
  2157.   DBLookupEh;
  2158. {$R DBGRIDEH.RES}
  2159. {$ELSE}
  2160. uses DBConsts, QDialogs, QComctrls, QDBGridEhImpExp, QClipbrd, QExtCtrls,
  2161.   QEhLibConsts, QDBLookupGridsEh, QCalculatorEh, QDbUtilsEh, QDBGridEhFindDlgs;
  2162. {$R QDBGRIDEH.RES}
  2163. {$ENDIF}
  2164. const
  2165.   bmArrow = 'DBGARROWEH';
  2166.   bmEdit = 'DBEDITEH';
  2167.   bmInsert = 'DBINSERTEH';
  2168.   bmMultiDot = 'DBMULTIDOTEH';
  2169.   bmMultiArrow = 'DBMULTIARROWEH';
  2170.   bmSmDown = 'DBSMDOWNEH';
  2171.   bmSmUp = 'DBSMUPEH';
  2172.   bmEditWhite = 'DBGARROWEHW';
  2173.   MaxMapSize = (MaxInt div 2) div SizeOf(Integer);          { 250 million }
  2174. var
  2175.   hcrDownCurEh: HCursor = 0;
  2176.   hcrRightCurEh: HCursor = 0;
  2177.   hcrLeftCurEh: HCursor = 0;
  2178.   VarColCellParamsEh: TColCellParamsEh;
  2179. procedure ChangeCanvasDrawOrientation(Canvas: TCanvas;
  2180.   RightToLeftOrientation: Boolean; Width, Height: Integer);
  2181. var
  2182.   Org: TPoint;
  2183.   Ext: TPoint;
  2184. begin
  2185.   if RightToLeftOrientation then
  2186.   begin
  2187.     Org := Point(Width, 0);
  2188.     Ext := Point(-1, 1);
  2189.     SetMapMode(Canvas.Handle, mm_Anisotropic);
  2190.     SetWindowOrgEx(Canvas.Handle, Org.X, Org.Y, nil);
  2191.     SetViewportExtEx(Canvas.Handle, Width, Height, nil);
  2192.     SetWindowExtEx(Canvas.Handle, Ext.X * Width, Ext.Y * Height, nil);
  2193.   end else
  2194.   begin
  2195.     Org := Point(0, 0);
  2196.     Ext := Point(1, 1);
  2197.     SetMapMode(Canvas.Handle, mm_Anisotropic);
  2198.     SetWindowOrgEx(Canvas.Handle, Org.X, Org.Y, nil);
  2199.     SetViewportExtEx(Canvas.Handle, Width, Height, nil);
  2200.     SetWindowExtEx(Canvas.Handle, Ext.X * Width, Ext.Y * Height, nil);
  2201.   end;
  2202. end;
  2203. function SafeGetFieldAsInteger(Field: TField; ValueOnError: Integer): Integer;
  2204. begin
  2205.   Result := ValueOnError;
  2206.   if (Field.DataType in [ftSmallint, ftInteger, ftWord]) then
  2207.     Result := Field.AsInteger
  2208.   else if (Field is TLargeintField) and
  2209.     (TLargeintField(Field).AsLargeInt >= Low(Integer)) and
  2210.     (TLargeintField(Field).AsLargeInt <= MAXINT) then
  2211.     Result := TLargeintField(Field).AsLargeInt
  2212.   else if (Field.DataType in [ftFloat]) and
  2213.     (Field.AsFloat >= Low(Integer)) and
  2214.     (Field.AsFloat <= MAXINT) then
  2215.     Result := Field.AsInteger
  2216.   else if (Field.DataType in [ftCurrency]) and
  2217.     (Field.AsCurrency >= Low(Integer)) and
  2218.     (Field.AsCurrency <= MAXINT) then
  2219.     Result := Field.AsInteger
  2220.   else if (Field.DataType in [ftBCD{$IFDEF EH_LIB_6}, ftFMTBcd{$ENDIF}]) and
  2221.     not VarIsNull(Field.AsVariant) and
  2222.     (Field.AsVariant >= Low(Integer)) and
  2223.     (Field.AsVariant <= MAXINT) then
  2224.     Result := Field.AsInteger;
  2225. end;
  2226. function FieldsCanModify(Fields: TObjectList): Boolean;
  2227. var
  2228.   i: Integer;
  2229. begin
  2230.   Result := True;
  2231.   for i := 0 to Fields.Count - 1 do
  2232.     if not TField(Fields[i]).CanModify then
  2233.     begin
  2234.       Result := False;
  2235.       Exit;
  2236.     end;
  2237. end;
  2238. function GridRect(ALeft, ATop, ARight, ABottom: Integer): TGridRect;
  2239. begin
  2240.   Result.Left := ALeft;
  2241.   Result.Top := ATop;
  2242.   Result.Bottom := ABottom;
  2243.   Result.Right := ARight;
  2244. end;
  2245. { Error reporting }
  2246. procedure RaiseGridError(const S: string);
  2247. begin
  2248.   raise EInvalidGridOperationEh.Create(S);
  2249. end;
  2250. procedure KillMessage(Wnd: HWnd; Msg: Integer);
  2251. // Delete the requested message from the queue, but throw back
  2252. // any WM_QUIT msgs that PeekMessage may also return
  2253. var
  2254.   M: TMsg;
  2255. begin
  2256.   M.Message := 0;
  2257.   if PeekMessage(M, Wnd, Msg, Msg, pm_Remove) and (M.Message = WM_QUIT) then
  2258.     PostQuitMessage(M.wparam);
  2259. end;
  2260. type
  2261.   TCharSet = set of AnsiChar;
  2262. function ExtractWord(N: Integer; const S: string; WordDelims: TCharSet): string; forward;
  2263. function GetDefaultSection(Component: TComponent): string;
  2264. var
  2265.   //  F: TCustomForm;
  2266.   Owner: TComponent;
  2267. begin
  2268.   if Component <> nil then
  2269.   begin
  2270.     if Component is TCustomForm then
  2271.       Result := Component.ClassName
  2272.     else
  2273.     begin
  2274.       Result := Component.Name;
  2275.       Owner := Component.Owner;
  2276.       while (Owner <> nil) and not (Owner is TCustomForm) do
  2277.       begin
  2278.         Result := Owner.Name + '.' + Result;
  2279.         Owner := Owner.Owner;
  2280.       end;
  2281.       if Owner <> nil then
  2282.         Result := Owner.ClassName + Result;
  2283.       {      if Component is TControl then
  2284.             begin
  2285.               F := GetParentForm(TControl(Component));
  2286.               if F <> nil then Result := F.ClassName + Result
  2287.               else
  2288.               begin
  2289.                 if TControl(Component).Parent <> nil then
  2290.                   Result := TControl(Component).Parent.Name + Result;
  2291.               end;
  2292.             end
  2293.             else
  2294.             begin
  2295.               Owner := Component.Owner;
  2296.               if Owner is TForm then
  2297.                 Result := Format('%s.%s', [Owner.ClassName, Result]);
  2298.             end;}
  2299.     end;
  2300.   end else
  2301.     Result := '';
  2302. end;
  2303. function Max(A, B: Longint): Longint;
  2304. begin
  2305.   if A > B
  2306.     then Result := A
  2307.   else Result := B;
  2308. end;
  2309. function Min(A, B: Longint): Longint;
  2310. begin
  2311.   if A < B
  2312.     then Result := A
  2313.   else Result := B;
  2314. end;
  2315. function iif(Condition: Boolean; V1, V2: Integer): Integer;
  2316. begin
  2317.   if (Condition) then Result := V1 else Result := V2;
  2318. end;
  2319. procedure GridInvalidateRow(Grid: TCustomDBGridEh; Row: Longint);
  2320. var
  2321.   I: Longint;
  2322. begin
  2323.   for I := 0 to Grid.FullColCount - 1 do Grid.InvalidateCell(I, Row);
  2324. end;
  2325. procedure OverturnUpRect(var ARect: TRect);
  2326. var Bottom: Integer;
  2327. begin
  2328.   Bottom := ARect.Bottom;
  2329.   ARect.Bottom := ARect.Top + (ARect.Right - ARect.Left);
  2330.   ARect.Right := ARect.Left + (Bottom - ARect.Top);
  2331. end;
  2332. function CheckHintTextRect(DrawTextBiDiModeFlagsReadingOnly: Longint;
  2333.   Canvas: TCanvas; RightIndent, FInterlinear: Integer; ws: string; ARect: TRect;
  2334.   WordWrap: Boolean; var TextWidth, TextHeight: Integer): Boolean;
  2335. var
  2336.   NewRect: TRect;
  2337.   uFormat: Integer;
  2338. begin
  2339.   Result := False;
  2340.   uFormat := DT_CALCRECT or DT_LEFT or DT_NOPREFIX or DrawTextBiDiModeFlagsReadingOnly;
  2341.   if WordWrap then uFormat := uFormat or DT_WORDBREAK;
  2342.   NewRect := Rect(0, 0, ARect.Right - ARect.Left - 2 - RightIndent, 0);
  2343.   if NewRect.Right <= 0 then NewRect.Right := 1;
  2344.   DrawTextEh(Canvas.Handle, ws, Length(ws), NewRect, uFormat);
  2345.   TextWidth := NewRect.Right - NewRect.Left;
  2346.   TextHeight := NewRect.Bottom - NewRect.Top;
  2347.   if (NewRect.Right - NewRect.Left > ARect.Right - ARect.Left - 2 - RightIndent) or
  2348.     (NewRect.Bottom - NewRect.Top > ARect.Bottom - ARect.Top - FInterlinear + 1) then
  2349.     Result := True;
  2350. end;
  2351. {function DefineCursor(Identifier: PChar): TCursor;
  2352. var Handle:HCursor;
  2353. begin
  2354.   Handle := LoadCursor(hInstance, Identifier);
  2355.   if Handle = 0 then raise EOutOfResources.Create('Cannot load cursor resource');
  2356.   for Result := 1 to High(TCursor) do
  2357.     if Screen.Cursors[Result] = Screen.Cursors[crArrow]  then
  2358.     begin
  2359.       Screen.Cursors[Result] := Handle;
  2360.       Exit;
  2361.     end;
  2362.   raise EOutOfResources.Create('Too many user-defined cursors');
  2363. end;}
  2364. function GetTextWidth(Canvas: TCanvas; Text: string): Integer;
  2365. var ARect: TRect;
  2366.   uFormat: Integer;
  2367. begin
  2368.   uFormat := DT_CALCRECT or DT_LEFT or DT_NOPREFIX;
  2369.   ARect := Rect(0, 0, 1, 0);
  2370.   DrawTextEh(Canvas.Handle, Text, Length(Text), ARect, uFormat);
  2371.   Result := ARect.Right - ARect.Left;
  2372. end;
  2373. function PointInGridRect(Col, Row: Longint; const Rect: TGridRect): Boolean;
  2374. begin
  2375.   Result := (Col >= Rect.Left) and (Col <= Rect.Right) and (Row >= Rect.Top)
  2376.     and (Row <= Rect.Bottom);
  2377. end;
  2378. var
  2379.   FDBGridEhDefaultStyle: TDBGridEhStyle = nil;
  2380. function SetDBGridEhDefaultStyle(NewGridDefaultStyle: TDBGridEhStyle): TDBGridEhStyle;
  2381. begin
  2382.   Result := FDBGridEhDefaultStyle;
  2383.   FDBGridEhDefaultStyle := NewGridDefaultStyle;
  2384.   FDBGridEhDefaultStyle.Changed;
  2385. end;
  2386. function DBGridEhDefaultStyle: TDBGridEhStyle;
  2387. begin
  2388.   Result := FDBGridEhDefaultStyle;
  2389. end;
  2390. { TDBGridEhStyle }
  2391. constructor TDBGridEhStyle.Create;
  2392. begin
  2393.   inherited Create;
  2394.   FGrids := TObjectList.Create(False);
  2395.   {$IFDEF CIL}
  2396.   FWindowHandle := WinUtils.AllocateHWnd(StyleWndProc);
  2397.   {$ELSE}
  2398.   FWindowHandle := {$IFDEF EH_LIB_6}Classes.{$ENDIF}AllocateHWnd(StyleWndProc);
  2399.   {$ENDIF}
  2400.   FLuminateSelection := True;
  2401.   FIsDrawFocusRect := True;
  2402.   SysColorChanged;
  2403. end;
  2404. destructor TDBGridEhStyle.Destroy;
  2405. var
  2406.   i: Integer;
  2407. begin
  2408.   {$IFDEF CIL}
  2409.   WinUtils.DeallocateHWnd(FWindowHandle);
  2410.   {$ELSE}
  2411.   {$IFDEF EH_LIB_6}Classes.{$ENDIF}DeallocateHWnd(FWindowHandle);
  2412.   {$ENDIF}
  2413.   if FDBGridEhDefaultStyle = Self then
  2414.     FDBGridEhDefaultStyle := nil;
  2415.   for i := FGrids.Count - 1 downto 0 do
  2416.     TCustomDBGridEh(FGrids[i]).Style := nil;
  2417.   FGrids.Free;
  2418.   inherited Destroy;
  2419. end;
  2420. procedure TDBGridEhStyle.Changed;
  2421. var
  2422.   i: Integer;
  2423. begin
  2424.   for i := 0 to FGrids.Count - 1 do
  2425.     TCustomDBGridEh(FGrids[i]).StyleEhChanged;
  2426. end;
  2427. procedure TDBGridEhStyle.AddChangeNotification(Grid: TCustomDBGridEh);
  2428. begin
  2429.   if not GridInChangeNotification(Grid) then
  2430.     FGrids.Add(Grid);
  2431. end;
  2432. function TDBGridEhStyle.GridInChangeNotification(Grid: TCustomDBGridEh): Boolean;
  2433. begin
  2434.   Result := (FGrids.IndexOf(Grid) >= 0);
  2435. end;
  2436. procedure TDBGridEhStyle.RemoveChangeNotification(Grid: TCustomDBGridEh);
  2437. begin
  2438.   FGrids.Remove(Grid);
  2439. end;
  2440. procedure TDBGridEhStyle.RemoveAllChangeNotification;
  2441. var
  2442.   i: Integer;
  2443. begin
  2444.   for i := 0 to FGrids.Count - 1 do
  2445.     FGrids.Delete(i);
  2446. end;
  2447. function TDBGridEhStyle.HighlightDataCellColor(AGrid: TCustomDBGridEh;
  2448.   ACol, ARow, DataCol, DataRow: Integer; const Value: string;
  2449.   AState: TGridDrawState; InMultiSelect: Boolean; var AColor: TColor; AFont: TFont): Boolean;
  2450. var
  2451.   AFocused: Boolean;
  2452. begin
  2453.   Result := False;
  2454.   AFocused := False;
  2455.   if {(dgMultiSelect in AGrid.Options) and} AGrid.Datalink.Active then
  2456.     Result := AGrid.Selection.DataCellSelected(DataCol, AGrid.Datalink.Datasource.Dataset.Bookmark);
  2457.   if not Result then
  2458.   begin
  2459.     AFocused := AGrid.Focused and (dghHighlightFocus in AGrid.OptionsEh);
  2460.     if (dghRowHighlight in AGrid.OptionsEh) and (DataRow + AGrid.TopDataOffset = AGrid.Row) and
  2461.       (AGrid.Selection.SelectionType = gstNon) and not (DataCol + AGrid.FIndicatorOffset = AGrid.Col) then
  2462.     begin
  2463.       AFocused := True;
  2464.       AState := AState + [gdSelected];
  2465.     end;
  2466.     Result := ((gdSelected in AState) {ddd//} or ((ARow) = AGrid.Row) and (dgRowSelect in AGrid.Options))
  2467.       and ((dgAlwaysShowSelection in AGrid.Options) or (AFocused {ddd//}))
  2468.       { updatelock eliminates flicker when tabbing between rows }
  2469.     and ((AGrid.UpdateLock = 0) or (dgRowSelect in AGrid.Options));
  2470.   end;
  2471.   if Result then
  2472.     if AGrid.IsSelectionActive then
  2473.     begin
  2474.       if LuminateSelection and (FScreenNumColors = -1) and
  2475.         not ((ARow = AGrid.Row) and ((ACol = AGrid.Col) or (dgRowSelect in AGrid.Options)))
  2476.         then
  2477.         //AColor := FLuminateSelectionColor
  2478.         AColor := GetNearestColor(AGrid.Canvas.Handle, LightenColor(AColor, clHighlight, True))
  2479.       else
  2480.       begin
  2481.         AColor := clHighlight;
  2482.         AFont.Color := clHighlightText;
  2483.       end;
  2484.     end else if (ARow = AGrid.Row) and
  2485.       ((ACol = AGrid.Col) or (dgRowSelect in AGrid.Options)) and
  2486.       ((dgAlwaysShowSelection in AGrid.Options) or AFocused) then
  2487.     begin
  2488.       AColor := clBtnShadow;
  2489.       AFont.Color := clHighlightText;
  2490.     end else if (FScreenNumColors = -1) then
  2491.       AColor := GetNearestColor(AGrid.Canvas.Handle, LightenColor(AColor, clBtnShadow, False))
  2492.     else
  2493.       AColor := clBtnFace;
  2494. end;
  2495. function TDBGridEhStyle.HighlightNoDataCellColor(AGrid: TCustomDBGridEh;
  2496.   ACol, ARow, DataCol, DataRow: Integer; CellType: TCellTypeEh;
  2497.   AState: TGridDrawState; InMultiSelect: Boolean; var AColor: TColor;
  2498.   AFont: TFont): Boolean;
  2499. begin
  2500.   Result := False;
  2501.   if InMultiSelect then
  2502.   begin
  2503.     if ((CellType.HorzType = hctIndicatorEh) and (CellType.VertType <> vctAboveFooterEh)) or
  2504.       ((CellType.HorzType = hctDataEh) and (CellType.VertType in [vctTitleEh, vctSubTitleEh])) then
  2505.     begin
  2506.       AColor := RGB(64, 64, 64);
  2507.       AFont.Color := clWhite;
  2508.     end else if AGrid.IsSelectionActive then
  2509.     begin
  2510.       if LuminateSelection and (FScreenNumColors = -1) then
  2511.         //        AColor := FLuminateSelectionColor
  2512.         AColor := LightenColor(AColor, clHighlight, True)
  2513.       else
  2514.       begin
  2515.         AColor := clHighlight;
  2516.         AFont.Color := clHighlightText;
  2517.       end;
  2518.     end else if (FScreenNumColors = -1) then
  2519.       AColor := LightenColor(AColor, clBtnShadow, False)
  2520.     else
  2521.       AColor := clBtnFace;
  2522.     Result := True;
  2523.   end;
  2524. end;
  2525. procedure TDBGridEhStyle.SetLuminateSelection(const Value: Boolean);
  2526. begin
  2527.   if FLuminateSelection = Value then Exit;
  2528.   FLuminateSelection := Value;
  2529.   Changed;
  2530. end;
  2531. procedure TDBGridEhStyle.StyleWndProc(var Msg: TMessage);
  2532. begin
  2533.   with Msg do
  2534.     if Msg = WM_SYSCOLORCHANGE then
  2535.     try
  2536.       SysColorChanged;
  2537.     except
  2538.       Application.HandleException(Self);
  2539.     end
  2540.     else
  2541.       Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
  2542. end;
  2543. function TDBGridEhStyle.LightenColor(AColor: TColor; GlassColor: TColor; Ungray: Boolean): TColor;
  2544. var
  2545.   r, g, b: Double;
  2546.   rgb: Longint;
  2547.   r_c, g_c, b_c: Double;
  2548.   rgb_c: Longint;
  2549. begin
  2550.   rgb := ColorToRGB(AColor);
  2551.   r := rgb and $FF;
  2552.   g := (rgb shr 8) and $FF;
  2553.   b := (rgb shr 16) and $FF;
  2554.   rgb_c := ColorToRGB(GlassColor);
  2555.   r_c := rgb_c and $FF;
  2556.   g_c := (rgb_c shr 8) and $FF;
  2557.   b_c := (rgb_c shr 16) and $FF;
  2558.   r := r + (r_c - r) * 0.5;
  2559.   g := g + (g_c - g) * 0.5;
  2560.   b := b + (b_c - b) * 0.5;
  2561.   r := r + (225 - r) * 0.6;
  2562.   g := g + (225 - g) * 0.6;
  2563.   b := b + (225 - b) * 0.6;
  2564.   if Ungray then
  2565.   begin
  2566.     r := r - (integer(122) - r) * 0.25;
  2567.     g := g - (integer(122) - g) * 0.25;
  2568.     b := b - (integer(122) - b) * 0.25;
  2569.   end;
  2570.   Result := TColor((Max(Min(Round(b), 255), 0) shl 16)
  2571.     or (Max(Min(Round(g), 255), 0) shl 8)
  2572.     or Max(Min(Round(r), 255), 0));
  2573. end;
  2574. procedure TDBGridEhStyle.SysColorChanged;
  2575. var
  2576.   DC: HDC;
  2577. begin
  2578.   DC := GetDC(0);
  2579.   FScreenNumColors := GetDeviceCaps(DC, NUMCOLORS);         // -1 if more then 256
  2580.   ReleaseDC(0, DC);
  2581. end;
  2582. { TDBGridInplaceEdit }
  2583. { TDBGridInplaceEdit adds support for a button on the in-place editor,
  2584.   which can be used to drop down a table-based lookup list, a stringlist-based
  2585.   pick list, or (if button style is esEllipsis) fire the grid event
  2586.   OnEditButtonClick.  }
  2587. //const
  2588. //  InitRepeatPause:Integer = 500;  { pause before repeat timer (ms) }
  2589. //  RepeatPause:Integer     = 100;  { pause before hint window displays (ms)}
  2590. type
  2591.   TEditStyle = (esSimple, esEllipsis, esPickList, esDataList, esDateCalendar, esUpDown, esDropDown);
  2592.   //  TPopupListbox = class;
  2593.   TDBGridInplaceEdit = class(TInplaceEdit, IComboEditEh{$IFNDEF CIL}, IUnknown{$ENDIF})
  2594.   private
  2595.     FCanvas: TCanvas;
  2596.     FActiveList: TWinControl;
  2597.     FButtonHeight: Integer;
  2598.     FButtonsWidth: Integer;
  2599.     FCharKeyStr: string;
  2600.     FDataList: TPopupDataGridEh;
  2601.     FDroppedDown: Boolean;
  2602.     FEditButtonControlList: TEditButtonControlList;
  2603.     FEditStyle: TEditStyle;
  2604.     FListColumnMothed: Boolean;
  2605.     FListVisible: Boolean;
  2606.     FLockCloseList: Boolean;
  2607.     FLookupSource: TDatasource;
  2608.     FMRUList: TMRUListEh;
  2609.     FMRUListControl: TWinControl;
  2610.     FNoClickCloseUp: Boolean;
  2611.     FPickList: TPopupListboxEh;
  2612.     FPopupCalculator: TWinControl;
  2613.     FPopupMonthCalendar: TPopupMonthCalendarEh;
  2614.     FReadOnlyStored: Boolean;
  2615.     FUserTextChanged: Boolean;
  2616.     FWordWrap: Boolean;
  2617.     FImageIndex: Integer;
  2618.     function DeleteSeletedText: string;
  2619.     function GetColumn: TColumnEh;
  2620.     function GetEditButtonByShortCut(ShortCut: TShortCut): TEditButtonEh;
  2621.     function GetGrid: TCustomDBGridEh;
  2622.     function GetMRUListControl: TWinControl;
  2623.     procedure CMCancelMode(var Message: TCMCancelMode); message CM_CancelMode;
  2624.     procedure DoDBCSKeyPress(var Key: Char);
  2625.     procedure ListColumnMoved(Sender: TObject; FromIndex, ToIndex: Longint);
  2626.     procedure ListMouseCloseUp(Sender: TObject; Accept: Boolean);
  2627.     procedure ListMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2628.     procedure LocateListText;
  2629.     procedure PopupListboxGetImageIndex(Sender: TObject; ItemIndex: Integer; var ImageIndex: Integer);
  2630.     procedure SetEditStyle(Value: TEditStyle);
  2631.     procedure SetWordWrap(const Value: Boolean);
  2632.     procedure UpdateImageIndex; virtual;
  2633.     procedure UpDownClick(Sender: TObject; Button: TUDBtnType);
  2634.     procedure WMKillFocus(var Message: TWMKillFocus); message WM_KillFocus;
  2635.     procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LButtonDblClk;
  2636.     procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  2637.     procedure WMPaste(var Message: TMessage); message WM_PASTE;
  2638.     procedure WMSetCursor(var Message: TWMSetCursor); message WM_SetCursor;
  2639.     procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  2640.   protected
  2641.     function CanDropCalculator: Boolean;
  2642.     function CreateEditButtonControl: TEditButtonControlEh; virtual;
  2643.     function CreateMRUListControl: TWinControl; virtual;
  2644.     function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
  2645.     function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
  2646.     function GetPopupCalculator: TWinControl; virtual;
  2647.     function TraceMouseMoveForPopupListbox(Sender: TObject; Shift: TShiftState; X, Y: Integer): Boolean;
  2648.     procedure BoundsChanged; override;
  2649.     procedure ButtonDown(IsDownButton: Boolean); virtual;
  2650.     procedure CalcEditRect(var ARect: TRect); virtual;
  2651.     procedure CloseUp(Accept: Boolean);
  2652.     procedure CreateParams(var Params: TCreateParams); override;
  2653.     procedure DBCSKeyPress(var Key: string); virtual;
  2654.     procedure DoDropDownKeys(var Key: Word; Shift: TShiftState);
  2655.     procedure DrawEditImage(DC: HDC);
  2656.     procedure DropDown;
  2657.     procedure EditButtonClick(Sender: TObject); virtual;
  2658.     procedure EditButtonDown(Sender: TObject; TopButton: Boolean;
  2659.       var AutoRepeat: Boolean; var Handled: Boolean); virtual;
  2660.     procedure EditButtonMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); virtual;
  2661.     procedure EditButtonMouseUp(Sender: TObject; Button: TMouseButton;
  2662.       Shift: TShiftState; X, Y: Integer); virtual;
  2663.     procedure FilterMRUItem(AText: string; var Accept: Boolean); virtual;
  2664.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  2665.     procedure KeyPress(var Key: Char); override;
  2666.     procedure KeyUp(var Key: Word; Shift: TShiftState); override;
  2667.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  2668.     procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  2669.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  2670.     procedure MRUListCloseUp(Sender: TObject; Accept: Boolean);
  2671.     procedure MRUListControlMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2672.     procedure MRUListControlResized(Sender: TObject); virtual;
  2673.     procedure MRUListDropDown(Sender: TObject);
  2674.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  2675.     procedure PaintRequiredState(ACanvas: TCanvas); virtual;
  2676.     procedure PaintWindow(DC: HDC); override;
  2677.     procedure UpdateContents; override;
  2678.     procedure UpdateEditButtonControlList;
  2679.     procedure UpdateEditButtonControlsState;
  2680.     procedure UserChange; virtual;
  2681.     procedure WndProc(var Message: TMessage); override;
  2682.     property ActiveList: TWinControl read FActiveList write FActiveList;
  2683.     property Column: TColumnEh read GetColumn;
  2684.     property DataList: TPopupDataGridEh read FDataList;
  2685.     property EditStyle: TEditStyle read FEditStyle write SetEditStyle;
  2686.     property Grid: TCustomDBGridEh read GetGrid;
  2687.     property MRUList: TMRUListEh read FMRUList write FMRUList;
  2688.     property MRUListControl: TWinControl read GetMRUListControl;
  2689.     property PickList: TPopupListboxEh read FPickList;
  2690.     property WordWrap: Boolean read FWordWrap write SetWordWrap;
  2691.     property ReadOnly;
  2692.   public
  2693.     constructor Create(Owner: TComponent); override;
  2694.     destructor Destroy; override;
  2695.     procedure DefaultHandler(var Message); override;
  2696.   end;
  2697.   { TDBGridInplaceEdit }
  2698. constructor TDBGridInplaceEdit.Create(Owner: TComponent);
  2699. begin
  2700.   inherited Create(Owner);
  2701.   FLookupSource := TDataSource.Create(Self);
  2702.   FEditStyle := esSimple;
  2703.   FCanvas := TControlCanvas.Create;
  2704.   TControlCanvas(FCanvas).Control := Self;
  2705. end;
  2706. destructor TDBGridInplaceEdit.Destroy;
  2707. begin
  2708.   FCanvas.Free;
  2709.   inherited Destroy;
  2710. end;
  2711. function TDBGridInplaceEdit.DeleteSeletedText: string;
  2712. begin
  2713.   Result := Text;
  2714.   Delete(Result, SelStart + 1, SelLength);
  2715. end;
  2716. function GetTextHeight(Canvas: TCanvas; Font: TFont): Integer;
  2717. var
  2718.   DC: HDC;
  2719.   SaveFont: HFont;
  2720.   Metrics: TTextMetric;
  2721. begin
  2722.   if Canvas = nil
  2723.     then DC := GetDC(0)
  2724.   else DC := Canvas.Handle;
  2725.   SaveFont := SelectObject(DC, Font.Handle);
  2726.   GetTextMetrics(DC, Metrics);
  2727.   SelectObject(DC, SaveFont);
  2728.   if Canvas = nil then
  2729.     ReleaseDC(0, DC);
  2730.   Result := Metrics.tmHeight;
  2731. end;
  2732. procedure TDBGridInplaceEdit.CalcEditRect(var ARect: TRect);
  2733. begin
  2734.   if Grid.Flat
  2735.     then SetRect(ARect, 2, 1, Width - 2, Height - 1)
  2736.   else SetRect(ARect, 2, 2, Width - 2, Height);
  2737.   if ((ARect.Bottom - ARect.Top) < GetTextHeight(nil, Font)) and (ARect.Bottom < Height) then
  2738.     Inc(ARect.Bottom);
  2739.   if FButtonsWidth > 0 then
  2740.     if Column.UseRightToLeftAlignment
  2741.       then Inc(ARect.Left, FButtonsWidth)
  2742.     else Dec(ARect.Right, FButtonsWidth);
  2743.   if (Column <> nil) and (Column.ImageList <> nil) and Column.ShowImageAndText then
  2744.     if Column.UseRightToLeftAlignment
  2745.       then Dec(ARect.Right, Column.ImageList.Width + 5)
  2746.     else Inc(ARect.Left, Column.ImageList.Width + 5);
  2747.   if (Grid.FIntMemTable <> nil) and (Column = Grid.VisibleColumns[0]) and Grid.FIntMemTable.MemTableIsTreeList then
  2748.     if Column.UseRightToLeftAlignment
  2749.       then Dec(ARect.Right, Grid.GetCellTreeElmentsAreaWidth + 1)
  2750.     else Inc(ARect.Left, Grid.GetCellTreeElmentsAreaWidth + 1);
  2751. end;
  2752. procedure TDBGridInplaceEdit.BoundsChanged;
  2753. var
  2754.   R: TRect;
  2755.   Msg: TMsg;
  2756. begin
  2757.   PeekMessage(Msg, Handle, CM_IGNOREEDITDOWN, CM_IGNOREEDITDOWN, PM_REMOVE);
  2758.   UpdateEditButtonControlList;
  2759.   UpdateEditButtonControlsState;
  2760.   CalcEditRect(R);
  2761.   //  SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@R));
  2762.   SendStructMessage(Handle, EM_SETRECTNP, 0, R);
  2763.   SendMessage(Handle, EM_SCROLLCARET, 0, 0);
  2764.   if SysLocale.FarEast
  2765.     then SetImeCompositionWindow(Font, R.Left, R.Top);
  2766.   if Height > Round(FButtonsWidth * 3 / 2)
  2767.     then FButtonHeight := FButtonsWidth
  2768.   else FButtonHeight := Height;
  2769. end;
  2770. procedure TDBGridInplaceEdit.CreateParams(var Params: TCreateParams);
  2771. begin
  2772.   inherited CreateParams(Params);
  2773.   if WordWrap then
  2774.     Params.Style := Params.Style and (not ES_AUTOHSCROLL) or ES_MULTILINE or ES_LEFT;
  2775.   if Grid.Flat then
  2776.     FButtonsWidth := FlatButtonWidth + 1
  2777.   else
  2778.     FButtonsWidth := GetSystemMetrics(SM_CXVSCROLL);
  2779. end;
  2780. procedure TDBGridInplaceEdit.DoDropDownKeys(var Key: Word; Shift: TShiftState);
  2781. begin
  2782.   case Key of
  2783.     VK_UP, VK_DOWN:
  2784.       if ssAlt in Shift then
  2785.       begin
  2786.         if FListVisible then CloseUp(True) else DropDown;
  2787.         Key := 0;
  2788.       end;
  2789.     VK_RETURN, VK_ESCAPE:
  2790.       if FListVisible and not (ssAlt in Shift) and not (FActiveList = FPopupCalculator) then
  2791.       begin
  2792.         CloseUp(Key = VK_RETURN);
  2793.         Key := 0;
  2794.       end
  2795.       else if not FListVisible and (Key = VK_RETURN) and ([ssCtrl] = Shift) then
  2796.       begin
  2797.         DropDown;
  2798.         Key := 0;
  2799.       end;
  2800.   end;
  2801. end;
  2802. procedure TDBGridInplaceEdit.DropDown;
  2803. var
  2804.   P: TPoint;
  2805.   I, J, Y: Integer;
  2806.   Column: TColumnEh;
  2807.   {WorkArea, }R: TRect;
  2808.   FLookupDataSet: TDataSet;
  2809.   PopupCalculatorIntf: IPopupCalculatorEh;
  2810.   ADropDownAlign: TDropDownAlign;
  2811. begin
  2812.   if not FListVisible and Assigned(FActiveList) then
  2813.   begin
  2814.     FActiveList.Width := Width;
  2815.     with Grid do
  2816.       Column := Columns[SelectedIndex];
  2817.     if FActiveList = FDataList then                         //DataList
  2818.       with Column.Field do
  2819.       begin
  2820.         //for delete FDataList.FSizeGrip.Visible := Column.DropDownSizing;
  2821.         FLookupDataSet := Column.UsedLookupDataSet;
  2822.         if not Assigned(FLookupDataSet) then Exit;
  2823.         FDataList.Color := Color;
  2824.         FDataList.Font := Font;
  2825.         //      FDataList.RowCount := Column.DropDownRows;
  2826.         FDataList.SpecRow := Column.DropDownSpecRow;
  2827.         if FLookupDataSet.IsSequenced and
  2828.           (FLookupDataSet.RecordCount > 0) and
  2829.           (Integer(Column.DropDownRows) > FLookupDataSet.RecordCount)
  2830.           then
  2831.           FDataList.RowCount := FLookupDataSet.RecordCount
  2832.         else
  2833.           FDataList.RowCount := Column.DropDownRows;
  2834.         FDataList.ShowTitles := Column.DropDownShowTitles;
  2835.         FLookupSource.DataSet := FLookupDataSet;
  2836.         FDataList.KeyField := LookupKeyFields;
  2837.         //ddd      FDataList.ListField := {ddd LookupResultField}Column.LookupDisplayFields;
  2838.         FDataList.ListFieldIndex := 0;
  2839.         FDataList.ListField := Column.LookupDisplayFields;  // Assignment ListField must be after ListFieldIndex
  2840.         FDataList.AutoFitColWidths := False;                // To avoid fit columns width to editbox width for Column.DropDownWidth = -1
  2841.         FDataList.UseMultiTitle := Column.DropDownBox.UseMultiTitle;
  2842.         FDataList.ListSource := FLookupSource;
  2843.         if (Column.DropDownWidth = -1) then
  2844.           FDataList.ClientWidth := FDataList.GetColumnsWidthToFit
  2845.         else if Column.DropDownWidth > 0 then
  2846.           FDataList.Width := Column.DropDownWidth
  2847.         else
  2848.           FDataList.Width := Self.Width;
  2849.         if (FDataList.Width < Width) then
  2850.           FDataList.Width := Self.Width;
  2851.         FDataList.KeyValue := Grid.FEditKeyValue {DataSet.FieldByName(KeyFields).Value ddd};
  2852.         FListColumnMothed := False;
  2853.         FDataList.OnColumnMoved := ListColumnMoved;
  2854.         FDataList.AutoFitColWidths := Column.DropDownBox.AutoFitColWidths;
  2855.         {      J := Column.DefaultWidth;
  2856.               if J > FDataList.ClientWidth then
  2857.                 FDataList.ClientWidth := J;
  2858.       }end
  2859.     else if (FActiveList = FPopupMonthCalendar) then
  2860.     begin
  2861.       FPopupMonthCalendar.Color := Color;
  2862.       FPopupMonthCalendar.Font := Font;
  2863.       {try
  2864.         FPopupMonthCalendar.Date := StrToDate(Text);
  2865.       except
  2866.         FPopupMonthCalendar.Date := Grid.Columns[CurColumn.Field.AsDateTime;
  2867.       end;}
  2868.       try
  2869.         if Text = '' then
  2870.           FPopupMonthCalendar.Date := TDate(Date)
  2871.         else
  2872.           FPopupMonthCalendar.Date := TDate(StrToDate(Text));
  2873.       except
  2874.         if Column.Field.AsDateTime = 0 then
  2875.           FPopupMonthCalendar.Date := TDate(Date)
  2876.         else
  2877.           FPopupMonthCalendar.Date := TDate(Column.Field.AsDateTime);
  2878.       end;
  2879.       MonthCal_GetMinReqRect(FPopupMonthCalendar.Handle, R);
  2880.       FPopupMonthCalendar.Width := R.Right - R.Left;
  2881.       FPopupMonthCalendar.Height := R.Bottom - R.Top;
  2882.     end else if (FActiveList = FPopupCalculator) then
  2883.     begin
  2884.       if Supports(FPopupCalculator, IPopupCalculatorEh, PopupCalculatorIntf) then
  2885.       begin
  2886.         if Text = ''
  2887.           then PopupCalculatorIntf.Value := 0
  2888.         else PopupCalculatorIntf.Value := StrToFloat(Text);
  2889.         PopupCalculatorIntf.Flat := Grid.Flat;
  2890.       end;
  2891.       HideCaret(Handle);
  2892.       SelLength := 0;
  2893.     end else
  2894.     begin
  2895.       //for delete FPickList.FSizeGripResized := False;
  2896.       //for delete FPickList.FSizeGrip.Visible := Column.DropDownSizing;
  2897.       FPickList.Color := Color;
  2898.       FPickList.Font := Font;
  2899.       if Assigned(Column.KeyList) and (Column.KeyList.Count > 0) then
  2900.       begin
  2901.         FPickList.Items.BeginUpdate;
  2902.         FPickList.Items.Clear;
  2903.         for i := 0 to Min(Column.KeyList.Count, Column.Picklist.Count) - 1 do
  2904.           FPickList.Items.AddObject(Column.Picklist.Strings[i], Column.Picklist.Objects[i]);
  2905.         FPickList.Items.EndUpdate;
  2906.       end else
  2907.         FPickList.Items := Column.Picklist;
  2908.       if FPickList.Items.Count >= Integer(Column.DropDownRows) then
  2909.         FPickList.Height := Integer(Column.DropDownRows) * FPickList.ItemHeight + 4
  2910.       else
  2911.         FPickList.Height := FPickList.Items.Count * FPickList.ItemHeight + 4;
  2912.       if Column.Field.IsNull then
  2913.         FPickList.ItemIndex := -1
  2914.       else if Assigned(Column.KeyList) and (Column.KeyList.Count > 0)
  2915.         then FPickList.ItemIndex := Column.PickList.IndexOf(Text)
  2916.       else FPickList.ItemIndex := FPickList.Items.IndexOf({dddColumn.Field.Value}Text);
  2917.       J := FPickList.ClientWidth;
  2918.       for I := 0 to FPickList.Items.Count - 1 do
  2919.       begin
  2920.         Y := FPickList.Canvas.TextWidth(FPickList.Items[I]);
  2921.         if Y > J then J := Y;
  2922.       end;
  2923.       FPickList.ClientWidth := J + 4;
  2924.     end;
  2925.     {
  2926.         P := Parent.ClientToScreen(Point(Left, Top));
  2927.         Y := P.Y + Height;
  2928.     //    SystemParametersInfo(SPI_GETWORKAREA, 0, Pointer(@WorkArea), 0);
  2929.         SystemParametersInfoEh(SPI_GETWORKAREA, 0, WorkArea, 0);
  2930.         if ((Y + FActiveList.Height > WorkArea.Bottom) and (P.Y - FActiveList.Height >= WorkArea.Top)) or
  2931.           ((P.Y - FActiveList.Height < WorkArea.Top) and (WorkArea.Bottom - Y < P.Y - WorkArea.Top))
  2932.           then
  2933.         begin
  2934.           if P.Y - FActiveList.Height < WorkArea.Top then
  2935.             FActiveList.Height := P.Y - WorkArea.Top;
  2936.           Y := P.Y - FActiveList.Height;
  2937.           FActiveList.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToTop), 0);
  2938.         end else
  2939.         begin
  2940.           if Y + FActiveList.Height > WorkArea.Bottom then
  2941.             FActiveList.Height := WorkArea.Bottom - Y;
  2942.           FActiveList.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToBottom), 0);
  2943.         end;
  2944.         //Drop Down Width
  2945.         if (FActiveList.Width > WorkArea.Right - WorkArea.Left) then
  2946.           FActiveList.Width := WorkArea.Right - WorkArea.Left;
  2947.         if (P.X + FActiveList.Width > WorkArea.Right) then
  2948.         begin
  2949.           P.X := WorkArea.Right - FActiveList.Width;
  2950.           FActiveList.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToLeft), 0);
  2951.         end else
  2952.           FActiveList.Perform(cm_SetSizeGripChangePosition, Ord(sgcpToRight), 0);
  2953.     }
  2954.     if MRUList.DroppedDown then
  2955.       MRUListCloseUp(MRUList, False);
  2956.     if BiDiMode = bdRightToLeft
  2957.       then ADropDownAlign := daRight
  2958.     else ADropDownAlign := daLeft;
  2959.     P := AlignDropDownWindow(Self, FActiveList, ADropDownAlign);
  2960.     //To avoid overlapping IME windows need to use HWND_NOTOPMOST instead of HWND_TOP
  2961.     SetWindowPos(FActiveList.Handle, {HWND_NOTOPMOST} HWND_TOP, P.X, P.Y, 0, 0,
  2962.       SWP_NOSIZE or SWP_NOACTIVATE or SWP_SHOWWINDOW);
  2963.     if FActiveList = FDataList then
  2964.     begin
  2965.       FDataList.Visible := True;                            //???
  2966.       FDataList.SizeGrip.Visible := Column.DropDownSizing;
  2967.       FDataList.RowCount := FDataList.RowCount;             //To update row count for horz scroll bar
  2968.     end
  2969.     else if FActiveList = FPickList then
  2970.       FPickList.SizeGrip.Visible := Column.DropDownSizing
  2971.     else if FActiveList = FPopupCalculator then
  2972.       FPopupCalculator.Visible := True;                     //???
  2973.     if FActiveList = FDataList then
  2974.       FDataList.SizeGripResized := False
  2975.     else if FActiveList = FPickList then
  2976.       FPickList.SizeGripResized := False;
  2977.     //FActiveList.Visible := True;
  2978.     FListVisible := True;
  2979.     Invalidate;
  2980.     Windows.SetFocus(Handle);
  2981.     FEditButtonControlList[0].EditButtonControl.AlwaysDown := True;
  2982.     FDroppedDown := True;
  2983.   end;
  2984. end;
  2985. procedure TDBGridInplaceEdit.CloseUp(Accept: Boolean);
  2986. var
  2987.   MasterFields: TObjectList;
  2988.   ListValue: Variant;
  2989.   CurColumn: TColumnEh;
  2990.   CanChange: Boolean;
  2991.   PopupCalculatorIntf: IPopupCalculatorEh;
  2992. begin
  2993.   ListValue := Null;
  2994.   CurColumn := Grid.Columns[Grid.SelectedIndex];
  2995.   if (FActiveList <> nil) and (FActiveList.HandleAllocated) and
  2996.     ((GetFocus = FActiveList.Handle) or
  2997.     (GetParent(GetFocus) = FActiveList.Handle)) then
  2998.     SetFocus;
  2999.   if FListVisible then
  3000.   begin
  3001.     with FEditButtonControlList[0].EditButtonControl do
  3002.       AlwaysDown := False;
  3003.     if FLockCloseList then Exit;
  3004.     if GetCapture <> 0 then SendMessage(GetCapture, WM_CANCELMODE, 0, 0);
  3005.     if FActiveList = FDataList then
  3006.     begin
  3007.       ListValue := FDataList.KeyValue;
  3008.       if FDataList.SizeGripResized then
  3009.       begin
  3010.         CurColumn.DropDownRows := FDataList.RowCount;
  3011.         CurColumn.FDropDownWidth := FDataList.Width;        //Assign to FValue to avoid nil FActiveList when Tab
  3012.       end;
  3013.       if FListColumnMothed then
  3014.         CurColumn.DropDownSpecRow.CellsText := FDataList.SpecRow.CellsText;
  3015.     end else if FActiveList = FPopupMonthCalendar then
  3016.     begin                                                   //MonthCalendar
  3017.     end else if FPickList = FActiveList then
  3018.     begin
  3019.       if FPickList.ItemIndex <> -1 then
  3020.       begin
  3021.         if Assigned(CurColumn.KeyList) and (CurColumn.KeyList.Count > 0)
  3022.           then ListValue := CurColumn.KeyList.Strings[FPicklist.ItemIndex]
  3023.         else ListValue := FPickList.Items[FPicklist.ItemIndex];
  3024.       end;
  3025.       if PickList.SizeGripResized then
  3026.       begin
  3027.         CurColumn.DropDownRows := PickList.ClientHeight div FPickList.ItemHeight;
  3028.         CurColumn.FDropDownWidth := PickList.Width;         //Assign to FValue to avoid nil FActiveList when Tab
  3029.       end;
  3030.     end;
  3031.     SetWindowPos(FActiveList.Handle, 0, 0, 0, 0, 0, SWP_NOZORDER or
  3032.       SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE or SWP_HIDEWINDOW);
  3033.     FActiveList.Visible := False;
  3034.     FDroppedDown := False;
  3035.     FListVisible := False;
  3036.     if Assigned(FDataList) then
  3037.     begin
  3038.       FDataList.AutoFitColWidths := False;
  3039.       FDataList.ListSource := nil;
  3040.     end;
  3041.     FLookupSource.Dataset := nil;
  3042.     Invalidate;
  3043.     ShowCaret(Handle);
  3044.     if Accept then
  3045.     begin
  3046.       if FActiveList = FDataList then                       // Lookup
  3047.         with Grid, Columns[SelectedIndex].Field do
  3048.         begin
  3049.           MasterFields := TObjectList.Create(False);
  3050.           try
  3051.             Dataset.GetFieldList(MasterFields, KeyFields);
  3052.             if FieldsCanModify(MasterFields) and Grid.CanEditModifyText and
  3053.               CurColumn.CanModify(True) then
  3054.             begin
  3055.               DataSet.Edit;
  3056.               try
  3057.                 CanChange := Grid.Datalink.Editing;
  3058.                 if CanChange then
  3059.                 begin
  3060.                   Grid.Datalink.Modified;
  3061.                   //Dataset.FieldValues[KeyFields] := ListValue;
  3062.                   Grid.FEditKeyValue := ListValue;
  3063.                   Grid.FEditText := FDataList.SelectedItem;
  3064.                   //MasterField.Value := ListValue;
  3065.                 end;
  3066.               except
  3067.                 on Exception do
  3068.                 begin
  3069.                   Self.Text := CurColumn.Field.Text + ' ';  //May be delphi bag. But without ' ' don't assign
  3070.                   raise;
  3071.                 end;
  3072.               end;
  3073.               Self.Text := FDataList.SelectedItem;
  3074.               SelectAll;
  3075.             end;
  3076.           finally
  3077.             MasterFields.Free;
  3078.           end;
  3079.         end
  3080.       else if (FActiveList = FPopupMonthCalendar) then
  3081.       begin
  3082.         with Grid, CurColumn.Field do
  3083.           if CurColumn.CanModify(True) and CanEditModifyText then
  3084.           begin
  3085.             DataSet.Edit;
  3086.             CurColumn.UpdateDataValues(DateToStr(TDateTime(FPopupMonthCalendar.Date)), Variant(FPopupMonthCalendar.Date), False);
  3087.             //AsDateTime := FPopupMonthCalendar.Date;
  3088.           end;
  3089.       end
  3090.       else if (FActiveList = FPopupCalculator) then
  3091.       begin
  3092.         if CurColumn.CanModify(True) and Grid.CanEditModifyText then
  3093.         begin
  3094.           if Supports(FPopupCalculator, IPopupCalculatorEh, PopupCalculatorIntf) then
  3095.             if VarType(PopupCalculatorIntf.Value) in
  3096.               [varDouble, varSmallint, varInteger, varSingle, varCurrency]
  3097.               then
  3098.             begin
  3099.               Text := FloatToStr(PopupCalculatorIntf.Value);
  3100.               Grid.FEditText := Text;
  3101.               SelectAll;
  3102.             end;
  3103.         end;
  3104.       end
  3105.       else if (not VarIsNull(ListValue)) and Grid.CanEditModifyText then
  3106.         with Grid, CurColumn.Field do
  3107.           if Assigned(CurColumn) and Assigned(CurColumn.KeyList) and (CurColumn.KeyList.Count > 0) then
  3108.           begin
  3109.             if (FPicklist.ItemIndex >= 0) then
  3110.             begin
  3111.               Self.Text := FPickList.Items[FPicklist.ItemIndex];
  3112.               Grid.FEditText := Self.Text;
  3113.               UpdateImageIndex;
  3114.             end
  3115.           end else
  3116.           begin
  3117.             Self.Text := ListValue;
  3118.             Grid.FEditText := ListValue;
  3119.             UpdateImageIndex;
  3120.           end;
  3121.     end else if FActiveList = FDataList then
  3122.       Text := Grid.FEditText
  3123.     else if FActiveList = FPickList then
  3124.       if CurColumn.GetColumnType = ctKeyPickList then
  3125.       begin
  3126.         Text := Grid.FEditText;
  3127.       end else
  3128.         Text := Grid.FEditText;
  3129.   end;
  3130. end;
  3131. function StringsLocate(StrList: TStrings; Str: string; Options: TLocateOptions): Integer;
  3132.   function Compare(S1, S2: string): Integer;
  3133.   begin
  3134.     if loCaseInsensitive in Options
  3135.       then Result := NlsCompareText(S1, S2)
  3136.     else Result := NlsCompareStr(S1, S2);
  3137.   end;
  3138. var i: Integer;
  3139.   S: string;
  3140. begin
  3141.   Result := -1;
  3142.   for i := 0 to StrList.Count - 1 do
  3143.   begin
  3144.     if loPartialKey in Options
  3145.       then S := Copy(StrList.Strings[i], 1, Length(Str))
  3146.     else S := StrList.Strings[i];
  3147.     if NlsCompareText(S, Str) = 0 then
  3148.     begin
  3149.       Result := i;
  3150.       Break;
  3151.     end;
  3152.   end;
  3153. end;
  3154. procedure TDBGridInplaceEdit.LocateListText;
  3155. var AColumn: TColumnEh;
  3156. begin
  3157.   with Grid do AColumn := Columns[SelectedIndex];
  3158.   if not AColumn.CanModify(True) then Exit;
  3159.   if (EditStyle = esDataList) then
  3160.   begin
  3161.     Grid.FEditText := Text;
  3162.     if (AColumn.UsedLookupDataSet <> nil) and
  3163.       AColumn.UsedLookupDataSet.Locate(AColumn.Field.LookupResultField, Text, [loCaseInsensitive]) then
  3164.       Grid.FEditKeyValue :=
  3165.         AColumn.UsedLookupDataSet.FieldValues[AColumn.Field.LookupKeyFields]
  3166.     else
  3167.       Grid.FEditKeyValue := Null;
  3168.   end else
  3169.     Grid.FEditText := Text;
  3170. end;
  3171. type
  3172.   TWinControlCracker = class(TWinControl) end;
  3173. procedure TDBGridInplaceEdit.KeyDown(var Key: Word; Shift: TShiftState);
  3174. var
  3175.   MasterFields: TObjectList;
  3176.   Field: TField;
  3177.   Y: Integer;
  3178.   S: string;
  3179.   eb: TEditButtonEh;
  3180.   AutoRepeat: Boolean;
  3181.   procedure SendToParent;
  3182.   begin
  3183.     Grid.KeyDown(Key, Shift);
  3184.     Key := 0;
  3185.   end;
  3186. begin
  3187.   if (EditStyle in [esEllipsis, esDropDown]) and (Key = VK_RETURN) and (Shift = [ssCtrl]) then
  3188.   begin
  3189.     KillMessage(Handle, WM_CHAR);
  3190.     Grid.EditButtonClick;
  3191.   end else
  3192.     if (Key = VK_DELETE) and (Shift = []) and (Column.GetColumnType in [ctLookupField, ctKeyPickList])
  3193.       {(EditStyle in [esDataList,esPickList])}
  3194.     and Column.CanModify(False) then
  3195.     begin
  3196.       if (SelStart = 0) and (SelLength = Length(Text)) and Column.CanModify(True) then // All text seleted
  3197.       begin
  3198.         if EditStyle = esDataList then                      //lookup
  3199.         begin
  3200.           Field := Column.Field;
  3201.           MasterFields := TObjectList.Create(False);
  3202.           try
  3203.             Field.Dataset.GetFieldList(MasterFields, Field.KeyFields);
  3204.             if FieldsCanModify(MasterFields) then
  3205.             begin
  3206.               Field.DataSet.Edit;
  3207.               //for i := 0 to MasterFields.Count-1 do TField(MasterFields[i]).Clear;
  3208.               //MasterField.Clear;
  3209.               Grid.Datalink.Modified;
  3210.               Grid.FEditKeyValue := Null;
  3211.               Grid.FEditText := '';
  3212.               Text := '';
  3213.               if Assigned(FDataList) then FDataList.KeyValue := Grid.FEditKeyValue;