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();
188 libvlc_playlist_lock(p_vlc);
189 is_playing = libvlc_playlist_isplaying(p_vlc, NULL);
190 libvlc_playlist_lunock(p_vlc);
193 libvlc_media_player_t *p_md =
194 libvlc_playlist_get_media_player(p_vlc, NULL);
197 libvlc_toggle_fullscreen(p_md, NULL);
198 libvlc_media_player_release(p_md);
206 lastMouseUp = myEvent->when;
214 const NPWindow& npwindow = p_plugin->getWindow();
215 if( npwindow.window )
218 libvlc_instance_t *p_vlc = p_plugin->getVLC();
223 libvlc_playlist_lock(p_vlc);
224 is_playing = libvlc_playlist_isplaying(p_vlc, NULL);
225 libvlc_playlist_unlock(p_vlc);
228 libvlc_media_player_t *p_md =
229 libvlc_playlist_get_media_player(p_vlc, NULL);
232 hasVout = libvlc_media_player_has_vout(p_md,
236 libvlc_rectangle_t area;
239 area.right = npwindow.width;
240 area.bottom = npwindow.height;
241 libvlc_video_redraw_rectangle(p_md, &area,
244 libvlc_media_player_release(p_md);
251 /* draw the beautiful "No Picture" */
253 ForeColor(blackColor);
256 /* seems that firefox forgets to set the following
257 * on occasion (reload) */
258 SetOrigin(((NP_Port *)npwindow.window)->portx,
259 ((NP_Port *)npwindow.window)->porty);
264 rect.right = npwindow.width;
265 rect.bottom = npwindow.height;
268 ForeColor(whiteColor);
269 MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
270 DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
277 case NPEventType_GetFocusEvent:
278 case NPEventType_LoseFocusEvent:
280 case NPEventType_AdjustCursorEvent:
282 case NPEventType_MenuCommandEvent:
284 case NPEventType_ClippingChangedEvent:
286 case NPEventType_ScrollingBeginsEvent:
288 case NPEventType_ScrollingEndsEvent:
295 #endif /* XP_MACOSX */
297 /******************************************************************************
298 * General Plug-in Calls
299 *****************************************************************************/
300 NPError NPP_Initialize( void )
302 return NPERR_NO_ERROR;
305 jref NPP_GetJavaClass( void )
310 void NPP_Shutdown( void )
315 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
316 char* argn[], char* argv[], NPSavedData* saved )
320 if( instance == NULL )
322 return NPERR_INVALID_INSTANCE_ERROR;
325 VlcPlugin * p_plugin = new VlcPlugin( instance, mode );
326 if( NULL == p_plugin )
328 return NPERR_OUT_OF_MEMORY_ERROR;
331 status = p_plugin->init(argc, argn, argv);
332 if( NPERR_NO_ERROR == status )
334 instance->pdata = reinterpret_cast<void*>(p_plugin);
336 NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
337 NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
347 NPError NPP_Destroy( NPP instance, NPSavedData** save )
349 if( NULL == instance )
350 return NPERR_INVALID_INSTANCE_ERROR;
352 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
353 if( NULL == p_plugin )
354 return NPERR_NO_ERROR;
356 instance->pdata = NULL;
359 HWND win = (HWND)p_plugin->getWindow().window;
360 WNDPROC winproc = p_plugin->getWindowProc();
364 SetWindowLong( win, GWL_WNDPROC, (LONG)winproc );
370 return NPERR_NO_ERROR;
373 NPError NPP_SetWindow( NPP instance, NPWindow* window )
375 #if defined(XP_UNIX) && !defined(__APPLE__)
377 unsigned int i_control_height = 0, i_control_width = 0;
382 return NPERR_INVALID_INSTANCE_ERROR;
385 /* NPP_SetWindow may be called before NPP_New (Opera) */
386 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
387 if( NULL == p_plugin )
389 /* we should probably show a splash screen here */
390 return NPERR_NO_ERROR;
392 #if defined(XP_UNIX) && !defined(__APPLE__)
393 control = p_plugin->getControlWindow();
395 libvlc_instance_t *p_vlc = p_plugin->getVLC();
399 * Before setting window to point to the
400 * new window, you may wish to compare the new window
401 * info to the previous window (if any) to note window
405 /* retrieve current window */
406 NPWindow& curwin = p_plugin->getWindow();
409 if( window && window->window )
411 /* check if plugin has a new parent window */
412 CGrafPtr drawable = (((NP_Port*) (window->window))->port);
413 if( !curwin.window || drawable != (((NP_Port*) (curwin.window))->port) )
415 /* set/change parent window */
416 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
419 /* as MacOS X video output is windowless, set viewport */
420 libvlc_rectangle_t view, clip;
423 ** browser sets port origin to top-left location of plugin
424 ** relative to GrafPort window origin is set relative to document,
425 ** which of little use for drawing
427 view.top = ((NP_Port*) (window->window))->porty;
428 view.left = ((NP_Port*) (window->window))->portx;
429 view.bottom = window->height+view.top;
430 view.right = window->width+view.left;
431 /* clipRect coordinates are also relative to GrafPort */
432 clip.top = window->clipRect.top;
433 clip.left = window->clipRect.left;
434 clip.bottom = window->clipRect.bottom;
435 clip.right = window->clipRect.right;
437 libvlc_video_set_viewport(p_vlc, &view, &clip, NULL);
439 /* remember new window */
440 p_plugin->setWindow(*window);
442 else if( curwin.window ) {
443 /* change/set parent */
444 libvlc_video_set_parent(p_vlc, 0, NULL);
445 curwin.window = NULL;
447 #endif /* XP_MACOSX */
450 if( window && window->window )
452 /* check if plugin has a new parent window */
453 HWND drawable = (HWND) (window->window);
454 if( !curwin.window || drawable != curwin.window )
456 /* reset previous window settings */
457 HWND oldwin = (HWND)p_plugin->getWindow().window;
458 WNDPROC oldproc = p_plugin->getWindowProc();
462 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)oldproc );
464 /* attach our plugin object */
465 SetWindowLongPtr((HWND)drawable, GWLP_USERDATA,
466 reinterpret_cast<LONG_PTR>(p_plugin));
468 /* install our WNDPROC */
469 p_plugin->setWindowProc( (WNDPROC)SetWindowLong( drawable,
470 GWL_WNDPROC, (LONG)Manage ) );
472 /* change window style to our liking */
473 LONG style = GetWindowLong((HWND)drawable, GWL_STYLE);
474 style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
475 SetWindowLong((HWND)drawable, GWL_STYLE, style);
477 /* change/set parent */
478 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
480 /* remember new window */
481 p_plugin->setWindow(*window);
484 InvalidateRect( (HWND)drawable, NULL, TRUE );
485 UpdateWindow( (HWND)drawable );
488 else if ( curwin.window )
491 HWND oldwin = (HWND)curwin.window;
492 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) );
493 p_plugin->setWindowProc(NULL);
494 /* change/set parent */
495 libvlc_video_set_parent(p_vlc, 0, NULL);
496 curwin.window = NULL;
501 /* default to hidden toolbar, shown at the end of this method if asked *
502 * developers note : getToolbarSize need to wait the end of this method
504 i_control_height = 0;
505 i_control_width = window->width;
507 if( window && window->window )
509 Window parent = (Window) window->window;
510 if( !curwin.window || (parent != (Window)curwin.window) )
512 Display *p_display = ( (NPSetWindowCallbackStruct *)
513 window->ws_info )->display;
515 XResizeWindow( p_display, parent, window->width, window->height );
517 int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
520 Window video = XCreateSimpleWindow( p_display, parent, 0, 0,
521 window->width, window->height - i_control_height,
522 0, i_blackColor, i_blackColor );
523 Window controls = (Window) NULL;
524 controls = XCreateSimpleWindow( p_display, parent,
525 0, window->height - i_control_height-1,
526 window->width, i_control_height-1,
527 0, i_blackColor, i_blackColor );
529 XMapWindow( p_display, parent );
530 XMapWindow( p_display, video );
531 if( controls ) { XMapWindow( p_display, controls ); }
536 Widget w = XtWindowToWidget( p_display, parent );
538 XtAddEventHandler( w, ExposureMask, FALSE,
539 (XtEventHandler)Redraw, p_plugin );
540 XtAddEventHandler( w, StructureNotifyMask, FALSE,
541 (XtEventHandler)Resize, p_plugin );
542 XtAddEventHandler( w, ButtonReleaseMask, FALSE,
543 (XtEventHandler)ControlHandler, p_plugin );
547 libvlc_media_player_t *p_md;
549 libvlc_exception_t ex;
550 libvlc_exception_init(& ex );
551 p_md = libvlc_playlist_get_media_player( p_plugin->getVLC(), &ex );
552 libvlc_exception_init( &ex );
553 libvlc_event_attach( libvlc_media_player_event_manager( p_md, &ex ),
554 libvlc_MediaPlayerPositionChanged, Redraw, NULL, &ex );
557 /* set/change parent window */
558 libvlc_video_set_parent( p_vlc, (libvlc_drawable_t) video, NULL );
560 /* remember window */
561 p_plugin->setWindow( *window );
562 p_plugin->setVideoWindow( video );
563 if( controls ) { p_plugin->setControlWindow( controls ); }
565 Redraw( w, (XtPointer)p_plugin, NULL );
567 /* now display toolbar if asked through parameters */
568 if( p_plugin->b_toolbar )
570 p_plugin->showToolbar();
574 else if ( curwin.window )
576 /* change/set parent */
577 libvlc_video_set_parent(p_vlc, 0, NULL);
578 curwin.window = NULL;
582 if( !p_plugin->b_stream )
584 if( p_plugin->psz_target )
586 if( libvlc_playlist_add( p_vlc, p_plugin->psz_target,
589 if( p_plugin->b_autoplay )
591 libvlc_playlist_play(p_vlc, 0, 0, NULL, NULL);
594 p_plugin->b_stream = true;
597 return NPERR_NO_ERROR;
600 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
601 NPBool seekable, uint16 *stype )
603 if( NULL == instance )
605 return NPERR_INVALID_INSTANCE_ERROR;
608 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
609 if( NULL == p_plugin )
611 return NPERR_INVALID_INSTANCE_ERROR;
615 ** Firefox/Mozilla may decide to open a stream from the URL specified
616 ** in the SRC parameter of the EMBED tag and pass it to us
618 ** since VLC will open the SRC URL as well, we're not interested in
619 ** that stream. Otherwise, we'll take it and queue it up in the playlist
621 if( !p_plugin->psz_target || strcmp(stream->url, p_plugin->psz_target) )
623 /* TODO: use pipes !!!! */
624 *stype = NP_ASFILEONLY;
625 return NPERR_NO_ERROR;
627 return NPERR_GENERIC_ERROR;
630 int32 NPP_WriteReady( NPP instance, NPStream *stream )
637 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
638 int32 len, void *buffer )
645 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
647 if( instance == NULL )
649 return NPERR_INVALID_INSTANCE_ERROR;
651 return NPERR_NO_ERROR;
655 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
657 if( instance == NULL )
662 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
663 if( NULL == p_plugin )
668 if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL )
671 if( p_plugin->b_autoplay )
673 libvlc_playlist_play( p_plugin->getVLC(), 0, 0, NULL, NULL);
679 void NPP_URLNotify( NPP instance, const char* url,
680 NPReason reason, void* notifyData )
682 /***** Insert NPP_URLNotify code here *****\
683 PluginInstance* p_plugin;
684 if (instance != NULL)
685 p_plugin = (PluginInstance*) instance->pdata;
686 \*********************************************/
690 void NPP_Print( NPP instance, NPPrint* printInfo )
692 if( printInfo == NULL )
697 if( instance != NULL )
699 /***** Insert NPP_Print code here *****\
700 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
701 \**************************************/
703 if( printInfo->mode == NP_FULL )
707 * If your plugin would like to take over
708 * printing completely when it is in full-screen mode,
709 * set printInfo->pluginPrinted to TRUE and print your
710 * plugin as you see fit. If your plugin wants Netscape
711 * to handle printing in this case, set
712 * printInfo->pluginPrinted to FALSE (the default) and
713 * do nothing. If you do want to handle printing
714 * yourself, printOne is true if the print button
715 * (as opposed to the print menu) was clicked.
716 * On the Macintosh, platformPrint is a THPrint; on
717 * Windows, platformPrint is a structure
718 * (defined in npapi.h) containing the printer name, port,
722 /***** Insert NPP_Print code here *****\
723 void* platformPrint =
724 printInfo->print.fullPrint.platformPrint;
726 printInfo->print.fullPrint.printOne;
727 \**************************************/
730 printInfo->print.fullPrint.pluginPrinted = FALSE;
734 /* If not fullscreen, we must be embedded */
737 * If your plugin is embedded, or is full-screen
738 * but you returned false in pluginPrinted above, NPP_Print
739 * will be called with mode == NP_EMBED. The NPWindow
740 * in the printInfo gives the location and dimensions of
741 * the embedded plugin on the printed page. On the
742 * Macintosh, platformPrint is the printer port; on
743 * Windows, platformPrint is the handle to the printing
747 /***** Insert NPP_Print code here *****\
748 NPWindow* printWindow =
749 &(printInfo->print.embedPrint.window);
750 void* platformPrint =
751 printInfo->print.embedPrint.platformPrint;
752 \**************************************/
757 /******************************************************************************
758 * Windows-only methods
759 *****************************************************************************/
761 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
763 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
772 PAINTSTRUCT paintstruct;
776 hdc = BeginPaint( p_hwnd, &paintstruct );
778 GetClientRect( p_hwnd, &rect );
780 FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
781 SetTextColor(hdc, RGB(255, 255, 255));
782 SetBkColor(hdc, RGB(0, 0, 0));
783 DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect,
784 DT_CENTER|DT_VCENTER|DT_SINGLELINE);
786 EndPaint( p_hwnd, &paintstruct );
790 /* delegate to default handler */
791 return CallWindowProc( p_plugin->getWindowProc(), p_hwnd,
797 /******************************************************************************
799 *****************************************************************************/
801 static void Redraw( Widget w, XtPointer closure, XEvent *event )
803 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
804 Window control = p_plugin->getControlWindow();
805 const NPWindow& window = p_plugin->getWindow();
808 unsigned int i_control_height, i_control_width;
810 if( p_plugin->b_toolbar )
811 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
813 i_control_height = i_control_width = 0;
815 Window video = p_plugin->getVideoWindow();
816 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
818 gcv.foreground = BlackPixel( p_display, 0 );
819 gc = XCreateGC( p_display, video, GCForeground, &gcv );
821 XFillRectangle( p_display, video, gc,
822 0, 0, window.width, window.height - i_control_height);
824 gcv.foreground = WhitePixel( p_display, 0 );
825 XChangeGC( p_display, gc, GCForeground, &gcv );
827 XDrawString( p_display, video, gc,
828 window.width / 2 - 40, (window.height - i_control_height) / 2,
829 WINDOW_TEXT, strlen(WINDOW_TEXT) );
830 XFreeGC( p_display, gc );
832 p_plugin->redrawToolbar();
835 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
837 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
838 const NPWindow& window = p_plugin->getWindow();
840 int i_height = window.height;
841 int i_width = window.width;
842 int i_xPos = event->xbutton.x;
843 int i_yPos = event->xbutton.y;
845 if( p_plugin && p_plugin->b_toolbar )
848 libvlc_exception_t ex;
850 libvlc_exception_init( &ex );
851 libvlc_media_player_t *p_md =
852 libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
853 if( libvlc_exception_raised(&ex) )
854 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
855 libvlc_exception_clear( &ex );
857 libvlc_playlist_lock( p_plugin->getVLC() );
858 i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
859 libvlc_playlist_unlock( p_plugin->getVLC() );
860 if( libvlc_exception_raised(&ex) )
861 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
862 libvlc_exception_clear( &ex );
864 vlc_toolbar_clicked_t clicked;
865 clicked = p_plugin->getToolbarButtonClicked( i_xPos, i_yPos );
872 libvlc_playlist_pause( p_plugin->getVLC(), &ex );
874 libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
876 if( libvlc_exception_raised(&ex) )
877 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
878 libvlc_exception_clear( &ex );
884 libvlc_playlist_stop( p_plugin->getVLC(), &ex );
885 if( libvlc_exception_raised(&ex) )
886 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
887 libvlc_exception_clear( &ex );
891 case clicked_Fullscreen:
893 if( (i_playing == 1) && p_md )
895 libvlc_set_fullscreen( p_md, 1, &ex );
896 if( libvlc_exception_raised(&ex) )
897 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
898 libvlc_exception_clear( &ex );
906 libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
907 if( libvlc_exception_raised(&ex) )
908 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
909 libvlc_exception_clear( &ex );
913 case clicked_timeline:
915 /* if a movie is loaded */
919 f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
920 libvlc_exception_clear( &ex );
922 f_length = (float)f_length *
923 ( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) );
925 libvlc_media_player_set_time( p_md, f_length, &ex );
926 if( libvlc_exception_raised(&ex) )
927 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
928 libvlc_exception_clear( &ex );
935 /* Not implemented yet*/
939 default: /* button_Unknown */
942 if( p_md ) libvlc_media_player_release( p_md );
944 Redraw( w, closure, event );
947 static void Resize ( Widget w, XtPointer closure, XEvent *event )
949 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
950 Window control = p_plugin->getControlWindow();
951 const NPWindow& window = p_plugin->getWindow();
952 Window drawable = p_plugin->getVideoWindow();
953 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
956 Window root_return, parent_return, * children_return;
958 unsigned int i_nchildren;
959 unsigned int i_control_height, i_control_width;
961 if( p_plugin->b_toolbar )
963 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
967 i_control_height = i_control_width = 0;
970 #ifdef X11_RESIZE_DEBUG
971 XWindowAttributes attr;
973 if( event && event->type == ConfigureNotify )
975 fprintf( stderr, "vlcshell::Resize() ConfigureNotify %d x %d, "
976 "send_event ? %s\n", event->xconfigure.width,
977 event->xconfigure.height,
978 event->xconfigure.send_event ? "TRUE" : "FALSE" );
980 #endif /* X11_RESIZE_DEBUG */
982 if( ! p_plugin->setSize(window.width, (window.height - i_control_height)) )
984 /* size already set */
988 i_ret = XResizeWindow( p_display, drawable,
989 window.width, (window.height - i_control_height) );
991 #ifdef X11_RESIZE_DEBUG
993 "vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret );
995 XGetWindowAttributes ( p_display, drawable, &attr );
997 /* X is asynchronous, so the current size reported here is not
998 necessarily the requested size as the Resize request may not
999 yet have been handled by the plugin host */
1000 fprintf( stderr, "vlcshell::Resize() current (owner) size %d x %d\n",
1001 attr.width, attr.height );
1002 #endif /* X11_RESIZE_DEBUG */
1004 XQueryTree( p_display, drawable,
1005 &root_return, &parent_return, &children_return,
1008 if( i_nchildren > 0 )
1010 /* XXX: Make assumptions related to the window parenting structure in
1011 vlc/modules/video_output/x11/xcommon.c */
1012 base_window = children_return[i_nchildren - 1];
1014 #ifdef X11_RESIZE_DEBUG
1015 fprintf( stderr, "vlcshell::Resize() got %d children\n", i_nchildren );
1016 fprintf( stderr, "vlcshell::Resize() got base_window %p\n",
1018 #endif /* X11_RESIZE_DEBUG */
1020 i_ret = XResizeWindow( p_display, base_window,
1021 window.width, ( window.height - i_control_height ) );
1023 #ifdef X11_RESIZE_DEBUG
1025 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
1028 XGetWindowAttributes( p_display, base_window, &attr );
1030 fprintf( stderr, "vlcshell::Resize() new size %d x %d\n",
1031 attr.width, attr.height );
1032 #endif /* X11_RESIZE_DEBUG */
1036 #endif /* XP_UNIX */