tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / xmloff / source / xforms / xformsimport.cxx
bloba082c553b3c32ea703d1fd928d4a27455d52821f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "XFormsModelContext.hxx"
22 #include <utility>
23 #include <xmloff/xformsimport.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/form/binding/XValueBinding.hpp>
27 #include <com/sun/star/form/binding/XBindableValue.hpp>
28 #include <com/sun/star/form/binding/XListEntrySource.hpp>
29 #include <com/sun/star/form/binding/XListEntrySink.hpp>
30 #include <com/sun/star/form/submission/XSubmission.hpp>
31 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
32 #include <com/sun/star/container/XNameAccess.hpp>
33 #include <rtl/ustring.hxx>
34 #include "xformsapi.hxx"
35 #include <comphelper/namedvaluecollection.hxx>
36 #include <comphelper/diagnose_ex.hxx>
38 using std::pair;
39 using com::sun::star::uno::Reference;
40 using com::sun::star::uno::Exception;
41 using com::sun::star::uno::UNO_QUERY;
42 using com::sun::star::uno::UNO_QUERY_THROW;
43 using com::sun::star::uno::UNO_SET_THROW;
44 using com::sun::star::uno::Sequence;
45 using com::sun::star::beans::XPropertySet;
46 using com::sun::star::beans::XPropertySetInfo;
47 using com::sun::star::beans::PropertyValue;
48 using com::sun::star::frame::XModel;
49 using com::sun::star::container::XNameAccess;
50 using com::sun::star::form::binding::XValueBinding;
51 using com::sun::star::form::binding::XBindableValue;
52 using com::sun::star::form::binding::XListEntrySource;
53 using com::sun::star::form::binding::XListEntrySink;
54 using com::sun::star::form::submission::XSubmission;
55 using com::sun::star::form::submission::XSubmissionSupplier;
57 SvXMLImportContext* createXFormsModelContext(
58 SvXMLImport& rImport )
60 return new XFormsModelContext( rImport );
63 void bindXFormsValueBinding(Reference<XModel> const& xModel,
64 const pair<Reference<XPropertySet>, OUString>& aPair)
66 Reference<XBindableValue> xBindable(
67 aPair.first,
68 UNO_QUERY );
69 Reference<XValueBinding> xBinding(
70 xforms_findXFormsBinding( xModel, aPair.second ),
71 UNO_QUERY );
73 if( xBindable.is() && xBinding.is() )
75 try
77 xBindable->setValueBinding( xBinding );
79 catch( const Exception& )
81 // ignore problems during binding
82 // TODO: call XML error handling
87 void bindXFormsListBinding(Reference<XModel> const& xModel,
88 const ::pair<Reference<XPropertySet>, OUString>& aPair)
90 Reference<XListEntrySink> xListEntrySink(
91 aPair.first,
92 UNO_QUERY );
93 Reference<XListEntrySource> xListEntrySource(
94 xforms_findXFormsBinding( xModel, aPair.second ),
95 UNO_QUERY );
97 if( xListEntrySink.is() && xListEntrySource.is() )
99 try
101 xListEntrySink->setListEntrySource( xListEntrySource );
103 catch( const Exception& )
105 // ignore problems during binding
106 // TODO: call XML error handling
111 void bindXFormsSubmission(Reference<XModel> const& xModel,
112 const pair<Reference<XPropertySet>, OUString>& aPair)
114 Reference<XSubmissionSupplier> xSubmissionSupp( aPair.first, UNO_QUERY );
115 Reference<XSubmission> xSubmission(
116 xforms_findXFormsSubmission( xModel, aPair.second ),
117 UNO_QUERY );
119 if( xSubmissionSupp.is() && xSubmission.is() )
123 xSubmissionSupp->setSubmission( xSubmission );
125 catch( const Exception& )
127 // ignore problems during binding
128 // TODO: call XML error handling
133 void applyXFormsSettings( const Reference< XNameAccess >& _rXForms, const Sequence< PropertyValue >& _rSettings )
135 OSL_PRECOND( _rXForms.is(), "applyXFormsSettings: invalid XForms container!" );
136 if ( !_rXForms.is() )
137 return;
139 Reference< XNameAccess > xModelSettings( ::comphelper::NamedValueCollection::get( _rSettings, u"XFormModels" ), UNO_QUERY );
140 if ( !xModelSettings.is() )
142 OSL_FAIL( "applyXFormsSettings: wrong type for the XFormModels settings!" );
143 return;
148 const Sequence< OUString > aSettingsForModels( xModelSettings->getElementNames() );
149 for ( auto const & modelName : aSettingsForModels )
151 // the settings for this particular model
152 Sequence< PropertyValue > aModelSettings;
153 OSL_VERIFY( xModelSettings->getByName( modelName ) >>= aModelSettings );
155 // the model itself
156 if ( !_rXForms->hasByName( modelName ) )
158 OSL_FAIL( "applyXFormsSettings: have settings for a non-existent XForms model!" );
159 continue;
162 // propagate the settings, being tolerant by omitting properties which are not supported
163 Reference< XPropertySet > xModelProps( _rXForms->getByName( modelName ), UNO_QUERY_THROW );
164 Reference< XPropertySetInfo > xModelPSI( xModelProps->getPropertySetInfo(), UNO_SET_THROW );
166 for (auto const& setting : aModelSettings)
168 if ( !xModelPSI->hasPropertyByName( setting.Name ) )
170 OSL_FAIL( "applyXFormsSettings: non-existent model property!" );
171 continue;
174 xModelProps->setPropertyValue( setting.Name, setting.Value );
178 catch( const Exception& )
180 DBG_UNHANDLED_EXCEPTION("xmloff");
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */