source: trunk/macosx/StatusBarView.m @ 11625

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

Instead of explicitly setting the status bar as draggable, let it take on the window's default behavior.

  • Property svn:keywords set to Date Rev Author Id
File size: 3.6 KB
Line 
1/******************************************************************************
2 * $Id: StatusBarView.m 11625 2011-01-03 03:41:42Z 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    [fGradient release];
54    [super dealloc];
55}
56
57- (void) drawRect: (NSRect) rect
58{
59    const BOOL active = [[self window] isMainWindow];
60   
61    NSInteger count = 0;
62    NSRect gridRects[active ? 2 : 3];
63    NSColor * colorRects[active ? 2 : 3];
64   
65    NSRect lineBorderRect = NSMakeRect(NSMinX(rect), NSHeight([self bounds]) - 1.0, NSWidth(rect), 1.0);
66    if (active)
67    {
68        if (NSIntersectsRect(lineBorderRect, rect))
69        {
70            gridRects[count] = lineBorderRect;
71            colorRects[count] = [NSColor colorWithCalibratedWhite: 0.75 alpha: 1.0];
72            ++count;
73           
74            rect.size.height -= 1.0;
75        }
76    }
77   
78    lineBorderRect.origin.y = 0.0;
79    if (NSIntersectsRect(lineBorderRect, rect))
80    {
81        gridRects[count] = lineBorderRect;
82        colorRects[count] = active ? [NSColor colorWithCalibratedWhite: 0.25 alpha: 1.0]
83                                    : [NSColor colorWithCalibratedWhite: 0.5 alpha: 1.0];
84        ++count;
85       
86        rect.origin.y += 1.0;
87        rect.size.height -= 1.0;
88    }
89   
90    if (active)
91        [fGradient drawInRect: rect angle: 270.0];
92    else
93    {
94        gridRects[count] = rect;
95        colorRects[count] = [NSColor colorWithCalibratedWhite: 0.85 alpha: 1.0];
96        ++count;
97    }
98   
99    NSRectFillListWithColors(gridRects, colorRects, count);
100}
101
102@end
103
104@implementation StatusBarView (Private)
105
106- (void) reload
107{
108    [self setNeedsDisplay: YES];
109}
110
111@end
Note: See TracBrowser for help on using the repository browser.