27
27
//##apiwiz##sps## // Do not remove, no wizard declaration before this line
29
function CocoaCombineMode(ACombineMode: Integer): TCocoaCombine;
32
RGN_AND: Result:=cc_And;
33
RGN_OR: Result:=cc_Or;
34
RGN_XOR: Result:=cc_Xor;
35
RGN_DIFF: Result:=cc_Diff;
42
CocoaRegionTypeToWin32Map: array[TCocoaRegionType] of Integer = (
44
{ crt_Empty } NULLREGION,
45
{ crt_Rectangle } SIMPLEREGION,
46
{ crt_Complex } COMPLEXREGION
49
function TCocoaWidgetSet.Arc(DC: HDC; Left, Top, Right, Bottom, angle1,
50
angle2: Integer): Boolean;
52
Result:=inherited Arc(DC, Left, Top, Right, Bottom, angle1, angle2);
55
function TCocoaWidgetSet.AngleChord(DC: HDC; x1, y1, x2, y2, angle1,
56
angle2: Integer): Boolean;
58
Result:=inherited AngleChord(DC, x1, y1, x2, y2, angle1, angle2);
61
function TCocoaWidgetSet.BeginPaint(Handle: hWnd; var PS: TPaintStruct): hdc;
63
Result := inherited BeginPaint(Handle, PS);
67
function TCocoaWidgetSet.BitBlt(DestDC: HDC; X, Y, Width, Height: Integer;
68
SrcDC: HDC; XSrc, YSrc: Integer; Rop: DWORD): Boolean;
70
Result := StretchMaskBlt(DestDC, X, Y, Width, Height, SrcDC, XSrc, YSrc,
71
Width, Height, 0, 0, 0, Rop);
74
function TCocoaWidgetSet.ClientToScreen(Handle: HWND; var P: TPoint): Boolean;
76
Result := Handle <> 0;
80
// 1. convert client to window
81
with NSObject(Handle).lclClientFrame do
86
// 2. convert window to screen
87
NSObject(Handle).lclLocalToScreen(P.X, P.Y);
91
function TCocoaWidgetSet.CombineRgn(Dest, Src1, Src2: HRGN; fnCombineMode: Longint): Longint;
93
Result := LCLType.Error;
94
if (Dest = 0) or (Src1 = 0) or (fnCombineMode<RGN_AND) or (fnCombineMode>RGN_COPY) then Exit;
95
if (fnCombineMode <> RGN_COPY) and (Src2 = 0) then Exit;
97
TCocoaRegion(Dest).CombineWith(TCocoaRegion(Src1), cc_Copy);
99
if fnCombineMode <> RGN_COPY then
100
TCocoaRegion(Dest). CombineWith(TCocoaRegion(Src2), CocoaCombineMode(fnCombineMode));
103
{------------------------------------------------------------------------------
105
Params: Width - Bitmap width, in pixels
106
Height - Bitmap height, in pixels
107
Planes - Number of color planes
108
BitCount - Number of bits required to identify a color (TODO)
109
BitmapBits - Pointer to array containing color data (TODO)
110
Returns: A handle to a bitmap
112
Creates a bitmap with the specified width, height and color format
113
------------------------------------------------------------------------------}
114
function TCocoaWidgetSet.CreateBitmap(Width, Height: Integer;
115
Planes, BitCount: Longint; BitmapBits: Pointer): HBITMAP;
117
bmpType: TCocoaBitmapType;
119
// WORKAROUND: force context supported depths
120
if BitmapBits = nil then
122
if BitCount = 24 then BitCount := 32;
123
// if BitCount = 1 then BitCount := 8;
127
1: bmpType := cbtMono;
128
8: bmpType := cbtGray;
129
32: bmpType := cbtARGB;
134
// winapi Bitmaps are on a word boundary
135
Result := HBITMAP(TCocoaBitmap.Create(Width, Height, BitCount, BitCount, cbaWord, bmpType, BitmapBits));
138
function TCocoaWidgetSet.CreateBrushIndirect(const LogBrush: TLogBrush): HBRUSH;
140
Result := HBrush(TCocoaBrush.Create(LogBrush));
143
function TCocoaWidgetSet.CreateCaret(Handle: HWND; Bitmap: hBitmap; Width,
144
Height: Integer): Boolean;
148
Result := (Handle <> 0);
151
Obj := NSObject(Handle);
152
if Obj.isKindOfClass(NSView) then
153
Result := CocoaCaret.CreateCaret(NSView(Handle), Bitmap, Width, Height)
155
if Obj.isKindOfClass(NSWindow) then
156
Result := CocoaCaret.CreateCaret(NSWindow(Handle).contentView, Bitmap, Width, Height)
162
function TCocoaWidgetSet.CreateCompatibleBitmap(DC: HDC; Width, Height: Integer): HBITMAP;
164
Result := HBITMAP(TCocoaBitmap.Create(Width, Height, 32, 32, cbaDQWord, cbtARGB, nil));
167
{------------------------------------------------------------------------------
168
Method: CreateCompatibleDC
169
Params: DC - Handle to memory device context
170
Returns: Handle to a memory device context
172
Creates a memory device context (DC) compatible with the specified device
173
------------------------------------------------------------------------------}
174
function TCocoaWidgetSet.CreateCompatibleDC(DC: HDC): HDC;
176
Result := HDC(TCocoaContext.Create);
180
//function TCocoaWidgetSet.CreateEllipticRgn(p1, p2, p3, p4: Integer): HRGN;
184
function TCocoaWidgetSet.CreateFontIndirect(const LogFont: TLogFont): HFONT;
186
Result := HFont(TCocoaFont.Create(LogFont, LogFont.lfFaceName));
189
function TCocoaWidgetSet.CreateFontIndirectEx(const LogFont: TLogFont;
190
const LongFontName: string): HFONT;
192
Result := HFont(TCocoaFont.Create(LogFont, LongFontName));
195
function Create32BitAlphaBitmap(ABitmap, AMask: TCocoaBitmap): TCocoaBitmap;
197
ARawImage: TRawImage;
198
Desc: TRawImageDescription absolute ARawimage.Description;
200
ImgHandle, ImgMaskHandle: HBitmap;
203
DevDesc: TRawImageDescription;
204
SrcImage, DstImage: TLazIntfImage;
209
if not RawImage_FromBitmap(ARawImage, HBITMAP(ABitmap), HBITMAP(AMask)) then
215
if W < 1 then W := 1;
217
if H < 1 then H := 1;
219
QueryDescription(DevDesc, [riqfRGB, riqfAlpha], W, H);
221
if DevDesc.IsEqual(Desc)
223
// image is compatible, so use it
225
ImagePtr := @ARawImage;
228
// create compatible copy
229
SrcImage := TLazIntfImage.Create(ARawImage, False);
230
DstImage := TLazIntfImage.Create(0,0,[]);
231
DstImage.DataDescription := DevDesc;
232
DstImage.CopyPixels(SrcImage);
234
DstImage.GetRawImage(DevImage);
235
ImagePtr := @DevImage;
239
if not RawImage_CreateBitmaps(ImagePtr^, ImgHandle, ImgMaskHandle, True) then Exit;
241
Result := TCocoaBitmap(ImgHandle);
248
function TCocoaWidgetSet.CreateIconIndirect(IconInfo: PIconInfo): HICON;
250
ABitmap: TCocoaBitmap;
253
if IconInfo^.hbmColor = 0 then Exit;
255
ABitmap := Create32BitAlphaBitmap(TCocoaBitmap(IconInfo^.hbmColor), TCocoaBitmap(IconInfo^.hbmMask));
257
if IconInfo^.fIcon then
258
Result := HICON(ABitmap)
260
Result := HICON(TCocoaCursor.CreateFromBitmap(ABitmap, GetNSPoint(IconInfo^.xHotSpot, IconInfo^.yHotSpot)));
263
function TCocoaWidgetSet.CreatePenIndirect(const LogPen: TLogPen): HPEN;
265
Result := HPen(TCocoaPen.Create(LogPen));
268
{------------------------------------------------------------------------------
269
Method: CreatePolygonRgn
270
Params: Points - Pointer to array of polygon points
271
NumPts - Number of points passed
272
FillMode - Filling mode
273
Returns: The new polygonal region
275
Creates a new polygonal region from the specified points
276
------------------------------------------------------------------------------}
277
function TCocoaWidgetSet.CreatePolygonRgn(Points: PPoint; NumPts: Integer;
278
FillMode: integer): HRGN;
280
{$IFDEF VerboseWinAPI}
281
DebugLn('TCocoaWidgetSet.CreatePolygonRgn NumPts: ' + DbgS(NumPts) +
282
' FillMode: ' + DbgS(FillMode));
285
Result := HRGN(TCocoaRegion.Create(Points, NumPts, FillMode=ALTERNATE));
288
function TCocoaWidgetSet.CreateRectRgn(X1, Y1, X2, Y2: Integer): HRGN;
290
{$IFDEF VerboseWinAPI}
291
DebugLn('TCocoaWidgetSet.CreateRectRgn R: ' + DbgS(Classes.Rect(X1, Y1, X2, Y2)));
294
Result := HRGN(TCocoaRegion.Create(X1, Y1, X2, Y2));
297
function TCocoaWidgetSet.DeleteObject(GDIObject: HGDIOBJ): Boolean;
299
gdi: TCocoaGDIObject;
302
if GDIObject = 0 then
305
gdi := CheckGDIOBJ(GdiObject);
307
if not Assigned(gdi) then
313
if gdi.RefCount = 0 then gdi.Destroy;
316
function TCocoaWidgetSet.DestroyCaret(Handle: HWND): Boolean;
318
Result := CocoaCaret.DestroyCaret;
321
function TCocoaWidgetSet.DestroyIcon(Handle: HICON): Boolean;
325
Result := Handle <> 0;
328
Ico := TObject(Handle);
329
Result := (Ico is TCocoaBitmap) or (Ico is TCocoaCursor);
334
function TCocoaWidgetSet.DrawFocusRect(DC: HDC; const Rect: TRect): boolean;
339
Result := Assigned(ctx);
341
ctx.DrawFocusRect(Rect);
344
function TCocoaWidgetSet.DrawEdge(DC: HDC; var Rect: TRect; edge: Cardinal;
345
grfFlags: Cardinal): Boolean;
347
Result := inherited DrawEdge(DC, Rect, edge, grfFlags);
350
function TCocoaWidgetSet.Ellipse(DC: HDC; x1, y1, x2, y2: Integer): Boolean;
355
Result := Assigned(ctx);
357
ctx.Ellipse(x1, y1, x2, y2);
360
function TCocoaWidgetSet.EnableWindow(hWnd: HWND; bEnable: Boolean): Boolean;
364
NSObject(hWnd).lclSetEnabled(bEnable)
367
function TCocoaWidgetSet.EndPaint(Handle: hwnd; var PS: TPaintStruct): Integer;
369
Result:=inherited EndPaint(Handle, PS);
372
function TCocoaWidgetSet.EnumFontFamiliesEx(DC: HDC; lpLogFont: PLogFont;
373
Callback: FontEnumExProc; Lparam: LParam; Flags: dword): longint;
376
ELogFont: TEnumLogFontEx;
377
Metric: TNewTextMetricEx;
378
FontName: AnsiString;
381
if not Assigned(Callback) then Exit;
382
for fname in NSFontManager.sharedFontManager.availableFontFamilies do
385
FontName := NSStringToString(fname);
386
FillChar(ELogFont, SizeOf(ELogFont), #0);
387
FillChar(Metric, SizeOf(Metric), #0);
388
ELogFont.elfLogFont.lfFaceName := FontName;
389
ELogFont.elfFullName := FontName;
390
//todo: read the data from all fonts of the fontfamily
391
Result := CallBack(ELogFont, Metric, TRUETYPE_FONTTYPE, lparam);
392
if Result = 0 then Break;
399
function TCocoaWidgetSet.EnumDisplayMonitors(hdc: HDC; lprcClip: PRect;
400
lpfnEnum: MonitorEnumProc; dwData: LPARAM): LongBool;
405
for i := 0 to NSScreen.screens.count - 1 do
407
Result := Result and lpfnEnum(HMONITOR(NSScreen.screens.objectAtIndex(i)), 0, nil, dwData);
408
if not Result then break;
412
function TCocoaWidgetSet.ExtSelectClipRGN(dc: hdc; rgn: hrgn; Mode: Longint): Integer;
417
if Assigned(ctx) then
418
Result := CocoaRegionTypeToWin32Map[ctx.SetClipRegion(TCocoaRegion(rgn), CocoaCombineMode(Mode))]
423
function TCocoaWidgetSet.ExtCreatePen(dwPenStyle, dwWidth: DWord;
424
const lplb: TLogBrush; dwStyleCount: DWord; lpStyle: PDWord): HPEN;
426
Result := HPEN(TCocoaPen.Create(dwPenStyle, dwWidth, lplb, dwStyleCount, lpStyle));
429
function TCocoaWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint;
430
Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
435
Result := Assigned(ctx);
436
if Assigned(ctx) then
437
ctx.TextOut(X, Y, Options, Rect, Str, Count, Dx);
440
function TCocoaWidgetSet.FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean;
446
br := CheckGDIOBJ(Brush);
447
Result := Assigned(ctx) and (not Assigned(br) or (br is TCocoaBrush));
448
if not Result then Exit;
451
ctx.Rectangle(Left, Top, Right, Bottom, True, TCocoaBrush(br));
454
function TCocoaWidgetSet.FillRgn(DC: HDC; RegionHnd: HRGN; hbr: HBRUSH): Bool;
456
OldRgn: TCocoaRegion;
464
br := CheckGDIOBJ(hbr);
465
Result := Assigned(ctx) and (not Assigned(br) or (br is TCocoaBrush));
466
if not Result then Exit;
468
Clipped := ctx.Clipped;
471
OldRgn := TCocoaRegion.CreateDefault;
474
ctx.CopyClipRegion(OldRgn);
475
if SelectClipRgn(DC, RegionHnd) <> ERROR then
477
R := TCocoaRegion(RegionHnd).GetBounds;
479
ctx.Rectangle(Left, Top, Right, Bottom, True, TCocoaBrush(br));
481
SelectClipRgn(DC, HRGN(OldRgn));
491
function TCocoaWidgetSet.Frame3d(DC: HDC; var ARect: TRect;
492
const FrameWidth: integer; const Style: TBevelCut): Boolean;
497
Result := Assigned(ctx) and (FrameWidth > 0);
499
ctx.Frame3d(ARect, FrameWidth, Style);
502
function TCocoaWidgetSet.FrameRect(DC: HDC; const ARect: TRect; hBr: HBRUSH): Integer;
507
if Assigned(ctx) then
509
ctx.FrameRect(ARect, TCocoaBrush(hBr));
516
function TCocoaWidgetSet.GetActiveWindow: HWND;
518
// return the currect application active window
519
Result := HWND(NSApp.keyWindow);
522
function TCocoaWidgetSet.GetBkColor(DC: HDC): TColorRef;
527
if Assigned(ctx) then
528
Result := ctx.BkColor
530
Result := CLR_INVALID;
533
function TCocoaWidgetSet.GetCaretPos(var lpPoint: TPoint): Boolean;
535
Result := CocoaCaret.GetCaretPos(lpPoint);
538
function TCocoaWidgetSet.GetCaretRespondToFocus(handle: HWND;
539
var ShowHideOnFocus: boolean): Boolean;
541
Result := inherited GetCaretRespondToFocus(handle, ShowHideOnFocus);
29
544
{------------------------------------------------------------------------------
30
545
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
33
548
SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED
34
549
------------------------------------------------------------------------------}
36
procedure ColorToRGBFloat(cl: TColorRef; var r,g,b: Single); inline;
38
R:=(cl and $FF) / $FF;
39
G:=((cl shr 8) and $FF) / $FF;
40
B:=((cl shr 16) and $FF) / $FF;
43
function RGBToColorFloat(r,g,b: Single): TColorRef; inline;
45
Result:=(Round(b*$FF) shl 16) or (Round(g*$FF) shl 8) or Round(r*$FF);
48
{--------------------------------- WINDOWS ------------------------------------}
50
550
function TCocoaWidgetSet.ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
52
552
{$ifdef VerboseCocoaWinAPI}
113
654
function TCocoaWidgetSet.GetClientBounds(handle : HWND; var ARect : TRect) : Boolean;
115
if Handle<>0 then begin
117
ARect:=NSObject(handle).lclClientFrame;
656
Result := Handle <> 0;
658
ARect := NSObject(handle).lclClientFrame;
122
661
function TCocoaWidgetSet.GetClientRect(handle : HWND; var ARect : TRect) : Boolean;
126
if Handle<>0 then begin
128
ARect:=NSObject(handle).lclClientFrame;
130
NSObject(Handle).lclLocalToScreen(dx, dy);
131
MoveRect(ARect, dx, dy);
663
Result := Handle <> 0;
666
ARect := NSObject(handle).lclClientFrame;
667
OffsetRect(ARect, -ARect.Left, -ARect.Top);
671
function TCocoaWidgetSet.GetClipBox(DC: hDC; lpRect: PRect): Longint;
676
if Assigned(ctx) and Assigned(lpRect) then
678
lpRect^ := ctx.GetClipRect;
679
Result := COMPLEXREGION;
685
function TCocoaWidgetSet.GetClipRGN(DC: hDC; RGN: hRGN): Longint;
690
if Assigned(ctx) and (RGN <> 0) then
691
Result := CocoaRegionTypeToWin32Map[ctx.CopyClipRegion(TCocoaRegion(RGN))]
696
function TCocoaWidgetSet.GetCursorPos(var lpPoint: TPoint ): Boolean;
698
with NSEvent.mouseLocation do
700
lpPoint.x := Round(x);
701
// cocoa returns cursor with inverted y coordinate
702
lpPoint.y := Round(NSScreen.mainScreen.frame.size.height-y);
707
function TCocoaWidgetSet.GetMonitorInfo(hMonitor: HMONITOR; lpmi: PMonitorInfo): Boolean;
709
ScreenID: NSScreen absolute hMonitor;
711
Result := (lpmi <> nil) and (lpmi^.cbSize >= SizeOf(TMonitorInfo));
712
if not Result then Exit;
713
NSToLCLRect(ScreenID.frame, lpmi^.rcMonitor);
714
NSToLCLRect(ScreenID.visibleFrame, lpmi^.rcWork);
715
if ScreenID = NSScreen.mainScreen then
716
lpmi^.dwFlags := MONITORINFOF_PRIMARY
721
function TCocoaWidgetSet.GetObject(GDIObj: HGDIOBJ; BufSize: Integer; Buf: Pointer): Integer;
723
AObject: TCocoaGDIObject;
725
Width, Height, RequiredSize, i: Integer;
727
APen: TCocoaPen absolute AObject;
728
ALogPen: PLogPen absolute Buf;
729
AExtLogPen: PExtLogPen absolute Buf;
733
AObject := CheckGDIObj(GDIObj);
735
if AObject is TCocoaBitmap then
739
Result := SizeOf(TDIBSection);
743
Width := TCocoaBitmap(AObject).Width;
744
Height := TCocoaBitmap(AObject).Height;
746
FillChar(DIB, SizeOf(TDIBSection), 0);
749
DIB.dsBm.bmType := $4D42;
750
DIB.dsBm.bmWidth := Width;
751
DIB.dsBm.bmHeight := Height;
752
DIB.dsBm.bmWidthBytes := 0;
753
DIB.dsBm.bmPlanes := 1;
754
DIB.dsBm.bmBitsPixel := 32;
755
DIB.dsBm.bmBits := nil;
757
{dsBmih - BITMAPINFOHEADER}
758
DIB.dsBmih.biSize := 40;
759
DIB.dsBmih.biWidth := Width;
760
DIB.dsBmih.biHeight := Height;
761
DIB.dsBmih.biPlanes := DIB.dsBm.bmPlanes;
762
DIB.dsBmih.biCompression := 0;
763
DIB.dsBmih.biSizeImage := 0;
764
DIB.dsBmih.biXPelsPerMeter := 0;
765
DIB.dsBmih.biYPelsPerMeter := 0;
766
DIB.dsBmih.biClrUsed := 0;
767
DIB.dsBmih.biClrImportant := 0;
768
DIB.dsBmih.biBitCount := 32;
770
if BufSize >= SizeOf(TDIBSection) then
772
PDIBSection(Buf)^ := DIB;
773
Result := SizeOf(TDIBSection);
778
System.Move(DIB, Buf^, BufSize);
783
if AObject is TCocoaPen then
785
if APen.IsExtPen then
787
RequiredSize := SizeOf(TExtLogPen);
788
if Length(APen.Dashes) > 1 then
789
inc(RequiredSize, (Length(APen.Dashes) - 1) * SizeOf(DWord));
791
Result := RequiredSize
793
if BufSize >= RequiredSize then
795
Result := RequiredSize;
796
AExtLogPen^.elpPenStyle := APen.Style;
797
if APen.IsGeometric then
799
case APen.JoinStyle of
801
AExtLogPen^.elpPenStyle := AExtLogPen^.elpPenStyle or PS_JOIN_ROUND;
803
AExtLogPen^.elpPenStyle := AExtLogPen^.elpPenStyle or PS_JOIN_BEVEL;
805
AExtLogPen^.elpPenStyle := AExtLogPen^.elpPenStyle or PS_JOIN_MITER;
808
case APen.CapStyle of
810
AExtLogPen^.elpPenStyle := AExtLogPen^.elpPenStyle or PS_ENDCAP_ROUND;
812
AExtLogPen^.elpPenStyle := AExtLogPen^.elpPenStyle or PS_ENDCAP_SQUARE;
814
AExtLogPen^.elpPenStyle := AExtLogPen^.elpPenStyle or PS_ENDCAP_FLAT;
816
AExtLogPen^.elpWidth := APen.Width;
819
AExtLogPen^.elpWidth := 1;
821
AExtLogPen^.elpBrushStyle := BS_SOLID;
822
AExtLogPen^.elpColor := APen.ColorRef;
823
AExtLogPen^.elpHatch := 0;
825
AExtLogPen^.elpNumEntries := Length(APen.Dashes);
826
if AExtLogPen^.elpNumEntries > 0 then
828
for i := 0 to AExtLogPen^.elpNumEntries - 1 do
829
PDword(@AExtLogPen^.elpStyleEntry)[i] := Trunc(APen.Dashes[i]);
832
AExtLogPen^.elpStyleEntry[0] := 0;
838
Result := SizeOf(TLogPen)
840
if BufSize >= SizeOf(TLogPen) then
842
Result := SizeOf(TLogPen);
843
ALogPen^.lopnStyle := APen.Style;
844
ALogPen^.lopnWidth := Types.Point(APen.Width, 0);
845
ALogPen^.lopnColor := APen.ColorRef;
136
851
function TCocoaWidgetSet.GetParent(Handle : HWND): HWND;
1009
function TCocoaWidgetSet.GetStockObject(Value: Integer): THandle;
1014
BLACK_BRUSH: // Black brush.
1015
Result := FStockBlackBrush;
1016
DKGRAY_BRUSH: // Dark gray brush.
1017
Result := FStockDKGrayBrush;
1018
GRAY_BRUSH: // Gray brush.
1019
Result := FStockGrayBrush;
1020
LTGRAY_BRUSH: // Light gray brush.
1021
Result := FStockLtGrayBrush;
1022
NULL_BRUSH: // Null brush (equivalent to HOLLOW_BRUSH).
1023
Result := FStockNullBrush;
1024
WHITE_BRUSH: // White brush.
1025
Result := FStockWhiteBrush;
1027
BLACK_PEN: // Black pen.
1028
Result := FStockBlackPen;
1029
NULL_PEN: // Null pen.
1030
Result := FStockNullPen;
1031
WHITE_PEN: // White pen.
1032
Result := FStockWhitePen;
1034
DEFAULT_GUI_FONT, SYSTEM_FONT:
1035
Result := FStockSystemFont;
1037
Result := FStockFixedFont;
1041
function SysColorToNSColor(nIndex: Integer): NSColor;
1044
COLOR_GRADIENTACTIVECAPTION, COLOR_ACTIVECAPTION,
1045
COLOR_WINDOWFRAME, COLOR_ACTIVEBORDER:
1046
Result := NSColor.windowFrameColor;
1047
COLOR_GRADIENTINACTIVECAPTION, COLOR_INACTIVECAPTION, COLOR_INACTIVEBORDER:
1048
Result := NSColor.windowBackgroundColor;
1050
COLOR_INACTIVECAPTIONTEXT:
1051
Result := NSColor.windowFrameTextColor;
1053
COLOR_WINDOW, COLOR_FORM:
1054
Result := NSColor.windowBackgroundColor;
1056
Result := NSColor.controlBackgroundColor;
1058
Result := NSColor.controlTextColor;
1060
Result := NSColor.selectedTextBackgroundColor;
1062
Result := NSColor.selectedMenuItemColor;
1063
COLOR_INFOTEXT, COLOR_WINDOWTEXT:
1064
Result := NSColor.controlTextColor;
1066
Result := NSColor.windowBackgroundColor;
1068
Result := NSColor.selectedControlColor;
1070
Result := NSColor.alternateSelectedControlColor;
1071
COLOR_HIGHLIGHTTEXT:
1072
Result := NSColor.selectedControlTextColor;
1074
Result := NSColor.scrollBarColor;
1076
Result := NSColor.controlColor;
1078
Result := NSColor.controlShadowColor;
1080
Result := NSColor.controlHighlightColor;
1082
Result := NSColor.controlTextColor;
1084
Result := NSColor.disabledControlTextColor;
1086
Result := NSColor.controlDarkShadowColor;
1088
Result := NSColor.controlLightHighlightColor;
1090
Result := NSColor.colorWithCalibratedRed_green_blue_alpha(249 / $FF, 252 / $FF, 201 / $FF, 1);
1096
function TCocoaWidgetSet.GetSysColor(nIndex: Integer): DWORD;
1101
// 1. get the system brush - it has a NSColor reference
1102
SysBrush := GetSysColorBrush(nIndex);
1103
if SysBrush = 0 then
1109
Color := TCocoaBrush(SysBrush).Color;
1111
if Assigned(Color) then
1112
Result := NSColorToColorRef(Color)
1117
function TCocoaWidgetSet.GetSysColorBrush(nIndex: Integer): HBRUSH;
1119
if (nIndex < 0) or (nIndex > MAX_SYS_COLORS) then
1125
if (FSysColorBrushes[nIndex] = 0) then
1126
FSysColorBrushes[nIndex] := HBrush(TCocoaBrush.Create(SysColorToNSColor(nIndex), True));
1127
Result := FSysColorBrushes[nIndex]
209
1130
function TCocoaWidgetSet.SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer;
226
1147
function TCocoaWidgetSet.LineTo(DC: HDC; X, Y: Integer): Boolean;
231
Result:=Assigned(ctx);
232
if not Result then Exit;
1152
Result := Assigned(ctx);
237
1157
function TCocoaWidgetSet.MoveToEx(DC: HDC; X, Y: Integer; OldPoint: PPoint): Boolean;
242
Result:=Assigned(ctx);
243
if not Result then Exit;
245
if Assigned(OldPoint) then OldPoint^:=ctx.PenPos;
1162
Result := Assigned(ctx);
1165
if Assigned(OldPoint) then
1166
OldPoint^ := ctx.PenPos;
249
1171
function TCocoaWidgetSet.Polygon(DC: HDC; Points: PPoint; NumPts: Integer; Winding: boolean): boolean;
254
Result:=Assigned(ctx) and Assigned(Points) and (NumPts>=2);
255
if not Result then Exit;
257
ctx.Polygon(PPointArray(Points)^, NumPts, Winding);
1176
Result := Assigned(ctx) and Assigned(Points) and (NumPts >= 2);
1178
ctx.Polygon(PPointArray(Points)^, NumPts, Winding);
261
1181
function TCocoaWidgetSet.Polyline(DC: HDC; Points: PPoint; NumPts: Integer): boolean;
266
Result:=Assigned(ctx) and Assigned(Points) and (NumPts>0);
267
if not Result then Exit;
1186
Result := Assigned(ctx) and Assigned(Points) and (NumPts > 0);
1188
ctx.Polyline(PPointArray(Points)^, NumPts);
269
ctx.Polyline(PPointArray(Points)^, NumPts);
1191
function TCocoaWidgetSet.PostMessage(Handle: HWND; Msg: Cardinal;
1192
wParam: WParam; lParam: LParam): Boolean;
1197
Result := Handle <> 0;
1200
Info := PrepareUserEventInfo(Handle, Msg, WParam, LParam);
1201
// if we will want a postmessage using notification center
1202
// NSDistributedNotificationCenter.defaultCenter.postNotificationName_object_userInfo_deliverImmediately(NSMessageNotification, nil, Info, False);
1203
Event := PrepareUserEvent(Handle, Info);
1204
NSApp.postEvent_atStart(Event, False);
273
1208
function TCocoaWidgetSet.Rectangle(DC: HDC; X1, Y1, X2, Y2: Integer): Boolean;
278
Result:=Assigned(ctx);
279
if not Result then Exit;
281
ctx.Rectangle(X1, Y1, X2, Y2, False, nil);
285
function TCocoaWidgetSet.FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean;
288
br : TCocoaGDIObject;
291
br:=CheckGDIOBJ(Brush);
292
Result:=Assigned(ctx) and (not Assigned(br) or (br is TCocoaBrush));
293
if not Result then Exit;
296
ctx.Rectangle(Left, Top, Right, Bottom, True, TCocoaBrush(br));
299
function TCocoaWidgetSet.Ellipse(DC: HDC; x1, y1, x2, y2: Integer): Boolean;
304
Result:=Assigned(ctx);
305
if not Result then Exit;
307
ctx.Ellipse(x1, y1, x2, y2);
310
{----------------------------------- REGION -----------------------------------}
312
{------------------------------------------------------------------------------
313
Method: CreatePolygonRgn
314
Params: Points - Pointer to array of polygon points
315
NumPts - Number of points passed
316
FillMode - Filling mode
317
Returns: The new polygonal region
319
Creates a new polygonal region from the specified points
320
------------------------------------------------------------------------------}
321
function TCocoaWidgetSet.CreatePolygonRgn(Points: PPoint; NumPts: Integer;
322
FillMode: integer): HRGN;
324
{$IFDEF VerboseWinAPI}
325
DebugLn('TCocoaWidgetSet.CreatePolygonRgn NumPts: ' + DbgS(NumPts) +
326
' FillMode: ' + DbgS(FillMode));
329
Result := HRGN(TCocoaRegion.Create(Points, NumPts, FillMode=ALTERNATE));
332
function CocoaCombineMode(fnCombineMode: Integer): TCocoaCombine;
334
case fnCombineMode of
335
RGN_AND: Result:=cc_And;
336
RGN_OR: Result:=cc_Or;
337
RGN_XOR: Result:=cc_Xor;
338
RGN_DIFF: Result:=cc_Diff;
344
function TCocoaWidgetSet.CombineRgn(Dest, Src1, Src2: HRGN;
345
fnCombineMode: Longint): Longint;
347
Result := LCLType.Error;
348
if (Dest = 0) or (Src1 = 0) or (fnCombineMode<RGN_AND) or (fnCombineMode>RGN_COPY) then Exit;
349
if (fnCombineMode <> RGN_COPY) and (Src2 = 0) then Exit;
351
TCocoaRegion(Dest).CombineWith(TCocoaRegion(Src1), cc_Copy);
353
if fnCombineMode <> RGN_COPY then
354
TCocoaRegion(Dest). CombineWith(TCocoaRegion(Src2), CocoaCombineMode(fnCombineMode));
357
function TCocoaWidgetSet.CreateRectRgn(X1, Y1, X2, Y2: Integer): HRGN;
359
{$IFDEF VerboseWinAPI}
360
DebugLn('TCocoaWidgetSet.CreateRectRgn R: ' + DbgS(Classes.Rect(X1, Y1, X2, Y2)));
363
Result := HRGN(TCocoaRegion.Create(X1, Y1, X2, Y2));
367
//function TCocoaWidgetSet.CreateEllipticRgn(p1, p2, p3, p4: Integer): HRGN;
371
{---------------------------- PEN AND BRUSH -----------------------------------}
373
function TCocoaWidgetSet.CreatePenIndirect(const LogPen: TLogPen): HPEN;
378
{$IFDEF VerboseWinAPI}
379
DebugLn('TCocoaWidgetSet.CreatePenIndirect');
382
if LogPen.lopnWidth.x>0 then p.Width:=LogPen.lopnWidth.x;
383
p.Style:=LogPen.lopnStyle;
384
if LogPen.lopnColor and $8000000 > 0 then cl:=GetSysColor(LogPen.lopnColor)
385
else cl:=LogPen.lopnColor;
387
ColorToRGBFloat(cl, p.R, p.G, p.B);
388
Result := HPEN(p);//TCocoaPen.Create(LogPen));
391
function TCocoaWidgetSet.CreateBrushIndirect(const LogBrush: TLogBrush): HBRUSH;
395
b:=TCocoaBrush.Create;
396
with b do ColorToRGBFloat(LogBrush.lbColor, R, G, B);
1213
Result := Assigned(ctx);
1215
ctx.Rectangle(X1, Y1, X2, Y2, False, nil);
400
1218
{------------------------------- SYNC OBJECTS ---------------------------------}
433
1251
{------------------------------- DEVICE CONTEXT -------------------------------}
435
1253
function TCocoaWidgetSet.GetDC(hWnd: HWND): HDC;
438
1259
if not Assigned(ScreenContext) then ScreenContext:=TCocoaContext.Create;
439
1260
Result:=HDC(ScreenContext);
445
function TCocoaWidgetSet.DeleteObject(GDIObject: HGDIOBJ): Boolean;
447
gdi: TCocoaGDIObject;
450
gdi:=CheckGDIOBJ(GdiObject);
451
if Assigned(gdi) then gdi.Release;
1264
// ToDo: Not finished yet
1267
{ if NSObject(hWnd) is TCocoaGroupBox then ctx := TCocoaGroupBox(hWnd).Context;
1271
// use dummy context if we are outside paint event
1274
ctx := TCocoaContext.Create({NSObject(HWnd)});
1279
{$IFDEF VerboseWinAPI}
1280
DebugLn('[TCocoaWidgetSet.GetDC] hWnd: %x Result: %x', [hWnd, Result]);
1284
function TCocoaWidgetSet.GetDeviceCaps(DC: HDC; Index: Integer): Integer;
1289
if not Assigned(ctx) then
1292
// todo: change implementation for printers
1295
Result := Round(NSScreen.mainScreen.frame.size.width / 72 * 25.4);
1297
Result := Round(NSScreen.mainScreen.frame.size.height / 72 * 25.4);
1299
Result := Round(NSScreen.mainScreen.frame.size.width);
1301
Result := CGDisplayBitsPerPixel(CGMainDisplayID);
1311
Result := Round(NSScreen.mainScreen.frame.size.height);
1315
DebugLn('TCocoaWidgetSet.GetDeviceCaps TODO Index: ' + DbgS(Index));
1319
function TCocoaWidgetSet.GetDeviceSize(DC: HDC; var P: TPoint): Boolean;
1324
Result := Assigned(ctx);
1333
function TCocoaWidgetSet.GetFocus: HWND;
1337
Result := HWND(NSApp.keyWindow);
1340
Obj := NSWindow(Result).firstResponder;
1341
if Assigned(Obj) and Obj.isKindOfClass(NSView) then
1342
Result := HWND(Obj);
1346
function TCocoaWidgetSet.GetForegroundWindow: HWND;
1348
// App: NSRunningApplication;
1350
// return the currect active window in the system
1351
{ this is not possible because we can't access another application NSApplication
1352
for App in NSWorkSpace.sharedWorkspace.runningApplications do
1353
if App.isActive then
1355
Result := HWND(App.keyWindow);
1359
if NSApp.isActive then
1360
Result := HWND(NSApp.keyWindow)
1365
function TCocoaWidgetSet.GetKeyState(nVirtKey: Integer): Smallint;
1367
StateDown = SmallInt($FF80);
1368
StateToggled = SmallInt($0001);
1369
DownMap: array[Boolean] of SmallInt = (0, StateDown);
1370
ToggleMap: array[Boolean] of SmallInt = (0, StateToggled);
1372
Modifiers: NSUInteger;
1374
Modifiers := NSApp.currentEvent.modifierFlags;
1378
// the ssAlt/VK_MENU is mapped to optionKey under MacOS
1379
Result := DownMap[(Modifiers and NSAlternateKeyMask) <> 0];
1382
Result := DownMap[(Modifiers and NSShiftKeyMask) <> 0];
1385
Result := DownMap[(Modifiers and NSControlKeyMask) <> 0];
1387
Result := DownMap[(Modifiers and NSCommandKeyMask) <> 0];
1389
Result := ToggleMap[(Modifiers and NSAlphaShiftKeyMask) <> 0];
1391
Result := DownMap[(GetCurrentEventButtonState and $01) <> 0];
1393
Result := DownMap[(GetCurrentEventButtonState and $02) <> 0];
1395
Result := DownMap[(GetCurrentEventButtonState and $03) <> 0];
1397
Result := DownMap[(GetCurrentEventButtonState and $04) <> 0];
1399
Result := DownMap[(GetCurrentEventButtonState and $05) <> 0];
454
1405
function TCocoaWidgetSet.SelectObject(ADC: HDC; GDIObj: HGDIOBJ): HGDIOBJ;
1580
function TCocoaWidgetSet.SetCursor(ACursor: HCURSOR): HCURSOR;
1582
Result := HCURSOR(TCocoaCursor(ACursor).Install);
1585
function TCocoaWidgetSet.SetCursorPos(X, Y: Integer): Boolean;
1593
if CGWarpMouseCursorPosition(CursorPos) <> noErr then Exit;
1597
function TCocoaWidgetSet.SetFocus(Handle: HWND): HWND;
1603
if Result = Handle then
1605
Obj := NSObject(Handle);
1606
if Obj.isKindOfClass(NSWindow) then
1608
NSWindow(Obj).makeKeyWindow;
1609
NSWindow(Obj).makeFirstResponder(nil);
1612
if Obj.isKindOfClass(NSView) then
1614
NSView(Obj).window.makeKeyWindow;
1615
NSView(Obj).window.makeFirstResponder(NSView(Obj));
1620
function TCocoaWidgetSet.SetForegroundWindow(HWnd: HWND): boolean;
1624
Result := HWnd <> 0;
1627
NSApp.activateIgnoringOtherApps(True);
1628
Obj := NSObject(HWnd);
1629
if Obj.isKindOfClass(NSWindow) then
1630
NSwindow(Obj).makeKeyAndOrderFront(NSApp)
1632
if Obj.isKindOfClass(NSView) then
1633
NSView(Obj).window.makeKeyAndOrderFront(NSApp)
555
1639
{------------------------------- FONT AND TEXT --------------------------------}
557
function TCocoaWidgetSet.CreateFontIndirect(const LogFont: TLogFont): HFONT;
559
Result:=CreateFontIndirectEx(LogFont, LogFont.lfFaceName);
562
function TCocoaWidgetSet.CreateFontIndirectEx(const LogFont: TLogFont;
563
const LongFontName: string): HFONT;
567
cf:=TCocoaFont.Create;
568
cf.Size:=LogFont.lfHeight;
569
cf.Name:=LongFontName;
570
if LogFont.lfWeight>FW_NORMAL then Include(cf.Style, cfs_Bold);
571
if LogFont.lfItalic>0 then Include(cf.Style, cfs_Italic);
572
if LogFont.lfUnderline>0 then Include(cf.Style, cfs_Underline);
573
if LogFont.lfStrikeOut>0 then Include(cf.Style, cfs_Strikeout);
574
cf.Antialiased:=logFont.lfQuality>=ANTIALIASED_QUALITY;
578
function TCocoaWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint;
579
Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
584
Result:=Assigned(ctx);
585
if not Assigned(ctx) then Exit;
586
ctx.TextOut(X,Y, Str, Count, Dx);
589
1641
function TCocoaWidgetSet.SetTextColor(DC: HDC; Color: TColorRef): TColorRef;
594
if not Assigned(ctx) then begin
599
Result:=RGBToColorFloat(TR, TG, TB);
600
ColorToRGBFloat(Color, TR, TG, TB);
1646
if Assigned(ctx) then
1648
Result := ctx.TextColor;
1649
ctx.TextColor := Color
1652
Result := CLR_INVALID;
1655
function TCocoaWidgetSet.ShowCaret(Handle: HWND): Boolean;
1659
Result := (Handle <> 0);
1662
Obj := NSObject(Handle);
1663
if Obj.isKindOfClass(NSView) then
1664
Result := CocoaCaret.ShowCaret(NSView(Handle))
1666
if Obj.isKindOfClass(NSWindow) then
1667
Result := CocoaCaret.ShowCaret(NSWindow(Handle).contentView)
1673
{------------------------------------------------------------------------------
1674
Method: GetSystemMetrics
1675
Params: NIndex - System metric to retrieve
1676
Returns: The requested system metric value
1678
Retrieves various system metrics.
1679
------------------------------------------------------------------------------}
1680
function TCocoaWidgetSet.GetSystemMetrics(nIndex: Integer): Integer;
1684
{$IFDEF VerboseWinAPI}
1685
DebugLn('TCocoaWidgetSet.GetSystemMetrics NIndex: ' + DbgS(NIndex));
1693
Result := 10;//GetCarbonThemeMetric(kThemeMetricScrollBarWidth);}
1695
SM_CXVIRTUALSCREEN: Result := Round(NSScreen.mainScreen.frame.size.width);
1697
SM_CYVIRTUALSCREEN: Result := Round(NSScreen.mainScreen.frame.size.height);
1698
SM_XVIRTUALSCREEN: Result := Round(NSScreen.mainScreen.frame.origin.x);
1699
SM_YVIRTUALSCREEN: Result := Round(NSScreen.mainScreen.frame.origin.y);
1709
{ if TCarbonCursor.HardwareCursorsSupported then
1714
Result := 16;//GetCarbonThemeMetric(kThemeMetricScrollBarMinThumbWidth);
1716
Result := 16;//GetCarbonThemeMetric(kThemeMetricScrollBarMinThumbHeight);}
1717
SM_SWSCROLLBARSPACING:
1720
DebugLn('TCocoaWidgetSet.GetSystemMetrics TODO ', DbgS(NIndex));;
1723
{$IFDEF VerboseWinAPI}
1724
DebugLn('TCocoaWidgetSet.GetSystemMetrics Result: ' + DbgS(Result));
604
1728
function TCocoaWidgetSet.GetTextColor(DC: HDC) : TColorRef;
1733
if Assigned(ctx) then
1734
Result := ctx.TextColor
1736
Result := CLR_INVALID;
1739
{------------------------------------------------------------------------------
1740
Method: GetTextExtentPoint
1741
Params: DC - Handle of device context
1743
Count - Number of characters in string
1744
Size - The record for the dimensions of the string
1745
Returns: If the function succeeds
1747
Computes the width and height of the specified string of text
1748
------------------------------------------------------------------------------}
1749
function TCocoaWidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean;
606
1751
ctx : TCocoaContext;
1753
{$IFDEF VerboseWinAPI}
1754
DebugLn('[TCocoaWidgetSet.GetTextExtentPoint] DC: %x Str: %s Count: %d', [DC, Str, Count]);
608
1756
ctx:=CheckDC(DC);
609
if not Assigned(ctx) then begin
613
with ctx do Result:=RGBToColorFloat(TR, TG, TB);
616
function TCocoaWidgetSet.TextOut(DC: HDC; X,Y : Integer; Str : Pchar; Count: Integer) : Boolean;
618
Result:=ExtTextOut(DC, X, Y, 0, nil, Str, Count, nil);
621
function TCocoaWidgetSet.EnumFontFamiliesEx(DC: HDC; lpLogFont: PLogFont;
622
Callback: FontEnumExProc; Lparam: LParam; Flags: dword): longint;
1757
Result:=Assigned(ctx);
1758
if not Assigned(ctx) then Exit(False);
1759
Result := ctx.GetTextExtentPoint(Str, Count, Size);
1760
{$IFDEF VerboseWinAPI}
1761
DebugLn('[TCocoaWidgetSet.GetTextExtentPoint] Size: %d,%d', [Size.cx, Size.cy]);
1765
{------------------------------------------------------------------------------
1766
Method: GetTextMetrics
1767
Params: DC - Handle of device context
1768
TM - The Record for the text metrics
1769
Returns: If the function succeeds
1771
Fills the specified buffer with the metrics for the currently selected font
1772
TODO: get exact max. and av. char width, pitch and charset
1773
------------------------------------------------------------------------------}
1774
function TCocoaWidgetSet.GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean;
624
fontManager : NSFontManager;
1779
Result := Assigned(ctx) and ctx.GetTextMetrics(TM);
629
ELogFont : TEnumLogFontEx;
630
Metric : TNewTextMetricEx;
631
FontName : AnsiString;
1782
function TCocoaWidgetSet.TextOut(DC: HDC; X,Y: Integer; Str: Pchar; Count: Integer) : Boolean;
634
if not Assigned(Callback) then Exit;
635
fontManager:=NSFontManager.sharedFontManager;
636
arr:=fontManager.availableFontFamilies;
637
for i:=0 to arr.count-1 do begin
638
fname:=NSString(arr.objectAtIndex(i));
640
FontName:=NSStringToString(fname);
641
FillChar(ELogFont, SizeOf(ELogFont), #0);
642
FillChar(Metric, SizeOf(Metric), #0);
643
ELogFont.elfLogFont.lfFaceName := FontName;
644
ELogFont.elfFullName := FontName;
645
//todo: read the data from all fonts of the fontfamily
646
Result:=CallBack(ELogFont, Metric, TRUETYPE_FONTTYPE, lparam);
647
if Result=0 then Break;
1784
Result := ExtTextOut(DC, X, Y, 0, nil, Str, Count, nil);
655
1787
function TCocoaWidgetSet.SaveDC(DC: HDC): Integer;
660
1791
ctx := CheckDC(DC);
661
if not Assigned(ctx) then begin
666
if Assigned(cg) then begin
667
CGContextSaveGState(cg);
1792
if Assigned(ctx) then
1793
Result := ctx.SaveDC
1798
function TCocoaWidgetSet.ScreenToClient(Handle: HWND; var P: TPoint): Integer;
1800
Result := Ord(Handle <> 0);
1804
// 1. convert screen to window
1805
NSObject(Handle).lclScreenToLocal(P.X, P.Y);
1806
// 2. convert window to client
1807
with NSObject(Handle).lclClientFrame do
1815
function TCocoaWidgetSet.SelectClipRGN(DC: hDC; RGN: HRGN): Longint;
1817
Result := ExtSelectClipRgn(DC, RGN, RGN_COPY);
1820
function TCocoaWidgetSet.SetSysColors(cElements: Integer; const lpaElements; const lpaRgbValues): Boolean;
1827
if cElements > MAX_SYS_COLORS then Exit;
1829
for n := 0 to cElements - 1 do
1831
Element := PInteger(@lpaElements)[n];
1832
if (Element > MAX_SYS_COLORS) or (Element < 0) then
1834
Color := ColorToNSColor(PDWord(@lpaRgbValues)[n]);
1835
if (FSysColorBrushes[Element] <> 0) then
1836
TCocoaBrush(FSysColorBrushes[Element]).Color := Color
1838
FSysColorBrushes[Element] := HBrush(TCocoaBrush.Create(Color, True));
674
1844
function TCocoaWidgetSet.RestoreDC(DC: HDC; SavedDC: Integer): Boolean;
682
1848
ctx := CheckDC(DC);
684
if not Assigned(ctx) or not Assigned(cg) then Exit;
686
if SavedDC<0 then cnt:=1
687
else cnt:=ctx.Stack-SavedDC+1;
691
for i:=1 to cnt do CGContextRestoreGState(cg);
1849
if Assigned(ctx) then
1850
Result := ctx.RestoreDC(SavedDC)
1855
function TCocoaWidgetSet.RoundRect(DC: HDC; X1, Y1, X2, Y2: Integer; RX,
1856
RY: Integer): Boolean;
1858
Result:=inherited RoundRect(DC, X1, Y1, X2, Y2, RX, RY);
696
1861
//##apiwiz##eps## // Do not remove, no wizard declaration after this line