richmemo: cocoa adding GetStyleRange, patch by David. #34559

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7014 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
skalogryz
2019-06-20 13:27:16 +00:00
parent fe98aaa771
commit 939a9b6bbb

View File

@ -29,6 +29,11 @@ type
class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer; class function GetTextAttributes(const AWinControl: TWinControl; TextStart: Integer;
var Params: TIntFontParams): Boolean; override; var Params: TIntFontParams): Boolean; override;
{ Returns True if passed text styles are indentical }
class function FPisEqual(const FP, FPRef : TFontParams) : boolean;
{ Returns with the range (in 0 based bytes) of the style that TextStart is in }
class function GetStyleRange(const AWinControl: TWinControl; TextStart: Integer;
var RangeStart, RangeLen: Integer): Boolean; override;
class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer; class procedure SetTextAttributes(const AWinControl: TWinControl; TextStart, TextLen: Integer;
const Params: TIntFontParams); override; const Params: TIntFontParams); override;
@ -263,6 +268,44 @@ begin
Result:=true; Result:=true;
end; end;
class function TCocoaWSCustomRichMemo.FPisEqual(const FP, FPRef : TFontParams) : boolean;
begin // DRB - an addition function to help GetStyleRange()
Result := false;
if (FP.name = FPRef.name) and (FP.size = FPRef.size) and (FP.style = FPRef.style)
and (FP.bkColor = FPRef.bkcolor) and (FP.HasBkClr = FPRef.HasBkClr)
and (FP.VScriptPos = FPRef.VScriptPos) then
Result := true
end;
class function TCocoaWSCustomRichMemo.GetStyleRange(const AWinControl: TWinControl;
TextStart: Integer; var RangeStart, RangeLen: Integer): Boolean;
var
txt : TCocoaTextView;
TextLength : integer; // all text, in bytes (2 byte line endings)
FPRef, FP : TIntFontParams;
begin // DRB - new method to implement GetStypeRange() on Cocoa.
Result := False;
txt:=MemoTextView(AWinControl);
TextLength := txt.textStorage.string_.length;
if (TextStart < 0) or (TextStart >= TextLength) then exit;
if not GetTextAttributes(AWinControl, TextStart, FPRef) then exit;
RangeStart := TextStart;
repeat
dec(RangeStart);
if RangeStart <= 0 then break;
if not GetTextAttributes(AWinControl, RangeStart, FP) then exit;
until not FPisEqual(FP, FPRef);
inc(RangeStart);
RangeLen := TextStart - RangeStart;
repeat
if RangeStart + RangeLen >= TextLength then break;
inc(RangeLen);
if not GetTextAttributes(AWinControl, RangeStart + RangeLen, FP) then exit;
until not FPisEqual(FP, FPRef);
Result:=true;
end;
function FindFont(const FamilyName: String; astyle: TFontStyles): NSFontDescriptor; function FindFont(const FamilyName: String; astyle: TFontStyles): NSFontDescriptor;
var var
fd : NSFontDescriptor; fd : NSFontDescriptor;