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 /*****************************************************************************
34 * Missing extension to NSWindow
35 *****************************************************************************/
37 @implementation VLCWindow
38 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
39 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
41 self = [super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag];
43 b_isset_canBecomeKeyWindow = NO;
46 - (void)setCanBecomeKeyWindow: (BOOL)canBecomeKey
48 b_isset_canBecomeKeyWindow = YES;
49 b_canBecomeKeyWindow = canBecomeKey;
52 - (BOOL)canBecomeKeyWindow
54 if(b_isset_canBecomeKeyWindow)
55 return b_canBecomeKeyWindow;
57 return [super canBecomeKeyWindow];
61 /*****************************************************************************
63 *****************************************************************************/
65 @implementation VLCControllerWindow
67 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
68 backing:(NSBackingStoreType)backingType defer:(BOOL)flag
70 self = [super initWithContentRect:contentRect styleMask:styleMask //& ~NSTitledWindowMask
71 backing:backingType defer:flag];
73 [[VLCMain sharedInstance] updateTogglePlaylistState];
78 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
80 /* We indeed want to prioritize Cocoa key equivalent against libvlc,
81 so we perform the menu equivalent now. */
82 if([[NSApp mainMenu] performKeyEquivalent:o_event])
85 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event] ||
86 [(VLCControls *)[[VLCMain sharedInstance] getControls] keyEvent:o_event];
93 /*****************************************************************************
95 *****************************************************************************/
97 @implementation VLCControllerView
101 [self unregisterDraggedTypes];
108 /* dealloc doesn't get called on 10.5 if GC is enabled, so we need to provide the basic functionality here */
109 [self unregisterDraggedTypes];
116 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
117 NSFilenamesPboardType, nil]];
120 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
122 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
123 == NSDragOperationGeneric)
125 return NSDragOperationGeneric;
129 return NSDragOperationNone;
133 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
138 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
140 NSPasteboard *o_paste = [sender draggingPasteboard];
141 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
142 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
143 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
147 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
150 NSArray *o_array = [NSArray array];
151 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
152 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
154 for( i = 0; i < (int)[o_values count]; i++)
157 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
158 o_array = [o_array arrayByAddingObject: o_dic];
160 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
164 [self setNeedsDisplay:YES];
168 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
170 [self setNeedsDisplay:YES];
175 /*****************************************************************************
176 * VLBrushedMetalImageView
177 *****************************************************************************/
179 @implementation VLBrushedMetalImageView
181 - (BOOL)mouseDownCanMoveWindow
188 [self unregisterDraggedTypes];
195 /* dealloc doesn't get called on 10.5 if GC is enabled, so we need to provide the basic functionality here */
196 [self unregisterDraggedTypes];
203 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
204 NSFilenamesPboardType, nil]];
207 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
209 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
210 == NSDragOperationGeneric)
212 return NSDragOperationGeneric;
216 return NSDragOperationNone;
220 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
225 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
227 NSPasteboard *o_paste = [sender draggingPasteboard];
228 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
229 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
230 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
231 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
235 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
238 NSArray *o_array = [NSArray array];
239 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
240 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
242 for( i = 0; i < (int)[o_values count]; i++)
245 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
246 o_array = [o_array arrayByAddingObject: o_dic];
249 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
251 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:YES];
255 [self setNeedsDisplay:YES];
259 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
261 [self setNeedsDisplay:YES];
267 /*****************************************************************************
269 *****************************************************************************/
270 @implementation MPSlider
272 void _drawKnobInRect(NSRect knobRect)
274 // Center knob in given rect
275 knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
276 knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
279 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
280 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
281 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 4, 5, 1), NSCompositeSourceOver);
282 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 0, knobRect.origin.y + 3, 7, 1), NSCompositeSourceOver);
283 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 2, 5, 1), NSCompositeSourceOver);
284 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 1, 3, 1), NSCompositeSourceOver);
285 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 0, 1, 1), NSCompositeSourceOver);
288 void _drawFrameInRect(NSRect frameRect)
291 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
292 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
293 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
294 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
297 - (void)drawRect:(NSRect)rect
299 // Draw default to make sure the slider behaves correctly
300 [[NSGraphicsContext currentContext] saveGraphicsState];
301 NSRectClip(NSZeroRect);
302 [super drawRect:rect];
303 [[NSGraphicsContext currentContext] restoreGraphicsState];
306 rect = [self bounds];
307 int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
308 rect.origin.x += diff-1;
309 rect.origin.y += diff;
310 rect.size.width -= 2*diff-2;
311 rect.size.height -= 2*diff;
314 NSRect knobRect = [[self cell] knobRectFlipped:NO];
315 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
316 _drawFrameInRect(rect);
317 _drawKnobInRect(knobRect);
320 [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
325 _drawFrameInRect(rect);
326 _drawKnobInRect(knobRect);
332 /*****************************************************************************
334 *****************************************************************************/
336 @implementation ITSlider
340 if ([[self cell] class] != [ITSliderCell class]) {
342 NSSliderCell *oldCell = [self cell];
343 NSSliderCell *newCell = [[[ITSliderCell alloc] init] autorelease];
344 [newCell setTag:[oldCell tag]];
345 [newCell setTarget:[oldCell target]];
346 [newCell setAction:[oldCell action]];
347 [newCell setControlSize:[oldCell controlSize]];
348 [newCell setType:[oldCell type]];
349 [newCell setState:[oldCell state]];
350 [newCell setAllowsTickMarkValuesOnly:[oldCell allowsTickMarkValuesOnly]];
351 [newCell setAltIncrementValue:[oldCell altIncrementValue]];
352 [newCell setControlTint:[oldCell controlTint]];
353 [newCell setKnobThickness:[oldCell knobThickness]];
354 [newCell setMaxValue:[oldCell maxValue]];
355 [newCell setMinValue:[oldCell minValue]];
356 [newCell setDoubleValue:[oldCell doubleValue]];
357 [newCell setNumberOfTickMarks:[oldCell numberOfTickMarks]];
358 [newCell setEditable:[oldCell isEditable]];
359 [newCell setEnabled:[oldCell isEnabled]];
360 [newCell setEntryType:[oldCell entryType]];
361 [newCell setHighlighted:[oldCell isHighlighted]];
362 [newCell setTickMarkPosition:[oldCell tickMarkPosition]];
363 [self setCell:newCell];
369 /*****************************************************************************
371 *****************************************************************************/
372 @implementation ITSliderCell
377 _knobOff = [[NSImage imageNamed:@"volumeslider_normal"] retain];
378 _knobOn = [[NSImage imageNamed:@"volumeslider_blue"] retain];
379 b_mouse_down = FALSE;
390 - (void)drawKnob:(NSRect)knob_rect
399 [[self controlView] lockFocus];
400 [knob compositeToPoint:NSMakePoint( knob_rect.origin.x + 1,
401 knob_rect.origin.y + knob_rect.size.height -2 )
402 operation:NSCompositeSourceOver];
403 [[self controlView] unlockFocus];
406 - (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:
407 (NSView *)controlView mouseIsUp:(BOOL)flag
411 [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
414 - (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
418 return [super startTrackingAt:startPoint inView:controlView];