1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 #include <svx/sdr/contact/objectcontactofpageview.hxx> 28 #include <svx/sdr/contact/viewobjectcontactofsdrmediaobj.hxx> 29 #include <svx/sdr/contact/viewcontactofsdrmediaobj.hxx> 30 #include <svx/sdr/contact/displayinfo.hxx> 31 #include <svx/svdomedia.hxx> 32 #include <svx/svdpagv.hxx> 33 #include <vcl/outdev.hxx> 34 #include <vcl/window.hxx> 35 #include <avmedia/mediaitem.hxx> 36 #include "sdrmediawindow.hxx" 37 #include <svx/sdrpagewindow.hxx> 38 #include <svx/sdrpaintwindow.hxx> 39 40 ////////////////////////////////////////////////////////////////////////////// 41 42 namespace sdr { namespace contact { 43 44 // ---------------------------------- 45 // - ViewObjectContactOfSdrMediaObj - 46 // ---------------------------------- 47 48 ViewObjectContactOfSdrMediaObj::ViewObjectContactOfSdrMediaObj( ObjectContact& rObjectContact, 49 ViewContact& rViewContact, 50 const ::avmedia::MediaItem& rMediaItem ) : 51 ViewObjectContactOfSdrObj( rObjectContact, rViewContact ), 52 mpMediaWindow( NULL ) 53 { 54 Window* pWindow = getWindow(); 55 56 if( pWindow ) 57 { 58 mpMediaWindow = new SdrMediaWindow( pWindow, *this ); 59 mpMediaWindow->hide(); 60 executeMediaItem( rMediaItem ); 61 } 62 } 63 64 // ------------------------------------------------------------------------------ 65 66 ViewObjectContactOfSdrMediaObj::~ViewObjectContactOfSdrMediaObj() 67 { 68 delete mpMediaWindow; 69 mpMediaWindow = NULL; 70 } 71 72 // ------------------------------------------------------------------------------ 73 74 Window* ViewObjectContactOfSdrMediaObj::getWindow() const 75 { 76 Window* pRetval = 0; 77 78 const ObjectContactOfPageView* pObjectContactOfPageView = dynamic_cast< const ObjectContactOfPageView* >(&GetObjectContact()); 79 80 if(pObjectContactOfPageView) 81 { 82 const SdrPageWindow& rPageWindow = pObjectContactOfPageView->GetPageWindow(); 83 const SdrPaintWindow* pPaintWindow = &rPageWindow.GetPaintWindow(); 84 85 if(rPageWindow.GetOriginalPaintWindow()) 86 { 87 // #i83183# prefer OriginalPaintWindow if set; this is 88 // the real target device. GetPaintWindow() may return 89 // the current buffer device instead 90 pPaintWindow = rPageWindow.GetOriginalPaintWindow(); 91 } 92 93 OutputDevice& rOutDev = pPaintWindow->GetOutputDevice(); 94 95 if(OUTDEV_WINDOW == rOutDev.GetOutDevType()) 96 { 97 pRetval = static_cast< Window* >(&rOutDev); 98 } 99 } 100 101 return pRetval; 102 } 103 104 // ------------------------------------------------------------------------------ 105 106 bool ViewObjectContactOfSdrMediaObj::hasPreferredSize() const 107 { 108 return( mpMediaWindow != NULL && mpMediaWindow->hasPreferredSize() ); 109 } 110 111 // ------------------------------------------------------------------------------ 112 113 Size ViewObjectContactOfSdrMediaObj::getPreferredSize() const 114 { 115 Size aRet; 116 117 if( mpMediaWindow ) 118 aRet = mpMediaWindow->getPreferredSize(); 119 120 return aRet; 121 } 122 123 // ------------------------------------------------------------------------------ 124 125 void ViewObjectContactOfSdrMediaObj::updateMediaItem( ::avmedia::MediaItem& rItem ) const 126 { 127 if( mpMediaWindow ) 128 { 129 mpMediaWindow->updateMediaItem( rItem ); 130 131 // show/hide is now dependent of play state 132 if(avmedia::MEDIASTATE_STOP == rItem.getState()) 133 { 134 mpMediaWindow->hide(); 135 } 136 else 137 { 138 basegfx::B2DRange aViewRange(getObjectRange()); 139 aViewRange.transform(GetObjectContact().getViewInformation2D().getViewTransformation()); 140 141 const Rectangle aViewRectangle( 142 (sal_Int32)floor(aViewRange.getMinX()), (sal_Int32)floor(aViewRange.getMinY()), 143 (sal_Int32)ceil(aViewRange.getMaxX()), (sal_Int32)ceil(aViewRange.getMaxY())); 144 145 mpMediaWindow->setPosSize(aViewRectangle); 146 mpMediaWindow->show(); 147 } 148 } 149 } 150 151 // ------------------------------------------------------------------------------ 152 153 void ViewObjectContactOfSdrMediaObj::executeMediaItem( const ::avmedia::MediaItem& rItem ) 154 { 155 if( mpMediaWindow ) 156 { 157 ::avmedia::MediaItem aUpdatedItem; 158 159 mpMediaWindow->executeMediaItem( rItem ); 160 161 // query new properties after trying to set the new properties 162 updateMediaItem( aUpdatedItem ); 163 static_cast< ViewContactOfSdrMediaObj& >( GetViewContact() ).mediaPropertiesChanged( aUpdatedItem ); 164 } 165 } 166 167 // ------------------------------------------------------------------------------ 168 169 }} // end of namespace sdr::contact 170 171 ////////////////////////////////////////////////////////////////////////////// 172 // eof 173