Add "toolbar:bool" RW property for the JS API, fix toolbar visibility
authorAnthony Loiseau <anthony.loiseau@gmail.com>
Mon, 31 Mar 2008 15:03:31 +0000 (17:03 +0200)
committerJean-Paul Saman <jpsaman@videolan.org>
Wed, 18 Jun 2008 09:39:23 +0000 (11:39 +0200)
The mozilla plugin has already a "toolbar"(bool) parameter.
For coherency between ActiveX and mozilla plugin, the "toolbar"
parameter has been added to ActiveX, which has created also a
"toolbar" property in the exported API (JavaScript for web pages).
This commit add it to mozilla plugin too, to maintain coherency.

This commit also fix toolbar visibility when toolbar="true" parameter
is used in embed object.

Signed-off-by: Jean-Paul Saman <jpsaman@videolan.org>
projects/mozilla/vlcplugin.cpp
projects/mozilla/vlcshell.cpp

index d9e631c..b95ed61 100644 (file)
@@ -59,6 +59,14 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
     ,i_tb_width(0)
     ,i_tb_height(0)
     ,i_last_position(0)
     ,i_tb_width(0)
     ,i_tb_height(0)
     ,i_last_position(0)
+    ,p_btnPlay(NULL)
+    ,p_btnPause(NULL)
+    ,p_btnStop(NULL)
+    ,p_btnMute(NULL)
+    ,p_btnUnmute(NULL)
+    ,p_btnFullscreen(NULL)
+    ,p_btnTime(NULL)
+    ,p_timeline(NULL)
 #endif
 {
     memset(&npwindow, 0, sizeof(NPWindow));
 #endif
 {
     memset(&npwindow, 0, sizeof(NPWindow));
@@ -157,7 +165,8 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
             {
                 ppsz_argv[ppsz_argc++] = "--loop";
             }
             {
                 ppsz_argv[ppsz_argc++] = "--loop";
             }
-            else {
+            else
+            {
                 ppsz_argv[ppsz_argc++] = "--no-loop";
             }
         }
                 ppsz_argv[ppsz_argc++] = "--no-loop";
             }
         }
@@ -418,61 +427,70 @@ void VlcPlugin::showToolbar()
 {
     const NPWindow& window = getWindow();
     Window control = getControlWindow();
 {
     const NPWindow& window = getWindow();
     Window control = getControlWindow();
+    Window video = getVideoWindow();
     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
     unsigned int i_height = 0, i_width = 0;
 
     /* load icons */
     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
     unsigned int i_height = 0, i_width = 0;
 
     /* load icons */
-    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
-                        &p_btnPlay, NULL, NULL);
+    if( !p_btnPlay )
+        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
+                            &p_btnPlay, NULL, NULL);
     if( p_btnPlay )
     {
         i_height = __MAX( i_height, p_btnPlay->height );
         i_width += p_btnPlay->width;
     }
     if( p_btnPlay )
     {
         i_height = __MAX( i_height, p_btnPlay->height );
         i_width += p_btnPlay->width;
     }
-    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
-                        &p_btnPause, NULL, NULL);
+    if( !p_btnPause )
+        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
+                            &p_btnPause, NULL, NULL);
     if( p_btnPause )
     {
         i_height = __MAX( i_height, p_btnPause->height );
         i_width += p_btnPause->width;
     }
     if( p_btnPause )
     {
         i_height = __MAX( i_height, p_btnPause->height );
         i_width += p_btnPause->width;
     }
-    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
-                        &p_btnStop, NULL, NULL );
+    if( !p_btnStop )
+        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
+                            &p_btnStop, NULL, NULL );
     if( p_btnStop )
     {
         i_height = __MAX( i_height, p_btnStop->height );
         i_width += p_btnStop->width;
     }
     if( p_btnStop )
     {
         i_height = __MAX( i_height, p_btnStop->height );
         i_width += p_btnStop->width;
     }
-    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
-                        &p_timeline, NULL, NULL);
+    if( !p_timeline )
+        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
+                            &p_timeline, NULL, NULL);
     if( p_timeline )
     {
         i_height = __MAX( i_height, p_timeline->height );
         i_width += p_timeline->width;
     }
     if( p_timeline )
     {
         i_height = __MAX( i_height, p_timeline->height );
         i_width += p_timeline->width;
     }
-    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
-                        &p_btnTime, NULL, NULL);
+    if( !p_btnTime )
+        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
+                            &p_btnTime, NULL, NULL);
     if( p_btnTime )
     {
         i_height = __MAX( i_height, p_btnTime->height );
         i_width += p_btnTime->width;
     }
     if( p_btnTime )
     {
         i_height = __MAX( i_height, p_btnTime->height );
         i_width += p_btnTime->width;
     }
-    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
-                        &p_btnFullscreen, NULL, NULL);
+    if( !p_btnFullscreen )
+        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
+                            &p_btnFullscreen, NULL, NULL);
     if( p_btnFullscreen )
     {
         i_height = __MAX( i_height, p_btnFullscreen->height );
         i_width += p_btnFullscreen->width;
     }
     if( p_btnFullscreen )
     {
         i_height = __MAX( i_height, p_btnFullscreen->height );
         i_width += p_btnFullscreen->width;
     }
-    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
-                        &p_btnMute, NULL, NULL);
+    if( !p_btnMute )
+        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
+                            &p_btnMute, NULL, NULL);
     if( p_btnMute )
     {
         i_height = __MAX( i_height, p_btnMute->height );
         i_width += p_btnMute->width;
     }
     if( p_btnMute )
     {
         i_height = __MAX( i_height, p_btnMute->height );
         i_width += p_btnMute->width;
     }
-    XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
-                        &p_btnUnmute, NULL, NULL);
+    if( !p_btnUnmute )
+        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
+                            &p_btnUnmute, NULL, NULL);
     if( p_btnUnmute )
     {
         i_height = __MAX( i_height, p_btnUnmute->height );
     if( p_btnUnmute )
     {
         i_height = __MAX( i_height, p_btnUnmute->height );
@@ -483,10 +501,24 @@ void VlcPlugin::showToolbar()
     if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
         !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
         fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
     if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
         !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
         fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
+
+    /* reset panels position and size */
+    /* XXX  use i_width */
+    XResizeWindow( p_display, video, window.width, window.height - i_height);
+    XMoveWindow( p_display, control, 0, window.height - i_height );
+    XResizeWindow( p_display, control, window.width, i_height -1);
+
+    b_toolbar = 1; /* says toolbar is now shown */
+    redrawToolbar();
 }
 
 void VlcPlugin::hideToolbar()
 {
 }
 
 void VlcPlugin::hideToolbar()
 {
+    const NPWindow& window = getWindow();
+    Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
+    Window control = getControlWindow();
+    Window video = getVideoWindow();
+
     i_tb_width = i_tb_height = 0;
 
     if( p_btnPlay )  XDestroyImage( p_btnPlay );
     i_tb_width = i_tb_height = 0;
 
     if( p_btnPlay )  XDestroyImage( p_btnPlay );
@@ -506,6 +538,15 @@ void VlcPlugin::hideToolbar()
     p_btnFullscreen = NULL;
     p_btnMute = NULL;
     p_btnUnmute = NULL;
     p_btnFullscreen = NULL;
     p_btnMute = NULL;
     p_btnUnmute = NULL;
+
+    /* reset panels position and size */
+    /* XXX  use i_width */
+    XResizeWindow( p_display, video, window.width, window.height );
+    XMoveWindow( p_display, control, 0, window.height-1 );
+    XResizeWindow( p_display, control, window.width, 1 );
+
+    b_toolbar = 0; /* says toolbar is now hidden */
+    redrawToolbar();
 }
 
 void VlcPlugin::redrawToolbar()
 }
 
 void VlcPlugin::redrawToolbar()
@@ -518,12 +559,19 @@ void VlcPlugin::redrawToolbar()
     unsigned int dst_x, dst_y;
     GC gc;
     XGCValues gcv;
     unsigned int dst_x, dst_y;
     GC gc;
     XGCValues gcv;
+    unsigned int i_tb_width, i_tb_height;
 #define BTN_SPACE ((unsigned int)4)
 
 #define BTN_SPACE ((unsigned int)4)
 
+    /* This method does nothing if toolbar is hidden. */
+    if( !b_toolbar )
+        return;
+
     const NPWindow& window = getWindow();
     Window control = getControlWindow();
     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
 
     const NPWindow& window = getWindow();
     Window control = getControlWindow();
     Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
 
+    getToolbarSize( &i_tb_width, &i_tb_height );
+
     /* get media instance */
     libvlc_exception_init( &ex );
     p_md = libvlc_playlist_get_media_player( getVLC(), &ex );
     /* get media instance */
     libvlc_exception_init( &ex );
     p_md = libvlc_playlist_get_media_player( getVLC(), &ex );
@@ -557,64 +605,69 @@ void VlcPlugin::redrawToolbar()
     XChangeGC( p_display, gc, GCForeground, &gcv );
 
     /* position icons */
     XChangeGC( p_display, gc, GCForeground, &gcv );
 
     /* position icons */
-    dst_x = 4; dst_y = 4;
+    dst_x = BTN_SPACE;
+    dst_y = i_tb_height >> 1; /* baseline = vertical middle */
 
     fprintf( stderr, ">>>>>> is playing = %d\n", i_playing );
     if( p_btnPause && (i_playing == 1) )
     {
 
     fprintf( stderr, ">>>>>> is playing = %d\n", i_playing );
     if( p_btnPause && (i_playing == 1) )
     {
-        XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x, dst_y,
+        XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
+                   dst_y - (p_btnPause->height >> 1),
                    p_btnPause->width, p_btnPause->height );
                    p_btnPause->width, p_btnPause->height );
+        dst_x += BTN_SPACE + p_btnPause->width;
     }
     else if( p_btnPlay )
     {
     }
     else if( p_btnPlay )
     {
-        XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x, dst_y,
+        XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
+                   dst_y - (p_btnPlay->height >> 1),
                    p_btnPlay->width, p_btnPlay->height );
                    p_btnPlay->width, p_btnPlay->height );
+        dst_x += BTN_SPACE + p_btnPlay->width;
     }
 
     }
 
-    dst_x += BTN_SPACE + ( p_btnPlay ? p_btnPlay->width : 0 );
-    dst_y = 4;
-
     if( p_btnStop )
     if( p_btnStop )
-        XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x, dst_y,
+        XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
+                   dst_y - (p_btnStop->height >> 1),
                    p_btnStop->width, p_btnStop->height );
 
     dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
                    p_btnStop->width, p_btnStop->height );
 
     dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
-    dst_y = 4;
 
     if( p_btnFullscreen )
 
     if( p_btnFullscreen )
-        XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x, dst_y,
+        XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
+                   dst_y - (p_btnFullscreen->height >> 1),
                    p_btnFullscreen->width, p_btnFullscreen->height );
 
     dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
                    p_btnFullscreen->width, p_btnFullscreen->height );
 
     dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
-    dst_y = 4;
 
     if( p_btnUnmute && b_mute )
     {
 
     if( p_btnUnmute && b_mute )
     {
-        XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x, dst_y,
+        XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
+                   dst_y - (p_btnUnmute->height >> 1),
                    p_btnUnmute->width, p_btnUnmute->height );
 
         dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
                    p_btnUnmute->width, p_btnUnmute->height );
 
         dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
-        dst_y = 4;
     }
     else if( p_btnMute )
     {
     }
     else if( p_btnMute )
     {
-        XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x, dst_y,
+        XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
+                   dst_y - (p_btnMute->height >> 1),
                    p_btnMute->width, p_btnMute->height );
 
         dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
                    p_btnMute->width, p_btnMute->height );
 
         dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
-        dst_y = 4;
     }
 
     if( p_timeline )
     }
 
     if( p_timeline )
-        XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x, dst_y,
+        XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
+                   dst_y - (p_timeline->height >> 1),
                    (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
 
     if( f_position > 0 )
                    (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
 
     if( f_position > 0 )
-        i_last_position = (((float)window.width-8.0)/100.0)*f_position;
+        i_last_position = (int)( f_position *
+                        ( ((float)(window.width-(dst_x+BTN_SPACE))) / 100.0 ));
 
     if( p_btnTime )
         XPutImage( p_display, control, gc, p_btnTime,
 
     if( p_btnTime )
         XPutImage( p_display, control, gc, p_btnTime,
-                   0, 0, (dst_x+i_last_position), dst_y,
+                   0, 0, (dst_x+i_last_position),
+                   dst_y - (p_btnTime->height >> 1),
                    p_btnTime->width, p_btnTime->height );
 
     XFreeGC( p_display, gc );
                    p_btnTime->width, p_btnTime->height );
 
     XFreeGC( p_display, gc );
index 4d93ae9..b7d835d 100644 (file)
@@ -490,18 +490,15 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
 #endif /* XP_WIN */
 
 #ifdef XP_UNIX
 #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 )
     {
 
     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 *)
         if( !curwin.window || (parent != (Window)curwin.window) )
         {
             Display *p_display = ( (NPSetWindowCallbackStruct *)
@@ -516,13 +513,10 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
                            window->width, window->height - i_control_height,
                            0, i_blackColor, i_blackColor );
             Window controls = (Window) NULL;
                            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 );
 
             XMapWindow( p_display, parent );
             XMapWindow( p_display, video );
@@ -561,6 +555,12 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
             if( controls ) { p_plugin->setControlWindow( controls ); }
 
             Redraw( w, (XtPointer)p_plugin, NULL );
             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 )
         }
     }
     else if ( curwin.window )
@@ -800,10 +800,7 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
     unsigned int i_control_height, i_control_width;
 
     if( p_plugin->b_toolbar )
     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 );
         p_plugin->getToolbarSize( &i_control_width, &i_control_height );
-    }
     else
         i_control_height = i_control_width = 0;
 
     else
         i_control_height = i_control_width = 0;
 
@@ -824,11 +821,7 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
                  WINDOW_TEXT, strlen(WINDOW_TEXT) );
     XFreeGC( p_display, gc );
 
                  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 )
 }
 
 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )