cocoa: adding theme update notification

git-svn-id: trunk@61235 -
This commit is contained in:
dmitry 2019-05-17 00:29:46 +00:00
parent ab3b8df7cc
commit 6dfa26faa8

View File

@ -30,6 +30,7 @@ type
TCocoaThemeServices = class(TThemeServices) TCocoaThemeServices = class(TThemeServices)
private private
protected protected
callback : NSObject;
BtnCell : NSButtonCell; BtnCell : NSButtonCell;
function SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails): Boolean; function SetButtonCellType(btn: NSButtonCell; Details: TThemedElementDetails): Boolean;
procedure SetButtonCellToDetails(btn: NSButtonCell; Details: TThemedElementDetails); procedure SetButtonCellToDetails(btn: NSButtonCell; Details: TThemedElementDetails);
@ -58,6 +59,7 @@ type
BezelToolBar : NSBezelStyle; BezelToolBar : NSBezelStyle;
BezelButton : NSBezelStyle; BezelButton : NSBezelStyle;
constructor Create; constructor Create;
destructor Destroy; override;
procedure DrawElement(DC: HDC; Details: TThemedElementDetails; const R: TRect; ClipRect: PRect); 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; 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 implementation
type
TCocoaThemeCallback = objcclass(NSObject)
procedure notifySysColorsChanged(notification: NSNotification); message 'notifySysColorsChanged:';
end;
type type
TCocoaContextAccess = class(TCocoaContext); TCocoaContextAccess = class(TCocoaContext);
@ -624,6 +631,18 @@ begin
BtnCell := NSButtonCell.alloc.initTextCell(NSSTR('')); BtnCell := NSButtonCell.alloc.initTextCell(NSSTR(''));
BezelToolBar := NSSmallSquareBezelStyle; // can be resized at any size BezelToolBar := NSSmallSquareBezelStyle; // can be resized at any size
BezelButton := NSSmallSquareBezelStyle; 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; end;
(*function TCarbonThemeServices.DrawWindowElement(DC: TCarbonDeviceContext; (*function TCarbonThemeServices.DrawWindowElement(DC: TCarbonDeviceContext;
@ -1027,6 +1046,14 @@ begin
NSGraphicsContext.setCurrentContext( cur ); NSGraphicsContext.setCurrentContext( cur );
end; end;
{ TCocoaThemeCallback }
procedure TCocoaThemeCallback.notifySysColorsChanged(notification: NSNotification);
begin
ThemeServices.UpdateThemes;
Graphics.UpdateHandleObjects;
ThemeServices.IntfDoOnThemeChange;
end;
end. end.