]> git.sesse.net Git - vlc/blob - projects/mozilla/vlcplugin.cpp
Add --no-plugins-cache when compiling the mozilla plugin with debugging enabled,...
[vlc] / projects / mozilla / vlcplugin.cpp
1 /*****************************************************************************
2  * vlcplugin.cpp: a VLC plugin for Mozilla
3  *****************************************************************************
4  * Copyright (C) 2002-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          Damien Fouilleul <damienf.fouilleul@laposte.net>
9  *          Jean-Paul Saman <jpsaman@videolan.org>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
28  *****************************************************************************/
29 #include "config.h"
30
31 #ifdef HAVE_MOZILLA_CONFIG_H
32 #   include <mozilla-config.h>
33 #endif
34
35 #include "vlcplugin.h"
36 #include "control/npolibvlc.h"
37
38 #include <ctype.h>
39
40 /*****************************************************************************
41  * VlcPlugin constructor and destructor
42  *****************************************************************************/
43 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
44     i_npmode(mode),
45     b_stream(0),
46     b_autoplay(1),
47     b_toolbar(0),
48     psz_target(NULL),
49     libvlc_instance(NULL),
50     libvlc_log(NULL),
51     p_scriptClass(NULL),
52     p_browser(instance),
53     psz_baseURL(NULL)
54 #if XP_WIN
55     ,pf_wndproc(NULL)
56 #endif
57 #if XP_UNIX
58     ,i_width((unsigned)-1)
59     ,i_height((unsigned)-1)
60     ,i_tb_width(0)
61     ,i_tb_height(0)
62     ,i_last_position(0)
63     ,p_btnPlay(NULL)
64     ,p_btnPause(NULL)
65     ,p_btnStop(NULL)
66     ,p_btnMute(NULL)
67     ,p_btnUnmute(NULL)
68     ,p_btnFullscreen(NULL)
69     ,p_btnTime(NULL)
70     ,p_timeline(NULL)
71 #endif
72 {
73     memset(&npwindow, 0, sizeof(NPWindow));
74 }
75
76 static bool boolValue(const char *value) {
77     return ( !strcmp(value, "1") ||
78              !strcasecmp(value, "true") ||
79              !strcasecmp(value, "yes") );
80 }
81
82 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
83 {
84     /* prepare VLC command line */
85     const char *ppsz_argv[32];
86     int ppsz_argc = 0;
87
88 #ifndef NDEBUG
89     ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
90 #endif
91
92     /* locate VLC module path */
93 #ifdef XP_MACOSX
94     ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
95     ppsz_argv[ppsz_argc++] = "--vout=macosx";
96 #elif defined(XP_WIN)
97     HKEY h_key;
98     DWORD i_type, i_data = MAX_PATH + 1;
99     char p_data[MAX_PATH + 1];
100     if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
101                       0, KEY_READ, &h_key ) == ERROR_SUCCESS )
102     {
103          if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
104                               (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
105          {
106              if( i_type == REG_SZ )
107              {
108                  strcat( p_data, "\\plugins" );
109                  ppsz_argv[ppsz_argc++] = "--plugin-path";
110                  ppsz_argv[ppsz_argc++] = p_data;
111              }
112          }
113          RegCloseKey( h_key );
114     }
115     ppsz_argv[ppsz_argc++] = "--no-one-instance";
116
117 #endif /* XP_MACOSX */
118
119     /* common settings */
120     ppsz_argv[ppsz_argc++] = "-vv";
121     ppsz_argv[ppsz_argc++] = "--no-stats";
122     ppsz_argv[ppsz_argc++] = "--no-media-library";
123     ppsz_argv[ppsz_argc++] = "--ignore-config";
124     ppsz_argv[ppsz_argc++] = "--intf=dummy";
125     const char *progid = NULL;
126
127     /* parse plugin arguments */
128     for( int i = 0; i < argc ; i++ )
129     {
130         fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]);
131
132         if( !strcmp( argn[i], "target" )
133          || !strcmp( argn[i], "mrl")
134          || !strcmp( argn[i], "filename")
135          || !strcmp( argn[i], "src") )
136         {
137             psz_target = argv[i];
138         }
139         else if( !strcmp( argn[i], "autoplay")
140               || !strcmp( argn[i], "autostart") )
141         {
142             b_autoplay = boolValue(argv[i]);
143         }
144         else if( !strcmp( argn[i], "fullscreen" ) )
145         {
146             if( boolValue(argv[i]) )
147             {
148                 ppsz_argv[ppsz_argc++] = "--fullscreen";
149             }
150             else
151             {
152                 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
153             }
154         }
155         else if( !strcmp( argn[i], "mute" ) )
156         {
157             if( boolValue(argv[i]) )
158             {
159                 ppsz_argv[ppsz_argc++] = "--volume=0";
160             }
161         }
162         else if( !strcmp( argn[i], "loop")
163               || !strcmp( argn[i], "autoloop") )
164         {
165             if( boolValue(argv[i]) )
166             {
167                 ppsz_argv[ppsz_argc++] = "--loop";
168             }
169             else
170             {
171                 ppsz_argv[ppsz_argc++] = "--no-loop";
172             }
173         }
174         else if( !strcmp( argn[i], "version")
175               || !strcmp( argn[i], "progid") )
176         {
177             progid = argv[i];
178         }
179         else if( !strcmp( argn[i], "toolbar" ) )
180         {
181 /* FIXME: Remove this when toolbar functionality has been implemented on\
182  * MacOS X and Win32 for Firefox/Mozilla/Safari. */
183 #ifdef XP_UNIX
184             b_toolbar = boolValue(argv[i]);
185 #endif
186         }
187     }
188
189     libvlc_exception_t ex;
190     libvlc_exception_init(&ex);
191
192     libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, &ex);
193     if( libvlc_exception_raised(&ex) )
194     {
195         libvlc_exception_clear(&ex);
196         return NPERR_GENERIC_ERROR;
197     }
198     libvlc_exception_clear(&ex);
199
200     /*
201     ** fetch plugin base URL, which is the URL of the page containing the plugin
202     ** this URL is used for making absolute URL from relative URL that may be
203     ** passed as an MRL argument
204     */
205     NPObject *plugin;
206
207     if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
208     {
209         /*
210         ** is there a better way to get that info ?
211         */
212         static const char docLocHref[] = "document.location.href";
213         NPString script;
214         NPVariant result;
215
216         script.utf8characters = docLocHref;
217         script.utf8length = sizeof(docLocHref)-1;
218
219         if( NPN_Evaluate(p_browser, plugin, &script, &result) )
220         {
221             if( NPVARIANT_IS_STRING(result) )
222             {
223                 NPString &location = NPVARIANT_TO_STRING(result);
224
225                 psz_baseURL = static_cast<char*>(malloc(location.utf8length+1));
226                 if( psz_baseURL )
227                 {
228                     strncpy(psz_baseURL, location.utf8characters, location.utf8length);
229                     psz_baseURL[location.utf8length] = '\0';
230                 }
231             }
232             NPN_ReleaseVariantValue(&result);
233         }
234         NPN_ReleaseObject(plugin);
235     }
236
237     if( psz_target )
238     {
239         // get absolute URL from src
240         char *psz_absurl = getAbsoluteURL(psz_target);
241         psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
242     }
243
244     /* assign plugin script root class */
245     /* new APIs */
246     p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
247
248     return NPERR_NO_ERROR;
249 }
250
251 VlcPlugin::~VlcPlugin()
252 {
253     free(psz_baseURL);
254     free(psz_target);
255     if( libvlc_log )
256         libvlc_log_close(libvlc_log, NULL);
257     if( libvlc_instance )
258         libvlc_release(libvlc_instance);
259 }
260
261 /*****************************************************************************
262  * VlcPlugin methods
263  *****************************************************************************/
264
265 char *VlcPlugin::getAbsoluteURL(const char *url)
266 {
267     if( NULL != url )
268     {
269         // check whether URL is already absolute
270         const char *end=strchr(url, ':');
271         if( (NULL != end) && (end != url) )
272         {
273             // validate protocol header
274             const char *start = url;
275             char c = *start;
276             if( isalpha(c) )
277             {
278                 ++start;
279                 while( start != end )
280                 {
281                     c  = *start;
282                     if( ! (isalnum(c)
283                        || ('-' == c)
284                        || ('+' == c)
285                        || ('.' == c)
286                        || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
287                         // not valid protocol header, assume relative URL
288                         goto relativeurl;
289                     ++start;
290                 }
291                 /* we have a protocol header, therefore URL is absolute */
292                 return strdup(url);
293             }
294             // not a valid protocol header, assume relative URL
295         }
296
297 relativeurl:
298
299         if( psz_baseURL )
300         {
301             size_t baseLen = strlen(psz_baseURL);
302             char *href = static_cast<char*>(malloc(baseLen+strlen(url)+1));
303             if( href )
304             {
305                 /* prepend base URL */
306                 strcpy(href, psz_baseURL);
307
308                 /*
309                 ** relative url could be empty,
310                 ** in which case return base URL
311                 */
312                 if( '\0' == *url )
313                     return href;
314
315                 /*
316                 ** locate pathname part of base URL
317                 */
318
319                 /* skip over protocol part  */
320                 char *pathstart = strchr(href, ':');
321                 char *pathend;
322                 if( pathstart )
323                 {
324                     if( '/' == *(++pathstart) )
325                     {
326                         if( '/' == *(++pathstart) )
327                         {
328                             ++pathstart;
329                         }
330                     }
331                     /* skip over host part */
332                     pathstart = strchr(pathstart, '/');
333                     pathend = href+baseLen;
334                     if( ! pathstart )
335                     {
336                         // no path, add a / past end of url (over '\0')
337                         pathstart = pathend;
338                         *pathstart = '/';
339                     }
340                 }
341                 else
342                 {
343                     /* baseURL is just a UNIX path */
344                     if( '/' != *href )
345                     {
346                         /* baseURL is not an absolute path */
347                         free(href);
348                         return NULL;
349                     }
350                     pathstart = href;
351                     pathend = href+baseLen;
352                 }
353
354                 /* relative URL made of an absolute path ? */
355                 if( '/' == *url )
356                 {
357                     /* replace path completely */
358                     strcpy(pathstart, url);
359                     return href;
360                 }
361
362                 /* find last path component and replace it */
363                 while( '/' != *pathend)
364                     --pathend;
365
366                 /*
367                 ** if relative url path starts with one or more '../',
368                 ** factor them out of href so that we return a
369                 ** normalized URL
370                 */
371                 while( pathend != pathstart )
372                 {
373                     const char *p = url;
374                     if( '.' != *p )
375                         break;
376                     ++p;
377                     if( '\0' == *p  )
378                     {
379                         /* relative url is just '.' */
380                         url = p;
381                         break;
382                     }
383                     if( '/' == *p  )
384                     {
385                         /* relative url starts with './' */
386                         url = ++p;
387                         continue;
388                     }
389                     if( '.' != *p )
390                         break;
391                     ++p;
392                     if( '\0' == *p )
393                     {
394                         /* relative url is '..' */
395                     }
396                     else
397                     {
398                         if( '/' != *p )
399                             break;
400                         /* relative url starts with '../' */
401                         ++p;
402                     }
403                     url = p;
404                     do
405                     {
406                         --pathend;
407                     }
408                     while( '/' != *pathend );
409                 }
410                 /* skip over '/' separator */
411                 ++pathend;
412                 /* concatenate remaining base URL and relative URL */
413                 strcpy(pathend, url);
414             }
415             return href;
416         }
417     }
418     return NULL;
419 }
420
421 #if XP_UNIX
422 int  VlcPlugin::setSize(unsigned width, unsigned height)
423 {
424     int diff = (width != i_width) || (height != i_height);
425
426     i_width = width;
427     i_height = height;
428
429     /* return size */
430     return diff;
431 }
432
433 #define BTN_SPACE ((unsigned int)4)
434 void VlcPlugin::showToolbar()
435 {
436     const NPWindow& window = getWindow();
437     Window control = getControlWindow();
438     Window video = getVideoWindow();
439     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
440     unsigned int i_height = 0, i_width = BTN_SPACE;
441
442     /* load icons */
443     if( !p_btnPlay )
444         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
445                             &p_btnPlay, NULL, NULL);
446     if( p_btnPlay )
447     {
448         i_height = __MAX( i_height, p_btnPlay->height );
449     }
450     if( !p_btnPause )
451         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
452                             &p_btnPause, NULL, NULL);
453     if( p_btnPause )
454     {
455         i_height = __MAX( i_height, p_btnPause->height );
456     }
457     i_width += __MAX( p_btnPause->width, p_btnPlay->width );
458
459     if( !p_btnStop )
460         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
461                             &p_btnStop, NULL, NULL );
462     if( p_btnStop )
463     {
464         i_height = __MAX( i_height, p_btnStop->height );
465         i_width += BTN_SPACE + p_btnStop->width;
466     }
467     if( !p_timeline )
468         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
469                             &p_timeline, NULL, NULL);
470     if( p_timeline )
471     {
472         i_height = __MAX( i_height, p_timeline->height );
473         i_width += BTN_SPACE + p_timeline->width;
474     }
475     if( !p_btnTime )
476         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
477                             &p_btnTime, NULL, NULL);
478     if( p_btnTime )
479     {
480         i_height = __MAX( i_height, p_btnTime->height );
481         i_width += BTN_SPACE + p_btnTime->width;
482     }
483     if( !p_btnFullscreen )
484         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
485                             &p_btnFullscreen, NULL, NULL);
486     if( p_btnFullscreen )
487     {
488         i_height = __MAX( i_height, p_btnFullscreen->height );
489         i_width += BTN_SPACE + p_btnFullscreen->width;
490     }
491     if( !p_btnMute )
492         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
493                             &p_btnMute, NULL, NULL);
494     if( p_btnMute )
495     {
496         i_height = __MAX( i_height, p_btnMute->height );
497     }
498     if( !p_btnUnmute )
499         XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
500                             &p_btnUnmute, NULL, NULL);
501     if( p_btnUnmute )
502     {
503         i_height = __MAX( i_height, p_btnUnmute->height );
504     }
505     i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
506
507     setToolbarSize( i_width, i_height );
508
509     if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
510         !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
511         fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
512
513     /* reset panels position and size */
514     /* XXX  use i_width */
515     XResizeWindow( p_display, video, window.width, window.height - i_height);
516     XMoveWindow( p_display, control, 0, window.height - i_height );
517     XResizeWindow( p_display, control, window.width, i_height -1);
518
519     b_toolbar = 1; /* says toolbar is now shown */
520     redrawToolbar();
521 }
522
523 void VlcPlugin::hideToolbar()
524 {
525     const NPWindow& window = getWindow();
526     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
527     Window control = getControlWindow();
528     Window video = getVideoWindow();
529
530     i_tb_width = i_tb_height = 0;
531
532     if( p_btnPlay )  XDestroyImage( p_btnPlay );
533     if( p_btnPause ) XDestroyImage( p_btnPause );
534     if( p_btnStop )  XDestroyImage( p_btnStop );
535     if( p_timeline ) XDestroyImage( p_timeline );
536     if( p_btnTime )  XDestroyImage( p_btnTime );
537     if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
538     if( p_btnMute )  XDestroyImage( p_btnMute );
539     if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
540
541     p_btnPlay = NULL;
542     p_btnPause = NULL;
543     p_btnStop = NULL;
544     p_timeline = NULL;
545     p_btnTime = NULL;
546     p_btnFullscreen = NULL;
547     p_btnMute = NULL;
548     p_btnUnmute = NULL;
549
550     /* reset panels position and size */
551     /* XXX  use i_width */
552     XResizeWindow( p_display, video, window.width, window.height );
553     XMoveWindow( p_display, control, 0, window.height-1 );
554     XResizeWindow( p_display, control, window.width, 1 );
555
556     b_toolbar = 0; /* says toolbar is now hidden */
557     redrawToolbar();
558 }
559
560 void VlcPlugin::redrawToolbar()
561 {
562     libvlc_media_player_t *p_md = NULL;
563     libvlc_exception_t ex;
564     float f_position = 0.0;
565     int is_playing = 0;
566     bool b_mute = false;
567     unsigned int dst_x, dst_y;
568     GC gc;
569     XGCValues gcv;
570     unsigned int i_tb_width, i_tb_height;
571
572     /* This method does nothing if toolbar is hidden. */
573     if( !b_toolbar )
574         return;
575
576     const NPWindow& window = getWindow();
577     Window control = getControlWindow();
578     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
579
580     getToolbarSize( &i_tb_width, &i_tb_height );
581
582     /* get media instance */
583     libvlc_exception_init( &ex );
584     p_md = libvlc_playlist_get_media_player( getVLC(), &ex );
585     libvlc_exception_clear( &ex );
586     if( p_md )
587     {
588         /* get isplaying */
589         libvlc_playlist_lock( getVLC() );
590         is_playing = libvlc_playlist_isplaying( getVLC(), &ex );
591         libvlc_playlist_unlock( getVLC() );
592         libvlc_exception_clear( &ex );
593
594         /* get movie position in % */
595         if( is_playing == 1 )
596         {
597             f_position = libvlc_media_player_get_position( p_md, &ex ) * 100.0;
598             libvlc_exception_clear( &ex );
599         }
600         libvlc_media_player_release( p_md );
601     }
602
603     /* get mute info */
604     b_mute = libvlc_audio_get_mute( getVLC(), &ex );
605     libvlc_exception_clear( &ex );
606
607     gcv.foreground = BlackPixel( p_display, 0 );
608     gc = XCreateGC( p_display, control, GCForeground, &gcv );
609
610     XFillRectangle( p_display, control, gc,
611                     0, 0, window.width, i_tb_height );
612     gcv.foreground = WhitePixel( p_display, 0 );
613     XChangeGC( p_display, gc, GCForeground, &gcv );
614
615     /* position icons */
616     dst_x = BTN_SPACE;
617     dst_y = i_tb_height >> 1; /* baseline = vertical middle */
618
619     if( p_btnPause && (is_playing == 1) )
620     {
621         XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
622                    dst_y - (p_btnPause->height >> 1),
623                    p_btnPause->width, p_btnPause->height );
624         dst_x += BTN_SPACE + p_btnPause->width;
625     }
626     else if( p_btnPlay )
627     {
628         XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
629                    dst_y - (p_btnPlay->height >> 1),
630                    p_btnPlay->width, p_btnPlay->height );
631         dst_x += BTN_SPACE + p_btnPlay->width;
632     }
633
634     if( p_btnStop )
635         XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
636                    dst_y - (p_btnStop->height >> 1),
637                    p_btnStop->width, p_btnStop->height );
638
639     dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
640
641     if( p_btnFullscreen )
642         XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
643                    dst_y - (p_btnFullscreen->height >> 1),
644                    p_btnFullscreen->width, p_btnFullscreen->height );
645
646     dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
647
648     if( p_btnUnmute && b_mute )
649     {
650         XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
651                    dst_y - (p_btnUnmute->height >> 1),
652                    p_btnUnmute->width, p_btnUnmute->height );
653
654         dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
655     }
656     else if( p_btnMute )
657     {
658         XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
659                    dst_y - (p_btnMute->height >> 1),
660                    p_btnMute->width, p_btnMute->height );
661
662         dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
663     }
664
665     if( p_timeline )
666         XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
667                    dst_y - (p_timeline->height >> 1),
668                    (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
669
670     if( f_position > 0 )
671         i_last_position = (int)( f_position *
672                         ( ((float)(window.width-(dst_x+BTN_SPACE))) / 100.0 ));
673
674     if( p_btnTime )
675         XPutImage( p_display, control, gc, p_btnTime,
676                    0, 0, (dst_x+i_last_position),
677                    dst_y - (p_btnTime->height >> 1),
678                    p_btnTime->width, p_btnTime->height );
679
680     XFreeGC( p_display, gc );
681 }
682
683 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
684 {
685     unsigned int i_dest = BTN_SPACE;//(i_tb_height >> 1);
686     int is_playing = 0;
687     bool b_mute = false;
688     libvlc_exception_t ex;
689
690     fprintf( stderr, "ToolbarButtonClicked:: "
691                      "trying to match (%d,%d) (%d,%d)\n",
692              i_xpos, i_ypos, i_tb_height, i_tb_width );
693
694     if( i_ypos >= i_tb_width )
695         return clicked_Unknown;
696
697     /* Note: the order of testing is dependend on the original
698      * drawing positions of the icon buttons. Buttons are tested
699      * left to right.
700      */
701
702     /* get isplaying */
703     libvlc_exception_init( &ex );
704     libvlc_playlist_lock( getVLC() );
705     is_playing = libvlc_playlist_isplaying( getVLC(), &ex );
706     libvlc_playlist_unlock( getVLC() );
707     libvlc_exception_clear( &ex );
708
709     /* get mute info */
710     b_mute = libvlc_audio_get_mute( getVLC(), &ex );
711     libvlc_exception_clear( &ex );
712
713     /* is Pause of Play button clicked */
714     if( (is_playing != 1) &&
715         (i_xpos >= (BTN_SPACE>>1)) &&
716         (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
717         return clicked_Play;
718     else if( (i_xpos >= (BTN_SPACE>>1))  &&
719              (i_xpos <= i_dest + p_btnPause->width) )
720         return clicked_Pause;
721
722     /* is Stop button clicked */
723     if( is_playing != 1 )
724         i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
725     else
726         i_dest += (p_btnPause->width + (BTN_SPACE>>1));
727
728     if( (i_xpos >= i_dest) &&
729         (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
730         return clicked_Stop;
731
732     /* is Fullscreen button clicked */
733     i_dest += (p_btnStop->width + (BTN_SPACE>>1));
734     if( (i_xpos >= i_dest) &&
735         (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
736         return clicked_Fullscreen;
737
738     /* is Mute or Unmute button clicked */
739     i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
740     if( !b_mute && (i_xpos >= i_dest) &&
741         (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
742         return clicked_Mute;
743     else if( (i_xpos >= i_dest) &&
744              (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
745         return clicked_Unmute;
746
747     /* is timeline clicked */
748     if( !b_mute )
749         i_dest += (p_btnMute->width + (BTN_SPACE>>1));
750     else
751         i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
752     if( (i_xpos >= i_dest) &&
753         (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
754         return clicked_timeline;
755
756     /* is time button clicked */
757     i_dest += (p_timeline->width + (BTN_SPACE>>1));
758     if( (i_xpos >= i_dest) &&
759         (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
760         return clicked_Time;
761
762     return clicked_Unknown;
763 }
764 #undef BTN_SPACE
765 #endif