mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-13 06:24:05 +02:00
325 lines
8.3 KiB
ObjectPascal
325 lines
8.3 KiB
ObjectPascal
{ $Id: $}
|
|
{ --------------------------------------------
|
|
cocoaprivate.pp - Cocoa internal classes
|
|
--------------------------------------------
|
|
|
|
This unit contains the private classhierarchy for the Cocoa implemetations
|
|
|
|
*****************************************************************************
|
|
* *
|
|
* This file is part of the Lazarus Component Library (LCL) *
|
|
* *
|
|
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
|
|
* for details about the copyright. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
* *
|
|
*****************************************************************************
|
|
}
|
|
unit CocoaPrivate;
|
|
|
|
{$mode objfpc}{$H+}
|
|
{$modeswitch objectivec1}
|
|
|
|
interface
|
|
|
|
uses
|
|
// rtl+ftl
|
|
Types, Classes, SysUtils,
|
|
// Libs
|
|
MacOSAll, CocoaAll, CocoaUtils;
|
|
|
|
type
|
|
|
|
{ TCommonCallback }
|
|
|
|
TCommonCallback = class(TObject)
|
|
public
|
|
Owner : NSObject;
|
|
constructor Create(AOwner: NSObject);
|
|
procedure MouseDown(x,y: Integer); virtual; abstract;
|
|
procedure MouseUp(x,y: Integer); virtual; abstract;
|
|
procedure MouseClick(ClickCount: Integer); virtual; abstract;
|
|
procedure MouseMove(x,y: Integer); virtual; abstract;
|
|
end;
|
|
|
|
{ TWindowCallback }
|
|
|
|
TWindowCallback = class(TObject)
|
|
public
|
|
Owner : NSWindow;
|
|
constructor Create(AOwner: NSWindow);
|
|
procedure Activate; virtual; abstract;
|
|
procedure Deactivate; virtual; abstract;
|
|
procedure CloseQuery(var CanClose: Boolean); virtual; abstract;
|
|
procedure Close; virtual; abstract;
|
|
procedure Resize; virtual; abstract;
|
|
end;
|
|
|
|
{ TCocoaWindowContentView }
|
|
|
|
TCocoaWindowContentView = objcclass(NSView)
|
|
public
|
|
procedure drawRect(r: NSRect); override;
|
|
end;
|
|
|
|
{todo: consider using common protocol for all TCocoa* derived objcclasses }
|
|
{TCocoaTopLeftRect = objcprotocol
|
|
procedure getTopLeftFrame(var r: TRect); message 'getTopLeftFrame:';
|
|
procedure setTopLeftFrame(const r: TRect); message 'setTopLeftFrame:';
|
|
end;}
|
|
|
|
{ TCocoaButton }
|
|
|
|
TCocoaButton = objcclass(NSButton)
|
|
protected
|
|
procedure actionButtonClick(sender: NSObject); message 'actionButtonClick:';
|
|
public
|
|
callback : TCommonCallback;
|
|
function initWithFrame(frameRect: NSRect): id; override;
|
|
function acceptsFirstResponder: Boolean; override;
|
|
procedure mouseDown(event: NSEvent); override;
|
|
procedure mouseDragged(event: NSEvent); override;
|
|
procedure mouseEntered(event: NSEvent); override;
|
|
procedure mouseExited(event: NSEvent); override;
|
|
procedure mouseMoved(event: NSEvent); override;
|
|
procedure mouseUp(event: NSEvent); override;
|
|
end;
|
|
|
|
TCocoaTextField = objcclass(NSTextField)
|
|
callback : TCommonCallback;
|
|
function acceptsFirstResponder: Boolean; override;
|
|
end;
|
|
|
|
{ TCocoaSecureTextField }
|
|
|
|
TCocoaSecureTextField = objcclass(NSSecureTextField)
|
|
callback : TCommonCallback;
|
|
function acceptsFirstResponder: Boolean; override;
|
|
end;
|
|
|
|
|
|
TCocoaTextView = objcclass(NSTextView)
|
|
callback : TCommonCallback;
|
|
function acceptsFirstResponder: Boolean; override;
|
|
end;
|
|
|
|
TCocoaWindow = objcclass(NSWindow)
|
|
protected
|
|
function windowShouldClose(sender : id): LongBool; message 'windowShouldClose:';
|
|
procedure windowWillClose(notification: NSNotification); message 'windowWillClose:';
|
|
procedure windowDidBecomeKey(notification: NSNotification); message 'windowDidBecomeKey:';
|
|
procedure windowDidResignKey(notification: NSNotification); message 'windowDidResignKey:';
|
|
procedure windowDidResize(notification: NSNotification); message 'windowDidResize:';
|
|
public
|
|
callback : TCommonCallback;
|
|
wincallback : TWindowCallback;
|
|
function acceptsFirstResponder: Boolean; override;
|
|
procedure mouseUp(event: NSEvent); override;
|
|
procedure mouseDown(event: NSEvent); override;
|
|
procedure mouseDragged(event: NSEvent); override;
|
|
procedure mouseEntered(event: NSEvent); override;
|
|
procedure mouseExited(event: NSEvent); override;
|
|
procedure mouseMoved(event: NSEvent); override;
|
|
end;
|
|
|
|
TCocoaCustomControl = objcclass(NSControl)
|
|
callback : TCommonCallback;
|
|
end;
|
|
|
|
implementation
|
|
|
|
{ TCocoaWindowContentView }
|
|
|
|
procedure TCocoaWindowContentView.drawRect(r: NSRect);
|
|
begin
|
|
//LCLSendPaintMsg();
|
|
inherited drawRect(r);
|
|
end;
|
|
|
|
{ TCocoaButton }
|
|
|
|
procedure TCocoaButton.actionButtonClick(sender: NSObject);
|
|
begin
|
|
callback.MouseClick(1);
|
|
//todo: simulate MouseUp
|
|
end;
|
|
|
|
function TCocoaButton.initWithFrame(frameRect: NSRect): id;
|
|
begin
|
|
Result:=inherited initWithFrame(frameRect);
|
|
if Assigned(Result) then begin
|
|
setTarget(Self);
|
|
setAction(objcselector('actionButtonClick:'));
|
|
end;
|
|
end;
|
|
|
|
function TCocoaButton.acceptsFirstResponder: Boolean;
|
|
begin
|
|
Result:=true;
|
|
end;
|
|
|
|
procedure TCocoaButton.mouseUp(event: NSEvent);
|
|
var
|
|
mp : NSPoint;
|
|
begin
|
|
mp:=event.locationInWindow;
|
|
callback.MouseUp(round(mp.x), round(mp.y));
|
|
inherited mouseUp(event);
|
|
end;
|
|
|
|
procedure TCocoaButton.mouseDown(event: NSEvent);
|
|
var
|
|
mp : NSPoint;
|
|
begin
|
|
mp:=event.locationInWindow;
|
|
callback.MouseDown(round(mp.x), round(mp.y));
|
|
inherited mouseDown(event);
|
|
end;
|
|
|
|
procedure TCocoaButton.mouseDragged(event: NSEvent);
|
|
begin
|
|
inherited mouseDragged(event);
|
|
end;
|
|
|
|
procedure TCocoaButton.mouseEntered(event: NSEvent);
|
|
begin
|
|
inherited mouseEntered(event);
|
|
end;
|
|
|
|
procedure TCocoaButton.mouseExited(event: NSEvent);
|
|
begin
|
|
inherited mouseExited(event);
|
|
end;
|
|
|
|
procedure TCocoaButton.mouseMoved(event: NSEvent);
|
|
begin
|
|
inherited mouseMoved(event);
|
|
end;
|
|
|
|
{ TCocoaTextField }
|
|
|
|
function TCocoaTextField.acceptsFirstResponder: Boolean;
|
|
begin
|
|
Result:=true;
|
|
end;
|
|
|
|
{ TCocoaTextView }
|
|
|
|
function TCocoaTextView.acceptsFirstResponder: Boolean;
|
|
begin
|
|
Result:=true;
|
|
end;
|
|
|
|
{ TCocoaWindow }
|
|
|
|
function TCocoaWindow.windowShouldClose(sender: id): LongBool;
|
|
var
|
|
canClose : Boolean;
|
|
begin
|
|
canClose:=true;
|
|
wincallback.CloseQuery(canClose);
|
|
Result:=canClose;
|
|
end;
|
|
|
|
procedure TCocoaWindow.windowWillClose(notification: NSNotification);
|
|
begin
|
|
wincallback.Close;
|
|
end;
|
|
|
|
procedure TCocoaWindow.windowDidBecomeKey(notification: NSNotification);
|
|
begin
|
|
wincallback.Activate;
|
|
end;
|
|
|
|
procedure TCocoaWindow.windowDidResignKey(notification: NSNotification);
|
|
begin
|
|
wincallback.Deactivate;
|
|
end;
|
|
|
|
procedure TCocoaWindow.windowDidResize(notification: NSNotification);
|
|
begin
|
|
wincallback.Resize;
|
|
end;
|
|
|
|
function TCocoaWindow.acceptsFirstResponder: Boolean;
|
|
begin
|
|
Result:=true;
|
|
end;
|
|
|
|
procedure TCocoaWindow.mouseUp(event: NSEvent);
|
|
var
|
|
mp : NSPoint;
|
|
begin
|
|
mp:=event.locationInWindow;
|
|
mp.y:=NSView(event.window.contentView).bounds.size.height-mp.y;
|
|
callback.MouseUp(round(mp.x), round(mp.y));
|
|
inherited mouseUp(event);
|
|
end;
|
|
|
|
procedure TCocoaWindow.mouseDown(event: NSEvent);
|
|
var
|
|
mp : NSPoint;
|
|
begin
|
|
mp:=event.locationInWindow;
|
|
mp.y:=NSView(event.window.contentView).bounds.size.height-mp.y;
|
|
callback.MouseDown(round(mp.x), round(mp.y));
|
|
inherited mouseDown(event);
|
|
end;
|
|
|
|
procedure TCocoaWindow.mouseDragged(event: NSEvent);
|
|
var
|
|
mp : NSPoint;
|
|
begin
|
|
mp:=event.locationInWindow;
|
|
mp.y:=NSView(event.window.contentView).bounds.size.height-mp.y;
|
|
callback.MouseMove(round(mp.x), round(mp.y));
|
|
inherited mouseMoved(event);
|
|
end;
|
|
|
|
procedure TCocoaWindow.mouseMoved(event: NSEvent);
|
|
var
|
|
mp : NSPoint;
|
|
begin
|
|
mp:=event.locationInWindow;
|
|
mp.y:=NSView(event.window.contentView).bounds.size.height-mp.y;
|
|
callback.MouseMove(round(mp.x), round(mp.y));
|
|
inherited mouseMoved(event);
|
|
end;
|
|
|
|
procedure TCocoaWindow.mouseEntered(event: NSEvent);
|
|
begin
|
|
inherited mouseEntered(event);
|
|
end;
|
|
|
|
procedure TCocoaWindow.mouseExited(event: NSEvent);
|
|
begin
|
|
inherited mouseExited(event);
|
|
end;
|
|
|
|
{ TCommonCallback }
|
|
|
|
constructor TCommonCallback.Create(AOwner: NSObject);
|
|
begin
|
|
Owner:=AOwner;
|
|
end;
|
|
|
|
{ TCocoaSecureTextField }
|
|
|
|
function TCocoaSecureTextField.acceptsFirstResponder: Boolean;
|
|
begin
|
|
Result:=True;
|
|
end;
|
|
|
|
{ TWindowCallback }
|
|
|
|
constructor TWindowCallback.Create(AOwner: NSWindow);
|
|
begin
|
|
Owner:=AOwner;
|
|
end;
|
|
|
|
end.
|
|
|