From 892ed4877e77da78f9baa48b2bd1b314100e5c68 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Thu, 4 Apr 2024 22:23:14 +0200 Subject: [PATCH] NSBox: (re-)implement isOpaque (#254) This (re-)implements logic where a box is marked as opaque if it is a custom box which is not transparent, but moves the logic to `GSTheme`, allowing themes to override this loggic. This fixes the rendering of custom boxes with a custom fill color; the current implementation would mark them as non-opaque and hence the fill color would not be rendered. - The original implementation (from 1999) always returned `YES` (53bcb5024020fe85e370d9d49297aca4320d7768) - A more complete implementation was backported from the Testplant branch in 2012 (e85b16bc05d5d513788c09b470fd09ad5f888882, by @fredkiefer, upstream commit 36e77b95f7921e9539fdc0c115fe4039fa573150) - More recently, the a return value of `NO` was hardcoded (02bc49e2d5336e9092001e3d56cb43750a8466a3, by @ericwa) --- Headers/Additions/GNUstepGUI/GSTheme.h | 2 ++ Source/GSThemeDrawing.m | 12 ++++++++++++ Source/NSBox.m | 13 +------------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index b936087fd..dff07525d 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -1339,6 +1339,8 @@ APPKIT_EXPORT_CLASS clipRect: (NSRect)clipRect inView: (NSView *)view; +- (BOOL) isBoxOpaque: (NSBox *)box; + - (void) drawBoxInClipRect: (NSRect)clipRect boxType: (NSBoxType)boxType borderType: (NSBorderType)borderType diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index 773386076..046b0793b 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -3475,6 +3475,18 @@ - (void) drawTableViewRow: (NSInteger)rowIndex } } +- (BOOL) isBoxOpaque: (NSBox *)box +{ + if ([box boxType] == NSBoxCustom) + { + return ![box isTransparent]; + } + else + { + return YES; + } +} + - (void) drawBoxInClipRect: (NSRect)clipRect boxType: (NSBoxType)boxType borderType: (NSBorderType)borderType diff --git a/Source/NSBox.m b/Source/NSBox.m index f41a47d40..12f4e88a0 100644 --- a/Source/NSBox.m +++ b/Source/NSBox.m @@ -464,18 +464,7 @@ - (void) drawRect: (NSRect)rect - (BOOL) isOpaque { - // FIXME: Depends on theme; if always returning NO is a performance hit - // we can check if GSTheme is going to draw an old-style opaque box - // or not. - return NO; - // if (_box_type == NSBoxCustom) - // { - // return !_transparent; - // } - // else - // { - // return YES; - // } + return [[GSTheme theme] isBoxOpaque: self]; } - (NSColor*) fillColor