1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "precompiled_reportdesign.hxx"
28 #include "ReportComponentHandler.hxx"
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <comphelper/sequence.hxx>
31 #ifndef REPORTDESIGN_SHARED_UISTRINGS_HRC
32 #include "uistrings.hrc"
33 #endif
34 #include <comphelper/types.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <unotools/syslocale.hxx>
37 #include <com/sun/star/inspection/PropertyControlType.hpp>
38 #include <com/sun/star/report/XReportDefinition.hpp>
39 #include <com/sun/star/report/XSection.hpp>
40 #include <com/sun/star/inspection/XNumericControl.hpp>
41 #include <com/sun/star/container/XNameContainer.hpp>
42 #include <com/sun/star/util/MeasureUnit.hpp>
43 #include <tools/fldunit.hxx>
44 #include "metadata.hxx"
45 
46 //........................................................................
47 namespace rptui
48 {
49 //........................................................................
50 using namespace ::com::sun::star;
51 // using namespace comphelper;
52 
53 ReportComponentHandler::ReportComponentHandler(uno::Reference< uno::XComponentContext > const & context)
54     :ReportComponentHandler_Base(m_aMutex)
55     ,m_xContext(context)
56     ,m_pInfoService( new OPropertyInfoService() )
57 {
58     try
59     {
60         m_xFormComponentHandler.set(m_xContext->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.FormComponentPropertyHandler")),m_xContext),uno::UNO_QUERY_THROW);
61 
62     }catch(uno::Exception)
63     {
64     }
65 }
66 
67 //------------------------------------------------------------------------
68 ::rtl::OUString SAL_CALL ReportComponentHandler::getImplementationName(  ) throw(uno::RuntimeException)
69 {
70 	return getImplementationName_Static();
71 }
72 
73 //------------------------------------------------------------------------
74 sal_Bool SAL_CALL ReportComponentHandler::supportsService( const ::rtl::OUString& ServiceName ) throw(uno::RuntimeException)
75 {
76 	return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static());
77 }
78 
79 //------------------------------------------------------------------------
80 uno::Sequence< ::rtl::OUString > SAL_CALL ReportComponentHandler::getSupportedServiceNames(  ) throw(uno::RuntimeException)
81 {
82 	return getSupportedServiceNames_static();
83 }
84 
85 //------------------------------------------------------------------------
86 ::rtl::OUString ReportComponentHandler::getImplementationName_Static(  ) throw(uno::RuntimeException)
87 {
88     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.ReportComponentHandler"));
89 }
90 
91 //------------------------------------------------------------------------
92 uno::Sequence< ::rtl::OUString > ReportComponentHandler::getSupportedServiceNames_static(  ) throw(uno::RuntimeException)
93 {
94 	uno::Sequence< ::rtl::OUString > aSupported(1);
95     aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.ReportComponentHandler"));
96 	return aSupported;
97 }
98 
99 //------------------------------------------------------------------------
100 uno::Reference< uno::XInterface > SAL_CALL ReportComponentHandler::create( const uno::Reference< uno::XComponentContext >& _rxContext )
101 {
102 	return *(new ReportComponentHandler( _rxContext ));
103 }
104 // overload WeakComponentImplHelperBase::disposing()
105 // This function is called upon disposing the component,
106 // if your component needs special work when it becomes
107 // disposed, do it here.
108 void SAL_CALL ReportComponentHandler::disposing()
109 {
110     ::comphelper::disposeComponent(m_xFormComponentHandler);
111 }
112 void SAL_CALL ReportComponentHandler::addEventListener(const uno::Reference< lang::XEventListener > & xListener) throw (uno::RuntimeException)
113 {
114     m_xFormComponentHandler->addEventListener(xListener);
115 }
116 
117 void SAL_CALL ReportComponentHandler::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw (uno::RuntimeException)
118 {
119     m_xFormComponentHandler->removeEventListener(aListener);
120 }
121 
122 // inspection::XPropertyHandler:
123 
124 /********************************************************************************/
125 void SAL_CALL ReportComponentHandler::inspect(const uno::Reference< uno::XInterface > & Component) throw (uno::RuntimeException, lang::NullPointerException)
126 {
127     try
128     {
129         uno::Reference< container::XNameContainer > xNameCont(Component,uno::UNO_QUERY);
130         const ::rtl::OUString sFormComponent(RTL_CONSTASCII_USTRINGPARAM("FormComponent"));
131         if ( xNameCont->hasByName(sFormComponent) )
132             xNameCont->getByName(sFormComponent) >>= m_xFormComponent;
133         const ::rtl::OUString sRowSet(RTL_CONSTASCII_USTRINGPARAM("RowSet"));
134         if ( xNameCont->hasByName(sRowSet) )
135         {
136             uno::Reference<beans::XPropertySet> xProp(m_xFormComponentHandler,uno::UNO_QUERY);
137             xProp->setPropertyValue(sRowSet,xNameCont->getByName(sRowSet));
138         }
139     }
140     catch(uno::Exception)
141     {
142         throw lang::NullPointerException();
143     }
144     if ( m_xFormComponent.is() )
145     {
146         m_xFormComponentHandler->inspect(m_xFormComponent);
147     }
148 }
149 
150 uno::Any SAL_CALL ReportComponentHandler::getPropertyValue(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
151 {
152     return m_xFormComponentHandler->getPropertyValue(PropertyName);
153 }
154 
155 void SAL_CALL ReportComponentHandler::setPropertyValue(const ::rtl::OUString & PropertyName, const uno::Any & Value) throw (uno::RuntimeException, beans::UnknownPropertyException)
156 {
157     m_xFormComponentHandler->setPropertyValue(PropertyName, Value);
158 }
159 
160 beans::PropertyState SAL_CALL ReportComponentHandler::getPropertyState(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
161 {
162     return m_xFormComponentHandler->getPropertyState(PropertyName);
163 }
164 
165 inspection::LineDescriptor SAL_CALL ReportComponentHandler::describePropertyLine(const ::rtl::OUString & PropertyName,  const uno::Reference< inspection::XPropertyControlFactory > & ControlFactory) throw (beans::UnknownPropertyException, lang::NullPointerException,uno::RuntimeException)
166 {
167     return m_xFormComponentHandler->describePropertyLine(PropertyName, ControlFactory);
168 }
169 
170 uno::Any SAL_CALL ReportComponentHandler::convertToPropertyValue(const ::rtl::OUString & PropertyName, const uno::Any & ControlValue) throw (uno::RuntimeException, beans::UnknownPropertyException)
171 {
172     return m_xFormComponentHandler->convertToPropertyValue(PropertyName, ControlValue);
173 }
174 
175 uno::Any SAL_CALL ReportComponentHandler::convertToControlValue(const ::rtl::OUString & PropertyName, const uno::Any & PropertyValue, const uno::Type & ControlValueType) throw (uno::RuntimeException, beans::UnknownPropertyException)
176 {
177     return m_xFormComponentHandler->convertToControlValue(PropertyName, PropertyValue, ControlValueType);
178 }
179 
180 void SAL_CALL ReportComponentHandler::addPropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & Listener) throw (uno::RuntimeException, lang::NullPointerException)
181 {
182     m_xFormComponentHandler->addPropertyChangeListener(Listener);
183 }
184 
185 void SAL_CALL ReportComponentHandler::removePropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException)
186 {
187     m_xFormComponentHandler->removePropertyChangeListener(_rxListener);
188 }
189 
190 uno::Sequence< beans::Property > SAL_CALL ReportComponentHandler::getSupportedProperties() throw (uno::RuntimeException)
191 {
192     ::std::vector< beans::Property > aNewProps;
193     m_pInfoService->getExcludeProperties( aNewProps, m_xFormComponentHandler );
194 
195     return aNewProps.empty() ? uno::Sequence< beans::Property > () : uno::Sequence< beans::Property > (&(*aNewProps.begin()),aNewProps.size());
196 }
197 
198 uno::Sequence< ::rtl::OUString > SAL_CALL ReportComponentHandler::getSupersededProperties() throw (uno::RuntimeException)
199 {
200     uno::Sequence< ::rtl::OUString > aRet;
201     return aRet;
202 }
203 
204 uno::Sequence< ::rtl::OUString > SAL_CALL ReportComponentHandler::getActuatingProperties() throw (uno::RuntimeException)
205 {
206     return m_xFormComponentHandler->getActuatingProperties();
207 }
208 
209 ::sal_Bool SAL_CALL ReportComponentHandler::isComposable( const ::rtl::OUString& _rPropertyName ) throw (uno::RuntimeException, beans::UnknownPropertyException)
210 {
211     return m_pInfoService->isComposable( _rPropertyName, m_xFormComponentHandler );
212 }
213 
214 inspection::InteractiveSelectionResult SAL_CALL ReportComponentHandler::onInteractivePropertySelection(const ::rtl::OUString & PropertyName, ::sal_Bool Primary, uno::Any & out_Data, const uno::Reference< inspection::XObjectInspectorUI > & InspectorUI) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::NullPointerException)
215 {
216     return m_xFormComponentHandler->onInteractivePropertySelection(PropertyName, Primary, out_Data, InspectorUI);
217 }
218 
219 void SAL_CALL ReportComponentHandler::actuatingPropertyChanged(const ::rtl::OUString & ActuatingPropertyName, const uno::Any & NewValue, const uno::Any & OldValue, const uno::Reference< inspection::XObjectInspectorUI > & InspectorUI, ::sal_Bool FirstTimeInit) throw (uno::RuntimeException, lang::NullPointerException)
220 {
221     m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, InspectorUI, FirstTimeInit);
222 }
223 
224 ::sal_Bool SAL_CALL ReportComponentHandler::suspend(::sal_Bool Suspend) throw (uno::RuntimeException)
225 {
226     return m_xFormComponentHandler->suspend(Suspend);
227 }
228 
229 //........................................................................
230 } // namespace rptui
231 //........................................................................
232 
233