1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "DefaultInspection.hxx"
20 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
21 #include <com/sun/star/lang/IllegalArgumentException.hpp>
22 #include <RptResId.hrc>
23 #include "ModuleHelper.hxx"
24 #include "helpids.hrc"
25 #include <cppuhelper/implbase1.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <osl/diagnose.h>
28 #include <rtl/ustrbuf.hxx>
29 #include <tools/debug.hxx>
30 #include "metadata.hxx"
31 #include <tools/urlobj.hxx>
36 OUString
HelpIdUrl::getHelpURL( const OString
& sHelpId
)
38 OUStringBuffer aBuffer
;
39 OUString
aTmp( OStringToOUString(sHelpId
, RTL_TEXTENCODING_UTF8
) );
40 DBG_ASSERT( INetURLObject( aTmp
).GetProtocol() == INetProtocol::NotValid
, "Wrong HelpId!" );
41 aBuffer
.appendAscii( INET_HID_SCHEME
);
42 aBuffer
.append( aTmp
.getStr() );
43 return aBuffer
.makeStringAndClear();
46 using namespace com::sun::star::uno
;
47 using namespace com::sun::star
;
48 using com::sun::star::inspection::PropertyCategoryDescriptor
;
51 //= DefaultComponentInspectorModel
54 DefaultComponentInspectorModel::DefaultComponentInspectorModel( const Reference
< XComponentContext
>& _rxContext
)
55 :m_xContext( _rxContext
)
56 ,m_bConstructed( false )
57 ,m_bHasHelpSection( false )
59 ,m_nMinHelpTextLines( 3 )
60 ,m_nMaxHelpTextLines( 8 )
61 ,m_pInfoService(new OPropertyInfoService())
65 DefaultComponentInspectorModel::~DefaultComponentInspectorModel()
69 OUString SAL_CALL
DefaultComponentInspectorModel::getImplementationName( ) throw(RuntimeException
, std::exception
)
71 return getImplementationName_Static();
74 sal_Bool SAL_CALL
DefaultComponentInspectorModel::supportsService( const OUString
& ServiceName
) throw(RuntimeException
, std::exception
)
76 return cppu::supportsService(this, ServiceName
);
79 Sequence
< OUString
> SAL_CALL
DefaultComponentInspectorModel::getSupportedServiceNames( ) throw(RuntimeException
, std::exception
)
81 return getSupportedServiceNames_static();
84 OUString
DefaultComponentInspectorModel::getImplementationName_Static( ) throw(RuntimeException
)
86 return OUString("com.sun.star.comp.report.DefaultComponentInspectorModel");
89 Sequence
< OUString
> DefaultComponentInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException
)
91 Sequence
< OUString
> aSupported(1);
92 aSupported
[0] = "com.sun.star.report.inspection.DefaultComponentInspectorModel";
96 Reference
< XInterface
> SAL_CALL
DefaultComponentInspectorModel::create( const Reference
< XComponentContext
>& _rxContext
)
98 return *(new DefaultComponentInspectorModel( _rxContext
));
102 Sequence
< Any
> SAL_CALL
DefaultComponentInspectorModel::getHandlerFactories() throw (RuntimeException
, std::exception
)
104 ::osl::MutexGuard
aGuard( m_aMutex
);
107 // service names for all our handlers
110 const sal_Char
* serviceName
;
113 { "com.sun.star.report.inspection.ReportComponentHandler"},
114 { "com.sun.star.form.inspection.EditPropertyHandler"},
115 { "com.sun.star.report.inspection.DataProviderHandler"},
116 { "com.sun.star.report.inspection.GeometryHandler"}
118 // generic virtual edit properties
122 const size_t nFactories
= sizeof( aFactories
) / sizeof( aFactories
[ 0 ] );
123 Sequence
< Any
> aReturn( nFactories
);
124 Any
* pReturn
= aReturn
.getArray();
125 for ( size_t i
= 0; i
< nFactories
; ++i
)
127 *pReturn
++ <<= OUString::createFromAscii( aFactories
[i
].serviceName
);
133 sal_Bool SAL_CALL
DefaultComponentInspectorModel::getHasHelpSection() throw (RuntimeException
, std::exception
)
135 ::osl::MutexGuard
aGuard(m_aMutex
);
136 return m_bHasHelpSection
;
140 ::sal_Int32 SAL_CALL
DefaultComponentInspectorModel::getMinHelpTextLines() throw (RuntimeException
, std::exception
)
142 ::osl::MutexGuard
aGuard(m_aMutex
);
143 return m_nMinHelpTextLines
;
146 sal_Bool SAL_CALL
DefaultComponentInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
148 ::osl::MutexGuard
aGuard(m_aMutex
);
149 return m_bIsReadOnly
;
152 void SAL_CALL
DefaultComponentInspectorModel::setIsReadOnly( sal_Bool _isreadonly
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
154 ::osl::MutexGuard
aGuard(m_aMutex
);
155 m_bIsReadOnly
= _isreadonly
;
159 ::sal_Int32 SAL_CALL
DefaultComponentInspectorModel::getMaxHelpTextLines() throw (RuntimeException
, std::exception
)
161 ::osl::MutexGuard
aGuard(m_aMutex
);
162 return m_nMaxHelpTextLines
;
165 void SAL_CALL
DefaultComponentInspectorModel::initialize( const Sequence
< Any
>& _arguments
) throw (Exception
, RuntimeException
, std::exception
)
167 ::osl::MutexGuard
aGuard(m_aMutex
);
168 if ( m_bConstructed
)
169 throw ucb::AlreadyInitializedException();
171 if ( !_arguments
.hasElements() )
172 { // constructor: "createDefault()"
177 sal_Int32
nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
178 if ( _arguments
.getLength() == 2 )
179 { // constructor: "createWithHelpSection( long, long )"
180 if ( !( _arguments
[0] >>= nMinHelpTextLines
) || !( _arguments
[1] >>= nMaxHelpTextLines
) )
181 throw lang::IllegalArgumentException( OUString(), *this, 0 );
182 createWithHelpSection( nMinHelpTextLines
, nMaxHelpTextLines
);
186 throw lang::IllegalArgumentException( OUString(), *this, 0 );
190 void DefaultComponentInspectorModel::createDefault()
192 m_bConstructed
= true;
195 void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
197 if ( ( _nMinHelpTextLines
<= 0 ) || ( _nMaxHelpTextLines
<= 0 ) || ( _nMinHelpTextLines
> _nMaxHelpTextLines
) )
198 throw lang::IllegalArgumentException( OUString(), *this, 0 );
200 m_bHasHelpSection
= true;
201 m_nMinHelpTextLines
= _nMinHelpTextLines
;
202 m_nMaxHelpTextLines
= _nMaxHelpTextLines
;
203 m_bConstructed
= true;
206 Sequence
< PropertyCategoryDescriptor
> SAL_CALL
DefaultComponentInspectorModel::describeCategories( ) throw (RuntimeException
, std::exception
)
208 ::osl::MutexGuard
aGuard( m_aMutex
);
212 const sal_Char
* programmaticName
;
213 sal_uInt16 uiNameResId
;
216 { "General", RID_STR_PROPPAGE_DEFAULT
, HID_RPT_PROPDLG_TAB_GENERAL
},
217 { "Data", RID_STR_PROPPAGE_DATA
, HID_RPT_PROPDLG_TAB_DATA
},
220 const size_t nCategories
= sizeof( aCategories
) / sizeof( aCategories
[0] );
221 Sequence
< PropertyCategoryDescriptor
> aReturn( nCategories
);
222 PropertyCategoryDescriptor
* pReturn
= aReturn
.getArray();
223 for ( size_t i
=0; i
<nCategories
; ++i
, ++pReturn
)
225 pReturn
->ProgrammaticName
= OUString::createFromAscii( aCategories
[i
].programmaticName
);
226 pReturn
->UIName
= ModuleRes( aCategories
[i
].uiNameResId
);
227 pReturn
->HelpURL
= HelpIdUrl::getHelpURL( aCategories
[i
].helpId
);
234 ::sal_Int32 SAL_CALL
DefaultComponentInspectorModel::getPropertyOrderIndex( const OUString
& _rPropertyName
) throw (RuntimeException
, std::exception
)
236 ::osl::MutexGuard
aGuard(m_aMutex
);
237 const sal_Int32
nPropertyId( OPropertyInfoService::getPropertyId( _rPropertyName
) );
238 if ( nPropertyId
!= -1 )
241 if ( !m_xComponent
.is() )
244 m_xComponent
.set(m_xContext
->getServiceManager()->createInstanceWithContext("com.sun.star.form.inspection.DefaultFormComponentInspectorModel",m_xContext
),UNO_QUERY_THROW
);
246 catch(const Exception
&)
251 return m_xComponent
->getPropertyOrderIndex(_rPropertyName
);
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */