1 /*****************************************************************************
2 * vlcplugin.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Damien Fouilleul <damienf.fouilleul@laposte.net>
9 * Jean-Paul Saman <jpsaman@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
31 #ifdef HAVE_MOZILLA_CONFIG_H
32 # include <mozilla-config.h>
35 #include "vlcplugin.h"
36 #include "control/npolibvlc.h"
41 /*****************************************************************************
42 * VlcPlugin constructor and destructor
43 *****************************************************************************/
44 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
52 libvlc_instance(NULL),
53 libvlc_media_list(NULL),
54 libvlc_media_player(NULL),
62 ,i_width((unsigned)-1)
63 ,i_height((unsigned)-1)
72 ,p_btnFullscreen(NULL)
77 memset(&npwindow, 0, sizeof(NPWindow));
79 memset(&npvideo, 0, sizeof(Window));
80 memset(&npcontrol, 0, sizeof(Window));
84 static bool boolValue(const char *value) {
85 return ( !strcmp(value, "1") ||
86 !strcasecmp(value, "true") ||
87 !strcasecmp(value, "yes") );
91 void EventObj::deliver(NPP browser)
96 pthread_mutex_lock(&mutex);
98 for( ev_l::iterator i=_elist.begin();i!=_elist.end();++i )
100 libvlc_event_type_t event = *i;
101 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
103 // Invalid events aren't supposed to be queued up.
104 // if( !have_event(event) ) continue;
106 for( lr_l::iterator j=_llist.begin();j!=_llist.end();++j )
110 NPN_InvokeDefault(browser, j->listener(), params, 1, &result);
111 NPN_ReleaseVariantValue(&result);
117 pthread_mutex_unlock(&mutex);
120 void VlcPlugin::eventAsync(void *param)
122 VlcPlugin *plugin = (VlcPlugin*)param;
123 plugin->events.deliver(plugin->getBrowser());
126 void EventObj::callback(const libvlc_event_t* event)
128 pthread_mutex_lock(&mutex);
130 if( have_event(event->type) )
131 _elist.push_back(event->type);
133 pthread_mutex_unlock(&mutex);
136 void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
138 VlcPlugin *plugin = (VlcPlugin*)param;
139 plugin->events.callback(event);
141 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
143 NPN_SetException(this, "NPN_PluginThreadAsyncCall not implemented yet.");
147 inline EventObj::event_t EventObj::find_event(const char *s) const
150 for(i=0;i<maxbit();++i)
151 if(!strcmp(s,libvlc_event_type_name(i)))
156 bool EventObj::insert(const NPString &s, NPObject *l, bool b)
158 event_t e = find_event(s.utf8characters);
162 if( !have_event(e) && !ask_for_event(e) )
166 for(i=_llist.begin();i!=_llist.end();++i)
167 if(i->listener()==l && i->bubble()==b)
170 if( i == _llist.end() ) {
171 _llist.push_back(Listener(e,l,b));
180 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
182 event_t e = find_event(s.utf8characters);
183 if( e>=maxbit() || !get(e) )
187 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
189 if(i->listener()!=l || i->bubble()!=b)
207 void EventObj::hook_manager(libvlc_event_manager_t *em,
208 libvlc_callback_t cb, void *udata)
210 _em = em; _cb = cb; _ud = udata;
213 for(size_t i=0;i<maxbit();++i)
215 libvlc_event_attach(_em, i, _cb, _ud);
218 void EventObj::unhook_manager()
222 for(size_t i=0;i<maxbit();++i)
224 libvlc_event_detach(_em, i, _cb, _ud);
228 bool EventObj::ask_for_event(event_t e)
230 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
234 void EventObj::unask_for_event(event_t e)
236 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
240 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
242 /* prepare VLC command line */
243 const char *ppsz_argv[32];
247 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
250 /* locate VLC module path */
252 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
253 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
254 #elif defined(XP_WIN)
256 DWORD i_type, i_data = MAX_PATH + 1;
257 char p_data[MAX_PATH + 1];
258 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
259 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
261 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
262 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
264 if( i_type == REG_SZ )
266 strcat( p_data, "\\plugins" );
267 ppsz_argv[ppsz_argc++] = "--plugin-path";
268 ppsz_argv[ppsz_argc++] = p_data;
271 RegCloseKey( h_key );
273 ppsz_argv[ppsz_argc++] = "--no-one-instance";
275 #endif /* XP_MACOSX */
277 /* common settings */
278 ppsz_argv[ppsz_argc++] = "-vv";
279 ppsz_argv[ppsz_argc++] = "--no-stats";
280 ppsz_argv[ppsz_argc++] = "--no-media-library";
281 ppsz_argv[ppsz_argc++] = "--intf=dummy";
282 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
284 const char *progid = NULL;
286 /* parse plugin arguments */
287 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
289 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
291 if( !strcmp( argn[i], "target" )
292 || !strcmp( argn[i], "mrl")
293 || !strcmp( argn[i], "filename")
294 || !strcmp( argn[i], "src") )
296 psz_target = argv[i];
298 else if( !strcmp( argn[i], "text" ) )
301 psz_text = strdup( argv[i] );
303 else if( !strcmp( argn[i], "autoplay")
304 || !strcmp( argn[i], "autostart") )
306 b_autoplay = boolValue(argv[i]);
308 else if( !strcmp( argn[i], "fullscreen" ) )
310 if( boolValue(argv[i]) )
312 ppsz_argv[ppsz_argc++] = "--fullscreen";
316 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
319 else if( !strcmp( argn[i], "mute" ) )
321 if( boolValue(argv[i]) )
323 ppsz_argv[ppsz_argc++] = "--volume=0";
326 else if( !strcmp( argn[i], "loop")
327 || !strcmp( argn[i], "autoloop") )
329 if( boolValue(argv[i]) )
331 ppsz_argv[ppsz_argc++] = "--loop";
335 ppsz_argv[ppsz_argc++] = "--no-loop";
338 else if( !strcmp( argn[i], "version")
339 || !strcmp( argn[i], "progid") )
343 else if( !strcmp( argn[i], "toolbar" ) )
345 /* FIXME: Remove this when toolbar functionality has been implemented on
346 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
348 b_toolbar = boolValue(argv[i]);
353 libvlc_exception_t ex;
354 libvlc_exception_init(&ex);
356 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, &ex);
357 if( libvlc_exception_raised(&ex) )
359 libvlc_exception_clear(&ex);
360 return NPERR_GENERIC_ERROR;
363 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
366 ** fetch plugin base URL, which is the URL of the page containing the plugin
367 ** this URL is used for making absolute URL from relative URL that may be
368 ** passed as an MRL argument
370 NPObject *plugin = NULL;
372 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
375 ** is there a better way to get that info ?
377 static const char docLocHref[] = "document.location.href";
381 script.utf8characters = docLocHref;
382 script.utf8length = sizeof(docLocHref)-1;
384 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
386 if( NPVARIANT_IS_STRING(result) )
388 NPString &location = NPVARIANT_TO_STRING(result);
390 psz_baseURL = (char *) malloc(location.utf8length+1);
393 strncpy(psz_baseURL, location.utf8characters, location.utf8length);
394 psz_baseURL[location.utf8length] = '\0';
397 NPN_ReleaseVariantValue(&result);
399 NPN_ReleaseObject(plugin);
404 // get absolute URL from src
405 char *psz_absurl = getAbsoluteURL(psz_target);
406 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
409 /* assign plugin script root class */
411 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
414 return NPERR_GENERIC_ERROR;
416 return NPERR_NO_ERROR;
419 VlcPlugin::~VlcPlugin()
425 if( libvlc_media_player )
427 events.unhook_manager();
428 libvlc_media_player_release( libvlc_media_player );
430 if( libvlc_media_list )
431 libvlc_media_list_release( libvlc_media_list );
432 if( libvlc_instance )
433 libvlc_release(libvlc_instance);
436 /*****************************************************************************
437 * VlcPlugin playlist replacement methods
438 *****************************************************************************/
439 void VlcPlugin::set_player_window()
442 libvlc_media_player_set_xwindow(libvlc_media_player,
443 (libvlc_drawable_t)getVideoWindow());
446 // XXX FIXME insert appropriate call here
449 libvlc_media_player_set_hwnd(libvlc_media_player,
454 int VlcPlugin::playlist_add( const char *mrl, libvlc_exception_t *ex )
457 libvlc_media_t *p_m = libvlc_media_new(libvlc_instance,mrl,ex);
458 if( libvlc_exception_raised(ex) )
461 libvlc_media_list_lock(libvlc_media_list);
462 libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
463 if( !libvlc_exception_raised(ex) )
464 item = libvlc_media_list_count(libvlc_media_list)-1;
465 libvlc_media_list_unlock(libvlc_media_list);
467 libvlc_media_release(p_m);
472 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
473 int optc, const char **optv, libvlc_exception_t *ex )
475 libvlc_media_t *p_m = libvlc_media_new(libvlc_instance, mrl,ex);
477 if( libvlc_exception_raised(ex) )
480 for( int i = 0; i < optc; ++i )
481 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
483 libvlc_media_list_lock(libvlc_media_list);
484 libvlc_media_list_add_media(libvlc_media_list,p_m,ex);
485 if( !libvlc_exception_raised(ex) )
486 item = libvlc_media_list_count(libvlc_media_list)-1;
487 libvlc_media_list_unlock(libvlc_media_list);
488 libvlc_media_release(p_m);
493 bool VlcPlugin::playlist_select( int idx, libvlc_exception_t *ex )
495 libvlc_media_t *p_m = NULL;
497 libvlc_media_list_lock(libvlc_media_list);
499 int count = libvlc_media_list_count(libvlc_media_list);
501 if( idx<0||idx>=count )
504 playlist_index = idx;
506 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index,ex);
507 libvlc_media_list_unlock(libvlc_media_list);
509 if( libvlc_exception_raised(ex) )
512 if( libvlc_media_player )
514 events.unhook_manager();
515 libvlc_media_player_release( libvlc_media_player );
516 libvlc_media_player = NULL;
519 libvlc_media_player = libvlc_media_player_new_from_media(p_m,ex);
520 if( libvlc_media_player )
524 libvlc_media_player_event_manager(libvlc_media_player),
525 event_callback, this);
528 libvlc_media_release( p_m );
529 return !libvlc_exception_raised(ex);
532 libvlc_media_list_unlock(libvlc_media_list);
536 void VlcPlugin::playlist_delete_item( int idx, libvlc_exception_t *ex )
538 libvlc_media_list_lock(libvlc_media_list);
539 libvlc_media_list_remove_index(libvlc_media_list,idx,ex);
540 libvlc_media_list_unlock(libvlc_media_list);
543 void VlcPlugin::playlist_clear( libvlc_exception_t *ex )
545 if( libvlc_media_list )
546 libvlc_media_list_release(libvlc_media_list);
547 libvlc_media_list = libvlc_media_list_new(getVLC());
550 int VlcPlugin::playlist_count()
553 libvlc_media_list_lock(libvlc_media_list);
554 items_count = libvlc_media_list_count(libvlc_media_list);
555 libvlc_media_list_unlock(libvlc_media_list);
559 void VlcPlugin::toggle_fullscreen( libvlc_exception_t *ex )
561 if( playlist_isplaying() )
562 libvlc_toggle_fullscreen(libvlc_media_player,ex);
564 void VlcPlugin::set_fullscreen( int yes, libvlc_exception_t *ex )
566 if( playlist_isplaying() )
567 libvlc_set_fullscreen(libvlc_media_player,yes,ex);
569 int VlcPlugin::get_fullscreen( libvlc_exception_t *ex )
572 if( playlist_isplaying() )
573 r = libvlc_get_fullscreen(libvlc_media_player,ex);
577 bool VlcPlugin::player_has_vout( libvlc_exception_t *ex )
580 if( playlist_isplaying() )
581 r = libvlc_media_player_has_vout(libvlc_media_player, ex);
585 /*****************************************************************************
587 *****************************************************************************/
589 char *VlcPlugin::getAbsoluteURL(const char *url)
593 // check whether URL is already absolute
594 const char *end=strchr(url, ':');
595 if( (NULL != end) && (end != url) )
597 // validate protocol header
598 const char *start = url;
603 while( start != end )
610 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
611 // not valid protocol header, assume relative URL
615 /* we have a protocol header, therefore URL is absolute */
618 // not a valid protocol header, assume relative URL
625 size_t baseLen = strlen(psz_baseURL);
626 char *href = (char *) malloc(baseLen+strlen(url)+1);
629 /* prepend base URL */
630 memcpy(href, psz_baseURL, baseLen+1);
633 ** relative url could be empty,
634 ** in which case return base URL
640 ** locate pathname part of base URL
643 /* skip over protocol part */
644 char *pathstart = strchr(href, ':');
645 char *pathend = href+baseLen;
648 if( '/' == *(++pathstart) )
650 if( '/' == *(++pathstart) )
655 /* skip over host part */
656 pathstart = strchr(pathstart, '/');
659 // no path, add a / past end of url (over '\0')
666 /* baseURL is just a UNIX path */
669 /* baseURL is not an absolute path */
676 /* relative URL made of an absolute path ? */
679 /* replace path completely */
680 strcpy(pathstart, url);
684 /* find last path component and replace it */
685 while( '/' != *pathend)
689 ** if relative url path starts with one or more '../',
690 ** factor them out of href so that we return a
693 while( pathend != pathstart )
701 /* relative url is just '.' */
707 /* relative url starts with './' */
716 /* relative url is '..' */
722 /* relative url starts with '../' */
730 while( '/' != *pathend );
732 /* skip over '/' separator */
734 /* concatenate remaining base URL and relative URL */
735 strcpy(pathend, url);
744 int VlcPlugin::setSize(unsigned width, unsigned height)
746 int diff = (width != i_width) || (height != i_height);
755 #define BTN_SPACE ((unsigned int)4)
756 void VlcPlugin::showToolbar()
758 const NPWindow& window = getWindow();
759 Window control = getControlWindow();
760 Window video = getVideoWindow();
761 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
762 unsigned int i_height = 0, i_width = BTN_SPACE;
766 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
767 &p_btnPlay, NULL, NULL);
770 i_height = __MAX( i_height, p_btnPlay->height );
773 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
774 &p_btnPause, NULL, NULL);
777 i_height = __MAX( i_height, p_btnPause->height );
779 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
782 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
783 &p_btnStop, NULL, NULL );
786 i_height = __MAX( i_height, p_btnStop->height );
787 i_width += BTN_SPACE + p_btnStop->width;
790 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
791 &p_timeline, NULL, NULL);
794 i_height = __MAX( i_height, p_timeline->height );
795 i_width += BTN_SPACE + p_timeline->width;
798 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
799 &p_btnTime, NULL, NULL);
802 i_height = __MAX( i_height, p_btnTime->height );
803 i_width += BTN_SPACE + p_btnTime->width;
805 if( !p_btnFullscreen )
806 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
807 &p_btnFullscreen, NULL, NULL);
808 if( p_btnFullscreen )
810 i_height = __MAX( i_height, p_btnFullscreen->height );
811 i_width += BTN_SPACE + p_btnFullscreen->width;
814 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
815 &p_btnMute, NULL, NULL);
818 i_height = __MAX( i_height, p_btnMute->height );
821 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
822 &p_btnUnmute, NULL, NULL);
825 i_height = __MAX( i_height, p_btnUnmute->height );
827 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
829 setToolbarSize( i_width, i_height );
831 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
832 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
833 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
835 /* reset panels position and size */
836 /* XXX use i_width */
837 XResizeWindow( p_display, video, window.width, window.height - i_height);
838 XMoveWindow( p_display, control, 0, window.height - i_height );
839 XResizeWindow( p_display, control, window.width, i_height -1);
841 b_toolbar = 1; /* says toolbar is now shown */
845 void VlcPlugin::hideToolbar()
847 const NPWindow& window = getWindow();
848 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
849 Window control = getControlWindow();
850 Window video = getVideoWindow();
852 i_tb_width = i_tb_height = 0;
854 if( p_btnPlay ) XDestroyImage( p_btnPlay );
855 if( p_btnPause ) XDestroyImage( p_btnPause );
856 if( p_btnStop ) XDestroyImage( p_btnStop );
857 if( p_timeline ) XDestroyImage( p_timeline );
858 if( p_btnTime ) XDestroyImage( p_btnTime );
859 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
860 if( p_btnMute ) XDestroyImage( p_btnMute );
861 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
868 p_btnFullscreen = NULL;
872 /* reset panels position and size */
873 /* XXX use i_width */
874 XResizeWindow( p_display, video, window.width, window.height );
875 XMoveWindow( p_display, control, 0, window.height-1 );
876 XResizeWindow( p_display, control, window.width, 1 );
878 b_toolbar = 0; /* says toolbar is now hidden */
882 void VlcPlugin::redrawToolbar()
886 unsigned int dst_x, dst_y;
889 unsigned int i_tb_width, i_tb_height;
891 /* This method does nothing if toolbar is hidden. */
895 const NPWindow& window = getWindow();
896 Window control = getControlWindow();
897 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
899 getToolbarSize( &i_tb_width, &i_tb_height );
903 b_mute = libvlc_audio_get_mute( getVLC() );
905 gcv.foreground = BlackPixel( p_display, 0 );
906 gc = XCreateGC( p_display, control, GCForeground, &gcv );
908 XFillRectangle( p_display, control, gc,
909 0, 0, window.width, i_tb_height );
910 gcv.foreground = WhitePixel( p_display, 0 );
911 XChangeGC( p_display, gc, GCForeground, &gcv );
915 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
917 if( p_btnPause && (is_playing == 1) )
919 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
920 dst_y - (p_btnPause->height >> 1),
921 p_btnPause->width, p_btnPause->height );
922 dst_x += BTN_SPACE + p_btnPause->width;
926 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
927 dst_y - (p_btnPlay->height >> 1),
928 p_btnPlay->width, p_btnPlay->height );
929 dst_x += BTN_SPACE + p_btnPlay->width;
933 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
934 dst_y - (p_btnStop->height >> 1),
935 p_btnStop->width, p_btnStop->height );
937 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
939 if( p_btnFullscreen )
940 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
941 dst_y - (p_btnFullscreen->height >> 1),
942 p_btnFullscreen->width, p_btnFullscreen->height );
944 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
946 if( p_btnUnmute && b_mute )
948 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
949 dst_y - (p_btnUnmute->height >> 1),
950 p_btnUnmute->width, p_btnUnmute->height );
952 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
956 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
957 dst_y - (p_btnMute->height >> 1),
958 p_btnMute->width, p_btnMute->height );
960 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
964 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
965 dst_y - (p_timeline->height >> 1),
966 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
968 /* get movie position in % */
969 if( playlist_isplaying() )
971 libvlc_exception_t ex;
972 libvlc_exception_init( &ex );
973 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
974 libvlc_media_player_get_position(libvlc_media_player,&ex));
975 libvlc_exception_clear( &ex );
979 XPutImage( p_display, control, gc, p_btnTime,
980 0, 0, (dst_x+i_last_position),
981 dst_y - (p_btnTime->height >> 1),
982 p_btnTime->width, p_btnTime->height );
984 XFreeGC( p_display, gc );
987 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
989 unsigned int i_dest = BTN_SPACE;
994 fprintf( stderr, "ToolbarButtonClicked:: "
995 "trying to match (%d,%d) (%d,%d)\n",
996 i_xpos, i_ypos, i_tb_height, i_tb_width );
998 if( i_ypos >= i_tb_width )
999 return clicked_Unknown;
1001 /* Note: the order of testing is dependend on the original
1002 * drawing positions of the icon buttons. Buttons are tested
1007 is_playing = playlist_isplaying();
1010 b_mute = libvlc_audio_get_mute( getVLC() );
1012 /* is Pause of Play button clicked */
1013 if( (is_playing != 1) &&
1014 (i_xpos >= (BTN_SPACE>>1)) &&
1015 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1016 return clicked_Play;
1017 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1018 (i_xpos <= i_dest + p_btnPause->width) )
1019 return clicked_Pause;
1021 /* is Stop button clicked */
1022 if( is_playing != 1 )
1023 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1025 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1027 if( (i_xpos >= i_dest) &&
1028 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1029 return clicked_Stop;
1031 /* is Fullscreen button clicked */
1032 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1033 if( (i_xpos >= i_dest) &&
1034 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1035 return clicked_Fullscreen;
1037 /* is Mute or Unmute button clicked */
1038 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1039 if( !b_mute && (i_xpos >= i_dest) &&
1040 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1041 return clicked_Mute;
1042 else if( (i_xpos >= i_dest) &&
1043 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1044 return clicked_Unmute;
1046 /* is timeline clicked */
1048 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1050 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1051 if( (i_xpos >= i_dest) &&
1052 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1053 return clicked_timeline;
1055 /* is time button clicked */
1056 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1057 if( (i_xpos >= i_dest) &&
1058 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1059 return clicked_Time;
1061 return clicked_Unknown;
1066 // Verifies the version of the NPAPI.
1067 // The eventListeners use a NPAPI function available
1069 bool VlcPlugin::canUseEventListener()
1071 int plugin_major, plugin_minor;
1072 int browser_major, browser_minor;
1074 NPN_Version(&plugin_major, &plugin_minor,
1075 &browser_major, &browser_minor);
1077 if (browser_minor >= 19 || browser_major > 0)