diff --git a/components/richmemo/richmemo.pas b/components/richmemo/richmemo.pas index b2932873b..dccfabbf1 100644 --- a/components/richmemo/richmemo.pas +++ b/components/richmemo/richmemo.pas @@ -250,7 +250,8 @@ type procedure SetSelLengthFor(const aselstr: string); - function Search(const ANiddle: string; Start, Len: Integer; const SearchOpt: TSearchOptions): Integer; + function Search(const ANiddle: string; Start, Len: Integer; const SearchOpt: TSearchOptions): Integer; overload; + function Search(const ANiddle: string; Start, Len: Integer; const SearchOpt: TSearchOptions; var ATextStart, ATextLength: Integer): Boolean; overload; function Print(const params: TPrintParams): Integer; @@ -1050,6 +1051,15 @@ end; function TCustomRichMemo.Search(const ANiddle: string; Start, Len: Integer; const SearchOpt: TSearchOptions): Integer; +var + ln : Integer; +begin + ln := 0; + if not Search(ANiddle, Start, Len, SearchOpt, Result, ln) then Result:=-1; +end; + +function TCustomRichMemo.Search(const ANiddle: string; Start, Len: Integer; const SearchOpt: TSearchOptions; + var ATextStart, ATextLength: Integer): Boolean; overload; var so : TIntSearchOpt; begin @@ -1058,9 +1068,17 @@ begin so.len:=Len; so.start:=Start; so.options:=SearchOpt; - Result:=TWSCustomRichMemoClass(WidgetSetClass).Search(Self, ANiddle, so); + if not TWSCustomRichMemoClass(WidgetSetClass).isSearchEx then begin + ATextStart:=TWSCustomRichMemoClass(WidgetSetClass).Search(Self, ANiddle, so); + // not recommended. The text found coulbe longer than Niddle + // depending on the language and search options (to be done) + // mostly for Arabi and Hebrew languages + ATextLength:=UTF8Length(ANiddle); + end else begin + Result:=TWSCustomRichMemoClass(WidgetSetClass).SearchEx(Self, ANiddle, so, ATextStart, ATextLength); + end; end else - Result:=-1; + Result:=false; end; function TCustomRichMemo.Print(const params: TPrintParams): Integer; diff --git a/components/richmemo/win32/win32richmemo.pas b/components/richmemo/win32/win32richmemo.pas index 94e90b3e7..cf9dab4a1 100644 --- a/components/richmemo/win32/win32richmemo.pas +++ b/components/richmemo/win32/win32richmemo.pas @@ -122,6 +122,9 @@ type class function Search(const AWinControl: TWinControl; const ANiddle: string; const SearchOpts: TIntSearchOpt): Integer; override; + class function isSearchEx: Boolean; override; + class function SearchEx(const AWinControl: TWinControl; const ANiddle: string; + const SearchOpts: TIntSearchOpt; var ATextStart, ATextLength: Integer ): Boolean; override; class procedure SetZoomFactor(const AWinControl: TWinControl; AZoomFactor: Double); override; @@ -166,7 +169,7 @@ var NCPaint : TNCPaintProc = nil; function GetSelRTF(amemo: TCustomRichMemo): string; - + implementation type @@ -1113,6 +1116,19 @@ begin Result:=RichEditManager.Find(AWinControl.Handle, UTF8Decode(ANiddle), SearchOpts); end; +class function TWin32WSCustomRichMemo.isSearchEx: Boolean; +begin + Result:=true; +end; + +class function TWin32WSCustomRichMemo.SearchEx(const AWinControl: TWinControl; + const ANiddle: string; const SearchOpts: TIntSearchOpt; var ATextStart, + ATextLength: Integer): Boolean; +begin + ATextStart:=RichEditManager.Find(AWinControl.Handle, UTF8Decode(ANiddle), SearchOpts, ATextLength); + Result:=ATextStart>=0; +end; + class procedure TWin32WSCustomRichMemo.SetZoomFactor( const AWinControl: TWinControl; AZoomFactor: Double); var diff --git a/components/richmemo/win32/win32richmemoproc.pas b/components/richmemo/win32/win32richmemoproc.pas index 72e14d838..cf5663c4e 100644 --- a/components/richmemo/win32/win32richmemoproc.pas +++ b/components/richmemo/win32/win32richmemoproc.pas @@ -184,7 +184,9 @@ type class procedure GetPara2(RichEditWnd: Handle; TextStart: Integer; var para: PARAFORMAT2); virtual; class procedure SetPara2(RichEditWnd: Handle; TextStart, TextLen: Integer; const para: PARAFORMAT2); virtual; - class function Find(RichEditWnd: THandle; const ANiddle: WideString; const ASearch: TIntSearchOpt): Integer; virtual; + // the ugly Find() overload, might go away eventually + class function Find(RichEditWnd: THandle; const ANiddle: WideString; const ASearch: TIntSearchOpt; var TextLen: Integer): Integer; virtual; overload; + class function Find(RichEditWnd: THandle; const ANiddle: WideString; const ASearch: TIntSearchOpt): Integer; overload; class procedure GetParaRange(RichEditWnd: Handle; TextStart: integer; var para: TParaRange); virtual; end; TRichManagerClass = class of TRichEditManager; @@ -823,11 +825,18 @@ begin SetSelection(RichEditWnd, s, l); end; -class function TRichEditManager.Find(RichEditWnd: THandle; - const ANiddle: WideString; const ASearch: TIntSearchOpt): Integer; +class function TRichEditManager.Find(RichEditWnd: THandle; const ANiddle: WideString; const ASearch: TIntSearchOpt): Integer; overload; var - fw: TFINDTEXTW; - fa: TFINDTEXTA; + l : integer; +begin + Result:=Find(RichEDitWnd, ANiddle, ASearch, l); +end; + +class function TRichEditManager.Find(RichEditWnd: THandle; + const ANiddle: WideString; const ASearch: TIntSearchOpt; var TextLen: Integer): Integer; +var + fw: TFINDTEXTEXW; + fa: TFINDTEXTEXA; opt: WParam; txt: string; mn, mx : Integer; @@ -859,13 +868,15 @@ begin fw.chrg.cpMin := mn; fw.chrg.cpMax := mx; fw.lpstrText := PWideChar(@ANiddle[1]); - Result := SendMessage(RichEditWnd, EM_FINDTEXTW, opt, LParam(@fw)); + Result := SendMessage(RichEditWnd, EM_FINDTEXTEXW, opt, LParam(@fw)); + if Result>=0 then TextLen:=fw.chrgText.cpMax-fw.chrgText.cpMin; end else begin fa.chrg.cpMin := mn; fa.chrg.cpMax := mx; txt:=ANiddle; fa.lpstrText := PAnsiChar(@txt[1]); - Result := SendMessage(RichEditWnd, EM_FINDTEXT, opt, LParam(@fa)); + Result := SendMessage(RichEditWnd, EM_FINDTEXTEX, opt, LParam(@fa)); + if Result>=0 then TextLen:=fa.chrgText.cpMax-fa.chrgText.cpMin; end; end; diff --git a/components/richmemo/wsrichmemo.pas b/components/richmemo/wsrichmemo.pas index 59003f4e7..10b8150b9 100644 --- a/components/richmemo/wsrichmemo.pas +++ b/components/richmemo/wsrichmemo.pas @@ -101,6 +101,9 @@ type class function SaveRichText(const AWinControl: TWinControl; Dest: TStream): Boolean; virtual; class function Search(const AWinControl: TWinControl; const ANiddle: string; const SearchOpts: TIntSearchOpt): Integer; virtual; + // this is a temproray solution and will be removed eventually leaving a variant of SearchEx only + class function isSearchEx: Boolean; virtual; + class function SearchEx(const AWinControl: TWinControl; const ANiddle: string; const SearchOpts: TIntSearchOpt; var TextStart, TextLength: Integer): Boolean; virtual; class procedure SetZoomFactor(const AWinControl: TWinControl; AZoomFactor: Double); virtual; @@ -358,6 +361,18 @@ begin Result:=-1; end; +class function TWSCustomRichMemo.isSearchEx: Boolean; +begin + Result:=false; +end; + +class function TWSCustomRichMemo.SearchEx(const AWinControl: TWinControl; + const ANiddle: string; const SearchOpts: TIntSearchOpt; var TextStart, + TextLength: Integer): Boolean; +begin + Result:=false; +end; + class procedure TWSCustomRichMemo.SetZoomFactor(const AWinControl: TWinControl; AZoomFactor: Double); begin