You've already forked lazarus-ccr
richmemo: updating search method to return the length of the found text (for cases, where found text could be different than a searched one. I.e. Hebrew or Arabic scripts)
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5115 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -250,7 +250,8 @@ type
|
|||||||
|
|
||||||
procedure SetSelLengthFor(const aselstr: string);
|
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;
|
function Print(const params: TPrintParams): Integer;
|
||||||
|
|
||||||
@ -1050,6 +1051,15 @@ end;
|
|||||||
|
|
||||||
function TCustomRichMemo.Search(const ANiddle: string; Start, Len: Integer;
|
function TCustomRichMemo.Search(const ANiddle: string; Start, Len: Integer;
|
||||||
const SearchOpt: TSearchOptions): 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
|
var
|
||||||
so : TIntSearchOpt;
|
so : TIntSearchOpt;
|
||||||
begin
|
begin
|
||||||
@ -1058,9 +1068,17 @@ begin
|
|||||||
so.len:=Len;
|
so.len:=Len;
|
||||||
so.start:=Start;
|
so.start:=Start;
|
||||||
so.options:=SearchOpt;
|
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
|
end else
|
||||||
Result:=-1;
|
Result:=false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomRichMemo.Print(const params: TPrintParams): Integer;
|
function TCustomRichMemo.Print(const params: TPrintParams): Integer;
|
||||||
|
@ -122,6 +122,9 @@ type
|
|||||||
|
|
||||||
class function Search(const AWinControl: TWinControl; const ANiddle: string;
|
class function Search(const AWinControl: TWinControl; const ANiddle: string;
|
||||||
const SearchOpts: TIntSearchOpt): Integer; override;
|
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;
|
class procedure SetZoomFactor(const AWinControl: TWinControl; AZoomFactor: Double); override;
|
||||||
|
|
||||||
@ -166,7 +169,7 @@ var
|
|||||||
NCPaint : TNCPaintProc = nil;
|
NCPaint : TNCPaintProc = nil;
|
||||||
|
|
||||||
function GetSelRTF(amemo: TCustomRichMemo): string;
|
function GetSelRTF(amemo: TCustomRichMemo): string;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -1113,6 +1116,19 @@ begin
|
|||||||
Result:=RichEditManager.Find(AWinControl.Handle, UTF8Decode(ANiddle), SearchOpts);
|
Result:=RichEditManager.Find(AWinControl.Handle, UTF8Decode(ANiddle), SearchOpts);
|
||||||
end;
|
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(
|
class procedure TWin32WSCustomRichMemo.SetZoomFactor(
|
||||||
const AWinControl: TWinControl; AZoomFactor: Double);
|
const AWinControl: TWinControl; AZoomFactor: Double);
|
||||||
var
|
var
|
||||||
|
@ -184,7 +184,9 @@ type
|
|||||||
|
|
||||||
class procedure GetPara2(RichEditWnd: Handle; TextStart: Integer; var para: PARAFORMAT2); virtual;
|
class procedure GetPara2(RichEditWnd: Handle; TextStart: Integer; var para: PARAFORMAT2); virtual;
|
||||||
class procedure SetPara2(RichEditWnd: Handle; TextStart, TextLen: Integer; const 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;
|
class procedure GetParaRange(RichEditWnd: Handle; TextStart: integer; var para: TParaRange); virtual;
|
||||||
end;
|
end;
|
||||||
TRichManagerClass = class of TRichEditManager;
|
TRichManagerClass = class of TRichEditManager;
|
||||||
@ -823,11 +825,18 @@ begin
|
|||||||
SetSelection(RichEditWnd, s, l);
|
SetSelection(RichEditWnd, s, l);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TRichEditManager.Find(RichEditWnd: THandle;
|
class function TRichEditManager.Find(RichEditWnd: THandle; const ANiddle: WideString; const ASearch: TIntSearchOpt): Integer; overload;
|
||||||
const ANiddle: WideString; const ASearch: TIntSearchOpt): Integer;
|
|
||||||
var
|
var
|
||||||
fw: TFINDTEXTW;
|
l : integer;
|
||||||
fa: TFINDTEXTA;
|
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;
|
opt: WParam;
|
||||||
txt: string;
|
txt: string;
|
||||||
mn, mx : Integer;
|
mn, mx : Integer;
|
||||||
@ -859,13 +868,15 @@ begin
|
|||||||
fw.chrg.cpMin := mn;
|
fw.chrg.cpMin := mn;
|
||||||
fw.chrg.cpMax := mx;
|
fw.chrg.cpMax := mx;
|
||||||
fw.lpstrText := PWideChar(@ANiddle[1]);
|
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
|
end else begin
|
||||||
fa.chrg.cpMin := mn;
|
fa.chrg.cpMin := mn;
|
||||||
fa.chrg.cpMax := mx;
|
fa.chrg.cpMax := mx;
|
||||||
txt:=ANiddle;
|
txt:=ANiddle;
|
||||||
fa.lpstrText := PAnsiChar(@txt[1]);
|
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;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -101,6 +101,9 @@ type
|
|||||||
class function SaveRichText(const AWinControl: TWinControl; Dest: TStream): Boolean; virtual;
|
class function SaveRichText(const AWinControl: TWinControl; Dest: TStream): Boolean; virtual;
|
||||||
|
|
||||||
class function Search(const AWinControl: TWinControl; const ANiddle: string; const SearchOpts: TIntSearchOpt): Integer; 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;
|
class procedure SetZoomFactor(const AWinControl: TWinControl; AZoomFactor: Double); virtual;
|
||||||
|
|
||||||
@ -358,6 +361,18 @@ begin
|
|||||||
Result:=-1;
|
Result:=-1;
|
||||||
end;
|
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;
|
class procedure TWSCustomRichMemo.SetZoomFactor(const AWinControl: TWinControl;
|
||||||
AZoomFactor: Double);
|
AZoomFactor: Double);
|
||||||
begin
|
begin
|
||||||
|
Reference in New Issue
Block a user