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., 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 [[VLCMain sharedInstance] updateTogglePlaylistState];
47 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
49 return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
56 /*****************************************************************************
58 *****************************************************************************/
60 @implementation VLCControllerView
64 [self unregisterDraggedTypes];
70 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
71 NSFilenamesPboardType, nil]];
74 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
76 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
77 == NSDragOperationGeneric)
79 return NSDragOperationGeneric;
83 return NSDragOperationNone;
87 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
92 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
94 NSPasteboard *o_paste = [sender draggingPasteboard];
95 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
96 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
97 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
101 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
104 NSArray *o_array = [NSArray array];
105 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
106 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
108 for( i = 0; i < (int)[o_values count]; i++)
111 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
112 o_array = [o_array arrayByAddingObject: o_dic];
114 [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
118 [self setNeedsDisplay:YES];
122 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
124 [self setNeedsDisplay:YES];
129 /*****************************************************************************
130 * VLBrushedMetalImageView
131 *****************************************************************************/
133 @implementation VLBrushedMetalImageView
135 - (BOOL)mouseDownCanMoveWindow
142 [self unregisterDraggedTypes];
148 [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType,
149 NSFilenamesPboardType, nil]];
152 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
154 if ((NSDragOperationGeneric & [sender draggingSourceOperationMask])
155 == NSDragOperationGeneric)
157 return NSDragOperationGeneric;
161 return NSDragOperationNone;
165 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
170 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
172 NSPasteboard *o_paste = [sender draggingPasteboard];
173 NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
174 NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
175 NSData *o_carried_data = [o_paste dataForType:o_desired_type];
179 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
182 NSArray *o_array = [NSArray array];
183 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
184 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
186 for( i = 0; i < (int)[o_values count]; i++)
189 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
190 o_array = [o_array arrayByAddingObject: o_dic];
192 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
196 [self setNeedsDisplay:YES];
200 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
202 [self setNeedsDisplay:YES];
208 /*****************************************************************************
210 *****************************************************************************/
211 @implementation MPSlider
213 void _drawKnobInRect(NSRect knobRect)
215 // Center knob in given rect
216 knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
217 knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
220 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
221 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
222 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 4, 5, 1), NSCompositeSourceOver);
223 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 0, knobRect.origin.y + 3, 7, 1), NSCompositeSourceOver);
224 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 2, 5, 1), NSCompositeSourceOver);
225 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 1, 3, 1), NSCompositeSourceOver);
226 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 0, 1, 1), NSCompositeSourceOver);
229 void _drawFrameInRect(NSRect frameRect)
232 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
233 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
234 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
235 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
238 - (void)drawRect:(NSRect)rect
240 // Draw default to make sure the slider behaves correctly
241 [[NSGraphicsContext currentContext] saveGraphicsState];
242 NSRectClip(NSZeroRect);
243 [super drawRect:rect];
244 [[NSGraphicsContext currentContext] restoreGraphicsState];
247 rect = [self bounds];
248 int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
249 rect.origin.x += diff-1;
250 rect.origin.y += diff;
251 rect.size.width -= 2*diff-2;
252 rect.size.height -= 2*diff;
255 NSRect knobRect = [[self cell] knobRectFlipped:NO];
256 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
257 _drawFrameInRect(rect);
258 _drawKnobInRect(knobRect);
261 [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
266 _drawFrameInRect(rect);
267 _drawKnobInRect(knobRect);
273 /*****************************************************************************
275 *****************************************************************************/
277 @implementation ITSlider
281 if ([[self cell] class] != [ITSliderCell class]) {
283 NSSliderCell *oldCell = [self cell];
284 NSSliderCell *newCell = [[[ITSliderCell alloc] init] autorelease];
285 [newCell setTag:[oldCell tag]];
286 [newCell setTarget:[oldCell target]];
287 [newCell setAction:[oldCell action]];
288 [newCell setControlSize:[oldCell controlSize]];
289 [newCell setType:[oldCell type]];
290 [newCell setState:[oldCell state]];
291 [newCell setAllowsTickMarkValuesOnly:[oldCell allowsTickMarkValuesOnly]];
292 [newCell setAltIncrementValue:[oldCell altIncrementValue]];
293 [newCell setControlTint:[oldCell controlTint]];
294 [newCell setKnobThickness:[oldCell knobThickness]];
295 [newCell setMaxValue:[oldCell maxValue]];
296 [newCell setMinValue:[oldCell minValue]];
297 [newCell setDoubleValue:[oldCell doubleValue]];
298 [newCell setNumberOfTickMarks:[oldCell numberOfTickMarks]];
299 [newCell setSliderType:[oldCell sliderType]];
300 [newCell setEditable:[oldCell isEditable]];
301 [newCell setEnabled:[oldCell isEnabled]];
302 [newCell setEntryType:[oldCell entryType]];
303 [newCell setFocusRingType:[oldCell focusRingType]];
304 [newCell setHighlighted:[oldCell isHighlighted]];
305 [newCell setTickMarkPosition:[oldCell tickMarkPosition]];
306 [self setCell:newCell];
312 /*****************************************************************************
314 *****************************************************************************/
315 @implementation ITSliderCell
320 _knobOff = [[NSImage imageNamed:@"volumeslider_normal"] retain];
321 _knobOn = [[NSImage imageNamed:@"volumeslider_blue"] retain];
322 b_mouse_down = FALSE;
333 - (void)drawKnob:(NSRect)knob_rect
342 [[self controlView] lockFocus];
343 [knob compositeToPoint:NSMakePoint( knob_rect.origin.x + 1,
344 knob_rect.origin.y + knob_rect.size.height -2 )
345 operation:NSCompositeSourceOver];
346 [[self controlView] unlockFocus];
349 - (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:
350 (NSView *)controlView mouseIsUp:(BOOL)flag
354 [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
357 - (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
361 return [super startTrackingAt:startPoint inView:controlView];