]> git.sesse.net Git - vlc/blob - projects/activex/plugin.h
Merge branch 'master' of git@git.videolan.org:vlc
[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/libvlc.h>
30
31 extern "C" const GUID CLSID_VLCPlugin;
32 extern "C" const GUID CLSID_VLCPlugin2;
33 extern "C" const GUID LIBID_AXVLC;
34 extern "C" const GUID DIID_DVLCEvents;
35
36 class VLCPluginClass : public IClassFactory
37 {
38
39 public:
40
41     VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid);
42
43     /* IUnknown methods */
44     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
45     STDMETHODIMP_(ULONG) AddRef(void);
46     STDMETHODIMP_(ULONG) Release(void);
47
48     /* IClassFactory methods */
49     STDMETHODIMP CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv);
50     STDMETHODIMP LockServer(BOOL fLock);
51
52     REFCLSID getClassID(void) { return (REFCLSID)_classid; };
53
54     LPCTSTR getInPlaceWndClassName(void) const { return TEXT("VLC Plugin In-Place"); };
55     HINSTANCE getHInstance(void) const { return _hinstance; };
56     LPPICTURE getInPlacePict(void) const
57         { if( NULL != _inplace_picture) _inplace_picture->AddRef(); return _inplace_picture; };
58
59 protected:
60
61     virtual ~VLCPluginClass();
62
63 private:
64
65     LPLONG      _p_class_ref;
66     HINSTANCE   _hinstance;
67     CLSID       _classid;
68     ATOM        _inplace_wndclass_atom;
69     LPPICTURE   _inplace_picture;
70 };
71
72 class VLCPlugin : public IUnknown
73 {
74
75 public:
76
77     VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter);
78
79     /* IUnknown methods */
80     STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
81     STDMETHODIMP_(ULONG) AddRef(void);
82     STDMETHODIMP_(ULONG) Release(void);
83
84     /* 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     REFIID getDispEventID(void) { return (REFIID)DIID_DVLCEvents; };
88
89     /*
90     ** persistant properties
91     */
92     void setMRL(BSTR mrl)
93     {
94         SysFreeString(_bstr_mrl);
95         _bstr_mrl = SysAllocStringLen(mrl, SysStringLen(mrl));
96         setDirty(TRUE);
97     };
98     const BSTR getMRL(void) { return _bstr_mrl; };
99
100     inline void setAutoPlay(BOOL autoplay)
101     {
102         _b_autoplay = autoplay;
103         setDirty(TRUE);
104     };
105     inline BOOL getAutoPlay(void) { return _b_autoplay; };
106
107     inline void setAutoLoop(BOOL autoloop)
108     {
109         _b_autoloop = autoloop;
110         setDirty(TRUE);
111     };
112     inline BOOL getAutoLoop(void) { return _b_autoloop;};
113
114     inline void setShowToolbar(BOOL showtoolbar)
115     {
116         _b_toolbar = showtoolbar;
117         setDirty(TRUE);
118     };
119     inline BOOL getShowToolbar(void) { return _b_toolbar;};
120
121     void setVolume(int volume);
122     int getVolume(void) { return _i_volume; };
123
124     void setBackColor(OLE_COLOR backcolor);
125     OLE_COLOR getBackColor(void) { return _i_backcolor; };
126
127     void setVisible(BOOL fVisible);
128     BOOL getVisible(void) { return _b_visible; };
129     BOOL isVisible(void) { return _b_visible || (! _b_usermode); };
130
131     inline void setStartTime(int time)
132     {
133         _i_time = time;
134         setDirty(TRUE);
135     };
136     inline int getStartTime(void) { return _i_time; };
137
138     void setTime(int time);
139     int  getTime(void) { return _i_time; };
140
141     void setBaseURL(BSTR url)
142     {
143         SysFreeString(_bstr_baseurl);
144         _bstr_baseurl = SysAllocStringLen(url, SysStringLen(url));
145         setDirty(TRUE);
146     };
147     const BSTR getBaseURL(void) { return _bstr_baseurl; };
148
149     // control size in HIMETRIC
150     inline void setExtent(const SIZEL& extent)
151     {
152         _extent = extent;
153         setDirty(TRUE);
154     };
155     const SIZEL& getExtent(void) { return _extent; };
156
157     // transient properties
158     inline void setMute(BOOL mute) { _b_mute = mute; };
159
160     inline void setPicture(LPPICTURE pict)
161     {
162         if( NULL != _p_pict )
163             _p_pict->Release();
164         if( NULL != pict )
165             _p_pict->AddRef();
166         _p_pict = pict;
167     };
168
169     inline LPPICTURE getPicture(void)
170     {
171         if( NULL != _p_pict )
172             _p_pict->AddRef();
173         return _p_pict;
174     };
175
176     BOOL hasFocus(void);
177     void setFocus(BOOL fFocus);
178
179     inline UINT getCodePage(void) { return _i_codepage; };
180     inline void setCodePage(UINT cp)
181     {
182         // accept new codepage only if it works on this system
183         size_t mblen = WideCharToMultiByte(cp,
184                 0, L"test", -1, NULL, 0, NULL, NULL);
185         if( mblen > 0 )
186             _i_codepage = cp;
187     };
188
189     inline BOOL isUserMode(void) { return _b_usermode; };
190     inline void setUserMode(BOOL um) { _b_usermode = um; };
191
192     inline BOOL isDirty(void) { return _b_dirty; };
193     inline void setDirty(BOOL dirty) { _b_dirty = dirty; };
194
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     inline HWND getInPlaceWindow(void) const { return _inplacewnd; };
203     BOOL isInPlaceActive(void);
204
205     /*
206     ** container events
207     */
208     HRESULT onInit(void);
209     HRESULT onLoad(void);
210     HRESULT onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect);
211     HRESULT onInPlaceDeactivate(void);
212     HRESULT onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID);
213     HRESULT onClose(DWORD dwSaveOption);
214     void onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect);
215     void onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
216             HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds);
217     void onPaint(HDC hdc, const RECT &bounds, const RECT &pr);
218
219     /*
220     ** control events
221     */
222     void freezeEvents(BOOL freeze);
223     void firePropChangedEvent(DISPID dispid);
224     void fireOnPlayEvent(void);
225     void fireOnPauseEvent(void);
226     void fireOnStopEvent(void);
227
228     // controlling IUnknown interface
229     LPUNKNOWN pUnkOuter;
230
231 protected:
232
233     virtual ~VLCPlugin();
234
235 private:
236
237     //implemented interfaces
238     class VLCOleObject *vlcOleObject;
239     class VLCOleControl *vlcOleControl;
240     class VLCOleInPlaceObject *vlcOleInPlaceObject;
241     class VLCOleInPlaceActiveObject *vlcOleInPlaceActiveObject;
242     class VLCPersistStreamInit *vlcPersistStreamInit;
243     class VLCPersistStorage *vlcPersistStorage;
244     class VLCPersistPropertyBag *vlcPersistPropertyBag;
245     class VLCProvideClassInfo *vlcProvideClassInfo;
246     class VLCConnectionPointContainer *vlcConnectionPointContainer;
247     class VLCObjectSafety *vlcObjectSafety;
248     class VLCControl *vlcControl;
249     class VLCControl2 *vlcControl2;
250     class VLCViewObject *vlcViewObject;
251     class VLCDataObject *vlcDataObject;
252     class VLCSupportErrorInfo *vlcSupportErrorInfo;
253
254     // in place activated window (Plugin window)
255     HWND _inplacewnd;
256
257     VLCPluginClass* _p_class;
258     ULONG _i_ref;
259
260     libvlc_instance_t* _p_libvlc;
261     UINT _i_codepage;
262     BOOL _b_usermode;
263     RECT _posRect;
264     LPPICTURE _p_pict;
265
266     // persistable properties
267     BSTR _bstr_baseurl;
268     BSTR _bstr_mrl;
269     BOOL _b_autoplay;
270     BOOL _b_autoloop;
271     BOOL _b_toolbar;
272     BOOL _b_visible;
273     BOOL _b_mute;
274     int  _i_volume;
275     int  _i_time;
276     SIZEL _extent;
277     OLE_COLOR _i_backcolor;
278     // indicates whether properties needs persisting
279     BOOL _b_dirty;
280 };
281
282 #endif