intf.m
来自「VLC媒体播放程序」· M 代码 · 共 1,410 行 · 第 1/4 页
M
1,410 行
/***************************************************************************** * intf.m: MacOS X interface module ***************************************************************************** * Copyright (C) 2002-2004 VideoLAN * $Id: intf.m,v 1.115 2004/01/30 12:44:21 hartman Exp $ * * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> * Christophe Massiot <massiot@via.ecp.fr> * Derk-Jan Hartman <hartman at videolan.org> * * 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. * * 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 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h> /* malloc(), free() */#include <sys/param.h> /* for MAXPATHLEN */#include <string.h>#include <vlc_keys.h>#include "intf.h"#include "vout.h"#include "prefs.h"#include "playlist.h"#include "info.h"#include "controls.h"/***************************************************************************** * Local prototypes. *****************************************************************************/static void Run ( intf_thread_t *p_intf );/***************************************************************************** * OpenIntf: initialize interface *****************************************************************************/int E_(OpenIntf) ( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t*) p_this; p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); if( p_intf->p_sys == NULL ) { return( 1 ); } memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) ); p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init]; /* Put Cocoa into multithread mode as soon as possible. * http://developer.apple.com/techpubs/macosx/Cocoa/ * TasksAndConcepts/ProgrammingTopics/Multithreading/index.html * This thread does absolutely nothing at all. */ [NSThread detachNewThreadSelector:@selector(self) toTarget:[NSString string] withObject:nil]; p_intf->p_sys->o_sendport = [[NSPort port] retain]; p_intf->p_sys->p_sub = msg_Subscribe( p_intf ); p_intf->pf_run = Run; [[VLCApplication sharedApplication] autorelease]; [NSApp setIntf: p_intf]; [NSBundle loadNibNamed: @"MainMenu" owner: NSApp]; return( 0 );}/***************************************************************************** * CloseIntf: destroy interface *****************************************************************************/void E_(CloseIntf) ( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t*) p_this; msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub ); [p_intf->p_sys->o_sendport release]; [p_intf->p_sys->o_pool release]; free( p_intf->p_sys );}/***************************************************************************** * Run: main loop *****************************************************************************/static void Run( intf_thread_t *p_intf ){ /* Do it again - for some unknown reason, vlc_thread_create() often * fails to go to real-time priority with the first launched thread * (???) --Meuuh */ vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW ); [NSApp run];}/***************************************************************************** * VLCApplication implementation *****************************************************************************/@implementation VLCApplication- (NSString *)localizedString:(char *)psz{ NSString * o_str = nil; if( psz != NULL ) { o_str = [[[NSString alloc] initWithUTF8String: psz] autorelease]; } if ( o_str == NULL ) { msg_Err( p_intf, "could not translate: %s", psz ); } 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( p_intf, "cannot convert to wanted 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;}- (void)setIntf:(intf_thread_t *)_p_intf{ p_intf = _p_intf;}- (intf_thread_t *)getIntf{ return( p_intf );}- (void)terminate:(id)sender{ p_intf->p_vlc->b_die = VLC_TRUE;}@endint ExecuteOnMainThread( id target, SEL sel, void * p_arg ){ int i_ret = 0; NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init]; if( [target respondsToSelector: @selector(performSelectorOnMainThread: withObject:waitUntilDone:)] ) { [target performSelectorOnMainThread: sel withObject: [NSValue valueWithPointer: p_arg] waitUntilDone: YES]; } else if( NSApp != nil && [NSApp respondsToSelector: @selector(getIntf)] ) { NSValue * o_v1; NSValue * o_v2; NSArray * o_array; NSPort * o_recv_port; NSInvocation * o_inv; NSPortMessage * o_msg; intf_thread_t * p_intf; NSConditionLock * o_lock; NSMethodSignature * o_sig; id * val[] = { &o_lock, &o_v2 }; p_intf = (intf_thread_t *)[NSApp getIntf]; o_recv_port = [[NSPort port] retain]; o_v1 = [NSValue valueWithPointer: val]; o_v2 = [NSValue valueWithPointer: p_arg]; o_sig = [target methodSignatureForSelector: sel]; o_inv = [NSInvocation invocationWithMethodSignature: o_sig]; [o_inv setArgument: &o_v1 atIndex: 2]; [o_inv setTarget: target]; [o_inv setSelector: sel]; o_array = [NSArray arrayWithObject: [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]]; o_msg = [[NSPortMessage alloc] initWithSendPort: p_intf->p_sys->o_sendport receivePort: o_recv_port components: o_array]; o_lock = [[NSConditionLock alloc] initWithCondition: 0]; [o_msg sendBeforeDate: [NSDate distantPast]]; [o_lock lockWhenCondition: 1]; [o_lock unlock]; [o_lock release]; [o_msg release]; [o_recv_port release]; } else { i_ret = 1; } [o_pool release]; return( i_ret );}/***************************************************************************** * playlistChanged: Callback triggered by the intf-change playlist * variable, to let the intf update the playlist. *****************************************************************************/int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable, vlc_value_t old_val, vlc_value_t new_val, void *param ){ intf_thread_t * p_intf = [NSApp getIntf]; p_intf->p_sys->b_playlist_update = TRUE; p_intf->p_sys->b_intf_update = TRUE; return VLC_SUCCESS;}static 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 }, { NSHomeFunctionKey, KEY_HOME }, { NSEndFunctionKey, KEY_END }, { NSPageUpFunctionKey, KEY_PAGEUP }, { NSPageDownFunctionKey, KEY_PAGEDOWN }, { NSTabCharacter, KEY_TAB }, { NSCarriageReturnCharacter, KEY_ENTER }, { NSEnterCharacter, KEY_ENTER }, { NSBackspaceCharacter, KEY_BACKSPACE }, { (unichar) ' ', KEY_SPACE }, { (unichar) 0x1b, KEY_ESC }, {0,0}};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; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?