]> git.sesse.net Git - vlc/blob - mozilla/vlcshell.cpp
* configure.ac, mozilla/vlcshell.cpp, mozilla/support/npwin.cpp: mozilla plugin for...
[vlc] / mozilla / vlcshell.cpp
1 /*****************************************************************************
2  * vlcshell.cpp: a VLC plugin for Mozilla
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: vlcshell.cpp,v 1.24 2003/09/23 16:07:48 gbazin Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /* XXX: disable VLC here */
25 #define USE_LIBVLC 1
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33
34 /* vlc stuff */
35 #ifdef USE_LIBVLC
36 #   include <vlc/vlc.h>
37 #endif
38
39 /* Mozilla stuff */
40 #include <nsISupports.h>
41 #include <nsMemory.h>
42 #include <npapi.h>
43
44 #ifdef XP_WIN
45     /* Windows stuff */
46 #endif
47
48 #ifdef XP_MACOSX
49     /* Mac OS X stuff */
50 #   include <Quickdraw.h>
51 #endif
52
53 #include "vlcpeer.h"
54 #include "vlcplugin.h"
55
56 #if USE_LIBVLC
57 #   define WINDOW_TEXT "(no picture)"
58 #else
59 #   define WINDOW_TEXT "(no libvlc)"
60 #endif
61
62 /* No, I really don't want to use XP_UNIX stuff on MacOSX */
63 #ifdef XP_MACOSX
64 #undef XP_UNIX
65 #endif
66
67 #ifdef XP_UNIX
68     /* X11 stuff */
69 #   include <X11/Xlib.h>
70 #   include <X11/Intrinsic.h>
71 #   include <X11/StringDefs.h>
72 #endif
73
74 /*****************************************************************************
75  * Unix-only declarations
76 ******************************************************************************/
77 #ifdef XP_UNIX
78 #   define VOUT_PLUGINS "xvideo,x11,dummy"
79 #   define AOUT_PLUGINS "oss,dummy"
80
81 static void Redraw( Widget w, XtPointer closure, XEvent *event );
82 #endif
83
84 /*****************************************************************************
85  * MacOS-only declarations
86 ******************************************************************************/
87 #ifdef XP_MACOSX
88 #   define VOUT_PLUGINS "macosx"
89 #   define AOUT_PLUGINS "macosx"
90
91 #endif
92
93 /*****************************************************************************
94  * Windows-only declarations
95  *****************************************************************************/
96 #ifdef XP_WIN
97 #   define VOUT_PLUGINS "directx,wingdi,dummy"
98 #   define AOUT_PLUGINS "directx,waveout,dummy"
99
100 HINSTANCE g_hDllInstance = NULL;
101
102 BOOL WINAPI DllMain( HINSTANCE hinstDLL, /* handle of DLL module */
103                      DWORD fdwReason,    /* reason for calling the function */
104                      LPVOID lpvReserved )
105 {
106     switch( fdwReason )
107     {
108     case DLL_PROCESS_ATTACH:
109         g_hDllInstance = hinstDLL;
110         break;
111     case DLL_THREAD_ATTACH:
112     case DLL_PROCESS_DETACH:
113     case DLL_THREAD_DETACH:
114         break;
115     }
116     return TRUE;
117 }
118
119 LRESULT CALLBACK Manage( HWND, UINT, WPARAM, LPARAM );
120 #endif
121
122 /******************************************************************************
123  * UNIX-only API calls
124  *****************************************************************************/
125 char * NPP_GetMIMEDescription( void )
126 {
127     return PLUGIN_MIMETYPES;
128 }
129
130 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
131 {
132
133     static nsIID nsid = VLCINTF_IID;
134     static char psz_desc[1000];
135
136     switch( variable )
137     {
138         case NPPVpluginNameString:
139             *((char **)value) = PLUGIN_NAME;
140             return NPERR_NO_ERROR;
141
142         case NPPVpluginDescriptionString:
143 #if USE_LIBVLC
144             snprintf( psz_desc, 1000-1, PLUGIN_DESCRIPTION, VLC_Version() );
145 #else
146             snprintf( psz_desc, 1000-1, PLUGIN_DESCRIPTION, "(disabled)" );
147 #endif
148             psz_desc[1000-1] = 0;
149             *((char **)value) = psz_desc;
150             return NPERR_NO_ERROR;
151
152         default:
153             /* go on... */
154             break;
155     }
156
157     if( instance == NULL )
158     {
159         return NPERR_INVALID_INSTANCE_ERROR;
160     }
161
162     VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
163
164     switch( variable )
165     {
166         case NPPVpluginScriptableInstance:
167             *(nsISupports**)value = p_plugin->GetPeer();
168             if( *(nsISupports**)value == NULL )
169             {
170                 return NPERR_OUT_OF_MEMORY_ERROR;
171             }
172             break;
173
174         case NPPVpluginScriptableIID:
175             *(nsIID**)value = (nsIID*)NPN_MemAlloc( sizeof(nsIID) );
176             if( *(nsIID**)value == NULL )
177             {
178                 return NPERR_OUT_OF_MEMORY_ERROR;
179             }
180             **(nsIID**)value = nsid;
181             break;
182
183         default:
184             return NPERR_GENERIC_ERROR;
185     }
186
187     return NPERR_NO_ERROR;
188 }
189
190 /******************************************************************************
191  * Mac-only API calls
192  *****************************************************************************/
193 #ifdef XP_MACOSX
194 int16 NPP_HandleEvent( NPP instance, void * event )
195 {
196     VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
197     vlc_value_t value;
198
199     if( instance == NULL )
200     {
201         return false;
202     }
203
204     EventRecord *pouetEvent = (EventRecord*)event;
205
206     if (pouetEvent->what == 6)
207     {
208         value.i_int = 1;
209         VLC_Set( p_plugin->i_vlc, "drawableredraw", value );
210         return true;
211     }
212
213     Boolean eventHandled = false;
214
215     return eventHandled;
216 }
217 #endif
218
219 /******************************************************************************
220  * General Plug-in Calls
221  *****************************************************************************/
222 NPError NPP_Initialize( void )
223 {
224     return NPERR_NO_ERROR;
225 }
226
227 jref NPP_GetJavaClass( void )
228 {
229     return NULL;
230 }
231
232 void NPP_Shutdown( void )
233 {
234     ;
235 }
236
237 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
238                  char* argn[], char* argv[], NPSavedData* saved )
239 {
240     int i;
241
242 #if USE_LIBVLC
243     vlc_value_t value;
244     int i_ret;
245
246 #endif
247
248     if( instance == NULL )
249     {
250         return NPERR_INVALID_INSTANCE_ERROR;
251     }
252
253     VlcPlugin * p_plugin = new VlcPlugin( instance );
254
255     if( p_plugin == NULL )
256     {
257         return NPERR_OUT_OF_MEMORY_ERROR;
258     }
259
260     instance->pdata = p_plugin;
261
262 #ifdef XP_WIN
263     p_plugin->p_hwnd = NULL;
264     p_plugin->pf_wndproc = NULL;
265 #endif
266
267 #ifdef XP_UNIX
268     p_plugin->window = 0;
269     p_plugin->p_display = NULL;
270 #endif
271
272     p_plugin->p_npwin = NULL;
273     p_plugin->i_npmode = mode;
274     p_plugin->i_width = 0;
275     p_plugin->i_height = 0;
276
277 #if USE_LIBVLC
278     p_plugin->i_vlc = VLC_Create();
279     if( p_plugin->i_vlc < 0 )
280     {
281         p_plugin->i_vlc = 0;
282         delete p_plugin;
283         p_plugin = NULL;
284         return NPERR_GENERIC_ERROR;
285     }
286
287     {
288 #ifdef XP_MACOSX
289         char *home_user;
290         char *directory;
291         char *plugin_path;
292         char *ppsz_argv[] = { "vlc", "--plugin-path", NULL };
293
294         home_user = strdup( getenv("HOME") );
295         directory = strdup( "/Library/Internet Plug-Ins/VLC Plugin.plugin/"
296                             "Contents/MacOS/modules" );
297         plugin_path = malloc( strlen( directory ) + strlen( home_user ) );
298         memcpy( plugin_path , home_user , strlen(home_user) );
299         memcpy( plugin_path + strlen( home_user ) , directory ,
300                 strlen( directory ) );
301
302         ppsz_argv[2] = plugin_path;
303
304 #elif defined(XP_WIN)
305         char *ppsz_argv[] = { "vlc", "--plugin-path", NULL, "-vv" };
306         HKEY h_key;
307         DWORD i_type, i_data;
308         char p_data[MAX_PATH + 1];
309
310         if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
311                           0, KEY_READ, &h_key ) == ERROR_SUCCESS )
312         {
313              if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
314                                   (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
315              {
316                  if( i_type == REG_SZ )
317                  {
318                      strcat( p_data, "\\plugins" );
319                      ppsz_argv[2] = p_data;
320                  }
321              }
322              RegCloseKey( h_key );
323         }
324
325         if( !ppsz_argv[2] ) ppsz_argv[2] = ".";
326
327 #else
328         char *ppsz_argv[] =
329         {
330             "vlc"
331             /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
332         };
333
334 #endif
335
336         i_ret = VLC_Init( p_plugin->i_vlc, sizeof(ppsz_argv)/sizeof(char*),
337                           ppsz_argv );
338
339 #ifdef XP_MACOSX
340         free( home_user );
341         free( directory );
342         free( plugin_path );
343 #endif
344     }
345
346     if( i_ret )
347     {
348         VLC_Destroy( p_plugin->i_vlc );
349         p_plugin->i_vlc = 0;
350         delete p_plugin;
351         p_plugin = NULL;
352         return NPERR_GENERIC_ERROR;
353     }
354
355     value.psz_string = "dummy";
356     VLC_Set( p_plugin->i_vlc, "conf::intf", value );
357     value.psz_string = VOUT_PLUGINS;
358     VLC_Set( p_plugin->i_vlc, "conf::vout", value );
359     value.psz_string = AOUT_PLUGINS;
360     VLC_Set( p_plugin->i_vlc, "conf::aout", value );
361
362 #else
363     p_plugin->i_vlc = 1;
364
365 #endif /* USE_LIBVLC */
366
367     p_plugin->b_stream = VLC_FALSE;
368     p_plugin->b_autoplay = VLC_FALSE;
369     p_plugin->psz_target = NULL;
370
371     for( i = 0; i < argc ; i++ )
372     {
373         if( !strcmp( argn[i], "target" ) )
374         {
375             p_plugin->psz_target = argv[i];
376         }
377         else if( !strcmp( argn[i], "autoplay" ) )
378         {
379             if( !strcmp( argv[i], "yes" ) )
380             {
381                 p_plugin->b_autoplay = 1;
382             }
383         }
384         else if( !strcmp( argn[i], "autostart" ) )
385         {
386             if( !strcmp( argv[i], "1" ) || !strcmp( argv[i], "true" ) )
387             {
388                 p_plugin->b_autoplay = 1;
389             }
390         }
391         else if( !strcmp( argn[i], "filename" ) )
392         {
393             p_plugin->psz_target = argv[i];
394         }
395         else if( !strcmp( argn[i], "src" ) )
396         {
397             p_plugin->psz_target = argv[i];
398         }
399
400 #if USE_LIBVLC
401         else if( !strcmp( argn[i], "loop" ) )
402         {
403             if( !strcmp( argv[i], "yes" ) )
404             {
405                 value.b_bool = VLC_TRUE;
406                 VLC_Set( p_plugin->i_vlc, "conf::loop", value );
407             }
408         }
409 #endif
410     }
411
412     if( p_plugin->psz_target )
413     {
414         p_plugin->psz_target = strdup( p_plugin->psz_target );
415     }
416
417     return NPERR_NO_ERROR;
418 }
419
420 NPError NPP_Destroy( NPP instance, NPSavedData** save )
421 {
422     if( instance == NULL )
423     {
424         return NPERR_INVALID_INSTANCE_ERROR;
425     }
426
427     VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
428
429     if( p_plugin != NULL )
430     {
431         if( p_plugin->i_vlc )
432         {
433 #if USE_LIBVLC
434             VLC_Stop( p_plugin->i_vlc );
435             VLC_Destroy( p_plugin->i_vlc );
436 #endif
437             p_plugin->i_vlc = 0;
438         }
439
440         if( p_plugin->psz_target )
441         {
442             free( p_plugin->psz_target );
443             p_plugin->psz_target = NULL;
444         }
445
446         delete p_plugin;
447     }
448
449     instance->pdata = NULL;
450
451     return NPERR_NO_ERROR;
452 }
453
454 NPError NPP_SetWindow( NPP instance, NPWindow* window )
455 {
456     vlc_value_t value;
457 #ifdef XP_MACOSX
458     vlc_value_t valuex;
459     vlc_value_t valuey;
460     vlc_value_t valuew;
461     vlc_value_t valueh;
462     vlc_value_t valuet;
463     vlc_value_t valuel;
464     vlc_value_t valueb;
465     vlc_value_t valuer;
466     vlc_value_t valueportx;
467     vlc_value_t valueporty;
468     Rect black_rect;
469     char * text;
470 #endif
471
472     if( instance == NULL )
473     {
474         return NPERR_INVALID_INSTANCE_ERROR;
475     }
476
477     VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
478
479     /* Write the window ID for vlc */
480 #if USE_LIBVLC
481
482 #ifdef XP_MACOSX
483     value.i_int = ((NP_Port*) (window->window))->port;
484     VLC_Set( p_plugin->i_vlc, "drawable", value );
485
486     valueportx.i_int = ((NP_Port*) (window->window))->portx;
487     valueporty.i_int = ((NP_Port*) (window->window))->porty;
488     VLC_Set( p_plugin->i_vlc, "drawableportx", valueportx );
489     VLC_Set( p_plugin->i_vlc, "drawableporty", valueporty );
490
491     valuex.i_int = window->x;
492     valuey.i_int = window->y;
493     valuew.i_int = window->width;
494     valueh.i_int = window->height;
495     valuet.i_int = window->clipRect.top;
496     valuel.i_int = window->clipRect.left;
497     valueb.i_int = window->clipRect.bottom;
498     valuer.i_int = window->clipRect.right;
499
500     VLC_Set( p_plugin->i_vlc, "drawablet", valuet );
501     VLC_Set( p_plugin->i_vlc, "drawablel", valuel );
502     VLC_Set( p_plugin->i_vlc, "drawableb", valueb );
503     VLC_Set( p_plugin->i_vlc, "drawabler", valuer );
504     VLC_Set( p_plugin->i_vlc, "drawablex", valuex );
505     VLC_Set( p_plugin->i_vlc, "drawabley", valuey );
506     VLC_Set( p_plugin->i_vlc, "drawablew", valuew );
507     VLC_Set( p_plugin->i_vlc, "drawableh", valueh );
508
509     p_plugin->window = window;
510
511     /* draw the beautiful "No Picture" */
512
513     black_rect.top = valuet.i_int - valuey.i_int;
514     black_rect.left = valuel.i_int - valuex.i_int;
515     black_rect.bottom = valueb.i_int - valuey.i_int;
516     black_rect.right = valuer.i_int - valuex.i_int;
517
518     SetPort( value.i_int );
519     SetOrigin( valueportx.i_int , valueporty.i_int );
520     ForeColor(blackColor);
521     PenMode( patCopy );
522     PaintRect( &black_rect );
523
524     ForeColor(whiteColor);
525     text = strdup( WINDOW_TEXT );
526     MoveTo( valuew.i_int / 2 - 40 , valueh.i_int / 2 );
527     DrawText( text , 0 , strlen(text) );
528     free(text);
529
530 #else
531     /* FIXME: this cast sucks */
532     value.i_int = (int) (ptrdiff_t) (void *) window->window;
533     VLC_Set( p_plugin->i_vlc, "drawable", value );
534 #endif
535
536 #endif
537
538     /*
539      * PLUGIN DEVELOPERS:
540      *  Before setting window to point to the
541      *  new window, you may wish to compare the new window
542      *  info to the previous window (if any) to note window
543      *  size changes, etc.
544      */
545
546 #ifdef XP_WIN
547     if( !window || !window->window )
548     {
549         /* Window was destroyed. Invalidate everything. */
550         if( p_plugin->p_npwin )
551         {
552             SetWindowLong( p_plugin->p_hwnd, GWL_WNDPROC,
553                            (LONG)p_plugin->pf_wndproc );
554             p_plugin->pf_wndproc = NULL;
555             p_plugin->p_hwnd = NULL;
556         }
557
558         p_plugin->p_npwin = window;
559         return NPERR_NO_ERROR;
560     }
561
562     if( p_plugin->p_npwin )
563     {
564         if( p_plugin->p_hwnd == (HWND)window->window )
565         {
566             /* Same window, but something may have changed. First we
567              * update the plugin structure, then we redraw the window */
568             InvalidateRect( p_plugin->p_hwnd, NULL, TRUE );
569             p_plugin->i_width = window->width;
570             p_plugin->i_height = window->height;
571             p_plugin->p_npwin = window;
572             UpdateWindow( p_plugin->p_hwnd );
573             return NPERR_NO_ERROR;
574         }
575
576         /* Window has changed. Destroy the one we have, and go
577          * on as if it was a real initialization. */
578         SetWindowLong( p_plugin->p_hwnd, GWL_WNDPROC,
579                        (LONG)p_plugin->pf_wndproc );
580         p_plugin->pf_wndproc = NULL;
581         p_plugin->p_hwnd = NULL;
582     }
583
584     p_plugin->pf_wndproc = (WNDPROC)SetWindowLong( (HWND)window->window,
585                                                    GWL_WNDPROC, (LONG)Manage );
586     p_plugin->p_hwnd = (HWND)window->window;
587     SetProp( p_plugin->p_hwnd, "w00t", (HANDLE)p_plugin );
588     InvalidateRect( p_plugin->p_hwnd, NULL, TRUE );
589     UpdateWindow( p_plugin->p_hwnd );
590 #endif
591
592 #ifdef XP_UNIX
593     p_plugin->window = (Window) window->window;
594     p_plugin->p_display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
595
596     Widget w = XtWindowToWidget( p_plugin->p_display, p_plugin->window );
597     XtAddEventHandler( w, ExposureMask, FALSE,
598                        (XtEventHandler)Redraw, p_plugin );
599     Redraw( w, (XtPointer)p_plugin, NULL );
600 #endif
601
602     p_plugin->p_npwin = window;
603
604     p_plugin->i_width = window->width;
605     p_plugin->i_height = window->height;
606
607     if( !p_plugin->b_stream )
608     {
609         int i_mode = PLAYLIST_APPEND;
610
611         if( p_plugin->b_autoplay )
612         {
613             i_mode |= PLAYLIST_GO;
614         }
615
616         if( p_plugin->psz_target )
617         {
618 #if USE_LIBVLC
619             VLC_AddTarget( p_plugin->i_vlc, p_plugin->psz_target,
620                            0, 0, i_mode, PLAYLIST_END );
621 #endif
622             p_plugin->b_stream = VLC_TRUE;
623         }
624     }
625
626     return NPERR_NO_ERROR;
627 }
628
629 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
630                        NPBool seekable, uint16 *stype )
631 {
632     if( instance == NULL )
633     {
634         return NPERR_INVALID_INSTANCE_ERROR;
635     }
636
637 #if 0
638     VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
639 #endif
640
641     /* fprintf(stderr, "NPP_NewStream - FILE mode !!\n"); */
642
643     /* We want a *filename* ! */
644     *stype = NP_ASFILE;
645
646 #if 0
647     if( !p_plugin->b_stream )
648     {
649         p_plugin->psz_target = strdup( stream->url );
650         p_plugin->b_stream = VLC_TRUE;
651     }
652 #endif
653
654     return NPERR_NO_ERROR;
655 }
656
657 int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
658                    * mode so we can take any size stream in our
659                    * write call (since we ignore it) */
660
661 #define SARASS_SIZE (1024*1024)
662
663 int32 NPP_WriteReady( NPP instance, NPStream *stream )
664 {
665     VlcPlugin* p_plugin;
666
667     /* fprintf(stderr, "NPP_WriteReady\n"); */
668
669     if (instance != NULL)
670     {
671         p_plugin = (VlcPlugin*) instance->pdata;
672         /* Muahahahahahahaha */
673         return STREAMBUFSIZE;
674         /*return SARASS_SIZE;*/
675     }
676
677     /* Number of bytes ready to accept in NPP_Write() */
678     return STREAMBUFSIZE;
679     /*return 0;*/
680 }
681
682
683 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
684                  int32 len, void *buffer )
685 {
686     /* fprintf(stderr, "NPP_Write %i\n", (int)len); */
687
688     if( instance != NULL )
689     {
690         /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
691     }
692
693     return len;         /* The number of bytes accepted */
694 }
695
696
697 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
698 {
699     if( instance == NULL )
700     {
701         return NPERR_INVALID_INSTANCE_ERROR;
702     }
703
704     return NPERR_NO_ERROR;
705 }
706
707
708 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
709 {
710     if( instance == NULL )
711     {
712         return;
713     }
714
715     /* fprintf(stderr, "NPP_StreamAsFile %s\n", fname); */
716
717 #if USE_LIBVLC
718     VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
719
720     VLC_AddTarget( p_plugin->i_vlc, fname, 0, 0,
721                    PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
722 #endif
723 }
724
725
726 void NPP_URLNotify( NPP instance, const char* url,
727                     NPReason reason, void* notifyData )
728 {
729     /***** Insert NPP_URLNotify code here *****\
730     PluginInstance* p_plugin;
731     if (instance != NULL)
732         p_plugin = (PluginInstance*) instance->pdata;
733     \*********************************************/
734 }
735
736
737 void NPP_Print( NPP instance, NPPrint* printInfo )
738 {
739     if( printInfo == NULL )
740     {
741         return;
742     }
743
744     if( instance != NULL )
745     {
746         /***** Insert NPP_Print code here *****\
747         PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
748         \**************************************/
749
750         if( printInfo->mode == NP_FULL )
751         {
752             /*
753              * PLUGIN DEVELOPERS:
754              *  If your plugin would like to take over
755              *  printing completely when it is in full-screen mode,
756              *  set printInfo->pluginPrinted to TRUE and print your
757              *  plugin as you see fit.  If your plugin wants Netscape
758              *  to handle printing in this case, set
759              *  printInfo->pluginPrinted to FALSE (the default) and
760              *  do nothing.  If you do want to handle printing
761              *  yourself, printOne is true if the print button
762              *  (as opposed to the print menu) was clicked.
763              *  On the Macintosh, platformPrint is a THPrint; on
764              *  Windows, platformPrint is a structure
765              *  (defined in npapi.h) containing the printer name, port,
766              *  etc.
767              */
768
769             /***** Insert NPP_Print code here *****\
770             void* platformPrint =
771                 printInfo->print.fullPrint.platformPrint;
772             NPBool printOne =
773                 printInfo->print.fullPrint.printOne;
774             \**************************************/
775
776             /* Do the default*/
777             printInfo->print.fullPrint.pluginPrinted = FALSE;
778         }
779         else
780         {
781             /* If not fullscreen, we must be embedded */
782             /*
783              * PLUGIN DEVELOPERS:
784              *  If your plugin is embedded, or is full-screen
785              *  but you returned false in pluginPrinted above, NPP_Print
786              *  will be called with mode == NP_EMBED.  The NPWindow
787              *  in the printInfo gives the location and dimensions of
788              *  the embedded plugin on the printed page.  On the
789              *  Macintosh, platformPrint is the printer port; on
790              *  Windows, platformPrint is the handle to the printing
791              *  device context.
792              */
793
794             /***** Insert NPP_Print code here *****\
795             NPWindow* printWindow =
796                 &(printInfo->print.embedPrint.window);
797             void* platformPrint =
798                 printInfo->print.embedPrint.platformPrint;
799             \**************************************/
800         }
801     }
802 }
803
804 /******************************************************************************
805  * Windows-only methods
806  *****************************************************************************/
807 #ifdef XP_WIN
808 LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
809 {
810     VlcPlugin* p_plugin = (VlcPlugin*) GetProp( p_hwnd, "w00t" );
811
812     switch( i_msg )
813     {
814 #if !USE_LIBVLC
815         case WM_PAINT:
816         {
817             PAINTSTRUCT paintstruct;
818             HDC hdc;
819             RECT rect;
820
821             hdc = BeginPaint( p_hwnd, &paintstruct );
822
823             GetClientRect( p_hwnd, &rect );
824             FillRect( hdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH) );
825             TextOut( hdc, p_plugin->i_width / 2 - 40, p_plugin->i_height / 2,
826                      WINDOW_TEXT, strlen(WINDOW_TEXT) );
827
828             EndPaint( p_hwnd, &paintstruct );
829             break;
830         }
831 #endif
832         default:
833             p_plugin->pf_wndproc( p_hwnd, i_msg, wpar, lpar );
834             break;
835     }
836     return 0;
837 }
838 #endif
839
840 /******************************************************************************
841  * UNIX-only methods
842  *****************************************************************************/
843 #ifdef XP_UNIX
844 static void Redraw( Widget w, XtPointer closure, XEvent *event )
845 {
846     VlcPlugin* p_plugin = (VlcPlugin*)closure;
847     GC gc;
848     XGCValues gcv;
849
850     gcv.foreground = BlackPixel( p_plugin->p_display, 0 );
851     gc = XCreateGC( p_plugin->p_display, p_plugin->window, GCForeground, &gcv );
852
853     XFillRectangle( p_plugin->p_display, p_plugin->window, gc,
854                     0, 0, p_plugin->i_width, p_plugin->i_height );
855
856     gcv.foreground = WhitePixel( p_plugin->p_display, 0 );
857     XChangeGC( p_plugin->p_display, gc, GCForeground, &gcv );
858
859     XDrawString( p_plugin->p_display, p_plugin->window, gc,
860                  p_plugin->i_width / 2 - 40, p_plugin->i_height / 2,
861                  WINDOW_TEXT, strlen(WINDOW_TEXT) );
862
863     XFreeGC( p_plugin->p_display, gc );
864 }
865 #endif
866