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..."
55 #define CONTROL_HEIGHT 45
57 /*****************************************************************************
58 * Unix-only declarations
59 ******************************************************************************/
62 static void Redraw( Widget w
, XtPointer closure
, XEvent
*event
);
63 static void ControlHandler( Widget w
, XtPointer closure
, XEvent
*event
);
64 static void Resize( Widget w
, XtPointer closure
, XEvent
*event
);
68 /*****************************************************************************
69 * MacOS-only declarations
70 ******************************************************************************/
74 /*****************************************************************************
75 * Windows-only declarations
76 *****************************************************************************/
79 static LRESULT CALLBACK
Manage( HWND p_hwnd
, UINT i_msg
, WPARAM wpar
, LPARAM lpar
);
83 /******************************************************************************
85 *****************************************************************************/
86 char * NPP_GetMIMEDescription( void )
88 return PLUGIN_MIMETYPES
;
91 NPError
NPP_GetValue( NPP instance
, NPPVariable variable
, void *value
)
94 static char psz_desc
[1000];
96 /* plugin class variables */
99 case NPPVpluginNameString
:
100 *((char **)value
) = PLUGIN_NAME
;
101 return NPERR_NO_ERROR
;
103 case NPPVpluginDescriptionString
:
104 snprintf( psz_desc
, sizeof(psz_desc
), PLUGIN_DESCRIPTION
, VLC_Version() );
105 *((char **)value
) = psz_desc
;
106 return NPERR_NO_ERROR
;
109 /* move on to instance variables ... */
113 if( instance
== NULL
)
115 return NPERR_INVALID_INSTANCE_ERROR
;
118 /* plugin instance variables */
120 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
121 if( NULL
== p_plugin
)
123 // plugin has not been initialized yet !
124 return NPERR_INVALID_INSTANCE_ERROR
;
129 case NPPVpluginScriptableNPObject
:
131 /* retrieve plugin root class */
132 NPClass
*scriptClass
= p_plugin
->getScriptClass();
135 /* create an instance and return it */
136 *(NPObject
**)value
= NPN_CreateObject(instance
, scriptClass
);
137 return NPERR_NO_ERROR
;
145 return NPERR_GENERIC_ERROR
;
149 * there is some confusion in gecko headers regarding definition of this API
150 * NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
153 NPError
NPP_SetValue( NPP instance
, NPNVariable variable
, void *value
)
155 return NPERR_GENERIC_ERROR
;
158 /******************************************************************************
160 *****************************************************************************/
162 int16
NPP_HandleEvent( NPP instance
, void * event
)
164 static UInt32 lastMouseUp
= 0;
166 if( instance
== NULL
)
171 VlcPlugin
*p_plugin
= (VlcPlugin
*)instance
->pdata
;
173 if( p_plugin
== NULL
)
178 EventRecord
*myEvent
= (EventRecord
*)event
;
180 switch( myEvent
->what
)
186 if( (myEvent
->when
- lastMouseUp
) < GetDblTime() )
189 libvlc_instance_t
*p_vlc
= p_plugin
->getVLC();
193 if( libvlc_playlist_isplaying(p_vlc
, NULL
) )
195 libvlc_media_instance_t
*p_md
=
196 libvlc_playlist_get_media_instance(p_vlc
, NULL
);
199 libvlc_toggle_fullscreen(p_md
, NULL
);
200 libvlc_media_instance_release(p_md
);
208 lastMouseUp
= myEvent
->when
;
216 const NPWindow
& npwindow
= p_plugin
->getWindow();
217 if( npwindow
.window
)
220 libvlc_instance_t
*p_vlc
= p_plugin
->getVLC();
224 if( libvlc_playlist_isplaying(p_vlc
, NULL
) )
226 libvlc_media_instance_t
*p_md
=
227 libvlc_playlist_get_media_instance(p_vlc
, NULL
);
230 hasVout
= libvlc_media_instance_has_vout(p_md
, NULL
);
233 libvlc_rectangle_t area
;
236 area
.right
= npwindow
.width
;
237 area
.bottom
= npwindow
.height
;
238 libvlc_video_redraw_rectangle(p_md
, &area
, NULL
);
240 libvlc_media_instance_release(p_md
);
247 /* draw the beautiful "No Picture" */
249 ForeColor(blackColor
);
252 /* seems that firefox forgets to set the following on occasion (reload) */
253 SetOrigin(((NP_Port
*)npwindow
.window
)->portx
,
254 ((NP_Port
*)npwindow
.window
)->porty
);
259 rect
.right
= npwindow
.width
;
260 rect
.bottom
= npwindow
.height
;
263 ForeColor(whiteColor
);
264 MoveTo( (npwindow
.width
-80)/ 2 , npwindow
.height
/ 2 );
265 DrawText( WINDOW_TEXT
, 0 , strlen(WINDOW_TEXT
) );
272 case NPEventType_GetFocusEvent
:
273 case NPEventType_LoseFocusEvent
:
275 case NPEventType_AdjustCursorEvent
:
277 case NPEventType_MenuCommandEvent
:
279 case NPEventType_ClippingChangedEvent
:
281 case NPEventType_ScrollingBeginsEvent
:
283 case NPEventType_ScrollingEndsEvent
:
290 #endif /* XP_MACOSX */
292 /******************************************************************************
293 * General Plug-in Calls
294 *****************************************************************************/
295 NPError
NPP_Initialize( void )
297 return NPERR_NO_ERROR
;
300 jref
NPP_GetJavaClass( void )
305 void NPP_Shutdown( void )
310 NPError
NPP_New( NPMIMEType pluginType
, NPP instance
, uint16 mode
, int16 argc
,
311 char* argn
[], char* argv
[], NPSavedData
* saved
)
315 if( instance
== NULL
)
317 return NPERR_INVALID_INSTANCE_ERROR
;
320 VlcPlugin
* p_plugin
= new VlcPlugin( instance
, mode
);
321 if( NULL
== p_plugin
)
323 return NPERR_OUT_OF_MEMORY_ERROR
;
326 status
= p_plugin
->init(argc
, argn
, argv
);
327 if( NPERR_NO_ERROR
== status
)
329 instance
->pdata
= reinterpret_cast<void*>(p_plugin
);
331 NPN_SetValue(instance
, NPPVpluginWindowBool
, (void *)false);
332 NPN_SetValue(instance
, NPPVpluginTransparentBool
, (void *)false);
342 NPError
NPP_Destroy( NPP instance
, NPSavedData
** save
)
344 if( NULL
== instance
)
345 return NPERR_INVALID_INSTANCE_ERROR
;
347 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
348 if( NULL
== p_plugin
)
349 return NPERR_NO_ERROR
;
351 instance
->pdata
= NULL
;
354 HWND win
= (HWND
)p_plugin
->getWindow().window
;
355 WNDPROC winproc
= p_plugin
->getWindowProc();
359 SetWindowLong( win
, GWL_WNDPROC
, (LONG
)winproc
);
365 return NPERR_NO_ERROR
;
368 NPError
NPP_SetWindow( NPP instance
, NPWindow
* window
)
372 return NPERR_INVALID_INSTANCE_ERROR
;
375 /* NPP_SetWindow may be called before NPP_New (Opera) */
376 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
379 /* we should probably show a splash screen here */
380 return NPERR_NO_ERROR
;
383 libvlc_instance_t
*p_vlc
= p_plugin
->getVLC();
387 * Before setting window to point to the
388 * new window, you may wish to compare the new window
389 * info to the previous window (if any) to note window
393 /* retrieve current window */
394 NPWindow
& curwin
= p_plugin
->getWindow();
397 if( window
&& window
->window
)
399 /* check if plugin has a new parent window */
400 CGrafPtr drawable
= (((NP_Port
*) (window
->window
))->port
);
401 if( !curwin
.window
|| drawable
!= (((NP_Port
*) (curwin
.window
))->port
) )
403 /* set/change parent window */
404 libvlc_video_set_parent(p_vlc
, (libvlc_drawable_t
)drawable
, NULL
);
407 /* as MacOS X video output is windowless, set viewport */
408 libvlc_rectangle_t view
, clip
;
411 ** browser sets port origin to top-left location of plugin relative to GrafPort
412 ** window origin is set relative to document, which of little use for drawing
414 view
.top
= ((NP_Port
*) (window
->window
))->porty
;
415 view
.left
= ((NP_Port
*) (window
->window
))->portx
;
416 view
.bottom
= window
->height
+view
.top
;
417 view
.right
= window
->width
+view
.left
;
418 /* clipRect coordinates are also relative to GrafPort */
419 clip
.top
= window
->clipRect
.top
;
420 clip
.left
= window
->clipRect
.left
;
421 clip
.bottom
= window
->clipRect
.bottom
;
422 clip
.right
= window
->clipRect
.right
;
424 libvlc_video_set_viewport(p_vlc
, &view
, &clip
, NULL
);
426 /* remember new window */
427 p_plugin
->setWindow(*window
);
429 else if( curwin
.window
) {
430 /* change/set parent */
431 libvlc_video_set_parent(p_vlc
, 0, NULL
);
432 curwin
.window
= NULL
;
434 #endif /* XP_MACOSX */
437 if( window
&& window
->window
)
439 /* check if plugin has a new parent window */
440 HWND drawable
= (HWND
) (window
->window
);
441 if( !curwin
.window
|| drawable
!= curwin
.window
)
443 /* reset previous window settings */
444 HWND oldwin
= (HWND
)p_plugin
->getWindow().window
;
445 WNDPROC oldproc
= p_plugin
->getWindowProc();
449 SetWindowLong( oldwin
, GWL_WNDPROC
, (LONG
)oldproc
);
451 /* attach our plugin object */
452 SetWindowLongPtr((HWND
)drawable
, GWLP_USERDATA
,
453 reinterpret_cast<LONG_PTR
>(p_plugin
));
455 /* install our WNDPROC */
456 p_plugin
->setWindowProc( (WNDPROC
)SetWindowLong( drawable
,
457 GWL_WNDPROC
, (LONG
)Manage
) );
459 /* change window style to our liking */
460 LONG style
= GetWindowLong((HWND
)drawable
, GWL_STYLE
);
461 style
|= WS_CLIPCHILDREN
|WS_CLIPSIBLINGS
;
462 SetWindowLong((HWND
)drawable
, GWL_STYLE
, style
);
464 /* change/set parent */
465 libvlc_video_set_parent(p_vlc
, (libvlc_drawable_t
)drawable
, NULL
);
467 /* remember new window */
468 p_plugin
->setWindow(*window
);
471 InvalidateRect( (HWND
)drawable
, NULL
, TRUE
);
472 UpdateWindow( (HWND
)drawable
);
475 else if ( curwin
.window
)
478 HWND oldwin
= (HWND
)curwin
.window
;
479 SetWindowLong( oldwin
, GWL_WNDPROC
, (LONG
)(p_plugin
->getWindowProc()) );
480 p_plugin
->setWindowProc(NULL
);
481 /* change/set parent */
482 libvlc_video_set_parent(p_vlc
, 0, NULL
);
483 curwin
.window
= NULL
;
488 if( window
&& window
->window
)
490 Window parent
= (Window
) window
->window
;
491 if( !curwin
.window
|| (parent
!= (Window
)curwin
.window
) )
493 Display
*p_display
= ((NPSetWindowCallbackStruct
*)window
->ws_info
)->display
;
495 XResizeWindow( p_display
, parent
, window
->width
, window
->height
);
497 int i_blackColor
= BlackPixel(p_display
, DefaultScreen(p_display
));
499 Window video
= XCreateSimpleWindow( p_display
, parent
, 0, 0,
500 window
->width
, window
->height
- CONTROL_HEIGHT
, 0,
501 i_blackColor
, i_blackColor
);
502 Window controls
= XCreateSimpleWindow( p_display
, parent
, 0,
503 window
->height
- CONTROL_HEIGHT
-1, window
->width
,
504 CONTROL_HEIGHT
-1, 0, i_blackColor
, i_blackColor
);
506 XMapWindow( p_display
, parent
);
507 XMapWindow( p_display
, video
);
508 XMapWindow( p_display
, controls
);
512 Widget w
= XtWindowToWidget( p_display
, parent
);
514 XtAddEventHandler( w
, ExposureMask
, FALSE
,
515 (XtEventHandler
)Redraw
, p_plugin
);
516 XtAddEventHandler( w
, StructureNotifyMask
, FALSE
,
517 (XtEventHandler
)Resize
, p_plugin
);
518 XtAddEventHandler( w
, ButtonReleaseMask
, FALSE
,
519 (XtEventHandler
)ControlHandler
, p_plugin
);
523 libvlc_media_instance_t *p_md;
525 libvlc_exception_t ex;
526 libvlc_exception_init(& ex );
527 p_md = libvlc_playlist_get_media_instance( p_plugin->getVLC(), &ex );
528 libvlc_exception_init( &ex );
529 libvlc_event_attach( libvlc_media_instance_event_manager( p_md, &ex ),
530 libvlc_MediaInstancePositionChanged, Redraw, NULL, &ex );
533 /* set/change parent window */
534 libvlc_video_set_parent( p_vlc
, (libvlc_drawable_t
) video
, NULL
);
536 /* remember window */
537 p_plugin
->setWindow( *window
);
538 p_plugin
->setVideoWindow( video
);
539 p_plugin
->setControlWindow( controls
);
541 Redraw( w
, (XtPointer
)p_plugin
, NULL
);
544 else if ( curwin
.window
)
546 /* change/set parent */
547 libvlc_video_set_parent(p_vlc
, 0, NULL
);
548 curwin
.window
= NULL
;
552 if( !p_plugin
->b_stream
)
554 if( p_plugin
->psz_target
)
556 if( libvlc_playlist_add( p_vlc
, p_plugin
->psz_target
,
559 if( p_plugin
->b_autoplay
)
561 libvlc_playlist_play(p_vlc
, 0, 0, NULL
, NULL
);
564 p_plugin
->b_stream
= VLC_TRUE
;
567 return NPERR_NO_ERROR
;
570 NPError
NPP_NewStream( NPP instance
, NPMIMEType type
, NPStream
*stream
,
571 NPBool seekable
, uint16
*stype
)
573 if( NULL
== instance
)
575 return NPERR_INVALID_INSTANCE_ERROR
;
578 VlcPlugin
*p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
579 if( NULL
== p_plugin
)
581 return NPERR_INVALID_INSTANCE_ERROR
;
585 ** Firefox/Mozilla may decide to open a stream from the URL specified
586 ** in the SRC parameter of the EMBED tag and pass it to us
588 ** since VLC will open the SRC URL as well, we're not interested in
589 ** that stream. Otherwise, we'll take it and queue it up in the playlist
591 if( !p_plugin
->psz_target
|| strcmp(stream
->url
, p_plugin
->psz_target
) )
593 /* TODO: use pipes !!!! */
594 *stype
= NP_ASFILEONLY
;
595 return NPERR_NO_ERROR
;
597 return NPERR_GENERIC_ERROR
;
600 int32
NPP_WriteReady( NPP instance
, NPStream
*stream
)
607 int32
NPP_Write( NPP instance
, NPStream
*stream
, int32 offset
,
608 int32 len
, void *buffer
)
615 NPError
NPP_DestroyStream( NPP instance
, NPStream
*stream
, NPError reason
)
617 if( instance
== NULL
)
619 return NPERR_INVALID_INSTANCE_ERROR
;
621 return NPERR_NO_ERROR
;
625 void NPP_StreamAsFile( NPP instance
, NPStream
*stream
, const char* fname
)
627 if( instance
== NULL
)
632 VlcPlugin
*p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
633 if( NULL
== p_plugin
)
638 if( libvlc_playlist_add( p_plugin
->getVLC(), fname
, stream
->url
, NULL
) != -1 )
640 if( p_plugin
->b_autoplay
)
642 libvlc_playlist_play( p_plugin
->getVLC(), 0, 0, NULL
, NULL
);
648 void NPP_URLNotify( NPP instance
, const char* url
,
649 NPReason reason
, void* notifyData
)
651 /***** Insert NPP_URLNotify code here *****\
652 PluginInstance* p_plugin;
653 if (instance != NULL)
654 p_plugin = (PluginInstance*) instance->pdata;
655 \*********************************************/
659 void NPP_Print( NPP instance
, NPPrint
* printInfo
)
661 if( printInfo
== NULL
)
666 if( instance
!= NULL
)
668 /***** Insert NPP_Print code here *****\
669 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
670 \**************************************/
672 if( printInfo
->mode
== NP_FULL
)
676 * If your plugin would like to take over
677 * printing completely when it is in full-screen mode,
678 * set printInfo->pluginPrinted to TRUE and print your
679 * plugin as you see fit. If your plugin wants Netscape
680 * to handle printing in this case, set
681 * printInfo->pluginPrinted to FALSE (the default) and
682 * do nothing. If you do want to handle printing
683 * yourself, printOne is true if the print button
684 * (as opposed to the print menu) was clicked.
685 * On the Macintosh, platformPrint is a THPrint; on
686 * Windows, platformPrint is a structure
687 * (defined in npapi.h) containing the printer name, port,
691 /***** Insert NPP_Print code here *****\
692 void* platformPrint =
693 printInfo->print.fullPrint.platformPrint;
695 printInfo->print.fullPrint.printOne;
696 \**************************************/
699 printInfo
->print
.fullPrint
.pluginPrinted
= FALSE
;
703 /* If not fullscreen, we must be embedded */
706 * If your plugin is embedded, or is full-screen
707 * but you returned false in pluginPrinted above, NPP_Print
708 * will be called with mode == NP_EMBED. The NPWindow
709 * in the printInfo gives the location and dimensions of
710 * the embedded plugin on the printed page. On the
711 * Macintosh, platformPrint is the printer port; on
712 * Windows, platformPrint is the handle to the printing
716 /***** Insert NPP_Print code here *****\
717 NPWindow* printWindow =
718 &(printInfo->print.embedPrint.window);
719 void* platformPrint =
720 printInfo->print.embedPrint.platformPrint;
721 \**************************************/
726 /******************************************************************************
727 * Windows-only methods
728 *****************************************************************************/
730 static LRESULT CALLBACK
Manage( HWND p_hwnd
, UINT i_msg
, WPARAM wpar
, LPARAM lpar
)
732 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(GetWindowLongPtr(p_hwnd
, GWLP_USERDATA
));
741 PAINTSTRUCT paintstruct
;
745 hdc
= BeginPaint( p_hwnd
, &paintstruct
);
747 GetClientRect( p_hwnd
, &rect
);
749 FillRect( hdc
, &rect
, (HBRUSH
)GetStockObject(BLACK_BRUSH
) );
750 SetTextColor(hdc
, RGB(255, 255, 255));
751 SetBkColor(hdc
, RGB(0, 0, 0));
752 DrawText( hdc
, WINDOW_TEXT
, strlen(WINDOW_TEXT
), &rect
,
753 DT_CENTER
|DT_VCENTER
|DT_SINGLELINE
);
755 EndPaint( p_hwnd
, &paintstruct
);
759 /* delegate to default handler */
760 return CallWindowProc(p_plugin
->getWindowProc(), p_hwnd
, i_msg
, wpar
, lpar
);
765 /******************************************************************************
767 *****************************************************************************/
769 static void Redraw( Widget w
, XtPointer closure
, XEvent
*event
)
771 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(closure
);
772 const NPWindow
& window
= p_plugin
->getWindow();
777 XImage
*p_playIcon
= NULL
;
778 XImage
*p_pauseIcon
= NULL
;
779 XImage
*p_stopIcon
= NULL
;
780 XImage
*p_timeline
= NULL
;
781 XImage
*p_timeKnob
= NULL
;
782 XImage
*p_fscreen
= NULL
;
783 XImage
*p_muteIcon
= NULL
;
784 XImage
*p_unmuteIcon
= NULL
;
786 libvlc_media_instance_t
*p_md
= NULL
;
787 float f_position
= 0;
791 Window video
= p_plugin
->getVideoWindow();
792 Window control
= p_plugin
->getControlWindow();
793 Display
*p_display
= ((NPSetWindowCallbackStruct
*)window
.ws_info
)->display
;
795 gcv
.foreground
= BlackPixel( p_display
, 0 );
796 gc
= XCreateGC( p_display
, video
, GCForeground
, &gcv
);
798 XFillRectangle( p_display
, video
, gc
,
799 0, 0, window
.width
, window
.height
- CONTROL_HEIGHT
);
801 gcv
.foreground
= WhitePixel( p_display
, 0 );
802 XChangeGC( p_display
, gc
, GCForeground
, &gcv
);
804 XDrawString( p_display
, video
, gc
,
805 window
.width
/ 2 - 40, (window
.height
- CONTROL_HEIGHT
) / 2,
806 WINDOW_TEXT
, strlen(WINDOW_TEXT
) );
809 gcv
.foreground
= BlackPixel( p_display
, 0 );
810 gc
= XCreateGC( p_display
, control
, GCForeground
, &gcv
);
812 XFillRectangle( p_display
, control
, gc
,
813 0, 0, window
.width
, CONTROL_HEIGHT
);
816 gcv
.foreground
= WhitePixel( p_display
, 0 );
817 XChangeGC( p_display
, gc
, GCForeground
, &gcv
);
819 /* get media instance */
820 libvlc_exception_t ex
;
821 libvlc_exception_init( &ex
);
822 p_md
= libvlc_playlist_get_media_instance( p_plugin
->getVLC(), &ex
);
823 libvlc_exception_clear( &ex
);
826 libvlc_exception_init( &ex
);
827 i_playing
= libvlc_playlist_isplaying( p_plugin
->getVLC(), &ex
);
828 libvlc_exception_clear( &ex
);
831 libvlc_exception_init(&ex
);
832 b_mute
= libvlc_audio_get_mute( p_plugin
->getVLC(), &ex
);
833 libvlc_exception_clear( &ex
);
835 /* get movie position in % */
838 libvlc_exception_init( &ex
);
839 f_position
= libvlc_media_instance_get_position(p_md
, &ex
)*100;
840 libvlc_exception_clear( &ex
);
842 libvlc_media_instance_release(p_md
);
845 XpmReadFileToImage( p_display
, DATA_PATH
"/mozilla/play.xpm",
846 &p_playIcon
, NULL
, NULL
);
847 XpmReadFileToImage( p_display
, DATA_PATH
"/mozilla/pause.xpm",
848 &p_pauseIcon
, NULL
, NULL
);
849 XpmReadFileToImage( p_display
, DATA_PATH
"/mozilla/stop.xpm",
850 &p_stopIcon
, NULL
, NULL
);
851 XpmReadFileToImage( p_display
, DATA_PATH
"/mozilla/time_line.xpm",
852 &p_timeline
, NULL
, NULL
);
853 XpmReadFileToImage( p_display
, DATA_PATH
"/mozilla/time_icon.xpm",
854 &p_timeKnob
, NULL
, NULL
);
855 XpmReadFileToImage( p_display
, DATA_PATH
"/mozilla/fullscreen.xpm",
856 &p_fscreen
, NULL
, NULL
);
857 XpmReadFileToImage( p_display
, DATA_PATH
"/mozilla/volume_max.xpm",
858 &p_muteIcon
, NULL
, NULL
);
859 XpmReadFileToImage( p_display
, DATA_PATH
"/mozilla/volume_mute.xpm",
860 &p_unmuteIcon
, NULL
, NULL
);
865 fprintf(stderr
, "Error: playImage not found\n");
869 fprintf(stderr
, "Error: pauseImage not found\n");
873 fprintf(stderr
, "Error: stopImage not found\n");
877 fprintf(stderr
, "Error: TimeLineImage not found\n");
881 fprintf(stderr
, "Error: TimeIcon not found\n");
885 fprintf(stderr
, "Error: FullscreenImage not found\n");
889 fprintf(stderr
, "Error: MuteImage not found\n");
893 fprintf(stderr
, "Error: UnMuteImage not found\n");
898 if( p_pauseIcon
&& (i_playing
== 1) )
900 XPutImage( p_display
, control
, gc
, p_pauseIcon
, 0, 0, 4, 14,
901 p_pauseIcon
->width
, p_pauseIcon
->height
);
903 else if( p_playIcon
)
905 XPutImage( p_display
, control
, gc
, p_playIcon
, 0, 0, 4, 14,
906 p_playIcon
->width
, p_playIcon
->height
);
910 XPutImage( p_display
, control
, gc
, p_stopIcon
, 0, 0, 39, 14,
911 p_stopIcon
->width
, p_stopIcon
->height
);
913 XPutImage( p_display
, control
, gc
, p_fscreen
, 0, 0, 67, 21,
914 p_fscreen
->width
, p_fscreen
->height
);
916 if( p_unmuteIcon
&& b_mute
)
918 XPutImage( p_display
, control
, gc
, p_unmuteIcon
, 0, 0, 94, 30,
919 p_unmuteIcon
->width
, p_unmuteIcon
->height
);
921 else if( p_muteIcon
)
923 XPutImage( p_display
, control
, gc
, p_muteIcon
, 0, 0, 94, 30,
924 p_muteIcon
->width
, p_muteIcon
->height
);
928 XPutImage( p_display
, control
, gc
, p_timeline
, 0, 0, 4, 4,
929 (window
.width
-8), p_timeline
->height
);
930 if( p_timeKnob
&& (f_position
> 0) )
932 f_position
= (((float)window
.width
-8)/100)*f_position
;
933 XPutImage( p_display
, control
, gc
, p_timeKnob
, 0, 0, (4+f_position
), 2,
934 p_timeKnob
->width
, p_timeKnob
->height
);
938 if( p_playIcon
) XDestroyImage( p_playIcon
);
939 if( p_pauseIcon
) XDestroyImage( p_pauseIcon
);
940 if( p_stopIcon
) XDestroyImage( p_stopIcon
);
941 if( p_timeline
) XDestroyImage( p_timeline
);
942 if( p_timeKnob
) XDestroyImage( p_timeKnob
);
943 if( p_fscreen
) XDestroyImage( p_fscreen
);
944 if( p_muteIcon
) XDestroyImage( p_muteIcon
);
945 if( p_unmuteIcon
) XDestroyImage( p_unmuteIcon
);
947 XFreeGC( p_display
, gc
);
950 static void ControlHandler( Widget w
, XtPointer closure
, XEvent
*event
)
952 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(closure
);
953 const NPWindow
& window
= p_plugin
->getWindow();
955 int i_height
= window
.height
;
956 int i_width
= window
.width
;
957 int i_xPos
= event
->xbutton
.x
;
958 int i_yPos
= event
->xbutton
.y
;
960 libvlc_exception_t ex
;
961 libvlc_exception_init( &ex
);
962 libvlc_media_instance_t
*p_md
=
963 libvlc_playlist_get_media_instance(p_plugin
->getVLC(), &ex
);
964 libvlc_exception_clear( &ex
);
966 /* jump in the movie */
967 if( i_yPos
<= (i_height
-30) )
969 vlc_int64_t f_length
;
970 libvlc_exception_init( &ex
);
971 f_length
= libvlc_media_instance_get_length( p_md
, &ex
) / 100;
972 libvlc_exception_clear( &ex
);
974 f_length
= (float)f_length
*
975 ( ((float)i_xPos
-4 ) / ( ((float)i_width
-8)/100) );
977 libvlc_exception_init( &ex
);
978 libvlc_media_instance_set_time( p_md
, f_length
, &ex
);
979 libvlc_exception_clear( &ex
);
982 /* play/pause toggle */
983 if( (i_yPos
> (i_height
-30)) && (i_xPos
> 4) && (i_xPos
<= 39) )
986 libvlc_exception_init( &ex
);
987 i_playing
= libvlc_playlist_isplaying( p_plugin
->getVLC(), &ex
);
988 libvlc_exception_clear( &ex
);
990 libvlc_exception_init( &ex
);
992 libvlc_playlist_pause( p_plugin
->getVLC(), &ex
);
994 libvlc_playlist_play( p_plugin
->getVLC(), -1, 0, NULL
, &ex
);
995 libvlc_exception_clear( &ex
);
999 if( (i_yPos
> (i_height
-30)) && (i_xPos
> 39) && (i_xPos
< 67) )
1001 libvlc_exception_init( &ex
);
1002 libvlc_playlist_stop( p_plugin
->getVLC(), &ex
);
1003 libvlc_exception_clear( &ex
);
1007 if( (i_yPos
> (i_height
-30)) && (i_xPos
>= 67) && (i_xPos
< 94) )
1009 libvlc_exception_init( &ex
);
1010 libvlc_set_fullscreen( p_md
, 1, &ex
);
1011 libvlc_exception_clear( &ex
);
1015 if( (i_yPos
> (i_height
-30)) && (i_xPos
>= 94) && (i_xPos
< 109))
1017 libvlc_exception_init( &ex
);
1018 libvlc_audio_toggle_mute( p_plugin
->getVLC(), &ex
);
1019 libvlc_exception_clear( &ex
);
1021 libvlc_media_instance_release( p_md
);
1023 Redraw( w
, closure
, event
);
1026 static void Resize ( Widget w
, XtPointer closure
, XEvent
*event
)
1028 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(closure
);
1029 const NPWindow
& window
= p_plugin
->getWindow();
1030 Window drawable
= p_plugin
->getVideoWindow();
1031 Display
*p_display
= ((NPSetWindowCallbackStruct
*)window
.ws_info
)->display
;
1034 Window root_return
, parent_return
, * children_return
;
1036 unsigned int i_nchildren
;
1038 #ifdef X11_RESIZE_DEBUG
1039 XWindowAttributes attr
;
1041 if( event
&& event
->type
== ConfigureNotify
)
1043 fprintf( stderr
, "vlcshell::Resize() ConfigureNotify %d x %d, "
1044 "send_event ? %s\n", event
->xconfigure
.width
,
1045 event
->xconfigure
.height
,
1046 event
->xconfigure
.send_event
? "TRUE" : "FALSE" );
1048 #endif /* X11_RESIZE_DEBUG */
1050 if( ! p_plugin
->setSize(window
.width
, (window
.height
- CONTROL_HEIGHT
)) )
1052 /* size already set */
1057 i_ret
= XResizeWindow( p_display
, drawable
, window
.width
, (window
.height
- 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
- 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 */