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 
31 namespace rptui
32 {
33  OUString HelpIdUrl::getHelpURL( std::string_view sHelpId )
34  {
35  OUString aTmp( OStringToOUString(sHelpId, RTL_TEXTENCODING_UTF8) );
36  DBG_ASSERT( INetURLObject( aTmp ).GetProtocol() == INetProtocol::NotValid, "Wrong HelpId!" );
37  return INET_HID_SCHEME + aTmp;
38  }
39 
40  using namespace com::sun::star::uno;
41  using namespace com::sun::star;
42  using com::sun::star::inspection::PropertyCategoryDescriptor;
43 
44 
45  //= DefaultComponentInspectorModel
46 
47 
49  :m_xContext( _rxContext )
50  ,m_bConstructed( false )
51  ,m_bHasHelpSection( false )
52  ,m_bIsReadOnly(false)
53  ,m_nMinHelpTextLines( 3 )
54  ,m_nMaxHelpTextLines( 8 )
55  {
56  }
57 
59  {
60  }
61 
63  {
64  return "com.sun.star.comp.report.DefaultComponentInspectorModel";
65  }
66 
67  sal_Bool SAL_CALL DefaultComponentInspectorModel::supportsService( const OUString& ServiceName )
68  {
69  return cppu::supportsService(this, ServiceName);
70  }
71 
73  {
74  return { "com.sun.star.report.inspection.DefaultComponentInspectorModel" };
75  }
76 
78  {
79  // service names for all our handlers
80  return Sequence<Any> {
81  Any(OUString( "com.sun.star.report.inspection.ReportComponentHandler")),
82  Any(OUString( "com.sun.star.form.inspection.EditPropertyHandler")),
83  Any(OUString( "com.sun.star.report.inspection.DataProviderHandler")),
84  Any(OUString( "com.sun.star.report.inspection.GeometryHandler"))
85  };
86  }
87 
89  {
90  ::osl::MutexGuard aGuard(m_aMutex);
91  return m_bHasHelpSection;
92  }
93 
94 
96  {
97  ::osl::MutexGuard aGuard(m_aMutex);
98  return m_nMinHelpTextLines;
99  }
100 
102  {
103  ::osl::MutexGuard aGuard(m_aMutex);
104  return m_bIsReadOnly;
105  }
106 
108  {
109  ::osl::MutexGuard aGuard(m_aMutex);
110  m_bIsReadOnly = _isreadonly;
111  }
112 
113 
115  {
116  ::osl::MutexGuard aGuard(m_aMutex);
117  return m_nMaxHelpTextLines;
118  }
119 
121  {
122  ::osl::MutexGuard aGuard(m_aMutex);
123  if ( m_bConstructed )
124  throw ucb::AlreadyInitializedException();
125 
126  if ( !_arguments.hasElements() )
127  { // constructor: "createDefault()"
128  m_bConstructed = true;
129  return;
130  }
131 
132  if ( _arguments.getLength() == 2 )
133  { // constructor: "createWithHelpSection( long, long )"
134  sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
135  if ( !( _arguments[0] >>= nMinHelpTextLines ) || !( _arguments[1] >>= nMaxHelpTextLines ) )
136  throw lang::IllegalArgumentException( OUString(), *this, 0 );
137  createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines );
138  return;
139  }
140 
141  throw lang::IllegalArgumentException( OUString(), *this, 0 );
142  }
143 
144 
145  void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
146  {
147  if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) )
148  throw lang::IllegalArgumentException( OUString(), *this, 0 );
149 
150  m_bHasHelpSection = true;
151  m_nMinHelpTextLines = _nMinHelpTextLines;
152  m_nMaxHelpTextLines = _nMaxHelpTextLines;
153  m_bConstructed = true;
154  }
155 
157  {
158  ::osl::MutexGuard aGuard( m_aMutex );
159 
160  const struct
161  {
162  const char* programmaticName;
163  const char* uiNameResId;
164  OString helpId;
165  } aCategories[] = {
166  { "General", RID_STR_PROPPAGE_DEFAULT, HID_RPT_PROPDLG_TAB_GENERAL },
167  { "Data", RID_STR_PROPPAGE_DATA, HID_RPT_PROPDLG_TAB_DATA },
168  };
169 
170  const size_t nCategories = SAL_N_ELEMENTS( aCategories );
171  Sequence< PropertyCategoryDescriptor > aReturn( nCategories );
172  PropertyCategoryDescriptor* pReturn = aReturn.getArray();
173  for ( size_t i=0; i<nCategories; ++i, ++pReturn )
174  {
175  pReturn->ProgrammaticName = OUString::createFromAscii( aCategories[i].programmaticName );
176  pReturn->UIName = RptResId( aCategories[i].uiNameResId );
177  pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId );
178  }
179 
180  return aReturn;
181  }
182 
183 
184  ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getPropertyOrderIndex( const OUString& _rPropertyName )
185  {
186  ::osl::MutexGuard aGuard(m_aMutex);
187  const sal_Int32 nPropertyId( OPropertyInfoService::getPropertyId( _rPropertyName ) );
188  if ( nPropertyId != -1 )
189  return nPropertyId;
190 
191  if ( !m_xComponent.is() )
192  try
193  {
194  m_xComponent.set(m_xContext->getServiceManager()->createInstanceWithContext("com.sun.star.form.inspection.DefaultFormComponentInspectorModel",m_xContext),UNO_QUERY_THROW);
195  }
196  catch(const Exception &)
197  {
198  return 0;
199  }
200 
201  return m_xComponent->getPropertyOrderIndex(_rPropertyName);
202  }
203 
204 
205 } // namespace rptui
206 
207 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
209  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
210 {
211  return cppu::acquire(new rptui::DefaultComponentInspectorModel(context));
212 }
213 
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ::sal_Int32 SAL_CALL getMinHelpTextLines() override
static OUString getHelpURL(std::string_view _sHelpId)
virtual ::sal_Int32 SAL_CALL getPropertyOrderIndex(const OUString &PropertyName) override
virtual sal_Bool SAL_CALL getIsReadOnly() override
virtual sal_Bool SAL_CALL getHasHelpSection() override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
static sal_Int32 getPropertyId(const OUString &_rName)
Definition: metadata.cxx:157
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
#define HID_RPT_PROPDLG_TAB_DATA
Definition: helpids.h:38
#define INET_HID_SCHEME
PropFlags nPropertyId
#define SAL_N_ELEMENTS(arr)
DefaultComponentInspectorModel(const DefaultComponentInspectorModel &)=delete
virtual ::sal_Int32 SAL_CALL getMaxHelpTextLines() override
#define DBG_ASSERT(sCon, aError)
int i
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_DefaultComponentInspectorModel_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
unsigned char sal_Bool
OUString RptResId(const char *pId)
#define HID_RPT_PROPDLG_TAB_GENERAL
Definition: helpids.h:37
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
void createWithHelpSection(sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines)
css::uno::Reference< css::inspection::XObjectInspectorModel > m_xComponent
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual void SAL_CALL setIsReadOnly(sal_Bool _isreadonly) override
virtual css::uno::Sequence< css::inspection::PropertyCategoryDescriptor > SAL_CALL describeCategories() override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getHandlerFactories() override
Reference< XComponentContext > m_xContext