Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef REPORTDESIGN_TOOLS_HXX
29 : : #define REPORTDESIGN_TOOLS_HXX
30 : :
31 : : #include <com/sun/star/report/XReportDefinition.hpp>
32 : : #include <com/sun/star/report/XSection.hpp>
33 : : #include <com/sun/star/awt/Point.hpp>
34 : : #include <com/sun/star/awt/Size.hpp>
35 : : #include <com/sun/star/container/XChild.hpp>
36 : : #include <com/sun/star/uno/XComponentContext.hpp>
37 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 : : #include <com/sun/star/report/XFixedText.hpp>
39 : : #include <com/sun/star/report/XFormattedField.hpp>
40 : :
41 : :
42 : : #include "Section.hxx"
43 : : #include "corestrings.hrc"
44 : :
45 : : namespace reportdesign
46 : : {
47 : 0 : 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)
48 : : {
49 [ # # ][ # # ]: 0 : if ( _bOn && !_xSection.is() )
[ # # ]
50 [ # # ][ # # ]: 0 : _xSection = OSection::createOSection(_xParent,_xParent->getContext(),_bPageSection);
[ # # ][ # # ]
51 [ # # ]: 0 : else if ( !_bOn )
52 : 0 : ::comphelper::disposeComponent(_xSection);
53 : 0 : }
54 : :
55 : : /** gets the properties which should be removed form the property set implementation.
56 : : *
57 : : * \return A sequence of all properties which should be removed for none char able implementations.
58 : : */
59 : : ::com::sun::star::uno::Sequence< ::rtl::OUString > lcl_getCharOptionals();
60 : :
61 : : /** uses the XChild interface to get the section from any child of it.
62 : : *
63 : : * \param _xReportComponent A report component which is a child of the section.
64 : : * \return The sectin where this report component resists in.
65 : : */
66 : : ::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 : :
68 : : /** throws an illegal argument exception. The message text is the resource RID_STR_ERROR_WRONG_ARGUMENT + the type as reference.
69 : : *
70 : : * \param _sTypeName The reference where to look for the correct values.
71 : : * \param ExceptionContext_ The exception context.
72 : : * \param ArgumentPosition_ The argument position.
73 : : * \param Context_ The context to get the factory service.
74 : : */
75 : : void throwIllegallArgumentException(const ::rtl::OUString& _sTypeName
76 : : ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& ExceptionContext_
77 : : ,const ::sal_Int16& ArgumentPosition_
78 : : ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& Context_);
79 : :
80 : : /** clones the given object
81 : : *
82 : : * \param _xReportComponent the object to be cloned
83 : : * \param _xFactory the factory to create the clone
84 : : * \param _sServiceName the service of the to be cloned object
85 : : * \return the clone
86 : : */
87 : : ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > cloneObject(
88 : : const ::com::sun::star::uno::Reference< ::com::sun::star::report::XReportComponent>& _xReportComponent
89 : : ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _xFactory
90 : : ,const ::rtl::OUString& _sServiceName);
91 : :
92 : : class OShapeHelper
93 : : {
94 : : public:
95 : 0 : template<typename T> static void setSize(const ::com::sun::star::awt::Size& aSize,T* _pShape)
96 : : {
97 : : OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal width or height!");
98 : :
99 [ # # ]: 0 : ::osl::MutexGuard aGuard(_pShape->m_aMutex);
100 [ # # ]: 0 : if ( _pShape->m_aProps.aComponent.m_xShape.is() )
101 : : {
102 [ # # ][ # # ]: 0 : ::com::sun::star::awt::Size aOldSize = _pShape->m_aProps.aComponent.m_xShape->getSize();
103 [ # # ][ # # ]: 0 : if ( aOldSize.Height != aSize.Height || aOldSize.Width != aSize.Width )
104 : : {
105 : 0 : _pShape->m_aProps.aComponent.m_nWidth = aOldSize.Width;
106 : 0 : _pShape->m_aProps.aComponent.m_nHeight = aOldSize.Height;
107 [ # # ][ # # ]: 0 : _pShape->m_aProps.aComponent.m_xShape->setSize(aSize);
108 : : }
109 : : }
110 [ # # ][ # # ]: 0 : _pShape->set(PROPERTY_WIDTH,aSize.Width,_pShape->m_aProps.aComponent.m_nWidth);
111 [ # # ][ # # ]: 0 : _pShape->set(PROPERTY_HEIGHT,aSize.Height,_pShape->m_aProps.aComponent.m_nHeight);
[ # # ]
112 : 0 : }
113 : 0 : template<typename T> static ::com::sun::star::awt::Size getSize( T* _pShape )
114 : : {
115 [ # # ]: 0 : ::osl::MutexGuard aGuard(_pShape->m_aMutex);
116 [ # # ]: 0 : if ( _pShape->m_aProps.aComponent.m_xShape.is() )
117 : : {
118 [ # # ][ # # ]: 0 : ::com::sun::star::awt::Size aSize = _pShape->m_aProps.aComponent.m_xShape->getSize();
119 : : OSL_ENSURE(aSize.Width >= 0 && aSize.Height >= 0,"Illegal width or height!");
120 : 0 : return aSize;
121 : : }
122 [ # # ]: 0 : return ::com::sun::star::awt::Size(_pShape->m_aProps.aComponent.m_nWidth,_pShape->m_aProps.aComponent.m_nHeight);
123 : : }
124 : :
125 : 0 : template<typename T> static void setPosition( const ::com::sun::star::awt::Point& _aPosition ,T* _pShape)
126 : : {
127 : : // we know it is not allowed that the position in smaller 0, but in NbcMove() it will handled right.
128 : : // only at 'Undo' it is possible to short set the position smaller 0
129 : : // OSL_ENSURE(_aPosition.X >= 0 && _aPosition.Y >= 0,"set to Illegal position!");
130 [ # # ]: 0 : ::osl::MutexGuard aGuard(_pShape->m_aMutex);
131 : 0 : ::com::sun::star::awt::Point aOldPos;
132 : 0 : aOldPos.X = _pShape->m_aProps.aComponent.m_nPosX;
133 : 0 : aOldPos.Y = _pShape->m_aProps.aComponent.m_nPosY;
134 : :
135 : 0 : ::com::sun::star::awt::Point aPosition(_aPosition);
136 [ # # ]: 0 : if ( _pShape->m_aProps.aComponent.m_xShape.is() )
137 : : {
138 [ # # ][ # # ]: 0 : aOldPos = _pShape->m_aProps.aComponent.m_xShape->getPosition();
139 [ # # ][ # # ]: 0 : if ( aOldPos.X != aPosition.X || aOldPos.Y != aPosition.Y )
140 : : {
141 : 0 : _pShape->m_aProps.aComponent.m_nPosX = aOldPos.X;
142 : 0 : _pShape->m_aProps.aComponent.m_nPosY = aOldPos.Y;
143 [ # # ][ # # ]: 0 : _pShape->m_aProps.aComponent.m_xShape->setPosition(aPosition);
144 : : }
145 : : }
146 [ # # ][ # # ]: 0 : _pShape->set(PROPERTY_POSITIONX,aPosition.X,aOldPos.X);
147 [ # # ][ # # ]: 0 : _pShape->set(PROPERTY_POSITIONY,aPosition.Y,aOldPos.Y);
[ # # ]
148 : 0 : }
149 : 0 : template<typename T> static ::com::sun::star::awt::Point getPosition(T* _pShape)
150 : : {
151 [ # # ]: 0 : ::osl::MutexGuard aGuard(_pShape->m_aMutex);
152 [ # # ]: 0 : if ( _pShape->m_aProps.aComponent.m_xShape.is() )
153 : : {
154 [ # # ][ # # ]: 0 : ::com::sun::star::awt::Point aPosition = _pShape->m_aProps.aComponent.m_xShape->getPosition();
155 : 0 : return aPosition;
156 : : }
157 [ # # ]: 0 : return ::com::sun::star::awt::Point(_pShape->m_aProps.aComponent.m_nPosX,_pShape->m_aProps.aComponent.m_nPosY);
158 : : }
159 : 0 : template<typename T> static void setParent( const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& Parent, T* _pShape)
160 : : {
161 [ # # ]: 0 : ::osl::MutexGuard aGuard(_pShape->m_aMutex);
162 [ # # ][ # # ]: 0 : _pShape->m_aProps.aComponent.m_xParent = ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild >(Parent,::com::sun::star::uno::UNO_QUERY);
163 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > xChild;
164 [ # # ]: 0 : comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild);
165 [ # # ]: 0 : if ( xChild.is() )
166 [ # # ][ # # ]: 0 : xChild->setParent(Parent);
[ # # ]
167 : 0 : }
168 : 0 : template<typename T> static com::sun::star::uno::Reference< com::sun::star::uno::XInterface > getParent( T* _pShape )
169 : : {
170 [ # # ]: 0 : ::osl::MutexGuard aGuard(_pShape->m_aMutex);
171 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XChild > xChild;
172 [ # # ]: 0 : comphelper::query_aggregation(_pShape->m_aProps.aComponent.m_xProxy,xChild);
173 [ # # ]: 0 : if ( xChild.is() )
174 [ # # ][ # # ]: 0 : return xChild->getParent();
175 [ # # ][ # # ]: 0 : return _pShape->m_aProps.aComponent.m_xParent;
176 : : }
177 : : };
178 : : // =============================================================================
179 : : } // namespace reportdesign
180 : : // =============================================================================
181 : : #endif // REPORTDESIGN_TOOLS_HXX
182 : :
183 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|