diff options
Diffstat (limited to 'avmedia/source/framework')
-rw-r--r-- | avmedia/source/framework/makefile.mk | 58 | ||||
-rw-r--r-- | avmedia/source/framework/mediacontrol.cxx | 631 | ||||
-rw-r--r-- | avmedia/source/framework/mediacontrol.hrc | 53 | ||||
-rw-r--r-- | avmedia/source/framework/mediacontrol.src | 193 | ||||
-rw-r--r-- | avmedia/source/framework/mediaitem.cxx | 329 | ||||
-rw-r--r-- | avmedia/source/framework/mediamisc.cxx | 48 | ||||
-rw-r--r-- | avmedia/source/framework/mediaplayer.cxx | 166 | ||||
-rw-r--r-- | avmedia/source/framework/mediatoolbox.cxx | 168 | ||||
-rw-r--r-- | avmedia/source/framework/soundhandler.cxx | 525 | ||||
-rw-r--r-- | avmedia/source/framework/soundhandler.hxx | 187 | ||||
-rw-r--r-- | avmedia/source/framework/soundhandler.xml | 49 |
11 files changed, 2407 insertions, 0 deletions
diff --git a/avmedia/source/framework/makefile.mk b/avmedia/source/framework/makefile.mk new file mode 100644 index 000000000000..4185f3cbfc49 --- /dev/null +++ b/avmedia/source/framework/makefile.mk @@ -0,0 +1,58 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=avmedia +TARGET=framework + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Resources --------------------------------- + +SRS1NAME=$(TARGET) +SRC1FILES =\ + mediacontrol.src + +# --- Files ------------------------------------- + +SLOFILES= \ + $(SLO)$/mediaitem.obj \ + $(SLO)$/mediamisc.obj \ + $(SLO)$/mediacontrol.obj \ + $(SLO)$/mediatoolbox.obj \ + $(SLO)$/mediaplayer.obj \ + $(SLO)$/soundhandler.obj + +EXCEPTIONSFILES = \ + $(SLO)$/mediatoolbox.obj \ + $(SLO)$/soundhandler.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk diff --git a/avmedia/source/framework/mediacontrol.cxx b/avmedia/source/framework/mediacontrol.cxx new file mode 100644 index 000000000000..701b7c6cf238 --- /dev/null +++ b/avmedia/source/framework/mediacontrol.cxx @@ -0,0 +1,631 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "mediacontrol.hxx" +#include "mediacontrol.hrc" +#include "mediamisc.hxx" +#include <avmedia/mediawindow.hxx> +#include <avmedia/mediaplayer.hxx> +#include "helpids.hrc" +#include <tools/time.hxx> +#include <vcl/svapp.hxx> +#include <vcl/lstbox.hxx> +#include <unotools/syslocale.hxx> +#include <sfx2/viewfrm.hxx> +#include <math.h> +#include <algorithm> + +#define AVMEDIA_TIMEOUT 100 +#define AVMEDIA_TIME_RANGE 2048 +#define AVMEDIA_DB_RANGE -40 +#define AVMEDIA_LINEINCREMENT 1.0 +#define AVMEDIA_PAGEINCREMENT 10.0 + +#define AVMEDIA_TOOLBOXITEM_PLAY 0x0001 +#define AVMEDIA_TOOLBOXITEM_PLAYFFW 0x0002 +#define AVMEDIA_TOOLBOXITEM_PAUSE 0x0004 +#define AVMEDIA_TOOLBOXITEM_STOP 0x0008 +#define AVMEDIA_TOOLBOXITEM_MUTE 0x0010 +#define AVMEDIA_TOOLBOXITEM_LOOP 0x0011 +#define AVMEDIA_TOOLBOXITEM_ZOOM 0x0012 +#define AVMEDIA_TOOLBOXITEM_OPEN 0x0014 +#define AVMEDIA_TOOLBOXITEM_INSERT 0x0018 + +#define AVMEDIA_ZOOMLEVEL_50 0 +#define AVMEDIA_ZOOMLEVEL_100 1 +#define AVMEDIA_ZOOMLEVEL_200 2 +#define AVMEDIA_ZOOMLEVEL_FIT 3 +#define AVMEDIA_ZOOMLEVEL_SCALED 4 +#define AVMEDIA_ZOOMLEVEL_INVALID 65535 + +namespace avmedia +{ + +// ---------------- +// - MediaControl - +// --------------- + +MediaControl::MediaControl( Window* pParent, MediaControlStyle eControlStyle ) : + Control( pParent ), + maImageList( AVMEDIA_RESID( AVMEDIA_IMGLST ) ), + maItem( 0, AVMEDIA_SETMASK_ALL ), + maPlayToolBox( this, WB_3DLOOK ), + maTimeSlider( this, WB_HORZ | WB_DRAG | WB_3DLOOK | WB_SLIDERSET ), + maMuteToolBox( this, WB_3DLOOK ), + maVolumeSlider( this, WB_HORZ | WB_DRAG | WB_SLIDERSET ), + maZoomToolBox( this, WB_3DLOOK ), + mpZoomListBox( new ListBox( &maZoomToolBox, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL | WB_3DLOOK ) ), + maTimeEdit( this, WB_CENTER | WB_READONLY | WB_BORDER | WB_3DLOOK | WB_READONLY ), + meControlStyle( eControlStyle ), + mbLocked( false ) +{ + const String aTimeText( RTL_CONSTASCII_USTRINGPARAM( " 00:00:00/00:00:00 " ) ); + + SetBackground(); + SetPaintTransparent( sal_True ); + SetParentClipMode( PARENTCLIPMODE_NOCLIP ); + + if( MEDIACONTROLSTYLE_SINGLELINE != meControlStyle ) + { + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_OPEN, implGetImage( AVMEDIA_IMG_OPEN ), String( AVMEDIA_RESID( AVMEDIA_STR_OPEN ) ) ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_OPEN, HID_AVMEDIA_TOOLBOXITEM_OPEN ); + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_INSERT, implGetImage( AVMEDIA_IMG_INSERT ), String( AVMEDIA_RESID( AVMEDIA_STR_INSERT ) ) ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_INSERT, HID_AVMEDIA_TOOLBOXITEM_INSERT ); + + maPlayToolBox.InsertSeparator(); + } + else + { + mpZoomListBox->SetBackground(); + + maZoomToolBox.SetBackground(); + maZoomToolBox.SetPaintTransparent( sal_True ); + maPlayToolBox.SetBackground(); + maPlayToolBox.SetPaintTransparent( sal_True ); + maMuteToolBox.SetBackground(); + maMuteToolBox.SetPaintTransparent( sal_True ); + + } + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PLAY, implGetImage( AVMEDIA_IMG_PLAY ), String( AVMEDIA_RESID( AVMEDIA_STR_PLAY ) ), TIB_CHECKABLE ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PLAY, HID_AVMEDIA_TOOLBOXITEM_PLAY ); + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_PAUSE, implGetImage( AVMEDIA_IMG_PAUSE ), String( AVMEDIA_RESID( AVMEDIA_STR_PAUSE ) ), TIB_CHECKABLE ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_PAUSE, HID_AVMEDIA_TOOLBOXITEM_PAUSE ); + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_STOP, implGetImage( AVMEDIA_IMG_STOP ), String( AVMEDIA_RESID( AVMEDIA_STR_STOP ) ), TIB_CHECKABLE ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_STOP, HID_AVMEDIA_TOOLBOXITEM_STOP ); + + maPlayToolBox.InsertSeparator(); + + maPlayToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_LOOP, implGetImage( AVMEDIA_IMG_ENDLESS ), String( AVMEDIA_RESID( AVMEDIA_STR_ENDLESS ) ) ); + maPlayToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_LOOP, HID_AVMEDIA_TOOLBOXITEM_LOOP ); + + if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle ) + maPlayToolBox.InsertSeparator(); + + maPlayToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) ); + maPlayToolBox.SetSizePixel( maPlayToolBox.CalcWindowSizePixel() ); + maPlayToolBox.Show(); + maMinSize = maPlayToolBox.GetSizePixel(); + + maTimeSlider.SetSlideHdl( LINK( this, MediaControl, implTimeHdl ) ); + maTimeSlider.SetEndSlideHdl( LINK( this, MediaControl, implTimeEndHdl ) ); + maTimeSlider.SetRange( Range( 0, AVMEDIA_TIME_RANGE ) ); + maTimeSlider.SetHelpId( HID_AVMEDIA_TIMESLIDER ); + maTimeSlider.SetUpdateMode( true ); + maTimeSlider.SetSizePixel( Size( 128, maPlayToolBox.GetSizePixel().Height() ) ); + maTimeSlider.Show(); + maMinSize.Width() += maTimeSlider.GetSizePixel().Width(); + + maTimeEdit.SetText( aTimeText ); + maTimeEdit.SetUpdateMode( true ); + maTimeEdit.SetSizePixel( Size( maTimeEdit.GetTextWidth( aTimeText ) + 8, maPlayToolBox.GetSizePixel().Height() ) ); + maTimeEdit.SetControlBackground( Application::GetSettings().GetStyleSettings().GetWindowColor() ); + maTimeEdit.SetHelpId( HID_AVMEDIA_TIMEEDIT ); + maTimeEdit.Disable(); + maTimeEdit.Show(); + maMinSize.Width() += maTimeEdit.GetSizePixel().Width(); + + if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle ) + maMuteToolBox.InsertSeparator(); + + maMuteToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_MUTE, implGetImage( AVMEDIA_IMG_MUTE ), String( AVMEDIA_RESID( AVMEDIA_STR_MUTE ) ) ); + maMuteToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_MUTE, HID_AVMEDIA_TOOLBOXITEM_MUTE ); + + maMuteToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) ); + maMuteToolBox.SetSizePixel( maMuteToolBox.CalcWindowSizePixel() ); + maMuteToolBox.Show(); + maMinSize.Width() += maMuteToolBox.GetSizePixel().Width(); + + maVolumeSlider.SetSlideHdl( LINK( this, MediaControl, implVolumeHdl ) ); + maVolumeSlider.SetEndSlideHdl( LINK( this, MediaControl, implVolumeEndHdl ) ); + maVolumeSlider.SetRange( Range( AVMEDIA_DB_RANGE, 0 ) ); + maVolumeSlider.SetUpdateMode( true ); + maVolumeSlider.SetHelpId( HID_AVMEDIA_VOLUMESLIDER ); + maVolumeSlider.SetSizePixel( Size( 48, maPlayToolBox.GetSizePixel().Height() ) ); + maVolumeSlider.Show(); + maMinSize.Width() += maVolumeSlider.GetSizePixel().Width(); + + mpZoomListBox->SetSizePixel( Size( maTimeEdit.GetSizePixel().Width(), 260 ) ); + mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_50 ) ), AVMEDIA_ZOOMLEVEL_50 ); + mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_100 ) ), AVMEDIA_ZOOMLEVEL_100 ); + mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_200 ) ), AVMEDIA_ZOOMLEVEL_200 ); + mpZoomListBox->InsertEntry( String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM_FIT ) ), AVMEDIA_ZOOMLEVEL_FIT ); + mpZoomListBox->SetSelectHdl( LINK( this, MediaControl, implZoomSelectHdl ) ); + mpZoomListBox->SetHelpId( HID_AVMEDIA_ZOOMLISTBOX ); + + maZoomToolBox.InsertItem( AVMEDIA_TOOLBOXITEM_ZOOM, String( AVMEDIA_RESID( AVMEDIA_STR_ZOOM ) ) ); + maZoomToolBox.SetHelpId( AVMEDIA_TOOLBOXITEM_ZOOM, HID_AVMEDIA_ZOOMLISTBOX ); + + maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, mpZoomListBox ); + maZoomToolBox.SetSelectHdl( LINK( this, MediaControl, implSelectHdl ) ); + maZoomToolBox.SetSizePixel( maZoomToolBox.CalcWindowSizePixel() ); + maZoomToolBox.Show(); + maMinSize.Width() += maZoomToolBox.GetSizePixel().Width(); + + if( MEDIACONTROLSTYLE_MULTILINE == meControlStyle ) + { + maMinSize.Width() = 256; + maMinSize.Height() = ( maMinSize.Height() << 1 ) + AVMEDIA_CONTROLOFFSET; + } + + maTimer.SetTimeout( AVMEDIA_TIMEOUT ); + maTimer.SetTimeoutHdl( LINK( this, MediaControl, implTimeoutHdl ) ); + maTimer.Start(); +} + +// ------------------------------------------------------------------------------ + +MediaControl::~MediaControl() +{ + maZoomToolBox.SetItemWindow( AVMEDIA_TOOLBOXITEM_ZOOM, NULL ); + delete mpZoomListBox; +} + +// ------------------------------------------------------------------------------ + +const Size& MediaControl::getMinSizePixel() const +{ + return maMinSize; +} + +// ------------------------------------------------------------------------------ + +void MediaControl::Resize() +{ + Point aPos( 0, 0 ); + const sal_Int32 nPlayToolBoxWidth = maPlayToolBox.GetSizePixel().Width(); + const sal_Int32 nMuteToolBoxWidth = maMuteToolBox.GetSizePixel().Width(); + const sal_Int32 nVolumeSliderWidth = maVolumeSlider.GetSizePixel().Width(); + const sal_Int32 nZoomToolBoxWidth = maZoomToolBox.GetSizePixel().Width(); + const sal_Int32 nTimeEditWidth = maTimeEdit.GetSizePixel().Width(); + const sal_Int32 nTimeSliderHeight = maTimeSlider.GetSizePixel().Height(); + + if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle ) + { + const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - ( AVMEDIA_CONTROLOFFSET * 3 ) - + nPlayToolBoxWidth - nMuteToolBoxWidth - nVolumeSliderWidth - nTimeEditWidth - nZoomToolBoxWidth; + + maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() ); + + aPos.X() += nPlayToolBoxWidth; + maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) ); + + aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET; + maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() ); + + aPos.X() += nTimeEditWidth + AVMEDIA_CONTROLOFFSET; + maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() ); + + aPos.X() += nMuteToolBoxWidth; + maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() ); + + aPos.X() += nVolumeSliderWidth + AVMEDIA_CONTROLOFFSET; + maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() ); + } + else + { + const sal_Int32 nTimeSliderWidth = GetSizePixel().Width() - AVMEDIA_CONTROLOFFSET - nTimeEditWidth; + + maTimeSlider.SetPosSizePixel( aPos, Size( nTimeSliderWidth, nTimeSliderHeight ) ); + + aPos.X() += nTimeSliderWidth + AVMEDIA_CONTROLOFFSET; + maTimeEdit.SetPosSizePixel( aPos, maTimeEdit.GetSizePixel() ); + + aPos.X() = 0; + aPos.Y() += nTimeSliderHeight + AVMEDIA_CONTROLOFFSET; + maPlayToolBox.SetPosSizePixel( aPos, maPlayToolBox.GetSizePixel() ); + + aPos.X() = GetSizePixel().Width() - nVolumeSliderWidth - nMuteToolBoxWidth - nZoomToolBoxWidth - AVMEDIA_CONTROLOFFSET; + maMuteToolBox.SetPosSizePixel( aPos, maMuteToolBox.GetSizePixel() ); + + aPos.X() += nMuteToolBoxWidth; + maVolumeSlider.SetPosSizePixel( aPos, maVolumeSlider.GetSizePixel() ); + + aPos.X() = GetSizePixel().Width() - nZoomToolBoxWidth; + maZoomToolBox.SetPosSizePixel( aPos, maZoomToolBox.GetSizePixel() ); + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::setState( const MediaItem& rItem ) +{ + if( !mbLocked ) + { + maItem.merge( rItem ); + + implUpdateToolboxes(); + implUpdateTimeSlider(); + implUpdateVolumeSlider(); + implUpdateTimeField( maItem.getTime() ); + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::getState( MediaItem& rItem ) const +{ + rItem.merge( maItem ); +} + +// ------------------------------------------------------------------------------ + +void MediaControl::update() +{ +} + +// ------------------------------------------------------------------------------ + +void MediaControl::execute( const MediaItem& ) +{ +} + +// ------------------------------------------------------------------------------ + +void MediaControl::implUpdateToolboxes() +{ + const bool bValidURL = ( maItem.getURL().getLength() > 0 ); + + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_INSERT, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAY, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_PAUSE, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_STOP, bValidURL ); + maPlayToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_LOOP, bValidURL ); + maMuteToolBox.EnableItem( AVMEDIA_TOOLBOXITEM_MUTE, bValidURL ); + + if( !bValidURL || !IsEnabled() ) + { + mpZoomListBox->Disable(); + + if( MEDIACONTROLSTYLE_SINGLELINE == meControlStyle ) + maPlayToolBox.Disable(); + + maMuteToolBox.Disable(); + } + else + { + maPlayToolBox.Enable(); + maMuteToolBox.Enable(); + + if( MEDIASTATE_PLAY == maItem.getState() || MEDIASTATE_PLAYFFW == maItem.getState() ) + { + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, true ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, MEDIASTATE_PLAYFFW == maItem.getState() ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false ); + } + else if( maItem.getTime() > 0.0 && ( maItem.getTime() < maItem.getDuration() ) ) + { + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, true ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, false ); + } + else + { + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAY, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PLAYFFW, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_PAUSE, false ); + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_STOP, true ); + } + + maPlayToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_LOOP, maItem.isLoop() ); + maMuteToolBox.CheckItem( AVMEDIA_TOOLBOXITEM_MUTE, maItem.isMute() ); + + if( !mpZoomListBox->IsTravelSelect() && !mpZoomListBox->IsInDropDown() ) + { + sal_uInt16 nSelectEntryPos ; + + switch( maItem.getZoom() ) + { + case( ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_50; break; + case( ::com::sun::star::media::ZoomLevel_ORIGINAL ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_100; break; + case( ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1 ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_200; break; + case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_FIT; break; + case( ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW ): nSelectEntryPos = AVMEDIA_ZOOMLEVEL_SCALED; break; + + default: nSelectEntryPos = AVMEDIA_ZOOMLEVEL_INVALID; break; + } + + if( nSelectEntryPos != AVMEDIA_ZOOMLEVEL_INVALID ) + { + mpZoomListBox->Enable(); + mpZoomListBox->SelectEntryPos( nSelectEntryPos ); + } + else + mpZoomListBox->Disable(); + } + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::implUpdateTimeSlider() +{ + if( !maItem.getURL().getLength() || !IsEnabled() ) + maTimeSlider.Disable(); + else + { + maTimeSlider.Enable(); + + const double fDuration = maItem.getDuration(); + + if( fDuration > 0.0 ) + { + const double fTime = ::std::min( maItem.getTime(), fDuration ); + + if( !maTimeSlider.GetLineSize() ) + maTimeSlider.SetLineSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_LINEINCREMENT / fDuration ) ); + + if( !maTimeSlider.GetPageSize() ) + maTimeSlider.SetPageSize( static_cast< sal_uInt32 >( AVMEDIA_TIME_RANGE * AVMEDIA_PAGEINCREMENT / fDuration ) ); + + maTimeSlider.SetThumbPos( static_cast< sal_Int32 >( fTime / fDuration * AVMEDIA_TIME_RANGE ) ); + } + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::implUpdateVolumeSlider() +{ + if( !maItem.getURL().getLength() || !IsEnabled() ) + maVolumeSlider.Disable(); + else + { + maVolumeSlider.Enable(); + + const sal_Int32 nVolumeDB = maItem.getVolumeDB(); + + maVolumeSlider.SetThumbPos( ::std::min( ::std::max( nVolumeDB, static_cast< sal_Int32 >( AVMEDIA_DB_RANGE ) ), + static_cast< sal_Int32 >( 0 ) ) ); + } +} + +// ------------------------------------------------------------------------------ + +void MediaControl::implUpdateTimeField( double fCurTime ) +{ + if( maItem.getURL().getLength() > 0 ) + { + String aTimeString; + + SvtSysLocale aSysLocale; + const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData(); + + aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( fCurTime ) ) ) ); + aTimeString.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " / " )); + aTimeString += rLocaleData.getDuration( Time( 0, 0, static_cast< sal_uInt32 >( floor( maItem.getDuration() ) )) ); + + if( maTimeEdit.GetText() != aTimeString ) + maTimeEdit.SetText( aTimeString ); + } +} + +// ------------------------------------------------------------------------------ + +Image MediaControl::implGetImage( sal_Int32 nImageId ) const +{ + return maImageList.GetImage( static_cast< sal_uInt16 >( nImageId ) ); +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implTimeHdl, Slider*, p ) +{ + mbLocked = true; + maTimer.Stop(); + implUpdateTimeField( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE ); + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implTimeEndHdl, Slider*, p ) +{ + MediaItem aExecItem; + + aExecItem.setTime( p->GetThumbPos() * maItem.getDuration() / AVMEDIA_TIME_RANGE ); + execute( aExecItem ); + update(); + maTimer.Start(); + mbLocked = false; + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implVolumeHdl, Slider*, p ) +{ + MediaItem aExecItem; + + aExecItem.setVolumeDB( static_cast< sal_Int16 >( p->GetThumbPos() ) ); + execute( aExecItem ); + update(); + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implVolumeEndHdl, Slider*, EMPTYARG ) +{ + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implSelectHdl, ToolBox*, p ) +{ + if( p ) + { + MediaItem aExecItem; + + switch( p->GetCurItemId() ) + { + case( AVMEDIA_TOOLBOXITEM_OPEN ): + { + ::rtl::OUString aURL; + + if( ::avmedia::MediaWindow::executeMediaURLDialog( GetParent(), aURL, false ) ) + { + if( !::avmedia::MediaWindow::isMediaURL( aURL, true ) ) + ::avmedia::MediaWindow::executeFormatErrorBox( this ); + else + { + aExecItem.setURL( aURL ); + aExecItem.setState( MEDIASTATE_PLAY ); + } + } + } + break; + + case( AVMEDIA_TOOLBOXITEM_INSERT ): + { + MediaFloater* pFloater = AVMEDIA_MEDIAWINDOW(); + + if( pFloater ) + pFloater->dispatchCurrentURL(); + } + break; + + case( AVMEDIA_TOOLBOXITEM_PLAY ): + case( AVMEDIA_TOOLBOXITEM_PLAYFFW ): + { + aExecItem.setState( ( AVMEDIA_TOOLBOXITEM_PLAYFFW == p->GetCurItemId() ) ? MEDIASTATE_PLAYFFW : MEDIASTATE_PLAY ); + + if( maItem.getTime() == maItem.getDuration() ) + aExecItem.setTime( 0.0 ); + else + aExecItem.setTime( maItem.getTime() ); + } + break; + + case( AVMEDIA_TOOLBOXITEM_PAUSE ): + { + aExecItem.setState( MEDIASTATE_PAUSE ); + } + break; + + case( AVMEDIA_TOOLBOXITEM_STOP ): + { + aExecItem.setState( MEDIASTATE_STOP ); + aExecItem.setTime( 0.0 ); + } + break; + + case( AVMEDIA_TOOLBOXITEM_MUTE ): + { + aExecItem.setMute( !maMuteToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_MUTE ) ); + } + break; + + case( AVMEDIA_TOOLBOXITEM_LOOP ): + { + aExecItem.setLoop( !maPlayToolBox.IsItemChecked( AVMEDIA_TOOLBOXITEM_LOOP ) ); + } + break; + + default: + break; + } + + if( aExecItem.getMaskSet() != AVMEDIA_SETMASK_NONE ) + execute( aExecItem ); + } + + update(); + p->Invalidate( INVALIDATE_UPDATE ); + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implZoomSelectHdl, ListBox*, p ) +{ + if( p ) + { + MediaItem aExecItem; + ::com::sun::star::media::ZoomLevel eLevel; + + switch( p->GetSelectEntryPos() ) + { + case( AVMEDIA_ZOOMLEVEL_50 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_1_TO_2; break; + case( AVMEDIA_ZOOMLEVEL_100 ): eLevel = ::com::sun::star::media::ZoomLevel_ORIGINAL; break; + case( AVMEDIA_ZOOMLEVEL_200 ): eLevel = ::com::sun::star::media::ZoomLevel_ZOOM_2_TO_1; break; + case( AVMEDIA_ZOOMLEVEL_FIT ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT; break; + case( AVMEDIA_ZOOMLEVEL_SCALED ): eLevel = ::com::sun::star::media::ZoomLevel_FIT_TO_WINDOW; break; + + default: eLevel = ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE; break; + } + + aExecItem.setZoom( eLevel ); + execute( aExecItem ); + update(); + } + + return 0; +} + +// ------------------------------------------------------------------------------ + +IMPL_LINK( MediaControl, implTimeoutHdl, Timer*, EMPTYARG ) +{ + update(); + maTimer.Start(); + + return 0; +} + +} diff --git a/avmedia/source/framework/mediacontrol.hrc b/avmedia/source/framework/mediacontrol.hrc new file mode 100644 index 000000000000..081958ccd42c --- /dev/null +++ b/avmedia/source/framework/mediacontrol.hrc @@ -0,0 +1,53 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#define AVMEDIA_STR_PLAY 1024 +#define AVMEDIA_STR_PAUSE 1025 +#define AVMEDIA_STR_STOP 1026 +#define AVMEDIA_STR_ENDLESS 1027 +#define AVMEDIA_STR_ZOOM 1028 +#define AVMEDIA_STR_ZOOM_50 1029 +#define AVMEDIA_STR_ZOOM_100 1030 +#define AVMEDIA_STR_ZOOM_200 1031 +#define AVMEDIA_STR_ZOOM_FIT 1032 +#define AVMEDIA_STR_MUTE 1033 +#define AVMEDIA_STR_OPEN 1034 +#define AVMEDIA_STR_INSERT 1035 +#define AVMEDIA_STR_MEDIAPLAYER 1036 + +#define AVMEDIA_IMG_OPEN 2048 +#define AVMEDIA_IMG_PLAY 2049 +#define AVMEDIA_IMG_PAUSE 2050 +#define AVMEDIA_IMG_STOP 2051 +#define AVMEDIA_IMG_ENDLESS 2052 +#define AVMEDIA_IMG_INSERT 2053 +#define AVMEDIA_IMG_MUTE 2054 + +#define AVMEDIA_IMGLST 3072 +#define AVMEDIA_IMGLST_HC 3073 +#define AVMEDIA_IMGLST_L 3074 +#define AVMEDIA_IMGLST_L_HC 3075 diff --git a/avmedia/source/framework/mediacontrol.src b/avmedia/source/framework/mediacontrol.src new file mode 100644 index 000000000000..2ad203e2c34f --- /dev/null +++ b/avmedia/source/framework/mediacontrol.src @@ -0,0 +1,193 @@ + /************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "mediacontrol.hrc" + +String AVMEDIA_STR_OPEN +{ + Text[en-US] = "Open"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_INSERT +{ + Text [ en-US ] = "Apply" ; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_PLAY +{ + Text[en-US] = "Play"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_PAUSE +{ + Text[en-US] = "Pause"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_STOP +{ + Text[en-US] = "Stop"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ENDLESS +{ + Text[en-US] = "Repeat"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_MUTE +{ + Text[en-US] = "Mute"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM +{ + Text[en-US] = "View"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM_50 +{ + Text[en-US] = "50%"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM_100 +{ + Text[en-US] = "100%"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM_200 +{ + Text[en-US] = "200%"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_ZOOM_FIT +{ + Text[en-US] = "Scaled"; +}; + +// ------------------------------------------------------------------------------ + +String AVMEDIA_STR_MEDIAPLAYER +{ + Text[en-US] = "Media Player"; +}; + +// ------------------------------------------------------------------------------ + +ImageList AVMEDIA_IMGLST +{ + Prefix = "av"; + MaskColor = Color{ Red = 0xff00; Green = 0x0000; Blue = 0xff00; }; + IdList = + { + AVMEDIA_IMG_OPEN; + AVMEDIA_IMG_PLAY; + AVMEDIA_IMG_PAUSE; + AVMEDIA_IMG_STOP; + AVMEDIA_IMG_ENDLESS; + AVMEDIA_IMG_INSERT; + AVMEDIA_IMG_MUTE; + }; + IdCount = 7; +}; + +// ------------------------------------------------------------------------------ + +ImageList AVMEDIA_IMGLST_L +{ + Prefix = "avl"; + MaskColor = Color{ Red = 0xff00; Green = 0x0000; Blue = 0xff00; }; + IdList = + { + AVMEDIA_IMG_OPEN; + AVMEDIA_IMG_PLAY; + AVMEDIA_IMG_PAUSE; + AVMEDIA_IMG_STOP; + AVMEDIA_IMG_ENDLESS; + AVMEDIA_IMG_INSERT; + AVMEDIA_IMG_MUTE; + }; + IdCount = 7; +}; + +// ------------------------------------------------------------------------------ + +ImageList AVMEDIA_IMGLST_HC +{ + Prefix = "avh"; + MaskColor = Color{ Red = 0xff00; Green = 0x0000; Blue = 0xff00; }; + IdList = + { + AVMEDIA_IMG_OPEN; + AVMEDIA_IMG_PLAY; + AVMEDIA_IMG_PAUSE; + AVMEDIA_IMG_STOP; + AVMEDIA_IMG_ENDLESS; + AVMEDIA_IMG_INSERT; + AVMEDIA_IMG_MUTE; + }; + IdCount = 7; +}; + +// ------------------------------------------------------------------------------ + +ImageList AVMEDIA_IMGLST_L_HC +{ + Prefix = "avlh"; + MaskColor = Color{ Red = 0xff00; Green = 0x0000; Blue = 0xff00; }; + IdList = + { + AVMEDIA_IMG_OPEN; + AVMEDIA_IMG_PLAY; + AVMEDIA_IMG_PAUSE; + AVMEDIA_IMG_STOP; + AVMEDIA_IMG_ENDLESS; + AVMEDIA_IMG_INSERT; + AVMEDIA_IMG_MUTE; + }; + IdCount = 7; +}; diff --git a/avmedia/source/framework/mediaitem.cxx b/avmedia/source/framework/mediaitem.cxx new file mode 100644 index 000000000000..f75fafa0509e --- /dev/null +++ b/avmedia/source/framework/mediaitem.cxx @@ -0,0 +1,329 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <avmedia/mediaitem.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +using namespace ::com::sun::star; + +namespace avmedia +{ + +// ------------- +// - MediaItem - +// ------------- + +TYPEINIT1_AUTOFACTORY( MediaItem, ::SfxPoolItem ); + ::rtl::OUString maURL; + sal_uInt32 mnMaskSet; + MediaState meState; + double mfTime; + double mfDuration; + sal_Int16 mnVolumeDB; + sal_Bool mbLoop; + sal_Bool mbMute; + ::com::sun::star::media::ZoomLevel meZoom; + +// ------------------------------------------------------------------------------ + +MediaItem::MediaItem( sal_uInt16 _nWhich, sal_uInt32 nMaskSet ) : + SfxPoolItem( _nWhich ), + mnMaskSet( nMaskSet ), + meState( MEDIASTATE_STOP ), + mfTime( 0.0 ), + mfDuration( 0.0 ), + mnVolumeDB( 0 ), + mbLoop( false ), + mbMute( false ), + meZoom( ::com::sun::star::media::ZoomLevel_NOT_AVAILABLE ) +{ +} + +// ------------------------------------------------------------------------------ + +MediaItem::MediaItem( const MediaItem& rItem ) : + SfxPoolItem( rItem ), + maURL( rItem.maURL ), + mnMaskSet( rItem.mnMaskSet ), + meState( rItem.meState ), + mfTime( rItem.mfTime ), + mfDuration( rItem.mfDuration ), + mnVolumeDB( rItem.mnVolumeDB ), + mbLoop( rItem.mbLoop ), + mbMute( rItem.mbMute ), + meZoom( rItem.meZoom ) +{ +} + +// ------------------------------------------------------------------------------ + +MediaItem::~MediaItem() +{ +} + +// ------------------------------------------------------------------------------ + +int MediaItem::operator==( const SfxPoolItem& rItem ) const +{ + DBG_ASSERT( SfxPoolItem::operator==(rItem), "unequal types" ); + return( mnMaskSet == static_cast< const MediaItem& >( rItem ).mnMaskSet && + maURL == static_cast< const MediaItem& >( rItem ).maURL && + meState == static_cast< const MediaItem& >( rItem ).meState && + mfDuration == static_cast< const MediaItem& >( rItem ).mfDuration && + mfTime == static_cast< const MediaItem& >( rItem ).mfTime && + mnVolumeDB == static_cast< const MediaItem& >( rItem ).mnVolumeDB && + mbLoop == static_cast< const MediaItem& >( rItem ).mbLoop && + mbMute == static_cast< const MediaItem& >( rItem ).mbMute && + meZoom == static_cast< const MediaItem& >( rItem ).meZoom ); +} + +// ------------------------------------------------------------------------------ + +SfxPoolItem* MediaItem::Clone( SfxItemPool* ) const +{ + return new MediaItem( *this ); +} + +//------------------------------------------------------------------------ + +SfxItemPresentation MediaItem::GetPresentation( SfxItemPresentation, + SfxMapUnit, + SfxMapUnit, + XubString& rText, + const IntlWrapper * ) const +{ + rText.Erase(); + return SFX_ITEM_PRESENTATION_NONE; +} + +//------------------------------------------------------------------------ + +sal_Bool MediaItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const +{ + uno::Sequence< uno::Any > aSeq( 9 ); + + aSeq[ 0 ] <<= maURL; + aSeq[ 1 ] <<= mnMaskSet; + aSeq[ 2 ] <<= static_cast< sal_Int32 >( meState ); + aSeq[ 3 ] <<= mfTime; + aSeq[ 4 ] <<= mfDuration; + aSeq[ 5 ] <<= mnVolumeDB; + aSeq[ 6 ] <<= mbLoop; + aSeq[ 7 ] <<= mbMute; + aSeq[ 8 ] <<= meZoom; + + rVal <<= aSeq; + + return true; +} + +//------------------------------------------------------------------------ + +sal_Bool MediaItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 ) +{ + uno::Sequence< uno::Any > aSeq; + sal_Bool bRet = false; + + if( ( rVal >>= aSeq ) && ( aSeq.getLength() == 9 ) ) + { + sal_Int32 nInt32 = 0; + + aSeq[ 0 ] >>= maURL; + aSeq[ 1 ] >>= mnMaskSet; + aSeq[ 2 ] >>= nInt32; meState = static_cast< MediaState >( nInt32 ); + aSeq[ 3 ] >>= mfTime; + aSeq[ 4 ] >>= mfDuration; + aSeq[ 5 ] >>= mnVolumeDB; + aSeq[ 6 ] >>= mbLoop; + aSeq[ 7 ] >>= mbMute; + aSeq[ 8 ] >>= meZoom; + + bRet = true; + } + + return bRet; +} + +//------------------------------------------------------------------------ + +void MediaItem::merge( const MediaItem& rMediaItem ) +{ + const sal_uInt32 nMaskSet = rMediaItem.getMaskSet(); + + if( AVMEDIA_SETMASK_URL & nMaskSet ) + setURL( rMediaItem.getURL() ); + + if( AVMEDIA_SETMASK_STATE & nMaskSet ) + setState( rMediaItem.getState() ); + + if( AVMEDIA_SETMASK_DURATION & nMaskSet ) + setDuration( rMediaItem.getDuration() ); + + if( AVMEDIA_SETMASK_TIME & nMaskSet ) + setTime( rMediaItem.getTime() ); + + if( AVMEDIA_SETMASK_LOOP & nMaskSet ) + setLoop( rMediaItem.isLoop() ); + + if( AVMEDIA_SETMASK_MUTE & nMaskSet ) + setMute( rMediaItem.isMute() ); + + if( AVMEDIA_SETMASK_VOLUMEDB & nMaskSet ) + setVolumeDB( rMediaItem.getVolumeDB() ); + + if( AVMEDIA_SETMASK_ZOOM & nMaskSet ) + setZoom( rMediaItem.getZoom() ); +} + +//------------------------------------------------------------------------ + +sal_uInt32 MediaItem::getMaskSet() const +{ + return mnMaskSet; +} + +//------------------------------------------------------------------------ + +void MediaItem::setURL( const ::rtl::OUString& rURL ) +{ + maURL = rURL; + mnMaskSet |= AVMEDIA_SETMASK_URL; +} + +//------------------------------------------------------------------------ + +const ::rtl::OUString& MediaItem::getURL() const +{ + return maURL; +} + +//------------------------------------------------------------------------ + +void MediaItem::setState( MediaState eState ) +{ + meState = eState; + mnMaskSet |= AVMEDIA_SETMASK_STATE; +} + +//------------------------------------------------------------------------ + +MediaState MediaItem::getState() const +{ + return meState; +} + +//------------------------------------------------------------------------ + +void MediaItem::setDuration( double fDuration ) +{ + mfDuration = fDuration; + mnMaskSet |= AVMEDIA_SETMASK_DURATION; +} + +//------------------------------------------------------------------------ + +double MediaItem::getDuration() const +{ + return mfDuration; +} + +//------------------------------------------------------------------------ + +void MediaItem::setTime( double fTime ) +{ + mfTime = fTime; + mnMaskSet |= AVMEDIA_SETMASK_TIME; +} + +//------------------------------------------------------------------------ + +double MediaItem::getTime() const +{ + return mfTime; +} + +//------------------------------------------------------------------------ + +void MediaItem::setLoop( sal_Bool bLoop ) +{ + mbLoop = bLoop; + mnMaskSet |= AVMEDIA_SETMASK_LOOP; +} + +//------------------------------------------------------------------------ + +sal_Bool MediaItem::isLoop() const +{ + return mbLoop; +} + +//------------------------------------------------------------------------ + +void MediaItem::setMute( sal_Bool bMute ) +{ + mbMute = bMute; + mnMaskSet |= AVMEDIA_SETMASK_MUTE; +} + +//------------------------------------------------------------------------ + +sal_Bool MediaItem::isMute() const +{ + return mbMute; +} + +//------------------------------------------------------------------------ + +void MediaItem::setVolumeDB( sal_Int16 nDB ) +{ + mnVolumeDB = nDB; + mnMaskSet |= AVMEDIA_SETMASK_VOLUMEDB; +} + +//------------------------------------------------------------------------ + +sal_Int16 MediaItem::getVolumeDB() const +{ + return mnVolumeDB; +} + +//------------------------------------------------------------------------ + +void MediaItem::setZoom( ::com::sun::star::media::ZoomLevel eZoom ) +{ + meZoom = eZoom; + mnMaskSet |= AVMEDIA_SETMASK_ZOOM; +} + +//------------------------------------------------------------------------ + +::com::sun::star::media::ZoomLevel MediaItem::getZoom() const +{ + return meZoom; +} + +} diff --git a/avmedia/source/framework/mediamisc.cxx b/avmedia/source/framework/mediamisc.cxx new file mode 100644 index 000000000000..b7807e767c6d --- /dev/null +++ b/avmedia/source/framework/mediamisc.cxx @@ -0,0 +1,48 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <tools/resmgr.hxx> +#include <svl/solar.hrc> +#include <vcl/svapp.hxx> + +namespace avmedia { + +ResMgr* GetResMgr() +{ + static ResMgr* pResMgr = NULL; + + if( !pResMgr ) + { + ByteString aResMgrName( "avmedia" ); + + pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); + } + + return pResMgr; +} + +} // namespace avemdia diff --git a/avmedia/source/framework/mediaplayer.cxx b/avmedia/source/framework/mediaplayer.cxx new file mode 100644 index 000000000000..b476f9a2ef41 --- /dev/null +++ b/avmedia/source/framework/mediaplayer.cxx @@ -0,0 +1,166 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <avmedia/mediaplayer.hxx> +#include <avmedia/mediawindow.hxx> +#include <avmedia/mediaitem.hxx> +#include "mediamisc.hxx" +#include "mediacontrol.hrc" +#include "helpids.hrc" + +#include <svl/stritem.hxx> +#include <sfx2/app.hxx> +#include <sfx2/sfxsids.hrc> +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> + +namespace avmedia +{ + +// --------------- +// - MediaPlayer - +// --------------- + +MediaPlayer::MediaPlayer( Window* _pParent, sal_uInt16 nId, SfxBindings* _pBindings, SfxChildWinInfo* pInfo ) : + SfxChildWindow( _pParent, nId ) +{ + pWindow = new MediaFloater( _pBindings, this, _pParent ); + eChildAlignment = SFX_ALIGN_NOALIGNMENT; + static_cast< MediaFloater* >( pWindow )->Initialize( pInfo ); +}; + +// ----------------------------------------------------------------------------- + +MediaPlayer::~MediaPlayer() +{ +} + +// ----------------------------------------------------------------------------- + +SFX_IMPL_DOCKINGWINDOW( MediaPlayer, SID_AVMEDIA_PLAYER ) + +// ---------------- +// - MediaFloater - +// ---------------- + +MediaFloater::MediaFloater( SfxBindings* _pBindings, SfxChildWindow* pCW, Window* pParent ) : + SfxDockingWindow( _pBindings, pCW, pParent, WB_CLOSEABLE | WB_MOVEABLE | WB_SIZEABLE | WB_DOCKABLE ), + mpMediaWindow( new MediaWindow( this, true ) ) +{ + const Size aSize( 378, 256 ); + + SetPosSizePixel( Point( 0, 0 ), aSize ); + SetMinOutputSizePixel( aSize ); + SetText( String( AVMEDIA_RESID( AVMEDIA_STR_MEDIAPLAYER ) ) ); + implInit(); + mpMediaWindow->show(); +} + +// ----------------------------------------------------------------------------- + +MediaFloater::~MediaFloater() +{ + delete mpMediaWindow; + mpMediaWindow = NULL; +} + +// ----------------------------------------------------------------------------- + +void MediaFloater::implInit() +{ +} + +// ------------------------------------------------------------------------- + +void MediaFloater::Resize() +{ + SfxDockingWindow::Resize(); + + if( mpMediaWindow ) + mpMediaWindow->setPosSize( Rectangle( Point(), GetOutputSizePixel() ) ); +} + +// ----------------------------------------------------------------------------- + +void MediaFloater::ToggleFloatingMode() +{ + ::avmedia::MediaItem aRestoreItem; + + mpMediaWindow->updateMediaItem( aRestoreItem ); + delete mpMediaWindow; + mpMediaWindow = NULL; + + SfxDockingWindow::ToggleFloatingMode(); + + mpMediaWindow = new MediaWindow( this, true ); + + mpMediaWindow->setPosSize( Rectangle( Point(), GetOutputSizePixel() ) ); + mpMediaWindow->executeMediaItem( aRestoreItem ); + + Window* pWindow = mpMediaWindow->getWindow(); + + if( pWindow ) + pWindow->SetHelpId( HID_AVMEDIA_PLAYERWINDOW ); + + mpMediaWindow->show(); +} + +// ----------------------------------------------------------------------------- + +void MediaFloater::setURL( const ::rtl::OUString& rURL, bool bPlayImmediately ) +{ + if( mpMediaWindow ) + { + mpMediaWindow->setURL( rURL ); + + if( mpMediaWindow->isValid() && bPlayImmediately ) + mpMediaWindow->start(); + } +} + +// ----------------------------------------------------------------------------- + +const ::rtl::OUString& MediaFloater::getURL() const +{ + static const ::rtl::OUString aEmptyStr; + return( mpMediaWindow ? mpMediaWindow->getURL() : aEmptyStr ); +} + +// ----------------------------------------------------------------------------- + +void MediaFloater::dispatchCurrentURL() +{ + SfxDispatcher* pDispatcher = GetBindings().GetDispatcher(); + + if( pDispatcher ) + { + const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, getURL() ); + pDispatcher->Execute( SID_INSERT_AVMEDIA, SFX_CALLMODE_RECORD, &aMediaURLItem, 0L ); + } +} + +} diff --git a/avmedia/source/framework/mediatoolbox.cxx b/avmedia/source/framework/mediatoolbox.cxx new file mode 100644 index 000000000000..74bacb3861f0 --- /dev/null +++ b/avmedia/source/framework/mediatoolbox.cxx @@ -0,0 +1,168 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <avmedia/mediatoolbox.hxx> +#include <avmedia/mediaitem.hxx> +#include "mediacontrol.hxx" + +#include <sfx2/app.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/sfxsids.hrc> + +using namespace ::com::sun::star; + +namespace avmedia +{ + +// ----------------------- +// - MediaToolboxControl - +// ----------------------- + +class MediaToolBoxControl_Impl : public MediaControl +{ +public: + + MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl ); + ~MediaToolBoxControl_Impl(); + + void update(); + void execute( const MediaItem& rItem ); + +private: + + MediaToolBoxControl* mpToolBoxControl; +}; + +// --------------------------------------------------------------------- + +MediaToolBoxControl_Impl::MediaToolBoxControl_Impl( Window& rParent, MediaToolBoxControl& rControl ) : + MediaControl( &rParent, MEDIACONTROLSTYLE_SINGLELINE ), + mpToolBoxControl( &rControl ) +{ + SetSizePixel( getMinSizePixel() ); +} + +// --------------------------------------------------------------------- + +MediaToolBoxControl_Impl::~MediaToolBoxControl_Impl() +{ +} + +// --------------------------------------------------------------------- + +void MediaToolBoxControl_Impl::update() +{ + mpToolBoxControl->implUpdateMediaControl(); +} + +// --------------------------------------------------------------------- + +void MediaToolBoxControl_Impl::execute( const MediaItem& rItem ) +{ + mpToolBoxControl->implExecuteMediaControl( rItem ); +} + +// ----------------------- +// - MediaToolBoxControl - +// ----------------------- + +SFX_IMPL_TOOLBOX_CONTROL( ::avmedia::MediaToolBoxControl, ::avmedia::MediaItem ); + +// ----------------------------------------------------------------------------- + +MediaToolBoxControl::MediaToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) : + SfxToolBoxControl( nSlotId, nId, rTbx ) +{ + rTbx.Invalidate(); +} + +// ----------------------------------------------------------------------------- + +MediaToolBoxControl::~MediaToolBoxControl() +{ +} + +// ----------------------------------------------------------------------------- + +void MediaToolBoxControl::StateChanged( sal_uInt16 /* nSID */, SfxItemState eState, const SfxPoolItem* pState ) + +{ + MediaToolBoxControl_Impl* pCtrl = static_cast< MediaToolBoxControl_Impl* >( GetToolBox().GetItemWindow( GetId() ) ); + + DBG_ASSERT( pCtrl, "MediaToolBoxControl::StateChanged: media control not found" ); + + if( eState == SFX_ITEM_DISABLED ) + { + pCtrl->Enable( false, false ); + pCtrl->SetText( String() ); + + const MediaItem aEmptyMediaItem( 0, AVMEDIA_SETMASK_ALL ); + pCtrl->setState( aEmptyMediaItem ); + } + else + { + pCtrl->Enable( true, false ); + + const MediaItem* pMediaItem = PTR_CAST( MediaItem, pState ); + + if( pMediaItem && ( SFX_ITEM_AVAILABLE == eState ) ) + pCtrl->setState( *pMediaItem ); + } +} + +// ----------------------------------------------------------------------------- + +Window* MediaToolBoxControl::CreateItemWindow( Window *pParent ) +{ + return( pParent ? new MediaToolBoxControl_Impl( *pParent, *this ) : NULL ); +} + +// ----------------------------------------------------------------------------- + +void MediaToolBoxControl::implUpdateMediaControl() +{ + updateStatus( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AVMediaToolBox" ) ) ); +} + +// ----------------------------------------------------------------------------- + +void MediaToolBoxControl::implExecuteMediaControl( const MediaItem& rItem ) +{ + MediaItem aExecItem( SID_AVMEDIA_TOOLBOX ); + uno::Sequence< beans::PropertyValue > aArgs( 1 ); + uno::Any aAny; + + aExecItem.merge( rItem ); + aExecItem.QueryValue( aAny ); + aArgs[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AVMediaToolBox" ) ); + aArgs[ 0 ].Value = aAny; + + Dispatch( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AVMediaToolBox" ) ), aArgs ); +} + +} diff --git a/avmedia/source/framework/soundhandler.cxx b/avmedia/source/framework/soundhandler.cxx new file mode 100644 index 000000000000..a1fed18a0f68 --- /dev/null +++ b/avmedia/source/framework/soundhandler.cxx @@ -0,0 +1,525 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +//_________________________________________________________________________________________________________________ +// my own includes +//_________________________________________________________________________________________________________________ + +#ifndef __FRAMEWORK_DISPATCH_SOUNDHANDLER_HXX_ +#include "soundhandler.hxx" +#endif + +#ifndef __COMPHELPER_MEDIADESCRIPTOR_HXX_ +#include <comphelper/mediadescriptor.hxx> +#endif + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/frame/DispatchResultState.hpp> + +//_________________________________________________________________________________________________________________ +// includes of other projects +//_________________________________________________________________________________________________________________ +#include <comphelper/sequenceashashmap.hxx> +#include <rtl/ustrbuf.hxx> + +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/factory.hxx> + +//_________________________________________________________________________________________________________________ +// namespace +//_________________________________________________________________________________________________________________ + +namespace avmedia{ + +//_________________________________________________________________________________________________________________ +// non exported const +//_________________________________________________________________________________________________________________ + +//_________________________________________________________________________________________________________________ +// non exported definitions +//_________________________________________________________________________________________________________________ + +//_________________________________________________________________________________________________________________ +// declarations +//_________________________________________________________________________________________________________________ + +//***************************************************************************************************************** +// XInterface, XTypeProvider, XServiceInfo +//***************************************************************************************************************** + +void SAL_CALL SoundHandler::acquire() throw() +{ + /* Don't use mutex in methods of XInterface! */ + OWeakObject::acquire(); +} + +void SAL_CALL SoundHandler::release() throw() +{ + /* Don't use mutex in methods of XInterface! */ + OWeakObject::release(); +} + +css::uno::Any SAL_CALL SoundHandler::queryInterface( const css::uno::Type& aType ) throw( css::uno::RuntimeException ) +{ + /* Attention: Don't use mutex or guard in this method!!! Is a method of XInterface. */ + /* Ask for my own supported interfaces ...*/ + css::uno::Any aReturn( ::cppu::queryInterface( aType, + static_cast< css::lang::XTypeProvider* >(this), + static_cast< css::lang::XServiceInfo* >(this), + static_cast< css::frame::XNotifyingDispatch* >(this), + static_cast< css::frame::XDispatch* >(this), + static_cast< css::document::XExtendedFilterDetection* >(this))); + /* If searched interface not supported by this class ... */ + if ( aReturn.hasValue() == sal_False ) + { + /* ... ask baseclass for interfaces! */ + aReturn = OWeakObject::queryInterface( aType ); + } + /* Return result of this search. */ + return aReturn; +} + +css::uno::Sequence< sal_Int8 > SAL_CALL SoundHandler::getImplementationId() throw( css::uno::RuntimeException ) +{ + /* Create one Id for all instances of this class. */ + /* Use ethernet address to do this! (sal_True) */ + /* Optimize this method */ + /* We initialize a static variable only one time. And we don't must use a mutex at every call! */ + /* For the first call; pID is NULL - for the second call pID is different from NULL! */ + static ::cppu::OImplementationId* pID = NULL ; + if ( pID == NULL ) + { + /* Ready for multithreading; get global mutex for first call of this method only! see before */ + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + /* Control these pointer again ... it can be, that another instance will be faster then these! */ + if ( pID == NULL ) + { + /* Create a new static ID ... */ + static ::cppu::OImplementationId aID( sal_False ); + /* ... and set his address to static pointer! */ + pID = &aID ; + } + } + return pID->getImplementationId(); +} + +css::uno::Sequence< css::uno::Type > SAL_CALL SoundHandler::getTypes() throw( css::uno::RuntimeException ) +{ + /* Optimize this method ! */ + /* We initialize a static variable only one time. */ + /* And we don't must use a mutex at every call! */ + /* For the first call; pTypeCollection is NULL - */ + /* for the second call pTypeCollection is different from NULL! */ + static ::cppu::OTypeCollection* pTypeCollection = NULL ; + if ( pTypeCollection == NULL ) + { + /* Ready for multithreading; get global mutex for first call of this method only! see before */ + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + /* Control these pointer again ... it can be, that another instance will be faster then these! */ + if ( pTypeCollection == NULL ) + { + /* Create a static typecollection ... */ + static ::cppu::OTypeCollection aTypeCollection + ( + ::getCppuType(( const ::com::sun::star::uno::Reference< css::lang::XTypeProvider >*)NULL ), + ::getCppuType(( const ::com::sun::star::uno::Reference< css::lang::XServiceInfo >*)NULL ), + ::getCppuType(( const ::com::sun::star::uno::Reference< css::frame::XNotifyingDispatch >*)NULL ), + ::getCppuType(( const ::com::sun::star::uno::Reference< css::frame::XDispatch >*)NULL ), + ::getCppuType(( const ::com::sun::star::uno::Reference< css::document::XExtendedFilterDetection >*)NULL ) + ); + /* ... and set his address to static pointer! */ + pTypeCollection = &aTypeCollection ; + } + } + return pTypeCollection->getTypes(); +} + +#define DECLARE_ASCII( SASCIIVALUE ) \ + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SASCIIVALUE ) ) + +#define IMPLEMENTATIONNAME_SOUNDHANDLER DECLARE_ASCII("com.sun.star.comp.framework.SoundHandler") +#define SERVICENAME_CONTENTHANDLER DECLARE_ASCII("com.sun.star.frame.ContentHandler") + +/*===========================================================================================================*/ +/* XServiceInfo */ +/*===========================================================================================================*/ +::rtl::OUString SAL_CALL SoundHandler::getImplementationName() throw( css::uno::RuntimeException ) +{ + return impl_getStaticImplementationName(); +} + +/*===========================================================================================================*/ +/* XServiceInfo */ +/*===========================================================================================================*/ +sal_Bool SAL_CALL SoundHandler::supportsService( const ::rtl::OUString& sServiceName ) throw( css::uno::RuntimeException ) +{ + /* Set default return value. */ + sal_Bool bReturn = sal_False ; + /* Get names of all supported servicenames. */ + css::uno::Sequence< ::rtl::OUString > seqServiceNames = getSupportedServiceNames(); + const ::rtl::OUString* pArray = seqServiceNames.getConstArray(); + sal_Int32 nCounter = 0; + sal_Int32 nLength = seqServiceNames.getLength(); + /* Search for right name in list. */ + while ( + ( nCounter < nLength ) && + ( bReturn == sal_False ) + ) + { + /* Is name was found, say "YES, SERVICE IS SUPPORTED." and break loop. */ + if ( pArray[nCounter] == sServiceName ) + { + bReturn = sal_True ; + } + /* Else step to next element in list. */ + ++nCounter; + } + /* Return state of search. */ + return bReturn; +} + +/*===========================================================================================================*/ +/* XServiceInfo */ +/*===========================================================================================================*/ +css::uno::Sequence< ::rtl::OUString > SAL_CALL SoundHandler::getSupportedServiceNames() throw( css::uno::RuntimeException ) +{ + return impl_getStaticSupportedServiceNames(); +} + +/*===========================================================================================================*/ +/* Helper for XServiceInfo */ +/*===========================================================================================================*/ +css::uno::Sequence< ::rtl::OUString > SoundHandler::impl_getStaticSupportedServiceNames() +{ + css::uno::Sequence< ::rtl::OUString > seqServiceNames( 1 ); + seqServiceNames.getArray() [0] = SERVICENAME_CONTENTHANDLER; + return seqServiceNames; +} + +/*===========================================================================================================*/ +/* Helper for XServiceInfo */ +/*===========================================================================================================*/ +::rtl::OUString SoundHandler::impl_getStaticImplementationName() +{ + return IMPLEMENTATIONNAME_SOUNDHANDLER; +} + +css::uno::Reference< css::uno::XInterface > SAL_CALL SoundHandler::impl_createInstance( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception ) +{ + /* create new instance of service */ + SoundHandler* pClass = new SoundHandler( xServiceManager ); + /* hold it alive by increasing his ref count!!! */ + css::uno::Reference< css::uno::XInterface > xService( static_cast< ::cppu::OWeakObject* >(pClass), css::uno::UNO_QUERY ); + /* initialize new service instance ... he can use his own refcount ... we hold it! */ + pClass->impl_initService(); + /* return new created service as reference */ + return xService; +} + +css::uno::Reference< css::lang::XSingleServiceFactory > SoundHandler::impl_createFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) +{ + css::uno::Reference< css::lang::XSingleServiceFactory > xReturn ( cppu::createSingleFactory ( + xServiceManager, + SoundHandler::impl_getStaticImplementationName(), + SoundHandler::impl_createInstance, + SoundHandler::impl_getStaticSupportedServiceNames() + ) + ); + return xReturn; +} + +void SAL_CALL SoundHandler::impl_initService() +{ +} + + +/*-************************************************************************************************************//** + @short standard ctor + @descr These initialize a new instance of this class with needed informations for work. + + @seealso using at owner + + @param "xFactory", reference to service manager for creation of new services + @return - + + @onerror Show an assertion and do nothing else. + @threadsafe yes +*//*-*************************************************************************************************************/ +SoundHandler::SoundHandler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ) + // Init baseclasses first + : ThreadHelpBase ( ) + , ::cppu::OWeakObject ( ) + // Init member + , m_bError ( false ) + , m_xFactory ( xFactory ) +{ + m_aUpdateTimer.SetTimeoutHdl(LINK(this, SoundHandler, implts_PlayerNotify)); +} + +/*-************************************************************************************************************//** + @short standard dtor + @descr - + + @seealso - + + @param - + @return - + + @onerror - + @threadsafe - +*//*-*************************************************************************************************************/ +SoundHandler::~SoundHandler() +{ + if (m_xListener.is()) + { + css::frame::DispatchResultEvent aEvent; + aEvent.State = css::frame::DispatchResultState::FAILURE; + m_xListener->dispatchFinished(aEvent); + m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >(); + } +} + +/*-************************************************************************************************************//** + @interface ::com::sun::star::frame::XDispatch + + @short try to load audio file + @descr This method try to load given audio file by URL and play it. We use vcl/Sound class to do that. + Playing of sound is asynchron everytime. + + @attention We must hold us alive by ourself ... because we use async. vcl sound player ... but playing is started + in async interface call "dispatch()" too. And caller forget us imediatly. But then our uno ref count + will decreased to 0 and will die. The only solution is to use own reference to our implementation. + But we do it for realy started jobs only and release it during call back of vcl. + + @seealso class vcl/Sound + @seealso method implts_PlayerNotify() + + @param "aURL" , URL to dispatch. + @param "lArguments", list of optional arguments. + @return - + + @onerror We do nothing. + @threadsafe yes +*//*-*************************************************************************************************************/ +void SAL_CALL SoundHandler::dispatchWithNotification(const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lDescriptor, + const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException) +{ + // SAFE { + const ::vos::OGuard aLock( m_aLock ); + + { + //close streams otherwise on windows we can't reopen the file in the + //media player when we pass the url to directx as it'll already be open + ::comphelper::MediaDescriptor aDescriptor(lDescriptor); + + css::uno::Reference< css::io::XInputStream > xInputStream = + aDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_INPUTSTREAM(), + css::uno::Reference< css::io::XInputStream >()); + if (xInputStream.is()) xInputStream->closeInput(); + } + + // If player currently used for other dispatch() requests ... + // cancel it by calling stop()! + m_aUpdateTimer.Stop(); + if (m_xPlayer.is()) + { + if (m_xPlayer->isPlaying()) + m_xPlayer->stop(); + m_xPlayer.clear(); + } + + // Try to initialize player. + m_xListener = xListener; + try + { + m_bError = false; + m_xPlayer.set( avmedia::MediaWindow::createPlayer( aURL.Complete ), css::uno::UNO_QUERY_THROW ); + // OK- we can start async playing ... + // Count this request and initialize self-holder against dieing by uno ref count ... + m_xSelfHold = css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY); + m_xPlayer->start(); + m_aUpdateTimer.SetTimeout( 200 ); + m_aUpdateTimer.Start(); + } + catch( css::uno::Exception& e ) + { + m_bError = true; + (void)e; + m_xPlayer.clear(); + } + + // } SAFE +} + +void SAL_CALL SoundHandler::dispatch( const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException ) +{ + dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >()); +} + +/*-************************************************************************************************************//** + @interface ::com::sun::star::document::XExtendedFilterDetection + + @short try to detect file (given as argument included in "lDescriptor") + @descr We try to detect, if given file could be handled by this class and is a well known one. + If it is - we return right internal type name - otherwise we return nothing! + So call can search for another detect service and ask him too. + + @attention a) We don't need any mutex here ... because we don't use any member! + b) Dont' use internal player instance "m_pPlayer" to detect given sound file! + It's not neccessary to do that ... and we can use temp. variable to do the same. + This way is easy - we don't must synchronize it with currently played sounds! + Another reason to do so ... We are a listener on our internal ma_Player object. + If you would call "IsSoundFile()" on this instance, he would call us back and + we make some uneccssary things ... + + @seealso - + + @param "lDescriptor", description of file to detect + @return Internal type name which match this file ... or nothing if it is unknown. + + @onerror We return nothing. + @threadsafe yes +*//*-*************************************************************************************************************/ +::rtl::OUString SAL_CALL SoundHandler::detect( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor ) throw( css::uno::RuntimeException ) +{ + // Our default is "nothing". So we can return it, if detection failed or fily type is realy unknown. + ::rtl::OUString sTypeName; + + // Analyze given descriptor to find filename or input stream or ... + ::comphelper::MediaDescriptor aDescriptor(lDescriptor); + ::rtl::OUString sURL = aDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_URL(), ::rtl::OUString()); + + if ( + (sURL.getLength() ) && + (avmedia::MediaWindow::isMediaURL(sURL)) + ) + { + // If the file type is supported depends on the OS, so... + // I think we can the following ones: + // a) look for given extension of url to map our type decision HARD CODED!!! + // b) return preferred type every time... it's easy :-) + sTypeName = ::rtl::OUString::createFromAscii("wav_Wave_Audio_File"); + aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sTypeName; + aDescriptor >> lDescriptor; + } + + // Return our decision. + return sTypeName; +} + +/*-************************************************************************************************************//** + @short call back of sound player + @descr Our player call us back to give us some informations. + We use this informations to callback our might existing listener. + + @seealso method dispatchWithNotification() + + @param - + @return 0 everytime ... it doesnt matter for us. + + @onerror - + @threadsafe yes +*//*-*************************************************************************************************************/ +IMPL_LINK( SoundHandler, implts_PlayerNotify, void*, EMPTYARG ) +{ + // SAFE { + ::vos::OClearableGuard aLock( m_aLock ); + + if (m_xPlayer.is() && m_xPlayer->isPlaying() && m_xPlayer->getMediaTime() < m_xPlayer->getDuration()) + { + m_aUpdateTimer.Start(); + return 0L; + } + m_xPlayer.clear(); + + // We use m_xSelfHold to let us die ... but we must live till real finishing of this method too!!! + // So we SHOULD use another "self-holder" temp. to provide that ... + css::uno::Reference< css::uno::XInterface > xOperationHold = m_xSelfHold; + m_xSelfHold = css::uno::Reference< css::uno::XInterface >(); + + // notify might existing listener + // And forget this listener! + // Because the corresponding dispatch was finished. + if (m_xListener.is()) + { + css::frame::DispatchResultEvent aEvent; + if (!m_bError) + aEvent.State = css::frame::DispatchResultState::SUCCESS; + else + aEvent.State = css::frame::DispatchResultState::FAILURE; + m_xListener->dispatchFinished(aEvent); + m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >(); + } + + // } SAFE + //release aLock before end of method at which point xOperationHold goes out of scope and pThis dies + aLock.clear(); + return 0; +} + +} // namespace framework + +// ------------------------------------------ +// - component_getImplementationEnvironment - +// ------------------------------------------ + +extern "C" void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +// ------------------------ +// - component_getFactory - +// ------------------------ + +extern "C" void* SAL_CALL component_getFactory(const sal_Char* pImplementationName, void* pServiceManager, void* /*pRegistryKey*/ ) +{ + void* pReturn = NULL; + if (pServiceManager != NULL ) + { + /* Define variables which are used in following macros. */ + css::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > xFactory; + css::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager; + xServiceManager = reinterpret_cast< ::com::sun::star::lang::XMultiServiceFactory* >( pServiceManager ) ; + + if ( avmedia::SoundHandler::impl_getStaticImplementationName().equals( ::rtl::OUString::createFromAscii( pImplementationName ) ) ) + xFactory = avmedia::SoundHandler::impl_createFactory( xServiceManager ); + + if ( xFactory.is() == sal_True ) + { + xFactory->acquire(); + pReturn = xFactory.get(); + } + } + /* Return with result of this operation. */ + return pReturn; +} diff --git a/avmedia/source/framework/soundhandler.hxx b/avmedia/source/framework/soundhandler.hxx new file mode 100644 index 000000000000..55d30536d8ce --- /dev/null +++ b/avmedia/source/framework/soundhandler.hxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_ +#define __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_ + +//_________________________________________________________________________________________________________________ +// interface includes +//_________________________________________________________________________________________________________________ + +#include <com/sun/star/lang/XTypeProvider.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/frame/XNotifyingDispatch.hpp> +#include <com/sun/star/frame/XStatusListener.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/media/XPlayer.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/util/URL.hpp> + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> + +//_________________________________________________________________________________________________________________ +// other includes +//_________________________________________________________________________________________________________________ +#include <cppuhelper/weak.hxx> + +#include <vcl/timer.hxx> +#include <tools/link.hxx> +#include <avmedia/mediawindow.hxx> +#include <vos/mutex.hxx> + +namespace css = ::com::sun::star; + +//_________________________________________________________________________________________________________________ +// namespace +//_________________________________________________________________________________________________________________ + +namespace avmedia{ + +//_________________________________________________________________________________________________________________ +// exported const +//_________________________________________________________________________________________________________________ + +//_________________________________________________________________________________________________________________ +// exported definitions +//_________________________________________________________________________________________________________________ + +struct ThreadHelpBase +{ + public: + mutable ::vos::OMutex m_aLock; +}; + +/*-************************************************************************************************************//** + @short handler to detect and play sounds ("wav" and "au" only!) + @descr Register this implementation as a content handler to detect and/or play wav- and au-sounds. + It doesn't depend from the target platform. But one instance of this class + can play one sound at the same time only. Means every new dispatch request will stop the + might still running one. So we support one operation/one URL/one listener at the same time + only. + + @devstatus ready + @threadsafe yes +*//*-*************************************************************************************************************/ +class SoundHandler : // interfaces + public css::lang::XTypeProvider + , public css::lang::XServiceInfo + , public css::frame::XNotifyingDispatch // => XDispatch + , public css::document::XExtendedFilterDetection + // baseclasses + // Order is neccessary for right initialization! + , private ThreadHelpBase + , public ::cppu::OWeakObject +{ + //------------------------------------------------------------------------------------------------------------- + // public methods + //------------------------------------------------------------------------------------------------------------- + public: + + //--------------------------------------------------------------------------------------------------------- + // constructor / destructor + //--------------------------------------------------------------------------------------------------------- + SoundHandler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ); + virtual ~SoundHandler( ); + + //--------------------------------------------------------------------------------------------------------- + // XInterface, XTypeProvider, XServiceInfo + //--------------------------------------------------------------------------------------------------------- + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) throw( css::uno::RuntimeException ); + virtual void SAL_CALL acquire() throw(); + virtual void SAL_CALL release() throw(); + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes () throw( css::uno::RuntimeException ); + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() throw( css::uno::RuntimeException ); + + + /* interface XServiceInfo */ + virtual ::rtl::OUString SAL_CALL getImplementationName ( ) throw( css::uno::RuntimeException ); + virtual sal_Bool SAL_CALL supportsService ( const ::rtl::OUString& sServiceName ) throw( css::uno::RuntimeException ); + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames ( ) throw( css::uno::RuntimeException ); + /* Helper for XServiceInfo */ + static css::uno::Sequence< ::rtl::OUString > SAL_CALL impl_getStaticSupportedServiceNames( ); + static ::rtl::OUString SAL_CALL impl_getStaticImplementationName ( ); + /* Helper for registry */ + static css::uno::Reference< css::uno::XInterface > SAL_CALL impl_createInstance ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ) throw( css::uno::Exception ); + static css::uno::Reference< css::lang::XSingleServiceFactory > SAL_CALL impl_createFactory ( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager ); + /* Helper for initialization of service by using own reference! */ + virtual void SAL_CALL impl_initService ( ); + + //--------------------------------------------------------------------------------------------------------- + // XNotifyingDispatch + //--------------------------------------------------------------------------------------------------------- + virtual void SAL_CALL dispatchWithNotification(const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lArguments, + const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) throw(css::uno::RuntimeException); + + //--------------------------------------------------------------------------------------------------------- + // XDispatch + //--------------------------------------------------------------------------------------------------------- + virtual void SAL_CALL dispatch ( const css::util::URL& aURL , + const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) throw( css::uno::RuntimeException ); + // not supported ! + virtual void SAL_CALL addStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ , + const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException ) {}; + virtual void SAL_CALL removeStatusListener ( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ , + const css::util::URL& /*aURL*/ ) throw( css::uno::RuntimeException ) {}; + + //--------------------------------------------------------------------------------------------------------- + // XExtendedFilterDetection + //--------------------------------------------------------------------------------------------------------- + virtual ::rtl::OUString SAL_CALL detect ( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor ) throw( css::uno::RuntimeException ); + + //------------------------------------------------------------------------------------------------------------- + // protected methods + //------------------------------------------------------------------------------------------------------------- + protected: + + //------------------------------------------------------------------------------------------------------------- + // private methods + //------------------------------------------------------------------------------------------------------------- + private: + DECL_LINK( implts_PlayerNotify, void* ); + + //------------------------------------------------------------------------------------------------------------- + // variables + // (should be private everyway!) + //------------------------------------------------------------------------------------------------------------- + private: + + bool m_bError; + css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory ; /// global uno service factory to create new services + css::uno::Reference< css::uno::XInterface > m_xSelfHold ; /// we must protect us against dieing during async(!) dispatch() call! + css::uno::Reference< css::media::XPlayer > m_xPlayer ; /// uses avmedia player to play sounds ... + + css::uno::Reference< css::frame::XDispatchResultListener > m_xListener ; + Timer m_aUpdateTimer; + +}; // class SoundHandler + +} // namespace avmedia + +#endif // #ifndef __FRAMEWORK_HANDLER_SOUNDHANDLER_HXX_ diff --git a/avmedia/source/framework/soundhandler.xml b/avmedia/source/framework/soundhandler.xml new file mode 100644 index 000000000000..fceeffbde0e3 --- /dev/null +++ b/avmedia/source/framework/soundhandler.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd"> + +<module-description xmlns:xlink="http://www.w3.org/1999/xlink"> + + <module-name> avmedia </module-name> + + <component-description> + <author> Andreas Schluens </author> + <name> com.sun.star.comp.framework.SoundHandler </name> + <description> + Implements a handler service to detect and/or play audio files. + supported formats: wav/au + </description> + <loader-name> com.sun.star.loader.SharedLibrary </loader-name> + <language> c++ </language> + <status value="final"/> + <supported-service> com.sun.star.frame.ContentHandler </supported-service> + </component-description> + + <project-build-dependency> cppu </project-build-dependency> + <project-build-dependency> cppuhelper </project-build-dependency> + <project-build-dependency> vos </project-build-dependency> + <project-build-dependency> sal </project-build-dependency> + <project-build-dependency> tools </project-build-dependency> + <project-build-dependency> svtools </project-build-dependency> + <project-build-dependency> toolkit </project-build-dependency> + <project-build-dependency> sv </project-build-dependency> + <project-build-dependency> comphelper </project-build-dependency> + <project-build-dependency> unotools </project-build-dependency> + <project-build-dependency> ucbhelper </project-build-dependency> + <project-build-dependency> svl </project-build-dependency> + <project-build-dependency> sot </project-build-dependency> + + <runtime-module-dependency> cppu2 </runtime-module-dependency> + <runtime-module-dependency> cppuhelper </runtime-module-dependency> + <runtime-module-dependency> vos2$(COM) </runtime-module-dependency> + <runtime-module-dependency> sal2 </runtime-module-dependency> + <runtime-module-dependency> tl </runtime-module-dependency> + <runtime-module-dependency> svt </runtime-module-dependency> + <runtime-module-dependency> svl </runtime-module-dependency> + <runtime-module-dependency> tk </runtime-module-dependency> + <runtime-module-dependency> sv </runtime-module-dependency> + <runtime-module-dependency> comphelp2 </runtime-module-dependency> + <runtime-module-dependency> utl </runtime-module-dependency> + <runtime-module-dependency> ucb </runtime-module-dependency> + <runtime-module-dependency> sot </runtime-module-dependency> + +</module-description> |