From f0a111408b97f6eccc8a56a75537a72b0045f879 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Tue, 24 Jun 2008 02:29:33 +0000 Subject: [PATCH] Improves Cocoa widgetset git-svn-id: trunk@15555 - --- .gitattributes | 2 + lcl/interfaces/cocoa/cocoaint.pas | 8 +- lcl/interfaces/cocoa/cocoaobject.inc | 1 + lcl/interfaces/cocoa/cocoaprivate.pp | 25 +++- lcl/interfaces/cocoa/cocoawinapi.inc | 65 +++++++++ lcl/interfaces/cocoa/cocoawinapih.inc | 198 ++++++++++++++++++++++++++ lcl/interfaces/cocoa/cocoawsforms.pp | 4 +- 7 files changed, 292 insertions(+), 11 deletions(-) create mode 100644 lcl/interfaces/cocoa/cocoawinapi.inc create mode 100644 lcl/interfaces/cocoa/cocoawinapih.inc diff --git a/.gitattributes b/.gitattributes index 8b97eebe36..ebd4326cde 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3100,6 +3100,8 @@ lcl/interfaces/cocoa/Makefile.fpc svneol=native#text/plain lcl/interfaces/cocoa/cocoaint.pas svneol=native#text/plain lcl/interfaces/cocoa/cocoaobject.inc svneol=native#text/plain lcl/interfaces/cocoa/cocoaprivate.pp svneol=native#text/plain +lcl/interfaces/cocoa/cocoawinapi.inc svneol=native#text/plain +lcl/interfaces/cocoa/cocoawinapih.inc svneol=native#text/plain lcl/interfaces/cocoa/cocoawsforms.pp svneol=native#text/plain lcl/interfaces/cocoa/cocoawsstdctrls.pp svneol=native#text/plain lcl/interfaces/cocoa/interfaces.pas svneol=native#text/plain diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index bb338d3438..11d1ce802a 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -41,8 +41,8 @@ uses ctypes, objc, foundation, appkit, // interfacebase InterfaceBase, - // widgetset -// CarbonGDIObjects, + // private + CocoaPrivate, // LCL LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType; // GraphType, GraphMath, Graphics, Controls, Forms, Dialogs, Menus, Maps, Themes; @@ -107,7 +107,7 @@ type // lParam: LParam; out Target: EventTargetRef): EventRef; // the winapi compatibility methods -// {$I carbonwinapih.inc} + {$I cocoawinapih.inc} // the extra LCL interface methods // {$I carbonlclintfh.inc} @@ -154,7 +154,7 @@ uses // the implementation of the utility methods {$I cocoaobject.inc} // the implementation of the winapi compatibility methods -//{$I Cocoawinapi.inc} +{$I cocoawinapi.inc} // the implementation of the extra LCL interface methods //{$I Cocoalclintf.inc} diff --git a/lcl/interfaces/cocoa/cocoaobject.inc b/lcl/interfaces/cocoa/cocoaobject.inc index 1fbb575122..8810ee3dc5 100644 --- a/lcl/interfaces/cocoa/cocoaobject.inc +++ b/lcl/interfaces/cocoa/cocoaobject.inc @@ -129,6 +129,7 @@ begin DebugLn('TCocoaWidgetSet.AppTerminate'); {$ENDIF} + NSApp.terminate(nil); end; {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index 4d7e1d93a7..695b4aa30a 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -125,21 +125,31 @@ begin end; procedure TCocoaControl.InitializeFields; +var + ParentHeight: Single; begin + ParentHeight := 0; + CFTitle := CFStringCreateWithPascalString(nil, LCLControl.Caption, kCFStringEncodingUTF8); - ControlRect.origin.x := LCLControl.Left; - ControlRect.origin.y := LCLControl.Top; - ControlRect.size.width := LCLControl.Width; - ControlRect.size.height := LCLControl.Height; - + // Get's information form the parent if LCLControl.Parent <> nil then begin if LCLControl.Parent is TCustomForm then begin ParentView := TCocoaForm(LCLControl.Parent.Handle).MainWindowView; + ParentHeight := ParentView.frame.size.height; end; end; + + // Calculates the position on the Screen + // Cocoa and LCL declare differently the coordinates system + // In LCL (0,0) is in the top-left corner without title, + // and in Cocoa it is in the bottom-left corner + ControlRect.origin.x := LCLControl.Left; + ControlRect.origin.y := ParentHeight - LCLControl.Top; + ControlRect.size.width := LCLControl.Width; + ControlRect.size.height := LCLControl.Height; end; procedure TCocoaControl.InitializeControl; @@ -155,12 +165,15 @@ begin inherited Create(AWinControl, AParams); Control := NSButton.initWithFrame(ControlRect); + + InitializeControl(); + Button.setTitle(CFTitle); Button.setBezelStyle(NSRoundedBezelStyle); Button.setAction(sel_registerName(PChar(Str_Button_OnClick))); Button.setTarget(Handle); - if ParentView <> nil then ParentView.addSubview(Button); + if ParentView <> nil then ParentView.addSubview(Button.Handle); end; function TCocoaButton.Button: NSButton; diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc new file mode 100644 index 0000000000..fb424a3868 --- /dev/null +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -0,0 +1,65 @@ +{%MainUnit cocoaint.pp} +{ $Id: cocoawinapi.inc 15525 2008-06-23 06:39:58Z paul $ } +{****************************************************************************** + All Cocoa Winapi implementations. + This are the implementations of the overrides of the Cocoa Interface for the + methods defined in the + lcl/include/winapi.inc + + + !! Keep alphabetical !! + + + ****************************************************************************** + Implementation + ****************************************************************************** + + ***************************************************************************** + * * + * 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. * + * * + ***************************************************************************** +} + +//##apiwiz##sps## // Do not remove, no wizard declaration before this line + +{------------------------------------------------------------------------------ + function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; + + nCmdShow: + SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED +------------------------------------------------------------------------------} +function TCocoaWidgetSet.ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; +var + CocoaForm: TCocoaForm; +begin + {$ifdef VerboseCocoaWinAPI} + WriteLn('[WinAPI ShowWindow]'); + {$endif} + + Result := False; + + CocoaForm := TCocoaForm(hWnd); + + if CocoaForm <> nil then + begin + case nCmdShow of + SW_SHOW: CocoaForm.MainWindow.orderFront(nil); + SW_SHOWNORMAL: CocoaForm.MainWindow.orderFront(nil); +// SW_MINIMIZE: Widget.setWindowState(QtWindowMinimized); +// SW_SHOWMINIMIZED: Widget.ShowMinimized; +// SW_SHOWMAXIMIZED: Widget.ShowMaximized; + SW_HIDE: CocoaForm.MainWindow.orderOut(nil); + end; + Result := True; + end; +end; + +//##apiwiz##eps## // Do not remove, no wizard declaration after this line diff --git a/lcl/interfaces/cocoa/cocoawinapih.inc b/lcl/interfaces/cocoa/cocoawinapih.inc new file mode 100644 index 0000000000..6ef55fd675 --- /dev/null +++ b/lcl/interfaces/cocoa/cocoawinapih.inc @@ -0,0 +1,198 @@ +{%MainUnit cocoaint.pas} + +{****************************************************************************** + All Cocoa Winapi related stuff goes here. + This are the overrides of the Cocoa Interface for the methods defined in the + lcl/include/winapih.inc + + !! Keep this alphabetical !! + + ****************************************************************************** + Interface + ****************************************************************************** + + ***************************************************************************** + * * + * 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. * + * * + ***************************************************************************** +} + +//##apiwiz##sps## // Do not remove, no wizard declaration before this line + +{function Arc(DC: HDC; Left,Top,Right,Bottom,angle1,angle2 : Integer): Boolean; override; +function AngleChord(DC: HDC; x1, y1, x2, y2, angle1, angle2: Integer): Boolean; override; + +function BeginPaint(Handle: hWnd; Var PS : TPaintStruct) : hdc; override; +function BitBlt(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, YSrc: Integer; Rop: DWORD): Boolean; override; + +function CallNextHookEx(hHk: HHOOK; ncode : Integer; wParam: WParam; lParam : LParam) : Integer; override; +function CallWindowProc(lpPrevWndFunc : TFarProc; Handle : HWND; Msg : UINT; wParam: WParam; lParam : lParam) : Integer; override; +function ClientToScreen(Handle: HWND; var P: TPoint) : Boolean; override; + +function ClipboardFormatToMimeType(FormatID: TClipboardFormat): string; override; +function ClipboardGetData(ClipboardType: TClipboardType; + FormatID: TClipboardFormat; Stream: TStream): boolean; override; +// ! List will be created. You must free it yourself with FreeMem(List) ! +function ClipboardGetFormats(ClipboardType: TClipboardType; + var Count: integer; var List: PClipboardFormat): boolean; override; +function ClipboardGetOwnerShip(ClipboardType: TClipboardType; + OnRequestProc: TClipboardRequestEvent; FormatCount: integer; + Formats: PClipboardFormat): boolean; override; +function ClipboardRegisterFormat(const AMimeType: string): TClipboardFormat; override; + +function CombineRgn(Dest, Src1, Src2: HRGN; fnCombineMode: Longint): Longint; override; +function ComboBoxDropDown(Handle: HWND; DropDown: boolean): boolean; 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 CreateCompatibleBitmap(DC: HDC; Width, Height: Integer): HBITMAP; override; +function CreateCompatibleDC(DC: HDC): HDC; override; +function CreateEllipticRgn(p1, p2, p3, p4: Integer): HRGN; override; +function CreateFontIndirect(const LogFont: TLogFont): HFONT; override; +function CreateFontIndirectEx(const LogFont: TLogFont; const LongFontName: string): HFONT; override; +function CreateIconIndirect(IconInfo: PIconInfo): HICON; override; +function CreatePenIndirect(const LogPen: TLogPen): HPEN; override; +function CreatePolygonRgn(Points: PPoint; NumPts: Integer; FillMode: integer): HRGN; override; +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 DestroyIcon(Handle: HICON): Boolean; override; +function DPtoLP(DC: HDC; var Points; Count: Integer): BOOL; override; +function DrawFocusRect(DC: HDC; const Rect: TRect): boolean; override; +function DrawEdge(DC: HDC; var Rect: TRect; edge: Cardinal; grfFlags: Cardinal): Boolean; override; +function DrawText(DC: HDC; Str: PChar; Count: Integer; var ARect: TRect; Flags: Cardinal): Integer; override; + +function Ellipse(DC: HDC; x1, y1, x2, y2: Integer): Boolean; override; +function EnableScrollBar(Wnd: HWND; wSBflags, wArrows: Cardinal): Boolean; override; +function EnableWindow(hWnd: HWND; bEnable: Boolean): Boolean; override; +function EndPaint(Handle: hwnd; var PS: TPaintStruct): Integer; override; +procedure EnterCriticalSection(var CritSection: TCriticalSection); override; +function EnumFontFamiliesEx(DC: HDC; lpLogFont: PLogFont; Callback: FontEnumExProc; Lparam: LParam; Flags: dword): longint; override; +function ExcludeClipRect(dc: hdc; Left, Top, Right, Bottom : Integer) : Integer; override; +function ExtSelectClipRGN(dc: hdc; rgn : hrgn; Mode : Longint) : Integer; override; +function ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean; override; + +function FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean; override; +function FillRgn(DC: HDC; RegionHnd: HRGN; hbr: HBRUSH): Bool; override; +function Frame(DC: HDC; const ARect: TRect): Integer; override; +function Frame3d(DC: HDC; var ARect: TRect; const FrameWidth : integer; const Style : TBevelCut): Boolean; override; +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 GetCapture: HWND; override; +function GetCaretPos(var lpPoint: TPoint): 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; +function GetClipRGN(DC: hDC; RGN: hRGN): Longint; override; +function GetCursorPos(var lpPoint: TPoint ): Boolean; override; +function GetDC(hWnd: HWND): HDC; override; +function GetDCOriginRelativeToWindow(PaintDC: HDC; WindowHandle: HWND; var OriginDiff: TPoint): boolean; override; +function GetDeviceCaps(DC: HDC; Index: Integer): Integer; override; +function GetDeviceSize(DC: HDC; var P: TPoint): Boolean; Override; +function GetDIBits(DC: HDC; Bitmap: HBitmap; StartScan, NumScans: UINT; Bits: Pointer; var BitInfo: BitmapInfo; Usage: UINT): Integer; Override; +function GetFocus: HWND; override; +function GetKeyState(nVirtKey: Integer): Smallint; override; +function GetObject(GDIObj: HGDIOBJ; BufSize: Integer; Buf: Pointer): Integer; override; +function GetParent(Handle : HWND): HWND; override; +function GetProp(Handle : hwnd; Str : PChar): Pointer; override; +function GetRgnBox(RGN : HRGN; lpRect : PRect) : Longint; override; +function GetROP2(DC: HDC): Integer; override; +function GetScrollBarSize(Handle: HWND; BarKind: Integer): integer; override; +function GetScrollbarVisible(Handle: HWND; SBStyle: Integer): boolean; override; +function GetScrollInfo(Handle: HWND; BarFlag: Integer; Var ScrollInfo: TScrollInfo): Boolean; override; +function GetStockObject(Value: Integer): THandle; override; +function GetSysColor(nIndex: Integer): DWORD; override; +function GetSystemMetrics(nIndex: Integer): Integer; override; +function GetTextColor(DC: HDC) : TColorRef; Override; +function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; override; +function GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean; override; +function GetWindowLong(Handle : hwnd; int: Integer): PtrInt; override; +function GetWindowOrgEx(dc : hdc; P : PPoint): Integer; override; +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; + +function HideCaret(hWnd: HWND): Boolean; override; + +function InvalidateRect(aHandle : HWND; Rect : pRect; bErase : Boolean) : Boolean; override; +procedure InitializeCriticalSection(var CritSection: TCriticalSection); override; +function IntersectClipRect(dc: hdc; Left, Top, Right, Bottom: Integer): Integer; override; +function IsWindowEnabled(Handle: HWND): boolean; override; +function IsWindowVisible(Handle: HWND): boolean; override; + +procedure LeaveCriticalSection(var CritSection: TCriticalSection); override; +function LineTo(DC: HDC; X, Y: Integer): Boolean; override; + +function MessageBox(hWnd: HWND; lpText, lpCaption: PChar; uType: Cardinal): integer; override; +function MoveToEx(DC: HDC; X, Y: Integer; OldPoint: PPoint): Boolean; override; + +function PeekMessage(var lpMsg : TMsg; Handle : HWND; wMsgFilterMin, wMsgFilterMax,wRemoveMsg : UINT): Boolean; override; +function PolyBezier(DC: HDC; Points: PPoint; NumPts: Integer; Filled, Continuous: boolean): boolean; override; +function Polygon(DC: HDC; Points: PPoint; NumPts: Integer; Winding: boolean): boolean; override; +function Polyline(DC: HDC; Points: PPoint; NumPts: Integer): boolean; override; +function PostMessage(Handle: HWND; Msg: Cardinal; wParam: WParam; lParam: LParam): Boolean; override; + +function Rectangle(DC: HDC; X1, Y1, X2, Y2: Integer): Boolean; override; +function RectVisible(dc : hdc; const ARect: TRect) : Boolean; override; +function ReleaseCapture : Boolean; override; +function ReleaseDC(hWnd: HWND; DC: HDC): Integer; override; +function RestoreDC(DC: HDC; SavedDC: Integer): Boolean; override; +function RoundRect(DC : hDC; X1, Y1, X2, Y2: Integer; RX,RY : Integer): Boolean; override; + +function SaveDC(DC: HDC): Integer; override; +function ScreenToClient(Handle : HWND; var P : TPoint) : Integer; override; +function SelectClipRGN(DC : hDC; RGN : HRGN) : Longint; override; +function SelectObject(DC: HDC; GDIObj: HGDIOBJ): HGDIOBJ; override; +function SendMessage(HandleWnd: HWND; Msg: Cardinal; WParam: WParam; LParam: LParam): LResult; override; +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 SetCaretPos(X, Y: Integer): Boolean; override; +function SetCaretPosEx(Handle: HWnd; X, Y: Integer): 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(hWnd: HWND): HWND; override; +function SetForegroundWindow(HWnd: HWND): boolean; override; +function SetProp(Handle: hwnd; Str : PChar; Data : Pointer) : Boolean; override; +function SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer; 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 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; + SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; ROp: Cardinal): Boolean; override; +function StretchMaskBlt(DestDC: HDC; X, Y, Width, Height: Integer; + SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; Mask: HBITMAP; + XMask, YMask: Integer; Rop: DWORD): Boolean; override; +function SystemParametersInfo(uiAction: DWord; uiParam: DWord; pvParam: Pointer; fWinIni: DWord): LongBool; override; + +function TextOut(DC: HDC; X,Y : Integer; Str : Pchar; Count: Integer) : Boolean; override; +function UpdateWindow(Handle: HWND): Boolean; override; +function WindowFromPoint(Point: TPoint): HWND; override;} + +//##apiwiz##eps## // Do not remove, no wizard declaration after this line + + + + + + diff --git a/lcl/interfaces/cocoa/cocoawsforms.pp b/lcl/interfaces/cocoa/cocoawsforms.pp index c1a699b2f3..543e0435bc 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pp +++ b/lcl/interfaces/cocoa/cocoawsforms.pp @@ -157,7 +157,9 @@ var begin CocoaForm := TCocoaForm(ACustomForm.Handle); - CocoaForm.MainWindow.orderFrontRegardless; + if AWinControl.Visible then + CocoaForm.MainWindow.orderFrontRegardless() + else CocoaForm.MainWindow.orderOut(nil); end; initialization