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 "mediacontrol.hxx"
25 #include "mediacontrol.hrc"
26 #include "mediamisc.hxx"
27 #include <avmedia/mediawindow.hxx>
28 #include <avmedia/mediaplayer.hxx>
29 #include "helpids.hrc"
30 #include <tools/time.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/lstbox.hxx>
33 #include <unotools/syslocale.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <math.h>
36 #include <algorithm>
37 
38 #define AVMEDIA_TIMEOUT				100
39 #define AVMEDIA_TIME_RANGE 			2048
40 #define AVMEDIA_DB_RANGE 			-40
41 #define AVMEDIA_LINEINCREMENT		1.0
42 #define AVMEDIA_PAGEINCREMENT		10.0
43 
44 #define AVMEDIA_TOOLBOXITEM_PLAY 	0x0001
45 #define AVMEDIA_TOOLBOXITEM_PLAYFFW 0x0002
46 #define AVMEDIA_TOOLBOXITEM_PAUSE 	0x0004
47 #define AVMEDIA_TOOLBOXITEM_STOP 	0x0008
48 #define AVMEDIA_TOOLBOXITEM_MUTE	0x0010
49 #define AVMEDIA_TOOLBOXITEM_LOOP	0x0011
50 #define AVMEDIA_TOOLBOXITEM_ZOOM	0x0012
51 #define AVMEDIA_TOOLBOXITEM_OPEN 	0x0014
52 #define AVMEDIA_TOOLBOXITEM_INSERT 	0x0018
53 
54 #define AVMEDIA_ZOOMLEVEL_50		0
55 #define AVMEDIA_ZOOMLEVEL_100		1
56 #define AVMEDIA_ZOOMLEVEL_200		2
57 #define AVMEDIA_ZOOMLEVEL_FIT		3
58 #define AVMEDIA_ZOOMLEVEL_SCALED	4
59 #define AVMEDIA_ZOOMLEVEL_INVALID	65535
60 
61 namespace avmedia
62 {
63 
64 // ----------------
65 // - MediaControl -
66 // ---------------
67 
MediaControl(Window * pParent,MediaControlStyle eControlStyle)68 MediaControl::MediaControl( Window* pParent, MediaControlStyle eControlStyle ) :
69     Control( pParent ),
70 	maImageList( AVMEDIA_RESID( AVMEDIA_IMGLST ) ),
71 	maItem( 0, AVMEDIA_SETMASK_ALL ),
72     maPlayToolBox( this, WB_3DLOOK ),
73 	maTimeSlider( this, WB_HORZ | WB_DRAG | WB_3DLOOK | WB_SLIDERSET ),
74     maMuteToolBox( this, WB_3DLOOK ),
75 	maVolumeSlider( this, WB_HORZ | WB_DRAG | WB_SLIDERSET ),
76 	maZoomToolBox( this, WB_3DLOOK ),
77 	mpZoomListBox( new ListBox( &maZoomToolBox, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL | WB_3DLOOK ) ),
78     maTimeEdit( this, WB_CENTER | WB_READONLY | WB_BORDER | WB_3DLOOK | WB_READONLY ),
79 	meControlStyle( eControlStyle ),
80 	mbLocked( false )
81 {
82     const String aTimeText( RTL_CONSTASCII_USTRINGPARAM( " 00:00:00/00:00:00 " ) );
83 
84 	SetBackground();
85     SetPaintTransparent( sal_True );
86     SetParentClipMode( PARENTCLIPMODE_NOCLIP );
87 
88     if( MEDIACONTROLSTYLE_SINGLELINE != meControlStyle )
89 	{
90     	maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_OPEN, implGetImage( AVMEDIA_IMG_OPEN ), String( AVMEDIA_RESID( AVMEDIA_STR_OPEN ) ) );
91     	maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_OPEN, HID_AVMEDIA_TOOLBOXITEM_OPEN );
92 
93     	maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_INSERT, implGetImage( AVMEDIA_IMG_INSERT ), String( AVMEDIA_RESID( AVMEDIA_STR_INSERT ) ) );
94     	maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_INSERT, HID_AVMEDIA_TOOLBOXITEM_INSERT );
95 
96 		maPlayToolBox.InsertSeparator();
97 	}
98 	else
99 	{
100 		mpZoomListBox->SetBackground();
101 
102 		maZoomToolBox.SetBackground();
103 		maZoomToolBox.SetPaintTransparent( sal_True );
104 		maPlayToolBox.SetBackground();
105 		maPlayToolBox.SetPaintTransparent( sal_True );
106 		maMuteToolBox.SetBackground();
107 		maMuteToolBox.SetPaintTransparent( sal_True );
108 
109 	}
110 
111     maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PLAY, implGetImage( AVMEDIA_IMG_PLAY ), String( AVMEDIA_RESID( AVMEDIA_STR_PLAY ) ), TIB_CHECKABLE );
112    	maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PLAY, HID_AVMEDIA_TOOLBOXITEM_PLAY );
113 
114 	maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PAUSE, implGetImage( AVMEDIA_IMG_PAUSE ), String( AVMEDIA_RESID( AVMEDIA_STR_PAUSE ) ), TIB_CHECKABLE );
115    	maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PAUSE, HID_AVMEDIA_TOOLBOXITEM_PAUSE );
116 
117 	maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_STOP, implGetImage( AVMEDIA_IMG_STOP ), String( AVMEDIA_RESID( AVMEDIA_STR_STOP ) ), TIB_CHECKABLE );
118    	maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_STOP, HID_AVMEDIA_TOOLBOXITEM_STOP );
119 
120 	maPlayToolBox.InsertSeparator();
121 
122     maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_LOOP, implGetImage( AVMEDIA_IMG_ENDLESS ), String( AVMEDIA_RESID( AVMEDIA_STR_ENDLESS ) ) );
123    	maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_LOOP, HID_AVMEDIA_TOOLBOXITEM_LOOP );
124 
125 	if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
126 		maPlayToolBox.InsertSeparator();
127 
128     maPlayToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
129     maPlayToolBox.SetSizePixel( maPlayToolBox.CalcWindowSizePixel() );
130     maPlayToolBox.Show();
131 	maMinSize = maPlayToolBox.GetSizePixel();
132 
133     maTimeSlider.SetSlideHdl( LINK( this, MediaControl, implTimeHdl ) );
134     maTimeSlider.SetEndSlideHdl( LINK( this, MediaControl, implTimeEndHdl ) );
135     maTimeSlider.SetRange( Range( 0, AVMEDIA_TIME_RANGE ) );
136 	maTimeSlider.SetHelpId( HID_AVMEDIA_TIMESLIDER );
137     maTimeSlider.SetUpdateMode( true );
138     maTimeSlider.SetSizePixel( Size( 128, maPlayToolBox.GetSizePixel().Height() ) );
139     maTimeSlider.Show();
140 	maMinSize.Width() += maTimeSlider.GetSizePixel().Width();
141 
142     maTimeEdit.SetText( aTimeText );
143     maTimeEdit.SetUpdateMode( true );
144     maTimeEdit.SetSizePixel( Size( maTimeEdit.GetTextWidth( aTimeText ) + 8, maPlayToolBox.GetSizePixel().Height() ) );
145 	maTimeEdit.SetControlBackground( Application::GetSettings().GetStyleSettings().GetWindowColor() );
146 	maTimeEdit.SetHelpId( HID_AVMEDIA_TIMEEDIT );
147 	maTimeEdit.Disable();
148     maTimeEdit.Show();
149 	maMinSize.Width() += maTimeEdit.GetSizePixel().Width();
150 
151 	if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
152 		maMuteToolBox.InsertSeparator();
153 
154     maMuteToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_MUTE, implGetImage( AVMEDIA_IMG_MUTE ), String( AVMEDIA_RESID( AVMEDIA_STR_MUTE ) ) );
155    	maMuteToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_MUTE, HID_AVMEDIA_TOOLBOXITEM_MUTE );
156 
157 	maMuteToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
158     maMuteToolBox.SetSizePixel( maMuteToolBox.CalcWindowSizePixel() );
159     maMuteToolBox.Show();
160 	maMinSize.Width() += maMuteToolBox.GetSizePixel().Width();
161 
162     maVolumeSlider.SetSlideHdl( LINK( this, MediaControl, implVolumeHdl ) );
163     maVolumeSlider.SetEndSlideHdl( LINK( this, MediaControl, implVolumeEndHdl ) );
164     maVolumeSlider.SetRange( Range( AVMEDIA_DB_RANGE, 0 ) );
165     maVolumeSlider.SetUpdateMode( true );
166     maVolumeSlider.SetHelpId( HID_AVMEDIA_VOLUMESLIDER );
167     maVolumeSlider.SetSizePixel( Size( 48, maPlayToolBox.GetSizePixel().Height() ) );
168 	maVolumeSlider.Show();
169 	maMinSize.Width() += maVolumeSlider.GetSizePixel().Width();
170 
171 	mpZoomListBox->SetSizePixel( Size( maTimeEdit.GetSizePixel().Width(), 260 ) );
172 	mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_50 ) ), AVMEDIA_ZOOMLEVEL_50 );
173 	mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_100 ) ), AVMEDIA_ZOOMLEVEL_100 );
174 	mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_200 ) ), AVMEDIA_ZOOMLEVEL_200 );
175 	mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_FIT ) ), AVMEDIA_ZOOMLEVEL_FIT );
176     mpZoomListBox->SetSelectHdl( LINK( this, MediaControl, implZoomSelectHdl ) );
177     mpZoomListBox->SetHelpId( HID_AVMEDIA_ZOOMLISTBOX );
178 
179     maZoomToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_ZOOM, String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM ) ) );
180     maZoomToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_ZOOM, HID_AVMEDIA_ZOOMLISTBOX );
181 
182     maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, mpZoomListBox );
183 	maZoomToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
184     maZoomToolBox.SetSizePixel( maZoomToolBox.CalcWindowSizePixel() );
185     maZoomToolBox.Show();
186 	maMinSize.Width() += maZoomToolBox.GetSizePixel().Width();
187 
188 	if( MEDIACONTROLSTYLE_MULTILINE == meControlStyle )
189 	{
190 		maMinSize.Width() = 256;
191 		maMinSize.Height() = ( maMinSize.Height() << 1 ) + AVMEDIA_CONTROLOFFSET;
192 	}
193 
194 	maTimer.SetTimeout( AVMEDIA_TIMEOUT );
195     maTimer.SetTimeoutHdl( LINK( this, MediaControl, implTimeoutHdl ) );
196 	maTimer.Start();
197 }
198 
199 // ------------------------------------------------------------------------------
200 
~MediaControl()201 MediaControl::~MediaControl()
202 {
203     maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, NULL );
204 	delete mpZoomListBox;
205 }
206 
207 // ------------------------------------------------------------------------------
208 
getMinSizePixel() const209 const Size&	MediaControl::getMinSizePixel() const
210 {
211 	return maMinSize;
212 }
213 
214 // ------------------------------------------------------------------------------
215 
Resize()216 void MediaControl::Resize()
217 {
218 	Point 			aPos( 0, 0 );
219 	const sal_Int32	nPlayToolBoxWidth = maPlayToolBox.GetSizePixel().Width();
220 	const sal_Int32	nMuteToolBoxWidth = maMuteToolBox.GetSizePixel().Width();
221 	const sal_Int32	nVolumeSliderWidth = maVolumeSlider.GetSizePixel().Width();
222 	const sal_Int32 nZoomToolBoxWidth = maZoomToolBox.GetSizePixel().Width();
223 	const sal_Int32	nTimeEditWidth = maTimeEdit.GetSizePixel().Width();
224 	const sal_Int32	nTimeSliderHeight = maTimeSlider.GetSizePixel().Height();
225 
226 	if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
227 	{
228 		const sal_Int32	nTimeSliderWidth = GetSizePixel().Width() - ( AVMEDIA_CONTROLOFFSET * 3 ) -
229 										   nPlayToolBoxWidth - nMuteToolBoxWidth - nVolumeSliderWidth - nTimeEditWidth - nZoomToolBoxWidth;
230 
231 		maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() );
232 
233 		aPos.X() += nPlayToolBoxWidth;
234 		maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) );
235 
236 		aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET;
237 		maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() );
238 
239 		aPos.X() += nTimeEditWidth + AVMEDIA_CONTROLOFFSET;
240 		maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() );
241 
242 		aPos.X() += nMuteToolBoxWidth;
243 		maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() );
244 
245 		aPos.X() += nVolumeSliderWidth + AVMEDIA_CONTROLOFFSET;
246 		maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() );
247 	}
248 	else
249 	{
250 		const sal_Int32	nTimeSliderWidth = GetSizePixel().Width() - AVMEDIA_CONTROLOFFSET - nTimeEditWidth;
251 
252 		maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) );
253 
254 		aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET;
255 		maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() );
256 
257 		aPos.X() = 0;
258 		aPos.Y() += nTimeSliderHeight + AVMEDIA_CONTROLOFFSET;
259 		maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() );
260 
261 		aPos.X() = GetSizePixel().Width() - nVolumeSliderWidth - nMuteToolBoxWidth - nZoomToolBoxWidth - AVMEDIA_CONTROLOFFSET;
262 		maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() );
263 
264 		aPos.X() += nMuteToolBoxWidth;
265 		maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() );
266 
267 		aPos.X() = GetSizePixel().Width() - nZoomToolBoxWidth;
268 		maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() );
269 	}
270 }
271 
272 // ------------------------------------------------------------------------------
273 
setState(const MediaItem & rItem)274 void MediaControl::setState( const MediaItem& rItem )
275 {
276     if( !mbLocked )
277     {
278 	    maItem.merge( rItem );
279 
280 	    implUpdateToolboxes();
281 	    implUpdateTimeSlider();
282 	    implUpdateVolumeSlider();
283 	    implUpdateTimeField( maItem.getTime() );
284 	}
285 }
286 
287 // ------------------------------------------------------------------------------
288 
getState(MediaItem & rItem) const289 void MediaControl::getState( MediaItem& rItem ) const
290 {
291 	rItem.merge( maItem );
292 }
293 
294 // ------------------------------------------------------------------------------
295 
update()296 void MediaControl::update()
297 {
298 }
299 
300 // ------------------------------------------------------------------------------
301 
execute(const MediaItem &)302 void MediaControl::execute( const MediaItem& )
303 {
304 }
305 
306 // ------------------------------------------------------------------------------
307 
implUpdateToolboxes()308 void MediaControl::implUpdateToolboxes()
309 {
310 	const bool bValidURL = !maItem.getURL().isEmpty();
311 
312 	maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_INSERT, bValidURL );
313 	maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAY, bValidURL );
314 	maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, bValidURL );
315 	maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PAUSE, bValidURL );
316 	maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_STOP, bValidURL );
317 	maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_LOOP, bValidURL );
318 	maMuteToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_MUTE, bValidURL );
319 
320 	if( !bValidURL || !IsEnabled() )
321 	{
322 		mpZoomListBox->Disable();
323 
324         if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
325     	    maPlayToolBox.Disable();
326 
327         maMuteToolBox.Disable();
328 	}
329 	else
330 	{
331 	    maPlayToolBox.Enable();
332 	    maMuteToolBox.Enable();
333 
334 		if( MEDIASTATE_PLAY == maItem.getState() || MEDIASTATE_PLAYFFW == maItem.getState() )
335 		{
336 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, true );
337 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, MEDIASTATE_PLAYFFW == maItem.getState() );
338 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false );
339 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false );
340 		}
341 		else if( maItem.getTime() > 0.0 && ( maItem.getTime() < maItem.getDuration() ) )
342 		{
343 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false );
344 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false );
345 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, true );
346 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false );
347 		}
348 		else
349 		{
350 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false );
351 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false );
352 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false );
353 			maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, true );
354 		}
355 
356 		maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_LOOP, maItem.isLoop() );
357 		maMuteToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_MUTE, maItem.isMute() );
358 
359 		if( !mpZoomListBox->IsTravelSelect() && !mpZoomListBox->IsInDropDown() )
360 		{
361 			sal_uInt16 nSelectEntryPos ;
362 
363 			switch( maItem.getZoom() )
364 			{
365 				case( ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_50; break;
366 				case( ::com::sun::star::media::ZoomLevel_ORIGINAL ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_100; break;
367 				case( ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_200; break;
368 				case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_FIT; break;
369 				case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_SCALED; break;
370 
371 				default: nSelectEntryPos = AVMEDIA_ZOOMLEVEL_INVALID; break;
372 			}
373 
374 			if( nSelectEntryPos != AVMEDIA_ZOOMLEVEL_INVALID )
375 			{
376 				mpZoomListBox->Enable();
377 				mpZoomListBox->SelectEntryPos( nSelectEntryPos );
378 			}
379 			else
380 				mpZoomListBox->Disable();
381 		}
382 	}
383 }
384 
385 // ------------------------------------------------------------------------------
386 
implUpdateTimeSlider()387 void MediaControl::implUpdateTimeSlider()
388 {
389 	if( maItem.getURL().isEmpty() || !IsEnabled() )
390 		maTimeSlider.Disable();
391 	else
392 	{
393 		maTimeSlider.Enable();
394 
395 		const double fDuration = maItem.getDuration();
396 
397 		if( fDuration > 0.0 )
398 		{
399 			const double fTime = ::std::min( maItem.getTime(), fDuration );
400 
401 			if( !maTimeSlider.GetLineSize() )
402 				maTimeSlider.SetLineSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_LINEINCREMENT / fDuration ) );
403 
404 			if( !maTimeSlider.GetPageSize() )
405 				maTimeSlider.SetPageSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_PAGEINCREMENT / fDuration ) );
406 
407 			maTimeSlider.SetThumbPos( static_cast< sal_Int32 >( fTime / fDuration * AVMEDIA_TIME_RANGE ) );
408 		}
409 	}
410 }
411 
412 // ------------------------------------------------------------------------------
413 
implUpdateVolumeSlider()414 void MediaControl::implUpdateVolumeSlider()
415 {
416 	if( maItem.getURL().isEmpty() || !IsEnabled() )
417 		maVolumeSlider.Disable();
418 	else
419 	{
420 		maVolumeSlider.Enable();
421 
422 		const sal_Int32 nVolumeDB = maItem.getVolumeDB();
423 
424 		maVolumeSlider.SetThumbPos( ::std::min( ::std::max( nVolumeDB, static_cast< sal_Int32 >( AVMEDIA_DB_RANGE ) ),
425 												static_cast< sal_Int32 >( 0 ) ) );
426 	}
427 }
428 
429 // ------------------------------------------------------------------------------
430 
implUpdateTimeField(double fCurTime)431 void MediaControl::implUpdateTimeField( double fCurTime )
432 {
433     if( !maItem.getURL().isEmpty() )
434 	{
435 		String				aTimeString;
436 
437         SvtSysLocale aSysLocale;
438         const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
439 
440         aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( fCurTime ) ) ) );
441 		aTimeString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " / " ));
442         aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( maItem.getDuration() ) )) );
443 
444 		if( maTimeEdit.GetText() != aTimeString )
445 		    maTimeEdit.SetText( aTimeString );
446 	}
447 }
448 
449 // ------------------------------------------------------------------------------
450 
implGetImage(sal_Int32 nImageId) const451 Image MediaControl::implGetImage( sal_Int32 nImageId ) const
452 {
453 	return maImageList.GetImage( static_cast< sal_uInt16 >( nImageId ) );
454 }
455 
456 // ------------------------------------------------------------------------------
457 
IMPL_LINK(MediaControl,implTimeHdl,Slider *,p)458 IMPL_LINK( MediaControl, implTimeHdl, Slider*, p )
459 {
460     mbLocked = true;
461 	maTimer.Stop();
462 	implUpdateTimeField( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE );
463 
464 	return 0;
465 }
466 
467 // ------------------------------------------------------------------------------
468 
IMPL_LINK(MediaControl,implTimeEndHdl,Slider *,p)469 IMPL_LINK( MediaControl, implTimeEndHdl, Slider*, p )
470 {
471 	MediaItem aExecItem;
472 
473 	aExecItem.setTime( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE );
474 	execute( aExecItem );
475 	update();
476 	maTimer.Start();
477 	mbLocked = false;
478 
479 	return 0;
480 }
481 
482 // ------------------------------------------------------------------------------
483 
IMPL_LINK(MediaControl,implVolumeHdl,Slider *,p)484 IMPL_LINK( MediaControl, implVolumeHdl, Slider*, p )
485 {
486 	MediaItem aExecItem;
487 
488 	aExecItem.setVolumeDB( static_cast< sal_Int16 >( p->GetThumbPos() ) );
489 	execute( aExecItem );
490 	update();
491 
492 	return 0;
493 }
494 
495 // ------------------------------------------------------------------------------
496 
IMPL_LINK(MediaControl,implVolumeEndHdl,Slider *,EMPTYARG)497 IMPL_LINK( MediaControl, implVolumeEndHdl, Slider*, EMPTYARG )
498 {
499 	return 0;
500 }
501 
502 // ------------------------------------------------------------------------------
503 
IMPL_LINK(MediaControl,implSelectHdl,ToolBox *,p)504 IMPL_LINK( MediaControl, implSelectHdl, ToolBox*, p )
505 {
506     if( p )
507     {
508 		MediaItem aExecItem;
509 
510 		switch( p->GetCurItemId() )
511         {
512 			case( AVMEDIA_TOOLBOXITEM_OPEN ):
513 			{
514 				::rtl::OUString aURL;
515 
516 				 if( ::avmedia::MediaWindow::executeMediaURLDialog( GetParent(), aURL, false ) )
517 				 {
518 				 	if( !::avmedia::MediaWindow::isMediaURL( aURL, true ) )
519 						::avmedia::MediaWindow::executeFormatErrorBox( this );
520 					else
521 					{
522 						aExecItem.setURL( aURL );
523 						aExecItem.setState( MEDIASTATE_PLAY );
524 					}
525 				}
526 			}
527 			break;
528 
529 			case( AVMEDIA_TOOLBOXITEM_INSERT ):
530 			{
531 				MediaFloater* pFloater = AVMEDIA_MEDIAWINDOW();
532 
533 				if( pFloater )
534 					pFloater->dispatchCurrentURL();
535 			}
536 			break;
537 
538 			case( AVMEDIA_TOOLBOXITEM_PLAY ):
539 			case( AVMEDIA_TOOLBOXITEM_PLAYFFW ):
540             {
541 				aExecItem.setState( ( AVMEDIA_TOOLBOXITEM_PLAYFFW == p->GetCurItemId() ) ? MEDIASTATE_PLAYFFW : MEDIASTATE_PLAY );
542 
543                 if( maItem.getTime() == maItem.getDuration() )
544 					aExecItem.setTime( 0.0 );
545 				else
546 					aExecItem.setTime( maItem.getTime() );
547             }
548             break;
549 
550             case( AVMEDIA_TOOLBOXITEM_PAUSE ):
551 			{
552 				aExecItem.setState( MEDIASTATE_PAUSE );
553 			}
554             break;
555 
556 			case( AVMEDIA_TOOLBOXITEM_STOP ):
557             {
558 				aExecItem.setState( MEDIASTATE_STOP );
559 				aExecItem.setTime( 0.0 );
560             }
561             break;
562 
563             case( AVMEDIA_TOOLBOXITEM_MUTE ):
564 			{
565                 aExecItem.setMute( !maMuteToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_MUTE ) );
566 			}
567             break;
568 
569             case( AVMEDIA_TOOLBOXITEM_LOOP ):
570 			{
571                 aExecItem.setLoop( !maPlayToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_LOOP ) );
572 			}
573             break;
574 
575             default:
576             break;
577         }
578 
579 		if( aExecItem.getMaskSet() != AVMEDIA_SETMASK_NONE )
580 			execute( aExecItem );
581     }
582 
583 	update();
584 	p->Invalidate( INVALIDATE_UPDATE );
585 
586     return 0;
587 }
588 
589 // ------------------------------------------------------------------------------
590 
IMPL_LINK(MediaControl,implZoomSelectHdl,ListBox *,p)591 IMPL_LINK( MediaControl, implZoomSelectHdl, ListBox*, p )
592 {
593     if( p )
594     {
595 		MediaItem aExecItem;
596 		::com::sun::star::media::ZoomLevel eLevel;
597 
598 		switch( p->GetSelectEntryPos() )
599 		{
600 			case( AVMEDIA_ZOOMLEVEL_50 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2; break;
601 			case( AVMEDIA_ZOOMLEVEL_100 ): eLevel = ::com::sun::star::media::ZoomLevel_ORIGINAL; break;
602 			case( AVMEDIA_ZOOMLEVEL_200 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1; break;
603 			case( AVMEDIA_ZOOMLEVEL_FIT ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT; break;
604 			case( AVMEDIA_ZOOMLEVEL_SCALED ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW; break;
605 
606 			default: eLevel = ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE; break;
607 		}
608 
609 		aExecItem.setZoom( eLevel );
610 		execute( aExecItem );
611 		update();
612 	}
613 
614 	return 0;
615 }
616 
617 // ------------------------------------------------------------------------------
618 
IMPL_LINK(MediaControl,implTimeoutHdl,Timer *,EMPTYARG)619 IMPL_LINK( MediaControl, implTimeoutHdl, Timer*, EMPTYARG )
620 {
621 	update();
622 	maTimer.Start();
623 
624 	return 0;
625 }
626 
627 }
628