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