cocoa: Implements Application.OnDropFiles

git-svn-id: trunk@49727 -
This commit is contained in:
sekelsenmat 2015-08-29 14:13:02 +00:00
parent fdde7f3583
commit bec0723351
6 changed files with 89 additions and 31 deletions

1
.gitattributes vendored
View File

@ -6960,6 +6960,7 @@ lcl/interfaces/cocoa/Makefile svneol=native#text/plain
lcl/interfaces/cocoa/Makefile.compiled svneol=native#text/plain
lcl/interfaces/cocoa/Makefile.fpc svneol=native#text/plain
lcl/interfaces/cocoa/alllclintfunits.pas svneol=native#text/plain
lcl/interfaces/cocoa/cocoa_extra.pas svneol=native#text/plain
lcl/interfaces/cocoa/cocoacaret.pas svneol=native#text/pascal
lcl/interfaces/cocoa/cocoagdiobjects.pas svneol=native#text/plain
lcl/interfaces/cocoa/cocoaint.pas svneol=native#text/plain

View File

@ -0,0 +1,61 @@
{ $Id: $}
{ --------------------------------------------
cocoa_extra.pp - Cocoa headers not available in FPC
--------------------------------------------
This unit contains Cocoa headers which are not yet available in the latest FPC release
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
unit cocoa_extra;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
interface
uses
// rtl+ftl
Types, Classes, SysUtils,
CGGeometry,
// Libs
MacOSAll, CocoaAll;
type
NSViewFix = objccategory external (NSView)
function fittingSize: NSSize; message 'fittingSize';
end;
NSButtonSoundExtensionsCategory = objccategory external (NSButton)
function intrinsicContentSize(): NSSize; message 'intrinsicContentSize';
end;
// The following dummy categories fix bugs in the Cocoa bindings available in FPC
// Remove them when the FPC binding parser is fixed.
// More details:
// http://wiki.freepascal.org/FPC_PasCocoa/Differences#Sending_messages_to_id
// http://wiki.lazarus.freepascal.org/FPC_PasCocoa#Category_declaration
NSBitmapImageRepFix = objccategory external(NSBitmapImageRep)
function initWithBitmapDataPlanes_pixelsWide_pixelsHigh__colorSpaceName_bytesPerRow_bitsPerPixel(planes: PPByte; width: NSInteger; height: NSInteger; bps: NSInteger; spp: NSInteger; alpha: Boolean; isPlanar_: Boolean; colorSpaceName_: NSString; rBytes: NSInteger; pBits: NSInteger): id; message 'initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:';
function initWithBitmapDataPlanes_pixelsWide_pixelsHigh__colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel(planes: PPByte; width: NSInteger; height: NSInteger; bps: NSInteger; spp: NSInteger; alpha: Boolean; isPlanar_: Boolean; colorSpaceName_: NSString; bitmapFormat_: NSBitmapFormat; rBytes: NSInteger; pBits: NSInteger): id; message 'initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:';
end;
NSGraphicsContextFix = objccategory external(NSGraphicsContext)
procedure setImageInterpolation(interpolation: NSImageInterpolation); message 'setImageInterpolation:';
procedure setShouldAntialias(antialias: Boolean); message 'setShouldAntialias:';
end;
{// private since 10.5, doesn't seam to do anything in 10.10
NSApplicationSetAppleMenu = objccategory external(NSApplication)
procedure setAppleMenu(AMenu: NSMenu); message 'setAppleMenu:';
end;}
implementation
end.

View File

@ -11,6 +11,7 @@ uses
MacOSAll, // for CGContextRef
LCLtype, LCLProc, Graphics, Controls, fpcanvas,
CocoaAll, CocoaProc, CocoaUtils,
cocoa_extra,
{$ifndef CocoaUseHITheme}
customdrawndrawers, customdrawn_mac,
{$endif}
@ -513,24 +514,6 @@ begin
Result:=(p1.x=p2.x) and (p1.y=p2.y);
end;
{ TCocoaBitmap }
type
// The following dummy categories fix bugs in the Cocoa bindings available in FPC
// Remove them when the FPC binding parser is fixed.
// More details:
// http://wiki.freepascal.org/FPC_PasCocoa/Differences#Sending_messages_to_id
// http://wiki.lazarus.freepascal.org/FPC_PasCocoa#Category_declaration
NSBitmapImageRepFix = objccategory external(NSBitmapImageRep)
function initWithBitmapDataPlanes_pixelsWide_pixelsHigh__colorSpaceName_bytesPerRow_bitsPerPixel(planes: PPByte; width: NSInteger; height: NSInteger; bps: NSInteger; spp: NSInteger; alpha: Boolean; isPlanar_: Boolean; colorSpaceName_: NSString; rBytes: NSInteger; pBits: NSInteger): id; message 'initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:';
function initWithBitmapDataPlanes_pixelsWide_pixelsHigh__colorSpaceName_bitmapFormat_bytesPerRow_bitsPerPixel(planes: PPByte; width: NSInteger; height: NSInteger; bps: NSInteger; spp: NSInteger; alpha: Boolean; isPlanar_: Boolean; colorSpaceName_: NSString; bitmapFormat_: NSBitmapFormat; rBytes: NSInteger; pBits: NSInteger): id; message 'initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:';
end;
NSGraphicsContextFix = objccategory external(NSGraphicsContext)
procedure setImageInterpolation(interpolation: NSImageInterpolation); message 'setImageInterpolation:';
procedure setShouldAntialias(antialias: Boolean); message 'setShouldAntialias:';
end;
{ TCocoaFont }
constructor TCocoaFont.CreateDefault(AGlobal: Boolean = False);

View File

@ -33,7 +33,7 @@ uses
InterfaceBase, GraphType,
// private
CocoaAll, CocoaPrivate, CocoaUtils, CocoaGDIObjects,
CocoaProc,
CocoaProc, cocoa_extra,
// LCL
LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType,
Controls, Forms, Themes, Menus,
@ -59,10 +59,9 @@ type
constructor Create(AMimeType: string; ACocoaFormat: NSString; ADataType: TCocoaClipboardDataType);
end;
{// private since 10.5, doesn't seam to do anything in 10.10
NSApplicationSetAppleMenu = objccategory external(NSApplication)
procedure setAppleMenu(AMenu: NSMenu); message 'setAppleMenu:';
end;}
TAppDelegate = objcclass(NSObject, NSApplicationDelegateProtocol)
procedure application_openFiles(sender: NSApplication; filenames: NSArray);
end;
{ TCocoaWidgetSet }
@ -70,6 +69,7 @@ type
private
FTerminating: Boolean;
FNSApp: NSApplication;
FNSApp_Delegate: TAppDelegate;
FCurrentCursor: HCursor;
FCaptureControl: HWND;

View File

@ -33,7 +33,9 @@ begin
{$ENDIF}
{ Creates the application NSApp object }
FNsApp := NSApplication.sharedApplication;
FNSApp := NSApplication.sharedApplication;
FNSApp_Delegate := TAppDelegate.alloc.init;
FNSApp.setDelegate(FNSApp_Delegate);
// Sandboxing
lDict := NSProcessInfo.processInfo.environment;
@ -537,6 +539,21 @@ begin
DataType := ADataType;
end;
procedure TAppDelegate.application_openFiles(sender: NSApplication; filenames: NSArray);
var
lFiles: array of string;
lNSStr: NSString;
i: Integer;
begin
SetLength(lFiles, filenames.count);
for i := 0 to filenames.count-1 do
begin
lNSStr := NSString(filenames.objectAtIndex(i));
lFiles[i] := NSStringToString(lNSStr);
end;
Application.IntfDropFiles(lFiles);
end;
{------------------------------------------------------------------------------
Method: TCocoaWidgetSet.RawImage_DescriptionFromCocoaBitmap

View File

@ -27,8 +27,9 @@ uses
Classes, Controls, Buttons, LCLType, LCLProc, Graphics, GraphType,
// widgetset
WSButtons, WSLCLClasses, WSProc,
// LCL Carbon
CocoaWSCommon, CocoaWSStdCtrls, CocoaGDIObjects, CocoaPrivate, CocoaUtils;
// LCL Cocoa
CocoaWSCommon, CocoaWSStdCtrls, CocoaGDIObjects, CocoaPrivate, CocoaUtils,
cocoa_extra;
type
@ -88,11 +89,6 @@ begin
Result := TLCLIntfHandle(btn);
end;
type
NSButtonSoundExtensionsCategory = objccategory external (NSButton)
function intrinsicContentSize(): NSSize; message 'intrinsicContentSize';
end;
class procedure TCocoaWSBitBtn.GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
var