cocoa: add implementation for winapi caret functions

git-svn-id: trunk@34446 -
This commit is contained in:
paul 2011-12-27 07:19:09 +00:00
parent 548a38c43c
commit d2a0cd5d20
5 changed files with 104 additions and 26 deletions

View File

@ -35,7 +35,7 @@ uses
// Free Pascal
Classes, SysUtils, Types,
// Widgetset
CocoaGDIObjects, CocoaInt, CocoaPrivate,
CocoaGDIObjects, CocoaPrivate,
// LCL
LCLType, LCLIntf, LCLProc, Graphics, Controls, ExtCtrls, Forms;

View File

@ -1283,14 +1283,14 @@ end;
procedure TCocoaContext.InvertRectangle(X1, Y1, X2, Y2: Integer);
begin
// save dest context
CGContextSaveGState(CGContext);
ctx.saveGraphicsState;
try
DefaultBrush.Apply(Self, False);
CGContextSetBlendMode(CGContext, kCGBlendModeDifference);
CGContextFillRect(CGContext, GetCGRectSorted(X1, Y1, X2, Y2));
finally
CGContextRestoreGState(CGContext);
ctx.restoreGraphicsState;
end;
end;

View File

@ -116,10 +116,6 @@ function TCocoaWidgetSet.CreateBitmap(Width, Height: Integer;
var
bmpType: TCocoaBitmapType;
begin
{$IFDEF VerboseWinAPI}
DebugLn('TCocoaWidgetSet.CreateBitmap');
{$ENDIF}
// WORKAROUND: force context supported depths
if BitmapBits = nil then
begin
@ -144,12 +140,27 @@ begin
Result := HBrush(TCocoaBrush.Create(LogBrush));
end;
function TCocoaWidgetSet.CreateCaret(Handle: HWND; Bitmap: hBitmap; Width,
Height: Integer): Boolean;
var
Obj: NSObject;
begin
Result := (Handle <> 0);
if Result then
begin
Obj := NSObject(Handle);
if Obj.isKindOfClass(NSView) then
Result := CocoaCaret.CreateCaret(NSView(Handle), Bitmap, Width, Height)
else
if Obj.isKindOfClass(NSWindow) then
Result := CocoaCaret.CreateCaret(NSWindow(Handle).contentView, Bitmap, Width, Height)
else
Result := False;
end;
end;
function TCocoaWidgetSet.CreateCompatibleBitmap(DC: HDC; Width, Height: Integer): HBITMAP;
begin
{$IFDEF VerboseWinAPI}
DebugLn('TCocoaWidgetSet.CreateCompatibleBitmap');
{$ENDIF}
Result := HBITMAP(TCocoaBitmap.Create(Width, Height, 32, 32, cbaDQWord, cbtARGB, nil));
end;
@ -162,10 +173,6 @@ end;
------------------------------------------------------------------------------}
function TCocoaWidgetSet.CreateCompatibleDC(DC: HDC): HDC;
begin
{$IFDEF VerboseWinAPI}
DebugLn('TCocoaWidgetSet.CreateCompatibleDC');
{$ENDIF}
Result := HDC(TCocoaContext.Create);
end;
@ -306,6 +313,11 @@ begin
if gdi.RefCount = 0 then gdi.Destroy;
end;
function TCocoaWidgetSet.DestroyCaret(Handle: HWND): Boolean;
begin
Result := CocoaCaret.DestroyCaret;
end;
function TCocoaWidgetSet.DestroyIcon(Handle: HICON): Boolean;
var
Ico: TObject;
@ -518,6 +530,17 @@ begin
Result := CLR_INVALID;
end;
function TCocoaWidgetSet.GetCaretPos(var lpPoint: TPoint): Boolean;
begin
Result := CocoaCaret.GetCaretPos(lpPoint);
end;
function TCocoaWidgetSet.GetCaretRespondToFocus(handle: HWND;
var ShowHideOnFocus: boolean): Boolean;
begin
Result := inherited GetCaretRespondToFocus(handle, ShowHideOnFocus);
end;
{------------------------------------------------------------------------------
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean;
@ -837,6 +860,24 @@ begin
end;
end;
function TCocoaWidgetSet.HideCaret(Handle: HWND): Boolean;
var
Obj: NSObject;
begin
Result := (Handle <> 0);
if Result then
begin
Obj := NSObject(Handle);
if Obj.isKindOfClass(NSView) then
Result := CocoaCaret.HideCaret(NSView(Handle))
else
if Obj.isKindOfClass(NSWindow) then
Result := CocoaCaret.HideCaret(NSWindow(Handle).contentView)
else
Result := False;
end;
end;
function TCocoaWidgetSet.InvalidateRect(aHandle : HWND; Rect : pRect; bErase : Boolean): Boolean;
begin
Result := aHandle <> 0;
@ -1430,6 +1471,22 @@ begin
Result := 0;
end;
function TCocoaWidgetSet.SetCaretPos(X, Y: Integer): Boolean;
begin
Result := CocoaCaret.SetCaretPos(X, Y);
end;
function TCocoaWidgetSet.SetCaretPosEx(Handle: HWnd; X, Y: Integer): Boolean;
begin
Result := CocoaCaret.SetCaretPos(X, Y);
end;
function TCocoaWidgetSet.SetCaretRespondToFocus(handle: HWND;
ShowHideOnFocus: boolean): Boolean;
begin
Result:=inherited SetCaretRespondToFocus(handle, ShowHideOnFocus);
end;
function TCocoaWidgetSet.RectVisible(DC: HDC; const ARect: TRect): Boolean;
var
ClipBox: CGRect;
@ -1551,6 +1608,24 @@ begin
Result := CLR_INVALID;
end;
function TCocoaWidgetSet.ShowCaret(Handle: HWND): Boolean;
var
Obj: NSObject;
begin
Result := (Handle <> 0);
if Result then
begin
Obj := NSObject(Handle);
if Obj.isKindOfClass(NSView) then
Result := CocoaCaret.ShowCaret(NSView(Handle))
else
if Obj.isKindOfClass(NSWindow) then
Result := CocoaCaret.ShowCaret(NSWindow(Handle).contentView)
else
Result := False;
end;
end;
{------------------------------------------------------------------------------
Method: GetSystemMetrics
Params: NIndex - System metric to retrieve

View File

@ -51,7 +51,7 @@ function ClipboardRegisterFormat(const AMimeType: string): TClipboardFormat; ove
function CombineRgn(Dest, Src1, Src2: HRGN; fnCombineMode: Longint): Longint; override;
function CreateBitmap(Width, Height: Integer; Planes, BitCount: Longint; BitmapBits: Pointer): HBITMAP; override;
function CreateBrushIndirect(const LogBrush: TLogBrush): HBRUSH; override;
{function CreateCaret(Handle : HWND; Bitmap : hBitmap; Width, Height : Integer) : Boolean; override;}
function CreateCaret(Handle : HWND; Bitmap : hBitmap; Width, Height : Integer) : Boolean; override;
function CreateCompatibleBitmap(DC: HDC; Width, Height: Integer): HBITMAP; override;
function CreateCompatibleDC(DC: HDC): HDC; override;
{function CreateEllipticRgn(p1, p2, p3, p4: Integer): HRGN; override;}
@ -64,7 +64,7 @@ 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 DrawFocusRect(DC: HDC; const Rect: TRect): boolean; override;
@ -91,9 +91,9 @@ function FrameRect(DC: HDC; const ARect: TRect; hBr: HBRUSH): Integer; override;
function GetActiveWindow: HWND; override;
{function GetBitmapBits(Bitmap: HBITMAP; Count: Longint; Bits: Pointer): Longint; override;}
function GetBkColor(DC: HDC): TColorRef; override;
{function GetCapture: HWND; override;
{function GetCapture: HWND; override;}
function GetCaretPos(var lpPoint: TPoint): Boolean; override;
function GetCaretRespondToFocus(handle: HWND; var ShowHideOnFocus: boolean): Boolean; override;}
function GetCaretRespondToFocus(handle: HWND; var ShowHideOnFocus: boolean): Boolean; override;
function GetClientBounds(handle : HWND; var ARect : TRect) : Boolean; override;
function GetClientRect(handle : HWND; var ARect : TRect) : Boolean; override;
function GetClipBox(DC : hDC; lpRect : PRect) : Longint; override;
@ -129,9 +129,9 @@ function GetWindowRect(Handle: hwnd; var ARect: TRect): Integer; override;
function GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; override;
function GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean; override;
{function GradientFill(DC: HDC; Vertices: PTriVertex; NumVertices : Longint;
Meshes: Pointer; NumMeshes : Longint; Mode : Longint): Boolean; override;
Meshes: Pointer; NumMeshes : Longint; Mode : Longint): Boolean; override;}
function HideCaret(hWnd: HWND): Boolean; override;}
function HideCaret(Handle: HWND): Boolean; override;
function InvalidateRect(aHandle : HWND; Rect : pRect; bErase : Boolean) : Boolean; override;
procedure InitializeCriticalSection(var CritSection: TCriticalSection); override;
@ -166,10 +166,10 @@ function SendMessage(Handle: HWND; Msg: Cardinal; WParam: WParam; LParam: LParam
function SetActiveWindow(Handle: HWND): HWND; override;
function SetBKColor(DC: HDC; Color: TColorRef): TColorRef; override;
function SetBkMode(DC: HDC; bkMode : Integer) : Integer; override;
{function SetCapture(AHandle: HWND): HWND; 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(Handle: HWND): HWND; override;
@ -179,8 +179,8 @@ function SetROP2(DC: HDC; Mode: Integer): Integer; override;
function SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer; override;
function SetSysColors(cElements: Integer; const lpaElements; const lpaRgbValues): Boolean; override;
function SetTextColor(DC: HDC; Color: TColorRef): TColorRef; override;
{function SetWindowOrgEx(DC : HDC; NewX, NewY : Integer; OldPoint: PPoint) : Boolean; override;
function ShowCaret(hWnd: HWND): Boolean; override;}
{function SetWindowOrgEx(DC : HDC; NewX, NewY : Integer; OldPoint: PPoint) : Boolean; override;}
function ShowCaret(Handle: HWND): Boolean; override;
function ShowScrollBar(Handle: HWND; wBar: Integer; bShow: Boolean): Boolean; override;
function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; override;
function StretchBlt(DestDC: HDC; X, Y, Width, Height: Integer;

View File

@ -11,7 +11,7 @@ uses
Classes, Controls, SysUtils,
//
WSControls, LCLType, LMessages, LCLProc, Forms,
CocoaPrivate, CocoaGDIObjects, CocoaUtils, LCLMessageGlue;
CocoaPrivate, CocoaGDIObjects, CocoaCaret, CocoaUtils, LCLMessageGlue;
type
@ -137,6 +137,7 @@ begin
Owner := AOwner;
Target := ATarget;
FContext := nil;
FHasCaret := False;
FPropStorage := TStringList.Create;
FPropStorage.Sorted := True;
FPropStorage.Duplicates := dupAccept;
@ -274,6 +275,8 @@ begin
FillChar(struct, SizeOf(TPaintStruct), 0);
struct.hdc := HDC(FContext);
LCLSendPaintMsg(Target, HDC(FContext), @struct);
if FHasCaret then
DrawCaret;
end;
finally
FreeAndNil(FContext);