LibreOffice Module reportdesign (master) 1
DefaultInspection.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
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>
24#include <helpids.h>
26#include <tools/debug.hxx>
27#include <metadata.hxx>
28#include <tools/urlobj.hxx>
29
30
31namespace rptui
32{
33 OUString HelpIdUrl::getHelpURL( std::u16string_view sHelpId )
34 {
35 DBG_ASSERT( INetURLObject(sHelpId).GetProtocol() == INetProtocol::NotValid, "Wrong HelpId!" );
36 return INET_HID_SCHEME + sHelpId;
37 }
38
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star;
41 using com::sun::star::inspection::PropertyCategoryDescriptor;
42
43
44 //= DefaultComponentInspectorModel
45
46
48 :m_xContext( _rxContext )
49 ,m_bConstructed( false )
50 ,m_bHasHelpSection( false )
51 ,m_bIsReadOnly(false)
52 ,m_nMinHelpTextLines( 3 )
53 ,m_nMaxHelpTextLines( 8 )
54 {
55 }
56
58 {
59 }
60
62 {
63 return "com.sun.star.comp.report.DefaultComponentInspectorModel";
64 }
65
66 sal_Bool SAL_CALL DefaultComponentInspectorModel::supportsService( const OUString& ServiceName )
67 {
69 }
70
72 {
73 return { "com.sun.star.report.inspection.DefaultComponentInspectorModel" };
74 }
75
77 {
78 // service names for all our handlers
79 return Sequence<Any> {
80 Any(OUString( "com.sun.star.report.inspection.ReportComponentHandler")),
81 Any(OUString( "com.sun.star.form.inspection.EditPropertyHandler")),
82 Any(OUString( "com.sun.star.report.inspection.DataProviderHandler")),
83 Any(OUString( "com.sun.star.report.inspection.GeometryHandler"))
84 };
85 }
86
88 {
89 std::unique_lock aGuard(m_aMutex);
90 return m_bHasHelpSection;
91 }
92
93
95 {
96 std::unique_lock aGuard(m_aMutex);
98 }
99
101 {
102 std::unique_lock aGuard(m_aMutex);
103 return m_bIsReadOnly;
104 }
105
107 {
108 std::unique_lock aGuard(m_aMutex);
109 m_bIsReadOnly = _isreadonly;
110 }
111
112
114 {
115 std::unique_lock aGuard(m_aMutex);
116 return m_nMaxHelpTextLines;
117 }
118
120 {
121 std::unique_lock aGuard(m_aMutex);
122 if ( m_bConstructed )
123 throw ucb::AlreadyInitializedException();
124
125 if ( !_arguments.hasElements() )
126 { // constructor: "createDefault()"
127 m_bConstructed = true;
128 return;
129 }
130
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 );
137 return;
138 }
139
140 throw lang::IllegalArgumentException( OUString(), *this, 0 );
141 }
142
143
144 void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
145 {
146 if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) )
147 throw lang::IllegalArgumentException( OUString(), *this, 0 );
148
149 m_bHasHelpSection = true;
150 m_nMinHelpTextLines = _nMinHelpTextLines;
151 m_nMaxHelpTextLines = _nMaxHelpTextLines;
152 m_bConstructed = true;
153 }
154
156 {
157 std::unique_lock aGuard( m_aMutex );
158
159 const struct
160 {
161 const char* programmaticName;
162 TranslateId uiNameResId;
163 OUString helpId;
164 } aCategories[] = {
165 { "General", RID_STR_PROPPAGE_DEFAULT, HID_RPT_PROPDLG_TAB_GENERAL },
166 { "Data", RID_STR_PROPPAGE_DATA, HID_RPT_PROPDLG_TAB_DATA },
167 };
168
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 )
173 {
174 pReturn->ProgrammaticName = OUString::createFromAscii( aCategories[i].programmaticName );
175 pReturn->UIName = RptResId( aCategories[i].uiNameResId );
176 pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId );
177 }
178
179 return aReturn;
180 }
181
182
183 ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getPropertyOrderIndex( const OUString& _rPropertyName )
184 {
185 std::unique_lock aGuard(m_aMutex);
186 const sal_Int32 nPropertyId( OPropertyInfoService::getPropertyId( _rPropertyName ) );
187 if ( nPropertyId != -1 )
188 return nPropertyId;
189
190 if ( !m_xComponent.is() )
191 try
192 {
193 m_xComponent.set(m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.form.inspection.DefaultFormComponentInspectorModel",m_xContext),UNO_QUERY_THROW);
194 }
195 catch(const Exception &)
196 {
197 return 0;
198 }
199
200 return m_xComponent->getPropertyOrderIndex(_rPropertyName);
201 }
202
203
204} // namespace rptui
205
206extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
208 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
209{
210 return cppu::acquire(new rptui::DefaultComponentInspectorModel(context));
211}
212
213/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_DefaultComponentInspectorModel_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< XComponentContext > m_xContext
PropFlags nPropertyId
virtual sal_Bool SAL_CALL getIsReadOnly() override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getHandlerFactories() override
virtual ::sal_Int32 SAL_CALL getMaxHelpTextLines() override
virtual void SAL_CALL setIsReadOnly(sal_Bool _isreadonly) override
virtual sal_Bool SAL_CALL getHasHelpSection() override
virtual ::sal_Int32 SAL_CALL getMinHelpTextLines() override
virtual ::sal_Int32 SAL_CALL getPropertyOrderIndex(const OUString &PropertyName) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
void createWithHelpSection(sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines)
DefaultComponentInspectorModel(const DefaultComponentInspectorModel &)=delete
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Sequence< css::inspection::PropertyCategoryDescriptor > SAL_CALL describeCategories() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::inspection::XObjectInspectorModel > m_xComponent
static OUString getHelpURL(std::u16string_view _sHelpId)
static sal_Int32 getPropertyId(const OUString &_rName)
Definition: metadata.cxx:146
OUString RptResId(TranslateId aId)
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral HID_RPT_PROPDLG_TAB_DATA
Definition: helpids.h:36
constexpr OUStringLiteral HID_RPT_PROPDLG_TAB_GENERAL
Definition: helpids.h:35
#define SAL_N_ELEMENTS(arr)
@ Exception
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
unsigned char sal_Bool
constexpr OUStringLiteral INET_HID_SCHEME