/
vlcshell.cpp
966 lines (826 loc) · 28.9 KB
/
vlcshell.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
/*****************************************************************************
* vlcshell.cpp: a VLC plugin for Mozilla
*****************************************************************************
* Copyright (C) 2002-2009 the VideoLAN team
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
* Jean-Paul Saman <jpsaman@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "vlcplugin.h"
#include "vlcshell.h"
/* Enable/disable debugging printf's for X11 resizing */
#undef X11_RESIZE_DEBUG
/*****************************************************************************
* Unix-only declarations
******************************************************************************/
#if defined(XP_UNIX)
static void Redraw( Widget w, XtPointer closure, XEvent *event );
static void ControlHandler( Widget w, XtPointer closure, XEvent *event );
static void Resize( Widget w, XtPointer closure, XEvent *event );
#endif
/*****************************************************************************
* MacOS-only declarations
******************************************************************************/
#ifdef XP_MACOSX
#endif
/*****************************************************************************
* Windows-only declarations
*****************************************************************************/
#ifdef XP_WIN
static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );
#endif
/******************************************************************************
* UNIX-only API calls
*****************************************************************************/
char * NPP_GetMIMEDescription( void )
{
return mimetype;
}
NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
{
static char psz_name[] = PLUGIN_NAME;
static char psz_desc[1000];
/* plugin class variables */
switch( variable )
{
case NPPVpluginNameString:
*((char **)value) = psz_name;
return NPERR_NO_ERROR;
case NPPVpluginDescriptionString:
snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION,
libvlc_get_version() );
*((char **)value) = psz_desc;
return NPERR_NO_ERROR;
default:
/* move on to instance variables ... */
;
}
if( instance == NULL )
{
return NPERR_INVALID_INSTANCE_ERROR;
}
/* plugin instance variables */
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
if( NULL == p_plugin )
{
/* plugin has not been initialized yet ! */
return NPERR_INVALID_INSTANCE_ERROR;
}
switch( variable )
{
case NPPVpluginScriptableNPObject:
{
/* retrieve plugin root class */
NPClass *scriptClass = p_plugin->getScriptClass();
if( scriptClass )
{
/* create an instance and return it */
*(NPObject**)value = NPN_CreateObject(instance, scriptClass);
return NPERR_NO_ERROR;
}
break;
}
default:
;
}
return NPERR_GENERIC_ERROR;
}
/*
* there is some confusion in gecko headers regarding definition of this API
* NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
*/
NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
{
return NPERR_GENERIC_ERROR;
}
/******************************************************************************
* Mac-only API calls
*****************************************************************************/
#ifdef XP_MACOSX
int16_t NPP_HandleEvent( NPP instance, void * event )
{
static UInt32 lastMouseUp = 0;
if( instance == NULL )
{
return false;
}
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
if( p_plugin == NULL )
{
return false;
}
#ifndef __x86_64__
EventRecord *myEvent = (EventRecord*)event;
switch( myEvent->what )
{
case nullEvent:
return true;
case mouseDown:
{
if( (myEvent->when - lastMouseUp) < GetDblTime() )
{
/* double click */
p_plugin->toggle_fullscreen();
}
return true;
}
case mouseUp:
lastMouseUp = myEvent->when;
return true;
case keyUp:
case keyDown:
case autoKey:
return true;
case updateEvt:
{
const NPWindow& npwindow = p_plugin->getWindow();
if( npwindow.window )
{
bool hasVout = false;
if( p_plugin->playlist_isplaying() )
{
hasVout = p_plugin->player_has_vout();
#if 0
if( hasVout )
{
libvlc_rectangle_t area;
area.left = 0;
area.top = 0;
area.right = npwindow.width;
area.bottom = npwindow.height;
libvlc_video_redraw_rectangle(p_plugin->getMD(), &area, NULL);
}
#else
#warning disabled code
#endif
}
if( ! hasVout )
{
/* draw the text from p_plugin->psz_text */
ForeColor(blackColor);
PenMode( patCopy );
/* seems that firefox forgets to set the following
* on occasion (reload) */
SetOrigin(((NP_Port *)npwindow.window)->portx,
((NP_Port *)npwindow.window)->porty);
Rect rect;
rect.left = 0;
rect.top = 0;
rect.right = npwindow.width;
rect.bottom = npwindow.height;
PaintRect( &rect );
ForeColor(whiteColor);
MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
if( p_plugin->psz_text )
DrawText( p_plugin->psz_text, 0, strlen(p_plugin->psz_text) );
}
}
return true;
}
case activateEvt:
return false;
case NPEventType_GetFocusEvent:
case NPEventType_LoseFocusEvent:
return true;
case NPEventType_AdjustCursorEvent:
return false;
case NPEventType_MenuCommandEvent:
return false;
case NPEventType_ClippingChangedEvent:
return false;
case NPEventType_ScrollingBeginsEvent:
return true;
case NPEventType_ScrollingEndsEvent:
return true;
default:
;
}
#endif // __x86_64__
return false;
}
#endif /* XP_MACOSX */
/******************************************************************************
* General Plug-in Calls
*****************************************************************************/
NPError NPP_Initialize( void )
{
return NPERR_NO_ERROR;
}
#ifdef OJI
jref NPP_GetJavaClass( void )
{
return NULL;
}
#endif
void NPP_Shutdown( void )
{
;
}
NPError NPP_New( NPMIMEType pluginType, NPP instance,
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
uint16 mode, int16 argc,
#else
uint16_t mode, int16_t argc,
#endif
char* argn[], char* argv[], NPSavedData* saved )
{
NPError status;
if( instance == NULL )
{
return NPERR_INVALID_INSTANCE_ERROR;
}
VlcPlugin * p_plugin = new VlcPlugin( instance, mode );
if( NULL == p_plugin )
{
return NPERR_OUT_OF_MEMORY_ERROR;
}
status = p_plugin->init(argc, argn, argv);
if( NPERR_NO_ERROR == status )
{
instance->pdata = reinterpret_cast<void*>(p_plugin);
#if 0
NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
#endif
}
else
{
delete p_plugin;
}
return status;
}
NPError NPP_Destroy( NPP instance, NPSavedData** save )
{
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 defined(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->playlist_isplaying() )
p_plugin->playlist_stop();
delete p_plugin;
return NPERR_NO_ERROR;
}
NPError NPP_SetWindow( NPP instance, NPWindow* window )
{
#if defined(XP_UNIX)
Window control;
unsigned int i_control_height = 0, i_control_width = 0;
#endif
if( ! instance )
{
return NPERR_INVALID_INSTANCE_ERROR;
}
/* NPP_SetWindow may be called before NPP_New (Opera) */
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
if( NULL == p_plugin )
{
/* we should probably show a splash screen here */
return NPERR_NO_ERROR;
}
#if defined(XP_UNIX)
control = p_plugin->getControlWindow();
#endif
libvlc_instance_t *p_vlc = p_plugin->getVLC();
/*
* PLUGIN DEVELOPERS:
* Before setting window to point to the
* new window, you may wish to compare the new window
* info to the previous window (if any) to note window
* size changes, etc.
*/
/* retrieve current window */
NPWindow& curwin = p_plugin->getWindow();
#ifdef XP_MACOSX
if( window && window->window )
{
/* check if plugin has a new parent window */
CGrafPtr drawable = (((NP_Port*) (window->window))->port);
/* as MacOS X video output is windowless, set viewport */
libvlc_rectangle_t view, clip;
/*
** browser sets port origin to top-left location of plugin
** relative to GrafPort window origin is set relative to document,
** which of little use for drawing
*/
view.top = ((NP_Port*) (window->window))->porty;
view.left = ((NP_Port*) (window->window))->portx;
view.bottom = window->height+view.top;
view.right = window->width+view.left;
/* clipRect coordinates are also relative to GrafPort */
clip.top = window->clipRect.top;
clip.left = window->clipRect.left;
clip.bottom = window->clipRect.bottom;
clip.right = window->clipRect.right;
#ifdef NOT_WORKING
libvlc_video_set_viewport(p_vlc, p_plugin->getMD(), &view, &clip);
#else
#warning disabled code
#endif
/* remember new window */
p_plugin->setWindow(*window);
}
else if( curwin.window )
{
/* change/set parent */
curwin.window = NULL;
}
#endif /* XP_MACOSX */
#ifdef XP_WIN
if( window && window->window )
{
/* check if plugin has a new parent window */
HWND drawable = (HWND) (window->window);
if( !curwin.window || drawable != curwin.window )
{
/* reset previous window settings */
HWND oldwin = (HWND)p_plugin->getWindow().window;
WNDPROC oldproc = p_plugin->getWindowProc();
if( oldproc )
{
/* 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 ) );
/* change window style to our liking */
LONG style = GetWindowLong((HWND)drawable, GWL_STYLE);
style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
SetWindowLong((HWND)drawable, GWL_STYLE, style);
/* remember new window */
p_plugin->setWindow(*window);
/* Redraw window */
InvalidateRect( (HWND)drawable, NULL, TRUE );
UpdateWindow( (HWND)drawable );
}
}
else if( curwin.window )
{
/* reset WNDPROC */
HWND oldwin = (HWND)curwin.window;
SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) );
p_plugin->setWindowProc(NULL);
curwin.window = NULL;
}
#endif /* XP_WIN */
#if defined(XP_UNIX)
/* 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 )
{
Window parent = (Window) window->window;
if( !curwin.window || (parent != (Window)curwin.window) )
{
Display *p_display = ( (NPSetWindowCallbackStruct *)
window->ws_info )->display;
XResizeWindow( p_display, parent, window->width, window->height );
int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
/* create windows */
Window video = XCreateSimpleWindow( p_display, parent, 0, 0,
window->width, window->height - i_control_height,
0, i_blackColor, i_blackColor );
Window controls = (Window) NULL;
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 );
if( controls ) { XMapWindow( p_display, controls ); }
XFlush(p_display);
/* bind events */
Widget w = XtWindowToWidget( p_display, parent );
XtAddEventHandler( w, ExposureMask, FALSE,
(XtEventHandler)Redraw, p_plugin );
XtAddEventHandler( w, StructureNotifyMask, FALSE,
(XtEventHandler)Resize, p_plugin );
XtAddEventHandler( w, ButtonReleaseMask, FALSE,
(XtEventHandler)ControlHandler, p_plugin );
/* remember window */
p_plugin->setWindow( *window );
p_plugin->setVideoWindow( video );
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 )
{
curwin.window = NULL;
}
#endif /* XP_UNIX */
if( !p_plugin->b_stream )
{
if( p_plugin->psz_target )
{
if( p_plugin->playlist_add( p_plugin->psz_target ) != -1 )
{
if( p_plugin->b_autoplay )
{
p_plugin->playlist_play();
}
}
p_plugin->b_stream = true;
}
}
return NPERR_NO_ERROR;
}
NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
NPBool seekable, uint16 *stype )
#else
NPBool seekable, uint16_t *stype )
#endif
{
if( NULL == instance )
{
return NPERR_INVALID_INSTANCE_ERROR;
}
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
if( NULL == p_plugin )
{
return NPERR_INVALID_INSTANCE_ERROR;
}
/*
** 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) )
{
/* TODO: use pipes !!!! */
*stype = NP_ASFILEONLY;
return NPERR_NO_ERROR;
}
return NPERR_GENERIC_ERROR;
}
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
int32 NPP_WriteReady( NPP instance, NPStream *stream )
#else
int32_t NPP_WriteReady( NPP instance, NPStream *stream )
#endif
{
/* TODO */
return 8*1024;
}
#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
int32 len, void *buffer )
#else
int32_t NPP_Write( NPP instance, NPStream *stream, int32_t offset,
int32_t len, void *buffer )
#endif
{
/* TODO */
return len;
}
NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
{
if( instance == NULL )
{
return NPERR_INVALID_INSTANCE_ERROR;
}
return NPERR_NO_ERROR;
}
void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
{
if( instance == NULL )
{
return;
}
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
if( NULL == p_plugin )
{
return;
}
if( p_plugin->playlist_add( stream->url ) != -1 )
{
if( p_plugin->b_autoplay )
{
p_plugin->playlist_play();
}
}
}
void NPP_URLNotify( NPP instance, const char* url,
NPReason reason, void* notifyData )
{
/***** Insert NPP_URLNotify code here *****\
PluginInstance* p_plugin;
if (instance != NULL)
p_plugin = (PluginInstance*) instance->pdata;
\*********************************************/
}
void NPP_Print( NPP instance, NPPrint* printInfo )
{
if( printInfo == NULL )
{
return;
}
if( instance != NULL )
{
/***** Insert NPP_Print code here *****\
PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
\**************************************/
if( printInfo->mode == NP_FULL )
{
/*
* PLUGIN DEVELOPERS:
* If your plugin would like to take over
* printing completely when it is in full-screen mode,
* set printInfo->pluginPrinted to TRUE and print your
* plugin as you see fit. If your plugin wants Netscape
* to handle printing in this case, set
* printInfo->pluginPrinted to FALSE (the default) and
* do nothing. If you do want to handle printing
* yourself, printOne is true if the print button
* (as opposed to the print menu) was clicked.
* On the Macintosh, platformPrint is a THPrint; on
* Windows, platformPrint is a structure
* (defined in npapi.h) containing the printer name, port,
* etc.
*/
/***** 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 */
/*
* PLUGIN DEVELOPERS:
* If your plugin is embedded, or is full-screen
* but you returned false in pluginPrinted above, NPP_Print
* will be called with mode == NP_EMBED. The NPWindow
* in the printInfo gives the location and dimensions of
* the embedded plugin on the printed page. On the
* Macintosh, platformPrint is the printer port; on
* Windows, platformPrint is the handle to the printing
* device context.
*/
/***** Insert NPP_Print code here *****\
NPWindow* printWindow =
&(printInfo->print.embedPrint.window);
void* platformPrint =
printInfo->print.embedPrint.platformPrint;
\**************************************/
}
}
}
/******************************************************************************
* Windows-only methods
*****************************************************************************/
#if defined(XP_WIN)
static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
{
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
switch( i_msg )
{
case WM_ERASEBKGND:
return 1L;
case WM_PAINT:
{
PAINTSTRUCT paintstruct;
HDC hdc;
RECT rect;
hdc = BeginPaint( p_hwnd, &paintstruct );
GetClientRect( p_hwnd, &rect );
FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
SetTextColor(hdc, RGB(255, 255, 255));
SetBkColor(hdc, RGB(0, 0, 0));
if( p_plugin->psz_text )
DrawText( hdc, p_plugin->psz_text, strlen(p_plugin->psz_text), &rect,
DT_CENTER|DT_VCENTER|DT_SINGLELINE);
EndPaint( p_hwnd, &paintstruct );
return 0L;
}
default:
/* delegate to default handler */
return CallWindowProc( p_plugin->getWindowProc(), p_hwnd,
i_msg, wpar, lpar );
}
}
#endif /* XP_WIN */
/******************************************************************************
* UNIX-only methods
*****************************************************************************/
#if defined(XP_UNIX)
static void Redraw( Widget w, XtPointer closure, XEvent *event )
{
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
Window control = p_plugin->getControlWindow();
const NPWindow& window = p_plugin->getWindow();
GC gc;
XGCValues gcv;
unsigned int i_control_height, i_control_width;
if( p_plugin->b_toolbar )
p_plugin->getToolbarSize( &i_control_width, &i_control_height );
else
i_control_height = i_control_width = 0;
Window video = p_plugin->getVideoWindow();
Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
gcv.foreground = BlackPixel( p_display, 0 );
gc = XCreateGC( p_display, video, GCForeground, &gcv );
XFillRectangle( p_display, video, gc,
0, 0, window.width, window.height - i_control_height);
gcv.foreground = WhitePixel( p_display, 0 );
XChangeGC( p_display, gc, GCForeground, &gcv );
if( p_plugin->psz_text )
XDrawString( p_display, video, gc,
window.width / 2 - 40, (window.height - i_control_height) / 2,
p_plugin->psz_text, strlen(p_plugin->psz_text) );
XFreeGC( p_display, gc );
p_plugin->redrawToolbar();
}
static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
{
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
const NPWindow& window = p_plugin->getWindow();
int i_height = window.height;
int i_width = window.width;
int i_xPos = event->xbutton.x;
int i_yPos = event->xbutton.y;
if( p_plugin && p_plugin->b_toolbar )
{
int i_playing;
libvlc_media_player_t *p_md = p_plugin->getMD();
i_playing = p_plugin->playlist_isplaying();
vlc_toolbar_clicked_t clicked;
clicked = p_plugin->getToolbarButtonClicked( i_xPos, i_yPos );
switch( clicked )
{
case clicked_Play:
case clicked_Pause:
{
if( i_playing == 1 )
p_plugin->playlist_pause();
else
p_plugin->playlist_play();
}
break;
case clicked_Stop:
{
p_plugin->playlist_stop();
}
break;
case clicked_Fullscreen:
{
p_plugin->set_fullscreen( 1 );
}
break;
case clicked_Mute:
case clicked_Unmute:
{
if( p_md )
libvlc_audio_toggle_mute( p_md );
}
break;
case clicked_timeline:
{
/* if a movie is loaded */
if( p_md )
{
int64_t f_length;
f_length = libvlc_media_player_get_length( p_md ) / 100;
f_length = (float)f_length *
( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) );
libvlc_media_player_set_time( p_md, f_length );
}
}
break;
case clicked_Time:
{
/* Not implemented yet*/
}
break;
default: /* button_Unknown */
break;
}
}
Redraw( w, closure, event );
}
static void Resize ( Widget w, XtPointer closure, XEvent *event )
{
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
Window control = p_plugin->getControlWindow();
const NPWindow& window = p_plugin->getWindow();
Window drawable = p_plugin->getVideoWindow();
Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
int i_ret;
Window root_return, parent_return, * children_return;
Window base_window;
unsigned int i_nchildren;
unsigned int i_control_height, i_control_width;
if( p_plugin->b_toolbar )
{
p_plugin->getToolbarSize( &i_control_width, &i_control_height );
}
else
{
i_control_height = i_control_width = 0;
}
#ifdef X11_RESIZE_DEBUG
XWindowAttributes attr;
if( event && event->type == ConfigureNotify )
{
fprintf( stderr, "vlcshell::Resize() ConfigureNotify %d x %d, "
"send_event ? %s\n", event->xconfigure.width,
event->xconfigure.height,
event->xconfigure.send_event ? "TRUE" : "FALSE" );
}
#endif /* X11_RESIZE_DEBUG */
if( ! p_plugin->setSize(window.width, (window.height - i_control_height)) )
{
/* size already set */
return;
}
i_ret = XResizeWindow( p_display, drawable,
window.width, (window.height - i_control_height) );
#ifdef X11_RESIZE_DEBUG
fprintf( stderr,
"vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret );
XGetWindowAttributes ( p_display, drawable, &attr );
/* X is asynchronous, so the current size reported here is not
necessarily the requested size as the Resize request may not
yet have been handled by the plugin host */
fprintf( stderr, "vlcshell::Resize() current (owner) size %d x %d\n",
attr.width, attr.height );
#endif /* X11_RESIZE_DEBUG */
XQueryTree( p_display, drawable,
&root_return, &parent_return, &children_return,
&i_nchildren );
if( i_nchildren > 0 )
{
/* XXX: Make assumptions related to the window parenting structure in
vlc/modules/video_output/x11/xcommon.c */
base_window = children_return[i_nchildren - 1];
#ifdef X11_RESIZE_DEBUG
fprintf( stderr, "vlcshell::Resize() got %d children\n", i_nchildren );
fprintf( stderr, "vlcshell::Resize() got base_window %p\n",
base_window );
#endif /* X11_RESIZE_DEBUG */
i_ret = XResizeWindow( p_display, base_window,
window.width, ( window.height - i_control_height ) );
#ifdef X11_RESIZE_DEBUG
fprintf( stderr,
"vlcshell::Resize() XResizeWindow(base) returned %d\n",
i_ret );
XGetWindowAttributes( p_display, base_window, &attr );
fprintf( stderr, "vlcshell::Resize() new size %d x %d\n",
attr.width, attr.height );
#endif /* X11_RESIZE_DEBUG */
}
}
#endif /* XP_UNIX */