diff --git a/components/richmemo/cocoa/cocoarichmemo.pas b/components/richmemo/cocoa/cocoarichmemo.pas new file mode 100644 index 000000000..d69b00c21 --- /dev/null +++ b/components/richmemo/cocoa/cocoarichmemo.pas @@ -0,0 +1,76 @@ +unit CocoaRichMemo; + +interface + +{$mode delphi} +{$modeswitch objectivec1} +{$modeswitch objectivec2} + +uses + CocoaAll, Types, + LCLType, Controls, StdCtrls, + CocoaPrivate, CocoaUtils, + CocoaWSCommon, CocoaWSStdCtrls, + WSRichMemo; + +type + + { TCocoaWSCustomRichMemo } + + TCocoaWSCustomRichMemo = class(TWSCustomRichMemo) + public + // assumption is made that LCL creates NSTextView + class procedure SetParaAlignment(const AWinControl: TWinControl; TextStart, TextLen: Integer; + const AAlign: TIntParaAlignment); override; + class procedure InDelText(const AWinControl: TWinControl; + const TextUTF8: String; DstStart, DstLen: Integer); override; + end; + +implementation + + +function MemoTextView(AWinControl: TWinControl): TCocoaTextView; +begin + if not Assigned(AWinControl) or (AWinControl.Handle=0) then + Result := nil + else + Result := TCocoaTextView(NSScrollView(AWinControl.Handle).documentView); +end; + +{ TCocoaWSCustomRichMemo } + +class procedure TCocoaWSCustomRichMemo.SetParaAlignment( + const AWinControl: TWinControl; TextStart, TextLen: Integer; + const AAlign: TIntParaAlignment); +var + txt : TCocoaTextView; + rng : NSRange; +const + TxtAlign : array [TIntParaAlignment] of integer = ( + NSLeftTextAlignment, NSRightTextAlignment, NSCenterTextAlignment, NSJustifiedTextAlignment + ); +begin + txt:=MemoTextView(AWinControl); + if not Assigned(txt) then Exit; + + rng.location:=TextStart; + rng.length:=TextLen; + rng:=txt.textStorage.string_.paragraphRangeForRange(rng); + txt.setAlignment_range(TxtAlign[AAlign], rng); +end; + +class procedure TCocoaWSCustomRichMemo.InDelText( + const AWinControl: TWinControl; const TextUTF8: String; DstStart, + DstLen: Integer); +var + txt : TCocoaTextView; + str : NSString; +begin + txt:=MemoTextView(AWinControl); + if not Assigned(txt) then Exit; + str := NSStringUtf8(TextUtf8); + txt.textStorage.replaceCharactersInRange_withString(NSMakeRange(DstStart, DstLen), str); + str.release; +end; + +end. diff --git a/components/richmemo/richmemofactory.pas b/components/richmemo/richmemofactory.pas index 9c9fc3d41..d1ec82868 100644 --- a/components/richmemo/richmemofactory.pas +++ b/components/richmemo/richmemofactory.pas @@ -8,6 +8,7 @@ interface {$ifdef LCLWin32}{$undef NoRichMemo}{$endif} {$ifdef LCLCarbon}{$undef NoRichMemo}{$endif} {$ifdef LCLGtk2}{$undef NoRichMemo}{$endif} +{$ifdef LCLCocoa}{$undef NoRichMemo}{$endif} uses WSLCLClasses, @@ -16,6 +17,7 @@ uses {$ifdef LCLWin32},Win32RichMemo{$endif} {$ifdef LCLCarbon},CarbonRichMemo{$endif} {$ifdef LCLGtk2},RichMemoRTF, Gtk2RichMemo{$endif} + {$ifdef LCLCocoa},CocoaRichMemo{$endif} ; function RegisterCustomRichMemo: Boolean; @@ -28,6 +30,7 @@ begin {$ifdef LCLWin32}RegisterWSComponent(TCustomRichMemo, TWin32WSCustomRichMemo);{$endif} {$ifdef LCLCarbon}RegisterWSComponent(TCustomRichMemo, TCarbonWSCustomRichMemo);{$endif} {$ifdef LCLGtk2}RegisterWSComponent(TCustomRichMemo, TGtk2WSCustomRichMemo);{$endif} + {$ifdef LCLCocoa}RegisterWSComponent(TCustomRichMemo, TCocoaWSCustomRichMemo);{$endif} {$ifdef NoRichMemo}RegisterWSComponent(TCustomRichMemo, TWSCustomRichMemo);{$endif} end; diff --git a/components/richmemo/richmemopackage.lpk b/components/richmemo/richmemopackage.lpk index eddb825b9..769f50c3d 100644 --- a/components/richmemo/richmemopackage.lpk +++ b/components/richmemo/richmemopackage.lpk @@ -9,7 +9,8 @@ - + + @@ -27,7 +28,7 @@ "/> - + @@ -84,6 +85,10 @@ + + + + @@ -96,7 +101,7 @@ - +