Skip to content

Commit b302e37

Browse files
committed
BookMacster 1.19.8, shipped.
1 parent b604227 commit b302e37

5 files changed

+194
-23
lines changed

SSMoveableToolTip.h

+18-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,30 @@
22

33
@interface SSMoveableToolTip : NSObject {
44
NSPoint _offset ;
5-
NSWindow* _window;
6-
NSTextField* _textField;
7-
NSDictionary* _textAttributes;
5+
NSWindow* _window ;
6+
NSTextField* _textField ;
87
}
98

9+
/*
10+
@brief Displays a moveable tool tip with given parameters
11+
12+
@details Any tooltip displayed by a prior invocation of this method
13+
disappears, so that there isonly one simultaneous moveable tooltip per app.
14+
If you really want more than one, talk to the User Interface Police :))
15+
@param font The font to be used in the tooltip. If you pass nil, defaults
16+
to [NSFont toolTipsFontOfSize:[NSFont systemFontSize]] which is what Cocoa
17+
uses.
18+
@param offset On 2013-12-04, removed hard-coded
19+
offset of (10.0, 28.0) in the implementation which was
20+
being added to the offset you pass here.
21+
*/
1022
+ (void)setString:(NSString *)string
23+
font:(NSFont*)font
1124
origin:(NSPoint)origin
1225
inWindow:(NSWindow*)hostWindow ;
26+
1327
+ (void)goAway ;
28+
1429
+ (void)setOffset:(NSPoint)offset ;
1530

1631
@end

SSMoveableToolTip.m

+31-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ - (void) drawRect:(NSRect)aRect
1919

2020
@implementation SSMoveableToolTip
2121

22-
- (id) init {
22+
- (id)init {
2323
self = [super init] ;
2424

2525
if (self != nil) {
@@ -49,59 +49,71 @@ - (id) init {
4949
[_textField setDrawsBackground:NO];
5050
[_textField setAlignment:NSLeftTextAlignment];
5151
[_textField setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
52-
[_textField setFont:[NSFont toolTipsFontOfSize:[NSFont smallSystemFontSize]]];
5352
[[_window contentView] addSubview:_textField];
5453

55-
[_textField setStringValue:@" "]; // Just having at least 1 char to allow the next message...
56-
_textAttributes = [[[_textField attributedStringValue] attributesAtIndex:0 effectiveRange:nil] retain];
5754
}
5855

5956
return self ;
6057
}
6158

6259
- (void) dealloc {
6360
[_window release] ;
64-
[_textAttributes release] ;
6561
[_textField release] ; // Memory leak fixed in BookMacster 1.17
6662

6763
[super dealloc];
6864
}
6965

70-
- (void) setString:(NSString *)string
66+
#define GRRRRR_MARGIN_REQUIRED_TO_SAFELY_PREVENT_TEXT_WRAPPING 10.0
67+
68+
- (void) setString:(NSString*)string
69+
font:(NSFont*)font
7170
origin:(NSPoint)origin
72-
inWindow:(NSWindow*)hostWindow
73-
{
71+
inWindow:(NSWindow*)hostWindow {
72+
if (!font) {
73+
font = [NSFont toolTipsFontOfSize:[NSFont smallSystemFontSize]] ;
74+
}
75+
76+
if ([string length] == 0) {
77+
string = @ " " ;
78+
}
79+
80+
[_textField setStringValue:string] ;
81+
[_textField setFont:font] ;
82+
83+
NSDictionary* textAttributes = [[_textField attributedStringValue] attributesAtIndex:0
84+
effectiveRange:nil] ;
7485
origin.x += _offset.x ;
7586
origin.y += _offset.y ;
7687

77-
NSSize size = [string sizeWithAttributes:_textAttributes];
78-
NSSize windowSize = NSMakeSize(size.width + 10, size.height + 1) ;
88+
NSSize size = [string sizeWithAttributes:textAttributes] ;
89+
NSSize windowSize = NSMakeSize(
90+
size.width + GRRRRR_MARGIN_REQUIRED_TO_SAFELY_PREVENT_TEXT_WRAPPING,
91+
size.height + 1
92+
) ;
7993

8094
NSPoint cursorScreenPosition = [hostWindow convertBaseToScreen:origin];
81-
82-
[_window setFrameTopLeftPoint:NSMakePoint(cursorScreenPosition.x + 10, cursorScreenPosition.y + 28)];
83-
[_window setContentSize:windowSize] ;
8495

85-
if (string) {
86-
[_textField setStringValue:string] ;
87-
}
88-
96+
// On 2013-12-04, removed hard-coded offsets in here which were for my app.
97+
// Any offset you need should be passed in the 'origin' parameter!
98+
[_window setFrameTopLeftPoint:NSMakePoint(cursorScreenPosition.x, cursorScreenPosition.y)];
99+
[_window setContentSize:windowSize] ;
89100
}
90101

91102
- (void)setOffset:(NSPoint)offset {
92103
_offset = offset ;
93104
}
94105

95-
+ (void) setString:(NSString *)string
106+
+ (void) setString:(NSString*)string
107+
font:(NSFont*)font
96108
origin:(NSPoint)origin
97109
inWindow:(NSWindow*)hostWindow
98110
{
99111
if (sharedToolTip == nil) {
100-
101112
sharedToolTip = [[SSMoveableToolTip alloc] init];
102113
}
103114

104115
[sharedToolTip setString:string
116+
font:font
105117
origin:origin
106118
inWindow:hostWindow];
107119
}

SSYAlert.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ - (void)display {
17601760
// See discussion:
17611761
// http://www.cocoabuilder.com/archive/message/cocoa/2007/4/9/181560
17621762
[[self window] display] ;
1763-
[[self window] makeKeyAndOrderFront:self] ;
1763+
[[self window] makeKeyAndOrderFront:self] ;
17641764
}
17651765

17661766
- (void)goAway {

SSYXMLPeeker.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface SSYXMLPeeker : NSObject <NSXMLParserDelegate> {
4+
NSMutableString* m_parsedValue ;
5+
NSError* m_error ;
6+
NSString* m_targetElement ;
7+
BOOL m_ignoreError ;
8+
}
9+
10+
/*
11+
@brief Parses an XML file at a given path and returns a the string value
12+
of a single given target element
13+
14+
@details This method returns synchronously.
15+
16+
@param error_p If a parse error occurs, and error_p is not NULL, upon
17+
return error_p will point to the parse error.
18+
19+
@result If the target element exists in the XML but does not have a string
20+
value, result is an empty string. If the target element does not exist in the
21+
XML, result is nil.
22+
*/
23+
+ (NSString*)stringValueOfElement:(NSString*)targetElement
24+
XMLFilePath:(NSString*)path
25+
error_p:(NSError**)error_p ;
26+
27+
@end

SSYXMLPeeker.m

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#import "SSYXMLPeeker.h"
2+
#import "SSY_ARC_OR_NO_ARC.h"
3+
4+
@interface SSYXMLPeeker ()
5+
6+
@property (retain) NSMutableString* parsedValue ;
7+
@property (retain) NSString* targetElement ;
8+
@property (retain) NSError* error ;
9+
10+
@end
11+
12+
13+
@implementation SSYXMLPeeker
14+
15+
@synthesize parsedValue = m_parsedValue ;
16+
@synthesize targetElement = m_targetElement ;
17+
@synthesize error = m_error ;
18+
19+
#if NO_ARC
20+
- (void)dealloc {
21+
[m_parsedValue release] ;
22+
[m_targetElement release] ;
23+
[m_error release] ;
24+
25+
[super dealloc] ;
26+
}
27+
#endif
28+
29+
- (NSString*)stringValueOfElement:(NSString*)targetElement
30+
XMLFilePath:(NSString*)path {
31+
NSURL* url = [NSURL fileURLWithPath:path] ;
32+
NSXMLParser* parser = [[NSXMLParser alloc] initWithContentsOfURL:url] ;
33+
[parser setDelegate:self] ;
34+
[self setTargetElement:targetElement] ;
35+
[self setError:nil] ;
36+
37+
[parser parse] ;
38+
// Note that -parse is synchronous and will not return until the parsing
39+
// is done or aborted.
40+
41+
42+
#if NO_ARC
43+
[parser release] ;
44+
#endif
45+
return [self parsedValue] ;
46+
}
47+
48+
+ (NSString*)stringValueOfElement:(NSString*)targetElement
49+
XMLFilePath:(NSString*)path
50+
error_p:(NSError**)error_p {
51+
SSYXMLPeeker* peeker = [[self alloc] init] ;
52+
NSString* answer = [peeker stringValueOfElement:targetElement
53+
XMLFilePath:path] ;
54+
if (error_p) {
55+
*error_p = [peeker error] ;
56+
}
57+
58+
#if NO_ARC
59+
[peeker release] ;
60+
#endif
61+
62+
return answer ;
63+
}
64+
65+
66+
#pragma mark * NSXMLParser Delegate Methods
67+
68+
- (void) parser:(NSXMLParser*)parser
69+
didStartElement:(NSString*)elementName
70+
namespaceURI:(NSString*)namespaceURI
71+
qualifiedName:(NSString*)qualifiedName
72+
attributes:(NSDictionary*)attributeDict {
73+
if ([elementName isEqualToString:[self targetElement]]) {
74+
NSMutableString* emptyString = [[NSMutableString alloc] init] ;
75+
[self setParsedValue:emptyString] ;
76+
#if NO_ARC
77+
[emptyString release] ;
78+
#endif
79+
}
80+
}
81+
82+
- (void)parser:(NSXMLParser *)parser
83+
didEndElement:(NSString *)elementName
84+
namespaceURI:(NSString *)namespaceURI
85+
qualifiedName:(NSString *)qName {
86+
if ([elementName isEqualToString:[self targetElement]]) {
87+
[parser abortParsing] ;
88+
// When we send -abortParsing, NSXMLParser invokes -parser:parseErrorOccurred:,
89+
// announcing the abortion as an error, when of course it is not an error.
90+
// And by some magic it does not do this synchronously but does so *after*
91+
// this method returns. So [self setError:nil] at this point does not
92+
// clear the error. We therefore do this kludge instead:
93+
if (![self error]) {
94+
m_ignoreError = YES ;
95+
}
96+
}
97+
}
98+
99+
- (void) parser:(NSXMLParser*)parser
100+
foundCharacters:(NSString*)string {
101+
if ([self parsedValue]) {
102+
/* For some reason, this method is invoked by the parser when it parses
103+
elements that don't have string values, and the value of 'string' is
104+
a single line feed. We now filter those out. */
105+
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ;
106+
[[self parsedValue] appendString:string] ;
107+
}
108+
}
109+
110+
- (void) parser:(NSXMLParser*)parser
111+
parseErrorOccurred:(NSError*)error {
112+
if (!m_ignoreError) {
113+
[self setError:error] ;
114+
}
115+
}
116+
117+
@end

0 commit comments

Comments
 (0)