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