1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sysplug.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <sys/types.h>
35 #include <osl/thread.h>
37 #include <plugin/impl.hxx>
39 extern NPNetscapeFuncs aNPNFuncs
;
41 #include <tools/debug.hxx>
44 using namespace plugstringhelper
;
46 #if OSL_DEBUG_LEVEL > 1
47 void TRACE( char const * s
);
48 void TRACEN( char const * s
, long n
);
54 struct FakeEventRecord
: public EventRecord
58 memset( this, 0, sizeof(EventRecord
) );
59 ::GetGlobalMouse( &where
);
61 modifiers
= ::GetCurrentEventKeyModifiers();
66 @interface OOoPluginView
: NSView
68 XPlugin_Impl
* m_pImpl
;
69 MacPluginComm
* m_pCom
;
71 -(id
)initWithInstance
: (XPlugin_Impl
*)i_pImpl pluginComm
: (MacPluginComm
*)i_pCom frame
: (NSRect
)i_aRect
;
72 -(void)drawRect
: (NSRect
)i_aRect
;
74 -(MacOSBOOL
)isFlipped
;
77 -(void)mouseMoved
: (NSEvent
*)i_pEvent
;
78 -(void)mouseDown
: (NSEvent
*)i_pEvent
;
79 -(void)mouseDragged
: (NSEvent
*)i_pEvent
;
80 -(void)mouseUp
: (NSEvent
*)i_pEvent
;
81 -(void)rightMouseDown
: (NSEvent
*)i_pEvent
;
82 -(void)rightMouseDragged
: (NSEvent
*)i_pEvent
;
83 -(void)rightMouseUp
: (NSEvent
*)i_pEvent
;
84 -(void)otherMouseDown
: (NSEvent
*)i_pEvent
;
85 -(void)otherMouseDragged
: (NSEvent
*)i_pEvent
;
86 -(void)otherMouseUp
: (NSEvent
*)i_pEvent
;
87 -(void)mouseEntered
: (NSEvent
*)i_pEvent
;
88 -(void)mouseExited
: (NSEvent
*)i_pEvent
;
91 @implementation OOoPluginView
92 -(id
)initWithInstance
: (XPlugin_Impl
*)i_pImpl pluginComm
: (MacPluginComm
*)i_pCom frame
: (NSRect
) i_aRect
94 if( (self
= [super initWithFrame
: i_aRect
]) )
102 -(void)drawRect
: (NSRect
) i_aRect
104 m_pCom
->drawView( m_pImpl
);
112 -(MacOSBOOL
)isFlipped
118 -(void)mouseMoved
: (NSEvent
*)i_pEvent
120 FakeEventRecord aRec
;
121 aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
122 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
125 -(void)mouseDown
: (NSEvent
*)i_pEvent
;
127 FakeEventRecord aRec
;
128 aRec
.what
= mouseDown
;
129 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
132 -(void)mouseDragged
: (NSEvent
*)i_pEvent
;
134 FakeEventRecord aRec
;
135 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
136 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
139 -(void)mouseUp
: (NSEvent
*)i_pEvent
;
141 FakeEventRecord aRec
;
143 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
146 -(void)rightMouseDown
: (NSEvent
*)i_pEvent
;
148 FakeEventRecord aRec
;
149 aRec
.what
= mouseDown
;
150 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
153 -(void)rightMouseDragged
: (NSEvent
*)i_pEvent
;
155 FakeEventRecord aRec
;
156 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
157 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
160 -(void)rightMouseUp
: (NSEvent
*)i_pEvent
;
162 FakeEventRecord aRec
;
164 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
167 -(void)otherMouseDown
: (NSEvent
*)i_pEvent
;
169 FakeEventRecord aRec
;
170 aRec
.what
= mouseDown
;
171 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
174 -(void)otherMouseDragged
: (NSEvent
*)i_pEvent
;
176 FakeEventRecord aRec
;
177 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
178 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
181 -(void)otherMouseUp
: (NSEvent
*)i_pEvent
;
183 FakeEventRecord aRec
;
185 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
188 -(void)mouseEntered
: (NSEvent
*)i_pEvent
;
190 FakeEventRecord aRec
;
191 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
192 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
195 -(void)mouseExited
: (NSEvent
*)i_pEvent
;
197 FakeEventRecord aRec
;
198 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
199 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
204 //--------------------------------------------------------------------------------------------------
205 MacPluginComm::MacPluginComm( const rtl::OUString
& i_rMimetype
, const rtl::OUString
& i_rBundle
, NSView
* i_pParent
)
206 : PluginComm( OUStringToOString( i_rBundle
, RTL_TEXTENCODING_UTF8
) ),
211 // initialize plugin function table
212 memset( &m_aNPPfuncs
, 0, sizeof( m_aNPPfuncs
) );
215 CFURLRef xURL
= createURL( i_rBundle
);
216 m_xBundle
= CFBundleCreate( NULL
, xURL
);
220 // ask the plugin library
221 // first get its location
222 CFURLRef xLibURL
= CFBundleCopyExecutableURL( m_xBundle
);
225 // get the file system path
226 rtl::OUString
aModuleURL( CFURLtoOSLURL( xLibURL
) );
227 CFRelease( xLibURL
);
228 m_hPlugLib
= osl_loadModule( aModuleURL
.pData
, SAL_LOADMODULE_DEFAULT
);
229 #if OSL_DEBUG_LEVEL > 1
231 fprintf( stderr
, "module %s could not be loaded\n", OUStringToOString( aModuleURL
, RTL_TEXTENCODING_UTF8
).getStr() );
234 #if OSL_DEBUG_LEVEL > 1
236 fprintf( stderr
, "bundle %s has no exectutable URL\n", OUStringToOString( i_rBundle
, RTL_TEXTENCODING_UTF8
).getStr() );
241 #if OSL_DEBUG_LEVEL > 1
242 fprintf( stderr
, "bundle %s could not be loaded\n", OUStringToOString( i_rBundle
, RTL_TEXTENCODING_UTF8
).getStr() );
246 DBG_ASSERT( m_xBundle
&& m_hPlugLib
, "loading plugin bundle failed!" );
249 m_aNPPfuncs
.size
= sizeof( m_aNPPfuncs
);
250 m_aNPPfuncs
.version
= 0;
253 m_eCall
= eNP_Initialize
;
257 //--------------------------------------------------------------------------------------------------
258 MacPluginComm::~MacPluginComm()
263 NPError (*pShutdown
)();
264 if( retrieveFunction( "NP_Shutdown", (void**)&pShutdown
) )
266 NPError nErr
= (*pShutdown
)(); (void)nErr
;
267 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "NP_Shutdown() failed!" );
269 osl_unloadModule( m_hPlugLib
);
272 CFRelease( m_xBundle
);
275 //--------------------------------------------------------------------------------------------------
276 BOOL
MacPluginComm::retrieveFunction( const char* i_pName
, void** o_ppFunc
) const
278 if( ! m_hPlugLib
|| ! o_ppFunc
)
281 *o_ppFunc
= (void*)osl_getAsciiFunctionSymbol( m_hPlugLib
, i_pName
);
283 if( ! *o_ppFunc
&& m_xBundle
)
285 rtl::OUString
aName( OUString::createFromAscii( *i_pName
== '_' ? i_pName
+1 : i_pName
) );
286 CFStringRef xName
= createString( aName
);
289 *o_ppFunc
= CFBundleGetFunctionPointerForName( m_xBundle
, xName
);
294 return (*o_ppFunc
!= NULL
);
297 IMPL_LINK( MacPluginComm
, NullTimerHdl
, void*, EMPTYARG
)
299 // note: this is a Timer handler, we are already protected by the SolarMutex
301 FakeEventRecord aRec
;
302 aRec
.what
= nullEvent
;
303 aRec
.where
.h
= aRec
.where
.v
= 20000;
305 for( std::list
< XPlugin_Impl
* >::iterator it
= m_aNullEventClients
.begin();
306 it
!= m_aNullEventClients
.end(); ++it
)
308 SysPlugData
& rPlugData( (*it
)->getSysPlugData() );
309 if( rPlugData
.m_pPlugView
) // for safety do not dispatch null events before first NPP_SetWindow
310 (*m_aNPPfuncs
.event
)( (*it
)->getNPPInstance(), &aRec
);
316 //--------------------------------------------------------------------------------------------------
318 long MacPluginComm::doIt()
325 TRACE( "eNP_Initialize" );
326 NPError (*pInit
)( NPNetscapeFuncs
* );
327 if( retrieveFunction( "NP_Initialize", (void**)&pInit
) )
329 nRet
= (*pInit
)( &aNPNFuncs
);
331 NPError nErr
= NPERR_NO_ERROR
;
332 NPError (*pEntry
)( NPPluginFuncs
* );
333 retrieveFunction( "NP_GetEntryPoints", (void**)&pEntry
);
334 nErr
= (*pEntry
)( &m_aNPPfuncs
);
336 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "NP_GetEntryPoints() failed!" );
340 nRet
= NPERR_GENERIC_ERROR
;
342 DBG_ASSERT( nRet
== NPERR_NO_ERROR
, "### NP_Initialize() failed!" );
346 if( m_aNullEventClients
.empty() )
347 delete m_pNullTimer
, m_pNullTimer
= NULL
;
349 TRACE( "eNPP_Destroy" );
350 nRet
= (m_aNPPfuncs
.destroy
351 ? (*m_aNPPfuncs
.destroy
)(
353 (NPSavedData
**)m_aArgs
[1] )
354 : NPERR_GENERIC_ERROR
);
356 case eNPP_DestroyStream
:
357 TRACE( "eNPP_DestroyStream" );
358 nRet
= (m_aNPPfuncs
.destroystream
359 ? (*m_aNPPfuncs
.destroystream
)(
361 (NPStream
*)m_aArgs
[1],
362 (NPError
)(sal_IntPtr
)m_aArgs
[2] )
363 : NPERR_GENERIC_ERROR
);
367 nRet
= (m_aNPPfuncs
.newp
368 ? (*m_aNPPfuncs
.newp
)(
369 (NPMIMEType
)m_aArgs
[0],
371 (uint16
)(sal_IntPtr
)m_aArgs
[2],
372 (int16
)(sal_IntPtr
)m_aArgs
[3],
375 (NPSavedData
*)m_aArgs
[6] )
376 : NPERR_GENERIC_ERROR
);
378 if( ! m_pNullTimer
&& m_aNPPfuncs
.event
)
380 m_pNullTimer
= new AutoTimer();
381 m_pNullTimer
->SetTimeout( 50 );
382 m_pNullTimer
->SetTimeoutHdl( LINK( this, MacPluginComm
, NullTimerHdl
) );
383 m_pNullTimer
->Start();
388 TRACE( "eNPP_NewStream" );
389 nRet
= (m_aNPPfuncs
.newstream
390 ? (*m_aNPPfuncs
.newstream
)(
392 (NPMIMEType
)m_aArgs
[1],
393 (NPStream
*)m_aArgs
[2],
394 (NPBool
)(sal_IntPtr
)m_aArgs
[3],
395 (uint16
*)m_aArgs
[4] )
396 : NPERR_GENERIC_ERROR
);
399 TRACE( "eNPP_Print" );
400 if (m_aNPPfuncs
.print
)
401 (*m_aNPPfuncs
.print
)(
403 (NPPrint
*)m_aArgs
[1] );
407 TRACE( "eNPP_SetWindow" );
408 nRet
= (m_aNPPfuncs
.setwindow
409 ? (*m_aNPPfuncs
.setwindow
)(
411 (NPWindow
*)m_aArgs
[1] )
412 : NPERR_GENERIC_ERROR
);
416 case eNPP_HandleEvent
:
418 TRACE( "eNPP_HandleEvent" );
419 nRet
= (m_aNPPfuncs
.event
420 ? (*m_aNPPfuncs
.event
)(
423 : NPERR_GENERIC_ERROR
);
427 case eNPP_StreamAsFile
:
428 TRACE( "eNPP_StreamAsFile" );
429 if (m_aNPPfuncs
.asfile
)
430 (*m_aNPPfuncs
.asfile
)(
432 (NPStream
*)m_aArgs
[1],
436 TRACE( "eNPP_URLNotify" );
437 if (m_aNPPfuncs
.urlnotify
)
438 (*m_aNPPfuncs
.urlnotify
)(
441 (NPReason
)(sal_IntPtr
)m_aArgs
[2],
445 TRACEN( "eNPP_Write n=", (int32
)m_aArgs
[3] );
446 nRet
= (m_aNPPfuncs
.write
447 ? (*m_aNPPfuncs
.write
)(
449 (NPStream
*)m_aArgs
[1],
455 case eNPP_WriteReady
:
456 TRACE( "eNPP_WriteReady" );
457 nRet
= (m_aNPPfuncs
.writeready
458 ? (*m_aNPPfuncs
.writeready
)(
460 (NPStream
*)m_aArgs
[1] )
464 TRACE( "eNPP_GetValue" );
465 nRet
= (m_aNPPfuncs
.getvalue
466 ? (*m_aNPPfuncs
.getvalue
)(
468 (NPPVariable
)(int)m_aArgs
[1],
470 : NPERR_GENERIC_ERROR
);
473 TRACE( "eNPP_SetValue" );
474 nRet
= (m_aNPPfuncs
.setvalue
475 ? (*m_aNPPfuncs
.setvalue
)(
477 (NPNVariable
)(int)m_aArgs
[1],
479 : NPERR_GENERIC_ERROR
);
483 TRACE( "eNPP_Shutdown" );
484 NPP_ShutdownUPP pFunc
;
485 if (retrieveFunction( "NPP_Shutdown", (void**)&pFunc
))
489 case eNPP_Initialize
:
490 TRACE( "eNPP_Initialize" );
491 OSL_ENSURE( false, "NPP_Initialize: not implemented!" );
493 case eNPP_GetJavaClass
:
494 TRACE( "eNPP_GetJavaClass" );
495 OSL_ENSURE( false, "NPP_GetJavaClass: not implemented!" );
501 //--------------------------------------------------------------------------------------------------
502 NPError
MacPluginComm::NPP_Destroy( XPlugin_Impl
* i_pImpl
, NPSavedData
** save
)
504 // remove from NullEvent timer
505 m_aNullEventClients
.remove( i_pImpl
);
507 NPError nErr
= NPP_Destroy( i_pImpl
->getNPPInstance(), save
);
509 // release plugin view
510 SysPlugData
& rPlugData( i_pImpl
->getSysPlugData() );
511 if( rPlugData
.m_pPlugView
)
513 [rPlugData
.m_pPlugView removeFromSuperview
];
514 [rPlugData
.m_pPlugView release
];
515 rPlugData
.m_pPlugView
= nil
;
522 NPError
MacPluginComm::NPP_Destroy( NPP instance
, NPSavedData
** save
)
524 DBG_ASSERT( m_aNPPfuncs
.destroy
, "### NPP_Destroy(): null pointer in NPP functions table!" );
525 m_eCall
= eNPP_Destroy
;
526 m_aArgs
[0] = (void*)instance
;
527 m_aArgs
[1] = (void*)save
;
528 return (NPError
)execute();
531 //--------------------------------------------------------------------------------------------------
532 NPError
MacPluginComm::NPP_DestroyStream( NPP instance
, NPStream
* stream
, NPError reason
)
534 DBG_ASSERT( m_aNPPfuncs
.destroystream
, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
535 m_eCall
= eNPP_DestroyStream
;
536 m_aArgs
[0] = (void*)instance
;
537 m_aArgs
[1] = (void*)stream
;
538 m_aArgs
[2] = (void*)reason
;
539 return (NPError
)execute();
542 //--------------------------------------------------------------------------------------------------
543 NPError
MacPluginComm::NPP_New( NPMIMEType pluginType
, NPP instance
, uint16 mode
, int16 argc
,
544 char* argn
[], char* argv
[], NPSavedData
*saved
)
546 XPlugin_Impl
* pImpl
= XPluginManager_Impl::getXPluginFromNPP( instance
);
547 DBG_ASSERT( pImpl
, "no instance found" );
549 if( pImpl
) // sanity check
550 m_aNullEventClients
.push_back( pImpl
);
552 DBG_ASSERT( m_aNPPfuncs
.newp
, "### NPP_New(): null pointer in NPP functions table!" );
553 #if OSL_DEBUG_LEVEL > 1
554 fprintf( stderr
, "NPP_New( %s. %p, %d, %d",
555 pluginType
, instance
, (int)mode
, (int)argc
);
556 for( int16 i
= 0; i
< argc
; i
++ )
557 fprintf( stderr
, "\n%s = %s", argn
[i
], argv
[i
] );
558 fprintf( stderr
, ", %p )\n", saved
);
561 m_aArgs
[0] = (void*)pluginType
;
562 m_aArgs
[1] = (void*)instance
;
563 m_aArgs
[2] = (void*)mode
;
564 m_aArgs
[3] = (void*)argc
;
565 m_aArgs
[4] = (void*)argn
;
566 m_aArgs
[5] = (void*)argv
;
567 m_aArgs
[6] = (void*)saved
;
569 return (NPError
)execute();
572 //--------------------------------------------------------------------------------------------------
573 NPError
MacPluginComm::NPP_NewStream( NPP instance
, NPMIMEType type
, NPStream
* stream
,
574 NPBool seekable
, uint16
* stype
)
576 DBG_ASSERT( m_aNPPfuncs
.newstream
, "### NPP_NewStream(): null pointer in NPP functions table!" );
577 m_eCall
= eNPP_NewStream
;
578 m_aArgs
[0] = (void*)instance
;
579 m_aArgs
[1] = (void*)type
;
580 m_aArgs
[2] = (void*)stream
;
581 m_aArgs
[3] = (void*)seekable
;
582 m_aArgs
[4] = (void*)stype
;
583 return (NPError
)execute();
586 //--------------------------------------------------------------------------------------------------
587 void MacPluginComm::NPP_Print( NPP instance
, NPPrint
* platformPrint
)
589 DBG_ASSERT( m_aNPPfuncs
.print
, "### NPP_Print(): null pointer in NPP functions table!" );
590 m_eCall
= eNPP_Print
;
591 m_aArgs
[0] = (void*)instance
;
592 m_aArgs
[1] = (void*)platformPrint
;
596 //--------------------------------------------------------------------------------------------------
597 NPError
MacPluginComm::NPP_SetWindow( NPP instance
, NPWindow
* window
)
599 DBG_ASSERT( m_aNPPfuncs
.setwindow
, "### NPP_SetWindow(): null pointer in NPP functions table!" );
600 m_eCall
= eNPP_SetWindow
;
601 m_aArgs
[0] = (void*)instance
;
602 m_aArgs
[1] = (void*)window
;
603 return (NPError
)execute();
606 //--------------------------------------------------------------------------------------------------
607 NPError
MacPluginComm::NPP_HandleEvent( NPP instance
, void* event
)
609 DBG_ASSERT( m_aNPPfuncs
.event
, "### NPP_HandleEvent(): null pointer in NPP functions table!" );
610 m_eCall
= eNPP_HandleEvent
;
611 m_aArgs
[0] = (void*)instance
;
613 return (NPError
)execute();
616 //--------------------------------------------------------------------------------------------------
617 void MacPluginComm::NPP_StreamAsFile( NPP instance
, NPStream
* stream
, const char* fname
)
619 DBG_ASSERT( m_aNPPfuncs
.asfile
, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
620 m_eCall
= eNPP_StreamAsFile
;
621 m_aArgs
[0] = (void*)instance
;
622 m_aArgs
[1] = (void*)stream
;
623 m_aArgs
[2] = (void*)fname
;
627 //--------------------------------------------------------------------------------------------------
628 void MacPluginComm::NPP_URLNotify( NPP instance
, const char* url
, NPReason reason
, void* notifyData
)
630 DBG_ASSERT( m_aNPPfuncs
.urlnotify
, "### NPP_URLNotify(): null pointer in NPP functions table!" );
631 m_eCall
= eNPP_URLNotify
;
632 m_aArgs
[0] = (void*)instance
;
633 m_aArgs
[1] = (void*)url
;
634 m_aArgs
[2] = (void*)reason
;
635 m_aArgs
[3] = notifyData
;
639 //--------------------------------------------------------------------------------------------------
640 int32
MacPluginComm::NPP_Write( NPP instance
, NPStream
* stream
, int32 offset
, int32 len
, void* buffer
)
642 DBG_ASSERT( m_aNPPfuncs
.write
, "### NPP_Write(): null pointer in NPP functions table!" );
643 m_eCall
= eNPP_Write
;
644 m_aArgs
[0] = (void*)instance
;
645 m_aArgs
[1] = (void*)stream
;
646 m_aArgs
[2] = (void*)offset
;
647 m_aArgs
[3] = (void*)len
;
649 return (NPError
)execute();
652 //--------------------------------------------------------------------------------------------------
653 int32
MacPluginComm::NPP_WriteReady( NPP instance
, NPStream
* stream
)
655 DBG_ASSERT( m_aNPPfuncs
.writeready
, "### NPP_WriteReady(): null pointer in NPP functions table!" );
656 m_eCall
= eNPP_WriteReady
;
657 m_aArgs
[0] = (void*)instance
;
658 m_aArgs
[1] = (void*)stream
;
662 //--------------------------------------------------------------------------------------------------
663 NPError
MacPluginComm::NPP_GetValue( NPP instance
, NPPVariable variable
, void *ret_value
)
665 DBG_ASSERT( m_aNPPfuncs
.getvalue
, "### NPP_GetValue(): null pointer in NPP functions table!" );
666 m_eCall
= eNPP_GetValue
;
667 m_aArgs
[0] = (void*)instance
;
668 m_aArgs
[1] = (void*)variable
;
669 m_aArgs
[2] = ret_value
;
670 return (NPError
)execute();
673 //--------------------------------------------------------------------------------------------------
674 NPError
MacPluginComm::NPP_SetValue( NPP instance
, NPNVariable variable
, void *set_value
)
676 DBG_ASSERT( m_aNPPfuncs
.setvalue
, "### NPP_SetValue(): null pointer in NPP functions table!" );
677 m_eCall
= eNPP_SetValue
;
678 m_aArgs
[0] = (void*)instance
;
679 m_aArgs
[1] = (void*)variable
;
680 m_aArgs
[2] = set_value
;
681 return (NPError
)execute();
684 //--------------------------------------------------------------------------------------------------
685 void * MacPluginComm::NPP_GetJavaClass()
687 DBG_ERROR( "no java class available!" );
691 //--------------------------------------------------------------------------------------------------
692 NPError
MacPluginComm::NPP_Initialize()
694 return NPERR_NO_ERROR
;
697 //--------------------------------------------------------------------------------------------------
698 void MacPluginComm::NPP_Shutdown()
700 m_eCall
= eNPP_Shutdown
;
704 //--------------------------------------------------------------------------------------------------
705 NPError
MacPluginComm::NPP_SetWindow( XPlugin_Impl
* i_pImpl
)
707 // update window NPWindow from view
708 SysPlugData
& rPlugData( i_pImpl
->getSysPlugData() );
711 NSRect aPlugRect
= [rPlugData
.m_pParentView frame
];
712 aPlugRect
.origin
.x
= aPlugRect
.origin
.y
= 0;
713 if( ! rPlugData
.m_pPlugView
)
715 rPlugData
.m_pPlugView
= [[OOoPluginView alloc
] initWithInstance
: i_pImpl pluginComm
: this frame
: aPlugRect
];
716 [rPlugData
.m_pParentView addSubview
: rPlugData
.m_pPlugView
];
719 [rPlugData
.m_pPlugView setFrame
: aPlugRect
];
721 NPWindow
* pNPWin
= i_pImpl
->getNPWindow();
722 NSWindow
* pWin
= [rPlugData
.m_pPlugView window
];
723 NSRect aWinRect
= [pWin frame
];
724 NSRect aBounds
= [rPlugData
.m_pPlugView frame
];
725 NSRect aVisibleBounds
= [rPlugData
.m_pPlugView visibleRect
];
727 #if OSL_DEBUG_LEVEL > 1
728 fprintf( stderr
, "visible bounds = %d+%d+%dx%d\n",
729 (int)aVisibleBounds
.origin
.x
, (int)aVisibleBounds
.origin
.y
,
730 (int)aVisibleBounds
.size
.width
, (int)aVisibleBounds
.size
.height
);
733 NSPoint aViewOrigin
= [rPlugData
.m_pPlugView convertPoint
: NSZeroPoint toView
: nil
];
734 // save view origin so we can notice movement of the view in drawView
735 // in case of a moved view we need to reset the port/context
736 rPlugData
.m_aLastPlugViewOrigin
= aViewOrigin
;
738 // convert view origin to topdown coordinates
739 aViewOrigin
.y
= aWinRect
.size
.height
- aViewOrigin
.y
;
742 NSPoint aClipOrigin
= [rPlugData
.m_pPlugView convertPoint
: aVisibleBounds
.origin toView
: nil
];
743 aClipOrigin
.y
= aWinRect
.size
.height
- aClipOrigin
.y
;
745 #if OSL_DEBUG_LEVEL > 1
746 fprintf( stderr
, "view origin: %d+%d, clip origin = %d+%d\n",
747 (int)aViewOrigin
.x
, (int)aViewOrigin
.y
,
748 (int)aClipOrigin
.x
, (int)aClipOrigin
.y
);
751 pNPWin
->x
= aViewOrigin
.x
;
752 pNPWin
->y
= aViewOrigin
.y
;
753 pNPWin
->width
= aBounds
.size
.width
;
754 pNPWin
->height
= aBounds
.size
.height
;
755 pNPWin
->clipRect
.left
= aClipOrigin
.x
;
756 pNPWin
->clipRect
.top
= aClipOrigin
.y
;
757 pNPWin
->clipRect
.right
= aClipOrigin
.x
+ aVisibleBounds
.size
.width
;
758 pNPWin
->clipRect
.bottom
= aClipOrigin
.y
+ aVisibleBounds
.size
.height
;
760 if( rPlugData
.m_nDrawingModel
== 1 )
762 rPlugData
.m_aCGContext
.window
= reinterpret_cast<WindowRef
>([pWin windowRef
]);
763 pNPWin
->window
= &rPlugData
.m_aCGContext
;
764 rPlugData
.m_aCGContext
.context
= reinterpret_cast<CGContextRef
>([[pWin graphicsContext
] graphicsPort
]);
765 #if OSL_DEBUG_LEVEL > 1
766 fprintf( stderr
, "window is %p, context is %p\n",
767 rPlugData
.m_aCGContext
.window
, rPlugData
.m_aCGContext
.context
);
772 rPlugData
.m_aNPPort
.port
= GetWindowPort( reinterpret_cast<WindowRef
>([pWin windowRef
]) );
773 rPlugData
.m_aNPPort
.portx
= aClipOrigin
.x
;
774 rPlugData
.m_aNPPort
.porty
= aClipOrigin
.y
;
775 pNPWin
->window
= &rPlugData
.m_aNPPort
;
776 #if OSL_DEBUG_LEVEL > 1
777 fprintf( stderr
, "port is %p at (%d,%d)\n",
778 rPlugData
.m_aNPPort
.port
, (int)rPlugData
.m_aNPPort
.portx
, (int)rPlugData
.m_aNPPort
.porty
);
782 if( pNPWin
->width
== 0 || pNPWin
->height
== 0 || [rPlugData
.m_pPlugView isHiddenOrHasHiddenAncestor
] )
783 rPlugData
.m_bSetWindowOnDraw
= true;
785 NPError nErr
= NPP_SetWindow( i_pImpl
->getNPPInstance(), i_pImpl
->getNPWindow() );
790 void MacPluginComm::drawView( XPlugin_Impl
* i_pImpl
)
792 SysPlugData
& rPlugData( i_pImpl
->getSysPlugData() );
794 // check if the view was moved since the last SetWindow
795 NSPoint aViewOrigin
= [rPlugData
.m_pPlugView convertPoint
: NSZeroPoint toView
: nil
];
796 if( rPlugData
.m_bSetWindowOnDraw
||
797 aViewOrigin
.x
!= rPlugData
.m_aLastPlugViewOrigin
.x
||
798 aViewOrigin
.y
!= rPlugData
.m_aLastPlugViewOrigin
.y
)
800 NPP_SetWindow( i_pImpl
);
801 rPlugData
.m_bSetWindowOnDraw
= false;
804 // send a paint event
805 NSWindow
* pWin
= [rPlugData
.m_pPlugView window
];
806 FakeEventRecord aRec
;
807 aRec
.what
= updateEvt
;
808 aRec
.message
= (UInt32
)[pWin windowRef
];
809 this->NPP_HandleEvent( i_pImpl
->getNPPInstance(), &aRec
);