Load the pictures from the good place
[vlc/vlc-skelet.git] / mozilla / vlcshell.cpp
blob3268b09bc5f656dc2456c973d13c9434129a1b82
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 #ifdef XP_UNIX
39 #ifndef __APPLE__
40 #include <X11/xpm.h>
41 #endif
42 #endif
44 /* This is from mozilla java, do we really need it? */
45 #if 0
46 #include <jri.h>
47 #endif
49 #include "vlcplugin.h"
51 /* Enable/disable debugging printf's for X11 resizing */
52 #undef X11_RESIZE_DEBUG
54 #define WINDOW_TEXT "Video is loading..."
55 #define CONTROL_HEIGHT 45
57 /*****************************************************************************
58 * Unix-only declarations
59 ******************************************************************************/
60 #ifdef XP_UNIX
62 static void Redraw( Widget w, XtPointer closure, XEvent *event );
63 static void ControlHandler( Widget w, XtPointer closure, XEvent *event );
64 static void Resize( Widget w, XtPointer closure, XEvent *event );
66 #endif
68 /*****************************************************************************
69 * MacOS-only declarations
70 ******************************************************************************/
71 #ifdef XP_MACOSX
72 #endif
74 /*****************************************************************************
75 * Windows-only declarations
76 *****************************************************************************/
77 #ifdef XP_WIN
79 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );
81 #endif
83 /******************************************************************************
84 * UNIX-only API calls
85 *****************************************************************************/
86 char * NPP_GetMIMEDescription( void )
88 return PLUGIN_MIMETYPES;
91 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
94 static char psz_desc[1000];
96 /* plugin class variables */
97 switch( variable )
99 case NPPVpluginNameString:
100 *((char **)value) = PLUGIN_NAME;
101 return NPERR_NO_ERROR;
103 case NPPVpluginDescriptionString:
104 snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION, VLC_Version() );
105 *((char **)value) = psz_desc;
106 return NPERR_NO_ERROR;
108 default:
109 /* move on to instance variables ... */
113 if( instance == NULL )
115 return NPERR_INVALID_INSTANCE_ERROR;
118 /* plugin instance variables */
120 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
121 if( NULL == p_plugin )
123 // plugin has not been initialized yet !
124 return NPERR_INVALID_INSTANCE_ERROR;
127 switch( variable )
129 case NPPVpluginScriptableNPObject:
131 /* retrieve plugin root class */
132 NPClass *scriptClass = p_plugin->getScriptClass();
133 if( scriptClass )
135 /* create an instance and return it */
136 *(NPObject**)value = NPN_CreateObject(instance, scriptClass);
137 return NPERR_NO_ERROR;
139 break;
142 default:
145 return NPERR_GENERIC_ERROR;
149 * there is some confusion in gecko headers regarding definition of this API
150 * NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
153 NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
155 return NPERR_GENERIC_ERROR;
158 /******************************************************************************
159 * Mac-only API calls
160 *****************************************************************************/
161 #ifdef XP_MACOSX
162 int16 NPP_HandleEvent( NPP instance, void * event )
164 static UInt32 lastMouseUp = 0;
166 if( instance == NULL )
168 return false;
171 VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
173 if( p_plugin == NULL )
175 return false;
178 EventRecord *myEvent = (EventRecord*)event;
180 switch( myEvent->what )
182 case nullEvent:
183 return true;
184 case mouseDown:
186 if( (myEvent->when - lastMouseUp) < GetDblTime() )
188 /* double click */
189 libvlc_instance_t *p_vlc = p_plugin->getVLC();
191 if( p_vlc )
193 if( libvlc_playlist_isplaying(p_vlc, NULL) )
195 libvlc_media_instance_t *p_md =
196 libvlc_playlist_get_media_instance(p_vlc, NULL);
197 if( p_md )
199 libvlc_toggle_fullscreen(p_md, NULL);
200 libvlc_media_instance_release(p_md);
205 return true;
207 case mouseUp:
208 lastMouseUp = myEvent->when;
209 return true;
210 case keyUp:
211 case keyDown:
212 case autoKey:
213 return true;
214 case updateEvt:
216 const NPWindow& npwindow = p_plugin->getWindow();
217 if( npwindow.window )
219 int hasVout = FALSE;
220 libvlc_instance_t *p_vlc = p_plugin->getVLC();
222 if( p_vlc )
224 if( libvlc_playlist_isplaying(p_vlc, NULL) )
226 libvlc_media_instance_t *p_md =
227 libvlc_playlist_get_media_instance(p_vlc, NULL);
228 if( p_md )
230 hasVout = libvlc_media_instance_has_vout(p_md, NULL);
231 if( hasVout )
233 libvlc_rectangle_t area;
234 area.left = 0;
235 area.top = 0;
236 area.right = npwindow.width;
237 area.bottom = npwindow.height;
238 libvlc_video_redraw_rectangle(p_md, &area, NULL);
240 libvlc_media_instance_release(p_md);
245 if( ! hasVout )
247 /* draw the beautiful "No Picture" */
249 ForeColor(blackColor);
250 PenMode( patCopy );
252 /* seems that firefox forgets to set the following on occasion (reload) */
253 SetOrigin(((NP_Port *)npwindow.window)->portx,
254 ((NP_Port *)npwindow.window)->porty);
256 Rect rect;
257 rect.left = 0;
258 rect.top = 0;
259 rect.right = npwindow.width;
260 rect.bottom = npwindow.height;
261 PaintRect( &rect );
263 ForeColor(whiteColor);
264 MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
265 DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
268 return true;
270 case activateEvt:
271 return false;
272 case NPEventType_GetFocusEvent:
273 case NPEventType_LoseFocusEvent:
274 return true;
275 case NPEventType_AdjustCursorEvent:
276 return false;
277 case NPEventType_MenuCommandEvent:
278 return false;
279 case NPEventType_ClippingChangedEvent:
280 return false;
281 case NPEventType_ScrollingBeginsEvent:
282 return true;
283 case NPEventType_ScrollingEndsEvent:
284 return true;
285 default:
288 return false;
290 #endif /* XP_MACOSX */
292 /******************************************************************************
293 * General Plug-in Calls
294 *****************************************************************************/
295 NPError NPP_Initialize( void )
297 return NPERR_NO_ERROR;
300 jref NPP_GetJavaClass( void )
302 return NULL;
305 void NPP_Shutdown( void )
310 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
311 char* argn[], char* argv[], NPSavedData* saved )
313 NPError status;
315 if( instance == NULL )
317 return NPERR_INVALID_INSTANCE_ERROR;
320 VlcPlugin * p_plugin = new VlcPlugin( instance, mode );
321 if( NULL == p_plugin )
323 return NPERR_OUT_OF_MEMORY_ERROR;
326 status = p_plugin->init(argc, argn, argv);
327 if( NPERR_NO_ERROR == status )
329 instance->pdata = reinterpret_cast<void*>(p_plugin);
330 #if 0
331 NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
332 NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
333 #endif
335 else
337 delete p_plugin;
339 return status;
342 NPError NPP_Destroy( NPP instance, NPSavedData** save )
344 if( NULL == instance )
345 return NPERR_INVALID_INSTANCE_ERROR;
347 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
348 if( NULL == p_plugin )
349 return NPERR_NO_ERROR;
351 instance->pdata = NULL;
353 #if XP_WIN
354 HWND win = (HWND)p_plugin->getWindow().window;
355 WNDPROC winproc = p_plugin->getWindowProc();
356 if( winproc )
358 /* reset WNDPROC */
359 SetWindowLong( win, GWL_WNDPROC, (LONG)winproc );
361 #endif
363 delete p_plugin;
365 return NPERR_NO_ERROR;
368 NPError NPP_SetWindow( NPP instance, NPWindow* window )
370 if( ! instance )
372 return NPERR_INVALID_INSTANCE_ERROR;
375 /* NPP_SetWindow may be called before NPP_New (Opera) */
376 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
377 if( ! p_plugin )
379 /* we should probably show a splash screen here */
380 return NPERR_NO_ERROR;
383 libvlc_instance_t *p_vlc = p_plugin->getVLC();
386 * PLUGIN DEVELOPERS:
387 * Before setting window to point to the
388 * new window, you may wish to compare the new window
389 * info to the previous window (if any) to note window
390 * size changes, etc.
393 /* retrieve current window */
394 NPWindow& curwin = p_plugin->getWindow();
396 #ifdef XP_MACOSX
397 if( window && window->window )
399 /* check if plugin has a new parent window */
400 CGrafPtr drawable = (((NP_Port*) (window->window))->port);
401 if( !curwin.window || drawable != (((NP_Port*) (curwin.window))->port) )
403 /* set/change parent window */
404 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
407 /* as MacOS X video output is windowless, set viewport */
408 libvlc_rectangle_t view, clip;
411 ** browser sets port origin to top-left location of plugin relative to GrafPort
412 ** window origin is set relative to document, which of little use for drawing
414 view.top = ((NP_Port*) (window->window))->porty;
415 view.left = ((NP_Port*) (window->window))->portx;
416 view.bottom = window->height+view.top;
417 view.right = window->width+view.left;
418 /* clipRect coordinates are also relative to GrafPort */
419 clip.top = window->clipRect.top;
420 clip.left = window->clipRect.left;
421 clip.bottom = window->clipRect.bottom;
422 clip.right = window->clipRect.right;
424 libvlc_video_set_viewport(p_vlc, &view, &clip, NULL);
426 /* remember new window */
427 p_plugin->setWindow(*window);
429 else if( curwin.window ) {
430 /* change/set parent */
431 libvlc_video_set_parent(p_vlc, 0, NULL);
432 curwin.window = NULL;
434 #endif /* XP_MACOSX */
436 #ifdef XP_WIN
437 if( window && window->window )
439 /* check if plugin has a new parent window */
440 HWND drawable = (HWND) (window->window);
441 if( !curwin.window || drawable != curwin.window )
443 /* reset previous window settings */
444 HWND oldwin = (HWND)p_plugin->getWindow().window;
445 WNDPROC oldproc = p_plugin->getWindowProc();
446 if( oldproc )
448 /* reset WNDPROC */
449 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)oldproc );
451 /* attach our plugin object */
452 SetWindowLongPtr((HWND)drawable, GWLP_USERDATA,
453 reinterpret_cast<LONG_PTR>(p_plugin));
455 /* install our WNDPROC */
456 p_plugin->setWindowProc( (WNDPROC)SetWindowLong( drawable,
457 GWL_WNDPROC, (LONG)Manage ) );
459 /* change window style to our liking */
460 LONG style = GetWindowLong((HWND)drawable, GWL_STYLE);
461 style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
462 SetWindowLong((HWND)drawable, GWL_STYLE, style);
464 /* change/set parent */
465 libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
467 /* remember new window */
468 p_plugin->setWindow(*window);
470 /* Redraw window */
471 InvalidateRect( (HWND)drawable, NULL, TRUE );
472 UpdateWindow( (HWND)drawable );
475 else if ( curwin.window )
477 /* reset WNDPROC */
478 HWND oldwin = (HWND)curwin.window;
479 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) );
480 p_plugin->setWindowProc(NULL);
481 /* change/set parent */
482 libvlc_video_set_parent(p_vlc, 0, NULL);
483 curwin.window = NULL;
485 #endif /* XP_WIN */
487 #ifdef XP_UNIX
488 if( window && window->window )
490 Window parent = (Window) window->window;
491 if( !curwin.window || (parent != (Window)curwin.window) )
493 Display *p_display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
495 XResizeWindow( p_display, parent, window->width, window->height );
497 int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
499 Window video = XCreateSimpleWindow( p_display, parent, 0, 0,
500 window->width, window->height - CONTROL_HEIGHT, 0,
501 i_blackColor, i_blackColor );
502 Window controls = XCreateSimpleWindow( p_display, parent, 0,
503 window->height - CONTROL_HEIGHT-1, window->width,
504 CONTROL_HEIGHT-1, 0, i_blackColor, i_blackColor );
506 XMapWindow( p_display, parent );
507 XMapWindow( p_display, video );
508 XMapWindow( p_display, controls );
510 XFlush(p_display);
512 Widget w = XtWindowToWidget( p_display, parent );
514 XtAddEventHandler( w, ExposureMask, FALSE,
515 (XtEventHandler)Redraw, p_plugin );
516 XtAddEventHandler( w, StructureNotifyMask, FALSE,
517 (XtEventHandler)Resize, p_plugin );
518 XtAddEventHandler( w, ButtonReleaseMask, FALSE,
519 (XtEventHandler)ControlHandler, p_plugin );
521 /* callback */
523 libvlc_media_instance_t *p_md;
525 libvlc_exception_t ex;
526 libvlc_exception_init(& ex );
527 p_md = libvlc_playlist_get_media_instance( p_plugin->getVLC(), &ex );
528 libvlc_exception_init( &ex );
529 libvlc_event_attach( libvlc_media_instance_event_manager( p_md, &ex ),
530 libvlc_MediaInstancePositionChanged, Redraw, NULL, &ex );
533 /* set/change parent window */
534 libvlc_video_set_parent( p_vlc, (libvlc_drawable_t) video, NULL );
536 /* remember window */
537 p_plugin->setWindow( *window );
538 p_plugin->setVideoWindow( video );
539 p_plugin->setControlWindow( controls );
541 Redraw( w, (XtPointer)p_plugin, NULL );
544 else if ( curwin.window )
546 /* change/set parent */
547 libvlc_video_set_parent(p_vlc, 0, NULL);
548 curwin.window = NULL;
550 #endif /* XP_UNIX */
552 if( !p_plugin->b_stream )
554 if( p_plugin->psz_target )
556 if( libvlc_playlist_add( p_vlc, p_plugin->psz_target,
557 NULL, NULL ) != -1 )
559 if( p_plugin->b_autoplay )
561 libvlc_playlist_play(p_vlc, 0, 0, NULL, NULL);
564 p_plugin->b_stream = VLC_TRUE;
567 return NPERR_NO_ERROR;
570 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
571 NPBool seekable, uint16 *stype )
573 if( NULL == instance )
575 return NPERR_INVALID_INSTANCE_ERROR;
578 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
579 if( NULL == p_plugin )
581 return NPERR_INVALID_INSTANCE_ERROR;
585 ** Firefox/Mozilla may decide to open a stream from the URL specified
586 ** in the SRC parameter of the EMBED tag and pass it to us
588 ** since VLC will open the SRC URL as well, we're not interested in
589 ** that stream. Otherwise, we'll take it and queue it up in the playlist
591 if( !p_plugin->psz_target || strcmp(stream->url, p_plugin->psz_target) )
593 /* TODO: use pipes !!!! */
594 *stype = NP_ASFILEONLY;
595 return NPERR_NO_ERROR;
597 return NPERR_GENERIC_ERROR;
600 int32 NPP_WriteReady( NPP instance, NPStream *stream )
602 /* TODO */
603 return 8*1024;
607 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
608 int32 len, void *buffer )
610 /* TODO */
611 return len;
615 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
617 if( instance == NULL )
619 return NPERR_INVALID_INSTANCE_ERROR;
621 return NPERR_NO_ERROR;
625 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
627 if( instance == NULL )
629 return;
632 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
633 if( NULL == p_plugin )
635 return;
638 if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) != -1 )
640 if( p_plugin->b_autoplay )
642 libvlc_playlist_play( p_plugin->getVLC(), 0, 0, NULL, NULL);
648 void NPP_URLNotify( NPP instance, const char* url,
649 NPReason reason, void* notifyData )
651 /***** Insert NPP_URLNotify code here *****\
652 PluginInstance* p_plugin;
653 if (instance != NULL)
654 p_plugin = (PluginInstance*) instance->pdata;
655 \*********************************************/
659 void NPP_Print( NPP instance, NPPrint* printInfo )
661 if( printInfo == NULL )
663 return;
666 if( instance != NULL )
668 /***** Insert NPP_Print code here *****\
669 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
670 \**************************************/
672 if( printInfo->mode == NP_FULL )
675 * PLUGIN DEVELOPERS:
676 * If your plugin would like to take over
677 * printing completely when it is in full-screen mode,
678 * set printInfo->pluginPrinted to TRUE and print your
679 * plugin as you see fit. If your plugin wants Netscape
680 * to handle printing in this case, set
681 * printInfo->pluginPrinted to FALSE (the default) and
682 * do nothing. If you do want to handle printing
683 * yourself, printOne is true if the print button
684 * (as opposed to the print menu) was clicked.
685 * On the Macintosh, platformPrint is a THPrint; on
686 * Windows, platformPrint is a structure
687 * (defined in npapi.h) containing the printer name, port,
688 * etc.
691 /***** Insert NPP_Print code here *****\
692 void* platformPrint =
693 printInfo->print.fullPrint.platformPrint;
694 NPBool printOne =
695 printInfo->print.fullPrint.printOne;
696 \**************************************/
698 /* Do the default*/
699 printInfo->print.fullPrint.pluginPrinted = FALSE;
701 else
703 /* If not fullscreen, we must be embedded */
705 * PLUGIN DEVELOPERS:
706 * If your plugin is embedded, or is full-screen
707 * but you returned false in pluginPrinted above, NPP_Print
708 * will be called with mode == NP_EMBED. The NPWindow
709 * in the printInfo gives the location and dimensions of
710 * the embedded plugin on the printed page. On the
711 * Macintosh, platformPrint is the printer port; on
712 * Windows, platformPrint is the handle to the printing
713 * device context.
716 /***** Insert NPP_Print code here *****\
717 NPWindow* printWindow =
718 &(printInfo->print.embedPrint.window);
719 void* platformPrint =
720 printInfo->print.embedPrint.platformPrint;
721 \**************************************/
726 /******************************************************************************
727 * Windows-only methods
728 *****************************************************************************/
729 #if XP_WIN
730 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
732 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
734 switch( i_msg )
736 case WM_ERASEBKGND:
737 return 1L;
739 case WM_PAINT:
741 PAINTSTRUCT paintstruct;
742 HDC hdc;
743 RECT rect;
745 hdc = BeginPaint( p_hwnd, &paintstruct );
747 GetClientRect( p_hwnd, &rect );
749 FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
750 SetTextColor(hdc, RGB(255, 255, 255));
751 SetBkColor(hdc, RGB(0, 0, 0));
752 DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect,
753 DT_CENTER|DT_VCENTER|DT_SINGLELINE);
755 EndPaint( p_hwnd, &paintstruct );
756 return 0L;
758 default:
759 /* delegate to default handler */
760 return CallWindowProc(p_plugin->getWindowProc(), p_hwnd, i_msg, wpar, lpar );
763 #endif /* XP_WIN */
765 /******************************************************************************
766 * UNIX-only methods
767 *****************************************************************************/
768 #ifdef XP_UNIX
769 static void Redraw( Widget w, XtPointer closure, XEvent *event )
771 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
772 const NPWindow& window = p_plugin->getWindow();
773 GC gc;
774 XGCValues gcv;
776 /* Toolbar */
777 XImage *p_playIcon = NULL;
778 XImage *p_pauseIcon = NULL;
779 XImage *p_stopIcon = NULL;
780 XImage *p_timeline = NULL;
781 XImage *p_timeKnob = NULL;
782 XImage *p_fscreen = NULL;
783 XImage *p_muteIcon = NULL;
784 XImage *p_unmuteIcon = NULL;
786 libvlc_media_instance_t *p_md = NULL;
787 float f_position = 0;
788 int i_playing = 0;
789 bool b_mute = false;
791 Window video = p_plugin->getVideoWindow();
792 Window control = p_plugin->getControlWindow();
793 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
795 gcv.foreground = BlackPixel( p_display, 0 );
796 gc = XCreateGC( p_display, video, GCForeground, &gcv );
798 XFillRectangle( p_display, video, gc,
799 0, 0, window.width, window.height - CONTROL_HEIGHT );
801 gcv.foreground = WhitePixel( p_display, 0 );
802 XChangeGC( p_display, gc, GCForeground, &gcv );
804 XDrawString( p_display, video, gc,
805 window.width / 2 - 40, (window.height - CONTROL_HEIGHT) / 2,
806 WINDOW_TEXT, strlen(WINDOW_TEXT) );
808 /* RedrawToolbar */
809 gcv.foreground = BlackPixel( p_display, 0 );
810 gc = XCreateGC( p_display, control, GCForeground, &gcv );
812 XFillRectangle( p_display, control, gc,
813 0, 0, window.width, CONTROL_HEIGHT );
816 gcv.foreground = WhitePixel( p_display, 0 );
817 XChangeGC( p_display, gc, GCForeground, &gcv );
819 /* get media instance */
820 libvlc_exception_t ex;
821 libvlc_exception_init( &ex );
822 p_md = libvlc_playlist_get_media_instance( p_plugin->getVLC(), &ex );
823 libvlc_exception_clear( &ex );
825 /* get isplaying */
826 libvlc_exception_init( &ex );
827 i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
828 libvlc_exception_clear( &ex );
830 /* get mute info */
831 libvlc_exception_init(&ex);
832 b_mute = libvlc_audio_get_mute( p_plugin->getVLC(), &ex );
833 libvlc_exception_clear( &ex );
835 /* get movie position in % */
836 if( i_playing == 1 )
838 libvlc_exception_init( &ex );
839 f_position = libvlc_media_instance_get_position(p_md, &ex)*100;
840 libvlc_exception_clear( &ex );
842 libvlc_media_instance_release(p_md);
844 /* load icons */
845 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
846 &p_playIcon, NULL, NULL);
847 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
848 &p_pauseIcon, NULL, NULL);
849 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
850 &p_stopIcon, NULL, NULL );
851 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
852 &p_timeline, NULL, NULL);
853 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
854 &p_timeKnob, NULL, NULL);
855 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
856 &p_fscreen, NULL, NULL);
857 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
858 &p_muteIcon, NULL, NULL);
859 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
860 &p_unmuteIcon, NULL, NULL);
862 #if 1 /* DEBUG */
863 if( !p_playIcon )
865 fprintf(stderr, "Error: playImage not found\n");
867 if( !p_pauseIcon )
869 fprintf(stderr, "Error: pauseImage not found\n");
871 if( !p_stopIcon )
873 fprintf(stderr, "Error: stopImage not found\n");
875 if( !p_timeline )
877 fprintf(stderr, "Error: TimeLineImage not found\n");
879 if( !p_timeKnob )
881 fprintf(stderr, "Error: TimeIcon not found\n");
883 if( !p_fscreen )
885 fprintf(stderr, "Error: FullscreenImage not found\n");
887 if( !p_muteIcon )
889 fprintf(stderr, "Error: MuteImage not found\n");
891 if( !p_unmuteIcon )
893 fprintf(stderr, "Error: UnMuteImage not found\n");
895 #endif
897 /* position icons */
898 if( p_pauseIcon && (i_playing == 1) )
900 XPutImage( p_display, control, gc, p_pauseIcon, 0, 0, 4, 14,
901 p_pauseIcon->width, p_pauseIcon->height );
903 else if( p_playIcon )
905 XPutImage( p_display, control, gc, p_playIcon, 0, 0, 4, 14,
906 p_playIcon->width, p_playIcon->height );
909 if( p_stopIcon )
910 XPutImage( p_display, control, gc, p_stopIcon, 0, 0, 39, 14,
911 p_stopIcon->width, p_stopIcon->height );
912 if( p_fscreen )
913 XPutImage( p_display, control, gc, p_fscreen, 0, 0, 67, 21,
914 p_fscreen->width, p_fscreen->height );
916 if( p_unmuteIcon && b_mute )
918 XPutImage( p_display, control, gc, p_unmuteIcon, 0, 0, 94, 30,
919 p_unmuteIcon->width, p_unmuteIcon->height );
921 else if( p_muteIcon )
923 XPutImage( p_display, control, gc, p_muteIcon, 0, 0, 94, 30,
924 p_muteIcon->width, p_muteIcon->height );
927 if( p_timeline )
928 XPutImage( p_display, control, gc, p_timeline, 0, 0, 4, 4,
929 (window.width-8), p_timeline->height );
930 if( p_timeKnob && (f_position > 0) )
932 f_position = (((float)window.width-8)/100)*f_position;
933 XPutImage( p_display, control, gc, p_timeKnob, 0, 0, (4+f_position), 2,
934 p_timeKnob->width, p_timeKnob->height );
937 /* Cleanup */
938 if( p_playIcon ) XDestroyImage( p_playIcon );
939 if( p_pauseIcon ) XDestroyImage( p_pauseIcon );
940 if( p_stopIcon ) XDestroyImage( p_stopIcon );
941 if( p_timeline ) XDestroyImage( p_timeline );
942 if( p_timeKnob ) XDestroyImage( p_timeKnob );
943 if( p_fscreen ) XDestroyImage( p_fscreen );
944 if( p_muteIcon ) XDestroyImage( p_muteIcon );
945 if( p_unmuteIcon ) XDestroyImage( p_unmuteIcon );
947 XFreeGC( p_display, gc );
950 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
952 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
953 const NPWindow& window = p_plugin->getWindow();
955 int i_height = window.height;
956 int i_width = window.width;
957 int i_xPos = event->xbutton.x;
958 int i_yPos = event->xbutton.y;
960 libvlc_exception_t ex;
961 libvlc_exception_init( &ex );
962 libvlc_media_instance_t *p_md =
963 libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex);
964 libvlc_exception_clear( &ex );
966 /* jump in the movie */
967 if( i_yPos <= (i_height-30) )
969 vlc_int64_t f_length;
970 libvlc_exception_init( &ex );
971 f_length = libvlc_media_instance_get_length( p_md, &ex ) / 100;
972 libvlc_exception_clear( &ex );
974 f_length = (float)f_length *
975 ( ((float)i_xPos-4 ) / ( ((float)i_width-8)/100) );
977 libvlc_exception_init( &ex );
978 libvlc_media_instance_set_time( p_md, f_length, &ex );
979 libvlc_exception_clear( &ex );
982 /* play/pause toggle */
983 if( (i_yPos > (i_height-30)) && (i_xPos > 4) && (i_xPos <= 39) )
985 int i_playing;
986 libvlc_exception_init( &ex );
987 i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
988 libvlc_exception_clear( &ex );
990 libvlc_exception_init( &ex );
991 if( i_playing == 1 )
992 libvlc_playlist_pause( p_plugin->getVLC(), &ex );
993 else
994 libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
995 libvlc_exception_clear( &ex );
998 /* stop */
999 if( (i_yPos > (i_height-30)) && (i_xPos > 39) && (i_xPos < 67) )
1001 libvlc_exception_init( &ex );
1002 libvlc_playlist_stop( p_plugin->getVLC(), &ex );
1003 libvlc_exception_clear( &ex );
1006 /* fullscreen */
1007 if( (i_yPos > (i_height-30)) && (i_xPos >= 67) && (i_xPos < 94) )
1009 libvlc_exception_init( &ex );
1010 libvlc_set_fullscreen( p_md, 1, &ex );
1011 libvlc_exception_clear( &ex );
1014 /* mute toggle */
1015 if( (i_yPos > (i_height-30)) && (i_xPos >= 94) && (i_xPos < 109))
1017 libvlc_exception_init( &ex );
1018 libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
1019 libvlc_exception_clear( &ex );
1021 libvlc_media_instance_release( p_md );
1023 Redraw( w, closure, event );
1026 static void Resize ( Widget w, XtPointer closure, XEvent *event )
1028 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
1029 const NPWindow& window = p_plugin->getWindow();
1030 Window drawable = p_plugin->getVideoWindow();
1031 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
1033 int i_ret;
1034 Window root_return, parent_return, * children_return;
1035 Window base_window;
1036 unsigned int i_nchildren;
1038 #ifdef X11_RESIZE_DEBUG
1039 XWindowAttributes attr;
1041 if( event && event->type == ConfigureNotify )
1043 fprintf( stderr, "vlcshell::Resize() ConfigureNotify %d x %d, "
1044 "send_event ? %s\n", event->xconfigure.width,
1045 event->xconfigure.height,
1046 event->xconfigure.send_event ? "TRUE" : "FALSE" );
1048 #endif /* X11_RESIZE_DEBUG */
1050 if( ! p_plugin->setSize(window.width, (window.height - CONTROL_HEIGHT)) )
1052 /* size already set */
1053 return;
1057 i_ret = XResizeWindow( p_display, drawable, window.width, (window.height - CONTROL_HEIGHT) );
1059 #ifdef X11_RESIZE_DEBUG
1060 fprintf( stderr,
1061 "vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret );
1063 XGetWindowAttributes ( p_display, drawable, &attr );
1065 /* X is asynchronous, so the current size reported here is not
1066 necessarily the requested size as the Resize request may not
1067 yet have been handled by the plugin host */
1068 fprintf( stderr, "vlcshell::Resize() current (owner) size %d x %d\n",
1069 attr.width, attr.height );
1070 #endif /* X11_RESIZE_DEBUG */
1072 XQueryTree( p_display, drawable,
1073 &root_return, &parent_return, &children_return,
1074 &i_nchildren );
1076 if( i_nchildren > 0 )
1078 /* XXX: Make assumptions related to the window parenting structure in
1079 vlc/modules/video_output/x11/xcommon.c */
1080 base_window = children_return[i_nchildren - 1];
1082 #ifdef X11_RESIZE_DEBUG
1083 fprintf( stderr, "vlcshell::Resize() got %d children\n", i_nchildren );
1084 fprintf( stderr, "vlcshell::Resize() got base_window %p\n",
1085 base_window );
1086 #endif /* X11_RESIZE_DEBUG */
1088 i_ret = XResizeWindow( p_display, base_window,
1089 window.width, ( window.height - CONTROL_HEIGHT ) );
1091 #ifdef X11_RESIZE_DEBUG
1092 fprintf( stderr,
1093 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
1094 i_ret );
1096 XGetWindowAttributes( p_display, base_window, &attr );
1098 fprintf( stderr, "vlcshell::Resize() new size %d x %d\n",
1099 attr.width, attr.height );
1100 #endif /* X11_RESIZE_DEBUG */
1104 #endif /* XP_UNIX */