1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_extensions.hxx" 30 #include "defaultforminspection.hxx" 31 #include "pcrcommon.hxx" 32 #ifndef EXTENSIONS_PROPRESID_HRC 33 #include "propresid.hrc" 34 #endif 35 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_ 36 #include "formresid.hrc" 37 #endif 38 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_ 39 #include "modulepcr.hxx" 40 #endif 41 #include "propctrlr.hrc" 42 #include "formmetadata.hxx" 43 44 /** === begin UNO includes === **/ 45 #include <com/sun/star/ucb/AlreadyInitializedException.hpp> 46 #include <com/sun/star/lang/IllegalArgumentException.hpp> 47 /** === end UNO includes === **/ 48 #include <cppuhelper/implbase1.hxx> 49 #include <osl/diagnose.h> 50 51 //------------------------------------------------------------------------ 52 extern "C" void SAL_CALL createRegistryInfo_DefaultFormComponentInspectorModel() 53 { 54 ::pcr::OAutoRegistration< ::pcr::DefaultFormComponentInspectorModel > aAutoRegistration; 55 } 56 57 //........................................................................ 58 namespace pcr 59 { 60 //........................................................................ 61 62 /** === begin UNO using === **/ 63 using ::com::sun::star::uno::Reference; 64 using ::com::sun::star::uno::Sequence; 65 using ::com::sun::star::uno::Any; 66 using ::com::sun::star::uno::RuntimeException; 67 using ::com::sun::star::uno::XInterface; 68 using ::com::sun::star::uno::XComponentContext; 69 using ::com::sun::star::uno::Exception; 70 using ::com::sun::star::lang::EventObject; 71 using ::com::sun::star::inspection::PropertyCategoryDescriptor; 72 using ::com::sun::star::beans::UnknownPropertyException; 73 using ::com::sun::star::ucb::AlreadyInitializedException; 74 using ::com::sun::star::lang::IllegalArgumentException; 75 /** === end UNO using === **/ 76 77 //==================================================================== 78 //= DefaultFormComponentInspectorModel 79 //==================================================================== 80 //-------------------------------------------------------------------- 81 DefaultFormComponentInspectorModel::DefaultFormComponentInspectorModel( const Reference< XComponentContext >& _rxContext, bool _bUseFormFormComponentHandlers ) 82 :ImplInspectorModel( _rxContext ) 83 ,m_bUseFormComponentHandlers( _bUseFormFormComponentHandlers ) 84 ,m_bConstructed( false ) 85 ,m_pInfoService( new OPropertyInfoService ) 86 { 87 } 88 89 //------------------------------------------------------------------------ 90 DefaultFormComponentInspectorModel::~DefaultFormComponentInspectorModel() 91 { 92 } 93 94 //------------------------------------------------------------------------ 95 ::rtl::OUString SAL_CALL DefaultFormComponentInspectorModel::getImplementationName( ) throw(RuntimeException) 96 { 97 return getImplementationName_static(); 98 } 99 100 //------------------------------------------------------------------------ 101 Sequence< ::rtl::OUString > SAL_CALL DefaultFormComponentInspectorModel::getSupportedServiceNames( ) throw(RuntimeException) 102 { 103 return getSupportedServiceNames_static(); 104 } 105 106 //------------------------------------------------------------------------ 107 ::rtl::OUString DefaultFormComponentInspectorModel::getImplementationName_static( ) throw(RuntimeException) 108 { 109 return ::rtl::OUString::createFromAscii( "org.openoffice.comp.extensions.DefaultFormComponentInspectorModel"); 110 } 111 112 //------------------------------------------------------------------------ 113 Sequence< ::rtl::OUString > DefaultFormComponentInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException) 114 { 115 Sequence< ::rtl::OUString > aSupported(1); 116 aSupported[0] = ::rtl::OUString::createFromAscii( "com.sun.star.form.inspection.DefaultFormComponentInspectorModel" ); 117 return aSupported; 118 } 119 120 //------------------------------------------------------------------------ 121 Reference< XInterface > SAL_CALL DefaultFormComponentInspectorModel::Create( const Reference< XComponentContext >& _rxContext ) 122 { 123 return *new DefaultFormComponentInspectorModel( _rxContext ); 124 } 125 126 //-------------------------------------------------------------------- 127 Sequence< Any > SAL_CALL DefaultFormComponentInspectorModel::getHandlerFactories() throw (RuntimeException) 128 { 129 ::osl::MutexGuard aGuard( m_aMutex ); 130 131 // service names for all our handlers 132 struct 133 { 134 const sal_Char* serviceName; 135 bool isFormOnly; 136 } aFactories[] = { 137 138 // a generic handler for form component properties (must precede the ButtonNavigationHandler) 139 { "com.sun.star.form.inspection.FormComponentPropertyHandler", false }, 140 141 // generic virtual edit properties 142 { "com.sun.star.form.inspection.EditPropertyHandler", false }, 143 144 // a handler which virtualizes the ButtonType property, to provide additional types like 145 // "move to next record" 146 { "com.sun.star.form.inspection.ButtonNavigationHandler", false }, 147 148 // a handler for script events bound to form components or dialog elements 149 { "com.sun.star.form.inspection.EventHandler", false }, 150 151 // a handler which introduces virtual properties for binding controls to spreadsheet cells 152 { "com.sun.star.form.inspection.CellBindingPropertyHandler", true }, 153 154 // properties related to binding to an XForms DOM node 155 { "com.sun.star.form.inspection.XMLFormsPropertyHandler", true }, 156 157 // properties related to the XSD data against which a control content is validated 158 { "com.sun.star.form.inspection.XSDValidationPropertyHandler", true }, 159 160 // a handler which cares for XForms submissions 161 { "com.sun.star.form.inspection.SubmissionPropertyHandler", true }, 162 163 // a handler which cares for geometry properties of form controls 164 { "com.sun.star.form.inspection.FormGeometryHandler", true } 165 }; 166 167 sal_Int32 nFactories = sizeof( aFactories ) / sizeof( aFactories[ 0 ] ); 168 Sequence< Any > aReturn( nFactories ); 169 Any* pReturn = aReturn.getArray(); 170 for ( sal_Int32 i = 0; i < nFactories; ++i ) 171 { 172 if ( aFactories[i].isFormOnly && !m_bUseFormComponentHandlers ) 173 continue; 174 *pReturn++ <<= ::rtl::OUString::createFromAscii( aFactories[i].serviceName ); 175 } 176 aReturn.realloc( pReturn - aReturn.getArray() ); 177 178 return aReturn; 179 } 180 181 //-------------------------------------------------------------------- 182 Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultFormComponentInspectorModel::describeCategories( ) throw (RuntimeException) 183 { 184 ::osl::MutexGuard aGuard( m_aMutex ); 185 186 struct 187 { 188 const sal_Char* programmaticName; 189 sal_uInt16 uiNameResId; 190 const sal_Char* helpId; 191 } aCategories[] = { 192 { "General", RID_STR_PROPPAGE_DEFAULT, HID_FM_PROPDLG_TAB_GENERAL }, 193 { "Data", RID_STR_PROPPAGE_DATA, HID_FM_PROPDLG_TAB_DATA }, 194 { "Events", RID_STR_EVENTS, HID_FM_PROPDLG_TAB_EVT } 195 }; 196 197 sal_Int32 nCategories = sizeof( aCategories ) / sizeof( aCategories[0] ); 198 Sequence< PropertyCategoryDescriptor > aReturn( nCategories ); 199 PropertyCategoryDescriptor* pReturn = aReturn.getArray(); 200 for ( sal_Int32 i=0; i<nCategories; ++i, ++pReturn ) 201 { 202 pReturn->ProgrammaticName = ::rtl::OUString::createFromAscii( aCategories[i].programmaticName ); 203 pReturn->UIName = String( PcrRes( aCategories[i].uiNameResId ) ); 204 pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId ); 205 } 206 207 return aReturn; 208 } 209 210 //-------------------------------------------------------------------- 211 ::sal_Int32 SAL_CALL DefaultFormComponentInspectorModel::getPropertyOrderIndex( const ::rtl::OUString& _rPropertyName ) throw (RuntimeException) 212 { 213 sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) ); 214 if ( nPropertyId == -1 ) 215 { 216 if ( _rPropertyName.indexOf( ';' ) != -1 ) 217 // it's an event. Just give it an arbitrary number - events will be on a separate 218 // page, and by definition, if two properties have the same OrderIndex, then 219 // they will be ordered as they appear in the handler's getSupportedProperties. 220 return 1000; 221 return 0; 222 } 223 return m_pInfoService->getPropertyPos( nPropertyId ); 224 } 225 226 //-------------------------------------------------------------------- 227 void SAL_CALL DefaultFormComponentInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException) 228 { 229 if ( m_bConstructed ) 230 throw AlreadyInitializedException(); 231 232 StlSyntaxSequence< Any > arguments( _arguments ); 233 if ( arguments.empty() ) 234 { // constructor: "createDefault()" 235 createDefault(); 236 return; 237 } 238 239 sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 ); 240 if ( arguments.size() == 2 ) 241 { // constructor: "createWithHelpSection( long, long )" 242 if ( !( arguments[0] >>= nMinHelpTextLines ) || !( arguments[1] >>= nMaxHelpTextLines ) ) 243 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 244 createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines ); 245 return; 246 } 247 248 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 249 } 250 251 //-------------------------------------------------------------------- 252 void DefaultFormComponentInspectorModel::createDefault() 253 { 254 m_bConstructed = true; 255 } 256 257 //-------------------------------------------------------------------- 258 void DefaultFormComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines ) 259 { 260 if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) ) 261 throw IllegalArgumentException( ::rtl::OUString(), *this, 0 ); 262 263 enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines ); 264 m_bConstructed = true; 265 } 266 267 //........................................................................ 268 } // namespace pcr 269 //........................................................................ 270 271