Line data Source code
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 :
20 : #include "defaultforminspection.hxx"
21 : #include "pcrcommon.hxx"
22 : #include "pcrservices.hxx"
23 : #include "propresid.hrc"
24 : #include "formresid.hrc"
25 : #include "modulepcr.hxx"
26 : #include "propctrlr.hrc"
27 : #include "formmetadata.hxx"
28 :
29 : #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
30 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 : #include <cppuhelper/implbase1.hxx>
32 : #include <osl/diagnose.h>
33 : #include <sal/macros.h>
34 :
35 :
36 2 : extern "C" void SAL_CALL createRegistryInfo_DefaultFormComponentInspectorModel()
37 : {
38 2 : ::pcr::OAutoRegistration< ::pcr::DefaultFormComponentInspectorModel > aAutoRegistration;
39 2 : }
40 :
41 :
42 : namespace pcr
43 : {
44 :
45 :
46 : using ::com::sun::star::uno::Reference;
47 : using ::com::sun::star::uno::Sequence;
48 : using ::com::sun::star::uno::Any;
49 : using ::com::sun::star::uno::RuntimeException;
50 : using ::com::sun::star::uno::XInterface;
51 : using ::com::sun::star::uno::XComponentContext;
52 : using ::com::sun::star::uno::Exception;
53 : using ::com::sun::star::lang::EventObject;
54 : using ::com::sun::star::inspection::PropertyCategoryDescriptor;
55 : using ::com::sun::star::beans::UnknownPropertyException;
56 : using ::com::sun::star::ucb::AlreadyInitializedException;
57 : using ::com::sun::star::lang::IllegalArgumentException;
58 :
59 2 : DefaultFormComponentInspectorModel::DefaultFormComponentInspectorModel( bool _bUseFormFormComponentHandlers )
60 : :ImplInspectorModel()
61 : ,m_bUseFormComponentHandlers( _bUseFormFormComponentHandlers )
62 : ,m_bConstructed( false )
63 2 : ,m_pInfoService( new OPropertyInfoService )
64 : {
65 2 : }
66 :
67 :
68 4 : DefaultFormComponentInspectorModel::~DefaultFormComponentInspectorModel()
69 : {
70 4 : }
71 :
72 :
73 1 : OUString SAL_CALL DefaultFormComponentInspectorModel::getImplementationName( ) throw(RuntimeException, std::exception)
74 : {
75 1 : return getImplementationName_static();
76 : }
77 :
78 :
79 1 : Sequence< OUString > SAL_CALL DefaultFormComponentInspectorModel::getSupportedServiceNames( ) throw(RuntimeException, std::exception)
80 : {
81 1 : return getSupportedServiceNames_static();
82 : }
83 :
84 :
85 3 : OUString DefaultFormComponentInspectorModel::getImplementationName_static( ) throw(RuntimeException)
86 : {
87 3 : return OUString("org.openoffice.comp.extensions.DefaultFormComponentInspectorModel");
88 : }
89 :
90 :
91 3 : Sequence< OUString > DefaultFormComponentInspectorModel::getSupportedServiceNames_static( ) throw(RuntimeException)
92 : {
93 3 : Sequence< OUString > aSupported(1);
94 3 : aSupported[0] = "com.sun.star.form.inspection.DefaultFormComponentInspectorModel";
95 3 : return aSupported;
96 : }
97 :
98 :
99 1 : Reference< XInterface > SAL_CALL DefaultFormComponentInspectorModel::Create( const Reference< XComponentContext >& )
100 : {
101 1 : return *new DefaultFormComponentInspectorModel();
102 : }
103 :
104 :
105 0 : Sequence< Any > SAL_CALL DefaultFormComponentInspectorModel::getHandlerFactories() throw (RuntimeException, std::exception)
106 : {
107 0 : ::osl::MutexGuard aGuard( m_aMutex );
108 :
109 : // service names for all our handlers
110 : struct
111 : {
112 : const sal_Char* serviceName;
113 : bool isFormOnly;
114 : } aFactories[] = {
115 :
116 : // a generic handler for form component properties (must precede the ButtonNavigationHandler)
117 : { "com.sun.star.form.inspection.FormComponentPropertyHandler", false },
118 :
119 : // generic virtual edit properties
120 : { "com.sun.star.form.inspection.EditPropertyHandler", false },
121 :
122 : // a handler which virtualizes the ButtonType property, to provide additional types like
123 : // "move to next record"
124 : { "com.sun.star.form.inspection.ButtonNavigationHandler", false },
125 :
126 : // a handler for script events bound to form components or dialog elements
127 : { "com.sun.star.form.inspection.EventHandler", false },
128 :
129 : // a handler which introduces virtual properties for binding controls to spreadsheet cells
130 : { "com.sun.star.form.inspection.CellBindingPropertyHandler", false },
131 :
132 : // properties related to binding to an XForms DOM node
133 : { "com.sun.star.form.inspection.XMLFormsPropertyHandler", true },
134 :
135 : // properties related to the XSD data against which a control content is validated
136 : { "com.sun.star.form.inspection.XSDValidationPropertyHandler", true },
137 :
138 : // a handler which cares for XForms submissions
139 : { "com.sun.star.form.inspection.SubmissionPropertyHandler", true },
140 :
141 : // a handler which cares for geometry properties of form controls
142 : { "com.sun.star.form.inspection.FormGeometryHandler", true }
143 0 : };
144 :
145 0 : sal_Int32 nFactories = SAL_N_ELEMENTS( aFactories );
146 0 : Sequence< Any > aReturn( nFactories );
147 0 : Any* pReturn = aReturn.getArray();
148 0 : for ( sal_Int32 i = 0; i < nFactories; ++i )
149 : {
150 0 : if ( aFactories[i].isFormOnly && !m_bUseFormComponentHandlers )
151 0 : continue;
152 0 : *pReturn++ <<= OUString::createFromAscii( aFactories[i].serviceName );
153 : }
154 0 : aReturn.realloc( pReturn - aReturn.getArray() );
155 :
156 0 : return aReturn;
157 : }
158 :
159 :
160 0 : Sequence< PropertyCategoryDescriptor > SAL_CALL DefaultFormComponentInspectorModel::describeCategories( ) throw (RuntimeException, std::exception)
161 : {
162 0 : ::osl::MutexGuard aGuard( m_aMutex );
163 :
164 : struct
165 : {
166 : const sal_Char* programmaticName;
167 : sal_uInt16 uiNameResId;
168 : const sal_Char* helpId;
169 : } aCategories[] = {
170 : { "General", RID_STR_PROPPAGE_DEFAULT, HID_FM_PROPDLG_TAB_GENERAL },
171 : { "Data", RID_STR_PROPPAGE_DATA, HID_FM_PROPDLG_TAB_DATA },
172 : { "Events", RID_STR_EVENTS, HID_FM_PROPDLG_TAB_EVT }
173 0 : };
174 :
175 0 : sal_Int32 nCategories = SAL_N_ELEMENTS( aCategories );
176 0 : Sequence< PropertyCategoryDescriptor > aReturn( nCategories );
177 0 : PropertyCategoryDescriptor* pReturn = aReturn.getArray();
178 0 : for ( sal_Int32 i=0; i<nCategories; ++i, ++pReturn )
179 : {
180 0 : pReturn->ProgrammaticName = OUString::createFromAscii( aCategories[i].programmaticName );
181 0 : pReturn->UIName = PcrRes( aCategories[i].uiNameResId ).toString();
182 0 : pReturn->HelpURL = HelpIdUrl::getHelpURL( aCategories[i].helpId );
183 : }
184 :
185 0 : return aReturn;
186 : }
187 :
188 :
189 0 : ::sal_Int32 SAL_CALL DefaultFormComponentInspectorModel::getPropertyOrderIndex( const OUString& _rPropertyName ) throw (RuntimeException, std::exception)
190 : {
191 0 : sal_Int32 nPropertyId( m_pInfoService->getPropertyId( _rPropertyName ) );
192 0 : if ( nPropertyId == -1 )
193 : {
194 0 : if ( _rPropertyName.indexOf( ';' ) != -1 )
195 : // it's an event. Just give it an arbitrary number - events will be on a separate
196 : // page, and by definition, if two properties have the same OrderIndex, then
197 : // they will be ordered as they appear in the handler's getSupportedProperties.
198 0 : return 1000;
199 0 : return 0;
200 : }
201 0 : return m_pInfoService->getPropertyPos( nPropertyId );
202 : }
203 :
204 :
205 1 : void SAL_CALL DefaultFormComponentInspectorModel::initialize( const Sequence< Any >& _arguments ) throw (Exception, RuntimeException, std::exception)
206 : {
207 1 : if ( m_bConstructed )
208 0 : throw AlreadyInitializedException();
209 :
210 1 : StlSyntaxSequence< Any > arguments( _arguments );
211 1 : if ( arguments.empty() )
212 : { // constructor: "createDefault()"
213 1 : createDefault();
214 1 : return;
215 : }
216 :
217 0 : sal_Int32 nMinHelpTextLines( 0 ), nMaxHelpTextLines( 0 );
218 0 : if ( arguments.size() == 2 )
219 : { // constructor: "createWithHelpSection( long, long )"
220 0 : if ( !( arguments[0] >>= nMinHelpTextLines ) || !( arguments[1] >>= nMaxHelpTextLines ) )
221 0 : throw IllegalArgumentException( OUString(), *this, 0 );
222 0 : createWithHelpSection( nMinHelpTextLines, nMaxHelpTextLines );
223 0 : return;
224 : }
225 :
226 1 : throw IllegalArgumentException( OUString(), *this, 0 );
227 : }
228 :
229 :
230 1 : void DefaultFormComponentInspectorModel::createDefault()
231 : {
232 1 : m_bConstructed = true;
233 1 : }
234 :
235 :
236 0 : void DefaultFormComponentInspectorModel::createWithHelpSection( sal_Int32 _nMinHelpTextLines, sal_Int32 _nMaxHelpTextLines )
237 : {
238 0 : if ( ( _nMinHelpTextLines <= 0 ) || ( _nMaxHelpTextLines <= 0 ) || ( _nMinHelpTextLines > _nMaxHelpTextLines ) )
239 0 : throw IllegalArgumentException( OUString(), *this, 0 );
240 :
241 0 : enableHelpSectionProperties( _nMinHelpTextLines, _nMaxHelpTextLines );
242 0 : m_bConstructed = true;
243 0 : }
244 :
245 :
246 : } // namespace pcr
247 :
248 :
249 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|