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