diff --git a/lcl/interfaces/cocoa/cocoagdiobjects.pas b/lcl/interfaces/cocoa/cocoagdiobjects.pas index f7623c4c36..98c5678ad9 100644 --- a/lcl/interfaces/cocoa/cocoagdiobjects.pas +++ b/lcl/interfaces/cocoa/cocoagdiobjects.pas @@ -139,6 +139,21 @@ type property Height: Integer read FHeight; end; + { TCocoaCursor } + + TCocoaCursor = class(TObject) + private + FStandard: Boolean; + FBitmap: TCocoaBitmap; + FCursor: NSCursor; + public + constructor CreateStandard(const ACursor: NSCursor); + constructor CreateFromBitmap(const ABitmap: TCocoaBitmap; const hotSpot: NSPoint); + destructor Destroy; override; + function Install: TCocoaCursor; + property Standard: Boolean read FStandard; + end; + { TCocoaTextLayout } TCocoaTextLayout = class(TObject) @@ -361,6 +376,35 @@ begin end; end; +{ TCocoaCursor } +constructor TCocoaCursor.CreateStandard(const ACursor: NSCursor); +begin + FBitmap := nil; + FCursor := ACursor; + FStandard := True; +end; + +constructor TCocoaCursor.CreateFromBitmap(const ABitmap: TCocoaBitmap; const hotSpot: NSPoint); +begin + FBitmap := ABitmap; + FCursor := NSCursor.alloc.initWithImage_hotSpot(ABitmap.Image, hotSpot); + FStandard := False; +end; + +destructor TCocoaCursor.Destroy; +begin + FBitmap.Free; + if not Standard then + FCursor.release; + inherited; +end; + +function TCocoaCursor.Install: TCocoaCursor; +begin + FCursor.set_; + Result := nil; +end; + { TCocoaContext } function TCocoaContext.CGContext:CGContextRef; diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index 931ae6c31e..a9bfb86e21 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -41,6 +41,7 @@ uses CocoaProc, // LCL LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType, + Controls, IntfGraphics, Graphics, CocoaWSFactory; type diff --git a/lcl/interfaces/cocoa/cocoalclintf.inc b/lcl/interfaces/cocoa/cocoalclintf.inc index 9cc93bd2f0..6b328b9338 100644 --- a/lcl/interfaces/cocoa/cocoalclintf.inc +++ b/lcl/interfaces/cocoa/cocoalclintf.inc @@ -26,34 +26,32 @@ * * ***************************************************************************** } -(* + {------------------------------------------------------------------------------ Method: CreateStandardCursor Params: ACursor - Cursor type Returns: Cursor object in Carbon for the specified cursor type ------------------------------------------------------------------------------} -function TCarbonWidgetSet.CreateStandardCursor(ACursor: SmallInt): hCursor; -var - AThemeCursor: ThemeCursor; +function TCocoaWidgetSet.CreateStandardCursor(ACursor: SmallInt): HCursor; begin - {$IFDEF VerboseLCLIntf} - DebugLn('TCarbonWidgetSet.CreateStandardCursor ACursor: ' + DbgS(ACursor)); - {$ENDIF} - - Result := 0; - if (ACursor >= crLow) and (ACursor <= crHigh) then - begin - AThemeCursor := CursorToThemeCursor[TCursor(ACursor)]; - if AThemeCursor <> kThemeUndefCursor then - Result := hCursor(TCarbonCursor.CreateThemed(AThemeCursor, - TCursor(ACursor) = crDefault)); + 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)); + 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)); + crHandPoint : Result := HCursor(TCocoaCursor.CreateStandard(NSCursor.pointingHandCursor)); + else + Result := 0; end; - - {$IFDEF VerboseLCLIntf} - DebugLn('TCarbonWidgetSet.CreateStandardCursor Result: ' + DbgS(Result)); - {$ENDIF} end; - +(* {------------------------------------------------------------------------------ Method: DrawGrid Params: DC - Handle to device context diff --git a/lcl/interfaces/cocoa/cocoalclintfh.inc b/lcl/interfaces/cocoa/cocoalclintfh.inc index 97fb7b952e..e6ac95d8e3 100644 --- a/lcl/interfaces/cocoa/cocoalclintfh.inc +++ b/lcl/interfaces/cocoa/cocoalclintfh.inc @@ -25,8 +25,8 @@ ***************************************************************************** } -{function CreateStandardCursor(ACursor: SmallInt): hCursor; override; -procedure DrawGrid(DC: HDC; const R: TRect; DX, DY: Integer); override; +function CreateStandardCursor(ACursor: SmallInt): hCursor; override; +{procedure DrawGrid(DC: HDC; const R: TRect; DX, DY: Integer); override; function ExtUTF8Out(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean; override; diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc index 6440fcdd33..efca971c10 100644 --- a/lcl/interfaces/cocoa/cocoawinapi.inc +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -223,19 +223,11 @@ begin if IconInfo^.hbmColor = 0 then Exit; ABitmap := Create32BitAlphaBitmap(TCocoaBitmap(IconInfo^.hbmColor), TCocoaBitmap(IconInfo^.hbmMask)); - // For now just ignore the mask - Result := HICON(IconInfo^.hbmColor); if IconInfo^.fIcon then - begin Result := HICON(ABitmap) - end; -{ else - begin - IconInfo^.hbmColor := HBITMAP(ABitmap); - IconInfo^.hbmMask := 0; - Result := HICON(TCarbonCursor.CreateFromInfo(IconInfo)); - end;} + else + Result := HICON(TCocoaCursor.CreateFromBitmap(ABitmap, GetNSPoint(IconInfo^.xHotSpot, IconInfo^.yHotSpot))); end; function TCocoaWidgetSet.CreatePenIndirect(const LogPen: TLogPen): HPEN; @@ -294,6 +286,19 @@ begin if Assigned(gdi) then gdi.Release; end; +function TCocoaWidgetSet.DestroyIcon(Handle: HICON): Boolean; +var + Ico: TObject; +begin + Result := Handle <> 0; + if not Result then + Exit; + Ico := TObject(Handle); + Result := (Ico is TCocoaBitmap) or (Ico is TCocoaCursor); + if Result then + Ico.Destroy; +end; + function TCocoaWidgetSet.Ellipse(DC: HDC; x1, y1, x2, y2: Integer): Boolean; var ctx : TCocoaContext; @@ -796,6 +801,23 @@ begin end; end; +function TCocoaWidgetSet.SetCursor(ACursor: HCURSOR): HCURSOR; +begin + Result := HCURSOR(TCocoaCursor(ACursor).Install); +end; + +function TCocoaWidgetSet.SetCursorPos(X, Y: Integer): Boolean; +var + CursorPos: CGPoint; +begin + Result := False; + + CursorPos.X := X; + CursorPos.Y := Y; + if CGWarpMouseCursorPosition(CursorPos) <> noErr then Exit; + Result := True; +end; + {------------------------------- FONT AND TEXT --------------------------------} function TCocoaWidgetSet.SetTextColor(DC: HDC; Color: TColorRef): TColorRef; diff --git a/lcl/interfaces/cocoa/cocoawinapih.inc b/lcl/interfaces/cocoa/cocoawinapih.inc index 4d43b79f39..5668aa63fd 100644 --- a/lcl/interfaces/cocoa/cocoawinapih.inc +++ b/lcl/interfaces/cocoa/cocoawinapih.inc @@ -64,9 +64,9 @@ function CreateRectRgn(X1, Y1, X2, Y2: Integer): HRGN; override; procedure DeleteCriticalSection(var CritSection: TCriticalSection); override; {function DeleteDC(hDC: HDC): Boolean; override;} function DeleteObject(GDIObject: HGDIOBJ): Boolean; override; -{function DestroyCaret(Handle : HWND): Boolean; override; +{function DestroyCaret(Handle : HWND): Boolean; override;} function DestroyIcon(Handle: HICON): Boolean; override; -function DPtoLP(DC: HDC; var Points; Count: Integer): BOOL; override; +{function DPtoLP(DC: HDC; var Points; Count: Integer): BOOL; override; function DrawFocusRect(DC: HDC; const Rect: TRect): boolean; override; function DrawEdge(DC: HDC; var Rect: TRect; edge: Cardinal; grfFlags: Cardinal): Boolean; override;} //function DrawText(DC: HDC; Str: PChar; Count: Integer; var ARect: TRect; Flags: Cardinal): Integer; override; @@ -167,10 +167,10 @@ function SetBkMode(DC: HDC; bkMode : Integer) : Integer; override; function SetCapture(AHandle: HWND): HWND; override; function SetCaretPos(X, Y: Integer): Boolean; override; function SetCaretPosEx(Handle: HWnd; X, Y: Integer): Boolean; override; -function SetCaretRespondToFocus(handle: HWND; ShowHideOnFocus: boolean): Boolean; override; +function SetCaretRespondToFocus(handle: HWND; ShowHideOnFocus: boolean): Boolean; override;} function SetCursor(ACursor: HCURSOR): HCURSOR; override; function SetCursorPos(X, Y: Integer): Boolean; override; -function SetFocus(hWnd: HWND): HWND; override; +{function SetFocus(hWnd: HWND): HWND; override; function SetForegroundWindow(HWnd: HWND): boolean; override;} function SetProp(Handle: hwnd; Str : PChar; Data : Pointer) : Boolean; override; function SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer; override;