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];
181 if ([o_desired_type isEqualToString:NSFilenamesPboardType])
184 NSArray *o_array = [NSArray array];
185 NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
186 sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
188 for( i = 0; i < (int)[o_values count]; i++)
191 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
192 o_array = [o_array arrayByAddingObject: o_dic];
194 [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
198 [self setNeedsDisplay:YES];
202 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
204 [self setNeedsDisplay:YES];
210 /*****************************************************************************
212 *****************************************************************************/
213 @implementation MPSlider
215 void _drawKnobInRect(NSRect knobRect)
217 // Center knob in given rect
218 knobRect.origin.x += (int)((float)(knobRect.size.width - 7)/2.0);
219 knobRect.origin.y += (int)((float)(knobRect.size.height - 7)/2.0);
222 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 6, 1, 1), NSCompositeSourceOver);
223 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 5, 3, 1), NSCompositeSourceOver);
224 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 4, 5, 1), NSCompositeSourceOver);
225 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 0, knobRect.origin.y + 3, 7, 1), NSCompositeSourceOver);
226 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 1, knobRect.origin.y + 2, 5, 1), NSCompositeSourceOver);
227 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 2, knobRect.origin.y + 1, 3, 1), NSCompositeSourceOver);
228 NSRectFillUsingOperation(NSMakeRect(knobRect.origin.x + 3, knobRect.origin.y + 0, 1, 1), NSCompositeSourceOver);
231 void _drawFrameInRect(NSRect frameRect)
234 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, frameRect.size.width, 1), NSCompositeSourceOver);
235 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y + frameRect.size.height-1, frameRect.size.width, 1), NSCompositeSourceOver);
236 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
237 NSRectFillUsingOperation(NSMakeRect(frameRect.origin.x+frameRect.size.width-1, frameRect.origin.y, 1, frameRect.size.height), NSCompositeSourceOver);
240 - (void)drawRect:(NSRect)rect
242 // Draw default to make sure the slider behaves correctly
243 [[NSGraphicsContext currentContext] saveGraphicsState];
244 NSRectClip(NSZeroRect);
245 [super drawRect:rect];
246 [[NSGraphicsContext currentContext] restoreGraphicsState];
249 rect = [self bounds];
250 int diff = (int)(([[self cell] knobThickness] - 7.0)/2.0) - 1;
251 rect.origin.x += diff-1;
252 rect.origin.y += diff;
253 rect.size.width -= 2*diff-2;
254 rect.size.height -= 2*diff;
257 NSRect knobRect = [[self cell] knobRectFlipped:NO];
258 [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
259 _drawFrameInRect(rect);
260 _drawKnobInRect(knobRect);
263 [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
268 _drawFrameInRect(rect);
269 _drawKnobInRect(knobRect);
275 /*****************************************************************************
277 *****************************************************************************/
279 @implementation ITSlider
283 if ([[self cell] class] != [ITSliderCell class]) {
285 NSSliderCell *oldCell = [self cell];
286 NSSliderCell *newCell = [[[ITSliderCell alloc] init] autorelease];
287 [newCell setTag:[oldCell tag]];
288 [newCell setTarget:[oldCell target]];
289 [newCell setAction:[oldCell action]];
290 [newCell setControlSize:[oldCell controlSize]];
291 [newCell setType:[oldCell type]];
292 [newCell setState:[oldCell state]];
293 [newCell setAllowsTickMarkValuesOnly:[oldCell allowsTickMarkValuesOnly]];
294 [newCell setAltIncrementValue:[oldCell altIncrementValue]];
295 [newCell setControlTint:[oldCell controlTint]];
296 [newCell setKnobThickness:[oldCell knobThickness]];
297 [newCell setMaxValue:[oldCell maxValue]];
298 [newCell setMinValue:[oldCell minValue]];
299 [newCell setDoubleValue:[oldCell doubleValue]];
300 [newCell setNumberOfTickMarks:[oldCell numberOfTickMarks]];
301 [newCell setEditable:[oldCell isEditable]];
302 [newCell setEnabled:[oldCell isEnabled]];
303 [newCell setEntryType:[oldCell entryType]];
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];