1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofunocontrol.hxx> 27cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactofunocontrol.hxx> 28cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 29cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 30cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 31cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 32cdf0e10cSrcweir #include <com/sun/star/io/XPersistObject.hpp> 33cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 34cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 35cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 36cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp> 37cdf0e10cSrcweir #include <com/sun/star/io/XObjectOutputStream.hpp> 38cdf0e10cSrcweir #include <com/sun/star/io/XObjectInputStream.hpp> 39cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp> 40cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 41cdf0e10cSrcweir #include <comphelper/types.hxx> 42cdf0e10cSrcweir #include <vcl/pdfextoutdevdata.hxx> 43cdf0e10cSrcweir #include <svx/svdouno.hxx> 44cdf0e10cSrcweir #include <svx/svdpagv.hxx> 45cdf0e10cSrcweir #include <svx/svdmodel.hxx> 46cdf0e10cSrcweir #include "svx/svdglob.hxx" // Stringcache 47cdf0e10cSrcweir #include "svx/svdstr.hrc" // Objektname 48cdf0e10cSrcweir #include <svx/svdetc.hxx> 49cdf0e10cSrcweir #include <svx/svdview.hxx> 50cdf0e10cSrcweir #include <svx/svdorect.hxx> 51cdf0e10cSrcweir #include "svx/svdviter.hxx" 52cdf0e10cSrcweir #include <rtl/ref.hxx> 53cdf0e10cSrcweir #include <set> 54cdf0e10cSrcweir #include <memory> 55cdf0e10cSrcweir #include <svx/sdrpagewindow.hxx> 56cdf0e10cSrcweir #include <svx/sdrpaintwindow.hxx> 57cdf0e10cSrcweir #include <tools/diagnose_ex.h> 58cdf0e10cSrcweir #include <svx/svdograf.hxx> 59cdf0e10cSrcweir 60cdf0e10cSrcweir using namespace ::com::sun::star; 61cdf0e10cSrcweir using namespace ::sdr::contact; 62cdf0e10cSrcweir 63cdf0e10cSrcweir //************************************************************ 64cdf0e10cSrcweir // Defines 65cdf0e10cSrcweir //************************************************************ 66cdf0e10cSrcweir 67cdf0e10cSrcweir //************************************************************ 68cdf0e10cSrcweir // Hilfsklasse SdrControlEventListenerImpl 69cdf0e10cSrcweir //************************************************************ 70cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 71cdf0e10cSrcweir 72cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 73cdf0e10cSrcweir 74cdf0e10cSrcweir // ============================================================================= 75cdf0e10cSrcweir class SdrControlEventListenerImpl : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener > 76cdf0e10cSrcweir { 77cdf0e10cSrcweir protected: 78cdf0e10cSrcweir SdrUnoObj* pObj; 79cdf0e10cSrcweir 80cdf0e10cSrcweir public: 81cdf0e10cSrcweir SdrControlEventListenerImpl(SdrUnoObj* _pObj) 82cdf0e10cSrcweir : pObj(_pObj) 83cdf0e10cSrcweir {} 84cdf0e10cSrcweir 85cdf0e10cSrcweir // XEventListener 86cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException); 87cdf0e10cSrcweir 88cdf0e10cSrcweir void StopListening(const uno::Reference< lang::XComponent >& xComp); 89cdf0e10cSrcweir void StartListening(const uno::Reference< lang::XComponent >& xComp); 90cdf0e10cSrcweir }; 91cdf0e10cSrcweir 92cdf0e10cSrcweir // XEventListener 93cdf0e10cSrcweir void SAL_CALL SdrControlEventListenerImpl::disposing( const ::com::sun::star::lang::EventObject& /*Source*/) 94cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir if (pObj) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir pObj->xUnoControlModel = NULL; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir void SdrControlEventListenerImpl::StopListening(const uno::Reference< lang::XComponent >& xComp) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir if (xComp.is()) 105cdf0e10cSrcweir xComp->removeEventListener(this); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir void SdrControlEventListenerImpl::StartListening(const uno::Reference< lang::XComponent >& xComp) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir if (xComp.is()) 111cdf0e10cSrcweir xComp->addEventListener(this); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir // ============================================================================= 115cdf0e10cSrcweir struct SAL_DLLPRIVATE SdrUnoObjDataHolder 116cdf0e10cSrcweir { 117cdf0e10cSrcweir mutable ::rtl::Reference< SdrControlEventListenerImpl > 118cdf0e10cSrcweir pEventListener; 119cdf0e10cSrcweir }; 120cdf0e10cSrcweir 121cdf0e10cSrcweir // ============================================================================= 122cdf0e10cSrcweir namespace 123cdf0e10cSrcweir { 124cdf0e10cSrcweir void lcl_ensureControlVisibility( SdrView* _pView, const SdrUnoObj* _pObject, bool _bVisible ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir OSL_PRECOND( _pObject, "lcl_ensureControlVisibility: no object -> no survival!" ); 127cdf0e10cSrcweir 128cdf0e10cSrcweir SdrPageView* pPageView = _pView ? _pView->GetSdrPageView() : NULL; 129cdf0e10cSrcweir DBG_ASSERT( pPageView, "lcl_ensureControlVisibility: no view found!" ); 130cdf0e10cSrcweir if ( !pPageView ) 131cdf0e10cSrcweir return; 132cdf0e10cSrcweir 133cdf0e10cSrcweir ViewContact& rUnoControlContact( _pObject->GetViewContact() ); 134cdf0e10cSrcweir 135cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < pPageView->PageWindowCount(); ++i ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir const SdrPageWindow* pPageWindow = pPageView->GetPageWindow( i ); 138cdf0e10cSrcweir DBG_ASSERT( pPageWindow, "lcl_ensureControlVisibility: invalid PageViewWindow!" ); 139cdf0e10cSrcweir if ( !pPageWindow ) 140cdf0e10cSrcweir continue; 141cdf0e10cSrcweir 142cdf0e10cSrcweir if ( !pPageWindow->HasObjectContact() ) 143cdf0e10cSrcweir continue; 144cdf0e10cSrcweir 145cdf0e10cSrcweir ObjectContact& rPageViewContact( pPageWindow->GetObjectContact() ); 146cdf0e10cSrcweir const ViewObjectContact& rViewObjectContact( rUnoControlContact.GetViewObjectContact( rPageViewContact ) ); 147cdf0e10cSrcweir const ViewObjectContactOfUnoControl* pUnoControlContact = dynamic_cast< const ViewObjectContactOfUnoControl* >( &rViewObjectContact ); 148cdf0e10cSrcweir DBG_ASSERT( pUnoControlContact, "lcl_ensureControlVisibility: wrong ViewObjectContact type!" ); 149cdf0e10cSrcweir if ( !pUnoControlContact ) 150cdf0e10cSrcweir continue; 151cdf0e10cSrcweir 152cdf0e10cSrcweir pUnoControlContact->ensureControlVisibility( _bVisible ); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir } 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir //************************************************************ 158cdf0e10cSrcweir // SdrUnoObj 159cdf0e10cSrcweir //************************************************************ 160cdf0e10cSrcweir 161cdf0e10cSrcweir TYPEINIT1(SdrUnoObj, SdrRectObj); 162cdf0e10cSrcweir 163cdf0e10cSrcweir SdrUnoObj::SdrUnoObj(const String& rModelName, sal_Bool _bOwnUnoControlModel) 164cdf0e10cSrcweir : m_pImpl( new SdrUnoObjDataHolder ), 165cdf0e10cSrcweir bOwnUnoControlModel( _bOwnUnoControlModel ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir bIsUnoObj = sal_True; 168cdf0e10cSrcweir 169cdf0e10cSrcweir m_pImpl->pEventListener = new SdrControlEventListenerImpl(this); 170cdf0e10cSrcweir 171cdf0e10cSrcweir // nur ein owner darf eigenstaendig erzeugen 172cdf0e10cSrcweir if (rModelName.Len()) 173cdf0e10cSrcweir CreateUnoControlModel(rModelName); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir SdrUnoObj::SdrUnoObj(const String& rModelName, 177cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSFac, 178cdf0e10cSrcweir sal_Bool _bOwnUnoControlModel) 179cdf0e10cSrcweir : m_pImpl( new SdrUnoObjDataHolder ), 180cdf0e10cSrcweir bOwnUnoControlModel( _bOwnUnoControlModel ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir bIsUnoObj = sal_True; 183cdf0e10cSrcweir 184cdf0e10cSrcweir m_pImpl->pEventListener = new SdrControlEventListenerImpl(this); 185cdf0e10cSrcweir 186cdf0e10cSrcweir // nur ein owner darf eigenstaendig erzeugen 187cdf0e10cSrcweir if (rModelName.Len()) 188cdf0e10cSrcweir CreateUnoControlModel(rModelName,rxSFac); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir SdrUnoObj::~SdrUnoObj() 192cdf0e10cSrcweir { 193cdf0e10cSrcweir try 194cdf0e10cSrcweir { 195cdf0e10cSrcweir // clean up the control model 196cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY); 197cdf0e10cSrcweir if (xComp.is()) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir // is the control model owned by it's environment? 200cdf0e10cSrcweir uno::Reference< container::XChild > xContent(xUnoControlModel, uno::UNO_QUERY); 201cdf0e10cSrcweir if (xContent.is() && !xContent->getParent().is()) 202cdf0e10cSrcweir xComp->dispose(); 203cdf0e10cSrcweir else 204cdf0e10cSrcweir m_pImpl->pEventListener->StopListening(xComp); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir } 207cdf0e10cSrcweir catch( const uno::Exception& ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir OSL_ENSURE( sal_False, "SdrUnoObj::~SdrUnoObj: caught an exception!" ); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir delete m_pImpl; 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir void SdrUnoObj::SetModel(SdrModel* pNewModel) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir SdrRectObj::SetModel(pNewModel); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir void SdrUnoObj::SetPage(SdrPage* pNewPage) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir SdrRectObj::SetPage(pNewPage); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir void SdrUnoObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const 225cdf0e10cSrcweir { 226cdf0e10cSrcweir rInfo.bRotateFreeAllowed = sal_False; 227cdf0e10cSrcweir rInfo.bRotate90Allowed = sal_False; 228cdf0e10cSrcweir rInfo.bMirrorFreeAllowed = sal_False; 229cdf0e10cSrcweir rInfo.bMirror45Allowed = sal_False; 230cdf0e10cSrcweir rInfo.bMirror90Allowed = sal_False; 231cdf0e10cSrcweir rInfo.bTransparenceAllowed = sal_False; 232cdf0e10cSrcweir rInfo.bGradientAllowed = sal_False; 233cdf0e10cSrcweir rInfo.bShearAllowed = sal_False; 234cdf0e10cSrcweir rInfo.bEdgeRadiusAllowed = sal_False; 235cdf0e10cSrcweir rInfo.bNoOrthoDesired = sal_False; 236cdf0e10cSrcweir rInfo.bCanConvToPath = sal_False; 237cdf0e10cSrcweir rInfo.bCanConvToPoly = sal_False; 238cdf0e10cSrcweir rInfo.bCanConvToPathLineToArea = sal_False; 239cdf0e10cSrcweir rInfo.bCanConvToPolyLineToArea = sal_False; 240cdf0e10cSrcweir rInfo.bCanConvToContour = sal_False; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir sal_uInt16 SdrUnoObj::GetObjIdentifier() const 244cdf0e10cSrcweir { 245cdf0e10cSrcweir return sal_uInt16(OBJ_UNO); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir void SdrUnoObj::SetContextWritingMode( const sal_Int16 _nContextWritingMode ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir try 251cdf0e10cSrcweir { 252cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xModelProperties( GetUnoControlModel(), uno::UNO_QUERY_THROW ); 253cdf0e10cSrcweir xModelProperties->setPropertyValue( 254cdf0e10cSrcweir ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "ContextWritingMode" ) ), 255cdf0e10cSrcweir uno::makeAny( _nContextWritingMode ) 256cdf0e10cSrcweir ); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir catch( const uno::Exception& ) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 261cdf0e10cSrcweir } 262cdf0e10cSrcweir } 263cdf0e10cSrcweir 264cdf0e10cSrcweir // ---------------------------------------------------------------------------- 265cdf0e10cSrcweir namespace 266cdf0e10cSrcweir { 267cdf0e10cSrcweir /** helper class to restore graphics at <awt::XView> object after <SdrUnoObj::Paint> 268cdf0e10cSrcweir 269cdf0e10cSrcweir OD 08.05.2003 #109432# 270cdf0e10cSrcweir Restoration of graphics necessary to assure that paint on a window 271cdf0e10cSrcweir 272cdf0e10cSrcweir @author OD 273cdf0e10cSrcweir */ 274cdf0e10cSrcweir class RestoreXViewGraphics 275cdf0e10cSrcweir { 276cdf0e10cSrcweir private: 277cdf0e10cSrcweir uno::Reference< awt::XView > m_rXView; 278cdf0e10cSrcweir uno::Reference< awt::XGraphics > m_rXGraphics; 279cdf0e10cSrcweir 280cdf0e10cSrcweir public: 281cdf0e10cSrcweir RestoreXViewGraphics( const uno::Reference< awt::XView >& _rXView ) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir m_rXView = _rXView; 284cdf0e10cSrcweir m_rXGraphics = m_rXView->getGraphics(); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir ~RestoreXViewGraphics() 287cdf0e10cSrcweir { 288cdf0e10cSrcweir m_rXView->setGraphics( m_rXGraphics ); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir }; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir void SdrUnoObj::TakeObjNameSingul(XubString& rName) const 294cdf0e10cSrcweir { 295cdf0e10cSrcweir rName = ImpGetResStr(STR_ObjNameSingulUno); 296cdf0e10cSrcweir 297cdf0e10cSrcweir String aName( GetName() ); 298cdf0e10cSrcweir if(aName.Len()) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir rName += sal_Unicode(' '); 301cdf0e10cSrcweir rName += sal_Unicode('\''); 302cdf0e10cSrcweir rName += aName; 303cdf0e10cSrcweir rName += sal_Unicode('\''); 304cdf0e10cSrcweir } 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir void SdrUnoObj::TakeObjNamePlural(XubString& rName) const 308cdf0e10cSrcweir { 309cdf0e10cSrcweir rName = ImpGetResStr(STR_ObjNamePluralUno); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir void SdrUnoObj::operator = (const SdrObject& rObj) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir SdrRectObj::operator = (rObj); 315cdf0e10cSrcweir 316cdf0e10cSrcweir // release the reference to the current control model 317cdf0e10cSrcweir SetUnoControlModel( NULL ); 318cdf0e10cSrcweir 319cdf0e10cSrcweir const SdrUnoObj& rUnoObj = dynamic_cast< const SdrUnoObj& >( rObj ); 320cdf0e10cSrcweir 321cdf0e10cSrcweir aUnoControlModelTypeName = rUnoObj.aUnoControlModelTypeName; 322cdf0e10cSrcweir aUnoControlTypeName = rUnoObj.aUnoControlTypeName; 323cdf0e10cSrcweir 324cdf0e10cSrcweir // copy the uno control model 325cdf0e10cSrcweir const uno::Reference< awt::XControlModel > xSourceControlModel( rUnoObj.GetUnoControlModel(), uno::UNO_QUERY ); 326cdf0e10cSrcweir if ( xSourceControlModel.is() ) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir try 329cdf0e10cSrcweir { 330cdf0e10cSrcweir uno::Reference< util::XCloneable > xClone( xSourceControlModel, uno::UNO_QUERY_THROW ); 331cdf0e10cSrcweir xUnoControlModel.set( xClone->createClone(), uno::UNO_QUERY_THROW ); 332cdf0e10cSrcweir } 333cdf0e10cSrcweir catch( const uno::Exception& ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 336cdf0e10cSrcweir } 337cdf0e10cSrcweir } 338cdf0e10cSrcweir 339cdf0e10cSrcweir // get service name of the control from the control model 340cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xSet(xUnoControlModel, uno::UNO_QUERY); 341cdf0e10cSrcweir if (xSet.is()) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir uno::Any aValue( xSet->getPropertyValue( rtl::OUString::createFromAscii("DefaultControl")) ); 344cdf0e10cSrcweir ::rtl::OUString aStr; 345cdf0e10cSrcweir 346cdf0e10cSrcweir if( aValue >>= aStr ) 347cdf0e10cSrcweir aUnoControlTypeName = String(aStr); 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY); 351cdf0e10cSrcweir if (xComp.is()) 352cdf0e10cSrcweir m_pImpl->pEventListener->StartListening(xComp); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir void SdrUnoObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir SdrRectObj::NbcResize(rRef,xFact,yFact); 358cdf0e10cSrcweir 359cdf0e10cSrcweir if (aGeo.nShearWink!=0 || aGeo.nDrehWink!=0) 360cdf0e10cSrcweir { 361cdf0e10cSrcweir // kleine Korrekturen 362cdf0e10cSrcweir if (aGeo.nDrehWink>=9000 && aGeo.nDrehWink<27000) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir aRect.Move(aRect.Left()-aRect.Right(),aRect.Top()-aRect.Bottom()); 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir aGeo.nDrehWink = 0; 368cdf0e10cSrcweir aGeo.nShearWink = 0; 369cdf0e10cSrcweir aGeo.nSin = 0.0; 370cdf0e10cSrcweir aGeo.nCos = 1.0; 371cdf0e10cSrcweir aGeo.nTan = 0.0; 372cdf0e10cSrcweir SetRectsDirty(); 373cdf0e10cSrcweir } 374cdf0e10cSrcweir } 375cdf0e10cSrcweir 376cdf0e10cSrcweir // ----------------------------------------------------------------------------- 377cdf0e10cSrcweir 378cdf0e10cSrcweir bool SdrUnoObj::hasSpecialDrag() const 379cdf0e10cSrcweir { 380cdf0e10cSrcweir // no special drag; we have no rounding rect and 381cdf0e10cSrcweir // do want frame handles 382cdf0e10cSrcweir return false; 383cdf0e10cSrcweir } 384cdf0e10cSrcweir 385cdf0e10cSrcweir bool SdrUnoObj::supportsFullDrag() const 386cdf0e10cSrcweir { 387cdf0e10cSrcweir // overloaded to have the possibility to enable/disable in debug and 388cdf0e10cSrcweir // to ckeck some things out. Current solution is working, so default is 389cdf0e10cSrcweir // enabled 390cdf0e10cSrcweir static bool bDoSupportFullDrag(true); 391cdf0e10cSrcweir 392cdf0e10cSrcweir return bDoSupportFullDrag; 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir SdrObject* SdrUnoObj::getFullDragClone() const 396cdf0e10cSrcweir { 397cdf0e10cSrcweir SdrObject* pRetval = 0; 398cdf0e10cSrcweir static bool bHandleSpecial(false); 399cdf0e10cSrcweir 400cdf0e10cSrcweir if(bHandleSpecial) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir // special handling for SdrUnoObj (FormControl). Create a SdrGrafObj 403cdf0e10cSrcweir // for drag containing the graphical representation. This does not work too 404cdf0e10cSrcweir // well, so the default is to simply clone 405cdf0e10cSrcweir pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect()); 406cdf0e10cSrcweir } 407cdf0e10cSrcweir else 408cdf0e10cSrcweir { 409cdf0e10cSrcweir // call parent (simply clone) 410cdf0e10cSrcweir pRetval = SdrRectObj::getFullDragClone(); 411cdf0e10cSrcweir } 412cdf0e10cSrcweir 413cdf0e10cSrcweir return pRetval; 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir // ----------------------------------------------------------------------------- 417cdf0e10cSrcweir void SdrUnoObj::NbcSetLayer( SdrLayerID _nLayer ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir if ( GetLayer() == _nLayer ) 420cdf0e10cSrcweir { // redundant call -> not interested in doing anything here 421cdf0e10cSrcweir SdrRectObj::NbcSetLayer( _nLayer ); 422cdf0e10cSrcweir return; 423cdf0e10cSrcweir } 424cdf0e10cSrcweir 425cdf0e10cSrcweir // we need some special handling here in case we're moved from an invisible layer 426cdf0e10cSrcweir // to a visible one, or vice versa 427cdf0e10cSrcweir // (relative to a layer. Remember that the visibility of a layer is a view attribute 428cdf0e10cSrcweir // - the same layer can be visible in one view, and invisible in another view, at the 429cdf0e10cSrcweir // same time) 430cdf0e10cSrcweir // 2003-06-03 - #110592# - fs@openoffice.org 431cdf0e10cSrcweir 432cdf0e10cSrcweir // collect all views in which our old layer is visible 433cdf0e10cSrcweir ::std::set< SdrView* > aPreviouslyVisible; 434cdf0e10cSrcweir 435cdf0e10cSrcweir { 436cdf0e10cSrcweir SdrViewIter aIter( this ); 437cdf0e10cSrcweir for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() ) 438cdf0e10cSrcweir aPreviouslyVisible.insert( pView ); 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir SdrRectObj::NbcSetLayer( _nLayer ); 442cdf0e10cSrcweir 443cdf0e10cSrcweir // collect all views in which our new layer is visible 444cdf0e10cSrcweir ::std::set< SdrView* > aNewlyVisible; 445cdf0e10cSrcweir 446cdf0e10cSrcweir { 447cdf0e10cSrcweir SdrViewIter aIter( this ); 448cdf0e10cSrcweir for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() ) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir ::std::set< SdrView* >::const_iterator aPrevPos = aPreviouslyVisible.find( pView ); 451cdf0e10cSrcweir if ( aPreviouslyVisible.end() != aPrevPos ) 452cdf0e10cSrcweir { // in pView, we were visible _before_ the layer change, and are 453cdf0e10cSrcweir // visible _after_ the layer change, too 454cdf0e10cSrcweir // -> we're not interested in this view at all 455cdf0e10cSrcweir aPreviouslyVisible.erase( aPrevPos ); 456cdf0e10cSrcweir } 457cdf0e10cSrcweir else 458cdf0e10cSrcweir { 459cdf0e10cSrcweir // in pView, we were visible _before_ the layer change, and are 460cdf0e10cSrcweir // _not_ visible after the layer change 461cdf0e10cSrcweir // => remember this view, as our visibility there changed 462cdf0e10cSrcweir aNewlyVisible.insert( pView ); 463cdf0e10cSrcweir } 464cdf0e10cSrcweir } 465cdf0e10cSrcweir } 466cdf0e10cSrcweir 467cdf0e10cSrcweir // now aPreviouslyVisible contains all views where we became invisible 468cdf0e10cSrcweir ::std::set< SdrView* >::const_iterator aLoopViews; 469cdf0e10cSrcweir for ( aLoopViews = aPreviouslyVisible.begin(); 470cdf0e10cSrcweir aLoopViews != aPreviouslyVisible.end(); 471cdf0e10cSrcweir ++aLoopViews 472cdf0e10cSrcweir ) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir lcl_ensureControlVisibility( *aLoopViews, this, false ); 475cdf0e10cSrcweir } 476cdf0e10cSrcweir 477cdf0e10cSrcweir // and aNewlyVisible all views where we became visible 478cdf0e10cSrcweir for ( aLoopViews = aNewlyVisible.begin(); 479cdf0e10cSrcweir aLoopViews != aNewlyVisible.end(); 480cdf0e10cSrcweir ++aLoopViews 481cdf0e10cSrcweir ) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir lcl_ensureControlVisibility( *aLoopViews, this, true ); 484cdf0e10cSrcweir } 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir void SdrUnoObj::CreateUnoControlModel(const String& rModelName) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir DBG_ASSERT(!xUnoControlModel.is(), "model already exists"); 490cdf0e10cSrcweir 491cdf0e10cSrcweir aUnoControlModelTypeName = rModelName; 492cdf0e10cSrcweir 493cdf0e10cSrcweir uno::Reference< awt::XControlModel > xModel; 494cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); 495cdf0e10cSrcweir if (aUnoControlModelTypeName.Len() && xFactory.is() ) 496cdf0e10cSrcweir { 497cdf0e10cSrcweir xModel = uno::Reference< awt::XControlModel >(xFactory->createInstance( 498cdf0e10cSrcweir aUnoControlModelTypeName), uno::UNO_QUERY); 499cdf0e10cSrcweir 500cdf0e10cSrcweir if (xModel.is()) 501cdf0e10cSrcweir SetChanged(); 502cdf0e10cSrcweir } 503cdf0e10cSrcweir 504cdf0e10cSrcweir SetUnoControlModel(xModel); 505cdf0e10cSrcweir } 506cdf0e10cSrcweir 507cdf0e10cSrcweir void SdrUnoObj::CreateUnoControlModel(const String& rModelName, 508cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSFac) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir DBG_ASSERT(!xUnoControlModel.is(), "model already exists"); 511cdf0e10cSrcweir 512cdf0e10cSrcweir aUnoControlModelTypeName = rModelName; 513cdf0e10cSrcweir 514cdf0e10cSrcweir uno::Reference< awt::XControlModel > xModel; 515cdf0e10cSrcweir if (aUnoControlModelTypeName.Len() && rxSFac.is() ) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir xModel = uno::Reference< awt::XControlModel >(rxSFac->createInstance( 518cdf0e10cSrcweir aUnoControlModelTypeName), uno::UNO_QUERY); 519cdf0e10cSrcweir 520cdf0e10cSrcweir if (xModel.is()) 521cdf0e10cSrcweir SetChanged(); 522cdf0e10cSrcweir } 523cdf0e10cSrcweir 524cdf0e10cSrcweir SetUnoControlModel(xModel); 525cdf0e10cSrcweir } 526cdf0e10cSrcweir 527cdf0e10cSrcweir void SdrUnoObj::SetUnoControlModel( const uno::Reference< awt::XControlModel >& xModel) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir if (xUnoControlModel.is()) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY); 532cdf0e10cSrcweir if (xComp.is()) 533cdf0e10cSrcweir m_pImpl->pEventListener->StopListening(xComp); 534cdf0e10cSrcweir } 535cdf0e10cSrcweir 536cdf0e10cSrcweir xUnoControlModel = xModel; 537cdf0e10cSrcweir 538cdf0e10cSrcweir // control model muss servicename des controls enthalten 539cdf0e10cSrcweir if (xUnoControlModel.is()) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xSet(xUnoControlModel, uno::UNO_QUERY); 542cdf0e10cSrcweir if (xSet.is()) 543cdf0e10cSrcweir { 544cdf0e10cSrcweir uno::Any aValue( xSet->getPropertyValue(String("DefaultControl", gsl_getSystemTextEncoding())) ); 545cdf0e10cSrcweir ::rtl::OUString aStr; 546cdf0e10cSrcweir if( aValue >>= aStr ) 547cdf0e10cSrcweir aUnoControlTypeName = String(aStr); 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp(xUnoControlModel, uno::UNO_QUERY); 551cdf0e10cSrcweir if (xComp.is()) 552cdf0e10cSrcweir m_pImpl->pEventListener->StartListening(xComp); 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir // invalidate all ViewObject contacts 556cdf0e10cSrcweir ViewContactOfUnoControl* pVC = NULL; 557cdf0e10cSrcweir if ( impl_getViewContact( pVC ) ) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir // flushViewObjectContacts() removes all existing VOCs for the local DrawHierarchy. This 560cdf0e10cSrcweir // is always allowed since they will be re-created on demand (and with the changed model) 561cdf0e10cSrcweir GetViewContact().flushViewObjectContacts(true); 562cdf0e10cSrcweir } 563cdf0e10cSrcweir } 564cdf0e10cSrcweir 565cdf0e10cSrcweir //------------------------------------------------------------------------ 566cdf0e10cSrcweir uno::Reference< awt::XControl > SdrUnoObj::GetUnoControl(const SdrView& _rView, const OutputDevice& _rOut) const 567cdf0e10cSrcweir { 568cdf0e10cSrcweir uno::Reference< awt::XControl > xControl; 569cdf0e10cSrcweir 570cdf0e10cSrcweir SdrPageView* pPageView = _rView.GetSdrPageView(); 571cdf0e10cSrcweir OSL_ENSURE( GetPage() == pPageView->GetPage(), "SdrUnoObj::GetUnoControl: This object is not displayed in that particular view!" ); 572cdf0e10cSrcweir if ( GetPage() != pPageView->GetPage() ) 573cdf0e10cSrcweir return NULL; 574cdf0e10cSrcweir 575cdf0e10cSrcweir SdrPageWindow* pPageWindow = pPageView ? pPageView->FindPageWindow( _rOut ) : NULL; 576cdf0e10cSrcweir OSL_ENSURE( pPageWindow, "SdrUnoObj::GetUnoControl: did not find my SdrPageWindow!" ); 577cdf0e10cSrcweir if ( !pPageWindow ) 578cdf0e10cSrcweir return NULL; 579cdf0e10cSrcweir 580cdf0e10cSrcweir ViewObjectContact& rViewObjectContact( GetViewContact().GetViewObjectContact( pPageWindow->GetObjectContact() ) ); 581cdf0e10cSrcweir ViewObjectContactOfUnoControl* pUnoContact = dynamic_cast< ViewObjectContactOfUnoControl* >( &rViewObjectContact ); 582cdf0e10cSrcweir OSL_ENSURE( pUnoContact, "SdrUnoObj::GetUnoControl: wrong contact type!" ); 583cdf0e10cSrcweir if ( pUnoContact ) 584cdf0e10cSrcweir xControl = pUnoContact->getControl(); 585cdf0e10cSrcweir 586cdf0e10cSrcweir return xControl; 587cdf0e10cSrcweir } 588cdf0e10cSrcweir 589cdf0e10cSrcweir //------------------------------------------------------------------------ 590cdf0e10cSrcweir uno::Reference< awt::XControl > SdrUnoObj::GetTemporaryControlForWindow( 591cdf0e10cSrcweir const Window& _rWindow, uno::Reference< awt::XControlContainer >& _inout_ControlContainer ) const 592cdf0e10cSrcweir { 593cdf0e10cSrcweir uno::Reference< awt::XControl > xControl; 594cdf0e10cSrcweir 595cdf0e10cSrcweir ViewContactOfUnoControl* pVC = NULL; 596cdf0e10cSrcweir if ( impl_getViewContact( pVC ) ) 597cdf0e10cSrcweir xControl = pVC->getTemporaryControlForWindow( _rWindow, _inout_ControlContainer ); 598cdf0e10cSrcweir 599cdf0e10cSrcweir return xControl; 600cdf0e10cSrcweir } 601cdf0e10cSrcweir 602cdf0e10cSrcweir //------------------------------------------------------------------------ 603cdf0e10cSrcweir bool SdrUnoObj::impl_getViewContact( ViewContactOfUnoControl*& _out_rpContact ) const 604cdf0e10cSrcweir { 605cdf0e10cSrcweir ViewContact& rViewContact( GetViewContact() ); 606cdf0e10cSrcweir _out_rpContact = dynamic_cast< ViewContactOfUnoControl* >( &rViewContact ); 607cdf0e10cSrcweir DBG_ASSERT( _out_rpContact, "SdrUnoObj::impl_getViewContact: could not find my ViewContact!" ); 608cdf0e10cSrcweir return ( _out_rpContact != NULL ); 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir //------------------------------------------------------------------------ 612cdf0e10cSrcweir ::sdr::contact::ViewContact* SdrUnoObj::CreateObjectSpecificViewContact() 613cdf0e10cSrcweir { 614cdf0e10cSrcweir return new ::sdr::contact::ViewContactOfUnoControl( *this ); 615cdf0e10cSrcweir } 616cdf0e10cSrcweir 617cdf0e10cSrcweir // ----------------------------------------------------------------------------- 618cdf0e10cSrcweir // eof 619