1 /*****************************************************************************
2 * persistpropbag.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
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.
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.
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 *****************************************************************************/
24 #include "persistpropbag.h"
27 #include "oleobject.h"
31 STDMETHODIMP VLCPersistPropertyBag::GetClassID(LPCLSID pClsID)
36 *pClsID = _p_instance->getClassID();
41 STDMETHODIMP VLCPersistPropertyBag::InitNew(void)
43 return _p_instance->onInit();
46 STDMETHODIMP VLCPersistPropertyBag::Load(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog)
48 HRESULT hr = _p_instance->onInit();
52 if( NULL == pPropBag )
57 V_VT(&value) = VT_BSTR;
58 if( S_OK == pPropBag->Read(OLESTR("mrl"), &value, pErrorLog) )
60 _p_instance->setMRL(V_BSTR(&value));
66 ** try alternative syntax
68 V_VT(&value) = VT_BSTR;
69 if( S_OK == pPropBag->Read(OLESTR("src"), &value, pErrorLog) )
71 _p_instance->setMRL(V_BSTR(&value));
76 V_VT(&value) = VT_BSTR;
77 if( S_OK == pPropBag->Read(OLESTR("filename"), &value, pErrorLog) )
79 _p_instance->setMRL(V_BSTR(&value));
85 V_VT(&value) = VT_BOOL;
86 if( S_OK == pPropBag->Read(OLESTR("autoplay"), &value, pErrorLog) )
88 _p_instance->setAutoPlay(V_BOOL(&value) != VARIANT_FALSE);
94 ** try alternative syntax
96 V_VT(&value) = VT_BOOL;
97 if( S_OK == pPropBag->Read(OLESTR("autostart"), &value, pErrorLog) )
99 _p_instance->setAutoPlay(V_BOOL(&value) != VARIANT_FALSE);
100 VariantClear(&value);
104 V_VT(&value) = VT_BOOL;
105 if( S_OK == pPropBag->Read(OLESTR("toolbar"), &value, pErrorLog) )
107 _p_instance->setShowToolbar(V_BOOL(&value) != VARIANT_FALSE);
108 VariantClear(&value);
111 SIZEL size = _p_instance->getExtent();
112 V_VT(&value) = VT_I4;
113 if( S_OK == pPropBag->Read(OLESTR("extentwidth"), &value, pErrorLog) )
115 size.cx = V_I4(&value);
116 VariantClear(&value);
118 V_VT(&value) = VT_I4;
119 if( S_OK == pPropBag->Read(OLESTR("extentheight"), &value, pErrorLog) )
121 size.cy = V_I4(&value);
122 VariantClear(&value);
124 _p_instance->setExtent(size);
126 V_VT(&value) = VT_BOOL;
127 if( S_OK == pPropBag->Read(OLESTR("autoloop"), &value, pErrorLog) )
129 _p_instance->setAutoLoop(V_BOOL(&value) != VARIANT_FALSE);
130 VariantClear(&value);
135 ** try alternative syntax
137 V_VT(&value) = VT_BOOL;
138 if( S_OK == pPropBag->Read(OLESTR("loop"), &value, pErrorLog) )
140 _p_instance->setAutoLoop(V_BOOL(&value) != VARIANT_FALSE);
141 VariantClear(&value);
145 V_VT(&value) = VT_BOOL;
146 if( S_OK == pPropBag->Read(OLESTR("mute"), &value, pErrorLog) )
148 _p_instance->setMute(V_BOOL(&value) != VARIANT_FALSE);
149 VariantClear(&value);
152 V_VT(&value) = VT_BOOL;
153 if( S_OK == pPropBag->Read(OLESTR("visible"), &value, pErrorLog) )
155 _p_instance->setVisible(V_BOOL(&value) != VARIANT_FALSE);
156 VariantClear(&value);
161 ** try alternative syntax
163 V_VT(&value) = VT_BOOL;
164 if( S_OK == pPropBag->Read(OLESTR("showdisplay"), &value, pErrorLog) )
166 _p_instance->setVisible(V_BOOL(&value) != VARIANT_FALSE);
167 VariantClear(&value);
171 V_VT(&value) = VT_I4;
172 if( S_OK == pPropBag->Read(OLESTR("volume"), &value, pErrorLog) )
174 _p_instance->setVolume(V_I4(&value));
175 VariantClear(&value);
178 V_VT(&value) = VT_I4;
179 if( S_OK == pPropBag->Read(OLESTR("starttime"), &value, pErrorLog) )
181 _p_instance->setStartTime(V_I4(&value));
182 VariantClear(&value);
185 V_VT(&value) = VT_BSTR;
186 if( S_OK == pPropBag->Read(OLESTR("baseurl"), &value, pErrorLog) )
188 _p_instance->setBaseURL(V_BSTR(&value));
189 VariantClear(&value);
192 V_VT(&value) = VT_I4;
193 if( S_OK == pPropBag->Read(OLESTR("backcolor"), &value, pErrorLog) )
195 _p_instance->setBackColor(V_I4(&value));
196 VariantClear(&value);
201 ** try alternative syntax
203 V_VT(&value) = VT_BSTR;
204 if( S_OK == pPropBag->Read(OLESTR("bgcolor"), &value, pErrorLog) )
207 if( swscanf(V_BSTR(&value), L"#%lX", &backcolor) )
209 _p_instance->setBackColor(backcolor);
211 VariantClear(&value);
215 return _p_instance->onLoad();
218 STDMETHODIMP VLCPersistPropertyBag::Save(LPPROPERTYBAG pPropBag, BOOL fClearDirty, BOOL fSaveAllProperties)
220 if( NULL == pPropBag )
227 V_VT(&value) = VT_BOOL;
228 V_BOOL(&value) = _p_instance->getAutoLoop()? VARIANT_TRUE : VARIANT_FALSE;
229 pPropBag->Write(OLESTR("AutoLoop"), &value);
230 VariantClear(&value);
232 V_VT(&value) = VT_BOOL;
233 V_BOOL(&value) = _p_instance->getAutoPlay()? VARIANT_TRUE : VARIANT_FALSE;
234 pPropBag->Write(OLESTR("AutoPlay"), &value);
235 VariantClear(&value);
237 V_VT(&value) = VT_BOOL;
238 V_BOOL(&value) = _p_instance->getShowToolbar()? VARIANT_TRUE : VARIANT_FALSE;
239 pPropBag->Write(OLESTR("Toolbar"), &value);
240 VariantClear(&value);
242 SIZEL size = _p_instance->getExtent();
243 V_VT(&value) = VT_I4;
244 V_I4(&value) = size.cx;
245 pPropBag->Write(OLESTR("ExtentWidth"), &value);
246 V_I4(&value) = size.cy;
247 pPropBag->Write(OLESTR("ExtentHeight"), &value);
249 V_VT(&value) = VT_BSTR;
250 V_BSTR(&value) = SysAllocStringLen(_p_instance->getMRL(),
251 SysStringLen(_p_instance->getMRL()));
252 pPropBag->Write(OLESTR("MRL"), &value);
253 VariantClear(&value);
255 V_VT(&value) = VT_BOOL;
256 V_BOOL(&value) = _p_instance->getVisible()? VARIANT_TRUE : VARIANT_FALSE;
257 pPropBag->Write(OLESTR("Visible"), &value);
258 VariantClear(&value);
260 V_VT(&value) = VT_I4;
261 V_I4(&value) = _p_instance->getVolume();
262 pPropBag->Write(OLESTR("Volume"), &value);
263 VariantClear(&value);
265 V_VT(&value) = VT_I4;
266 V_I4(&value) = _p_instance->getStartTime();
267 pPropBag->Write(OLESTR("StartTime"), &value);
268 VariantClear(&value);
270 V_VT(&value) = VT_BSTR;
271 V_BSTR(&value) = SysAllocStringLen(_p_instance->getBaseURL(),
272 SysStringLen(_p_instance->getBaseURL()));
273 pPropBag->Write(OLESTR("BaseURL"), &value);
274 VariantClear(&value);
276 V_VT(&value) = VT_I4;
277 V_I4(&value) = _p_instance->getBackColor();
278 pPropBag->Write(OLESTR("BackColor"), &value);
279 VariantClear(&value);
282 _p_instance->setDirty(FALSE);