1 /*****************************************************************************
2 * misc.m: code not specific to vlc
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: misc.m,v 1.3 2003/11/15 22:42:16 hartman Exp $
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>
29 /*****************************************************************************
31 *****************************************************************************/
33 @implementation VLCControllerWindow
35 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
36 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
38 self = [super initWithContentRect:contentRect styleMask:styleMask //& ~NSTitledWindowMask
39 backing:backingType defer:flag];
47 /*****************************************************************************
49 *****************************************************************************/
51 @implementation VLCControllerView
55 [self unregisterDraggedTypes];
61 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
62 NSFilenamesPboardType, nil]];
65 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
67 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
68 == NSDragOperationGeneric)
70 return NSDragOperationGeneric;
74 return NSDragOperationNone;
78 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
83 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
85 NSPasteboard *o_paste = [sender draggingPasteboard];
86 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
87 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
88 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
92 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
95 NSArray *o_array = [NSArray array];
96 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
97 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
99 for( i = 0; i < (int)[o_values count]; i++)
102 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
103 o_array = [o_array arrayByAddingObject: o_dic];
105 [(VLCPlaylist *)[[NSApp delegate] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
109 [self setNeedsDisplay:YES];
113 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
115 [self setNeedsDisplay:YES];
120 /*****************************************************************************
121 * VLBrushedMetalImageView
122 *****************************************************************************/
124 @implementation VLBrushedMetalImageView
126 - (BOOL)mouseDownCanMoveWindow
133 [self unregisterDraggedTypes];
139 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
140 NSFilenamesPboardType, nil]];
143 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
145 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
146 == NSDragOperationGeneric)
148 return NSDragOperationGeneric;
152 return NSDragOperationNone;
156 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
161 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
163 NSPasteboard *o_paste = [sender draggingPasteboard];
164 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
165 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
166 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
170 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
173 NSArray *o_array = [NSArray array];
174 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
175 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
177 for( i = 0; i < (int)[o_values count]; i++)
180 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
181 o_array = [o_array arrayByAddingObject: o_dic];
183 [(VLCPlaylist *)[[NSApp delegate] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
187 [self setNeedsDisplay:YES];
191 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
193 [self setNeedsDisplay:YES];
199 /*****************************************************************************
201 *****************************************************************************/
203 @implementation MPSlider
207 return( [MPSliderCell class] );
212 /*****************************************************************************
214 *****************************************************************************/
216 @implementation MPSliderCell
224 _bgColor = [[NSColor colorWithDeviceRed: 0.8627451
228 _knobColor = [[NSColor blackColor] retain];
237 [_knobColor release];
241 - (void)setBackgroundColor:(NSColor *)newColor
244 _bgColor = [newColor retain];
247 - (NSColor *)backgroundColor
252 - (void)setKnobColor:(NSColor *)newColor
254 [_knobColor release];
255 _knobColor = [newColor retain];
258 - (NSColor *)knobColor
260 return( _knobColor );
263 - (void)setKnobThickness:(float)f_value
265 _knobThickness = f_value;
268 - (float)knobThickness
270 return( _knobThickness );
273 - (NSSize)cellSizeForBounds:(NSRect)s_rc
278 - (void)drawWithFrame:(NSRect)s_rc inView:(NSView *)o_view
280 if( _scFlags.weAreVertical )
282 s_rc.origin.x = 1; s_rc.size.width -= 3;
283 s_rc.origin.y = 2; s_rc.size.height -= 5;
287 s_rc.origin.x = 2; s_rc.size.width -= 5;
288 s_rc.origin.y = 1; s_rc.size.height -= 3;
291 [super drawWithFrame: s_rc inView: o_view];
294 - (void)drawBarInside:(NSRect)s_rc flipped:(BOOL)b_flipped
298 s_rc.size.width += (s_rc.origin.x * 2) + 1;
299 s_rc.size.height += (s_rc.origin.y * 2) + 1;
300 s_rc.origin.x = s_rc.origin.y = 0;
302 [[NSGraphicsContext currentContext] setShouldAntialias: NO];
308 s_arc.origin.x += 1.5;
309 s_arc.origin.y += 1.5;
310 s_arc.size.width -= s_arc.origin.x;
311 s_arc.size.height -= s_arc.origin.y;
312 [[_bgColor shadowWithLevel: 0.1] set];
313 [NSBezierPath strokeRect: s_arc];
315 s_arc.origin = s_rc.origin;
316 [[NSColor blackColor] set];
317 [NSBezierPath strokeRect: s_arc];
319 [[NSGraphicsContext currentContext] setShouldAntialias: YES];
322 - (NSRect)knobRectFlipped:(BOOL)b_flipped
328 floatValue = [self floatValue];
330 if( _scFlags.weAreVertical && b_flipped )
332 floatValue = _maxValue + _minValue - floatValue;
335 floatValue = (floatValue - _minValue) / (_maxValue - _minValue);
337 if( _scFlags.weAreVertical )
339 s_size = NSMakeSize( _trackRect.size.width, _knobThickness ?
340 _knobThickness : _trackRect.size.width );
341 s_pto = _trackRect.origin;
342 s_pto.y += (_trackRect.size.height - s_size.height) * floatValue;
346 s_size = NSMakeSize( _knobThickness ? _knobThickness :
347 _trackRect.size.height, _trackRect.size.height );
348 s_pto = _trackRect.origin;
349 s_pto.x += (_trackRect.size.width - s_size.width) * floatValue;
352 return NSMakeRect( s_pto.x, s_pto.y, s_size.width, s_size.height );
355 - (void)drawKnob:(NSRect)s_rc
357 [[NSGraphicsContext currentContext] setShouldAntialias: NO];
362 [[NSGraphicsContext currentContext] setShouldAntialias: YES];