]> git.sesse.net Git - vlc/blob - modules/gui/macosx/sidestatusview.m
macosx: merge Eric Dudiak's code from GSoC 2008
[vlc] / modules / gui / macosx / sidestatusview.m
1 /*****************************************************************************
2  * sidestatusview.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2005-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Eric Dudiak <dudiak at gmail dot com>
8  *          Colloquy <http://colloquy.info/>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #import "sidestatusview.h"
26
27 @implementation sidestatusview
28 -(void)resetCursorRects
29 {
30         [super resetCursorRects];
31         if( ! splitView ) return;
32     
33         NSImage *resizeImage = [NSImage imageNamed:@"sidebarResizeWidget"];
34         NSRect location;
35         location.size = [resizeImage size];
36         location.origin = NSMakePoint( NSWidth( [self bounds] ) - [resizeImage size].width, 0. );
37         [self addCursorRect:location cursor:[NSCursor resizeLeftRightCursor]];
38 }
39
40 - (void)drawRect:(NSRect)rect
41 {
42         NSImage *backgroundImage = [NSImage imageNamed:@"sidebarStatusAreaBackground"];
43     [backgroundImage setSize:NSMakeSize(NSWidth( [self bounds] ), [backgroundImage size].height)];
44     [backgroundImage setScalesWhenResized:YES];
45     [backgroundImage compositeToPoint:NSMakePoint( 0., 0. ) operation:NSCompositeCopy];
46     
47         if( splitView ) {
48                 NSImage *resizeImage = [NSImage imageNamed:@"sidebarResizeWidget"];
49                 [resizeImage compositeToPoint:NSMakePoint( NSWidth( [self bounds] ) - [resizeImage size].width, 0. ) operation:NSCompositeCopy];
50         }
51 }
52
53 - (void)mouseDown:(NSEvent *)event
54 {
55         if( ! splitView ) return;
56     NSPoint clickLocation = [self convertPoint:[event locationInWindow] fromView:nil];
57     
58         NSImage *resizeImage = [NSImage imageNamed:@"sidebarResizeWidget"];
59         NSRect location;
60         location.size = [resizeImage size];
61         location.origin = NSMakePoint( NSWidth( [self bounds] ) - [resizeImage size].width, 0. );
62     
63         _insideResizeArea = ( NSPointInRect( clickLocation, location ) );
64         if( ! _insideResizeArea ) return;
65     
66         clickLocation = [self convertPoint:[event locationInWindow] fromView:[self superview]];
67         _clickOffset = NSWidth( [[self superview] frame] ) - clickLocation.x;
68 }
69
70 - (void)mouseDragged:(NSEvent *)event
71 {
72         if( ! splitView || ! _insideResizeArea ) return;
73     
74         [[NSNotificationCenter defaultCenter] postNotificationName:NSSplitViewWillResizeSubviewsNotification object:splitView];
75     
76     NSPoint clickLocation = [self convertPoint:[event locationInWindow] fromView:[self superview]];
77     
78         NSRect newFrame = [[self superview] frame];
79         newFrame.size.width = clickLocation.x + _clickOffset;
80     
81         id delegate = [splitView delegate];
82         if( delegate && [delegate respondsToSelector:@selector( splitView:constrainSplitPosition:ofSubviewAt: )] ) {
83                 float new = [delegate splitView:splitView constrainSplitPosition:newFrame.size.width ofSubviewAt:0];
84                 newFrame.size.width = new;
85         }
86     
87         if( delegate && [delegate respondsToSelector:@selector( splitView:constrainMinCoordinate:ofSubviewAt: )] ) {
88                 float min = [delegate splitView:splitView constrainMinCoordinate:0. ofSubviewAt:0];
89                 newFrame.size.width = MAX( min, newFrame.size.width );
90         }
91     
92         if( delegate && [delegate respondsToSelector:@selector( splitView:constrainMaxCoordinate:ofSubviewAt: )] ) {
93                 float max = [delegate splitView:splitView constrainMaxCoordinate:0. ofSubviewAt:0];
94                 newFrame.size.width = MIN( max, newFrame.size.width );
95         }
96     
97     if( delegate ) {
98         [delegate setMinSize:NSMakeSize(newFrame.size.width + 551., 114.)];
99     }
100     
101         [[self superview] setFrame:newFrame];
102     
103         [splitView adjustSubviews];
104     
105         [[NSNotificationCenter defaultCenter] postNotificationName:NSSplitViewDidResizeSubviewsNotification object:splitView];
106 }
107 @end