From 051ffb68b3e5c3572550502ef166348653cfc038 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Tue, 10 Jul 2018 19:14:56 +0200 Subject: [PATCH] Post a notification when mouse enters/leaves OakRolloverButton --- Frameworks/OakAppKit/src/OakRolloverButton.h | 3 +++ Frameworks/OakAppKit/src/OakRolloverButton.mm | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/Frameworks/OakAppKit/src/OakRolloverButton.h b/Frameworks/OakAppKit/src/OakRolloverButton.h index f3d2618d..95555ac4 100644 --- a/Frameworks/OakAppKit/src/OakRolloverButton.h +++ b/Frameworks/OakAppKit/src/OakRolloverButton.h @@ -1,5 +1,8 @@ #include +extern NSString* const OakRolloverButtonMouseDidEnterNotification; +extern NSString* const OakRolloverButtonMouseDidLeaveNotification; + PUBLIC @interface OakRolloverButton : NSButton @property (nonatomic) NSImage* regularImage; @property (nonatomic) NSImage* pressedImage; diff --git a/Frameworks/OakAppKit/src/OakRolloverButton.mm b/Frameworks/OakAppKit/src/OakRolloverButton.mm index 36f669a0..343ee594 100644 --- a/Frameworks/OakAppKit/src/OakRolloverButton.mm +++ b/Frameworks/OakAppKit/src/OakRolloverButton.mm @@ -1,5 +1,8 @@ #import "OakRolloverButton.h" +NSString* const OakRolloverButtonMouseDidEnterNotification = @"OakRolloverButtonMouseDidEnterNotification"; +NSString* const OakRolloverButtonMouseDidLeaveNotification = @"OakRolloverButtonMouseDidLeaveNotification"; + typedef NS_ENUM(NSUInteger, OakImageState) { OakImageStateRegular = 0, OakImageStatePressed, @@ -163,7 +166,11 @@ typedef NS_ENUM(NSUInteger, OakImageState) { { if(_mouseInside == flag) return; + _mouseInside = flag; [self updateImage]; + + NSString* notification = _mouseInside ? OakRolloverButtonMouseDidEnterNotification : OakRolloverButtonMouseDidLeaveNotification; + [NSNotificationCenter.defaultCenter postNotificationName:notification object:self]; } @end