* XPCOM implementation in mozilla plugin on MacOSX (Play, pause, stop
[vlc.git] / mozilla / vlcshell.cpp
index 2fe7a94..1be001f 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * vlcshell.c: a VideoLAN Client plugin for Mozilla
+ * vlcshell.cpp: a VLC plugin for Mozilla
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: vlcshell.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
+ * $Id: vlcshell.cpp,v 1.18 2003/08/19 14:07:51 garf Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+/* XXX: disable VLC here */
+#define USE_LIBVLC 1
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
+
+/* vlc stuff */
+#ifdef USE_LIBVLC
+#   include <vlc/vlc.h>
+#endif
 
 /* Mozilla stuff */
-#include <plugin/npapi.h>
+#include <nsISupports.h>
+#include <nsMemory.h>
+#include <npapi.h>
 
-/* X11 stuff */
-#include <X11/Xlib.h>
-#include <X11/Intrinsic.h>
-#include <X11/StringDefs.h>
+#ifdef XP_WIN
+    /* Windows stuff */
+#endif
 
-/* vlc stuff */
-#include <vlc/vlc.h>
-#include "config.h"
+#ifdef XP_MACOSX
+    /* Mac OS X stuff */
+#   include <QuickDraw.h>
+#endif
 
 #include "vlcpeer.h"
 #include "vlcplugin.h"
 
-/******************************************************************************
+#if USE_LIBVLC
+#   define WINDOW_TEXT "(no picture)"
+#else
+#   define WINDOW_TEXT "(no libvlc)"
+#endif
+
+/* No, I really don't want to use XP_UNIX stuff on MacOSX */
+#ifdef XP_MACOSX
+#undef XP_UNIX
+#endif
+
+#ifdef XP_UNIX
+    /* X11 stuff */
+#   include <X11/Xlib.h>
+#   include <X11/Intrinsic.h>
+#   include <X11/StringDefs.h>
+#endif
+
+/*****************************************************************************
  * Unix-only declarations
- ******************************************************************************/
-#ifndef WIN32
+******************************************************************************/
+#ifdef XP_UNIX
+#   define VOUT_PLUGINS "xvideo,x11,dummy"
+#   define AOUT_PLUGINS "oss,dummy"
+
 static void Redraw( Widget w, XtPointer closure, XEvent *event );
 #endif
 
-/******************************************************************************
+/*****************************************************************************
+ * MacOS-only declarations
+******************************************************************************/
+#ifdef XP_MACOSX
+#   define VOUT_PLUGINS "macosx"
+#   define AOUT_PLUGINS "macosx"
+
+#endif
+
+/*****************************************************************************
  * Windows-only declarations
  *****************************************************************************/
-#ifdef WIN32
+#ifdef XP_WIN
+#   define VOUT_PLUGINS "directx,dummy"
+#   define AOUT_PLUGINS "none" /* "directx,waveout,dummy" */
+
 HINSTANCE g_hDllInstance = NULL;
 
 BOOL WINAPI
@@ -60,17 +104,20 @@ DllMain( HINSTANCE  hinstDLL,                   // handle of DLL module
                     DWORD  fdwReason,       // reason for calling function
                     LPVOID  lpvReserved)
 {
-        switch (fdwReason) {
-                case DLL_PROCESS_ATTACH:
-                  g_hDllInstance = hinstDLL;
-                  break;
-                case DLL_THREAD_ATTACH:
-                case DLL_PROCESS_DETACH:
-                case DLL_THREAD_DETACH:
-                break;
-        }
-        return TRUE;
+    switch (fdwReason)
+    {
+        case DLL_PROCESS_ATTACH:
+            g_hDllInstance = hinstDLL;
+            break;
+        case DLL_THREAD_ATTACH:
+        case DLL_PROCESS_DETACH:
+        case DLL_THREAD_DETACH:
+            break;
+    }
+    return TRUE;
 }
+
+LRESULT CALLBACK Manage( HWND, UINT, WPARAM, LPARAM );
 #endif
 
 /******************************************************************************
@@ -83,7 +130,9 @@ char * NPP_GetMIMEDescription( void )
 
 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
 {
+
     static nsIID nsid = VLCINTF_IID;
+    static char psz_desc[1000];
 
     switch( variable )
     {
@@ -92,8 +141,18 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
             return NPERR_NO_ERROR;
 
         case NPPVpluginDescriptionString:
-            *((char **)value) = PLUGIN_DESCRIPTION;
+#if USE_LIBVLC
+            snprintf( psz_desc, 1000-1, PLUGIN_DESCRIPTION, VLC_Version() );
+#else
+            snprintf( psz_desc, 1000-1, PLUGIN_DESCRIPTION, "(disabled)" );
+#endif
+            psz_desc[1000-1] = 0;
+            *((char **)value) = psz_desc;
             return NPERR_NO_ERROR;
+
+        default:
+            /* go on... */
+            break;
     }
 
     if( instance == NULL )
@@ -106,7 +165,7 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
     switch( variable )
     {
         case NPPVpluginScriptableInstance:
-            *(nsISupports**)value = p_plugin->getScriptable();
+            *(nsISupports**)value = p_plugin->GetPeer();
             if( *(nsISupports**)value == NULL )
             {
                 return NPERR_OUT_OF_MEMORY_ERROR;
@@ -129,6 +188,36 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
     return NPERR_NO_ERROR;
 }
 
+/******************************************************************************
+ * Mac-only API calls
+ *****************************************************************************/
+#ifdef XP_MACOSX
+int16 NPP_HandleEvent( NPP instance, void * event )
+{
+    VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
+    vlc_value_t value;
+
+    if( instance == NULL )
+    {
+        return false;
+    }
+
+    EventRecord *pouetEvent = (EventRecord*)event;
+
+    if (pouetEvent->what == 6)
+    {
+        value.i_int = 1;
+        VLC_Set( p_plugin->i_vlc, "drawableredraw", value );
+
+        return true;
+    }
+
+    Boolean eventHandled = false;
+
+    return eventHandled;
+}
+#endif
+
 /******************************************************************************
  * General Plug-in Calls
  *****************************************************************************/
@@ -150,20 +239,17 @@ void NPP_Shutdown( void )
 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
                  char* argn[], char* argv[], NPSavedData* saved )
 {
-    int i_ret;
     int i;
+#if USE_LIBVLC
+    vlc_value_t value;
+    int i_ret;
 
     char *ppsz_foo[] =
     {
         "vlc"
         /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
-        , "--vout", "xvideo,x11,dummy"
-        /*, "--aout", "none"*/
-        , "--intf", "dummy"
-        /*, "--noaudio"*/
-        , "-q"
-        /*, "-v"*/
     };
+#endif
 
     if( instance == NULL )
     {
@@ -179,57 +265,101 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
 
     instance->pdata = p_plugin;
 
-    p_plugin->fMode = mode;
-    p_plugin->fWindow = NULL;
+#ifdef XP_WIN
+    p_plugin->p_hwnd = NULL;
+    p_plugin->pf_wndproc = NULL;
+#endif
+
+#ifdef XP_UNIX
     p_plugin->window = 0;
+    p_plugin->p_display = NULL;
+#endif
 
-    p_plugin->p_vlc = vlc_create_r();
-    if( p_plugin->p_vlc == NULL )
+    p_plugin->p_npwin = NULL;
+    p_plugin->i_npmode = mode;
+    p_plugin->i_width = 0;
+    p_plugin->i_height = 0;
+
+#if USE_LIBVLC
+    p_plugin->i_vlc = VLC_Create();
+    if( p_plugin->i_vlc < 0 )
     {
+        p_plugin->i_vlc = 0;
         delete p_plugin;
         p_plugin = NULL;
         return NPERR_GENERIC_ERROR;
     }
 
-    i_ret = vlc_init_r( p_plugin->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
+    i_ret = VLC_Init( p_plugin->i_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
     if( i_ret )
     {
-        vlc_destroy_r( p_plugin->p_vlc );
-        p_plugin->p_vlc = NULL;
+        VLC_Destroy( p_plugin->i_vlc );
+        p_plugin->i_vlc = 0;
         delete p_plugin;
         p_plugin = NULL;
         return NPERR_GENERIC_ERROR;
     }
 
-    vlc_set_r( p_plugin->p_vlc, "vout", "xvideo,x11,dummy" );
-    vlc_set_r( p_plugin->p_vlc, "intf", "dummy" );
-    vlc_set_r( p_plugin->p_vlc, "audio", "0" );
+    value.psz_string = "dummy";
+    VLC_Set( p_plugin->i_vlc, "conf::intf", value );
+    value.psz_string = VOUT_PLUGINS;
+    VLC_Set( p_plugin->i_vlc, "conf::vout", value );
+    value.psz_string = AOUT_PLUGINS;
+    VLC_Set( p_plugin->i_vlc, "conf::aout", value );
 
-    i_ret = vlc_run_r( p_plugin->p_vlc );
-    if( i_ret )
-    {
-        vlc_destroy_r( p_plugin->p_vlc );
-        p_plugin->p_vlc = NULL;
-        delete p_plugin;
-        p_plugin = NULL;
-        return NPERR_GENERIC_ERROR;
-    }
+#else
+    p_plugin->i_vlc = 1;
 
-    p_plugin->b_stream = 0;
+#endif /* USE_LIBVLC */
+
+    p_plugin->b_stream = VLC_FALSE;
+    p_plugin->b_autoplay = VLC_FALSE;
     p_plugin->psz_target = NULL;
 
     for( i = 0; i < argc ; i++ )
     {
-        fprintf(stderr, "arg %i: '%s' = '%s'\n", i, argn[i], argv[i]);
-        if( !strcmp(argn[i],"target") )
+        if( !strcmp( argn[i], "target" ) )
         {
-            fprintf(stderr, "target specified: %s\n", argv[i]);
-            p_plugin->psz_target = strdup( argv[i] );
+            p_plugin->psz_target = argv[i];
         }
-        else
+        else if( !strcmp( argn[i], "autoplay" ) )
+        {
+            if( !strcmp( argv[i], "yes" ) )
+            {
+                p_plugin->b_autoplay = 1;
+            }
+        }
+        else if( !strcmp( argn[i], "autostart" ) )
+        {
+            if( !strcmp( argv[i], "1" ) || !strcmp( argv[i], "true" ) )
+            {
+                p_plugin->b_autoplay = 1;
+            }
+        }
+        else if( !strcmp( argn[i], "filename" ) )
+        {
+            p_plugin->psz_target = argv[i];
+        }
+        else if( !strcmp( argn[i], "src" ) )
+        {
+            p_plugin->psz_target = argv[i];
+        }
+
+#if USE_LIBVLC
+        else if( !strcmp( argn[i], "loop" ) )
         {
-            /*vlc_set_r( p_plugin->psz_target, argn[i], argv[i] );*/
+            if( !strcmp( argv[i], "yes" ) )
+            {
+                value.b_bool = VLC_TRUE;
+                VLC_Set( p_plugin->i_vlc, "conf::loop", value );
+            }
         }
+#endif
+    }
+
+    if( p_plugin->psz_target )
+    {
+        p_plugin->psz_target = strdup( p_plugin->psz_target );
     }
 
     return NPERR_NO_ERROR;
@@ -246,10 +376,13 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
 
     if( p_plugin != NULL )
     {
-        if( p_plugin->p_vlc != NULL )
+        if( p_plugin->i_vlc )
         {
-            vlc_destroy_r( p_plugin->p_vlc );
-            p_plugin->p_vlc = NULL;
+#if USE_LIBVLC
+            VLC_Stop( p_plugin->i_vlc );
+            VLC_Destroy( p_plugin->i_vlc );
+#endif
+            p_plugin->i_vlc = 0;
         }
 
         if( p_plugin->psz_target )
@@ -268,7 +401,19 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
 
 NPError NPP_SetWindow( NPP instance, NPWindow* window )
 {
-    char psz_window[32];
+    vlc_value_t value;
+#ifdef XP_MACOSX
+    vlc_value_t valuex;
+    vlc_value_t valuey;
+    vlc_value_t valuew;
+    vlc_value_t valueh;
+    vlc_value_t valuet;
+    vlc_value_t valuel;
+    vlc_value_t valueb;
+    vlc_value_t valuer;
+    vlc_value_t valueportx;
+    vlc_value_t valueporty;
+#endif
 
     if( instance == NULL )
     {
@@ -278,9 +423,44 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
     VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
 
     /* Write the window ID for vlc */
-    sprintf( psz_window, "%li", (long int)window->window );
-    vlc_set_r( p_plugin->p_vlc, "x11-drawable", psz_window );
-    vlc_set_r( p_plugin->p_vlc, "xvideo-drawable", psz_window );
+#if USE_LIBVLC
+
+#ifdef XP_MACOSX
+    value.i_int = ((NP_Port*) (window->window))->port;
+    VLC_Set( p_plugin->i_vlc, "drawable", value );
+
+    valueportx.i_int = ((NP_Port*) (window->window))->portx;
+    valueporty.i_int = ((NP_Port*) (window->window))->porty;
+    VLC_Set( p_plugin->i_vlc, "drawableportx", valueportx );
+    VLC_Set( p_plugin->i_vlc, "drawableporty", valueporty );
+
+    valuex.i_int = window->x;
+    valuey.i_int = window->y;
+    valuew.i_int = window->width;
+    valueh.i_int = window->height;
+    valuet.i_int = window->clipRect.top;
+    valuel.i_int = window->clipRect.left;
+    valueb.i_int = window->clipRect.bottom;
+    valuer.i_int = window->clipRect.right;
+
+    VLC_Set( p_plugin->i_vlc, "drawablet", valuet );
+    VLC_Set( p_plugin->i_vlc, "drawablel", valuel );
+    VLC_Set( p_plugin->i_vlc, "drawableb", valueb );
+    VLC_Set( p_plugin->i_vlc, "drawabler", valuer );
+    VLC_Set( p_plugin->i_vlc, "drawablex", valuex );
+    VLC_Set( p_plugin->i_vlc, "drawabley", valuey );
+    VLC_Set( p_plugin->i_vlc, "drawablew", valuew );
+    VLC_Set( p_plugin->i_vlc, "drawableh", valueh );
+
+    p_plugin->window = window;
+
+#else
+    /* FIXME: this cast sucks */
+    value.i_int = (int) (ptrdiff_t) (void *) window->window;
+    VLC_Set( p_plugin->i_vlc, "drawable", value );
+#endif
+
+#endif
 
     /*
      * PLUGIN DEVELOPERS:
@@ -290,34 +470,85 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
      *  size changes, etc.
      */
 
-    Widget netscape_widget;
+#ifdef XP_WIN
+    if( !window || !window->window )
+    {
+        /* Window was destroyed. Invalidate everything. */
+        if( p_plugin->p_npwin )
+        {
+            SetWindowLong( p_plugin->p_hwnd, GWL_WNDPROC,
+                           (LONG)p_plugin->pf_wndproc );
+            p_plugin->pf_wndproc = NULL;
+            p_plugin->p_hwnd = NULL;
+        }
+
+        p_plugin->p_npwin = window;
+        return NPERR_NO_ERROR;
+    }
 
+    if( p_plugin->p_npwin )
+    {
+        if( p_plugin->p_hwnd == (HWND)window->window )
+        {
+            /* Same window, but something may have changed. First we
+             * update the plugin structure, then we redraw the window */
+            InvalidateRect( p_plugin->p_hwnd, NULL, TRUE );
+            p_plugin->i_width = window->width;
+            p_plugin->i_height = window->height;
+            p_plugin->p_npwin = window;
+            UpdateWindow( p_plugin->p_hwnd );
+            return NPERR_NO_ERROR;
+        }
+
+        /* Window has changed. Destroy the one we have, and go
+         * on as if it was a real initialization. */
+        SetWindowLong( p_plugin->p_hwnd, GWL_WNDPROC,
+                       (LONG)p_plugin->pf_wndproc );
+        p_plugin->pf_wndproc = NULL;
+        p_plugin->p_hwnd = NULL;
+    }
+
+    p_plugin->pf_wndproc = (WNDPROC)SetWindowLong( (HWND)window->window,
+                                                   GWL_WNDPROC, (LONG)Manage );
+    p_plugin->p_hwnd = (HWND)window->window;
+    SetProp( p_plugin->p_hwnd, "w00t", (HANDLE)p_plugin );
+    InvalidateRect( p_plugin->p_hwnd, NULL, TRUE );
+    UpdateWindow( p_plugin->p_hwnd );
+#endif
+
+#ifdef XP_UNIX
     p_plugin->window = (Window) window->window;
-    p_plugin->x = window->x;
-    p_plugin->y = window->y;
-    p_plugin->width = window->width;
-    p_plugin->height = window->height;
-    p_plugin->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
+    p_plugin->p_display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
+
+    Widget w = XtWindowToWidget( p_plugin->p_display, p_plugin->window );
+    XtAddEventHandler( w, ExposureMask, FALSE,
+                       (XtEventHandler)Redraw, p_plugin );
+    Redraw( w, (XtPointer)p_plugin, NULL );
+#endif
 
-    netscape_widget = XtWindowToWidget(p_plugin->display, p_plugin->window);
-    XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, p_plugin);
-    Redraw(netscape_widget, (XtPointer)p_plugin, NULL);
+    p_plugin->p_npwin = window;
 
-    p_plugin->fWindow = window;
+    p_plugin->i_width = window->width;
+    p_plugin->i_height = window->height;
 
-#if 1
     if( !p_plugin->b_stream )
     {
-        p_plugin->b_stream = 1;
+        int i_mode = PLAYLIST_APPEND;
+
+        if( p_plugin->b_autoplay )
+        {
+            i_mode |= PLAYLIST_GO;
+        }
+
         if( p_plugin->psz_target )
         {
-            vlc_add_target_r( p_plugin->p_vlc, p_plugin->psz_target,
-                              PLAYLIST_APPEND, PLAYLIST_END );
-            vlc_add_target_r( p_plugin->p_vlc, "vlc:loop",
-                              PLAYLIST_APPEND, PLAYLIST_END );
+#if USE_LIBVLC
+            VLC_AddTarget( p_plugin->i_vlc, p_plugin->psz_target,
+                           0, 0, i_mode, PLAYLIST_END );
+#endif
+            p_plugin->b_stream = VLC_TRUE;
         }
     }
-#endif
 
     return NPERR_NO_ERROR;
 }
@@ -330,18 +561,20 @@ NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
         return NPERR_INVALID_INSTANCE_ERROR;
     }
 
+#if 0
     VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
+#endif
 
-    fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
+    /* fprintf(stderr, "NPP_NewStream - FILE mode !!\n"); */
 
     /* We want a *filename* ! */
     *stype = NP_ASFILE;
 
 #if 0
-    if( p_plugin->b_stream == 0 )
+    if( !p_plugin->b_stream )
     {
         p_plugin->psz_target = strdup( stream->url );
-        p_plugin->b_stream = 1;
+        p_plugin->b_stream = VLC_TRUE;
     }
 #endif
 
@@ -358,7 +591,7 @@ int32 NPP_WriteReady( NPP instance, NPStream *stream )
 {
     VlcPlugin* p_plugin;
 
-    fprintf(stderr, "NPP_WriteReady\n");
+    /* fprintf(stderr, "NPP_WriteReady\n"); */
 
     if (instance != NULL)
     {
@@ -377,9 +610,9 @@ int32 NPP_WriteReady( NPP instance, NPStream *stream )
 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
                  int32 len, void *buffer )
 {
-    fprintf(stderr, "NPP_Write %i\n", len);
+    /* fprintf(stderr, "NPP_Write %i\n", (int)len); */
 
-    if (instance != NULL)
+    if( instance != NULL )
     {
         /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
     }
@@ -395,8 +628,6 @@ NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
         return NPERR_INVALID_INSTANCE_ERROR;
     }
 
-    VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
-
     return NPERR_NO_ERROR;
 }
 
@@ -408,23 +639,15 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
         return;
     }
 
-    VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
+    /* fprintf(stderr, "NPP_StreamAsFile %s\n", fname); */
 
-    fprintf(stderr, "NPP_StreamAsFile\n");
-    vlc_add_target_r( p_plugin->p_vlc, fname, PLAYLIST_APPEND, PLAYLIST_END );
-    vlc_add_target_r( p_plugin->p_vlc, "vlc:loop", 
-                      PLAYLIST_APPEND, PLAYLIST_END );
-}
-
-#if 0
-void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
-{
-    fprintf(stderr,"filename : %s\n", fname);
-    ((VlcPlugin*) instance->pdata)->SetFileName(fname);
+#if USE_LIBVLC
+    VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
 
-    fprintf(stderr,"SetFileNeme ok. \n");
-}
+    VLC_AddTarget( p_plugin->i_vlc, fname, 0, 0,
+                   PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
 #endif
+}
 
 
 void NPP_URLNotify( NPP instance, const char* url,
@@ -440,15 +663,19 @@ void NPP_URLNotify( NPP instance, const char* url,
 
 void NPP_Print( NPP instance, NPPrint* printInfo )
 {
-    if(printInfo == NULL)
+    if( printInfo == NULL )
+    {
         return;
+    }
 
-    if (instance != NULL) {
-    /***** Insert NPP_Print code here *****\
+    if( instance != NULL )
+    {
+        /***** Insert NPP_Print code here *****\
         PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
-    \**************************************/
+        \**************************************/
 
-        if (printInfo->mode == NP_FULL) {
+        if( printInfo->mode == NP_FULL )
+        {
             /*
              * PLUGIN DEVELOPERS:
              *  If your plugin would like to take over
@@ -466,17 +693,19 @@ void NPP_Print( NPP instance, NPPrint* printInfo )
              *  etc.
              */
 
-    /***** Insert NPP_Print code here *****\
+            /***** Insert NPP_Print code here *****\
             void* platformPrint =
                 printInfo->print.fullPrint.platformPrint;
             NPBool printOne =
                 printInfo->print.fullPrint.printOne;
-    \**************************************/
+            \**************************************/
 
             /* Do the default*/
             printInfo->print.fullPrint.pluginPrinted = FALSE;
         }
-        else {  /* If not fullscreen, we must be embedded */
+        else
+        {
+            /* If not fullscreen, we must be embedded */
             /*
              * PLUGIN DEVELOPERS:
              *  If your plugin is embedded, or is full-screen
@@ -489,37 +718,76 @@ void NPP_Print( NPP instance, NPPrint* printInfo )
              *  device context.
              */
 
-    /***** Insert NPP_Print code here *****\
+            /***** Insert NPP_Print code here *****\
             NPWindow* printWindow =
                 &(printInfo->print.embedPrint.window);
             void* platformPrint =
                 printInfo->print.embedPrint.platformPrint;
-    \**************************************/
+            \**************************************/
         }
     }
 }
 
+/******************************************************************************
+ * Windows-only methods
+ *****************************************************************************/
+#ifdef XP_WIN
+LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
+{
+    VlcPlugin* p_plugin = (VlcPlugin*) GetProp( p_hwnd, "w00t" );
+
+    switch( i_msg )
+    {
+#if !USE_LIBVLC
+        case WM_PAINT:
+        {
+            PAINTSTRUCT paintstruct;
+            HDC hdc;
+            RECT rect;
+
+            hdc = BeginPaint( p_hwnd, &paintstruct );
+
+            GetClientRect( p_hwnd, &rect );
+            FillRect( hdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH) );
+            TextOut( hdc, p_plugin->i_width / 2 - 40, p_plugin->i_height / 2,
+                     WINDOW_TEXT, strlen(WINDOW_TEXT) );
+
+            EndPaint( p_hwnd, &paintstruct );
+            break;
+        }
+#endif
+        default:
+            p_plugin->pf_wndproc( p_hwnd, i_msg, wpar, lpar );
+            break;
+    }
+    return 0;
+}
+#endif
+
 /******************************************************************************
  * UNIX-only methods
  *****************************************************************************/
-#ifndef WIN32
+#ifdef XP_UNIX
 static void Redraw( Widget w, XtPointer closure, XEvent *event )
 {
     VlcPlugin* p_plugin = (VlcPlugin*)closure;
     GC gc;
     XGCValues gcv;
-    const char* text = "hello d00dZ, I'm in void Redraw()";
-
-    XtVaGetValues(w, XtNbackground, &gcv.background,
-                  XtNforeground, &gcv.foreground, 0);
-    gc = XCreateGC(p_plugin->display, p_plugin->window,
-                   GCForeground|GCBackground, &gcv);
-    XDrawRectangle(p_plugin->display, p_plugin->window, gc,
-                   0, 0, p_plugin->width-1, p_plugin->height-1);
-    XDrawString(p_plugin->display, p_plugin->window, gc,
-                p_plugin->width/2 - 100, p_plugin->height/2,
-                text, strlen(text));
-    return;
+
+    gcv.foreground = BlackPixel( p_plugin->p_display, 0 );
+    gc = XCreateGC( p_plugin->p_display, p_plugin->window, GCForeground, &gcv );
+
+    XFillRectangle( p_plugin->p_display, p_plugin->window, gc,
+                    0, 0, p_plugin->i_width, p_plugin->i_height );
+
+    gcv.foreground = WhitePixel( p_plugin->p_display, 0 );
+    XChangeGC( p_plugin->p_display, gc, GCForeground, &gcv );
+
+    XDrawString( p_plugin->p_display, p_plugin->window, gc,
+                 p_plugin->i_width / 2 - 40, p_plugin->i_height / 2,
+                 WINDOW_TEXT, strlen(WINDOW_TEXT) );
+
+    XFreeGC( p_plugin->p_display, gc );
 }
 #endif