richmemo: started cocoa ws

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3748 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
skalogryz
2014-11-19 05:27:26 +00:00
parent 7b756e79c9
commit bb37e60dd1
3 changed files with 87 additions and 3 deletions

View File

@ -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.

View File

@ -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;

View File

@ -9,7 +9,8 @@
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<OtherUnitFiles Value="win32;carbon;gtk2"/>
<IncludeFiles Value="cocoa"/>
<OtherUnitFiles Value="win32;carbon;gtk2;cocoa"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
@ -27,7 +28,7 @@
"/>
<License Value="LGPL"/>
<Version Major="1"/>
<Files Count="12">
<Files Count="13">
<Item1>
<Filename Value="wsrichmemo.pas"/>
<AddToUsesPkgSection Value="False"/>
@ -84,6 +85,10 @@
<Filename Value="rtfdata.inc"/>
<Type Value="Include"/>
</Item12>
<Item13>
<Filename Value="cocoa\cocoarichmemo.pas"/>
<AddToUsesPkgSection Value="False"/>
</Item13>
</Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="2">
@ -96,7 +101,7 @@
</Item2>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)\"/>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>