mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-30 17:22:42 +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);
|
||||
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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user