1 /*****************************************************************************
2 * vlcshell.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2008 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Jean-Paul Saman <jpsaman@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
35 #ifdef HAVE_MOZILLA_CONFIG_H
36 # include <mozilla-config.h>
39 /* This is from mozilla java, do we really need it? */
44 #include "vlcplugin.h"
46 /* Enable/disable debugging printf's for X11 resizing */
47 #undef X11_RESIZE_DEBUG
49 #define WINDOW_TEXT "Video is loading..."
51 /*****************************************************************************
52 * Unix-only declarations
53 ******************************************************************************/
56 static void Redraw( Widget w
, XtPointer closure
, XEvent
*event
);
57 static void ControlHandler( Widget w
, XtPointer closure
, XEvent
*event
);
58 static void Resize( Widget w
, XtPointer closure
, XEvent
*event
);
62 /*****************************************************************************
63 * MacOS-only declarations
64 ******************************************************************************/
68 /*****************************************************************************
69 * Windows-only declarations
70 *****************************************************************************/
73 static LRESULT CALLBACK
Manage( HWND p_hwnd
, UINT i_msg
, WPARAM wpar
, LPARAM lpar
);
77 /******************************************************************************
79 *****************************************************************************/
80 char * NPP_GetMIMEDescription( void )
82 return PLUGIN_MIMETYPES
;
85 NPError
NPP_GetValue( NPP instance
, NPPVariable variable
, void *value
)
88 static char psz_desc
[1000];
90 /* plugin class variables */
93 case NPPVpluginNameString
:
94 *((char **)value
) = PLUGIN_NAME
;
95 return NPERR_NO_ERROR
;
97 case NPPVpluginDescriptionString
:
98 snprintf( psz_desc
, sizeof(psz_desc
), PLUGIN_DESCRIPTION
,
99 libvlc_get_version() );
100 *((char **)value
) = psz_desc
;
101 return NPERR_NO_ERROR
;
104 /* move on to instance variables ... */
108 if( instance
== NULL
)
110 return NPERR_INVALID_INSTANCE_ERROR
;
113 /* plugin instance variables */
115 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
116 if( NULL
== p_plugin
)
118 // plugin has not been initialized yet !
119 return NPERR_INVALID_INSTANCE_ERROR
;
124 case NPPVpluginScriptableNPObject
:
126 /* retrieve plugin root class */
127 NPClass
*scriptClass
= p_plugin
->getScriptClass();
130 /* create an instance and return it */
131 *(NPObject
**)value
= NPN_CreateObject(instance
, scriptClass
);
132 return NPERR_NO_ERROR
;
140 return NPERR_GENERIC_ERROR
;
144 * there is some confusion in gecko headers regarding definition of this API
145 * NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
148 NPError
NPP_SetValue( NPP instance
, NPNVariable variable
, void *value
)
150 return NPERR_GENERIC_ERROR
;
153 /******************************************************************************
155 *****************************************************************************/
157 int16
NPP_HandleEvent( NPP instance
, void * event
)
159 static UInt32 lastMouseUp
= 0;
161 if( instance
== NULL
)
166 VlcPlugin
*p_plugin
= (VlcPlugin
*)instance
->pdata
;
168 if( p_plugin
== NULL
)
173 EventRecord
*myEvent
= (EventRecord
*)event
;
175 switch( myEvent
->what
)
181 if( (myEvent
->when
- lastMouseUp
) < GetDblTime() )
184 libvlc_instance_t
*p_vlc
= p_plugin
->getVLC();
187 if( libvlc_playlist_isplaying(p_vlc
, NULL
) )
189 libvlc_media_player_t
*p_md
=
190 libvlc_playlist_get_media_player(p_vlc
, NULL
);
193 libvlc_toggle_fullscreen(p_md
, NULL
);
194 libvlc_media_player_release(p_md
);
202 lastMouseUp
= myEvent
->when
;
210 const NPWindow
& npwindow
= p_plugin
->getWindow();
211 if( npwindow
.window
)
214 libvlc_instance_t
*p_vlc
= p_plugin
->getVLC();
218 if( libvlc_playlist_isplaying(p_vlc
, NULL
) )
220 libvlc_media_player_t
*p_md
=
221 libvlc_playlist_get_media_player(p_vlc
, NULL
);
224 hasVout
= libvlc_media_player_has_vout(p_md
,
228 libvlc_rectangle_t area
;
231 area
.right
= npwindow
.width
;
232 area
.bottom
= npwindow
.height
;
233 libvlc_video_redraw_rectangle(p_md
, &area
,
236 libvlc_media_player_release(p_md
);
243 /* draw the beautiful "No Picture" */
245 ForeColor(blackColor
);
248 /* seems that firefox forgets to set the following
249 * on occasion (reload) */
250 SetOrigin(((NP_Port
*)npwindow
.window
)->portx
,
251 ((NP_Port
*)npwindow
.window
)->porty
);
256 rect
.right
= npwindow
.width
;
257 rect
.bottom
= npwindow
.height
;
260 ForeColor(whiteColor
);
261 MoveTo( (npwindow
.width
-80)/ 2 , npwindow
.height
/ 2 );
262 DrawText( WINDOW_TEXT
, 0 , strlen(WINDOW_TEXT
) );
269 case NPEventType_GetFocusEvent
:
270 case NPEventType_LoseFocusEvent
:
272 case NPEventType_AdjustCursorEvent
:
274 case NPEventType_MenuCommandEvent
:
276 case NPEventType_ClippingChangedEvent
:
278 case NPEventType_ScrollingBeginsEvent
:
280 case NPEventType_ScrollingEndsEvent
:
287 #endif /* XP_MACOSX */
289 /******************************************************************************
290 * General Plug-in Calls
291 *****************************************************************************/
292 NPError
NPP_Initialize( void )
294 return NPERR_NO_ERROR
;
297 jref
NPP_GetJavaClass( void )
302 void NPP_Shutdown( void )
307 NPError
NPP_New( NPMIMEType pluginType
, NPP instance
, uint16 mode
, int16 argc
,
308 char* argn
[], char* argv
[], NPSavedData
* saved
)
312 if( instance
== NULL
)
314 return NPERR_INVALID_INSTANCE_ERROR
;
317 VlcPlugin
* p_plugin
= new VlcPlugin( instance
, mode
);
318 if( NULL
== p_plugin
)
320 return NPERR_OUT_OF_MEMORY_ERROR
;
323 status
= p_plugin
->init(argc
, argn
, argv
);
324 if( NPERR_NO_ERROR
== status
)
326 instance
->pdata
= reinterpret_cast<void*>(p_plugin
);
328 NPN_SetValue(instance
, NPPVpluginWindowBool
, (void *)false);
329 NPN_SetValue(instance
, NPPVpluginTransparentBool
, (void *)false);
339 NPError
NPP_Destroy( NPP instance
, NPSavedData
** save
)
341 if( NULL
== instance
)
342 return NPERR_INVALID_INSTANCE_ERROR
;
344 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
345 if( NULL
== p_plugin
)
346 return NPERR_NO_ERROR
;
348 instance
->pdata
= NULL
;
351 HWND win
= (HWND
)p_plugin
->getWindow().window
;
352 WNDPROC winproc
= p_plugin
->getWindowProc();
356 SetWindowLong( win
, GWL_WNDPROC
, (LONG
)winproc
);
362 return NPERR_NO_ERROR
;
365 NPError
NPP_SetWindow( NPP instance
, NPWindow
* window
)
367 #if defined(XP_UNIX) && !defined(__APPLE__)
369 unsigned int i_control_height
= 0, i_control_width
= 0;
374 return NPERR_INVALID_INSTANCE_ERROR
;
377 /* NPP_SetWindow may be called before NPP_New (Opera) */
378 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
379 if( NULL
== p_plugin
)
381 /* we should probably show a splash screen here */
382 return NPERR_NO_ERROR
;
384 #if defined(XP_UNIX) && !defined(__APPLE__)
385 control
= p_plugin
->getControlWindow();
387 libvlc_instance_t
*p_vlc
= p_plugin
->getVLC();
391 * Before setting window to point to the
392 * new window, you may wish to compare the new window
393 * info to the previous window (if any) to note window
397 /* retrieve current window */
398 NPWindow
& curwin
= p_plugin
->getWindow();
401 if( window
&& window
->window
)
403 /* check if plugin has a new parent window */
404 CGrafPtr drawable
= (((NP_Port
*) (window
->window
))->port
);
405 if( !curwin
.window
|| drawable
!= (((NP_Port
*) (curwin
.window
))->port
) )
407 /* set/change parent window */
408 libvlc_video_set_parent(p_vlc
, (libvlc_drawable_t
)drawable
, NULL
);
411 /* as MacOS X video output is windowless, set viewport */
412 libvlc_rectangle_t view
, clip
;
415 ** browser sets port origin to top-left location of plugin
416 ** relative to GrafPort window origin is set relative to document,
417 ** which of little use for drawing
419 view
.top
= ((NP_Port
*) (window
->window
))->porty
;
420 view
.left
= ((NP_Port
*) (window
->window
))->portx
;
421 view
.bottom
= window
->height
+view
.top
;
422 view
.right
= window
->width
+view
.left
;
423 /* clipRect coordinates are also relative to GrafPort */
424 clip
.top
= window
->clipRect
.top
;
425 clip
.left
= window
->clipRect
.left
;
426 clip
.bottom
= window
->clipRect
.bottom
;
427 clip
.right
= window
->clipRect
.right
;
429 libvlc_video_set_viewport(p_vlc
, &view
, &clip
, NULL
);
431 /* remember new window */
432 p_plugin
->setWindow(*window
);
434 else if( curwin
.window
) {
435 /* change/set parent */
436 libvlc_video_set_parent(p_vlc
, 0, NULL
);
437 curwin
.window
= NULL
;
439 #endif /* XP_MACOSX */
442 if( window
&& window
->window
)
444 /* check if plugin has a new parent window */
445 HWND drawable
= (HWND
) (window
->window
);
446 if( !curwin
.window
|| drawable
!= curwin
.window
)
448 /* reset previous window settings */
449 HWND oldwin
= (HWND
)p_plugin
->getWindow().window
;
450 WNDPROC oldproc
= p_plugin
->getWindowProc();
454 SetWindowLong( oldwin
, GWL_WNDPROC
, (LONG
)oldproc
);
456 /* attach our plugin object */
457 SetWindowLongPtr((HWND
)drawable
, GWLP_USERDATA
,
458 reinterpret_cast<LONG_PTR
>(p_plugin
));
460 /* install our WNDPROC */
461 p_plugin
->setWindowProc( (WNDPROC
)SetWindowLong( drawable
,
462 GWL_WNDPROC
, (LONG
)Manage
) );
464 /* change window style to our liking */
465 LONG style
= GetWindowLong((HWND
)drawable
, GWL_STYLE
);
466 style
|= WS_CLIPCHILDREN
|WS_CLIPSIBLINGS
;
467 SetWindowLong((HWND
)drawable
, GWL_STYLE
, style
);
469 /* change/set parent */
470 libvlc_video_set_parent(p_vlc
, (libvlc_drawable_t
)drawable
, NULL
);
472 /* remember new window */
473 p_plugin
->setWindow(*window
);
476 InvalidateRect( (HWND
)drawable
, NULL
, TRUE
);
477 UpdateWindow( (HWND
)drawable
);
480 else if ( curwin
.window
)
483 HWND oldwin
= (HWND
)curwin
.window
;
484 SetWindowLong( oldwin
, GWL_WNDPROC
, (LONG
)(p_plugin
->getWindowProc()) );
485 p_plugin
->setWindowProc(NULL
);
486 /* change/set parent */
487 libvlc_video_set_parent(p_vlc
, 0, NULL
);
488 curwin
.window
= NULL
;
493 /* default to hidden toolbar, shown at the end of this method if asked *
494 * developers note : getToolbarSize need to wait the end of this method
496 i_control_height
= 0;
497 i_control_width
= window
->width
;
499 if( window
&& window
->window
)
501 Window parent
= (Window
) window
->window
;
502 if( !curwin
.window
|| (parent
!= (Window
)curwin
.window
) )
504 Display
*p_display
= ( (NPSetWindowCallbackStruct
*)
505 window
->ws_info
)->display
;
507 XResizeWindow( p_display
, parent
, window
->width
, window
->height
);
509 int i_blackColor
= BlackPixel(p_display
, DefaultScreen(p_display
));
512 Window video
= XCreateSimpleWindow( p_display
, parent
, 0, 0,
513 window
->width
, window
->height
- i_control_height
,
514 0, i_blackColor
, i_blackColor
);
515 Window controls
= (Window
) NULL
;
516 controls
= XCreateSimpleWindow( p_display
, parent
,
517 0, window
->height
- i_control_height
-1,
518 window
->width
, i_control_height
-1,
519 0, i_blackColor
, i_blackColor
);
521 XMapWindow( p_display
, parent
);
522 XMapWindow( p_display
, video
);
523 if( controls
) { XMapWindow( p_display
, controls
); }
528 Widget w
= XtWindowToWidget( p_display
, parent
);
530 XtAddEventHandler( w
, ExposureMask
, FALSE
,
531 (XtEventHandler
)Redraw
, p_plugin
);
532 XtAddEventHandler( w
, StructureNotifyMask
, FALSE
,
533 (XtEventHandler
)Resize
, p_plugin
);
534 XtAddEventHandler( w
, ButtonReleaseMask
, FALSE
,
535 (XtEventHandler
)ControlHandler
, p_plugin
);
539 libvlc_media_player_t *p_md;
541 libvlc_exception_t ex;
542 libvlc_exception_init(& ex );
543 p_md = libvlc_playlist_get_media_player( p_plugin->getVLC(), &ex );
544 libvlc_exception_init( &ex );
545 libvlc_event_attach( libvlc_media_player_event_manager( p_md, &ex ),
546 libvlc_MediaPlayerPositionChanged, Redraw, NULL, &ex );
549 /* set/change parent window */
550 libvlc_video_set_parent( p_vlc
, (libvlc_drawable_t
) video
, NULL
);
552 /* remember window */
553 p_plugin
->setWindow( *window
);
554 p_plugin
->setVideoWindow( video
);
555 if( controls
) { p_plugin
->setControlWindow( controls
); }
557 Redraw( w
, (XtPointer
)p_plugin
, NULL
);
559 /* now display toolbar if asked through parameters */
560 if( p_plugin
->b_toolbar
)
562 p_plugin
->showToolbar();
566 else if ( curwin
.window
)
568 /* change/set parent */
569 libvlc_video_set_parent(p_vlc
, 0, NULL
);
570 curwin
.window
= NULL
;
574 if( !p_plugin
->b_stream
)
576 if( p_plugin
->psz_target
)
578 if( libvlc_playlist_add( p_vlc
, p_plugin
->psz_target
,
581 if( p_plugin
->b_autoplay
)
583 libvlc_playlist_play(p_vlc
, 0, 0, NULL
, NULL
);
586 p_plugin
->b_stream
= true;
589 return NPERR_NO_ERROR
;
592 NPError
NPP_NewStream( NPP instance
, NPMIMEType type
, NPStream
*stream
,
593 NPBool seekable
, uint16
*stype
)
595 if( NULL
== instance
)
597 return NPERR_INVALID_INSTANCE_ERROR
;
600 VlcPlugin
*p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
601 if( NULL
== p_plugin
)
603 return NPERR_INVALID_INSTANCE_ERROR
;
607 ** Firefox/Mozilla may decide to open a stream from the URL specified
608 ** in the SRC parameter of the EMBED tag and pass it to us
610 ** since VLC will open the SRC URL as well, we're not interested in
611 ** that stream. Otherwise, we'll take it and queue it up in the playlist
613 if( !p_plugin
->psz_target
|| strcmp(stream
->url
, p_plugin
->psz_target
) )
615 /* TODO: use pipes !!!! */
616 *stype
= NP_ASFILEONLY
;
617 return NPERR_NO_ERROR
;
619 return NPERR_GENERIC_ERROR
;
622 int32
NPP_WriteReady( NPP instance
, NPStream
*stream
)
629 int32
NPP_Write( NPP instance
, NPStream
*stream
, int32 offset
,
630 int32 len
, void *buffer
)
637 NPError
NPP_DestroyStream( NPP instance
, NPStream
*stream
, NPError reason
)
639 if( instance
== NULL
)
641 return NPERR_INVALID_INSTANCE_ERROR
;
643 return NPERR_NO_ERROR
;
647 void NPP_StreamAsFile( NPP instance
, NPStream
*stream
, const char* fname
)
649 if( instance
== NULL
)
654 VlcPlugin
*p_plugin
= reinterpret_cast<VlcPlugin
*>(instance
->pdata
);
655 if( NULL
== p_plugin
)
660 if( libvlc_playlist_add( p_plugin
->getVLC(), fname
, stream
->url
, NULL
)
663 if( p_plugin
->b_autoplay
)
665 libvlc_playlist_play( p_plugin
->getVLC(), 0, 0, NULL
, NULL
);
671 void NPP_URLNotify( NPP instance
, const char* url
,
672 NPReason reason
, void* notifyData
)
674 /***** Insert NPP_URLNotify code here *****\
675 PluginInstance* p_plugin;
676 if (instance != NULL)
677 p_plugin = (PluginInstance*) instance->pdata;
678 \*********************************************/
682 void NPP_Print( NPP instance
, NPPrint
* printInfo
)
684 if( printInfo
== NULL
)
689 if( instance
!= NULL
)
691 /***** Insert NPP_Print code here *****\
692 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
693 \**************************************/
695 if( printInfo
->mode
== NP_FULL
)
699 * If your plugin would like to take over
700 * printing completely when it is in full-screen mode,
701 * set printInfo->pluginPrinted to TRUE and print your
702 * plugin as you see fit. If your plugin wants Netscape
703 * to handle printing in this case, set
704 * printInfo->pluginPrinted to FALSE (the default) and
705 * do nothing. If you do want to handle printing
706 * yourself, printOne is true if the print button
707 * (as opposed to the print menu) was clicked.
708 * On the Macintosh, platformPrint is a THPrint; on
709 * Windows, platformPrint is a structure
710 * (defined in npapi.h) containing the printer name, port,
714 /***** Insert NPP_Print code here *****\
715 void* platformPrint =
716 printInfo->print.fullPrint.platformPrint;
718 printInfo->print.fullPrint.printOne;
719 \**************************************/
722 printInfo
->print
.fullPrint
.pluginPrinted
= FALSE
;
726 /* If not fullscreen, we must be embedded */
729 * If your plugin is embedded, or is full-screen
730 * but you returned false in pluginPrinted above, NPP_Print
731 * will be called with mode == NP_EMBED. The NPWindow
732 * in the printInfo gives the location and dimensions of
733 * the embedded plugin on the printed page. On the
734 * Macintosh, platformPrint is the printer port; on
735 * Windows, platformPrint is the handle to the printing
739 /***** Insert NPP_Print code here *****\
740 NPWindow* printWindow =
741 &(printInfo->print.embedPrint.window);
742 void* platformPrint =
743 printInfo->print.embedPrint.platformPrint;
744 \**************************************/
749 /******************************************************************************
750 * Windows-only methods
751 *****************************************************************************/
753 static LRESULT CALLBACK
Manage( HWND p_hwnd
, UINT i_msg
, WPARAM wpar
, LPARAM lpar
)
755 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(GetWindowLongPtr(p_hwnd
, GWLP_USERDATA
));
764 PAINTSTRUCT paintstruct
;
768 hdc
= BeginPaint( p_hwnd
, &paintstruct
);
770 GetClientRect( p_hwnd
, &rect
);
772 FillRect( hdc
, &rect
, (HBRUSH
)GetStockObject(BLACK_BRUSH
) );
773 SetTextColor(hdc
, RGB(255, 255, 255));
774 SetBkColor(hdc
, RGB(0, 0, 0));
775 DrawText( hdc
, WINDOW_TEXT
, strlen(WINDOW_TEXT
), &rect
,
776 DT_CENTER
|DT_VCENTER
|DT_SINGLELINE
);
778 EndPaint( p_hwnd
, &paintstruct
);
782 /* delegate to default handler */
783 return CallWindowProc( p_plugin
->getWindowProc(), p_hwnd
,
789 /******************************************************************************
791 *****************************************************************************/
793 static void Redraw( Widget w
, XtPointer closure
, XEvent
*event
)
795 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(closure
);
796 Window control
= p_plugin
->getControlWindow();
797 const NPWindow
& window
= p_plugin
->getWindow();
800 unsigned int i_control_height
, i_control_width
;
802 if( p_plugin
->b_toolbar
)
803 p_plugin
->getToolbarSize( &i_control_width
, &i_control_height
);
805 i_control_height
= i_control_width
= 0;
807 Window video
= p_plugin
->getVideoWindow();
808 Display
*p_display
= ((NPSetWindowCallbackStruct
*)window
.ws_info
)->display
;
810 gcv
.foreground
= BlackPixel( p_display
, 0 );
811 gc
= XCreateGC( p_display
, video
, GCForeground
, &gcv
);
813 XFillRectangle( p_display
, video
, gc
,
814 0, 0, window
.width
, window
.height
- i_control_height
);
816 gcv
.foreground
= WhitePixel( p_display
, 0 );
817 XChangeGC( p_display
, gc
, GCForeground
, &gcv
);
819 XDrawString( p_display
, video
, gc
,
820 window
.width
/ 2 - 40, (window
.height
- i_control_height
) / 2,
821 WINDOW_TEXT
, strlen(WINDOW_TEXT
) );
822 XFreeGC( p_display
, gc
);
824 p_plugin
->redrawToolbar();
827 static void ControlHandler( Widget w
, XtPointer closure
, XEvent
*event
)
829 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(closure
);
830 const NPWindow
& window
= p_plugin
->getWindow();
832 int i_height
= window
.height
;
833 int i_width
= window
.width
;
834 int i_xPos
= event
->xbutton
.x
;
835 int i_yPos
= event
->xbutton
.y
;
837 if( p_plugin
&& p_plugin
->b_toolbar
)
840 libvlc_exception_t ex
;
842 libvlc_exception_init( &ex
);
843 libvlc_media_player_t
*p_md
=
844 libvlc_playlist_get_media_player(p_plugin
->getVLC(), &ex
);
845 if( libvlc_exception_raised(&ex
) )
846 fprintf( stderr
, "%s\n", libvlc_exception_get_message(&ex
));
847 libvlc_exception_clear( &ex
);
849 i_playing
= libvlc_playlist_isplaying( p_plugin
->getVLC(), &ex
);
850 if( libvlc_exception_raised(&ex
) )
851 fprintf( stderr
, "%s\n", libvlc_exception_get_message(&ex
));
852 libvlc_exception_clear( &ex
);
854 vlc_toolbar_clicked_t clicked
;
855 clicked
= p_plugin
->getToolbarButtonClicked( i_xPos
, i_yPos
);
862 libvlc_playlist_pause( p_plugin
->getVLC(), &ex
);
864 libvlc_playlist_play( p_plugin
->getVLC(), -1, 0, NULL
, &ex
);
866 if( libvlc_exception_raised(&ex
) )
867 fprintf( stderr
, "%s\n", libvlc_exception_get_message(&ex
));
868 libvlc_exception_clear( &ex
);
874 libvlc_playlist_stop( p_plugin
->getVLC(), &ex
);
875 if( libvlc_exception_raised(&ex
) )
876 fprintf( stderr
, "%s\n", libvlc_exception_get_message(&ex
));
877 libvlc_exception_clear( &ex
);
881 case clicked_Fullscreen
:
883 if( (i_playing
== 1) && p_md
)
885 libvlc_set_fullscreen( p_md
, 1, &ex
);
886 if( libvlc_exception_raised(&ex
) )
887 fprintf( stderr
, "%s\n", libvlc_exception_get_message(&ex
));
888 libvlc_exception_clear( &ex
);
896 libvlc_audio_toggle_mute( p_plugin
->getVLC(), &ex
);
897 if( libvlc_exception_raised(&ex
) )
898 fprintf( stderr
, "%s\n", libvlc_exception_get_message(&ex
));
899 libvlc_exception_clear( &ex
);
903 case clicked_timeline
:
905 /* if a movie is loaded */
909 f_length
= libvlc_media_player_get_length( p_md
, &ex
) / 100;
910 libvlc_exception_clear( &ex
);
912 f_length
= (float)f_length
*
913 ( ((float)i_xPos
-4.0 ) / ( ((float)i_width
-8.0)/100) );
915 libvlc_media_player_set_time( p_md
, f_length
, &ex
);
916 if( libvlc_exception_raised(&ex
) )
917 fprintf( stderr
, "%s\n", libvlc_exception_get_message(&ex
));
918 libvlc_exception_clear( &ex
);
925 /* Not implemented yet*/
929 default: /* button_Unknown */
932 if( p_md
) libvlc_media_player_release( p_md
);
934 Redraw( w
, closure
, event
);
937 static void Resize ( Widget w
, XtPointer closure
, XEvent
*event
)
939 VlcPlugin
* p_plugin
= reinterpret_cast<VlcPlugin
*>(closure
);
940 Window control
= p_plugin
->getControlWindow();
941 const NPWindow
& window
= p_plugin
->getWindow();
942 Window drawable
= p_plugin
->getVideoWindow();
943 Display
*p_display
= ((NPSetWindowCallbackStruct
*)window
.ws_info
)->display
;
946 Window root_return
, parent_return
, * children_return
;
948 unsigned int i_nchildren
;
949 unsigned int i_control_height
, i_control_width
;
951 if( p_plugin
->b_toolbar
)
953 p_plugin
->getToolbarSize( &i_control_width
, &i_control_height
);
957 i_control_height
= i_control_width
= 0;
960 #ifdef X11_RESIZE_DEBUG
961 XWindowAttributes attr
;
963 if( event
&& event
->type
== ConfigureNotify
)
965 fprintf( stderr
, "vlcshell::Resize() ConfigureNotify %d x %d, "
966 "send_event ? %s\n", event
->xconfigure
.width
,
967 event
->xconfigure
.height
,
968 event
->xconfigure
.send_event
? "TRUE" : "FALSE" );
970 #endif /* X11_RESIZE_DEBUG */
972 if( ! p_plugin
->setSize(window
.width
, (window
.height
- i_control_height
)) )
974 /* size already set */
978 i_ret
= XResizeWindow( p_display
, drawable
,
979 window
.width
, (window
.height
- i_control_height
) );
981 #ifdef X11_RESIZE_DEBUG
983 "vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret
);
985 XGetWindowAttributes ( p_display
, drawable
, &attr
);
987 /* X is asynchronous, so the current size reported here is not
988 necessarily the requested size as the Resize request may not
989 yet have been handled by the plugin host */
990 fprintf( stderr
, "vlcshell::Resize() current (owner) size %d x %d\n",
991 attr
.width
, attr
.height
);
992 #endif /* X11_RESIZE_DEBUG */
994 XQueryTree( p_display
, drawable
,
995 &root_return
, &parent_return
, &children_return
,
998 if( i_nchildren
> 0 )
1000 /* XXX: Make assumptions related to the window parenting structure in
1001 vlc/modules/video_output/x11/xcommon.c */
1002 base_window
= children_return
[i_nchildren
- 1];
1004 #ifdef X11_RESIZE_DEBUG
1005 fprintf( stderr
, "vlcshell::Resize() got %d children\n", i_nchildren
);
1006 fprintf( stderr
, "vlcshell::Resize() got base_window %p\n",
1008 #endif /* X11_RESIZE_DEBUG */
1010 i_ret
= XResizeWindow( p_display
, base_window
,
1011 window
.width
, ( window
.height
- i_control_height
) );
1013 #ifdef X11_RESIZE_DEBUG
1015 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
1018 XGetWindowAttributes( p_display
, base_window
, &attr
);
1020 fprintf( stderr
, "vlcshell::Resize() new size %d x %d\n",
1021 attr
.width
, attr
.height
);
1022 #endif /* X11_RESIZE_DEBUG */
1026 #endif /* XP_UNIX */