Don't use vlc_int64_t. It no longer exist.
[vlc.git] / projects / mozilla / vlcshell.cpp
blob0dbc3a07356262b734fba8ec4eee8893b22ce65c
1 /*****************************************************************************
2 * vlcshell.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2005 the VideoLAN team
5 * $Id$
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 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #include "config.h"
29 #include <stdio.h>
30 #include <string.h>
31 #include <stdlib.h>
33 /* Mozilla stuff */
34 #ifdef HAVE_MOZILLA_CONFIG_H
35 # include <mozilla-config.h>
36 #endif
38 /* This is from mozilla java, do we really need it? */
39 #if 0
40 #include <jri.h>
41 #endif
43 #include "vlcplugin.h"
45 /* Enable/disable debugging printf's for X11 resizing */
46 #undef X11_RESIZE_DEBUG
48 #define WINDOW_TEXT "Video is loading..."
50 /*****************************************************************************
51 * Unix-only declarations
52 ******************************************************************************/
53 #ifdef XP_UNIX
55 static void Redraw( Widget w, XtPointer closure, XEvent *event );
56 static void ControlHandler( Widget w, XtPointer closure, XEvent *event );
57 static void Resize( Widget w, XtPointer closure, XEvent *event );
59 #endif
61 /*****************************************************************************
62 * MacOS-only declarations
63 ******************************************************************************/
64 #ifdef XP_MACOSX
65 #endif
67 /*****************************************************************************
68 * Windows-only declarations
69 *****************************************************************************/
70 #ifdef XP_WIN
72 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );
74 #endif
76 /******************************************************************************
77 * UNIX-only API calls
78 *****************************************************************************/
79 char * NPP_GetMIMEDescription( void )
81 return PLUGIN_MIMETYPES;
84 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
87 static char psz_desc[1000];
89 /* plugin class variables */
90 switch( variable )
92 case NPPVpluginNameString:
93 *((char **)value) = PLUGIN_NAME;
94 return NPERR_NO_ERROR;
96 case NPPVpluginDescriptionString:
97 snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION,
98 VLC_Version() );
99 *((char **)value) = psz_desc;
100 return NPERR_NO_ERROR;
102 default:
103 /* move on to instance variables ... */
107 if( instance == NULL )
109 return NPERR_INVALID_INSTANCE_ERROR;
112 /* plugin instance variables */
114 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
115 if( NULL == p_plugin )
117 // plugin has not been initialized yet !
118 return NPERR_INVALID_INSTANCE_ERROR;
121 switch( variable )
123 case NPPVpluginScriptableNPObject:
125 /* retrieve plugin root class */
126 NPClass *scriptClass = p_plugin->getScriptClass();
127 if( scriptClass )
129 /* create an instance and return it */
130 *(NPObject**)value = NPN_CreateObject(instance, scriptClass);
131 return NPERR_NO_ERROR;
133 break;
136 default:
139 return NPERR_GENERIC_ERROR;
143 * there is some confusion in gecko headers regarding definition of this API
144 * NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
147 NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
149 return NPERR_GENERIC_ERROR;
152 /******************************************************************************
153 * Mac-only API calls
154 *****************************************************************************/
155 #ifdef XP_MACOSX
156 int16 NPP_HandleEvent( NPP instance, void * event )
158 static UInt32 lastMouseUp = 0;
160 if( instance == NULL )
162 return false;
165 VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
167 if( p_plugin == NULL )
169 return false;
172 EventRecord *myEvent = (EventRecord*)event;
174 switch( myEvent->what )
176 case nullEvent:
177 return true;
178 case mouseDown:
180 if( (myEvent->when - lastMouseUp) < GetDblTime() )
182 /* double click */
183 libvlc_instance_t *p_vlc = p_plugin->getVLC();
185 if( p_vlc )
187 if( libvlc_playlist_isplaying(p_vlc, NULL) )
189 libvlc_media_player_t *p_md =
190 libvlc_playlist_get_media_player(p_vlc, NULL);
191 if( p_md )
193 libvlc_toggle_fullscreen(p_md, NULL);
194 libvlc_media_player_release(p_md);
199 return true;
201 case mouseUp:
202 lastMouseUp = myEvent->when;
203 return true;
204 case keyUp:
205 case keyDown:
206 case autoKey:
207 return true;
208 case updateEvt:
210 const NPWindow& npwindow = p_plugin->getWindow();
211 if( npwindow.window )
213 int hasVout = FALSE;
214 libvlc_instance_t *p_vlc = p_plugin->getVLC();
216 if( p_vlc )
218 if( libvlc_playlist_isplaying(p_vlc, NULL) )
220 libvlc_media_player_t *p_md =
221 libvlc_playlist_get_media_player(p_vlc, NULL);
222 if( p_md )
224 hasVout = libvlc_media_player_has_vout(p_md,
225 NULL);
226 if( hasVout )
228 libvlc_rectangle_t area;
229 area.left = 0;
230 area.top = 0;
231 area.right = npwindow.width;
232 area.bottom = npwindow.height;
233 libvlc_video_redraw_rectangle(p_md, &area,
234 NULL);
236 libvlc_media_player_release(p_md);
241 if( ! hasVout )
243 /* draw the beautiful "No Picture" */
245 ForeColor(blackColor);
246 PenMode( patCopy );
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);
253 Rect rect;
254 rect.left = 0;
255 rect.top = 0;
256 rect.right = npwindow.width;
257 rect.bottom = npwindow.height;
258 PaintRect( &rect );
260 ForeColor(whiteColor);
261 MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
262 DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
265 return true;
267 case activateEvt:
268 return false;
269 case NPEventType_GetFocusEvent:
270 case NPEventType_LoseFocusEvent:
271 return true;
272 case NPEventType_AdjustCursorEvent:
273 return false;
274 case NPEventType_MenuCommandEvent:
275 return false;
276 case NPEventType_ClippingChangedEvent:
277 return false;
278 case NPEventType_ScrollingBeginsEvent:
279 return true;
280 case NPEventType_ScrollingEndsEvent:
281 return true;
282 default:
285 return false;
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 )
299 return NULL;
302 void NPP_Shutdown( void )
307 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
308 char* argn[], char* argv[], NPSavedData* saved )
310 NPError status;
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);
327 #if 0
328 NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
329 NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
330 #endif
332 else
334 delete p_plugin;
336 return status;
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;
350 #if XP_WIN
351 HWND win = (HWND)p_plugin->getWindow().window;
352 WNDPROC winproc = p_plugin->getWindowProc();
353 if( winproc )
355 /* reset WNDPROC */
356 SetWindowLong( win, GWL_WNDPROC, (LONG)winproc );
358 #endif
360 delete p_plugin;
362 return NPERR_NO_ERROR;
365 NPError NPP_SetWindow( NPP instance, NPWindow* window )
367 #ifdef XP_UNIX && !defined(__APPLE__)
368 Window control;
369 unsigned int i_control_height = 0, i_control_width = 0;
370 #endif
372 if( ! instance )
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 #ifdef XP_UNIX && !defined(__APPLE__)
385 control = p_plugin->getControlWindow();
386 #endif
387 libvlc_instance_t *p_vlc = p_plugin->getVLC();
390 * PLUGIN DEVELOPERS:
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
394 * size changes, etc.
397 /* retrieve current window */
398 NPWindow& curwin = p_plugin->getWindow();
400 #ifdef XP_MACOSX
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 */
441 #ifdef XP_WIN
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();
451 if( oldproc )
453 /* reset WNDPROC */
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);
475 /* Redraw window */
476 InvalidateRect( (HWND)drawable, NULL, TRUE );
477 UpdateWindow( (HWND)drawable );
480 else if ( curwin.window )
482 /* reset WNDPROC */
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;
490 #endif /* XP_WIN */
492 #ifdef XP_UNIX
493 if( p_plugin->b_toolbar )
495 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
497 else
499 i_control_height = i_control_width = 0;
502 if( window && window->window )
504 Window parent = (Window) window->window;
505 if( !curwin.window || (parent != (Window)curwin.window) )
507 Display *p_display = ( (NPSetWindowCallbackStruct *)
508 window->ws_info )->display;
510 XResizeWindow( p_display, parent, window->width, window->height );
512 int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
514 /* create windows */
515 Window video = XCreateSimpleWindow( p_display, parent, 0, 0,
516 window->width, window->height - i_control_height,
517 0, i_blackColor, i_blackColor );
518 Window controls = (Window) NULL;
519 if( p_plugin->b_toolbar )
521 controls = XCreateSimpleWindow( p_display, parent,
522 0, window->height - i_control_height-1,
523 window->width, i_control_height-1,
524 0, i_blackColor, i_blackColor );
527 XMapWindow( p_display, parent );
528 XMapWindow( p_display, video );
529 if( controls ) { XMapWindow( p_display, controls ); }
531 XFlush(p_display);
533 /* bind events */
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 /* callback */
545 libvlc_media_player_t *p_md;
547 libvlc_exception_t ex;
548 libvlc_exception_init(& ex );
549 p_md = libvlc_playlist_get_media_player( p_plugin->getVLC(), &ex );
550 libvlc_exception_init( &ex );
551 libvlc_event_attach( libvlc_media_player_event_manager( p_md, &ex ),
552 libvlc_MediaPlayerPositionChanged, Redraw, NULL, &ex );
555 /* set/change parent window */
556 libvlc_video_set_parent( p_vlc, (libvlc_drawable_t) video, NULL );
558 /* remember window */
559 p_plugin->setWindow( *window );
560 p_plugin->setVideoWindow( video );
561 if( controls ) { p_plugin->setControlWindow( controls ); }
563 Redraw( w, (XtPointer)p_plugin, NULL );
566 else if ( curwin.window )
568 /* change/set parent */
569 libvlc_video_set_parent(p_vlc, 0, NULL);
570 curwin.window = NULL;
572 #endif /* XP_UNIX */
574 if( !p_plugin->b_stream )
576 if( p_plugin->psz_target )
578 if( libvlc_playlist_add( p_vlc, p_plugin->psz_target,
579 NULL, NULL ) != -1 )
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 )
624 /* TODO */
625 return 8*1024;
629 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
630 int32 len, void *buffer )
632 /* TODO */
633 return len;
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 )
651 return;
654 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
655 if( NULL == p_plugin )
657 return;
660 if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL )
661 != -1 )
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 )
686 return;
689 if( instance != NULL )
691 /***** Insert NPP_Print code here *****\
692 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
693 \**************************************/
695 if( printInfo->mode == NP_FULL )
698 * PLUGIN DEVELOPERS:
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,
711 * etc.
714 /***** Insert NPP_Print code here *****\
715 void* platformPrint =
716 printInfo->print.fullPrint.platformPrint;
717 NPBool printOne =
718 printInfo->print.fullPrint.printOne;
719 \**************************************/
721 /* Do the default*/
722 printInfo->print.fullPrint.pluginPrinted = FALSE;
724 else
726 /* If not fullscreen, we must be embedded */
728 * PLUGIN DEVELOPERS:
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
736 * device context.
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 *****************************************************************************/
752 #if XP_WIN
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));
757 switch( i_msg )
759 case WM_ERASEBKGND:
760 return 1L;
762 case WM_PAINT:
764 PAINTSTRUCT paintstruct;
765 HDC hdc;
766 RECT rect;
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 );
779 return 0L;
781 default:
782 /* delegate to default handler */
783 return CallWindowProc( p_plugin->getWindowProc(), p_hwnd,
784 i_msg, wpar, lpar );
787 #endif /* XP_WIN */
789 /******************************************************************************
790 * UNIX-only methods
791 *****************************************************************************/
792 #ifdef XP_UNIX
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();
798 GC gc;
799 XGCValues gcv;
800 unsigned int i_control_height, i_control_width;
802 if( p_plugin->b_toolbar )
804 p_plugin->showToolbar();
805 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
807 else
808 i_control_height = i_control_width = 0;
810 Window video = p_plugin->getVideoWindow();
811 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
813 gcv.foreground = BlackPixel( p_display, 0 );
814 gc = XCreateGC( p_display, video, GCForeground, &gcv );
816 XFillRectangle( p_display, video, gc,
817 0, 0, window.width, window.height - i_control_height);
819 gcv.foreground = WhitePixel( p_display, 0 );
820 XChangeGC( p_display, gc, GCForeground, &gcv );
822 XDrawString( p_display, video, gc,
823 window.width / 2 - 40, (window.height - i_control_height) / 2,
824 WINDOW_TEXT, strlen(WINDOW_TEXT) );
825 XFreeGC( p_display, gc );
827 if( p_plugin->b_toolbar )
829 p_plugin->redrawToolbar();
830 p_plugin->hideToolbar();
834 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
836 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
837 const NPWindow& window = p_plugin->getWindow();
839 int i_height = window.height;
840 int i_width = window.width;
841 int i_xPos = event->xbutton.x;
842 int i_yPos = event->xbutton.y;
844 if( p_plugin && p_plugin->b_toolbar )
846 libvlc_exception_t ex;
847 libvlc_exception_init( &ex );
848 libvlc_media_player_t *p_md =
849 libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
850 libvlc_exception_clear( &ex );
852 /* jump in the movie */
853 if( i_yPos <= (i_height-30) )
855 /* if a movie is loaded */
856 if( p_md )
858 int64_t f_length;
859 libvlc_exception_init( &ex );
860 f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
861 libvlc_exception_clear( &ex );
863 f_length = (float)f_length *
864 ( ((float)i_xPos-4 ) / ( ((float)i_width-8)/100) );
866 libvlc_exception_init( &ex );
867 libvlc_media_player_set_time( p_md, f_length, &ex );
868 libvlc_exception_clear( &ex );
872 /* play/pause toggle */
873 if( (i_yPos > (i_height-30)) && (i_xPos > 4) && (i_xPos <= 39) )
875 int i_playing;
876 libvlc_exception_init( &ex );
877 i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
878 libvlc_exception_clear( &ex );
880 libvlc_exception_init( &ex );
881 if( i_playing == 1 )
882 libvlc_playlist_pause( p_plugin->getVLC(), &ex );
883 else
884 libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
885 libvlc_exception_clear( &ex );
888 /* stop */
889 if( (i_yPos > (i_height-30)) && (i_xPos > 39) && (i_xPos < 67) )
891 libvlc_exception_init( &ex );
892 libvlc_playlist_stop( p_plugin->getVLC(), &ex );
893 libvlc_exception_clear( &ex );
896 /* fullscreen */
897 if( (i_yPos > (i_height-30)) && (i_xPos >= 67) && (i_xPos < 94) )
899 int i_playing;
900 libvlc_exception_init( &ex );
901 i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
902 libvlc_exception_clear( &ex );
904 if( (i_playing == 1) && p_md )
906 libvlc_exception_init( &ex );
907 libvlc_set_fullscreen( p_md, 1, &ex );
908 libvlc_exception_clear( &ex );
912 /* mute toggle */
913 if( (i_yPos > (i_height-30)) && (i_xPos >= 94) && (i_xPos < 109))
915 libvlc_exception_init( &ex );
916 libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
917 libvlc_exception_clear( &ex );
920 if( p_md ) libvlc_media_player_release( p_md );
922 Redraw( w, closure, event );
925 static void Resize ( Widget w, XtPointer closure, XEvent *event )
927 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
928 Window control = p_plugin->getControlWindow();
929 const NPWindow& window = p_plugin->getWindow();
930 Window drawable = p_plugin->getVideoWindow();
931 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
933 int i_ret;
934 Window root_return, parent_return, * children_return;
935 Window base_window;
936 unsigned int i_nchildren;
937 unsigned int i_control_height, i_control_width;
939 if( p_plugin->b_toolbar )
941 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
943 else
945 i_control_height = i_control_width = 0;
948 #ifdef X11_RESIZE_DEBUG
949 XWindowAttributes attr;
951 if( event && event->type == ConfigureNotify )
953 fprintf( stderr, "vlcshell::Resize() ConfigureNotify %d x %d, "
954 "send_event ? %s\n", event->xconfigure.width,
955 event->xconfigure.height,
956 event->xconfigure.send_event ? "TRUE" : "FALSE" );
958 #endif /* X11_RESIZE_DEBUG */
960 if( ! p_plugin->setSize(window.width, (window.height - i_control_height)) )
962 /* size already set */
963 return;
966 i_ret = XResizeWindow( p_display, drawable,
967 window.width, (window.height - i_control_height) );
969 #ifdef X11_RESIZE_DEBUG
970 fprintf( stderr,
971 "vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret );
973 XGetWindowAttributes ( p_display, drawable, &attr );
975 /* X is asynchronous, so the current size reported here is not
976 necessarily the requested size as the Resize request may not
977 yet have been handled by the plugin host */
978 fprintf( stderr, "vlcshell::Resize() current (owner) size %d x %d\n",
979 attr.width, attr.height );
980 #endif /* X11_RESIZE_DEBUG */
982 XQueryTree( p_display, drawable,
983 &root_return, &parent_return, &children_return,
984 &i_nchildren );
986 if( i_nchildren > 0 )
988 /* XXX: Make assumptions related to the window parenting structure in
989 vlc/modules/video_output/x11/xcommon.c */
990 base_window = children_return[i_nchildren - 1];
992 #ifdef X11_RESIZE_DEBUG
993 fprintf( stderr, "vlcshell::Resize() got %d children\n", i_nchildren );
994 fprintf( stderr, "vlcshell::Resize() got base_window %p\n",
995 base_window );
996 #endif /* X11_RESIZE_DEBUG */
998 i_ret = XResizeWindow( p_display, base_window,
999 window.width, ( window.height - i_control_height ) );
1001 #ifdef X11_RESIZE_DEBUG
1002 fprintf( stderr,
1003 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
1004 i_ret );
1006 XGetWindowAttributes( p_display, base_window, &attr );
1008 fprintf( stderr, "vlcshell::Resize() new size %d x %d\n",
1009 attr.width, attr.height );
1010 #endif /* X11_RESIZE_DEBUG */
1014 #endif /* XP_UNIX */