1 /*****************************************************************************
2 * misc.m: code not specific to vlc
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 #include <Cocoa/Cocoa.h>
26 #include "intf.h" /* VLCApplication */
30 /*****************************************************************************
32 *****************************************************************************/
34 @implementation VLCControllerWindow
36 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
37 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
39 self = [super initWithContentRect:contentRect styleMask:styleMask //& ~NSTitledWindowMask
40 backing:backingType defer:flag];
45 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
47 return [( (VLCApplication *) [VLCApplication sharedApplication] )
48 hasDefinedShortcutKey:o_event];
55 /*****************************************************************************
57 *****************************************************************************/
59 @implementation VLCControllerView
63 [self unregisterDraggedTypes];
69 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
70 NSFilenamesPboardType, nil]];
73 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
75 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
76 == NSDragOperationGeneric)
78 return NSDragOperationGeneric;
82 return NSDragOperationNone;
86 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
91 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
93 NSPasteboard *o_paste = [sender draggingPasteboard];
94 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
95 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
96 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
100 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
103 NSArray *o_array = [NSArray array];
104 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
105 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
107 for( i = 0; i < (int)[o_values count]; i++)
110 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
111 o_array = [o_array arrayByAddingObject: o_dic];
113 [(VLCPlaylist *)[[NSApp delegate] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
117 [self setNeedsDisplay:YES];
121 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
123 [self setNeedsDisplay:YES];
128 /*****************************************************************************
129 * VLBrushedMetalImageView
130 *****************************************************************************/
132 @implementation VLBrushedMetalImageView
134 - (BOOL)mouseDownCanMoveWindow
141 [self unregisterDraggedTypes];
147 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
148 NSFilenamesPboardType, nil]];
151 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
153 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
154 == NSDragOperationGeneric)
156 return NSDragOperationGeneric;
160 return NSDragOperationNone;
164 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
169 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
171 NSPasteboard *o_paste = [sender draggingPasteboard];
172 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
173 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
174 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
178 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
181 NSArray *o_array = [NSArray array];
182 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
183 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
185 for( i = 0; i < (int)[o_values count]; i++)
188 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
189 o_array = [o_array arrayByAddingObject: o_dic];
191 [(VLCPlaylist *)[[NSApp delegate] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
195 [self setNeedsDisplay:YES];
199 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
201 [self setNeedsDisplay:YES];
207 /*****************************************************************************
209 *****************************************************************************/
211 @implementation MPSlider
215 return( [MPSliderCell class] );
220 /*****************************************************************************
222 *****************************************************************************/
224 @implementation MPSliderCell
232 _bgColor = [[NSColor colorWithDeviceRed: 0.8627451
236 _knobColor = [[NSColor blackColor] retain];
245 [_knobColor release];
249 - (void)setBackgroundColor:(NSColor *)newColor
252 _bgColor = [newColor retain];
255 - (NSColor *)backgroundColor
260 - (void)setKnobColor:(NSColor *)newColor
262 [_knobColor release];
263 _knobColor = [newColor retain];
266 - (NSColor *)knobColor
268 return( _knobColor );
271 - (void)setKnobThickness:(float)f_value
273 _knobThickness = f_value;
276 - (float)knobThickness
278 return( _knobThickness );
281 - (NSSize)cellSizeForBounds:(NSRect)s_rc
286 - (void)drawWithFrame:(NSRect)s_rc inView:(NSView *)o_view
288 if( _scFlags.weAreVertical )
290 s_rc.origin.x = 1; s_rc.size.width -= 3;
291 s_rc.origin.y = 2; s_rc.size.height -= 5;
295 s_rc.origin.x = 2; s_rc.size.width -= 5;
296 s_rc.origin.y = 1; s_rc.size.height -= 3;
299 [super drawWithFrame: s_rc inView: o_view];
302 - (void)drawBarInside:(NSRect)s_rc flipped:(BOOL)b_flipped
306 s_rc.size.width += (s_rc.origin.x * 2) + 1;
307 s_rc.size.height += (s_rc.origin.y * 2) + 1;
308 s_rc.origin.x = s_rc.origin.y = 0;
310 [[NSGraphicsContext currentContext] setShouldAntialias: NO];
316 s_arc.origin.x += 1.5;
317 s_arc.origin.y += 1.5;
318 s_arc.size.width -= s_arc.origin.x;
319 s_arc.size.height -= s_arc.origin.y;
320 [[_bgColor shadowWithLevel: 0.1] set];
321 [NSBezierPath strokeRect: s_arc];
323 s_arc.origin = s_rc.origin;
324 [[NSColor blackColor] set];
325 [NSBezierPath strokeRect: s_arc];
327 [[NSGraphicsContext currentContext] setShouldAntialias: YES];
330 - (NSRect)knobRectFlipped:(BOOL)b_flipped
336 floatValue = [self floatValue];
338 if( _scFlags.weAreVertical && b_flipped )
340 floatValue = _maxValue + _minValue - floatValue;
343 floatValue = (floatValue - _minValue) / (_maxValue - _minValue);
345 if( _scFlags.weAreVertical )
347 s_size = NSMakeSize( _trackRect.size.width, _knobThickness ?
348 _knobThickness : _trackRect.size.width );
349 s_pto = _trackRect.origin;
350 s_pto.y += (_trackRect.size.height - s_size.height) * floatValue;
354 s_size = NSMakeSize( _knobThickness ? _knobThickness :
355 _trackRect.size.height, _trackRect.size.height );
356 s_pto = _trackRect.origin;
357 s_pto.x += (_trackRect.size.width - s_size.width) * floatValue;
360 return NSMakeRect( s_pto.x, s_pto.y, s_size.width, s_size.height );
363 - (void)drawKnob:(NSRect)s_rc
365 [[NSGraphicsContext currentContext] setShouldAntialias: NO];
370 [[NSGraphicsContext currentContext] setShouldAntialias: YES];