1 /*****************************************************************************
2 * sidestatusview.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2005-2008 the VideoLAN team
7 * Authors: Eric Dudiak <dudiak at gmail dot com>
8 * Colloquy <http://colloquy.info/>
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.
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.
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 *****************************************************************************/
25 #import "sidestatusview.h"
27 @implementation sidestatusview
28 -(void)resetCursorRects
30 [super resetCursorRects];
31 if( ! splitView ) return;
33 NSImage *resizeImage = [NSImage imageNamed:@"sidebarResizeWidget"];
35 location.size = [resizeImage size];
36 location.origin = NSMakePoint( NSWidth( [self bounds] ) - [resizeImage size].width, 0. );
37 [self addCursorRect:location cursor:[NSCursor resizeLeftRightCursor]];
40 - (void)drawRect:(NSRect)rect
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];
48 NSImage *resizeImage = [NSImage imageNamed:@"sidebarResizeWidget"];
49 [resizeImage compositeToPoint:NSMakePoint( NSWidth( [self bounds] ) - [resizeImage size].width, 0. ) operation:NSCompositeCopy];
53 - (void)mouseDown:(NSEvent *)event
55 if( ! splitView ) return;
56 NSPoint clickLocation = [self convertPoint:[event locationInWindow] fromView:nil];
58 NSImage *resizeImage = [NSImage imageNamed:@"sidebarResizeWidget"];
60 location.size = [resizeImage size];
61 location.origin = NSMakePoint( NSWidth( [self bounds] ) - [resizeImage size].width, 0. );
63 _insideResizeArea = ( NSPointInRect( clickLocation, location ) );
64 if( ! _insideResizeArea ) return;
66 clickLocation = [self convertPoint:[event locationInWindow] fromView:[self superview]];
67 _clickOffset = NSWidth( [[self superview] frame] ) - clickLocation.x;
70 - (void)mouseDragged:(NSEvent *)event
72 if( ! splitView || ! _insideResizeArea ) return;
74 [[NSNotificationCenter defaultCenter] postNotificationName:NSSplitViewWillResizeSubviewsNotification object:splitView];
76 NSPoint clickLocation = [self convertPoint:[event locationInWindow] fromView:[self superview]];
78 NSRect newFrame = [[self superview] frame];
79 newFrame.size.width = clickLocation.x + _clickOffset;
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;
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 );
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 );
98 [delegate setMinSize:NSMakeSize(newFrame.size.width + 551., 114.)];
101 [[self superview] setFrame:newFrame];
103 [splitView adjustSubviews];
105 [[NSNotificationCenter defaultCenter] postNotificationName:NSSplitViewDidResizeSubviewsNotification object:splitView];