source: trunk/macosx/StatusBarView.m @ 11989

Last change on this file since 11989 was 11989, checked in by livings124, 11 years ago

remove the status bar view's observer on dealloc

  • Property svn:keywords set to Date Rev Author Id
File size: 3.7 KB
Line 
1/******************************************************************************
2 * $Id: StatusBarView.m 11989 2011-02-19 21:38:38Z livings124 $
3 *
4 * Copyright (c) 2006-2011 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
27@interface StatusBarView (Private)
28
29- (void) reload;
30
31@end
32
33@implementation StatusBarView
34
35- (id) initWithFrame: (NSRect) rect
36{
37    if ((self = [super initWithFrame: rect]))
38    {
39        NSColor * lightColor = [NSColor colorWithCalibratedRed: 160.0/255.0 green: 160.0/255.0 blue: 160.0/255.0 alpha: 1.0];
40        NSColor * darkColor = [NSColor colorWithCalibratedRed: 155.0/255.0 green: 155.0/255.0 blue: 155.0/255.0 alpha: 1.0];
41        fGradient = [[NSGradient alloc] initWithStartingColor: lightColor endingColor: darkColor];
42       
43        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reload)
44            name: NSWindowDidBecomeMainNotification object: [self window]];
45        [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reload)
46            name: NSWindowDidResignMainNotification object: [self window]];
47    }
48    return self;
49}
50
51- (void) dealloc
52{
53    [[NSNotificationCenter defaultCenter] removeObserver: self];
54   
55    [fGradient release];
56    [super dealloc];
57}
58
59- (void) drawRect: (NSRect) rect
60{
61    const BOOL active = [[self window] isMainWindow];
62   
63    NSInteger count = 0;
64    NSRect gridRects[active ? 2 : 3];
65    NSColor * colorRects[active ? 2 : 3];
66   
67    NSRect lineBorderRect = NSMakeRect(NSMinX(rect), NSHeight([self bounds]) - 1.0, NSWidth(rect), 1.0);
68    if (active)
69    {
70        if (NSIntersectsRect(lineBorderRect, rect))
71        {
72            gridRects[count] = lineBorderRect;
73            colorRects[count] = [NSColor colorWithCalibratedWhite: 0.75 alpha: 1.0];
74            ++count;
75           
76            rect.size.height -= 1.0;
77        }
78    }
79   
80    lineBorderRect.origin.y = 0.0;
81    if (NSIntersectsRect(lineBorderRect, rect))
82    {
83        gridRects[count] = lineBorderRect;
84        colorRects[count] = active ? [NSColor colorWithCalibratedWhite: 0.25 alpha: 1.0]
85                                    : [NSColor colorWithCalibratedWhite: 0.5 alpha: 1.0];
86        ++count;
87       
88        rect.origin.y += 1.0;
89        rect.size.height -= 1.0;
90    }
91   
92    if (active)
93        [fGradient drawInRect: rect angle: 270.0];
94    else
95    {
96        gridRects[count] = rect;
97        colorRects[count] = [NSColor colorWithCalibratedWhite: 0.85 alpha: 1.0];
98        ++count;
99    }
100   
101    NSRectFillListWithColors(gridRects, colorRects, count);
102}
103
104@end
105
106@implementation StatusBarView (Private)
107
108- (void) reload
109{
110    [self setNeedsDisplay: YES];
111}
112
113@end
Note: See TracBrowser for help on using the repository browser.