1*9e0e4191SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9e0e4191SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9e0e4191SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9e0e4191SAndrew Rist * distributed with this work for additional information 6*9e0e4191SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9e0e4191SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9e0e4191SAndrew Rist * "License"); you may not use this file except in compliance 9*9e0e4191SAndrew Rist * with the License. You may obtain a copy of the License at 10*9e0e4191SAndrew Rist * 11*9e0e4191SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*9e0e4191SAndrew Rist * 13*9e0e4191SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9e0e4191SAndrew Rist * software distributed under the License is distributed on an 15*9e0e4191SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9e0e4191SAndrew Rist * KIND, either express or implied. See the License for the 17*9e0e4191SAndrew Rist * specific language governing permissions and limitations 18*9e0e4191SAndrew Rist * under the License. 19*9e0e4191SAndrew Rist * 20*9e0e4191SAndrew Rist *************************************************************/ 21*9e0e4191SAndrew Rist 22*9e0e4191SAndrew Rist 23cdf0e10cSrcweir #include "precompiled_reportdesign.hxx" 24cdf0e10cSrcweir #include "DefaultInspection.hxx" 25cdf0e10cSrcweir #include <comphelper/sequence.hxx> 26cdf0e10cSrcweir #include <com/sun/star/ucb/AlreadyInitializedException.hpp> 27cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 28cdf0e10cSrcweir #ifndef _REPORT_DLGRESID_HRC 29cdf0e10cSrcweir #include <RptResId.hrc> 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir #include "ModuleHelper.hxx" 32cdf0e10cSrcweir #ifndef RTPUI_REPORTDESIGN_HELPID_HRC 33cdf0e10cSrcweir #include "helpids.hrc" 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 36cdf0e10cSrcweir #include <osl/diagnose.h> 37cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 38cdf0e10cSrcweir #include <tools/debug.hxx> 39cdf0e10cSrcweir #include "metadata.hxx" 40cdf0e10cSrcweir #include <tools/urlobj.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir //........................................................................ 43cdf0e10cSrcweir namespace rptui 44cdf0e10cSrcweir { 45cdf0e10cSrcweir //........................................................................ 46cdf0e10cSrcweir //------------------------------------------------------------------------ 47cdf0e10cSrcweir ::rtl::OUString HelpIdUrl::getHelpURL( const rtl::OString& sHelpId ) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir ::rtl::OUStringBuffer aBuffer; 50cdf0e10cSrcweir ::rtl::OUString aTmp( sHelpId, sHelpId.getLength(), RTL_TEXTENCODING_UTF8 ); 51cdf0e10cSrcweir DBG_ASSERT( INetURLObject( aTmp ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" ); 52cdf0e10cSrcweir aBuffer.appendAscii( INET_HID_SCHEME ); 53cdf0e10cSrcweir aBuffer.append( aTmp.getStr() ); 54cdf0e10cSrcweir return aBuffer.makeStringAndClear(); 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir /** === begin UNO using === **/ 58cdf0e10cSrcweir using namespace com::sun::star::uno; 59cdf0e10cSrcweir using namespace com::sun::star; 60cdf0e10cSrcweir using com::sun::star::inspection::PropertyCategoryDescriptor; 61cdf0e10cSrcweir /** === end UNO using === **/ 62cdf0e10cSrcweir 63cdf0e10cSrcweir //==================================================================== 64cdf0e10cSrcweir //= DefaultComponentInspectorModel 65cdf0e10cSrcweir //==================================================================== 66cdf0e10cSrcweir DBG_NAME(DefaultComponentInspectorModel) 67cdf0e10cSrcweir //-------------------------------------------------------------------- 68cdf0e10cSrcweir DefaultComponentInspectorModel::DefaultComponentInspectorModel( const Reference< XComponentContext >& _rxContext) 69cdf0e10cSrcweir :m_xContext( _rxContext ) 70cdf0e10cSrcweir ,m_bConstructed( false ) 71cdf0e10cSrcweir ,m_bHasHelpSection( false ) 72cdf0e10cSrcweir ,m_bIsReadOnly(sal_False) 73cdf0e10cSrcweir ,m_nMinHelpTextLines( 3 ) 74cdf0e10cSrcweir ,m_nMaxHelpTextLines( 8 ) 75cdf0e10cSrcweir ,m_pInfoService(new OPropertyInfoService()) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir DBG_CTOR(DefaultComponentInspectorModel,NULL); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir //------------------------------------------------------------------------ 81cdf0e10cSrcweir DefaultComponentInspectorModel::~DefaultComponentInspectorModel() 82cdf0e10cSrcweir { 83cdf0e10cSrcweir DBG_DTOR(DefaultComponentInspectorModel,NULL); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir //------------------------------------------------------------------------ 87cdf0e10cSrcweir ::rtl::OUString SAL_CALL DefaultComponentInspectorModel::getImplementationName( ) throw(RuntimeException) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir return getImplementationName_Static(); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir //------------------------------------------------------------------------ 93cdf0e10cSrcweir sal_Bool SAL_CALL DefaultComponentInspectorModel::supportsService( const ::rtl::OUString& ServiceName ) throw(RuntimeException) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static()); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir //------------------------------------------------------------------------ 99cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL DefaultComponentInspectorModel::getSupportedServiceNames( ) throw(RuntimeException) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir return getSupportedServiceNames_static(); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir //------------------------------------------------------------------------ 105cdf0e10cSrcweir ::rtl::OUString DefaultComponentInspectorModel::getImplementationName_Static( ) throw(RuntimeException) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.DefaultComponentInspectorModel")); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir //------------------------------------------------------------------------ 111cdf0e10cSrcweir Sequence< ::rtl::OUString > DefaultComponentInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported(1); 114cdf0e10cSrcweir aSupported[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.inspection.DefaultComponentInspectorModel")); 115cdf0e10cSrcweir return aSupported; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir //------------------------------------------------------------------------ 119cdf0e10cSrcweir Reference< XInterface > SAL_CALL DefaultComponentInspectorModel::create( const Reference< XComponentContext >& _rxContext ) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir return *(new DefaultComponentInspectorModel( _rxContext )); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir //-------------------------------------------------------------------- 125cdf0e10cSrcweir Sequence< Any > SAL_CALL DefaultComponentInspectorModel::getHandlerFactories() throw (RuntimeException) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir 130cdf0e10cSrcweir // service names for all our handlers 131cdf0e10cSrcweir const struct 132cdf0e10cSrcweir { 133cdf0e10cSrcweir const sal_Char* serviceName; 134cdf0e10cSrcweir } aFactories[] = { 135cdf0e10cSrcweir 136cdf0e10cSrcweir { "com.sun.star.report.inspection.ReportComponentHandler"}, 137cdf0e10cSrcweir { "com.sun.star.form.inspection.EditPropertyHandler"}, 138cdf0e10cSrcweir { "com.sun.star.report.inspection.DataProviderHandler"}, 139cdf0e10cSrcweir { "com.sun.star.report.inspection.GeometryHandler"} 140cdf0e10cSrcweir 141cdf0e10cSrcweir // generic virtual edit properties 142cdf0e10cSrcweir 143cdf0e10cSrcweir }; 144cdf0e10cSrcweir 145cdf0e10cSrcweir const size_t nFactories = sizeof( aFactories ) / sizeof( aFactories[ 0 ] ); 146cdf0e10cSrcweir Sequence< Any > aReturn( nFactories ); 147cdf0e10cSrcweir Any* pReturn = aReturn.getArray(); 148cdf0e10cSrcweir for ( size_t i = 0; i < nFactories; ++i ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir *pReturn++ <<= ::rtl::OUString::createFromAscii( aFactories[i].serviceName ); 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir return aReturn; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir //-------------------------------------------------------------------- 156cdf0e10cSrcweir ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getHasHelpSection() throw (RuntimeException) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 159cdf0e10cSrcweir return m_bHasHelpSection; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir //-------------------------------------------------------------------- 163cdf0e10cSrcweir ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMinHelpTextLines() throw (RuntimeException) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 166cdf0e10cSrcweir return m_nMinHelpTextLines; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir //-------------------------------------------------------------------- 169cdf0e10cSrcweir ::sal_Bool SAL_CALL DefaultComponentInspectorModel::getIsReadOnly() throw (::com::sun::star::uno::RuntimeException) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 172cdf0e10cSrcweir return m_bIsReadOnly; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir //-------------------------------------------------------------------- 175cdf0e10cSrcweir void SAL_CALL DefaultComponentInspectorModel::setIsReadOnly( ::sal_Bool _isreadonly ) throw (::com::sun::star::uno::RuntimeException) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 178cdf0e10cSrcweir m_bIsReadOnly = _isreadonly; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir //-------------------------------------------------------------------- 182cdf0e10cSrcweir ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getMaxHelpTextLines() throw (RuntimeException) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 185cdf0e10cSrcweir return m_nMaxHelpTextLines; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir //-------------------------------------------------------------------- 188cdf0e10cSrcweir void SAL_CALL DefaultComponentInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 191cdf0e10cSrcweir if ( m_bConstructed ) 192cdf0e10cSrcweir throw ucb::AlreadyInitializedException(); 193cdf0e10cSrcweir 194cdf0e10cSrcweir if ( !_arguments.hasElements() ) 195cdf0e10cSrcweir { // constructor: "createDefault()" 196cdf0e10cSrcweir createDefault(); 197cdf0e10cSrcweir return; 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 ); 201cdf0e10cSrcweir if ( _arguments.getLength() == 2 ) 202cdf0e10cSrcweir { // constructor: "createWithHelpSection( long, long )" 203cdf0e10cSrcweir if ( !( _arguments[0] >>= nMinHelpTextLines ) || !( _arguments[1] >>= nMaxHelpTextLines ) ) 204cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 205cdf0e10cSrcweir createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines ); 206cdf0e10cSrcweir return; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir //-------------------------------------------------------------------- 213cdf0e10cSrcweir void DefaultComponentInspectorModel::createDefault() 214cdf0e10cSrcweir { 215cdf0e10cSrcweir m_bConstructed = true; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir //-------------------------------------------------------------------- 218cdf0e10cSrcweir void DefaultComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) ) 221cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 222cdf0e10cSrcweir 223cdf0e10cSrcweir m_bHasHelpSection = true; 224cdf0e10cSrcweir m_nMinHelpTextLines = _nMinHelpTextLines; 225cdf0e10cSrcweir m_nMaxHelpTextLines = _nMaxHelpTextLines; 226cdf0e10cSrcweir m_bConstructed = true; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir //-------------------------------------------------------------------- 229cdf0e10cSrcweir Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultComponentInspectorModel::describeCategories( ) throw (RuntimeException) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 232cdf0e10cSrcweir 233cdf0e10cSrcweir const struct 234cdf0e10cSrcweir { 235cdf0e10cSrcweir const sal_Char* programmaticName; 236cdf0e10cSrcweir sal_uInt16 uiNameResId; 237cdf0e10cSrcweir rtl::OString helpId; 238cdf0e10cSrcweir } aCategories[] = { 239cdf0e10cSrcweir { "General", RID_STR_PROPPAGE_DEFAULT, HID_RPT_PROPDLG_TAB_GENERAL }, 240cdf0e10cSrcweir { "Data", RID_STR_PROPPAGE_DATA, HID_RPT_PROPDLG_TAB_DATA }, 241cdf0e10cSrcweir }; 242cdf0e10cSrcweir 243cdf0e10cSrcweir const size_t nCategories = sizeof( aCategories ) / sizeof( aCategories[0] ); 244cdf0e10cSrcweir Sequence< PropertyCategoryDescriptor > aReturn( nCategories ); 245cdf0e10cSrcweir PropertyCategoryDescriptor* pReturn = aReturn.getArray(); 246cdf0e10cSrcweir for ( size_t i=0; i<nCategories; ++i, ++pReturn ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir pReturn->ProgrammaticName = ::rtl::OUString::createFromAscii( aCategories[i].programmaticName ); 249cdf0e10cSrcweir pReturn->UIName = String( ModuleRes( aCategories[i].uiNameResId ) ); 250cdf0e10cSrcweir pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId ); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir return aReturn; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir 256cdf0e10cSrcweir //-------------------------------------------------------------------- 257cdf0e10cSrcweir ::sal_Int32 SAL_CALL DefaultComponentInspectorModel::getPropertyOrderIndex( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 260cdf0e10cSrcweir const sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) ); 261cdf0e10cSrcweir if ( nPropertyId != -1 ) 262cdf0e10cSrcweir return nPropertyId; 263cdf0e10cSrcweir 264cdf0e10cSrcweir if ( !m_xComponent.is() ) 265cdf0e10cSrcweir try 266cdf0e10cSrcweir { 267cdf0e10cSrcweir m_xComponent.set(m_xContext->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.inspection.DefaultFormComponentInspectorModel")),m_xContext),UNO_QUERY_THROW); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir catch(Exception) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir return 0; 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir return m_xComponent->getPropertyOrderIndex(_rPropertyName); 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir //........................................................................ 278cdf0e10cSrcweir } // namespace rptui 279cdf0e10cSrcweir //........................................................................ 280cdf0e10cSrcweir 281