1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <avmedia/mediaitem.hxx>
29 #include <com/sun/star/uno/Sequence.hxx>
30 
31 using namespace ::com::sun::star;
32 
33 namespace avmedia
34 {
35 
36 // -------------
37 // - MediaItem -
38 // -------------
39 
40 TYPEINIT1_AUTOFACTORY( MediaItem, ::SfxPoolItem );
41 	::rtl::OUString			maURL;
42 	sal_uInt32				mnMaskSet;
43 	MediaState				meState;
44 	double					mfTime;
45 	double					mfDuration;
46 	sal_Int16				mnVolumeDB;
47 	sal_Bool				mbLoop;
48 	sal_Bool				mbMute;
49 	::com::sun::star::media::ZoomLevel meZoom;
50 
51 // ------------------------------------------------------------------------------
52 
53 MediaItem::MediaItem( sal_uInt16 _nWhich, sal_uInt32 nMaskSet ) :
54 	SfxPoolItem( _nWhich ),
55 	mnMaskSet( nMaskSet ),
56 	meState( MEDIASTATE_STOP ),
57 	mfTime( 0.0 ),
58 	mfDuration( 0.0 ),
59 	mnVolumeDB( 0 ),
60 	mbLoop( false ),
61 	mbMute( false ),
62 	meZoom( ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE )
63 {
64 }
65 
66 // ------------------------------------------------------------------------------
67 
68 MediaItem::MediaItem( const MediaItem& rItem ) :
69 	SfxPoolItem( rItem ),
70 	maURL( rItem.maURL ),
71 	mnMaskSet( rItem.mnMaskSet ),
72 	meState( rItem.meState ),
73 	mfTime( rItem.mfTime ),
74 	mfDuration( rItem.mfDuration ),
75 	mnVolumeDB( rItem.mnVolumeDB ),
76 	mbLoop( rItem.mbLoop ),
77 	mbMute( rItem.mbMute ),
78 	meZoom( rItem.meZoom )
79 {
80 }
81 
82 // ------------------------------------------------------------------------------
83 
84 MediaItem::~MediaItem()
85 {
86 }
87 
88 // ------------------------------------------------------------------------------
89 
90 int	MediaItem::operator==( const SfxPoolItem& rItem ) const
91 {
92 	DBG_ASSERT( SfxPoolItem::operator==(rItem), "unequal types" );
93 	return( mnMaskSet == static_cast< const MediaItem& >( rItem ).mnMaskSet &&
94 			maURL == static_cast< const MediaItem& >( rItem ).maURL &&
95 			meState == static_cast< const MediaItem& >( rItem ).meState &&
96 			mfDuration == static_cast< const MediaItem& >( rItem ).mfDuration &&
97 			mfTime == static_cast< const MediaItem& >( rItem ).mfTime &&
98 			mnVolumeDB == static_cast< const MediaItem& >( rItem ).mnVolumeDB &&
99 			mbLoop == static_cast< const MediaItem& >( rItem ).mbLoop &&
100 			mbMute == static_cast< const MediaItem& >( rItem ).mbMute &&
101 			meZoom == static_cast< const MediaItem& >( rItem ).meZoom );
102 }
103 
104 // ------------------------------------------------------------------------------
105 
106 SfxPoolItem* MediaItem::Clone( SfxItemPool* ) const
107 {
108 	return new MediaItem( *this );
109 }
110 
111 //------------------------------------------------------------------------
112 
113 SfxItemPresentation MediaItem::GetPresentation( SfxItemPresentation,
114 												  SfxMapUnit,
115 												  SfxMapUnit,
116     											  XubString& rText,
117 												  const IntlWrapper * ) const
118 {
119 	rText.Erase();
120 	return SFX_ITEM_PRESENTATION_NONE;
121 }
122 
123 //------------------------------------------------------------------------
124 
125 sal_Bool MediaItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
126 {
127 	uno::Sequence< uno::Any > aSeq( 9 );
128 
129 	aSeq[ 0 ] <<= maURL;
130 	aSeq[ 1 ] <<= mnMaskSet;
131 	aSeq[ 2 ] <<= static_cast< sal_Int32 >( meState );
132 	aSeq[ 3 ] <<= mfTime;
133 	aSeq[ 4 ] <<= mfDuration;
134 	aSeq[ 5 ] <<= mnVolumeDB;
135 	aSeq[ 6 ] <<= mbLoop;
136 	aSeq[ 7 ] <<= mbMute;
137 	aSeq[ 8 ] <<= meZoom;
138 
139 	rVal <<= aSeq;
140 
141 	return true;
142 }
143 
144 //------------------------------------------------------------------------
145 
146 sal_Bool MediaItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
147 {
148 	uno::Sequence< uno::Any >	aSeq;
149 	sal_Bool						bRet = false;
150 
151 	if( ( rVal >>= aSeq ) && ( aSeq.getLength() == 9 ) )
152 	{
153 		sal_Int32 nInt32 = 0;
154 
155 		aSeq[ 0 ] >>= maURL;
156 		aSeq[ 1 ] >>= mnMaskSet;
157 		aSeq[ 2 ] >>= nInt32; meState = static_cast< MediaState >( nInt32 );
158 		aSeq[ 3 ] >>= mfTime;
159 		aSeq[ 4 ] >>= mfDuration;
160 		aSeq[ 5 ] >>= mnVolumeDB;
161 		aSeq[ 6 ] >>= mbLoop;
162 		aSeq[ 7 ] >>= mbMute;
163 		aSeq[ 8 ] >>= meZoom;
164 
165 		bRet = true;
166 	}
167 
168 	return bRet;
169 }
170 
171 //------------------------------------------------------------------------
172 
173 void MediaItem::merge( const MediaItem& rMediaItem )
174 {
175 	const sal_uInt32 nMaskSet = rMediaItem.getMaskSet();
176 
177 	if( AVMEDIA_SETMASK_URL & nMaskSet )
178 		setURL( rMediaItem.getURL() );
179 
180 	if( AVMEDIA_SETMASK_STATE & nMaskSet )
181 		setState( rMediaItem.getState() );
182 
183 	if( AVMEDIA_SETMASK_DURATION & nMaskSet )
184 		setDuration( rMediaItem.getDuration() );
185 
186 	if( AVMEDIA_SETMASK_TIME & nMaskSet )
187 		setTime( rMediaItem.getTime() );
188 
189 	if( AVMEDIA_SETMASK_LOOP & nMaskSet )
190 		setLoop( rMediaItem.isLoop() );
191 
192 	if( AVMEDIA_SETMASK_MUTE & nMaskSet )
193 		setMute( rMediaItem.isMute() );
194 
195 	if( AVMEDIA_SETMASK_VOLUMEDB & nMaskSet )
196 		setVolumeDB( rMediaItem.getVolumeDB() );
197 
198 	if( AVMEDIA_SETMASK_ZOOM & nMaskSet )
199 		setZoom( rMediaItem.getZoom() );
200 }
201 
202 //------------------------------------------------------------------------
203 
204 sal_uInt32 MediaItem::getMaskSet() const
205 {
206 	return mnMaskSet;
207 }
208 
209 //------------------------------------------------------------------------
210 
211 void MediaItem::setURL( const ::rtl::OUString& rURL )
212 {
213 	maURL = rURL;
214 	mnMaskSet |= AVMEDIA_SETMASK_URL;
215 }
216 
217 //------------------------------------------------------------------------
218 
219 const ::rtl::OUString& MediaItem::getURL() const
220 {
221 	return maURL;
222 }
223 
224 //------------------------------------------------------------------------
225 
226 void MediaItem::setState( MediaState eState )
227 {
228 	meState = eState;
229 	mnMaskSet |= AVMEDIA_SETMASK_STATE;
230 }
231 
232 //------------------------------------------------------------------------
233 
234 MediaState MediaItem::getState() const
235 {
236 	return meState;
237 }
238 
239 //------------------------------------------------------------------------
240 
241 void MediaItem::setDuration( double fDuration )
242 {
243 	mfDuration = fDuration;
244 	mnMaskSet |= AVMEDIA_SETMASK_DURATION;
245 }
246 
247 //------------------------------------------------------------------------
248 
249 double MediaItem::getDuration() const
250 {
251 	return mfDuration;
252 }
253 
254 //------------------------------------------------------------------------
255 
256 void MediaItem::setTime( double fTime )
257 {
258 	mfTime = fTime;
259 	mnMaskSet |= AVMEDIA_SETMASK_TIME;
260 }
261 
262 //------------------------------------------------------------------------
263 
264 double MediaItem::getTime() const
265 {
266 	return mfTime;
267 }
268 
269 //------------------------------------------------------------------------
270 
271 void MediaItem::setLoop( sal_Bool bLoop )
272 {
273 	mbLoop = bLoop;
274 	mnMaskSet |= AVMEDIA_SETMASK_LOOP;
275 }
276 
277 //------------------------------------------------------------------------
278 
279 sal_Bool MediaItem::isLoop() const
280 {
281 	return mbLoop;
282 }
283 
284 //------------------------------------------------------------------------
285 
286 void MediaItem::setMute( sal_Bool bMute )
287 {
288 	mbMute = bMute;
289 	mnMaskSet |= AVMEDIA_SETMASK_MUTE;
290 }
291 
292 //------------------------------------------------------------------------
293 
294 sal_Bool MediaItem::isMute() const
295 {
296 	return mbMute;
297 }
298 
299 //------------------------------------------------------------------------
300 
301 void MediaItem::setVolumeDB( sal_Int16 nDB )
302 {
303 	mnVolumeDB = nDB;
304 	mnMaskSet |= AVMEDIA_SETMASK_VOLUMEDB;
305 }
306 
307 //------------------------------------------------------------------------
308 
309 sal_Int16 MediaItem::getVolumeDB() const
310 {
311 	return mnVolumeDB;
312 }
313 
314 //------------------------------------------------------------------------
315 
316 void MediaItem::setZoom( ::com::sun::star::media::ZoomLevel eZoom )
317 {
318 	meZoom = eZoom;
319 	mnMaskSet |= AVMEDIA_SETMASK_ZOOM;
320 }
321 
322 //------------------------------------------------------------------------
323 
324 ::com::sun::star::media::ZoomLevel MediaItem::getZoom() const
325 {
326 	return meZoom;
327 }
328 
329 }
330