]> git.sesse.net Git - vlc/blob - modules/gui/macosx/misc.m
Copyright fixes
[vlc] / modules / gui / macosx / misc.m
1 /*****************************************************************************
2  * misc.m: code not specific to vlc
3  *****************************************************************************
4  * Copyright (C) 2003-2005 VideoLAN (Centrale Réseaux) and its contributors
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     [[VLCMain sharedInstance] updateTogglePlaylistState];
43
44     return( self );
45 }
46
47 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
48 {
49     return [[VLCMain sharedInstance] hasDefinedShortcutKey:o_event];
50 }
51
52 @end
53
54
55
56 /*****************************************************************************
57  * VLCControllerView
58  *****************************************************************************/
59
60 @implementation VLCControllerView
61
62 - (void)dealloc
63 {
64     [self unregisterDraggedTypes];
65     [super dealloc];
66 }
67
68 - (void)awakeFromNib
69 {
70     [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, 
71         NSFilenamesPboardType, nil]];
72 }
73
74 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
75 {
76     if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) 
77                 == NSDragOperationGeneric)
78     {
79         return NSDragOperationGeneric;
80     }
81     else
82     {
83         return NSDragOperationNone;
84     }
85 }
86
87 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
88 {
89     return YES;
90 }
91
92 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
93 {
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];
98
99     if( o_carried_data )
100     {
101         if ([o_desired_type isEqualToString:NSFilenamesPboardType])
102         {
103             int i;
104             NSArray *o_array = [NSArray array];
105             NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
106                         sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
107
108             for( i = 0; i < (int)[o_values count]; i++)
109             {
110                 NSDictionary *o_dic;
111                 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
112                 o_array = [o_array arrayByAddingObject: o_dic];
113             }
114             [(VLCPlaylist *)[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
115             return YES;
116         }
117     }
118     [self setNeedsDisplay:YES];
119     return YES;
120 }
121
122 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
123 {
124     [self setNeedsDisplay:YES];
125 }
126
127 @end
128
129 /*****************************************************************************
130  * VLBrushedMetalImageView
131  *****************************************************************************/
132
133 @implementation VLBrushedMetalImageView
134
135 - (BOOL)mouseDownCanMoveWindow
136 {
137     return YES;
138 }
139
140 - (void)dealloc
141 {
142     [self unregisterDraggedTypes];
143     [super dealloc];
144 }
145
146 - (void)awakeFromNib
147 {
148     [self registerForDraggedTypes:[NSArray arrayWithObjects:NSTIFFPboardType, 
149         NSFilenamesPboardType, nil]];
150 }
151
152 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
153 {
154     if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) 
155                 == NSDragOperationGeneric)
156     {
157         return NSDragOperationGeneric;
158     }
159     else
160     {
161         return NSDragOperationNone;
162     }
163 }
164
165 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
166 {
167     return YES;
168 }
169
170 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
171 {
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];
176
177     if( o_carried_data )
178     {
179         if ([o_desired_type isEqualToString:NSFilenamesPboardType])
180         {
181             int i;
182             NSArray *o_array = [NSArray array];
183             NSArray *o_values = [[o_paste propertyListForType: NSFilenamesPboardType]
184                         sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
185
186             for( i = 0; i < (int)[o_values count]; i++)
187             {
188                 NSDictionary *o_dic;
189                 o_dic = [NSDictionary dictionaryWithObject:[o_values objectAtIndex:i] forKey:@"ITEM_URL"];
190                 o_array = [o_array arrayByAddingObject: o_dic];
191             }
192             [[[VLCMain sharedInstance] getPlaylist] appendArray: o_array atPos: -1 enqueue:NO];
193             return YES;
194         }
195     }
196     [self setNeedsDisplay:YES];
197     return YES;
198 }
199
200 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
201 {
202     [self setNeedsDisplay:YES];
203 }
204
205 @end
206
207
208 /*****************************************************************************
209  * MPSlider
210  *****************************************************************************/
211 @implementation MPSlider
212
213 void _drawKnobInRect(NSRect knobRect)
214 {
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);
218     
219     // Draw diamond
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);
227 }
228
229 void _drawFrameInRect(NSRect frameRect)
230 {
231     // Draw frame
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);
236 }
237
238 - (void)drawRect:(NSRect)rect
239 {
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];
245     
246     // Full size
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;
253     
254     // Draw dark
255     NSRect knobRect = [[self cell] knobRectFlipped:NO];
256     [[[NSColor blackColor] colorWithAlphaComponent:0.6] set];
257     _drawFrameInRect(rect);
258     _drawKnobInRect(knobRect);
259     
260     // Draw shadow
261     [[[NSColor blackColor] colorWithAlphaComponent:0.1] set];
262     rect.origin.x++;
263     rect.origin.y++;
264     knobRect.origin.x++;
265     knobRect.origin.y++;
266     _drawFrameInRect(rect);
267     _drawKnobInRect(knobRect);
268 }
269
270 @end
271