You've already forked lazarus-ccr
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:
76
components/richmemo/cocoa/cocoarichmemo.pas
Normal file
76
components/richmemo/cocoa/cocoarichmemo.pas
Normal 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.
|
@ -8,6 +8,7 @@ interface
|
|||||||
{$ifdef LCLWin32}{$undef NoRichMemo}{$endif}
|
{$ifdef LCLWin32}{$undef NoRichMemo}{$endif}
|
||||||
{$ifdef LCLCarbon}{$undef NoRichMemo}{$endif}
|
{$ifdef LCLCarbon}{$undef NoRichMemo}{$endif}
|
||||||
{$ifdef LCLGtk2}{$undef NoRichMemo}{$endif}
|
{$ifdef LCLGtk2}{$undef NoRichMemo}{$endif}
|
||||||
|
{$ifdef LCLCocoa}{$undef NoRichMemo}{$endif}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
WSLCLClasses,
|
WSLCLClasses,
|
||||||
@ -16,6 +17,7 @@ uses
|
|||||||
{$ifdef LCLWin32},Win32RichMemo{$endif}
|
{$ifdef LCLWin32},Win32RichMemo{$endif}
|
||||||
{$ifdef LCLCarbon},CarbonRichMemo{$endif}
|
{$ifdef LCLCarbon},CarbonRichMemo{$endif}
|
||||||
{$ifdef LCLGtk2},RichMemoRTF, Gtk2RichMemo{$endif}
|
{$ifdef LCLGtk2},RichMemoRTF, Gtk2RichMemo{$endif}
|
||||||
|
{$ifdef LCLCocoa},CocoaRichMemo{$endif}
|
||||||
;
|
;
|
||||||
|
|
||||||
function RegisterCustomRichMemo: Boolean;
|
function RegisterCustomRichMemo: Boolean;
|
||||||
@ -28,6 +30,7 @@ begin
|
|||||||
{$ifdef LCLWin32}RegisterWSComponent(TCustomRichMemo, TWin32WSCustomRichMemo);{$endif}
|
{$ifdef LCLWin32}RegisterWSComponent(TCustomRichMemo, TWin32WSCustomRichMemo);{$endif}
|
||||||
{$ifdef LCLCarbon}RegisterWSComponent(TCustomRichMemo, TCarbonWSCustomRichMemo);{$endif}
|
{$ifdef LCLCarbon}RegisterWSComponent(TCustomRichMemo, TCarbonWSCustomRichMemo);{$endif}
|
||||||
{$ifdef LCLGtk2}RegisterWSComponent(TCustomRichMemo, TGtk2WSCustomRichMemo);{$endif}
|
{$ifdef LCLGtk2}RegisterWSComponent(TCustomRichMemo, TGtk2WSCustomRichMemo);{$endif}
|
||||||
|
{$ifdef LCLCocoa}RegisterWSComponent(TCustomRichMemo, TCocoaWSCustomRichMemo);{$endif}
|
||||||
{$ifdef NoRichMemo}RegisterWSComponent(TCustomRichMemo, TWSCustomRichMemo);{$endif}
|
{$ifdef NoRichMemo}RegisterWSComponent(TCustomRichMemo, TWSCustomRichMemo);{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
<Version Value="11"/>
|
<Version Value="11"/>
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<OtherUnitFiles Value="win32;carbon;gtk2"/>
|
<IncludeFiles Value="cocoa"/>
|
||||||
|
<OtherUnitFiles Value="win32;carbon;gtk2;cocoa"/>
|
||||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<Parsing>
|
<Parsing>
|
||||||
@ -27,7 +28,7 @@
|
|||||||
"/>
|
"/>
|
||||||
<License Value="LGPL"/>
|
<License Value="LGPL"/>
|
||||||
<Version Major="1"/>
|
<Version Major="1"/>
|
||||||
<Files Count="12">
|
<Files Count="13">
|
||||||
<Item1>
|
<Item1>
|
||||||
<Filename Value="wsrichmemo.pas"/>
|
<Filename Value="wsrichmemo.pas"/>
|
||||||
<AddToUsesPkgSection Value="False"/>
|
<AddToUsesPkgSection Value="False"/>
|
||||||
@ -84,6 +85,10 @@
|
|||||||
<Filename Value="rtfdata.inc"/>
|
<Filename Value="rtfdata.inc"/>
|
||||||
<Type Value="Include"/>
|
<Type Value="Include"/>
|
||||||
</Item12>
|
</Item12>
|
||||||
|
<Item13>
|
||||||
|
<Filename Value="cocoa\cocoarichmemo.pas"/>
|
||||||
|
<AddToUsesPkgSection Value="False"/>
|
||||||
|
</Item13>
|
||||||
</Files>
|
</Files>
|
||||||
<Type Value="RunAndDesignTime"/>
|
<Type Value="RunAndDesignTime"/>
|
||||||
<RequiredPkgs Count="2">
|
<RequiredPkgs Count="2">
|
||||||
@ -96,7 +101,7 @@
|
|||||||
</Item2>
|
</Item2>
|
||||||
</RequiredPkgs>
|
</RequiredPkgs>
|
||||||
<UsageOptions>
|
<UsageOptions>
|
||||||
<UnitPath Value="$(PkgOutDir)\"/>
|
<UnitPath Value="$(PkgOutDir)"/>
|
||||||
</UsageOptions>
|
</UsageOptions>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
|
Reference in New Issue
Block a user