1 /*****************************************************************************
2 * misc.m: code not specific to vlc
3 *****************************************************************************
4 * Copyright (C) 2003-2007 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include <Cocoa/Cocoa.h>
26 #include "intf.h" /* VLCApplication */
31 /*****************************************************************************
33 *****************************************************************************/
35 @implementation VLCControllerWindow
37 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
38 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
40 self = [super initWithContentRect:contentRect styleMask:styleMask //& ~NSTitledWindowMask
41 backing:backingType defer:flag];
43 [[VLCMain sharedInstance] updateTogglePlaylistState];
48 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
50 /* We indeed want to prioritize Cocoa key equivalent against libvlc,
51 so we perform the menu equivalent now. */
52 if([[NSApp mainMenu] performKeyEquivalent:o_event])
55 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event] ||
56 [(VLCControls *)[[VLCMain sharedInstance] getControls] keyEvent:o_event];
63 /*****************************************************************************
65 *****************************************************************************/
67 @implementation VLCControllerView
71 [self unregisterDraggedTypes];
78 /* dealloc doesn't get called on 10.5 if GC is enabled, so we need to provide the basic functionality here */
79 [self unregisterDraggedTypes];
86 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
87 NSFilenamesPboardType, nil]];
90 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
92 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
93 == NSDragOperationGeneric)
95 return NSDragOperationGeneric;
99 return NSDragOperationNone;
103 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
108 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
110 NSPasteboard *o_paste = [sender draggingPasteboard];
111 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
112 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
113 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
117 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
120 NSArray *o_array = [NSArray array];
121 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
122 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
124 for( i = 0; i < (int)[o_values count]; i++)
127 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
128 o_array = [o_array arrayByAddingObject: o_dic];
130 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
134 [self setNeedsDisplay:YES];
138 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
140 [self setNeedsDisplay:YES];
145 /*****************************************************************************
146 * VLBrushedMetalImageView
147 *****************************************************************************/
149 @implementation VLBrushedMetalImageView
151 - (BOOL)mouseDownCanMoveWindow
158 [self unregisterDraggedTypes];
165 /* dealloc doesn't get called on 10.5 if GC is enabled, so we need to provide the basic functionality here */
166 [self unregisterDraggedTypes];
173 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
174 NSFilenamesPboardType, nil]];
177 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
179 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
180 == NSDragOperationGeneric)
182 return NSDragOperationGeneric;
186 return NSDragOperationNone;
190 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
195 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
197 NSPasteboard *o_paste = [sender draggingPasteboard];
198 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
199 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
200 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
201 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
205 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
208 NSArray *o_array = [NSArray array];
209 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
210 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
212 for( i = 0; i < (int)[o_values count]; i++)
215 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
216 o_array = [o_array arrayByAddingObject: o_dic];
219 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
221 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:YES];
225 [self setNeedsDisplay:YES];
229 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
231 [self setNeedsDisplay:YES];
237 /*****************************************************************************
239 *****************************************************************************/
240 @implementation MPSlider
242 void _drawKnobInRect(NSRect knobRect)
244 // Center knob in given rect
245 knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
246 knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
249 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
250 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
251 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 4, 5, 1), NSCompositeSourceOver);
252 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 0, knobRect.origin.y + 3, 7, 1), NSCompositeSourceOver);
253 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 2, 5, 1), NSCompositeSourceOver);
254 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 1, 3, 1), NSCompositeSourceOver);
255 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 0, 1, 1), NSCompositeSourceOver);
258 void _drawFrameInRect(NSRect frameRect)
261 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
262 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
263 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
264 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
267 - (void)drawRect:(NSRect)rect
269 // Draw default to make sure the slider behaves correctly
270 [[NSGraphicsContext currentContext] saveGraphicsState];
271 NSRectClip(NSZeroRect);
272 [super drawRect:rect];
273 [[NSGraphicsContext currentContext] restoreGraphicsState];
276 rect = [self bounds];
277 int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
278 rect.origin.x += diff-1;
279 rect.origin.y += diff;
280 rect.size.width -= 2*diff-2;
281 rect.size.height -= 2*diff;
284 NSRect knobRect = [[self cell] knobRectFlipped:NO];
285 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
286 _drawFrameInRect(rect);
287 _drawKnobInRect(knobRect);
290 [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
295 _drawFrameInRect(rect);
296 _drawKnobInRect(knobRect);
302 /*****************************************************************************
304 *****************************************************************************/
306 @implementation ITSlider
310 if ([[self cell] class] != [ITSliderCell class]) {
312 NSSliderCell *oldCell = [self cell];
313 NSSliderCell *newCell = [[[ITSliderCell alloc] init] autorelease];
314 [newCell setTag:[oldCell tag]];
315 [newCell setTarget:[oldCell target]];
316 [newCell setAction:[oldCell action]];
317 [newCell setControlSize:[oldCell controlSize]];
318 [newCell setType:[oldCell type]];
319 [newCell setState:[oldCell state]];
320 [newCell setAllowsTickMarkValuesOnly:[oldCell allowsTickMarkValuesOnly]];
321 [newCell setAltIncrementValue:[oldCell altIncrementValue]];
322 [newCell setControlTint:[oldCell controlTint]];
323 [newCell setKnobThickness:[oldCell knobThickness]];
324 [newCell setMaxValue:[oldCell maxValue]];
325 [newCell setMinValue:[oldCell minValue]];
326 [newCell setDoubleValue:[oldCell doubleValue]];
327 [newCell setNumberOfTickMarks:[oldCell numberOfTickMarks]];
328 [newCell setEditable:[oldCell isEditable]];
329 [newCell setEnabled:[oldCell isEnabled]];
330 [newCell setEntryType:[oldCell entryType]];
331 [newCell setHighlighted:[oldCell isHighlighted]];
332 [newCell setTickMarkPosition:[oldCell tickMarkPosition]];
333 [self setCell:newCell];
339 /*****************************************************************************
341 *****************************************************************************/
342 @implementation ITSliderCell
347 _knobOff = [[NSImage imageNamed:@"volumeslider_normal"] retain];
348 _knobOn = [[NSImage imageNamed:@"volumeslider_blue"] retain];
349 b_mouse_down = FALSE;
360 - (void)drawKnob:(NSRect)knob_rect
369 [[self controlView] lockFocus];
370 [knob compositeToPoint:NSMakePoint( knob_rect.origin.x + 1,
371 knob_rect.origin.y + knob_rect.size.height -2 )
372 operation:NSCompositeSourceOver];
373 [[self controlView] unlockFocus];
376 - (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:
377 (NSView *)controlView mouseIsUp:(BOOL)flag
381 [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
384 - (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
388 return [super startTrackingAt:startPoint inView:controlView];