plugin.h 10.8 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 77
    : public IUnknown, private vlc_player_options,
      public VLCWindowsManager::InputObserver
78 79
{
public:
Damien Fouilleul's avatar
Damien Fouilleul committed
80
    VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter);
81 82
    VLCPlugin(const VLCPlugin&) = delete;
    VLCPlugin& operator=(const VLCPlugin&) = delete;
83 84 85 86 87 88 89

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

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

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

99 100 101 102 103
    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); }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

221 222
    BOOL isInPlaceActive(void);

223 224 225 226
    //VLCWindowsManager::InputObserver methods
    virtual void OnKeyEvent(UINT uKeyMsg, WPARAM wParam, LPARAM lParam) override;
    virtual void OnMouseEvent(UINT uMouseMsg, WPARAM wParam, LPARAM lParam) override;

227 228 229 230 231 232 233 234 235
    /*
    ** 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);
236
    void onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect);
Damien Fouilleul's avatar
Damien Fouilleul committed
237 238
    void onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
            HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds);
239
    void onPaint(HDC hdc, const RECT &bounds, const RECT &pr);
240

241 242 243
    /*
    ** control events
    */
Damien Fouilleul's avatar
Damien Fouilleul committed
244
    void freezeEvents(BOOL freeze);
245 246
    void firePropChangedEvent(DISPID dispid);

247
    // async events;
248 249
    void fireOnMediaPlayerNothingSpecialEvent();
    void fireOnMediaPlayerOpeningEvent();
250
    void fireOnMediaPlayerBufferingEvent(float cache);
251 252 253 254 255 256 257
    void fireOnMediaPlayerPlayingEvent();
    void fireOnMediaPlayerPausedEvent();
    void fireOnMediaPlayerForwardEvent();
    void fireOnMediaPlayerBackwardEvent();
    void fireOnMediaPlayerEncounteredErrorEvent();
    void fireOnMediaPlayerEndReachedEvent();
    void fireOnMediaPlayerStoppedEvent();
258
    void fireOnMediaPlayerStopAsyncDoneEvent();
259

260 261
    void fireOnMediaPlayerTimeChangedEvent(libvlc_time_t time);
    void fireOnMediaPlayerPositionChangedEvent(float position);
262 263
    void fireOnMediaPlayerSeekableChangedEvent(VARIANT_BOOL seekable);
    void fireOnMediaPlayerPausableChangedEvent(VARIANT_BOOL pausable);
264 265 266
    void fireOnMediaPlayerMediaChangedEvent();
    void fireOnMediaPlayerTitleChangedEvent(int title);
    void fireOnMediaPlayerLengthChangedEvent(long length);
267 268 269 270 271 272 273 274 275 276
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(3, 0, 0, 0)
    void fireOnMediaPlayerChapterChangedEvent(int chapter);
#endif

    void fireOnMediaPlayerVoutEvent(int count);
#if LIBVLC_VERSION_INT >= LIBVLC_VERSION(2, 2, 2, 0)
    void fireOnMediaPlayerMutedEvent();
    void fireOnMediaPlayerUnmutedEvent();
    void fireOnMediaPlayerAudioVolumeEvent(float volume);
#endif
277

278 279 280 281 282 283 284 285 286
    void fireClickEvent();
    void fireDblClickEvent();
    void fireMouseDownEvent(short nButton, short nShiftState, int x, int y);
    void fireMouseMoveEvent(short nButton, short nShiftState, int x, int y);
    void fireMouseUpEvent(short nButton, short nShiftState, int x, int y);
    void fireKeyDownEvent(short nChar, short nShiftState);
    void fireKeyPressEvent(short nChar);
    void fireKeyUpEvent(short nchar, short shiftState);

Damien Fouilleul's avatar
Damien Fouilleul committed
287 288 289
    // controlling IUnknown interface
    LPUNKNOWN pUnkOuter;

290 291 292 293
protected:
    virtual ~VLCPlugin();

private:
JP Dinger's avatar
JP Dinger committed
294
    void initVLC();
295
    void set_player_window();
296
    void player_register_events();
297 298 299 300 301 302 303 304 305 306 307 308

    //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;
309
    class VLCControl2 *vlcControl2;
310
    class VLCViewObject *vlcViewObject;
Damien Fouilleul's avatar
Damien Fouilleul committed
311
    class VLCDataObject *vlcDataObject;
312
    class VLCSupportErrorInfo *vlcSupportErrorInfo;
313

314
    // in place activated window (Plugin window)
315
    HWND _inplacewnd;
316
    VLCViewResources  _ViewRC;
317
    VLCWindowsManager _WindowsManager;
318

319
    VLCPluginClass* _p_class;
320 321
    ULONG _i_ref;

322
    vlc_player m_player;
JP Dinger's avatar
JP Dinger committed
323

324 325
    UINT _i_codepage;
    BOOL _b_usermode;
326
    RECT _posRect;
327
    LPPICTURE _p_pict;
328 329

    // persistable properties
330
    BSTR _bstr_baseurl;
331 332
    BSTR _bstr_mrl;
    BOOL _b_autoloop;
333
    BOOL _b_visible;
334
    BOOL _b_mute;
335
    int  _i_volume;
336
    int  _i_time;
Damien Fouilleul's avatar
Damien Fouilleul committed
337
    SIZEL _extent;
338
    OLE_COLOR _i_backcolor;
339 340
    // indicates whether properties needs persisting
    BOOL _b_dirty;
341 342 343
};

#endif