1 /*****************************************************************************
2 * vlcshell.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2009 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"
47 /* Enable/disable debugging printf's for X11 resizing */
48 #undef X11_RESIZE_DEBUG
50 #define WINDOW_TEXT "Waiting for video"
52 /*****************************************************************************
53 * Unix-only declarations
54 ******************************************************************************/
57 static void Redraw( Widget w, XtPointer closure, XEvent *event );
58 static void ControlHandler( Widget w, XtPointer closure, XEvent *event );
59 static void Resize( Widget w, XtPointer closure, XEvent *event );
63 /*****************************************************************************
64 * MacOS-only declarations
65 ******************************************************************************/
69 /*****************************************************************************
70 * Windows-only declarations
71 *****************************************************************************/
74 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );
78 /******************************************************************************
80 *****************************************************************************/
81 char * NPP_GetMIMEDescription( void )
83 static char mimetype[] = PLUGIN_MIMETYPES;
87 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
89 static char psz_name[] = PLUGIN_NAME;
90 static char psz_desc[1000];
92 /* plugin class variables */
95 case NPPVpluginNameString:
96 *((char **)value) = psz_name;
97 return NPERR_NO_ERROR;
99 case NPPVpluginDescriptionString:
100 snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION,
101 libvlc_get_version() );
102 *((char **)value) = psz_desc;
103 return NPERR_NO_ERROR;
106 /* move on to instance variables ... */
110 if( instance == NULL )
112 return NPERR_INVALID_INSTANCE_ERROR;
115 /* plugin instance variables */
117 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
118 if( NULL == p_plugin )
120 // plugin has not been initialized yet !
121 return NPERR_INVALID_INSTANCE_ERROR;
126 case NPPVpluginScriptableNPObject:
128 /* retrieve plugin root class */
129 NPClass *scriptClass = p_plugin->getScriptClass();
132 /* create an instance and return it */
133 *(NPObject**)value = NPN_CreateObject(instance, scriptClass);
134 return NPERR_NO_ERROR;
142 return NPERR_GENERIC_ERROR;
146 * there is some confusion in gecko headers regarding definition of this API
147 * NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
150 NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
152 return NPERR_GENERIC_ERROR;
155 /******************************************************************************
157 *****************************************************************************/
159 int16 NPP_HandleEvent( NPP instance, void * event )
161 static UInt32 lastMouseUp = 0;
162 libvlc_exception_t ex;
163 libvlc_exception_init(&ex);
165 if( instance == NULL )
170 VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
172 if( p_plugin == NULL )
177 EventRecord *myEvent = (EventRecord*)event;
179 switch( myEvent->what )
185 if( (myEvent->when - lastMouseUp) < GetDblTime() )
188 p_plugin->toggle_fullscreen(&ex);
189 libvlc_exception_clear(&ex);
194 lastMouseUp = myEvent->when;
202 const NPWindow& npwindow = p_plugin->getWindow();
203 if( npwindow.window )
207 if( p_plugin->playlist_isplaying(&ex) )
209 hasVout = p_plugin->player_has_vout(NULL);
212 libvlc_rectangle_t area;
215 area.right = npwindow.width;
216 area.bottom = npwindow.height;
217 libvlc_video_redraw_rectangle(p_plugin->getMD(&ex), &area, NULL);
220 libvlc_exception_clear(&ex);
224 /* draw the beautiful "No Picture" */
226 ForeColor(blackColor);
229 /* seems that firefox forgets to set the following
230 * on occasion (reload) */
231 SetOrigin(((NP_Port *)npwindow.window)->portx,
232 ((NP_Port *)npwindow.window)->porty);
237 rect.right = npwindow.width;
238 rect.bottom = npwindow.height;
241 ForeColor(whiteColor);
242 MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
243 DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
250 case NPEventType_GetFocusEvent:
251 case NPEventType_LoseFocusEvent:
253 case NPEventType_AdjustCursorEvent:
255 case NPEventType_MenuCommandEvent:
257 case NPEventType_ClippingChangedEvent:
259 case NPEventType_ScrollingBeginsEvent:
261 case NPEventType_ScrollingEndsEvent:
268 #endif /* XP_MACOSX */
270 /******************************************************************************
271 * General Plug-in Calls
272 *****************************************************************************/
273 NPError NPP_Initialize( void )
275 return NPERR_NO_ERROR;
278 jref NPP_GetJavaClass( void )
283 void NPP_Shutdown( void )
288 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
289 char* argn[], char* argv[], NPSavedData* saved )
293 if( instance == NULL )
295 return NPERR_INVALID_INSTANCE_ERROR;
298 VlcPlugin * p_plugin = new VlcPlugin( instance, mode );
299 if( NULL == p_plugin )
301 return NPERR_OUT_OF_MEMORY_ERROR;
304 status = p_plugin->init(argc, argn, argv);
305 if( NPERR_NO_ERROR == status )
307 instance->pdata = reinterpret_cast<void*>(p_plugin);
309 NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
310 NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
320 NPError NPP_Destroy( NPP instance, NPSavedData** save )
322 if( NULL == instance )
323 return NPERR_INVALID_INSTANCE_ERROR;
325 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
326 if( NULL == p_plugin )
327 return NPERR_NO_ERROR;
329 instance->pdata = NULL;
332 HWND win = (HWND)p_plugin->getWindow().window;
333 WNDPROC winproc = p_plugin->getWindowProc();
337 SetWindowLong( win, GWL_WNDPROC, (LONG)winproc );
343 return NPERR_NO_ERROR;
346 NPError NPP_SetWindow( NPP instance, NPWindow* window )
348 #if defined(XP_UNIX) && !defined(__APPLE__)
350 unsigned int i_control_height = 0, i_control_width = 0;
355 return NPERR_INVALID_INSTANCE_ERROR;
358 /* NPP_SetWindow may be called before NPP_New (Opera) */
359 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
360 if( NULL == p_plugin )
362 /* we should probably show a splash screen here */
363 return NPERR_NO_ERROR;
366 #if defined(XP_UNIX) && !defined(__APPLE__)
367 control = p_plugin->getControlWindow();
370 libvlc_exception_t ex;
371 libvlc_exception_init(&ex);
373 libvlc_instance_t *p_vlc = p_plugin->getVLC();
377 * Before setting window to point to the
378 * new window, you may wish to compare the new window
379 * info to the previous window (if any) to note window
383 /* retrieve current window */
384 NPWindow& curwin = p_plugin->getWindow();
387 if( window && window->window )
389 /* check if plugin has a new parent window */
390 CGrafPtr drawable = (((NP_Port*) (window->window))->port);
391 if( !curwin.window || drawable != (((NP_Port*) (curwin.window))->port) )
393 /* set/change parent window */
394 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, &ex);
395 if( libvlc_exception_raised(&ex) )
396 fprintf( stderr, "Exception: %s\n", libvlc_exception_get_message(&ex) );
397 libvlc_exception_clear(&ex);
400 /* as MacOS X video output is windowless, set viewport */
401 libvlc_rectangle_t view, clip;
404 ** browser sets port origin to top-left location of plugin
405 ** relative to GrafPort window origin is set relative to document,
406 ** which of little use for drawing
408 view.top = ((NP_Port*) (window->window))->porty;
409 view.left = ((NP_Port*) (window->window))->portx;
410 view.bottom = window->height+view.top;
411 view.right = window->width+view.left;
413 /* clipRect coordinates are also relative to GrafPort */
414 clip.top = window->clipRect.top;
415 clip.left = window->clipRect.left;
416 clip.bottom = window->clipRect.bottom;
417 clip.right = window->clipRect.right;
419 libvlc_video_set_viewport(p_vlc, p_plugin->getMD(&ex), &view, &clip, &ex);
420 if( libvlc_exception_raised(&ex) )
421 fprintf( stderr, "Exception: %s\n", libvlc_exception_get_message(&ex) );
422 libvlc_exception_clear(&ex);
424 /* remember new window */
425 p_plugin->setWindow(*window);
427 else if( curwin.window )
429 /* change/set parent */
430 libvlc_video_set_parent(p_vlc, 0, &ex);
431 if( libvlc_exception_raised(&ex) )
432 fprintf( stderr, "Exception: %s\n", libvlc_exception_get_message(&ex) );
433 libvlc_exception_clear(&ex);
435 curwin.window = NULL;
437 #endif /* XP_MACOSX */
440 if( window && window->window )
442 /* check if plugin has a new parent window */
443 HWND drawable = (HWND) (window->window);
444 if( !curwin.window || drawable != curwin.window )
446 /* reset previous window settings */
447 HWND oldwin = (HWND)p_plugin->getWindow().window;
448 WNDPROC oldproc = p_plugin->getWindowProc();
452 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)oldproc );
454 /* attach our plugin object */
455 SetWindowLongPtr((HWND)drawable, GWLP_USERDATA,
456 reinterpret_cast<LONG_PTR>(p_plugin));
458 /* install our WNDPROC */
459 p_plugin->setWindowProc( (WNDPROC)SetWindowLong( drawable,
460 GWL_WNDPROC, (LONG)Manage ) );
462 /* change window style to our liking */
463 LONG style = GetWindowLong((HWND)drawable, GWL_STYLE);
464 style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
465 SetWindowLong((HWND)drawable, GWL_STYLE, style);
467 /* change/set parent */
468 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, &ex);
469 if( libvlc_exception_raised(&ex) )
470 fprintf( stderr, "Exception: %s\n", libvlc_exception_get_message(&ex) );
471 libvlc_exception_clear(&ex);
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);
488 /* change/set parent */
489 libvlc_video_set_parent(p_vlc, 0, &ex);
490 if( libvlc_exception_raised(&ex) )
491 fprintf( stderr, "Exception: %s\n", libvlc_exception_get_message(&ex) );
492 libvlc_exception_clear(&ex);
494 curwin.window = NULL;
499 /* default to hidden toolbar, shown at the end of this method if asked *
500 * developers note : getToolbarSize need to wait the end of this method
502 i_control_height = 0;
503 i_control_width = window->width;
505 if( window && window->window )
507 Window parent = (Window) window->window;
508 if( !curwin.window || (parent != (Window)curwin.window) )
510 Display *p_display = ( (NPSetWindowCallbackStruct *)
511 window->ws_info )->display;
513 XResizeWindow( p_display, parent, window->width, window->height );
515 int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
518 Window video = XCreateSimpleWindow( p_display, parent, 0, 0,
519 window->width, window->height - i_control_height,
520 0, i_blackColor, i_blackColor );
521 Window controls = (Window) NULL;
522 controls = XCreateSimpleWindow( p_display, parent,
523 0, window->height - i_control_height-1,
524 window->width, i_control_height-1,
525 0, i_blackColor, i_blackColor );
527 XMapWindow( p_display, parent );
528 XMapWindow( p_display, video );
529 if( controls ) { XMapWindow( p_display, controls ); }
534 Widget w = XtWindowToWidget( p_display, parent );
536 XtAddEventHandler( w, ExposureMask, FALSE,
537 (XtEventHandler)Redraw, p_plugin );
538 XtAddEventHandler( w, StructureNotifyMask, FALSE,
539 (XtEventHandler)Resize, p_plugin );
540 XtAddEventHandler( w, ButtonReleaseMask, FALSE,
541 (XtEventHandler)ControlHandler, p_plugin );
543 /* set/change parent window */
544 libvlc_video_set_parent( p_vlc, (libvlc_drawable_t) video, &ex );
545 if( libvlc_exception_raised(&ex) )
546 fprintf( stderr, "Exception: %s\n", libvlc_exception_get_message(&ex) );
547 libvlc_exception_clear(&ex);
549 /* remember window */
550 p_plugin->setWindow( *window );
551 p_plugin->setVideoWindow( video );
555 p_plugin->setControlWindow( controls );
558 Redraw( w, (XtPointer)p_plugin, NULL );
560 /* now display toolbar if asked through parameters */
561 if( p_plugin->b_toolbar )
563 p_plugin->showToolbar();
567 else if( curwin.window )
569 /* change/set parent */
570 libvlc_video_set_parent(p_vlc, 0, &ex);
571 if( libvlc_exception_raised(&ex) )
572 fprintf( stderr, "Exception: %s\n", libvlc_exception_get_message(&ex) );
573 libvlc_exception_clear(&ex);
574 curwin.window = NULL;
578 if( !p_plugin->b_stream )
580 if( p_plugin->psz_target )
582 if( p_plugin->playlist_add( p_plugin->psz_target, NULL ) != -1 )
584 if( p_plugin->b_autoplay )
586 p_plugin->playlist_play(NULL);
589 p_plugin->b_stream = true;
592 return NPERR_NO_ERROR;
595 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
596 NPBool seekable, uint16 *stype )
598 if( NULL == instance )
600 return NPERR_INVALID_INSTANCE_ERROR;
603 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
604 if( NULL == p_plugin )
606 return NPERR_INVALID_INSTANCE_ERROR;
610 ** Firefox/Mozilla may decide to open a stream from the URL specified
611 ** in the SRC parameter of the EMBED tag and pass it to us
613 ** since VLC will open the SRC URL as well, we're not interested in
614 ** that stream. Otherwise, we'll take it and queue it up in the playlist
616 if( !p_plugin->psz_target || strcmp(stream->url, p_plugin->psz_target) )
618 /* TODO: use pipes !!!! */
619 *stype = NP_ASFILEONLY;
620 return NPERR_NO_ERROR;
622 return NPERR_GENERIC_ERROR;
625 int32 NPP_WriteReady( NPP instance, NPStream *stream )
631 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
632 int32 len, void *buffer )
638 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
640 if( instance == NULL )
642 return NPERR_INVALID_INSTANCE_ERROR;
644 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( p_plugin->playlist_add( stream->url, NULL ) != -1 )
662 if( p_plugin->b_autoplay )
664 p_plugin->playlist_play(NULL);
669 void NPP_URLNotify( NPP instance, const char* url,
670 NPReason reason, void* notifyData )
672 /***** Insert NPP_URLNotify code here *****\
673 PluginInstance* p_plugin;
674 if (instance != NULL)
675 p_plugin = (PluginInstance*) instance->pdata;
676 \*********************************************/
679 void NPP_Print( NPP instance, NPPrint* printInfo )
681 if( printInfo == NULL )
686 if( instance != NULL )
688 /***** Insert NPP_Print code here *****\
689 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
690 \**************************************/
692 if( printInfo->mode == NP_FULL )
696 * If your plugin would like to take over
697 * printing completely when it is in full-screen mode,
698 * set printInfo->pluginPrinted to TRUE and print your
699 * plugin as you see fit. If your plugin wants Netscape
700 * to handle printing in this case, set
701 * printInfo->pluginPrinted to FALSE (the default) and
702 * do nothing. If you do want to handle printing
703 * yourself, printOne is true if the print button
704 * (as opposed to the print menu) was clicked.
705 * On the Macintosh, platformPrint is a THPrint; on
706 * Windows, platformPrint is a structure
707 * (defined in npapi.h) containing the printer name, port,
711 /***** Insert NPP_Print code here *****\
712 void* platformPrint =
713 printInfo->print.fullPrint.platformPrint;
715 printInfo->print.fullPrint.printOne;
716 \**************************************/
719 printInfo->print.fullPrint.pluginPrinted = FALSE;
723 /* If not fullscreen, we must be embedded */
726 * If your plugin is embedded, or is full-screen
727 * but you returned false in pluginPrinted above, NPP_Print
728 * will be called with mode == NP_EMBED. The NPWindow
729 * in the printInfo gives the location and dimensions of
730 * the embedded plugin on the printed page. On the
731 * Macintosh, platformPrint is the printer port; on
732 * Windows, platformPrint is the handle to the printing
736 /***** Insert NPP_Print code here *****\
737 NPWindow* printWindow =
738 &(printInfo->print.embedPrint.window);
739 void* platformPrint =
740 printInfo->print.embedPrint.platformPrint;
741 \**************************************/
746 /******************************************************************************
747 * Windows-only methods
748 *****************************************************************************/
750 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
752 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
761 PAINTSTRUCT paintstruct;
765 hdc = BeginPaint( p_hwnd, &paintstruct );
767 GetClientRect( p_hwnd, &rect );
769 FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
770 SetTextColor(hdc, RGB(255, 255, 255));
771 SetBkColor(hdc, RGB(0, 0, 0));
772 DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect,
773 DT_CENTER|DT_VCENTER|DT_SINGLELINE);
775 EndPaint( p_hwnd, &paintstruct );
779 /* delegate to default handler */
780 return CallWindowProc( p_plugin->getWindowProc(), p_hwnd,
786 /******************************************************************************
788 *****************************************************************************/
790 static void Redraw( Widget w, XtPointer closure, XEvent *event )
792 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
793 Window control = p_plugin->getControlWindow();
794 const NPWindow& window = p_plugin->getWindow();
797 unsigned int i_control_height, i_control_width;
799 if( p_plugin->b_toolbar )
800 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
802 i_control_height = i_control_width = 0;
804 Window video = p_plugin->getVideoWindow();
805 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
807 gcv.foreground = BlackPixel( p_display, 0 );
808 gc = XCreateGC( p_display, video, GCForeground, &gcv );
810 XFillRectangle( p_display, video, gc,
811 0, 0, window.width, window.height - i_control_height);
813 gcv.foreground = WhitePixel( p_display, 0 );
814 XChangeGC( p_display, gc, GCForeground, &gcv );
816 XDrawString( p_display, video, gc,
817 window.width / 2 - 40, (window.height - i_control_height) / 2,
818 WINDOW_TEXT, strlen(WINDOW_TEXT) );
819 XFreeGC( p_display, gc );
821 p_plugin->redrawToolbar();
824 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
826 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
827 const NPWindow& window = p_plugin->getWindow();
829 int i_height = window.height;
830 int i_width = window.width;
831 int i_xPos = event->xbutton.x;
832 int i_yPos = event->xbutton.y;
834 if( p_plugin && p_plugin->b_toolbar )
837 libvlc_exception_t ex;
839 libvlc_exception_init( &ex );
840 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
841 if( libvlc_exception_raised(&ex) )
842 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
843 libvlc_exception_clear( &ex );
845 i_playing = p_plugin->playlist_isplaying( &ex );
846 if( libvlc_exception_raised(&ex) )
847 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
848 libvlc_exception_clear( &ex );
850 vlc_toolbar_clicked_t clicked;
851 clicked = p_plugin->getToolbarButtonClicked( i_xPos, i_yPos );
858 p_plugin->playlist_pause( &ex );
860 p_plugin->playlist_play( &ex );
862 if( libvlc_exception_raised(&ex) )
863 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
864 libvlc_exception_clear( &ex );
870 p_plugin->playlist_stop(&ex);
871 if( libvlc_exception_raised(&ex) )
872 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
873 libvlc_exception_clear( &ex );
877 case clicked_Fullscreen:
879 p_plugin->set_fullscreen( 1, &ex );
880 if( libvlc_exception_raised(&ex) )
881 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
882 libvlc_exception_clear( &ex );
889 libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
890 if( libvlc_exception_raised(&ex) )
891 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
892 libvlc_exception_clear( &ex );
896 case clicked_timeline:
898 /* if a movie is loaded */
902 f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
903 libvlc_exception_clear( &ex );
905 f_length = (float)f_length *
906 ( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) );
908 libvlc_media_player_set_time( p_md, f_length, &ex );
909 if( libvlc_exception_raised(&ex) )
910 fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
911 libvlc_exception_clear( &ex );
918 /* Not implemented yet*/
922 default: /* button_Unknown */
926 Redraw( w, closure, event );
929 static void Resize ( Widget w, XtPointer closure, XEvent *event )
931 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
932 Window control = p_plugin->getControlWindow();
933 const NPWindow& window = p_plugin->getWindow();
934 Window drawable = p_plugin->getVideoWindow();
935 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
938 Window root_return, parent_return, * children_return;
940 unsigned int i_nchildren;
941 unsigned int i_control_height, i_control_width;
943 if( p_plugin->b_toolbar )
945 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
949 i_control_height = i_control_width = 0;
952 #ifdef X11_RESIZE_DEBUG
953 XWindowAttributes attr;
955 if( event && event->type == ConfigureNotify )
957 fprintf( stderr, "vlcshell::Resize() ConfigureNotify %d x %d, "
958 "send_event ? %s\n", event->xconfigure.width,
959 event->xconfigure.height,
960 event->xconfigure.send_event ? "TRUE" : "FALSE" );
962 #endif /* X11_RESIZE_DEBUG */
964 if( ! p_plugin->setSize(window.width, (window.height - i_control_height)) )
966 /* size already set */
970 i_ret = XResizeWindow( p_display, drawable,
971 window.width, (window.height - i_control_height) );
973 #ifdef X11_RESIZE_DEBUG
975 "vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret );
977 XGetWindowAttributes ( p_display, drawable, &attr );
979 /* X is asynchronous, so the current size reported here is not
980 necessarily the requested size as the Resize request may not
981 yet have been handled by the plugin host */
982 fprintf( stderr, "vlcshell::Resize() current (owner) size %d x %d\n",
983 attr.width, attr.height );
984 #endif /* X11_RESIZE_DEBUG */
986 XQueryTree( p_display, drawable,
987 &root_return, &parent_return, &children_return,
990 if( i_nchildren > 0 )
992 /* XXX: Make assumptions related to the window parenting structure in
993 vlc/modules/video_output/x11/xcommon.c */
994 base_window = children_return[i_nchildren - 1];
996 #ifdef X11_RESIZE_DEBUG
997 fprintf( stderr, "vlcshell::Resize() got %d children\n", i_nchildren );
998 fprintf( stderr, "vlcshell::Resize() got base_window %p\n",
1000 #endif /* X11_RESIZE_DEBUG */
1002 i_ret = XResizeWindow( p_display, base_window,
1003 window.width, ( window.height - i_control_height ) );
1005 #ifdef X11_RESIZE_DEBUG
1007 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
1010 XGetWindowAttributes( p_display, base_window, &attr );
1012 fprintf( stderr, "vlcshell::Resize() new size %d x %d\n",
1013 attr.width, attr.height );
1014 #endif /* X11_RESIZE_DEBUG */
1018 #endif /* XP_UNIX */