{*************************************************************************}
{                                                                         }
{ written by TMS Software                                                 }
{           copyright © 2013                                              }
{           Email : info@tmssoftware.com                                  }
{           Web : http://www.tmssoftware.com                              }
{                                                                         }
{ The source code is given as is. The author is not responsible           }
{ for any possible damage done due to the use of this code.               }
{ The component can be freely used in any application. The complete       }
{ source code remains property of the author and may not be distributed,  }
{ published, given or sold in any form as such. No parts of the source    }
{ code can be included in any other component or application without      }
{ written authorization of the author.                                    }
{*************************************************************************}

unit FMX.TMSFindDialog;

interface

{$I TMSDEFS.INC}


uses
  Classes, FMX.Forms, FMX.Memo, FMX.Menus, FMX.Edit, FMX.Controls, FMX.Types, FMX.TMSBaseControl,
  FMX.Layouts, FMX.ListBox, UITypes, FMX.StdCtrls;

type
  TTMSFMXFindDialogOption = (fdoCaseSensitive, fdoExpression, fdoCloseIfFound,
    fdoWholeWordOnly, fdoWrapAtEndOfFile, fdoContinueToNextFile, fdoMoreEnabled,
    fdoSetMarkerEnabled, fdoPreviousEnabled, fdoFindEnabled, fdoCloseEnabled, fdoMoreExpanded, fdoFindList, fdoDown, fdoSelection);

  TTMSFMXFindDialogVisibleOption = (fdovCaseSensitive, fdovExpression, fdovCloseIfFound,
    fdovWholeWordOnly, fdovWrapAtEndOfFile, fdovContinueToNextFile, fdovMore, fdovSetMarker, fdovPrevious, fdovFind,
    fdovClose, fdovFindCombo, fdovFindMemo, fdovDirection, fdovSelection);

  TTMSFMXFindDialogOptions = set of TTMSFMXFindDialogOption;
  TTMSFMXFindDialogVisibleOptions = set of TTMSFMXFindDialogVisibleOption;

const
  DefaultFindOptions = [fdoMoreEnabled, fdoPreviousEnabled, fdoSetMarkerEnabled, fdoFindEnabled, fdoCloseEnabled, fdoDown];
  DefaultVisibleFindOptions = [fdovCaseSensitive, fdovExpression, fdovCloseIfFound,
    fdovWholeWordOnly, fdovWrapAtEndOfFile, fdovPrevious, fdovFind,
    fdovClose, fdovFindCombo, fdovFindMemo, fdovDirection];

type
  TTMSFMXFindDialog = class;

  TFindEditChangeEvent = procedure(Sender: TObject; var AText: string) of object;

  TFindUILanguage = class(TPersistent)
  private
    FCloseIfFound: String;
    FFindWhat: String;
    FCaseSensitive: String;
    FWrapAtEndOfFile: String;
    FExpression: String;
    FMore: String;
    FSetMarker: String;
    FPrevious: String;
    FWholeWordOnly: String;
    FClose: String;
    FFind: String;
    FContinueToNextFile: String;
    FLess: String;
    FDirection: String;
    FDown: String;
    FUp: String;
    FFindCaption: string;
    FSelection: string;
  public
    constructor Create(AOwner: TComponent);
    procedure Assign(Source: TPersistent); override;
    procedure Init;
  published
    property FindCaption: string read FFindCaption write FFindCaption;
    property FindWhat: String read FFindWhat write FFindWhat;
    property CaseSensitive: String read FCaseSensitive write FCaseSensitive;
    property Expression: String read FExpression write FExpression;
    property CloseIfFound: String read FCloseIfFound write FCloseIfFound;
    property WholeWordOnly: String read FWholeWordOnly write FWholeWordOnly;
    property WrapAtEndOfFile: String read FWrapAtEndOfFile write FWrapAtEndOfFile;
    property ContinueToNextFile: String read FContinueToNextFile write FContinueToNextFile;
    property Find: String read FFind write FFind;
    property Previous: String read FPrevious write FPrevious;
    property SetMarker: String read FSetMarker write FSetMarker;
    property Close: String read FClose write FClose;
    property More: String read FMore write FMore;
    property Less: String read FLess write FLess;
    property Direction: String read FDirection write FDirection;
    property Up: String read FUp write FUp;
    property Down: String read FDown write FDown;
    property Selection: String read FSelection write FSelection;
  end;

  TTMSFMXFindDialogForm = class;

  [ComponentPlatformsAttribute(TMSPlatforms)]
  TTMSFMXFindDialog = class(TComponent)
  private
    FFindText: String;
    FOnFind: TNotifyEvent;
    FOnSetMarker: TNotifyEvent;
    FOnFindPrevious: TNotifyEvent;
    FOnClose: TNotifyEvent;
    FOptions: TTMSFMXFindDialogOptions;
    FFindList: TStringList;
    FUILanguage: TFindUILanguage;
    FVisibleOptions: TTMSFMXFindDialogVisibleOptions;
    FOnFindEditChange: TFindEditChangeEvent;
    FAutoHistory: boolean;
    Frm: TTMSFMXFindDialogForm;
    procedure SetUILanguage(const Value: TFindUILanguage);
  protected
    procedure DoClose(Sender: TObject);
    procedure DoFind(Sender: TObject);
    procedure DoFindPrevious(Sender: TObject);
    procedure DoSetMarker(Sender: TObject);
    procedure DoFindEditChange(Sender: TObject; var AText: string);
    function CreateDialogForm(AOwner: TComponent): TTMSFMXFindDialogForm; virtual;
    function InitDialog: TCustomForm; virtual;
  public
    procedure Execute; virtual;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Assign(Source: TPersistent); override;
    property Form: TTMSFMXFindDialogForm read Frm;
    procedure Close;
  published
    property AutoHistory: boolean read FAutoHistory write FAutoHistory default true;
    property FindText: String read FFindText write FFindText;
    property FindList: TStringList read FFindList write FFindList;
    property OnFindEditChange: TFindEditChangeEvent read FOnFindEditChange write FOnFindEditChange;
    property OnFind: TNotifyEvent read FOnFind write FOnFind;
    property OnClose: TNotifyEvent read FOnClose write FOnClose;
    property OnFindPrevious: TNotifyEvent read FOnFindPrevious write FOnFindPrevious;
    property OnSetMarker: TNotifyEvent read FOnSetMarker write FOnSetMarker;
    property Options: TTMSFMXFindDialogOptions read FOptions write FOptions default DefaultFindOptions;
    property VisibleOptions: TTMSFMXFindDialogVisibleOptions read FVisibleOptions write FVisibleOptions default DefaultVisibleFindOptions;
    property UILanguage: TFindUILanguage read FUILanguage write SetUILanguage;
  end;


  TTMSFMXFindDialogForm = class(TForm)
    Label1: TLabel;
    ComboBox1: TComboEdit;
    SpeedButton1: TSpeedButton;
    PopupMenu1: TPopupMenu;
    abCharacter1: TMenuItem;
    NewLine1: TMenuItem;
    AnyCharacter1: TMenuItem;
    CharacterinRange1: TMenuItem;
    CharacternotinRange1: TMenuItem;
    BeginningofLine1: TMenuItem;
    EndofLine1: TMenuItem;
    aggedExpression1: TMenuItem;
    Or1: TMenuItem;
    N0or1matches1: TMenuItem;
    N1orMoreMatches1: TMenuItem;
    N0or1Matches2: TMenuItem;
    N1: TMenuItem;
    FindBtn: TButton;
    PrevBtn: TButton;
    Marker: TButton;
    CloseBtn: TButton;
    MoreBtn: TButton;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    CheckBox4: TCheckBox;
    CheckBox5: TCheckBox;
    CheckBox6: TCheckBox;
    Label2: TLabel;
    Memo1: TMemo;
    DirGroup: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    SelCheck: TCheckBox;
    procedure abCharacter1Click(Sender: TObject);
    procedure NewLine1Click(Sender: TObject);
    procedure AnyCharacter1Click(Sender: TObject);
    procedure CharacterinRange1Click(Sender: TObject);
    procedure CharacternotinRange1Click(Sender: TObject);
    procedure BeginningofLine1Click(Sender: TObject);
    procedure EndofLine1Click(Sender: TObject);
    procedure aggedExpression1Click(Sender: TObject);
    procedure Or1Click(Sender: TObject);
    procedure N0or1matches1Click(Sender: TObject);
    procedure N1orMoreMatches1Click(Sender: TObject);
    procedure N0or1Matches2Click(Sender: TObject);
    procedure CloseBtnClick(Sender: TObject);
    procedure FindBtnClick(Sender: TObject);
    procedure PrevBtnClick(Sender: TObject);
    procedure MarkerClick(Sender: TObject);
    procedure MoreBtnClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox3Click(Sender: TObject);
    procedure CheckBox4Click(Sender: TObject);
    procedure CheckBox5Click(Sender: TObject);
    procedure CheckBox6Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure DirGroupClick(Sender: TObject);
    procedure Memo1Change(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SelCheckChange(Sender: TObject);
  private
    { Private declarations }
    FOnFind: TNotifyEvent;
    FOnSetMarker: TNotifyEvent;
    FOnFindPrevious: TNotifyEvent;
    FOnClose: TNotifyEvent;
    FOnFindEditChange: TFindEditChangeEvent;
    FDialog: TTMSFMXFindDialog;
    function GetFindText: String;
    procedure SetFindText(const Value: String);
  protected
    { Protected declarations }
    procedure DoFindEditChange(var AText: string); virtual;
    procedure EnableButtons; virtual;
    procedure UpdateMoreButton(const AValue: string); virtual;
  public
    { Public declarations }
    property Dialog: TTMSFMXFindDialog read FDialog write FDialog;
    property OnFindEditChange: TFindEditChangeEvent read FOnFindEditChange write FOnFindEditChange;
    property OnFind: TNotifyEvent read FOnFind write FOnFind;
    property OnClose: TNotifyEvent read FOnClose write FOnClose;
    property OnFindPrevious: TNotifyEvent read FOnFindPrevious write FOnFindPrevious;
    property OnSetMarker: TNotifyEvent read FOnSetMarker write FOnSetMarker;
    property FindText: String read GetFindText write SetFindText;
  end;

var
  TMSFMXFindDialogForm: TTMSFMXFindDialogForm;
  More: Boolean;

implementation

{$R *.fmx}



procedure TTMSFMXFindDialog.Assign(Source: TPersistent);
begin
  if (Source is TTMSFMXFindDialog) then
  begin
    Options := (Source as TTMSFMXFindDialog).Options;
    VisibleOptions := (Source as TTMSFMXFindDialog).VisibleOptions;
    UILanguage.Assign((Source as TTMSFMXFindDialog).UILanguage);
    AutoHistory := (Source as TTMSFMXFindDialog).AutoHistory;
    FindText := (Source as TTMSFMXFindDialog).FindText;
    FindList.Assign((Source as TTMSFMXFindDialog).FindList);
  end;
end;



procedure TTMSFMXFindDialog.Close;
begin
  Form.Close;
end;

constructor TTMSFMXFindDialog.Create(AOwner: TComponent);
begin
  inherited;
  FUILanguage := TFindUILanguage.Create(Self);
  FOptions := DefaultFindOptions;
  FVisibleOptions := DefaultVisibleFindOptions;
  FFindList := TStringList.Create;
  FAutoHistory := True;
end;



destructor TTMSFMXFindDialog.Destroy;
begin
  FUILanguage.Destroy;
  FFindList.Free;
  inherited;
end;



procedure TTMSFMXFindDialog.DoClose(Sender: TObject);
begin
  if FAutoHistory then
  begin
    if FFindList.IndexOf(FindText) = -1 then
      FFindList.Add(FindText);
  end;

  if Assigned(OnClose) then
    OnClose(Self);
end;



procedure TTMSFMXFindDialog.DoFind(Sender: TObject);
begin
  if Assigned(OnFind) then
    OnFind(Self);
end;



procedure TTMSFMXFindDialog.DoFindEditChange(Sender: TObject; var AText: string);
begin
  if Assigned(FOnFindEditChange) then
    FOnFindEditChange(Self, AText);
end;



procedure TTMSFMXFindDialog.DoFindPrevious(Sender: TObject);
begin
  if Assigned(OnFindPrevious) then
    OnFindPrevious(Self);
end;



procedure TTMSFMXFindDialog.DoSetMarker(Sender: TObject);
begin
  if Assigned(OnSetMarker) then
    OnSetMarker(Self);
end;


function TTMSFMXFindDialog.CreateDialogForm(AOwner: TComponent): TTMSFMXFindDialogForm;
begin
  Result := TTMSFMXFindDialogForm.Create(AOwner);
end;


function TTMSFMXFindDialog.InitDialog: TCustomForm;
begin
  frm := CreateDialogForm(Self);
  frm.Dialog := Self;
  frm.FindText := FindText;
  frm.OnClose := DoClose;
  frm.OnFind := DoFind;
  frm.OnFindPrevious := DoFindPrevious;
  frm.OnSetMarker := DoSetMarker;
  frm.OnFindEditChange := DoFindEditChange;

  frm.CheckBox1.IsChecked := fdoCaseSensitive in Options;
  frm.CheckBox2.IsChecked := fdoExpression in Options;
  frm.CheckBox3.IsChecked := fdoCloseIfFound in Options;
  frm.CheckBox4.IsChecked := fdoWholeWordOnly in Options;
  frm.CheckBox5.IsChecked := fdoWrapAtEndOfFile in Options;
  frm.CheckBox6.IsChecked := fdoContinueToNextFile in Options;
  frm.SelCheck.IsChecked := fdoSelection in Options;

  frm.FindBtn.Enabled := fdoFindEnabled in Options;
  frm.PrevBtn.Enabled := fdoPreviousEnabled in Options;
  frm.Marker.Enabled := fdoSetMarkerEnabled in Options;
  frm.CloseBtn.Enabled := fdoCloseEnabled in Options;
  frm.MoreBtn.Enabled := fdoMoreEnabled in Options;

  frm.CheckBox1.Visible := fdovCaseSensitive in VisibleOptions;
  frm.CheckBox2.Visible := fdovExpression in VisibleOptions;
  frm.CheckBox3.Visible := fdovCloseIfFound in VisibleOptions;
  frm.CheckBox4.Visible := fdovWholeWordOnly in VisibleOptions;
  frm.CheckBox5.Visible := fdovWrapAtEndOfFile in VisibleOptions;
  frm.CheckBox6.Visible := fdovContinueToNextFile in VisibleOptions;
  frm.SelCheck.Visible := fdovSelection in VisibleOptions;
  frm.FindBtn.Visible := fdovFind in VisibleOptions;
  frm.PrevBtn.Visible := fdovPrevious in VisibleOptions;
  frm.Marker.Visible := fdovSetMarker in VisibleOptions;
  frm.CloseBtn.Visible := fdovClose in VisibleOptions;
  frm.MoreBtn.Visible := fdovMore in VisibleOptions;

  frm.CheckBox1.Text := UILanguage.CaseSensitive;
  frm.CheckBox2.Text := UILanguage.Expression;
  frm.CheckBox3.Text := UILanguage.CloseIfFound;
  frm.CheckBox4.Text := UILanguage.WholeWordOnly;
  frm.CheckBox5.Text := UILanguage.WrapAtEndOfFile;
  frm.CheckBox6.Text := UILanguage.ContinueToNextFile;
  frm.SelCheck.Text := UILanguage.Selection;
  frm.FindBtn.Text := UILanguage.Find;
  frm.PrevBtn.Text := UILanguage.Previous;
  frm.Marker.Text := UILanguage.SetMarker;
  frm.CloseBtn.Text := UILanguage.Close;
  frm.MoreBtn.Text := UILanguage.More;

  frm.Label1.Text := UILanguage.FindWhat;
  frm.Label2.Text := UILanguage.FindWhat;

  (frm.DirGroup.Children[0] as TRadioButton).OnChange := frm.DirGroupClick;
  (frm.DirGroup.Children[1] as TRadioButton).OnChange := frm.DirGroupClick;

  frm.DirGroup.Text := UILanguage.Direction;
  frm.RadioButton1.Text := UILanguage.Down;
  frm.RadioButton2.Text := UILanguage.Up;

  if fdoFindList in Options then
    frm.ComboBox1.Typing := False;

  frm.ComboBox1.Items.Assign(FindList);

  frm.ComboBox1.Visible := fdovFindCombo in VisibleOptions;
  frm.Memo1.Visible := fdovFindMemo in VisibleOptions;
  frm.DirGroup.Visible := fdovDirection in VisibleOptions;

  if (fdoDown in Options) then
    frm.RadioButton1.IsChecked := True
  else
    frm.RadioButton2.IsChecked := True;

  if frm.DirGroup.Visible then
    frm.Height := 210
  else
    frm.Height := 157;

  frm.Caption := UILanguage.FindCaption;

  if not frm.DirGroup.Visible then
  begin
    frm.memo1.Position.Y := frm.memo1.Position.Y - 54;
    frm.Label2.Position.Y := frm.Label2.Position.Y - 54;
  end;


  if (fdoMoreExpanded in Options) then
  begin
    if not More then
      frm.MoreBtnClick(Self);
  end
  else
  begin
    if More then
      frm.MoreBtnClick(Self);
  end;

  Result := frm;
end;


procedure TTMSFMXFindDialog.Execute;
var
  frm: TTMSFMXFindDialogForm;
begin
  frm := InitDialog as TTMSFMXFindDialogForm;
  frm.EnableButtons;
  try
    frm.ShowModal;
  finally
    frm.Free;
  end;
end;

procedure TTMSFMXFindDialog.SetUILanguage(const Value: TFindUILanguage);
begin
  if FUILanguage <> Value then
    FUILanguage.Assign(Value);
end;


{ TFindUILanguage }

procedure TFindUILanguage.Assign(Source: TPersistent);
begin
  if (Source is TFindUILanguage) then
  begin
    FFindCaption := (Source as TFindUILanguage).FindCaption;
    FFindWhat :=  (Source as TFindUILanguage).FindWhat;
    FCaseSensitive := (Source as TFindUILanguage).CaseSensitive;
    FExpression := (Source as TFindUILanguage).Expression;
    FCloseIfFound := (Source as TFindUILanguage).CloseIfFound;
    FWholeWordOnly := (Source as TFindUILanguage).WholeWordOnly;
    FWrapAtEndOfFile := (Source as TFindUILanguage).WrapAtEndOfFile;
    FContinueToNextFile := (Source as TFindUILanguage).ContinueToNextFile;
    FFind := (Source as TFindUILanguage).Find;
    FPrevious := (Source as TFindUILanguage).Previous;
    FSetMarker := (Source as TFindUILanguage).SetMarker;
    FClose := (Source as TFindUILanguage).Close;
    FMore := (Source as TFindUILanguage).More;
    FLess := (Source as TFindUILanguage).Less;
    FDirection := (Source as TFindUILanguage).Direction;
    FUp := (Source as TFindUILanguage).Up;
    FDown := (Source as TFindUILanguage).Down;
    FSelection := (Source as TFindUILanguage).Selection;
  end;
end;



constructor TFindUILanguage.Create(AOwner: TComponent);
begin
  inherited Create;
  if(csDesigning in AOwner.ComponentState) and not
    ((csReading in AOwner.ComponentState) or (csLoading in AOwner.ComponentState)) then
  begin
    Init;
  end;
end;

procedure TFindUILanguage.Init;
begin
  FFindCaption := 'Find';
  FCloseIfFound := 'Close if Found';
  FCaseSensitive := 'Case sensitive';
  FExpression := 'Expression';
  FWholeWordOnly := 'Whole word Only';
  FWrapAtEndOfFile := 'Wrap at the end of file';
  FContinueToNextFile := 'Continue to next file';
  FFind := 'Find';
  FFindWhat := 'Find what:';
  FSetMarker := 'Set Marker';
  FPrevious := 'Previous';
  FClose := 'Close';
  FMore := 'More';
  FLess := 'Less';
  FDirection := 'Direction';
  FUp := 'Up';
  FDown := 'Down';
  FSelection := 'Selection';
end;

procedure TTMSFMXFindDialogForm.abCharacter1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '\t';
end;



procedure TTMSFMXFindDialogForm.aggedExpression1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '()';
end;



procedure TTMSFMXFindDialogForm.AnyCharacter1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '.';
end;



procedure TTMSFMXFindDialogForm.BeginningofLine1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '^';
end;



procedure TTMSFMXFindDialogForm.FindBtnClick(Sender: TObject);
begin
  if Assigned(OnFind) then
    OnFind(Self);

  if CheckBox3.IsChecked then
    Close;
end;



procedure TTMSFMXFindDialogForm.PrevBtnClick(Sender: TObject);
begin
  if Assigned(OnFindPrevious) then
    OnFindPrevious(Self);
end;



procedure TTMSFMXFindDialogForm.MarkerClick(Sender: TObject);
begin
  if Assigned(OnSetMarker) then
    OnSetMarker(Self);
end;



procedure TTMSFMXFindDialogForm.Memo1Change(Sender: TObject);
var
  s: string;
  i: integer;
begin
  s := '';
  for i := 0 to Memo1.Lines.Count - 1 do
  begin
    if i > 0 then
      s := s + #13#10 + Memo1.Lines[i]
    else
      s := Memo1.Lines[i];
  end;

  DoFindEditChange(s);
  Dialog.FindText := s;
  EnableButtons;
end;



procedure TTMSFMXFindDialogForm.CloseBtnClick(Sender: TObject);
begin
  Close;
end;



procedure TTMSFMXFindDialogForm.UpdateMoreButton(const AValue: string);
begin
  MoreBtn.Text := AValue;
end;



procedure TTMSFMXFindDialogForm.MoreBtnClick(Sender: TObject);
var
  heightopen, heightclosed: integer;
begin
  if DirGroup.Visible then
  begin
    heightopen := 315;
    heightclosed := 200;
  end
  else
  begin
    heightopen := 258;
    heightclosed := 147;
  end;

  if not More then
  begin
    UpdateMoreButton(Dialog.UILanguage.Less);
    Dialog.Options := Dialog.Options + [fdoMoreExpanded];
    Height := heightopen;
  end
  else
  begin
    UpdateMoreButton(Dialog.UILanguage.More);
    Dialog.Options := Dialog.Options - [fdoMoreExpanded];
    Height := heightclosed;
  end;

  Label1.Enabled := More;
  ComboBox1.Enabled := More;
  More := not More;
end;



procedure TTMSFMXFindDialogForm.CharacterinRange1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '[]';
end;



procedure TTMSFMXFindDialogForm.CharacternotinRange1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '[^]';
end;



procedure TTMSFMXFindDialogForm.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.IsChecked then
    Dialog.Options := Dialog.Options + [fdoCaseSensitive]
  else
    Dialog.Options := Dialog.Options - [fdoCaseSensitive];
end;



procedure TTMSFMXFindDialogForm.CheckBox2Click(Sender: TObject);
begin
  if CheckBox2.IsChecked then
    Dialog.Options := Dialog.Options + [fdoExpression]
  else
    Dialog.Options := Dialog.Options - [fdoExpression];
end;



procedure TTMSFMXFindDialogForm.CheckBox3Click(Sender: TObject);
begin
  if CheckBox3.IsChecked then
    Dialog.Options := Dialog.Options + [fdoCloseIfFound]
  else
    Dialog.Options := Dialog.Options - [fdoCloseIfFound];
end;



procedure TTMSFMXFindDialogForm.CheckBox4Click(Sender: TObject);
begin
  if CheckBox4.IsChecked then
    Dialog.Options := Dialog.Options + [fdoWholeWordOnly]
  else
    Dialog.Options := Dialog.Options - [fdoWholeWordOnly];
end;



procedure TTMSFMXFindDialogForm.CheckBox5Click(Sender: TObject);
begin
  if CheckBox5.IsChecked then
    Dialog.Options := Dialog.Options + [fdoWrapAtEndOfFile]
  else
    Dialog.Options := Dialog.Options - [fdoWrapAtEndOfFile];
end;



procedure TTMSFMXFindDialogForm.CheckBox6Click(Sender: TObject);
begin
  if CheckBox6.IsChecked then
    Dialog.Options := Dialog.Options + [fdoContinueToNextFile]
  else
    Dialog.Options := Dialog.Options - [fdoContinueToNextFile];
end;



procedure TTMSFMXFindDialogForm.ComboBox1Change(Sender: TObject);
var
  s: string;
begin
  s := ComboBox1.Text;
  DoFindEditChange(s);
  Dialog.FindText := s;
  EnableButtons;
end;

procedure TTMSFMXFindDialogForm.EnableButtons;
begin
  FindBtn.Enabled := (Dialog.FindText <> '') and (fdoFindEnabled in Dialog.Options);
  PrevBtn.Enabled := (Dialog.FindText <> '') and (fdoPreviousEnabled in Dialog.Options);
  Marker.Enabled := (Dialog.FindText <> '') and (fdoSetMarkerEnabled in Dialog.Options);
end;

procedure TTMSFMXFindDialogForm.DirGroupClick(Sender: TObject);
begin
  if RadioButton1.IsChecked then
    Dialog.Options := Dialog.Options + [fdoDown]
  else
    Dialog.Options := Dialog.Options - [fdoDown];
end;


procedure TTMSFMXFindDialogForm.DoFindEditChange(var AText: string);
begin
  if Assigned(FOnFindEditChange) then
    FOnFindEditChange(Self, AText);
end;



procedure TTMSFMXFindDialogForm.EndofLine1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '$';
end;

procedure TTMSFMXFindDialogForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  if Assigned(OnClose) then
    OnClose(Self);
end;

procedure TTMSFMXFindDialogForm.FormCreate(Sender: TObject);
begin
  More := False;
  ComboBox1.TabOrder := 0;
  FindBtn.TabOrder := 1;
  CheckBox1.TabOrder := 3;
  CheckBox4.TabOrder := 4;
  PrevBtn.TabOrder := 5;
  CheckBox2.TabOrder := 6;
  CheckBox5.TabOrder := 7;
  Marker.TabOrder := 8;
  CheckBox3.TabOrder := 9;
  CheckBox6.TabOrder := 10;
  MoreBtn.TabOrder := 11;
  CloseBtn.TabOrder := 12;
  SelCheck.TabOrder := 13;

  RadioButton1.TabOrder := 14;
  RadioButton2.TabOrder := 15;

  Memo1.TabOrder := 16;
end;

function TTMSFMXFindDialogForm.GetFindText: String;
var
  i: integer;
begin
  if not More then
    Result := ComboBox1.Text
  else
  begin
    Result := '';
    for i := 0 to Memo1.Lines.Count - 1 do
    begin
      if i > 0 then
        Result := Result + #13#10 + Memo1.Lines[i]
      else
       Result := Memo1.Lines[i];
    end;
  end;
end;



procedure TTMSFMXFindDialogForm.N0or1matches1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '*';
end;



procedure TTMSFMXFindDialogForm.N0or1Matches2Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '?';
end;



procedure TTMSFMXFindDialogForm.N1orMoreMatches1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '+';
end;



procedure TTMSFMXFindDialogForm.NewLine1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '\n';
end;



procedure TTMSFMXFindDialogForm.Or1Click(Sender: TObject);
begin
  ComboBox1.Text := ComboBox1.Text + '|';
end;



procedure TTMSFMXFindDialogForm.SelCheckChange(Sender: TObject);
begin
  if SelCheck.IsChecked then
    Dialog.Options := Dialog.Options + [fdoSelection]
  else
    Dialog.Options := Dialog.Options - [fdoSelection];
end;

procedure TTMSFMXFindDialogForm.SetFindText(const Value: String);
begin
  if not More then
    ComboBox1.Text := Value
  else
    Memo1.Text := Value;
end;



end.
