19e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39e0e4191SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49e0e4191SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59e0e4191SAndrew Rist  * distributed with this work for additional information
69e0e4191SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79e0e4191SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89e0e4191SAndrew Rist  * "License"); you may not use this file except in compliance
99e0e4191SAndrew Rist  * with the License.  You may obtain a copy of the License at
109e0e4191SAndrew Rist  *
119e0e4191SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129e0e4191SAndrew Rist  *
139e0e4191SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149e0e4191SAndrew Rist  * software distributed under the License is distributed on an
159e0e4191SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169e0e4191SAndrew Rist  * KIND, either express or implied.  See the License for the
179e0e4191SAndrew Rist  * specific language governing permissions and limitations
189e0e4191SAndrew Rist  * under the License.
199e0e4191SAndrew Rist  *
209e0e4191SAndrew Rist  *************************************************************/
219e0e4191SAndrew Rist 
229e0e4191SAndrew Rist 
23cdf0e10cSrcweir #include "precompiled_reportdesign.hxx"
24cdf0e10cSrcweir #include "DataProviderHandler.hxx"
25cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
26cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
27cdf0e10cSrcweir #include <comphelper/sequence.hxx>
28cdf0e10cSrcweir #include <comphelper/property.hxx>
29cdf0e10cSrcweir #include <comphelper/types.hxx>
30cdf0e10cSrcweir #include "uistrings.hrc"
31cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
32cdf0e10cSrcweir #include <unotools/syslocale.hxx>
33cdf0e10cSrcweir #include <com/sun/star/inspection/PropertyControlType.hpp>
34cdf0e10cSrcweir #include <com/sun/star/inspection/PropertyLineElement.hpp>
35cdf0e10cSrcweir #include <com/sun/star/chart/ChartDataRowSource.hpp>
36cdf0e10cSrcweir #include <com/sun/star/chart2/XDiagram.hpp>
37cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
38cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp>
39cdf0e10cSrcweir #include <com/sun/star/chart2/XChartType.hpp>
40cdf0e10cSrcweir #include <com/sun/star/chart2/XFormattedString.hpp>
41cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp>
42cdf0e10cSrcweir #include <com/sun/star/chart2/XTitle.hpp>
43cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataReceiver.hpp>
44cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
45cdf0e10cSrcweir #include <com/sun/star/report/XReportDefinition.hpp>
46cdf0e10cSrcweir #include <com/sun/star/report/XSection.hpp>
47cdf0e10cSrcweir #include <com/sun/star/inspection/XNumericControl.hpp>
48cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
49cdf0e10cSrcweir #include <com/sun/star/util/MeasureUnit.hpp>
50cdf0e10cSrcweir #include <tools/fldunit.hxx>
51cdf0e10cSrcweir #include "metadata.hxx"
52cdf0e10cSrcweir #include <vcl/svapp.hxx>
53cdf0e10cSrcweir #include <vos/mutex.hxx>
54cdf0e10cSrcweir #include "helpids.hrc"
55cdf0e10cSrcweir #include "uistrings.hrc"
56cdf0e10cSrcweir #include "RptResId.hrc"
57cdf0e10cSrcweir #include "PropertyForward.hxx"
58cdf0e10cSrcweir //........................................................................
59cdf0e10cSrcweir namespace rptui
60cdf0e10cSrcweir {
61cdf0e10cSrcweir //........................................................................
62cdf0e10cSrcweir using namespace ::com::sun::star;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir DataProviderHandler::DataProviderHandler(uno::Reference< uno::XComponentContext > const & context)
65cdf0e10cSrcweir     :DataProviderHandler_Base(m_aMutex)
66cdf0e10cSrcweir     ,m_xContext(context)
67cdf0e10cSrcweir     ,m_pInfoService( new OPropertyInfoService() )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     try
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         m_xFormComponentHandler.set(m_xContext->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.FormComponentPropertyHandler")),m_xContext),uno::UNO_QUERY_THROW);
72cdf0e10cSrcweir         m_xTypeConverter.set(m_xContext->getServiceManager()->createInstanceWithContext( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter" )),m_xContext),uno::UNO_QUERY_THROW);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     }catch(uno::Exception)
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir //------------------------------------------------------------------------
80cdf0e10cSrcweir ::rtl::OUString SAL_CALL DataProviderHandler::getImplementationName(  ) throw(uno::RuntimeException)
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	return getImplementationName_Static();
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir //------------------------------------------------------------------------
86cdf0e10cSrcweir sal_Bool SAL_CALL DataProviderHandler::supportsService( const ::rtl::OUString& ServiceName ) throw(uno::RuntimeException)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static());
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir //------------------------------------------------------------------------
92cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL DataProviderHandler::getSupportedServiceNames(  ) throw(uno::RuntimeException)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	return getSupportedServiceNames_static();
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir //------------------------------------------------------------------------
98cdf0e10cSrcweir ::rtl::OUString DataProviderHandler::getImplementationName_Static(  ) throw(uno::RuntimeException)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.DataProviderHandler"));
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir //------------------------------------------------------------------------
104cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > DataProviderHandler::getSupportedServiceNames_static(  ) throw(uno::RuntimeException)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSupported(1);
107cdf0e10cSrcweir     aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.DataProviderHandler"));
108cdf0e10cSrcweir 	return aSupported;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //------------------------------------------------------------------------
112cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL DataProviderHandler::create( const uno::Reference< uno::XComponentContext >& _rxContext )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 	return *(new DataProviderHandler( _rxContext ));
115cdf0e10cSrcweir }
116cdf0e10cSrcweir // overload WeakComponentImplHelperBase::disposing()
117cdf0e10cSrcweir // This function is called upon disposing the component,
118cdf0e10cSrcweir // if your component needs special work when it becomes
119cdf0e10cSrcweir // disposed, do it here.
120cdf0e10cSrcweir void SAL_CALL DataProviderHandler::disposing()
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     ::comphelper::disposeComponent(m_xFormComponentHandler);
123cdf0e10cSrcweir     ::comphelper::disposeComponent( m_xMasterDetails );
124cdf0e10cSrcweir     ::comphelper::disposeComponent(m_xTypeConverter);
125cdf0e10cSrcweir }
126cdf0e10cSrcweir void SAL_CALL DataProviderHandler::addEventListener(const uno::Reference< lang::XEventListener > & xListener) throw (uno::RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     m_xFormComponentHandler->addEventListener(xListener);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir void SAL_CALL DataProviderHandler::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw (uno::RuntimeException)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     m_xFormComponentHandler->removeEventListener(aListener);
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir // inspection::XPropertyHandler:
137cdf0e10cSrcweir 
138cdf0e10cSrcweir /********************************************************************************/
139cdf0e10cSrcweir void SAL_CALL DataProviderHandler::inspect(const uno::Reference< uno::XInterface > & Component) throw (uno::RuntimeException, lang::NullPointerException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     try
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         uno::Reference< container::XNameContainer > xNameCont(Component,uno::UNO_QUERY);
144cdf0e10cSrcweir         const ::rtl::OUString sFormComponent(RTL_CONSTASCII_USTRINGPARAM("FormComponent"));
145cdf0e10cSrcweir         if ( xNameCont->hasByName(sFormComponent) )
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             uno::Reference<beans::XPropertySet> xProp(xNameCont->getByName(sFormComponent),uno::UNO_QUERY);
148cdf0e10cSrcweir             const ::rtl::OUString sModel(RTL_CONSTASCII_USTRINGPARAM("Model"));
149cdf0e10cSrcweir             if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(sModel) )
150cdf0e10cSrcweir             {
151cdf0e10cSrcweir                 m_xChartModel.set(xProp->getPropertyValue(sModel),uno::UNO_QUERY);
152cdf0e10cSrcweir                 if ( m_xChartModel.is() )
153cdf0e10cSrcweir                     m_xFormComponent = m_xChartModel->getDataProvider();
154cdf0e10cSrcweir             }
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir         m_xDataProvider.set(m_xFormComponent,uno::UNO_QUERY);
157cdf0e10cSrcweir         m_xReportComponent.set( xNameCont->getByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ReportComponent" ) ) ), uno::UNO_QUERY );
158cdf0e10cSrcweir         if ( m_xDataProvider.is() )
159cdf0e10cSrcweir         {
160cdf0e10cSrcweir             ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
161cdf0e10cSrcweir             TPropertyNamePair aPropertyMediation;
162cdf0e10cSrcweir             aPropertyMediation.insert( TPropertyNamePair::value_type( PROPERTY_MASTERFIELDS, TPropertyConverter(PROPERTY_MASTERFIELDS,aNoConverter) ) );
163cdf0e10cSrcweir             aPropertyMediation.insert( TPropertyNamePair::value_type( PROPERTY_DETAILFIELDS, TPropertyConverter(PROPERTY_DETAILFIELDS,aNoConverter) ) );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir             m_xMasterDetails = new OPropertyMediator( m_xDataProvider.get(), m_xReportComponent.get(), aPropertyMediation,sal_True );
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         //const ::rtl::OUString sRowSet(RTL_CONSTASCII_USTRINGPARAM("RowSet"));
169cdf0e10cSrcweir         //if ( xNameCont->hasByName(sRowSet) )
170cdf0e10cSrcweir         //{
171cdf0e10cSrcweir         //    uno::Reference<beans::XPropertySet> xProp(m_xFormComponentHandler,uno::UNO_QUERY);
172cdf0e10cSrcweir         //    xProp->setPropertyValue(sRowSet,xNameCont->getByName(sRowSet));
173cdf0e10cSrcweir         //}
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir     catch(uno::Exception)
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         throw lang::NullPointerException();
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir     if ( m_xFormComponent.is() )
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         m_xFormComponentHandler->inspect(m_xFormComponent);
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir uno::Any SAL_CALL DataProviderHandler::getPropertyValue(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
188cdf0e10cSrcweir     uno::Any aPropertyValue;
189cdf0e10cSrcweir     const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
190cdf0e10cSrcweir     switch(nId)
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         case PROPERTY_ID_CHARTTYPE:
193*30acf5e8Spfg             // TODO: We need a possibility to get the UI of the selected chart type
194cdf0e10cSrcweir             //if( m_xChartModel.is() )
195cdf0e10cSrcweir             //{
196cdf0e10cSrcweir             //    uno::Reference< chart2::XDiagram > xDiagram( m_xChartModel->getFirstDiagram() );
197cdf0e10cSrcweir             //    if( xDiagram.is() )
198cdf0e10cSrcweir             //    {
199cdf0e10cSrcweir             //        ::rtl::OUString sChartTypes;
200cdf0e10cSrcweir             //        uno::Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
201cdf0e10cSrcweir             //        const uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
202cdf0e10cSrcweir             //        const uno::Reference< chart2::XCoordinateSystem >* pIter = aCooSysSeq.getConstArray();
203cdf0e10cSrcweir             //        const uno::Reference< chart2::XCoordinateSystem >* pEnd	  = pIter + aCooSysSeq.getLength();
204cdf0e10cSrcweir             //        for(;pIter != pEnd;++pIter)
205cdf0e10cSrcweir             //        {
206cdf0e10cSrcweir             //            const uno::Reference< chart2::XChartTypeContainer > xCTCnt( *pIter, uno::UNO_QUERY_THROW );
207cdf0e10cSrcweir             //            const uno::Sequence< uno::Reference< chart2::XChartType > > aCTSeq( xCTCnt->getChartTypes());
208cdf0e10cSrcweir             //            const uno::Reference< chart2::XChartType >* pChartTypeIter = aCTSeq.getConstArray();
209cdf0e10cSrcweir             //            const uno::Reference< chart2::XChartType >* pChartTypeEnd  = pChartTypeIter + aCTSeq.getLength();
210cdf0e10cSrcweir             //            for(;pChartTypeIter != pChartTypeEnd;++pChartTypeIter)
211cdf0e10cSrcweir             //            {
212cdf0e10cSrcweir             //                sChartTypes += (*pChartTypeIter)->getChartType();
213cdf0e10cSrcweir             //                sChartTypes += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";"));
214cdf0e10cSrcweir             //            }
215cdf0e10cSrcweir             //        }
216cdf0e10cSrcweir             //        aPropertyValue;// <<= sChartTypes;
217cdf0e10cSrcweir             //    }
218cdf0e10cSrcweir             //}
219cdf0e10cSrcweir             break;
220cdf0e10cSrcweir         case PROPERTY_ID_PREVIEW_COUNT:
221cdf0e10cSrcweir             aPropertyValue <<= m_xDataProvider->getRowLimit();
222cdf0e10cSrcweir             break;
223cdf0e10cSrcweir         default:
224cdf0e10cSrcweir             aPropertyValue = m_xFormComponentHandler->getPropertyValue( PropertyName );
225cdf0e10cSrcweir             break;
226cdf0e10cSrcweir     }
227cdf0e10cSrcweir     return aPropertyValue;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir void SAL_CALL DataProviderHandler::setPropertyValue(const ::rtl::OUString & PropertyName, const uno::Any & Value) throw (uno::RuntimeException, beans::UnknownPropertyException)
231cdf0e10cSrcweir {
232cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
233cdf0e10cSrcweir     uno::Any aPropertyValue;
234cdf0e10cSrcweir     const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
235cdf0e10cSrcweir     switch(nId)
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         case PROPERTY_ID_CHARTTYPE:
238cdf0e10cSrcweir             break;
239cdf0e10cSrcweir         case PROPERTY_ID_PREVIEW_COUNT:
240cdf0e10cSrcweir             m_xDataProvider->setPropertyValue(PropertyName,Value);
241cdf0e10cSrcweir             break;
242cdf0e10cSrcweir         default:
243cdf0e10cSrcweir             m_xFormComponentHandler->setPropertyValue(PropertyName, Value);
244cdf0e10cSrcweir             break;
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir }
247cdf0e10cSrcweir // -----------------------------------------------------------------------------
248cdf0e10cSrcweir void DataProviderHandler::impl_updateChartTitle_throw(const uno::Any& _aValue)
249cdf0e10cSrcweir {
250cdf0e10cSrcweir     uno::Reference<chart2::XTitled> xTitled(m_xChartModel,uno::UNO_QUERY);
251cdf0e10cSrcweir     if ( xTitled.is() )
252cdf0e10cSrcweir     {
253cdf0e10cSrcweir         uno::Reference<chart2::XTitle> xTitle = xTitled->getTitleObject();
254cdf0e10cSrcweir         if ( !xTitle.is() )
255cdf0e10cSrcweir         {
256cdf0e10cSrcweir             xTitle.set(m_xContext->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.Title")),m_xContext),uno::UNO_QUERY);
257cdf0e10cSrcweir             xTitled->setTitleObject(xTitle);
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir         if ( xTitle.is() )
260cdf0e10cSrcweir         {
261cdf0e10cSrcweir             uno::Reference< chart2::XFormattedString> xFormatted(m_xContext->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.FormattedString")),m_xContext),uno::UNO_QUERY);
262cdf0e10cSrcweir             ::rtl::OUString sStr;
263cdf0e10cSrcweir             _aValue>>= sStr;
264cdf0e10cSrcweir             xFormatted->setString(sStr);
265cdf0e10cSrcweir             uno::Sequence< uno::Reference< chart2::XFormattedString> > aArgs(1);
266cdf0e10cSrcweir             aArgs[0] = xFormatted;
267cdf0e10cSrcweir             xTitle->setText(aArgs);
268cdf0e10cSrcweir         }
269cdf0e10cSrcweir     } // if ( xTitled.is() )
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir beans::PropertyState SAL_CALL DataProviderHandler::getPropertyState(const ::rtl::OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     return m_xFormComponentHandler->getPropertyState(PropertyName);
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir inspection::LineDescriptor SAL_CALL DataProviderHandler::describePropertyLine(const ::rtl::OUString & PropertyName,  const uno::Reference< inspection::XPropertyControlFactory > & _xControlFactory) throw (beans::UnknownPropertyException, lang::NullPointerException,uno::RuntimeException)
278cdf0e10cSrcweir {
279cdf0e10cSrcweir     inspection::LineDescriptor aOut;
280cdf0e10cSrcweir     const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
281cdf0e10cSrcweir     switch(nId)
282cdf0e10cSrcweir     {
283cdf0e10cSrcweir         case PROPERTY_ID_CHARTTYPE:
284cdf0e10cSrcweir             aOut.PrimaryButtonId = rtl::OUString::createFromAscii(UID_RPT_PROP_CHARTTYPE_DLG);
285cdf0e10cSrcweir             aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::TextField , sal_True);
286cdf0e10cSrcweir             aOut.HasPrimaryButton = sal_True;
287cdf0e10cSrcweir             break;
288cdf0e10cSrcweir         case PROPERTY_ID_PREVIEW_COUNT:
289cdf0e10cSrcweir             aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::NumericField , sal_False);
290cdf0e10cSrcweir             break;
291cdf0e10cSrcweir         case PROPERTY_ID_MASTERFIELDS:
292cdf0e10cSrcweir         case PROPERTY_ID_DETAILFIELDS:
293cdf0e10cSrcweir             aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::StringListField , sal_False);
294cdf0e10cSrcweir             aOut.PrimaryButtonId = rtl::OUString::createFromAscii(UID_RPT_PROP_DLG_LINKFIELDS);
295cdf0e10cSrcweir             aOut.HasPrimaryButton = sal_True;
296cdf0e10cSrcweir             break;
297cdf0e10cSrcweir         default:
298cdf0e10cSrcweir             aOut = m_xFormComponentHandler->describePropertyLine(PropertyName, _xControlFactory);
299cdf0e10cSrcweir     }
300cdf0e10cSrcweir     if ( nId != -1 )
301cdf0e10cSrcweir     {
302cdf0e10cSrcweir         aOut.Category = ((m_pInfoService->getPropertyUIFlags(nId ) & PROP_FLAG_DATA_PROPERTY) != 0) ?
303cdf0e10cSrcweir                                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Data"))
304cdf0e10cSrcweir                                                         :
305cdf0e10cSrcweir                                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("General"));
306cdf0e10cSrcweir         aOut.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nId ) );
307cdf0e10cSrcweir         aOut.DisplayName = m_pInfoService->getPropertyTranslation(nId);
308cdf0e10cSrcweir     }
309cdf0e10cSrcweir     return aOut;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir uno::Any SAL_CALL DataProviderHandler::convertToPropertyValue(const ::rtl::OUString & _rPropertyValue, const uno::Any & _rControlValue) throw (uno::RuntimeException, beans::UnknownPropertyException)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
315cdf0e10cSrcweir     uno::Any aPropertyValue( _rControlValue );
316cdf0e10cSrcweir     const sal_Int32 nId = m_pInfoService->getPropertyId(_rPropertyValue);
317cdf0e10cSrcweir     switch(nId)
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir         case PROPERTY_ID_CHARTTYPE:
320cdf0e10cSrcweir             break;
321cdf0e10cSrcweir         case PROPERTY_ID_PREVIEW_COUNT:
322cdf0e10cSrcweir             try
323cdf0e10cSrcweir             {
324cdf0e10cSrcweir                 aPropertyValue = m_xTypeConverter->convertTo( _rControlValue, ::getCppuType((const sal_Int32*)0));
325cdf0e10cSrcweir             }
326cdf0e10cSrcweir             catch( const uno::Exception& )
327cdf0e10cSrcweir             {
328cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "DataProviderHandler::convertToPropertyValue: caught an exception while converting via TypeConverter!" );
329cdf0e10cSrcweir             }
330cdf0e10cSrcweir             break;
331cdf0e10cSrcweir         case PROPERTY_ID_MASTERFIELDS:
332cdf0e10cSrcweir         case PROPERTY_ID_DETAILFIELDS:
333cdf0e10cSrcweir             break;
334cdf0e10cSrcweir         default:
335cdf0e10cSrcweir             aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(_rPropertyValue, _rControlValue);
336cdf0e10cSrcweir     }
337cdf0e10cSrcweir     return aPropertyValue;
338cdf0e10cSrcweir }
339cdf0e10cSrcweir 
340cdf0e10cSrcweir uno::Any SAL_CALL DataProviderHandler::convertToControlValue(const ::rtl::OUString & _rPropertyName, const uno::Any & _rPropertyValue, const uno::Type & ControlValueType) throw (uno::RuntimeException, beans::UnknownPropertyException)
341cdf0e10cSrcweir {
342cdf0e10cSrcweir     uno::Any aControlValue( _rPropertyValue );
343cdf0e10cSrcweir     if ( !aControlValue.hasValue() )
344cdf0e10cSrcweir         // NULL is converted to NULL
345cdf0e10cSrcweir         return aControlValue;
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
348cdf0e10cSrcweir     const sal_Int32 nId = m_pInfoService->getPropertyId(_rPropertyName);
349cdf0e10cSrcweir     switch(nId)
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         case PROPERTY_ID_CHARTTYPE:
352cdf0e10cSrcweir             break;
353cdf0e10cSrcweir         case PROPERTY_ID_MASTERFIELDS:
354cdf0e10cSrcweir         case PROPERTY_ID_DETAILFIELDS:
355cdf0e10cSrcweir         case PROPERTY_ID_PREVIEW_COUNT:
356cdf0e10cSrcweir             try
357cdf0e10cSrcweir             {
358cdf0e10cSrcweir                 aControlValue = m_xTypeConverter->convertTo( _rPropertyValue, ControlValueType);
359cdf0e10cSrcweir             }
360cdf0e10cSrcweir             catch( const uno::Exception& )
361cdf0e10cSrcweir             {
362cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "GeometryHandler::convertToPropertyValue: caught an exception while converting via TypeConverter!" );
363cdf0e10cSrcweir             }
364cdf0e10cSrcweir             break;
365cdf0e10cSrcweir         default:
366cdf0e10cSrcweir             aControlValue = m_xFormComponentHandler->convertToControlValue(_rPropertyName, _rPropertyValue, ControlValueType);
367cdf0e10cSrcweir     }
368cdf0e10cSrcweir     return aControlValue;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir void SAL_CALL DataProviderHandler::addPropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & Listener) throw (uno::RuntimeException, lang::NullPointerException)
372cdf0e10cSrcweir {
373cdf0e10cSrcweir     m_xFormComponentHandler->addPropertyChangeListener(Listener);
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir void SAL_CALL DataProviderHandler::removePropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException)
377cdf0e10cSrcweir {
378cdf0e10cSrcweir     m_xFormComponentHandler->removePropertyChangeListener(_rxListener);
379cdf0e10cSrcweir }
380cdf0e10cSrcweir 
381cdf0e10cSrcweir uno::Sequence< beans::Property > SAL_CALL DataProviderHandler::getSupportedProperties() throw (uno::RuntimeException)
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     ::std::vector< beans::Property > aNewProps;
384cdf0e10cSrcweir     if( m_xChartModel.is() )
385cdf0e10cSrcweir     {
386cdf0e10cSrcweir         m_pInfoService->getExcludeProperties( aNewProps, m_xFormComponentHandler );
387cdf0e10cSrcweir         beans::Property aValue;
388cdf0e10cSrcweir         static const ::rtl::OUString s_pProperties[] =
389cdf0e10cSrcweir         {
390cdf0e10cSrcweir              PROPERTY_CHARTTYPE
391cdf0e10cSrcweir             ,PROPERTY_MASTERFIELDS
392cdf0e10cSrcweir             ,PROPERTY_DETAILFIELDS
393cdf0e10cSrcweir             ,PROPERTY_PREVIEW_COUNT
394cdf0e10cSrcweir             //,PROPERTY_TITLE
395cdf0e10cSrcweir         };
396cdf0e10cSrcweir 
397cdf0e10cSrcweir         for (size_t nPos = 0; nPos < sizeof(s_pProperties)/sizeof(s_pProperties[0]) ;++nPos )
398cdf0e10cSrcweir         {
399cdf0e10cSrcweir             aValue.Name = s_pProperties[nPos];
400cdf0e10cSrcweir             aNewProps.push_back(aValue);
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir     }
403cdf0e10cSrcweir     return aNewProps.empty() ? uno::Sequence< beans::Property > () : uno::Sequence< beans::Property > (&(*aNewProps.begin()),aNewProps.size());
404cdf0e10cSrcweir }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL DataProviderHandler::getSupersededProperties() throw (uno::RuntimeException)
407cdf0e10cSrcweir {
408cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aRet(1);
409cdf0e10cSrcweir     aRet[0] = PROPERTY_TITLE; // have a look at OPropertyInfoService::getExcludeProperties
410cdf0e10cSrcweir     return aRet;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL DataProviderHandler::getActuatingProperties() throw (uno::RuntimeException)
414cdf0e10cSrcweir {
415cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aSeq(1);
418cdf0e10cSrcweir     aSeq[0] = PROPERTY_TITLE;
419cdf0e10cSrcweir     return ::comphelper::concatSequences(m_xFormComponentHandler->getActuatingProperties(),aSeq);
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
422cdf0e10cSrcweir ::sal_Bool SAL_CALL DataProviderHandler::isComposable( const ::rtl::OUString& _rPropertyName ) throw (uno::RuntimeException, beans::UnknownPropertyException)
423cdf0e10cSrcweir {
424cdf0e10cSrcweir     return m_pInfoService->isComposable( _rPropertyName, m_xFormComponentHandler );
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir inspection::InteractiveSelectionResult SAL_CALL DataProviderHandler::onInteractivePropertySelection(const ::rtl::OUString & PropertyName, ::sal_Bool Primary, uno::Any & out_Data, const uno::Reference< inspection::XObjectInspectorUI > & _rxInspectorUI) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::NullPointerException)
428cdf0e10cSrcweir {
429cdf0e10cSrcweir     if ( !_rxInspectorUI.is() )
430cdf0e10cSrcweir         throw lang::NullPointerException();
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
433cdf0e10cSrcweir     ::osl::ClearableMutexGuard aGuard( m_aMutex );
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
436cdf0e10cSrcweir     switch(nId)
437cdf0e10cSrcweir     {
438cdf0e10cSrcweir         case PROPERTY_ID_CHARTTYPE:
439cdf0e10cSrcweir             if ( impl_dialogChartType_nothrow(aGuard) )
440cdf0e10cSrcweir                 eResult = inspection::InteractiveSelectionResult_ObtainedValue;
441cdf0e10cSrcweir             break;
442cdf0e10cSrcweir         case PROPERTY_ID_MASTERFIELDS:
443cdf0e10cSrcweir         case PROPERTY_ID_DETAILFIELDS:
444cdf0e10cSrcweir             if ( impl_dialogLinkedFields_nothrow( aGuard ) )
445cdf0e10cSrcweir                 eResult = inspection::InteractiveSelectionResult_Success;
446cdf0e10cSrcweir             break;
447cdf0e10cSrcweir         default:
448cdf0e10cSrcweir             eResult = m_xFormComponentHandler->onInteractivePropertySelection(PropertyName, Primary, out_Data, _rxInspectorUI);
449cdf0e10cSrcweir     }
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     return eResult;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir void SAL_CALL DataProviderHandler::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)
455cdf0e10cSrcweir {
456cdf0e10cSrcweir     ::osl::ClearableMutexGuard aGuard( m_aMutex );
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     if ( ActuatingPropertyName == PROPERTY_COMMAND )
459cdf0e10cSrcweir     {
460cdf0e10cSrcweir         if ( NewValue != OldValue )
461cdf0e10cSrcweir         {
462cdf0e10cSrcweir             uno::Reference< report::XReportDefinition> xReport = m_xReportComponent->getSection()->getReportDefinition();
463cdf0e10cSrcweir             bool bDoEnableMasterDetailFields = xReport.is() && xReport->getCommand().getLength() && m_xDataProvider->getCommand().getLength();
464cdf0e10cSrcweir             InspectorUI->enablePropertyUIElements( PROPERTY_DETAILFIELDS, inspection::PropertyLineElement::PrimaryButton, bDoEnableMasterDetailFields );
465cdf0e10cSrcweir             InspectorUI->enablePropertyUIElements( PROPERTY_MASTERFIELDS, inspection::PropertyLineElement::PrimaryButton, bDoEnableMasterDetailFields );
466cdf0e10cSrcweir 
467cdf0e10cSrcweir             sal_Bool bModified = xReport->isModified();
468cdf0e10cSrcweir             // this fills the chart again
469cdf0e10cSrcweir             ::comphelper::NamedValueCollection aArgs;
470cdf0e10cSrcweir             aArgs.put( "CellRangeRepresentation", uno::makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "all" ) ) ) );
471cdf0e10cSrcweir             aArgs.put( "HasCategories", uno::makeAny( sal_True ) );
472cdf0e10cSrcweir             aArgs.put( "FirstCellAsLabel", uno::makeAny( sal_True ) );
473cdf0e10cSrcweir             aArgs.put( "DataRowSource", uno::makeAny( chart::ChartDataRowSource_COLUMNS ) );
474cdf0e10cSrcweir             uno::Reference< chart2::data::XDataReceiver > xReceiver(m_xChartModel,uno::UNO_QUERY_THROW);
475cdf0e10cSrcweir             xReceiver->setArguments( aArgs.getPropertyValues() );
476cdf0e10cSrcweir             if ( !bModified )
477cdf0e10cSrcweir                 xReport->setModified(sal_False);
478cdf0e10cSrcweir         } // if ( NewValue != OldValue )
479cdf0e10cSrcweir         m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, InspectorUI, FirstTimeInit);
480cdf0e10cSrcweir     } // if ( ActuatingPropertyName == PROPERTY_COMMAND )
481cdf0e10cSrcweir     else if ( ActuatingPropertyName == PROPERTY_TITLE )
482cdf0e10cSrcweir     {
483cdf0e10cSrcweir         if ( NewValue != OldValue )
484cdf0e10cSrcweir             impl_updateChartTitle_throw(NewValue);
485cdf0e10cSrcweir     }
486cdf0e10cSrcweir     else
487cdf0e10cSrcweir     {
488cdf0e10cSrcweir         const sal_Int32 nId = m_pInfoService->getPropertyId(ActuatingPropertyName);
489cdf0e10cSrcweir         switch(nId)
490cdf0e10cSrcweir         {
491cdf0e10cSrcweir 
492cdf0e10cSrcweir             case PROPERTY_ID_MASTERFIELDS:
493cdf0e10cSrcweir                 break;
494cdf0e10cSrcweir             case PROPERTY_ID_DETAILFIELDS:
495cdf0e10cSrcweir                 break;
496cdf0e10cSrcweir             default:
497cdf0e10cSrcweir                 m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, InspectorUI, FirstTimeInit);
498cdf0e10cSrcweir         }
499cdf0e10cSrcweir     }
500cdf0e10cSrcweir }
501cdf0e10cSrcweir 
502cdf0e10cSrcweir ::sal_Bool SAL_CALL DataProviderHandler::suspend(::sal_Bool Suspend) throw (uno::RuntimeException)
503cdf0e10cSrcweir {
504cdf0e10cSrcweir     return m_xFormComponentHandler->suspend(Suspend);
505cdf0e10cSrcweir }
506cdf0e10cSrcweir bool DataProviderHandler::impl_dialogLinkedFields_nothrow( ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     uno::Sequence<uno::Any> aSeq(6);
509cdf0e10cSrcweir     beans::PropertyValue aParam;
510cdf0e10cSrcweir     aParam.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow"));
511cdf0e10cSrcweir     aParam.Value <<= m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow")));
512cdf0e10cSrcweir     aSeq[0] <<= aParam;
513cdf0e10cSrcweir     aParam.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Detail"));
514cdf0e10cSrcweir     aParam.Value <<= m_xDataProvider;
515cdf0e10cSrcweir     aSeq[1] <<= aParam;
516cdf0e10cSrcweir     aParam.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Master"));
517cdf0e10cSrcweir     aParam.Value <<= m_xReportComponent->getSection()->getReportDefinition();
518cdf0e10cSrcweir     aSeq[2] <<= aParam;
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     aParam.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Explanation"));
521cdf0e10cSrcweir     aParam.Value <<= ::rtl::OUString(String(ModuleRes(RID_STR_EXPLANATION)));
522cdf0e10cSrcweir     aSeq[3] <<= aParam;
523cdf0e10cSrcweir     aParam.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DetailLabel"));
524cdf0e10cSrcweir     aParam.Value <<= ::rtl::OUString(String(ModuleRes(RID_STR_DETAILLABEL)));
525cdf0e10cSrcweir     aSeq[4] <<= aParam;
526cdf0e10cSrcweir     aParam.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MasterLabel"));
527cdf0e10cSrcweir     aParam.Value <<= ::rtl::OUString(String(ModuleRes(RID_STR_MASTERLABEL)));
528cdf0e10cSrcweir     aSeq[5] <<= aParam;
529cdf0e10cSrcweir 
530cdf0e10cSrcweir     uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
531cdf0e10cSrcweir         m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
532cdf0e10cSrcweir         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.form.ui.MasterDetailLinkDialog")),aSeq
533cdf0e10cSrcweir             , m_xContext), uno::UNO_QUERY);
534cdf0e10cSrcweir 
535cdf0e10cSrcweir     _rClearBeforeDialog.clear();
536cdf0e10cSrcweir     return ( xDialog->execute() != 0 );
537cdf0e10cSrcweir }
538cdf0e10cSrcweir // -----------------------------------------------------------------------------
539cdf0e10cSrcweir bool DataProviderHandler::impl_dialogChartType_nothrow( ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const
540cdf0e10cSrcweir {
541cdf0e10cSrcweir     uno::Sequence<uno::Any> aSeq(2);
542cdf0e10cSrcweir     beans::PropertyValue aParam;
543cdf0e10cSrcweir     aParam.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow"));
544cdf0e10cSrcweir     aParam.Value <<= m_xContext->getValueByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DialogParentWindow")));
545cdf0e10cSrcweir     aSeq[0] <<= aParam;
546cdf0e10cSrcweir     aParam.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ChartModel"));
547cdf0e10cSrcweir     aParam.Value <<= m_xChartModel;
548cdf0e10cSrcweir     aSeq[1] <<= aParam;
549cdf0e10cSrcweir 
550cdf0e10cSrcweir     uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
551cdf0e10cSrcweir         m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
552cdf0e10cSrcweir         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.chart2.ChartTypeDialog")),aSeq
553cdf0e10cSrcweir             , m_xContext), uno::UNO_QUERY);
554cdf0e10cSrcweir 
555cdf0e10cSrcweir     _rClearBeforeDialog.clear();
556cdf0e10cSrcweir     return ( xDialog->execute() != 0 );
557cdf0e10cSrcweir }
558cdf0e10cSrcweir //........................................................................
559cdf0e10cSrcweir } // namespace rptui
560cdf0e10cSrcweir //........................................................................
561cdf0e10cSrcweir 
562