VideoView.m 7.56 KB
Newer Older
1
/*****************************************************************************
2
 * VideoView.m: MacOS X video output module
3
 *****************************************************************************
4
 * Copyright (C) 2002-2012 VLC authors and VideoLAN
Benjamin Pracht's avatar
...  
Benjamin Pracht committed
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 14 15 16
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
17
 *
18 19 20 21 22 23 24
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 27 28 29 30
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
31 32 33 34
#import <stdlib.h>                                                 /* free() */
#import <string.h>

#import "intf.h"
35
#import "VideoView.h"
36 37
#import "CoreInteraction.h"
#import "MainMenu.h"
38
#import "MainWindow.h"
39 40 41

#import <vlc_common.h>
#import <vlc_keys.h>
42

43 44 45 46 47 48 49 50
/*****************************************************************************
 * DeviceCallback: Callback triggered when the video-device variable is changed
 *****************************************************************************/
int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
                     vlc_value_t old_val, vlc_value_t new_val, void *param )
{
    vlc_value_t val;
    vout_thread_t *p_vout = (vout_thread_t *)p_this;
51

52
    msg_Dbg( p_vout, "set %"PRId64, new_val.i_int );
53 54
    var_Create( p_vout->p_libvlc, "video-device", VLC_VAR_INTEGER );
    var_Set( p_vout->p_libvlc, "video-device", new_val );
55

56
    val.b_bool = true;
57 58 59 60
    var_Set( p_vout, "intf-change", val );
    return VLC_SUCCESS;
}

61 62 63 64
/*****************************************************************************
 * VLCVoutView implementation
 *****************************************************************************/
@implementation VLCVoutView
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

#pragma mark -
#pragma mark drag & drop support

- (void)dealloc
{
    [self unregisterDraggedTypes];
    [super dealloc];
}

- (void)awakeFromNib
{
    [self registerForDraggedTypes:[NSArray arrayWithObject: NSFilenamesPboardType]];
}

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
    if ((NSDragOperationGeneric & [sender draggingSourceOperationMask]) == NSDragOperationGeneric)
        return NSDragOperationGeneric;
    return NSDragOperationNone;
}

- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
    return YES;
}

- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
    BOOL b_returned;
    b_returned = [[VLCCoreInteraction sharedInstance] performDragOperation: sender];

    [self setNeedsDisplay:YES];
    return b_returned;
}

- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
    [self setNeedsDisplay:YES];
}

#pragma mark -
#pragma mark vout actions

109
- (void)closeVout
110
{
111 112 113 114 115 116
    vout_thread_t * p_vout = getVout();
    if( !p_vout )
    {
        var_DelCallback( p_vout, "video-device", DeviceCallback, NULL );
        vlc_object_release( p_vout );
    }
117
}
118

119 120
- (void)scrollWheel:(NSEvent *)theEvent
{
121
    VLCControls * o_controls = (VLCControls *)[[NSApp delegate] controls];
122
    [o_controls scrollWheel: theEvent];
123 124
}

125 126 127
- (void)keyDown:(NSEvent *)o_event
{
    unichar key = 0;
128
    vlc_value_t val;
129
    unsigned int i_pressed_modifiers = 0;
130
    val.i_int = 0;
131

132
    i_pressed_modifiers = [o_event modifierFlags];
133

134 135 136 137 138 139 140 141
    if( i_pressed_modifiers & NSShiftKeyMask )
        val.i_int |= KEY_MODIFIER_SHIFT;
    if( i_pressed_modifiers & NSControlKeyMask )
        val.i_int |= KEY_MODIFIER_CTRL;
    if( i_pressed_modifiers & NSAlternateKeyMask )
        val.i_int |= KEY_MODIFIER_ALT;
    if( i_pressed_modifiers & NSCommandKeyMask )
        val.i_int |= KEY_MODIFIER_COMMAND;
142

143
    key = [[[o_event charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
144

145 146
    if( key )
    {
147
        vout_thread_t * p_vout = getVout();
148 149 150
        /* Escape should always get you out of fullscreen */
        if( key == (unichar) 0x1b )
        {
151 152 153
            playlist_t * p_playlist = pl_Get( VLCIntf );
             if( var_GetBool( p_playlist, "fullscreen") )
                 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
154
        }
155 156 157
        /* handle Lion's default key combo for fullscreen-toggle in addition to our own hotkeys */
        else if( key == 'f' && i_pressed_modifiers & NSControlKeyMask && i_pressed_modifiers & NSCommandKeyMask )
            [[VLCCoreInteraction sharedInstance] toggleFullscreen];
158
        else if ( p_vout )
159
        {
160 161 162 163
            if( key == ' ' )
            {
                [[VLCCoreInteraction sharedInstance] play];
            }
164
            else
165
            {
166
                val.i_int |= (int)CocoaKeyToVLC( key );
167 168
                var_Set( p_vout->p_libvlc, "key-pressed", val );
            }
169
            vlc_object_release( p_vout );
170
        }
171 172
        else
            msg_Dbg( VLCIntf, "could not send keyevent to VLC core" );
173 174 175
    }
    else
        [super keyDown: o_event];
176 177
}

178 179 180 181 182
- (BOOL)performKeyEquivalent:(NSEvent *)o_event
{
    return [[VLCMainWindow sharedInstance] performKeyEquivalent: o_event];
}

183
- (void)mouseDown:(NSEvent *)o_event
184
{
185 186
    if( ( [o_event type] == NSLeftMouseDown ) &&
       ( ! ( [o_event modifierFlags] &  NSControlKeyMask ) ) )
187
    {
188
        if( [o_event clickCount] > 1 )
189
        {
190 191
            /* multiple clicking */
            [[VLCCoreInteraction sharedInstance] toggleFullscreen];
192
        }
193 194 195 196 197 198
    }
    else if( ( [o_event type] == NSRightMouseDown ) ||
            ( ( [o_event type] == NSLeftMouseDown ) &&
             ( [o_event modifierFlags] &  NSControlKeyMask ) ) )
    {
        [NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
199
    }
200 201

    [super mouseDown: o_event];
202 203 204 205
}

- (void)rightMouseDown:(NSEvent *)o_event
{
206
    if( [o_event type] == NSRightMouseDown )
207
        [NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
208 209

    [super mouseDown: o_event];
210 211 212 213
}

- (void)rightMouseUp:(NSEvent *)o_event
{
214
    if( [o_event type] == NSRightMouseUp )
215
        [NSMenu popUpContextMenu: [[VLCMainMenu sharedInstance] voutMenu] withEvent: o_event forView: self];
216 217

    [super mouseUp: o_event];
218 219 220 221
}

- (void)mouseMoved:(NSEvent *)o_event
{
222 223 224 225
    NSPoint ml = [self convertPoint: [o_event locationInWindow] fromView: nil];
    if( [self mouse: ml inRect: [self bounds]] )
        [[VLCMain sharedInstance] showFullscreenController];

226
    [super mouseMoved: o_event];
227 228
}

229 230 231 232 233
- (BOOL)mouseDownCanMoveWindow
{
    return YES;
}

Eric Petit's avatar
Eric Petit committed
234 235 236
- (BOOL)acceptsFirstResponder
{
    return YES;
237 238
}

Eric Petit's avatar
Eric Petit committed
239
- (BOOL)becomeFirstResponder
240
{
Eric Petit's avatar
Eric Petit committed
241
    return YES;
242 243
}

Eric Petit's avatar
Eric Petit committed
244
- (BOOL)resignFirstResponder
245
{
246 247
    /* while we need to be the first responder most of the time, we need to give up that status when toggling the playlist */
    return YES;
Eric Petit's avatar
Eric Petit committed
248
}
249 250 251 252 253 254

-(void)didAddSubview:(NSView *)subview
{
    [[self window] makeFirstResponder: subview];
}

255
@end