]> git.sesse.net Git - vlc/commitdiff
all: clean-up, bug fixes so that plugin is now working correctly with Visual Basic...
authorDamien Fouilleul <damienf@videolan.org>
Mon, 27 Jun 2005 11:41:16 +0000 (11:41 +0000)
committerDamien Fouilleul <damienf@videolan.org>
Mon, 27 Jun 2005 11:41:16 +0000 (11:41 +0000)
Outstanding issue: the control properties are not persisted

vlc16x16.bmp: toolbar icon for VLC plugin

12 files changed:
activex/Makefile.am
activex/axvlc_rc.rc
activex/main.cpp
activex/oleobject.cpp
activex/persistpropbag.cpp
activex/persiststorage.cpp
activex/persiststreaminit.cpp
activex/plugin.cpp
activex/plugin.h
activex/utils.h
activex/viewobject.cpp
activex/vlc16x16.bmp [new file with mode: 0644]

index 80ac888bb54ff8b2b9faa830a6c7e21ee2be1248..cceef8be1dbe460066017ac390ffab9f3b3e4f6f 100644 (file)
@@ -52,6 +52,7 @@ DIST_misc = \
     axvlc.idl \
     axvlc.tlb \
     inplace.bmp \
+    vlc16x16.bmp \
     test.html \
     $(NULL)
 
index 1ee8e9e913110e2f156b33e934b555e7f30102e5..8bb30b1075697e7ecd1a2c43bb4e3754ea941dfe 100644 (file)
@@ -8,6 +8,7 @@
 #define STRINGIFY( z ) UGLY_KLUDGE( z )
 #define UGLY_KLUDGE( z ) #z
 
+1 BITMAP "vlc16x16.bmp"
 1 VERSIONINFO
 FILETYPE 1
 FILEOS 4
index 3a407dd62e5159d71b761ba7d92c64cf6f2038bc..8ac7e1e2449dd30949c5e43a2b8f5343241bd333 100644 (file)
@@ -186,6 +186,14 @@ STDAPI DllRegisterServer(VOID)
         hSubKey = keyCreate(hClassKey, TEXT("Control"));
         RegCloseKey(hSubKey);
 
+        // ToolboxBitmap32 key value
+        hSubKey = keyCreate(hClassKey, TEXT("ToolboxBitmap32"));
+        strcpy(DllPath+DllPathLen, ",1");
+        RegSetValueEx(hSubKey, NULL, 0, REG_SZ,
+                (const BYTE*)DllPath, DllPathLen+2);
+        DllPath[DllPathLen] = '\0';
+        RegCloseKey(hSubKey);
+
 #ifdef BUILD_LOCALSERVER
         // LocalServer32 key value
         hSubKey = keyCreate(hClassKey, TEXT("LocalServer32"));
index ec7d8aedbefbaa66ac04a8888642d9040c8c1d8e..bf6a76246fc12c88c90688fe2b3d38b94828e656 100644 (file)
@@ -56,9 +56,6 @@ STDMETHODIMP VLCOleObject::Close(DWORD dwSaveOption)
 STDMETHODIMP VLCOleObject::DoVerb(LONG iVerb, LPMSG lpMsg, LPOLECLIENTSITE pActiveSite,
                                     LONG lIndex, HWND hwndParent, LPCRECT lprcPosRect)
 {
-    if( 0 != lIndex )
-        return DV_E_LINDEX;
-
     switch( iVerb )
     {
         case OLEIVERB_PRIMARY:
@@ -104,7 +101,9 @@ HRESULT VLCOleObject::doInPlaceActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite
         if( SUCCEEDED(pActiveSite->QueryInterface(IID_IOleInPlaceSite, (void**)&p_inPlaceSite)) )
         {
             if( S_OK != p_inPlaceSite->CanInPlaceActivate() )
+            {
                 return OLEOBJ_S_CANNOT_DOVERB_NOW;
+            }
 
             LPOLEINPLACEFRAME p_inPlaceFrame;
             LPOLEINPLACEUIWINDOW p_inPlaceUIWindow;
@@ -128,7 +127,9 @@ HRESULT VLCOleObject::doInPlaceActivate(LPMSG lpMsg, LPOLECLIENTSITE pActiveSite
             }
         }
         else if( NULL == hwndParent )
+        {
             return OLEOBJ_S_INVALIDHWND;
+        }
 
         if( FAILED(_p_instance->onActivateInPlace(lpMsg, hwndParent, lprcPosRect, lprcClipRect)) )
         {
@@ -293,8 +294,6 @@ STDMETHODIMP VLCOleObject::IsUpToDate(void)
 
 STDMETHODIMP VLCOleObject::SetClientSite(LPOLECLIENTSITE pClientSite)
 {
-    if( NULL != _p_clientsite )
-        _p_clientsite->Release(); 
  
     if( NULL != pClientSite )
     {
@@ -312,8 +311,13 @@ STDMETHODIMP VLCOleObject::SetClientSite(LPOLECLIENTSITE pClientSite)
             VariantClear(&v);
         }
     }
+
+    if( NULL != _p_clientsite )
+        _p_clientsite->Release();
+
     _p_clientsite = pClientSite;
     _p_instance->onClientSiteChanged(pClientSite);
+
     return S_OK;
 };
 
@@ -337,30 +341,18 @@ STDMETHODIMP VLCOleObject::SetExtent(DWORD dwDrawAspect, SIZEL *pSizel)
 
             if( SUCCEEDED(_p_clientsite->QueryInterface(IID_IOleInPlaceSite, (void**)&p_inPlaceSite)) )
             {
-                LPOLECONTROLSITE p_controlSite;
-                RECT posRect = _p_instance->getPosRect();
+                HWND hwnd;
 
-                if( SUCCEEDED(_p_clientsite->QueryInterface(IID_IOleControlSite, (void**)&p_controlSite)) )
+                if( SUCCEEDED(p_inPlaceSite->GetWindow(&hwnd)) )
                 {
-                    // use HIMETRIC to container transform
-                    POINTL extent = { pSizel->cx, pSizel->cy };
-                    POINTF container;
-                    if( SUCCEEDED(p_controlSite->TransformCoords(&extent,
-                                    &container, XFORMCOORDS_SIZE|XFORMCOORDS_HIMETRICTOCONTAINER)) )
-                    {
-                        posRect.right  = ((LONG)container.x)+posRect.left;
-                        posRect.bottom = ((LONG)container.y)+posRect.top;
-                    }
-                    p_controlSite->Release();
-                }
-                else {
-                    // use HIMETRIC to display transform 
-                    HDC hDC = CreateDevDC(NULL);
+                    // use HIMETRIC to pixel transform 
+                    RECT posRect = _p_instance->getPosRect();
+                    HDC hDC = GetDC(hwnd);
                     posRect.right = (pSizel->cx*GetDeviceCaps(hDC, LOGPIXELSX)/2540L)+posRect.left;
                     posRect.bottom = (pSizel->cy*GetDeviceCaps(hDC, LOGPIXELSY)/2540L)+posRect.top;
                     DeleteDC(hDC);
+                    p_inPlaceSite->OnPosRectChange(&posRect);
                 }
-                p_inPlaceSite->OnPosRectChange(&posRect);
                 p_inPlaceSite->Release();
             }
         }
index c92f5129ee4a0af4f2d684beac303e5a1d33e6dd..52b928b5c693c1ff1343b9ee36b2e817520775c4 100644 (file)
@@ -40,7 +40,7 @@ STDMETHODIMP VLCPersistPropertyBag::GetClassID(LPCLSID pClsID)
 
 STDMETHODIMP VLCPersistPropertyBag::InitNew(void)
 {
-    return _p_instance->onInit(TRUE);
+    return _p_instance->onInit();
 };
 
 STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog)
@@ -48,7 +48,7 @@ STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErr
     if( NULL == pPropBag )
         return E_POINTER;
 
-    HRESULT hr = _p_instance->onInit(FALSE);
+    HRESULT hr = _p_instance->onInit();
     if( FAILED(hr) )
         return hr;
 
index 53d508647484cd955774068e1852e20853187060..e097e6ebb0e41ec1d1533ec254db930506d4bbea 100644 (file)
@@ -45,7 +45,7 @@ STDMETHODIMP VLCPersistStorage::InitNew(IStorage *pStg)
     if( NULL == pStg )
         return E_POINTER;
 
-    return _p_instance->onInit(TRUE);
+    return _p_instance->onInit();
 };
 
 STDMETHODIMP VLCPersistStorage::Load(IStorage *pStg)
@@ -53,7 +53,7 @@ STDMETHODIMP VLCPersistStorage::Load(IStorage *pStg)
     if( NULL == pStg )
         return E_POINTER;
 
-    return _p_instance->onInit(TRUE);
+    return _p_instance->onInit();
 };
 
 STDMETHODIMP VLCPersistStorage::Save(IStorage *pStg, BOOL fSameAsLoad)
index 0940b29d4880ad1cb9486d1cc1582e37870cb2c4..c640c2b920837528dcb221f415dae8c7bcf319d8 100644 (file)
@@ -37,7 +37,7 @@ STDMETHODIMP VLCPersistStreamInit::GetClassID(LPCLSID pClsID)
 
 STDMETHODIMP VLCPersistStreamInit::InitNew(void)
 {
-    return _p_instance->onInit(TRUE);
+    return _p_instance->onInit();
 };
 
 STDMETHODIMP VLCPersistStreamInit::Load(LPSTREAM pStm)
@@ -45,7 +45,7 @@ STDMETHODIMP VLCPersistStreamInit::Load(LPSTREAM pStm)
     if( NULL == pStm )
         return E_POINTER;
 
-    return _p_instance->onInit(TRUE);
+    return _p_instance->onInit();
 };
 
 STDMETHODIMP VLCPersistStreamInit::Save(LPSTREAM pStm, BOOL fClearDirty)
index 057ea88ea16da78790a7c56475ca6bbe6e53cf58..deec1f11284b36de2853540023009699ec037d76 100644 (file)
@@ -34,6 +34,7 @@
 #include "objectsafety.h"
 #include "vlccontrol.h"
 #include "viewobject.h"
+#include "dataobject.h"
 
 #include "utils.h"
 
@@ -510,7 +511,7 @@ static void getViewportCoords(LPRECT lprPosRect, LPRECT lprClipRect)
     *lprPosRect  = bounds;
 };
 
-HRESULT VLCPlugin::onInit(BOOL isNew)
+HRESULT VLCPlugin::onInit(void)
 {
     if( 0 == _i_vlc )
     {
@@ -549,21 +550,6 @@ HRESULT VLCPlugin::onInit(BOOL isNew)
             _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;
@@ -571,16 +557,20 @@ HRESULT VLCPlugin::onInit(BOOL isNew)
 
 HRESULT VLCPlugin::onLoad(void)
 {
-    /*
-    ** object has fully initialized,
-    ** try to activate in place if container is ready
-    */
-    LPOLECLIENTSITE pActiveSite;
+    if( _b_mute )
+        VLC_VolumeMute(_i_vlc);
 
-    if( SUCCEEDED(vlcOleObject->GetClientSite(&pActiveSite)) && (NULL != pActiveSite) )
+    if( NULL != _psz_src )
     {
-        vlcOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, pActiveSite, 0, NULL, NULL);
-        pActiveSite->Release();
+        // add default target to playlist
+        char *cOptions[1];
+        int  cOptionsCount = 0;
+
+        if( _b_loopmode )
+        {
+            cOptions[cOptionsCount++] = "loop";
+        }
+        VLC_AddTarget(_i_vlc, _psz_src, (const char **)&cOptions, cOptionsCount, PLAYLIST_APPEND, PLAYLIST_END);
     }
     return S_OK;
 };
@@ -694,23 +684,10 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprc
     val.i_int = reinterpret_cast<int>(_videownd);
     VLC_VariableSet(_i_vlc, "drawable", val);
 
-    if( NULL != _psz_src )
+    if( _b_autostart & (VLC_PlaylistNumberOfItems(_i_vlc) > 0) )
     {
-        // add target to playlist
-        char *cOptions[1];
-        int  cOptionsCount = 0;
-
-        if( _b_loopmode )
-        {
-            cOptions[cOptionsCount++] = "loop";
-        }
-        VLC_AddTarget(_i_vlc, _psz_src, (const char **)&cOptions, cOptionsCount, PLAYLIST_APPEND, PLAYLIST_END);
-
-        if( _b_autostart )
-        {
-            VLC_Play(_i_vlc);
-            fireOnPlayEvent();
-        }
+        VLC_Play(_i_vlc);
+        fireOnPlayEvent();
     }
     return S_OK;
 };
@@ -749,50 +726,53 @@ BOOL VLCPlugin::hasFocus(void)
 
 void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &pr)
 {
-    /*
-    ** if VLC is playing, it may not display any VIDEO content 
-    ** hence, draw control logo
-    */ 
-    int width = bounds.right-bounds.left;
-    int height = bounds.bottom-bounds.top;
-
-    HBITMAP pict = _p_class->getInPlacePict();
-    if( NULL != pict )
+    if( getVisible() )
     {
-        HDC hdcPict = CreateCompatibleDC(hdc);
-        if( NULL != hdcPict )
+        /*
+        ** if VLC is playing, it may not display any VIDEO content 
+        ** hence, draw control logo
+        */ 
+        int width = bounds.right-bounds.left;
+        int height = bounds.bottom-bounds.top;
+
+        HBITMAP pict = _p_class->getInPlacePict();
+        if( NULL != pict )
         {
-            BITMAP bm;
-            if( GetObject(pict, sizeof(BITMAPINFO), &bm) )
+            HDC hdcPict = CreateCompatibleDC(hdc);
+            if( NULL != hdcPict )
             {
-                int dstWidth = bm.bmWidth;
-                if( dstWidth > width-4 )
-                    dstWidth = width-4;
-
-                int dstHeight = bm.bmHeight;
-                if( dstHeight > height-4 )
-                    dstHeight = height-4;
-
-                int dstX = bounds.left+(width-dstWidth)/2;
-                int dstY = bounds.top+(height-dstHeight)/2;
-
-                SelectObject(hdcPict, pict);
-                StretchBlt(hdc, dstX, dstY, dstWidth, dstHeight,
-                        hdcPict, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
-                DeleteDC(hdcPict);
-                ExcludeClipRect(hdc, dstX, dstY, dstWidth+dstX, dstHeight+dstY);
+                BITMAP bm;
+                if( GetObject(pict, sizeof(BITMAPINFO), &bm) )
+                {
+                    int dstWidth = bm.bmWidth;
+                    if( dstWidth > width-4 )
+                        dstWidth = width-4;
+
+                    int dstHeight = bm.bmHeight;
+                    if( dstHeight > height-4 )
+                        dstHeight = height-4;
+
+                    int dstX = bounds.left+(width-dstWidth)/2;
+                    int dstY = bounds.top+(height-dstHeight)/2;
+
+                    SelectObject(hdcPict, pict);
+                    StretchBlt(hdc, dstX, dstY, dstWidth, dstHeight,
+                            hdcPict, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
+                    DeleteDC(hdcPict);
+                    ExcludeClipRect(hdc, dstX, dstY, dstWidth+dstX, dstHeight+dstY);
+                }
             }
         }
-    }
 
-    FillRect(hdc, &pr, (HBRUSH)GetStockObject(WHITE_BRUSH));
-    SelectObject(hdc, GetStockObject(BLACK_BRUSH));
+        FillRect(hdc, &pr, (HBRUSH)GetStockObject(WHITE_BRUSH));
+        SelectObject(hdc, GetStockObject(BLACK_BRUSH));
 
-    MoveToEx(hdc, bounds.left, bounds.top, NULL);
-    LineTo(hdc, bounds.left+width-1, bounds.top);
-    LineTo(hdc, bounds.left+width-1, bounds.top+height-1);
-    LineTo(hdc, bounds.left, bounds.top+height-1);
-    LineTo(hdc, bounds.left, bounds.top);
+        MoveToEx(hdc, bounds.left, bounds.top, NULL);
+        LineTo(hdc, bounds.left+width-1, bounds.top);
+        LineTo(hdc, bounds.left+width-1, bounds.top+height-1);
+        LineTo(hdc, bounds.left, bounds.top+height-1);
+        LineTo(hdc, bounds.left, bounds.top);
+    }
 };
 
 void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
@@ -800,9 +780,16 @@ void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
     RECT clipRect = *lprcClipRect;
     RECT posRect  = *lprcPosRect;
 
+    /*
+    ** tell container that previous area needs redrawing
+    */
+
+    InvalidateRect(GetParent(_inplacewnd), &_posRect, TRUE);
+
     /*
     ** record keeping of control geometry within container
-    */ 
+    */
+
     _posRect = posRect;
 
     /*
@@ -830,7 +817,6 @@ void VLCPlugin::onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect)
             posRect.bottom-posRect.top,
             FALSE);
 
-
     /*
     ** force a full refresh of control content
     */
index dd029891239b71ca6a2cd26f239575601bb72f09..e9e7206c3305d800b71504703d0c4d9de71015f5 100644 (file)
@@ -84,7 +84,7 @@ public:
     REFCLSID getClassID(void) { return (REFCLSID)CLSID_VLCPlugin; };
     REFIID getDispEventID(void) { return (REFIID)DIID_DVLCEvents; };
 
-    HRESULT onInit(BOOL isNew);
+    HRESULT onInit(void);
     HRESULT onLoad(void);
     HRESULT onClientSiteChanged(LPOLECLIENTSITE pActiveSite);
     HRESULT onClose(DWORD dwSaveOption);
@@ -102,20 +102,14 @@ public:
 
     int  getVLCObject(void) { return _i_vlc; };
 
-    // control properties
+    // persistent control properties, may be overriden by HTML & javascript
     void setSourceURL(const char *url) { _psz_src = strdup(url); };
     void setAutoStart(BOOL autostart) { _b_autostart = autostart; };
     void setLoopMode(BOOL loopmode) { _b_loopmode = loopmode; };
-    void setMute(BOOL mute) {
-        if( mute && _i_vlc )
-        {
-            VLC_VolumeMute(_i_vlc);
-        }
-    };
+    void setMute(BOOL mute) { _b_mute = mute; };
     void setSendEvents(BOOL sendevents) { _b_sendevents = sendevents; };
     void setVisible(BOOL fVisible);
     BOOL getVisible(void) { return _b_visible; };
-
     
     // container events
     void onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect);
@@ -167,6 +161,7 @@ private:
     BOOL _b_autostart;
     BOOL _b_loopmode;
     BOOL _b_visible;
+    BOOL _b_mute;
     BOOL _b_sendevents;
     int  _i_vlc;
 
index f63c387aaae1fda7522128046aa03a57ae0ee0df..c0648cd0557ddc65e50f85149844a4cbc3177cdd 100644 (file)
@@ -60,7 +60,6 @@ public:
     STDMETHODIMP Reset(void);
     // cloning is implemented by subclasses and must use copy constructor
     //STDMETHODIMP Clone(VLCEnum<T> **);
-    // cloning is implemented by subclasses and must use copy constructor
 
     typedef void (*retainer)(T);
 
index a0c51138e5317c8e33caf1d5de1df413f1d008c0..4cd39c4bebbf7944b3a49acb3ed142995985a8b5 100644 (file)
@@ -33,15 +33,12 @@ STDMETHODIMP VLCViewObject::Draw(DWORD dwAspect, LONG lindex, PVOID pvAspect,
 {
     if( dwAspect & DVASPECT_CONTENT )
     {
-        if( _p_instance->getVisible() )
-        {
-            RECT bounds;
-            bounds.left   = lprcBounds->left;
-            bounds.top    = lprcBounds->top;
-            bounds.right  = lprcBounds->right;
-            bounds.bottom = lprcBounds->bottom;
-            _p_instance->onPaint(hdcDraw, bounds, bounds);
-        }
+        RECT bounds;
+        bounds.left   = lprcBounds->left;
+        bounds.top    = lprcBounds->top;
+        bounds.right  = lprcBounds->right;
+        bounds.bottom = lprcBounds->bottom;
+        _p_instance->onPaint(hdcDraw, bounds, bounds);
         return S_OK;
     }
     return E_NOTIMPL;
@@ -84,21 +81,22 @@ STDMETHODIMP VLCViewObject::GetColorSet(DWORD dwAspect, LONG lindex,
 STDMETHODIMP VLCViewObject::SetAdvise(DWORD dwAspect, DWORD advf,
         LPADVISESINK pAdvSink)
 {
-    _dwAspect = dwAspect;
-    _advf = advf;
+
+    if( NULL != pAdvSink )
+        pAdvSink->AddRef();
+
     if( NULL != _pAdvSink )
         _pAdvSink->Release();
 
+    _dwAspect = dwAspect;
+    _advf = advf;
     _pAdvSink = pAdvSink;
-    if( NULL != pAdvSink )
-    {
-        pAdvSink->AddRef();
 
-        if( dwAspect & DVASPECT_CONTENT )
-        {
-            pAdvSink->OnViewChange(DVASPECT_CONTENT, -1);
-        }
+    if( (dwAspect & DVASPECT_CONTENT) && (advf & ADVF_PRIMEFIRST) && (NULL != _pAdvSink) )
+    {
+        _pAdvSink->OnViewChange(DVASPECT_CONTENT, -1);
     }
+
     return S_OK;
 };
 
diff --git a/activex/vlc16x16.bmp b/activex/vlc16x16.bmp
new file mode 100644 (file)
index 0000000..fbfbdd1
Binary files /dev/null and b/activex/vlc16x16.bmp differ