]> git.sesse.net Git - vlc/blob - modules/gui/macosx/VideoView.m
macosx: remove outdated and unused isFullscreen methods
[vlc] / modules / gui / macosx / VideoView.m
1 /*****************************************************************************
2  * VideoView.m: MacOS X video output module
3  *****************************************************************************
4  * Copyright (C) 2002-2012 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
8  *          Eric Petit <titer@m0k.org>
9  *          Benjamin Pracht <bigben at videolan dot org>
10  *          Pierre d'Herbemont <pdherbemont # videolan org>
11  *          Felix Paul Kühne <fkuehne at videolan dot org>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26  *****************************************************************************/
27
28 /*****************************************************************************
29  * Preamble
30  *****************************************************************************/
31 #import <stdlib.h>                                                 /* free() */
32 #import <string.h>
33
34 #import "intf.h"
35 #import "VideoView.h"
36 #import "CoreInteraction.h"
37 #import "MainMenu.h"
38 #import "MainWindow.h"
39
40 #import <vlc_common.h>
41 #import <vlc_keys.h>
42
43 /*****************************************************************************
44  * DeviceCallback: Callback triggered when the video-device variable is changed
45  *****************************************************************************/
46 int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
47                      vlc_value_t old_val, vlc_value_t new_val, void *param )
48 {
49     vlc_value_t val;
50     vout_thread_t *p_vout = (vout_thread_t *)p_this;
51
52     msg_Dbg( p_vout, "set %"PRId64, new_val.i_int );
53     var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER );
54     var_Set( p_vout->p_libvlc, "video-device", new_val );
55
56     val.b_bool = true;
57     var_Set( p_vout, "intf-change", val );
58     return VLC_SUCCESS;
59 }
60
61 /*****************************************************************************
62  * VLCVoutView implementation
63  *****************************************************************************/
64 @implementation VLCVoutView
65
66 #pragma mark -
67 #pragma mark drag & drop support
68
69 - (void)dealloc
70 {
71     [self unregisterDraggedTypes];
72     [super dealloc];
73 }
74
75 - (void)awakeFromNib
76 {
77     [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]];
78
79     f_cumulated_magnification = 0.0;
80 }
81
82 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
83 {
84     if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
85         return NSDragOperationGeneric;
86     return NSDragOperationNone;
87 }
88
89 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
90 {
91     return YES;
92 }
93
94 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
95 {
96     BOOL b_returned;
97     b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];
98
99     [self setNeedsDisplay:YES];
100     return b_returned;
101 }
102
103 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
104 {
105     [self setNeedsDisplay:YES];
106 }
107
108 #pragma mark -
109 #pragma mark vout actions
110
111 - (void)closeVout
112 {
113     vout_thread_t * p_vout = getVout();
114     if( p_vout )
115     {
116         var_DelCallback( p_vout, "video-device", DeviceCallback, NULL );
117         vlc_object_release( p_vout );
118     }
119 }
120
121 - (void)scrollWheel:(NSEvent *)theEvent
122 {
123     VLCControls * o_controls = (VLCControls *)[[NSApp delegate] controls];
124     [o_controls scrollWheel: theEvent];
125 }
126
127 - (void)keyDown:(NSEvent *)o_event
128 {
129     unichar key = 0;
130     vlc_value_t val;
131     unsigned int i_pressed_modifiers = 0;
132     val.i_int = 0;
133
134     i_pressed_modifiers = [o_event modifierFlags];
135
136     if( i_pressed_modifiers & NSShiftKeyMask )
137         val.i_int |= KEY_MODIFIER_SHIFT;
138     if( i_pressed_modifiers & NSControlKeyMask )
139         val.i_int |= KEY_MODIFIER_CTRL;
140     if( i_pressed_modifiers & NSAlternateKeyMask )
141         val.i_int |= KEY_MODIFIER_ALT;
142     if( i_pressed_modifiers & NSCommandKeyMask )
143         val.i_int |= KEY_MODIFIER_COMMAND;
144
145     key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
146
147     if( key )
148     {
149         vout_thread_t * p_vout = getVout();
150         /* Escape should always get you out of fullscreen */
151         if( key == (unichar) 0x1b )
152         {
153             playlist_t * p_playlist = pl_Get( VLCIntf );
154             if( var_GetBool( p_playlist, "fullscreen" ) )
155                  [[VLCCoreInteraction sharedInstance] toggleFullscreen];
156         }
157         /* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
158         else if( key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask )
159             [[VLCCoreInteraction sharedInstance] toggleFullscreen];
160         else if ( p_vout )
161         {
162             if( key == ' ' )
163             {
164                 [[VLCCoreInteraction sharedInstance] play];
165             }
166             else
167             {
168                 val.i_int |= (int)CocoaKeyToVLC( key );
169                 var_Set( p_vout->p_libvlc, "key-pressed", val );
170             }
171         }
172         else
173             msg_Dbg( VLCIntf, "could not send keyevent to VLC core" );
174
175         if (p_vout)
176             vlc_object_release( p_vout );
177     }
178     else
179         [super keyDown: o_event];
180 }
181
182 - (BOOL)performKeyEquivalent:(NSEvent *)o_event
183 {
184     return [[VLCMainWindow sharedInstance] performKeyEquivalent: o_event];
185 }
186
187 - (void)mouseDown:(NSEvent *)o_event
188 {
189     if( ( [o_event type] == NSLeftMouseDown ) &&
190        ( ! ( [o_event modifierFlags] &  NSControlKeyMask ) ) )
191     {
192         if( [o_event clickCount] > 1 )
193         {
194             /* multiple clicking */
195             [[VLCCoreInteraction sharedInstance] toggleFullscreen];
196         }
197     }
198     else if( ( [o_event type] == NSRightMouseDown ) ||
199             ( ( [o_event type] == NSLeftMouseDown ) &&
200              ( [o_event modifierFlags] &  NSControlKeyMask ) ) )
201     {
202         [NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
203     }
204
205     [super mouseDown: o_event];
206 }
207
208 - (void)rightMouseDown:(NSEvent *)o_event
209 {
210     if( [o_event type] == NSRightMouseDown )
211         [NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
212
213     [super mouseDown: o_event];
214 }
215
216 - (void)rightMouseUp:(NSEvent *)o_event
217 {
218     if( [o_event type] == NSRightMouseUp )
219         [NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
220
221     [super mouseUp: o_event];
222 }
223
224 - (void)mouseMoved:(NSEvent *)o_event
225 {
226     NSPoint ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
227     if( [self mouse: ml inRect: [self bounds]] )
228         [[VLCMain sharedInstance] showFullscreenController];
229
230     [super mouseMoved: o_event];
231 }
232
233 - (BOOL)mouseDownCanMoveWindow
234 {
235     return YES;
236 }
237
238 - (BOOL)acceptsFirstResponder
239 {
240     return YES;
241 }
242
243 - (BOOL)becomeFirstResponder
244 {
245     return YES;
246 }
247
248 - (BOOL)resignFirstResponder
249 {
250     /* while we need to be the first responder most of the time, we need to give up that status when toggling the playlist */
251     return YES;
252 }
253
254 -(void)didAddSubview:(NSView *)subview
255 {
256     [[self window] makeFirstResponder: subview];
257 }
258
259 - (void)magnifyWithEvent:(NSEvent *)event
260 {
261     f_cumulated_magnification += [event magnification];
262
263     // This is the result of [NSEvent standardMagnificationThreshold].
264     // Unfortunately, this is a private API, currently.
265     CGFloat f_threshold = 0.3;
266     BOOL b_fullscreen = [[VLCMainWindow sharedInstance] isFullscreen];
267
268     if( ( f_cumulated_magnification > f_threshold && !b_fullscreen ) || ( f_cumulated_magnification < -f_threshold && b_fullscreen ) )
269     {
270         f_cumulated_magnification = 0.0;
271         [[VLCCoreInteraction sharedInstance] toggleFullscreen];
272     }
273 }
274
275 - (void)beginGestureWithEvent:(NSEvent *)event
276 {
277     f_cumulated_magnification = 0.0;
278 }
279
280 @end