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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 31 #include <svx/sdr/contact/objectcontactofpageview.hxx> 32 #include <svx/sdr/contact/viewobjectcontactofsdrmediaobj.hxx> 33 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx> 34 #include <svx/sdr/contact/displayinfo.hxx> 35 #include <svx/svdomedia.hxx> 36 #include <svx/svdpagv.hxx> 37 #include <vcl/outdev.hxx> 38 #include <vcl/window.hxx> 39 #include <avmedia/mediaitem.hxx> 40 #include "sdrmediawindow.hxx" 41 #include <svx/sdrpagewindow.hxx> 42 #include <svx/sdrpaintwindow.hxx> 43 44 ////////////////////////////////////////////////////////////////////////////// 45 46 namespace sdr { namespace contact { 47 48 // ---------------------------------- 49 // - ViewObjectContactOfSdrMediaObj - 50 // ---------------------------------- 51 52 ViewObjectContactOfSdrMediaObj::ViewObjectContactOfSdrMediaObj( ObjectContact& rObjectContact, 53 ViewContact& rViewContact, 54 const ::avmedia::MediaItem& rMediaItem ) : 55 ViewObjectContactOfSdrObj( rObjectContact, rViewContact ), 56 mpMediaWindow( NULL ) 57 { 58 Window* pWindow = getWindow(); 59 60 if( pWindow ) 61 { 62 mpMediaWindow = new SdrMediaWindow( pWindow, *this ); 63 mpMediaWindow->hide(); 64 executeMediaItem( rMediaItem ); 65 } 66 } 67 68 // ------------------------------------------------------------------------------ 69 70 ViewObjectContactOfSdrMediaObj::~ViewObjectContactOfSdrMediaObj() 71 { 72 delete mpMediaWindow; 73 mpMediaWindow = NULL; 74 } 75 76 // ------------------------------------------------------------------------------ 77 78 Window* ViewObjectContactOfSdrMediaObj::getWindow() const 79 { 80 Window* pRetval = 0; 81 82 const ObjectContactOfPageView* pObjectContactOfPageView = dynamic_cast< const ObjectContactOfPageView* >(&GetObjectContact()); 83 84 if(pObjectContactOfPageView) 85 { 86 const SdrPageWindow& rPageWindow = pObjectContactOfPageView->GetPageWindow(); 87 const SdrPaintWindow* pPaintWindow = &rPageWindow.GetPaintWindow(); 88 89 if(rPageWindow.GetOriginalPaintWindow()) 90 { 91 // #i83183# prefer OriginalPaintWindow if set; this is 92 // the real target device. GetPaintWindow() may return 93 // the current buffer device instead 94 pPaintWindow = rPageWindow.GetOriginalPaintWindow(); 95 } 96 97 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice(); 98 99 if(OUTDEV_WINDOW == rOutDev.GetOutDevType()) 100 { 101 pRetval = static_cast< Window* >(&rOutDev); 102 } 103 } 104 105 return pRetval; 106 } 107 108 // ------------------------------------------------------------------------------ 109 110 bool ViewObjectContactOfSdrMediaObj::hasPreferredSize() const 111 { 112 return( mpMediaWindow != NULL && mpMediaWindow->hasPreferredSize() ); 113 } 114 115 // ------------------------------------------------------------------------------ 116 117 Size ViewObjectContactOfSdrMediaObj::getPreferredSize() const 118 { 119 Size aRet; 120 121 if( mpMediaWindow ) 122 aRet = mpMediaWindow->getPreferredSize(); 123 124 return aRet; 125 } 126 127 // ------------------------------------------------------------------------------ 128 129 void ViewObjectContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rItem ) const 130 { 131 if( mpMediaWindow ) 132 { 133 mpMediaWindow->updateMediaItem( rItem ); 134 135 // show/hide is now dependent of play state 136 if(avmedia::MEDIASTATE_STOP == rItem.getState()) 137 { 138 mpMediaWindow->hide(); 139 } 140 else 141 { 142 basegfx::B2DRange aViewRange(getObjectRange()); 143 aViewRange.transform(GetObjectContact().getViewInformation2D().getViewTransformation()); 144 145 const Rectangle aViewRectangle( 146 (sal_Int32)floor(aViewRange.getMinX()), (sal_Int32)floor(aViewRange.getMinY()), 147 (sal_Int32)ceil(aViewRange.getMaxX()), (sal_Int32)ceil(aViewRange.getMaxY())); 148 149 mpMediaWindow->setPosSize(aViewRectangle); 150 mpMediaWindow->show(); 151 } 152 } 153 } 154 155 // ------------------------------------------------------------------------------ 156 157 void ViewObjectContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem ) 158 { 159 if( mpMediaWindow ) 160 { 161 ::avmedia::MediaItem aUpdatedItem; 162 163 mpMediaWindow->executeMediaItem( rItem ); 164 165 // query new properties after trying to set the new properties 166 updateMediaItem( aUpdatedItem ); 167 static_cast< ViewContactOfSdrMediaObj& >( GetViewContact() ).mediaPropertiesChanged( aUpdatedItem ); 168 } 169 } 170 171 // ------------------------------------------------------------------------------ 172 173 }} // end of namespace sdr::contact 174 175 ////////////////////////////////////////////////////////////////////////////// 176 // eof 177