unit frxSearchForm;

{$I frx.inc}

interface

uses
  {$IFDEF FPC}
  LCLIntf, LCLType, LMessages,
  {$ENDIF}
  {$IFNDEF FPC}
  Windows,
  {$ENDIF}
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, ExtCtrls, frxBaseForm, frxRes;

type

  { TfrxSearchForm }

{$IFNDEF FPC}
  TTView = class(TTreeView)
    procedure WM_MouseWheel(var Msg: TWMMouseWheel); message WM_MouseWheel; //TWMMouseWheel
  end;
{$ENDIF}

  TfrxSearchForm = class(TfrxBaseForm)
    pnlSearch: TPanel;
    edtFind: TEdit;
    lblFind: TLabel;
    btnFind: TButton;
    trvFind: {$IFNDEF FPC}TTView{$ELSE}TTreeView{$ENDIF};
    gbSearch: TGroupBox;
    chkBeg: TCheckBox;
    chkCase: TCheckBox;
    chkFindAll: TCheckBox;
{$IFDEF  FPC}
    procedure chkFindAllChange(Sender: TObject);
{$ELSE}
    procedure chkFindAllClick(Sender: TObject);
{$ENDIF}
    procedure edtFindKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure UpdateResouces; override;
    procedure CleartrvFind();
  end;

//var
//  frxSearchForm: TfrxSearchForm;

const
  EventScrollFind = High(SmallInt);

implementation

{$IFDEF FPC}
{$R *.lfm}
{$ELSE}
{$R *.dfm}
{$ENDIF}
uses frxPreview;

{$IFNDEF FPC}
procedure TTView.WM_MouseWheel(var Msg: TWMMouseWheel);
begin
  Msg.XPos := EventScrollFind;
  Msg.YPos := EventScrollFind;
  Inherited;
end;
{$ENDIF}

{$IFDEF FPC}
procedure TfrxSearchForm.chkFindAllChange(Sender: TObject);
{$ELSE}
procedure TfrxSearchForm.chkFindAllClick(Sender: TObject);
{$ENDIF}
begin
  CleartrvFind();
  trvFind.Visible := chkFindAll.Checked;
end;


  procedure TfrxSearchForm.UpdateResouces;
  begin
    inherited;
    lblFind.Caption := frxGet(301);
    chkCase.Caption := frxGet(305);
    btnFind.Caption := frxGet(300);
    chkBeg.Caption := frxGet(304);
    gbSearch.Caption := frxGet(302);
    chkFindAll.Caption := frxGet(306);
  end;

procedure TfrxSearchForm.edtFindKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_RETURN then btnFind.OnClick(nil);
end;

procedure TfrxSearchForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if ssCtrl in Shift then
    if Key = Ord('F') then
      begin
         if Self.Parent.Parent is TfrxPreviewForm then
           TfrxPreviewForm(Self.Parent.Parent).FindB.Down := False;
         TfrxPreview(Self.Parent).FindFmVisible := False;
         Hide;
         TfrxPreview(Self.Parent).SetFocus;
      end;
end;

procedure TfrxSearchForm.FormShow(Sender: TObject);
begin
  edtFind.SetFocus;
  edtFind.SelectAll;
end;

procedure TfrxSearchForm.CleartrvFind();
var
  i: Integer;
  data: PfrxTrvData;
begin
  for i := 0 to trvFind.Items.Count - 1 do
  begin
    data := trvFind.Items[i].Data;
    if data <> nil then
      Dispose(data);
  end;
  trvFind.Items.Clear();
end;

{$IFNDEF FPC}
initialization
  RegisterClass(TTView);
{$ENDIF}

end.
