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];
42 o_size_with_playlist = [self frame].size;
44 [[[VLCMain sharedInstance] getPlaylist] updateTogglePlaylistState];
49 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
51 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
54 /*Stores the size the controller one resize, to be able to restore it when
55 toggling the playlist*/
57 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)proposedFrameSize
59 o_size_with_playlist = proposedFrameSize;
61 /*Callback to update the state of Playlist Toggle Button*/
62 [[[VLCMain sharedInstance] getPlaylist] updateTogglePlaylistState];
64 return proposedFrameSize;
67 - (NSSize)getSizeWithPlaylist
69 return o_size_with_playlist;
76 /*****************************************************************************
78 *****************************************************************************/
80 @implementation VLCControllerView
84 [self unregisterDraggedTypes];
90 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
91 NSFilenamesPboardType, nil]];
94 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
96 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
97 == NSDragOperationGeneric)
99 return NSDragOperationGeneric;
103 return NSDragOperationNone;
107 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
112 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
114 NSPasteboard *o_paste = [sender draggingPasteboard];
115 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
116 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
117 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
121 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
124 NSArray *o_array = [NSArray array];
125 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
126 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
128 for( i = 0; i < (int)[o_values count]; i++)
131 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
132 o_array = [o_array arrayByAddingObject: o_dic];
134 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
138 [self setNeedsDisplay:YES];
142 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
144 [self setNeedsDisplay:YES];
149 /*****************************************************************************
150 * VLBrushedMetalImageView
151 *****************************************************************************/
153 @implementation VLBrushedMetalImageView
155 - (BOOL)mouseDownCanMoveWindow
162 [self unregisterDraggedTypes];
168 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
169 NSFilenamesPboardType, nil]];
172 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
174 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
175 == NSDragOperationGeneric)
177 return NSDragOperationGeneric;
181 return NSDragOperationNone;
185 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
190 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
192 NSPasteboard *o_paste = [sender draggingPasteboard];
193 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
194 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
195 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
199 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
202 NSArray *o_array = [NSArray array];
203 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
204 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
206 for( i = 0; i < (int)[o_values count]; i++)
209 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
210 o_array = [o_array arrayByAddingObject: o_dic];
212 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
216 [self setNeedsDisplay:YES];
220 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
222 [self setNeedsDisplay:YES];
228 /*****************************************************************************
230 *****************************************************************************/
231 @implementation MPSlider
233 void _drawKnobInRect(NSRect knobRect)
235 // Center knob in given rect
236 knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
237 knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
240 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
241 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
242 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 4, 5, 1), NSCompositeSourceOver);
243 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 0, knobRect.origin.y + 3, 7, 1), NSCompositeSourceOver);
244 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 2, 5, 1), NSCompositeSourceOver);
245 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 1, 3, 1), NSCompositeSourceOver);
246 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 0, 1, 1), NSCompositeSourceOver);
249 void _drawFrameInRect(NSRect frameRect)
252 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
253 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
254 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
255 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
258 - (void)drawRect:(NSRect)rect
260 // Draw default to make sure the slider behaves correctly
261 [[NSGraphicsContext currentContext] saveGraphicsState];
262 NSRectClip(NSZeroRect);
263 [super drawRect:rect];
264 [[NSGraphicsContext currentContext] restoreGraphicsState];
267 rect = [self bounds];
268 int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
269 rect.origin.x += diff-1;
270 rect.origin.y += diff;
271 rect.size.width -= 2*diff-2;
272 rect.size.height -= 2*diff;
275 NSRect knobRect = [[self cell] knobRectFlipped:NO];
276 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
277 _drawFrameInRect(rect);
278 _drawKnobInRect(knobRect);
281 [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
286 _drawFrameInRect(rect);
287 _drawKnobInRect(knobRect);