Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / avmedia / source / framework / mediacontrol.cxx
blob68b0cdda5593dfb9b34087b7b445df888bcd3396
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 <vcl/svapp.hxx>
28 #include <vcl/lstbox.hxx>
29 #include <unotools/syslocale.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <math.h>
32 #include <algorithm>
34 #define AVMEDIA_TIMEOUT 100
35 #define AVMEDIA_TIME_RANGE 2048
36 #define AVMEDIA_DB_RANGE -40
37 #define AVMEDIA_LINEINCREMENT 1.0
38 #define AVMEDIA_PAGEINCREMENT 10.0
40 #define AVMEDIA_TOOLBOXITEM_PLAY 0x0001
41 #define AVMEDIA_TOOLBOXITEM_PLAYFFW 0x0002
42 #define AVMEDIA_TOOLBOXITEM_PAUSE 0x0004
43 #define AVMEDIA_TOOLBOXITEM_STOP 0x0008
44 #define AVMEDIA_TOOLBOXITEM_MUTE 0x0010
45 #define AVMEDIA_TOOLBOXITEM_LOOP 0x0011
46 #define AVMEDIA_TOOLBOXITEM_ZOOM 0x0012
47 #define AVMEDIA_TOOLBOXITEM_OPEN 0x0014
48 #define AVMEDIA_TOOLBOXITEM_INSERT 0x0018
50 #define AVMEDIA_ZOOMLEVEL_50 0
51 #define AVMEDIA_ZOOMLEVEL_100 1
52 #define AVMEDIA_ZOOMLEVEL_200 2
53 #define AVMEDIA_ZOOMLEVEL_FIT 3
54 #define AVMEDIA_ZOOMLEVEL_SCALED 4
55 #define AVMEDIA_ZOOMLEVEL_INVALID 65535
57 namespace avmedia
60 // ----------------
61 // - MediaControl -
62 // ---------------
64 MediaControl::MediaControl( Window* pParent, MediaControlStyle eControlStyle ) :
65 Control( pParent ),
66 maImageList( AVMEDIA_RESID( AVMEDIA_IMGLST ) ),
67 maItem( 0, AVMEDIA_SETMASK_ALL ),
68 maPlayToolBox( this, WB_3DLOOK ),
69 maTimeSlider( this, WB_HORZ | WB_DRAG | WB_3DLOOK | WB_SLIDERSET ),
70 maMuteToolBox( this, WB_3DLOOK ),
71 maVolumeSlider( this, WB_HORZ | WB_DRAG | WB_SLIDERSET ),
72 maZoomToolBox( this, WB_3DLOOK ),
73 mpZoomListBox( new ListBox( &maZoomToolBox, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL | WB_3DLOOK ) ),
74 maTimeEdit( this, WB_CENTER | WB_READONLY | WB_BORDER | WB_3DLOOK | WB_READONLY ),
75 meControlStyle( eControlStyle ),
76 mbLocked( false )
78 const String aTimeText( RTL_CONSTASCII_USTRINGPARAM( " 00:00:00/00:00:00 " ) );
80 SetBackground();
81 SetPaintTransparent( sal_True );
82 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
84 if( MEDIACONTROLSTYLE_SINGLELINE != meControlStyle )
86 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_OPEN, implGetImage( AVMEDIA_IMG_OPEN ), String( AVMEDIA_RESID( AVMEDIA_STR_OPEN ) ) );
87 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_OPEN, HID_AVMEDIA_TOOLBOXITEM_OPEN );
89 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_INSERT, implGetImage( AVMEDIA_IMG_INSERT ), String( AVMEDIA_RESID( AVMEDIA_STR_INSERT ) ) );
90 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_INSERT, HID_AVMEDIA_TOOLBOXITEM_INSERT );
92 maPlayToolBox.InsertSeparator();
94 else
96 mpZoomListBox->SetBackground();
98 maZoomToolBox.SetBackground();
99 maZoomToolBox.SetPaintTransparent( sal_True );
100 maPlayToolBox.SetBackground();
101 maPlayToolBox.SetPaintTransparent( sal_True );
102 maMuteToolBox.SetBackground();
103 maMuteToolBox.SetPaintTransparent( sal_True );
107 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PLAY, implGetImage( AVMEDIA_IMG_PLAY ), String( AVMEDIA_RESID( AVMEDIA_STR_PLAY ) ), TIB_CHECKABLE );
108 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PLAY, HID_AVMEDIA_TOOLBOXITEM_PLAY );
110 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PAUSE, implGetImage( AVMEDIA_IMG_PAUSE ), String( AVMEDIA_RESID( AVMEDIA_STR_PAUSE ) ), TIB_CHECKABLE );
111 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PAUSE, HID_AVMEDIA_TOOLBOXITEM_PAUSE );
113 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_STOP, implGetImage( AVMEDIA_IMG_STOP ), String( AVMEDIA_RESID( AVMEDIA_STR_STOP ) ), TIB_CHECKABLE );
114 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_STOP, HID_AVMEDIA_TOOLBOXITEM_STOP );
116 maPlayToolBox.InsertSeparator();
118 maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_LOOP, implGetImage( AVMEDIA_IMG_ENDLESS ), String( AVMEDIA_RESID( AVMEDIA_STR_ENDLESS ) ) );
119 maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_LOOP, HID_AVMEDIA_TOOLBOXITEM_LOOP );
121 if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
122 maPlayToolBox.InsertSeparator();
124 maPlayToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
125 maPlayToolBox.SetSizePixel( maPlayToolBox.CalcWindowSizePixel() );
126 maPlayToolBox.Show();
127 maMinSize = maPlayToolBox.GetSizePixel();
129 maTimeSlider.SetSlideHdl( LINK( this, MediaControl, implTimeHdl ) );
130 maTimeSlider.SetEndSlideHdl( LINK( this, MediaControl, implTimeEndHdl ) );
131 maTimeSlider.SetRange( Range( 0, AVMEDIA_TIME_RANGE ) );
132 maTimeSlider.SetHelpId( HID_AVMEDIA_TIMESLIDER );
133 maTimeSlider.SetUpdateMode( true );
134 maTimeSlider.SetSizePixel( Size( 128, maPlayToolBox.GetSizePixel().Height() ) );
135 maTimeSlider.Show();
136 maMinSize.Width() += maTimeSlider.GetSizePixel().Width();
138 maTimeEdit.SetText( aTimeText );
139 maTimeEdit.SetUpdateMode( true );
140 maTimeEdit.SetSizePixel( Size( maTimeEdit.GetTextWidth( aTimeText ) + 8, maPlayToolBox.GetSizePixel().Height() ) );
141 maTimeEdit.SetControlBackground( Application::GetSettings().GetStyleSettings().GetWindowColor() );
142 maTimeEdit.SetHelpId( HID_AVMEDIA_TIMEEDIT );
143 maTimeEdit.Disable();
144 maTimeEdit.Show();
145 maMinSize.Width() += maTimeEdit.GetSizePixel().Width();
147 if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
148 maMuteToolBox.InsertSeparator();
150 maMuteToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_MUTE, implGetImage( AVMEDIA_IMG_MUTE ), String( AVMEDIA_RESID( AVMEDIA_STR_MUTE ) ) );
151 maMuteToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_MUTE, HID_AVMEDIA_TOOLBOXITEM_MUTE );
153 maMuteToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
154 maMuteToolBox.SetSizePixel( maMuteToolBox.CalcWindowSizePixel() );
155 maMuteToolBox.Show();
156 maMinSize.Width() += maMuteToolBox.GetSizePixel().Width();
158 maVolumeSlider.SetSlideHdl( LINK( this, MediaControl, implVolumeHdl ) );
159 maVolumeSlider.SetEndSlideHdl( LINK( this, MediaControl, implVolumeEndHdl ) );
160 maVolumeSlider.SetRange( Range( AVMEDIA_DB_RANGE, 0 ) );
161 maVolumeSlider.SetUpdateMode( true );
162 maVolumeSlider.SetHelpId( HID_AVMEDIA_VOLUMESLIDER );
163 maVolumeSlider.SetSizePixel( Size( 48, maPlayToolBox.GetSizePixel().Height() ) );
164 maVolumeSlider.Show();
165 maMinSize.Width() += maVolumeSlider.GetSizePixel().Width();
167 mpZoomListBox->SetSizePixel( Size( maTimeEdit.GetSizePixel().Width(), 260 ) );
168 mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_50 ) ), AVMEDIA_ZOOMLEVEL_50 );
169 mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_100 ) ), AVMEDIA_ZOOMLEVEL_100 );
170 mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_200 ) ), AVMEDIA_ZOOMLEVEL_200 );
171 mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_FIT ) ), AVMEDIA_ZOOMLEVEL_FIT );
172 mpZoomListBox->SetSelectHdl( LINK( this, MediaControl, implZoomSelectHdl ) );
173 mpZoomListBox->SetHelpId( HID_AVMEDIA_ZOOMLISTBOX );
175 maZoomToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_ZOOM, String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM ) ) );
176 maZoomToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_ZOOM, HID_AVMEDIA_ZOOMLISTBOX );
178 maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, mpZoomListBox );
179 maZoomToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) );
180 maZoomToolBox.SetSizePixel( maZoomToolBox.CalcWindowSizePixel() );
181 maZoomToolBox.Show();
182 maMinSize.Width() += maZoomToolBox.GetSizePixel().Width();
184 if( MEDIACONTROLSTYLE_MULTILINE == meControlStyle )
186 maMinSize.Width() = 256;
187 maMinSize.Height() = ( maMinSize.Height() << 1 ) + AVMEDIA_CONTROLOFFSET;
190 maTimer.SetTimeout( AVMEDIA_TIMEOUT );
191 maTimer.SetTimeoutHdl( LINK( this, MediaControl, implTimeoutHdl ) );
192 maTimer.Start();
195 // ------------------------------------------------------------------------------
197 MediaControl::~MediaControl()
199 maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, NULL );
200 delete mpZoomListBox;
203 // ------------------------------------------------------------------------------
205 const Size& MediaControl::getMinSizePixel() const
207 return maMinSize;
210 // ------------------------------------------------------------------------------
212 void MediaControl::Resize()
214 Point aPos( 0, 0 );
215 const sal_Int32 nPlayToolBoxWidth = maPlayToolBox.GetSizePixel().Width();
216 const sal_Int32 nMuteToolBoxWidth = maMuteToolBox.GetSizePixel().Width();
217 const sal_Int32 nVolumeSliderWidth = maVolumeSlider.GetSizePixel().Width();
218 const sal_Int32 nZoomToolBoxWidth = maZoomToolBox.GetSizePixel().Width();
219 const sal_Int32 nTimeEditWidth = maTimeEdit.GetSizePixel().Width();
220 const sal_Int32 nTimeSliderHeight = maTimeSlider.GetSizePixel().Height();
222 if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
224 const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - ( AVMEDIA_CONTROLOFFSET * 3 ) -
225 nPlayToolBoxWidth - nMuteToolBoxWidth - nVolumeSliderWidth - nTimeEditWidth - nZoomToolBoxWidth;
227 maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() );
229 aPos.X() += nPlayToolBoxWidth;
230 maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) );
232 aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET;
233 maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() );
235 aPos.X() += nTimeEditWidth + AVMEDIA_CONTROLOFFSET;
236 maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() );
238 aPos.X() += nMuteToolBoxWidth;
239 maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() );
241 aPos.X() += nVolumeSliderWidth + AVMEDIA_CONTROLOFFSET;
242 maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() );
244 else
246 const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - AVMEDIA_CONTROLOFFSET - nTimeEditWidth;
248 maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) );
250 aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET;
251 maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() );
253 aPos.X() = 0;
254 aPos.Y() += nTimeSliderHeight + AVMEDIA_CONTROLOFFSET;
255 maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() );
257 aPos.X() = GetSizePixel().Width() - nVolumeSliderWidth - nMuteToolBoxWidth - nZoomToolBoxWidth - AVMEDIA_CONTROLOFFSET;
258 maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() );
260 aPos.X() += nMuteToolBoxWidth;
261 maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() );
263 aPos.X() = GetSizePixel().Width() - nZoomToolBoxWidth;
264 maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() );
268 // ------------------------------------------------------------------------------
270 void MediaControl::setState( const MediaItem& rItem )
272 if( !mbLocked )
274 maItem.merge( rItem );
276 implUpdateToolboxes();
277 implUpdateTimeSlider();
278 implUpdateVolumeSlider();
279 implUpdateTimeField( maItem.getTime() );
283 // ------------------------------------------------------------------------------
285 void MediaControl::implUpdateToolboxes()
287 const bool bValidURL = ( !maItem.getURL().isEmpty());
289 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_INSERT, bValidURL );
290 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAY, bValidURL );
291 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, bValidURL );
292 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PAUSE, bValidURL );
293 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_STOP, bValidURL );
294 maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_LOOP, bValidURL );
295 maMuteToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_MUTE, bValidURL );
297 if( !bValidURL || !IsEnabled() )
299 mpZoomListBox->Disable();
301 if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle )
302 maPlayToolBox.Disable();
304 maMuteToolBox.Disable();
306 else
308 maPlayToolBox.Enable();
309 maMuteToolBox.Enable();
311 if( MEDIASTATE_PLAY == maItem.getState() || MEDIASTATE_PLAYFFW == maItem.getState() )
313 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, true );
314 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, MEDIASTATE_PLAYFFW == maItem.getState() );
315 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false );
316 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false );
318 else if( maItem.getTime() > 0.0 && ( maItem.getTime() < maItem.getDuration() ) )
320 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false );
321 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false );
322 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, true );
323 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false );
325 else
327 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false );
328 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false );
329 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false );
330 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, true );
333 maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_LOOP, maItem.isLoop() );
334 maMuteToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_MUTE, maItem.isMute() );
336 if( !mpZoomListBox->IsTravelSelect() && !mpZoomListBox->IsInDropDown() )
338 sal_uInt16 nSelectEntryPos ;
340 switch( maItem.getZoom() )
342 case( ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_50; break;
343 case( ::com::sun::star::media::ZoomLevel_ORIGINAL ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_100; break;
344 case( ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_200; break;
345 case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_FIT; break;
346 case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_SCALED; break;
348 default: nSelectEntryPos = AVMEDIA_ZOOMLEVEL_INVALID; break;
351 if( nSelectEntryPos != AVMEDIA_ZOOMLEVEL_INVALID )
353 mpZoomListBox->Enable();
354 mpZoomListBox->SelectEntryPos( nSelectEntryPos );
356 else
357 mpZoomListBox->Disable();
362 // ------------------------------------------------------------------------------
364 void MediaControl::implUpdateTimeSlider()
366 if( maItem.getURL().isEmpty() || !IsEnabled() )
367 maTimeSlider.Disable();
368 else
370 maTimeSlider.Enable();
372 const double fDuration = maItem.getDuration();
374 if( fDuration > 0.0 )
376 const double fTime = ::std::min( maItem.getTime(), fDuration );
378 if( !maTimeSlider.GetLineSize() )
379 maTimeSlider.SetLineSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_LINEINCREMENT / fDuration ) );
381 if( !maTimeSlider.GetPageSize() )
382 maTimeSlider.SetPageSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_PAGEINCREMENT / fDuration ) );
384 maTimeSlider.SetThumbPos( static_cast< sal_Int32 >( fTime / fDuration * AVMEDIA_TIME_RANGE ) );
389 // ------------------------------------------------------------------------------
391 void MediaControl::implUpdateVolumeSlider()
393 if( maItem.getURL().isEmpty() || !IsEnabled() )
394 maVolumeSlider.Disable();
395 else
397 maVolumeSlider.Enable();
399 const sal_Int32 nVolumeDB = maItem.getVolumeDB();
401 maVolumeSlider.SetThumbPos( ::std::min( ::std::max( nVolumeDB, static_cast< sal_Int32 >( AVMEDIA_DB_RANGE ) ),
402 static_cast< sal_Int32 >( 0 ) ) );
406 // ------------------------------------------------------------------------------
408 void MediaControl::implUpdateTimeField( double fCurTime )
410 if( !maItem.getURL().isEmpty() )
412 String aTimeString;
414 SvtSysLocale aSysLocale;
415 const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
417 aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( fCurTime ) ) ) );
418 aTimeString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " / " ));
419 aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( maItem.getDuration() ) )) );
421 if( maTimeEdit.GetText() != aTimeString )
422 maTimeEdit.SetText( aTimeString );
426 // ------------------------------------------------------------------------------
428 Image MediaControl::implGetImage( sal_Int32 nImageId ) const
430 return maImageList.GetImage( static_cast< sal_uInt16 >( nImageId ) );
433 // ------------------------------------------------------------------------------
435 IMPL_LINK( MediaControl, implTimeHdl, Slider*, p )
437 mbLocked = true;
438 maTimer.Stop();
439 implUpdateTimeField( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE );
441 return 0;
444 // ------------------------------------------------------------------------------
446 IMPL_LINK( MediaControl, implTimeEndHdl, Slider*, p )
448 MediaItem aExecItem;
450 aExecItem.setTime( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE );
451 execute( aExecItem );
452 update();
453 maTimer.Start();
454 mbLocked = false;
456 return 0;
459 // ------------------------------------------------------------------------------
461 IMPL_LINK( MediaControl, implVolumeHdl, Slider*, p )
463 MediaItem aExecItem;
465 aExecItem.setVolumeDB( static_cast< sal_Int16 >( p->GetThumbPos() ) );
466 execute( aExecItem );
467 update();
469 return 0;
472 // ------------------------------------------------------------------------------
474 IMPL_LINK_NOARG(MediaControl, implVolumeEndHdl)
476 return 0;
479 // ------------------------------------------------------------------------------
481 IMPL_LINK( MediaControl, implSelectHdl, ToolBox*, p )
483 if( p )
485 MediaItem aExecItem;
487 switch( p->GetCurItemId() )
489 case( AVMEDIA_TOOLBOXITEM_OPEN ):
491 OUString aURL;
493 if (::avmedia::MediaWindow::executeMediaURLDialog(
494 GetParent(), aURL, 0))
496 if( !::avmedia::MediaWindow::isMediaURL( aURL, true ) )
497 ::avmedia::MediaWindow::executeFormatErrorBox( this );
498 else
500 aExecItem.setURL( aURL, 0 );
501 aExecItem.setState( MEDIASTATE_PLAY );
505 break;
507 case( AVMEDIA_TOOLBOXITEM_INSERT ):
509 MediaFloater* pFloater = AVMEDIA_MEDIAWINDOW();
511 if( pFloater )
512 pFloater->dispatchCurrentURL();
514 break;
516 case( AVMEDIA_TOOLBOXITEM_PLAY ):
517 case( AVMEDIA_TOOLBOXITEM_PLAYFFW ):
519 aExecItem.setState( ( AVMEDIA_TOOLBOXITEM_PLAYFFW == p->GetCurItemId() ) ? MEDIASTATE_PLAYFFW : MEDIASTATE_PLAY );
521 if( maItem.getTime() == maItem.getDuration() )
522 aExecItem.setTime( 0.0 );
523 else
524 aExecItem.setTime( maItem.getTime() );
526 break;
528 case( AVMEDIA_TOOLBOXITEM_PAUSE ):
530 aExecItem.setState( MEDIASTATE_PAUSE );
532 break;
534 case( AVMEDIA_TOOLBOXITEM_STOP ):
536 aExecItem.setState( MEDIASTATE_STOP );
537 aExecItem.setTime( 0.0 );
539 break;
541 case( AVMEDIA_TOOLBOXITEM_MUTE ):
543 aExecItem.setMute( !maMuteToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_MUTE ) );
545 break;
547 case( AVMEDIA_TOOLBOXITEM_LOOP ):
549 aExecItem.setLoop( !maPlayToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_LOOP ) );
551 break;
553 default:
554 break;
557 if( aExecItem.getMaskSet() != AVMEDIA_SETMASK_NONE )
558 execute( aExecItem );
561 update();
562 p->Invalidate( INVALIDATE_UPDATE );
564 return 0;
567 // ------------------------------------------------------------------------------
569 IMPL_LINK( MediaControl, implZoomSelectHdl, ListBox*, p )
571 if( p )
573 MediaItem aExecItem;
574 ::com::sun::star::media::ZoomLevel eLevel;
576 switch( p->GetSelectEntryPos() )
578 case( AVMEDIA_ZOOMLEVEL_50 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2; break;
579 case( AVMEDIA_ZOOMLEVEL_100 ): eLevel = ::com::sun::star::media::ZoomLevel_ORIGINAL; break;
580 case( AVMEDIA_ZOOMLEVEL_200 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1; break;
581 case( AVMEDIA_ZOOMLEVEL_FIT ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT; break;
582 case( AVMEDIA_ZOOMLEVEL_SCALED ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW; break;
584 default: eLevel = ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE; break;
587 aExecItem.setZoom( eLevel );
588 execute( aExecItem );
589 update();
592 return 0;
595 // ------------------------------------------------------------------------------
597 IMPL_LINK_NOARG(MediaControl, implTimeoutHdl)
599 update();
600 maTimer.Start();
602 return 0;
607 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */