merge the formfield patch from ooo-build
[ooovba.git] / reportdesign / source / core / inc / Tools.hxx
blobf88adaad88ed0e56ce0a4f79f07deda3df05eb8c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Tools.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef REPORTDESIGN_TOOLS_HXX
31 #define REPORTDESIGN_TOOLS_HXX
33 #include <com/sun/star/report/XReportDefinition.hpp>
34 #include <com/sun/star/report/XSection.hpp>
35 #include <com/sun/star/awt/Point.hpp>
36 #include <com/sun/star/awt/Size.hpp>
37 #include <com/sun/star/container/XChild.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/report/XFixedText.hpp>
41 #include <com/sun/star/report/XFormattedField.hpp>
44 #include "Section.hxx"
45 #include "corestrings.hrc"
47 namespace reportdesign
49 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)
51 if ( _bOn && !_xSection.is() )
52 _xSection = new OSection(_xParent,_xParent->getContext(),_bPageSection);
53 else if ( !_bOn )
54 //_xSection.clear();
55 ::comphelper::disposeComponent(_xSection);
58 /** gets the properties which should be removed form the property set implementation.
60 * \return A sequence of all properties which should be removed for none char able implementations.
62 ::com::sun::star::uno::Sequence< ::rtl::OUString > lcl_getCharOptionals();
64 /** uses the XChild interface to get the section from any child of it.
66 * \param _xReportComponent A report component which is a child of the section.
67 * \return The sectin where this report component resists in.
69 ::com::sun::star::uno::Reference< ::com::sun::star::report::XSection> lcl_getSection(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _xReportComponent);
71 /** throws an illegal argument exception. The message text is the resource RID_STR_ERROR_WRONG_ARGUMENT + the type as reference.
73 * \param _sTypeName The reference where to look for the correct values.
74 * \param ExceptionContext_ The exception context.
75 * \param ArgumentPosition_ The argument position.
76 * \param Context_ The context to get the factory service.
78 void throwIllegallArgumentException(const ::rtl::OUString& _sTypeName
79 ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& ExceptionContext_
80 ,const ::sal_Int16& ArgumentPosition_
81 ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& Context_);
83 /** clones the given object
85 * \param _xReportComponent the object to be cloned
86 * \param _xFactory the factory to create the clone
87 * \param _sServiceName the service of the to be cloned object
88 * \return the clone
90 ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > cloneObject(
91 const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportComponent>& _xReportComponent
92 ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _xFactory
93 ,const ::rtl::OUString& _sServiceName);
95 class OShapeHelper
97 public:
98 template<typename T> static void setSize(const ::com::sun::star::awt::Size& aSize,T* _pShape)
100 OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal with or height!");
102 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
103 if ( _pShape->m_aProps.aComponent.m_xShape.is() )
105 ::com::sun::star::awt::Size aOldSize = _pShape->m_aProps.aComponent.m_xShape->getSize();
106 if ( aOldSize.Height != aSize.Height || aOldSize.Width != aSize.Width )
108 _pShape->m_aProps.aComponent.m_nWidth = aOldSize.Width;
109 _pShape->m_aProps.aComponent.m_nHeight = aOldSize.Height;
110 _pShape->m_aProps.aComponent.m_xShape->setSize(aSize);
113 _pShape->set(PROPERTY_WIDTH,aSize.Width,_pShape->m_aProps.aComponent.m_nWidth);
114 _pShape->set(PROPERTY_HEIGHT,aSize.Height,_pShape->m_aProps.aComponent.m_nHeight);
116 template<typename T> static ::com::sun::star::awt::Size getSize( T* _pShape )
118 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
119 if ( _pShape->m_aProps.aComponent.m_xShape.is() )
121 ::com::sun::star::awt::Size aSize = _pShape->m_aProps.aComponent.m_xShape->getSize();
122 OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal with or height!");
123 return aSize;
125 return ::com::sun::star::awt::Size(_pShape->m_aProps.aComponent.m_nWidth,_pShape->m_aProps.aComponent.m_nHeight);
128 template<typename T> static void setPosition( const ::com::sun::star::awt::Point& _aPosition ,T* _pShape)
130 // we know it is not allowed that the position in smaller 0, but in NbcMove() it will handled right.
131 // only at 'Undo' it is possible to short set the position smaller 0
132 // OSL_ENSURE(_aPosition.X >= 0 && _aPosition.Y >= 0,"set to Illegal position!");
133 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
134 ::com::sun::star::awt::Point aOldPos;
135 aOldPos.X = _pShape->m_aProps.aComponent.m_nPosX;
136 aOldPos.Y = _pShape->m_aProps.aComponent.m_nPosY;
138 ::com::sun::star::awt::Point aPosition(_aPosition);
139 if ( _pShape->m_aProps.aComponent.m_xShape.is() )
141 aOldPos = _pShape->m_aProps.aComponent.m_xShape->getPosition();
142 if ( aOldPos.X != aPosition.X || aOldPos.Y != aPosition.Y )
144 _pShape->m_aProps.aComponent.m_nPosX = aOldPos.X;
145 _pShape->m_aProps.aComponent.m_nPosY = aOldPos.Y;
146 _pShape->m_aProps.aComponent.m_xShape->setPosition(aPosition);
149 _pShape->set(PROPERTY_POSITIONX,aPosition.X,aOldPos.X);
150 _pShape->set(PROPERTY_POSITIONY,aPosition.Y,aOldPos.Y);
152 template<typename T> static ::com::sun::star::awt::Point getPosition(T* _pShape)
154 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
155 if ( _pShape->m_aProps.aComponent.m_xShape.is() )
157 ::com::sun::star::awt::Point aPosition = _pShape->m_aProps.aComponent.m_xShape->getPosition();
158 // OSL_ENSURE(aPosition.X >= 0 && aPosition.Y >= 0,"Illegal position!");
159 return aPosition;
161 return ::com::sun::star::awt::Point(_pShape->m_aProps.aComponent.m_nPosX,_pShape->m_aProps.aComponent.m_nPosY);
163 template<typename T> static void setParent( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& Parent, T* _pShape)
165 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
166 _pShape->m_aProps.aComponent.m_xParent = ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild >(Parent,::com::sun::star::uno::UNO_QUERY);
167 ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > xChild;
168 comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild);
169 if ( xChild.is() )
170 xChild->setParent(Parent);
172 template<typename T> static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > getParent( T* _pShape )
174 ::osl::MutexGuard aGuard(_pShape->m_aMutex);
175 ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > xChild;
176 comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild);
177 if ( xChild.is() )
178 return xChild->getParent();
179 return _pShape->m_aProps.aComponent.m_xParent;
182 // =============================================================================
183 } // namespace reportdesign
184 // =============================================================================
185 #endif // REPORTDESIGN_TOOLS_HXX