intf.m

来自「VLC Player Source Code」· M 代码 · 共 1,944 行 · 第 1/5 页

M
1,944
字号
        [toolbarItem setLabel:@"Media Controls"];        [toolbarItem setPaletteLabel:@"Media Controls"];        NSSize size = toolbarMediaControl.frame.size;        [toolbarItem setView:toolbarMediaControl];        [toolbarItem setMinSize:size];        size.width += 1000.;        [toolbarItem setMaxSize:size];        // Hack: For some reason we need to make sure        // that the those element are on top        // Add them again will put them frontmost        [toolbarMediaControl addSubview:o_scrollfield];        [toolbarMediaControl addSubview:o_timeslider];        [toolbarMediaControl addSubview:o_timefield];        [toolbarMediaControl addSubview:o_main_pgbar];        /* TODO: setup a menu */    }    else    {        /* itemIdentifier referred to a toolbar item that is not         * provided or supported by us or Cocoa         * Returning nil will inform the toolbar         * that this kind of item is not supported */        toolbarItem = nil;    }    return toolbarItem;}#pragma mark -#pragma mark Other notification- (void)controlTintChanged{    BOOL b_playing = NO;        if( [o_btn_play alternateImage] == o_img_play_pressed )        b_playing = YES;        if( [NSColor currentControlTint] == NSGraphiteControlTint )    {        o_img_play_pressed = [NSImage imageNamed: @"play_graphite"];        o_img_pause_pressed = [NSImage imageNamed: @"pause_graphite"];                [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_graphite"]];        [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_graphite"]];        [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_graphite"]];        [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_graphite"]];        [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_graphite"]];        [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_graphite"]];        [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_graphite"]];        [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_graphite"]];    }    else    {        o_img_play_pressed = [NSImage imageNamed: @"play_blue"];        o_img_pause_pressed = [NSImage imageNamed: @"pause_blue"];                [o_btn_prev setAlternateImage: [NSImage imageNamed: @"previous_blue"]];        [o_btn_rewind setAlternateImage: [NSImage imageNamed: @"skip_previous_blue"]];        [o_btn_stop setAlternateImage: [NSImage imageNamed: @"stop_blue"]];        [o_btn_ff setAlternateImage: [NSImage imageNamed: @"skip_forward_blue"]];        [o_btn_next setAlternateImage: [NSImage imageNamed: @"next_blue"]];        [o_btn_fullscreen setAlternateImage: [NSImage imageNamed: @"fullscreen_blue"]];        [o_btn_playlist setAlternateImage: [NSImage imageNamed: @"playlistdrawer_blue"]];        [o_btn_equalizer setAlternateImage: [NSImage imageNamed: @"equalizerdrawer_blue"]];    }        if( b_playing )        [o_btn_play setAlternateImage: o_img_play_pressed];    else        [o_btn_play setAlternateImage: o_img_pause_pressed];}/* Listen to the remote in exclusive mode, only when VLC is the active   application */- (void)applicationDidBecomeActive:(NSNotification *)aNotification{    [o_remote startListening: self];}- (void)applicationDidResignActive:(NSNotification *)aNotification{    [o_remote stopListening: self];}/* Triggered when the computer goes to sleep */- (void)computerWillSleep: (NSNotification *)notification{    /* Pause */    if( p_intf->p_sys->i_play_status == PLAYING_S )    {        vlc_value_t val;        val.i_int = config_GetInt( p_intf, "key-play-pause" );        var_Set( p_intf->p_libvlc, "key-pressed", val );    }}#pragma mark -#pragma mark File opening- (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename{    BOOL b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );    NSDictionary *o_dic = [NSDictionary dictionaryWithObjectsAndKeys: o_filename, @"ITEM_URL", nil];    if( b_autoplay )        [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: NO];    else        [o_playlist appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue: YES];    return( TRUE );}/* When user click in the Dock icon our double click in the finder */- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)hasVisibleWindows{        if(!hasVisibleWindows)        [o_window makeKeyAndOrderFront:self];    return YES;}#pragma mark -#pragma mark Apple Remote Control/* Helper method for the remote control interface in order to trigger forward/backward and volume   increase/decrease as long as the user holds the left/right, plus/minus button */- (void) executeHoldActionForRemoteButton: (NSNumber*) buttonIdentifierNumber{    if(b_remote_button_hold)    {        switch([buttonIdentifierNumber intValue])        {            case kRemoteButtonRight_Hold:                  [o_controls forward: self];            break;            case kRemoteButtonLeft_Hold:                  [o_controls backward: self];            break;            case kRemoteButtonVolume_Plus_Hold:                [o_controls volumeUp: self];            break;            case kRemoteButtonVolume_Minus_Hold:                [o_controls volumeDown: self];            break;        }        if(b_remote_button_hold)        {            /* trigger event */            [self performSelector:@selector(executeHoldActionForRemoteButton:)                         withObject:buttonIdentifierNumber                         afterDelay:0.25];        }    }}/* Apple Remote callback */- (void) appleRemoteButton: (AppleRemoteEventIdentifier)buttonIdentifier               pressedDown: (BOOL) pressedDown                clickCount: (unsigned int) count{    switch( buttonIdentifier )    {        case kRemoteButtonPlay:            if(count >= 2) {                [o_controls toogleFullscreen:self];            } else {                [o_controls play: self];            }            break;        case kRemoteButtonVolume_Plus:            [o_controls volumeUp: self];            break;        case kRemoteButtonVolume_Minus:            [o_controls volumeDown: self];            break;        case kRemoteButtonRight:            [o_controls next: self];            break;        case kRemoteButtonLeft:            [o_controls prev: self];            break;        case kRemoteButtonRight_Hold:        case kRemoteButtonLeft_Hold:        case kRemoteButtonVolume_Plus_Hold:        case kRemoteButtonVolume_Minus_Hold:            /* simulate an event as long as the user holds the button */            b_remote_button_hold = pressedDown;            if( pressedDown )            {                NSNumber* buttonIdentifierNumber = [NSNumber numberWithInt: buttonIdentifier];                [self performSelector:@selector(executeHoldActionForRemoteButton:)                           withObject:buttonIdentifierNumber];            }            break;        case kRemoteButtonMenu:            [o_controls showPosition: self];            break;        default:            /* Add here whatever you want other buttons to do */            break;    }}#pragma mark -#pragma mark String utility// FIXME: this has nothing to do here- (NSString *)localizedString:(const char *)psz{    NSString * o_str = nil;    if( psz != NULL )    {        o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease];        if( o_str == NULL )        {            msg_Err( VLCIntf, "could not translate: %s", psz );            return( @"" );        }    }    else    {        msg_Warn( VLCIntf, "can't translate empty strings" );        return( @"" );    }    return( o_str );}- (char *)delocalizeString:(NSString *)id{    NSData * o_data = [id dataUsingEncoding: NSUTF8StringEncoding                          allowLossyConversion: NO];    char * psz_string;    if( o_data == nil )    {        o_data = [id dataUsingEncoding: NSUTF8StringEncoding                     allowLossyConversion: YES];        psz_string = malloc( [o_data length] + 1 );        [o_data getBytes: psz_string];        psz_string[ [o_data length] ] = '\0';        msg_Err( VLCIntf, "cannot convert to the requested encoding: %s",                 psz_string );    }    else    {        psz_string = malloc( [o_data length] + 1 );        [o_data getBytes: psz_string];        psz_string[ [o_data length] ] = '\0';    }    return psz_string;}/* i_width is in pixels */- (NSString *)wrapString: (NSString *)o_in_string toWidth: (int) i_width{    NSMutableString *o_wrapped;    NSString *o_out_string;    NSRange glyphRange, effectiveRange, charRange;    NSRect lineFragmentRect;    unsigned glyphIndex, breaksInserted = 0;    NSTextStorage *o_storage = [[NSTextStorage alloc] initWithString: o_in_string        attributes: [NSDictionary dictionaryWithObjectsAndKeys:        [NSFont labelFontOfSize: 0.0], NSFontAttributeName, nil]];    NSLayoutManager *o_layout_manager = [[NSLayoutManager alloc] init];    NSTextContainer *o_container = [[NSTextContainer alloc]        initWithContainerSize: NSMakeSize(i_width, 2000)];    [o_layout_manager addTextContainer: o_container];    [o_container release];    [o_storage addLayoutManager: o_layout_manager];    [o_layout_manager release];    o_wrapped = [o_in_string mutableCopy];    glyphRange = [o_layout_manager glyphRangeForTextContainer: o_container];    for( glyphIndex = glyphRange.location ; glyphIndex < NSMaxRange(glyphRange) ;            glyphIndex += effectiveRange.length) {        lineFragmentRect = [o_layout_manager lineFragmentRectForGlyphAtIndex: glyphIndex                                            effectiveRange: &effectiveRange];        charRange = [o_layout_manager characterRangeForGlyphRange: effectiveRange                                    actualGlyphRange: &effectiveRange];        if([o_wrapped lineRangeForRange:                NSMakeRange(charRange.location + breaksInserted, charRange.length)].length > charRange.length) {            [o_wrapped insertString: @"\n" atIndex: NSMaxRange(charRange) + breaksInserted];            breaksInserted++;        }    }    o_out_string = [NSString stringWithString: o_wrapped];    [o_wrapped release];    [o_storage release];    return o_out_string;}#pragma mark -#pragma mark Key Shortcutsstatic struct{    unichar i_nskey;    unsigned int i_vlckey;} nskeys_to_vlckeys[] ={    { NSUpArrowFunctionKey, KEY_UP },    { NSDownArrowFunctionKey, KEY_DOWN },    { NSLeftArrowFunctionKey, KEY_LEFT },    { NSRightArrowFunctionKey, KEY_RIGHT },    { NSF1FunctionKey, KEY_F1 },    { NSF2FunctionKey, KEY_F2 },    { NSF3FunctionKey, KEY_F3 },    { NSF4FunctionKey, KEY_F4 },    { NSF5FunctionKey, KEY_F5 },    { NSF6FunctionKey, KEY_F6 },    { NSF7FunctionKey, KEY_F7 },    { NSF8FunctionKey, KEY_F8 },    { NSF9FunctionKey, KEY_F9 },    { NSF10FunctionKey, KEY_F10 },    { NSF11FunctionKey, KEY_F11 },    { NSF12FunctionKey, KEY_F12 },    { NSInsertFunctionKey, KEY_INSERT },    { NSHomeFunctionKey, KEY_HOME },    { NSEndFunctionKey, KEY_END },    { NSPageUpFunctionKey, KEY_PAGEUP },    { NSPageDownFunctionKey, KEY_PAGEDOWN },    { NSMenuFunctionKey, KEY_MENU },    { NSTabCharacter, KEY_TAB },    { NSCarriageReturnCharacter, KEY_ENTER },    { NSEnterCharacter, KEY_ENTER },    { NSBackspaceCharacter, KEY_BACKSPACE },    { (unichar) ' ', KEY_SPACE },    { (unichar) 0x1b, KEY_ESC },    {0,0}};static unichar VLCKeyToCocoa( unsigned int i_key ){    unsigned int i;    for( i = 0; nskeys_to_vlckeys[i].i_vlckey != 0; i++ )    {        if( nskeys_to_vlckeys[i].i_vlckey == (i_key & ~KEY_MODIFIER) )        {            return nskeys_to_vlckeys[i].i_nskey;        }    }    return (unichar)(i_key & ~KEY_MODIFIER);}unsigned int CocoaKeyToVLC( unichar i_key ){    unsigned int i;    for( i = 0; nskeys_to_vlckeys[i].i_nskey != 0; i++ )    {        if( nskeys_to_vlckeys[i].i_nskey == i_key )        {            return nskeys_to_vlckeys[i].i_vlckey;        }    }    return (unsigned int)i_key;}static unsigned int VLCModifiersToCocoa( unsigned int i_key ){    unsigned int new = 0;    if( i_key & KEY_MODIFIER_COMMAND )        new |= NSCommandKeyMask;    if( i_key & KEY_MODIFIER_ALT )        new |= NSAlternateKeyMask;    if( i_key & KEY_MODIFIER_SHIFT )        new |= NSShiftKeyMask;    if( i_key & KEY_MODIFIER_CTRL )        new |= NSControlKeyMask;    return new;}/***************************************************************************** * hasDefinedShortcutKey: Check to see if the key press is a defined VLC * shortcut key.  If it is, pass it off to VLC for handling and return YES, * otherwise ignore it and return NO (where it will get handled by Cocoa).

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?