1 /*****************************************************************************
2 * misc.m: code not specific to vlc
3 *****************************************************************************
4 * Copyright (C) 2003-2004 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 [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
54 /*****************************************************************************
56 *****************************************************************************/
58 @implementation VLCControllerView
62 [self unregisterDraggedTypes];
68 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
69 NSFilenamesPboardType, nil]];
72 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
74 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
75 == NSDragOperationGeneric)
77 return NSDragOperationGeneric;
81 return NSDragOperationNone;
85 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
90 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
92 NSPasteboard *o_paste = [sender draggingPasteboard];
93 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
94 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
95 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
99 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
102 NSArray *o_array = [NSArray array];
103 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
104 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
106 for( i = 0; i < (int)[o_values count]; i++)
109 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
110 o_array = [o_array arrayByAddingObject: o_dic];
112 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
116 [self setNeedsDisplay:YES];
120 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
122 [self setNeedsDisplay:YES];
127 /*****************************************************************************
128 * VLBrushedMetalImageView
129 *****************************************************************************/
131 @implementation VLBrushedMetalImageView
133 - (BOOL)mouseDownCanMoveWindow
140 [self unregisterDraggedTypes];
146 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
147 NSFilenamesPboardType, nil]];
150 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
152 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
153 == NSDragOperationGeneric)
155 return NSDragOperationGeneric;
159 return NSDragOperationNone;
163 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
168 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
170 NSPasteboard *o_paste = [sender draggingPasteboard];
171 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
172 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
173 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
177 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
180 NSArray *o_array = [NSArray array];
181 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
182 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
184 for( i = 0; i < (int)[o_values count]; i++)
187 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
188 o_array = [o_array arrayByAddingObject: o_dic];
190 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
194 [self setNeedsDisplay:YES];
198 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
200 [self setNeedsDisplay:YES];
206 /*****************************************************************************
208 *****************************************************************************/
209 @implementation MPSlider
211 void _drawKnobInRect(NSRect knobRect)
213 // Center knob in given rect
214 knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
215 knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
218 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
219 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
220 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 4, 5, 1), NSCompositeSourceOver);
221 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 0, knobRect.origin.y + 3, 7, 1), NSCompositeSourceOver);
222 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 2, 5, 1), NSCompositeSourceOver);
223 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 1, 3, 1), NSCompositeSourceOver);
224 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 0, 1, 1), NSCompositeSourceOver);
227 void _drawFrameInRect(NSRect frameRect)
230 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
231 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
232 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
233 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
236 - (void)drawRect:(NSRect)rect
238 // Draw default to make sure the slider behaves correctly
239 [[NSGraphicsContext currentContext] saveGraphicsState];
240 NSRectClip(NSZeroRect);
241 [super drawRect:rect];
242 [[NSGraphicsContext currentContext] restoreGraphicsState];
245 rect = [self bounds];
246 int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
247 rect.origin.x += diff-1;
248 rect.origin.y += diff;
249 rect.size.width -= 2*diff-2;
250 rect.size.height -= 2*diff;
253 NSRect knobRect = [[self cell] knobRectFlipped:NO];
254 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
255 _drawFrameInRect(rect);
256 _drawKnobInRect(knobRect);
259 [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
264 _drawFrameInRect(rect);
265 _drawKnobInRect(knobRect);