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 *****************************************************************************/
210 @implementation MPSlider
212 void _drawKnobInRect(NSRect knobRect)
214 // Center knob in given rect
215 knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
216 knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
219 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
220 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
221 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 4, 5, 1), NSCompositeSourceOver);
222 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 0, knobRect.origin.y + 3, 7, 1), NSCompositeSourceOver);
223 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 2, 5, 1), NSCompositeSourceOver);
224 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 1, 3, 1), NSCompositeSourceOver);
225 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 0, 1, 1), NSCompositeSourceOver);
228 void _drawFrameInRect(NSRect frameRect)
231 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
232 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
233 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
234 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
237 - (void)drawRect:(NSRect)rect
239 // Draw default to make sure the slider behaves correctly
240 [[NSGraphicsContext currentContext] saveGraphicsState];
241 NSRectClip(NSZeroRect);
242 [super drawRect:rect];
243 [[NSGraphicsContext currentContext] restoreGraphicsState];
246 rect = [self bounds];
247 int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
248 rect.origin.x += diff-1;
249 rect.origin.y += diff;
250 rect.size.width -= 2*diff-2;
251 rect.size.height -= 2*diff;
254 NSRect knobRect = [[self cell] knobRectFlipped:NO];
255 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
256 _drawFrameInRect(rect);
257 _drawKnobInRect(knobRect);
260 [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
265 _drawFrameInRect(rect);
266 _drawKnobInRect(knobRect);