remove unneeded code
[vlc/asuraparaju-public.git] / projects / mozilla / vlcshell.cpp
blob7adfca67c9d83655107076cb16175d503105736d
1 /*****************************************************************************
2 * vlcshell.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2008 the VideoLAN team
5 * $Id$
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 /*****************************************************************************
26 * Preamble
27 *****************************************************************************/
28 #include "config.h"
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
34 /* Mozilla stuff */
35 #ifdef HAVE_MOZILLA_CONFIG_H
36 # include <mozilla-config.h>
37 #endif
39 /* This is from mozilla java, do we really need it? */
40 #if 0
41 #include <jri.h>
42 #endif
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 ******************************************************************************/
54 #ifdef XP_UNIX
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 );
60 #endif
62 /*****************************************************************************
63 * MacOS-only declarations
64 ******************************************************************************/
65 #ifdef XP_MACOSX
66 #endif
68 /*****************************************************************************
69 * Windows-only declarations
70 *****************************************************************************/
71 #ifdef XP_WIN
73 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );
75 #endif
77 /******************************************************************************
78 * UNIX-only API calls
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 */
91 switch( variable )
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;
103 default:
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;
122 switch( variable )
124 case NPPVpluginScriptableNPObject:
126 /* retrieve plugin root class */
127 NPClass *scriptClass = p_plugin->getScriptClass();
128 if( scriptClass )
130 /* create an instance and return it */
131 *(NPObject**)value = NPN_CreateObject(instance, scriptClass);
132 return NPERR_NO_ERROR;
134 break;
137 default:
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 /******************************************************************************
154 * Mac-only API calls
155 *****************************************************************************/
156 #ifdef XP_MACOSX
157 int16 NPP_HandleEvent( NPP instance, void * event )
159 static UInt32 lastMouseUp = 0;
161 if( instance == NULL )
163 return false;
166 VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
168 if( p_plugin == NULL )
170 return false;
173 EventRecord *myEvent = (EventRecord*)event;
175 switch( myEvent->what )
177 case nullEvent:
178 return true;
179 case mouseDown:
181 if( (myEvent->when - lastMouseUp) < GetDblTime() )
183 /* double click */
184 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 #if defined(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 #if defined(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 /* 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));
511 /* create windows */
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 ); }
525 XFlush(p_display);
527 /* bind events */
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 );
537 /* callback */
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;
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 )
803 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
804 else
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 )
839 int i_playing;
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 );
856 switch( clicked )
858 case clicked_Play:
859 case clicked_Pause:
861 if( i_playing == 1 )
862 libvlc_playlist_pause( p_plugin->getVLC(), &ex );
863 else
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 );
870 break;
872 case clicked_Stop:
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 );
879 break;
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 );
891 break;
893 case clicked_Mute:
894 case clicked_Unmute:
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 );
901 break;
903 case clicked_timeline:
905 /* if a movie is loaded */
906 if( p_md )
908 int64_t f_length;
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 );
921 break;
923 case clicked_Time:
925 /* Not implemented yet*/
927 break;
929 default: /* button_Unknown */
930 break;
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;
945 int i_ret;
946 Window root_return, parent_return, * children_return;
947 Window base_window;
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 );
955 else
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 */
975 return;
978 i_ret = XResizeWindow( p_display, drawable,
979 window.width, (window.height - i_control_height) );
981 #ifdef X11_RESIZE_DEBUG
982 fprintf( stderr,
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,
996 &i_nchildren );
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",
1007 base_window );
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
1014 fprintf( stderr,
1015 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
1016 i_ret );
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 */