]> git.sesse.net Git - vlc/blob - modules/gui/macosx/misc.m
* Mac OS X: intercept and respond to user-configured VLC hotkeys, rather
[vlc] / modules / gui / macosx / misc.m
1 /*****************************************************************************
2  * misc.m: code not specific to vlc
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include <Cocoa/Cocoa.h>
25
26 #include "intf.h"                                          /* VLCApplication */
27 #include "misc.h"
28 #include "playlist.h"
29
30 /*****************************************************************************
31  * VLCControllerWindow
32  *****************************************************************************/
33
34 @implementation VLCControllerWindow
35
36 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask
37     backing:(NSBackingStoreType)backingType defer:(BOOL)flag
38 {
39     self = [super initWithContentRect:contentRect styleMask:styleMask //& ~NSTitledWindowMask
40     backing:backingType defer:flag];
41
42     return( self );
43 }
44
45 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
46 {
47     return [( (VLCApplication *) [VLCApplication sharedApplication] )
48             hasDefinedShortcutKey:o_event];
49 }
50
51 @end
52
53
54
55 /*****************************************************************************
56  * VLCControllerView
57  *****************************************************************************/
58
59 @implementation VLCControllerView
60
61 - (void)dealloc
62 {
63     [self unregisterDraggedTypes];
64     [super dealloc];
65 }
66
67 - (void)awakeFromNib
68 {
69     [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, 
70         NSFilenamesPboardType, nil]];
71 }
72
73 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
74 {
75     if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) 
76                 == NSDragOperationGeneric)
77     {
78         return NSDragOperationGeneric;
79     }
80     else
81     {
82         return NSDragOperationNone;
83     }
84 }
85
86 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
87 {
88     return YES;
89 }
90
91 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
92 {
93     NSPasteboard *o_paste = [sender draggingPasteboard];
94     NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
95     NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
96     NSData *o_carried_data = [o_paste dataForType:o_desired_type];
97
98     if( o_carried_data )
99     {
100         if ([o_desired_type isEqualToString:NSFilenamesPboardType])
101         {
102             int i;
103             NSArray *o_array = [NSArray array];
104             NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
105                         sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
106
107             for( i = 0; i < (int)[o_values count]; i++)
108             {
109                 NSDictionary *o_dic;
110                 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
111                 o_array = [o_array arrayByAddingObject: o_dic];
112             }
113             [(VLCPlaylist *)[[NSApp delegate] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
114             return YES;
115         }
116     }
117     [self setNeedsDisplay:YES];
118     return YES;
119 }
120
121 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
122 {
123     [self setNeedsDisplay:YES];
124 }
125
126 @end
127
128 /*****************************************************************************
129  * VLBrushedMetalImageView
130  *****************************************************************************/
131
132 @implementation VLBrushedMetalImageView
133
134 - (BOOL)mouseDownCanMoveWindow
135 {
136     return YES;
137 }
138
139 - (void)dealloc
140 {
141     [self unregisterDraggedTypes];
142     [super dealloc];
143 }
144
145 - (void)awakeFromNib
146 {
147     [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, 
148         NSFilenamesPboardType, nil]];
149 }
150
151 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
152 {
153     if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) 
154                 == NSDragOperationGeneric)
155     {
156         return NSDragOperationGeneric;
157     }
158     else
159     {
160         return NSDragOperationNone;
161     }
162 }
163
164 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
165 {
166     return YES;
167 }
168
169 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
170 {
171     NSPasteboard *o_paste = [sender draggingPasteboard];
172     NSArray *o_types = [NSArray arrayWithObjects: NSFilenamesPboardType, nil];
173     NSString *o_desired_type = [o_paste availableTypeFromArray:o_types];
174     NSData *o_carried_data = [o_paste dataForType:o_desired_type];
175
176     if( o_carried_data )
177     {
178         if ([o_desired_type isEqualToString:NSFilenamesPboardType])
179         {
180             int i;
181             NSArray *o_array = [NSArray array];
182             NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
183                         sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
184
185             for( i = 0; i < (int)[o_values count]; i++)
186             {
187                 NSDictionary *o_dic;
188                 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
189                 o_array = [o_array arrayByAddingObject: o_dic];
190             }
191             [(VLCPlaylist *)[[NSApp delegate] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
192             return YES;
193         }
194     }
195     [self setNeedsDisplay:YES];
196     return YES;
197 }
198
199 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
200 {
201     [self setNeedsDisplay:YES];
202 }
203
204 @end
205
206
207 /*****************************************************************************
208  * MPSlider
209  *****************************************************************************/
210
211 @implementation MPSlider
212
213 + (Class)cellClass
214 {
215     return( [MPSliderCell class] );
216 }
217
218 @end
219
220 /*****************************************************************************
221  * MPSliderCell
222  *****************************************************************************/
223
224 @implementation MPSliderCell
225
226 - (id)init
227 {
228     self = [super init];
229
230     if( self != nil )
231     {
232         _bgColor = [[NSColor colorWithDeviceRed: 0.8627451
233                                                 green: 0.8784314
234                                                 blue: 0.7725490
235                                                 alpha: 1.0] retain];
236         _knobColor = [[NSColor blackColor] retain];
237     }
238         NSLog(@"boe");
239     return( self );
240 }
241
242 - (void)dealloc
243 {
244     [_bgColor release];
245     [_knobColor release];
246     [super dealloc];
247 }
248
249 - (void)setBackgroundColor:(NSColor *)newColor
250 {
251     [_bgColor release];  
252     _bgColor = [newColor retain];
253 }
254
255 - (NSColor *)backgroundColor
256 {
257     return( _bgColor );
258 }
259
260 - (void)setKnobColor:(NSColor *)newColor
261 {
262     [_knobColor release];  
263     _knobColor = [newColor retain];
264 }
265
266 - (NSColor *)knobColor
267 {
268     return( _knobColor );
269 }
270
271 - (void)setKnobThickness:(float)f_value
272 {
273     _knobThickness = f_value;
274 }
275
276 - (float)knobThickness
277 {
278     return( _knobThickness );
279 }
280
281 - (NSSize)cellSizeForBounds:(NSRect)s_rc
282 {
283     return( s_rc.size );
284 }
285
286 - (void)drawWithFrame:(NSRect)s_rc inView:(NSView *)o_view
287 {
288     if( _scFlags.weAreVertical )
289     {
290         s_rc.origin.x = 1; s_rc.size.width -= 3;
291         s_rc.origin.y = 2; s_rc.size.height -= 5;    
292     }
293     else
294     {
295         s_rc.origin.x = 2; s_rc.size.width -= 5;
296         s_rc.origin.y = 1; s_rc.size.height -= 3;
297     }
298
299     [super drawWithFrame: s_rc inView: o_view]; 
300 }
301
302 - (void)drawBarInside:(NSRect)s_rc flipped:(BOOL)b_flipped
303 {
304     NSRect s_arc;
305  
306     s_rc.size.width += (s_rc.origin.x * 2) + 1;
307     s_rc.size.height += (s_rc.origin.y * 2) + 1;
308     s_rc.origin.x = s_rc.origin.y = 0;
309
310     [[NSGraphicsContext currentContext] setShouldAntialias: NO];
311
312     [_bgColor set];
313     NSRectFill( s_rc );
314
315     s_arc = s_rc;
316     s_arc.origin.x += 1.5;
317     s_arc.origin.y += 1.5;
318     s_arc.size.width -= s_arc.origin.x;
319     s_arc.size.height -= s_arc.origin.y;
320     [[_bgColor shadowWithLevel: 0.1] set];
321     [NSBezierPath strokeRect: s_arc];
322
323     s_arc.origin = s_rc.origin;
324     [[NSColor blackColor] set];
325     [NSBezierPath strokeRect: s_arc];
326
327     [[NSGraphicsContext currentContext] setShouldAntialias: YES];
328 }
329
330 - (NSRect)knobRectFlipped:(BOOL)b_flipped
331 {
332     NSSize s_size;
333     NSPoint s_pto;
334     float floatValue;
335
336     floatValue = [self floatValue];
337
338     if( _scFlags.weAreVertical && b_flipped )
339     {
340         floatValue = _maxValue + _minValue - floatValue;
341     }
342
343     floatValue = (floatValue - _minValue) / (_maxValue - _minValue);
344
345     if( _scFlags.weAreVertical )
346     {   
347         s_size = NSMakeSize( _trackRect.size.width, _knobThickness ?
348                              _knobThickness : _trackRect.size.width );
349         s_pto = _trackRect.origin;
350         s_pto.y += (_trackRect.size.height - s_size.height) * floatValue;
351     }
352     else
353     {   
354         s_size = NSMakeSize( _knobThickness ? _knobThickness :
355                              _trackRect.size.height, _trackRect.size.height );
356         s_pto = _trackRect.origin;
357         s_pto.x += (_trackRect.size.width - s_size.width) * floatValue;
358     }
359
360     return NSMakeRect( s_pto.x, s_pto.y, s_size.width, s_size.height );
361 }
362
363 - (void)drawKnob:(NSRect)s_rc
364 {
365     [[NSGraphicsContext currentContext] setShouldAntialias: NO];
366
367     [_knobColor set];
368     NSRectFill( s_rc );
369
370     [[NSGraphicsContext currentContext] setShouldAntialias: YES];
371 }
372
373 @end