merged tag LIBREOFFICE_3_2_99_3
[LibreOffice.git] / extensions / source / plugin / win / sysplug.cxx
blobc992341dc94712b6a1c2e46562b8b5043a9e2388
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_extensions.hxx"
32 #include <plugin/impl.hxx>
34 #pragma warning (push,1)
35 #pragma warning (disable:4005)
37 #include <tools/prewin.h>
39 #include <windows.h>
40 #include <string.h>
41 #include <tchar.h>
42 #include <winreg.h>
43 #include <winbase.h>
44 #include <objbase.h>
46 #include <tools/postwin.h>
48 #pragma warning (pop)
50 #include <list>
51 #include <map>
52 #include <algorithm>
55 extern NPNetscapeFuncs aNPNFuncs;
57 #include <tools/debug.hxx>
59 using namespace rtl;
61 #if OSL_DEBUG_LEVEL > 1
62 void TRACE( char const * s );
63 void TRACEN( char const * s, long n );
64 #else
65 #define TRACE(x)
66 #define TRACEN(x,n)
67 #endif
70 //--------------------------------------------------------------------------------------------------
71 PluginComm_Impl::PluginComm_Impl( const OUString& /*rMIME*/, const OUString& rName, HWND /*hWnd*/ )
72 : PluginComm( OUStringToOString( rName, RTL_TEXTENCODING_MS_1252 ) )
74 // initialize plugin function table
75 memset( &_NPPfuncs, 0, sizeof( _NPPfuncs ) );
76 #ifdef UNICODE
77 _plDLL = ::LoadLibrary( rName.getStr() );
78 #else
79 OString aStr( OUStringToOString( rName, RTL_TEXTENCODING_MS_1252 ) );
80 _plDLL = ::LoadLibrary( aStr.getStr() );
81 #endif
82 DBG_ASSERT( _plDLL, "### loading plugin dll failed!" );
84 NPError nErr = NPERR_NO_ERROR;
85 NPError (WINAPI * pEntry)( NPPluginFuncs* );
86 retrieveFunction( _T("NP_GetEntryPoints"), (void**)&pEntry );
88 _NPPfuncs.size = sizeof( _NPPfuncs );
89 _NPPfuncs.version = 0;
90 nErr = (*pEntry)( &_NPPfuncs );
92 DBG_ASSERT( nErr == NPERR_NO_ERROR, "### NP_GetEntryPoints() failed!" );
93 DBG_ASSERT( (_NPPfuncs.version >> 8) >= NP_VERSION_MAJOR,
94 "### version failure!" );
96 m_eCall = eNP_Initialize;
97 execute();
100 //--------------------------------------------------------------------------------------------------
101 PluginComm_Impl::~PluginComm_Impl()
103 if (_plDLL)
105 // NPP_Shutdown();
107 NPError (WINAPI * pShutdown)();
108 if (retrieveFunction( _T("NP_Shutdown"), (void**)&pShutdown ))
110 NPError nErr = (*pShutdown)(); (void)nErr;
111 DBG_ASSERT( nErr == NPERR_NO_ERROR, "### NP_Shutdown() failed!" );
114 BOOL bRet = (BOOL)::FreeLibrary( _plDLL ); (void)bRet;
115 DBG_ASSERT( bRet, "### unloading plugin dll failed!" );
116 _plDLL = NULL;
120 //--------------------------------------------------------------------------------------------------
121 BOOL PluginComm_Impl::retrieveFunction( TCHAR* pName, void** ppFunc ) const
123 if( ! _plDLL )
124 return FALSE;
126 *ppFunc = (void*)::GetProcAddress( _plDLL, pName );
128 return (*ppFunc != NULL);
131 //--------------------------------------------------------------------------------------------------
133 long PluginComm_Impl::doIt()
135 long nRet = 0;
136 switch( m_eCall )
138 case eNP_Initialize:
140 TRACE( "eNP_Initialize" );
141 NPError (WINAPI * pInit)( NPNetscapeFuncs* );
142 if ((_NPPfuncs.version >> 8) >= NP_VERSION_MAJOR &&
143 (retrieveFunction( _T("NP_Initialize"), (void**)&pInit ) ||
144 retrieveFunction( _T("NP_PluginInit"), (void**)&pInit )))
146 nRet = (*pInit)( &aNPNFuncs );
148 else
150 nRet = NPERR_GENERIC_ERROR;
152 DBG_ASSERT( nRet == NPERR_NO_ERROR, "### NP_Initialize() failed!" );
154 break;
155 case eNPP_Destroy:
156 TRACE( "eNPP_Destroy" );
157 nRet = (_NPPfuncs.destroy
158 ? (*_NPPfuncs.destroy)(
159 (NPP)m_aArgs[0],
160 (NPSavedData**)m_aArgs[1] )
161 : NPERR_GENERIC_ERROR);
162 break;
163 case eNPP_DestroyStream:
164 TRACE( "eNPP_DestroyStream" );
165 nRet = (_NPPfuncs.destroystream
166 ? (*_NPPfuncs.destroystream)(
167 (NPP)m_aArgs[0],
168 (NPStream*)m_aArgs[1],
169 (NPError)(sal_IntPtr)m_aArgs[2] )
170 : NPERR_GENERIC_ERROR);
171 break;
172 case eNPP_New:
173 TRACE( "eNPP_New" );
174 nRet = (_NPPfuncs.newp
175 ? (*_NPPfuncs.newp)(
176 (NPMIMEType)m_aArgs[0],
177 (NPP)m_aArgs[1],
178 (uint16)(sal_IntPtr)m_aArgs[2],
179 (int16)(sal_IntPtr)m_aArgs[3],
180 (char**)m_aArgs[4],
181 (char**)m_aArgs[5],
182 (NPSavedData*)m_aArgs[6] )
183 : NPERR_GENERIC_ERROR);
184 break;
185 case eNPP_NewStream:
186 TRACE( "eNPP_NewStream" );
187 nRet = (_NPPfuncs.newstream
188 ? (*_NPPfuncs.newstream)(
189 (NPP)m_aArgs[0],
190 (NPMIMEType)m_aArgs[1],
191 (NPStream*)m_aArgs[2],
192 (NPBool)(sal_IntPtr)m_aArgs[3],
193 (uint16*)m_aArgs[4] )
194 : NPERR_GENERIC_ERROR);
195 break;
196 case eNPP_Print:
197 TRACE( "eNPP_Print" );
198 if (_NPPfuncs.print)
199 (*_NPPfuncs.print)(
200 (NPP)m_aArgs[0],
201 (NPPrint*)m_aArgs[1] );
202 break;
203 case eNPP_SetWindow:
205 TRACE( "eNPP_SetWindow" );
206 nRet = (_NPPfuncs.setwindow
207 ? (*_NPPfuncs.setwindow)(
208 (NPP)m_aArgs[0],
209 (NPWindow*)m_aArgs[1] )
210 : NPERR_GENERIC_ERROR);
211 break;
213 case eNPP_StreamAsFile:
214 TRACE( "eNPP_StreamAsFile" );
215 if (_NPPfuncs.asfile)
216 (*_NPPfuncs.asfile)(
217 (NPP)m_aArgs[0],
218 (NPStream*)m_aArgs[1],
219 (char*)m_aArgs[2] );
220 break;
221 case eNPP_URLNotify:
222 TRACE( "eNPP_URLNotify" );
223 if (_NPPfuncs.urlnotify)
224 (*_NPPfuncs.urlnotify)(
225 (NPP)m_aArgs[0],
226 (char*)m_aArgs[1],
227 (NPReason)(sal_IntPtr)m_aArgs[2],
228 m_aArgs[3] );
229 break;
230 case eNPP_Write:
231 TRACEN( "eNPP_Write n=", (int32)m_aArgs[3] );
232 nRet = (_NPPfuncs.write
233 ? (*_NPPfuncs.write)(
234 (NPP)m_aArgs[0],
235 (NPStream*)m_aArgs[1],
236 (int32)m_aArgs[2],
237 (int32)m_aArgs[3],
238 m_aArgs[4] )
239 : 0);
240 break;
241 case eNPP_WriteReady:
242 TRACE( "eNPP_WriteReady" );
243 nRet = (_NPPfuncs.writeready
244 ? (*_NPPfuncs.writeready)(
245 (NPP)m_aArgs[0],
246 (NPStream*)m_aArgs[1] )
247 : 0);
248 break;
249 case eNPP_GetValue:
250 TRACE( "eNPP_GetValue" );
251 nRet = (_NPPfuncs.getvalue
252 ? (*_NPPfuncs.getvalue)(
253 (NPP)m_aArgs[0],
254 (NPPVariable)(int)m_aArgs[1],
255 m_aArgs[2] )
256 : NPERR_GENERIC_ERROR);
257 break;
258 case eNPP_SetValue:
259 TRACE( "eNPP_SetValue" );
260 nRet = (_NPPfuncs.setvalue
261 ? (*_NPPfuncs.setvalue)(
262 (NPP)m_aArgs[0],
263 (NPNVariable)(int)m_aArgs[1],
264 m_aArgs[2] )
265 : NPERR_GENERIC_ERROR);
266 break;
267 case eNPP_Shutdown:
269 TRACE( "eNPP_Shutdown" );
270 NPP_ShutdownUPP pFunc;
271 if (retrieveFunction( _T("NPP_Shutdown"), (void**)&pFunc ))
272 (*pFunc)();
274 break;
275 case eNPP_Initialize:
276 TRACE( "eNPP_Initialize" );
277 OSL_ENSURE( false, "NPP_Initialize: not implemented!" );
278 break;
279 case eNPP_GetJavaClass:
280 TRACE( "eNPP_GetJavaClass" );
281 OSL_ENSURE( false, "NPP_GetJavaClass: not implemented!" );
282 break;
284 return nRet;
287 //--------------------------------------------------------------------------------------------------
288 NPError PluginComm_Impl::NPP_Destroy( NPP instance, NPSavedData** save )
290 DBG_ASSERT( _NPPfuncs.destroy, "### NPP_Destroy(): null pointer in NPP functions table!" );
291 m_eCall = eNPP_Destroy;
292 m_aArgs[0] = (void*)instance;
293 m_aArgs[1] = (void*)save;
294 return (NPError)execute();
297 //--------------------------------------------------------------------------------------------------
298 NPError PluginComm_Impl::NPP_DestroyStream( NPP instance, NPStream* stream, NPError reason )
300 DBG_ASSERT( _NPPfuncs.destroystream, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
301 m_eCall = eNPP_DestroyStream;
302 m_aArgs[0] = (void*)instance;
303 m_aArgs[1] = (void*)stream;
304 m_aArgs[2] = (void*)reason;
305 return (NPError)execute();
308 //--------------------------------------------------------------------------------------------------
309 NPError PluginComm_Impl::NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
310 char* argn[], char* argv[], NPSavedData *saved )
312 DBG_ASSERT( _NPPfuncs.newp, "### NPP_New(): null pointer in NPP functions table!" );
313 m_eCall = eNPP_New;
314 m_aArgs[0] = (void*)pluginType;
315 m_aArgs[1] = (void*)instance;
316 m_aArgs[2] = (void*)mode;
317 m_aArgs[3] = (void*)argc;
318 m_aArgs[4] = (void*)argn;
319 m_aArgs[5] = (void*)argv;
320 m_aArgs[6] = (void*)saved;
321 return (NPError)execute();
324 //--------------------------------------------------------------------------------------------------
325 NPError PluginComm_Impl::NPP_NewStream( NPP instance, NPMIMEType type, NPStream* stream,
326 NPBool seekable, uint16* stype )
328 DBG_ASSERT( _NPPfuncs.newstream, "### NPP_NewStream(): null pointer in NPP functions table!" );
329 m_eCall = eNPP_NewStream;
330 m_aArgs[0] = (void*)instance;
331 m_aArgs[1] = (void*)type;
332 m_aArgs[2] = (void*)stream;
333 m_aArgs[3] = (void*)seekable;
334 m_aArgs[4] = (void*)stype;
335 return (NPError)execute();
338 //--------------------------------------------------------------------------------------------------
339 void PluginComm_Impl::NPP_Print( NPP instance, NPPrint* platformPrint )
341 DBG_ASSERT( _NPPfuncs.print, "### NPP_Print(): null pointer in NPP functions table!" );
342 m_eCall = eNPP_Print;
343 m_aArgs[0] = (void*)instance;
344 m_aArgs[1] = (void*)platformPrint;
345 execute();
348 //--------------------------------------------------------------------------------------------------
349 NPError PluginComm_Impl::NPP_SetWindow( NPP instance, NPWindow* window )
351 DBG_ASSERT( _NPPfuncs.setwindow, "### NPP_SetWindow(): null pointer in NPP functions table!" );
352 m_eCall = eNPP_SetWindow;
353 m_aArgs[0] = (void*)instance;
354 m_aArgs[1] = (void*)window;
355 return (NPError)execute();
358 //--------------------------------------------------------------------------------------------------
359 void PluginComm_Impl::NPP_StreamAsFile( NPP instance, NPStream* stream, const char* fname )
361 DBG_ASSERT( _NPPfuncs.asfile, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
362 m_eCall = eNPP_StreamAsFile;
363 m_aArgs[0] = (void*)instance;
364 m_aArgs[1] = (void*)stream;
365 m_aArgs[2] = (void*)fname;
366 execute();
369 //--------------------------------------------------------------------------------------------------
370 void PluginComm_Impl::NPP_URLNotify( NPP instance, const char* url, NPReason reason, void* notifyData )
372 DBG_ASSERT( _NPPfuncs.urlnotify, "### NPP_URLNotify(): null pointer in NPP functions table!" );
373 m_eCall = eNPP_URLNotify;
374 m_aArgs[0] = (void*)instance;
375 m_aArgs[1] = (void*)url;
376 m_aArgs[2] = (void*)reason;
377 m_aArgs[3] = notifyData;
378 execute();
381 //--------------------------------------------------------------------------------------------------
382 int32 PluginComm_Impl::NPP_Write( NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer )
384 DBG_ASSERT( _NPPfuncs.write, "### NPP_Write(): null pointer in NPP functions table!" );
385 m_eCall = eNPP_Write;
386 m_aArgs[0] = (void*)instance;
387 m_aArgs[1] = (void*)stream;
388 m_aArgs[2] = (void*)offset;
389 m_aArgs[3] = (void*)len;
390 m_aArgs[4] = buffer;
391 return (NPError)execute();
394 //--------------------------------------------------------------------------------------------------
395 int32 PluginComm_Impl::NPP_WriteReady( NPP instance, NPStream* stream )
397 DBG_ASSERT( _NPPfuncs.writeready, "### NPP_WriteReady(): null pointer in NPP functions table!" );
398 m_eCall = eNPP_WriteReady;
399 m_aArgs[0] = (void*)instance;
400 m_aArgs[1] = (void*)stream;
401 return execute();
404 //--------------------------------------------------------------------------------------------------
405 NPError PluginComm_Impl::NPP_GetValue( NPP instance, NPPVariable variable, void *ret_value )
407 DBG_ASSERT( _NPPfuncs.getvalue, "### NPP_GetValue(): null pointer in NPP functions table!" );
408 m_eCall = eNPP_GetValue;
409 m_aArgs[0] = (void*)instance;
410 m_aArgs[1] = (void*)variable;
411 m_aArgs[2] = ret_value;
412 return (NPError)execute();
415 //--------------------------------------------------------------------------------------------------
416 NPError PluginComm_Impl::NPP_SetValue( NPP instance, NPNVariable variable, void *set_value )
418 DBG_ASSERT( _NPPfuncs.setvalue, "### NPP_SetValue(): null pointer in NPP functions table!" );
419 m_eCall = eNPP_SetValue;
420 m_aArgs[0] = (void*)instance;
421 m_aArgs[1] = (void*)variable;
422 m_aArgs[2] = set_value;
423 return (NPError)execute();
426 //--------------------------------------------------------------------------------------------------
427 void * PluginComm_Impl::NPP_GetJavaClass()
429 DBG_ERROR( "no java class available!" );
430 return 0;
433 //--------------------------------------------------------------------------------------------------
434 NPError PluginComm_Impl::NPP_Initialize()
436 return NPERR_NO_ERROR;
439 //--------------------------------------------------------------------------------------------------
440 void PluginComm_Impl::NPP_Shutdown()
442 m_eCall = eNPP_Shutdown;
443 execute();
446 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */