X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=projects%2Fmozilla%2Fvlcshell.cpp;h=5681fbdec3a59486b3683d1586a2990cd43c7960;hb=69ec164abb756871a3b7421493d28da1288a6bad;hp=5ee39b49b98f6f9a6bbcf4d29298e62d219ef601;hpb=f90b88ab5852ddaf8f3a11d67df0370c8641fb70;p=vlc diff --git a/projects/mozilla/vlcshell.cpp b/projects/mozilla/vlcshell.cpp index 5ee39b49b9..5681fbdec3 100644 --- a/projects/mozilla/vlcshell.cpp +++ b/projects/mozilla/vlcshell.cpp @@ -1,10 +1,11 @@ /***************************************************************************** * vlcshell.cpp: a VLC plugin for Mozilla ***************************************************************************** - * Copyright (C) 2002-2005 the VideoLAN team + * Copyright (C) 2002-2009 the VideoLAN team * $Id$ * * Authors: Samuel Hocevar + * Jean-Paul Saman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,35 +36,21 @@ # include #endif -#ifdef XP_UNIX -#ifndef __APPLE__ -#include -#endif -#endif - /* This is from mozilla java, do we really need it? */ #if 0 #include #endif #include "vlcplugin.h" +#include "vlcshell.h" /* Enable/disable debugging printf's for X11 resizing */ #undef X11_RESIZE_DEBUG -#define WINDOW_TEXT "Video is loading..." - -#ifndef __MAX -# define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) ) -#endif -#ifndef __MIN -# define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) ) -#endif - /***************************************************************************** * Unix-only declarations ******************************************************************************/ -#ifdef XP_UNIX +#if defined(XP_UNIX) static void Redraw( Widget w, XtPointer closure, XEvent *event ); static void ControlHandler( Widget w, XtPointer closure, XEvent *event ); @@ -91,23 +78,25 @@ static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpa *****************************************************************************/ char * NPP_GetMIMEDescription( void ) { - return PLUGIN_MIMETYPES; + static char mimetype[] = PLUGIN_MIMETYPES; + return mimetype; } NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value ) { - + static char psz_name[] = PLUGIN_NAME; static char psz_desc[1000]; /* plugin class variables */ switch( variable ) { case NPPVpluginNameString: - *((char **)value) = PLUGIN_NAME; + *((char **)value) = psz_name; return NPERR_NO_ERROR; case NPPVpluginDescriptionString: - snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION, VLC_Version() ); + snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION, + libvlc_get_version() ); *((char **)value) = psz_desc; return NPERR_NO_ERROR; @@ -168,14 +157,15 @@ NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value ) int16 NPP_HandleEvent( NPP instance, void * event ) { static UInt32 lastMouseUp = 0; + libvlc_exception_t ex; + libvlc_exception_init(&ex); if( instance == NULL ) { return false; } - VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata; - + VlcPlugin* p_plugin = reinterpret_cast(instance->pdata); if( p_plugin == NULL ) { return false; @@ -192,21 +182,8 @@ int16 NPP_HandleEvent( NPP instance, void * event ) if( (myEvent->when - lastMouseUp) < GetDblTime() ) { /* double click */ - libvlc_instance_t *p_vlc = p_plugin->getVLC(); - - if( p_vlc ) - { - if( libvlc_playlist_isplaying(p_vlc, NULL) ) - { - libvlc_media_instance_t *p_md = - libvlc_playlist_get_media_instance(p_vlc, NULL); - if( p_md ) - { - libvlc_toggle_fullscreen(p_md, NULL); - libvlc_media_instance_release(p_md); - } - } - } + p_plugin->toggle_fullscreen(&ex); + libvlc_exception_clear(&ex); } return true; } @@ -222,31 +199,26 @@ int16 NPP_HandleEvent( NPP instance, void * event ) const NPWindow& npwindow = p_plugin->getWindow(); if( npwindow.window ) { - int hasVout = FALSE; - libvlc_instance_t *p_vlc = p_plugin->getVLC(); + bool hasVout = false; - if( p_vlc ) + if( p_plugin->playlist_isplaying() ) { - if( libvlc_playlist_isplaying(p_vlc, NULL) ) + hasVout = p_plugin->player_has_vout(NULL); + if( hasVout ) { - libvlc_media_instance_t *p_md = - libvlc_playlist_get_media_instance(p_vlc, NULL); - if( p_md ) - { - hasVout = libvlc_media_instance_has_vout(p_md, NULL); - if( hasVout ) - { - libvlc_rectangle_t area; - area.left = 0; - area.top = 0; - area.right = npwindow.width; - area.bottom = npwindow.height; - libvlc_video_redraw_rectangle(p_md, &area, NULL); - } - libvlc_media_instance_release(p_md); - } +#ifdef NOT_WORKING + libvlc_rectangle_t area; + area.left = 0; + area.top = 0; + area.right = npwindow.width; + area.bottom = npwindow.height; + libvlc_video_redraw_rectangle(p_plugin->getMD(&ex), &area, NULL); +#else +#warning disabled code +#endif } } + libvlc_exception_clear(&ex); if( ! hasVout ) { @@ -255,7 +227,8 @@ int16 NPP_HandleEvent( NPP instance, void * event ) ForeColor(blackColor); PenMode( patCopy ); - /* seems that firefox forgets to set the following on occasion (reload) */ + /* seems that firefox forgets to set the following + * on occasion (reload) */ SetOrigin(((NP_Port *)npwindow.window)->portx, ((NP_Port *)npwindow.window)->porty); @@ -268,7 +241,8 @@ int16 NPP_HandleEvent( NPP instance, void * event ) ForeColor(whiteColor); MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 ); - DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) ); + if( p_plugin->psz_text ) + DrawText( p_plugin->psz_text, 0, strlen(p_plugin->psz_text) ); } } return true; @@ -356,7 +330,7 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save ) instance->pdata = NULL; -#if XP_WIN +#if defined(XP_WIN) HWND win = (HWND)p_plugin->getWindow().window; WNDPROC winproc = p_plugin->getWindowProc(); if( winproc ) @@ -366,6 +340,9 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save ) } #endif + if( p_plugin->playlist_isplaying() ) + p_plugin->playlist_stop(); + delete p_plugin; return NPERR_NO_ERROR; @@ -373,6 +350,11 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save ) NPError NPP_SetWindow( NPP instance, NPWindow* window ) { +#if defined(XP_UNIX) + Window control; + unsigned int i_control_height = 0, i_control_width = 0; +#endif + if( ! instance ) { return NPERR_INVALID_INSTANCE_ERROR; @@ -380,12 +362,19 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window ) /* NPP_SetWindow may be called before NPP_New (Opera) */ VlcPlugin* p_plugin = reinterpret_cast(instance->pdata); - if( ! p_plugin ) + if( NULL == p_plugin ) { /* we should probably show a splash screen here */ return NPERR_NO_ERROR; } +#if defined(XP_UNIX) + control = p_plugin->getControlWindow(); +#endif + + libvlc_exception_t ex; + libvlc_exception_init(&ex); + libvlc_instance_t *p_vlc = p_plugin->getVLC(); /* @@ -404,37 +393,37 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window ) { /* check if plugin has a new parent window */ CGrafPtr drawable = (((NP_Port*) (window->window))->port); - if( !curwin.window || drawable != (((NP_Port*) (curwin.window))->port) ) - { - /* set/change parent window */ - libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL); - } /* as MacOS X video output is windowless, set viewport */ libvlc_rectangle_t view, clip; /* - ** browser sets port origin to top-left location of plugin relative to GrafPort - ** window origin is set relative to document, which of little use for drawing + ** browser sets port origin to top-left location of plugin + ** relative to GrafPort window origin is set relative to document, + ** which of little use for drawing */ view.top = ((NP_Port*) (window->window))->porty; view.left = ((NP_Port*) (window->window))->portx; view.bottom = window->height+view.top; view.right = window->width+view.left; + /* clipRect coordinates are also relative to GrafPort */ clip.top = window->clipRect.top; clip.left = window->clipRect.left; clip.bottom = window->clipRect.bottom; clip.right = window->clipRect.right; - - libvlc_video_set_viewport(p_vlc, &view, &clip, NULL); - +#ifdef NOT_WORKING + libvlc_video_set_viewport(p_vlc, p_plugin->getMD(&ex), &view, &clip, &ex); + libvlc_exception_clear(&ex); +#else +#warning disabled code +#endif /* remember new window */ p_plugin->setWindow(*window); } - else if( curwin.window ) { + else if( curwin.window ) + { /* change/set parent */ - libvlc_video_set_parent(p_vlc, 0, NULL); curwin.window = NULL; } #endif /* XP_MACOSX */ @@ -467,9 +456,6 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window ) style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS; SetWindowLong((HWND)drawable, GWL_STYLE, style); - /* change/set parent */ - libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL); - /* remember new window */ p_plugin->setWindow(*window); @@ -478,43 +464,53 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window ) UpdateWindow( (HWND)drawable ); } } - else if ( curwin.window ) + else if( curwin.window ) { /* reset WNDPROC */ HWND oldwin = (HWND)curwin.window; SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) ); p_plugin->setWindowProc(NULL); - /* change/set parent */ - libvlc_video_set_parent(p_vlc, 0, NULL); + curwin.window = NULL; } #endif /* XP_WIN */ -#ifdef XP_UNIX +#if defined(XP_UNIX) + /* default to hidden toolbar, shown at the end of this method if asked * + * developers note : getToolbarSize need to wait the end of this method + */ + i_control_height = 0; + i_control_width = window->width; + if( window && window->window ) { - Window parent = (Window) window->window; + Window parent = (Window) window->window; if( !curwin.window || (parent != (Window)curwin.window) ) { - Display *p_display = ((NPSetWindowCallbackStruct *)window->ws_info)->display; + Display *p_display = ( (NPSetWindowCallbackStruct *) + window->ws_info )->display; XResizeWindow( p_display, parent, window->width, window->height ); int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display)); + /* create windows */ Window video = XCreateSimpleWindow( p_display, parent, 0, 0, - window->width, window->height - p_plugin->i_control_height, 0, - i_blackColor, i_blackColor ); - Window controls = XCreateSimpleWindow( p_display, parent, 0, - window->height - p_plugin->i_control_height-1, window->width, - p_plugin->i_control_height-1, 0, i_blackColor, i_blackColor ); + window->width, window->height - i_control_height, + 0, i_blackColor, i_blackColor ); + Window controls = (Window) NULL; + controls = XCreateSimpleWindow( p_display, parent, + 0, window->height - i_control_height-1, + window->width, i_control_height-1, + 0, i_blackColor, i_blackColor ); XMapWindow( p_display, parent ); XMapWindow( p_display, video ); - XMapWindow( p_display, controls ); + if( controls ) { XMapWindow( p_display, controls ); } XFlush(p_display); + /* bind events */ Widget w = XtWindowToWidget( p_display, parent ); XtAddEventHandler( w, ExposureMask, FALSE, @@ -524,33 +520,26 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window ) XtAddEventHandler( w, ButtonReleaseMask, FALSE, (XtEventHandler)ControlHandler, p_plugin ); - /* callback */ -/* - libvlc_media_instance_t *p_md; - - libvlc_exception_t ex; - libvlc_exception_init(& ex ); - p_md = libvlc_playlist_get_media_instance( p_plugin->getVLC(), &ex ); - libvlc_exception_init( &ex ); - libvlc_event_attach( libvlc_media_instance_event_manager( p_md, &ex ), - libvlc_MediaInstancePositionChanged, Redraw, NULL, &ex ); -*/ - - /* set/change parent window */ - libvlc_video_set_parent( p_vlc, (libvlc_drawable_t) video, NULL ); - /* remember window */ p_plugin->setWindow( *window ); p_plugin->setVideoWindow( video ); - p_plugin->setControlWindow( controls ); + + if( controls ) + { + p_plugin->setControlWindow( controls ); + } Redraw( w, (XtPointer)p_plugin, NULL ); + + /* now display toolbar if asked through parameters */ + if( p_plugin->b_toolbar ) + { + p_plugin->showToolbar(); + } } } - else if ( curwin.window ) + else if( curwin.window ) { - /* change/set parent */ - libvlc_video_set_parent(p_vlc, 0, NULL); curwin.window = NULL; } #endif /* XP_UNIX */ @@ -559,15 +548,15 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window ) { if( p_plugin->psz_target ) { - if( libvlc_playlist_add( p_vlc, p_plugin->psz_target, - NULL, NULL ) != -1 ) + if( p_plugin->playlist_add( p_plugin->psz_target, NULL ) != -1 ) { if( p_plugin->b_autoplay ) { - libvlc_playlist_play(p_vlc, 0, 0, NULL, NULL); + p_plugin->playlist_play(&ex); + libvlc_exception_clear(&ex); } } - p_plugin->b_stream = VLC_TRUE; + p_plugin->b_stream = true; } } return NPERR_NO_ERROR; @@ -609,7 +598,6 @@ int32 NPP_WriteReady( NPP instance, NPStream *stream ) return 8*1024; } - int32 NPP_Write( NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer ) { @@ -617,7 +605,6 @@ int32 NPP_Write( NPP instance, NPStream *stream, int32 offset, return len; } - NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason ) { if( instance == NULL ) @@ -627,7 +614,6 @@ NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason ) return NPERR_NO_ERROR; } - void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname ) { if( instance == NULL ) @@ -641,16 +627,15 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname ) return; } - if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) != -1 ) + if( p_plugin->playlist_add( stream->url, NULL ) != -1 ) { if( p_plugin->b_autoplay ) { - libvlc_playlist_play( p_plugin->getVLC(), 0, 0, NULL, NULL); + p_plugin->playlist_play(NULL); } } } - void NPP_URLNotify( NPP instance, const char* url, NPReason reason, void* notifyData ) { @@ -661,7 +646,6 @@ void NPP_URLNotify( NPP instance, const char* url, \*********************************************/ } - void NPP_Print( NPP instance, NPPrint* printInfo ) { if( printInfo == NULL ) @@ -732,7 +716,7 @@ void NPP_Print( NPP instance, NPPrint* printInfo ) /****************************************************************************** * Windows-only methods *****************************************************************************/ -#if XP_WIN +#if defined(XP_WIN) static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar ) { VlcPlugin* p_plugin = reinterpret_cast(GetWindowLongPtr(p_hwnd, GWLP_USERDATA)); @@ -755,15 +739,17 @@ static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpa FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) ); SetTextColor(hdc, RGB(255, 255, 255)); SetBkColor(hdc, RGB(0, 0, 0)); - DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect, - DT_CENTER|DT_VCENTER|DT_SINGLELINE); + if( p_plugin->psz_text ) + DrawText( hdc, p_plugin->psz_text, strlen(p_plugin->psz_text), &rect, + DT_CENTER|DT_VCENTER|DT_SINGLELINE); EndPaint( p_hwnd, &paintstruct ); return 0L; } default: /* delegate to default handler */ - return CallWindowProc(p_plugin->getWindowProc(), p_hwnd, i_msg, wpar, lpar ); + return CallWindowProc( p_plugin->getWindowProc(), p_hwnd, + i_msg, wpar, lpar ); } } #endif /* XP_WIN */ @@ -771,171 +757,40 @@ static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpa /****************************************************************************** * UNIX-only methods *****************************************************************************/ -#ifdef XP_UNIX +#if defined(XP_UNIX) static void Redraw( Widget w, XtPointer closure, XEvent *event ) { VlcPlugin* p_plugin = reinterpret_cast(closure); + Window control = p_plugin->getControlWindow(); const NPWindow& window = p_plugin->getWindow(); GC gc; XGCValues gcv; + unsigned int i_control_height, i_control_width; - /* Toolbar */ - XImage *p_btnPlay = NULL; - XImage *p_btnPause = NULL; - XImage *p_btnStop = NULL; - XImage *p_timeline = NULL; - XImage *p_btnTime = NULL; - XImage *p_btnFullscreen = NULL; - XImage *p_btnMute = NULL; - XImage *p_btnUnmute = NULL; - - libvlc_media_instance_t *p_md = NULL; - float f_position = 0; - int i_playing = 0; - bool b_mute = false; + if( p_plugin->b_toolbar ) + p_plugin->getToolbarSize( &i_control_width, &i_control_height ); + else + i_control_height = i_control_width = 0; Window video = p_plugin->getVideoWindow(); - Window control = p_plugin->getControlWindow(); Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display; - /* load icons */ - XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm", - &p_btnPlay, NULL, NULL); - p_plugin->i_control_height = __MAX( p_plugin->i_control_height, - p_btnPlay->height ); - XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm", - &p_btnPause, NULL, NULL); - p_plugin->i_control_height = __MAX( p_plugin->i_control_height, - p_btnPause->height ); - XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm", - &p_btnStop, NULL, NULL ); - p_plugin->i_control_height = __MAX( p_plugin->i_control_height, - p_btnStop->height ); - XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm", - &p_timeline, NULL, NULL); - p_plugin->i_control_height = __MAX( p_plugin->i_control_height, - p_timeline->height ); - XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm", - &p_btnTime, NULL, NULL); - p_plugin->i_control_height = __MAX( p_plugin->i_control_height, - p_btnTime->height ); - XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm", - &p_btnFullscreen, NULL, NULL); - p_plugin->i_control_height = __MAX( p_plugin->i_control_height, - p_btnFullscreen->height); - XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm", - &p_btnMute, NULL, NULL); - p_plugin->i_control_height = __MAX( p_plugin->i_control_height, - p_btnMute->height); - XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm", - &p_btnUnmute, NULL, NULL); - p_plugin->i_control_height = __MAX( p_plugin->i_control_height, - p_btnUnmute->height); - - if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline || - !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute ) - fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH ); - gcv.foreground = BlackPixel( p_display, 0 ); gc = XCreateGC( p_display, video, GCForeground, &gcv ); XFillRectangle( p_display, video, gc, - 0, 0, window.width, window.height - p_plugin->i_control_height ); - - gcv.foreground = WhitePixel( p_display, 0 ); - XChangeGC( p_display, gc, GCForeground, &gcv ); - - XDrawString( p_display, video, gc, - window.width / 2 - 40, (window.height - p_plugin->i_control_height) / 2, - WINDOW_TEXT, strlen(WINDOW_TEXT) ); - - /* RedrawToolbar */ - gcv.foreground = BlackPixel( p_display, 0 ); - gc = XCreateGC( p_display, control, GCForeground, &gcv ); - - XFillRectangle( p_display, control, gc, - 0, 0, window.width, p_plugin->i_control_height ); - + 0, 0, window.width, window.height - i_control_height); gcv.foreground = WhitePixel( p_display, 0 ); XChangeGC( p_display, gc, GCForeground, &gcv ); - /* get media instance */ - libvlc_exception_t ex; - libvlc_exception_init( &ex ); - p_md = libvlc_playlist_get_media_instance( p_plugin->getVLC(), &ex ); - libvlc_exception_clear( &ex ); - - /* get isplaying */ - libvlc_exception_init( &ex ); - i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex ); - libvlc_exception_clear( &ex ); - - /* get mute info */ - libvlc_exception_init(&ex); - b_mute = libvlc_audio_get_mute( p_plugin->getVLC(), &ex ); - libvlc_exception_clear( &ex ); - - /* get movie position in % */ - if( i_playing == 1 ) - { - libvlc_exception_init( &ex ); - f_position = libvlc_media_instance_get_position(p_md, &ex)*100; - libvlc_exception_clear( &ex ); - } - libvlc_media_instance_release(p_md); - - /* position icons */ - if( p_btnPause && (i_playing == 1) ) - { - XPutImage( p_display, control, gc, p_btnPause, 0, 0, 4, 14, - p_btnPause->width, p_btnPause->height ); - } - else if( p_btnPlay ) - { - XPutImage( p_display, control, gc, p_btnPlay, 0, 0, 4, 14, - p_btnPlay->width, p_btnPlay->height ); - } - - if( p_btnStop ) - XPutImage( p_display, control, gc, p_btnStop, 0, 0, 39, 14, - p_btnStop->width, p_btnStop->height ); - if( p_btnFullscreen ) - XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, 67, 21, - p_btnFullscreen->width, p_btnFullscreen->height ); - - if( p_btnUnmute && b_mute ) - { - XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, 94, 30, - p_btnUnmute->width, p_btnUnmute->height ); - } - else if( p_btnMute ) - { - XPutImage( p_display, control, gc, p_btnMute, 0, 0, 94, 30, - p_btnMute->width, p_btnMute->height ); - } - - if( p_timeline ) - XPutImage( p_display, control, gc, p_timeline, 0, 0, 4, 4, - (window.width-8), p_timeline->height ); - if( p_btnTime && (f_position > 0) ) - { - f_position = (((float)window.width-8)/100)*f_position; - XPutImage( p_display, control, gc, p_btnTime, 0, 0, (4+f_position), 2, - p_btnTime->width, p_btnTime->height ); - } - - /* Cleanup */ - if( p_btnPlay ) XDestroyImage( p_btnPlay ); - if( p_btnPause ) XDestroyImage( p_btnPause ); - if( p_btnStop ) XDestroyImage( p_btnStop ); - if( p_timeline ) XDestroyImage( p_timeline ); - if( p_btnTime ) XDestroyImage( p_btnTime ); - if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen ); - if( p_btnMute ) XDestroyImage( p_btnMute ); - if( p_btnUnmute ) XDestroyImage( p_btnUnmute ); - + if( p_plugin->psz_text ) + XDrawString( p_display, video, gc, + window.width / 2 - 40, (window.height - i_control_height) / 2, + p_plugin->psz_text, strlen(p_plugin->psz_text) ); XFreeGC( p_display, gc ); + + p_plugin->redrawToolbar(); } static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) @@ -948,70 +803,80 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) int i_xPos = event->xbutton.x; int i_yPos = event->xbutton.y; - if( p_plugin ) + if( p_plugin && p_plugin->b_toolbar ) { + int i_playing; libvlc_exception_t ex; + libvlc_exception_init( &ex ); - libvlc_media_instance_t *p_md = - libvlc_playlist_get_media_instance(p_plugin->getVLC(), &ex); + libvlc_media_player_t *p_md = p_plugin->getMD(&ex); libvlc_exception_clear( &ex ); - /* jump in the movie */ - if( i_yPos <= (i_height-30) ) + i_playing = p_plugin->playlist_isplaying(); + + vlc_toolbar_clicked_t clicked; + clicked = p_plugin->getToolbarButtonClicked( i_xPos, i_yPos ); + switch( clicked ) { - vlc_int64_t f_length; - libvlc_exception_init( &ex ); - f_length = libvlc_media_instance_get_length( p_md, &ex ) / 100; - libvlc_exception_clear( &ex ); + case clicked_Play: + case clicked_Pause: + { + if( i_playing == 1 ) + p_plugin->playlist_pause( &ex ); + else + p_plugin->playlist_play( &ex ); - f_length = (float)f_length * - ( ((float)i_xPos-4 ) / ( ((float)i_width-8)/100) ); + libvlc_exception_clear( &ex ); + } + break; - libvlc_exception_init( &ex ); - libvlc_media_instance_set_time( p_md, f_length, &ex ); - libvlc_exception_clear( &ex ); - } + case clicked_Stop: + { + p_plugin->playlist_stop(); + } + break; - /* play/pause toggle */ - if( (i_yPos > (i_height-30)) && (i_xPos > 4) && (i_xPos <= 39) ) - { - int i_playing; - libvlc_exception_init( &ex ); - i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex ); - libvlc_exception_clear( &ex ); - - libvlc_exception_init( &ex ); - if( i_playing == 1 ) - libvlc_playlist_pause( p_plugin->getVLC(), &ex ); - else - libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex ); - libvlc_exception_clear( &ex ); - } + case clicked_Fullscreen: + { + p_plugin->set_fullscreen( 1, &ex ); + libvlc_exception_clear( &ex ); + } + break; - /* stop */ - if( (i_yPos > (i_height-30)) && (i_xPos > 39) && (i_xPos < 67) ) - { - libvlc_exception_init( &ex ); - libvlc_playlist_stop( p_plugin->getVLC(), &ex ); - libvlc_exception_clear( &ex ); - } + case clicked_Mute: + case clicked_Unmute: + { + libvlc_audio_toggle_mute( p_plugin->getVLC() ); + } + break; - /* fullscreen */ - if( (i_yPos > (i_height-30)) && (i_xPos >= 67) && (i_xPos < 94) ) - { - libvlc_exception_init( &ex ); - libvlc_set_fullscreen( p_md, 1, &ex ); - libvlc_exception_clear( &ex ); - } + case clicked_timeline: + { + /* if a movie is loaded */ + if( p_md ) + { + int64_t f_length; + f_length = libvlc_media_player_get_length( p_md, &ex ) / 100; + libvlc_exception_clear( &ex ); - /* mute toggle */ - if( (i_yPos > (i_height-30)) && (i_xPos >= 94) && (i_xPos < 109)) - { - libvlc_exception_init( &ex ); - libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex ); - libvlc_exception_clear( &ex ); + f_length = (float)f_length * + ( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) ); + + libvlc_media_player_set_time( p_md, f_length, &ex ); + libvlc_exception_clear( &ex ); + } + } + break; + + case clicked_Time: + { + /* Not implemented yet*/ + } + break; + + default: /* button_Unknown */ + break; } - libvlc_media_instance_release( p_md ); } Redraw( w, closure, event ); } @@ -1019,6 +884,7 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event ) static void Resize ( Widget w, XtPointer closure, XEvent *event ) { VlcPlugin* p_plugin = reinterpret_cast(closure); + Window control = p_plugin->getControlWindow(); const NPWindow& window = p_plugin->getWindow(); Window drawable = p_plugin->getVideoWindow(); Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display; @@ -1027,6 +893,16 @@ static void Resize ( Widget w, XtPointer closure, XEvent *event ) Window root_return, parent_return, * children_return; Window base_window; unsigned int i_nchildren; + unsigned int i_control_height, i_control_width; + + if( p_plugin->b_toolbar ) + { + p_plugin->getToolbarSize( &i_control_width, &i_control_height ); + } + else + { + i_control_height = i_control_width = 0; + } #ifdef X11_RESIZE_DEBUG XWindowAttributes attr; @@ -1040,13 +916,14 @@ static void Resize ( Widget w, XtPointer closure, XEvent *event ) } #endif /* X11_RESIZE_DEBUG */ - if( ! p_plugin->setSize(window.width, (window.height - p_plugin->i_control_height)) ) + if( ! p_plugin->setSize(window.width, (window.height - i_control_height)) ) { /* size already set */ return; } - i_ret = XResizeWindow( p_display, drawable, window.width, (window.height - p_plugin->i_control_height) ); + i_ret = XResizeWindow( p_display, drawable, + window.width, (window.height - i_control_height) ); #ifdef X11_RESIZE_DEBUG fprintf( stderr, @@ -1078,7 +955,7 @@ static void Resize ( Widget w, XtPointer closure, XEvent *event ) #endif /* X11_RESIZE_DEBUG */ i_ret = XResizeWindow( p_display, base_window, - window.width, ( window.height - p_plugin->i_control_height ) ); + window.width, ( window.height - i_control_height ) ); #ifdef X11_RESIZE_DEBUG fprintf( stderr,