CFRelease the duration preference value if we get one. Found by the clang static analyzer.
2 // GrowliCalWindowController.m
5 // Created by Nelson Elhage on Wed Jun 09 2004.
6 // Name changed from KABubbleWindowController.m by Justin Burns on Fri Nov 05 2004.
7 // Adapted for iCal by Takumi Murayama on Thu Aug 17 2006.
8 // Copyright (c) 2004-2006 The Growl Project. All rights reserved.
11 #import "GrowliCalWindowController.h"
12 #import "GrowliCalWindowView.h"
13 #import "GrowliCalPrefsController.h"
14 #import "GrowliCalDefines.h"
15 #import "GrowlApplicationNotification.h"
16 #import "NSWindow+Transforms.h"
17 #include "CFDictionaryAdditions.h"
18 #import "GrowlWindowTransition.h"
19 #import "GrowlFadingWindowTransition.h"
21 @implementation GrowliCalWindowController
23 #define GrowliCalPadding 5.0f
29 READ_GROWL_PREF_INT(GrowliCalScreen, GrowliCalPrefDomain, &screenNumber);
30 NSArray *screens = [NSScreen screens];
31 unsigned screensCount = [screens count];
33 [self setScreen:((screensCount >= (screenNumber + 1)) ? [screens objectAtIndex:screenNumber] : [screens objectAtIndex:0])];
36 CFNumberRef prefsDuration = NULL;
37 READ_GROWL_PREF_VALUE(GrowliCalDuration, GrowliCalPrefDomain, CFNumberRef, &prefsDuration);
38 [self setDisplayDuration:(prefsDuration ?
39 [(NSNumber *)prefsDuration doubleValue] :
40 GrowliCalDurationPrefDefault)];
41 if (prefsDuration) CFRelease(prefsDuration);
43 // I tried setting the width/height to zero, since the view resizes itself later.
44 // This made it ignore the alpha at the edges (using 1.0 instead). Why?
45 // A window with a frame of NSZeroRect is off-screen and doesn't respect opacity even
46 // if moved on screen later. -Evan
47 NSPanel *panel = [[NSPanel alloc] initWithContentRect:NSMakeRect(0.0f, 0.0f, 270.0f, 65.0f)
48 styleMask:NSBorderlessWindowMask | NSNonactivatingPanelMask
49 backing:NSBackingStoreBuffered
51 NSRect panelFrame = [panel frame];
52 [panel setBecomesKeyOnlyIfNeeded:YES];
53 [panel setHidesOnDeactivate:NO];
54 [panel setBackgroundColor:[NSColor clearColor]];
55 [panel setLevel:NSStatusWindowLevel];
56 [panel setSticky:YES];
57 [panel setAlphaValue:0.0f];
59 [panel setHasShadow:YES];
60 [panel setCanHide:NO];
61 [panel setOneShot:YES];
62 [panel useOptimizedDrawing:YES];
63 [panel setMovableByWindowBackground:NO];
65 // Create the content view...
66 GrowliCalWindowView *view = [[GrowliCalWindowView alloc] initWithFrame:panelFrame];
67 [view setTarget:self];
68 [view setAction:@selector(notificationClicked:)];
69 [panel setContentView:view];
72 // call super so everything else is set up...
73 if ((self = [super initWithWindow:panel])) {
74 // set up the transitions...
75 GrowlFadingWindowTransition *fader = [[GrowlFadingWindowTransition alloc] initWithWindow:panel];
76 [self addTransition:fader];
77 [self setStartPercentage:0 endPercentage:100 forTransition:fader];
78 [fader setAutoReverses:YES];
89 - (void) setNotification: (GrowlApplicationNotification *) theNotification {
90 [super setNotification:theNotification];
94 NSDictionary *noteDict = [notification dictionaryRepresentation];
95 NSString *title = [notification title];
96 NSString *text = [notification notificationDescription];
97 NSImage *icon = getObjectForKey(noteDict, GROWL_NOTIFICATION_ICON);
98 int priority = getIntegerForKey(noteDict, GROWL_NOTIFICATION_PRIORITY);
100 GrowliCalWindowView *view = [[self window] contentView];
101 [view setPriority:priority];
102 [view setTitle:title];
109 #pragma mark positioning methods
111 - (NSPoint) idealOriginInRect:(NSRect)rect {
112 NSRect viewFrame = [[[self window] contentView] frame];
113 enum GrowlPosition originatingPosition = [[GrowlPositionController sharedInstance] originPosition];
116 switch(originatingPosition){
117 case GrowlTopRightPosition:
118 idealOrigin = NSMakePoint(NSMaxX(rect) - NSWidth(viewFrame) - GrowliCalPadding,
119 NSMaxY(rect) - GrowliCalPadding - NSHeight(viewFrame));
121 case GrowlTopLeftPosition:
122 idealOrigin = NSMakePoint(NSMinX(rect) + GrowliCalPadding,
123 NSMaxY(rect) - GrowliCalPadding - NSHeight(viewFrame));
125 case GrowlBottomLeftPosition:
126 idealOrigin = NSMakePoint(NSMinX(rect) + GrowliCalPadding,
127 NSMinY(rect) + GrowliCalPadding);
129 case GrowlBottomRightPosition:
130 idealOrigin = NSMakePoint(NSMaxX(rect) - NSWidth(viewFrame) - GrowliCalPadding,
131 NSMinY(rect) + GrowliCalPadding);
134 idealOrigin = NSMakePoint(NSMaxX(rect) - NSWidth(viewFrame) - GrowliCalPadding,
135 NSMaxY(rect) - GrowliCalPadding - NSHeight(viewFrame));
142 - (enum GrowlExpansionDirection) primaryExpansionDirection {
143 enum GrowlPosition originatingPosition = [[GrowlPositionController sharedInstance] originPosition];
144 enum GrowlExpansionDirection directionToExpand;
146 switch(originatingPosition){
147 case GrowlTopLeftPosition:
148 directionToExpand = GrowlDownExpansionDirection;
150 case GrowlTopRightPosition:
151 directionToExpand = GrowlDownExpansionDirection;
153 case GrowlBottomLeftPosition:
154 directionToExpand = GrowlUpExpansionDirection;
156 case GrowlBottomRightPosition:
157 directionToExpand = GrowlUpExpansionDirection;
160 directionToExpand = GrowlDownExpansionDirection;
164 return directionToExpand;
167 - (enum GrowlExpansionDirection) secondaryExpansionDirection {
168 enum GrowlPosition originatingPosition = [[GrowlPositionController sharedInstance] originPosition];
169 enum GrowlExpansionDirection directionToExpand;
171 switch(originatingPosition){
172 case GrowlTopLeftPosition:
173 directionToExpand = GrowlRightExpansionDirection;
175 case GrowlTopRightPosition:
176 directionToExpand = GrowlLeftExpansionDirection;
178 case GrowlBottomLeftPosition:
179 directionToExpand = GrowlRightExpansionDirection;
181 case GrowlBottomRightPosition:
182 directionToExpand = GrowlLeftExpansionDirection;
185 directionToExpand = GrowlRightExpansionDirection;
189 return directionToExpand;
192 - (float) requiredDistanceFromExistingDisplays {
193 return GrowliCalPadding;