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