plugin.h 9.71 KB
Newer Older
1 2 3
/*****************************************************************************
 * plugin.h: ActiveX control for VLC
 *****************************************************************************
4
 * Copyright (C) 2005-2010 the VideoLAN team
5 6
 *
 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7
 *          Jean-Paul Saman <jpsaman@videolan.org>
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * 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
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26 27 28
 *****************************************************************************/

#ifndef __PLUGIN_H__
#define __PLUGIN_H__

#include <olectl.h>

29
#include "../common/win32_fullscreen.h"
30
#include "../common/vlc_player.h"
31

32 33 34
extern "C" const GUID CLSID_VLCPlugin2;
extern "C" const GUID LIBID_AXVLC;
extern "C" const GUID DIID_DVLCEvents;
35

36 37
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

38 39 40 41 42
class VLCPluginClass : public IClassFactory
{

public:

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

    /* 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
51
    STDMETHODIMP CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv);
52 53
    STDMETHODIMP LockServer(BOOL fLock);

54 55
    REFCLSID getClassID(void) { return (REFCLSID)_classid; };

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

protected:

    virtual ~VLCPluginClass();

private:

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

75
class VLCPlugin
76
    : public IUnknown, private vlc_player_options
77 78
{
public:
Damien Fouilleul's avatar
Damien Fouilleul committed
79
    VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter);
80 81
    VLCPlugin(const VLCPlugin&) = delete;
    VLCPlugin& operator=(const VLCPlugin&) = delete;
82 83 84 85 86 87 88

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

    /* custom methods */
89
    HRESULT getTypeLib(LCID lcid, ITypeLib **pTL) { return LoadRegTypeLib(LIBID_AXVLC, 1, 0, lcid, pTL); };
90
    REFCLSID getClassID(void) { return _p_class->getClassID(); };
91 92
    REFIID getDispEventID(void) { return (REFIID)DIID_DVLCEvents; };

93 94
    vlc_player& get_player()
    {
95
        return m_player;
96 97
    }

98 99 100 101 102
    vlc_player_options& get_options()
        { return *static_cast<vlc_player_options*>(this); }
    const vlc_player_options& get_options() const
        { return *static_cast<const vlc_player_options*>(this); }

103 104 105 106 107 108
    /*
    ** persistant properties
    */
    void setMRL(BSTR mrl)
    {
        SysFreeString(_bstr_mrl);
109
        _bstr_mrl = SysAllocStringLen(mrl, SysStringLen(mrl));
110 111
        setDirty(TRUE);
    };
Rafaël Carré's avatar
Rafaël Carré committed
112
    BSTR getMRL(void) { return _bstr_mrl; };
113 114 115

    inline void setAutoPlay(BOOL autoplay)
    {
116
        set_autoplay(autoplay != FALSE);
117 118
        setDirty(TRUE);
    };
119
    inline BOOL getAutoPlay(void) { return get_autoplay()? TRUE : FALSE; };
120

121
    inline void setAutoLoop(BOOL autoloop)
122 123
    {
        _b_autoloop = autoloop;
124 125
        get_player().mlp().setPlaybackMode( autoloop ? libvlc_playback_mode_loop :
                                            libvlc_playback_mode_default );
126 127 128
        setDirty(TRUE);
    };
    inline BOOL getAutoLoop(void) { return _b_autoloop;};
129

130 131
    inline void setShowToolbar(BOOL showtoolbar)
    {
132
        set_show_toolbar(showtoolbar != FALSE);
133 134
        setDirty(TRUE);
    };
135
    inline BOOL getShowToolbar(void) { return get_show_toolbar() ? TRUE : FALSE; };
136

137
    void setVolume(int volume);
138
    int getVolume(void) { return _i_volume; };
139

140 141 142
    void setBackColor(OLE_COLOR backcolor);
    OLE_COLOR getBackColor(void) { return _i_backcolor; };

143 144
    void setVisible(BOOL fVisible);
    BOOL getVisible(void) { return _b_visible; };
145
    BOOL isVisible(void) { return _b_visible || (! _b_usermode); };
146

147 148 149 150 151 152 153
    inline void setStartTime(int time)
    {
        _i_time = time;
        setDirty(TRUE);
    };
    inline int getStartTime(void) { return _i_time; };

154 155 156
    void setTime(int time);
    int  getTime(void) { return _i_time; };

157 158 159 160 161 162
    void setBaseURL(BSTR url)
    {
        SysFreeString(_bstr_baseurl);
        _bstr_baseurl = SysAllocStringLen(url, SysStringLen(url));
        setDirty(TRUE);
    };
Rafaël Carré's avatar
Rafaël Carré committed
163
    BSTR getBaseURL(void) { return _bstr_baseurl; };
164

165 166 167 168 169 170 171 172
    // control size in HIMETRIC
    inline void setExtent(const SIZEL& extent)
    {
        _extent = extent;
        setDirty(TRUE);
    };
    const SIZEL& getExtent(void) { return _extent; };

173
    // transient properties
174
    void setMute(BOOL mute);
175 176 177 178 179 180

    inline void setPicture(LPPICTURE pict)
    {
        if( NULL != _p_pict )
            _p_pict->Release();
        if( NULL != pict )
181
            pict->AddRef();
182 183 184 185 186 187 188 189 190
        _p_pict = pict;
    };

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

192 193 194
    BOOL hasFocus(void);
    void setFocus(BOOL fFocus);

195
    inline UINT getCodePage(void) { return _i_codepage; };
196 197 198 199 200 201 202 203
    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;
    };
204

205 206
    inline BOOL isUserMode(void) { return _b_usermode; };
    inline void setUserMode(BOOL um) { _b_usermode = um; };
207

208 209 210
    inline BOOL isDirty(void) { return _b_dirty; };
    inline void setDirty(BOOL dirty) { _b_dirty = dirty; };

211
    void setErrorInfo(REFIID riid, const char *description);
212 213

    // control geometry within container
214
    RECT getPosRect(void) { return _posRect; };
215
    inline HWND getInPlaceWindow(void) const { return _inplacewnd; };
216
    void toggleFullscreen();
217 218
    void setFullscreen(BOOL yes);
    BOOL getFullscreen();
219

220 221 222 223 224 225 226 227 228 229 230
    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);
231
    void onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect);
Damien Fouilleul's avatar
Damien Fouilleul committed
232 233
    void onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
            HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds);
234
    void onPaint(HDC hdc, const RECT &bounds, const RECT &pr);
235

236 237 238
    /*
    ** control events
    */
Damien Fouilleul's avatar
Damien Fouilleul committed
239
    void freezeEvents(BOOL freeze);
240 241
    void firePropChangedEvent(DISPID dispid);

242
    // async events;
243 244
    void fireOnMediaPlayerNothingSpecialEvent();
    void fireOnMediaPlayerOpeningEvent();
245
    void fireOnMediaPlayerBufferingEvent(float cache);
246 247 248 249 250 251 252 253
    void fireOnMediaPlayerPlayingEvent();
    void fireOnMediaPlayerPausedEvent();
    void fireOnMediaPlayerForwardEvent();
    void fireOnMediaPlayerBackwardEvent();
    void fireOnMediaPlayerEncounteredErrorEvent();
    void fireOnMediaPlayerEndReachedEvent();
    void fireOnMediaPlayerStoppedEvent();

254 255
    void fireOnMediaPlayerTimeChangedEvent(libvlc_time_t time);
    void fireOnMediaPlayerPositionChangedEvent(float position);
256 257
    void fireOnMediaPlayerSeekableChangedEvent(VARIANT_BOOL seekable);
    void fireOnMediaPlayerPausableChangedEvent(VARIANT_BOOL pausable);
258 259 260
    void fireOnMediaPlayerMediaChangedEvent();
    void fireOnMediaPlayerTitleChangedEvent(int title);
    void fireOnMediaPlayerLengthChangedEvent(long length);
261

Damien Fouilleul's avatar
Damien Fouilleul committed
262 263 264
    // controlling IUnknown interface
    LPUNKNOWN pUnkOuter;

265 266 267 268
protected:
    virtual ~VLCPlugin();

private:
JP Dinger's avatar
JP Dinger committed
269
    void initVLC();
270
    void set_player_window();
271
    void player_register_events();
272 273 274 275 276 277 278 279 280 281 282 283

    //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;
284
    class VLCControl2 *vlcControl2;
285
    class VLCViewObject *vlcViewObject;
Damien Fouilleul's avatar
Damien Fouilleul committed
286
    class VLCDataObject *vlcDataObject;
287
    class VLCSupportErrorInfo *vlcSupportErrorInfo;
288

289
    // in place activated window (Plugin window)
290
    HWND _inplacewnd;
291
    VLCViewResources  _ViewRC;
292
    VLCWindowsManager _WindowsManager;
293

294
    VLCPluginClass* _p_class;
295 296
    ULONG _i_ref;

297
    vlc_player m_player;
JP Dinger's avatar
JP Dinger committed
298

299 300
    UINT _i_codepage;
    BOOL _b_usermode;
301
    RECT _posRect;
302
    LPPICTURE _p_pict;
303 304

    // persistable properties
305
    BSTR _bstr_baseurl;
306 307
    BSTR _bstr_mrl;
    BOOL _b_autoloop;
308
    BOOL _b_visible;
309
    BOOL _b_mute;
310
    int  _i_volume;
311
    int  _i_time;
Damien Fouilleul's avatar
Damien Fouilleul committed
312
    SIZEL _extent;
313
    OLE_COLOR _i_backcolor;
314 315
    // indicates whether properties needs persisting
    BOOL _b_dirty;
316 317 318
};

#endif