mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-11 02:47:20 +01:00
Carbon intf: started implementation of TClipboard - pasting text is working
- fixed Cursor changing for TControl - fixed SetForegroundWindow git-svn-id: trunk@12380 -
This commit is contained in:
parent
db339f6b42
commit
b96d6a2a15
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -2686,6 +2686,7 @@ lcl/interfaces/carbon/README.txt svneol=native#text/plain
|
||||
lcl/interfaces/carbon/carbonbars.pp svneol=native#text/pascal
|
||||
lcl/interfaces/carbon/carbonbuttons.pp svneol=native#text/pascal
|
||||
lcl/interfaces/carbon/carboncanvas.pp svneol=native#text/pascal
|
||||
lcl/interfaces/carbon/carbonclipboard.pp svneol=native#text/pascal
|
||||
lcl/interfaces/carbon/carbondbgconsts.pp svneol=native#text/pascal
|
||||
lcl/interfaces/carbon/carbondebug.inc svneol=native#text/plain
|
||||
lcl/interfaces/carbon/carbondebug.pp svneol=native#text/pascal
|
||||
|
||||
387
lcl/interfaces/carbon/carbonclipboard.pp
Normal file
387
lcl/interfaces/carbon/carbonclipboard.pp
Normal file
@ -0,0 +1,387 @@
|
||||
{ $Id$
|
||||
---------------------------------------
|
||||
carbonclipboard.pp - Carbon clipboard
|
||||
---------------------------------------
|
||||
|
||||
*****************************************************************************
|
||||
* *
|
||||
* This file is part of the Lazarus Component Library (LCL) *
|
||||
* *
|
||||
* See the file COPYING.modifiedLGPL, 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 CarbonClipboard;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
// debugging defines
|
||||
{$I carbondebug.inc}
|
||||
|
||||
uses
|
||||
// rtl+ftl
|
||||
Types, Classes, SysUtils, Math, Contnrs,
|
||||
// carbon bindings
|
||||
FPCMacOSAll,
|
||||
// LCL
|
||||
LCLProc, LCLType, Graphics, GraphType;
|
||||
|
||||
type
|
||||
|
||||
{ TCarbonClipboard }
|
||||
|
||||
TCarbonClipboard = class
|
||||
private
|
||||
FPasteboards: Array [TClipboardType] of PasteboardRef;
|
||||
FFormats: TList; // list of CFStringRef UTIs
|
||||
function FindFormat(const UTI: CFStringRef): TClipboardFormat;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
public
|
||||
function FormatToMimeType(FormatID: TClipboardFormat): String;
|
||||
function GetData(ClipboardType: TClipboardType; FormatID: TClipboardFormat;
|
||||
Stream: TStream): Boolean;
|
||||
function GetFormats(ClipboardType: TClipboardType; var Count: Integer;
|
||||
var List: PClipboardFormat): Boolean;
|
||||
function GetOwnerShip(ClipboardType: TClipboardType;
|
||||
OnRequestProc: TClipboardRequestEvent; FormatCount: Integer;
|
||||
Formats: PClipboardFormat): Boolean;
|
||||
function RegisterFormat(const AMimeType: String): TClipboardFormat;
|
||||
end;
|
||||
|
||||
var
|
||||
ClipboardTypeToPasteboard: Array [TClipboardType] of CFStringRef =
|
||||
(
|
||||
{ctPrimarySelection } kPasteboardUniqueName, // local application pasteboard
|
||||
{ctSecondarySelection} nil, // Find pasteboard
|
||||
{ctClipboard } nil // standard global pasteboard
|
||||
);
|
||||
Clipboard: TCarbonClipboard;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses CarbonProc, CarbonDbgConsts;
|
||||
|
||||
{ TCarbonClipboard }
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonClipboard.FindFormat
|
||||
Params: UTI
|
||||
Returns: The corresponding registered format identifier
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonClipboard.FindFormat(const UTI: CFStringRef): TClipboardFormat;
|
||||
var
|
||||
I: Integer;
|
||||
begin
|
||||
for I := 1 to FFormats.Count - 1 do
|
||||
begin
|
||||
if UTTypeConformsTo(UTI, CFStringRef(FFormats[I])) then
|
||||
begin
|
||||
Result := I;
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonClipboard.Create
|
||||
------------------------------------------------------------------------------}
|
||||
constructor TCarbonClipboard.Create;
|
||||
var
|
||||
T: TClipboardType;
|
||||
begin
|
||||
for T := Low(TClipboardType) to High(TClipboardType) do
|
||||
OSError(
|
||||
PasteboardCreate(ClipboardTypeToPasteboard[T], FPasteboards[T]),
|
||||
Self, SCreate, 'PasteboardCreate', ClipboardTypeName[T]);
|
||||
|
||||
FFormats := TList.Create;
|
||||
FFormats.Add(nil);
|
||||
|
||||
RegisterFormat(PredefinedClipboardMimeTypes[pcfText]);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonClipboard.Destroy
|
||||
------------------------------------------------------------------------------}
|
||||
destructor TCarbonClipboard.Destroy;
|
||||
var
|
||||
T: TClipboardType;
|
||||
I: Integer;
|
||||
S: CFStringRef;
|
||||
begin
|
||||
for I := 0 to FFormats.Count - 1 do
|
||||
begin
|
||||
S := FFormats[I];
|
||||
FreeCFString(S);
|
||||
end;
|
||||
|
||||
FFormats.Free;
|
||||
|
||||
for T := Low(TClipboardType) to High(TClipboardType) do
|
||||
CFRelease(FPasteboards[T]);
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonClipboard.FormatToMimeType
|
||||
Params: FormatID - A registered format identifier (0 is invalid)
|
||||
Returns: The corresponding mime type as string
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonClipboard.FormatToMimeType(FormatID: TClipboardFormat): String;
|
||||
var
|
||||
S: CFStringRef;
|
||||
begin
|
||||
if (FormatID > 0) and (FormatID < FFormats.Count) then
|
||||
begin
|
||||
if FormatID = 1 then
|
||||
begin
|
||||
Result := PredefinedClipboardMimeTypes[pcfText];
|
||||
Exit;
|
||||
end;
|
||||
|
||||
S := UTTypeCopyPreferredTagWithClass(CFStringRef(FFormats[FormatID]), kUTTagClassMIMEType);
|
||||
try
|
||||
Result := CFStringToStr(S);
|
||||
finally
|
||||
FreeCFString(S);
|
||||
end;
|
||||
end
|
||||
else
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonClipboard.GetData
|
||||
Params: ClipboardType - Clipboard type
|
||||
FormatID - A registered format identifier (0 is invalid)
|
||||
Stream - If format is available, it will be appended to this
|
||||
stream
|
||||
Returns: If the function succeeds
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonClipboard.GetData(ClipboardType: TClipboardType;
|
||||
FormatID: TClipboardFormat; Stream: TStream): Boolean;
|
||||
var
|
||||
Pasteboard: PasteboardRef;
|
||||
I, J: Integer;
|
||||
L: SizeUInt;
|
||||
Flavors: CFArrayRef;
|
||||
UTI: CFStringRef;
|
||||
FlavorCount: CFIndex;
|
||||
FlavorData: CFDataRef;
|
||||
Count: ItemCount;
|
||||
ID: PasteboardItemID;
|
||||
S: String;
|
||||
const
|
||||
SName = 'GetData';
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
if not ((FormatID > 0) and (FormatID < FFormats.Count)) then
|
||||
begin
|
||||
DebugLn('TCarbonClipboard.GetData Error: Invalid Format ' + DbgS(FormatID) + ' specified!');
|
||||
Exit;
|
||||
end;
|
||||
|
||||
Pasteboard := FPasteboards[ClipboardType];
|
||||
|
||||
PasteboardSynchronize(Pasteboard);
|
||||
if OSError(PasteboardGetItemCount(Pasteboard, Count), Self, SName,
|
||||
'PasteboardGetItemCount') then Exit;
|
||||
if Count < 1 then Exit;
|
||||
|
||||
for I := 1 to Count do
|
||||
begin
|
||||
if OSError(PasteboardGetItemIdentifier(Pasteboard, I, ID), Self, SName,
|
||||
'PasteboardGetItemIdentifier') then Continue;
|
||||
if OSError(PasteboardCopyItemFlavors(Pasteboard, ID, Flavors), Self, SName,
|
||||
'PasteboardCopyItemFlavors') then Continue;
|
||||
|
||||
FlavorCount := CFArrayGetCount(Flavors);
|
||||
for J := 0 to FlavorCount - 1 do
|
||||
begin
|
||||
UTI := CFArrayGetValueAtIndex(Flavors, J);
|
||||
//DebugLn('TCarbonClipboard.GetData FlavorType: ' + CFStringToStr(UTI) +
|
||||
// ' ' + CFStringToStr(FFormats[FormatID]));
|
||||
if UTTypeConformsTo(FFormats[FormatID], UTI) then
|
||||
begin
|
||||
//DebugLn('TCarbonClipboard.GetData Paste FlavorType: ' + CFStringToStr(UTI));
|
||||
|
||||
if OSError(PasteboardCopyItemFlavorData(Pasteboard, ID, UTI, FlavorData),
|
||||
Self, SGetData, 'PasteboardCopyItemFlavorData') then Continue;
|
||||
try
|
||||
//DebugLn('TCarbonClipboard.GetData Paste FlavordataLength: ' + DbgS(CFDataGetLength(FlavorData)));
|
||||
|
||||
if FormatID = 1 then // convert plain/text UTF-16 to UTF-8
|
||||
begin
|
||||
SetLength(S, (CFDataGetLength(FlavorData) div 2) * 3);
|
||||
if ConvertUTF16ToUTF8(PChar(S), Length(S) + 1,
|
||||
PWideChar(CFDataGetBytePtr(FlavorData)), CFDataGetLength(FlavorData) div 2,
|
||||
[toInvalidCharToSymbol], L) <> trNoError then Exit;
|
||||
|
||||
SetLength(S, L - 1);
|
||||
Stream.Write(S[1], L - 1);
|
||||
end
|
||||
else
|
||||
Stream.Write(CFDataGetBytePtr(FlavorData)^, CFDataGetLength(FlavorData));
|
||||
finally
|
||||
CFRelease(FlavorData);
|
||||
end;
|
||||
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonClipboard.GetFormats
|
||||
Params: ClipboardType - The type of clipboard operation
|
||||
Count - The number of clipboard formats
|
||||
List - Pointer to an array of supported formats
|
||||
(you must free it yourself)
|
||||
Returns: If the function succeeds
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonClipboard.GetFormats(ClipboardType: TClipboardType;
|
||||
var Count: Integer; var List: PClipboardFormat): Boolean;
|
||||
var
|
||||
Pasteboard: PasteboardRef;
|
||||
I, J: Integer;
|
||||
Flavors: CFArrayRef;
|
||||
UTI: CFStringRef;
|
||||
FlavorCount: CFIndex;
|
||||
FormatID: TClipboardFormat;
|
||||
C: ItemCount;
|
||||
ID: PasteboardItemID;
|
||||
Formats: TList;
|
||||
const
|
||||
SName = 'GetFormats';
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
Pasteboard := FPasteboards[ClipboardType];
|
||||
|
||||
PasteboardSynchronize(Pasteboard);
|
||||
if OSError(PasteboardGetItemCount(Pasteboard, C), Self, SName,
|
||||
'PasteboardGetItemCount') then Exit;
|
||||
if C < 1 then Exit;
|
||||
|
||||
Formats := TList.Create;
|
||||
try
|
||||
for I := 1 to C do
|
||||
begin
|
||||
if OSError(PasteboardGetItemIdentifier(Pasteboard, I, ID), Self, SName,
|
||||
'PasteboardGetItemIdentifier') then Continue;
|
||||
if OSError(PasteboardCopyItemFlavors(Pasteboard, ID, Flavors), Self, SName,
|
||||
'PasteboardCopyItemFlavors') then Continue;
|
||||
|
||||
FlavorCount := CFArrayGetCount(Flavors);
|
||||
for J := 0 to FlavorCount - 1 do
|
||||
begin
|
||||
UTI := CFArrayGetValueAtIndex(Flavors, J);
|
||||
|
||||
FormatID := FindFormat(UTI);
|
||||
if FormatID = 0 then
|
||||
FormatID := FFormats.Add(UTI);
|
||||
|
||||
if Formats.IndexOf(Pointer(FormatID)) = -1 then
|
||||
begin
|
||||
//DebugLn('TCarbonClipboard.GetFormats ' + FormatToMimeType(FormatID) +
|
||||
// ' ' + CFStringToStr(UTI));
|
||||
Formats.Add(Pointer(FormatID));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Count := Formats.Count;
|
||||
GetMem(List, Count * SizeOf(TClipboardFormat));
|
||||
for I := 0 to Count - 1 do List[i] := TClipboardFormat(Formats[I]);
|
||||
finally
|
||||
Formats.Free;
|
||||
end;
|
||||
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonClipboard.GetOwnerShip
|
||||
Params: ClipboardType - Type of clipboard
|
||||
OnRequestProc - TClipboardRequestEvent is defined in LCLType.pp
|
||||
If OnRequestProc is nil the onwership will end.
|
||||
FormatCount - Number of formats
|
||||
Formats - Array of TClipboardFormat. The supported formats the
|
||||
owner provides.
|
||||
|
||||
Returns: If the function succeeds
|
||||
|
||||
Sets the supported formats and requests ownership for the clipboard.
|
||||
The OnRequestProc is used to get the data from the LCL and to put it on the
|
||||
clipboard.
|
||||
If someone else requests the ownership, the OnRequestProc will be executed
|
||||
with the invalid FormatID 0 to notify the old owner of the lost of ownership.
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonClipboard.GetOwnerShip(ClipboardType: TClipboardType;
|
||||
OnRequestProc: TClipboardRequestEvent; FormatCount: Integer;
|
||||
Formats: PClipboardFormat): Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
DebugLn('TCarbonClipboard.GetOwnerShip TODO');
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonClipboard.RegisterFormat
|
||||
Params: AMimeType - A string (usually a MIME type) identifying a new format
|
||||
type to register
|
||||
Returns: The registered Format identifier (TClipboardFormat)
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonClipboard.RegisterFormat(const AMimeType: String): TClipboardFormat;
|
||||
var
|
||||
UTI, M: CFStringRef;
|
||||
begin
|
||||
CreateCFString(AMimeType, M);
|
||||
try
|
||||
if AMimeType = PredefinedClipboardMimeTypes[pcfText] then
|
||||
CreateCFString('public.utf16-plain-text', UTI)
|
||||
else
|
||||
UTI := UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, M, nil);
|
||||
finally
|
||||
FreeCFString(M);
|
||||
end;
|
||||
|
||||
Result := FindFormat(UTI);
|
||||
if Result = 0 then
|
||||
begin
|
||||
//DebugLn('TCarbonClipboard.RegisterFormat ' + AMimeType + ' ' + CFStringToStr(UTI));
|
||||
Result := FFormats.Add(UTI);
|
||||
end
|
||||
else
|
||||
FreeCFString(UTI);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
CreateCFString('com.apple.pasteboard.find', ClipboardTypeToPasteboard[ctSecondarySelection]);
|
||||
CreateCFString('com.apple.pasteboard.clipboard', ClipboardTypeToPasteboard[ctClipboard]);
|
||||
Clipboard := TCarbonClipboard.Create;
|
||||
|
||||
finalization
|
||||
|
||||
Clipboard.Free;
|
||||
FreeCFString(ClipboardTypeToPasteboard[ctSecondarySelection]);
|
||||
FreeCFString(ClipboardTypeToPasteboard[ctClipboard]);
|
||||
|
||||
|
||||
end.
|
||||
@ -63,6 +63,7 @@ type
|
||||
TCarbonWidget = class
|
||||
private
|
||||
FProperties: TStringList;
|
||||
FCursor: HCURSOR;
|
||||
function GetProperty(AIndex: String): Pointer;
|
||||
procedure SetProperty(AIndex: String; const AValue: Pointer);
|
||||
protected
|
||||
@ -94,6 +95,7 @@ type
|
||||
function GetScreenBounds(var ARect: TRect): Boolean; virtual; abstract;
|
||||
function SetBounds(const ARect: TRect): Boolean; virtual; abstract;
|
||||
procedure SetChildZPosition(AChild: TCarbonWidget; const AOldPos, ANewPos: Integer; const AChildren: TFPList); virtual; abstract;
|
||||
procedure SetCursor(ACursor: HCURSOR); virtual;
|
||||
|
||||
procedure ScrollBy(DX, DY: Integer); virtual;
|
||||
procedure SetFocus; virtual; abstract;
|
||||
@ -113,6 +115,7 @@ type
|
||||
- area for embedding child controls
|
||||
- processes track and draw event }
|
||||
property Content: ControlRef read GetContent;
|
||||
property Cursor: HCURSOR read FCursor;
|
||||
property Properties[AIndex: String]: Pointer read GetProperty write SetProperty;
|
||||
end;
|
||||
|
||||
@ -535,6 +538,17 @@ begin
|
||||
DebugLn(ClassName + '.GetScrollInfo unsupported or not implemented!');
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonWidget.SetCursor
|
||||
Params: ACursor - Handle of cursor to set
|
||||
|
||||
Sets the cursor
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TCarbonWidget.SetCursor(ACursor: HCURSOR);
|
||||
begin
|
||||
FCursor := ACursor;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonWidget.ScrollBy
|
||||
Params: DX, DY
|
||||
|
||||
@ -244,6 +244,7 @@ type
|
||||
TCarbonCursor = class(TCarbonGDIObject)
|
||||
private
|
||||
FCursorType: TCarbonCursorType;
|
||||
FDefault: Boolean;
|
||||
FThemeCursor: ThemeCursor;
|
||||
// animation
|
||||
FAnimationStep: Integer;
|
||||
@ -260,7 +261,7 @@ type
|
||||
public
|
||||
constructor Create;
|
||||
constructor CreateFromInfo(AInfo: PIconInfo);
|
||||
constructor CreateThemed(AThemeCursor: ThemeCursor);
|
||||
constructor CreateThemed(AThemeCursor: ThemeCursor; ADefault: Boolean = False);
|
||||
destructor Destroy; override;
|
||||
|
||||
procedure Install;
|
||||
@ -269,6 +270,7 @@ type
|
||||
class function HardwareCursorsSupported: Boolean;
|
||||
public
|
||||
property CursorType: TCarbonCursorType read FCursorType;
|
||||
property Default: Boolean read FDefault;
|
||||
end;
|
||||
|
||||
function CheckGDIObject(const GDIObject: HGDIOBJ; const AMethodName: String; AParamName: String = ''): Boolean;
|
||||
@ -1394,7 +1396,8 @@ end;
|
||||
|
||||
Creates new theme cursor
|
||||
------------------------------------------------------------------------------}
|
||||
constructor TCarbonCursor.CreateThemed(AThemeCursor: ThemeCursor);
|
||||
constructor TCarbonCursor.CreateThemed(AThemeCursor: ThemeCursor;
|
||||
ADefault: Boolean);
|
||||
const
|
||||
kThemeCursorTypeMap: array[kThemeArrowCursor..22] of TCarbonCursorType =
|
||||
(
|
||||
@ -1424,6 +1427,7 @@ const
|
||||
);
|
||||
begin
|
||||
Create;
|
||||
FDefault := ADefault;
|
||||
FThemeCursor := AThemeCursor;
|
||||
if (AThemeCursor >= Low(kThemeCursorTypeMap)) and
|
||||
(AThemeCursor <= High(kThemeCursorTypeMap)) then
|
||||
|
||||
@ -161,7 +161,7 @@ uses
|
||||
{ these can/should go up }
|
||||
CarbonDef, CarbonPrivate, CarbonMenus, CarbonButtons, CarbonBars, CarbonEdits,
|
||||
CarbonLists, CarbonTabs,
|
||||
CarbonThemes, CarbonCanvas, CarbonStrings,
|
||||
CarbonThemes, CarbonCanvas, CarbonStrings, CarbonClipboard,
|
||||
CarbonProc, CarbonDbgConsts, CarbonUtils,
|
||||
|
||||
Buttons, StdCtrls, PairSplitter, ComCtrls, CListBox, Calendar, Arrow,
|
||||
|
||||
@ -48,7 +48,8 @@ begin
|
||||
begin
|
||||
AThemeCursor := CursorToThemeCursor[TCursor(ACursor)];
|
||||
if AThemeCursor <> kThemeUndefCursor then
|
||||
Result := hCursor(TCarbonCursor.CreateThemed(AThemeCursor));
|
||||
Result := hCursor(TCarbonCursor.CreateThemed(AThemeCursor,
|
||||
TCursor(ACursor) = crDefault));
|
||||
end;
|
||||
|
||||
{$IFDEF VerboseLCLIntf}
|
||||
|
||||
@ -148,10 +148,11 @@ type
|
||||
function Update: Boolean; override;
|
||||
public
|
||||
function Activate: Boolean; virtual;
|
||||
|
||||
|
||||
procedure CloseModal; virtual;
|
||||
procedure ShowModal; virtual;
|
||||
|
||||
function SetForeground: Boolean; virtual;
|
||||
function Show(AShow: Integer): Boolean; virtual;
|
||||
|
||||
procedure SetBorderIcons(ABorderIcons: TBorderIcons); virtual;
|
||||
|
||||
@ -229,7 +229,6 @@ function CarbonCommon_CursorChange(ANextHandler: EventHandlerCallRef;
|
||||
var
|
||||
ALocation: FPCMacOSAll.Point;
|
||||
AModifiers: UInt32;
|
||||
ACursor: TCursor;
|
||||
ACursorWasSet: Boolean;
|
||||
|
||||
Widget: TCarbonWidget; //
|
||||
@ -256,19 +255,20 @@ begin
|
||||
Widget := GetCarbonWidget(Control);
|
||||
if Widget = nil then Exit;
|
||||
|
||||
GlobalToLocal(ALocation);
|
||||
|
||||
if OSError(HandleControlSetCursor(Control, ALocation, AModifiers, ACursorWasSet),
|
||||
SName, 'HandleControlSetCursor') then
|
||||
if Screen.Cursor = crDefault then // we can change cursor
|
||||
begin
|
||||
ACursorWasSet := False;
|
||||
|
||||
if not ACursorWasSet then
|
||||
begin
|
||||
ACursor := Screen.Cursor;
|
||||
if ACursor = crDefault then
|
||||
ACursor := Widget.LCLObject.Cursor;
|
||||
// if widget has default cursor set - get it from Carbon
|
||||
if TCarbonCursor(Widget.Cursor).Default then
|
||||
begin
|
||||
GlobalToLocal(ALocation);
|
||||
|
||||
WidgetSet.SetCursor(Screen.Cursors[ACursor]);
|
||||
if OSError(HandleControlSetCursor(Control, ALocation, AModifiers, ACursorWasSet),
|
||||
SName, 'HandleControlSetCursor') then ACursorWasSet := False;
|
||||
end;
|
||||
|
||||
if not ACursorWasSet then WidgetSet.SetCursor(Widget.Cursor);
|
||||
end;
|
||||
|
||||
Result := noErr;
|
||||
|
||||
@ -258,7 +258,7 @@ begin
|
||||
//Find out which control the mouse event should occur for
|
||||
Control := nil;
|
||||
if OSError(HIViewGetViewForMouseEvent(AWidget.Content, AEvent, Control),
|
||||
SName, 'HIViewGetViewForMouseEvent') then Exit;
|
||||
SName, SViewForMouse) then Exit;
|
||||
if Control = nil then Exit;
|
||||
|
||||
Widget := GetCarbonWidget(Control);
|
||||
@ -1307,7 +1307,6 @@ begin
|
||||
|
||||
if AVisible or (csDesigning in LCLobject.ComponentState) then
|
||||
begin
|
||||
SelectWindow(WindowRef(Widget)); // activate and move window to front
|
||||
FPCMacOSAll.ShowWindow(WindowRef(Widget));
|
||||
end
|
||||
else
|
||||
@ -1406,6 +1405,19 @@ begin
|
||||
SelectWindow(WindowRef(Widget));
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonWindow.SetForeground
|
||||
Returns: If the function succeeds
|
||||
|
||||
Brings the Carbon window to front and activates it
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonWindow.SetForeground: Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
SelectWindow(WindowRef(Widget)); // activate and move window to front
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonWindow.Show
|
||||
Params: AShow - (SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED)
|
||||
@ -1423,6 +1435,8 @@ const
|
||||
SZoomIdeal = 'ZoomWindowIdeal';
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
DebugLn('TCarbonWindow.Show ' + DbgS(AShow));
|
||||
|
||||
case AShow of
|
||||
SW_SHOWNORMAL, SW_SHOWMAXIMIZED:
|
||||
@ -1448,6 +1462,8 @@ begin
|
||||
if OSError(ZoomWindowIdeal(WindowRef(Widget), inZoomOut, P),
|
||||
Self, SName, SZoomIdeal, 'inZoomOut') then Exit;
|
||||
end;
|
||||
|
||||
SetForeground;
|
||||
end;
|
||||
SW_MINIMIZE:
|
||||
begin
|
||||
|
||||
@ -117,36 +117,97 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TCarbonWidgetSet.ClipboardFormatToMimeType(FormatID: TClipboardFormat
|
||||
): string;
|
||||
{------------------------------------------------------------------------------
|
||||
Method: ClipboardFormatToMimeType
|
||||
Params: FormatID - A registered format identifier (0 is invalid)
|
||||
Returns: The corresponding mime type as string
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonWidgetSet.ClipboardFormatToMimeType(FormatID: TClipboardFormat): string;
|
||||
begin
|
||||
Result:=inherited ClipboardFormatToMimeType(FormatID);
|
||||
{$IFDEF VerboseWinAPI}
|
||||
DebugLn('TCarbonWidgetSet.ClipboardFormatToMimeType FormatID: ' + DbgS(FormatID));
|
||||
{$ENDIF}
|
||||
|
||||
Result := Clipboard.FormatToMimeType(FormatID);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: ClipboardGetData
|
||||
Params: ClipboardType - Clipboard type
|
||||
FormatID - A registered format identifier (0 is invalid)
|
||||
Stream - If format is available, it will be appended to this
|
||||
stream
|
||||
Returns: If the function succeeds
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonWidgetSet.ClipboardGetData(ClipboardType: TClipboardType;
|
||||
FormatID: TClipboardFormat; Stream: TStream): boolean;
|
||||
begin
|
||||
Result:=inherited ClipboardGetData(ClipboardType, FormatID, Stream);
|
||||
{$IFDEF VerboseWinAPI}
|
||||
DebugLn('TCarbonWidgetSet.ClipboardGetData ClipboardType' +
|
||||
ClipboardTypeName[ClipboardType] + ' FormatID: ' + DbgS(FormatID));
|
||||
{$ENDIF}
|
||||
|
||||
Result := Clipboard.GetData(ClipboardType, FormatID, Stream);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: ClipboardGetFormats
|
||||
Params: ClipboardType - The type of clipboard operation
|
||||
Count - The number of clipboard formats
|
||||
List - Pointer to an array of supported formats
|
||||
(you must free it yourself)
|
||||
Returns: If the function succeeds
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonWidgetSet.ClipboardGetFormats(ClipboardType: TClipboardType;
|
||||
var Count: integer; var List: PClipboardFormat): boolean;
|
||||
var Count: integer; var List: PClipboardFormat): Boolean;
|
||||
begin
|
||||
Result:=inherited ClipboardGetFormats(ClipboardType, Count, List);
|
||||
{$IFDEF VerboseWinAPI}
|
||||
DebugLn('TCarbonWidgetSet.ClipboardGetFormats ClipboardType' +
|
||||
ClipboardTypeName[ClipboardType]);
|
||||
{$ENDIF}
|
||||
|
||||
Result := Clipboard.GetFormats(ClipboardType, Count, List);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: ClipboardGetOwnerShip
|
||||
Params: ClipboardType - Type of clipboard
|
||||
OnRequestProc - TClipboardRequestEvent is defined in LCLType.pp
|
||||
If OnRequestProc is nil the onwership will end.
|
||||
FormatCount - Number of formats
|
||||
Formats - Array of TClipboardFormat. The supported formats the
|
||||
owner provides.
|
||||
|
||||
Returns: If the function succeeds
|
||||
|
||||
Sets the supported formats and requests ownership for the clipboard.
|
||||
The OnRequestProc is used to get the data from the LCL and to put it on the
|
||||
clipboard.
|
||||
If someone else requests the ownership, the OnRequestProc will be executed
|
||||
with the invalid FormatID 0 to notify the old owner of the lost of ownership.
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonWidgetSet.ClipboardGetOwnerShip(ClipboardType: TClipboardType;
|
||||
OnRequestProc: TClipboardRequestEvent; FormatCount: integer;
|
||||
Formats: PClipboardFormat): boolean;
|
||||
begin
|
||||
Result:=inherited ClipboardGetOwnerShip(ClipboardType, OnRequestProc,
|
||||
FormatCount, Formats);
|
||||
{$IFDEF VerboseWinAPI}
|
||||
DebugLn('TCarbonWidgetSet.ClipboardGetOwnerShip ClipboardType' +
|
||||
ClipboardTypeName[ClipboardType] + ' FormatCount: ' + DbgS(FormatCount));
|
||||
{$ENDIF}
|
||||
|
||||
Result := Clipboard.GetOwnerShip(ClipboardType, OnRequestProc, FormatCount,
|
||||
Formats);
|
||||
end;
|
||||
|
||||
function TCarbonWidgetSet.ClipboardRegisterFormat(const AMimeType: string
|
||||
): TClipboardFormat;
|
||||
{------------------------------------------------------------------------------
|
||||
Method: ClipboardRegisterFormat
|
||||
Params: AMimeType - A string (usually a MIME type) identifying a new format
|
||||
type to register
|
||||
Returns: The registered Format identifier (TClipboardFormat)
|
||||
------------------------------------------------------------------------------}
|
||||
function TCarbonWidgetSet.ClipboardRegisterFormat(const AMimeType: string): TClipboardFormat;
|
||||
begin
|
||||
Result:=inherited ClipboardRegisterFormat(AMimeType);
|
||||
Result := Clipboard.RegisterFormat(AMimeType);
|
||||
end;
|
||||
|
||||
function TCarbonWidgetSet.CombineRgn(Dest, Src1, Src2: HRGN;
|
||||
@ -2602,6 +2663,7 @@ begin
|
||||
|
||||
Result := FCurrentCursor;
|
||||
if not CheckCursor(ACursor, 'SetCursor') then Exit;
|
||||
if FCurrentCursor = ACursor then Exit;
|
||||
|
||||
// If we setted cursor before, them we should uninstall it.
|
||||
// This needs for animated cursors (because of threading) and wait cursor
|
||||
@ -2651,7 +2713,7 @@ begin
|
||||
|
||||
if not CheckWidget(HWnd, 'SetForegroundWindow', TCarbonWindow) then Exit;
|
||||
|
||||
Result := TCarbonWindow(HWnd).Activate;
|
||||
Result := TCarbonWindow(HWnd).SetForeground;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
||||
@ -77,6 +77,7 @@ type
|
||||
const AOldPos, ANewPos: Integer;
|
||||
const AChildren: TFPList); override;
|
||||
class procedure SetColor(const AWinControl: TWinControl); override;
|
||||
class procedure SetCursor(const AWinControl: TWinControl; const ACursor: HCursor); override;
|
||||
class procedure SetFont(const AWinControl: TWinControl; const AFont: TFont); override;
|
||||
class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
|
||||
class procedure Invalidate(const AWinControl: TWinControl); override;
|
||||
@ -204,6 +205,21 @@ begin
|
||||
TCarbonWidget(AWinControl.Handle).SetColor(AWinControl.Color);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonWSWinControl.SetFont
|
||||
Params: AWinControl - LCL control
|
||||
ACursor - Cursor
|
||||
|
||||
Sets the cursor of control in Carbon interface
|
||||
------------------------------------------------------------------------------}
|
||||
class procedure TCarbonWSWinControl.SetCursor(const AWinControl: TWinControl;
|
||||
const ACursor: HCursor);
|
||||
begin
|
||||
if not CheckHandle(AWinControl, Self, 'SetCursor') then Exit;
|
||||
|
||||
TCarbonWidget(AWinControl.Handle).SetCursor(ACursor);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TCarbonWSWinControl.SetFont
|
||||
Params: AWinControl - LCL control
|
||||
|
||||
Loading…
Reference in New Issue
Block a user