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 #ifndef REPORTDESIGN_TOOLS_HXX 24 #define REPORTDESIGN_TOOLS_HXX 25 26 #include <com/sun/star/report/XReportDefinition.hpp> 27 #include <com/sun/star/report/XSection.hpp> 28 #include <com/sun/star/awt/Point.hpp> 29 #include <com/sun/star/awt/Size.hpp> 30 #include <com/sun/star/container/XChild.hpp> 31 #include <com/sun/star/uno/XComponentContext.hpp> 32 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 33 #include <com/sun/star/report/XFixedText.hpp> 34 #include <com/sun/star/report/XFormattedField.hpp> 35 36 37 #include "Section.hxx" 38 #include "corestrings.hrc" 39 40 namespace reportdesign 41 { lcl_createSectionIfNeeded(sal_Bool _bOn,const T & _xParent,::com::sun::star::uno::Reference<::com::sun::star::report::XSection> & _xSection,bool _bPageSection=false)42 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) 43 { 44 if ( _bOn && !_xSection.is() ) 45 _xSection = new OSection(_xParent,_xParent->getContext(),_bPageSection); 46 else if ( !_bOn ) 47 //_xSection.clear(); 48 ::comphelper::disposeComponent(_xSection); 49 } 50 51 /** gets the properties which should be removed form the property set implementation. 52 * 53 * \return A sequence of all properties which should be removed for none char able implementations. 54 */ 55 ::com::sun::star::uno::Sequence< ::rtl::OUString > lcl_getCharOptionals(); 56 57 /** uses the XChild interface to get the section from any child of it. 58 * 59 * \param _xReportComponent A report component which is a child of the section. 60 * \return The sectin where this report component resists in. 61 */ 62 ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection> lcl_getSection(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _xReportComponent); 63 64 /** throws an illegal argument exception. The message text is the resource RID_STR_ERROR_WRONG_ARGUMENT + the type as reference. 65 * 66 * \param _sTypeName The reference where to look for the correct values. 67 * \param ExceptionContext_ The exception context. 68 * \param ArgumentPosition_ The argument position. 69 * \param Context_ The context to get the factory service. 70 */ 71 void throwIllegallArgumentException(const ::rtl::OUString& _sTypeName 72 ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& ExceptionContext_ 73 ,const ::sal_Int16& ArgumentPosition_ 74 ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& Context_); 75 76 /** clones the given object 77 * 78 * \param _xReportComponent the object to be cloned 79 * \param _xFactory the factory to create the clone 80 * \param _sServiceName the service of the to be cloned object 81 * \return the clone 82 */ 83 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > cloneObject( 84 const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportComponent>& _xReportComponent 85 ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _xFactory 86 ,const ::rtl::OUString& _sServiceName); 87 88 class OShapeHelper 89 { 90 public: setSize(const::com::sun::star::awt::Size & aSize,T * _pShape)91 template<typename T> static void setSize(const ::com::sun::star::awt::Size& aSize,T* _pShape) 92 { 93 OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal with or height!"); 94 95 ::osl::MutexGuard aGuard(_pShape->m_aMutex); 96 if ( _pShape->m_aProps.aComponent.m_xShape.is() ) 97 { 98 ::com::sun::star::awt::Size aOldSize = _pShape->m_aProps.aComponent.m_xShape->getSize(); 99 if ( aOldSize.Height != aSize.Height || aOldSize.Width != aSize.Width ) 100 { 101 _pShape->m_aProps.aComponent.m_nWidth = aOldSize.Width; 102 _pShape->m_aProps.aComponent.m_nHeight = aOldSize.Height; 103 _pShape->m_aProps.aComponent.m_xShape->setSize(aSize); 104 } 105 } 106 _pShape->set(PROPERTY_WIDTH,aSize.Width,_pShape->m_aProps.aComponent.m_nWidth); 107 _pShape->set(PROPERTY_HEIGHT,aSize.Height,_pShape->m_aProps.aComponent.m_nHeight); 108 } getSize(T * _pShape)109 template<typename T> static ::com::sun::star::awt::Size getSize( T* _pShape ) 110 { 111 ::osl::MutexGuard aGuard(_pShape->m_aMutex); 112 if ( _pShape->m_aProps.aComponent.m_xShape.is() ) 113 { 114 ::com::sun::star::awt::Size aSize = _pShape->m_aProps.aComponent.m_xShape->getSize(); 115 OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal with or height!"); 116 return aSize; 117 } 118 return ::com::sun::star::awt::Size(_pShape->m_aProps.aComponent.m_nWidth,_pShape->m_aProps.aComponent.m_nHeight); 119 } 120 setPosition(const::com::sun::star::awt::Point & _aPosition,T * _pShape)121 template<typename T> static void setPosition( const ::com::sun::star::awt::Point& _aPosition ,T* _pShape) 122 { 123 // we know it is not allowed that the position in smaller 0, but in NbcMove() it will handled right. 124 // only at 'Undo' it is possible to short set the position smaller 0 125 // OSL_ENSURE(_aPosition.X >= 0 && _aPosition.Y >= 0,"set to Illegal position!"); 126 ::osl::MutexGuard aGuard(_pShape->m_aMutex); 127 ::com::sun::star::awt::Point aOldPos; 128 aOldPos.X = _pShape->m_aProps.aComponent.m_nPosX; 129 aOldPos.Y = _pShape->m_aProps.aComponent.m_nPosY; 130 131 ::com::sun::star::awt::Point aPosition(_aPosition); 132 if ( _pShape->m_aProps.aComponent.m_xShape.is() ) 133 { 134 aOldPos = _pShape->m_aProps.aComponent.m_xShape->getPosition(); 135 if ( aOldPos.X != aPosition.X || aOldPos.Y != aPosition.Y ) 136 { 137 _pShape->m_aProps.aComponent.m_nPosX = aOldPos.X; 138 _pShape->m_aProps.aComponent.m_nPosY = aOldPos.Y; 139 _pShape->m_aProps.aComponent.m_xShape->setPosition(aPosition); 140 } 141 } 142 _pShape->set(PROPERTY_POSITIONX,aPosition.X,aOldPos.X); 143 _pShape->set(PROPERTY_POSITIONY,aPosition.Y,aOldPos.Y); 144 } getPosition(T * _pShape)145 template<typename T> static ::com::sun::star::awt::Point getPosition(T* _pShape) 146 { 147 ::osl::MutexGuard aGuard(_pShape->m_aMutex); 148 if ( _pShape->m_aProps.aComponent.m_xShape.is() ) 149 { 150 ::com::sun::star::awt::Point aPosition = _pShape->m_aProps.aComponent.m_xShape->getPosition(); 151 // OSL_ENSURE(aPosition.X >= 0 && aPosition.Y >= 0,"Illegal position!"); 152 return aPosition; 153 } 154 return ::com::sun::star::awt::Point(_pShape->m_aProps.aComponent.m_nPosX,_pShape->m_aProps.aComponent.m_nPosY); 155 } setParent(const com::sun::star::uno::Reference<com::sun::star::uno::XInterface> & Parent,T * _pShape)156 template<typename T> static void setParent( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& Parent, T* _pShape) 157 { 158 ::osl::MutexGuard aGuard(_pShape->m_aMutex); 159 _pShape->m_aProps.aComponent.m_xParent = ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild >(Parent,::com::sun::star::uno::UNO_QUERY); 160 ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > xChild; 161 comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild); 162 if ( xChild.is() ) 163 xChild->setParent(Parent); 164 } getParent(T * _pShape)165 template<typename T> static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > getParent( T* _pShape ) 166 { 167 ::osl::MutexGuard aGuard(_pShape->m_aMutex); 168 ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > xChild; 169 comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild); 170 if ( xChild.is() ) 171 return xChild->getParent(); 172 return _pShape->m_aProps.aComponent.m_xParent; 173 } 174 }; 175 // ============================================================================= 176 } // namespace reportdesign 177 // ============================================================================= 178 #endif // REPORTDESIGN_TOOLS_HXX 179 180