]> git.sesse.net Git - vlc/blob - modules/gui/macosx/intf.m
a07b1450ed0c664b08dd42f551da0306419a1e12
[vlc] / modules / gui / macosx / intf.m
1 /*****************************************************************************
2  * intf.m: MacOS X interface plugin
3  *****************************************************************************
4  * Copyright (C) 2002-2003 VideoLAN
5  * $Id: intf.m,v 1.85 2003/05/20 18:53:03 hartman Exp $
6  *
7  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *          Derk-Jan Hartman <thedj@users.sourceforge.net>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  * 
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include <stdlib.h>                                      /* malloc(), free() */
30 #include <sys/param.h>                                    /* for MAXPATHLEN */
31 #include <string.h>
32
33 #include "intf.h"
34 #include "vout.h"
35 #include "prefs.h"
36 #include "playlist.h"
37 #include "info.h"
38
39 /*****************************************************************************
40  * Local prototypes.
41  *****************************************************************************/
42 static void Run ( intf_thread_t *p_intf );
43
44 /*****************************************************************************
45  * OpenIntf: initialize interface
46  *****************************************************************************/
47 int E_(OpenIntf) ( vlc_object_t *p_this )
48 {   
49     intf_thread_t *p_intf = (intf_thread_t*) p_this;
50
51     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
52     if( p_intf->p_sys == NULL )
53     {
54         return( 1 );
55     }
56
57     memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
58     
59     p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
60     
61     /* Put Cocoa into multithread mode as soon as possible.
62      * http://developer.apple.com/techpubs/macosx/Cocoa/
63      * TasksAndConcepts/ProgrammingTopics/Multithreading/index.html
64      * This thread does absolutely nothing at all. */
65     [NSThread detachNewThreadSelector:@selector(self) toTarget:[NSString string] withObject:nil];
66     
67     p_intf->p_sys->o_sendport = [[NSPort port] retain];
68     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
69     p_intf->pf_run = Run;
70     
71     [[VLCApplication sharedApplication] autorelease];
72     [NSApp initIntlSupport];
73     [NSApp setIntf: p_intf];
74
75     [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];
76
77     return( 0 );
78 }
79
80 /*****************************************************************************
81  * CloseIntf: destroy interface
82  *****************************************************************************/
83 void E_(CloseIntf) ( vlc_object_t *p_this )
84 {
85     intf_thread_t *p_intf = (intf_thread_t*) p_this;
86
87     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
88
89     [p_intf->p_sys->o_sendport release];
90     [p_intf->p_sys->o_pool release];
91
92     free( p_intf->p_sys );
93 }
94
95 /*****************************************************************************
96  * Run: main loop
97  *****************************************************************************/
98 static void Run( intf_thread_t *p_intf )
99 {
100     /* Do it again - for some unknown reason, vlc_thread_create() often
101      * fails to go to real-time priority with the first launched thread
102      * (???) --Meuuh */
103     vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
104
105     [NSApp run];
106 }
107
108 /*****************************************************************************
109  * VLCApplication implementation 
110  *****************************************************************************/
111 @implementation VLCApplication
112
113 - (id)init
114 {
115     /* default encoding: ISO-8859-1 */
116     i_encoding = NSISOLatin1StringEncoding;
117
118     return( [super init] );
119 }
120
121 - (void)initIntlSupport
122 {
123     char *psz_lang = getenv( "LANG" );
124
125     if( psz_lang == NULL )
126     {
127         return;
128     }
129
130     if( strncmp( psz_lang, "pl", 2 ) == 0 )
131     {
132         i_encoding = NSISOLatin2StringEncoding;
133     }
134     else if( strncmp( psz_lang, "ja", 2 ) == 0 ) 
135     {
136         i_encoding = NSJapaneseEUCStringEncoding;
137     }
138     else if( strncmp( psz_lang, "ru", 2 ) == 0 )
139     {
140 #define CFSENC2NSSENC(e) CFStringConvertEncodingToNSStringEncoding(e)
141         i_encoding = CFSENC2NSSENC( kCFStringEncodingKOI8_R ); 
142 #undef CFSENC2NSSENC
143     }
144 }
145
146 - (NSString *)localizedString:(char *)psz
147 {
148     NSString * o_str = nil;
149
150     if( psz != NULL )
151     {
152         UInt32 uiLength = (UInt32)strlen( psz );
153         NSData * o_data = [NSData dataWithBytes: psz length: uiLength];
154         o_str = [[[NSString alloc] initWithData: o_data
155                                        encoding: i_encoding] autorelease];
156     }
157
158     return( o_str );
159 }
160
161 - (char *)delocalizeString:(NSString *)id
162 {
163     NSData * o_data = [id dataUsingEncoding: i_encoding
164                           allowLossyConversion: NO];
165     char * psz_string;
166
167     if ( o_data == nil )
168     {
169         o_data = [id dataUsingEncoding: i_encoding
170                      allowLossyConversion: YES];
171         psz_string = malloc( [o_data length] + 1 ); 
172         [o_data getBytes: psz_string];
173         psz_string[ [o_data length] ] = '\0';
174         msg_Err( p_intf, "cannot convert to wanted encoding: %s",
175                  psz_string );
176     }
177     else
178     {
179         psz_string = malloc( [o_data length] + 1 ); 
180         [o_data getBytes: psz_string];
181         psz_string[ [o_data length] ] = '\0';
182     }
183
184     return psz_string;
185 }
186
187 - (NSStringEncoding)getEncoding
188 {
189     return i_encoding;
190 }
191
192 - (void)setIntf:(intf_thread_t *)_p_intf
193 {
194     p_intf = _p_intf;
195 }
196
197 - (intf_thread_t *)getIntf
198 {
199     return( p_intf );
200 }
201
202 - (void)terminate:(id)sender
203 {
204     p_intf->p_vlc->b_die = VLC_TRUE;
205 }
206
207 @end
208
209 int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
210 {
211     int i_ret = 0;
212
213     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
214
215     if( [target respondsToSelector: @selector(performSelectorOnMainThread:
216                                              withObject:waitUntilDone:)] )
217     {
218         [target performSelectorOnMainThread: sel
219                 withObject: [NSValue valueWithPointer: p_arg]
220                 waitUntilDone: YES];
221     }
222     else if( NSApp != nil && [NSApp respondsToSelector: @selector(getIntf)] ) 
223     {
224         NSValue * o_v1;
225         NSValue * o_v2;
226         NSArray * o_array;
227         NSPort * o_recv_port;
228         NSInvocation * o_inv;
229         NSPortMessage * o_msg;
230         intf_thread_t * p_intf;
231         NSConditionLock * o_lock;
232         NSMethodSignature * o_sig;
233
234         id * val[] = { &o_lock, &o_v2 };
235
236         p_intf = (intf_thread_t *)[NSApp getIntf];
237
238         o_recv_port = [[NSPort port] retain];
239         o_v1 = [NSValue valueWithPointer: val]; 
240         o_v2 = [NSValue valueWithPointer: p_arg];
241
242         o_sig = [target methodSignatureForSelector: sel];
243         o_inv = [NSInvocation invocationWithMethodSignature: o_sig];
244         [o_inv setArgument: &o_v1 atIndex: 2];
245         [o_inv setTarget: target];
246         [o_inv setSelector: sel];
247
248         o_array = [NSArray arrayWithObject:
249             [NSData dataWithBytes: &o_inv length: sizeof(o_inv)]];
250         o_msg = [[NSPortMessage alloc]
251             initWithSendPort: p_intf->p_sys->o_sendport
252             receivePort: o_recv_port components: o_array];
253
254         o_lock = [[NSConditionLock alloc] initWithCondition: 0];
255         [o_msg sendBeforeDate: [NSDate distantPast]];
256         [o_lock lockWhenCondition: 1];
257         [o_lock unlock];
258         [o_lock release];
259
260         [o_msg release];
261         [o_recv_port release];
262     } 
263     else
264     {
265         i_ret = 1;
266     }
267
268     [o_pool release];
269
270     return( i_ret );
271 }
272
273 /*****************************************************************************
274  * playlistChanged: Callback triggered by the intf-change playlist
275  * variable, to let the intf update the playlist.
276  *****************************************************************************/
277 int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,
278                      vlc_value_t old_val, vlc_value_t new_val, void *param )
279 {
280     intf_thread_t * p_intf = [NSApp getIntf];
281     p_intf->p_sys->b_playlist_update = VLC_TRUE;
282     p_intf->p_sys->b_intf_update = VLC_TRUE;
283     return VLC_SUCCESS;
284 }
285
286 /*****************************************************************************
287  * VLCMain implementation 
288  *****************************************************************************/
289 @implementation VLCMain
290
291 - (void)awakeFromNib
292 {
293     [o_window setTitle: _NS("VLC - Controller")];
294     [o_window setExcludedFromWindowsMenu: TRUE];
295
296     /* button controls */
297     [o_btn_playlist setToolTip: _NS("Playlist")];
298     [o_btn_prev setToolTip: _NS("Previous")];
299     [o_btn_slower setToolTip: _NS("Slower")];
300     [o_btn_play setToolTip: _NS("Play")];
301     [o_btn_stop setToolTip: _NS("Stop")];
302     [o_btn_faster setToolTip: _NS("Faster")];
303     [o_btn_next setToolTip: _NS("Next")];
304     [o_btn_prefs setToolTip: _NS("Preferences")];
305     [o_volumeslider setToolTip: _NS("Volume")];
306     [o_timeslider setToolTip: _NS("Position")];
307
308     /* messages panel */ 
309     [o_msgs_panel setDelegate: self];
310     [o_msgs_panel setTitle: _NS("Messages")];
311     [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
312     [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog")];
313
314     /* main menu */
315     [o_mi_about setTitle: _NS("About VLC media player")];
316     [o_mi_prefs setTitle: _NS("Preferences...")];
317     [o_mi_hide setTitle: _NS("Hide VLC")];
318     [o_mi_hide_others setTitle: _NS("Hide Others")];
319     [o_mi_show_all setTitle: _NS("Show All")];
320     [o_mi_quit setTitle: _NS("Quit VLC")];
321
322     [o_mu_file setTitle: _ANS("1:File")];
323     [o_mi_open_generic setTitle: _NS("Open...")];
324     [o_mi_open_file setTitle: _NS("Open File...")];
325     [o_mi_open_disc setTitle: _NS("Open Disc...")];
326     [o_mi_open_net setTitle: _NS("Open Network...")];
327     [o_mi_open_recent setTitle: _NS("Open Recent")];
328     [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
329
330     [o_mu_edit setTitle: _NS("Edit")];
331     [o_mi_cut setTitle: _NS("Cut")];
332     [o_mi_copy setTitle: _NS("Copy")];
333     [o_mi_paste setTitle: _NS("Paste")];
334     [o_mi_clear setTitle: _NS("Clear")];
335     [o_mi_select_all setTitle: _NS("Select All")];
336
337     [o_mu_controls setTitle: _NS("Controls")];
338     [o_mi_play setTitle: _NS("Play")];
339     [o_mi_stop setTitle: _NS("Stop")];
340     [o_mi_faster setTitle: _NS("Faster")];
341     [o_mi_slower setTitle: _NS("Slower")];
342     [o_mi_previous setTitle: _NS("Previous")];
343     [o_mi_next setTitle: _NS("Next")];
344     [o_mi_loop setTitle: _NS("Loop")];
345     [o_mi_fwd setTitle: _NS("Step Forward")];
346     [o_mi_bwd setTitle: _NS("Step Backward")];
347     [o_mi_program setTitle: _NS("Program")];
348     [o_mu_program setTitle: _NS("Program")];
349     [o_mi_title setTitle: _NS("Title")];
350     [o_mu_title setTitle: _NS("Title")];
351     [o_mi_chapter setTitle: _NS("Chapter")];
352     [o_mu_chapter setTitle: _NS("Chapter")];
353     
354     [o_mu_audio setTitle: _NS("Audio")];
355     [o_mi_vol_up setTitle: _NS("Volume Up")];
356     [o_mi_vol_down setTitle: _NS("Volume Down")];
357     [o_mi_mute setTitle: _NS("Mute")];
358     [o_mi_audiotrack setTitle: _NS("Audio Track")];
359     [o_mu_audiotrack setTitle: _NS("Audio Track")];
360     [o_mi_channels setTitle: _NS("Channels")];
361     [o_mu_channels setTitle: _NS("Channels")];
362     [o_mi_device setTitle: _NS("Device")];
363     [o_mu_device setTitle: _NS("Device")];
364     
365     [o_mu_video setTitle: _NS("Video")];
366     [o_mi_half_window setTitle: _NS("Half Size")];
367     [o_mi_normal_window setTitle: _NS("Normal Size")];
368     [o_mi_double_window setTitle: _NS("Double Size")];
369     [o_mi_fittoscreen setTitle: _NS("Fit To Screen")];
370     [o_mi_fullscreen setTitle: _NS("Fullscreen")];
371     [o_mi_floatontop setTitle: _NS("Float On Top")];
372     [o_mi_videotrack setTitle: _NS("Video Track")];
373     [o_mu_videotrack setTitle: _NS("Video Track")];
374     [o_mi_screen setTitle: _NS("Screen")];
375     [o_mu_screen setTitle: _NS("Screen")];
376     [o_mi_subtitle setTitle: _NS("Subtitles")];
377     [o_mu_subtitle setTitle: _NS("Subtitles")];
378     [o_mi_deinterlace setTitle: _NS("Deinterlace")];
379     [o_mu_deinterlace setTitle: _NS("Deinterlace")];
380
381     [o_mu_window setTitle: _NS("Window")];
382     [o_mi_minimize setTitle: _NS("Minimize Window")];
383     [o_mi_close_window setTitle: _NS("Close Window")];
384     [o_mi_controller setTitle: _NS("Controller")];
385     [o_mi_playlist setTitle: _NS("Playlist")];
386     [o_mi_info setTitle: _NS("Info")];
387     [o_mi_messages setTitle: _NS("Messages")];
388
389     [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
390
391     [o_mu_help setTitle: _NS("Help")];
392     [o_mi_readme setTitle: _NS("ReadMe...")];
393     [o_mi_documentation setTitle: _NS("Online Documentation")];
394     [o_mi_reportabug setTitle: _NS("Report a Bug")];
395     [o_mi_website setTitle: _NS("VideoLAN Website")];
396     [o_mi_license setTitle: _NS("License")];
397
398     /* dock menu */
399     [o_dmi_play setTitle: _NS("Play")];
400     [o_dmi_stop setTitle: _NS("Stop")];
401     [o_dmi_next setTitle: _NS("Next")];
402     [o_dmi_previous setTitle: _NS("Previous")];
403
404     /* error panel */
405     [o_error setTitle: _NS("Error")];
406     [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
407     [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")]; 
408     [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
409     [o_err_btn_dismiss setTitle: _NS("Dismiss")];
410
411     [o_info_window setTitle: _NS("Info")];
412
413     [self setSubmenusEnabled: FALSE];
414     [self manageVolumeSlider];
415 }
416
417 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
418 {
419     intf_thread_t * p_intf = [NSApp getIntf];
420
421     o_msg_lock = [[NSLock alloc] init];
422     o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
423
424     o_img_play = [[NSImage imageNamed: @"play"] retain];
425     o_img_pause = [[NSImage imageNamed: @"pause"] retain];
426
427     [p_intf->p_sys->o_sendport setDelegate: self];
428     [[NSRunLoop currentRunLoop] 
429         addPort: p_intf->p_sys->o_sendport
430         forMode: NSDefaultRunLoopMode];
431
432     [NSTimer scheduledTimerWithTimeInterval: 0.5
433         target: self selector: @selector(manageIntf:)
434         userInfo: nil repeats: FALSE];
435
436     [NSThread detachNewThreadSelector: @selector(manage)
437         toTarget: self withObject: nil];
438
439     vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
440 }
441
442 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
443 {
444     intf_thread_t * p_intf = [NSApp getIntf];
445     
446     config_PutPsz( p_intf, "sub-file", "" );
447     config_PutInt( p_intf, "sub-delay", 0 );
448     config_PutFloat( p_intf, "sub-fps", 0.0 );
449     config_PutPsz( p_intf, "sout", "" );
450     
451     [o_playlist appendArray:
452         [NSArray arrayWithObject: o_filename] atPos: -1 enqueue: NO];
453             
454     return( TRUE );
455 }
456
457 - (id)getControls
458 {
459     if ( o_controls )
460     {
461         return o_controls;
462     }
463     return nil;
464 }
465
466 - (void)manage
467 {
468     NSDate * o_sleep_date;
469     intf_thread_t * p_intf = [NSApp getIntf];
470     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
471
472     vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
473
474     while( !p_intf->b_die )
475     {
476         playlist_t * p_playlist;
477
478         vlc_mutex_lock( &p_intf->change_lock );
479
480         p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
481                                               FIND_ANYWHERE );
482
483         if( p_playlist != NULL )
484         {
485             var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
486             vlc_mutex_lock( &p_playlist->object_lock );
487             
488             [self manage: p_playlist];
489             
490             vlc_mutex_unlock( &p_playlist->object_lock );
491             vlc_object_release( p_playlist );
492         }
493
494         vlc_mutex_unlock( &p_intf->change_lock );
495
496         o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
497         [NSThread sleepUntilDate: o_sleep_date];
498     }
499
500     [self terminate];
501
502     [o_pool release];
503 }
504
505 - (void)manage:(playlist_t *)p_playlist
506 {
507     intf_thread_t * p_intf = [NSApp getIntf];
508
509 #define p_input p_playlist->p_input
510
511     if( p_input )
512     {
513         vout_thread_t   * p_vout  = NULL;
514         aout_instance_t * p_aout  = NULL; 
515
516         vlc_mutex_lock( &p_input->stream.stream_lock );
517
518         if( !p_input->b_die )
519         {
520             audio_volume_t i_volume;
521
522             /* New input or stream map change */
523             if( p_input->stream.b_changed )
524             {
525                 p_intf->p_sys->b_playing = TRUE;
526                 [self manageMode: p_playlist];
527             }
528
529             vlc_value_t val;
530
531             if( var_Get( (vlc_object_t *)p_input, "intf-change", &val )
532                 >= 0 && val.b_bool )
533             {
534                 p_intf->p_sys->b_input_update = TRUE;
535             }
536
537             p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
538                                               FIND_ANYWHERE );
539             if( p_aout != NULL )
540             {
541                 vlc_value_t val;
542
543                 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
544                     >= 0 && val.b_bool )
545                 {
546                     p_intf->p_sys->b_aout_update = TRUE;
547                 }
548
549                 vlc_object_release( (vlc_object_t *)p_aout );
550             }
551
552             aout_VolumeGet( p_intf, &i_volume );
553             p_intf->p_sys->b_mute = ( i_volume == 0 );
554
555             p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
556                                               FIND_ANYWHERE );
557             if( p_vout != NULL )
558             {
559                 vlc_value_t val;
560
561                 if( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
562                     >= 0 && val.b_bool )
563                 {
564                     p_intf->p_sys->b_vout_update = TRUE;
565                 }
566
567                 vlc_object_release( (vlc_object_t *)p_vout );
568             }
569             [self setupMenus: p_input];
570         }
571         vlc_mutex_unlock( &p_input->stream.stream_lock );
572     }
573     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
574     {
575         p_intf->p_sys->b_playing = FALSE;
576         [self manageMode: p_playlist];
577     }
578
579 #undef p_input
580 }
581
582 - (void)manageMode:(playlist_t *)p_playlist
583 {
584     intf_thread_t * p_intf = [NSApp getIntf];
585
586     if( p_playlist->p_input != NULL )
587     {
588         p_intf->p_sys->b_current_title_update = 1;
589         p_playlist->p_input->stream.b_changed = 0;
590         
591         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
592     }
593     else
594     {
595         vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
596                                                           FIND_ANYWHERE );
597         if( p_vout != NULL )
598         {
599             vlc_object_detach( p_vout );
600             vlc_object_release( p_vout );
601
602             vlc_mutex_unlock( &p_playlist->object_lock );
603             vout_Destroy( p_vout );
604             vlc_mutex_lock( &p_playlist->object_lock );
605         }
606     }
607
608     p_intf->p_sys->b_intf_update = VLC_TRUE;
609 }
610
611 - (void)manageIntf:(NSTimer *)o_timer
612 {
613     intf_thread_t * p_intf = [NSApp getIntf];
614
615     if( p_intf->p_vlc->b_die == VLC_TRUE )
616     {
617         [o_timer invalidate];
618         return;
619     }
620
621     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
622                                                        FIND_ANYWHERE );
623
624     if( p_playlist == NULL )
625     {
626         return;
627     }
628
629     if ( p_intf->p_sys->b_playlist_update )
630     {
631         [o_playlist playlistUpdated];
632         p_intf->p_sys->b_playlist_update = VLC_FALSE;
633     }
634
635     if( p_intf->p_sys->b_current_title_update )
636     {
637         vout_thread_t   *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
638                                               FIND_ANYWHERE );
639         if( p_vout != NULL )
640         {
641             id o_vout_wnd;
642             NSEnumerator * o_enum = [[NSApp windows] objectEnumerator];
643             
644             while( ( o_vout_wnd = [o_enum nextObject] ) )
645             {
646                 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
647                 {
648                     [o_vout_wnd updateTitle];
649                 }
650             }
651             vlc_object_release( (vlc_object_t *)p_vout );
652         }
653         [o_playlist updateRowSelection];
654         [o_info updateInfo];
655
656         p_intf->p_sys->b_current_title_update = FALSE;
657     }
658
659     vlc_mutex_lock( &p_playlist->object_lock );
660
661 #define p_input p_playlist->p_input
662
663     if( p_input != NULL )
664     {
665         vlc_mutex_lock( &p_input->stream.stream_lock );
666     }
667
668     if( p_intf->p_sys->b_intf_update )
669     {
670         vlc_bool_t b_input = VLC_FALSE;
671         vlc_bool_t b_plmul = VLC_FALSE;
672         vlc_bool_t b_control = VLC_FALSE;
673         vlc_bool_t b_seekable = VLC_FALSE;
674         vlc_bool_t b_chapters = VLC_FALSE;
675
676         b_plmul = p_playlist->i_size > 1;
677
678         if( ( b_input = ( p_input != NULL ) ) )
679         {
680             /* seekable streams */
681             b_seekable = p_input->stream.b_seekable;
682
683             /* control buttons for free pace streams */
684             b_control = p_input->stream.b_pace_control; 
685
686             /* chapters */
687             b_chapters = p_input->stream.p_selected_area->i_part_nb > 1; 
688
689             /* play status */
690             p_intf->p_sys->b_play_status = 
691                 p_input->stream.control.i_status != PAUSE_S;
692         }
693         else
694         {
695             /* play status */
696             p_intf->p_sys->b_play_status = FALSE;
697             [self setSubmenusEnabled: FALSE];
698         }
699
700         [self playStatusUpdated: p_intf->p_sys->b_play_status];
701
702         [o_btn_stop setEnabled: b_input];
703         [o_btn_faster setEnabled: b_control];
704         [o_btn_slower setEnabled: b_control];
705         [o_btn_prev setEnabled: (b_plmul || b_chapters)];
706         [o_btn_next setEnabled: (b_plmul || b_chapters)];
707
708         [o_timeslider setFloatValue: 0.0];
709         [o_timeslider setEnabled: b_seekable];
710         [o_timefield setStringValue: @"0:00:00"];
711
712         [self manageVolumeSlider];
713
714         p_intf->p_sys->b_intf_update = VLC_FALSE;
715     }
716
717 #define p_area p_input->stream.p_selected_area
718
719     if( p_intf->p_sys->b_playing && p_input != NULL )
720     {
721         vlc_bool_t b_field_update = TRUE;
722
723         if( !p_input->b_die && ( p_intf->p_sys->b_play_status !=
724             ( p_input->stream.control.i_status != PAUSE_S ) ) ) 
725         {
726             p_intf->p_sys->b_play_status =
727                 !p_intf->p_sys->b_play_status;
728
729             [self playStatusUpdated: p_intf->p_sys->b_play_status]; 
730         }
731
732         if( p_input->stream.b_seekable )
733         {
734             if( f_slider == f_slider_old )
735             {
736                 float f_updated = ( 10000. * p_area->i_tell ) /
737                                            p_area->i_size;
738
739                 if( f_slider != f_updated )
740                 {
741                     [o_timeslider setFloatValue: f_updated];
742                 }
743             }
744             else
745             {
746                 off_t i_seek = ( f_slider * p_area->i_size ) / 10000;
747
748                 /* release the lock to be able to seek */
749                 vlc_mutex_unlock( &p_input->stream.stream_lock );
750                 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
751                 vlc_mutex_lock( &p_input->stream.stream_lock );
752
753                 /* update the old value */
754                 f_slider_old = f_slider; 
755
756                 b_field_update = VLC_FALSE;
757             }
758         }
759
760         if( b_field_update )
761         {
762             NSString * o_time;
763             char psz_time[ OFFSETTOTIME_MAX_SIZE ];
764
765             input_OffsetToTime( p_input, psz_time, p_area->i_tell );
766
767             o_time = [NSString stringWithCString: psz_time];
768             [o_timefield setStringValue: o_time];
769         }
770
771         /* disable screen saver */
772         UpdateSystemActivity( UsrActivity );
773     }
774
775 #undef p_area
776
777     if( p_input != NULL )
778     {
779         vlc_mutex_unlock( &p_input->stream.stream_lock );
780     }
781
782 #undef p_input
783
784     vlc_mutex_unlock( &p_playlist->object_lock );
785     vlc_object_release( p_playlist );
786
787     [self updateMessageArray];
788
789     [NSTimer scheduledTimerWithTimeInterval: 0.5
790         target: self selector: @selector(manageIntf:)
791         userInfo: nil repeats: FALSE];
792 }
793
794 - (void)updateMessageArray
795 {
796     int i_start, i_stop;
797     intf_thread_t * p_intf = [NSApp getIntf];
798
799     vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
800     i_stop = *p_intf->p_sys->p_sub->pi_stop;
801     vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
802
803     if( p_intf->p_sys->p_sub->i_start != i_stop )
804     {
805         NSColor *o_white = [NSColor whiteColor];
806         NSColor *o_red = [NSColor redColor];
807         NSColor *o_yellow = [NSColor yellowColor];
808         NSColor *o_gray = [NSColor grayColor];
809
810         NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
811         static const char * ppsz_type[4] = { ": ", " error: ",
812                                              " warning: ", " debug: " };
813
814         for( i_start = p_intf->p_sys->p_sub->i_start;
815              i_start != i_stop;
816              i_start = (i_start+1) % VLC_MSG_QSIZE )
817         {
818             NSString *o_msg;
819             NSDictionary *o_attr;
820             NSAttributedString *o_msg_color;
821
822             int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
823
824             [o_msg_lock lock];
825
826             if( [o_msg_arr count] + 2 > 400 )
827             {
828                 unsigned rid[] = { 0, 1 };
829                 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
830                            numIndices: sizeof(rid)/sizeof(rid[0])];
831             }
832
833             o_attr = [NSDictionary dictionaryWithObject: o_gray
834                 forKey: NSForegroundColorAttributeName];
835             o_msg = [NSString stringWithFormat: @"%s%s",
836                 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
837                 ppsz_type[i_type]];
838             o_msg_color = [[NSAttributedString alloc]
839                 initWithString: o_msg attributes: o_attr];
840             [o_msg_arr addObject: [o_msg_color autorelease]];
841
842             o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
843                 forKey: NSForegroundColorAttributeName];
844             o_msg = [NSString stringWithFormat: @"%s\n",
845                 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
846             o_msg_color = [[NSAttributedString alloc]
847                 initWithString: o_msg attributes: o_attr];
848             [o_msg_arr addObject: [o_msg_color autorelease]];
849
850             [o_msg_lock unlock];
851
852             if( i_type == 1 )
853             {
854                 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
855                     p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
856                     p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
857
858                 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
859                 [o_err_msg setEditable: YES];
860                 [o_err_msg setSelectedRange: s_r];
861                 [o_err_msg insertText: o_my_msg];
862
863                 [o_error makeKeyAndOrderFront: self];
864                 [o_err_msg setEditable: NO];
865             }
866         }
867
868         vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
869         p_intf->p_sys->p_sub->i_start = i_start;
870         vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
871     }
872 }
873
874 - (void)playStatusUpdated:(BOOL)b_pause
875 {
876     if( b_pause )
877     {
878         [o_btn_play setImage: o_img_pause];
879         [o_btn_play setToolTip: _NS("Pause")];
880         [o_mi_play setTitle: _NS("Pause")];
881         [o_dmi_play setTitle: _NS("Pause")];
882     }
883     else
884     {
885         [o_btn_play setImage: o_img_play];
886         [o_btn_play setToolTip: _NS("Play")];
887         [o_mi_play setTitle: _NS("Play")];
888         [o_dmi_play setTitle: _NS("Play")];
889     }
890 }
891
892 - (void)setSubmenusEnabled:(BOOL)b_enabled
893 {
894     [o_mi_program setEnabled: b_enabled];
895     [o_mi_title setEnabled: b_enabled];
896     [o_mi_chapter setEnabled: b_enabled];
897     [o_mi_audiotrack setEnabled: b_enabled];
898     [o_mi_videotrack setEnabled: b_enabled];
899     [o_mi_subtitle setEnabled: b_enabled];
900     [o_mi_channels setEnabled: b_enabled];
901     [o_mi_device setEnabled: b_enabled];
902     [o_mi_screen setEnabled: b_enabled];
903 }
904
905 - (void)manageVolumeSlider
906 {
907     audio_volume_t i_volume;
908     intf_thread_t * p_intf = [NSApp getIntf];
909
910     aout_VolumeGet( p_intf, &i_volume );
911
912     [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP]; 
913     [o_volumeslider setEnabled: TRUE];
914
915     p_intf->p_sys->b_mute = ( i_volume == 0 );
916 }
917
918 - (void)terminate
919 {
920     NSEvent * o_event;
921     vout_thread_t * p_vout;
922     playlist_t * p_playlist;
923     intf_thread_t * p_intf = [NSApp getIntf];
924
925     /*
926      * Free playlists
927      */
928     msg_Dbg( p_intf, "removing all playlists" );
929     while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
930                                           FIND_CHILD )) )
931     {
932         vlc_object_detach( p_playlist );
933         vlc_object_release( p_playlist );
934         playlist_Destroy( p_playlist );
935     }
936
937     /*
938      * Free video outputs
939      */
940     msg_Dbg( p_intf, "removing all video outputs" );
941     while( (p_vout = vlc_object_find( p_intf->p_vlc, 
942                                       VLC_OBJECT_VOUT, FIND_CHILD )) )
943     {
944         vlc_object_detach( p_vout );
945         vlc_object_release( p_vout );
946         vout_Destroy( p_vout );
947     }
948
949     if( o_img_pause != nil )
950     {
951         [o_img_pause release];
952         o_img_pause = nil;
953     }
954
955     if( o_img_play != nil )
956     {
957         [o_img_play release];
958         o_img_play = nil;
959     }
960
961     if( o_msg_arr != nil )
962     {
963         [o_msg_arr removeAllObjects];
964         [o_msg_arr release];
965         o_msg_arr = nil;
966     }
967
968     if( o_msg_lock != nil )
969     {
970         [o_msg_lock release];
971         o_msg_lock = nil;
972     }
973
974     [NSApp stop: nil];
975
976     /* write cached user defaults to disk */
977     [[NSUserDefaults standardUserDefaults] synchronize];
978
979     /* send a dummy event to break out of the event loop */
980     o_event = [NSEvent mouseEventWithType: NSLeftMouseDown
981                 location: NSMakePoint( 1, 1 ) modifierFlags: 0
982                 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
983                 context: [NSGraphicsContext currentContext] eventNumber: 1
984                 clickCount: 1 pressure: 0.0];
985     [NSApp postEvent: o_event atStart: YES];
986 }
987
988 - (void)setupMenus:(input_thread_t *)p_input
989 {
990     intf_thread_t * p_intf = [NSApp getIntf];
991     vlc_value_t val;
992
993     if( p_intf->p_sys->b_input_update )
994     {
995         val.b_bool = FALSE;
996
997         [self setupVarMenu: o_mi_program target: (vlc_object_t *)p_input
998             var: "program" selector: @selector(toggleVar:)];
999
1000         [self setupVarMenu: o_mi_title target: (vlc_object_t *)p_input
1001             var: "title" selector: @selector(toggleVar:)];
1002
1003         [self setupVarMenu: o_mi_chapter target: (vlc_object_t *)p_input
1004             var: "chapter" selector: @selector(toggleVar:)];
1005
1006         [self setupVarMenu: o_mi_audiotrack target: (vlc_object_t *)p_input
1007             var: "audio-es" selector: @selector(toggleVar:)];
1008
1009         [self setupVarMenu: o_mi_videotrack target: (vlc_object_t *)p_input
1010             var: "video-es" selector: @selector(toggleVar:)];
1011
1012         [self setupVarMenu: o_mi_subtitle target: (vlc_object_t *)p_input
1013             var: "spu-es" selector: @selector(toggleVar:)];
1014
1015         p_intf->p_sys->b_input_update = FALSE;
1016         var_Set( (vlc_object_t *)p_input, "intf-change", val );
1017     }
1018
1019     if ( p_intf->p_sys->b_aout_update )
1020     {
1021         aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1022                                                     FIND_ANYWHERE );
1023
1024         if ( p_aout != NULL )
1025         {
1026             val.b_bool = FALSE;
1027             
1028             [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
1029                 var: "audio-channels" selector: @selector(toggleVar:)];
1030
1031             [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
1032                 var: "audio-device" selector: @selector(toggleVar:)];
1033             var_Set( (vlc_object_t *)p_aout, "intf-change", val );
1034             
1035             vlc_object_release( (vlc_object_t *)p_aout );
1036         }
1037         p_intf->p_sys->b_aout_update = FALSE;
1038     }
1039
1040     if( p_intf->p_sys->b_vout_update )
1041     {
1042         vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1043                                                           FIND_ANYWHERE );
1044
1045         if ( p_vout != NULL )
1046         {
1047             val.b_bool = FALSE;
1048
1049             [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
1050                 var: "video-device" selector: @selector(toggleVar:)];
1051             var_Set( (vlc_object_t *)p_vout, "intf-change", val );
1052             
1053             vlc_object_release( (vlc_object_t *)p_vout );
1054             [o_mi_close_window setEnabled: TRUE];
1055         }
1056         
1057         p_intf->p_sys->b_vout_update = FALSE;
1058     }
1059 }
1060
1061 - (void)setupVarMenu:(NSMenuItem *)o_mi
1062                      target:(vlc_object_t *)p_object
1063                      var:(const char *)psz_variable
1064                      selector:(SEL)pf_callback
1065 {
1066     int i, i_nb_items, i_value;
1067     NSMenu * o_menu = [o_mi submenu];
1068     vlc_value_t val, text;
1069     
1070     [o_mi setTag: (int)psz_variable];
1071     
1072     /* remove previous items */
1073     i_nb_items = [o_menu numberOfItems];
1074     for( i = 0; i < i_nb_items; i++ )
1075     {
1076         [o_menu removeItemAtIndex: 0];
1077     }
1078
1079     if ( var_Get( p_object, psz_variable, &val ) < 0 )
1080     {
1081         return;
1082     }
1083     i_value = val.i_int;
1084
1085     if ( var_Change( p_object, psz_variable,
1086                      VLC_VAR_GETLIST, &val, &text ) < 0 )
1087     {
1088         return;
1089     }
1090
1091     /* make (un)sensitive */
1092     [o_mi setEnabled: ( val.p_list->i_count > 1 )];
1093
1094     for ( i = 0; i < val.p_list->i_count; i++ )
1095     {
1096         NSMenuItem * o_lmi;
1097         NSString * o_title;
1098
1099         if ( text.p_list->p_values[i].psz_string )
1100         {
1101             o_title = [NSApp localizedString: text.p_list->p_values[i].psz_string];
1102         }
1103         else
1104         {
1105             o_title = [NSString stringWithFormat: @"%s - %d",
1106                         strdup(psz_variable), val.p_list->p_values[i].i_int ];
1107         }
1108         o_lmi = [o_menu addItemWithTitle: [o_title copy]
1109                 action: pf_callback keyEquivalent: @""];
1110         
1111         /* FIXME: this isn't 64-bit clean ! */
1112         [o_lmi setTag: val.p_list->p_values[i].i_int];
1113         [o_lmi setRepresentedObject:
1114             [NSValue valueWithPointer: p_object]];
1115         [o_lmi setTarget: o_controls];
1116
1117         if ( i_value == val.p_list->p_values[i].i_int )
1118             [o_lmi setState: NSOnState];
1119     }
1120
1121     var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
1122                 &val, &text );
1123
1124 }
1125
1126 - (IBAction)clearRecentItems:(id)sender
1127 {
1128     [[NSDocumentController sharedDocumentController]
1129                           clearRecentDocuments: nil];
1130 }
1131
1132 - (void)openRecentItem:(id)sender
1133 {
1134     [self application: nil openFile: [sender title]]; 
1135 }
1136
1137 - (IBAction)viewPreferences:(id)sender
1138 {
1139     [o_prefs showPrefs];
1140 }
1141
1142 - (IBAction)timesliderUpdate:(id)sender
1143 {
1144     float f_updated;
1145
1146     switch( [[NSApp currentEvent] type] )
1147     {
1148         case NSLeftMouseUp:
1149         case NSLeftMouseDown:
1150             f_slider = [sender floatValue];
1151             return;
1152
1153         case NSLeftMouseDragged:
1154             f_updated = [sender floatValue];
1155             break;
1156
1157         default:
1158             return;
1159     }
1160
1161     intf_thread_t * p_intf = [NSApp getIntf];
1162
1163     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1164                                                        FIND_ANYWHERE );
1165
1166     if( p_playlist == NULL )
1167     {
1168         return;
1169     }
1170
1171     vlc_mutex_lock( &p_playlist->object_lock );
1172
1173     if( p_playlist->p_input != NULL )
1174     {
1175         off_t i_tell;
1176         NSString * o_time;
1177         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1178
1179 #define p_area p_playlist->p_input->stream.p_selected_area
1180         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1181         i_tell = f_updated / 10000. * p_area->i_size;
1182         input_OffsetToTime( p_playlist->p_input, psz_time, i_tell );
1183         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1184 #undef p_area
1185
1186         o_time = [NSString stringWithCString: psz_time];
1187         [o_timefield setStringValue: o_time]; 
1188     }
1189
1190     vlc_mutex_unlock( &p_playlist->object_lock );
1191     vlc_object_release( p_playlist );
1192 }
1193
1194 - (IBAction)closeError:(id)sender
1195 {
1196     [o_err_msg setString: @""];
1197     [o_error performClose: self];
1198 }
1199
1200 - (IBAction)openReadMe:(id)sender
1201 {
1202     NSString * o_path = [[NSBundle mainBundle] 
1203         pathForResource: @"README.MacOSX" ofType: @"rtf"]; 
1204
1205     [[NSWorkspace sharedWorkspace] openFile: o_path 
1206                                    withApplication: @"TextEdit"];
1207 }
1208
1209 - (IBAction)openDocumentation:(id)sender
1210 {
1211     NSURL * o_url = [NSURL URLWithString: 
1212         @"http://www.videolan.org/doc/"];
1213
1214     [[NSWorkspace sharedWorkspace] openURL: o_url];
1215 }
1216
1217 - (IBAction)reportABug:(id)sender
1218 {
1219     NSURL * o_url = [NSURL URLWithString: 
1220         @"http://www.videolan.org/support/bug-reporting.html"];
1221
1222     [[NSWorkspace sharedWorkspace] openURL: o_url];
1223 }
1224
1225 - (IBAction)openWebsite:(id)sender
1226 {
1227     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org"];
1228
1229     [[NSWorkspace sharedWorkspace] openURL: o_url];
1230 }
1231
1232 - (IBAction)openLicense:(id)sender
1233 {
1234     NSString * o_path = [[NSBundle mainBundle] 
1235         pathForResource: @"COPYING" ofType: nil];
1236
1237     [[NSWorkspace sharedWorkspace] openFile: o_path 
1238                                    withApplication: @"TextEdit"];
1239 }
1240
1241 - (IBAction)openCrashLog:(id)sender
1242 {
1243     NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1244                                     stringByExpandingTildeInPath]; 
1245
1246     
1247     if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1248     {
1249         [[NSWorkspace sharedWorkspace] openFile: o_path 
1250                                     withApplication: @"Console"];
1251     }
1252     else
1253     {
1254         NSBeginInformationalAlertSheet(_NS("No CrashLog found"), @"Continue", nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("Either you are running Mac OS X pre 10.2 or you haven't experienced any heavy crashes yet.") );
1255
1256     }
1257 }
1258
1259 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1260 {
1261     if( [o_notification object] == o_msgs_panel )
1262     {
1263         id o_msg;
1264         NSEnumerator * o_enum;
1265
1266         [o_messages setString: @""]; 
1267
1268         [o_msg_lock lock];
1269
1270         o_enum = [o_msg_arr objectEnumerator];
1271
1272         while( ( o_msg = [o_enum nextObject] ) != nil )
1273         {
1274             [o_messages insertText: o_msg];
1275         }
1276
1277         [o_msg_lock unlock];
1278     }
1279 }
1280
1281 @end
1282
1283 @implementation VLCMain (NSMenuValidation)
1284
1285 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1286 {
1287     BOOL bEnabled = TRUE;
1288
1289     /* Recent Items Menu */
1290
1291     if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
1292     {
1293         NSMenu * o_menu = [o_mi_open_recent submenu];
1294         int i_nb_items = [o_menu numberOfItems];
1295         NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1296                                                        recentDocumentURLs];
1297         UInt32 i_nb_docs = [o_docs count];
1298
1299         if( i_nb_items > 1 )
1300         {
1301             while( --i_nb_items )
1302             {
1303                 [o_menu removeItemAtIndex: 0];
1304             }
1305         }
1306
1307         if( i_nb_docs > 0 )
1308         {
1309             NSURL * o_url;
1310             NSString * o_doc;
1311
1312             [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1313
1314             while( TRUE )
1315             {
1316                 i_nb_docs--;
1317
1318                 o_url = [o_docs objectAtIndex: i_nb_docs];
1319
1320                 if( [o_url isFileURL] )
1321                 {
1322                     o_doc = [o_url path];
1323                 }
1324                 else
1325                 {
1326                     o_doc = [o_url absoluteString];
1327                 }
1328
1329                 [o_menu insertItemWithTitle: o_doc
1330                     action: @selector(openRecentItem:)
1331                     keyEquivalent: @"" atIndex: 0]; 
1332
1333                 if( i_nb_docs == 0 )
1334                 {
1335                     break;
1336                 }
1337             } 
1338         }
1339         else
1340         {
1341             bEnabled = FALSE;
1342         }
1343     }
1344
1345     return( bEnabled );
1346 }
1347
1348 @end
1349
1350 @implementation VLCMain (Internal)
1351
1352 - (void)handlePortMessage:(NSPortMessage *)o_msg
1353 {
1354     id ** val;
1355     NSData * o_data;
1356     NSValue * o_value;
1357     NSInvocation * o_inv;
1358     NSConditionLock * o_lock;
1359  
1360     o_data = [[o_msg components] lastObject];
1361     o_inv = *((NSInvocation **)[o_data bytes]); 
1362     [o_inv getArgument: &o_value atIndex: 2];
1363     val = (id **)[o_value pointerValue];
1364     [o_inv setArgument: val[1] atIndex: 2];
1365     o_lock = *(val[0]);
1366
1367     [o_lock lock];
1368     [o_inv invoke];
1369     [o_lock unlockWithCondition: 1];
1370 }
1371
1372 @end