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 <strings.hrc>
23 #include <core_resource.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <tools/debug.hxx>
27 #include <metadata.hxx>
28 #include <tools/urlobj.hxx>
33 OUString
HelpIdUrl::getHelpURL( std::u16string_view sHelpId
)
35 DBG_ASSERT( INetURLObject(sHelpId
).GetProtocol() == INetProtocol::NotValid
, "Wrong HelpId!" );
36 return INET_HID_SCHEME
+ sHelpId
;
39 using namespace com::sun::star::uno
;
40 using namespace com::sun::star
;
41 using com::sun::star::inspection::PropertyCategoryDescriptor
;
44 //= DefaultComponentInspectorModel
47 DefaultComponentInspectorModel::DefaultComponentInspectorModel( const Reference
< XComponentContext
>& _rxContext
)
48 :m_xContext( _rxContext
)
49 ,m_bConstructed( false )
50 ,m_bHasHelpSection( false )
52 ,m_nMinHelpTextLines( 3 )
53 ,m_nMaxHelpTextLines( 8 )
57 DefaultComponentInspectorModel::~DefaultComponentInspectorModel()
61 OUString SAL_CALL
DefaultComponentInspectorModel::getImplementationName( )
63 return u
"com.sun.star.comp.report.DefaultComponentInspectorModel"_ustr
;
66 sal_Bool SAL_CALL
DefaultComponentInspectorModel::supportsService( const OUString
& ServiceName
)
68 return cppu::supportsService(this, ServiceName
);
71 Sequence
< OUString
> SAL_CALL
DefaultComponentInspectorModel::getSupportedServiceNames( )
73 return { u
"com.sun.star.report.inspection.DefaultComponentInspectorModel"_ustr
};
76 Sequence
< Any
> SAL_CALL
DefaultComponentInspectorModel::getHandlerFactories()
78 // service names for all our handlers
79 return Sequence
<Any
> {
80 Any(u
"com.sun.star.report.inspection.ReportComponentHandler"_ustr
),
81 Any(u
"com.sun.star.form.inspection.EditPropertyHandler"_ustr
),
82 Any(u
"com.sun.star.report.inspection.DataProviderHandler"_ustr
),
83 Any(u
"com.sun.star.report.inspection.GeometryHandler"_ustr
)
87 sal_Bool SAL_CALL
DefaultComponentInspectorModel::getHasHelpSection()
89 std::unique_lock
aGuard(m_aMutex
);
90 return m_bHasHelpSection
;
94 ::sal_Int32 SAL_CALL
DefaultComponentInspectorModel::getMinHelpTextLines()
96 std::unique_lock
aGuard(m_aMutex
);
97 return m_nMinHelpTextLines
;
100 sal_Bool SAL_CALL
DefaultComponentInspectorModel::getIsReadOnly()
102 std::unique_lock
aGuard(m_aMutex
);
103 return m_bIsReadOnly
;
106 void SAL_CALL
DefaultComponentInspectorModel::setIsReadOnly( sal_Bool _isreadonly
)
108 std::unique_lock
aGuard(m_aMutex
);
109 m_bIsReadOnly
= _isreadonly
;
113 ::sal_Int32 SAL_CALL
DefaultComponentInspectorModel::getMaxHelpTextLines()
115 std::unique_lock
aGuard(m_aMutex
);
116 return m_nMaxHelpTextLines
;
119 void SAL_CALL
DefaultComponentInspectorModel::initialize( const Sequence
< Any
>& _arguments
)
121 std::unique_lock
aGuard(m_aMutex
);
122 if ( m_bConstructed
)
123 throw ucb::AlreadyInitializedException();
125 if ( !_arguments
.hasElements() )
126 { // constructor: "createDefault()"
127 m_bConstructed
= true;
131 if ( _arguments
.getLength() == 2 )
132 { // constructor: "createWithHelpSection( long, long )"
133 sal_Int32
nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
134 if ( !( _arguments
[0] >>= nMinHelpTextLines
) || !( _arguments
[1] >>= nMaxHelpTextLines
) )
135 throw lang::IllegalArgumentException( OUString(), *this, 0 );
136 createWithHelpSection( nMinHelpTextLines
, nMaxHelpTextLines
);
140 throw lang::IllegalArgumentException( OUString(), *this, 0 );
144 void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines
, sal_Int32 _nMaxHelpTextLines
)
146 if ( ( _nMinHelpTextLines
<= 0 ) || ( _nMaxHelpTextLines
<= 0 ) || ( _nMinHelpTextLines
> _nMaxHelpTextLines
) )
147 throw lang::IllegalArgumentException( OUString(), *this, 0 );
149 m_bHasHelpSection
= true;
150 m_nMinHelpTextLines
= _nMinHelpTextLines
;
151 m_nMaxHelpTextLines
= _nMaxHelpTextLines
;
152 m_bConstructed
= true;
155 Sequence
< PropertyCategoryDescriptor
> SAL_CALL
DefaultComponentInspectorModel::describeCategories( )
157 std::unique_lock
aGuard( m_aMutex
);
161 const char* programmaticName
;
162 TranslateId uiNameResId
;
165 { "General", RID_STR_PROPPAGE_DEFAULT
, HID_RPT_PROPDLG_TAB_GENERAL
},
166 { "Data", RID_STR_PROPPAGE_DATA
, HID_RPT_PROPDLG_TAB_DATA
},
169 const size_t nCategories
= SAL_N_ELEMENTS( aCategories
);
170 Sequence
< PropertyCategoryDescriptor
> aReturn( nCategories
);
171 PropertyCategoryDescriptor
* pReturn
= aReturn
.getArray();
172 for ( size_t i
=0; i
<nCategories
; ++i
, ++pReturn
)
174 pReturn
->ProgrammaticName
= OUString::createFromAscii( aCategories
[i
].programmaticName
);
175 pReturn
->UIName
= RptResId( aCategories
[i
].uiNameResId
);
176 pReturn
->HelpURL
= HelpIdUrl::getHelpURL( aCategories
[i
].helpId
);
183 ::sal_Int32 SAL_CALL
DefaultComponentInspectorModel::getPropertyOrderIndex( const OUString
& _rPropertyName
)
185 std::unique_lock
aGuard(m_aMutex
);
186 const sal_Int32
nPropertyId( OPropertyInfoService::getPropertyId( _rPropertyName
) );
187 if ( nPropertyId
!= -1 )
190 if ( !m_xComponent
.is() )
193 m_xComponent
.set(m_xContext
->getServiceManager()->createInstanceWithContext(u
"com.sun.star.form.inspection.DefaultFormComponentInspectorModel"_ustr
,m_xContext
),UNO_QUERY_THROW
);
195 catch(const Exception
&)
200 return m_xComponent
->getPropertyOrderIndex(_rPropertyName
);
206 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
207 reportdesign_DefaultComponentInspectorModel_get_implementation(
208 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
210 return cppu::acquire(new rptui::DefaultComponentInspectorModel(context
));
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */