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