1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <avmedia/mediaplayer.hxx> 29 #include <avmedia/mediawindow.hxx> 30 #include <avmedia/mediaitem.hxx> 31 #include "mediamisc.hxx" 32 #include "mediacontrol.hrc" 33 #include "helpids.hrc" 34 35 #include <svl/stritem.hxx> 36 #include <sfx2/app.hxx> 37 #include <sfx2/sfxsids.hrc> 38 #include <sfx2/bindings.hxx> 39 #include <sfx2/dispatch.hxx> 40 41 namespace avmedia 42 { 43 44 // --------------- 45 // - MediaPlayer - 46 // --------------- 47 48 MediaPlayer::MediaPlayer( Window* _pParent, sal_uInt16 nId, SfxBindings* _pBindings, SfxChildWinInfo* pInfo ) : 49 SfxChildWindow( _pParent, nId ) 50 { 51 pWindow = new MediaFloater( _pBindings, this, _pParent ); 52 eChildAlignment = SFX_ALIGN_NOALIGNMENT; 53 static_cast< MediaFloater* >( pWindow )->Initialize( pInfo ); 54 }; 55 56 // ----------------------------------------------------------------------------- 57 58 MediaPlayer::~MediaPlayer() 59 { 60 } 61 62 // ----------------------------------------------------------------------------- 63 64 SFX_IMPL_DOCKINGWINDOW( MediaPlayer, SID_AVMEDIA_PLAYER ) 65 66 // ---------------- 67 // - MediaFloater - 68 // ---------------- 69 70 MediaFloater::MediaFloater( SfxBindings* _pBindings, SfxChildWindow* pCW, Window* pParent ) : 71 SfxDockingWindow( _pBindings, pCW, pParent, WB_CLOSEABLE | WB_MOVEABLE | WB_SIZEABLE | WB_DOCKABLE ), 72 mpMediaWindow( new MediaWindow( this, true ) ) 73 { 74 const Size aSize( 378, 256 ); 75 76 SetPosSizePixel( Point( 0, 0 ), aSize ); 77 SetMinOutputSizePixel( aSize ); 78 SetText( String( AVMEDIA_RESID( AVMEDIA_STR_MEDIAPLAYER ) ) ); 79 implInit(); 80 mpMediaWindow->show(); 81 } 82 83 // ----------------------------------------------------------------------------- 84 85 MediaFloater::~MediaFloater() 86 { 87 delete mpMediaWindow; 88 mpMediaWindow = NULL; 89 } 90 91 // ----------------------------------------------------------------------------- 92 93 void MediaFloater::implInit() 94 { 95 } 96 97 // ------------------------------------------------------------------------- 98 99 void MediaFloater::Resize() 100 { 101 SfxDockingWindow::Resize(); 102 103 if( mpMediaWindow ) 104 mpMediaWindow->setPosSize( Rectangle( Point(), GetOutputSizePixel() ) ); 105 } 106 107 // ----------------------------------------------------------------------------- 108 109 void MediaFloater::ToggleFloatingMode() 110 { 111 ::avmedia::MediaItem aRestoreItem; 112 113 mpMediaWindow->updateMediaItem( aRestoreItem ); 114 delete mpMediaWindow; 115 mpMediaWindow = NULL; 116 117 SfxDockingWindow::ToggleFloatingMode(); 118 119 mpMediaWindow = new MediaWindow( this, true ); 120 121 mpMediaWindow->setPosSize( Rectangle( Point(), GetOutputSizePixel() ) ); 122 mpMediaWindow->executeMediaItem( aRestoreItem ); 123 124 Window* pWindow = mpMediaWindow->getWindow(); 125 126 if( pWindow ) 127 pWindow->SetHelpId( HID_AVMEDIA_PLAYERWINDOW ); 128 129 mpMediaWindow->show(); 130 } 131 132 // ----------------------------------------------------------------------------- 133 134 void MediaFloater::setURL( const ::rtl::OUString& rURL, bool bPlayImmediately ) 135 { 136 if( mpMediaWindow ) 137 { 138 mpMediaWindow->setURL( rURL ); 139 140 if( mpMediaWindow->isValid() && bPlayImmediately ) 141 mpMediaWindow->start(); 142 } 143 } 144 145 // ----------------------------------------------------------------------------- 146 147 const ::rtl::OUString& MediaFloater::getURL() const 148 { 149 static const ::rtl::OUString aEmptyStr; 150 return( mpMediaWindow ? mpMediaWindow->getURL() : aEmptyStr ); 151 } 152 153 // ----------------------------------------------------------------------------- 154 155 void MediaFloater::dispatchCurrentURL() 156 { 157 SfxDispatcher* pDispatcher = GetBindings().GetDispatcher(); 158 159 if( pDispatcher ) 160 { 161 const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, getURL() ); 162 pDispatcher->Execute( SID_INSERT_AVMEDIA, SFX_CALLMODE_RECORD, &aMediaURLItem, 0L ); 163 } 164 } 165 166 } 167