TDBGridEh的 搜索面板 TDBGridSearchPanel

TCustomDBGridEh.Create  
  FSearchPanelControl := TDBGridSearchPanelControlEh.Create(Self); //这里,创建的构造函数是 另外一个类
  with FSearchPanelControl do
  begin
    Parent := Self;
    Name := 'FSearchPanelControl';
    Visible := False;
    SetBounds(0,0,0,0);
    {$IFDEF FPC}
    {$ELSE}
    ParentBackground := False;
    {$ENDIF}
    Text := '';
  end;
  
  
constructor TDBGridSearchPanelControlEh.Create(AGrid: TCustomGridEh);
begin
  inherited Create(AGrid); //这里 继承的
  ControlStyle := ControlStyle - [csSetCaption];
  FGrid := AGrid;
  InitItems;
  DoubleBuffered := True;
  Caption := '';
end;  


procedure TDBGridSearchPanelControlEh.InitItems;
var
  FI: TDBGridEhNavigatorFindBtn;
  FindBtn: TNavFindButtonEh;
  X: Integer;
//  ResName: string;
begin
  MinBtnSize := Point(10, 10);
  X := 0;

  FFindEditor := TNavFindEditEh.Create(Self); //这里 其实叫 FFindEditor,构造函数是 另外一个类
  FFindEditor.Flat := True;
  FFindEditor.SetBounds(X, 1, 100, MinBtnSize.Y-1);
  {$IFDEF FPC}
  {$ELSE}
  FFindEditor.BevelEdges := [beLeft, beTop, beRight, beBottom];
  FFindEditor.BevelInner := bvNone;
  FFindEditor.BevelKind := bkFlat;
  FFindEditor.BorderStyle := bsNone;
  FFindEditor.Ctl3D := True;
  {$ENDIF}
  FFindEditor.TabStop := False;
//  FFindEditor.SpecInternalSetText('Search');
  FFindEditor.EmptyDataInfo.Text := SSearchPanelEditorPromptText;
  FFindEditor.Parent := Self;
  FFindEditor.AutoSize := False;
  FFindEditor.IsEmptyState := True;
  FFindEditor.Font.Color := clGrayText;
  FFindEditor.Grid := FGrid;
  FFindEditor.OnUpdateModified := FindEditorUpdateModified;
  FFindEditor.EditButton.Visible := False;
//  FFindEditor.EditButton.Style := ebsAltDropDownEh;

  X := X + 85;

  for FI := Low(FindButtons) to High(FindButtons) do
  begin
    FindBtn := TNavFindButtonEh.Create(Self);
    FindBtn.Flat := True;
    FindBtn.Index := FI;
    FindBtn.ImageIndex := Ord(FI)+10;
    FindBtn.Enabled := True;
    FindBtn.SetBounds (X, 0, MinBtnSize.X, MinBtnSize.Y);
    FindBtn.Enabled := False;
    FindBtn.Enabled := True;
    FindBtn.OnClick := ClickHandler;
    FindBtn.OnMouseDown := BtnMouseDown;
    FindBtn.Parent := Self;
    FindButtons[FI] := FindBtn;
    X := X + MinBtnSize.X;
  end;

  FindButtons[gnfbCancelSearchFilterEh].Hint := SSearchPanelApplyFilterEh;
  FindButtons[gnfbFindNextEh].Hint := SSearchPanelFindNextEh;
  FindButtons[gnfbFindPrevEh].Hint := SSearchPanelFindPrevEh;
  FindButtons[gnfbOptionsEh].Hint := SSearchPanelOptionsEh;

  ResetVisibleControls;
end;


constructor TCustomDBComboBoxEh.Create(AOwner: TComponent); 这里
begin
  inherited Create(AOwner); //这里
  FItems := TStringList.Create;
  TStringList(FItems).OnChange := ItemsChanged;
  FKeyItems := TStringListEh.Create;
  TStringListEh(FKeyItems).CaseSensitive := True;
  TStringList(FKeyItems).OnChange := KeyItemsChanged;
  FVarValue := Null;
  FDropDownBox := CreateDropDownBox;
  FDropDownBox.Rows := 7;
  FItemIndex := -1;
  FCaseInsensitiveTextSearch := True;
  TStringList(FItems).CaseSensitive := not FCaseInsensitiveTextSearch;
end;


constructor TCustomDBEditEh.Create(AOwner: TComponent);
begin

  inherited Create(AOwner); 这里
  ControlStyle := ControlStyle + [csReplicatable, csCaptureMouse];
  FDataLink := CreateDataLink;
  FDataLink.Control := Self;
  FDataLink.OnDataChange := DataChange;
  FDataLink.OnEditingChange := EditingChange;
  FDataLink.OnUpdateData := InternalUpdateData;
  FDataLink.OnActiveChange := ActiveChange;

  FEditButton := CreateEditButton;
  FEditButton.OnChanged := EditButtonChanged;
  FEditButton.OnRefComponentChanged := EditButtonImagesRefComponentNotifyEvent;
  FEditButtons := CreateEditButtons;
  FEditButtons.OnChanged := EditButtonChanged;
  FEditButtons.OnRefComponentChanged := EditButtonImagesRefComponentNotifyEvent;
  FEditImage := CreateEditImage;

  FMRUList := TMRUListEh.Create(Self);
  FMRUList.OnSetDropDown := MRUListDropDown;
  FMRUList.OnSetCloseUp := MRUListCloseUp;

  FDynProps := TDynVarsEh.Create(Self);
  FEmptyDataInfo := TControlEmptyDataInfoEh.Create(Self);
  UpdateControlReadOnly;
  UpdateImageIndex;

  FButtonsBox := TEditButtonsBoxEh.Create(Self);
  FButtonsBox.SetBounds(0,0,0,0);
  FButtonsBox.Visible := False;
  FButtonsBox.Parent := Self;
  FButtonsBox.OnDown := EditButtonDown;
  FButtonsBox.OnClick := EditButtonClick;
  FButtonsBox.OnMouseMove := EditButtonMouseMove;
  FButtonsBox.OnMouseUp := EditButtonMouseUp;
  FButtonsBox.OnCreateEditButtonControl := CreateEditButtonControl;

  FControlLabel := TControlLabelEh.Create(Self);
  FControlLabel.FreeNotification(Self);
  FControlLabel.FocusControl := Self;
  FControlLabelLocation := TControlLabelLocationEh.Create(Self);
end;


constructor TCustomMaskEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);这里
  FMaskState := [];
  FMaskBlank := DefaultBlank;
end;


constructor TCustomEdit.Create(AOwner: TComponent);
const
  EditStyle = [csClickEvents, csSetCaption, csDoubleClicks, csFixedHeight, csPannable];
begin
  inherited Create(AOwner); 这里
  if NewStyleControls then
    ControlStyle := EditStyle else
    ControlStyle := EditStyle + [csFramed];
  Width := 121;
  Height := 25;
  TabStop := True;
  ParentColor := False;
  FBorderStyle := bsSingle;
  FAutoSize := True;
  FAutoSelect := True;
  FHideSelection := True;
  AdjustHeight;
  FOldSelLength := -1;
  FOldSelStart := -1;
end;

========================================================================


procedure TCustomDBEditEh.WMChar(var Message: TWMChar);
var
  CharMsg: Windows.TMsg;
  DBC: Boolean;
begin
  FCompleteKeyPress := Char(Message.CharCode);
  try
    DBC := False;
    if (CharInSetEh(Char(Message.CharCode), LeadBytes)) then
      if PeekMessage(CharMsg, Handle, WM_CHAR, WM_CHAR, PM_NOREMOVE) then
        if CharMsg.Message <> WM_Quit then
        begin
{$IFDEF CIL}
//          FCompleteKeyPress := FCompleteKeyPress + Char(CharMsg.wParam);
{$ELSE}
          FCompleteKeyPress := FCompleteKeyPress + Char(CharMsg.wParam);
{$ENDIF}
          DBC := True;
        end;

    inherited;

    if DBC and (Char(Message.CharCode) = #0) then
      PeekMessage(CharMsg, Handle, WM_CHAR, WM_CHAR, PM_REMOVE);
  finally
    FCompleteKeyPress := '';
  end;
end;

function TWinControl.DoKeyPress(var Message: TWMKey): Boolean;
var
  Form: TCustomForm;
  Ch: Char;
begin
  Result := True;
  Form := GetParentForm(Self);
  if (Form <> nil) and (Form <> Self) and Form.KeyPreview and
    TWinControl(Form).DoKeyPress(Message) then Exit;
  if not (csNoStdEvents in ControlStyle) then
    with Message do
    begin
      Ch := Char(CharCode);
      KeyPress(Ch);
      CharCode := Word(Ch);
      if Char(CharCode) = #0 then Exit;
    end;
  Result := False;
end;

procedure TNavFindEditEh.KeyPress(var Key: Char); 这里 输入
begin
  if (Key = #27) and not ListVisible then //ESC
  begin
{    if CanUndo then
    begin
      Undo;
      ClearUndo;
      Modified := False;
      UpdateModified;
    end else}
      CancelSearchEditorMode;
    Key := #0;
  end else if (Key = #13) and not ListVisible then
  begin
    if TCustomDBGridEhCrack(Grid).SearchPanel.FilterEnabled then
      ApplySearchFilter
    else
    begin
      if GetKeyState(VK_SHIFT) < 0
        then TDBGridSearchPanelControlEh(Parent).FindPrev
        else TDBGridSearchPanelControlEh(Parent).FindNext;
    end;
    Key := #0;
  end;
  inherited KeyPress(Key);
end;


procedure TDBGridSearchPanelControlEh.FindBtnClick(Index: TDBGridEhNavigatorFindBtn);右边3个按钮
var
  Grid: TCustomDBGridEhCrack;
begin
  Grid := TCustomDBGridEhCrack(FGrid);
  if (Grid.DataSource <> nil) and (Grid.DataSource.State <> dsInactive) then
  begin
    if Grid.SearchEditorMode = False then
      Grid.SearchEditorMode := True;
    case Index of
      gnfbCancelSearchFilterEh:
        if not FFindEditor.TextAppliedAsFilter
          then FFindEditor.ApplySearchFilter
          else FFindEditor.CancelSearchEditorMode;
      gnfbFindNextEh:
        FindNext;
      gnfbFindPrevEh:
        FindPrev;
      gnfbOptionsEh: ;
    end;
  end;
end;

procedure TNavFindEditEh.CancelSearchEditorMode;
begin
  SpecInternalSetText('');
  TDBGridSearchPanelEhCrack(TCustomDBGridEhCrack(Grid).SearchPanel).InterSetSearchingText(Text);
  TCustomDBGridEhCrack(Grid).SearchEditorMode := False;
  TCustomDBGridEhCrack(Grid).ClearSearchFilter;
  Modified := False;
  TextAppliedAsFilter := True;
  UpdateModified;
end;

 

转载于:https://www.cnblogs.com/CodeGear/p/5284848.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值