1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_FORMCOMPONENTHANDLER_HXX
29 #define EXTENSIONS_SOURCE_PROPCTRLR_FORMCOMPONENTHANDLER_HXX
31 #include "propertyhandler.hxx"
32 #include "sqlcommanddesign.hxx"
33 #include "pcrcommon.hxx"
34 #include <comphelper/uno3.hxx>
35 #include <comphelper/proparrhlp.hxx>
36 #include <comphelper/propertycontainer.hxx>
37 /** === begin UNO includes === **/
38 #include <com/sun/star/frame/XModel.hpp>
39 #include <com/sun/star/beans/XPropertyState.hpp>
40 #include <com/sun/star/sdbc/XRowSet.hpp>
41 #include <com/sun/star/awt/XControlContainer.hpp>
42 #include <com/sun/star/form/XForm.hpp>
43 /** === end UNO includes === **/
44 #include <vcl/fldunit.hxx>
45 #include <vcl/waitobj.hxx>
46 #include <connectivity/dbtools.hxx>
50 //........................................................................
53 //........................................................................
55 //====================================================================
56 //= ComponentClassification
57 //====================================================================
58 enum ComponentClassification
65 //====================================================================
66 //= FormComponentPropertyHandler
67 //====================================================================
68 class FormComponentPropertyHandler
;
69 typedef HandlerComponentBase
< FormComponentPropertyHandler
> FormComponentPropertyHandler_Base
;
70 typedef ::comphelper::OPropertyArrayUsageHelper
<FormComponentPropertyHandler
> FormComponentPropertyHandler_PROP
;
71 /** default ->XPropertyHandler for all form components.
73 class FormComponentPropertyHandler
: public FormComponentPropertyHandler_Base
,
74 public ::comphelper::OPropertyContainer
,
75 public FormComponentPropertyHandler_PROP
78 /// access to property states
79 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyState
> m_xPropertyState
;
80 /// the parent of our component
81 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xObjectParent
;
83 /// the database connection. Owned by us if and only if we created it ourself.
84 mutable ::dbtools::SharedConnection m_xRowSetConnection
;
85 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
> m_xRowSet
;
86 /** helper component encapsulating the handling for the QueryDesign component for
87 interactively designing an SQL command
89 ::rtl::Reference
< SQLCommandDesigner
> m_xCommandDesigner
;
90 ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorUI
> m_xBrowserUI
;
92 /// the string indicating a "default" (VOID) value in list-like controls
93 ::rtl::OUString m_sDefaultValueString
;
94 /// all properties to whose control's we added ->m_sDefaultValueString
95 ::std::set
< ::rtl::OUString
> m_aPropertiesWithDefListEntry
;
96 /// type of our component
97 ComponentClassification m_eComponentClass
;
98 /// is our component a (database) sub form?
99 bool m_bComponentIsSubForm
: 1;
100 /// our component has a "ListSource" property
101 bool m_bHaveListSource
: 1;
102 /// our component has a "Command" property
103 bool m_bHaveCommand
: 1;
104 /// the class id of the component - if appliable
105 sal_Int16 m_nClassId
;
108 FormComponentPropertyHandler(
109 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
112 DECLARE_XINTERFACE( )
115 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
);
117 static ::rtl::OUString SAL_CALL
getImplementationName_static( ) throw (::com::sun::star::uno::RuntimeException
);
118 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames_static( ) throw (::com::sun::star::uno::RuntimeException
);
121 ~FormComponentPropertyHandler();
124 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
125 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
126 // XPropertyHandler overridables
127 virtual ::com::sun::star::uno::Any SAL_CALL
getPropertyValue( const ::rtl::OUString
& _rPropertyName
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
);
128 virtual void SAL_CALL
setPropertyValue( const ::rtl::OUString
& _rPropertyName
, const ::com::sun::star::uno::Any
& _rValue
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
);
129 virtual ::com::sun::star::uno::Any SAL_CALL
convertToPropertyValue( const ::rtl::OUString
& _rPropertyName
, const ::com::sun::star::uno::Any
& _rControlValue
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
);
130 virtual ::com::sun::star::uno::Any SAL_CALL
convertToControlValue( const ::rtl::OUString
& _rPropertyName
, const ::com::sun::star::uno::Any
& _rPropertyValue
, const ::com::sun::star::uno::Type
& _rControlValueType
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
);
131 virtual ::com::sun::star::beans::PropertyState SAL_CALL
getPropertyState( const ::rtl::OUString
& _rPropertyName
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
);
132 virtual void SAL_CALL
addPropertyChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& _rxListener
) throw (::com::sun::star::uno::RuntimeException
);
133 virtual void SAL_CALL
removePropertyChangeListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& _rxListener
) throw (::com::sun::star::uno::RuntimeException
);
134 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupersededProperties() throw (::com::sun::star::uno::RuntimeException
);
135 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getActuatingProperties() throw (::com::sun::star::uno::RuntimeException
);
136 virtual ::com::sun::star::inspection::LineDescriptor SAL_CALL
describePropertyLine( const ::rtl::OUString
& _rPropertyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlFactory
>& _rxControlFactory
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::NullPointerException
, ::com::sun::star::uno::RuntimeException
);
137 virtual ::com::sun::star::inspection::InteractiveSelectionResult
138 SAL_CALL
onInteractivePropertySelection( const ::rtl::OUString
& _rPropertyName
, sal_Bool _bPrimary
, ::com::sun::star::uno::Any
& _rData
, const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorUI
>& _rxInspectorUI
) throw (::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::lang::NullPointerException
, ::com::sun::star::uno::RuntimeException
);
139 virtual void SAL_CALL
actuatingPropertyChanged( const ::rtl::OUString
& _rActuatingPropertyName
, const ::com::sun::star::uno::Any
& _rNewValue
, const ::com::sun::star::uno::Any
& _rOldValue
, const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool _bFirstTimeInit
) throw (::com::sun::star::lang::NullPointerException
, ::com::sun::star::uno::RuntimeException
);
140 virtual sal_Bool SAL_CALL
suspend( sal_Bool _bSuspend
) throw (::com::sun::star::uno::RuntimeException
);
143 virtual void SAL_CALL
disposing();
146 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::Property
>
147 SAL_CALL
doDescribeSupportedProperties() const;
148 virtual void onNewComponent();
151 /** initializes some (cached) meta data about the component
152 @throws RuntimeException
153 if a serious error occurs, for instance if the component does not provide an XPropertySetInfo instance
155 void impl_initComponentMetaData_throw();
157 /** classifies our component, in case it's a control model, by ClassId
159 Note that UNO dialog controls are also classified, though they don't have the ClassId property
161 void impl_classifyControlModel_throw();
163 /** const-version of ->getPropertyValue
165 ::com::sun::star::uno::Any
impl_getPropertyValue_throw( const ::rtl::OUString
& _rPropertyName
) const;
167 // some property values are faked, and not used in the way they're provided by our component
168 void impl_normalizePropertyValue_nothrow( ::com::sun::star::uno::Any
& _rValue
, PropertyId _nPropId
) const;
170 /** determines whether we should exclude a given property from our "supported properties"
172 bool impl_shouldExcludeProperty_nothrow( const ::com::sun::star::beans::Property
& _rProperty
) const;
174 /** initializes the list of field names, if we're handling a control which supports the
177 void impl_initFieldList_nothrow( ::std::vector
< ::rtl::OUString
>& rFieldNames
) const;
179 /** obtaines the RowSet to which our component belongs
181 If the component is a RowSet itself, it's returned directly. Else, the parent
182 is examined for the XRowSet interface. If the parent is no XRowSet, then
183 a check is made whether our component is a grid control column, and if so,
184 the parent of the grid control is examied for the XRowSet interace.
186 Normally, at least one of those methods should succeed.
188 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
> impl_getRowSet_throw( ) const;
190 /** nothrow-version of ->impl_getRowSet_throw
192 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
> impl_getRowSet_nothrow( ) const;
194 /** connects the row set belonging to our introspected data aware form component,
195 and remembers the connection in ->m_xRowSetConnection.
197 If the row set already is connected, ->m_xRowSetConnection will be set, too, but
198 not take the ownership of the connection.
200 If ->m_xRowSetConnection is already set, nothing happens, so if you want to
201 force creation of a connection, you need to clear ->m_xRowSetConnection.
203 bool impl_ensureRowsetConnection_nothrow() const;
205 /** clears ->m_xRowSetConnection
207 void impl_clearRowsetConnection_nothrow();
209 /** fills an ->LineDescriptor with information to represent a cursor source
210 of our form - that is, a table, a query, or an SQL statement.
212 As an example, if our form has currently a CommandType of TABLE, then the
213 value list in the LineDescriptor will contain a list of all tables
214 of the data source which the form is bound to.
216 @seealso impl_fillTableNames_throw
217 @seealso impl_fillQueryNames_throw
219 void impl_describeCursorSource_nothrow(
220 ::com::sun::star::inspection::LineDescriptor
& _out_rProperty
,
221 const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlFactory
>& _rxControlFactory
224 /** describes the UI for selecting a table name
227 m_xRowSetConnection is not <NULL/>
229 void impl_fillTableNames_throw( ::std::vector
< ::rtl::OUString
>& _out_rNames
) const;
231 /** describes the UI for selecting a query name
234 m_xRowSetConnection is not <NULL/>
236 void impl_fillQueryNames_throw( ::std::vector
< ::rtl::OUString
>& _out_rNames
) const;
238 /** describes the UI for selecting a query name
241 m_xRowSetConnection is not <NULL/>
243 void impl_fillQueryNames_throw( const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& _xQueryNames
244 ,::std::vector
< ::rtl::OUString
>& _out_rNames
245 ,const ::rtl::OUString
& _sName
= ::rtl::OUString() ) const;
247 /** describes the UI for selecting a ListSource (for list-like form controls)
249 ->m_xRowSetConnection is not <NULL/>
251 ->m_xComponent is not <NULL/>
253 void impl_describeListSourceUI_throw(
254 ::com::sun::star::inspection::LineDescriptor
& _out_rDescriptor
,
255 const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlFactory
>& _rxControlFactory
258 /** displays a datbase-related error to the user
260 void impl_displaySQLError_nothrow( const ::dbtools::SQLExceptionInfo
& _rErrorDescriptor
) const;
262 /** let's the user chose a selection of entries from a string list, and stores this
263 selection in the given property
265 <TRUE/> if and only if the user successfully changed the property
267 bool impl_dialogListSelection_nothrow( const ::rtl::OUString
& _rProperty
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
269 /** executes a dialog for chosing a filter or sort criterion for a database form
271 <TRUE/> if the Filter property should be used, <FALSE/> if it's the Order
273 @param _out_rSelectedClause
274 the filter or order clause as chosen by the user
276 we're really inspecting a database form (well, a RowSet at least)
278 <TRUE/> if and only if the user successfully chose a clause
280 bool impl_dialogFilterOrSort_nothrow( bool _bFilter
, ::rtl::OUString
& _out_rSelectedClause
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
282 /** executes a dialog which allows the user to chose the columns linking
283 a sub to a master form, and sets the respective MasterFields / SlaveFields
284 properties at the form.
286 we're inspecting (sub) database form
288 <TRUE/> if and only if the user successfully eneter master and slave fields
290 bool impl_dialogLinkedFormFields_nothrow( ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
292 /** executes a dialog which allows the user to modify the FormatKey
293 property of our component, by chosing a (number) format.
295 Our component actually has a FormatKey property.
296 @param _out_rNewValue
297 the new property value, if the user chose a new formatting
299 <TRUE/> if and only if a new formatting has been chosen by the user.
300 In this case, ->_out_rNewValue is filled with the new property value
302 bool impl_dialogFormatting_nothrow( ::com::sun::star::uno::Any
& _out_rNewValue
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
304 /** executes a dialog which allows to the user to change the ImageURL property
305 of our component by browsing for an image file.
307 our component actually has a ImageURL property
308 @param _out_rNewValue
309 the new property value, if the user chose a new image url
311 <TRUE/> if and only if a new image URL has been chosen by the user.
312 In this case, ->_out_rNewValue is filled with the new property value
314 bool impl_browseForImage_nothrow( ::com::sun::star::uno::Any
& _out_rNewValue
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
316 /** executes a dialog which allows the user to change the TargetURL property of
319 our component actually has a TargetURL property
320 @param _out_rNewValue
321 the new property value, if the user chose a new TargetURL
323 <TRUE/> if and only if a new TargetURL has been chosen by the user.
324 In this case, ->_out_rNewValue is filled with the new property value
326 bool impl_browseForTargetURL_nothrow( ::com::sun::star::uno::Any
& _out_rNewValue
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
328 /** executes a dialog which allows the user to change the font, plus related properties,
331 our component actually has a Font property
332 @param _out_rNewValue
333 a value desribing the new font, as <code>Sequence< NamedValue ></code>
335 <TRUE/> if and only if the user successfully changed the font of our component
337 bool impl_executeFontDialog_nothrow( ::com::sun::star::uno::Any
& _out_rNewValue
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
339 /** allows the user browsing for a database document
341 our component actually has a DataSource property
342 @param _out_rNewValue
343 the new property value, if the user chose a new DataSource
345 <TRUE/> if and only if a new DataSource has been chosen by the user.
346 In this case, ->_out_rNewValue is filled with the new property value
348 bool impl_browseForDatabaseDocument_throw( ::com::sun::star::uno::Any
& _out_rNewValue
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
350 /** raises a dialog which allows the user to choose a color
351 @param _nColorPropertyId
352 the ID of the color property
353 @param _out_rNewValue
354 the chosen color value
356 <TRUE/> if and only if a color was chosen by the user
358 bool impl_dialogColorChooser_throw( sal_Int32 _nColorPropertyId
, ::com::sun::star::uno::Any
& _out_rNewValue
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
360 /** raises a dialog which allows the user to choose a label control for our component
361 @param _out_rNewValue
362 the chosen label control, if any
364 <TRUE/> if and only if a label control was chosen by the user
366 bool impl_dialogChooseLabelControl_nothrow( ::com::sun::star::uno::Any
& _out_rNewValue
, ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
368 /** raises a dialog which lets the user chose the tab order of controls of a form
370 we have a view control container in which our controls live
372 <TRUE/> if and only if the user successfully changed the tab order
373 @seealso impl_getContextControlContainer_nothrow
375 bool impl_dialogChangeTabOrder_nothrow( ::osl::ClearableMutexGuard
& _rClearBeforeDialog
) const;
377 /** retrieves the context for controls, whose model(s) we're inspecting
379 If we're inspecting a control model, this is usually part of a set of controls
380 and control models, where the controls live in a certain context (a ->XControlContainer).
381 If we know this context, we can enable additional special functionality.
383 The ->XComponentContext in which we were created is examined for a value
384 named "ControlContext", and this value is returned.
386 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlContainer
>
387 impl_getContextControlContainer_nothrow() const;
389 /** opens a query design window for interactively designing the SQL command of a
392 access to the property browser UI
393 @param _nDesignForProperty
394 the ID for the property for which the designer is opened
396 <TRUE/> if the window was successfully opened, or was previously open,
399 bool impl_doDesignSQLCommand_nothrow(
400 const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorUI
>& _rxInspectorUI
,
401 PropertyId _nDesignForProperty
404 /** updates a property (UI) whose state depends on more than one other property
406 ->actuatingPropertyChanged is called for certain properties in whose changes
407 we expressed interes (->getActuatingProperty). Now such a property change can
408 result in simple UI updates, for instance another property being enabled or disabled.
410 However, it can also result in a more complex change: The current (UI) state might
411 depend on the value of more than one other property. Those dependent properties (their
412 UI, more precisly) are updated in this method.
415 the ->PropertyId of the dependent property whose UI state is to be updated
417 @param _rxInspectorUI
418 provides access to the property browser UI. Must not be <NULL/>.
420 void impl_updateDependentProperty_nothrow( PropertyId _nPropId
, const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XObjectInspectorUI
>& _rxInspectorUI
) const;
422 /** determines whether the given form has a valid data source signature.
424 Valid here means that the DataSource property denotes an existing data source, and the
425 Command property is not empty. No check is made whether the value of the Command property
426 denotes an existent object, since this would be way too expensive.
428 @param _xFormProperties
429 the form to check. Must not be <NULL/>.
430 @param _bAllowEmptyDataSourceName
431 determine whether an empty data source name is allowed (<TRUE/>), and should not
434 static bool impl_hasValidDataSourceSignature_nothrow(
435 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xFormProperties
,
436 bool _bAllowEmptyDataSourceName
);
438 /** returns the URL of our context document
441 ::rtl::OUString
impl_getDocumentURL_nothrow() const;
444 DECL_LINK( OnDesignerClosed
, void* );
447 FormComponentPropertyHandler(); // never implemented
448 FormComponentPropertyHandler( const FormComponentPropertyHandler
& ); // never implemented
449 FormComponentPropertyHandler
& operator=( const FormComponentPropertyHandler
& ); // never implemented
452 using ::comphelper::OPropertyContainer::addPropertyChangeListener
;
453 using ::comphelper::OPropertyContainer::removePropertyChangeListener
;
456 //====================================================================
458 //====================================================================
459 /** wrapper around a ->WaitObject which can cope with a NULL window
464 ::std::auto_ptr
< WaitObject
> m_aWaitObject
;
467 WaitCursor( Window
* _pWindow
)
470 m_aWaitObject
.reset( new WaitObject( _pWindow
) );
474 //........................................................................
476 //........................................................................
478 #endif // EXTENSIONS_SOURCE_PROPCTRLR_FORMCOMPONENTHANDLER_HXX