Skip to content

Commit 7fa2c1a

Browse files
committed
BookMacster 1.19.6, shipped
1 parent e42f017 commit 7fa2c1a

4 files changed

+36
-84
lines changed

SSYOperationQueue.m

+7-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,13 @@ - (void)observeValueForKeyPath:(NSString*)keyPath
233233
// Being built with Mac OS X 10.9 or later SDK
234234
id activity = [self noAppNapActivity] ;
235235
if (activity) {
236-
[[NSProcessInfo processInfo] endActivity:activity];
236+
// The following test is actually defensive programming, because
237+
// activity should only be YES if NSProcessInfo
238+
// responds to -beginActivityWithOptions:reason:,
239+
// which means that it should also respond to -endActivity:
240+
if ([[NSProcessInfo processInfo] respondsToSelector:@selector(endActivity:)]) {
241+
[[NSProcessInfo processInfo] endActivity:activity] ;
242+
}
237243
}
238244
#endif
239245

SSYPopUpTableHeaderCell.h

+2-36
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,8 @@
1313
or http://lists.apple.com/archives/cocoa-dev/2005/Apr/msg01223.html
1414
but I've made enough improvements to it that I decided it deserves
1515
to have my own SSY prefix.
16-
17-
The instance variable realSelf is to work around in case a bug occurs:
18-
19-
I have a subclass of NSPopUpButtonCell which I use in place of an NSTableHeaderCell,
20-
providing a popup menu so that the user can choose what attribute is displayed in the column.
21-
This subclass retains an instance variable, which I call a templateHeaderCell. This instance
22-
variable is a NSTableHeaderCell which it uses to draw the empty table header when needed.
23-
24-
Two of my table columns, in their -awakeFromNib, create one of these cells, and set them as
25-
their headerCell. From NSLog in my subclass' -init, I see that these are the only two
26-
instances of my subclass which are ever created.
27-
28-
However, when clicking on the table column which causes redrawing, my subclass' -drawWithFrame:inView:
29-
is invoked by a third instance, one with a different 'self' value, of my subclass. But it's
30-
worse -- the address of its -templateHeaderCell instance variable is the same as that in one of
31-
the two ^real^ instances. So, it's like an identity theft. The thief has the instance variables
32-
of the real object.
33-
34-
Apparently, whatever created the thief did not retain it, because it is soon deallocced, causing
35-
its instance variables to be deallocced, and things kind of go downhill from there when the ^real^
36-
instance comes back later and tries to access them :(
37-
38-
In order to work around this, during -init, I set another instance variable named 'realSelf':
39-
[self setRealSelf:self] ;
40-
And then during -drawWithFrame:inView: and -dealloc, test before doing anything with:
41-
if (self != [self realSelf])
42-
If this occurs I log an error and return.
43-
44-
This only happens if a column is resized without resizing other columns to compensate. I have
45-
seen another column created in this case and suspect the other column is the one that created
46-
the thief.
47-
*/
48-
@interface SSYPopUpTableHeaderCell : NSPopUpButtonCell {
49-
// A bug catcher. See long explanation in class documentation details
50-
SSYPopUpTableHeaderCell* realSelf ;
51-
16+
*/
17+
@interface SSYPopUpTableHeaderCell : NSPopUpButtonCell {
5218
CGFloat lostWidth ;
5319
}
5420

SSYPopUpTableHeaderCell.m

+8-47
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,36 @@
22

33
@interface SSYPopUpTableHeaderCell ()
44

5-
@property (retain) SSYPopUpTableHeaderCell* realSelf ;
65
@property CGFloat lostWidth ;
6+
77
@end
88

99

1010
@implementation SSYPopUpTableHeaderCell
1111

12-
@synthesize realSelf ;
1312
@synthesize lostWidth ;
1413

14+
- (id)copyWithZone:(NSZone *)zone {
15+
SSYPopUpTableHeaderCell* copy = [[SSYPopUpTableHeaderCell allocWithZone: zone] init] ;
16+
[copy setLostWidth:[self lostWidth]] ;
17+
18+
return copy ;
19+
}
20+
1521
- (id)init {
16-
#if LOG_UNREAL_SSY_POP_UP_TABLE_HEADER_CELLS
17-
BOOL didReinitialize = NO ;
18-
if (realSelf) {
19-
NSLog(@"Internal Error 340-8282 Re-initializing? oldSelf = %p realSelf = %p", self, realSelf) ;\
20-
didReinitialize = YES ;
21-
}
22-
#endif
2322
if (self = [super init]) {
24-
25-
#if LOG_UNREAL_SSY_POP_UP_TABLE_HEADER_CELLS
26-
if (didReinitialize) {
27-
NSLog(@"Internal Error 340-8257 Re-initializing? newSelf = %p realSelf = %p", self, realSelf) ;\
28-
}
29-
#endif
3023
// Set up the popup cell attributes
3124
[self setControlSize:NSMiniControlSize] ;
3225
[self setBordered:NO] ;
3326
[self setBezeled:NO] ;
3427
[self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]] ;
35-
36-
// Our mysterious bug catcher
37-
[self setRealSelf:self] ;
3828
}
3929

4030
return self ;
4131
}
4232

43-
/*- (void)stopTracking:(NSPoint)lastPoint
44-
at:(NSPoint)stopPoint
45-
inView:(NSView *)controlView
46-
mouseIsUp:(BOOL)flag {
47-
NSLog(@"1068 %s", __PRETTY_FUNCTION__) ;
48-
}
49-
*/
50-
51-
- (void)dealloc {
52-
if (self != [self realSelf]) {
53-
#if LOG_UNREAL_SSY_POP_UP_TABLE_HEADER_CELLS
54-
NSLog(@"Internal Error 340-9281 in %s", __PRETTY_FUNCTION__) ;
55-
#endif
56-
return ;
57-
}
58-
59-
[realSelf release] ;
60-
[super dealloc] ;
61-
}
62-
6333
- (void)drawWithFrame:(NSRect)cellFrame
6434
inView:(NSView*)controlView {
65-
if (self != [self realSelf]) {
66-
#if LOG_UNREAL_SSY_POP_UP_TABLE_HEADER_CELLS
67-
NSLog(@"Internal Error 300-9481 in %s", __PRETTY_FUNCTION__) ;
68-
NSLog(@" self: %p %@ %p %p %@", self, NSStringFromSize([self cellSize]), [self itemArray], [self controlView], [[self selectedItem] title]) ;
69-
NSLog(@" realSelf: %p %@ %p %p %@", realSelf, NSStringFromSize([realSelf cellSize]), [realSelf itemArray], [realSelf controlView], [[self selectedItem] title]) ;
70-
#endif
71-
return ;
72-
}
73-
7435
// Apple's documentation for this -[NSCell drawWithFrame:inView: states
7536
// "This method draws the cell in the currently focused view,
7637
// which can be different from the controlView passed in. Taking advantage

SSYTableHeaderView.m

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@
44
@implementation SSYTableHeaderView : NSTableHeaderView
55

66
- (void)drawRect:(NSRect)dirtyRect {
7+
/*
8+
Added in BookMacster 1.19.6. After eliminating the realSelf crap from
9+
SSYPopUpTableHeaderCell, when closing a document once, I got a failure in
10+
this method, at end where it invokes [headerCell drawWithFrame:inView:],
11+
an assertion was raised in -[NSView lockFocus].
12+
13+
** Assertion failure in -[SSYTableHeaderView lockFocus], /SourceCache/AppKit/AppKit-1265/AppKit.subproj/NSView.m:7041
14+
2013-11-15 06:52:03.413 BookMacster[11590:303] -[SSYTableHeaderView(0x6080003ab6e0) lockFocus] failed with window=0x6000001f6700, windowNumber=-1, [self isHiddenOrHasHiddenAncestor]=0
15+
16+
Poking around with the
17+
debugger, it seems that while the window controller is still around, its
18+
-document is nil, and furthermore
19+
[[NSDocumentController sharedDocumentController] documents] returns an
20+
empty set. So it seems like the following should fix this problem…
21+
*/
22+
if ([[[self window] windowController] document] == nil) {
23+
return ;
24+
}
25+
726
CGFloat height = [self frame].size.height ;
827
CGFloat overallWidth = [self frame].size.width ;
928
CGFloat intercellWidth = [[self tableView] intercellSpacing].width ;

0 commit comments

Comments
 (0)