]> git.sesse.net Git - vlc/blobdiff - activex/plugin.cpp
Removes trailing spaces. Removes tabs.
[vlc] / activex / plugin.cpp
index cc289b92459643095f3e826a738b704b0e17d1bc..4f7908271f9fc233f89bbdf6f090bb7c5f6f4020 100644 (file)
@@ -98,7 +98,7 @@ VLCPluginClass::VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID
         wClass.hbrBackground  = NULL;
         wClass.lpszMenuName   = NULL;
         wClass.lpszClassName  = getInPlaceWndClassName();
-       
+
         _inplace_wndclass_atom = RegisterClass(&wClass);
     }
     else
@@ -192,7 +192,7 @@ STDMETHODIMP VLCPluginClass::LockServer(BOOL fLock)
 {
     if( fLock )
         AddRef();
-    else 
+    else
         Release();
 
     return S_OK;
@@ -258,6 +258,7 @@ VLCPlugin::~VLCPlugin()
         _p_pict->Release();
 
     SysFreeString(_bstr_mrl);
+    SysFreeString(_bstr_baseurl);
 
     _p_class->Release();
 };
@@ -350,6 +351,7 @@ HRESULT VLCPlugin::onInit(void)
         _b_mute = FALSE;
         _i_volume = 50;
         _i_time   = 0;
+        _i_backcolor = 0;
         // set default/preferred size (320x240) pixels in HIMETRIC
         HDC hDC = CreateDevDC(NULL);
         _extent.cx = 320;
@@ -368,7 +370,7 @@ HRESULT VLCPlugin::onLoad(void)
     {
         /*
         ** try to retreive the base URL using the client site moniker, which for Internet Explorer
-        ** is the URL of the page the plugin is embedded into. 
+        ** is the URL of the page the plugin is embedded into.
         */
         LPOLECLIENTSITE pClientSite;
         if( SUCCEEDED(vlcOleObject->GetClientSite(&pClientSite)) && (NULL != pClientSite) )
@@ -428,61 +430,60 @@ HRESULT VLCPlugin::getVLC(libvlc_instance_t** pp_libvlc)
         char *ppsz_argv[32] = { "vlc" };
         int   ppsz_argc = 1;
 
-        HKEY h_key;
-        DWORD i_type, i_data = MAX_PATH + 1;
-        char p_data[MAX_PATH + 1];
-        if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
-                          0, KEY_READ, &h_key ) == ERROR_SUCCESS )
+        char p_progpath[MAX_PATH];
         {
-             if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
-                                  (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
-             {
-                 if( i_type == REG_SZ )
-                 {
-                     strcat( p_data, "\\plugins" );
-                     //ppsz_argv[ppsz_argc++] = "--plugin-path";
-                     //ppsz_argv[ppsz_argc++] = p_data;
-                 }
-             }
-             RegCloseKey( h_key );
+            TCHAR w_progpath[MAX_PATH];
+            DWORD len = GetModuleFileName(DllGetModule(), w_progpath, MAX_PATH);
+            if( len > 0 )
+            {
+                len = WideCharToMultiByte(CP_UTF8, 0, w_progpath, len, p_progpath,
+                           sizeof(p_progpath)-1, NULL, NULL);
+                if( len > 0 )
+                {
+                    p_progpath[len] = '\0';
+                    ppsz_argv[0] = p_progpath;
+                }
+            }
         }
 
-        char p_path[MAX_PATH+1];
-        DWORD len = GetModuleFileNameA(DllGetModule(), p_path, sizeof(p_path));
-        if( len > 0 )
+        ppsz_argv[ppsz_argc++] = "-vv";
+
+        HKEY h_key;
+        char p_pluginpath[MAX_PATH];
+        if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT("Software\\VideoLAN\\VLC"),
+                          0, KEY_READ, &h_key ) == ERROR_SUCCESS )
         {
-            p_path[len] = '\0';
-            ppsz_argv[0] = p_path;
+            DWORD i_type, i_data = MAX_PATH;
+            TCHAR w_pluginpath[MAX_PATH];
+            if( RegQueryValueEx( h_key, TEXT("InstallDir"), 0, &i_type,
+                                 (LPBYTE)w_pluginpath, &i_data ) == ERROR_SUCCESS )
+            {
+                if( i_type == REG_SZ )
+                {
+                    if( WideCharToMultiByte(CP_UTF8, 0, w_pluginpath, -1, p_pluginpath,
+                             sizeof(p_pluginpath)-sizeof("\\plugins")+1, NULL, NULL) )
+                    {
+                        strcat( p_pluginpath, "\\plugins" );
+                        ppsz_argv[ppsz_argc++] = "--plugin-path";
+                        ppsz_argv[ppsz_argc++] = p_pluginpath;
+                    }
+                }
+            }
+            RegCloseKey( h_key );
         }
 
         // make sure plugin isn't affected with VLC single instance mode
         ppsz_argv[ppsz_argc++] = "--no-one-instance";
 
         /* common settings */
-        ppsz_argv[ppsz_argc++] = "-vv";
         ppsz_argv[ppsz_argc++] = "--no-stats";
         ppsz_argv[ppsz_argc++] = "--no-media-library";
-        ppsz_argv[ppsz_argc++] = "--intf";
-        ppsz_argv[ppsz_argc++] = "dummy";
+        ppsz_argv[ppsz_argc++] = "--intf=dummy";
 
         // loop mode is a configuration option only
         if( _b_autoloop )
             ppsz_argv[ppsz_argc++] = "--loop";
 
-        if( IsDebuggerPresent() )
-        {
-            /*
-            ** VLC default threading mechanism is designed to be as compatible
-            ** with POSIX as possible. However when debugged on win32, threads
-            ** lose signals and eventually VLC get stuck during initialization.
-            ** threading support can be configured to be more debugging friendly
-            ** but it will be less compatible with POSIX.
-            ** This is done by initializing with the following options:
-            */
-            ppsz_argv[ppsz_argc++] = "--fast-mutex";
-            ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
-        }
-
         _p_libvlc = libvlc_new(ppsz_argc, ppsz_argv, NULL);
         if( NULL == _p_libvlc )
         {
@@ -496,7 +497,7 @@ HRESULT VLCPlugin::getVLC(libvlc_instance_t** pp_libvlc)
         {
             libvlc_audio_set_mute(_p_libvlc, TRUE, NULL);
         }
-            
+
         // initial playlist item
         if( SysStringLen(_bstr_mrl) > 0 )
         {
@@ -504,24 +505,19 @@ HRESULT VLCPlugin::getVLC(libvlc_instance_t** pp_libvlc)
 
             if( SysStringLen(_bstr_baseurl) > 0 )
             {
-                DWORD len = INTERNET_MAX_URL_LENGTH;
-                LPOLESTR abs_url = (LPOLESTR)CoTaskMemAlloc(sizeof(OLECHAR)*len);
+                /*
+                ** if the MRL a relative URL, we should end up with an absolute URL
+                */
+                LPWSTR abs_url = CombineURL(_bstr_baseurl, _bstr_mrl);
                 if( NULL != abs_url )
                 {
-                    /*
-                    ** if the MRL a relative URL, we should end up with an absolute URL
-                    */
-                    if( SUCCEEDED(UrlCombineW(_bstr_baseurl, _bstr_mrl, abs_url, &len,
-                                    URL_ESCAPE_UNSAFE|URL_PLUGGABLE_PROTOCOL)) )
-                    {
-                        psz_mrl = CStrFromBSTR(CP_UTF8, abs_url);
-                    }
-                    else
-                    {
-                        psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
-                    }
+                    psz_mrl = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
                     CoTaskMemFree(abs_url);
                 }
+                else
+                {
+                    psz_mrl = CStrFromBSTR(CP_UTF8, _bstr_mrl);
+                }
             }
             else
             {
@@ -564,6 +560,12 @@ HRESULT VLCPlugin::onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID)
     switch( dispID )
     {
         case DISPID_AMBIENT_BACKCOLOR:
+            VariantInit(&v);
+            V_VT(&v) = VT_I4;
+            if( SUCCEEDED(GetObjectProperty(pContainer, dispID, v)) )
+            {
+                setBackColor(V_I4(&v));
+            }
             break;
         case DISPID_AMBIENT_DISPLAYNAME:
             break;
@@ -648,6 +650,14 @@ HRESULT VLCPlugin::onClose(DWORD dwSaveOption)
     {
         libvlc_instance_t* p_libvlc = _p_libvlc;
 
+        IVLCLog *p_log;
+        if( SUCCEEDED(vlcControl2->get_log(&p_log)) )
+        {
+            // make sure the log is disabled
+            p_log->put_verbosity(-1);
+            p_log->Release();
+        }
+
         _p_libvlc = NULL;
         vlcDataObject->onClose();
 
@@ -667,7 +677,7 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprc
 
     /*
     ** record keeping of control geometry within container
-    */ 
+    */
     _posRect = *lprcPosRect;
 
     /*
@@ -677,7 +687,7 @@ HRESULT VLCPlugin::onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprc
     ** properly displayed.
     */
     _inplacewnd = CreateWindow(_p_class->getInPlaceWndClassName(),
-            "VLC Plugin In-Place Window",
+            TEXT("VLC Plugin In-Place Window"),
             WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
             lprcPosRect->left,
             lprcPosRect->top,
@@ -741,7 +751,7 @@ HRESULT VLCPlugin::onInPlaceDeactivate(void)
 
     DestroyWindow(_inplacewnd);
     _inplacewnd = NULL;
+
     return S_OK;
 };
 
@@ -779,6 +789,19 @@ void VLCPlugin::setVolume(int volume)
     }
 };
 
+void VLCPlugin::setBackColor(OLE_COLOR backcolor)
+{
+    if( _i_backcolor != backcolor )
+    {
+        _i_backcolor = backcolor;
+        if( isInPlaceActive() )
+        {
+
+        }
+        setDirty(TRUE);
+    }
+};
+
 void VLCPlugin::setTime(int seconds)
 {
     if( seconds < 0 )
@@ -789,11 +812,11 @@ void VLCPlugin::setTime(int seconds)
         setStartTime(_i_time);
         if( isRunning() )
         {
-            libvlc_input_t *p_input = libvlc_playlist_get_input(_p_libvlc, NULL);
-            if( NULL != p_input )
+            libvlc_media_instance_t *p_md = libvlc_playlist_get_media_instance(_p_libvlc, NULL);
+            if( NULL != p_md )
             {
-                libvlc_input_set_time(p_input, _i_time, NULL);
-                libvlc_input_free(p_input);
+                libvlc_media_instance_set_time(p_md, _i_time, NULL);
+                libvlc_media_instance_release(p_md);
             }
         }
     }
@@ -819,57 +842,80 @@ void VLCPlugin::onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
         long height = lprcBounds->bottom-lprcBounds->top;
 
         RECT bounds = { lprcBounds->left, lprcBounds->top, lprcBounds->right, lprcBounds->bottom };
-        FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
 
-        LPPICTURE pict = getPicture();
-        if( NULL != pict )
+        if( isUserMode() )
         {
-            OLE_XSIZE_HIMETRIC picWidth;
-            OLE_YSIZE_HIMETRIC picHeight;
-
-            pict->get_Width(&picWidth);
-            pict->get_Height(&picHeight);
-
-            SIZEL picSize = { picWidth, picHeight };
-
-            if( NULL != hicTargetDev )
+            /* VLC is in user mode, just draw background color */
+            COLORREF colorref = RGB(0, 0, 0);
+            OleTranslateColor(_i_backcolor, (HPALETTE)GetStockObject(DEFAULT_PALETTE), &colorref);
+            if( colorref != RGB(0, 0, 0) )
             {
-                DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
+                /* custom background */
+                HBRUSH colorbrush = CreateSolidBrush(colorref);
+                FillRect(hdcDraw, &bounds, colorbrush);
+                DeleteObject((HANDLE)colorbrush);
             }
-            else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
+            else
             {
-                DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
-                DeleteDC(hicTargetDev);
+                /* black background */
+                FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(BLACK_BRUSH));
             }
+        }
+        else
+        {
+            /* VLC is in design mode, draw the VLC logo */
+            FillRect(hdcDraw, &bounds, (HBRUSH)GetStockObject(WHITE_BRUSH));
 
-            if( picSize.cx > width-4 )
-                picSize.cx = width-4;
-            if( picSize.cy > height-4 )
-                picSize.cy = height-4;
+            LPPICTURE pict = getPicture();
+            if( NULL != pict )
+            {
+                OLE_XSIZE_HIMETRIC picWidth;
+                OLE_YSIZE_HIMETRIC picHeight;
 
-            LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
-            LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
+                pict->get_Width(&picWidth);
+                pict->get_Height(&picHeight);
 
-            if( NULL != lprcWBounds )
-            {
-                RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
-                pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
-                        0L, picHeight, picWidth, -picHeight, &wBounds);
-            }
-            else 
-                pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
-                        0L, picHeight, picWidth, -picHeight, NULL);
+                SIZEL picSize = { picWidth, picHeight };
 
-            pict->Release();
-        }
+                if( NULL != hicTargetDev )
+                {
+                    DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
+                }
+                else if( NULL != (hicTargetDev = CreateDevDC(ptd)) )
+                {
+                    DPFromHimetric(hicTargetDev, (LPPOINT)&picSize, 1);
+                    DeleteDC(hicTargetDev);
+                }
 
-        SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
+                if( picSize.cx > width-4 )
+                    picSize.cx = width-4;
+                if( picSize.cy > height-4 )
+                    picSize.cy = height-4;
 
-        MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
-        LineTo(hdcDraw, bounds.left+width-1, bounds.top);
-        LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
-        LineTo(hdcDraw, bounds.left, bounds.top+height-1);
-        LineTo(hdcDraw, bounds.left, bounds.top);
+                LONG dstX = lprcBounds->left+(width-picSize.cx)/2;
+                LONG dstY = lprcBounds->top+(height-picSize.cy)/2;
+
+                if( NULL != lprcWBounds )
+                {
+                    RECT wBounds = { lprcWBounds->left, lprcWBounds->top, lprcWBounds->right, lprcWBounds->bottom };
+                    pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
+                            0L, picHeight, picWidth, -picHeight, &wBounds);
+                }
+                else
+                    pict->Render(hdcDraw, dstX, dstY, picSize.cx, picSize.cy,
+                            0L, picHeight, picWidth, -picHeight, NULL);
+
+                pict->Release();
+            }
+
+            SelectObject(hdcDraw, GetStockObject(BLACK_BRUSH));
+
+            MoveToEx(hdcDraw, bounds.left, bounds.top, NULL);
+            LineTo(hdcDraw, bounds.left+width-1, bounds.top);
+            LineTo(hdcDraw, bounds.left+width-1, bounds.top+height-1);
+            LineTo(hdcDraw, bounds.left, bounds.top+height-1);
+            LineTo(hdcDraw, bounds.left, bounds.top);
+        }
     }
 };
 
@@ -877,8 +923,7 @@ void VLCPlugin::onPaint(HDC hdc, const RECT &bounds, const RECT &clipRect)
 {
     if( isVisible() )
     {
-        /** if VLC is playing, it may not display any VIDEO content 
-        ** hence, draw control logo*/
+        /* if VLC is in design mode, draw control logo */
         HDC hdcDraw = CreateCompatibleDC(hdc);
         if( NULL != hdcDraw )
         {
@@ -964,24 +1009,23 @@ void VLCPlugin::freezeEvents(BOOL freeze)
 
 void VLCPlugin::firePropChangedEvent(DISPID dispid)
 {
-    vlcConnectionPointContainer->firePropChangedEvent(dispid); 
+    vlcConnectionPointContainer->firePropChangedEvent(dispid);
 };
 
 void VLCPlugin::fireOnPlayEvent(void)
 {
     DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
-    vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs); 
+    vlcConnectionPointContainer->fireEvent(DISPID_PlayEvent, &dispparamsNoArgs);
 };
 
 void VLCPlugin::fireOnPauseEvent(void)
 {
     DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
-    vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs); 
+    vlcConnectionPointContainer->fireEvent(DISPID_PauseEvent, &dispparamsNoArgs);
 };
 
 void VLCPlugin::fireOnStopEvent(void)
 {
     DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
-    vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs); 
+    vlcConnectionPointContainer->fireEvent(DISPID_StopEvent, &dispparamsNoArgs);
 };
-