Try to correctly guess which button has been clicked in the mozilla toolbar.
authorJean-Paul Saman <jpsaman@videolan.org>
Tue, 17 Jun 2008 21:30:14 +0000 (23:30 +0200)
committerJean-Paul Saman <jpsaman@videolan.org>
Wed, 18 Jun 2008 09:39:23 +0000 (11:39 +0200)
projects/mozilla/vlcplugin.cpp
projects/mozilla/vlcplugin.h
projects/mozilla/vlcshell.cpp

index b95ed61..93576b8 100644 (file)
@@ -672,4 +672,82 @@ void VlcPlugin::redrawToolbar()
 
     XFreeGC( p_display, gc );
 }
+
+vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
+{
+    unsigned int i_dest = 0;
+    int i_playing = 0;
+    bool b_mute = false;
+    libvlc_exception_t ex;
+
+    if( i_xpos >= i_tb_height )
+        return clicked_Unknown;
+
+    /* Note: the order of testing is dependend on the original
+     * drawing positions of the icon buttons. Buttons are tested
+     * left to right.
+     */
+
+    /* get isplaying */
+    libvlc_exception_init( &ex );
+    i_playing = libvlc_playlist_isplaying( getVLC(), &ex );
+    libvlc_exception_clear( &ex );
+
+    /* get mute info */
+    libvlc_exception_init(&ex);
+    b_mute = libvlc_audio_get_mute( getVLC(), &ex );
+    libvlc_exception_clear( &ex );
+
+
+    /* is Pause of Play button clicked */
+    if( (i_playing != 1) &&
+        (i_ypos >= BTN_SPACE>>1) &&
+        (i_ypos <= p_btnPlay->width + (BTN_SPACE>>1)) )
+        return clicked_Play;
+    else if( (i_ypos >= BTN_SPACE>>1)  &&
+             (i_ypos <= p_btnPause->width) )
+        return clicked_Pause;
+
+    /* is Stop button clicked */
+    if( i_playing != 1 )
+        i_dest += BTN_SPACE + p_btnPause->width + (BTN_SPACE>>1);
+    else
+        i_dest += BTN_SPACE + p_btnPlay->width + (BTN_SPACE>>1);
+    if( (i_ypos >= i_dest) &&
+        (i_ypos <= p_btnStop->width + (BTN_SPACE>>1)) )
+        return clicked_Stop;
+
+    /* is Fullscreen button clicked */
+    i_dest += (p_btnStop->width + (BTN_SPACE>>1));
+    if( (i_ypos >= i_dest) &&
+        (i_ypos <= p_btnFullscreen->width + (BTN_SPACE>>1)) )
+        return clicked_Fullscreen;
+
+    /* is Mute or Unmute button clicked */
+    i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
+    if( !b_mute && (i_ypos >= i_dest) &&
+        (i_ypos <= p_btnMute->width + (BTN_SPACE>>1)) )
+        return clicked_Mute;
+    else if( (i_ypos >= i_dest) &&
+             (i_ypos <= p_btnUnmute->width + (BTN_SPACE>>1)) )
+        return clicked_Unmute;
+
+    /* is timeline clicked */
+    if( !b_mute )
+        i_dest += (p_btnMute->width + (BTN_SPACE>>1));
+    else
+        i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
+    if( (i_ypos >= i_dest) &&
+        (i_ypos <= p_timeline->width + (BTN_SPACE>>1)) )
+        return clicked_timeline;
+
+    /* is time button clicked */
+    i_dest += (p_timeline->width + (BTN_SPACE>>1));
+    if( (i_ypos >= i_dest) &&
+        (i_ypos <= p_btnTime->width + (BTN_SPACE>>1)) )
+        return clicked_Time;
+
+    return clicked_Unknown;
+}
+#undef BTN_SPACE
 #endif
index 4886aec..713dc58 100644 (file)
 #   define __MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
 #endif
 
+typedef enum vlc_toolbar_clicked_e {
+    clicked_Unknown = 0,
+    clicked_Play,
+    clicked_Pause,
+    clicked_Stop,
+    clicked_timeline,
+    clicked_Time,
+    clicked_Fullscreen,
+    clicked_Mute,
+    clicked_Unmute
+} vlc_toolbar_clicked_t;
+
 class VlcPlugin
 {
 public:
@@ -115,6 +127,7 @@ public:
                             { *width = i_tb_width; *height = i_tb_height; };
     int                 setToolbarSize(unsigned int width, unsigned int height)
                             { i_tb_width = width; i_tb_height = height; return 1; };
+    vlc_toolbar_clicked_t getToolbarButtonClicked( int i_xpos, int i_ypos );
 #endif
 
     uint16    i_npmode; /* either NP_EMBED or NP_FULL */
index b7d835d..a3e783f 100644 (file)
@@ -842,74 +842,90 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
                 libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
         libvlc_exception_clear( &ex );
 
-        /* jump in the movie */
-        if( i_yPos <= (i_height-30) )
+        vlc_toolbar_clicked_t clicked;
+        clicked = p_plugin->getToolbarButtonClicked( i_xPos, i_yPos );
+
+        switch( clicked )
         {
-            /* if a movie is loaded */
-            if( p_md )
+            case clicked_Play:
+            case clicked_Pause:
             {
-                int64_t f_length;
+                int i_playing;
                 libvlc_exception_init( &ex );
-                f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
+                i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
                 libvlc_exception_clear( &ex );
 
-                f_length = (float)f_length *
-                           ( ((float)i_xPos-4 ) / ( ((float)i_width-8)/100) );
+                libvlc_exception_init( &ex );
+                if( i_playing == 1 )
+                    libvlc_playlist_pause( p_plugin->getVLC(), &ex );
+                else
+                    libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
+                libvlc_exception_clear( &ex );
+            }
+            break;
 
+            case clicked_Stop:
+            {
                 libvlc_exception_init( &ex );
-                libvlc_media_player_set_time( p_md, f_length, &ex );
+                libvlc_playlist_stop( p_plugin->getVLC(), &ex );
                 libvlc_exception_clear( &ex );
             }
-        }
+            break;
 
-        /* play/pause toggle */
-        if( (i_yPos > (i_height-30)) && (i_xPos > 4) && (i_xPos <= 39) )
-        {
-            int i_playing;
-            libvlc_exception_init( &ex );
-            i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
-            libvlc_exception_clear( &ex );
+            case clicked_timeline:
+            {
+                /* if a movie is loaded */
+                if( p_md )
+                {
+                    int64_t f_length;
+                    libvlc_exception_init( &ex );
+                    f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
+                    libvlc_exception_clear( &ex );
 
-            libvlc_exception_init( &ex );
-            if( i_playing == 1 )
-                libvlc_playlist_pause( p_plugin->getVLC(), &ex );
-            else
-                libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
-            libvlc_exception_clear( &ex );
-        }
+                    f_length = (float)f_length *
+                            ( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) );
 
-        /* stop */
-        if( (i_yPos > (i_height-30)) && (i_xPos > 39) && (i_xPos < 67) )
-        {
-            libvlc_exception_init( &ex );
-            libvlc_playlist_stop( p_plugin->getVLC(), &ex );
-            libvlc_exception_clear( &ex );
-        }
+                    libvlc_exception_init( &ex );
+                    libvlc_media_player_set_time( p_md, f_length, &ex );
+                    libvlc_exception_clear( &ex );
+                }
+            }
+            break;
 
-        /* fullscreen */
-        if( (i_yPos > (i_height-30)) && (i_xPos >= 67) && (i_xPos < 94) )
-        {
-            int i_playing;
-            libvlc_exception_init( &ex );
-            i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
-            libvlc_exception_clear( &ex );
+            case clicked_Time:
+            {
+                /* Not implemented yet*/
+            }
+            break;
 
-            if( (i_playing == 1) && p_md )
+            case clicked_Fullscreen:
             {
+                int i_playing;
                 libvlc_exception_init( &ex );
-                libvlc_set_fullscreen( p_md, 1, &ex );
+                i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
                 libvlc_exception_clear( &ex );
+
+                if( (i_playing == 1) && p_md )
+                {
+                    libvlc_exception_init( &ex );
+                    libvlc_set_fullscreen( p_md, 1, &ex );
+                    libvlc_exception_clear( &ex );
+                }
             }
-        }
+            break;
 
-        /* mute toggle */
-        if( (i_yPos > (i_height-30)) && (i_xPos >= 94) && (i_xPos < 109))
-        {
-            libvlc_exception_init( &ex );
-            libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
-            libvlc_exception_clear( &ex );
-        }
+            case clicked_Mute:
+            case clicked_Unmute:
+            {
+                libvlc_exception_init( &ex );
+                libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
+                libvlc_exception_clear( &ex );
+            }
+            break;
 
+            default: /* button_Unknown */
+            break;
+        }
         if( p_md ) libvlc_media_player_release( p_md );
     }
     Redraw( w, closure, event );