]> git.sesse.net Git - vlc/blob - projects/activex/plugin.h
macosx/framework: Build a fat framework (x86_64 and i386) in Release mode.
[vlc] / projects / activex / plugin.h
1 /*****************************************************************************
2  * plugin.h: ActiveX control for VLC
3  *****************************************************************************
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  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef __PLUGIN_H__
25 #define __PLUGIN_H__
26
27 #include <ole2.h>
28 #include <olectl.h>
29
30 #include <vlc/vlc.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             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
198     HRESULT getVLC(libvlc_instance_t** pp_libvlc)
199     {
200         if( !isRunning() )
201             initVLC();
202         *pp_libvlc = _p_libvlc;
203         return _p_libvlc ? S_OK : E_FAIL;
204     }
205     HRESULT getMD(libvlc_media_player_t **pp_md)
206     {
207         *pp_md = _p_mplayer;
208         return _p_mplayer ? S_OK : E_FAIL;
209     }
210
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     BOOL isInPlaceActive(void);
217
218     /*
219     ** container events
220     */
221     HRESULT onInit(void);
222     HRESULT onLoad(void);
223     HRESULT onActivateInPlace(LPMSG lpMesg, HWND hwndParent, LPCRECT lprcPosRect, LPCRECT lprcClipRect);
224     HRESULT onInPlaceDeactivate(void);
225     HRESULT onAmbientChanged(LPUNKNOWN pContainer, DISPID dispID);
226     HRESULT onClose(DWORD dwSaveOption);
227     void onPositionChange(LPCRECT lprcPosRect, LPCRECT lprcClipRect);
228     void onDraw(DVTARGETDEVICE * ptd, HDC hicTargetDev,
229             HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds);
230     void onPaint(HDC hdc, const RECT &bounds, const RECT &pr);
231
232     /*
233     ** control events
234     */
235     void freezeEvents(BOOL freeze);
236     void firePropChangedEvent(DISPID dispid);
237     void fireOnPlayEvent(void);
238     void fireOnPauseEvent(void);
239     void fireOnStopEvent(void);
240
241     // async events;
242     void fireOnIdleEvent();
243     void fireOnOpeningEvent();
244     void fireOnBufferingEvent();
245     void fireOnPlayingEvent();
246     void fireOnPausedEvent();
247     void fireOnErrorEvent();
248     void fireOnEndedEvent();
249     void fireOnStoppedEvent();
250     void fireOnForwardEvent();
251     void fireOnBackwardEvent();
252
253     void fireOnTimeChangedEvent(long time);
254     void fireOnPositionChangedEvent(long position);
255     void fireOnSeekableChangedEvent(VARIANT_BOOL seekable);
256     void fireOnPausableChangedEvent(VARIANT_BOOL pausable);
257
258     void fireOnMouseButtonEvent(VARIANT_BOOL btn_right, VARIANT_BOOL btn_center,
259                 VARIANT_BOOL btn_left, VARIANT_BOOL btn_wheel_up,
260                 VARIANT_BOOL bnt_wheel_down);
261     void fireOnMouseMovedEvent(long x, long y);
262     void fireOnMouseClickedEvent(VARIANT_BOOL clicked);
263     void fireOnMouseObjectEvent(VARIANT_BOOL moved);
264
265     // controlling IUnknown interface
266     LPUNKNOWN pUnkOuter;
267
268     /*
269     ** libvlc interface
270     */
271     bool isPlaying()
272     {
273         return _p_mplayer && libvlc_media_player_is_playing(_p_mplayer);
274     }
275     int  playlist_get_current_index() { return _i_midx; }
276     int  playlist_add_extended_untrusted(const char *, int, const char **);
277     void playlist_delete_item(int idx)
278     {
279         if( _p_mlist )
280             libvlc_media_list_remove_index(_p_mlist,idx);
281     }
282     void playlist_clear()
283     {
284         if( !_p_libvlc )
285             return;
286         if( _p_mlist )
287             libvlc_media_list_release(_p_mlist);
288         _p_mlist = libvlc_media_list_new(_p_libvlc);
289     }
290     int  playlist_count()
291     {
292          int r = 0;
293          if( !_p_mlist )
294              return 0;
295          libvlc_media_list_lock(_p_mlist);
296          r = libvlc_media_list_count(_p_mlist);
297          libvlc_media_list_unlock(_p_mlist);
298          return r;
299     }
300     void playlist_pause()
301     {
302         if( isPlaying() )
303             libvlc_media_player_pause(_p_mplayer);
304     }
305     void playlist_play()
306     {
307         if( !_p_libvlc )
308             initVLC();
309         if( _p_mplayer || playlist_select(0) )
310             libvlc_media_player_play(_p_mplayer);
311     }
312     void playlist_play_item(int idx)
313     {
314         if( !_p_libvlc )
315             initVLC();
316         if( playlist_select(idx) )
317             libvlc_media_player_play(_p_mplayer);
318     }
319     void playlist_stop()
320     {
321         if( _p_mplayer )
322             libvlc_media_player_stop(_p_mplayer);
323     }
324     void playlist_next()
325     {
326         if( playlist_select( _i_midx+1 ) )
327             libvlc_media_player_play(_p_mplayer);
328     }
329     void playlist_prev()
330     {
331         if( playlist_select( _i_midx-1 ) )
332             libvlc_media_player_play(_p_mplayer);
333     }
334
335 protected:
336
337     virtual ~VLCPlugin();
338
339 private:
340     void initVLC();
341     bool playlist_select(int i);
342     void set_player_window();
343     void player_register_events();
344     void player_unregister_events();
345
346     //implemented interfaces
347     class VLCOleObject *vlcOleObject;
348     class VLCOleControl *vlcOleControl;
349     class VLCOleInPlaceObject *vlcOleInPlaceObject;
350     class VLCOleInPlaceActiveObject *vlcOleInPlaceActiveObject;
351     class VLCPersistStreamInit *vlcPersistStreamInit;
352     class VLCPersistStorage *vlcPersistStorage;
353     class VLCPersistPropertyBag *vlcPersistPropertyBag;
354     class VLCProvideClassInfo *vlcProvideClassInfo;
355     class VLCConnectionPointContainer *vlcConnectionPointContainer;
356     class VLCObjectSafety *vlcObjectSafety;
357     class VLCControl *vlcControl;
358     class VLCControl2 *vlcControl2;
359     class VLCViewObject *vlcViewObject;
360     class VLCDataObject *vlcDataObject;
361     class VLCSupportErrorInfo *vlcSupportErrorInfo;
362
363     // in place activated window (Plugin window)
364     HWND _inplacewnd;
365
366     VLCPluginClass* _p_class;
367     ULONG _i_ref;
368
369     libvlc_instance_t     *_p_libvlc;
370     libvlc_media_list_t   *_p_mlist;
371     libvlc_media_player_t *_p_mplayer;
372     int  _i_midx;
373
374     UINT _i_codepage;
375     BOOL _b_usermode;
376     RECT _posRect;
377     LPPICTURE _p_pict;
378
379     // persistable properties
380     BSTR _bstr_baseurl;
381     BSTR _bstr_mrl;
382     BOOL _b_autoplay;
383     BOOL _b_autoloop;
384     BOOL _b_toolbar;
385     BOOL _b_visible;
386     BOOL _b_mute;
387     int  _i_volume;
388     int  _i_time;
389     SIZEL _extent;
390     OLE_COLOR _i_backcolor;
391     // indicates whether properties needs persisting
392     BOOL _b_dirty;
393 };
394
395 #endif