]> git.sesse.net Git - vlc/blob - projects/mozilla/vlcplugin.cpp
Fix mozilla toolbar button click logic.
[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
195     /*
196     ** fetch plugin base URL, which is the URL of the page containing the plugin
197     ** this URL is used for making absolute URL from relative URL that may be
198     ** passed as an MRL argument
199     */
200     NPObject *plugin;
201
202     if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
203     {
204         /*
205         ** is there a better way to get that info ?
206         */
207         static const char docLocHref[] = "document.location.href";
208         NPString script;
209         NPVariant result;
210
211         script.utf8characters = docLocHref;
212         script.utf8length = sizeof(docLocHref)-1;
213
214         if( NPN_Evaluate(p_browser, plugin, &script, &result) )
215         {
216             if( NPVARIANT_IS_STRING(result) )
217             {
218                 NPString &location = NPVARIANT_TO_STRING(result);
219
220                 psz_baseURL = new char[location.utf8length+1];
221                 if( psz_baseURL )
222                 {
223                     strncpy(psz_baseURL, location.utf8characters, location.utf8length);
224                     psz_baseURL[location.utf8length] = '\0';
225                 }
226             }
227             NPN_ReleaseVariantValue(&result);
228         }
229         NPN_ReleaseObject(plugin);
230     }
231
232     if( psz_target )
233     {
234         // get absolute URL from src
235         char *psz_absurl = getAbsoluteURL(psz_target);
236         psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
237     }
238
239     /* assign plugin script root class */
240     /* new APIs */
241     p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
242
243     return NPERR_NO_ERROR;
244 }
245
246 VlcPlugin::~VlcPlugin()
247 {
248     delete psz_baseURL;
249     delete psz_target;
250     if( libvlc_log )
251         libvlc_log_close(libvlc_log, NULL);
252     if( libvlc_instance )
253         libvlc_release(libvlc_instance);
254 }
255
256 /*****************************************************************************
257  * VlcPlugin methods
258  *****************************************************************************/
259
260 char *VlcPlugin::getAbsoluteURL(const char *url)
261 {
262     if( NULL != url )
263     {
264         // check whether URL is already absolute
265         const char *end=strchr(url, ':');
266         if( (NULL != end) && (end != url) )
267         {
268             // validate protocol header
269             const char *start = url;
270             char c = *start;
271             if( isalpha(c) )
272             {
273                 ++start;
274                 while( start != end )
275                 {
276                     c  = *start;
277                     if( ! (isalnum(c)
278                        || ('-' == c)
279                        || ('+' == c)
280                        || ('.' == c)
281                        || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
282                         // not valid protocol header, assume relative URL
283                         goto relativeurl;
284                     ++start;
285                 }
286                 /* we have a protocol header, therefore URL is absolute */
287                 return strdup(url);
288             }
289             // not a valid protocol header, assume relative URL
290         }
291
292 relativeurl:
293
294         if( psz_baseURL )
295         {
296             size_t baseLen = strlen(psz_baseURL);
297             char *href = new char[baseLen+strlen(url)+1];
298             if( href )
299             {
300                 /* prepend base URL */
301                 strcpy(href, psz_baseURL);
302
303                 /*
304                 ** relative url could be empty,
305                 ** in which case return base URL
306                 */
307                 if( '\0' == *url )
308                     return href;
309
310                 /*
311                 ** locate pathname part of base URL
312                 */
313
314                 /* skip over protocol part  */
315                 char *pathstart = strchr(href, ':');
316                 char *pathend;
317                 if( pathstart )
318                 {
319                     if( '/' == *(++pathstart) )
320                     {
321                         if( '/' == *(++pathstart) )
322                         {
323                             ++pathstart;
324                         }
325                     }
326                     /* skip over host part */
327                     pathstart = strchr(pathstart, '/');
328                     pathend = href+baseLen;
329                     if( ! pathstart )
330                     {
331                         // no path, add a / past end of url (over '\0')
332                         pathstart = pathend;
333                         *pathstart = '/';
334                     }
335                 }
336                 else
337                 {
338                     /* baseURL is just a UNIX path */
339                     if( '/' != *href )
340                     {
341                         /* baseURL is not an absolute path */
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     libvlc_exception_init( &ex );
583     i_playing = libvlc_playlist_isplaying( getVLC(), &ex );
584     libvlc_exception_clear( &ex );
585
586     /* get mute info */
587     libvlc_exception_init(&ex);
588     b_mute = libvlc_audio_get_mute( getVLC(), &ex );
589     libvlc_exception_clear( &ex );
590
591     /* get movie position in % */
592     if( i_playing == 1 )
593     {
594         libvlc_exception_init( &ex );
595         f_position = libvlc_media_player_get_position( p_md, &ex ) * 100;
596         libvlc_exception_clear( &ex );
597     }
598     libvlc_media_player_release( p_md );
599
600     gcv.foreground = BlackPixel( p_display, 0 );
601     gc = XCreateGC( p_display, control, GCForeground, &gcv );
602
603     XFillRectangle( p_display, control, gc,
604                     0, 0, window.width, i_tb_height );
605     gcv.foreground = WhitePixel( p_display, 0 );
606     XChangeGC( p_display, gc, GCForeground, &gcv );
607
608     /* position icons */
609     dst_x = BTN_SPACE;
610     dst_y = i_tb_height >> 1; /* baseline = vertical middle */
611
612     if( p_btnPause && (i_playing == 1) )
613     {
614         XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
615                    dst_y - (p_btnPause->height >> 1),
616                    p_btnPause->width, p_btnPause->height );
617         dst_x += BTN_SPACE + p_btnPause->width;
618     }
619     else if( p_btnPlay )
620     {
621         XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
622                    dst_y - (p_btnPlay->height >> 1),
623                    p_btnPlay->width, p_btnPlay->height );
624         dst_x += BTN_SPACE + p_btnPlay->width;
625     }
626
627     if( p_btnStop )
628         XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
629                    dst_y - (p_btnStop->height >> 1),
630                    p_btnStop->width, p_btnStop->height );
631
632     dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
633
634     if( p_btnFullscreen )
635         XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
636                    dst_y - (p_btnFullscreen->height >> 1),
637                    p_btnFullscreen->width, p_btnFullscreen->height );
638
639     dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
640
641     if( p_btnUnmute && b_mute )
642     {
643         XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
644                    dst_y - (p_btnUnmute->height >> 1),
645                    p_btnUnmute->width, p_btnUnmute->height );
646
647         dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
648     }
649     else if( p_btnMute )
650     {
651         XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
652                    dst_y - (p_btnMute->height >> 1),
653                    p_btnMute->width, p_btnMute->height );
654
655         dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
656     }
657
658     if( p_timeline )
659         XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
660                    dst_y - (p_timeline->height >> 1),
661                    (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
662
663     if( f_position > 0 )
664         i_last_position = (int)( f_position *
665                         ( ((float)(window.width-(dst_x+BTN_SPACE))) / 100.0 ));
666
667     if( p_btnTime )
668         XPutImage( p_display, control, gc, p_btnTime,
669                    0, 0, (dst_x+i_last_position),
670                    dst_y - (p_btnTime->height >> 1),
671                    p_btnTime->width, p_btnTime->height );
672
673     XFreeGC( p_display, gc );
674 }
675
676 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
677 {
678     unsigned int i_dest = BTN_SPACE;//(i_tb_height >> 1);
679     int i_playing = 0;
680     bool b_mute = false;
681     libvlc_exception_t ex;
682
683     fprintf( stderr, "ToolbarButtonClicked:: "
684                      "trying to match (%d,%d) (%d,%d)\n",
685              i_xpos, i_ypos, i_tb_height, i_tb_width );
686
687     if( i_ypos >= i_tb_width )
688         return clicked_Unknown;
689
690     /* Note: the order of testing is dependend on the original
691      * drawing positions of the icon buttons. Buttons are tested
692      * left to right.
693      */
694
695     /* get isplaying */
696     libvlc_exception_init( &ex );
697     i_playing = libvlc_playlist_isplaying( getVLC(), &ex );
698     libvlc_exception_clear( &ex );
699
700     /* get mute info */
701     libvlc_exception_init(&ex);
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