1*9ee13d13SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9ee13d13SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9ee13d13SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9ee13d13SAndrew Rist * distributed with this work for additional information 6*9ee13d13SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9ee13d13SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9ee13d13SAndrew Rist * "License"); you may not use this file except in compliance 9*9ee13d13SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9ee13d13SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9ee13d13SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9ee13d13SAndrew Rist * software distributed under the License is distributed on an 15*9ee13d13SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9ee13d13SAndrew Rist * KIND, either express or implied. See the License for the 17*9ee13d13SAndrew Rist * specific language governing permissions and limitations 18*9ee13d13SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9ee13d13SAndrew Rist *************************************************************/ 21*9ee13d13SAndrew Rist 22*9ee13d13SAndrew Rist 23cdf0e10cSrcweir #ifndef REPORTDESIGN_TOOLS_HXX 24cdf0e10cSrcweir #define REPORTDESIGN_TOOLS_HXX 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <com/sun/star/report/XReportDefinition.hpp> 27cdf0e10cSrcweir #include <com/sun/star/report/XSection.hpp> 28cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp> 29cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp> 30cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 31cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 32cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 33cdf0e10cSrcweir #include <com/sun/star/report/XFixedText.hpp> 34cdf0e10cSrcweir #include <com/sun/star/report/XFormattedField.hpp> 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "Section.hxx" 38cdf0e10cSrcweir #include "corestrings.hrc" 39cdf0e10cSrcweir 40cdf0e10cSrcweir namespace reportdesign 41cdf0e10cSrcweir { lcl_createSectionIfNeeded(sal_Bool _bOn,const T & _xParent,::com::sun::star::uno::Reference<::com::sun::star::report::XSection> & _xSection,bool _bPageSection=false)42cdf0e10cSrcweir template <class T> void lcl_createSectionIfNeeded(sal_Bool _bOn,const T& _xParent,::com::sun::star::uno::Reference< ::com::sun::star::report::XSection>& _xSection/*in/out*/,bool _bPageSection = false) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir if ( _bOn && !_xSection.is() ) 45cdf0e10cSrcweir _xSection = new OSection(_xParent,_xParent->getContext(),_bPageSection); 46cdf0e10cSrcweir else if ( !_bOn ) 47cdf0e10cSrcweir //_xSection.clear(); 48cdf0e10cSrcweir ::comphelper::disposeComponent(_xSection); 49cdf0e10cSrcweir } 50cdf0e10cSrcweir 51cdf0e10cSrcweir /** gets the properties which should be removed form the property set implementation. 52cdf0e10cSrcweir * 53cdf0e10cSrcweir * \return A sequence of all properties which should be removed for none char able implementations. 54cdf0e10cSrcweir */ 55cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > lcl_getCharOptionals(); 56cdf0e10cSrcweir 57cdf0e10cSrcweir /** uses the XChild interface to get the section from any child of it. 58cdf0e10cSrcweir * 59cdf0e10cSrcweir * \param _xReportComponent A report component which is a child of the section. 60cdf0e10cSrcweir * \return The sectin where this report component resists in. 61cdf0e10cSrcweir */ 62cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection> lcl_getSection(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _xReportComponent); 63cdf0e10cSrcweir 64cdf0e10cSrcweir /** throws an illegal argument exception. The message text is the resource RID_STR_ERROR_WRONG_ARGUMENT + the type as reference. 65cdf0e10cSrcweir * 66cdf0e10cSrcweir * \param _sTypeName The reference where to look for the correct values. 67cdf0e10cSrcweir * \param ExceptionContext_ The exception context. 68cdf0e10cSrcweir * \param ArgumentPosition_ The argument position. 69cdf0e10cSrcweir * \param Context_ The context to get the factory service. 70cdf0e10cSrcweir */ 71cdf0e10cSrcweir void throwIllegallArgumentException(const ::rtl::OUString& _sTypeName 72cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& ExceptionContext_ 73cdf0e10cSrcweir ,const ::sal_Int16& ArgumentPosition_ 74cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& Context_); 75cdf0e10cSrcweir 76cdf0e10cSrcweir /** clones the given object 77cdf0e10cSrcweir * 78cdf0e10cSrcweir * \param _xReportComponent the object to be cloned 79cdf0e10cSrcweir * \param _xFactory the factory to create the clone 80cdf0e10cSrcweir * \param _sServiceName the service of the to be cloned object 81cdf0e10cSrcweir * \return the clone 82cdf0e10cSrcweir */ 83cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > cloneObject( 84cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportComponent>& _xReportComponent 85cdf0e10cSrcweir ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _xFactory 86cdf0e10cSrcweir ,const ::rtl::OUString& _sServiceName); 87cdf0e10cSrcweir 88cdf0e10cSrcweir class OShapeHelper 89cdf0e10cSrcweir { 90cdf0e10cSrcweir public: setSize(const::com::sun::star::awt::Size & aSize,T * _pShape)91cdf0e10cSrcweir template<typename T> static void setSize(const ::com::sun::star::awt::Size& aSize,T* _pShape) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal with or height!"); 94cdf0e10cSrcweir 95cdf0e10cSrcweir ::osl::MutexGuard aGuard(_pShape->m_aMutex); 96cdf0e10cSrcweir if ( _pShape->m_aProps.aComponent.m_xShape.is() ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir ::com::sun::star::awt::Size aOldSize = _pShape->m_aProps.aComponent.m_xShape->getSize(); 99cdf0e10cSrcweir if ( aOldSize.Height != aSize.Height || aOldSize.Width != aSize.Width ) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir _pShape->m_aProps.aComponent.m_nWidth = aOldSize.Width; 102cdf0e10cSrcweir _pShape->m_aProps.aComponent.m_nHeight = aOldSize.Height; 103cdf0e10cSrcweir _pShape->m_aProps.aComponent.m_xShape->setSize(aSize); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir _pShape->set(PROPERTY_WIDTH,aSize.Width,_pShape->m_aProps.aComponent.m_nWidth); 107cdf0e10cSrcweir _pShape->set(PROPERTY_HEIGHT,aSize.Height,_pShape->m_aProps.aComponent.m_nHeight); 108cdf0e10cSrcweir } getSize(T * _pShape)109cdf0e10cSrcweir template<typename T> static ::com::sun::star::awt::Size getSize( T* _pShape ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir ::osl::MutexGuard aGuard(_pShape->m_aMutex); 112cdf0e10cSrcweir if ( _pShape->m_aProps.aComponent.m_xShape.is() ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir ::com::sun::star::awt::Size aSize = _pShape->m_aProps.aComponent.m_xShape->getSize(); 115cdf0e10cSrcweir OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal with or height!"); 116cdf0e10cSrcweir return aSize; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir return ::com::sun::star::awt::Size(_pShape->m_aProps.aComponent.m_nWidth,_pShape->m_aProps.aComponent.m_nHeight); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir setPosition(const::com::sun::star::awt::Point & _aPosition,T * _pShape)121cdf0e10cSrcweir template<typename T> static void setPosition( const ::com::sun::star::awt::Point& _aPosition ,T* _pShape) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir // we know it is not allowed that the position in smaller 0, but in NbcMove() it will handled right. 124cdf0e10cSrcweir // only at 'Undo' it is possible to short set the position smaller 0 125cdf0e10cSrcweir // OSL_ENSURE(_aPosition.X >= 0 && _aPosition.Y >= 0,"set to Illegal position!"); 126cdf0e10cSrcweir ::osl::MutexGuard aGuard(_pShape->m_aMutex); 127cdf0e10cSrcweir ::com::sun::star::awt::Point aOldPos; 128cdf0e10cSrcweir aOldPos.X = _pShape->m_aProps.aComponent.m_nPosX; 129cdf0e10cSrcweir aOldPos.Y = _pShape->m_aProps.aComponent.m_nPosY; 130cdf0e10cSrcweir 131cdf0e10cSrcweir ::com::sun::star::awt::Point aPosition(_aPosition); 132cdf0e10cSrcweir if ( _pShape->m_aProps.aComponent.m_xShape.is() ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir aOldPos = _pShape->m_aProps.aComponent.m_xShape->getPosition(); 135cdf0e10cSrcweir if ( aOldPos.X != aPosition.X || aOldPos.Y != aPosition.Y ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir _pShape->m_aProps.aComponent.m_nPosX = aOldPos.X; 138cdf0e10cSrcweir _pShape->m_aProps.aComponent.m_nPosY = aOldPos.Y; 139cdf0e10cSrcweir _pShape->m_aProps.aComponent.m_xShape->setPosition(aPosition); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir _pShape->set(PROPERTY_POSITIONX,aPosition.X,aOldPos.X); 143cdf0e10cSrcweir _pShape->set(PROPERTY_POSITIONY,aPosition.Y,aOldPos.Y); 144cdf0e10cSrcweir } getPosition(T * _pShape)145cdf0e10cSrcweir template<typename T> static ::com::sun::star::awt::Point getPosition(T* _pShape) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir ::osl::MutexGuard aGuard(_pShape->m_aMutex); 148cdf0e10cSrcweir if ( _pShape->m_aProps.aComponent.m_xShape.is() ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir ::com::sun::star::awt::Point aPosition = _pShape->m_aProps.aComponent.m_xShape->getPosition(); 151cdf0e10cSrcweir // OSL_ENSURE(aPosition.X >= 0 && aPosition.Y >= 0,"Illegal position!"); 152cdf0e10cSrcweir return aPosition; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir return ::com::sun::star::awt::Point(_pShape->m_aProps.aComponent.m_nPosX,_pShape->m_aProps.aComponent.m_nPosY); 155cdf0e10cSrcweir } setParent(const com::sun::star::uno::Reference<com::sun::star::uno::XInterface> & Parent,T * _pShape)156cdf0e10cSrcweir template<typename T> static void setParent( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& Parent, T* _pShape) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir ::osl::MutexGuard aGuard(_pShape->m_aMutex); 159cdf0e10cSrcweir _pShape->m_aProps.aComponent.m_xParent = ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild >(Parent,::com::sun::star::uno::UNO_QUERY); 160cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > xChild; 161cdf0e10cSrcweir comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild); 162cdf0e10cSrcweir if ( xChild.is() ) 163cdf0e10cSrcweir xChild->setParent(Parent); 164cdf0e10cSrcweir } getParent(T * _pShape)165cdf0e10cSrcweir template<typename T> static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > getParent( T* _pShape ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir ::osl::MutexGuard aGuard(_pShape->m_aMutex); 168cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > xChild; 169cdf0e10cSrcweir comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild); 170cdf0e10cSrcweir if ( xChild.is() ) 171cdf0e10cSrcweir return xChild->getParent(); 172cdf0e10cSrcweir return _pShape->m_aProps.aComponent.m_xParent; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir }; 175cdf0e10cSrcweir // ============================================================================= 176cdf0e10cSrcweir } // namespace reportdesign 177cdf0e10cSrcweir // ============================================================================= 178cdf0e10cSrcweir #endif // REPORTDESIGN_TOOLS_HXX 179cdf0e10cSrcweir 180