1 /*****************************************************************************
2 * vlcshell.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2005 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
34 #ifdef HAVE_MOZILLA_CONFIG_H
35 # include <mozilla-config.h>
44 /* This is from mozilla java, do we really need it? */
49 #include "vlcplugin.h"
51 /* Enable/disable debugging printf's for X11 resizing */
52 #undef X11_RESIZE_DEBUG
54 #define WINDOW_TEXT "Video is loading..."
57 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
60 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
63 /*****************************************************************************
64 * Unix-only declarations
65 ******************************************************************************/
68 static void Redraw( Widget w, XtPointer closure, XEvent *event );
69 static void ControlHandler( Widget w, XtPointer closure, XEvent *event );
70 static void Resize( Widget w, XtPointer closure, XEvent *event );
74 /*****************************************************************************
75 * MacOS-only declarations
76 ******************************************************************************/
80 /*****************************************************************************
81 * Windows-only declarations
82 *****************************************************************************/
85 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );
89 /******************************************************************************
91 *****************************************************************************/
92 char * NPP_GetMIMEDescription( void )
94 return PLUGIN_MIMETYPES;
97 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
100 static char psz_desc[1000];
102 /* plugin class variables */
105 case NPPVpluginNameString:
106 *((char **)value) = PLUGIN_NAME;
107 return NPERR_NO_ERROR;
109 case NPPVpluginDescriptionString:
110 snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION, VLC_Version() );
111 *((char **)value) = psz_desc;
112 return NPERR_NO_ERROR;
115 /* move on to instance variables ... */
119 if( instance == NULL )
121 return NPERR_INVALID_INSTANCE_ERROR;
124 /* plugin instance variables */
126 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
127 if( NULL == p_plugin )
129 // plugin has not been initialized yet !
130 return NPERR_INVALID_INSTANCE_ERROR;
135 case NPPVpluginScriptableNPObject:
137 /* retrieve plugin root class */
138 NPClass *scriptClass = p_plugin->getScriptClass();
141 /* create an instance and return it */
142 *(NPObject**)value = NPN_CreateObject(instance, scriptClass);
143 return NPERR_NO_ERROR;
151 return NPERR_GENERIC_ERROR;
155 * there is some confusion in gecko headers regarding definition of this API
156 * NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
159 NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
161 return NPERR_GENERIC_ERROR;
164 /******************************************************************************
166 *****************************************************************************/
168 int16 NPP_HandleEvent( NPP instance, void * event )
170 static UInt32 lastMouseUp = 0;
172 if( instance == NULL )
177 VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
179 if( p_plugin == NULL )
184 EventRecord *myEvent = (EventRecord*)event;
186 switch( myEvent->what )
192 if( (myEvent->when - lastMouseUp) < GetDblTime() )
195 libvlc_instance_t *p_vlc = p_plugin->getVLC();
199 if( libvlc_playlist_isplaying(p_vlc, NULL) )
201 libvlc_media_instance_t *p_md =
202 libvlc_playlist_get_media_instance(p_vlc, NULL);
205 libvlc_toggle_fullscreen(p_md, NULL);
206 libvlc_media_instance_release(p_md);
214 lastMouseUp = myEvent->when;
222 const NPWindow& npwindow = p_plugin->getWindow();
223 if( npwindow.window )
226 libvlc_instance_t *p_vlc = p_plugin->getVLC();
230 if( libvlc_playlist_isplaying(p_vlc, NULL) )
232 libvlc_media_instance_t *p_md =
233 libvlc_playlist_get_media_instance(p_vlc, NULL);
236 hasVout = libvlc_media_instance_has_vout(p_md, NULL);
239 libvlc_rectangle_t area;
242 area.right = npwindow.width;
243 area.bottom = npwindow.height;
244 libvlc_video_redraw_rectangle(p_md, &area, NULL);
246 libvlc_media_instance_release(p_md);
253 /* draw the beautiful "No Picture" */
255 ForeColor(blackColor);
258 /* seems that firefox forgets to set the following on occasion (reload) */
259 SetOrigin(((NP_Port *)npwindow.window)->portx,
260 ((NP_Port *)npwindow.window)->porty);
265 rect.right = npwindow.width;
266 rect.bottom = npwindow.height;
269 ForeColor(whiteColor);
270 MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
271 DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
278 case NPEventType_GetFocusEvent:
279 case NPEventType_LoseFocusEvent:
281 case NPEventType_AdjustCursorEvent:
283 case NPEventType_MenuCommandEvent:
285 case NPEventType_ClippingChangedEvent:
287 case NPEventType_ScrollingBeginsEvent:
289 case NPEventType_ScrollingEndsEvent:
296 #endif /* XP_MACOSX */
298 /******************************************************************************
299 * General Plug-in Calls
300 *****************************************************************************/
301 NPError NPP_Initialize( void )
303 return NPERR_NO_ERROR;
306 jref NPP_GetJavaClass( void )
311 void NPP_Shutdown( void )
316 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
317 char* argn[], char* argv[], NPSavedData* saved )
321 if( instance == NULL )
323 return NPERR_INVALID_INSTANCE_ERROR;
326 VlcPlugin * p_plugin = new VlcPlugin( instance, mode );
327 if( NULL == p_plugin )
329 return NPERR_OUT_OF_MEMORY_ERROR;
332 status = p_plugin->init(argc, argn, argv);
333 if( NPERR_NO_ERROR == status )
335 instance->pdata = reinterpret_cast<void*>(p_plugin);
337 NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
338 NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
348 NPError NPP_Destroy( NPP instance, NPSavedData** save )
350 if( NULL == instance )
351 return NPERR_INVALID_INSTANCE_ERROR;
353 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
354 if( NULL == p_plugin )
355 return NPERR_NO_ERROR;
357 instance->pdata = NULL;
360 HWND win = (HWND)p_plugin->getWindow().window;
361 WNDPROC winproc = p_plugin->getWindowProc();
365 SetWindowLong( win, GWL_WNDPROC, (LONG)winproc );
371 return NPERR_NO_ERROR;
374 NPError NPP_SetWindow( NPP instance, NPWindow* window )
378 return NPERR_INVALID_INSTANCE_ERROR;
381 /* NPP_SetWindow may be called before NPP_New (Opera) */
382 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
385 /* we should probably show a splash screen here */
386 return NPERR_NO_ERROR;
389 libvlc_instance_t *p_vlc = p_plugin->getVLC();
393 * Before setting window to point to the
394 * new window, you may wish to compare the new window
395 * info to the previous window (if any) to note window
399 /* retrieve current window */
400 NPWindow& curwin = p_plugin->getWindow();
403 if( window && window->window )
405 /* check if plugin has a new parent window */
406 CGrafPtr drawable = (((NP_Port*) (window->window))->port);
407 if( !curwin.window || drawable != (((NP_Port*) (curwin.window))->port) )
409 /* set/change parent window */
410 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
413 /* as MacOS X video output is windowless, set viewport */
414 libvlc_rectangle_t view, clip;
417 ** browser sets port origin to top-left location of plugin relative to GrafPort
418 ** window origin is set relative to document, which of little use for drawing
420 view.top = ((NP_Port*) (window->window))->porty;
421 view.left = ((NP_Port*) (window->window))->portx;
422 view.bottom = window->height+view.top;
423 view.right = window->width+view.left;
424 /* clipRect coordinates are also relative to GrafPort */
425 clip.top = window->clipRect.top;
426 clip.left = window->clipRect.left;
427 clip.bottom = window->clipRect.bottom;
428 clip.right = window->clipRect.right;
430 libvlc_video_set_viewport(p_vlc, &view, &clip, NULL);
432 /* remember new window */
433 p_plugin->setWindow(*window);
435 else if( curwin.window ) {
436 /* change/set parent */
437 libvlc_video_set_parent(p_vlc, 0, NULL);
438 curwin.window = NULL;
440 #endif /* XP_MACOSX */
443 if( window && window->window )
445 /* check if plugin has a new parent window */
446 HWND drawable = (HWND) (window->window);
447 if( !curwin.window || drawable != curwin.window )
449 /* reset previous window settings */
450 HWND oldwin = (HWND)p_plugin->getWindow().window;
451 WNDPROC oldproc = p_plugin->getWindowProc();
455 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)oldproc );
457 /* attach our plugin object */
458 SetWindowLongPtr((HWND)drawable, GWLP_USERDATA,
459 reinterpret_cast<LONG_PTR>(p_plugin));
461 /* install our WNDPROC */
462 p_plugin->setWindowProc( (WNDPROC)SetWindowLong( drawable,
463 GWL_WNDPROC, (LONG)Manage ) );
465 /* change window style to our liking */
466 LONG style = GetWindowLong((HWND)drawable, GWL_STYLE);
467 style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
468 SetWindowLong((HWND)drawable, GWL_STYLE, style);
470 /* change/set parent */
471 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
473 /* remember new window */
474 p_plugin->setWindow(*window);
477 InvalidateRect( (HWND)drawable, NULL, TRUE );
478 UpdateWindow( (HWND)drawable );
481 else if ( curwin.window )
484 HWND oldwin = (HWND)curwin.window;
485 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) );
486 p_plugin->setWindowProc(NULL);
487 /* change/set parent */
488 libvlc_video_set_parent(p_vlc, 0, NULL);
489 curwin.window = NULL;
494 if( window && window->window )
496 Window parent = (Window) window->window;
497 if( !curwin.window || (parent != (Window)curwin.window) )
499 Display *p_display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
501 XResizeWindow( p_display, parent, window->width, window->height );
503 int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
505 Window video = XCreateSimpleWindow( p_display, parent, 0, 0,
506 window->width, window->height - p_plugin->i_control_height, 0,
507 i_blackColor, i_blackColor );
508 Window controls = XCreateSimpleWindow( p_display, parent, 0,
509 window->height - p_plugin->i_control_height-1, window->width,
510 p_plugin->i_control_height-1, 0, i_blackColor, i_blackColor );
512 XMapWindow( p_display, parent );
513 XMapWindow( p_display, video );
514 XMapWindow( p_display, controls );
518 Widget w = XtWindowToWidget( p_display, parent );
520 XtAddEventHandler( w, ExposureMask, FALSE,
521 (XtEventHandler)Redraw, p_plugin );
522 XtAddEventHandler( w, StructureNotifyMask, FALSE,
523 (XtEventHandler)Resize, p_plugin );
524 XtAddEventHandler( w, ButtonReleaseMask, FALSE,
525 (XtEventHandler)ControlHandler, p_plugin );
529 libvlc_media_instance_t *p_md;
531 libvlc_exception_t ex;
532 libvlc_exception_init(& ex );
533 p_md = libvlc_playlist_get_media_instance( p_plugin->getVLC(), &ex );
534 libvlc_exception_init( &ex );
535 libvlc_event_attach( libvlc_media_instance_event_manager( p_md, &ex ),
536 libvlc_MediaInstancePositionChanged, Redraw, NULL, &ex );
539 /* set/change parent window */
540 libvlc_video_set_parent( p_vlc, (libvlc_drawable_t) video, NULL );
542 /* remember window */
543 p_plugin->setWindow( *window );
544 p_plugin->setVideoWindow( video );
545 p_plugin->setControlWindow( controls );
547 Redraw( w, (XtPointer)p_plugin, NULL );
550 else if ( curwin.window )
552 /* change/set parent */
553 libvlc_video_set_parent(p_vlc, 0, NULL);
554 curwin.window = NULL;
558 if( !p_plugin->b_stream )
560 if( p_plugin->psz_target )
562 if( libvlc_playlist_add( p_vlc, p_plugin->psz_target,
565 if( p_plugin->b_autoplay )
567 libvlc_playlist_play(p_vlc, 0, 0, NULL, NULL);
570 p_plugin->b_stream = VLC_TRUE;
573 return NPERR_NO_ERROR;
576 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
577 NPBool seekable, uint16 *stype )
579 if( NULL == instance )
581 return NPERR_INVALID_INSTANCE_ERROR;
584 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
585 if( NULL == p_plugin )
587 return NPERR_INVALID_INSTANCE_ERROR;
591 ** Firefox/Mozilla may decide to open a stream from the URL specified
592 ** in the SRC parameter of the EMBED tag and pass it to us
594 ** since VLC will open the SRC URL as well, we're not interested in
595 ** that stream. Otherwise, we'll take it and queue it up in the playlist
597 if( !p_plugin->psz_target || strcmp(stream->url, p_plugin->psz_target) )
599 /* TODO: use pipes !!!! */
600 *stype = NP_ASFILEONLY;
601 return NPERR_NO_ERROR;
603 return NPERR_GENERIC_ERROR;
606 int32 NPP_WriteReady( NPP instance, NPStream *stream )
613 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
614 int32 len, void *buffer )
621 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
623 if( instance == NULL )
625 return NPERR_INVALID_INSTANCE_ERROR;
627 return NPERR_NO_ERROR;
631 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
633 if( instance == NULL )
638 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
639 if( NULL == p_plugin )
644 if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) != -1 )
646 if( p_plugin->b_autoplay )
648 libvlc_playlist_play( p_plugin->getVLC(), 0, 0, NULL, NULL);
654 void NPP_URLNotify( NPP instance, const char* url,
655 NPReason reason, void* notifyData )
657 /***** Insert NPP_URLNotify code here *****\
658 PluginInstance* p_plugin;
659 if (instance != NULL)
660 p_plugin = (PluginInstance*) instance->pdata;
661 \*********************************************/
665 void NPP_Print( NPP instance, NPPrint* printInfo )
667 if( printInfo == NULL )
672 if( instance != NULL )
674 /***** Insert NPP_Print code here *****\
675 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
676 \**************************************/
678 if( printInfo->mode == NP_FULL )
682 * If your plugin would like to take over
683 * printing completely when it is in full-screen mode,
684 * set printInfo->pluginPrinted to TRUE and print your
685 * plugin as you see fit. If your plugin wants Netscape
686 * to handle printing in this case, set
687 * printInfo->pluginPrinted to FALSE (the default) and
688 * do nothing. If you do want to handle printing
689 * yourself, printOne is true if the print button
690 * (as opposed to the print menu) was clicked.
691 * On the Macintosh, platformPrint is a THPrint; on
692 * Windows, platformPrint is a structure
693 * (defined in npapi.h) containing the printer name, port,
697 /***** Insert NPP_Print code here *****\
698 void* platformPrint =
699 printInfo->print.fullPrint.platformPrint;
701 printInfo->print.fullPrint.printOne;
702 \**************************************/
705 printInfo->print.fullPrint.pluginPrinted = FALSE;
709 /* If not fullscreen, we must be embedded */
712 * If your plugin is embedded, or is full-screen
713 * but you returned false in pluginPrinted above, NPP_Print
714 * will be called with mode == NP_EMBED. The NPWindow
715 * in the printInfo gives the location and dimensions of
716 * the embedded plugin on the printed page. On the
717 * Macintosh, platformPrint is the printer port; on
718 * Windows, platformPrint is the handle to the printing
722 /***** Insert NPP_Print code here *****\
723 NPWindow* printWindow =
724 &(printInfo->print.embedPrint.window);
725 void* platformPrint =
726 printInfo->print.embedPrint.platformPrint;
727 \**************************************/
732 /******************************************************************************
733 * Windows-only methods
734 *****************************************************************************/
736 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
738 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
747 PAINTSTRUCT paintstruct;
751 hdc = BeginPaint( p_hwnd, &paintstruct );
753 GetClientRect( p_hwnd, &rect );
755 FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
756 SetTextColor(hdc, RGB(255, 255, 255));
757 SetBkColor(hdc, RGB(0, 0, 0));
758 DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect,
759 DT_CENTER|DT_VCENTER|DT_SINGLELINE);
761 EndPaint( p_hwnd, &paintstruct );
765 /* delegate to default handler */
766 return CallWindowProc(p_plugin->getWindowProc(), p_hwnd, i_msg, wpar, lpar );
771 /******************************************************************************
773 *****************************************************************************/
775 static void Redraw( Widget w, XtPointer closure, XEvent *event )
777 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
778 const NPWindow& window = p_plugin->getWindow();
783 XImage *p_btnPlay = NULL;
784 XImage *p_btnPause = NULL;
785 XImage *p_btnStop = NULL;
786 XImage *p_timeline = NULL;
787 XImage *p_btnTime = NULL;
788 XImage *p_btnFullscreen = NULL;
789 XImage *p_btnMute = NULL;
790 XImage *p_btnUnmute = NULL;
792 libvlc_media_instance_t *p_md = NULL;
793 float f_position = 0;
797 Window video = p_plugin->getVideoWindow();
798 Window control = p_plugin->getControlWindow();
799 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
802 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
803 &p_btnPlay, NULL, NULL);
804 p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
806 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
807 &p_btnPause, NULL, NULL);
808 p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
809 p_btnPause->height );
810 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
811 &p_btnStop, NULL, NULL );
812 p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
814 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
815 &p_timeline, NULL, NULL);
816 p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
817 p_timeline->height );
818 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
819 &p_btnTime, NULL, NULL);
820 p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
822 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
823 &p_btnFullscreen, NULL, NULL);
824 p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
825 p_btnFullscreen->height);
826 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
827 &p_btnMute, NULL, NULL);
828 p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
830 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
831 &p_btnUnmute, NULL, NULL);
832 p_plugin->i_control_height = __MAX( p_plugin->i_control_height,
833 p_btnUnmute->height);
835 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
836 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
837 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
839 gcv.foreground = BlackPixel( p_display, 0 );
840 gc = XCreateGC( p_display, video, GCForeground, &gcv );
842 XFillRectangle( p_display, video, gc,
843 0, 0, window.width, window.height - p_plugin->i_control_height );
845 gcv.foreground = WhitePixel( p_display, 0 );
846 XChangeGC( p_display, gc, GCForeground, &gcv );
848 XDrawString( p_display, video, gc,
849 window.width / 2 - 40, (window.height - p_plugin->i_control_height) / 2,
850 WINDOW_TEXT, strlen(WINDOW_TEXT) );
853 gcv.foreground = BlackPixel( p_display, 0 );
854 gc = XCreateGC( p_display, control, GCForeground, &gcv );
856 XFillRectangle( p_display, control, gc,
857 0, 0, window.width, p_plugin->i_control_height );
860 gcv.foreground = WhitePixel( p_display, 0 );
861 XChangeGC( p_display, gc, GCForeground, &gcv );
863 /* get media instance */
864 libvlc_exception_t ex;
865 libvlc_exception_init( &ex );
866 p_md = libvlc_playlist_get_media_instance( p_plugin->getVLC(), &ex );
867 libvlc_exception_clear( &ex );
870 libvlc_exception_init( &ex );
871 i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
872 libvlc_exception_clear( &ex );
875 libvlc_exception_init(&ex);
876 b_mute = libvlc_audio_get_mute( p_plugin->getVLC(), &ex );
877 libvlc_exception_clear( &ex );
879 /* get movie position in % */
882 libvlc_exception_init( &ex );
883 f_position = libvlc_media_instance_get_position(p_md, &ex)*100;
884 libvlc_exception_clear( &ex );
886 libvlc_media_instance_release(p_md);
889 if( p_btnPause && (i_playing == 1) )
891 XPutImage( p_display, control, gc, p_btnPause, 0, 0, 4, 14,
892 p_btnPause->width, p_btnPause->height );
896 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, 4, 14,
897 p_btnPlay->width, p_btnPlay->height );
901 XPutImage( p_display, control, gc, p_btnStop, 0, 0, 39, 14,
902 p_btnStop->width, p_btnStop->height );
903 if( p_btnFullscreen )
904 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, 67, 21,
905 p_btnFullscreen->width, p_btnFullscreen->height );
907 if( p_btnUnmute && b_mute )
909 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, 94, 30,
910 p_btnUnmute->width, p_btnUnmute->height );
914 XPutImage( p_display, control, gc, p_btnMute, 0, 0, 94, 30,
915 p_btnMute->width, p_btnMute->height );
919 XPutImage( p_display, control, gc, p_timeline, 0, 0, 4, 4,
920 (window.width-8), p_timeline->height );
921 if( p_btnTime && (f_position > 0) )
923 f_position = (((float)window.width-8)/100)*f_position;
924 XPutImage( p_display, control, gc, p_btnTime, 0, 0, (4+f_position), 2,
925 p_btnTime->width, p_btnTime->height );
929 if( p_btnPlay ) XDestroyImage( p_btnPlay );
930 if( p_btnPause ) XDestroyImage( p_btnPause );
931 if( p_btnStop ) XDestroyImage( p_btnStop );
932 if( p_timeline ) XDestroyImage( p_timeline );
933 if( p_btnTime ) XDestroyImage( p_btnTime );
934 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
935 if( p_btnMute ) XDestroyImage( p_btnMute );
936 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
938 XFreeGC( p_display, gc );
941 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
943 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
944 const NPWindow& window = p_plugin->getWindow();
946 int i_height = window.height;
947 int i_width = window.width;
948 int i_xPos = event->xbutton.x;
949 int i_yPos = event->xbutton.y;
953 libvlc_exception_t ex;
954 libvlc_exception_init( &ex );
955 libvlc_media_instance_t *p_md =
956 libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);
957 libvlc_exception_clear( &ex );
959 /* jump in the movie */
960 if( i_yPos <= (i_height-30) )
962 vlc_int64_t f_length;
963 libvlc_exception_init( &ex );
964 f_length = libvlc_media_instance_get_length( p_md, &ex ) / 100;
965 libvlc_exception_clear( &ex );
967 f_length = (float)f_length *
968 ( ((float)i_xPos-4 ) / ( ((float)i_width-8)/100) );
970 libvlc_exception_init( &ex );
971 libvlc_media_instance_set_time( p_md, f_length, &ex );
972 libvlc_exception_clear( &ex );
975 /* play/pause toggle */
976 if( (i_yPos > (i_height-30)) && (i_xPos > 4) && (i_xPos <= 39) )
979 libvlc_exception_init( &ex );
980 i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
981 libvlc_exception_clear( &ex );
983 libvlc_exception_init( &ex );
985 libvlc_playlist_pause( p_plugin->getVLC(), &ex );
987 libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
988 libvlc_exception_clear( &ex );
992 if( (i_yPos > (i_height-30)) && (i_xPos > 39) && (i_xPos < 67) )
994 libvlc_exception_init( &ex );
995 libvlc_playlist_stop( p_plugin->getVLC(), &ex );
996 libvlc_exception_clear( &ex );
1000 if( (i_yPos > (i_height-30)) && (i_xPos >= 67) && (i_xPos < 94) )
1003 libvlc_exception_init( &ex );
1004 i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
1005 libvlc_exception_clear( &ex );
1007 if( i_playing == 1 )
1009 libvlc_exception_init( &ex );
1010 libvlc_set_fullscreen( p_md, 1, &ex );
1011 libvlc_exception_clear( &ex );
1016 if( (i_yPos > (i_height-30)) && (i_xPos >= 94) && (i_xPos < 109))
1018 libvlc_exception_init( &ex );
1019 libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
1020 libvlc_exception_clear( &ex );
1022 libvlc_media_instance_release( p_md );
1024 Redraw( w, closure, event );
1027 static void Resize ( Widget w, XtPointer closure, XEvent *event )
1029 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
1030 const NPWindow& window = p_plugin->getWindow();
1031 Window drawable = p_plugin->getVideoWindow();
1032 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
1035 Window root_return, parent_return, * children_return;
1037 unsigned int i_nchildren;
1039 #ifdef X11_RESIZE_DEBUG
1040 XWindowAttributes attr;
1042 if( event && event->type == ConfigureNotify )
1044 fprintf( stderr, "vlcshell::Resize() ConfigureNotify %d x %d, "
1045 "send_event ? %s\n", event->xconfigure.width,
1046 event->xconfigure.height,
1047 event->xconfigure.send_event ? "TRUE" : "FALSE" );
1049 #endif /* X11_RESIZE_DEBUG */
1051 if( ! p_plugin->setSize(window.width, (window.height - p_plugin->i_control_height)) )
1053 /* size already set */
1057 i_ret = XResizeWindow( p_display, drawable, window.width, (window.height - p_plugin->i_control_height) );
1059 #ifdef X11_RESIZE_DEBUG
1061 "vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret );
1063 XGetWindowAttributes ( p_display, drawable, &attr );
1065 /* X is asynchronous, so the current size reported here is not
1066 necessarily the requested size as the Resize request may not
1067 yet have been handled by the plugin host */
1068 fprintf( stderr, "vlcshell::Resize() current (owner) size %d x %d\n",
1069 attr.width, attr.height );
1070 #endif /* X11_RESIZE_DEBUG */
1072 XQueryTree( p_display, drawable,
1073 &root_return, &parent_return, &children_return,
1076 if( i_nchildren > 0 )
1078 /* XXX: Make assumptions related to the window parenting structure in
1079 vlc/modules/video_output/x11/xcommon.c */
1080 base_window = children_return[i_nchildren - 1];
1082 #ifdef X11_RESIZE_DEBUG
1083 fprintf( stderr, "vlcshell::Resize() got %d children\n", i_nchildren );
1084 fprintf( stderr, "vlcshell::Resize() got base_window %p\n",
1086 #endif /* X11_RESIZE_DEBUG */
1088 i_ret = XResizeWindow( p_display, base_window,
1089 window.width, ( window.height - p_plugin->i_control_height ) );
1091 #ifdef X11_RESIZE_DEBUG
1093 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
1096 XGetWindowAttributes( p_display, base_window, &attr );
1098 fprintf( stderr, "vlcshell::Resize() new size %d x %d\n",
1099 attr.width, attr.height );
1100 #endif /* X11_RESIZE_DEBUG */
1104 #endif /* XP_UNIX */