diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2008-11-20 13:15:41 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2008-11-20 13:15:41 +0000 |
commit | bfaf0a0ed00eb603acfc735eb9085e33eff543f7 (patch) | |
tree | aa300355fa99e1dc9837a0b161c3489b5df7a7b0 /extensions | |
parent | f2c4534897cb050c980be4470251e19008cbd150 (diff) |
CWS-TOOLING: integrate CWS swffixes_DEV300
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/source/plugin/base/makefile.mk | 7 | ||||
-rw-r--r-- | extensions/source/plugin/inc/plugin/unx/mediator.hxx | 9 | ||||
-rw-r--r-- | extensions/source/plugin/inc/plugin/unx/plugcon.hxx | 45 | ||||
-rw-r--r-- | extensions/source/plugin/unx/makefile.mk | 22 | ||||
-rw-r--r-- | extensions/source/plugin/unx/mediator.cxx | 39 | ||||
-rw-r--r-- | extensions/source/plugin/unx/npnapi.cxx | 210 | ||||
-rw-r--r-- | extensions/source/plugin/unx/nppapi.cxx | 75 | ||||
-rw-r--r-- | extensions/source/plugin/unx/npwrap.cxx | 175 | ||||
-rw-r--r-- | extensions/source/plugin/unx/plugcon.cxx | 76 | ||||
-rw-r--r-- | extensions/source/plugin/unx/unxmgr.cxx | 77 | ||||
-rw-r--r-- | extensions/source/plugin/win/winmgr.cxx | 75 |
11 files changed, 606 insertions, 204 deletions
diff --git a/extensions/source/plugin/base/makefile.mk b/extensions/source/plugin/base/makefile.mk index 9ec5418ead28..fdbbe7282279 100644 --- a/extensions/source/plugin/base/makefile.mk +++ b/extensions/source/plugin/base/makefile.mk @@ -8,7 +8,7 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.14 $ +# $Revision: 1.14.90.2 $ # # This file is part of OpenOffice.org. # @@ -55,6 +55,11 @@ OBJCXXFLAGS=-x objective-c++ -fobjc-exceptions CFLAGSCXX+=$(OBJCXXFLAGS) .ENDIF # "$(GUIBASE)"=="aqua" +.IF "$(GUIBASE)" == "unx" && "$(ENABLE_GTK)" == "TRUE" +PKGCONFIG_MODULES=gtk+-2.0 +.INCLUDE : pkg_config.mk +.ENDIF + SLOFILES= \ $(SLO)$/plctrl.obj \ $(SLO)$/service.obj \ diff --git a/extensions/source/plugin/inc/plugin/unx/mediator.hxx b/extensions/source/plugin/inc/plugin/unx/mediator.hxx index f9bc9a4c23ba..8c796b9a1918 100644 --- a/extensions/source/plugin/inc/plugin/unx/mediator.hxx +++ b/extensions/source/plugin/inc/plugin/unx/mediator.hxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: mediator.hxx,v $ - * $Revision: 1.8 $ + * $Revision: 1.8.90.1 $ * * This file is part of OpenOffice.org. * @@ -33,7 +33,6 @@ #include <string.h> #include <stdarg.h> #include <tools/string.hxx> -#include <tools/list.hxx> #include <tools/link.hxx> #include <vos/pipe.hxx> #include <vos/mutex.hxx> @@ -43,6 +42,8 @@ #include <stdio.h> #endif +#include <vector> + struct MediatorMessage { ULONG m_nID; @@ -83,8 +84,6 @@ struct MediatorMessage void Rewind() { m_pRun = NULL; } }; -DECLARE_LIST( MediatorMessageList, MediatorMessage* ) - class MediatorListener; class Mediator @@ -93,7 +92,7 @@ class Mediator protected: int m_nSocket; - MediatorMessageList m_aMessageQueue; + std::vector<MediatorMessage*> m_aMessageQueue; NAMESPACE_VOS(OMutex) m_aQueueMutex; NAMESPACE_VOS(OMutex) m_aSendMutex; // only one thread can send a message at any given time diff --git a/extensions/source/plugin/inc/plugin/unx/plugcon.hxx b/extensions/source/plugin/inc/plugin/unx/plugcon.hxx index afa306bfaf66..795dd647e30c 100644 --- a/extensions/source/plugin/inc/plugin/unx/plugcon.hxx +++ b/extensions/source/plugin/inc/plugin/unx/plugcon.hxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: plugcon.hxx,v $ - * $Revision: 1.13 $ + * $Revision: 1.13.90.3 $ * * This file is part of OpenOffice.org. * @@ -34,7 +34,7 @@ #include <string.h> #include <list> -#include <tools/list.hxx> +#include <vector> #include <plugin/unx/mediator.hxx> #if defined SOLARIS @@ -82,6 +82,25 @@ extern "C" { #include <npsdk/npupp.h> } #include <npapi.h> + +#if NP_VERSION_MINOR < 17 +// compatibility hack: compile with older NPN api header, but define +// some later introduced constants +// for gcc 3 +#define NP_ABI_MASK 0x10000000 +#define NPNVSupportsXEmbedBool ((NPNVariable)14) +#define NPPVpluginNeedsXEmbed ((NPPVariable)14) +#define NPNVToolkit ((int)(13 | NP_ABI_MASK)) +#define NPNVGtk12 1 +#define NPNVGtk2 2 +#endif +#endif + +#ifdef ENABLE_GTK +#include <gtk/gtk.h> +#include <gdk/gdkx.h> +#else +#define GtkWidget void #endif #undef Window @@ -105,6 +124,11 @@ public: void* pWidget; void* pForm; + GtkWidget* pGtkWindow; + GtkWidget* pGtkWidget; + + bool bShouldUseXEmbed; + int nArg; char** argn; char** argv; @@ -119,24 +143,18 @@ public: ~ConnectorInstance(); }; -class PluginConnector; - -DECLARE_LIST( NPStreamList, NPStream* ) -DECLARE_LIST( InstanceList, ConnectorInstance* ) -DECLARE_LIST( PluginConnectorList, PluginConnector* ) - class PluginConnector : public Mediator { protected: NAMESPACE_VOS(OMutex) m_aUserEventMutex; - static PluginConnectorList allConnectors; + static std::vector<PluginConnector*> allConnectors; DECL_LINK( NewMessageHdl, Mediator* ); DECL_LINK( WorkOnNewMessageHdl, Mediator* ); - NPStreamList m_aNPWrapStreams; - InstanceList m_aInstances; + std::vector<NPStream*> m_aNPWrapStreams; + std::vector<ConnectorInstance*> m_aInstances; ULONG FillBuffer( char*&, const char*, ULONG, va_list ); public: @@ -155,7 +173,7 @@ public: UINT32 GetStreamID( NPStream* pStream ); UINT32 GetNPPID( NPP ); - NPStreamList& getStreamList() { return m_aNPWrapStreams; } + std::vector<NPStream*>& getStreamList() { return m_aNPWrapStreams; } NPError GetNPError( MediatorMessage* pMes ) { @@ -170,6 +188,9 @@ public: LINK( this, PluginConnector, WorkOnNewMessageHdl ). Call( (Mediator*)this ); } + + ConnectorInstance* getInstance( NPP ); + ConnectorInstance* getInstanceById( UINT32 ); }; enum CommandAtoms diff --git a/extensions/source/plugin/unx/makefile.mk b/extensions/source/plugin/unx/makefile.mk index d442040f2a1e..1160ecbff51c 100644 --- a/extensions/source/plugin/unx/makefile.mk +++ b/extensions/source/plugin/unx/makefile.mk @@ -8,7 +8,7 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.15 $ +# $Revision: 1.15.90.3 $ # # This file is part of OpenOffice.org. # @@ -33,6 +33,7 @@ PRJ=..$/..$/.. PRJNAME=extensions TARGET=plunx TARGETTYPE=CUI +ENABLE_EXCEPTIONS=TRUE .INCLUDE : ..$/util$/makefile.pmk @@ -57,6 +58,12 @@ CDEFS+=-DOJI CDEFS+=-DDISABLE_XAW .ENDIF +.IF "$(ENABLE_GTK)" == "TRUE" +CDEFS+=-DENABLE_GTK +PKGCONFIG_MODULES=gtk+-2.0 gthread-2.0 +.INCLUDE : pkg_config.mk +.ENDIF + SLOFILES=\ $(SLO)$/nppapi.obj \ $(SLO)$/sysplug.obj \ @@ -89,6 +96,19 @@ APP1STDLIBS+= -lXt -lXext -lX11 -ldl .ENDIF .ENDIF +.IF "$(ENABLE_GTK)" == "TRUE" +# libs for gtk plugin +APP1STDLIBS+=$(PKGCONFIG_LIBS:s/ -lpangoxft-1.0//) +# hack for faked SO environment +.IF "$(PKGCONFIG_ROOT)"!="" +.IF "$(OS)" == "SOLARIS" +# don't ask, it's ugly +DIRECT :=-z nodefs $(DIRECT) +.ENDIF +.ENDIF # "$(PKGCONFIG_ROOT)"!="" +.ENDIF + + APP1DEF= $(MISC)$/$(TARGET).def .ENDIF # $(WITH_MOZILLA) != "NO" diff --git a/extensions/source/plugin/unx/mediator.cxx b/extensions/source/plugin/unx/mediator.cxx index 939109d4190f..63048ad13589 100644 --- a/extensions/source/plugin/unx/mediator.cxx +++ b/extensions/source/plugin/unx/mediator.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: mediator.cxx,v $ - * $Revision: 1.11 $ + * $Revision: 1.11.90.1 $ * * This file is part of OpenOffice.org. * @@ -70,8 +70,11 @@ Mediator::~Mediator() } else close( m_nSocket ); - while( m_aMessageQueue.Count() ) - delete m_aMessageQueue.Remove( (ULONG)0 ); + for( std::vector< MediatorMessage* >::iterator it = m_aMessageQueue.begin(); + it != m_aMessageQueue.end(); ++it ) + { + delete *it; + } } @@ -107,7 +110,7 @@ BOOL Mediator::WaitForMessage( ULONG nTimeOut ) if( ! m_pListener ) return FALSE; - ULONG nItems = m_aMessageQueue.Count(); + size_t nItems = m_aMessageQueue.size(); if( ! nTimeOut && nItems > 0 ) return TRUE; @@ -116,11 +119,11 @@ BOOL Mediator::WaitForMessage( ULONG nTimeOut ) aValue.Seconds = nTimeOut/1000; aValue.Nanosec = ( nTimeOut % 1000 ) * 1000; - while( m_aMessageQueue.Count() == nItems ) + while( m_aMessageQueue.size() == nItems ) { m_aNewMessageCdtn.wait( & aValue ); m_aNewMessageCdtn.reset(); - if( nTimeOut && m_aMessageQueue.Count() == nItems ) + if( nTimeOut && m_aMessageQueue.size() == nItems ) return FALSE; } return TRUE; @@ -133,12 +136,16 @@ MediatorMessage* Mediator::WaitForAnswer( ULONG nMessageID ) { { NAMESPACE_VOS(OGuard) aGuard( m_aQueueMutex ); - for( ULONG i = 0; i < m_aMessageQueue.Count(); i++ ) + for( size_t i = 0; i < m_aMessageQueue.size(); i++ ) { - ULONG nID = m_aMessageQueue.GetObject( i )->m_nID; + MediatorMessage* pMessage = m_aMessageQueue[ i ]; + ULONG nID = pMessage->m_nID; if( ( nID & 0xff000000 ) && ( ( nID & 0x00ffffff ) == nMessageID ) ) - return m_aMessageQueue.Remove( i ); + { + m_aMessageQueue.erase( m_aMessageQueue.begin() + i ); + return pMessage; + } } } WaitForMessage( 10 ); @@ -154,9 +161,15 @@ MediatorMessage* Mediator::GetNextMessage( BOOL bWait ) // guard must be after WaitForMessage, else the listener // cannot insert a new one -> deadlock NAMESPACE_VOS(OGuard) aGuard( m_aQueueMutex ); - for( ULONG i = 0; i < m_aMessageQueue.Count(); i++ ) - if( ! ( m_aMessageQueue.GetObject( i )->m_nID & 0xff000000 ) ) - return m_aMessageQueue.Remove( i ); + for( size_t i = 0; i < m_aMessageQueue.size(); i++ ) + { + MediatorMessage* pMessage = m_aMessageQueue[ i ]; + if( ! ( pMessage->m_nID & 0xff000000 ) ) + { + m_aMessageQueue.erase( m_aMessageQueue.begin() + i ); + return pMessage; + } + } if( ! bWait ) return NULL; } @@ -201,7 +214,7 @@ void MediatorListener::run() aGuard( m_pMediator->m_aQueueMutex ); MediatorMessage* pMessage = new MediatorMessage( nHeader[ 0 ], nHeader[ 1 ], pBuffer ); - m_pMediator->m_aMessageQueue.Insert( pMessage, LIST_APPEND ); + m_pMediator->m_aMessageQueue.push_back( pMessage ); } m_pMediator->m_aNewMessageCdtn.set(); m_pMediator->m_aNewMessageHdl.Call( m_pMediator ); diff --git a/extensions/source/plugin/unx/npnapi.cxx b/extensions/source/plugin/unx/npnapi.cxx index cfbd21be7d0b..f35d1bc2a313 100644 --- a/extensions/source/plugin/unx/npnapi.cxx +++ b/extensions/source/plugin/unx/npnapi.cxx @@ -20,6 +20,7 @@ extern XtAppContext app_context; extern int wakeup_fd[]; extern Widget topLevel, topBox; extern Display* pAppDisplay; +extern Display* pXtAppDisplay; extern int nAppArguments; extern char** pAppArguments; @@ -62,7 +63,15 @@ static NPError l_NPN_DestroyStream( NPP instance, NPStream* stream, NPError reas if( ! pMes ) return NPERR_GENERIC_ERROR; - pConnector->getStreamList().Remove( stream ); + for( std::vector< NPStream* >::iterator it = pConnector->getStreamList().begin(); + it != pConnector->getStreamList().end(); ++it ) + { + if( *it == stream ) + { + pConnector->getStreamList().erase( it ); + break; + } + } delete [] stream->url; delete stream; // returns NPError @@ -164,7 +173,7 @@ static NPError l_NPN_NewStream( NPP instance, NPMIMEType type, const char* targe pStream->lastmodified = pMes->GetUINT32(); pStream->ndata = pStream->pdata = pStream->notifyData = NULL; - pConnector->getStreamList().Insert( pStream, LIST_APPEND ); + pConnector->getStreamList().push_back( pStream ); *stream = pStream; } @@ -353,12 +362,12 @@ static void l_NPN_ReloadPlugins( NPBool /*reloadPages*/ ) medDebug( 1, "NPN_ReloadPlugins: SNI\n" ); } -static NPError l_NPN_GetValue( NPP /*instance*/, NPNVariable variable, void* value ) +static NPError l_NPN_GetValue( NPP, NPNVariable variable, void* value ) { switch( variable ) { case NPNVxDisplay: - *((Display**)value) = pAppDisplay; + *((Display**)value) = pXtAppDisplay; medDebug( 1, "Display requested\n" ); break; case NPNVxtAppContext: @@ -380,8 +389,21 @@ static NPError l_NPN_GetValue( NPP /*instance*/, NPNVariable variable, void* val *(NPBool*)value = false; medDebug( 1, "offline browsing requested\n" ); break; + case NPNVSupportsXEmbedBool: + // asking xembed + *(int*)value = true; + medDebug( 1, "xembed requested\n" ); + break; + case NPNVToolkit: + #ifdef ENABLE_GTK + *(int*)value = NPNVGtk2; + #else + *(int*)value = 0; + #endif + medDebug( 1, "toolkit requested\n" ); + break; default: - medDebug( 1, "unknown NPNVariable %d requested\n", variable ); + medDebug( 1, "unknown NPNVariable %x requested\n", variable ); return NPERR_INVALID_PARAM; } return NPERR_NO_ERROR; @@ -468,7 +490,7 @@ char*(*pNPP_GetMIMEDescription)() = NULL; NPError (*pNP_Initialize)(NPNetscapeFuncs*,NPPluginFuncs*) = NULL; NPError (*pNP_Shutdown)() = NULL; -PluginConnectorList PluginConnector::allConnectors; +std::vector< PluginConnector* > PluginConnector::allConnectors; PluginConnector::PluginConnector( int nSocket ) : Mediator( nSocket ) @@ -493,11 +515,11 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPP_DestroyStream: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; UINT32 nFileID = pMessage->GetUINT32(); - NPStream* pStream = m_aNPWrapStreams.GetObject( nFileID ); + NPStream* pStream = m_aNPWrapStreams[ nFileID ]; NPError aReason = GetNPError( pMessage ); - m_aNPWrapStreams.Remove( pStream ); + m_aNPWrapStreams.erase( m_aNPWrapStreams.begin() + nFileID ); aReason = aPluginFuncs.destroystream( instance, pStream, aReason ); Respond( pMessage->m_nID, @@ -511,12 +533,13 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPP_Destroy: { UINT32 nInstance = pMessage->GetUINT32(); - ConnectorInstance* pInst= m_aInstances.GetObject( nInstance ); + ConnectorInstance* pInst= m_aInstances[ nInstance ]; // some plugin rely on old netscapes behaviour // to first destroy the widget and then destroy // the instance, so mimic that behaviour here - XtDestroyWidget( (Widget)pInst->pShell ); + if( pInst->pShell ) + XtDestroyWidget( (Widget)pInst->pShell ); pInst->pWidget = pInst->pShell = NULL; @@ -529,7 +552,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) { // now really destroy the instance UINT32 nInstance = pMessage->GetUINT32(); - ConnectorInstance* pInst= m_aInstances.GetObject( nInstance ); + ConnectorInstance* pInst= m_aInstances[ nInstance ]; NPP instance = pInst->instance; NPSavedData* pSave = NULL; @@ -548,7 +571,15 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) "0000", 4, NULL ); - delete m_aInstances.Remove( nInstance ); + #ifdef ENABLE_GTK + if( pInst->pGtkWindow ) + g_object_unref( G_OBJECT(pInst->pGtkWindow) ); + if( pInst->pGtkWidget ) + g_object_unref( G_OBJECT(pInst->pGtkWidget) ); + #endif + + m_aInstances.erase( m_aInstances.begin() + nInstance ); + delete pInst; delete instance; medDebug( 1, "destroyed instance (returning %d)\n", aRet ); } @@ -556,7 +587,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPP_NewStream: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; char* pType = pMessage->GetString(); NPStream* pStream = new NPStream; pStream->url = pMessage->GetString(); @@ -564,7 +595,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) pStream->lastmodified = pMessage->GetUINT32(); pStream->pdata = pStream->ndata = pStream->notifyData = NULL; NPBool* pSeekable = (NPBool*)pMessage->GetBytes(); - m_aNPWrapStreams.Insert( pStream, LIST_APPEND ); + m_aNPWrapStreams.push_back( pStream ); uint16 nStype = NP_ASFILE; NPError aRet = aPluginFuncs.newstream( instance, pType, pStream, *pSeekable, &nStype ); @@ -598,7 +629,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) pArgn, nArgnBytes, pArgv, nArgvBytes, pSavedData, nSaveBytes ); - m_aInstances.Insert( pInst, LIST_APPEND ); + m_aInstances.push_back( pInst ); NPError aRet; aRet = aPluginFuncs.newp( pInst->pMimeType, instance, *pMode, *pArgc, pInst->nArg ? pInst->argn : NULL, @@ -613,6 +644,22 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) for( int i = 0; i < pInst->nArg; i++ ) medDebug( 1, " \"%s\"=\"%s\"\n", pInst->argn[i], pInst->argv[i] ); #endif + + #ifdef ENABLE_GTK + // check if XEMBED is to be used + // ask for Bool. there seems to be no clear definition whether the + // return value should be an int or unsigned char + // int can hold both and will be nonzero in case of "true" + if( aPluginFuncs.getvalue ) + { + int bNeedsXEmbed = 0; + NPError error = aPluginFuncs.getvalue( instance, NPPVpluginNeedsXEmbed, (void *)&bNeedsXEmbed ); + if( error == NPERR_NO_ERROR ) + pInst->bShouldUseXEmbed = (bNeedsXEmbed != 0); + medDebug( 1, "should use xembed = %s\n", pInst->bShouldUseXEmbed ? "true" : "false" ); + } + #endif + Respond( pMessage->m_nID, (char*)&aRet, sizeof( aRet ), NULL ); @@ -624,51 +671,94 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPP_SetWindow: { UINT32 nInstance = pMessage->GetUINT32(); - ConnectorInstance* pInst= m_aInstances.GetObject( nInstance ); + ConnectorInstance* pInst= m_aInstances[ nInstance ]; NPWindow* pWindow = (NPWindow*)pMessage->GetBytes(); - if( ! pInst->pWidget ) - { - static bool bFirstWindow = true; - if( bFirstWindow ) + if( pWindow->width < 1 ) + pWindow->width = 1; + if( pWindow->height < 1 ) + pWindow->height = 1; + + #ifdef ENABLE_GTK + if( pInst->bShouldUseXEmbed ) + { + if( ! pInst->pGtkWidget ) { - bFirstWindow = false; - pInst->pShell = topLevel; - pInst->pWidget = topBox; - medDebug( 1, "reusing app window\n" ); + medDebug( 1, "creating gtk plug and socket\n" ); + + pInst->pGtkWindow = gtk_plug_new((GdkNativeWindow)pWindow->window); + gtk_widget_show( pInst->pGtkWindow ); + pInst->pGtkWidget = gtk_socket_new(); + gtk_widget_show( pInst->pGtkWidget ); + gtk_container_add( GTK_CONTAINER(pInst->pGtkWindow), pInst->pGtkWidget ); + gtk_widget_show_all( pInst->pGtkWindow ); + pInst->window.window = (void *)gtk_socket_get_id( GTK_SOCKET(pInst->pGtkWidget ) ); + + XSync( pAppDisplay, False ); + + XMapWindow( pAppDisplay, GDK_WINDOW_XWINDOW(pInst->pGtkWindow->window) ); + + XSync( pAppDisplay, False ); } - else + + // update widget size; alas out parent is not yet really XEMBED conformant + gtk_widget_set_size_request( pInst->pGtkWidget, pWindow->width, pWindow->height ); + gtk_window_resize( GTK_WINDOW(pInst->pGtkWindow), pWindow->width, pWindow->height ); + + GdkScreen* pGdkScreen = gtk_widget_get_screen( pInst->pGtkWidget ); + Screen* pScreen = ScreenOfDisplay( pAppDisplay, gdk_screen_get_number( pGdkScreen ) ); + + pInst->window.x = 0; + pInst->window.y = 0; + pInst->window.width = pWindow->width; + pInst->window.height = pWindow->height; + pInst->window.clipRect.left = 0; + pInst->window.clipRect.top = 0; + pInst->window.clipRect.right = pWindow->width; + pInst->window.clipRect.bottom = pWindow->height; + pInst->window.ws_info = &pInst->ws_info; + pInst->window.type = NPWindowTypeWindow; + pInst->ws_info.type = NP_SETWINDOW; + pInst->ws_info.display = pAppDisplay; + pInst->ws_info.visual = DefaultVisualOfScreen( pScreen ); + pInst->ws_info.colormap = DefaultColormapOfScreen( pScreen ); + pInst->ws_info.depth = DefaultDepthOfScreen( pScreen ); + } + else + #endif + { + if( ! pInst->pWidget ) { pInst->pWidget = CreateNewShell( &(pInst->pShell), (XLIB_Window)pWindow->window ); } - } - // fill in NPWindow and NPCallbackStruct - pInst->window.window = (void*)XtWindow( (Widget)pInst->pWidget ); - pInst->window.x = 0; - pInst->window.y = 0; - pInst->window.width = pWindow->width; - pInst->window.height = pWindow->height; - pInst->window.clipRect.left = 0; - pInst->window.clipRect.top = 0; - pInst->window.clipRect.right = pWindow->width; - pInst->window.clipRect.bottom = pWindow->height; - pInst->window.ws_info = &pInst->ws_info; - pInst->window.type = NPWindowTypeWindow; - pInst->ws_info.type = NP_SETWINDOW; - pInst->ws_info.display = XtDisplay( (Widget)pInst->pWidget ); - pInst->ws_info.visual = DefaultVisualOfScreen( XtScreen( (Widget)pInst->pWidget ) ); - pInst->ws_info.colormap = DefaultColormapOfScreen( XtScreen( (Widget)pInst->pWidget ) ); - pInst->ws_info.depth = DefaultDepthOfScreen( XtScreen( (Widget)pInst->pWidget ) ); - - XtResizeWidget( (Widget)pInst->pShell, - pInst->window.width, - pInst->window.height, - 0 ); - XtResizeWidget( (Widget)pInst->pWidget, - pInst->window.width, - pInst->window.height, - 0 ); + // fill in NPWindow and NPCallbackStruct + pInst->window.window = (void*)XtWindow( (Widget)pInst->pWidget ); + pInst->window.x = 0; + pInst->window.y = 0; + pInst->window.width = pWindow->width; + pInst->window.height = pWindow->height; + pInst->window.clipRect.left = 0; + pInst->window.clipRect.top = 0; + pInst->window.clipRect.right = pWindow->width; + pInst->window.clipRect.bottom = pWindow->height; + pInst->window.ws_info = &pInst->ws_info; + pInst->window.type = NPWindowTypeWindow; + pInst->ws_info.type = NP_SETWINDOW; + pInst->ws_info.display = XtDisplay( (Widget)pInst->pWidget ); + pInst->ws_info.visual = DefaultVisualOfScreen( XtScreen( (Widget)pInst->pWidget ) ); + pInst->ws_info.colormap = DefaultColormapOfScreen( XtScreen( (Widget)pInst->pWidget ) ); + pInst->ws_info.depth = DefaultDepthOfScreen( XtScreen( (Widget)pInst->pWidget ) ); + + XtResizeWidget( (Widget)pInst->pShell, + pInst->window.width, + pInst->window.height, + 0 ); + XtResizeWidget( (Widget)pInst->pWidget, + pInst->window.width, + pInst->window.height, + 0 ); + } NPError aRet = aPluginFuncs.setwindow( pInst->instance, &pInst->window ); medDebug( 1, "pluginapp: NPP_SetWindow returns %d\n", (int) aRet ); @@ -681,9 +771,9 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPP_StreamAsFile: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; UINT32 nFileID = pMessage->GetUINT32(); - NPStream* pStream = m_aNPWrapStreams.GetObject( nFileID ); + NPStream* pStream = m_aNPWrapStreams[ nFileID ]; char* fname = pMessage->GetString(); medDebug( 1, "pluginapp: NPP_StreamAsFile %s\n", fname ); aPluginFuncs.asfile( instance, pStream, fname ); @@ -693,7 +783,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPP_URLNotify: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; char* url = pMessage->GetString(); NPReason* pReason = (NPReason*)pMessage->GetBytes(); void** notifyData = (void**)pMessage->GetBytes(); @@ -706,9 +796,9 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPP_WriteReady: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; UINT32 nFileID = pMessage->GetUINT32(); - NPStream* pStream = m_aNPWrapStreams.GetObject( nFileID ); + NPStream* pStream = m_aNPWrapStreams[ nFileID ]; int32 nRet = aPluginFuncs.writeready( instance, pStream ); medDebug( 1, "pluginapp: NPP_WriteReady( %p, %p ) (stream id = %d) returns %d\n", @@ -722,9 +812,9 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPP_Write: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; UINT32 nFileID = pMessage->GetUINT32(); - NPStream* pStream = m_aNPWrapStreams.GetObject( nFileID ); + NPStream* pStream = m_aNPWrapStreams[ nFileID ]; int32 offset = pMessage->GetUINT32(); ULONG len; char* buffer = (char*)pMessage->GetBytes( len ); diff --git a/extensions/source/plugin/unx/nppapi.cxx b/extensions/source/plugin/unx/nppapi.cxx index 551eccfe5623..758d5860903d 100644 --- a/extensions/source/plugin/unx/nppapi.cxx +++ b/extensions/source/plugin/unx/nppapi.cxx @@ -16,25 +16,40 @@ #include <plugin/impl.hxx> #include <vcl/svapp.hxx> -PluginConnectorList PluginConnector::allConnectors; +std::vector<PluginConnector*> PluginConnector::allConnectors; PluginConnector::PluginConnector( int nSocket ) : Mediator( nSocket ) { - allConnectors.Insert( this, LIST_APPEND ); + allConnectors.push_back( this ); SetNewMessageHdl( LINK( this, PluginConnector, NewMessageHdl ) ); } PluginConnector::~PluginConnector() { NAMESPACE_VOS(OGuard) aGuard( m_aUserEventMutex ); - allConnectors.Remove( this ); + for( std::vector< PluginConnector* >::iterator it = allConnectors.begin(); + it != allConnectors.end(); ++it ) + { + if( *it == this ) + { + allConnectors.erase( it ); + break; + } + } } IMPL_LINK( PluginConnector, NewMessageHdl, Mediator*, /*pMediator*/ ) { NAMESPACE_VOS(OGuard) aGuard( m_aUserEventMutex ); - if( allConnectors.GetPos( this ) == LIST_ENTRY_NOTFOUND ) + bool bFound = false; + for( std::vector< PluginConnector* >::iterator it = allConnectors.begin(); + it != allConnectors.end() && bFound == false; ++it ) + { + if( *it == this ) + bFound = true; + } + if( ! bFound ) return 0; Application::PostUserEvent( LINK( this, PluginConnector, WorkOnNewMessageHdl ) ); return 0; @@ -42,7 +57,14 @@ IMPL_LINK( PluginConnector, NewMessageHdl, Mediator*, /*pMediator*/ ) IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) { - if( allConnectors.GetPos( this ) == LIST_ENTRY_NOTFOUND ) + bool bFound = false; + for( std::vector< PluginConnector* >::iterator it = allConnectors.begin(); + it != allConnectors.end() && bFound == false; ++it ) + { + if( *it == this ) + bFound = true; + } + if( ! bFound ) return 0; /* { @@ -62,7 +84,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_GetURL: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; char* pUrl = pMessage->GetString(); char* pWindow = pMessage->GetString(); NPError aRet = NPN_GetURL( instance, pUrl, pWindow ); @@ -75,7 +97,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_GetURLNotify: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; char* pUrl = pMessage->GetString(); char* pWindow = pMessage->GetString(); void** pNotifyData = (void**)pMessage->GetBytes(); @@ -91,23 +113,23 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_DestroyStream: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; UINT32 nFileID = pMessage->GetUINT32(); char* pUrl = pMessage->GetString(); NPError* pReason = (NPError*)pMessage->GetBytes(); NPError aRet = NPERR_FILE_NOT_FOUND; - if( nFileID < m_aNPWrapStreams.Count() ) + if( nFileID < static_cast<UINT32>(m_aNPWrapStreams.size()) ) { - if( ! strcmp( m_aNPWrapStreams.GetObject( nFileID )->url, pUrl ) ) + if( ! strcmp( m_aNPWrapStreams[ nFileID ]->url, pUrl ) ) { aRet = - NPN_DestroyStream( instance, m_aNPWrapStreams.GetObject( nFileID ), + NPN_DestroyStream( instance, m_aNPWrapStreams[ nFileID ], *pReason ); - m_aNPWrapStreams.Remove( nFileID ); + m_aNPWrapStreams.erase( m_aNPWrapStreams.begin() + nFileID ); } else medDebug( 1, "StreamID %d has incoherent urls %s and %s\n", - nFileID, pUrl, m_aNPWrapStreams.GetObject( nFileID )->url ); + nFileID, pUrl, m_aNPWrapStreams[ nFileID ]->url ); } else medDebug( 1, "Nonexistent StreamID %d\n", nFileID ); @@ -122,7 +144,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_NewStream: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; NPMIMEType pType = pMessage->GetString(); char* pTarget = pMessage->GetString(); @@ -142,7 +164,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) } else { - m_aNPWrapStreams.Insert( pStream, LIST_APPEND ); + m_aNPWrapStreams.push_back( pStream ); ULONG nLen = strlen( pStream->url ); Respond( pMessage->m_nID, @@ -160,7 +182,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_PostURLNotify: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; char* pUrl = pMessage->GetString(); char* pTarget = pMessage->GetString(); UINT32 nLen = pMessage->GetUINT32(); @@ -180,7 +202,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_PostURL: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; char* pUrl = pMessage->GetString(); char* pWindow = pMessage->GetString(); UINT32 nLen = pMessage->GetUINT32(); @@ -198,7 +220,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_RequestRead: { UINT32 nFileID = pMessage->GetUINT32(); - NPStream* pStream = m_aNPWrapStreams.GetObject( nFileID ); + NPStream* pStream = m_aNPWrapStreams[ nFileID ]; UINT32 nRanges = pMessage->GetUINT32(); UINT32* pArray = (UINT32*)pMessage->GetBytes(); // build ranges table @@ -225,7 +247,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_Status: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; char* pString = pMessage->GetString(); NPN_Status( instance, pString ); delete [] pString; @@ -246,9 +268,9 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_Write: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; UINT32 nFileID = pMessage->GetUINT32(); - NPStream* pStream = m_aNPWrapStreams.GetObject( nFileID ); + NPStream* pStream = m_aNPWrapStreams[ nFileID ]; INT32 nLen = pMessage->GetUINT32(); void* pBuffer = pMessage->GetBytes(); INT32 nRet = NPN_Write( instance, pStream, nLen, pBuffer ); @@ -262,7 +284,7 @@ IMPL_LINK( PluginConnector, WorkOnNewMessageHdl, Mediator*, /*pMediator*/ ) case eNPN_UserAgent: { UINT32 nInstance = pMessage->GetUINT32(); - NPP instance = m_aInstances.GetObject( nInstance )->instance; + NPP instance = m_aInstances[ nInstance ]->instance; const char* pAnswer = NPN_UserAgent( instance ); Respond( pMessage->m_nID, (char*)pAnswer, strlen( pAnswer ), @@ -338,7 +360,7 @@ NPError UnxPluginComm::NPP_DestroyStream( NPP instance, NPStream* stream, NPErro &nFileID, sizeof( nFileID ), &reason, sizeof( reason ), NULL ); - m_aNPWrapStreams.Remove( stream ); + m_aNPWrapStreams.erase( m_aNPWrapStreams.begin() + nFileID ); if( ! pMes ) return NPERR_GENERIC_ERROR; @@ -368,12 +390,11 @@ NPError UnxPluginComm::NPP_Initialize() NPError UnxPluginComm::NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData *saved ) { - m_aInstances.Insert( + m_aInstances.push_back( new ConnectorInstance( instance, pluginType, 0, NULL, 0, NULL, 0, saved ? (char*)saved->buf : NULL, - saved ? saved->len : 0 ), - LIST_APPEND ); + saved ? saved->len : 0 ) ); char *pArgnBuf, *pArgvBuf; int nArgnLen = 0, nArgvLen = 0; @@ -433,7 +454,7 @@ NPError UnxPluginComm::NPP_NewStream( NPP instance, NPMIMEType type, NPStream* s NPError aRet = NPERR_GENERIC_ERROR; GET_INSTANCE_RET( aRet ); - m_aNPWrapStreams.Insert( stream, LIST_APPEND ); + m_aNPWrapStreams.push_back( stream ); MediatorMessage* pMes = Transact( eNPP_NewStream, POST_INSTANCE(), diff --git a/extensions/source/plugin/unx/npwrap.cxx b/extensions/source/plugin/unx/npwrap.cxx index 65b276a9e3df..f9a333c77dda 100644 --- a/extensions/source/plugin/unx/npwrap.cxx +++ b/extensions/source/plugin/unx/npwrap.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: npwrap.cxx,v $ - * $Revision: 1.16 $ + * $Revision: 1.16.90.5 $ * * This file is part of OpenOffice.org. * @@ -33,6 +33,7 @@ #include <errno.h> #include <dlfcn.h> #include <unistd.h> +#include <sys/poll.h> #include <fcntl.h> #include <signal.h> @@ -46,6 +47,7 @@ PluginConnector* pConnector = NULL; int nAppArguments = 0; char** pAppArguments = NULL; Display* pAppDisplay = NULL; +Display* pXtAppDisplay = NULL; extern oslModule pPluginLib; extern NPError (*pNP_Shutdown)(); @@ -72,6 +74,7 @@ extern "C" return 0; } + #ifndef ENABLE_GTK static void ThreadEventHandler( XtPointer /*client_data*/, int* /*source*/, XtInputId* id ) { char buf[256]; @@ -99,6 +102,7 @@ extern "C" } } } + #endif } @@ -129,16 +133,17 @@ Widget createSubWidget( char* /*pPluginText*/, Widget shell, XLIB_Window aParent XtNheight, 200, (char *)NULL ); XtRealizeWidget( shell ); + XtRealizeWidget( newWidget ); medDebug( 1, "Reparenting new widget %x to %x\n", XtWindow( newWidget ), aParentWindow ); - XReparentWindow( pAppDisplay, + XReparentWindow( pXtAppDisplay, XtWindow( shell ), aParentWindow, 0, 0 ); XtMapWidget( shell ); XtMapWidget( newWidget ); - XRaiseWindow( pAppDisplay, XtWindow( shell ) ); - XSync( pAppDisplay, False ); + XRaiseWindow( pXtAppDisplay, XtWindow( shell ) ); + XSync( pXtAppDisplay, False ); return newWidget; } @@ -146,12 +151,12 @@ Widget createSubWidget( char* /*pPluginText*/, Widget shell, XLIB_Window aParent void* CreateNewShell( void** pShellReturn, XLIB_Window aParentWindow ) { XLIB_String n, c; - XtGetApplicationNameAndClass(pAppDisplay, &n, &c); + XtGetApplicationNameAndClass(pXtAppDisplay, &n, &c); Widget newShell = XtVaAppCreateShell( "pane", c, topLevelShellWidgetClass, - pAppDisplay, + pXtAppDisplay, XtNwidth, 200, XtNheight, 200, XtNoverrideRedirect, True, @@ -175,7 +180,7 @@ static oslModule LoadModule( const char* pPath ) oslModule pLib = osl_loadModule( sFileURL.pData, SAL_LOADMODULE_LAZY ); if( ! pLib ) { - medDebug( 1, "could not open %s\n", pPath ); + medDebug( 1, "could not open %s: %s\n", pPath, dlerror() ); } return pLib; } @@ -190,7 +195,7 @@ static void CheckPlugin( const char* pPath ) if( pNP_GetMIMEDescription ) printf( "%s\n", pNP_GetMIMEDescription() ); else - medDebug( 1, "could not symbol NP_GetMIMEDescription\n" ); + medDebug( 1, "could not get symbol NP_GetMIMEDescription %s\n", dlerror() ); osl_unloadModule( pLib ); } @@ -221,6 +226,88 @@ static void signal_handler( int nSig ) _exit(nSig); } +#ifdef ENABLE_GTK + +static gboolean noClosure( gpointer ) +{ + return TRUE; +} + +// Xt events +static gboolean prepareXtEvent( GSource*, gint* ) +{ + int nMask = XtAppPending( app_context ); + return (nMask & XtIMAll) != 0; +} + +static gboolean checkXtEvent( GSource* ) +{ + int nMask = XtAppPending( app_context ); + return (nMask & XtIMAll) != 0; +} + +static gboolean dispatchXtEvent( GSource*, GSourceFunc, gpointer ) +{ + XtAppProcessEvent( app_context, XtIMAll ); + return TRUE; +} + +static GSourceFuncs aXtEventFuncs = +{ + prepareXtEvent, + checkXtEvent, + dispatchXtEvent, + NULL, + noClosure, + NULL +}; + +static gboolean prepareWakeupEvent( GSource*, gint* ) +{ + struct pollfd aPoll = { wakeup_fd[0], POLLIN, 0 }; + poll( &aPoll, 1, 0 ); + return (aPoll.revents & POLLIN ) != 0; +} + +static gboolean checkWakeupEvent( GSource* pSource ) +{ + gint nDum = 0; + return prepareWakeupEvent( pSource, &nDum ); +} + +static gboolean dispatchWakeupEvent( GSource*, GSourceFunc, gpointer ) +{ + char buf[256]; + // clear pipe + int len, nLast = -1; + + while( (len = read( wakeup_fd[0], buf, sizeof( buf ) ) ) > 0 ) + nLast = len-1; + if( ( nLast == -1 || buf[nLast] != 'x' ) && pConnector ) + pConnector->CallWorkHandler(); + else + { + XtAppSetExitFlag( app_context ); + bPluginAppQuit = true; + + delete pConnector; + pConnector = NULL; + } + + return TRUE; +} + +static GSourceFuncs aWakeupEventFuncs = { + prepareWakeupEvent, + checkWakeupEvent, + dispatchWakeupEvent, + NULL, + noClosure, + NULL +}; + +#endif // GTK + } int main( int argc, char **argv) @@ -241,7 +328,7 @@ int main( int argc, char **argv) pBaseName--; LoadAdditionalLibs( pBaseName ); - if( argc < 3 ) + if( argc == 2 ) { CheckPlugin(argv[1]); exit(0); @@ -290,36 +377,62 @@ int main( int argc, char **argv) } int nSocket = atol( argv[1] ); + #ifdef ENABLE_GTK + g_thread_init(NULL); + gtk_init(&argc, &argv); + #endif + pConnector = new PluginConnector( nSocket ); pConnector->SetConnectionLostHdl( Link( NULL, GlobalConnectionLostHdl ) ); XtSetLanguageProc( NULL, NULL, NULL ); - topLevel = XtVaOpenApplication( - &app_context, /* Application context */ - "SOPlugin", /* Application class */ - NULL, 0, /* command line option list */ - &argc, argv, /* command line args */ - NULL, /* for missing app-defaults file */ - topLevelShellWidgetClass, - XtNoverrideRedirect, True, - (char *)NULL); /* terminate varargs list */ - pAppDisplay = XtDisplay( topLevel ); + XtToolkitInitialize(); + app_context = XtCreateApplicationContext(); + pXtAppDisplay = XtOpenDisplay( app_context, NULL, "SOPlugin", "SOPlugin", NULL, 0, &argc, argv ); + + + #ifdef ENABLE_GTK + // integrate Xt events into GTK event loop + GPollFD aXtPollDesc, aWakeupPollDesc; + + GSource* pXTSource = g_source_new( &aXtEventFuncs, sizeof(GSource) ); + if( !pXTSource ) + { + medDebug( 1, "could not get Xt GSource" ); + return 1; + } + g_source_set_priority( pXTSource, GDK_PRIORITY_EVENTS ); + g_source_set_can_recurse( pXTSource, TRUE ); + g_source_attach( pXTSource, NULL ); + aXtPollDesc.fd = ConnectionNumber( pXtAppDisplay ); + aXtPollDesc.events = G_IO_IN; + aXtPollDesc.revents = 0; + g_source_add_poll( pXTSource, &aXtPollDesc ); + + // Initialize wakeup events listener + GSource *pWakeupSource = g_source_new( &aWakeupEventFuncs, sizeof(GSource) ); + if ( pWakeupSource == NULL ) + { + medDebug( 1, "could not get wakeup source" ); + return 1; + } + g_source_set_priority( pWakeupSource, GDK_PRIORITY_EVENTS); + g_source_attach( pWakeupSource, NULL ); + aWakeupPollDesc.fd = wakeup_fd[0]; + aWakeupPollDesc.events = G_IO_IN; + aWakeupPollDesc.revents = 0; + g_source_add_poll( pWakeupSource, &aWakeupPollDesc ); + + pAppDisplay = gdk_x11_display_get_xdisplay( gdk_display_get_default() ); + #else + pAppDisplay = pXtAppDisplay; XtAppAddInput( app_context, wakeup_fd[0], (XtPointer)XtInputReadMask, ThreadEventHandler, NULL ); - - /* - * Create windows for widgets and map them. - */ - int nWindow; - sscanf( argv[3], "%d", &nWindow ); - char pText[1024]; - sprintf( pText, "starting plugin %s ...", pAppArguments[2] ); - topBox = createSubWidget( pText, topLevel, (XLIB_Window)nWindow ); - + #endif // send that we are ready to go MediatorMessage* pMessage = @@ -351,7 +464,11 @@ int main( int argc, char **argv) // of XtAppMainLoop do { + #ifdef ENABLE_GTK + g_main_context_iteration( NULL, TRUE ); + #else XtAppProcessEvent( app_context, XtIMAll ); + #endif } while( ! XtAppGetExitFlag( app_context ) && ! bPluginAppQuit ); medDebug( 1, "left plugin app main loop\n" ); diff --git a/extensions/source/plugin/unx/plugcon.cxx b/extensions/source/plugin/unx/plugcon.cxx index 142be9b83c03..9621fcc7d6e7 100644 --- a/extensions/source/plugin/unx/plugcon.cxx +++ b/extensions/source/plugin/unx/plugcon.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: plugcon.cxx,v $ - * $Revision: 1.8 $ + * $Revision: 1.8.90.2 $ * * This file is part of OpenOffice.org. * @@ -31,42 +31,65 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_extensions.hxx" #include <plugin/unx/plugcon.hxx> + #include <cstdarg> +#include <vector> UINT32 PluginConnector::GetStreamID( NPStream* pStream ) { - for( ULONG i = 0; i < m_aNPWrapStreams.Count(); i++ ) - if( m_aNPWrapStreams.GetObject( i ) == pStream ) - return i; + size_t nLen = m_aNPWrapStreams.size(); + for( size_t i = 0; i < nLen; i++ ) + if( m_aNPWrapStreams[ i ] == pStream ) + return static_cast<UINT32>(i); medDebug( 1, "Error: NPStream has no ID\n" ); return UnknownStreamID; } UINT32 PluginConnector::GetNPPID( NPP instance ) { - for( ULONG i=0; i < m_aInstances.Count(); i++ ) - if( m_aInstances.GetObject( i )->instance == instance ) - return i; + size_t nLen = m_aInstances.size(); + for( size_t i=0; i <nLen; i++ ) + if( m_aInstances[ i ]->instance == instance ) + return static_cast<UINT32>(i); medDebug( 1, "Error: NPP has no ID\n" ); return UnknownNPPID; } +ConnectorInstance* PluginConnector::getInstance( NPP instance ) +{ + size_t nLen = m_aInstances.size(); + for( size_t i=0; i <nLen; i++ ) + { + ConnectorInstance* pInst = m_aInstances[i]; + if( pInst->instance == instance ) + return pInst; + } + return NULL; +} + +ConnectorInstance* PluginConnector::getInstanceById( UINT32 nInstanceID ) +{ + return nInstanceID < static_cast<UINT32>(m_aInstances.size()) ? m_aInstances[ nInstanceID ] : NULL; +} + struct PtrStruct { char* pData; ULONG nBytes; -}; -DECLARE_LIST( PtrStructList, PtrStruct* ) + PtrStruct( char* i_pData, ULONG i_nBytes ) + : pData( i_pData ), nBytes( i_nBytes ) {} +}; ULONG PluginConnector::FillBuffer( char*& rpBuffer, const char* pFunction, ULONG nFunctionLen, va_list ap ) { - PtrStructList aList; - PtrStruct* pPtrStruct; + std::vector< PtrStruct > aList; + aList.reserve( 5 ); + ULONG nDataSize = nFunctionLen + sizeof( ULONG ); char* pNext; @@ -74,11 +97,8 @@ ULONG PluginConnector::FillBuffer( char*& rpBuffer, pNext = va_arg( ap, char* ); if( pNext ) { - pPtrStruct = new PtrStruct; - pPtrStruct->pData = pNext; - pPtrStruct->nBytes = va_arg( ap, ULONG ); - nDataSize += pPtrStruct->nBytes + sizeof(ULONG); - aList.Insert( pPtrStruct, LIST_APPEND ); + aList.push_back( PtrStruct( pNext, va_arg( ap, ULONG ) ) ); + nDataSize += aList.back().nBytes + sizeof(ULONG); } } while( pNext ); @@ -89,13 +109,12 @@ ULONG PluginConnector::FillBuffer( char*& rpBuffer, memcpy( pRun, pFunction, nFunctionLen ); pRun += nFunctionLen; - while( (pPtrStruct = aList.Remove( (ULONG) 0 )) ) + for( std::vector<PtrStruct>::const_iterator it = aList.begin(); it != aList.end(); ++it ) { - memcpy( pRun, &pPtrStruct->nBytes, sizeof( ULONG ) ); + memcpy( pRun, &it->nBytes, sizeof( ULONG ) ); pRun += sizeof( ULONG ); - memcpy( pRun, pPtrStruct->pData, pPtrStruct->nBytes ); - pRun += pPtrStruct->nBytes; - delete pPtrStruct; + memcpy( pRun, it->pData, it->nBytes ); + pRun += it->nBytes; } return nDataSize; } @@ -157,15 +176,19 @@ MediatorMessage* PluginConnector::WaitForAnswer( ULONG nMessageID ) { { NAMESPACE_VOS(OGuard) aGuard( m_aQueueMutex ); - for( ULONG i = 0; i < m_aMessageQueue.Count(); i++ ) + for( size_t i = 0; i < m_aMessageQueue.size(); i++ ) { - ULONG nID = m_aMessageQueue.GetObject( i )->m_nID; + MediatorMessage* pMessage = m_aMessageQueue[ i ]; + ULONG nID = pMessage->m_nID; if( ( nID & 0xff000000 ) && ( ( nID & 0x00ffffff ) == nMessageID ) ) - return m_aMessageQueue.Remove( i ); + { + m_aMessageQueue.erase( m_aMessageQueue.begin() + i ); + return pMessage; + } } } - if( m_aMessageQueue.Count() ) + if( ! m_aMessageQueue.empty() ) CallWorkHandler(); WaitForMessage( 2000 ); } @@ -180,6 +203,9 @@ ConnectorInstance::ConnectorInstance( NPP inst, char* type, pShell( NULL ), pWidget( NULL ), pForm( NULL ), + pGtkWindow( NULL ), + pGtkWidget( NULL ), + bShouldUseXEmbed( false ), nArg( args ), pArgnBuf( pargnbuf ), pArgvBuf( pargvbuf ) diff --git a/extensions/source/plugin/unx/unxmgr.cxx b/extensions/source/plugin/unx/unxmgr.cxx index 5adfe6203392..ff17d1e24324 100644 --- a/extensions/source/plugin/unx/unxmgr.cxx +++ b/extensions/source/plugin/unx/unxmgr.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: unxmgr.cxx,v $ - * $Revision: 1.14 $ + * $Revision: 1.14.90.1 $ * * This file is part of OpenOffice.org. * @@ -175,6 +175,57 @@ static bool CheckPlugin( const ByteString& rPath, list< PluginDescription* >& rD return nDescriptions > 0; } +static void CheckPluginRegistryFiles( const rtl::OString& rPath, list< PluginDescription* >& rDescriptions ) +{ + rtl::OStringBuffer aPath( 1024 ); + aPath.append( rPath ); + aPath.append( "/pluginreg.dat" ); + FILE* fp = fopen( aPath.getStr(), "r" ); + if( fp ) + { +#if OSL_DEBUG_LEVEL > 1 + fprintf( stderr, "parsing %s\n", aPath.getStr() ); +#endif + char aLine[1024]; + while( fgets( aLine, sizeof( aLine ), fp ) ) + { + int nLineLen = strlen( aLine ); + int nDotPos; + for( nDotPos = nLineLen-1; nDotPos > 0 && aLine[nDotPos] != ':'; nDotPos-- ) + ; + if( aLine[0] == '/' && aLine[nDotPos] == ':' && aLine[nDotPos+1] == '$' ) + CheckPlugin( ByteString( aLine, nDotPos ), rDescriptions ); + } + fclose( fp ); + } + + // check subdirectories + long aBuffer[ sizeof( struct dirent ) + _PC_NAME_MAX +1 ]; + + DIR* pDIR = opendir( rPath.getStr() ); + struct dirent* pDirEnt = NULL; + struct stat aStat; + while( pDIR && ! readdir_r( pDIR, (struct dirent*)aBuffer, &pDirEnt ) && pDirEnt ) + { + char* pBaseName = ((struct dirent*)aBuffer)->d_name; + if( rtl_str_compare( ".", pBaseName ) && rtl_str_compare( "..", pBaseName ) ) + { + rtl::OStringBuffer aBuf( 1024 ); + aBuf.append( rPath ); + aBuf.append( '/' ); + aBuf.append( pBaseName ); + + if( ! stat( aBuf.getStr(), &aStat ) ) + { + if( S_ISDIR( aStat.st_mode ) ) + CheckPluginRegistryFiles( aBuf.makeStringAndClear(), rDescriptions ); + } + } + } + if( pDIR ) + closedir( pDIR ); +} + Sequence<PluginDescription> XPluginManager_Impl::getPluginDescriptions() throw() { static Sequence<PluginDescription> aDescriptions; @@ -240,26 +291,10 @@ Sequence<PluginDescription> XPluginManager_Impl::getPluginDescriptions() throw() } // try ~/.mozilla/pluginreg.dat - ByteString aMozPluginreg( pHome ); - aMozPluginreg.Append( "/.mozilla/pluginreg.dat" ); - FILE* fp = fopen( aMozPluginreg.GetBuffer(), "r" ); - if( fp ) - { -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "parsing %s\n", aMozPluginreg.GetBuffer() ); -#endif - char aLine[1024]; - while( fgets( aLine, sizeof( aLine ), fp ) ) - { - int nLineLen = strlen( aLine ); - int nDotPos; - for( nDotPos = nLineLen-1; nDotPos > 0 && aLine[nDotPos] != ':'; nDotPos-- ) - ; - if( aLine[0] == '/' && aLine[nDotPos] == ':' && aLine[nDotPos+1] == '$' ) - CheckPlugin( ByteString( aLine, nDotPos ), aPlugins ); - } - fclose( fp ); - } + rtl::OStringBuffer aBuf(256); + aBuf.append( pHome ); + aBuf.append( "/.mozilla" ); + CheckPluginRegistryFiles( aBuf.makeStringAndClear(), aPlugins ); // create return value aDescriptions = Sequence<PluginDescription>( aPlugins.size() ); diff --git a/extensions/source/plugin/win/winmgr.cxx b/extensions/source/plugin/win/winmgr.cxx index 3cfdc1764842..6a63ad8b5402 100644 --- a/extensions/source/plugin/win/winmgr.cxx +++ b/extensions/source/plugin/win/winmgr.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: winmgr.cxx,v $ - * $Revision: 1.16 $ + * $Revision: 1.16.90.1 $ * * This file is part of OpenOffice.org. * @@ -31,20 +31,21 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_extensions.hxx" -#include <vcl/svapp.hxx> -#include <tools/fsys.hxx> -#include <osl/mutex.hxx> +#include "vcl/svapp.hxx" +#include "tools/fsys.hxx" +#include "tools/urlobj.hxx" +#include "osl/mutex.hxx" -#include <rtl/string.hxx> -#include <rtl/ustring.hxx> -#include <rtl/ustrbuf.hxx> +#include "rtl/string.hxx" +#include "rtl/ustring.hxx" +#include "rtl/ustrbuf.hxx" -#include <plugin/impl.hxx> +#include "plugin/impl.hxx" #pragma warning (push,1) #pragma warning (disable:4005) - #include <tools/prewin.h> + #include "tools/prewin.h" #include <windows.h> #include <string.h> @@ -53,7 +54,7 @@ #include <winbase.h> #include <objbase.h> - #include <tools/postwin.h> + #include "tools/postwin.h" #pragma warning (pop) @@ -236,6 +237,52 @@ static void add_NS_lookupRecursive( HKEY hKey, PluginLocationMap & rPlugins ) } } //__________________________________________________________________________________________________ +static void add_MozPlugin( HKEY hKey, PluginLocationMap & rPlugins ) +{ + TCHAR value[MAX_PATH]; + DWORD dwType, size = sizeof(value); + + size = sizeof(value); + if (::RegQueryValueEx( + hKey, _T("Path"), NULL, &dwType, + (LPBYTE)value, &size ) == ERROR_SUCCESS && + (dwType == REG_SZ || dwType == REG_EXPAND_SZ)) + { + OUString aUPath( OStringToOUString( value, RTL_TEXTENCODING_MS_1252 ) ); + INetURLObject aURL( aUPath ); + OString aName( OUStringToOString( aURL.GetName().toAsciiLowerCase(), RTL_TEXTENCODING_MS_1252 ) ); + + // no netscape default plugin anymore... + // and no double plugin dlls + if ( !aName.equals( "npnul32.dll" ) && + ! aName.equals( "npnrvp.dll" ) && + rPlugins.find( aName ) == rPlugins.end()) + { + rPlugins[ aName ] = aUPath; +#if OSL_DEBUG_LEVEL > 1 + logPlugin( aUPath ); +#endif + } + } +} +static void add_MozillaPlugin( HKEY hKey, PluginLocationMap & rPlugins ) +{ + TCHAR keyName[MAX_PATH]; + DWORD dwIndex = 0, size = sizeof (keyName); + + while (::RegEnumKeyEx( hKey, dwIndex, keyName, &size, NULL, NULL, NULL, NULL ) == ERROR_SUCCESS) + { + size = sizeof (keyName); + HKEY hSubKey; + if (::RegOpenKeyEx( hKey, keyName, 0, KEY_READ, &hSubKey ) == ERROR_SUCCESS) + { + add_MozPlugin( hSubKey, rPlugins ); + ::RegCloseKey( hSubKey ); + } + ++dwIndex; + } +} +//__________________________________________________________________________________________________ static void add_NS_Plugins( PluginLocationMap & rPlugins ) { HKEY hKey; @@ -255,6 +302,14 @@ static void add_NS_Plugins( PluginLocationMap & rPlugins ) add_NS_lookupRecursive( hKey, rPlugins ); ::RegCloseKey( hKey ); } + // Mozilla - plugins + if (::RegOpenKeyEx( + HKEY_LOCAL_MACHINE, _T("Software\\MozillaPlugins"), + 0, KEY_READ, &hKey ) == ERROR_SUCCESS) + { + add_MozillaPlugin( hKey, rPlugins ); + ::RegCloseKey( hKey ); + } } //__________________________________________________________________________________________________ |