Browse Source

now delaying initializing the plugin untill ActiveX control is ready to draw it

Arkady Trestman 16 years ago
parent
commit
1ac436a01f

+ 21 - 8
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,7 +353,21 @@ int CP3DActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
             }
         }
     }
+    return 0;
+}
+
+LRESULT CP3DActiveXCtrl::OnPandaNotification(WPARAM wParam, LPARAM lParam)
+{
+    PPInstance::HandleRequestLoop();
+
+    return 0;
+}
+
+int CP3DActiveXCtrl::Init( )
+{
+    int error( 0 );
     std::string p3dDllFilename;
+
     error = m_instance.DownloadP3DComponents( p3dDllFilename );
     if ( !error && !( p3dDllFilename.empty() ) )
     {
@@ -359,17 +378,11 @@ int CP3DActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
             m_instance.Start( m_instance.GetP3DFilename( ) );
         }
     }
-    return 0;
+    return error;
 }
 
-LRESULT CP3DActiveXCtrl::OnPandaNotification(WPARAM wParam, LPARAM lParam)
-{
-    PPInstance::HandleRequestLoop();
-
-    return 0;
-}
 
-HRESULT CP3DActiveXCtrl::ExchangeProperties(CPropExchange*  pPX)
+HRESULT CP3DActiveXCtrl::ExchangeProperties( CPropExchange*  pPX )
 {
 	USES_CONVERSION;
     HRESULT hr = E_FAIL;

+ 1 - 0
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();
 

+ 8 - 4
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<IDispatch> 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( )

+ 4 - 0
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;
 };