-/*****************************************************************************
- * 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;
-}
-
-
-/*****************************************************************************
- * 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).
- *****************************************************************************/
-- (BOOL)hasDefinedShortcutKey:(NSEvent *)o_event
-{
- unichar key = 0;
- vlc_value_t val;
- unsigned int i_pressed_modifiers = 0;
- struct hotkey *p_hotkeys;
- int i;
-
- val.i_int = 0;
- p_hotkeys = p_intf->p_vlc->p_hotkeys;
-
- i_pressed_modifiers = [o_event modifierFlags];
-
- 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;
-
- key = [[o_event charactersIgnoringModifiers] characterAtIndex: 0];
-
- val.i_int |= CocoaKeyToVLC( key );
-
- for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
- {
- if( p_hotkeys[i].i_key == val.i_int )
- {
- var_Set( p_intf->p_vlc, "key-pressed", val );
- return YES;
- }
- }
-
- return NO;
-}
-
-@end
-