From 1ac436a01fc3dd83d2c85eb6debfde96841fa3ec Mon Sep 17 00:00:00 2001 From: Arkady Trestman Date: Tue, 22 Sep 2009 20:23:35 +0000 Subject: [PATCH] now delaying initializing the plugin untill ActiveX control is ready to draw it --- direct/src/plugin_activex/P3DActiveXCtrl.cpp | 37 +++++++++++++------- direct/src/plugin_activex/P3DActiveXCtrl.h | 1 + direct/src/plugin_activex/PPInstance.cpp | 12 ++++--- direct/src/plugin_activex/PPInstance.h | 4 +++ 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/direct/src/plugin_activex/P3DActiveXCtrl.cpp b/direct/src/plugin_activex/P3DActiveXCtrl.cpp index 1ec6f39241..23130bf713 100644 --- a/direct/src/plugin_activex/P3DActiveXCtrl.cpp +++ b/direct/src/plugin_activex/P3DActiveXCtrl.cpp @@ -187,6 +187,11 @@ void CP3DActiveXCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInv if (!pdc) return; + if ( !m_instance.IsInit( ) ) + { + Init( ); + } + CBrush brBackGnd(TranslateColor(AmbientBackColor())); pdc->FillRect(rcBounds, &brBackGnd); @@ -348,17 +353,6 @@ int CP3DActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) } } } - std::string p3dDllFilename; - error = m_instance.DownloadP3DComponents( p3dDllFilename ); - if ( !error && !( p3dDllFilename.empty() ) ) - { - error = m_instance.LoadPlugin( p3dDllFilename ); - if ( !error ) - { - m_pPandaObject = new PPandaObject( this, NULL ); - m_instance.Start( m_instance.GetP3DFilename( ) ); - } - } return 0; } @@ -369,7 +363,26 @@ LRESULT CP3DActiveXCtrl::OnPandaNotification(WPARAM wParam, LPARAM lParam) return 0; } -HRESULT CP3DActiveXCtrl::ExchangeProperties(CPropExchange* pPX) +int CP3DActiveXCtrl::Init( ) +{ + int error( 0 ); + std::string p3dDllFilename; + + error = m_instance.DownloadP3DComponents( p3dDllFilename ); + if ( !error && !( p3dDllFilename.empty() ) ) + { + error = m_instance.LoadPlugin( p3dDllFilename ); + if ( !error ) + { + m_pPandaObject = new PPandaObject( this, NULL ); + m_instance.Start( m_instance.GetP3DFilename( ) ); + } + } + return error; +} + + +HRESULT CP3DActiveXCtrl::ExchangeProperties( CPropExchange* pPX ) { USES_CONVERSION; HRESULT hr = E_FAIL; diff --git a/direct/src/plugin_activex/P3DActiveXCtrl.h b/direct/src/plugin_activex/P3DActiveXCtrl.h index 7cb07c1629..ed03f0f554 100644 --- a/direct/src/plugin_activex/P3DActiveXCtrl.h +++ b/direct/src/plugin_activex/P3DActiveXCtrl.h @@ -74,6 +74,7 @@ public: }; afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); + int Init( ); virtual P3D_object* GetP3DObject( ); virtual IOleClientSite* GetClientSte(); diff --git a/direct/src/plugin_activex/PPInstance.cpp b/direct/src/plugin_activex/PPInstance.cpp index de972eeac6..57cd67ce3d 100644 --- a/direct/src/plugin_activex/PPInstance.cpp +++ b/direct/src/plugin_activex/PPInstance.cpp @@ -90,7 +90,7 @@ void P3D_NofificationSync(P3D_instance *instance) } PPInstance::PPInstance( CP3DActiveXCtrl& parentCtrl ) : - m_parentCtrl( parentCtrl ), m_p3dInstance( NULL ), m_p3dObject( NULL ), m_handleRequestOnUIThread( true ) + m_parentCtrl( parentCtrl ), m_p3dInstance( NULL ), m_p3dObject( NULL ), m_handleRequestOnUIThread( true ), m_isInit( false ) { TCHAR tempFolderName[ MAX_PATH ]; DWORD pathLength = ::GetTempPath( MAX_PATH, tempFolderName ); @@ -306,6 +306,7 @@ int PPInstance::UnloadPlugin() { nout << "Finalizing P3D\n"; P3D_finalize(); + m_isInit = false; nout << "Unloading P3D dll " << s_hP3DPluginDll << "\n"; if ( !::FreeLibrary( s_hP3DPluginDll ) ) @@ -355,7 +356,7 @@ int PPInstance::Start( const std::string& p3dFilename ) if ( !m_p3dInstance ) { nout << "Error creating P3D instance: " << GetLastError() << "\n"; - return 0; + return 1; } CComPtr pDispatch; PPBrowserObject *pobj = new PPBrowserObject( &m_parentCtrl, pDispatch ); @@ -374,10 +375,13 @@ int PPInstance::Start( const std::string& p3dFilename ) if ( !P3D_instance_start( m_p3dInstance, false, p3dRemoteFilename.c_str() ) ) { - nout << "Error starting P3D instance: " << GetLastError() << "\n"; + nout << "Error starting P3D instance: " << GetLastError() << "\n"; + return 1; } - return 1; + m_isInit = true; + + return 0; } std::string PPInstance::GetHostUrl( ) diff --git a/direct/src/plugin_activex/PPInstance.h b/direct/src/plugin_activex/PPInstance.h index b385dd8250..abf475d4e6 100644 --- a/direct/src/plugin_activex/PPInstance.h +++ b/direct/src/plugin_activex/PPInstance.h @@ -55,8 +55,11 @@ public: static void HandleRequestLoop(); + inline bool IsInit() { return m_isInit; } + HWND m_parentWnd; CEvent m_eventStop; + P3D_object* m_p3dObject; protected: @@ -74,4 +77,5 @@ protected: PPLogger m_logger; bool m_handleRequestOnUIThread; + bool m_isInit; };