plugin.h 8.21 KB
Newer Older
1 2 3
/*****************************************************************************
 * plugin.h: ActiveX control for VLC
 *****************************************************************************
4
 * Copyright (C) 2005 the VideoLAN team
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 22 23 24 25 26 27 28
 *****************************************************************************/

#ifndef __PLUGIN_H__
#define __PLUGIN_H__

#include <ole2.h>
#include <olectl.h>

29
#include <vlc/libvlc.h>
30

31 32 33 34
extern "C" const GUID CLSID_VLCPlugin;
extern "C" const GUID CLSID_VLCPlugin2;
extern "C" const GUID LIBID_AXVLC;
extern "C" const GUID DIID_DVLCEvents;
35 36 37 38 39 40

class VLCPluginClass : public IClassFactory
{

public:

41
    VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid);
42 43 44 45 46 47 48

    /* IUnknown methods */
    STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
    STDMETHODIMP_(ULONG) AddRef(void);
    STDMETHODIMP_(ULONG) Release(void);

    /* IClassFactory methods */
Damien Fouilleul's avatar
 
Damien Fouilleul committed
49
    STDMETHODIMP CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv);
50 51
    STDMETHODIMP LockServer(BOOL fLock);

52 53
    REFCLSID getClassID(void) { return (REFCLSID)_classid; };

54
    LPCTSTR getInPlaceWndClassName(void) const { return TEXT("VLC Plugin In-Place"); };
55
    HINSTANCE getHInstance(void) const { return _hinstance; };
Damien Fouilleul's avatar
 
Damien Fouilleul committed
56 57
    LPPICTURE getInPlacePict(void) const
        { if( NULL != _inplace_picture) _inplace_picture->AddRef(); return _inplace_picture; };
58 59 60 61 62 63 64 65 66

protected:

    virtual ~VLCPluginClass();

private:

    LPLONG      _p_class_ref;
    HINSTANCE   _hinstance;
67
    CLSID       _classid;
68
    ATOM        _inplace_wndclass_atom;
Damien Fouilleul's avatar
 
Damien Fouilleul committed
69
    LPPICTURE   _inplace_picture;
70 71 72 73 74 75 76
};

class VLCPlugin : public IUnknown
{

public:

Damien Fouilleul's avatar
 
Damien Fouilleul committed
77
    VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter);
78 79 80 81 82 83 84

    /* IUnknown methods */
    STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
    STDMETHODIMP_(ULONG) AddRef(void);
    STDMETHODIMP_(ULONG) Release(void);

    /* custom methods */
85
    HRESULT getTypeLib(LCID lcid, ITypeLib **pTL) { return LoadRegTypeLib(LIBID_AXVLC, 1, 0, lcid, pTL); };
86
    REFCLSID getClassID(void) { return _p_class->getClassID(); };
87 88
    REFIID getDispEventID(void) { return (REFIID)DIID_DVLCEvents; };

89 90 91 92 93 94
    /*
    ** persistant properties
    */
    void setMRL(BSTR mrl)
    {
        SysFreeString(_bstr_mrl);
Damien Fouilleul's avatar
Damien Fouilleul committed
95
        _bstr_mrl = SysAllocStringLen(mrl, SysStringLen(mrl));
96 97 98 99 100 101 102 103 104 105 106
        setDirty(TRUE);
    };
    const BSTR getMRL(void) { return _bstr_mrl; };

    inline void setAutoPlay(BOOL autoplay)
    {
        _b_autoplay = autoplay;
        setDirty(TRUE);
    };
    inline BOOL getAutoPlay(void) { return _b_autoplay; };

107
    inline void setAutoLoop(BOOL autoloop)
108 109 110 111 112
    {
        _b_autoloop = autoloop;
        setDirty(TRUE);
    };
    inline BOOL getAutoLoop(void) { return _b_autoloop;};
113

114 115 116 117 118 119 120
    inline void setShowToolbar(BOOL showtoolbar)
    {
        _b_toolbar = showtoolbar;
        setDirty(TRUE);
    };
    inline BOOL getShowToolbar(void) { return _b_toolbar;};

121
    void setVolume(int volume);
122
    int getVolume(void) { return _i_volume; };
123

124 125 126
    void setBackColor(OLE_COLOR backcolor);
    OLE_COLOR getBackColor(void) { return _i_backcolor; };

127 128
    void setVisible(BOOL fVisible);
    BOOL getVisible(void) { return _b_visible; };
129
    BOOL isVisible(void) { return _b_visible || (! _b_usermode); };
130

131 132 133 134 135 136 137
    inline void setStartTime(int time)
    {
        _i_time = time;
        setDirty(TRUE);
    };
    inline int getStartTime(void) { return _i_time; };

138 139 140
    void setTime(int time);
    int  getTime(void) { return _i_time; };

141 142 143 144 145 146 147 148
    void setBaseURL(BSTR url)
    {
        SysFreeString(_bstr_baseurl);
        _bstr_baseurl = SysAllocStringLen(url, SysStringLen(url));
        setDirty(TRUE);
    };
    const BSTR getBaseURL(void) { return _bstr_baseurl; };

149 150 151 152 153 154 155 156
    // control size in HIMETRIC
    inline void setExtent(const SIZEL& extent)
    {
        _extent = extent;
        setDirty(TRUE);
    };
    const SIZEL& getExtent(void) { return _extent; };

157
    // transient properties
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    inline void setMute(BOOL mute) { _b_mute = mute; };

    inline void setPicture(LPPICTURE pict)
    {
        if( NULL != _p_pict )
            _p_pict->Release();
        if( NULL != pict )
            _p_pict->AddRef();
        _p_pict = pict;
    };

    inline LPPICTURE getPicture(void)
    {
        if( NULL != _p_pict )
            _p_pict->AddRef();
        return _p_pict;
    };
175

176 177 178
    BOOL hasFocus(void);
    void setFocus(BOOL fFocus);

179
    inline UINT getCodePage(void) { return _i_codepage; };
180 181 182 183 184 185 186 187
    inline void setCodePage(UINT cp)
    {
        // accept new codepage only if it works on this system
        size_t mblen = WideCharToMultiByte(cp,
                0, L"test", -1, NULL, 0, NULL, NULL);
        if( mblen > 0 )
            _i_codepage = cp;
    };
188

189 190
    inline BOOL isUserMode(void) { return _b_usermode; };
    inline void setUserMode(BOOL um) { _b_usermode = um; };
191

192 193 194
    inline BOOL isDirty(void) { return _b_dirty; };
    inline void setDirty(BOOL dirty) { _b_dirty = dirty; };

195
    inline BOOL isRunning(void) { return NULL != _p_libvlc; };
196
    HRESULT getVLCObject(int *i_vlc);
197
    HRESULT getVLC(libvlc_instance_t** p_vlc);
198
    void setErrorInfo(REFIID riid, const char *description);
199 200

    // control geometry within container
201
    RECT getPosRect(void) { return _posRect; };
202 203 204 205 206 207 208 209 210 211 212 213
    inline HWND getInPlaceWindow(void) const { return _inplacewnd; };
    BOOL isInPlaceActive(void);

    /*
    ** container events
    */
    HRESULT onInit(void);
    HRESULT onLoad(void);
    HRESULT onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect);
    HRESULT onInPlaceDeactivate(void);
    HRESULT onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID);
    HRESULT onClose(DWORD dwSaveOption);
214
    void onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect);
Damien Fouilleul's avatar
 
Damien Fouilleul committed
215 216
    void onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
            HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds);
217
    void onPaint(HDC hdc, const RECT &bounds, const RECT &pr);
218

219 220 221
    /*
    ** control events
    */
Damien Fouilleul's avatar
 
Damien Fouilleul committed
222
    void freezeEvents(BOOL freeze);
223 224 225 226 227
    void firePropChangedEvent(DISPID dispid);
    void fireOnPlayEvent(void);
    void fireOnPauseEvent(void);
    void fireOnStopEvent(void);

Damien Fouilleul's avatar
 
Damien Fouilleul committed
228 229 230
    // controlling IUnknown interface
    LPUNKNOWN pUnkOuter;

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
protected:

    virtual ~VLCPlugin();

private:

    //implemented interfaces
    class VLCOleObject *vlcOleObject;
    class VLCOleControl *vlcOleControl;
    class VLCOleInPlaceObject *vlcOleInPlaceObject;
    class VLCOleInPlaceActiveObject *vlcOleInPlaceActiveObject;
    class VLCPersistStreamInit *vlcPersistStreamInit;
    class VLCPersistStorage *vlcPersistStorage;
    class VLCPersistPropertyBag *vlcPersistPropertyBag;
    class VLCProvideClassInfo *vlcProvideClassInfo;
    class VLCConnectionPointContainer *vlcConnectionPointContainer;
    class VLCObjectSafety *vlcObjectSafety;
    class VLCControl *vlcControl;
249
    class VLCControl2 *vlcControl2;
250
    class VLCViewObject *vlcViewObject;
Damien Fouilleul's avatar
 
Damien Fouilleul committed
251
    class VLCDataObject *vlcDataObject;
252
    class VLCSupportErrorInfo *vlcSupportErrorInfo;
253

254
    // in place activated window (Plugin window)
255 256
    HWND _inplacewnd;

257
    VLCPluginClass* _p_class;
258 259
    ULONG _i_ref;

260
    libvlc_instance_t* _p_libvlc;
261 262
    UINT _i_codepage;
    BOOL _b_usermode;
263
    RECT _posRect;
264
    LPPICTURE _p_pict;
265 266

    // persistable properties
267
    BSTR _bstr_baseurl;
268 269 270
    BSTR _bstr_mrl;
    BOOL _b_autoplay;
    BOOL _b_autoloop;
271
    BOOL _b_toolbar;
272
    BOOL _b_visible;
273
    BOOL _b_mute;
274
    int  _i_volume;
275
    int  _i_time;
Damien Fouilleul's avatar
Damien Fouilleul committed
276
    SIZEL _extent;
277
    OLE_COLOR _i_backcolor;
278 279
    // indicates whether properties needs persisting
    BOOL _b_dirty;
280 281 282
};

#endif