1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #include <avmedia/mediaitem.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26
27 using namespace ::com::sun::star;
28
29 namespace avmedia
30 {
31
32 // -------------
33 // - MediaItem -
34 // -------------
35
36 TYPEINIT1_AUTOFACTORY( MediaItem, ::SfxPoolItem );
37 ::rtl::OUString maURL;
38 sal_uInt32 mnMaskSet;
39 MediaState meState;
40 double mfTime;
41 double mfDuration;
42 sal_Int16 mnVolumeDB;
43 sal_Bool mbLoop;
44 sal_Bool mbMute;
45 ::com::sun::star::media::ZoomLevel meZoom;
46
47 // ------------------------------------------------------------------------------
48
MediaItem(sal_uInt16 _nWhich,sal_uInt32 nMaskSet)49 MediaItem::MediaItem( sal_uInt16 _nWhich, sal_uInt32 nMaskSet ) :
50 SfxPoolItem( _nWhich ),
51 mnMaskSet( nMaskSet ),
52 meState( MEDIASTATE_STOP ),
53 mfTime( 0.0 ),
54 mfDuration( 0.0 ),
55 mnVolumeDB( 0 ),
56 mbLoop( false ),
57 mbMute( false ),
58 meZoom( ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE )
59 {
60 }
61
62 // ------------------------------------------------------------------------------
63
MediaItem(const MediaItem & rItem)64 MediaItem::MediaItem( const MediaItem& rItem ) :
65 SfxPoolItem( rItem ),
66 maURL( rItem.maURL ),
67 mnMaskSet( rItem.mnMaskSet ),
68 meState( rItem.meState ),
69 mfTime( rItem.mfTime ),
70 mfDuration( rItem.mfDuration ),
71 mnVolumeDB( rItem.mnVolumeDB ),
72 mbLoop( rItem.mbLoop ),
73 mbMute( rItem.mbMute ),
74 meZoom( rItem.meZoom )
75 {
76 }
77
78 // ------------------------------------------------------------------------------
79
~MediaItem()80 MediaItem::~MediaItem()
81 {
82 }
83
84 // ------------------------------------------------------------------------------
85
operator ==(const SfxPoolItem & rItem) const86 int MediaItem::operator==( const SfxPoolItem& rItem ) const
87 {
88 DBG_ASSERT( SfxPoolItem::operator==(rItem), "unequal types" );
89 return( mnMaskSet == static_cast< const MediaItem& >( rItem ).mnMaskSet &&
90 maURL == static_cast< const MediaItem& >( rItem ).maURL &&
91 meState == static_cast< const MediaItem& >( rItem ).meState &&
92 mfDuration == static_cast< const MediaItem& >( rItem ).mfDuration &&
93 mfTime == static_cast< const MediaItem& >( rItem ).mfTime &&
94 mnVolumeDB == static_cast< const MediaItem& >( rItem ).mnVolumeDB &&
95 mbLoop == static_cast< const MediaItem& >( rItem ).mbLoop &&
96 mbMute == static_cast< const MediaItem& >( rItem ).mbMute &&
97 meZoom == static_cast< const MediaItem& >( rItem ).meZoom );
98 }
99
100 // ------------------------------------------------------------------------------
101
Clone(SfxItemPool *) const102 SfxPoolItem* MediaItem::Clone( SfxItemPool* ) const
103 {
104 return new MediaItem( *this );
105 }
106
107 //------------------------------------------------------------------------
108
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const109 SfxItemPresentation MediaItem::GetPresentation( SfxItemPresentation,
110 SfxMapUnit,
111 SfxMapUnit,
112 XubString& rText,
113 const IntlWrapper * ) const
114 {
115 rText.Erase();
116 return SFX_ITEM_PRESENTATION_NONE;
117 }
118
119 //------------------------------------------------------------------------
120
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const121 sal_Bool MediaItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
122 {
123 uno::Sequence< uno::Any > aSeq( 9 );
124
125 aSeq[ 0 ] <<= maURL;
126 aSeq[ 1 ] <<= mnMaskSet;
127 aSeq[ 2 ] <<= static_cast< sal_Int32 >( meState );
128 aSeq[ 3 ] <<= mfTime;
129 aSeq[ 4 ] <<= mfDuration;
130 aSeq[ 5 ] <<= mnVolumeDB;
131 aSeq[ 6 ] <<= mbLoop;
132 aSeq[ 7 ] <<= mbMute;
133 aSeq[ 8 ] <<= meZoom;
134
135 rVal <<= aSeq;
136
137 return true;
138 }
139
140 //------------------------------------------------------------------------
141
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)142 sal_Bool MediaItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
143 {
144 uno::Sequence< uno::Any > aSeq;
145 sal_Bool bRet = false;
146
147 if( ( rVal >>= aSeq ) && ( aSeq.getLength() == 9 ) )
148 {
149 sal_Int32 nInt32 = 0;
150
151 aSeq[ 0 ] >>= maURL;
152 aSeq[ 1 ] >>= mnMaskSet;
153 aSeq[ 2 ] >>= nInt32; meState = static_cast< MediaState >( nInt32 );
154 aSeq[ 3 ] >>= mfTime;
155 aSeq[ 4 ] >>= mfDuration;
156 aSeq[ 5 ] >>= mnVolumeDB;
157 aSeq[ 6 ] >>= mbLoop;
158 aSeq[ 7 ] >>= mbMute;
159 aSeq[ 8 ] >>= meZoom;
160
161 bRet = true;
162 }
163
164 return bRet;
165 }
166
167 //------------------------------------------------------------------------
168
merge(const MediaItem & rMediaItem)169 void MediaItem::merge( const MediaItem& rMediaItem )
170 {
171 const sal_uInt32 nMaskSet = rMediaItem.getMaskSet();
172
173 if( AVMEDIA_SETMASK_URL & nMaskSet )
174 setURL( rMediaItem.getURL() );
175
176 if( AVMEDIA_SETMASK_STATE & nMaskSet )
177 setState( rMediaItem.getState() );
178
179 if( AVMEDIA_SETMASK_DURATION & nMaskSet )
180 setDuration( rMediaItem.getDuration() );
181
182 if( AVMEDIA_SETMASK_TIME & nMaskSet )
183 setTime( rMediaItem.getTime() );
184
185 if( AVMEDIA_SETMASK_LOOP & nMaskSet )
186 setLoop( rMediaItem.isLoop() );
187
188 if( AVMEDIA_SETMASK_MUTE & nMaskSet )
189 setMute( rMediaItem.isMute() );
190
191 if( AVMEDIA_SETMASK_VOLUMEDB & nMaskSet )
192 setVolumeDB( rMediaItem.getVolumeDB() );
193
194 if( AVMEDIA_SETMASK_ZOOM & nMaskSet )
195 setZoom( rMediaItem.getZoom() );
196 }
197
198 //------------------------------------------------------------------------
199
getMaskSet() const200 sal_uInt32 MediaItem::getMaskSet() const
201 {
202 return mnMaskSet;
203 }
204
205 //------------------------------------------------------------------------
206
setURL(const::rtl::OUString & rURL)207 void MediaItem::setURL( const ::rtl::OUString& rURL )
208 {
209 maURL = rURL;
210 mnMaskSet |= AVMEDIA_SETMASK_URL;
211 }
212
213 //------------------------------------------------------------------------
214
getURL() const215 const ::rtl::OUString& MediaItem::getURL() const
216 {
217 return maURL;
218 }
219
220 //------------------------------------------------------------------------
221
setState(MediaState eState)222 void MediaItem::setState( MediaState eState )
223 {
224 meState = eState;
225 mnMaskSet |= AVMEDIA_SETMASK_STATE;
226 }
227
228 //------------------------------------------------------------------------
229
getState() const230 MediaState MediaItem::getState() const
231 {
232 return meState;
233 }
234
235 //------------------------------------------------------------------------
236
setDuration(double fDuration)237 void MediaItem::setDuration( double fDuration )
238 {
239 mfDuration = fDuration;
240 mnMaskSet |= AVMEDIA_SETMASK_DURATION;
241 }
242
243 //------------------------------------------------------------------------
244
getDuration() const245 double MediaItem::getDuration() const
246 {
247 return mfDuration;
248 }
249
250 //------------------------------------------------------------------------
251
setTime(double fTime)252 void MediaItem::setTime( double fTime )
253 {
254 mfTime = fTime;
255 mnMaskSet |= AVMEDIA_SETMASK_TIME;
256 }
257
258 //------------------------------------------------------------------------
259
getTime() const260 double MediaItem::getTime() const
261 {
262 return mfTime;
263 }
264
265 //------------------------------------------------------------------------
266
setLoop(sal_Bool bLoop)267 void MediaItem::setLoop( sal_Bool bLoop )
268 {
269 mbLoop = bLoop;
270 mnMaskSet |= AVMEDIA_SETMASK_LOOP;
271 }
272
273 //------------------------------------------------------------------------
274
isLoop() const275 sal_Bool MediaItem::isLoop() const
276 {
277 return mbLoop;
278 }
279
280 //------------------------------------------------------------------------
281
setMute(sal_Bool bMute)282 void MediaItem::setMute( sal_Bool bMute )
283 {
284 mbMute = bMute;
285 mnMaskSet |= AVMEDIA_SETMASK_MUTE;
286 }
287
288 //------------------------------------------------------------------------
289
isMute() const290 sal_Bool MediaItem::isMute() const
291 {
292 return mbMute;
293 }
294
295 //------------------------------------------------------------------------
296
setVolumeDB(sal_Int16 nDB)297 void MediaItem::setVolumeDB( sal_Int16 nDB )
298 {
299 mnVolumeDB = nDB;
300 mnMaskSet |= AVMEDIA_SETMASK_VOLUMEDB;
301 }
302
303 //------------------------------------------------------------------------
304
getVolumeDB() const305 sal_Int16 MediaItem::getVolumeDB() const
306 {
307 return mnVolumeDB;
308 }
309
310 //------------------------------------------------------------------------
311
setZoom(::com::sun::star::media::ZoomLevel eZoom)312 void MediaItem::setZoom( ::com::sun::star::media::ZoomLevel eZoom )
313 {
314 meZoom = eZoom;
315 mnMaskSet |= AVMEDIA_SETMASK_ZOOM;
316 }
317
318 //------------------------------------------------------------------------
319
getZoom() const320 ::com::sun::star::media::ZoomLevel MediaItem::getZoom() const
321 {
322 return meZoom;
323 }
324
325 }
326