DShow: small fixes and cosmetics
[vlc/asuraparaju-public.git] / projects / activex / plugin.h
blob412bdcedf3cc077434dcb115583c2624c5483888
1 /*****************************************************************************
2 * plugin.h: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005-2010 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7 * Jean-Paul Saman <jpsaman@videolan.org>
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.
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.
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 *****************************************************************************/
24 #ifndef __PLUGIN_H__
25 #define __PLUGIN_H__
27 #include <ole2.h>
28 #include <olectl.h>
30 #include <vlc/vlc.h>
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;
37 class VLCPluginClass : public IClassFactory
40 public:
42 VLCPluginClass(LONG *p_class_ref, HINSTANCE hInstance, REFCLSID rclsid);
44 /* IUnknown methods */
45 STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
46 STDMETHODIMP_(ULONG) AddRef(void);
47 STDMETHODIMP_(ULONG) Release(void);
49 /* IClassFactory methods */
50 STDMETHODIMP CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, void **ppv);
51 STDMETHODIMP LockServer(BOOL fLock);
53 REFCLSID getClassID(void) { return (REFCLSID)_classid; };
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; };
60 protected:
62 virtual ~VLCPluginClass();
64 private:
66 LPLONG _p_class_ref;
67 HINSTANCE _hinstance;
68 CLSID _classid;
69 ATOM _inplace_wndclass_atom;
70 LPPICTURE _inplace_picture;
73 class VLCPlugin : public IUnknown
76 public:
78 VLCPlugin(VLCPluginClass *p_class, LPUNKNOWN pUnkOuter);
80 /* IUnknown methods */
81 STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
82 STDMETHODIMP_(ULONG) AddRef(void);
83 STDMETHODIMP_(ULONG) Release(void);
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; };
91 ** persistant properties
93 void setMRL(BSTR mrl)
95 SysFreeString(_bstr_mrl);
96 _bstr_mrl = SysAllocStringLen(mrl, SysStringLen(mrl));
97 setDirty(TRUE);
99 const BSTR getMRL(void) { return _bstr_mrl; };
101 inline void setAutoPlay(BOOL autoplay)
103 _b_autoplay = autoplay;
104 setDirty(TRUE);
106 inline BOOL getAutoPlay(void) { return _b_autoplay; };
108 inline void setAutoLoop(BOOL autoloop)
110 _b_autoloop = autoloop;
111 setDirty(TRUE);
113 inline BOOL getAutoLoop(void) { return _b_autoloop;};
115 inline void setShowToolbar(BOOL showtoolbar)
117 _b_toolbar = showtoolbar;
118 setDirty(TRUE);
120 inline BOOL getShowToolbar(void) { return _b_toolbar;};
122 void setVolume(int volume);
123 int getVolume(void) { return _i_volume; };
125 void setBackColor(OLE_COLOR backcolor);
126 OLE_COLOR getBackColor(void) { return _i_backcolor; };
128 void setVisible(BOOL fVisible);
129 BOOL getVisible(void) { return _b_visible; };
130 BOOL isVisible(void) { return _b_visible || (! _b_usermode); };
132 inline void setStartTime(int time)
134 _i_time = time;
135 setDirty(TRUE);
137 inline int getStartTime(void) { return _i_time; };
139 void setTime(int time);
140 int getTime(void) { return _i_time; };
142 void setBaseURL(BSTR url)
144 SysFreeString(_bstr_baseurl);
145 _bstr_baseurl = SysAllocStringLen(url, SysStringLen(url));
146 setDirty(TRUE);
148 const BSTR getBaseURL(void) { return _bstr_baseurl; };
150 // control size in HIMETRIC
151 inline void setExtent(const SIZEL& extent)
153 _extent = extent;
154 setDirty(TRUE);
156 const SIZEL& getExtent(void) { return _extent; };
158 // transient properties
159 inline void setMute(BOOL mute) { _b_mute = mute; };
161 inline void setPicture(LPPICTURE pict)
163 if( NULL != _p_pict )
164 _p_pict->Release();
165 if( NULL != pict )
166 pict->AddRef();
167 _p_pict = pict;
170 inline LPPICTURE getPicture(void)
172 if( NULL != _p_pict )
173 _p_pict->AddRef();
174 return _p_pict;
177 BOOL hasFocus(void);
178 void setFocus(BOOL fFocus);
180 inline UINT getCodePage(void) { return _i_codepage; };
181 inline void setCodePage(UINT cp)
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;
190 inline BOOL isUserMode(void) { return _b_usermode; };
191 inline void setUserMode(BOOL um) { _b_usermode = um; };
193 inline BOOL isDirty(void) { return _b_dirty; };
194 inline void setDirty(BOOL dirty) { _b_dirty = dirty; };
196 inline BOOL isRunning(void) { return NULL != _p_libvlc; };
198 HRESULT getVLC(libvlc_instance_t** pp_libvlc)
200 if( !isRunning() )
201 initVLC();
202 *pp_libvlc = _p_libvlc;
203 return _p_libvlc ? S_OK : E_FAIL;
205 HRESULT getMD(libvlc_media_player_t **pp_md)
207 *pp_md = _p_mplayer;
208 return _p_mplayer ? S_OK : E_FAIL;
211 void setErrorInfo(REFIID riid, const char *description);
213 // control geometry within container
214 RECT getPosRect(void) { return _posRect; };
215 inline HWND getInPlaceWindow(void) const { return _inplacewnd; };
216 BOOL isInPlaceActive(void);
219 ** container events
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);
233 ** control events
235 void freezeEvents(BOOL freeze);
236 void firePropChangedEvent(DISPID dispid);
237 void fireOnPlayEvent(void);
238 void fireOnPauseEvent(void);
239 void fireOnStopEvent(void);
241 // async events;
242 void fireOnMediaPlayerNothingSpecialEvent();
243 void fireOnMediaPlayerOpeningEvent();
244 void fireOnMediaPlayerBufferingEvent();
245 void fireOnMediaPlayerPlayingEvent();
246 void fireOnMediaPlayerPausedEvent();
247 void fireOnMediaPlayerForwardEvent();
248 void fireOnMediaPlayerBackwardEvent();
249 void fireOnMediaPlayerEncounteredErrorEvent();
250 void fireOnMediaPlayerEndReachedEvent();
251 void fireOnMediaPlayerStoppedEvent();
253 void fireOnMediaPlayerTimeChangedEvent(long time);
254 void fireOnMediaPlayerPositionChangedEvent(long position);
255 void fireOnMediaPlayerSeekableChangedEvent(VARIANT_BOOL seekable);
256 void fireOnMediaPlayerPausableChangedEvent(VARIANT_BOOL pausable);
258 // controlling IUnknown interface
259 LPUNKNOWN pUnkOuter;
262 ** libvlc interface
264 bool isPlaying()
266 return _p_mplayer && libvlc_media_player_is_playing(_p_mplayer);
268 int playlist_get_current_index() { return _i_midx; }
269 int playlist_add_extended_untrusted(const char *, int, const char **);
270 void playlist_delete_item(int idx)
272 if( _p_mlist )
274 libvlc_media_list_lock(_p_mlist);
275 libvlc_media_list_remove_index(_p_mlist,idx);
276 libvlc_media_list_unlock(_p_mlist);
279 void playlist_clear()
281 if( !_p_libvlc )
282 return;
283 if( _p_mlist )
284 libvlc_media_list_release(_p_mlist);
285 _p_mlist = libvlc_media_list_new(_p_libvlc);
287 int playlist_count()
289 int r = 0;
290 if( !_p_mlist )
291 return 0;
292 libvlc_media_list_lock(_p_mlist);
293 r = libvlc_media_list_count(_p_mlist);
294 libvlc_media_list_unlock(_p_mlist);
295 return r;
297 void playlist_pause()
299 if( isPlaying() )
300 libvlc_media_player_pause(_p_mplayer);
302 void playlist_play()
304 if( _p_mplayer || playlist_select(0) )
305 libvlc_media_player_play(_p_mplayer);
307 void playlist_play_item(int idx)
309 if( playlist_select(idx) )
310 libvlc_media_player_play(_p_mplayer);
312 void playlist_stop()
314 if( _p_mplayer )
315 libvlc_media_player_stop(_p_mplayer);
317 void playlist_next()
319 if( playlist_select( _i_midx+1 ) )
320 libvlc_media_player_play(_p_mplayer);
322 void playlist_prev()
324 if( playlist_select( _i_midx-1 ) )
325 libvlc_media_player_play(_p_mplayer);
328 protected:
330 virtual ~VLCPlugin();
332 private:
333 void initVLC();
334 bool playlist_select(int i);
335 void set_player_window();
336 void player_register_events();
337 void player_unregister_events();
339 //implemented interfaces
340 class VLCOleObject *vlcOleObject;
341 class VLCOleControl *vlcOleControl;
342 class VLCOleInPlaceObject *vlcOleInPlaceObject;
343 class VLCOleInPlaceActiveObject *vlcOleInPlaceActiveObject;
344 class VLCPersistStreamInit *vlcPersistStreamInit;
345 class VLCPersistStorage *vlcPersistStorage;
346 class VLCPersistPropertyBag *vlcPersistPropertyBag;
347 class VLCProvideClassInfo *vlcProvideClassInfo;
348 class VLCConnectionPointContainer *vlcConnectionPointContainer;
349 class VLCObjectSafety *vlcObjectSafety;
350 class VLCControl *vlcControl;
351 class VLCControl2 *vlcControl2;
352 class VLCViewObject *vlcViewObject;
353 class VLCDataObject *vlcDataObject;
354 class VLCSupportErrorInfo *vlcSupportErrorInfo;
356 // in place activated window (Plugin window)
357 HWND _inplacewnd;
359 VLCPluginClass* _p_class;
360 ULONG _i_ref;
362 libvlc_instance_t *_p_libvlc;
363 libvlc_media_list_t *_p_mlist;
364 libvlc_media_player_t *_p_mplayer;
365 int _i_midx;
367 UINT _i_codepage;
368 BOOL _b_usermode;
369 RECT _posRect;
370 LPPICTURE _p_pict;
372 // persistable properties
373 BSTR _bstr_baseurl;
374 BSTR _bstr_mrl;
375 BOOL _b_autoplay;
376 BOOL _b_autoloop;
377 BOOL _b_toolbar;
378 BOOL _b_visible;
379 BOOL _b_mute;
380 int _i_volume;
381 int _i_time;
382 SIZEL _extent;
383 OLE_COLOR _i_backcolor;
384 // indicates whether properties needs persisting
385 BOOL _b_dirty;
388 #endif