From 1591dec08cacf0168d6008b41671d265264a7a4d Mon Sep 17 00:00:00 2001 From: Damien Fouilleul Date: Mon, 7 Mar 2005 10:40:23 +0000 Subject: [PATCH] - activate (make visible) as soon as embedded into a container, no longer wait for container to do the activation This fixes an annoying Internet Explorer optimization which would make the activex control invisible till a user moves the mouse over it --- activex/main.cpp | 6 ++-- activex/oleobject.cpp | 38 ++++++++++++------------- activex/persistpropbag.cpp | 7 +++-- activex/persiststorage.cpp | 4 +-- activex/persiststreaminit.cpp | 4 +-- activex/plugin.cpp | 53 +++++++++++++++++++++++++++++++++-- activex/plugin.h | 4 ++- 7 files changed, 85 insertions(+), 31 deletions(-) diff --git a/activex/main.cpp b/activex/main.cpp index 258a8abddc..48ada9be5d 100644 --- a/activex/main.cpp +++ b/activex/main.cpp @@ -28,13 +28,15 @@ using namespace std; -#define THREADING_MODEL "Both" #define COMPANY_STR "VideoLAN" #define PROGRAM_STR "VLCPlugin" #define VERSION_MAJOR_STR "1" #define VERSION_MINOR_STR "0" #define DESCRIPTION "VideoLAN VLC ActiveX Plugin" +#define THREADING_MODEL "Apartment" +#define MISC_STATUS "131473" + #define PROGID_STR COMPANY_STR"."PROGRAM_STR #define VERS_PROGID_STR COMPANY_STR"."PROGRAM_STR"."VERSION_MAJOR_STR #define VERSION_STR VERSION_MAJOR_STR"."VERSION_MINOR_STR @@ -193,7 +195,7 @@ STDAPI DllRegisterServer(VOID) // MiscStatus key value hSubKey = keyCreate(hClassKey, TEXT("MiscStatus\\1")); - RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (const BYTE*)"131473", sizeof("131473")); + RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (const BYTE*)MISC_STATUS, sizeof(MISC_STATUS)); RegCloseKey(hSubKey); // Programmable key value diff --git a/activex/oleobject.cpp b/activex/oleobject.cpp index 217af46d44..509d1b342a 100644 --- a/activex/oleobject.cpp +++ b/activex/oleobject.cpp @@ -65,13 +65,7 @@ STDMETHODIMP VLCOleObject::DoVerb(LONG iVerb, LPMSG lpMsg, LPOLECLIENTSITE pActi case OLEIVERB_SHOW: case OLEIVERB_OPEN: case OLEIVERB_INPLACEACTIVATE: - if( NULL == hwndParent ) - return OLEOBJ_S_INVALIDHWND; - - if( SUCCEEDED(doInPlaceActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect)) ) - return S_OK; - - return OLEOBJ_S_CANNOT_DOVERB_NOW; + return doInPlaceActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect); case OLEIVERB_HIDE: _p_instance->setVisible(FALSE); @@ -84,13 +78,7 @@ STDMETHODIMP VLCOleObject::DoVerb(LONG iVerb, LPMSG lpMsg, LPOLECLIENTSITE pActi return S_OK; default: - if( NULL == hwndParent ) - return OLEOBJ_S_INVALIDHWND; - - if( SUCCEEDED(doInPlaceActivate(lpMsg, pActiveSite, hwndParent, lprcPosRect)) ) - return OLEOBJ_S_INVALIDVERB; - - return OLEOBJ_S_CANNOT_DOVERB_NOW; + return OLEOBJ_S_INVALIDVERB; } }; @@ -116,7 +104,7 @@ HRESULT VLCOleObject::doInPlaceActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite if( SUCCEEDED(pActiveSite->QueryInterface(IID_IOleInPlaceSite, (void**)&p_inPlaceSite)) ) { if( S_OK != p_inPlaceSite->CanInPlaceActivate() ) - return E_FAIL; + return OLEOBJ_S_CANNOT_DOVERB_NOW; LPOLEINPLACEFRAME p_inPlaceFrame; LPOLEINPLACEUIWINDOW p_inPlaceUIWindow; @@ -132,10 +120,22 @@ HRESULT VLCOleObject::doInPlaceActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite if( NULL != p_inPlaceUIWindow ) p_inPlaceUIWindow->Release(); } + + if( (NULL == hwndParent) && FAILED(p_inPlaceSite->GetWindow(&hwndParent)) ) + { + p_inPlaceSite->Release(); + return OLEOBJ_S_INVALIDHWND; + } } + else if( NULL == hwndParent ) + return OLEOBJ_S_INVALIDHWND; if( FAILED(_p_instance->onActivateInPlace(lpMsg, hwndParent, lprcPosRect, lprcClipRect)) ) - return E_FAIL; + { + if( NULL != p_inPlaceSite ) + p_inPlaceSite->Release(); + return OLEOBJ_S_CANNOT_DOVERB_NOW; + } if( NULL != p_inPlaceSite ) p_inPlaceSite->OnPosRectChange(lprcPosRect); @@ -163,7 +163,7 @@ HRESULT VLCOleObject::doInPlaceActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite } return S_OK; } - return E_FAIL; + return OLEOBJ_S_CANNOT_DOVERB_NOW; }; HRESULT VLCOleObject::doUIActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite, HWND hwndParent, LPCRECT lprcPosRect) @@ -214,7 +214,7 @@ STDMETHODIMP VLCOleObject::GetClientSite(LPOLECLIENTSITE *ppClientSite) if( NULL != _p_clientsite ) _p_clientsite->AddRef(); - *ppClientSite= _p_clientsite; + *ppClientSite = _p_clientsite; return S_OK; }; @@ -302,8 +302,8 @@ STDMETHODIMP VLCOleObject::SetClientSite(LPOLECLIENTSITE pClientSite) VariantClear(&v); } } - _p_clientsite = pClientSite; + _p_instance->onClientSiteChanged(pClientSite); return S_OK; }; diff --git a/activex/persistpropbag.cpp b/activex/persistpropbag.cpp index e1fb0ab75b..240ab3b0f0 100644 --- a/activex/persistpropbag.cpp +++ b/activex/persistpropbag.cpp @@ -24,6 +24,7 @@ #include "persistpropbag.h" #include "utils.h" +#include "oleobject.h" using namespace std; @@ -39,7 +40,7 @@ STDMETHODIMP VLCPersistPropertyBag::GetClassID(LPCLSID pClsID) STDMETHODIMP VLCPersistPropertyBag::InitNew(void) { - return _p_instance->onInitNew(); + return _p_instance->onInit(TRUE); }; STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog) @@ -47,7 +48,7 @@ STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErr if( NULL == pPropBag ) return E_POINTER; - HRESULT hr = _p_instance->onInitNew(); + HRESULT hr = _p_instance->onInit(FALSE); if( FAILED(hr) ) return hr; @@ -112,7 +113,7 @@ STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErr VariantClear(&value); } - return S_OK; + return _p_instance->onLoad(); }; STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDiry, BOOL fSaveAllProperties) diff --git a/activex/persiststorage.cpp b/activex/persiststorage.cpp index 54b17ae9f6..53d5086474 100644 --- a/activex/persiststorage.cpp +++ b/activex/persiststorage.cpp @@ -45,7 +45,7 @@ STDMETHODIMP VLCPersistStorage::InitNew(IStorage *pStg) if( NULL == pStg ) return E_POINTER; - return _p_instance->onInitNew(); + return _p_instance->onInit(TRUE); }; STDMETHODIMP VLCPersistStorage::Load(IStorage *pStg) @@ -53,7 +53,7 @@ STDMETHODIMP VLCPersistStorage::Load(IStorage *pStg) if( NULL == pStg ) return E_POINTER; - return _p_instance->onInitNew(); + return _p_instance->onInit(TRUE); }; STDMETHODIMP VLCPersistStorage::Save(IStorage *pStg, BOOL fSameAsLoad) diff --git a/activex/persiststreaminit.cpp b/activex/persiststreaminit.cpp index 4d2fd55d00..0940b29d48 100644 --- a/activex/persiststreaminit.cpp +++ b/activex/persiststreaminit.cpp @@ -37,7 +37,7 @@ STDMETHODIMP VLCPersistStreamInit::GetClassID(LPCLSID pClsID) STDMETHODIMP VLCPersistStreamInit::InitNew(void) { - return _p_instance->onInitNew(); + return _p_instance->onInit(TRUE); }; STDMETHODIMP VLCPersistStreamInit::Load(LPSTREAM pStm) @@ -45,7 +45,7 @@ STDMETHODIMP VLCPersistStreamInit::Load(LPSTREAM pStm) if( NULL == pStm ) return E_POINTER; - return _p_instance->onInitNew(); + return _p_instance->onInit(TRUE); }; STDMETHODIMP VLCPersistStreamInit::Save(LPSTREAM pStm, BOOL fClearDirty) diff --git a/activex/plugin.cpp b/activex/plugin.cpp index a419037bb3..6bd4177411 100644 --- a/activex/plugin.cpp +++ b/activex/plugin.cpp @@ -484,7 +484,9 @@ void VLCPlugin::calcPositionChange(LPRECT lprPosRect, LPCRECT lprcClipRect) } }; -HRESULT VLCPlugin::onInitNew(void) +#include + +HRESULT VLCPlugin::onInit(BOOL isNew) { if( 0 == _i_vlc ) { @@ -519,11 +521,58 @@ HRESULT VLCPlugin::onInitNew(void) _i_vlc = 0; return E_FAIL; } + + if( isNew ) + { + /* + ** object has fully initialized, + ** try to activate in place if container is ready + */ + LPOLECLIENTSITE pActiveSite; + + if( SUCCEEDED(vlcOleObject->GetClientSite(&pActiveSite)) && (NULL != pActiveSite) ) + { + vlcOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pActiveSite, 0, NULL, NULL); + pActiveSite->Release(); + } + } return S_OK; } return E_UNEXPECTED; }; - + +HRESULT VLCPlugin::onLoad(void) +{ + /* + ** object has fully initialized, + ** try to activate in place if container is ready + */ + LPOLECLIENTSITE pActiveSite; + + if( SUCCEEDED(vlcOleObject->GetClientSite(&pActiveSite)) && (NULL != pActiveSite) ) + { + vlcOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pActiveSite, 0, NULL, NULL); + pActiveSite->Release(); + } + return S_OK; +}; + +HRESULT VLCPlugin::onClientSiteChanged(LPOLECLIENTSITE pActiveSite) +{ + if( NULL != pActiveSite ) + { + /* + ** object is embedded in container + ** try to activate in place if it has initialized + */ + if( _i_vlc ) + { + vlcOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pActiveSite, 0, NULL, NULL); + } + } + return S_OK; +}; + HRESULT VLCPlugin::onClose(DWORD dwSaveOption) { if( _i_vlc ) diff --git a/activex/plugin.h b/activex/plugin.h index 7b54c02474..9ad9234886 100644 --- a/activex/plugin.h +++ b/activex/plugin.h @@ -84,7 +84,9 @@ public: REFCLSID getClassID(void) { return (REFCLSID)CLSID_VLCPlugin; }; REFIID getDispEventID(void) { return (REFIID)DIID_DVLCEvents; }; - HRESULT onInitNew(void); + HRESULT onInit(BOOL isNew); + HRESULT onLoad(void); + HRESULT onClientSiteChanged(LPOLECLIENTSITE pActiveSite); HRESULT onClose(DWORD dwSaveOption); BOOL isInPlaceActive(void); -- 2.39.5