1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org 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 Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include <sys/types.h>
32 #include <osl/thread.h>
34 #include <plugin/impl.hxx>
36 extern NPNetscapeFuncs aNPNFuncs
;
38 #include <tools/debug.hxx>
41 using namespace plugstringhelper
;
43 #if OSL_DEBUG_LEVEL > 1
44 void TRACE( char const * s
);
45 void TRACEN( char const * s
, long n
);
51 struct FakeEventRecord
: public EventRecord
55 memset( this, 0, sizeof(EventRecord
) );
56 ::GetGlobalMouse( &where
);
58 modifiers
= ::GetCurrentEventKeyModifiers();
63 @interface OOoPluginView
: NSView
65 XPlugin_Impl
* m_pImpl
;
66 MacPluginComm
* m_pCom
;
68 -(id
)initWithInstance
: (XPlugin_Impl
*)i_pImpl pluginComm
: (MacPluginComm
*)i_pCom frame
: (NSRect
)i_aRect
;
69 -(void)drawRect
: (NSRect
)i_aRect
;
74 -(void)mouseMoved
: (NSEvent
*)i_pEvent
;
75 -(void)mouseDown
: (NSEvent
*)i_pEvent
;
76 -(void)mouseDragged
: (NSEvent
*)i_pEvent
;
77 -(void)mouseUp
: (NSEvent
*)i_pEvent
;
78 -(void)rightMouseDown
: (NSEvent
*)i_pEvent
;
79 -(void)rightMouseDragged
: (NSEvent
*)i_pEvent
;
80 -(void)rightMouseUp
: (NSEvent
*)i_pEvent
;
81 -(void)otherMouseDown
: (NSEvent
*)i_pEvent
;
82 -(void)otherMouseDragged
: (NSEvent
*)i_pEvent
;
83 -(void)otherMouseUp
: (NSEvent
*)i_pEvent
;
84 -(void)mouseEntered
: (NSEvent
*)i_pEvent
;
85 -(void)mouseExited
: (NSEvent
*)i_pEvent
;
88 @implementation OOoPluginView
89 -(id
)initWithInstance
: (XPlugin_Impl
*)i_pImpl pluginComm
: (MacPluginComm
*)i_pCom frame
: (NSRect
) i_aRect
91 if( (self
= [super initWithFrame
: i_aRect
]) )
99 -(void)drawRect
: (NSRect
) i_aRect
101 m_pCom
->drawView( m_pImpl
);
115 -(void)mouseMoved
: (NSEvent
*)i_pEvent
117 FakeEventRecord aRec
;
118 aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
119 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
122 -(void)mouseDown
: (NSEvent
*)i_pEvent
;
124 FakeEventRecord aRec
;
125 aRec
.what
= mouseDown
;
126 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
129 -(void)mouseDragged
: (NSEvent
*)i_pEvent
;
131 FakeEventRecord aRec
;
132 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
133 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
136 -(void)mouseUp
: (NSEvent
*)i_pEvent
;
138 FakeEventRecord aRec
;
140 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
143 -(void)rightMouseDown
: (NSEvent
*)i_pEvent
;
145 FakeEventRecord aRec
;
146 aRec
.what
= mouseDown
;
147 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
150 -(void)rightMouseDragged
: (NSEvent
*)i_pEvent
;
152 FakeEventRecord aRec
;
153 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
154 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
157 -(void)rightMouseUp
: (NSEvent
*)i_pEvent
;
159 FakeEventRecord aRec
;
161 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
164 -(void)otherMouseDown
: (NSEvent
*)i_pEvent
;
166 FakeEventRecord aRec
;
167 aRec
.what
= mouseDown
;
168 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
171 -(void)otherMouseDragged
: (NSEvent
*)i_pEvent
;
173 FakeEventRecord aRec
;
174 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
175 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
178 -(void)otherMouseUp
: (NSEvent
*)i_pEvent
;
180 FakeEventRecord aRec
;
182 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
185 -(void)mouseEntered
: (NSEvent
*)i_pEvent
;
187 FakeEventRecord aRec
;
188 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
189 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
192 -(void)mouseExited
: (NSEvent
*)i_pEvent
;
194 FakeEventRecord aRec
;
195 aRec
.what
= aRec
.what
= osEvt
+ 18; // NPEventType_AdjustCursorEvent
196 m_pCom
->NPP_HandleEvent( m_pImpl
->getNPPInstance(), &aRec
);
201 //--------------------------------------------------------------------------------------------------
202 MacPluginComm::MacPluginComm( const rtl::OUString
& i_rMimetype
, const rtl::OUString
& i_rBundle
, NSView
* i_pParent
)
203 : PluginComm( OUStringToOString( i_rBundle
, RTL_TEXTENCODING_UTF8
) ),
208 // initialize plugin function table
209 memset( &m_aNPPfuncs
, 0, sizeof( m_aNPPfuncs
) );
212 CFURLRef xURL
= createURL( i_rBundle
);
213 m_xBundle
= CFBundleCreate( NULL
, xURL
);
217 // ask the plugin library
218 // first get its location
219 CFURLRef xLibURL
= CFBundleCopyExecutableURL( m_xBundle
);
222 // get the file system path
223 rtl::OUString
aModuleURL( CFURLtoOSLURL( xLibURL
) );
224 CFRelease( xLibURL
);
225 m_hPlugLib
= osl_loadModule( aModuleURL
.pData
, SAL_LOADMODULE_DEFAULT
);
226 #if OSL_DEBUG_LEVEL > 1
228 fprintf( stderr
, "module %s could not be loaded\n", OUStringToOString( aModuleURL
, RTL_TEXTENCODING_UTF8
).getStr() );
231 #if OSL_DEBUG_LEVEL > 1
233 fprintf( stderr
, "bundle %s has no exectutable URL\n", OUStringToOString( i_rBundle
, RTL_TEXTENCODING_UTF8
).getStr() );
238 #if OSL_DEBUG_LEVEL > 1
239 fprintf( stderr
, "bundle %s could not be loaded\n", OUStringToOString( i_rBundle
, RTL_TEXTENCODING_UTF8
).getStr() );
243 DBG_ASSERT( m_xBundle
&& m_hPlugLib
, "loading plugin bundle failed!" );
246 m_aNPPfuncs
.size
= sizeof( m_aNPPfuncs
);
247 m_aNPPfuncs
.version
= 0;
250 m_eCall
= eNP_Initialize
;
254 //--------------------------------------------------------------------------------------------------
255 MacPluginComm::~MacPluginComm()
260 NPError (*pShutdown
)();
261 if( retrieveFunction( "NP_Shutdown", (void**)&pShutdown
) )
263 NPError nErr
= (*pShutdown
)(); (void)nErr
;
264 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "NP_Shutdown() failed!" );
266 osl_unloadModule( m_hPlugLib
);
269 CFRelease( m_xBundle
);
272 //--------------------------------------------------------------------------------------------------
273 sal_Bool
MacPluginComm::retrieveFunction( const char* i_pName
, void** o_ppFunc
) const
275 if( ! m_hPlugLib
|| ! o_ppFunc
)
278 *o_ppFunc
= (void*)osl_getAsciiFunctionSymbol( m_hPlugLib
, i_pName
);
280 if( ! *o_ppFunc
&& m_xBundle
)
282 rtl::OUString
aName( OUString::createFromAscii( *i_pName
== '_' ? i_pName
+1 : i_pName
) );
283 CFStringRef xName
= createString( aName
);
286 *o_ppFunc
= CFBundleGetFunctionPointerForName( m_xBundle
, xName
);
291 return (*o_ppFunc
!= NULL
);
294 IMPL_LINK( MacPluginComm
, NullTimerHdl
, void*, EMPTYARG
)
296 // note: this is a Timer handler, we are already protected by the SolarMutex
298 FakeEventRecord aRec
;
299 aRec
.what
= nullEvent
;
300 aRec
.where
.h
= aRec
.where
.v
= 20000;
302 for( std::list
< XPlugin_Impl
* >::iterator it
= m_aNullEventClients
.begin();
303 it
!= m_aNullEventClients
.end(); ++it
)
305 SysPlugData
& rPlugData( (*it
)->getSysPlugData() );
306 if( rPlugData
.m_pPlugView
) // for safety do not dispatch null events before first NPP_SetWindow
307 (*m_aNPPfuncs
.event
)( (*it
)->getNPPInstance(), &aRec
);
313 //--------------------------------------------------------------------------------------------------
315 long MacPluginComm::doIt()
322 TRACE( "eNP_Initialize" );
323 NPError (*pInit
)( NPNetscapeFuncs
* );
324 if( retrieveFunction( "NP_Initialize", (void**)&pInit
) )
326 nRet
= (*pInit
)( &aNPNFuncs
);
328 NPError nErr
= NPERR_NO_ERROR
;
329 NPError (*pEntry
)( NPPluginFuncs
* );
330 retrieveFunction( "NP_GetEntryPoints", (void**)&pEntry
);
331 nErr
= (*pEntry
)( &m_aNPPfuncs
);
333 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "NP_GetEntryPoints() failed!" );
337 nRet
= NPERR_GENERIC_ERROR
;
339 DBG_ASSERT( nRet
== NPERR_NO_ERROR
, "### NP_Initialize() failed!" );
343 if( m_aNullEventClients
.empty() )
344 delete m_pNullTimer
, m_pNullTimer
= NULL
;
346 TRACE( "eNPP_Destroy" );
347 nRet
= (m_aNPPfuncs
.destroy
348 ? (*m_aNPPfuncs
.destroy
)(
350 (NPSavedData
**)m_aArgs
[1] )
351 : NPERR_GENERIC_ERROR
);
353 case eNPP_DestroyStream
:
354 TRACE( "eNPP_DestroyStream" );
355 nRet
= (m_aNPPfuncs
.destroystream
356 ? (*m_aNPPfuncs
.destroystream
)(
358 (NPStream
*)m_aArgs
[1],
359 (NPError
)(sal_IntPtr
)m_aArgs
[2] )
360 : NPERR_GENERIC_ERROR
);
364 nRet
= (m_aNPPfuncs
.newp
365 ? (*m_aNPPfuncs
.newp
)(
366 (NPMIMEType
)m_aArgs
[0],
368 (uint16
)(sal_IntPtr
)m_aArgs
[2],
369 (int16
)(sal_IntPtr
)m_aArgs
[3],
372 (NPSavedData
*)m_aArgs
[6] )
373 : NPERR_GENERIC_ERROR
);
375 if( ! m_pNullTimer
&& m_aNPPfuncs
.event
)
377 m_pNullTimer
= new AutoTimer();
378 m_pNullTimer
->SetTimeout( 50 );
379 m_pNullTimer
->SetTimeoutHdl( LINK( this, MacPluginComm
, NullTimerHdl
) );
380 m_pNullTimer
->Start();
385 TRACE( "eNPP_NewStream" );
386 nRet
= (m_aNPPfuncs
.newstream
387 ? (*m_aNPPfuncs
.newstream
)(
389 (NPMIMEType
)m_aArgs
[1],
390 (NPStream
*)m_aArgs
[2],
391 (NPBool
)(sal_IntPtr
)m_aArgs
[3],
392 (uint16
*)m_aArgs
[4] )
393 : NPERR_GENERIC_ERROR
);
396 TRACE( "eNPP_Print" );
397 if (m_aNPPfuncs
.print
)
398 (*m_aNPPfuncs
.print
)(
400 (NPPrint
*)m_aArgs
[1] );
404 TRACE( "eNPP_SetWindow" );
405 nRet
= (m_aNPPfuncs
.setwindow
406 ? (*m_aNPPfuncs
.setwindow
)(
408 (NPWindow
*)m_aArgs
[1] )
409 : NPERR_GENERIC_ERROR
);
413 case eNPP_HandleEvent
:
415 TRACE( "eNPP_HandleEvent" );
416 nRet
= (m_aNPPfuncs
.event
417 ? (*m_aNPPfuncs
.event
)(
420 : NPERR_GENERIC_ERROR
);
424 case eNPP_StreamAsFile
:
425 TRACE( "eNPP_StreamAsFile" );
426 if (m_aNPPfuncs
.asfile
)
427 (*m_aNPPfuncs
.asfile
)(
429 (NPStream
*)m_aArgs
[1],
433 TRACE( "eNPP_URLNotify" );
434 if (m_aNPPfuncs
.urlnotify
)
435 (*m_aNPPfuncs
.urlnotify
)(
438 (NPReason
)(sal_IntPtr
)m_aArgs
[2],
442 TRACEN( "eNPP_Write n=", (int32
)m_aArgs
[3] );
443 nRet
= (m_aNPPfuncs
.write
444 ? (*m_aNPPfuncs
.write
)(
446 (NPStream
*)m_aArgs
[1],
452 case eNPP_WriteReady
:
453 TRACE( "eNPP_WriteReady" );
454 nRet
= (m_aNPPfuncs
.writeready
455 ? (*m_aNPPfuncs
.writeready
)(
457 (NPStream
*)m_aArgs
[1] )
461 TRACE( "eNPP_GetValue" );
462 nRet
= (m_aNPPfuncs
.getvalue
463 ? (*m_aNPPfuncs
.getvalue
)(
465 (NPPVariable
)(int)m_aArgs
[1],
467 : NPERR_GENERIC_ERROR
);
470 TRACE( "eNPP_SetValue" );
471 nRet
= (m_aNPPfuncs
.setvalue
472 ? (*m_aNPPfuncs
.setvalue
)(
474 (NPNVariable
)(int)m_aArgs
[1],
476 : NPERR_GENERIC_ERROR
);
480 TRACE( "eNPP_Shutdown" );
481 NPP_ShutdownUPP pFunc
;
482 if (retrieveFunction( "NPP_Shutdown", (void**)&pFunc
))
486 case eNPP_Initialize
:
487 TRACE( "eNPP_Initialize" );
488 OSL_ENSURE( false, "NPP_Initialize: not implemented!" );
490 case eNPP_GetJavaClass
:
491 TRACE( "eNPP_GetJavaClass" );
492 OSL_ENSURE( false, "NPP_GetJavaClass: not implemented!" );
498 //--------------------------------------------------------------------------------------------------
499 NPError
MacPluginComm::NPP_Destroy( XPlugin_Impl
* i_pImpl
, NPSavedData
** save
)
501 // remove from NullEvent timer
502 m_aNullEventClients
.remove( i_pImpl
);
504 NPError nErr
= NPP_Destroy( i_pImpl
->getNPPInstance(), save
);
506 // release plugin view
507 SysPlugData
& rPlugData( i_pImpl
->getSysPlugData() );
508 if( rPlugData
.m_pPlugView
)
510 [rPlugData
.m_pPlugView removeFromSuperview
];
511 [rPlugData
.m_pPlugView release
];
512 rPlugData
.m_pPlugView
= nil
;
519 NPError
MacPluginComm::NPP_Destroy( NPP instance
, NPSavedData
** save
)
521 DBG_ASSERT( m_aNPPfuncs
.destroy
, "### NPP_Destroy(): null pointer in NPP functions table!" );
522 m_eCall
= eNPP_Destroy
;
523 m_aArgs
[0] = (void*)instance
;
524 m_aArgs
[1] = (void*)save
;
525 return (NPError
)execute();
528 //--------------------------------------------------------------------------------------------------
529 NPError
MacPluginComm::NPP_DestroyStream( NPP instance
, NPStream
* stream
, NPError reason
)
531 DBG_ASSERT( m_aNPPfuncs
.destroystream
, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
532 m_eCall
= eNPP_DestroyStream
;
533 m_aArgs
[0] = (void*)instance
;
534 m_aArgs
[1] = (void*)stream
;
535 m_aArgs
[2] = (void*)reason
;
536 return (NPError
)execute();
539 //--------------------------------------------------------------------------------------------------
540 NPError
MacPluginComm::NPP_New( NPMIMEType pluginType
, NPP instance
, uint16 mode
, int16 argc
,
541 char* argn
[], char* argv
[], NPSavedData
*saved
)
543 XPlugin_Impl
* pImpl
= XPluginManager_Impl::getXPluginFromNPP( instance
);
544 DBG_ASSERT( pImpl
, "no instance found" );
546 if( pImpl
) // sanity check
547 m_aNullEventClients
.push_back( pImpl
);
549 DBG_ASSERT( m_aNPPfuncs
.newp
, "### NPP_New(): null pointer in NPP functions table!" );
550 #if OSL_DEBUG_LEVEL > 1
551 fprintf( stderr
, "NPP_New( %s. %p, %d, %d",
552 pluginType
, instance
, (int)mode
, (int)argc
);
553 for( int16 i
= 0; i
< argc
; i
++ )
554 fprintf( stderr
, "\n%s = %s", argn
[i
], argv
[i
] );
555 fprintf( stderr
, ", %p )\n", saved
);
558 m_aArgs
[0] = (void*)pluginType
;
559 m_aArgs
[1] = (void*)instance
;
560 m_aArgs
[2] = (void*)mode
;
561 m_aArgs
[3] = (void*)argc
;
562 m_aArgs
[4] = (void*)argn
;
563 m_aArgs
[5] = (void*)argv
;
564 m_aArgs
[6] = (void*)saved
;
566 return (NPError
)execute();
569 //--------------------------------------------------------------------------------------------------
570 NPError
MacPluginComm::NPP_NewStream( NPP instance
, NPMIMEType type
, NPStream
* stream
,
571 NPBool seekable
, uint16
* stype
)
573 DBG_ASSERT( m_aNPPfuncs
.newstream
, "### NPP_NewStream(): null pointer in NPP functions table!" );
574 m_eCall
= eNPP_NewStream
;
575 m_aArgs
[0] = (void*)instance
;
576 m_aArgs
[1] = (void*)type
;
577 m_aArgs
[2] = (void*)stream
;
578 m_aArgs
[3] = (void*)seekable
;
579 m_aArgs
[4] = (void*)stype
;
580 return (NPError
)execute();
583 //--------------------------------------------------------------------------------------------------
584 void MacPluginComm::NPP_Print( NPP instance
, NPPrint
* platformPrint
)
586 DBG_ASSERT( m_aNPPfuncs
.print
, "### NPP_Print(): null pointer in NPP functions table!" );
587 m_eCall
= eNPP_Print
;
588 m_aArgs
[0] = (void*)instance
;
589 m_aArgs
[1] = (void*)platformPrint
;
593 //--------------------------------------------------------------------------------------------------
594 NPError
MacPluginComm::NPP_SetWindow( NPP instance
, NPWindow
* window
)
596 DBG_ASSERT( m_aNPPfuncs
.setwindow
, "### NPP_SetWindow(): null pointer in NPP functions table!" );
597 m_eCall
= eNPP_SetWindow
;
598 m_aArgs
[0] = (void*)instance
;
599 m_aArgs
[1] = (void*)window
;
600 return (NPError
)execute();
603 //--------------------------------------------------------------------------------------------------
604 NPError
MacPluginComm::NPP_HandleEvent( NPP instance
, void* event
)
606 DBG_ASSERT( m_aNPPfuncs
.event
, "### NPP_HandleEvent(): null pointer in NPP functions table!" );
607 m_eCall
= eNPP_HandleEvent
;
608 m_aArgs
[0] = (void*)instance
;
610 return (NPError
)execute();
613 //--------------------------------------------------------------------------------------------------
614 void MacPluginComm::NPP_StreamAsFile( NPP instance
, NPStream
* stream
, const char* fname
)
616 DBG_ASSERT( m_aNPPfuncs
.asfile
, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
617 m_eCall
= eNPP_StreamAsFile
;
618 m_aArgs
[0] = (void*)instance
;
619 m_aArgs
[1] = (void*)stream
;
620 m_aArgs
[2] = (void*)fname
;
624 //--------------------------------------------------------------------------------------------------
625 void MacPluginComm::NPP_URLNotify( NPP instance
, const char* url
, NPReason reason
, void* notifyData
)
627 DBG_ASSERT( m_aNPPfuncs
.urlnotify
, "### NPP_URLNotify(): null pointer in NPP functions table!" );
628 m_eCall
= eNPP_URLNotify
;
629 m_aArgs
[0] = (void*)instance
;
630 m_aArgs
[1] = (void*)url
;
631 m_aArgs
[2] = (void*)reason
;
632 m_aArgs
[3] = notifyData
;
636 //--------------------------------------------------------------------------------------------------
637 int32
MacPluginComm::NPP_Write( NPP instance
, NPStream
* stream
, int32 offset
, int32 len
, void* buffer
)
639 DBG_ASSERT( m_aNPPfuncs
.write
, "### NPP_Write(): null pointer in NPP functions table!" );
640 m_eCall
= eNPP_Write
;
641 m_aArgs
[0] = (void*)instance
;
642 m_aArgs
[1] = (void*)stream
;
643 m_aArgs
[2] = (void*)offset
;
644 m_aArgs
[3] = (void*)len
;
646 return (NPError
)execute();
649 //--------------------------------------------------------------------------------------------------
650 int32
MacPluginComm::NPP_WriteReady( NPP instance
, NPStream
* stream
)
652 DBG_ASSERT( m_aNPPfuncs
.writeready
, "### NPP_WriteReady(): null pointer in NPP functions table!" );
653 m_eCall
= eNPP_WriteReady
;
654 m_aArgs
[0] = (void*)instance
;
655 m_aArgs
[1] = (void*)stream
;
659 //--------------------------------------------------------------------------------------------------
660 NPError
MacPluginComm::NPP_GetValue( NPP instance
, NPPVariable variable
, void *ret_value
)
662 DBG_ASSERT( m_aNPPfuncs
.getvalue
, "### NPP_GetValue(): null pointer in NPP functions table!" );
663 m_eCall
= eNPP_GetValue
;
664 m_aArgs
[0] = (void*)instance
;
665 m_aArgs
[1] = (void*)variable
;
666 m_aArgs
[2] = ret_value
;
667 return (NPError
)execute();
670 //--------------------------------------------------------------------------------------------------
671 NPError
MacPluginComm::NPP_SetValue( NPP instance
, NPNVariable variable
, void *set_value
)
673 DBG_ASSERT( m_aNPPfuncs
.setvalue
, "### NPP_SetValue(): null pointer in NPP functions table!" );
674 m_eCall
= eNPP_SetValue
;
675 m_aArgs
[0] = (void*)instance
;
676 m_aArgs
[1] = (void*)variable
;
677 m_aArgs
[2] = set_value
;
678 return (NPError
)execute();
681 //--------------------------------------------------------------------------------------------------
682 void * MacPluginComm::NPP_GetJavaClass()
684 DBG_ERROR( "no java class available!" );
688 //--------------------------------------------------------------------------------------------------
689 NPError
MacPluginComm::NPP_Initialize()
691 return NPERR_NO_ERROR
;
694 //--------------------------------------------------------------------------------------------------
695 void MacPluginComm::NPP_Shutdown()
697 m_eCall
= eNPP_Shutdown
;
701 //--------------------------------------------------------------------------------------------------
702 NPError
MacPluginComm::NPP_SetWindow( XPlugin_Impl
* i_pImpl
)
704 // update window NPWindow from view
705 SysPlugData
& rPlugData( i_pImpl
->getSysPlugData() );
708 NSRect aPlugRect
= [rPlugData
.m_pParentView frame
];
709 aPlugRect
.origin
.x
= aPlugRect
.origin
.y
= 0;
710 if( ! rPlugData
.m_pPlugView
)
712 rPlugData
.m_pPlugView
= [[OOoPluginView alloc
] initWithInstance
: i_pImpl pluginComm
: this frame
: aPlugRect
];
713 [rPlugData
.m_pParentView addSubview
: rPlugData
.m_pPlugView
];
716 [rPlugData
.m_pPlugView setFrame
: aPlugRect
];
718 NPWindow
* pNPWin
= i_pImpl
->getNPWindow();
719 NSWindow
* pWin
= [rPlugData
.m_pPlugView window
];
720 NSRect aWinRect
= [pWin frame
];
721 NSRect aBounds
= [rPlugData
.m_pPlugView frame
];
722 NSRect aVisibleBounds
= [rPlugData
.m_pPlugView visibleRect
];
724 #if OSL_DEBUG_LEVEL > 1
725 fprintf( stderr
, "visible bounds = %d+%d+%dx%d\n",
726 (int)aVisibleBounds
.origin
.x
, (int)aVisibleBounds
.origin
.y
,
727 (int)aVisibleBounds
.size
.width
, (int)aVisibleBounds
.size
.height
);
730 NSPoint aViewOrigin
= [rPlugData
.m_pPlugView convertPoint
: NSZeroPoint toView
: nil
];
731 // save view origin so we can notice movement of the view in drawView
732 // in case of a moved view we need to reset the port/context
733 rPlugData
.m_aLastPlugViewOrigin
= aViewOrigin
;
735 // convert view origin to topdown coordinates
736 aViewOrigin
.y
= aWinRect
.size
.height
- aViewOrigin
.y
;
739 NSPoint aClipOrigin
= [rPlugData
.m_pPlugView convertPoint
: aVisibleBounds
.origin toView
: nil
];
740 aClipOrigin
.y
= aWinRect
.size
.height
- aClipOrigin
.y
;
742 #if OSL_DEBUG_LEVEL > 1
743 fprintf( stderr
, "view origin: %d+%d, clip origin = %d+%d\n",
744 (int)aViewOrigin
.x
, (int)aViewOrigin
.y
,
745 (int)aClipOrigin
.x
, (int)aClipOrigin
.y
);
748 pNPWin
->x
= aViewOrigin
.x
;
749 pNPWin
->y
= aViewOrigin
.y
;
750 pNPWin
->width
= aBounds
.size
.width
;
751 pNPWin
->height
= aBounds
.size
.height
;
752 pNPWin
->clipRect
.left
= aClipOrigin
.x
;
753 pNPWin
->clipRect
.top
= aClipOrigin
.y
;
754 pNPWin
->clipRect
.right
= aClipOrigin
.x
+ aVisibleBounds
.size
.width
;
755 pNPWin
->clipRect
.bottom
= aClipOrigin
.y
+ aVisibleBounds
.size
.height
;
757 if( rPlugData
.m_nDrawingModel
== 1 )
759 rPlugData
.m_aCGContext
.window
= reinterpret_cast<WindowRef
>([pWin windowRef
]);
760 pNPWin
->window
= &rPlugData
.m_aCGContext
;
761 rPlugData
.m_aCGContext
.context
= reinterpret_cast<CGContextRef
>([[pWin graphicsContext
] graphicsPort
]);
762 #if OSL_DEBUG_LEVEL > 1
763 fprintf( stderr
, "window is %p, context is %p\n",
764 rPlugData
.m_aCGContext
.window
, rPlugData
.m_aCGContext
.context
);
769 rPlugData
.m_aNPPort
.port
= GetWindowPort( reinterpret_cast<WindowRef
>([pWin windowRef
]) );
770 rPlugData
.m_aNPPort
.portx
= aClipOrigin
.x
;
771 rPlugData
.m_aNPPort
.porty
= aClipOrigin
.y
;
772 pNPWin
->window
= &rPlugData
.m_aNPPort
;
773 #if OSL_DEBUG_LEVEL > 1
774 fprintf( stderr
, "port is %p at (%d,%d)\n",
775 rPlugData
.m_aNPPort
.port
, (int)rPlugData
.m_aNPPort
.portx
, (int)rPlugData
.m_aNPPort
.porty
);
779 if( pNPWin
->width
== 0 || pNPWin
->height
== 0 || [rPlugData
.m_pPlugView isHiddenOrHasHiddenAncestor
] )
780 rPlugData
.m_bSetWindowOnDraw
= true;
782 NPError nErr
= NPP_SetWindow( i_pImpl
->getNPPInstance(), i_pImpl
->getNPWindow() );
787 void MacPluginComm::drawView( XPlugin_Impl
* i_pImpl
)
789 SysPlugData
& rPlugData( i_pImpl
->getSysPlugData() );
791 // check if the view was moved since the last SetWindow
792 NSPoint aViewOrigin
= [rPlugData
.m_pPlugView convertPoint
: NSZeroPoint toView
: nil
];
793 if( rPlugData
.m_bSetWindowOnDraw
||
794 aViewOrigin
.x
!= rPlugData
.m_aLastPlugViewOrigin
.x
||
795 aViewOrigin
.y
!= rPlugData
.m_aLastPlugViewOrigin
.y
)
797 NPP_SetWindow( i_pImpl
);
798 rPlugData
.m_bSetWindowOnDraw
= false;
801 // send a paint event
802 NSWindow
* pWin
= [rPlugData
.m_pPlugView window
];
803 FakeEventRecord aRec
;
804 aRec
.what
= updateEvt
;
805 aRec
.message
= (UInt32
)[pWin windowRef
];
806 this->NPP_HandleEvent( i_pImpl
->getNPPInstance(), &aRec
);