source: trunk/macosx/StatusBarView.m

Last change on this file was 14662, checked in by mikedld, 6 years ago

#6042: Remove dead code now that we build for OS X 10.7+ (patch by mattrajca)

In addition to the patch,

  • remove unused global actions menu (popover is used instead)
  • remove *Lion class macros, use NSPopover and NSDataDetector directly
  • Property svn:keywords set to Date Rev Author Id
File size: 6.0 KB
Line 
1/******************************************************************************
2 * $Id: StatusBarView.m 14662 2016-01-06 11:05:37Z mikedld $
3 *
4 * Copyright (c) 2006-2012 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "StatusBarView.h"
26#import "NSApplicationAdditions.h"
27#import <QuartzCore/QuartzCore.h>
28
29@interface StatusBarView (Private)
30
31- (void) reload;
32
33@end
34
35@implementation StatusBarView
36
37- (id) initWithFrame: (NSRect) rect
38{
39    if ((self = [super initWithFrame: rect]))
40    {
41        NSColor * lightColor = [NSColor colorWithCalibratedRed: 160.0/255.0 green: 160.0/255.0 blue: 160.0/255.0 alpha: 1.0];
42        NSColor * darkColor = [NSColor colorWithCalibratedRed: 155.0/255.0 green: 155.0/255.0 blue: 155.0/255.0 alpha: 1.0];
43        fGradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor];
44       
45        if (![NSApp isOnYosemiteOrBetter])
46        {
47            CIFilter * randomFilter = [CIFilter filterWithName: @"CIRandomGenerator"];
48            [randomFilter setDefaults];
49           
50            fNoiseImage = [randomFilter valueForKey: @"outputImage"];
51           
52            CIFilter * monochromeFilter = [CIFilter filterWithName: @"CIColorMonochrome"];
53            [monochromeFilter setDefaults];
54            [monochromeFilter setValue: fNoiseImage forKey: @"inputImage"];
55            CIColor * monoFilterColor = [CIColor colorWithRed: 1.0 green: 1.0 blue: 1.0];
56            [monochromeFilter setValue: monoFilterColor forKey: @"inputColor"];
57            fNoiseImage = [[monochromeFilter valueForKey:@"outputImage"] retain];
58        }
59        else
60            fNoiseImage = nil;
61       
62        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reload) name: NSWindowDidBecomeMainNotification object: [self window]];
63        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reload) name: NSWindowDidResignMainNotification object: [self window]];
64    }
65    return self;
66}
67
68- (void) dealloc
69{
70    [[NSNotificationCenter defaultCenter] removeObserver: self];
71    [fNoiseImage release];
72    [fGradient release];
73    [super dealloc];
74}
75
76- (BOOL) mouseDownCanMoveWindow
77{
78    return YES;
79}
80
81- (BOOL) isOpaque
82{
83    return YES;
84}
85
86- (void) drawRect: (NSRect) rect
87{
88    if ([NSApp isOnYosemiteOrBetter]) {
89        [[NSColor windowBackgroundColor] setFill];
90        NSRectFill(rect);
91       
92        const NSRect lineBorderRect = NSMakeRect(NSMinX(rect), 0.0, NSWidth(rect), 1.0);
93        if (NSIntersectsRect(lineBorderRect, rect))
94        {
95            [[NSColor lightGrayColor] setFill];
96            NSRectFill(lineBorderRect);
97        }
98    }
99    else {
100        const BOOL active = [[self window] isMainWindow];
101       
102        NSInteger count = 0;
103        NSRect gridRects[active ? 2 : 3];
104        NSColor * colorRects[active ? 2 : 3];
105       
106        //bottom line
107        NSRect lineBorderRect = NSMakeRect(NSMinX(rect), 0.0, NSWidth(rect), 1.0);
108        NSRect intersectLineBorderRect = NSIntersectionRect(lineBorderRect, rect);
109        if (!NSIsEmptyRect(intersectLineBorderRect))
110        {
111            gridRects[count] = intersectLineBorderRect;
112            colorRects[count] = active ? [NSColor colorWithCalibratedWhite: 0.25 alpha: 1.0]
113            : [NSColor colorWithCalibratedWhite: 0.5 alpha: 1.0];
114            ++count;
115           
116            rect.origin.y += intersectLineBorderRect.size.height;
117            rect.size.height -= intersectLineBorderRect.size.height;
118        }
119       
120       
121        //top line
122        if (active)
123        {
124            lineBorderRect.origin.y = NSHeight([self bounds]) - 1.0;
125            intersectLineBorderRect = NSIntersectionRect(lineBorderRect, rect);
126            if (!NSIsEmptyRect(intersectLineBorderRect))
127            {
128                gridRects[count] = intersectLineBorderRect;
129                colorRects[count] = [NSColor colorWithCalibratedWhite: 0.75 alpha: 1.0];
130                ++count;
131               
132                rect.size.height -= intersectLineBorderRect.size.height;
133            }
134        }
135       
136        if (!NSIsEmptyRect(rect))
137        {
138            if (active)
139            {
140                const NSRect gradientRect = NSMakeRect(NSMinX(rect), 1.0, NSWidth(rect), NSHeight([self bounds]) - 1.0 - 1.0); //proper gradient requires the full height of the bar
141                [fGradient drawInRect: gradientRect angle: 270.0];
142            }
143            else
144            {
145                gridRects[count] = rect;
146                colorRects[count] = [NSColor colorWithCalibratedWhite: 0.85 alpha: 1.0];
147                ++count;
148            }
149        }
150       
151        NSRectFillListWithColors(gridRects, colorRects, count);
152       
153        if (fNoiseImage) {
154            [fNoiseImage drawInRect: rect
155                           fromRect: [self convertRectToBacking: rect]
156                          operation: NSCompositeSourceOver
157                           fraction: 0.12];
158        }
159    }
160}
161
162@end
163
164@implementation StatusBarView (Private)
165
166- (void) reload
167{
168    [self setNeedsDisplay: YES];
169}
170
171@end
Note: See TracBrowser for help on using the repository browser.