diff --git a/lcl/interfaces/cocoa/cocoagdiobjects.pas b/lcl/interfaces/cocoa/cocoagdiobjects.pas index 6ab2781f13..24be4a999b 100644 --- a/lcl/interfaces/cocoa/cocoagdiobjects.pas +++ b/lcl/interfaces/cocoa/cocoagdiobjects.pas @@ -223,6 +223,9 @@ function CheckBitmap(ABitmap: HBITMAP; AStr: string): Boolean; implementation +uses + CocoaInt; + //todo: a better check! function CheckDC(dc: HDC): TCocoaContext; @@ -421,6 +424,8 @@ end; function TCocoaCursor.Install: TCocoaCursor; begin FCursor.push; + // also request form cursors invalidation + CocoaWidgetSet.NSApp.keyWindow.resetCursorRects; Result := nil; end; diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index 5132f8adf9..0788a50055 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -67,7 +67,7 @@ type FTerminating: Boolean; pool : NSAutoreleasePool; - NSApp : NSApplication; + FNSApp : NSApplication; delegate : TCocoaAppDelegate; protected function GetAppHandle: THandle; override; @@ -102,7 +102,7 @@ type function RawImage_FromCocoaBitmap(out ARawImage: TRawImage; ABitmap, AMask: TCocoaBitmap; ARect: PRect = nil): Boolean; function RawImage_DescriptionToBitmapType(ADesc: TRawImageDescription; out bmpType: TCocoaBitmapType): Boolean; // function GetImagePixelData(AImage: CGImageRef; var bitmapByteCount: PtrUInt): Pointer; - + property NSApp: NSApplication read FNSApp; // the winapi compatibility methods {$I cocoawinapih.inc} // the extra LCL interface methods diff --git a/lcl/interfaces/cocoa/cocoaobject.inc b/lcl/interfaces/cocoa/cocoaobject.inc index 454b75cbf6..96446fe052 100644 --- a/lcl/interfaces/cocoa/cocoaobject.inc +++ b/lcl/interfaces/cocoa/cocoaobject.inc @@ -39,8 +39,8 @@ begin delegate:=TCocoaAppDelegate.alloc; { Creates the application NSApp object } - NsApp := NSApplication.sharedApplication; - NSApp.setDelegate(delegate); + FNsApp := NSApplication.sharedApplication; + FNSApp.setDelegate(delegate); end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index b0d3cdb984..776a94505f 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -93,7 +93,7 @@ type procedure MouseClick(ClickCount: Integer); virtual; abstract; procedure MouseMove(x,y: Integer); virtual; abstract; procedure Draw(ctx: NSGraphicsContext; const bounds, dirty: NSRect); virtual; abstract; - procedure ResetCursorRects; virtual; abstract; + function ResetCursorRects: Boolean; virtual; abstract; end; { TWindowCallback } @@ -141,9 +141,12 @@ type procedure resetCursorRects; override; end; + { TCocoaTextField } + TCocoaTextField = objcclass(NSTextField) callback : TCommonCallback; function acceptsFirstResponder: Boolean; override; + procedure resetCursorRects; override; end; { TCocoaSecureTextField } @@ -151,12 +154,16 @@ type TCocoaSecureTextField = objcclass(NSSecureTextField) callback : TCommonCallback; function acceptsFirstResponder: Boolean; override; + procedure resetCursorRects; override; end; + { TCocoaTextView } + TCocoaTextView = objcclass(NSTextView) callback : TCommonCallback; function acceptsFirstResponder: Boolean; override; + procedure resetCursorRects; override; end; { TCocoaWindow } @@ -192,6 +199,7 @@ type TCocoaScrollView = objcclass(NSScrollView) callback : TCommonCallback; + procedure resetCursorRects; override; end; @@ -220,12 +228,14 @@ type function numberOfItemsInComboBox(combo: TCocoaComboBox): NSInteger; message 'numberOfItemsInComboBox:'; procedure dealloc; override; + procedure resetCursorRects; override; end; { TCocoaScrollBar } TCocoaScrollBar = objcclass(NSScroller) callback : TCommonCallback; + procedure resetCursorRects; override; end; TCocoaListView = objcclass; @@ -251,16 +261,42 @@ type objectValueForTableColumn: NSTableColumn; row: NSInteger):id; message 'tableView:objectValueForTableColumn:row:'; procedure dealloc; override; + procedure resetCursorRects; override; end; { TCocoaGroupBox } TCocoaGroupBox = objcclass(NSBox) callback : TCommonCallback; + procedure resetCursorRects; override; end; implementation +{ TCocoaScrollView } + +procedure TCocoaScrollView.resetCursorRects; +begin + if not callback.resetCursorRects then + inherited resetCursorRects; +end; + +{ TCocoaScrollBar } + +procedure TCocoaScrollBar.resetCursorRects; +begin + if not callback.resetCursorRects then + inherited resetCursorRects; +end; + +{ TCocoaGroupBox } + +procedure TCocoaGroupBox.resetCursorRects; +begin + if not callback.resetCursorRects then + inherited resetCursorRects; +end; + { TCocoaButton } procedure TCocoaButton.actionButtonClick(sender: NSObject); @@ -294,8 +330,8 @@ end; procedure TCocoaButton.resetCursorRects; begin - callback.resetCursorRects; - inherited resetCursorRects; + if not callback.resetCursorRects then + inherited resetCursorRects; end; procedure TCocoaButton.mouseDown(event: NSEvent); @@ -334,6 +370,15 @@ begin Result:=true; end; +procedure TCocoaTextField.resetCursorRects; +begin + // this will not work well because + // cocoa replaced TextField and TextView cursors in + // mouseEntered, mouseMoved and CursorUpdate + if not callback.resetCursorRects then + inherited resetCursorRects; +end; + { TCocoaTextView } function TCocoaTextView.acceptsFirstResponder: Boolean; @@ -341,6 +386,12 @@ begin Result:=true; end; +procedure TCocoaTextView.resetCursorRects; +begin + if not callback.resetCursorRects then + inherited resetCursorRects; +end; + { TCocoaWindow } function TCocoaWindow.windowShouldClose(sender: id): LongBool; @@ -441,6 +492,12 @@ begin Result:=True; end; +procedure TCocoaSecureTextField.resetCursorRects; +begin + if not callback.resetCursorRects then + inherited resetCursorRects; +end; + { TWindowCallback } constructor TWindowCallback.Create(AOwner: NSWindow); @@ -458,8 +515,8 @@ end; procedure TCocoaCustomControl.resetCursorRects; begin - callback.resetCursorRects; - inherited resetCursorRects; + if not callback.resetCursorRects then + inherited resetCursorRects; end; { LCLObjectExtension } @@ -692,6 +749,12 @@ begin inherited dealloc; end; +procedure TCocoaListView.resetCursorRects; +begin + if not callback.resetCursorRects then + inherited resetCursorRects; +end; + { TCocoaStringList } procedure TCocoaStringList.Changed; @@ -746,6 +809,12 @@ begin inherited dealloc; end; +procedure TCocoaComboBox.resetCursorRects; +begin + if not callback.resetCursorRects then + inherited resetCursorRects; +end; + { TCocoaMenu } procedure TCocoaMenu.lclItemSelected(sender:id); diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index 00b503eb82..3c0423dce3 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -34,7 +34,7 @@ type procedure MouseClick(clickCount: Integer); override; procedure MouseMove(x,y: Integer); override; procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); override; - procedure ResetCursorRects; override; + function ResetCursorRects: Boolean; override; end; { TCocoaWSWinControl } @@ -162,12 +162,13 @@ begin end; end; -procedure TLCLCommonCallback.ResetCursorRects; +function TLCLCommonCallback.ResetCursorRects: Boolean; var ACursor: TCursor; AControl: TControl; View: NSView; begin + Result := False; if Owner.isKindOfClass_(NSWindow) then View := NSwindow(Owner).contentView else @@ -183,7 +184,8 @@ begin // traverse visible child controls ACursor := Target.Cursor; end; - if ACursor <> crDefault then + Result := ACursor <> crDefault; + if Result then View.addCursorRect_cursor(View.visibleRect, TCocoaCursor(Screen.Cursors[ACursor]).Cursor); end; end;