1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DefaultInspection.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "DefaultInspection.hxx"
32 #include <comphelper/sequence.hxx>
33 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
34 #include <com/sun/star/lang/IllegalArgumentException.hpp>
35 #ifndef _REPORT_DLGRESID_HRC
36 #include <RptResId.hrc>
38 #include "ModuleHelper.hxx"
39 #ifndef RTPUI_REPORTDESIGN_HELPID_HRC
40 #include "helpids.hrc"
42 #include <cppuhelper/implbase1.hxx>
43 #include <osl/diagnose.h>
44 #include <rtl/ustrbuf.hxx>
45 #include <tools/debug.hxx>
46 #include "metadata.hxx"
48 //........................................................................
51 //........................................................................
52 //------------------------------------------------------------------------
53 ::rtl::OUString
HelpIdUrl::getHelpURL( sal_uInt32 _nHelpId
)
55 ::rtl::OUStringBuffer aBuffer
;
56 aBuffer
.appendAscii( "HID:" );
57 aBuffer
.append( (sal_Int32
)_nHelpId
);
58 return aBuffer
.makeStringAndClear();
61 /** === begin UNO using === **/
62 using namespace com::sun::star::uno
;
63 using namespace com::sun::star
;
64 using com::sun::star::inspection::PropertyCategoryDescriptor
;
65 /** === end UNO using === **/
67 //====================================================================
68 //= DefaultComponentInspectorModel
69 //====================================================================
70 DBG_NAME(DefaultComponentInspectorModel
)
71 //--------------------------------------------------------------------
72 DefaultComponentInspectorModel::DefaultComponentInspectorModel( const Reference
< XComponentContext
>& _rxContext
)
73 :m_xContext( _rxContext
)
74 ,m_bConstructed( false )
75 ,m_bHasHelpSection( false )
76 ,m_bIsReadOnly(sal_False
)
77 ,m_nMinHelpTextLines( 3 )
78 ,m_nMaxHelpTextLines( 8 )
79 ,m_pInfoService(new OPropertyInfoService())
81 DBG_CTOR(DefaultComponentInspectorModel
,NULL
);
84 //------------------------------------------------------------------------
85 DefaultComponentInspectorModel::~DefaultComponentInspectorModel()
87 DBG_DTOR(DefaultComponentInspectorModel
,NULL
);
90 //------------------------------------------------------------------------
91 ::rtl::OUString SAL_CALL
DefaultComponentInspectorModel::getImplementationName( ) throw(RuntimeException
)
93 return getImplementationName_Static();
96 //------------------------------------------------------------------------
97 sal_Bool SAL_CALL
DefaultComponentInspectorModel::supportsService( const ::rtl::OUString
& ServiceName
) throw(RuntimeException
)
99 return ::comphelper::existsValue(ServiceName
,getSupportedServiceNames_static());
102 //------------------------------------------------------------------------
103 Sequence
< ::rtl::OUString
> SAL_CALL
DefaultComponentInspectorModel::getSupportedServiceNames( ) throw(RuntimeException
)
105 return getSupportedServiceNames_static();
108 //------------------------------------------------------------------------
109 ::rtl::OUString
DefaultComponentInspectorModel::getImplementationName_Static( ) throw(RuntimeException
)
111 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.DefaultComponentInspectorModel"));
114 //------------------------------------------------------------------------
115 Sequence
< ::rtl::OUString
> DefaultComponentInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException
)
117 Sequence
< ::rtl::OUString
> aSupported(1);
118 aSupported
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.DefaultComponentInspectorModel"));
122 //------------------------------------------------------------------------
123 Reference
< XInterface
> SAL_CALL
DefaultComponentInspectorModel::create( const Reference
< XComponentContext
>& _rxContext
)
125 return *(new DefaultComponentInspectorModel( _rxContext
));
128 //--------------------------------------------------------------------
129 Sequence
< Any
> SAL_CALL
DefaultComponentInspectorModel::getHandlerFactories() throw (RuntimeException
)
131 ::osl::MutexGuard
aGuard( m_aMutex
);
134 // service names for all our handlers
137 const sal_Char
* serviceName
;
140 { "com.sun.star.report.inspection.ReportComponentHandler"},
141 { "com.sun.star.form.inspection.EditPropertyHandler"},
142 { "com.sun.star.report.inspection.DataProviderHandler"},
143 { "com.sun.star.report.inspection.GeometryHandler"}
145 // generic virtual edit properties
149 const size_t nFactories
= sizeof( aFactories
) / sizeof( aFactories
[ 0 ] );
150 Sequence
< Any
> aReturn( nFactories
);
151 Any
* pReturn
= aReturn
.getArray();
152 for ( size_t i
= 0; i
< nFactories
; ++i
)
154 *pReturn
++ <<= ::rtl::OUString::createFromAscii( aFactories
[i
].serviceName
);
159 //--------------------------------------------------------------------
160 ::sal_Bool SAL_CALL
DefaultComponentInspectorModel::getHasHelpSection() throw (RuntimeException
)
162 ::osl::MutexGuard
aGuard(m_aMutex
);
163 return m_bHasHelpSection
;
166 //--------------------------------------------------------------------
167 ::sal_Int32 SAL_CALL
DefaultComponentInspectorModel::getMinHelpTextLines() throw (RuntimeException
)
169 ::osl::MutexGuard
aGuard(m_aMutex
);
170 return m_nMinHelpTextLines
;
172 //--------------------------------------------------------------------
173 ::sal_Bool SAL_CALL
DefaultComponentInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException
)
175 ::osl::MutexGuard
aGuard(m_aMutex
);
176 return m_bIsReadOnly
;
178 //--------------------------------------------------------------------
179 void SAL_CALL
DefaultComponentInspectorModel::setIsReadOnly( ::sal_Bool _isreadonly
) throw (::com::sun::star::uno::RuntimeException
)
181 ::osl::MutexGuard
aGuard(m_aMutex
);
182 m_bIsReadOnly
= _isreadonly
;
185 //--------------------------------------------------------------------
186 ::sal_Int32 SAL_CALL
DefaultComponentInspectorModel::getMaxHelpTextLines() throw (RuntimeException
)
188 ::osl::MutexGuard
aGuard(m_aMutex
);
189 return m_nMaxHelpTextLines
;
191 //--------------------------------------------------------------------
192 void SAL_CALL
DefaultComponentInspectorModel::initialize( const Sequence
< Any
>& _arguments
) throw (Exception
, RuntimeException
)
194 ::osl::MutexGuard
aGuard(m_aMutex
);
195 if ( m_bConstructed
)
196 throw ucb::AlreadyInitializedException();
198 if ( !_arguments
.hasElements() )
199 { // constructor: "createDefault()"
204 sal_Int32
nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
205 if ( _arguments
.getLength() == 2 )
206 { // constructor: "createWithHelpSection( long, long )"
207 if ( !( _arguments
[0] >>= nMinHelpTextLines
) || !( _arguments
[1] >>= nMaxHelpTextLines
) )
208 throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
209 createWithHelpSection( nMinHelpTextLines
, nMaxHelpTextLines
);
213 throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
216 //--------------------------------------------------------------------
217 void DefaultComponentInspectorModel::createDefault()
219 m_bConstructed
= true;
221 //--------------------------------------------------------------------
222 void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
224 if ( ( _nMinHelpTextLines
<= 0 ) || ( _nMaxHelpTextLines
<= 0 ) || ( _nMinHelpTextLines
> _nMaxHelpTextLines
) )
225 throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 );
227 m_bHasHelpSection
= true;
228 m_nMinHelpTextLines
= _nMinHelpTextLines
;
229 m_nMaxHelpTextLines
= _nMaxHelpTextLines
;
230 m_bConstructed
= true;
232 //--------------------------------------------------------------------
233 Sequence
< PropertyCategoryDescriptor
> SAL_CALL
DefaultComponentInspectorModel::describeCategories( ) throw (RuntimeException
)
235 ::osl::MutexGuard
aGuard( m_aMutex
);
239 const sal_Char
* programmaticName
;
243 { "General", RID_STR_PROPPAGE_DEFAULT
, HID_RPT_PROPDLG_TAB_GENERAL
},
244 { "Data", RID_STR_PROPPAGE_DATA
, HID_RPT_PROPDLG_TAB_DATA
},
247 const size_t nCategories
= sizeof( aCategories
) / sizeof( aCategories
[0] );
248 Sequence
< PropertyCategoryDescriptor
> aReturn( nCategories
);
249 PropertyCategoryDescriptor
* pReturn
= aReturn
.getArray();
250 for ( size_t i
=0; i
<nCategories
; ++i
, ++pReturn
)
252 pReturn
->ProgrammaticName
= ::rtl::OUString::createFromAscii( aCategories
[i
].programmaticName
);
253 pReturn
->UIName
= String( ModuleRes( aCategories
[i
].uiNameResId
) );
254 pReturn
->HelpURL
= HelpIdUrl::getHelpURL( aCategories
[i
].helpId
);
260 //--------------------------------------------------------------------
261 ::sal_Int32 SAL_CALL
DefaultComponentInspectorModel::getPropertyOrderIndex( const ::rtl::OUString
& _rPropertyName
) throw (RuntimeException
)
263 ::osl::MutexGuard
aGuard(m_aMutex
);
264 const sal_Int32
nPropertyId( m_pInfoService
->getPropertyId( _rPropertyName
) );
265 if ( nPropertyId
!= -1 )
268 if ( !m_xComponent
.is() )
271 m_xComponent
.set(m_xContext
->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.DefaultFormComponentInspectorModel")),m_xContext
),UNO_QUERY_THROW
);
278 return m_xComponent
->getPropertyOrderIndex(_rPropertyName
);
281 //........................................................................
283 //........................................................................