]> git.sesse.net Git - vlc/blobdiff - mozilla/vlcshell.cpp
hmmm i should use a clean tree for update-po
[vlc] / mozilla / vlcshell.cpp
index 15620209a542653f0e621ddbf8ac99499596ee4e..57e3c2b2724539c7161ee4b6b87b662839de7244 100644 (file)
@@ -93,8 +93,7 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
             return NPERR_NO_ERROR;
 
         case NPPVpluginDescriptionString:
-            snprintf( psz_desc, sizeof(psz_desc)-1, PLUGIN_DESCRIPTION, VLC_Version() );
-            psz_desc[sizeof(psz_desc)-1] = 0;
+            snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION, VLC_Version() );
             *((char **)value) = psz_desc;
             return NPERR_NO_ERROR;
 
@@ -121,7 +120,7 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
     {
         case NPPVpluginScriptableNPObject:
             /* create an instance and return it */
-            *(NPObject**)value = NPN_CreateObject(instance, p_plugin->getScriptClass());
+            *(NPObject**)value = p_plugin->getScriptObject();
             if( NULL == *(NPObject**)value )
             {
                 return NPERR_OUT_OF_MEMORY_ERROR;
@@ -140,6 +139,8 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
 #ifdef XP_MACOSX
 int16 NPP_HandleEvent( NPP instance, void * event )
 {
+    static UInt32 lastMouseUp = 0;
+
     if( instance == NULL )
     {
         return false;
@@ -153,7 +154,29 @@ int16 NPP_HandleEvent( NPP instance, void * event )
         case nullEvent:
             break;
         case mouseDown:
+        {
+            if( (myEvent->when - lastMouseUp) < GetDblTime() )
+            {
+                /* double click */
+                libvlc_instance_t *p_vlc = p_plugin->getVLC();
+
+                if( p_vlc )
+                {
+                    if( libvlc_playlist_isplaying(p_vlc, NULL) )
+                    {
+                        libvlc_input_t *p_input = libvlc_playlist_get_input(p_vlc, NULL);
+                        if( p_input )
+                        {
+                            libvlc_toggle_fullscreen(p_input, NULL);
+                            libvlc_input_free(p_input);
+                        }
+                    }
+                }
+            }
+            return true;
+        }
         case mouseUp:
+            lastMouseUp = myEvent->when;
             return true;
         case keyUp:
         case keyDown:
@@ -176,11 +199,11 @@ int16 NPP_HandleEvent( NPP instance, void * event )
                     }
                 }
             }
-            fprintf(stderr, "update !\n");
-            if( needsDisplay )
+
+            const NPWindow *npwindow = p_plugin->getWindow();
+
+            if( needsDisplay && npwindow->window )
             {
-                const NPWindow *npwindow = p_plugin->getWindow();
-                
                 /* draw the beautiful "No Picture" */
 
                 ForeColor(blackColor);
@@ -269,18 +292,28 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
 
 NPError NPP_Destroy( NPP instance, NPSavedData** save )
 {
-    if( instance == NULL )
-    {
+    if( NULL == instance )
         return NPERR_INVALID_INSTANCE_ERROR;
-    }
 
     VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
+    if( NULL == p_plugin )
+        return NPERR_NO_ERROR;
+
+    instance->pdata = NULL;
+
+#if XP_WIN
+    HWND win = (HWND)p_plugin->getWindow()->window;
+    WNDPROC winproc = p_plugin->getWindowProc();
+    if( winproc )
+    {
+        /* reset WNDPROC */
+        SetWindowLong( win, GWL_WNDPROC, (LONG)winproc );
+    }
+#endif
 
     if( p_plugin )
         delete p_plugin;
 
-    instance->pdata = NULL;
-
     return NPERR_NO_ERROR;
 }
 
@@ -333,7 +366,6 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
         view.left    = ((NP_Port*) (window->window))->portx;
         view.bottom  = window->height+view.top;
         view.right   = window->width+view.left;
-fprintf(stderr, "window.x=%d, window.y=%d, port.x=%d, port.y=%d\n", window->x, window->y, view.top, view.left);
         /* clipRect coordinates are also relative to GrafPort */
         clip.top     = window->clipRect.top;
         clip.left    = window->clipRect.left;
@@ -362,13 +394,13 @@ fprintf(stderr, "window.x=%d, window.y=%d, port.x=%d, port.y=%d\n", window->x, w
                 /* reset WNDPROC */
                 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)oldproc );
             }
+            /* attach our plugin object */
+            SetWindowLongPtr((HWND)drawable, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(p_plugin));
+
             /* install our WNDPROC */
             p_plugin->setWindowProc( (WNDPROC)SetWindowLong( drawable,
                                                            GWL_WNDPROC, (LONG)Manage ) );
 
-            /* attach our plugin object */
-            SetWindowLongPtr((HWND)drawable, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(p_plugin));
-
             /* change window style to our liking */
             LONG style = GetWindowLong((HWND)drawable, GWL_STYLE);
             style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
@@ -425,14 +457,14 @@ fprintf(stderr, "window.x=%d, window.y=%d, port.x=%d, port.y=%d\n", window->x, w
     {
         if( p_plugin->psz_target )
         {
-            if( VLC_SUCCESS == libvlc_playlist_add( p_vlc, p_plugin->psz_target, NULL, NULL ) )
+            if( libvlc_playlist_add( p_vlc, p_plugin->psz_target, NULL, NULL ) != -1 )
             {
                 if( p_plugin->b_autoplay )
                 {
                     libvlc_playlist_play(p_vlc, 0, 0, NULL, NULL);
                 }
-                p_plugin->b_stream = VLC_TRUE;
             }
+            p_plugin->b_stream = VLC_TRUE;
         }
     }
     return NPERR_NO_ERROR;
@@ -441,68 +473,41 @@ fprintf(stderr, "window.x=%d, window.y=%d, port.x=%d, port.y=%d\n", window->x, w
 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
                        NPBool seekable, uint16 *stype )
 {
-    if( instance == NULL )
+    if( NULL == instance  )
     {
         return NPERR_INVALID_INSTANCE_ERROR;
     }
 
-#if 0
-    VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
-#endif
-
-    /* fprintf(stderr, "NPP_NewStream - FILE mode !!\n"); */
-
-    /* We want a *filename* ! */
-    *stype = NP_ASFILE;
+    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
 
-#if 0
-    if( !p_plugin->b_stream )
+   /*
+   ** Firefox/Mozilla may decide to open a stream from the URL specified
+   ** in the SRC parameter of the EMBED tag and pass it to us
+   **
+   ** since VLC will open the SRC URL as well, we're not interested in
+   ** that stream. Otherwise, we'll take it and queue it up in the playlist
+   */
+    if( !p_plugin->psz_target || strcmp(stream->url, p_plugin->psz_target) )
     {
-        p_plugin->psz_target = strdup( stream->url );
-        p_plugin->b_stream = VLC_TRUE;
+        /* TODO: use pipes !!!! */
+        *stype = NP_ASFILEONLY;
+        return NPERR_NO_ERROR;
     }
-#endif
-
-    return NPERR_NO_ERROR;
+    return NPERR_GENERIC_ERROR;
 }
 
-int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
-                   * mode so we can take any size stream in our
-                   * write call (since we ignore it) */
-
-#define SARASS_SIZE (1024*1024)
-
 int32 NPP_WriteReady( NPP instance, NPStream *stream )
 {
-    VlcPlugin* p_plugin;
-
-    /* fprintf(stderr, "NPP_WriteReady\n"); */
-
-    if (instance != NULL)
-    {
-        p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
-        /* Muahahahahahahaha */
-        return STREAMBUFSIZE;
-        /*return SARASS_SIZE;*/
-    }
-
-    /* Number of bytes ready to accept in NPP_Write() */
-    return STREAMBUFSIZE;
-    /*return 0;*/
+    /* TODO */
+    return 8*1024;
 }
 
 
 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
                  int32 len, void *buffer )
 {
-    /* fprintf(stderr, "NPP_Write %i\n", (int)len); */
-
-    if( instance != NULL )
-    {
-        /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
-    }
-
-    return len;         /* The number of bytes accepted */
+    /* TODO */
+    return len;
 }
 
 
@@ -512,7 +517,6 @@ NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
     {
         return NPERR_INVALID_INSTANCE_ERROR;
     }
-
     return NPERR_NO_ERROR;
 }
 
@@ -524,14 +528,15 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
         return;
     }
 
-    /* fprintf(stderr, "NPP_StreamAsFile %s\n", fname); */
-
-#if 0
-    VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
+    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
 
-    VLC_AddTarget( p_plugin->i_vlc, fname, 0, 0,
-                   PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
-#endif /* USE_LIBVLC */
+    if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) != -1 )
+    {
+        if( p_plugin->b_autoplay )
+        {
+            libvlc_playlist_play( p_plugin->getVLC(), 0, 0, NULL, NULL);
+        }
+    }
 }
 
 
@@ -639,9 +644,7 @@ static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpa
             FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
             SetTextColor(hdc, RGB(255, 255, 255));
             SetBkColor(hdc, RGB(0, 0, 0));
-            TextOut( hdc, (rect.right-rect.left)/ 2 - 40,
-                          (rect.bottom-rect.top)/ 2,
-                     WINDOW_TEXT, strlen(WINDOW_TEXT) );
+            DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); 
 
             EndPaint( p_hwnd, &paintstruct );
             return 0L;