mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-04 01:38:31 +02:00
cocoa: implement setting cursor to control
git-svn-id: trunk@33603 -
This commit is contained in:
parent
8972794e3b
commit
a8fc0fa459
@ -153,6 +153,7 @@ type
|
|||||||
constructor CreateFromBitmap(const ABitmap: TCocoaBitmap; const hotSpot: NSPoint);
|
constructor CreateFromBitmap(const ABitmap: TCocoaBitmap; const hotSpot: NSPoint);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function Install: TCocoaCursor;
|
function Install: TCocoaCursor;
|
||||||
|
property Cursor: NSCursor read FCursor;
|
||||||
property Standard: Boolean read FStandard;
|
property Standard: Boolean read FStandard;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -419,7 +420,7 @@ end;
|
|||||||
|
|
||||||
function TCocoaCursor.Install: TCocoaCursor;
|
function TCocoaCursor.Install: TCocoaCursor;
|
||||||
begin
|
begin
|
||||||
FCursor.set_;
|
FCursor.push;
|
||||||
Result := nil;
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -35,18 +35,21 @@
|
|||||||
function TCocoaWidgetSet.CreateStandardCursor(ACursor: SmallInt): HCursor;
|
function TCocoaWidgetSet.CreateStandardCursor(ACursor: SmallInt): HCursor;
|
||||||
begin
|
begin
|
||||||
case ACursor of
|
case ACursor of
|
||||||
crDefault : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.currentSystemCursor));
|
|
||||||
crArrow : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.arrowCursor));
|
crArrow : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.arrowCursor));
|
||||||
crCross : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.crosshairCursor));
|
crCross : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.crosshairCursor));
|
||||||
crIBeam : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.IBeamCursor));
|
crIBeam : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.IBeamCursor));
|
||||||
crSizeNS : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeUpDownCursor));
|
crSizeNS,
|
||||||
crSizeWE : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeLeftRightCursor));
|
crVSplit : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeUpDownCursor));
|
||||||
|
crSizeWE,
|
||||||
|
crHSplit : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeLeftRightCursor));
|
||||||
crSizeN : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeUpCursor));
|
crSizeN : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeUpCursor));
|
||||||
crSizeW : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeLeftCursor));
|
crSizeW : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeLeftCursor));
|
||||||
crSizeE : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeRightCursor));
|
crSizeE : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeRightCursor));
|
||||||
crSizeS : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.resizeDownCursor));
|
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));
|
crHandPoint : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.pointingHandCursor));
|
||||||
|
crDrag : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.dragCopyCursor));
|
||||||
else
|
else
|
||||||
Result := 0;
|
Result := 0;
|
||||||
end;
|
end;
|
||||||
|
@ -93,6 +93,7 @@ type
|
|||||||
procedure MouseClick(ClickCount: Integer); virtual; abstract;
|
procedure MouseClick(ClickCount: Integer); virtual; abstract;
|
||||||
procedure MouseMove(x,y: Integer); virtual; abstract;
|
procedure MouseMove(x,y: Integer); virtual; abstract;
|
||||||
procedure Draw(ctx: NSGraphicsContext; const bounds, dirty: NSRect); virtual; abstract;
|
procedure Draw(ctx: NSGraphicsContext; const bounds, dirty: NSRect); virtual; abstract;
|
||||||
|
procedure ResetCursorRects; virtual; abstract;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TWindowCallback }
|
{ TWindowCallback }
|
||||||
@ -137,6 +138,7 @@ type
|
|||||||
procedure mouseExited(event: NSEvent); override;
|
procedure mouseExited(event: NSEvent); override;
|
||||||
procedure mouseMoved(event: NSEvent); override;
|
procedure mouseMoved(event: NSEvent); override;
|
||||||
procedure mouseUp(event: NSEvent); override;
|
procedure mouseUp(event: NSEvent); override;
|
||||||
|
procedure resetCursorRects; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCocoaTextField = objcclass(NSTextField)
|
TCocoaTextField = objcclass(NSTextField)
|
||||||
@ -176,6 +178,7 @@ type
|
|||||||
procedure mouseEntered(event: NSEvent); override;
|
procedure mouseEntered(event: NSEvent); override;
|
||||||
procedure mouseExited(event: NSEvent); override;
|
procedure mouseExited(event: NSEvent); override;
|
||||||
procedure mouseMoved(event: NSEvent); override;
|
procedure mouseMoved(event: NSEvent); override;
|
||||||
|
procedure resetCursorRects; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaCustomControl }
|
{ TCocoaCustomControl }
|
||||||
@ -183,6 +186,7 @@ type
|
|||||||
TCocoaCustomControl = objcclass(NSControl)
|
TCocoaCustomControl = objcclass(NSControl)
|
||||||
callback : TCommonCallback;
|
callback : TCommonCallback;
|
||||||
procedure drawRect(dirtyRect: NSRect); override;
|
procedure drawRect(dirtyRect: NSRect); override;
|
||||||
|
procedure resetCursorRects; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaScrollView }
|
{ TCocoaScrollView }
|
||||||
@ -289,6 +293,12 @@ begin
|
|||||||
inherited mouseUp(event);
|
inherited mouseUp(event);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaButton.resetCursorRects;
|
||||||
|
begin
|
||||||
|
callback.resetCursorRects;
|
||||||
|
inherited resetCursorRects;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCocoaButton.mouseDown(event: NSEvent);
|
procedure TCocoaButton.mouseDown(event: NSEvent);
|
||||||
var
|
var
|
||||||
mp : NSPoint;
|
mp : NSPoint;
|
||||||
@ -408,6 +418,12 @@ begin
|
|||||||
inherited mouseMoved(event);
|
inherited mouseMoved(event);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaWindow.resetCursorRects;
|
||||||
|
begin
|
||||||
|
callback.resetCursorRects;
|
||||||
|
inherited resetCursorRects;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCocoaWindow.mouseEntered(event: NSEvent);
|
procedure TCocoaWindow.mouseEntered(event: NSEvent);
|
||||||
begin
|
begin
|
||||||
inherited mouseEntered(event);
|
inherited mouseEntered(event);
|
||||||
@ -447,6 +463,12 @@ begin
|
|||||||
callback.Draw(NSGraphicsContext.currentContext, bounds, dirtyRect);
|
callback.Draw(NSGraphicsContext.currentContext, bounds, dirtyRect);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaCustomControl.resetCursorRects;
|
||||||
|
begin
|
||||||
|
callback.resetCursorRects;
|
||||||
|
inherited resetCursorRects;
|
||||||
|
end;
|
||||||
|
|
||||||
{ LCLObjectExtension }
|
{ LCLObjectExtension }
|
||||||
|
|
||||||
function LCLObjectExtension.lclIsEnabled:Boolean;
|
function LCLObjectExtension.lclIsEnabled:Boolean;
|
||||||
|
@ -10,7 +10,7 @@ uses
|
|||||||
MacOSAll, CocoaAll,
|
MacOSAll, CocoaAll,
|
||||||
Classes, Controls, SysUtils,
|
Classes, Controls, SysUtils,
|
||||||
//
|
//
|
||||||
WSControls, LCLType, LCLProc,
|
WSControls, LCLType, LCLProc, Forms,
|
||||||
CocoaPrivate, CocoaGDIObjects, CocoaUtils, LCLMessageGlue;
|
CocoaPrivate, CocoaGDIObjects, CocoaUtils, LCLMessageGlue;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -34,6 +34,7 @@ type
|
|||||||
procedure MouseClick(clickCount: Integer); override;
|
procedure MouseClick(clickCount: Integer); override;
|
||||||
procedure MouseMove(x,y: Integer); override;
|
procedure MouseMove(x,y: Integer); override;
|
||||||
procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); override;
|
procedure Draw(ControlContext: NSGraphicsContext; const bounds, dirty: NSRect); override;
|
||||||
|
procedure ResetCursorRects; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSWinControl }
|
{ TCocoaWSWinControl }
|
||||||
@ -160,6 +161,32 @@ begin
|
|||||||
end;
|
end;
|
||||||
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 }
|
{ TCocoaWSWinControl }
|
||||||
|
|
||||||
class function TCocoaWSWinControl.CreateHandle(const AWinControl: TWinControl;
|
class function TCocoaWSWinControl.CreateHandle(const AWinControl: TWinControl;
|
||||||
|
@ -215,6 +215,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
win:=TCocoaWindow(win.initWithContentRect_styleMask_backing_defer(CreateParamsToNSRect(AParams), WinMask, NSBackingStoreBuffered, False));
|
win:=TCocoaWindow(win.initWithContentRect_styleMask_backing_defer(CreateParamsToNSRect(AParams), WinMask, NSBackingStoreBuffered, False));
|
||||||
|
win.enableCursorRects;
|
||||||
TCocoaWindow(win).callback:=TLCLCommonCallback.Create(win, AWinControl);
|
TCocoaWindow(win).callback:=TLCLCommonCallback.Create(win, AWinControl);
|
||||||
TCocoaWindow(win).wincallback:=TLCLWindowCallback.Create(win, AWinControl);
|
TCocoaWindow(win).wincallback:=TLCLWindowCallback.Create(win, AWinControl);
|
||||||
win.setDelegate(win);
|
win.setDelegate(win);
|
||||||
|
Loading…
Reference in New Issue
Block a user