From 6dfa26faa8663ad4a050f4cda6da3b9551d470e3 Mon Sep 17 00:00:00 2001 From: dmitry Date: Fri, 17 May 2019 00:29:46 +0000 Subject: [PATCH] cocoa: adding theme update notification git-svn-id: trunk@61235 - --- lcl/interfaces/cocoa/cocoathemes.pas | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lcl/interfaces/cocoa/cocoathemes.pas b/lcl/interfaces/cocoa/cocoathemes.pas index 40b038e565..db12188072 100644 --- a/lcl/interfaces/cocoa/cocoathemes.pas +++ b/lcl/interfaces/cocoa/cocoathemes.pas @@ -30,6 +30,7 @@ type TCocoaThemeServices = class(TThemeServices) private protected + callback : NSObject; BtnCell : NSButtonCell; function SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails): Boolean; procedure SetButtonCellToDetails(btn: NSButtonCell; Details: TThemedElementDetails); @@ -58,6 +59,7 @@ type BezelToolBar : NSBezelStyle; BezelButton : NSBezelStyle; constructor Create; + destructor Destroy; override; procedure DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect; ClipRect: PRect); override; (* procedure DrawEdge({%H-}DC: HDC; {%H-}Details: TThemedElementDetails; const {%H-}R: TRect; {%H-}Edge, {%H-}Flags: Cardinal; {%H-}AContentRect: PRect); override; @@ -92,6 +94,11 @@ function NSAppearanceClass: pobjc_class; implementation +type + TCocoaThemeCallback = objcclass(NSObject) + procedure notifySysColorsChanged(notification: NSNotification); message 'notifySysColorsChanged:'; + end; + type TCocoaContextAccess = class(TCocoaContext); @@ -624,6 +631,18 @@ begin BtnCell := NSButtonCell.alloc.initTextCell(NSSTR('')); BezelToolBar := NSSmallSquareBezelStyle; // can be resized at any size BezelButton := NSSmallSquareBezelStyle; + + callback := TCocoaThemeCallback.alloc.init; + NSNotificationCenter(NSNotificationCenter.defaultCenter).addObserver_selector_name_object( + callback, ObjCSelector('notifySysColorsChanged:'), NSSystemColorsDidChangeNotification, nil + ); +end; + +destructor TCocoaThemeServices.Destroy; +begin + NSNotificationCenter(NSNotificationCenter.defaultCenter).removeObserver(callback); + callback.release; + inherited Destroy; end; (*function TCarbonThemeServices.DrawWindowElement(DC: TCarbonDeviceContext; @@ -1027,6 +1046,14 @@ begin NSGraphicsContext.setCurrentContext( cur ); end; +{ TCocoaThemeCallback } + +procedure TCocoaThemeCallback.notifySysColorsChanged(notification: NSNotification); +begin + ThemeServices.UpdateThemes; + Graphics.UpdateHandleObjects; + ThemeServices.IntfDoOnThemeChange; +end; end.