mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-15 23:00:35 +02:00
cocoa: revise word-wrap implementation. switching to automatic resizing on scrollView changing size (that should prevent undesired crashes). Horizontal scroll bar should now be more consistent in its behaviour. #32225
git-svn-id: trunk@56862 -
This commit is contained in:
parent
b561f1b752
commit
6001e4b474
@ -164,8 +164,6 @@ type
|
|||||||
class function GetScrollView(AWinControl: TWinControl): TCocoaScrollView;
|
class function GetScrollView(AWinControl: TWinControl): TCocoaScrollView;
|
||||||
published
|
published
|
||||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
// WSWinControl functions
|
|
||||||
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
|
|
||||||
// WSEdit functions
|
// WSEdit functions
|
||||||
//class function GetCanUndo(const ACustomEdit: TCustomEdit): Boolean; override;
|
//class function GetCanUndo(const ACustomEdit: TCustomEdit): Boolean; override;
|
||||||
class function GetCaretPos(const ACustomEdit: TCustomEdit): TPoint; override;
|
class function GetCaretPos(const ACustomEdit: TCustomEdit): TPoint; override;
|
||||||
@ -270,6 +268,8 @@ function AllocSecureTextField(ATarget: TWinControl; const AParams: TCreateParams
|
|||||||
function GetListBox(AWinControl: TWinControl): TCocoaListBox;
|
function GetListBox(AWinControl: TWinControl): TCocoaListBox;
|
||||||
procedure ListBoxSetStyle(list: TCocoaListBox; AStyle: TListBoxStyle);
|
procedure ListBoxSetStyle(list: TCocoaListBox; AStyle: TListBoxStyle);
|
||||||
|
|
||||||
|
procedure TextViewSetWordWrap(txt: NSTextView; lScroll: NSScrollView; NewWordWrap: Boolean);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -881,6 +881,33 @@ end;
|
|||||||
|
|
||||||
{ TCocoaWSCustomMemo }
|
{ TCocoaWSCustomMemo }
|
||||||
|
|
||||||
|
procedure TextViewSetWordWrap(txt: NSTextView; lScroll: NSScrollView; NewWordWrap: Boolean);
|
||||||
|
var
|
||||||
|
layoutSize: NSSize;
|
||||||
|
begin
|
||||||
|
if NewWordWrap then
|
||||||
|
begin
|
||||||
|
layoutSize := lScroll.contentSize();
|
||||||
|
layoutSize := GetNSSize(layoutSize.width, CGFloat_Max);
|
||||||
|
txt.textContainer.setContainerSize(layoutSize);
|
||||||
|
txt.textContainer.setWidthTracksTextView(True);
|
||||||
|
txt.setHorizontallyResizable(false);
|
||||||
|
txt.setAutoresizingMask(NSViewWidthSizable);
|
||||||
|
layoutSize.height:=txt.frame.size.height;
|
||||||
|
txt.setFrameSize(layoutSize);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
txt.textContainer.setWidthTracksTextView(False);
|
||||||
|
layoutSize := GetNSSize(CGFloat_Max, CGFloat_Max);
|
||||||
|
txt.textContainer.setContainerSize(layoutSize);
|
||||||
|
txt.textContainer.setWidthTracksTextView(False);
|
||||||
|
txt.setHorizontallyResizable(true);
|
||||||
|
txt.setAutoresizingMask(0);
|
||||||
|
end;
|
||||||
|
txt.sizeToFit;
|
||||||
|
end;
|
||||||
|
|
||||||
class function TCocoaWSCustomMemo.GetTextView(AWinControl: TWinControl): TCocoaTextView;
|
class function TCocoaWSCustomMemo.GetTextView(AWinControl: TWinControl): TCocoaTextView;
|
||||||
var
|
var
|
||||||
lScroll: TCocoaScrollView;
|
lScroll: TCocoaScrollView;
|
||||||
@ -922,6 +949,11 @@ begin
|
|||||||
nr.size.width:=AParams.Width;
|
nr.size.width:=AParams.Width;
|
||||||
|
|
||||||
txt := TCocoaTextView.alloc.initwithframe(nr);
|
txt := TCocoaTextView.alloc.initwithframe(nr);
|
||||||
|
// this is necessary for Ward Wrap disabled, so NSViewText
|
||||||
|
// doesn't have a constraint to resize
|
||||||
|
// Apple default maxsize is InitialWidth, 10000000
|
||||||
|
// (MaxSize is also changed automatically, if NSViewText size is changed)
|
||||||
|
txt.setMaxSize(NSMakeSize(10000000, 10000000));
|
||||||
scr.setDocumentView(txt);
|
scr.setDocumentView(txt);
|
||||||
|
|
||||||
scr.setHasVerticalScroller(VerticalScrollerVisible[TMemo(AWinControl).ScrollBars]);
|
scr.setHasVerticalScroller(VerticalScrollerVisible[TMemo(AWinControl).ScrollBars]);
|
||||||
@ -946,25 +978,11 @@ begin
|
|||||||
ns.release;
|
ns.release;
|
||||||
|
|
||||||
scr.callback := txt.callback;
|
scr.callback := txt.callback;
|
||||||
|
|
||||||
|
TextViewSetWordWrap(txt, scr, TCustomMemo(AWinControl).WordWrap);
|
||||||
Result := TLCLIntfHandle(scr);
|
Result := TLCLIntfHandle(scr);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCocoaWSCustomMemo.SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer);
|
|
||||||
var
|
|
||||||
nr: NSRect;
|
|
||||||
txt: TCocoaTextView;
|
|
||||||
lScroll: TCocoaScrollView;
|
|
||||||
begin
|
|
||||||
TCocoaWSWinControl.SetBounds(AWinControl, ALeft, ATop, AWidth, AHeight);
|
|
||||||
|
|
||||||
txt := GetTextView(AWinControl);
|
|
||||||
lScroll := GetScrollView(AWinControl);
|
|
||||||
if (not Assigned(txt)) or (not Assigned(lScroll)) then Exit;
|
|
||||||
|
|
||||||
nr := lScroll.documentVisibleRect;
|
|
||||||
txt.setFrame(nr);
|
|
||||||
end;
|
|
||||||
|
|
||||||
class function TCocoaWSCustomMemo.GetCaretPos(const ACustomEdit: TCustomEdit): TPoint;
|
class function TCocoaWSCustomMemo.GetCaretPos(const ACustomEdit: TCustomEdit): TPoint;
|
||||||
var
|
var
|
||||||
txt: TCocoaTextView;
|
txt: TCocoaTextView;
|
||||||
@ -1062,7 +1080,6 @@ end;
|
|||||||
|
|
||||||
class procedure TCocoaWSCustomMemo.SetWordWrap(const ACustomMemo: TCustomMemo; const NewWordWrap: boolean);
|
class procedure TCocoaWSCustomMemo.SetWordWrap(const ACustomMemo: TCustomMemo; const NewWordWrap: boolean);
|
||||||
var
|
var
|
||||||
layoutSize: NSSize;
|
|
||||||
txt: TCocoaTextView;
|
txt: TCocoaTextView;
|
||||||
lScroll: TCocoaScrollView;
|
lScroll: TCocoaScrollView;
|
||||||
begin
|
begin
|
||||||
@ -1070,19 +1087,7 @@ begin
|
|||||||
lScroll := GetScrollView(ACustomMemo);
|
lScroll := GetScrollView(ACustomMemo);
|
||||||
if (not Assigned(txt)) or (not Assigned(lScroll)) then Exit;
|
if (not Assigned(txt)) or (not Assigned(lScroll)) then Exit;
|
||||||
|
|
||||||
if NewWordWrap then
|
TextViewSetWordWrap(txt, lScroll, NewWordWrap);
|
||||||
begin
|
|
||||||
layoutSize := lScroll.contentSize();
|
|
||||||
layoutSize := GetNSSize(layoutSize.width, CGFloat_Max);
|
|
||||||
txt.textContainer.setContainerSize(layoutSize);
|
|
||||||
txt.textContainer.setWidthTracksTextView(True);
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
txt.textContainer.setWidthTracksTextView(False);
|
|
||||||
layoutSize := GetNSSize(CGFloat_Max, CGFloat_Max);
|
|
||||||
txt.textContainer.setContainerSize(layoutSize);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCocoaWSCustomMemo.SetText(const AWinControl:TWinControl;const AText:String);
|
class procedure TCocoaWSCustomMemo.SetText(const AWinControl:TWinControl;const AText:String);
|
||||||
|
Loading…
Reference in New Issue
Block a user