1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Tools.hxx,v $
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 "Section.hxx"
41 #include "corestrings.hrc"
43 namespace reportdesign
45 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)
47 if ( _bOn
&& !_xSection
.is() )
48 _xSection
= new OSection(_xParent
,_xParent
->getContext(),_bPageSection
);
51 ::comphelper::disposeComponent(_xSection
);
54 /** gets the properties which should be removed form the property set implementation.
56 * \return A sequence of all properties which should be removed for none char able implementations.
58 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> lcl_getCharOptionals();
60 /** uses the XChild interface to get the section from any child of it.
62 * \param _xReportComponent A report component which is a child of the section.
63 * \return The sectin where this report component resists in.
65 ::com::sun::star::uno::Reference
< ::com::sun::star::report::XSection
> lcl_getSection(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _xReportComponent
);
67 /** throws an illegal argument exception. The message text is the resource RID_STR_ERROR_WRONG_ARGUMENT + the type as reference.
69 * \param _sTypeName The reference where to look for the correct values.
70 * \param ExceptionContext_ The exception context.
71 * \param ArgumentPosition_ The argument position.
72 * \param Context_ The context to get the factory service.
74 void throwIllegallArgumentException(const ::rtl::OUString
& _sTypeName
75 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& ExceptionContext_
76 ,const ::sal_Int16
& ArgumentPosition_
77 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& Context_
);
79 /** clones the given object
81 * \param _xReportComponent the object to be cloned
82 * \param _xFactory the factory to create the clone
83 * \param _sServiceName the service of the to be cloned object
86 ::com::sun::star::uno::Reference
< ::com::sun::star::util::XCloneable
> cloneObject(
87 const ::com::sun::star::uno::Reference
< ::com::sun::star::report::XReportComponent
>& _xReportComponent
88 ,const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _xFactory
89 ,const ::rtl::OUString
& _sServiceName
);
94 template<typename T
> static void setSize(const ::com::sun::star::awt::Size
& aSize
,T
* _pShape
)
96 OSL_ENSURE(aSize
.Width
>= 0 && aSize
.Height
>= 0,"Illegal with or height!");
98 ::osl::MutexGuard
aGuard(_pShape
->m_aMutex
);
99 if ( _pShape
->m_aProps
.aComponent
.m_xShape
.is() )
101 ::com::sun::star::awt::Size aOldSize
= _pShape
->m_aProps
.aComponent
.m_xShape
->getSize();
102 _pShape
->m_aProps
.aComponent
.m_nWidth
= aOldSize
.Width
;
103 _pShape
->m_aProps
.aComponent
.m_nHeight
= aOldSize
.Height
;
104 _pShape
->m_aProps
.aComponent
.m_xShape
->setSize(aSize
);
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
);
109 template<typename T
> static ::com::sun::star::awt::Size
getSize( T
* _pShape
)
111 ::osl::MutexGuard
aGuard(_pShape
->m_aMutex
);
112 if ( _pShape
->m_aProps
.aComponent
.m_xShape
.is() )
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!");
118 return ::com::sun::star::awt::Size(_pShape
->m_aProps
.aComponent
.m_nWidth
,_pShape
->m_aProps
.aComponent
.m_nHeight
);
121 template<typename T
> static void setPosition( const ::com::sun::star::awt::Point
& aPosition
,T
* _pShape
)
123 OSL_ENSURE(aPosition
.X
>= 0 && aPosition
.Y
>= 0,"Illegal position!");
124 ::osl::MutexGuard
aGuard(_pShape
->m_aMutex
);
125 if ( _pShape
->m_aProps
.aComponent
.m_xShape
.is() )
127 ::com::sun::star::awt::Point aOldPos
= _pShape
->m_aProps
.aComponent
.m_xShape
->getPosition();
128 _pShape
->m_aProps
.aComponent
.m_nPosX
= aOldPos
.X
;
129 _pShape
->m_aProps
.aComponent
.m_nPosY
= aOldPos
.Y
;
130 _pShape
->m_aProps
.aComponent
.m_xShape
->setPosition(aPosition
);
132 _pShape
->set(PROPERTY_POSITIONX
,aPosition
.X
,_pShape
->m_aProps
.aComponent
.m_nPosX
);
133 _pShape
->set(PROPERTY_POSITIONY
,aPosition
.Y
,_pShape
->m_aProps
.aComponent
.m_nPosY
);
135 template<typename T
> static ::com::sun::star::awt::Point
getPosition(T
* _pShape
)
137 ::osl::MutexGuard
aGuard(_pShape
->m_aMutex
);
138 if ( _pShape
->m_aProps
.aComponent
.m_xShape
.is() )
140 ::com::sun::star::awt::Point aPosition
= _pShape
->m_aProps
.aComponent
.m_xShape
->getPosition();
141 OSL_ENSURE(aPosition
.X
>= 0 && aPosition
.Y
>= 0,"Illegal position!");
144 return ::com::sun::star::awt::Point(_pShape
->m_aProps
.aComponent
.m_nPosX
,_pShape
->m_aProps
.aComponent
.m_nPosY
);
146 template<typename T
> static void setParent( const com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
>& Parent
, T
* _pShape
)
148 ::osl::MutexGuard
aGuard(_pShape
->m_aMutex
);
149 _pShape
->m_aProps
.aComponent
.m_xParent
= ::com::sun::star::uno::Reference
< ::com::sun::star::container::XChild
>(Parent
,::com::sun::star::uno::UNO_QUERY
);
150 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XChild
> xChild
;
151 comphelper::query_aggregation(_pShape
->m_aProps
.aComponent
.m_xProxy
,xChild
);
153 xChild
->setParent(Parent
);
155 template<typename T
> static com::sun::star::uno::Reference
< com::sun::star::uno::XInterface
> getParent( T
* _pShape
)
157 ::osl::MutexGuard
aGuard(_pShape
->m_aMutex
);
158 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XChild
> xChild
;
159 comphelper::query_aggregation(_pShape
->m_aProps
.aComponent
.m_xProxy
,xChild
);
161 return xChild
->getParent();
162 return _pShape
->m_aProps
.aComponent
.m_xParent
;
165 // =============================================================================
166 } // namespace reportdesign
167 // =============================================================================
168 #endif // REPORTDESIGN_TOOLS_HXX