2a11a84a8d870801ed8efaefb414fb2428d71b0d
[vlc.git] / 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.83 2003/05/15 01:23:05 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_reportabug setTitle: _NS("Report a Bug")];
394     [o_mi_website setTitle: _NS("VideoLAN Website")];
395     [o_mi_license setTitle: _NS("License")];
396
397     /* dock menu */
398     [o_dmi_play setTitle: _NS("Play")];
399     [o_dmi_stop setTitle: _NS("Stop")];
400     [o_dmi_next setTitle: _NS("Next")];
401     [o_dmi_previous setTitle: _NS("Previous")];
402
403     /* error panel */
404     [o_error setTitle: _NS("Error")];
405     [o_err_lbl setStringValue: _NS("An error has occurred which probably prevented the execution of your request:")];
406     [o_err_bug_lbl setStringValue: _NS("If you believe that it is a bug, please follow the instructions at:")]; 
407     [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
408     [o_err_btn_dismiss setTitle: _NS("Dismiss")];
409
410     [o_info_window setTitle: _NS("Info")];
411
412     [self setSubmenusEnabled: FALSE];
413     [self manageVolumeSlider];
414 }
415
416 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
417 {
418     intf_thread_t * p_intf = [NSApp getIntf];
419
420     o_msg_lock = [[NSLock alloc] init];
421     o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
422
423     o_img_play = [[NSImage imageNamed: @"play"] retain];
424     o_img_pause = [[NSImage imageNamed: @"pause"] retain];
425
426     [p_intf->p_sys->o_sendport setDelegate: self];
427     [[NSRunLoop currentRunLoop] 
428         addPort: p_intf->p_sys->o_sendport
429         forMode: NSDefaultRunLoopMode];
430
431     [NSTimer scheduledTimerWithTimeInterval: 0.5
432         target: self selector: @selector(manageIntf:)
433         userInfo: nil repeats: FALSE];
434
435     [NSThread detachNewThreadSelector: @selector(manage)
436         toTarget: self withObject: nil];
437
438     vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
439 }
440
441 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
442 {
443     intf_thread_t * p_intf = [NSApp getIntf];
444     
445     config_PutPsz( p_intf, "sub-file", "" );
446     config_PutInt( p_intf, "sub-delay", 0 );
447     config_PutFloat( p_intf, "sub-fps", 0.0 );
448     config_PutPsz( p_intf, "sout", "" );
449     
450     [o_playlist appendArray:
451         [NSArray arrayWithObject: o_filename] atPos: -1 enqueue: NO];
452             
453     return( TRUE );
454 }
455
456 - (id)getControls
457 {
458     if ( o_controls )
459     {
460         return o_controls;
461     }
462     return nil;
463 }
464
465 - (void)manage
466 {
467     NSDate * o_sleep_date;
468     intf_thread_t * p_intf = [NSApp getIntf];
469     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
470
471     vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
472
473     while( !p_intf->b_die )
474     {
475         playlist_t * p_playlist;
476
477         vlc_mutex_lock( &p_intf->change_lock );
478
479         p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, 
480                                               FIND_ANYWHERE );
481
482         if( p_playlist != NULL )
483         {
484             var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
485             vlc_mutex_lock( &p_playlist->object_lock );
486             
487             [self manage: p_playlist];
488             
489             vlc_mutex_unlock( &p_playlist->object_lock );
490             vlc_object_release( p_playlist );
491         }
492
493         vlc_mutex_unlock( &p_intf->change_lock );
494
495         o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
496         [NSThread sleepUntilDate: o_sleep_date];
497     }
498
499     [self terminate];
500
501     [o_pool release];
502 }
503
504 - (void)manage:(playlist_t *)p_playlist
505 {
506     vlc_value_t val;
507
508     intf_thread_t * p_intf = [NSApp getIntf];
509
510 #define p_input p_playlist->p_input
511
512     if( p_input )
513     {
514         vout_thread_t   * p_vout  = NULL;
515         aout_instance_t * p_aout  = NULL; 
516
517         vlc_mutex_lock( &p_input->stream.stream_lock );
518
519         if( !p_input->b_die )
520         {
521             audio_volume_t i_volume;
522
523             /* New input or stream map change */
524             if( p_input->stream.b_changed )
525             {
526                 p_intf->p_sys->b_playing = TRUE;
527                 [self manageMode: p_playlist];
528             }
529
530             vlc_value_t val;
531
532             if( var_Get( (vlc_object_t *)p_input, "intf-change", &val )
533                 >= 0 && val.b_bool )
534             {
535                 p_intf->p_sys->b_input_update = TRUE;
536             }
537
538             p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
539                                               FIND_ANYWHERE );
540             if( p_aout != NULL )
541             {
542                 vlc_value_t val;
543
544                 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
545                     >= 0 && val.b_bool )
546                 {
547                     p_intf->p_sys->b_aout_update = TRUE;
548                 }
549
550                 vlc_object_release( (vlc_object_t *)p_aout );
551             }
552
553             aout_VolumeGet( p_intf, &i_volume );
554             p_intf->p_sys->b_mute = ( i_volume == 0 );
555
556             p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
557                                               FIND_ANYWHERE );
558             if( p_vout != NULL )
559             {
560                 vlc_value_t val;
561
562                 if( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
563                     >= 0 && val.b_bool )
564                 {
565                     p_intf->p_sys->b_vout_update = TRUE;
566                 }
567
568                 vlc_object_release( (vlc_object_t *)p_vout );
569             }
570             [self setupMenus: p_input];
571         }
572         vlc_mutex_unlock( &p_input->stream.stream_lock );
573     }
574     else if( p_intf->p_sys->b_playing && !p_intf->b_die )
575     {
576         p_intf->p_sys->b_playing = FALSE;
577         [self manageMode: p_playlist];
578     }
579
580 #undef p_input
581 }
582
583 - (void)manageMode:(playlist_t *)p_playlist
584 {
585     intf_thread_t * p_intf = [NSApp getIntf];
586
587     if( p_playlist->p_input != NULL )
588     {
589         p_intf->p_sys->b_current_title_update = 1;
590         p_playlist->p_input->stream.b_changed = 0;
591         
592         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
593     }
594     else
595     {
596         vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
597                                                           FIND_ANYWHERE );
598         if( p_vout != NULL )
599         {
600             vlc_object_detach( p_vout );
601             vlc_object_release( p_vout );
602
603             vlc_mutex_unlock( &p_playlist->object_lock );
604             vout_Destroy( p_vout );
605             vlc_mutex_lock( &p_playlist->object_lock );
606         }
607     }
608
609     p_intf->p_sys->b_intf_update = VLC_TRUE;
610 }
611
612 - (void)manageIntf:(NSTimer *)o_timer
613 {
614     intf_thread_t * p_intf = [NSApp getIntf];
615
616     if( p_intf->p_vlc->b_die == VLC_TRUE )
617     {
618         [o_timer invalidate];
619         return;
620     }
621
622     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
623                                                        FIND_ANYWHERE );
624
625     if( p_playlist == NULL )
626     {
627         return;
628     }
629
630     if ( p_intf->p_sys->b_playlist_update )
631     {
632         [o_playlist playlistUpdated];
633         p_intf->p_sys->b_playlist_update = VLC_FALSE;
634     }
635
636     if( p_intf->p_sys->b_current_title_update )
637     {
638         vout_thread_t   *p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
639                                               FIND_ANYWHERE );
640         if( p_vout != NULL )
641         {
642             id o_vout_wnd;
643             NSEnumerator * o_enum = [[NSApp windows] objectEnumerator];
644             
645             while( ( o_vout_wnd = [o_enum nextObject] ) )
646             {
647                 if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
648                 {
649                     [o_vout_wnd updateTitle];
650                 }
651             }
652             vlc_object_release( (vlc_object_t *)p_vout );
653         }
654         [o_playlist updateRowSelection];
655         [o_info updateInfo];
656
657         p_intf->p_sys->b_current_title_update = FALSE;
658     }
659
660     vlc_mutex_lock( &p_playlist->object_lock );
661
662 #define p_input p_playlist->p_input
663
664     if( p_input != NULL )
665     {
666         vlc_mutex_lock( &p_input->stream.stream_lock );
667     }
668
669     if( p_intf->p_sys->b_intf_update )
670     {
671         vlc_bool_t b_input = VLC_FALSE;
672         vlc_bool_t b_plmul = VLC_FALSE;
673         vlc_bool_t b_control = VLC_FALSE;
674         vlc_bool_t b_seekable = VLC_FALSE;
675         vlc_bool_t b_chapters = VLC_FALSE;
676
677         b_plmul = p_playlist->i_size > 1;
678
679         if( ( b_input = ( p_input != NULL ) ) )
680         {
681             /* seekable streams */
682             b_seekable = p_input->stream.b_seekable;
683
684             /* control buttons for free pace streams */
685             b_control = p_input->stream.b_pace_control; 
686
687             /* chapters */
688             b_chapters = p_input->stream.p_selected_area->i_part_nb > 1; 
689
690             /* play status */
691             p_intf->p_sys->b_play_status = 
692                 p_input->stream.control.i_status != PAUSE_S;
693         }
694         else
695         {
696             /* play status */
697             p_intf->p_sys->b_play_status = FALSE;
698             [self setSubmenusEnabled: FALSE];
699         }
700
701         [self playStatusUpdated: p_intf->p_sys->b_play_status];
702
703         [o_btn_stop setEnabled: b_input];
704         [o_btn_faster setEnabled: b_control];
705         [o_btn_slower setEnabled: b_control];
706         [o_btn_prev setEnabled: (b_plmul || b_chapters)];
707         [o_btn_next setEnabled: (b_plmul || b_chapters)];
708
709         [o_timeslider setFloatValue: 0.0];
710         [o_timeslider setEnabled: b_seekable];
711         [o_timefield setStringValue: @"0:00:00"];
712
713         [self manageVolumeSlider];
714
715         p_intf->p_sys->b_intf_update = VLC_FALSE;
716     }
717
718 #define p_area p_input->stream.p_selected_area
719
720     if( p_intf->p_sys->b_playing && p_input != NULL )
721     {
722         vlc_bool_t b_field_update = TRUE;
723
724         if( !p_input->b_die && ( p_intf->p_sys->b_play_status !=
725             ( p_input->stream.control.i_status != PAUSE_S ) ) ) 
726         {
727             p_intf->p_sys->b_play_status =
728                 !p_intf->p_sys->b_play_status;
729
730             [self playStatusUpdated: p_intf->p_sys->b_play_status]; 
731         }
732
733         if( p_input->stream.b_seekable )
734         {
735             if( f_slider == f_slider_old )
736             {
737                 float f_updated = ( 10000. * p_area->i_tell ) /
738                                            p_area->i_size;
739
740                 if( f_slider != f_updated )
741                 {
742                     [o_timeslider setFloatValue: f_updated];
743                 }
744             }
745             else
746             {
747                 off_t i_seek = ( f_slider * p_area->i_size ) / 10000;
748
749                 /* release the lock to be able to seek */
750                 vlc_mutex_unlock( &p_input->stream.stream_lock );
751                 input_Seek( p_input, i_seek, INPUT_SEEK_SET );
752                 vlc_mutex_lock( &p_input->stream.stream_lock );
753
754                 /* update the old value */
755                 f_slider_old = f_slider; 
756
757                 b_field_update = VLC_FALSE;
758             }
759         }
760
761         if( b_field_update )
762         {
763             NSString * o_time;
764             char psz_time[ OFFSETTOTIME_MAX_SIZE ];
765
766             input_OffsetToTime( p_input, psz_time, p_area->i_tell );
767
768             o_time = [NSString stringWithCString: psz_time];
769             [o_timefield setStringValue: o_time];
770         }
771
772         /* disable screen saver */
773         UpdateSystemActivity( UsrActivity );
774     }
775
776 #undef p_area
777
778     if( p_input != NULL )
779     {
780         vlc_mutex_unlock( &p_input->stream.stream_lock );
781     }
782
783 #undef p_input
784
785     vlc_mutex_unlock( &p_playlist->object_lock );
786     vlc_object_release( p_playlist );
787
788     [self updateMessageArray];
789
790     [NSTimer scheduledTimerWithTimeInterval: 0.5
791         target: self selector: @selector(manageIntf:)
792         userInfo: nil repeats: FALSE];
793 }
794
795 - (void)updateMessageArray
796 {
797     int i_start, i_stop;
798     intf_thread_t * p_intf = [NSApp getIntf];
799
800     vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
801     i_stop = *p_intf->p_sys->p_sub->pi_stop;
802     vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
803
804     if( p_intf->p_sys->p_sub->i_start != i_stop )
805     {
806         NSColor *o_white = [NSColor whiteColor];
807         NSColor *o_red = [NSColor redColor];
808         NSColor *o_yellow = [NSColor yellowColor];
809         NSColor *o_gray = [NSColor grayColor];
810
811         NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
812         static const char * ppsz_type[4] = { ": ", " error: ",
813                                              " warning: ", " debug: " };
814
815         for( i_start = p_intf->p_sys->p_sub->i_start;
816              i_start != i_stop;
817              i_start = (i_start+1) % VLC_MSG_QSIZE )
818         {
819             NSString *o_msg;
820             NSDictionary *o_attr;
821             NSAttributedString *o_msg_color;
822
823             int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
824
825             [o_msg_lock lock];
826
827             if( [o_msg_arr count] + 2 > 400 )
828             {
829                 unsigned rid[] = { 0, 1 };
830                 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
831                            numIndices: sizeof(rid)/sizeof(rid[0])];
832             }
833
834             o_attr = [NSDictionary dictionaryWithObject: o_gray
835                 forKey: NSForegroundColorAttributeName];
836             o_msg = [NSString stringWithFormat: @"%s%s",
837                 p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
838                 ppsz_type[i_type]];
839             o_msg_color = [[NSAttributedString alloc]
840                 initWithString: o_msg attributes: o_attr];
841             [o_msg_arr addObject: [o_msg_color autorelease]];
842
843             o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
844                 forKey: NSForegroundColorAttributeName];
845             o_msg = [NSString stringWithFormat: @"%s\n",
846                 p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
847             o_msg_color = [[NSAttributedString alloc]
848                 initWithString: o_msg attributes: o_attr];
849             [o_msg_arr addObject: [o_msg_color autorelease]];
850
851             [o_msg_lock unlock];
852
853             if( i_type == 1 )
854             {
855                 NSString *o_my_msg = [NSString stringWithFormat: @"%s: %s\n",
856                     p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
857                     p_intf->p_sys->p_sub->p_msg[i_start].psz_msg];
858
859                 NSRange s_r = NSMakeRange( [[o_err_msg string] length], 0 );
860                 [o_err_msg setEditable: YES];
861                 [o_err_msg setSelectedRange: s_r];
862                 [o_err_msg insertText: o_my_msg];
863
864                 [o_error makeKeyAndOrderFront: self];
865                 [o_err_msg setEditable: NO];
866             }
867         }
868
869         vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
870         p_intf->p_sys->p_sub->i_start = i_start;
871         vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
872     }
873 }
874
875 - (void)playStatusUpdated:(BOOL)b_pause
876 {
877     if( b_pause )
878     {
879         [o_btn_play setImage: o_img_pause];
880         [o_btn_play setToolTip: _NS("Pause")];
881         [o_mi_play setTitle: _NS("Pause")];
882         [o_dmi_play setTitle: _NS("Pause")];
883     }
884     else
885     {
886         [o_btn_play setImage: o_img_play];
887         [o_btn_play setToolTip: _NS("Play")];
888         [o_mi_play setTitle: _NS("Play")];
889         [o_dmi_play setTitle: _NS("Play")];
890     }
891 }
892
893 - (void)setSubmenusEnabled:(BOOL)b_enabled
894 {
895     [o_mi_program setEnabled: b_enabled];
896     [o_mi_title setEnabled: b_enabled];
897     [o_mi_chapter setEnabled: b_enabled];
898     [o_mi_audiotrack setEnabled: b_enabled];
899     [o_mi_videotrack setEnabled: b_enabled];
900     [o_mi_subtitle setEnabled: b_enabled];
901     [o_mi_channels setEnabled: b_enabled];
902     [o_mi_device setEnabled: b_enabled];
903     [o_mi_screen setEnabled: b_enabled];
904 }
905
906 - (void)manageVolumeSlider
907 {
908     audio_volume_t i_volume;
909     intf_thread_t * p_intf = [NSApp getIntf];
910
911     aout_VolumeGet( p_intf, &i_volume );
912
913     [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP]; 
914     [o_volumeslider setEnabled: TRUE];
915
916     p_intf->p_sys->b_mute = ( i_volume == 0 );
917 }
918
919 - (void)terminate
920 {
921     NSEvent * o_event;
922     vout_thread_t * p_vout;
923     playlist_t * p_playlist;
924     intf_thread_t * p_intf = [NSApp getIntf];
925
926     /*
927      * Free playlists
928      */
929     msg_Dbg( p_intf, "removing all playlists" );
930     while( (p_playlist = vlc_object_find( p_intf->p_vlc, VLC_OBJECT_PLAYLIST,
931                                           FIND_CHILD )) )
932     {
933         vlc_object_detach( p_playlist );
934         vlc_object_release( p_playlist );
935         playlist_Destroy( p_playlist );
936     }
937
938     /*
939      * Free video outputs
940      */
941     msg_Dbg( p_intf, "removing all video outputs" );
942     while( (p_vout = vlc_object_find( p_intf->p_vlc, 
943                                       VLC_OBJECT_VOUT, FIND_CHILD )) )
944     {
945         vlc_object_detach( p_vout );
946         vlc_object_release( p_vout );
947         vout_Destroy( p_vout );
948     }
949
950     if( o_img_pause != nil )
951     {
952         [o_img_pause release];
953         o_img_pause = nil;
954     }
955
956     if( o_img_play != nil )
957     {
958         [o_img_play release];
959         o_img_play = nil;
960     }
961
962     if( o_msg_arr != nil )
963     {
964         [o_msg_arr removeAllObjects];
965         [o_msg_arr release];
966         o_msg_arr = nil;
967     }
968
969     if( o_msg_lock != nil )
970     {
971         [o_msg_lock release];
972         o_msg_lock = nil;
973     }
974
975     if( o_prefs != nil )
976     {
977         [o_prefs release];
978         o_prefs = nil;
979     }
980
981     [NSApp stop: nil];
982
983     /* write cached user defaults to disk */
984     [[NSUserDefaults standardUserDefaults] synchronize];
985
986     /* send a dummy event to break out of the event loop */
987     o_event = [NSEvent mouseEventWithType: NSLeftMouseDown
988                 location: NSMakePoint( 1, 1 ) modifierFlags: 0
989                 timestamp: 1 windowNumber: [[NSApp mainWindow] windowNumber]
990                 context: [NSGraphicsContext currentContext] eventNumber: 1
991                 clickCount: 1 pressure: 0.0];
992     [NSApp postEvent: o_event atStart: YES];
993 }
994
995 - (void)setupMenus:(input_thread_t *)p_input
996 {
997     intf_thread_t * p_intf = [NSApp getIntf];
998     vlc_value_t val;
999
1000     if( p_intf->p_sys->b_input_update )
1001     {
1002         val.b_bool = FALSE;
1003
1004         [self setupVarMenu: o_mi_program target: (vlc_object_t *)p_input
1005             var: "program" selector: @selector(toggleVar:)];
1006
1007         [self setupVarMenu: o_mi_title target: (vlc_object_t *)p_input
1008             var: "title" selector: @selector(toggleVar:)];
1009
1010         [self setupVarMenu: o_mi_chapter target: (vlc_object_t *)p_input
1011             var: "chapter" selector: @selector(toggleVar:)];
1012
1013         [self setupVarMenu: o_mi_audiotrack target: (vlc_object_t *)p_input
1014             var: "audio-es" selector: @selector(toggleVar:)];
1015
1016         [self setupVarMenu: o_mi_videotrack target: (vlc_object_t *)p_input
1017             var: "video-es" selector: @selector(toggleVar:)];
1018
1019         [self setupVarMenu: o_mi_subtitle target: (vlc_object_t *)p_input
1020             var: "spu-es" selector: @selector(toggleVar:)];
1021
1022         p_intf->p_sys->b_input_update = FALSE;
1023         var_Set( (vlc_object_t *)p_input, "intf-change", val );
1024     }
1025
1026     if ( p_intf->p_sys->b_aout_update )
1027     {
1028         aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
1029                                                     FIND_ANYWHERE );
1030
1031         if ( p_aout != NULL )
1032         {
1033             val.b_bool = FALSE;
1034             
1035             [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
1036                 var: "audio-channels" selector: @selector(toggleVar:)];
1037
1038             [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
1039                 var: "audio-device" selector: @selector(toggleVar:)];
1040             var_Set( (vlc_object_t *)p_aout, "intf-change", val );
1041             
1042             vlc_object_release( (vlc_object_t *)p_aout );
1043         }
1044         p_intf->p_sys->b_aout_update = FALSE;
1045     }
1046
1047     if( p_intf->p_sys->b_vout_update )
1048     {
1049         vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
1050                                                           FIND_ANYWHERE );
1051
1052         if ( p_vout != NULL )
1053         {
1054             val.b_bool = FALSE;
1055
1056             [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
1057                 var: "video-device" selector: @selector(toggleVar:)];
1058             var_Set( (vlc_object_t *)p_vout, "intf-change", val );
1059             
1060             vlc_object_release( (vlc_object_t *)p_vout );
1061             [o_mi_close_window setEnabled: TRUE];
1062         }
1063         
1064         p_intf->p_sys->b_vout_update = FALSE;
1065     }
1066 }
1067
1068 - (void)setupVarMenu:(NSMenuItem *)o_mi
1069                      target:(vlc_object_t *)p_object
1070                      var:(const char *)psz_variable
1071                      selector:(SEL)pf_callback
1072 {
1073     int i, i_nb_items, i_value;
1074     NSMenu * o_menu = [o_mi submenu];
1075     vlc_value_t val, text;
1076     
1077     [o_mi setTag: (int)psz_variable];
1078     
1079     /* remove previous items */
1080     i_nb_items = [o_menu numberOfItems];
1081     for( i = 0; i < i_nb_items; i++ )
1082     {
1083         [o_menu removeItemAtIndex: 0];
1084     }
1085
1086     if ( var_Get( p_object, psz_variable, &val ) < 0 )
1087     {
1088         return;
1089     }
1090     i_value = val.i_int;
1091
1092     if ( var_Change( p_object, psz_variable,
1093                      VLC_VAR_GETLIST, &val, &text ) < 0 )
1094     {
1095         return;
1096     }
1097
1098     /* make (un)sensitive */
1099     [o_mi setEnabled: ( val.p_list->i_count > 1 )];
1100
1101     for ( i = 0; i < val.p_list->i_count; i++ )
1102     {
1103         NSMenuItem * o_lmi;
1104         NSString * o_title;
1105
1106         if ( text.p_list->p_values[i].psz_string )
1107         {
1108             o_title = [NSApp localizedString: text.p_list->p_values[i].psz_string];
1109         }
1110         else
1111         {
1112             o_title = [NSString stringWithFormat: @"%s - %d",
1113                         strdup(psz_variable), val.p_list->p_values[i].i_int ];
1114         }
1115         o_lmi = [o_menu addItemWithTitle: [o_title copy]
1116                 action: pf_callback keyEquivalent: @""];
1117         
1118         /* FIXME: this isn't 64-bit clean ! */
1119         [o_lmi setTag: val.p_list->p_values[i].i_int];
1120         [o_lmi setRepresentedObject:
1121             [NSValue valueWithPointer: p_object]];
1122         [o_lmi setTarget: o_controls];
1123
1124         if ( i_value == val.p_list->p_values[i].i_int )
1125             [o_lmi setState: NSOnState];
1126     }
1127
1128     var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
1129                 &val, &text );
1130
1131 }
1132
1133 - (IBAction)clearRecentItems:(id)sender
1134 {
1135     [[NSDocumentController sharedDocumentController]
1136                           clearRecentDocuments: nil];
1137 }
1138
1139 - (void)openRecentItem:(id)sender
1140 {
1141     [self application: nil openFile: [sender title]]; 
1142 }
1143
1144 - (IBAction)viewPreferences:(id)sender
1145 {
1146     if( o_prefs == nil )
1147     {
1148         o_prefs = [[VLCPrefs alloc] init];
1149     }
1150
1151     [o_prefs createPrefPanel: @"main"];
1152 }
1153
1154 - (IBAction)timesliderUpdate:(id)sender
1155 {
1156     float f_updated;
1157
1158     switch( [[NSApp currentEvent] type] )
1159     {
1160         case NSLeftMouseUp:
1161         case NSLeftMouseDown:
1162             f_slider = [sender floatValue];
1163             return;
1164
1165         case NSLeftMouseDragged:
1166             f_updated = [sender floatValue];
1167             break;
1168
1169         default:
1170             return;
1171     }
1172
1173     intf_thread_t * p_intf = [NSApp getIntf];
1174
1175     playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
1176                                                        FIND_ANYWHERE );
1177
1178     if( p_playlist == NULL )
1179     {
1180         return;
1181     }
1182
1183     vlc_mutex_lock( &p_playlist->object_lock );
1184
1185     if( p_playlist->p_input != NULL )
1186     {
1187         off_t i_tell;
1188         NSString * o_time;
1189         char psz_time[ OFFSETTOTIME_MAX_SIZE ];
1190
1191 #define p_area p_playlist->p_input->stream.p_selected_area
1192         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
1193         i_tell = f_updated / 10000. * p_area->i_size;
1194         input_OffsetToTime( p_playlist->p_input, psz_time, i_tell );
1195         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
1196 #undef p_area
1197
1198         o_time = [NSString stringWithCString: psz_time];
1199         [o_timefield setStringValue: o_time]; 
1200     }
1201
1202     vlc_mutex_unlock( &p_playlist->object_lock );
1203     vlc_object_release( p_playlist );
1204 }
1205
1206 - (IBAction)closeError:(id)sender
1207 {
1208     [o_err_msg setString: @""];
1209     [o_error performClose: self];
1210 }
1211
1212 - (IBAction)openReadMe:(id)sender
1213 {
1214     NSString * o_path = [[NSBundle mainBundle] 
1215         pathForResource: @"README.MacOSX" ofType: @"rtf"]; 
1216
1217     [[NSWorkspace sharedWorkspace] openFile: o_path 
1218                                    withApplication: @"TextEdit"];
1219 }
1220
1221 - (IBAction)reportABug:(id)sender
1222 {
1223     NSURL * o_url = [NSURL URLWithString: 
1224         @"http://www.videolan.org/support/bug-reporting.html"];
1225
1226     [[NSWorkspace sharedWorkspace] openURL: o_url];
1227 }
1228
1229 - (IBAction)openWebsite:(id)sender
1230 {
1231     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org"];
1232
1233     [[NSWorkspace sharedWorkspace] openURL: o_url];
1234 }
1235
1236 - (IBAction)openLicense:(id)sender
1237 {
1238     NSString * o_path = [[NSBundle mainBundle] 
1239         pathForResource: @"COPYING" ofType: nil];
1240
1241     [[NSWorkspace sharedWorkspace] openFile: o_path 
1242                                    withApplication: @"TextEdit"];
1243 }
1244
1245 - (IBAction)openCrashLog:(id)sender
1246 {
1247     NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
1248                                     stringByExpandingTildeInPath]; 
1249
1250     
1251     if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
1252     {
1253         [[NSWorkspace sharedWorkspace] openFile: o_path 
1254                                     withApplication: @"Console"];
1255     }
1256     else
1257     {
1258         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.") );
1259
1260     }
1261 }
1262
1263 - (void)windowDidBecomeKey:(NSNotification *)o_notification
1264 {
1265     if( [o_notification object] == o_msgs_panel )
1266     {
1267         id o_msg;
1268         NSEnumerator * o_enum;
1269
1270         [o_messages setString: @""]; 
1271
1272         [o_msg_lock lock];
1273
1274         o_enum = [o_msg_arr objectEnumerator];
1275
1276         while( ( o_msg = [o_enum nextObject] ) != nil )
1277         {
1278             [o_messages insertText: o_msg];
1279         }
1280
1281         [o_msg_lock unlock];
1282     }
1283 }
1284
1285 @end
1286
1287 @implementation VLCMain (NSMenuValidation)
1288
1289 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1290 {
1291     BOOL bEnabled = TRUE;
1292
1293     /* Recent Items Menu */
1294
1295     if( [[o_mi title] isEqualToString: _NS("Clear Menu")] )
1296     {
1297         NSMenu * o_menu = [o_mi_open_recent submenu];
1298         int i_nb_items = [o_menu numberOfItems];
1299         NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1300                                                        recentDocumentURLs];
1301         UInt32 i_nb_docs = [o_docs count];
1302
1303         if( i_nb_items > 1 )
1304         {
1305             while( --i_nb_items )
1306             {
1307                 [o_menu removeItemAtIndex: 0];
1308             }
1309         }
1310
1311         if( i_nb_docs > 0 )
1312         {
1313             NSURL * o_url;
1314             NSString * o_doc;
1315
1316             [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1317
1318             while( TRUE )
1319             {
1320                 i_nb_docs--;
1321
1322                 o_url = [o_docs objectAtIndex: i_nb_docs];
1323
1324                 if( [o_url isFileURL] )
1325                 {
1326                     o_doc = [o_url path];
1327                 }
1328                 else
1329                 {
1330                     o_doc = [o_url absoluteString];
1331                 }
1332
1333                 [o_menu insertItemWithTitle: o_doc
1334                     action: @selector(openRecentItem:)
1335                     keyEquivalent: @"" atIndex: 0]; 
1336
1337                 if( i_nb_docs == 0 )
1338                 {
1339                     break;
1340                 }
1341             } 
1342         }
1343         else
1344         {
1345             bEnabled = FALSE;
1346         }
1347     }
1348
1349     return( bEnabled );
1350 }
1351
1352 @end
1353
1354 @implementation VLCMain (Internal)
1355
1356 - (void)handlePortMessage:(NSPortMessage *)o_msg
1357 {
1358     id ** val;
1359     NSData * o_data;
1360     NSValue * o_value;
1361     NSInvocation * o_inv;
1362     NSConditionLock * o_lock;
1363  
1364     o_data = [[o_msg components] lastObject];
1365     o_inv = *((NSInvocation **)[o_data bytes]); 
1366     [o_inv getArgument: &o_value atIndex: 2];
1367     val = (id **)[o_value pointerValue];
1368     [o_inv setArgument: val[1] atIndex: 2];
1369     o_lock = *(val[0]);
1370
1371     [o_lock lock];
1372     [o_inv invoke];
1373     [o_lock unlockWithCondition: 1];
1374 }
1375
1376 @end