From 12152924e376e6cf884745a8c867369f6ba5d51f Mon Sep 17 00:00:00 2001 From: dmitry Date: Fri, 21 Jun 2019 15:42:10 +0000 Subject: [PATCH] cocoa: splitting window content into content and document, to allow the support of scrollbars for the form. #33988 git-svn-id: trunk@61439 - --- lcl/interfaces/cocoa/cocoawindows.pas | 61 +++++++++++++++++++-------- lcl/interfaces/cocoa/cocoawsforms.pas | 23 ++++++++-- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoawindows.pas b/lcl/interfaces/cocoa/cocoawindows.pas index 9ced29bf72..45025f60c2 100644 --- a/lcl/interfaces/cocoa/cocoawindows.pas +++ b/lcl/interfaces/cocoa/cocoawindows.pas @@ -28,7 +28,7 @@ uses CGGeometry, // Libs MacOSAll, CocoaAll, CocoaUtils, CocoaGDIObjects, - cocoa_extra, CocoaPrivate, CocoaTextEdits, + cocoa_extra, CocoaPrivate, CocoaTextEdits, CocoaScrollers, // LCL //Forms, LCLType, LCLProc; @@ -186,12 +186,28 @@ type procedure lclClearCallback; override; end; - { TCocoaWindowContent } + { TCocoaWindowContentDocument } - TCocoaWindowContent = objcclass(TCocoaCustomControl) + TCocoaWindowContentDocument = objcclass(TCocoaCustomControl) protected procedure didBecomeKeyNotification(sender: NSNotification); message 'didBecomeKeyNotification:'; procedure didResignKeyNotification(sender: NSNotification); message 'didResignKeyNotification:'; + public + overlay: NSView; + wincallback: IWindowCallback; + procedure didAddSubview(aview: NSView); override; + procedure setNeedsDisplay_(aflag: LCLObjCBoolean); override; + procedure setNeedsDisplayInRect(arect: NSRect); override; + // NSDraggingDestinationCategory + function draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation; override; + function performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean; override; + end; + + { TCocoaWindowContent } + + TCocoaWindowContent = objcclass(TCocoaScrollView) + private + _stringValue: NSString; public wincallback: IWindowCallback; isembedded: Boolean; // true - if the content is inside of another control, false - if the content is in its own window; @@ -199,7 +215,6 @@ type ownwin: NSWindow; fswin: NSWindow; // window that was used as a content prior to switching to old-school fullscreen popup_parent: HWND; // if not 0, indicates that we should set the popup parent - overlay: NSView; function performKeyEquivalent(event: NSEvent): LCLObjCBoolean; override; procedure resolvePopupParent(); message 'resolvePopupParent'; function lclOwnWindow: NSWindow; message 'lclOwnWindow'; @@ -211,12 +226,9 @@ type procedure viewWillMoveToWindow(newWindow: CocoaAll.NSWindow); override; procedure dealloc; override; procedure setHidden(aisHidden: LCLObjCBoolean); override; - procedure didAddSubview(aview: NSView); override; - // NSDraggingDestinationCategory - function draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation; override; - function performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean; override; - procedure setNeedsDisplay_(aflag: LCLObjCBoolean); override; - procedure setNeedsDisplayInRect(arect: NSRect); override; + + procedure setStringValue(avalue: NSString); message 'setStringValue:'; + function stringValue: NSString; message 'stringValue'; end; procedure NSScreenGetRect(sc: NSScreen; out r: TRect); @@ -255,7 +267,7 @@ end; { TCocoaWindowContent } -procedure TCocoaWindowContent.didAddSubview(aview: NSView); +procedure TCocoaWindowContentDocument.didAddSubview(aview: NSView); const mustHaveSizing = (NSViewWidthSizable or NSViewHeightSizable); begin @@ -272,18 +284,20 @@ begin inherited didAddSubview(aview); end; -procedure TCocoaWindowContent.didBecomeKeyNotification(sender: NSNotification); +procedure TCocoaWindowContentDocument.didBecomeKeyNotification(sender: NSNotification); begin if Assigned(callback) then callback.DidBecomeKeyNotification; end; -procedure TCocoaWindowContent.didResignKeyNotification(sender: NSNotification); +procedure TCocoaWindowContentDocument.didResignKeyNotification(sender: NSNotification); begin if Assigned(callback) then callback.DidResignKeyNotification; end; +{ TCocoaWindowContent } + procedure NSResponderHotKeys(asender: NSResponder; event: NSEvent; var handled: LCLObjCBoolean; atarget: NSResponder); var undoManager: NSUndoManager; @@ -516,6 +530,19 @@ begin end; end; +procedure TCocoaWindowContent.setStringValue(avalue: NSString); +begin + if _stringValue = avalue then Exit; + if Assigned(_stringValue) then _stringValue.release; + _stringValue := AValue; + if Assigned(_stringValue) then _stringValue.retain; +end; + +function TCocoaWindowContent.stringValue: NSString; +begin + Result := _stringValue; +end; + { TCocoaPanel } function TCocoaPanel.windowShouldClose(sender: id): LongBool; @@ -952,14 +979,14 @@ begin inherited keyDown(event); end; -function TCocoaWindowContent.draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation; +function TCocoaWindowContentDocument.draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation; begin Result := NSDragOperationNone; if (wincallback <> nil) and (wincallback.AcceptFilesDrag) then Result := sender.draggingSourceOperationMask(); end; -function TCocoaWindowContent.performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean; +function TCocoaWindowContentDocument.performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean; var draggedURLs{, lClasses}: NSArray; lFiles: array of string; @@ -999,13 +1026,13 @@ begin Result := True; end; -procedure TCocoaWindowContent.setNeedsDisplay_(aflag: LCLObjCBoolean); +procedure TCocoaWindowContentDocument.setNeedsDisplay_(aflag: LCLObjCBoolean); begin inherited setNeedsDisplay; if Assigned(overlay) then overlay.setNeedsDisplay_(aflag); end; -procedure TCocoaWindowContent.setNeedsDisplayInRect(arect: NSRect); +procedure TCocoaWindowContentDocument.setNeedsDisplayInRect(arect: NSRect); begin inherited setNeedsDisplayInRect(arect); if Assigned(overlay) then overlay.setNeedsDisplayInRect(arect); diff --git a/lcl/interfaces/cocoa/cocoawsforms.pas b/lcl/interfaces/cocoa/cocoawsforms.pas index f85e73ca6a..85de755afd 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pas +++ b/lcl/interfaces/cocoa/cocoawsforms.pas @@ -678,8 +678,10 @@ var Form: TCustomForm absolute AWinControl; win: TCocoaWindow; cnt: TCocoaWindowContent; + doc: TCocoaWindowContentDocument; ns: NSString; R: NSRect; + LR: NSRect; lDestView: NSView; ds: TCocoaDesignOverlay; cb: TLCLWindowCallback; @@ -689,10 +691,25 @@ begin // the only thing that needs to be created is Content R := CreateParamsToNSRect(AParams); + LR := R; + LR.origin.x := 0; + LR.origin.y := 0; + doc := TCocoaWindowContentDocument.alloc.initWithFrame(LR); cnt := TCocoaWindowContent.alloc.initWithFrame(R); - cb := TLCLWindowCallback.Create(cnt, AWinControl, cnt); + cb := TLCLWindowCallback.Create(doc, AWinControl, cnt); + cnt.callback := cb; cnt.wincallback := cb; + doc.callback := cb; + cnt.wincallback := cb; + cnt.isCustomRange := true; + + cnt.setDocumentView(doc); + cnt.setDrawsBackground(false); // everything is covered anyway + doc.setHidden(false); + + doc.setAutoresizesSubviews(true); + doc.setAutoresizingMask(NSViewMaxXMargin or NSViewMinYMargin); if (AParams.Style and WS_CHILD) = 0 then begin @@ -761,7 +778,7 @@ begin begin lDestView := GetNSObjectView(NSObject(AParams.WndParent)); lDestView.addSubView(cnt); - cnt.setAutoresizingMask(NSViewMaxXMargin or NSViewMinYMargin); + //cnt.setAutoresizingMask(NSViewMaxXMargin or NSViewMinYMargin); if cnt.window <> nil then cnt.window.setAcceptsMouseMovedEvents(True); cnt.callback.IsOpaque:=true; @@ -786,7 +803,7 @@ begin ); cnt.addSubview_positioned_relativeTo(ds, NSWindowAbove, nil); - cnt.overlay := ds; + doc.overlay := ds; end; Result := TLCLIntfHandle(cnt);