xref: /AOO41X/main/reportdesign/source/ui/inspection/DefaultInspection.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "DefaultInspection.hxx"
29*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
30*cdf0e10cSrcweir #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
32*cdf0e10cSrcweir #ifndef _REPORT_DLGRESID_HRC
33*cdf0e10cSrcweir #include <RptResId.hrc>
34*cdf0e10cSrcweir #endif
35*cdf0e10cSrcweir #include "ModuleHelper.hxx"
36*cdf0e10cSrcweir #ifndef RTPUI_REPORTDESIGN_HELPID_HRC
37*cdf0e10cSrcweir #include "helpids.hrc"
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
40*cdf0e10cSrcweir #include <osl/diagnose.h>
41*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
42*cdf0e10cSrcweir #include <tools/debug.hxx>
43*cdf0e10cSrcweir #include "metadata.hxx"
44*cdf0e10cSrcweir #include <tools/urlobj.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //........................................................................
47*cdf0e10cSrcweir namespace rptui
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir //........................................................................
50*cdf0e10cSrcweir 	//------------------------------------------------------------------------
51*cdf0e10cSrcweir     ::rtl::OUString HelpIdUrl::getHelpURL( const rtl::OString& sHelpId )
52*cdf0e10cSrcweir     {
53*cdf0e10cSrcweir         ::rtl::OUStringBuffer aBuffer;
54*cdf0e10cSrcweir         ::rtl::OUString aTmp( sHelpId, sHelpId.getLength(), RTL_TEXTENCODING_UTF8 );
55*cdf0e10cSrcweir         DBG_ASSERT( INetURLObject( aTmp ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" );
56*cdf0e10cSrcweir         aBuffer.appendAscii( INET_HID_SCHEME );
57*cdf0e10cSrcweir         aBuffer.append( aTmp.getStr() );
58*cdf0e10cSrcweir         return aBuffer.makeStringAndClear();
59*cdf0e10cSrcweir     }
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir     /** === begin UNO using === **/
62*cdf0e10cSrcweir     using namespace com::sun::star::uno;
63*cdf0e10cSrcweir     using namespace com::sun::star;
64*cdf0e10cSrcweir     using com::sun::star::inspection::PropertyCategoryDescriptor;
65*cdf0e10cSrcweir     /** === end UNO using === **/
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 	//====================================================================
68*cdf0e10cSrcweir 	//= DefaultComponentInspectorModel
69*cdf0e10cSrcweir 	//====================================================================
70*cdf0e10cSrcweir     DBG_NAME(DefaultComponentInspectorModel)
71*cdf0e10cSrcweir 	//--------------------------------------------------------------------
72*cdf0e10cSrcweir     DefaultComponentInspectorModel::DefaultComponentInspectorModel( const Reference< XComponentContext >& _rxContext)
73*cdf0e10cSrcweir         :m_xContext( _rxContext )
74*cdf0e10cSrcweir         ,m_bConstructed( false )
75*cdf0e10cSrcweir         ,m_bHasHelpSection( false )
76*cdf0e10cSrcweir         ,m_bIsReadOnly(sal_False)
77*cdf0e10cSrcweir         ,m_nMinHelpTextLines( 3 )
78*cdf0e10cSrcweir         ,m_nMaxHelpTextLines( 8 )
79*cdf0e10cSrcweir         ,m_pInfoService(new OPropertyInfoService())
80*cdf0e10cSrcweir     {
81*cdf0e10cSrcweir         DBG_CTOR(DefaultComponentInspectorModel,NULL);
82*cdf0e10cSrcweir     }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     //------------------------------------------------------------------------
85*cdf0e10cSrcweir     DefaultComponentInspectorModel::~DefaultComponentInspectorModel()
86*cdf0e10cSrcweir     {
87*cdf0e10cSrcweir         DBG_DTOR(DefaultComponentInspectorModel,NULL);
88*cdf0e10cSrcweir     }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 	//------------------------------------------------------------------------
91*cdf0e10cSrcweir 	::rtl::OUString SAL_CALL DefaultComponentInspectorModel::getImplementationName(  ) throw(RuntimeException)
92*cdf0e10cSrcweir 	{
93*cdf0e10cSrcweir 		return getImplementationName_Static();
94*cdf0e10cSrcweir 	}
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	//------------------------------------------------------------------------
97*cdf0e10cSrcweir 	sal_Bool SAL_CALL DefaultComponentInspectorModel::supportsService( const ::rtl::OUString& ServiceName ) throw(RuntimeException)
98*cdf0e10cSrcweir 	{
99*cdf0e10cSrcweir 		return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static());
100*cdf0e10cSrcweir 	}
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 	//------------------------------------------------------------------------
103*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > SAL_CALL DefaultComponentInspectorModel::getSupportedServiceNames(  ) throw(RuntimeException)
104*cdf0e10cSrcweir 	{
105*cdf0e10cSrcweir 		return getSupportedServiceNames_static();
106*cdf0e10cSrcweir 	}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	//------------------------------------------------------------------------
109*cdf0e10cSrcweir 	::rtl::OUString DefaultComponentInspectorModel::getImplementationName_Static(  ) throw(RuntimeException)
110*cdf0e10cSrcweir 	{
111*cdf0e10cSrcweir         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.DefaultComponentInspectorModel"));
112*cdf0e10cSrcweir 	}
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	//------------------------------------------------------------------------
115*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > DefaultComponentInspectorModel::getSupportedServiceNames_static(  ) throw(RuntimeException)
116*cdf0e10cSrcweir 	{
117*cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aSupported(1);
118*cdf0e10cSrcweir         aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.DefaultComponentInspectorModel"));
119*cdf0e10cSrcweir 		return aSupported;
120*cdf0e10cSrcweir 	}
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	//------------------------------------------------------------------------
123*cdf0e10cSrcweir 	Reference< XInterface > SAL_CALL DefaultComponentInspectorModel::create( const Reference< XComponentContext >& _rxContext )
124*cdf0e10cSrcweir 	{
125*cdf0e10cSrcweir 		return *(new DefaultComponentInspectorModel( _rxContext ));
126*cdf0e10cSrcweir 	}
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     //--------------------------------------------------------------------
129*cdf0e10cSrcweir     Sequence< Any > SAL_CALL DefaultComponentInspectorModel::getHandlerFactories() throw (RuntimeException)
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         // service names for all our handlers
135*cdf0e10cSrcweir         const struct
136*cdf0e10cSrcweir         {
137*cdf0e10cSrcweir             const sal_Char* serviceName;
138*cdf0e10cSrcweir         } aFactories[] = {
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir             { "com.sun.star.report.inspection.ReportComponentHandler"},
141*cdf0e10cSrcweir             { "com.sun.star.form.inspection.EditPropertyHandler"},
142*cdf0e10cSrcweir             { "com.sun.star.report.inspection.DataProviderHandler"},
143*cdf0e10cSrcweir             { "com.sun.star.report.inspection.GeometryHandler"}
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir             // generic virtual edit properties
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir         };
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir         const size_t nFactories = sizeof( aFactories ) / sizeof( aFactories[ 0 ] );
150*cdf0e10cSrcweir         Sequence< Any > aReturn( nFactories );
151*cdf0e10cSrcweir         Any* pReturn = aReturn.getArray();
152*cdf0e10cSrcweir         for ( size_t i = 0; i < nFactories; ++i )
153*cdf0e10cSrcweir         {
154*cdf0e10cSrcweir             *pReturn++ <<= ::rtl::OUString::createFromAscii( aFactories[i].serviceName );
155*cdf0e10cSrcweir         }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir         return aReturn;
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir     //--------------------------------------------------------------------
160*cdf0e10cSrcweir     ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getHasHelpSection() throw (RuntimeException)
161*cdf0e10cSrcweir     {
162*cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
163*cdf0e10cSrcweir         return m_bHasHelpSection;
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     //--------------------------------------------------------------------
167*cdf0e10cSrcweir     ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMinHelpTextLines() throw (RuntimeException)
168*cdf0e10cSrcweir     {
169*cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
170*cdf0e10cSrcweir         return m_nMinHelpTextLines;
171*cdf0e10cSrcweir     }
172*cdf0e10cSrcweir     //--------------------------------------------------------------------
173*cdf0e10cSrcweir     ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException)
174*cdf0e10cSrcweir     {
175*cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
176*cdf0e10cSrcweir         return m_bIsReadOnly;
177*cdf0e10cSrcweir     }
178*cdf0e10cSrcweir     //--------------------------------------------------------------------
179*cdf0e10cSrcweir     void SAL_CALL DefaultComponentInspectorModel::setIsReadOnly( ::sal_Bool _isreadonly ) throw (::com::sun::star::uno::RuntimeException)
180*cdf0e10cSrcweir     {
181*cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
182*cdf0e10cSrcweir         m_bIsReadOnly = _isreadonly;
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     //--------------------------------------------------------------------
186*cdf0e10cSrcweir     ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMaxHelpTextLines() throw (RuntimeException)
187*cdf0e10cSrcweir     {
188*cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
189*cdf0e10cSrcweir         return m_nMaxHelpTextLines;
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir     //--------------------------------------------------------------------
192*cdf0e10cSrcweir     void SAL_CALL DefaultComponentInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException)
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
195*cdf0e10cSrcweir         if ( m_bConstructed )
196*cdf0e10cSrcweir             throw ucb::AlreadyInitializedException();
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir         if ( !_arguments.hasElements() )
199*cdf0e10cSrcweir         {   // constructor: "createDefault()"
200*cdf0e10cSrcweir             createDefault();
201*cdf0e10cSrcweir             return;
202*cdf0e10cSrcweir         }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir         sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
205*cdf0e10cSrcweir         if ( _arguments.getLength() == 2 )
206*cdf0e10cSrcweir         {   // constructor: "createWithHelpSection( long, long )"
207*cdf0e10cSrcweir             if ( !( _arguments[0] >>= nMinHelpTextLines ) || !( _arguments[1] >>= nMaxHelpTextLines ) )
208*cdf0e10cSrcweir                 throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
209*cdf0e10cSrcweir             createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines );
210*cdf0e10cSrcweir             return;
211*cdf0e10cSrcweir         }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir         throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
214*cdf0e10cSrcweir     }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir     //--------------------------------------------------------------------
217*cdf0e10cSrcweir     void DefaultComponentInspectorModel::createDefault()
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir         m_bConstructed = true;
220*cdf0e10cSrcweir     }
221*cdf0e10cSrcweir     //--------------------------------------------------------------------
222*cdf0e10cSrcweir     void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
223*cdf0e10cSrcweir     {
224*cdf0e10cSrcweir         if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) )
225*cdf0e10cSrcweir             throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir         m_bHasHelpSection = true;
228*cdf0e10cSrcweir         m_nMinHelpTextLines = _nMinHelpTextLines;
229*cdf0e10cSrcweir         m_nMaxHelpTextLines = _nMaxHelpTextLines;
230*cdf0e10cSrcweir         m_bConstructed = true;
231*cdf0e10cSrcweir     }
232*cdf0e10cSrcweir     //--------------------------------------------------------------------
233*cdf0e10cSrcweir     Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultComponentInspectorModel::describeCategories(  ) throw (RuntimeException)
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir         const struct
238*cdf0e10cSrcweir         {
239*cdf0e10cSrcweir             const sal_Char* programmaticName;
240*cdf0e10cSrcweir             sal_uInt16          uiNameResId;
241*cdf0e10cSrcweir             rtl::OString    helpId;
242*cdf0e10cSrcweir         } aCategories[] = {
243*cdf0e10cSrcweir             { "General",    RID_STR_PROPPAGE_DEFAULT,   HID_RPT_PROPDLG_TAB_GENERAL },
244*cdf0e10cSrcweir             { "Data",       RID_STR_PROPPAGE_DATA,      HID_RPT_PROPDLG_TAB_DATA },
245*cdf0e10cSrcweir         };
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir         const size_t nCategories = sizeof( aCategories ) / sizeof( aCategories[0] );
248*cdf0e10cSrcweir         Sequence< PropertyCategoryDescriptor > aReturn( nCategories );
249*cdf0e10cSrcweir         PropertyCategoryDescriptor* pReturn = aReturn.getArray();
250*cdf0e10cSrcweir         for ( size_t i=0; i<nCategories; ++i, ++pReturn )
251*cdf0e10cSrcweir         {
252*cdf0e10cSrcweir             pReturn->ProgrammaticName = ::rtl::OUString::createFromAscii( aCategories[i].programmaticName );
253*cdf0e10cSrcweir             pReturn->UIName = String( ModuleRes( aCategories[i].uiNameResId ) );
254*cdf0e10cSrcweir             pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId );
255*cdf0e10cSrcweir         }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir         return aReturn;
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     //--------------------------------------------------------------------
261*cdf0e10cSrcweir     ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getPropertyOrderIndex( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException)
262*cdf0e10cSrcweir     {
263*cdf0e10cSrcweir         ::osl::MutexGuard aGuard(m_aMutex);
264*cdf0e10cSrcweir         const sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) );
265*cdf0e10cSrcweir         if ( nPropertyId != -1 )
266*cdf0e10cSrcweir             return nPropertyId;
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir         if ( !m_xComponent.is() )
269*cdf0e10cSrcweir             try
270*cdf0e10cSrcweir             {
271*cdf0e10cSrcweir                 m_xComponent.set(m_xContext->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.DefaultFormComponentInspectorModel")),m_xContext),UNO_QUERY_THROW);
272*cdf0e10cSrcweir             }
273*cdf0e10cSrcweir             catch(Exception)
274*cdf0e10cSrcweir             {
275*cdf0e10cSrcweir                 return 0;
276*cdf0e10cSrcweir             }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir         return m_xComponent->getPropertyOrderIndex(_rPropertyName);
279*cdf0e10cSrcweir     }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir //........................................................................
282*cdf0e10cSrcweir } // namespace rptui
283*cdf0e10cSrcweir //........................................................................
284*cdf0e10cSrcweir 
285