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