Updated core
[LibreOffice.git] / avmedia / source / framework / mediacontrol.cxx
blob09355e12b59e94b17e4ddeaa07aa91f525891733
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "mediacontrol.hxx"
21 #include "mediacontrol.hrc"
22 #include "mediamisc.hxx"
23 #include <avmedia/mediawindow.hxx>
24 #include <avmedia/mediaplayer.hxx>
25 #include "helpids.hrc"
26 #include <tools/time.hxx>
27 #include <svtools/miscopt.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/lstbox.hxx>
30 #include <unotools/syslocale.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <math.h>
33 #include <algorithm>
35 #define AVMEDIA_TIMEOUT 100
36 #define AVMEDIA_TIME_RANGE 2048
37 #define AVMEDIA_DB_RANGE -40
38 #define AVMEDIA_LINEINCREMENT 1.0
39 #define AVMEDIA_PAGEINCREMENT 10.0
41 #define AVMEDIA_TOOLBOXITEM_PLAY 0x0001
42 #define AVMEDIA_TOOLBOXITEM_PLAYFFW 0x0002
43 #define AVMEDIA_TOOLBOXITEM_PAUSE 0x0004
44 #define AVMEDIA_TOOLBOXITEM_STOP 0x0008
45 #define AVMEDIA_TOOLBOXITEM_MUTE 0x0010
46 #define AVMEDIA_TOOLBOXITEM_LOOP 0x0011
47 #define AVMEDIA_TOOLBOXITEM_ZOOM 0x0012
48 #define AVMEDIA_TOOLBOXITEM_OPEN 0x0014
49 #define AVMEDIA_TOOLBOXITEM_INSERT 0x0018
51 #define AVMEDIA_ZOOMLEVEL_50 0
52 #define AVMEDIA_ZOOMLEVEL_100 1
53 #define AVMEDIA_ZOOMLEVEL_200 2
54 #define AVMEDIA_ZOOMLEVEL_FIT 3
55 #define AVMEDIA_ZOOMLEVEL_SCALED 4
56 #define AVMEDIA_ZOOMLEVEL_INVALID 65535
58 namespace avmedia
61 // ----------------
62 // - MediaControl -
63 // ---------------
65 MediaControl::MediaControl( Window* pParent, MediaControlStyle eControlStyle ) :
66 Control( pParent ),
67 maImageList( SvtMiscOptions().AreCurrentSymbolsLarge() ? AVMEDIA_RESID( AVMEDIA_IMGLST_L ) : AVMEDIA_RESID( AVMEDIA_IMGLST ) ),
68 maItem( 0, AVMEDIA_SETMASK_ALL ),
69 maPlayToolBox( this, WB_3DLOOK ),
70 maTimeSlider( this, WB_HORZ | WB_DRAG | WB_3DLOOK | WB_SLIDERSET ),
71 maMuteToolBox( this, WB_3DLOOK ),
72 maVolumeSlider( this, WB_HORZ | WB_DRAG | WB_SLIDERSET ),
73 maZoomToolBox( this, WB_3DLOOK ),
74 mpZoomListBox( new ListBox( &maZoomToolBox, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL | WB_3DLOOK ) ),
75 maTimeEdit( this, WB_CENTER | WB_READONLY | WB_BORDER | WB_3DLOOK | WB_READONLY ),
76 meControlStyle( eControlStyle ),
77 mbLocked( false )
79 const OUString aTimeText( " 00:00:00/00:00:00 " );
81 SetBackground();
82 SetPaintTransparent( sal_True );
83 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
85 if( MEDIACONTROLSTYLE_SINGLELINE != meControlStyle )
87 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_OPEN, implGetImage( AVMEDIA_IMG_OPEN ), OUString( AVMEDIA_RESID( AVMEDIA_STR_OPEN ) ) );
88 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_OPEN, HID_AVMEDIA_TOOLBOXITEM_OPEN );
90 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_INSERT, implGetImage( AVMEDIA_IMG_INSERT ), OUString( AVMEDIA_RESID( AVMEDIA_STR_INSERT ) ) );
91 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_INSERT, HID_AVMEDIA_TOOLBOXITEM_INSERT );
93 maPlayToolBox.InsertSeparator();
95 else
97 mpZoomListBox->SetBackground();
99 maZoomToolBox.SetBackground();
100 maZoomToolBox.SetPaintTransparent( sal_True );
101 maPlayToolBox.SetBackground();
102 maPlayToolBox.SetPaintTransparent( sal_True );
103 maMuteToolBox.SetBackground();
104 maMuteToolBox.SetPaintTransparent( sal_True );
108 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PLAY, implGetImage( AVMEDIA_IMG_PLAY ), OUString( AVMEDIA_RESID( AVMEDIA_STR_PLAY ) ), TIB_CHECKABLE );
109 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PLAY, HID_AVMEDIA_TOOLBOXITEM_PLAY );
111 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PAUSE, implGetImage( AVMEDIA_IMG_PAUSE ), OUString( AVMEDIA_RESID( AVMEDIA_STR_PAUSE ) ), TIB_CHECKABLE );
112 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PAUSE, HID_AVMEDIA_TOOLBOXITEM_PAUSE );
114 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_STOP, implGetImage( AVMEDIA_IMG_STOP ), OUString( AVMEDIA_RESID( AVMEDIA_STR_STOP ) ), TIB_CHECKABLE );
115 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_STOP, HID_AVMEDIA_TOOLBOXITEM_STOP );
117 maPlayToolBox.InsertSeparator();
119 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_LOOP, implGetImage( AVMEDIA_IMG_ENDLESS ), OUString( AVMEDIA_RESID( AVMEDIA_STR_ENDLESS ) ) );
120 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_LOOP, HID_AVMEDIA_TOOLBOXITEM_LOOP );
122 if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
123 maPlayToolBox.InsertSeparator();
125 maPlayToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
126 maPlayToolBox.SetSizePixel( maPlayToolBox.CalcWindowSizePixel() );
127 maPlayToolBox.Show();
128 maMinSize = maPlayToolBox.GetSizePixel();
130 maTimeSlider.SetSlideHdl( LINK( this, MediaControl, implTimeHdl ) );
131 maTimeSlider.SetEndSlideHdl( LINK( this, MediaControl, implTimeEndHdl ) );
132 maTimeSlider.SetRange( Range( 0, AVMEDIA_TIME_RANGE ) );
133 maTimeSlider.SetHelpId( HID_AVMEDIA_TIMESLIDER );
134 maTimeSlider.SetUpdateMode( true );
135 maTimeSlider.SetSizePixel( Size( 128, maPlayToolBox.GetSizePixel().Height() ) );
136 maTimeSlider.Show();
137 maMinSize.Width() += maTimeSlider.GetSizePixel().Width();
139 maTimeEdit.SetText( aTimeText );
140 maTimeEdit.SetUpdateMode( true );
141 maTimeEdit.SetSizePixel( Size( maTimeEdit.GetTextWidth( aTimeText ) + 8, maPlayToolBox.GetSizePixel().Height() ) );
142 maTimeEdit.SetControlBackground( Application::GetSettings().GetStyleSettings().GetWindowColor() );
143 maTimeEdit.SetHelpId( HID_AVMEDIA_TIMEEDIT );
144 maTimeEdit.Disable();
145 maTimeEdit.Show();
146 maMinSize.Width() += maTimeEdit.GetSizePixel().Width();
148 if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
149 maMuteToolBox.InsertSeparator();
151 maMuteToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_MUTE, implGetImage( AVMEDIA_IMG_MUTE ), OUString( AVMEDIA_RESID( AVMEDIA_STR_MUTE ) ) );
152 maMuteToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_MUTE, HID_AVMEDIA_TOOLBOXITEM_MUTE );
154 maMuteToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
155 maMuteToolBox.SetSizePixel( maMuteToolBox.CalcWindowSizePixel() );
156 maMuteToolBox.Show();
157 maMinSize.Width() += maMuteToolBox.GetSizePixel().Width();
159 maVolumeSlider.SetSlideHdl( LINK( this, MediaControl, implVolumeHdl ) );
160 maVolumeSlider.SetEndSlideHdl( LINK( this, MediaControl, implVolumeEndHdl ) );
161 maVolumeSlider.SetRange( Range( AVMEDIA_DB_RANGE, 0 ) );
162 maVolumeSlider.SetUpdateMode( true );
163 maVolumeSlider.SetHelpId( HID_AVMEDIA_VOLUMESLIDER );
164 maVolumeSlider.SetSizePixel( Size( 48, maPlayToolBox.GetSizePixel().Height() ) );
165 maVolumeSlider.Show();
166 maMinSize.Width() += maVolumeSlider.GetSizePixel().Width();
168 mpZoomListBox->SetSizePixel( Size( maTimeEdit.GetSizePixel().Width(), 260 ) );
169 mpZoomListBox->InsertEntry( OUString( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_50 ) ), AVMEDIA_ZOOMLEVEL_50 );
170 mpZoomListBox->InsertEntry( OUString( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_100 ) ), AVMEDIA_ZOOMLEVEL_100 );
171 mpZoomListBox->InsertEntry( OUString( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_200 ) ), AVMEDIA_ZOOMLEVEL_200 );
172 mpZoomListBox->InsertEntry( OUString( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_FIT ) ), AVMEDIA_ZOOMLEVEL_FIT );
173 mpZoomListBox->SetSelectHdl( LINK( this, MediaControl, implZoomSelectHdl ) );
174 mpZoomListBox->SetHelpId( HID_AVMEDIA_ZOOMLISTBOX );
176 maZoomToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_ZOOM, OUString( AVMEDIA_RESID( AVMEDIA_STR_ZOOM ) ) );
177 maZoomToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_ZOOM, HID_AVMEDIA_ZOOMLISTBOX );
179 maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, mpZoomListBox );
180 maZoomToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
181 maZoomToolBox.SetSizePixel( maZoomToolBox.CalcWindowSizePixel() );
182 maZoomToolBox.Show();
183 maMinSize.Width() += maZoomToolBox.GetSizePixel().Width();
185 if( MEDIACONTROLSTYLE_MULTILINE == meControlStyle )
187 maMinSize.Width() = 256;
188 maMinSize.Height() = ( maMinSize.Height() << 1 ) + AVMEDIA_CONTROLOFFSET;
191 maTimer.SetTimeout( AVMEDIA_TIMEOUT );
192 maTimer.SetTimeoutHdl( LINK( this, MediaControl, implTimeoutHdl ) );
193 maTimer.Start();
196 // ------------------------------------------------------------------------------
198 MediaControl::~MediaControl()
200 maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, NULL );
201 delete mpZoomListBox;
204 // ------------------------------------------------------------------------------
206 const Size& MediaControl::getMinSizePixel() const
208 return maMinSize;
211 // ------------------------------------------------------------------------------
213 void MediaControl::Resize()
215 Point aPos( 0, 0 );
216 const sal_Int32 nPlayToolBoxWidth = maPlayToolBox.GetSizePixel().Width();
217 const sal_Int32 nMuteToolBoxWidth = maMuteToolBox.GetSizePixel().Width();
218 const sal_Int32 nVolumeSliderWidth = maVolumeSlider.GetSizePixel().Width();
219 const sal_Int32 nZoomToolBoxWidth = maZoomToolBox.GetSizePixel().Width();
220 const sal_Int32 nTimeEditWidth = maTimeEdit.GetSizePixel().Width();
221 const sal_Int32 nTimeSliderHeight = maTimeSlider.GetSizePixel().Height();
223 if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
225 const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - ( AVMEDIA_CONTROLOFFSET * 3 ) -
226 nPlayToolBoxWidth - nMuteToolBoxWidth - nVolumeSliderWidth - nTimeEditWidth - nZoomToolBoxWidth;
228 maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() );
230 aPos.X() += nPlayToolBoxWidth;
231 maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) );
233 aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET;
234 maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() );
236 aPos.X() += nTimeEditWidth + AVMEDIA_CONTROLOFFSET;
237 maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() );
239 aPos.X() += nMuteToolBoxWidth;
240 maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() );
242 aPos.X() += nVolumeSliderWidth + AVMEDIA_CONTROLOFFSET;
243 maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() );
245 else
247 const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - AVMEDIA_CONTROLOFFSET - nTimeEditWidth;
249 maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) );
251 aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET;
252 maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() );
254 aPos.X() = 0;
255 aPos.Y() += nTimeSliderHeight + AVMEDIA_CONTROLOFFSET;
256 maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() );
258 aPos.X() = GetSizePixel().Width() - nVolumeSliderWidth - nMuteToolBoxWidth - nZoomToolBoxWidth - AVMEDIA_CONTROLOFFSET;
259 maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() );
261 aPos.X() += nMuteToolBoxWidth;
262 maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() );
264 aPos.X() = GetSizePixel().Width() - nZoomToolBoxWidth;
265 maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() );
269 // ------------------------------------------------------------------------------
271 void MediaControl::setState( const MediaItem& rItem )
273 if( !mbLocked )
275 maItem.merge( rItem );
277 implUpdateToolboxes();
278 implUpdateTimeSlider();
279 implUpdateVolumeSlider();
280 implUpdateTimeField( maItem.getTime() );
284 // ------------------------------------------------------------------------------
286 void MediaControl::implUpdateToolboxes()
288 const bool bValidURL = ( !maItem.getURL().isEmpty());
290 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_INSERT, bValidURL );
291 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAY, bValidURL );
292 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, bValidURL );
293 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PAUSE, bValidURL );
294 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_STOP, bValidURL );
295 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_LOOP, bValidURL );
296 maMuteToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_MUTE, bValidURL );
298 if( !bValidURL || !IsEnabled() )
300 mpZoomListBox->Disable();
302 if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
303 maPlayToolBox.Disable();
305 maMuteToolBox.Disable();
307 else
309 maPlayToolBox.Enable();
310 maMuteToolBox.Enable();
312 if( MEDIASTATE_PLAY == maItem.getState() || MEDIASTATE_PLAYFFW == maItem.getState() )
314 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, true );
315 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, MEDIASTATE_PLAYFFW == maItem.getState() );
316 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false );
317 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false );
319 else if( maItem.getTime() > 0.0 && ( maItem.getTime() < maItem.getDuration() ) )
321 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false );
322 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false );
323 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, true );
324 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false );
326 else
328 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false );
329 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false );
330 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false );
331 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, true );
334 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_LOOP, maItem.isLoop() );
335 maMuteToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_MUTE, maItem.isMute() );
337 if( !mpZoomListBox->IsTravelSelect() && !mpZoomListBox->IsInDropDown() )
339 sal_uInt16 nSelectEntryPos ;
341 switch( maItem.getZoom() )
343 case( ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_50; break;
344 case( ::com::sun::star::media::ZoomLevel_ORIGINAL ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_100; break;
345 case( ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_200; break;
346 case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_FIT; break;
347 case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_SCALED; break;
349 default: nSelectEntryPos = AVMEDIA_ZOOMLEVEL_INVALID; break;
352 if( nSelectEntryPos != AVMEDIA_ZOOMLEVEL_INVALID )
354 mpZoomListBox->Enable();
355 mpZoomListBox->SelectEntryPos( nSelectEntryPos );
357 else
358 mpZoomListBox->Disable();
363 // ------------------------------------------------------------------------------
365 void MediaControl::implUpdateTimeSlider()
367 if( maItem.getURL().isEmpty() || !IsEnabled() )
368 maTimeSlider.Disable();
369 else
371 maTimeSlider.Enable();
373 const double fDuration = maItem.getDuration();
375 if( fDuration > 0.0 )
377 const double fTime = ::std::min( maItem.getTime(), fDuration );
379 if( !maTimeSlider.GetLineSize() )
380 maTimeSlider.SetLineSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_LINEINCREMENT / fDuration ) );
382 if( !maTimeSlider.GetPageSize() )
383 maTimeSlider.SetPageSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_PAGEINCREMENT / fDuration ) );
385 maTimeSlider.SetThumbPos( static_cast< sal_Int32 >( fTime / fDuration * AVMEDIA_TIME_RANGE ) );
390 // ------------------------------------------------------------------------------
392 void MediaControl::implUpdateVolumeSlider()
394 if( maItem.getURL().isEmpty() || !IsEnabled() )
395 maVolumeSlider.Disable();
396 else
398 maVolumeSlider.Enable();
400 const sal_Int32 nVolumeDB = maItem.getVolumeDB();
402 maVolumeSlider.SetThumbPos( ::std::min( ::std::max( nVolumeDB, static_cast< sal_Int32 >( AVMEDIA_DB_RANGE ) ),
403 static_cast< sal_Int32 >( 0 ) ) );
407 // ------------------------------------------------------------------------------
409 void MediaControl::implUpdateTimeField( double fCurTime )
411 if( !maItem.getURL().isEmpty() )
413 OUString aTimeString;
415 SvtSysLocale aSysLocale;
416 const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
418 aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( fCurTime ) ) ) ) +
419 " / " +
420 rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( maItem.getDuration() ) )) );
422 if( maTimeEdit.GetText() != aTimeString )
423 maTimeEdit.SetText( aTimeString );
427 // ------------------------------------------------------------------------------
429 Image MediaControl::implGetImage( sal_Int32 nImageId ) const
431 return maImageList.GetImage( static_cast< sal_uInt16 >( nImageId ) );
434 // ------------------------------------------------------------------------------
436 IMPL_LINK( MediaControl, implTimeHdl, Slider*, p )
438 mbLocked = true;
439 maTimer.Stop();
440 implUpdateTimeField( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE );
442 return 0;
445 // ------------------------------------------------------------------------------
447 IMPL_LINK( MediaControl, implTimeEndHdl, Slider*, p )
449 MediaItem aExecItem;
451 aExecItem.setTime( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE );
452 execute( aExecItem );
453 update();
454 maTimer.Start();
455 mbLocked = false;
457 return 0;
460 // ------------------------------------------------------------------------------
462 IMPL_LINK( MediaControl, implVolumeHdl, Slider*, p )
464 MediaItem aExecItem;
466 aExecItem.setVolumeDB( static_cast< sal_Int16 >( p->GetThumbPos() ) );
467 execute( aExecItem );
468 update();
470 return 0;
473 // ------------------------------------------------------------------------------
475 IMPL_LINK_NOARG(MediaControl, implVolumeEndHdl)
477 return 0;
480 // ------------------------------------------------------------------------------
482 IMPL_LINK( MediaControl, implSelectHdl, ToolBox*, p )
484 if( p )
486 MediaItem aExecItem;
488 switch( p->GetCurItemId() )
490 case( AVMEDIA_TOOLBOXITEM_OPEN ):
492 OUString aURL;
494 if (::avmedia::MediaWindow::executeMediaURLDialog(
495 GetParent(), aURL, 0))
497 if( !::avmedia::MediaWindow::isMediaURL( aURL, true ) )
498 ::avmedia::MediaWindow::executeFormatErrorBox( this );
499 else
501 aExecItem.setURL( aURL, 0 );
502 aExecItem.setState( MEDIASTATE_PLAY );
506 break;
508 case( AVMEDIA_TOOLBOXITEM_INSERT ):
510 MediaFloater* pFloater = AVMEDIA_MEDIAWINDOW();
512 if( pFloater )
513 pFloater->dispatchCurrentURL();
515 break;
517 case( AVMEDIA_TOOLBOXITEM_PLAY ):
518 case( AVMEDIA_TOOLBOXITEM_PLAYFFW ):
520 aExecItem.setState( ( AVMEDIA_TOOLBOXITEM_PLAYFFW == p->GetCurItemId() ) ? MEDIASTATE_PLAYFFW : MEDIASTATE_PLAY );
522 if( maItem.getTime() == maItem.getDuration() )
523 aExecItem.setTime( 0.0 );
524 else
525 aExecItem.setTime( maItem.getTime() );
527 break;
529 case( AVMEDIA_TOOLBOXITEM_PAUSE ):
531 aExecItem.setState( MEDIASTATE_PAUSE );
533 break;
535 case( AVMEDIA_TOOLBOXITEM_STOP ):
537 aExecItem.setState( MEDIASTATE_STOP );
538 aExecItem.setTime( 0.0 );
540 break;
542 case( AVMEDIA_TOOLBOXITEM_MUTE ):
544 aExecItem.setMute( !maMuteToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_MUTE ) );
546 break;
548 case( AVMEDIA_TOOLBOXITEM_LOOP ):
550 aExecItem.setLoop( !maPlayToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_LOOP ) );
552 break;
554 default:
555 break;
558 if( aExecItem.getMaskSet() != AVMEDIA_SETMASK_NONE )
559 execute( aExecItem );
562 update();
563 if(p)
565 p->Invalidate( INVALIDATE_UPDATE );
568 return 0;
571 // ------------------------------------------------------------------------------
573 IMPL_LINK( MediaControl, implZoomSelectHdl, ListBox*, p )
575 if( p )
577 MediaItem aExecItem;
578 ::com::sun::star::media::ZoomLevel eLevel;
580 switch( p->GetSelectEntryPos() )
582 case( AVMEDIA_ZOOMLEVEL_50 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2; break;
583 case( AVMEDIA_ZOOMLEVEL_100 ): eLevel = ::com::sun::star::media::ZoomLevel_ORIGINAL; break;
584 case( AVMEDIA_ZOOMLEVEL_200 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1; break;
585 case( AVMEDIA_ZOOMLEVEL_FIT ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT; break;
586 case( AVMEDIA_ZOOMLEVEL_SCALED ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW; break;
588 default: eLevel = ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE; break;
591 aExecItem.setZoom( eLevel );
592 execute( aExecItem );
593 update();
596 return 0;
599 // ------------------------------------------------------------------------------
601 IMPL_LINK_NOARG(MediaControl, implTimeoutHdl)
603 update();
604 maTimer.Start();
606 return 0;
611 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */