]> git.sesse.net Git - vlc/blob - projects/activex/plugin.h
7e6c0e770c010e3c47c15a0d51631216969a9ebc
[vlc] / projects / activex / plugin.h
1 /*****************************************************************************
2  * plugin.h: ActiveX control for VLC
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  *
6  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #ifndef __PLUGIN_H__
24 #define __PLUGIN_H__
25
26 #include <ole2.h>
27 #include <olectl.h>
28
29 #include <vlc/vlc.h>
30 #include <vlc/libvlc.h>
31
32 extern "C" const GUID CLSID_VLCPlugin;
33 extern "C" const GUID CLSID_VLCPlugin2;
34 extern "C" const GUID LIBID_AXVLC;
35 extern "C" const GUID DIID_DVLCEvents;
36
37 class VLCPluginClass : public IClassFactory
38 {
39
40 public:
41
42     VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid);
43
44     /* IUnknown methods */
45     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
46     STDMETHODIMP_(ULONG) AddRef(void);
47     STDMETHODIMP_(ULONG) Release(void);
48
49     /* IClassFactory methods */
50     STDMETHODIMP CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv);
51     STDMETHODIMP LockServer(BOOL fLock);
52
53     REFCLSID getClassID(void) { return (REFCLSID)_classid; };
54
55     LPCTSTR getInPlaceWndClassName(void) const { return TEXT("VLC Plugin In-Place"); };
56     HINSTANCE getHInstance(void) const { return _hinstance; };
57     LPPICTURE getInPlacePict(void) const
58         { if( NULL != _inplace_picture) _inplace_picture->AddRef(); return _inplace_picture; };
59
60 protected:
61
62     virtual ~VLCPluginClass();
63
64 private:
65
66     LPLONG      _p_class_ref;
67     HINSTANCE   _hinstance;
68     CLSID       _classid;
69     ATOM        _inplace_wndclass_atom;
70     LPPICTURE   _inplace_picture;
71 };
72
73 class VLCPlugin : public IUnknown
74 {
75
76 public:
77
78     VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter);
79
80     /* IUnknown methods */
81     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
82     STDMETHODIMP_(ULONG) AddRef(void);
83     STDMETHODIMP_(ULONG) Release(void);
84
85     /* custom methods */
86     HRESULT getTypeLib(LCID lcid, ITypeLib **pTL) { return LoadRegTypeLib(LIBID_AXVLC, 1, 0, lcid, pTL); };
87     REFCLSID getClassID(void) { return _p_class->getClassID(); };
88     REFIID getDispEventID(void) { return (REFIID)DIID_DVLCEvents; };
89
90     /*
91     ** persistant properties
92     */
93     void setMRL(BSTR mrl)
94     {
95         SysFreeString(_bstr_mrl);
96         _bstr_mrl = SysAllocStringLen(mrl, SysStringLen(mrl));
97         setDirty(TRUE);
98     };
99     const BSTR getMRL(void) { return _bstr_mrl; };
100
101     inline void setAutoPlay(BOOL autoplay)
102     {
103         _b_autoplay = autoplay;
104         setDirty(TRUE);
105     };
106     inline BOOL getAutoPlay(void) { return _b_autoplay; };
107
108     inline void setAutoLoop(BOOL autoloop)
109     {
110         _b_autoloop = autoloop;
111         setDirty(TRUE);
112     };
113     inline BOOL getAutoLoop(void) { return _b_autoloop;};
114
115     inline void setShowToolbar(BOOL showtoolbar)
116     {
117         _b_toolbar = showtoolbar;
118         setDirty(TRUE);
119     };
120     inline BOOL getShowToolbar(void) { return _b_toolbar;};
121
122     void setVolume(int volume);
123     int getVolume(void) { return _i_volume; };
124
125     void setBackColor(OLE_COLOR backcolor);
126     OLE_COLOR getBackColor(void) { return _i_backcolor; };
127
128     void setVisible(BOOL fVisible);
129     BOOL getVisible(void) { return _b_visible; };
130     BOOL isVisible(void) { return _b_visible || (! _b_usermode); };
131
132     inline void setStartTime(int time)
133     {
134         _i_time = time;
135         setDirty(TRUE);
136     };
137     inline int getStartTime(void) { return _i_time; };
138
139     void setTime(int time);
140     int  getTime(void) { return _i_time; };
141
142     void setBaseURL(BSTR url)
143     {
144         SysFreeString(_bstr_baseurl);
145         _bstr_baseurl = SysAllocStringLen(url, SysStringLen(url));
146         setDirty(TRUE);
147     };
148     const BSTR getBaseURL(void) { return _bstr_baseurl; };
149
150     // control size in HIMETRIC
151     inline void setExtent(const SIZEL& extent)
152     {
153         _extent = extent;
154         setDirty(TRUE);
155     };
156     const SIZEL& getExtent(void) { return _extent; };
157
158     // transient properties
159     inline void setMute(BOOL mute) { _b_mute = mute; };
160
161     inline void setPicture(LPPICTURE pict)
162     {
163         if( NULL != _p_pict )
164             _p_pict->Release();
165         if( NULL != pict )
166             _p_pict->AddRef();
167         _p_pict = pict;
168     };
169
170     inline LPPICTURE getPicture(void)
171     {
172         if( NULL != _p_pict )
173             _p_pict->AddRef();
174         return _p_pict;
175     };
176
177     BOOL hasFocus(void);
178     void setFocus(BOOL fFocus);
179
180     inline UINT getCodePage(void) { return _i_codepage; };
181     inline void setCodePage(UINT cp)
182     {
183         // accept new codepage only if it works on this system
184         size_t mblen = WideCharToMultiByte(cp,
185                 0, L"test", -1, NULL, 0, NULL, NULL);
186         if( mblen > 0 )
187             _i_codepage = cp;
188     };
189
190     inline BOOL isUserMode(void) { return _b_usermode; };
191     inline void setUserMode(BOOL um) { _b_usermode = um; };
192
193     inline BOOL isDirty(void) { return _b_dirty; };
194     inline void setDirty(BOOL dirty) { _b_dirty = dirty; };
195
196     inline BOOL isRunning(void) { return NULL != _p_libvlc; };
197     HRESULT getVLCObject(int *i_vlc);
198     HRESULT getVLC(libvlc_instance_t** p_vlc);
199     void setErrorInfo(REFIID riid, const char *description);
200
201     // control geometry within container
202     RECT getPosRect(void) { return _posRect; };
203     inline HWND getInPlaceWindow(void) const { return _inplacewnd; };
204     BOOL isInPlaceActive(void);
205
206     /*
207     ** container events
208     */
209     HRESULT onInit(void);
210     HRESULT onLoad(void);
211     HRESULT onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect);
212     HRESULT onInPlaceDeactivate(void);
213     HRESULT onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID);
214     HRESULT onClose(DWORD dwSaveOption);
215     void onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect);
216     void onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
217             HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds);
218     void onPaint(HDC hdc, const RECT &bounds, const RECT &pr);
219
220     /*
221     ** control events
222     */
223     void freezeEvents(BOOL freeze);
224     void firePropChangedEvent(DISPID dispid);
225     void fireOnPlayEvent(void);
226     void fireOnPauseEvent(void);
227     void fireOnStopEvent(void);
228
229     // controlling IUnknown interface
230     LPUNKNOWN pUnkOuter;
231
232 protected:
233
234     virtual ~VLCPlugin();
235
236 private:
237
238     //implemented interfaces
239     class VLCOleObject *vlcOleObject;
240     class VLCOleControl *vlcOleControl;
241     class VLCOleInPlaceObject *vlcOleInPlaceObject;
242     class VLCOleInPlaceActiveObject *vlcOleInPlaceActiveObject;
243     class VLCPersistStreamInit *vlcPersistStreamInit;
244     class VLCPersistStorage *vlcPersistStorage;
245     class VLCPersistPropertyBag *vlcPersistPropertyBag;
246     class VLCProvideClassInfo *vlcProvideClassInfo;
247     class VLCConnectionPointContainer *vlcConnectionPointContainer;
248     class VLCObjectSafety *vlcObjectSafety;
249     class VLCControl *vlcControl;
250     class VLCControl2 *vlcControl2;
251     class VLCViewObject *vlcViewObject;
252     class VLCDataObject *vlcDataObject;
253     class VLCSupportErrorInfo *vlcSupportErrorInfo;
254
255     // in place activated window (Plugin window)
256     HWND _inplacewnd;
257
258     VLCPluginClass* _p_class;
259     ULONG _i_ref;
260
261     libvlc_instance_t* _p_libvlc;
262     UINT _i_codepage;
263     BOOL _b_usermode;
264     RECT _posRect;
265     LPPICTURE _p_pict;
266
267     // persistable properties
268     BSTR _bstr_baseurl;
269     BSTR _bstr_mrl;
270     BOOL _b_autoplay;
271     BOOL _b_autoloop;
272     BOOL _b_toolbar;
273     BOOL _b_visible;
274     BOOL _b_mute;
275     int  _i_volume;
276     int  _i_time;
277     SIZEL _extent;
278     OLE_COLOR _i_backcolor;
279     // indicates whether properties needs persisting
280     BOOL _b_dirty;
281 };
282
283 #endif