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