1 /*****************************************************************************
2 * misc.m: code not specific to vlc
3 *****************************************************************************
4 * Copyright (C) 2003-2005 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 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event] ||
51 [(VLCControls *)[[VLCMain sharedInstance] getControls] keyEvent:o_event];
58 /*****************************************************************************
60 *****************************************************************************/
62 @implementation VLCControllerView
66 [self unregisterDraggedTypes];
72 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
73 NSFilenamesPboardType, nil]];
76 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
78 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
79 == NSDragOperationGeneric)
81 return NSDragOperationGeneric;
85 return NSDragOperationNone;
89 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
94 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
96 NSPasteboard *o_paste = [sender draggingPasteboard];
97 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
98 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
99 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
103 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
106 NSArray *o_array = [NSArray array];
107 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
108 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
110 for( i = 0; i < (int)[o_values count]; i++)
113 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
114 o_array = [o_array arrayByAddingObject: o_dic];
116 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
120 [self setNeedsDisplay:YES];
124 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
126 [self setNeedsDisplay:YES];
131 /*****************************************************************************
132 * VLBrushedMetalImageView
133 *****************************************************************************/
135 @implementation VLBrushedMetalImageView
137 - (BOOL)mouseDownCanMoveWindow
144 [self unregisterDraggedTypes];
150 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
151 NSFilenamesPboardType, nil]];
154 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
156 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
157 == NSDragOperationGeneric)
159 return NSDragOperationGeneric;
163 return NSDragOperationNone;
167 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
172 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
174 NSPasteboard *o_paste = [sender draggingPasteboard];
175 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
176 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
177 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
178 BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
182 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
185 NSArray *o_array = [NSArray array];
186 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
187 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
189 for( i = 0; i < (int)[o_values count]; i++)
192 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
193 o_array = [o_array arrayByAddingObject: o_dic];
196 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
198 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:YES];
202 [self setNeedsDisplay:YES];
206 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
208 [self setNeedsDisplay:YES];
214 /*****************************************************************************
216 *****************************************************************************/
217 @implementation MPSlider
219 void _drawKnobInRect(NSRect knobRect)
221 // Center knob in given rect
222 knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
223 knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
226 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
227 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
228 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 4, 5, 1), NSCompositeSourceOver);
229 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 0, knobRect.origin.y + 3, 7, 1), NSCompositeSourceOver);
230 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 2, 5, 1), NSCompositeSourceOver);
231 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 1, 3, 1), NSCompositeSourceOver);
232 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 0, 1, 1), NSCompositeSourceOver);
235 void _drawFrameInRect(NSRect frameRect)
238 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
239 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
240 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
241 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
244 - (void)drawRect:(NSRect)rect
246 // Draw default to make sure the slider behaves correctly
247 [[NSGraphicsContext currentContext] saveGraphicsState];
248 NSRectClip(NSZeroRect);
249 [super drawRect:rect];
250 [[NSGraphicsContext currentContext] restoreGraphicsState];
253 rect = [self bounds];
254 int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
255 rect.origin.x += diff-1;
256 rect.origin.y += diff;
257 rect.size.width -= 2*diff-2;
258 rect.size.height -= 2*diff;
261 NSRect knobRect = [[self cell] knobRectFlipped:NO];
262 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
263 _drawFrameInRect(rect);
264 _drawKnobInRect(knobRect);
267 [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
272 _drawFrameInRect(rect);
273 _drawKnobInRect(knobRect);
279 /*****************************************************************************
281 *****************************************************************************/
283 @implementation ITSlider
287 if ([[self cell] class] != [ITSliderCell class]) {
289 NSSliderCell *oldCell = [self cell];
290 NSSliderCell *newCell = [[[ITSliderCell alloc] init] autorelease];
291 [newCell setTag:[oldCell tag]];
292 [newCell setTarget:[oldCell target]];
293 [newCell setAction:[oldCell action]];
294 [newCell setControlSize:[oldCell controlSize]];
295 [newCell setType:[oldCell type]];
296 [newCell setState:[oldCell state]];
297 [newCell setAllowsTickMarkValuesOnly:[oldCell allowsTickMarkValuesOnly]];
298 [newCell setAltIncrementValue:[oldCell altIncrementValue]];
299 [newCell setControlTint:[oldCell controlTint]];
300 [newCell setKnobThickness:[oldCell knobThickness]];
301 [newCell setMaxValue:[oldCell maxValue]];
302 [newCell setMinValue:[oldCell minValue]];
303 [newCell setDoubleValue:[oldCell doubleValue]];
304 [newCell setNumberOfTickMarks:[oldCell numberOfTickMarks]];
305 [newCell setEditable:[oldCell isEditable]];
306 [newCell setEnabled:[oldCell isEnabled]];
307 [newCell setEntryType:[oldCell entryType]];
308 [newCell setHighlighted:[oldCell isHighlighted]];
309 [newCell setTickMarkPosition:[oldCell tickMarkPosition]];
310 [self setCell:newCell];
316 /*****************************************************************************
318 *****************************************************************************/
319 @implementation ITSliderCell
324 _knobOff = [[NSImage imageNamed:@"volumeslider_normal"] retain];
325 _knobOn = [[NSImage imageNamed:@"volumeslider_blue"] retain];
326 b_mouse_down = FALSE;
337 - (void)drawKnob:(NSRect)knob_rect
346 [[self controlView] lockFocus];
347 [knob compositeToPoint:NSMakePoint( knob_rect.origin.x + 1,
348 knob_rect.origin.y + knob_rect.size.height -2 )
349 operation:NSCompositeSourceOver];
350 [[self controlView] unlockFocus];
353 - (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:
354 (NSView *)controlView mouseIsUp:(BOOL)flag
358 [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
361 - (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
365 return [super startTrackingAt:startPoint inView:controlView];