📄 vlcshell.cpp
字号:
/***************************************************************************** * vlcshell.cpp: a VLC plugin for Mozilla ***************************************************************************** * Copyright (C) 2002-2008 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>/* Mozilla stuff */#ifdef HAVE_MOZILLA_CONFIG_H# include <mozilla-config.h>#endif/* This is from mozilla java, do we really need it? */#if 0#include <jri.h>#endif#include "vlcplugin.h"/* Enable/disable debugging printf's for X11 resizing */#undef X11_RESIZE_DEBUG#define WINDOW_TEXT "Video is loading..."/***************************************************************************** * Unix-only declarations******************************************************************************/#ifdef XP_UNIXstatic 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_WINstatic LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar );#endif/****************************************************************************** * UNIX-only API calls *****************************************************************************/char * NPP_GetMIMEDescription( void ){ return PLUGIN_MIMETYPES;}NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value ){ static char psz_desc[1000]; /* plugin class variables */ switch( variable ) { case NPPVpluginNameString: *((char **)value) = PLUGIN_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_MACOSXint16 NPP_HandleEvent( NPP instance, void * event ){ static UInt32 lastMouseUp = 0; if( instance == NULL ) { return false; } VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata; if( p_plugin == NULL ) { return false; } EventRecord *myEvent = (EventRecord*)event; switch( myEvent->what ) { case nullEvent: return true; case mouseDown: { if( (myEvent->when - lastMouseUp) < GetDblTime() ) { /* double click */ libvlc_instance_t *p_vlc = p_plugin->getVLC(); if( p_vlc ) { if( libvlc_playlist_isplaying(p_vlc, NULL) ) { libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_vlc, NULL); if( p_md ) { libvlc_toggle_fullscreen(p_md, NULL); libvlc_media_player_release(p_md); } } } } 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 ) { int hasVout = FALSE; libvlc_instance_t *p_vlc = p_plugin->getVLC(); if( p_vlc ) { if( libvlc_playlist_isplaying(p_vlc, NULL) ) { libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_vlc, NULL); if( p_md ) { hasVout = libvlc_media_player_has_vout(p_md, NULL); 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_md, &area, NULL); } libvlc_media_player_release(p_md); } } } if( ! hasVout ) { /* draw the beautiful "No Picture" */ 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 ); DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_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: ; } return false;}#endif /* XP_MACOSX *//****************************************************************************** * General Plug-in Calls *****************************************************************************/NPError NPP_Initialize( void ){ return NPERR_NO_ERROR;}jref NPP_GetJavaClass( void ){ return NULL;}void NPP_Shutdown( void ){ ;}NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -