]> git.sesse.net Git - vlc/blobdiff - projects/mozilla/vlcshell.cpp
input: Export input_GetState().
[vlc] / projects / mozilla / vlcshell.cpp
index ecb40d8ebe8337c1f46ae17ccaefcc9e49f354aa..be2ea7bbcb03bf59a594e9fbc0e5730be1c1050a 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * vlcshell.cpp: a VLC plugin for Mozilla
  *****************************************************************************
- * Copyright (C) 2002-2005 the VideoLAN team
+ * Copyright (C) 2002-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
+ *          Jean-Paul Saman <jpsaman@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -95,7 +96,7 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
 
         case NPPVpluginDescriptionString:
             snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION,
-                      VLC_Version() );
+                      libvlc_get_version() );
             *((char **)value) = psz_desc;
             return NPERR_NO_ERROR;
 
@@ -490,18 +491,15 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
 #endif /* XP_WIN */
 
 #ifdef XP_UNIX
-    if( p_plugin->b_toolbar )
-    {
-        p_plugin->getToolbarSize( &i_control_width, &i_control_height );
-    }
-    else
-    {
-        i_control_height = i_control_width = 0;
-    }
+    /* default to hidden toolbar, shown at the end of this method if asked *
+     * developers note : getToolbarSize need to wait the end of this method
+     */
+    i_control_height = 0;
+    i_control_width = window->width;
 
     if( window && window->window )
     {
-        Window  parent   = (Window) window->window;
+        Window  parent  = (Window) window->window;
         if( !curwin.window || (parent != (Window)curwin.window) )
         {
             Display *p_display = ( (NPSetWindowCallbackStruct *)
@@ -516,13 +514,10 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
                            window->width, window->height - i_control_height,
                            0, i_blackColor, i_blackColor );
             Window controls = (Window) NULL;
-            if( p_plugin->b_toolbar )
-            {
-                controls = XCreateSimpleWindow( p_display, parent,
-                                0, window->height - i_control_height-1,
-                                window->width, i_control_height-1,
-                                0, i_blackColor, i_blackColor );
-            }
+            controls = XCreateSimpleWindow( p_display, parent,
+                            0, window->height - i_control_height-1,
+                            window->width, i_control_height-1,
+                            0, i_blackColor, i_blackColor );
 
             XMapWindow( p_display, parent );
             XMapWindow( p_display, video );
@@ -561,6 +556,12 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
             if( controls ) { p_plugin->setControlWindow( controls ); }
 
             Redraw( w, (XtPointer)p_plugin, NULL );
+
+            /* now display toolbar if asked through parameters */
+            if( p_plugin->b_toolbar )
+            {
+                p_plugin->showToolbar();
+            }
         }
     }
     else if ( curwin.window )
@@ -800,10 +801,7 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
     unsigned int i_control_height, i_control_width;
 
     if( p_plugin->b_toolbar )
-    {
-        p_plugin->showToolbar();
         p_plugin->getToolbarSize( &i_control_width, &i_control_height );
-    }
     else
         i_control_height = i_control_width = 0;
 
@@ -824,11 +822,7 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
                  WINDOW_TEXT, strlen(WINDOW_TEXT) );
     XFreeGC( p_display, gc );
 
-    if( p_plugin->b_toolbar )
-    {
-        p_plugin->redrawToolbar();
-        p_plugin->hideToolbar();
-    }
+    p_plugin->redrawToolbar();
 }
 
 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
@@ -843,80 +837,106 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
 
     if( p_plugin && p_plugin->b_toolbar )
     {
+        int i_playing;
         libvlc_exception_t ex;
+
         libvlc_exception_init( &ex );
         libvlc_media_player_t *p_md =
                 libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+        if( libvlc_exception_raised(&ex) )
+            fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
+        libvlc_exception_clear( &ex );
+
+        libvlc_exception_init( &ex );
+        i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
+        if( libvlc_exception_raised(&ex) )
+            fprintf( stderr, "%s\n", libvlc_exception_get_message(&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:
             {
-                vlc_int64_t f_length;
                 libvlc_exception_init( &ex );
-                f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
-                libvlc_exception_clear( &ex );
+                if( i_playing == 1 )
+                    libvlc_playlist_pause( p_plugin->getVLC(), &ex );
+                else
+                    libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
 
-                f_length = (float)f_length *
-                           ( ((float)i_xPos-4 ) / ( ((float)i_width-8)/100) );
+                if( libvlc_exception_raised(&ex) )
+                    fprintf( stderr, "%s\n", libvlc_exception_get_message(&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 );
+                if( libvlc_exception_raised(&ex) )
+                    fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
                 libvlc_exception_clear( &ex );
             }
-        }
-
-        /* 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 );
-
-            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 );
-        }
-
-        /* 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 );
-        }
+            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_Fullscreen:
+            {
+                if( (i_playing == 1) && p_md )
+                {
+                    libvlc_exception_init( &ex );
+                    libvlc_set_fullscreen( p_md, 1, &ex );
+                    if( libvlc_exception_raised(&ex) )
+                        fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear( &ex );
+                }
+            }
+            break;
 
-            if( (i_playing == 1) && p_md )
+            case clicked_Mute:
+            case clicked_Unmute:
             {
                 libvlc_exception_init( &ex );
-                libvlc_set_fullscreen( p_md, 1, &ex );
+                libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
+                if( libvlc_exception_raised(&ex) )
+                    fprintf( stderr, "%s\n", libvlc_exception_get_message(&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_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 );
+
+                    f_length = (float)f_length *
+                            ( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) );
+
+                    libvlc_exception_init( &ex );
+                    libvlc_media_player_set_time( p_md, f_length, &ex );
+                    if( libvlc_exception_raised(&ex) )
+                        fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear( &ex );
+                }
+            }
+            break;
+
+            case clicked_Time:
+            {
+                /* Not implemented yet*/
+            }
+            break;
 
+            default: /* button_Unknown */
+            break;
+        }
         if( p_md ) libvlc_media_player_release( p_md );
     }
     Redraw( w, closure, event );