From e5212b707b239b6058b8984e729e3ec328b8e6a3 Mon Sep 17 00:00:00 2001 From: dmitry Date: Wed, 12 Jun 2019 18:23:40 +0000 Subject: [PATCH] cocoa: implemented form icons git-svn-id: trunk@61369 - --- lcl/interfaces/cocoa/cocoaobject.inc | 2 +- lcl/interfaces/cocoa/cocoawsforms.pas | 51 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lcl/interfaces/cocoa/cocoaobject.inc b/lcl/interfaces/cocoa/cocoaobject.inc index a0993c0eb6..834c67e24c 100644 --- a/lcl/interfaces/cocoa/cocoaobject.inc +++ b/lcl/interfaces/cocoa/cocoaobject.inc @@ -273,7 +273,6 @@ begin lcCanDrawOutsideOnPaint, lcNeedMininimizeAppWithMainForm, lcApplicationTitle, - lcFormIcon, {$ifndef COCOA_USE_NATIVE_MODAL} lcModalWindow, {$endif} @@ -282,6 +281,7 @@ begin {$ifdef COCOA_USE_NATIVE_MODAL} lcModalWindow, {$endif} + lcFormIcon, lcAntialiasingEnabledByDefault, lcTransparentWindow, lcCanDrawHidden: diff --git a/lcl/interfaces/cocoa/cocoawsforms.pas b/lcl/interfaces/cocoa/cocoawsforms.pas index 4bcad61aea..88e4d8bd63 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pas +++ b/lcl/interfaces/cocoa/cocoawsforms.pas @@ -31,6 +31,7 @@ uses WSForms, WSLCLClasses, WSProc, LCLMessageGlue, // LCL Cocoa CocoaPrivate, CocoaUtils, CocoaWSCommon, CocoaWSStdCtrls, CocoaWSMenus, + CocoaGDIObjects, CocoaWindows, CocoaScrollers, cocoa_extra; type @@ -128,6 +129,7 @@ type class procedure SetBorderIcons(const AForm: TCustomForm; const ABorderIcons: TBorderIcons); override; class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); override; class procedure SetFormStyle(const AForm: TCustomform; const AFormStyle, AOldFormStyle: TFormStyle); override; + class procedure SetIcon(const AForm: TCustomForm; const Small, Big: HICON); override; class procedure SetRealPopupParent(const ACustomForm: TCustomForm; const APopupParent: TCustomForm); override; class procedure ShowHide(const AWinControl: TWinControl); override; @@ -603,10 +605,35 @@ class procedure TCocoaWSCustomForm.UpdateWindowIcons(AWindow: NSWindow; end; end; +var + btn : NSButton; + url : NSURL; + b : NSBundle; + +const + // mimic Windows border styles + isIconVisible : array [TFormBorderStyle] of Boolean = ( + false, // bsNone + true, // bsSingle + true, // bsSizeable + false, // bsDialog + false, // bsToolWindow + false // bsSizeToolWin + ); + begin SetWindowButtonState(NSWindowMiniaturizeButton, biMinimize in ABorderIcons, (ABorderStyle in [bsSingle, bsSizeable]) and (biSystemMenu in ABorderIcons)); SetWindowButtonState(NSWindowZoomButton, (biMaximize in ABorderIcons) and (ABorderStyle in [bsSizeable, bsSizeToolWin]), (ABorderStyle in [bsSingle, bsSizeable]) and (biSystemMenu in ABorderIcons)); SetWindowButtonState(NSWindowCloseButton, True, (ABorderStyle <> bsNone) and (biSystemMenu in ABorderIcons)); + + btn := AWindow.standardWindowButton(NSWindowDocumentIconButton); + url := nil; + if isIconVisible[ABorderStyle] then + begin + b := NSBundle.mainBundle; + if Assigned(b) then url := b.bundleURL; + end; + AWindow.setRepresentedURL(url); end; class procedure TCocoaWSCustomForm.UpdateWindowMask(AWindow: NSWindow; @@ -977,6 +1004,30 @@ begin end; end; +class procedure TCocoaWSCustomForm.SetIcon(const AForm: TCustomForm; + const Small, Big: HICON); +var + win : NSWindow; + trg : NSImage; + btn : NSButton; +begin + if not AForm.HandleAllocated then Exit; + + win := TCocoaWindowContent(AForm.Handle).lclOwnWindow; + if Assigned(win) then + begin + if Small <> 0 then + trg := TCocoaBitmap(Small).image + else if Big <> 0 then + trg := TCocoaBitmap(Big).image + else + trg := nil; + + btn := win.standardWindowButton(NSWindowDocumentIconButton); + if Assigned(btn) then btn.setImage(trg); + end; +end; + class procedure TCocoaWSCustomForm.SetRealPopupParent( const ACustomForm: TCustomForm; const APopupParent: TCustomForm); var