From a8fc0fa459a404a8ea602fe0d78b33591ede49f4 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 18 Nov 2011 05:56:42 +0000 Subject: [PATCH] cocoa: implement setting cursor to control git-svn-id: trunk@33603 - --- lcl/interfaces/cocoa/cocoagdiobjects.pas | 3 ++- lcl/interfaces/cocoa/cocoalclintf.inc | 11 +++++---- lcl/interfaces/cocoa/cocoaprivate.pp | 22 ++++++++++++++++++ lcl/interfaces/cocoa/cocoawscommon.pas | 29 +++++++++++++++++++++++- lcl/interfaces/cocoa/cocoawsforms.pp | 1 + 5 files changed, 60 insertions(+), 6 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoagdiobjects.pas b/lcl/interfaces/cocoa/cocoagdiobjects.pas index 6f949a21a9..6ab2781f13 100644 --- a/lcl/interfaces/cocoa/cocoagdiobjects.pas +++ b/lcl/interfaces/cocoa/cocoagdiobjects.pas @@ -153,6 +153,7 @@ type constructor CreateFromBitmap(const ABitmap: TCocoaBitmap; const hotSpot: NSPoint); destructor Destroy; override; function Install: TCocoaCursor; + property Cursor: NSCursor read FCursor; property Standard: Boolean read FStandard; end; @@ -419,7 +420,7 @@ end; function TCocoaCursor.Install: TCocoaCursor; begin - FCursor.set_; + FCursor.push; Result := nil; end; diff --git a/lcl/interfaces/cocoa/cocoalclintf.inc b/lcl/interfaces/cocoa/cocoalclintf.inc index 6b328b9338..053f220949 100644 --- a/lcl/interfaces/cocoa/cocoalclintf.inc +++ b/lcl/interfaces/cocoa/cocoalclintf.inc @@ -35,18 +35,21 @@ function TCocoaWidgetSet.CreateStandardCursor(ACursor: SmallInt): HCursor; begin case ACursor of - crDefault : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.currentSystemCursor)); crArrow : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.arrowCursor)); crCross : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.crosshairCursor)); crIBeam : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.IBeamCursor)); - crSizeNS : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeUpDownCursor)); - crSizeWE : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeLeftRightCursor)); + crSizeNS, + crVSplit : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeUpDownCursor)); + crSizeWE, + crHSplit : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeLeftRightCursor)); crSizeN : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeUpCursor)); crSizeW : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeLeftCursor)); crSizeE : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeRightCursor)); crSizeS : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeDownCursor)); - crNo : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.operationNotAllowedCursor)); + crNo, + crNoDrop : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.operationNotAllowedCursor)); crHandPoint : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.pointingHandCursor)); + crDrag : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.dragCopyCursor)); else Result := 0; end; diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index a8a441f358..7195db8284 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -93,6 +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; end; { TWindowCallback } @@ -137,6 +138,7 @@ type procedure mouseExited(event: NSEvent); override; procedure mouseMoved(event: NSEvent); override; procedure mouseUp(event: NSEvent); override; + procedure resetCursorRects; override; end; TCocoaTextField = objcclass(NSTextField) @@ -176,6 +178,7 @@ type procedure mouseEntered(event: NSEvent); override; procedure mouseExited(event: NSEvent); override; procedure mouseMoved(event: NSEvent); override; + procedure resetCursorRects; override; end; { TCocoaCustomControl } @@ -183,6 +186,7 @@ type TCocoaCustomControl = objcclass(NSControl) callback : TCommonCallback; procedure drawRect(dirtyRect: NSRect); override; + procedure resetCursorRects; override; end; { TCocoaScrollView } @@ -289,6 +293,12 @@ begin inherited mouseUp(event); end; +procedure TCocoaButton.resetCursorRects; +begin + callback.resetCursorRects; + inherited resetCursorRects; +end; + procedure TCocoaButton.mouseDown(event: NSEvent); var mp : NSPoint; @@ -408,6 +418,12 @@ begin inherited mouseMoved(event); end; +procedure TCocoaWindow.resetCursorRects; +begin + callback.resetCursorRects; + inherited resetCursorRects; +end; + procedure TCocoaWindow.mouseEntered(event: NSEvent); begin inherited mouseEntered(event); @@ -447,6 +463,12 @@ begin callback.Draw(NSGraphicsContext.currentContext, bounds, dirtyRect); end; +procedure TCocoaCustomControl.resetCursorRects; +begin + callback.resetCursorRects; + inherited resetCursorRects; +end; + { LCLObjectExtension } function LCLObjectExtension.lclIsEnabled:Boolean; diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index d76e4e2bd0..ac77b51777 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -10,7 +10,7 @@ uses MacOSAll, CocoaAll, Classes, Controls, SysUtils, // - WSControls, LCLType, LCLProc, + WSControls, LCLType, LCLProc, Forms, CocoaPrivate, CocoaGDIObjects, CocoaUtils, LCLMessageGlue; type @@ -34,6 +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; end; { TCocoaWSWinControl } @@ -160,6 +161,32 @@ begin end; end; +procedure TLCLCommonCallback.ResetCursorRects; +var + ACursor: TCursor; + AControl: TControl; + View: NSView; +begin + if Owner.isKindOfClass_(NSWindow) then + View := NSwindow(Owner).contentView + else + if Owner.isKindOfClass_(NSView) then + View := NSView(Owner) + else + Exit; + if not (csDesigning in Target.ComponentState) then + begin + ACursor := Screen.Cursor; + if ACursor = crDefault then + begin + // traverse visible child controls + ACursor := Target.Cursor; + end; + if ACursor <> crDefault then + View.addCursorRect_cursor(View.visibleRect, TCocoaCursor(Screen.Cursors[ACursor]).Cursor); + end; +end; + { TCocoaWSWinControl } class function TCocoaWSWinControl.CreateHandle(const AWinControl: TWinControl; diff --git a/lcl/interfaces/cocoa/cocoawsforms.pp b/lcl/interfaces/cocoa/cocoawsforms.pp index 3a24f1630b..4146e47e65 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pp +++ b/lcl/interfaces/cocoa/cocoawsforms.pp @@ -215,6 +215,7 @@ begin end; win:=TCocoaWindow(win.initWithContentRect_styleMask_backing_defer(CreateParamsToNSRect(AParams), WinMask, NSBackingStoreBuffered, False)); + win.enableCursorRects; TCocoaWindow(win).callback:=TLCLCommonCallback.Create(win, AWinControl); TCocoaWindow(win).wincallback:=TLCLWindowCallback.Create(win, AWinControl); win.setDelegate(win);