Skip to content

Commit 3aeafb6

Browse files
committed
• Many changes to support Dark Mode in macOS 10.14.
• Two subclasses which do not play well with Dark Mode, and whose purpose is better served by other means now available in the Cocoa AppKit, have been deleted. • Fixed bug which could cause crash in edge case of SSYPopUpTableHeaderCell. • Added to SSYVectorImages a new style: SSYVectorImageStyleChasingArrowsFilled. • Property NSImage.name is now added to the *returned* image in SSYVectorImages.
1 parent a514809 commit 3aeafb6

15 files changed

+289
-185
lines changed

SSYAlert.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,6 @@ - (void)stealObjectsFromAppleAlerts {
823823
[image lockFocus] ;
824824
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
825825
CGFloat borderWength = 8.0 ;
826-
#warning Check this in Dark Mode
827826
[rawIcon drawInRect:NSMakeRect(
828827
borderWength,
829828
borderWength,
@@ -848,11 +847,11 @@ - (void)stealObjectsFromAppleAlerts {
848847
badge = [SSYVectorImages imageStyle:SSYVectorImageStyleHexagon
849848
wength:64.0
850849
color:[NSColor yellowColor]
850+
darkModeView:nil // Ignored since we passed in a constant `color`
851851
rotateDegrees:90.0
852852
inset:12.0] ;
853853
[image lockFocus] ;
854854
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
855-
#warning Check this in Dark Mode
856855
[badge drawInRect:NSMakeRect(
857856
[image size].width / 2,
858857
0,
@@ -875,11 +874,11 @@ - (void)stealObjectsFromAppleAlerts {
875874
badge = [SSYVectorImages imageStyle:SSYVectorImageStyleHexagon
876875
wength:64.0
877876
color:[NSColor redColor]
877+
darkModeView:nil // Ignored since we passed in a constant `color`
878878
rotateDegrees:90.0
879879
inset:12.0] ;
880880
[image lockFocus] ;
881881
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
882-
#warning Check this in Dark Mode
883882
[badge drawInRect:NSMakeRect(
884883
[image size].width / 2,
885884
0,

SSYMenuAddButton.h

-21
This file was deleted.

SSYMenuAddButton.m

-32
This file was deleted.

SSYMenuGearButton.h

-27
This file was deleted.

SSYMenuGearButton.m

-29
This file was deleted.

SSYMultiTextFieldCell.m

+5-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ - (NSRect)drawAtLeftImage:(NSImage*)image
6666
NSRectFill(imageFrame);
6767
}
6868

69-
[image drawInvertedIfDarkModeInRect:imageFrame
70-
operation:NSCompositingOperationPlusDarker
71-
fraction:1.0
72-
appearanceView:controlView];
69+
[image drawInRect:imageFrame
70+
operation:NSCompositingOperationPlusDarker
71+
fraction:1.0
72+
invertIfDarkMode:YES
73+
inView:controlView];
7374
}
7475

7576
return cellFrame ;

SSYPopUpTableHeaderCell.m

+26-17
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ - (void)drawWithFrame:(NSRect)cellFrame
221221
[path stroke] ;
222222
}
223223

224-
[[NSColor blackColor] set] ;
224+
[[NSColor controlTextColor] set] ;
225225

226226
if ([self isUserDefined]) {
227227
// Draw the upper arrow that points up
@@ -246,26 +246,35 @@ - (void)drawWithFrame:(NSRect)cellFrame
246246
CGFloat xMargin = 1.0 * scaleFactor ;
247247
CGFloat yMargin = 3.7 * scaleFactor ;
248248
NSPoint titlePoint = NSMakePoint(NSMinX(cellFrame) + xMargin, yMargin) ;
249-
NSAttributedString* attributedTitle ;
249+
NSPoint point = cellFrame.origin ;
250+
point.x = point.x + [tableView intercellSpacing].width ;
251+
point.y = point.y + [tableView intercellSpacing].height ;
252+
NSInteger columnIndex = [tableView columnAtPoint:point];
253+
NSFont* font;
254+
if (columnIndex != -1) {
255+
NSArray <NSTableColumn <SSYPopupTableHeaderSortableColumn>*> * columns = (NSArray <NSTableColumn <SSYPopupTableHeaderSortableColumn>*> *)[tableView tableColumns];
256+
NSTableColumn <SSYPopupTableHeaderSortableColumn> * thisColumn = [columns objectAtIndex:columnIndex];
257+
font = [thisColumn headerFont];
258+
} else {
259+
/* This can happen if the window is being resized while loading,
260+
but I think it does not matter because we use the system
261+
default font anyhow. */
262+
font = nil;
263+
}
264+
NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
265+
[NSColor controlTextColor], NSForegroundColorAttributeName,
266+
font, NSFontAttributeName,
267+
nil] ;
268+
NSAttributedString* attributedTitle;
269+
NSString* string;
250270
if ([self fixedNonMenuTitle]) {
251-
NSTableView* tableView = [(NSTableHeaderView*)controlView tableView] ;
252-
NSPoint point = cellFrame.origin ;
253-
point.x = point.x + [tableView intercellSpacing].width ;
254-
point.y = point.y + [tableView intercellSpacing].height ;
255-
NSInteger columnIndex = [tableView columnAtPoint:point] ;
256-
NSArray <NSTableColumn <SSYPopupTableHeaderSortableColumn>*> * columns = (NSArray <NSTableColumn <SSYPopupTableHeaderSortableColumn>*> *)[tableView tableColumns] ;
257-
NSTableColumn <SSYPopupTableHeaderSortableColumn> * thisColumn = [columns objectAtIndex:columnIndex] ;
258-
NSFont* font = [thisColumn headerFont] ;
259-
NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
260-
font, NSFontAttributeName,
261-
nil] ;
262-
attributedTitle = [[NSAttributedString alloc] initWithString:[self fixedNonMenuTitle]
263-
attributes:attributes] ;
271+
string = [self fixedNonMenuTitle];
264272
}
265273
else {
266-
attributedTitle = [self attributedTitle] ;
267-
[attributedTitle retain] ;
274+
string = [[self attributedTitle] string];
268275
}
276+
attributedTitle = [[NSAttributedString alloc] initWithString:string
277+
attributes:attributes] ;
269278
NSAttributedString* truncatedTitle = [attributedTitle attributedStringTruncatedToWidth:cellFrame.size.width - xMargin
270279
height:cellFrame.size.height] ;
271280
[truncatedTitle drawAtPoint:titlePoint] ;

SSYPrefsWindowController.h

+11
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@
4444

4545
- (BOOL)revealTabViewIdentifier:(NSString*)identifier ;
4646

47+
/*!
48+
@brief Returns a special image for certain tab view items
49+
50+
@details Subclasses may override this to provide a special image for
51+
certain tab view items, for example if you want to use a home-made vector
52+
image. For other tab view items, return nil and the default
53+
[NSImage imageNamed:<item-identifier>] will be used. The default
54+
implementation returns nil regardless of the passed-ib identifier.
55+
*/
56+
- (NSImage*)specialImageForTabViewIdentifier:(NSString*)identifier;
57+
4758
@end

SSYPrefsWindowController.m

+9-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ -(NSToolbarItem *) toolbar: (NSToolbar *)toolbar itemForItemIdentifier: (NSStrin
201201

202202
// Set up a reasonable tooltip, and image Note, these aren't localized, but you will likely want to localize many of the item's properties
203203
[toolbarItem setToolTip: [self toolTipForIdentifier:itemIdent]];
204-
[toolbarItem setImage: [NSImage imageNamed:itemIdent]];
204+
NSImage* image = [self specialImageForTabViewIdentifier:itemIdent];
205+
if (!image) {
206+
image = [NSImage imageNamed:itemIdent];
207+
}
208+
[toolbarItem setImage:image];
205209

206210
// Tell the item what message to send when it is clicked
207211
[toolbarItem setTarget: self];
@@ -324,5 +328,9 @@ - (NSString*)localizeString:(NSString*)key {
324328
return key ;
325329
}
326330

331+
- (NSImage*)specialImageForTabViewIdentifier:(NSString*)identifier {
332+
return nil;
333+
}
334+
327335

328336
@end

SSYProgressView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ - (void)unsafeSetText:(NSString*)text
712712
NSFont* font = [NSFont systemFontOfSize:11.0] ;
713713
NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
714714
font, NSFontAttributeName,
715-
[NSColor blueColor], NSForegroundColorAttributeName,
715+
[NSColor controlTextColor], NSForegroundColorAttributeName,
716716
[NSNumber numberWithInteger:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName,
717717
nil] ;
718718
NSAttributedString* title = [[NSAttributedString alloc] initWithString:hyperText

SSYStarRatingView.m

+3
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,19 @@ - (id)initWithFrame:(NSRect)frame
4646
[self setStarImage:[SSYVectorImages imageStyle:SSYVectorImageStyleStar
4747
wength:starHeight
4848
color:[NSColor lightGrayColor]
49+
darkModeView:self
4950
rotateDegrees:0.0
5051
inset:0.0]] ;
5152
[self setStarHighlightedImage:[SSYVectorImages imageStyle:SSYVectorImageStyleStar
5253
wength:starHeight
5354
color:[NSColor blueColor]
55+
darkModeView:self
5456
rotateDegrees:0.0
5557
inset:0.0]] ;
5658
[self setRemoveXImage:[SSYVectorImages imageStyle:SSYVectorImageStyleRemoveX
5759
wength:(0.9 * starHeight)
5860
color:nil
61+
darkModeView:self
5962
rotateDegrees:0.0
6063
inset:0.0]] ;
6164
[self setEditable:YES] ;

SSYToolbarButton.h

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#import <Cocoa/Cocoa.h>
22

3-
43
/*!
54
@brief A toolbar item which has a tristate 'value' attribute,
65
and three each additional images, labels and tooltips which
@@ -14,6 +13,7 @@
1413
NSImage* m_onImage ;
1514
NSImage* m_offImage ;
1615
NSImage* m_disImage ;
16+
NSImage* m_backgroundImage;
1717
NSImage* m_originalImage ;
1818
NSString* m_onLabel ;
1919
NSString* m_offLabel ;
@@ -36,23 +36,29 @@
3636
@property (assign) NSInteger value ;
3737

3838
/*!
39-
@brief The image that will be displayed when the receiver's
40-
value is set to NSOnState.
39+
@brief The image that will be displayed when the receiver's value is
40+
NSOnState.
4141
*/
4242
@property (retain) NSImage* onImage ;
4343

4444
/*!
45-
@brief The image that will be displayed when the receiver's
46-
value is set to NSOnState.
45+
@brief The image that will be displayed when the receiver's value is
46+
NSOnState.
4747
*/
4848
@property (retain) NSImage* offImage ;
4949

5050
/*!
51-
@brief The image that will be displayed when the receiver's
52-
value is set to NSMixedState.
51+
@brief The image that will be displayed when the receiver's value is
52+
NSMixedState.
5353
*/
5454
@property (retain) NSImage* disImage ;
5555

56+
/*!
57+
@brief An image that will always be displayed regardless of the receiver's
58+
value.
59+
*/
60+
@property (retain) NSImage* backgroundImage;
61+
5662
/*!
5763
@brief The string that will be displayed under the button
5864
when the receiver's value is set to NSOnState. This value
@@ -116,3 +122,10 @@
116122
@property (assign) NSTimeInterval flashDuration ;
117123

118124
@end
125+
126+
@interface SSYToolbarButtonView : NSView
127+
128+
@property (weak) SSYToolbarButton* toolbarItem;
129+
130+
@end
131+

0 commit comments

Comments
 (0)