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