Disable non implemented code to get build bot back.
[vlc.git] / projects / mozilla / vlcshell.cpp
blob2455d8c736f365e155ff953ae1961ac43d115f71
1 /*****************************************************************************
2 * vlcshell.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
5 * $Id$
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Jean-Paul Saman <jpsaman@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
26 * Preamble
27 *****************************************************************************/
28 #include "config.h"
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
34 /* Mozilla stuff */
35 #ifdef HAVE_MOZILLA_CONFIG_H
36 # include <mozilla-config.h>
37 #endif
39 /* This is from mozilla java, do we really need it? */
40 #if 0
41 #include <jri.h>
42 #endif
44 #include "vlcplugin.h"
45 #include "vlcshell.h"
47 /* Enable/disable debugging printf's for X11 resizing */
48 #undef X11_RESIZE_DEBUG
50 #define WINDOW_TEXT "Waiting for video"
52 /*****************************************************************************
53 * Unix-only declarations
54 ******************************************************************************/
55 #ifdef XP_UNIX
57 static void Redraw( Widget w, XtPointer closure, XEvent *event );
58 static void ControlHandler( Widget w, XtPointer closure, XEvent *event );
59 static void Resize( Widget w, XtPointer closure, XEvent *event );
61 #endif
63 /*****************************************************************************
64 * MacOS-only declarations
65 ******************************************************************************/
66 #ifdef XP_MACOSX
67 #endif
69 /*****************************************************************************
70 * Windows-only declarations
71 *****************************************************************************/
72 #ifdef XP_WIN
74 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );
76 #endif
78 /******************************************************************************
79 * UNIX-only API calls
80 *****************************************************************************/
81 char * NPP_GetMIMEDescription( void )
83 static char mimetype[] = PLUGIN_MIMETYPES;
84 return mimetype;
87 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
89 static char psz_name[] = PLUGIN_NAME;
90 static char psz_desc[1000];
92 /* plugin class variables */
93 switch( variable )
95 case NPPVpluginNameString:
96 *((char **)value) = psz_name;
97 return NPERR_NO_ERROR;
99 case NPPVpluginDescriptionString:
100 snprintf( psz_desc, sizeof(psz_desc), PLUGIN_DESCRIPTION,
101 libvlc_get_version() );
102 *((char **)value) = psz_desc;
103 return NPERR_NO_ERROR;
105 default:
106 /* move on to instance variables ... */
110 if( instance == NULL )
112 return NPERR_INVALID_INSTANCE_ERROR;
115 /* plugin instance variables */
117 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
118 if( NULL == p_plugin )
120 // plugin has not been initialized yet !
121 return NPERR_INVALID_INSTANCE_ERROR;
124 switch( variable )
126 case NPPVpluginScriptableNPObject:
128 /* retrieve plugin root class */
129 NPClass *scriptClass = p_plugin->getScriptClass();
130 if( scriptClass )
132 /* create an instance and return it */
133 *(NPObject**)value = NPN_CreateObject(instance, scriptClass);
134 return NPERR_NO_ERROR;
136 break;
139 default:
142 return NPERR_GENERIC_ERROR;
146 * there is some confusion in gecko headers regarding definition of this API
147 * NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
150 NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
152 return NPERR_GENERIC_ERROR;
155 /******************************************************************************
156 * Mac-only API calls
157 *****************************************************************************/
158 #ifdef XP_MACOSX
159 int16 NPP_HandleEvent( NPP instance, void * event )
161 static UInt32 lastMouseUp = 0;
162 libvlc_exception_t ex;
163 libvlc_exception_init(&ex);
165 if( instance == NULL )
167 return false;
170 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
171 if( p_plugin == NULL )
173 return false;
176 EventRecord *myEvent = (EventRecord*)event;
178 switch( myEvent->what )
180 case nullEvent:
181 return true;
182 case mouseDown:
184 if( (myEvent->when - lastMouseUp) < GetDblTime() )
186 /* double click */
187 p_plugin->toggle_fullscreen(&ex);
188 libvlc_exception_clear(&ex);
190 return true;
192 case mouseUp:
193 lastMouseUp = myEvent->when;
194 return true;
195 case keyUp:
196 case keyDown:
197 case autoKey:
198 return true;
199 case updateEvt:
201 const NPWindow& npwindow = p_plugin->getWindow();
202 if( npwindow.window )
204 int hasVout = FALSE;
206 if( p_plugin->playlist_isplaying(&ex) )
208 hasVout = p_plugin->player_has_vout(NULL);
209 if( hasVout )
211 #ifdef NOT_WORKING
212 libvlc_rectangle_t area;
213 area.left = 0;
214 area.top = 0;
215 area.right = npwindow.width;
216 area.bottom = npwindow.height;
217 libvlc_video_redraw_rectangle(p_plugin->getMD(&ex), &area, NULL);
218 #else
219 #warning disabled code
220 #endif
223 libvlc_exception_clear(&ex);
225 if( ! hasVout )
227 /* draw the beautiful "No Picture" */
229 ForeColor(blackColor);
230 PenMode( patCopy );
232 /* seems that firefox forgets to set the following
233 * on occasion (reload) */
234 SetOrigin(((NP_Port *)npwindow.window)->portx,
235 ((NP_Port *)npwindow.window)->porty);
237 Rect rect;
238 rect.left = 0;
239 rect.top = 0;
240 rect.right = npwindow.width;
241 rect.bottom = npwindow.height;
242 PaintRect( &rect );
244 ForeColor(whiteColor);
245 MoveTo( (npwindow.width-80)/ 2 , npwindow.height / 2 );
246 DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
249 return true;
251 case activateEvt:
252 return false;
253 case NPEventType_GetFocusEvent:
254 case NPEventType_LoseFocusEvent:
255 return true;
256 case NPEventType_AdjustCursorEvent:
257 return false;
258 case NPEventType_MenuCommandEvent:
259 return false;
260 case NPEventType_ClippingChangedEvent:
261 return false;
262 case NPEventType_ScrollingBeginsEvent:
263 return true;
264 case NPEventType_ScrollingEndsEvent:
265 return true;
266 default:
269 return false;
271 #endif /* XP_MACOSX */
273 /******************************************************************************
274 * General Plug-in Calls
275 *****************************************************************************/
276 NPError NPP_Initialize( void )
278 return NPERR_NO_ERROR;
281 jref NPP_GetJavaClass( void )
283 return NULL;
286 void NPP_Shutdown( void )
291 NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
292 char* argn[], char* argv[], NPSavedData* saved )
294 NPError status;
296 if( instance == NULL )
298 return NPERR_INVALID_INSTANCE_ERROR;
301 VlcPlugin * p_plugin = new VlcPlugin( instance, mode );
302 if( NULL == p_plugin )
304 return NPERR_OUT_OF_MEMORY_ERROR;
307 status = p_plugin->init(argc, argn, argv);
308 if( NPERR_NO_ERROR == status )
310 instance->pdata = reinterpret_cast<void*>(p_plugin);
311 #if 0
312 NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
313 NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
314 #endif
316 else
318 delete p_plugin;
320 return status;
323 NPError NPP_Destroy( NPP instance, NPSavedData** save )
325 if( NULL == instance )
326 return NPERR_INVALID_INSTANCE_ERROR;
328 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
329 if( NULL == p_plugin )
330 return NPERR_NO_ERROR;
332 instance->pdata = NULL;
334 #if XP_WIN
335 HWND win = (HWND)p_plugin->getWindow().window;
336 WNDPROC winproc = p_plugin->getWindowProc();
337 if( winproc )
339 /* reset WNDPROC */
340 SetWindowLong( win, GWL_WNDPROC, (LONG)winproc );
342 #endif
344 delete p_plugin;
346 return NPERR_NO_ERROR;
349 NPError NPP_SetWindow( NPP instance, NPWindow* window )
351 #if defined(XP_UNIX) && !defined(__APPLE__)
352 Window control;
353 unsigned int i_control_height = 0, i_control_width = 0;
354 #endif
356 if( ! instance )
358 return NPERR_INVALID_INSTANCE_ERROR;
361 /* NPP_SetWindow may be called before NPP_New (Opera) */
362 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
363 if( NULL == p_plugin )
365 /* we should probably show a splash screen here */
366 return NPERR_NO_ERROR;
369 #if defined(XP_UNIX) && !defined(__APPLE__)
370 control = p_plugin->getControlWindow();
371 #endif
373 libvlc_exception_t ex;
374 libvlc_exception_init(&ex);
376 libvlc_instance_t *p_vlc = p_plugin->getVLC();
379 * PLUGIN DEVELOPERS:
380 * Before setting window to point to the
381 * new window, you may wish to compare the new window
382 * info to the previous window (if any) to note window
383 * size changes, etc.
386 /* retrieve current window */
387 NPWindow& curwin = p_plugin->getWindow();
389 #ifdef XP_MACOSX
390 if( window && window->window )
392 /* check if plugin has a new parent window */
393 CGrafPtr drawable = (((NP_Port*) (window->window))->port);
395 /* as MacOS X video output is windowless, set viewport */
396 libvlc_rectangle_t view, clip;
399 ** browser sets port origin to top-left location of plugin
400 ** relative to GrafPort window origin is set relative to document,
401 ** which of little use for drawing
403 view.top = ((NP_Port*) (window->window))->porty;
404 view.left = ((NP_Port*) (window->window))->portx;
405 view.bottom = window->height+view.top;
406 view.right = window->width+view.left;
408 /* clipRect coordinates are also relative to GrafPort */
409 clip.top = window->clipRect.top;
410 clip.left = window->clipRect.left;
411 clip.bottom = window->clipRect.bottom;
412 clip.right = window->clipRect.right;
413 #ifdef NOT_WORKING
414 libvlc_video_set_viewport(p_vlc, p_plugin->getMD(&ex), &view, &clip, &ex);
415 libvlc_exception_clear(&ex);
416 #else
417 #warning disabled code
418 #endif
419 /* remember new window */
420 p_plugin->setWindow(*window);
422 else if( curwin.window )
424 /* change/set parent */
425 curwin.window = NULL;
427 #endif /* XP_MACOSX */
429 #ifdef XP_WIN
430 if( window && window->window )
432 /* check if plugin has a new parent window */
433 HWND drawable = (HWND) (window->window);
434 if( !curwin.window || drawable != curwin.window )
436 /* reset previous window settings */
437 HWND oldwin = (HWND)p_plugin->getWindow().window;
438 WNDPROC oldproc = p_plugin->getWindowProc();
439 if( oldproc )
441 /* reset WNDPROC */
442 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)oldproc );
444 /* attach our plugin object */
445 SetWindowLongPtr((HWND)drawable, GWLP_USERDATA,
446 reinterpret_cast<LONG_PTR>(p_plugin));
448 /* install our WNDPROC */
449 p_plugin->setWindowProc( (WNDPROC)SetWindowLong( drawable,
450 GWL_WNDPROC, (LONG)Manage ) );
452 /* change window style to our liking */
453 LONG style = GetWindowLong((HWND)drawable, GWL_STYLE);
454 style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
455 SetWindowLong((HWND)drawable, GWL_STYLE, style);
457 /* remember new window */
458 p_plugin->setWindow(*window);
460 /* Redraw window */
461 InvalidateRect( (HWND)drawable, NULL, TRUE );
462 UpdateWindow( (HWND)drawable );
465 else if( curwin.window )
467 /* reset WNDPROC */
468 HWND oldwin = (HWND)curwin.window;
469 SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) );
470 p_plugin->setWindowProc(NULL);
472 curwin.window = NULL;
474 #endif /* XP_WIN */
476 #ifdef XP_UNIX
477 /* default to hidden toolbar, shown at the end of this method if asked *
478 * developers note : getToolbarSize need to wait the end of this method
480 i_control_height = 0;
481 i_control_width = window->width;
483 if( window && window->window )
485 Window parent = (Window) window->window;
486 if( !curwin.window || (parent != (Window)curwin.window) )
488 Display *p_display = ( (NPSetWindowCallbackStruct *)
489 window->ws_info )->display;
491 XResizeWindow( p_display, parent, window->width, window->height );
493 int i_blackColor = BlackPixel(p_display, DefaultScreen(p_display));
495 /* create windows */
496 Window video = XCreateSimpleWindow( p_display, parent, 0, 0,
497 window->width, window->height - i_control_height,
498 0, i_blackColor, i_blackColor );
499 Window controls = (Window) NULL;
500 controls = XCreateSimpleWindow( p_display, parent,
501 0, window->height - i_control_height-1,
502 window->width, i_control_height-1,
503 0, i_blackColor, i_blackColor );
505 XMapWindow( p_display, parent );
506 XMapWindow( p_display, video );
507 if( controls ) { XMapWindow( p_display, controls ); }
509 XFlush(p_display);
511 /* bind events */
512 Widget w = XtWindowToWidget( p_display, parent );
514 XtAddEventHandler( w, ExposureMask, FALSE,
515 (XtEventHandler)Redraw, p_plugin );
516 XtAddEventHandler( w, StructureNotifyMask, FALSE,
517 (XtEventHandler)Resize, p_plugin );
518 XtAddEventHandler( w, ButtonReleaseMask, FALSE,
519 (XtEventHandler)ControlHandler, p_plugin );
521 /* remember window */
522 p_plugin->setWindow( *window );
523 p_plugin->setVideoWindow( video );
525 if( controls )
527 p_plugin->setControlWindow( controls );
530 Redraw( w, (XtPointer)p_plugin, NULL );
532 /* now display toolbar if asked through parameters */
533 if( p_plugin->b_toolbar )
535 p_plugin->showToolbar();
539 else if( curwin.window )
541 curwin.window = NULL;
543 #endif /* XP_UNIX */
545 if( !p_plugin->b_stream )
547 if( p_plugin->psz_target )
549 if( p_plugin->playlist_add( p_plugin->psz_target, NULL ) != -1 )
551 if( p_plugin->b_autoplay )
553 p_plugin->playlist_play(NULL);
556 p_plugin->b_stream = true;
559 return NPERR_NO_ERROR;
562 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
563 NPBool seekable, uint16 *stype )
565 if( NULL == instance )
567 return NPERR_INVALID_INSTANCE_ERROR;
570 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
571 if( NULL == p_plugin )
573 return NPERR_INVALID_INSTANCE_ERROR;
577 ** Firefox/Mozilla may decide to open a stream from the URL specified
578 ** in the SRC parameter of the EMBED tag and pass it to us
580 ** since VLC will open the SRC URL as well, we're not interested in
581 ** that stream. Otherwise, we'll take it and queue it up in the playlist
583 if( !p_plugin->psz_target || strcmp(stream->url, p_plugin->psz_target) )
585 /* TODO: use pipes !!!! */
586 *stype = NP_ASFILEONLY;
587 return NPERR_NO_ERROR;
589 return NPERR_GENERIC_ERROR;
592 int32 NPP_WriteReady( NPP instance, NPStream *stream )
594 /* TODO */
595 return 8*1024;
598 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
599 int32 len, void *buffer )
601 /* TODO */
602 return len;
605 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
607 if( instance == NULL )
609 return NPERR_INVALID_INSTANCE_ERROR;
611 return NPERR_NO_ERROR;
614 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
616 if( instance == NULL )
618 return;
621 VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
622 if( NULL == p_plugin )
624 return;
627 if( p_plugin->playlist_add( stream->url, NULL ) != -1 )
629 if( p_plugin->b_autoplay )
631 p_plugin->playlist_play(NULL);
636 void NPP_URLNotify( NPP instance, const char* url,
637 NPReason reason, void* notifyData )
639 /***** Insert NPP_URLNotify code here *****\
640 PluginInstance* p_plugin;
641 if (instance != NULL)
642 p_plugin = (PluginInstance*) instance->pdata;
643 \*********************************************/
646 void NPP_Print( NPP instance, NPPrint* printInfo )
648 if( printInfo == NULL )
650 return;
653 if( instance != NULL )
655 /***** Insert NPP_Print code here *****\
656 PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
657 \**************************************/
659 if( printInfo->mode == NP_FULL )
662 * PLUGIN DEVELOPERS:
663 * If your plugin would like to take over
664 * printing completely when it is in full-screen mode,
665 * set printInfo->pluginPrinted to TRUE and print your
666 * plugin as you see fit. If your plugin wants Netscape
667 * to handle printing in this case, set
668 * printInfo->pluginPrinted to FALSE (the default) and
669 * do nothing. If you do want to handle printing
670 * yourself, printOne is true if the print button
671 * (as opposed to the print menu) was clicked.
672 * On the Macintosh, platformPrint is a THPrint; on
673 * Windows, platformPrint is a structure
674 * (defined in npapi.h) containing the printer name, port,
675 * etc.
678 /***** Insert NPP_Print code here *****\
679 void* platformPrint =
680 printInfo->print.fullPrint.platformPrint;
681 NPBool printOne =
682 printInfo->print.fullPrint.printOne;
683 \**************************************/
685 /* Do the default*/
686 printInfo->print.fullPrint.pluginPrinted = FALSE;
688 else
690 /* If not fullscreen, we must be embedded */
692 * PLUGIN DEVELOPERS:
693 * If your plugin is embedded, or is full-screen
694 * but you returned false in pluginPrinted above, NPP_Print
695 * will be called with mode == NP_EMBED. The NPWindow
696 * in the printInfo gives the location and dimensions of
697 * the embedded plugin on the printed page. On the
698 * Macintosh, platformPrint is the printer port; on
699 * Windows, platformPrint is the handle to the printing
700 * device context.
703 /***** Insert NPP_Print code here *****\
704 NPWindow* printWindow =
705 &(printInfo->print.embedPrint.window);
706 void* platformPrint =
707 printInfo->print.embedPrint.platformPrint;
708 \**************************************/
713 /******************************************************************************
714 * Windows-only methods
715 *****************************************************************************/
716 #if XP_WIN
717 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
719 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
721 switch( i_msg )
723 case WM_ERASEBKGND:
724 return 1L;
726 case WM_PAINT:
728 PAINTSTRUCT paintstruct;
729 HDC hdc;
730 RECT rect;
732 hdc = BeginPaint( p_hwnd, &paintstruct );
734 GetClientRect( p_hwnd, &rect );
736 FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
737 SetTextColor(hdc, RGB(255, 255, 255));
738 SetBkColor(hdc, RGB(0, 0, 0));
739 DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect,
740 DT_CENTER|DT_VCENTER|DT_SINGLELINE);
742 EndPaint( p_hwnd, &paintstruct );
743 return 0L;
745 default:
746 /* delegate to default handler */
747 return CallWindowProc( p_plugin->getWindowProc(), p_hwnd,
748 i_msg, wpar, lpar );
751 #endif /* XP_WIN */
753 /******************************************************************************
754 * UNIX-only methods
755 *****************************************************************************/
756 #ifdef XP_UNIX
757 static void Redraw( Widget w, XtPointer closure, XEvent *event )
759 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
760 Window control = p_plugin->getControlWindow();
761 const NPWindow& window = p_plugin->getWindow();
762 GC gc;
763 XGCValues gcv;
764 unsigned int i_control_height, i_control_width;
766 if( p_plugin->b_toolbar )
767 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
768 else
769 i_control_height = i_control_width = 0;
771 Window video = p_plugin->getVideoWindow();
772 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
774 gcv.foreground = BlackPixel( p_display, 0 );
775 gc = XCreateGC( p_display, video, GCForeground, &gcv );
777 XFillRectangle( p_display, video, gc,
778 0, 0, window.width, window.height - i_control_height);
780 gcv.foreground = WhitePixel( p_display, 0 );
781 XChangeGC( p_display, gc, GCForeground, &gcv );
783 XDrawString( p_display, video, gc,
784 window.width / 2 - 40, (window.height - i_control_height) / 2,
785 WINDOW_TEXT, strlen(WINDOW_TEXT) );
786 XFreeGC( p_display, gc );
788 p_plugin->redrawToolbar();
791 static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
793 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
794 const NPWindow& window = p_plugin->getWindow();
796 int i_height = window.height;
797 int i_width = window.width;
798 int i_xPos = event->xbutton.x;
799 int i_yPos = event->xbutton.y;
801 if( p_plugin && p_plugin->b_toolbar )
803 int i_playing;
804 libvlc_exception_t ex;
806 libvlc_exception_init( &ex );
807 libvlc_media_player_t *p_md = p_plugin->getMD(&ex);
808 libvlc_exception_clear( &ex );
810 i_playing = p_plugin->playlist_isplaying( &ex );
811 libvlc_exception_clear( &ex );
813 vlc_toolbar_clicked_t clicked;
814 clicked = p_plugin->getToolbarButtonClicked( i_xPos, i_yPos );
815 switch( clicked )
817 case clicked_Play:
818 case clicked_Pause:
820 if( i_playing == 1 )
821 p_plugin->playlist_pause( &ex );
822 else
823 p_plugin->playlist_play( &ex );
825 libvlc_exception_clear( &ex );
827 break;
829 case clicked_Stop:
831 p_plugin->playlist_stop(&ex);
832 libvlc_exception_clear( &ex );
834 break;
836 case clicked_Fullscreen:
838 p_plugin->set_fullscreen( 1, &ex );
839 libvlc_exception_clear( &ex );
841 break;
843 case clicked_Mute:
844 case clicked_Unmute:
846 libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
847 libvlc_exception_clear( &ex );
849 break;
851 case clicked_timeline:
853 /* if a movie is loaded */
854 if( p_md )
856 int64_t f_length;
857 f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
858 libvlc_exception_clear( &ex );
860 f_length = (float)f_length *
861 ( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) );
863 libvlc_media_player_set_time( p_md, f_length, &ex );
864 libvlc_exception_clear( &ex );
867 break;
869 case clicked_Time:
871 /* Not implemented yet*/
873 break;
875 default: /* button_Unknown */
876 break;
879 Redraw( w, closure, event );
882 static void Resize ( Widget w, XtPointer closure, XEvent *event )
884 VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
885 Window control = p_plugin->getControlWindow();
886 const NPWindow& window = p_plugin->getWindow();
887 Window drawable = p_plugin->getVideoWindow();
888 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
890 int i_ret;
891 Window root_return, parent_return, * children_return;
892 Window base_window;
893 unsigned int i_nchildren;
894 unsigned int i_control_height, i_control_width;
896 if( p_plugin->b_toolbar )
898 p_plugin->getToolbarSize( &i_control_width, &i_control_height );
900 else
902 i_control_height = i_control_width = 0;
905 #ifdef X11_RESIZE_DEBUG
906 XWindowAttributes attr;
908 if( event && event->type == ConfigureNotify )
910 fprintf( stderr, "vlcshell::Resize() ConfigureNotify %d x %d, "
911 "send_event ? %s\n", event->xconfigure.width,
912 event->xconfigure.height,
913 event->xconfigure.send_event ? "TRUE" : "FALSE" );
915 #endif /* X11_RESIZE_DEBUG */
917 if( ! p_plugin->setSize(window.width, (window.height - i_control_height)) )
919 /* size already set */
920 return;
923 i_ret = XResizeWindow( p_display, drawable,
924 window.width, (window.height - i_control_height) );
926 #ifdef X11_RESIZE_DEBUG
927 fprintf( stderr,
928 "vlcshell::Resize() XResizeWindow(owner) returned %d\n", i_ret );
930 XGetWindowAttributes ( p_display, drawable, &attr );
932 /* X is asynchronous, so the current size reported here is not
933 necessarily the requested size as the Resize request may not
934 yet have been handled by the plugin host */
935 fprintf( stderr, "vlcshell::Resize() current (owner) size %d x %d\n",
936 attr.width, attr.height );
937 #endif /* X11_RESIZE_DEBUG */
939 XQueryTree( p_display, drawable,
940 &root_return, &parent_return, &children_return,
941 &i_nchildren );
943 if( i_nchildren > 0 )
945 /* XXX: Make assumptions related to the window parenting structure in
946 vlc/modules/video_output/x11/xcommon.c */
947 base_window = children_return[i_nchildren - 1];
949 #ifdef X11_RESIZE_DEBUG
950 fprintf( stderr, "vlcshell::Resize() got %d children\n", i_nchildren );
951 fprintf( stderr, "vlcshell::Resize() got base_window %p\n",
952 base_window );
953 #endif /* X11_RESIZE_DEBUG */
955 i_ret = XResizeWindow( p_display, base_window,
956 window.width, ( window.height - i_control_height ) );
958 #ifdef X11_RESIZE_DEBUG
959 fprintf( stderr,
960 "vlcshell::Resize() XResizeWindow(base) returned %d\n",
961 i_ret );
963 XGetWindowAttributes( p_display, base_window, &attr );
965 fprintf( stderr, "vlcshell::Resize() new size %d x %d\n",
966 attr.width, attr.height );
967 #endif /* X11_RESIZE_DEBUG */
971 #endif /* XP_UNIX */