changeset 2206:70460d0afd03

Mac: Attempt to restore the Container/Listbox focus rings. This used to work before switching to NSView based instead of NSCell based NSTableViews.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 30 Nov 2020 23:11:08 +0000
parents a43a3f80ed32
children 7c1e46dbc858
files mac/dw.m
diffstat 1 files changed, 40 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Sun Nov 29 08:31:47 2020 +0000
+++ b/mac/dw.m	Mon Nov 30 23:11:08 2020 +0000
@@ -2417,6 +2417,45 @@
 }
 #endif
 
+@interface DWFocusRingScrollView : NSScrollView
+{
+    BOOL shouldDrawFocusRing;
+    NSResponder* lastResp;
+}
+@end
+
+@implementation DWFocusRingScrollView
+-(BOOL)needsDisplay;
+{
+    NSResponder* resp = nil;
+    
+    if([[self window] isKeyWindow])
+    {
+        resp = [[self window] firstResponder];
+        if (resp == lastResp)
+            return [super needsDisplay];
+    }
+    else if (lastResp == nil)
+    {
+        return [super needsDisplay];
+    }
+    shouldDrawFocusRing = (resp != nil && [resp isKindOfClass:[NSView class]] && [(NSView*)resp isDescendantOf:self]);
+    lastResp = resp;
+    [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
+    return YES;
+}
+-(void)drawRect:(NSRect)rect
+{
+    [super drawRect:rect];
+                                                                                                    
+    if(shouldDrawFocusRing)
+    {
+        NSSetFocusRingStyle(NSFocusRingOnly);
+        NSRectFill(rect);
+    }
+}
+@end
+
 /* Subclass for a Container/List type */
 @interface DWContainer : NSTableView
 #ifdef BUILDING_FOR_SNOW_LEOPARD
@@ -5759,7 +5798,7 @@
 /* Internal common function to create containers and listboxes */
 HWND _dw_cont_new(ULONG cid, int multi)
 {
-    NSScrollView *scrollview  = [[NSScrollView alloc] init];
+    DWFocusRingScrollView *scrollview  = [[DWFocusRingScrollView alloc] init];
     DWContainer *cont = [[DWContainer alloc] init];
 
     [cont setScrollview:scrollview];