LCOV - code coverage report
Current view: top level - xmloff/source/forms - layerimport.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 126 203 62.1 %
Date: 2015-06-13 12:38:46 Functions: 13 21 61.9 %
Legend: Lines: hit not hit

          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 "layerimport.hxx"
      21             : #include "formenums.hxx"
      22             : #include "elementimport.hxx"
      23             : #include "officeforms.hxx"
      24             : #include "strings.hxx"
      25             : #include <xmloff/xmlictxt.hxx>
      26             : #include <xmloff/xmlstyle.hxx>
      27             : #include <xmloff/families.hxx>
      28             : #include <xmloff/xmlprmap.hxx>
      29             : #include <xmloff/prstylei.hxx>
      30             : #include <xmloff/xmlimp.hxx>
      31             : #include "XMLEventImportHelper.hxx"
      32             : #include <xmloff/xmlimppr.hxx>
      33             : #include <xmloff/xmlnumfi.hxx>
      34             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      35             : #include <com/sun/star/form/FormSubmitEncoding.hpp>
      36             : #include <com/sun/star/form/FormSubmitMethod.hpp>
      37             : #include <com/sun/star/sdb/CommandType.hpp>
      38             : #include <com/sun/star/form/NavigationBarMode.hpp>
      39             : #include <com/sun/star/form/TabulatorCycle.hpp>
      40             : #include <com/sun/star/form/FormButtonType.hpp>
      41             : #include <com/sun/star/awt/ScrollBarOrientation.hpp>
      42             : #include <com/sun/star/awt/VisualEffect.hpp>
      43             : #include <com/sun/star/form/ListSourceType.hpp>
      44             : #include <tools/gen.hxx>
      45             : #include <com/sun/star/lang/Locale.hpp>
      46             : #include <xmloff/controlpropertyhdl.hxx>
      47             : #include "controlpropertymap.hxx"
      48             : #include "formevents.hxx"
      49             : #include "formcellbinding.hxx"
      50             : #include <xmloff/xformsimport.hxx>
      51             : #include <xmloff/xmltoken.hxx>
      52             : #include <xmloff/xmlnmspe.hxx>
      53             : #include <rtl/strbuf.hxx>
      54             : #include <algorithm>
      55             : #include <functional>
      56             : 
      57             : namespace xmloff
      58             : {
      59             : 
      60             : using namespace ::com::sun::star::uno;
      61             : using namespace ::com::sun::star::awt;
      62             : using namespace ::com::sun::star::lang;
      63             : using namespace ::com::sun::star::beans;
      64             : using namespace ::com::sun::star::container;
      65             : using namespace ::com::sun::star::drawing;
      66             : using namespace ::com::sun::star;
      67             : using namespace ::com::sun::star::util;
      68             : using namespace ::com::sun::star::form;
      69             : using namespace ::com::sun::star::sdb;
      70             : 
      71             : //= OFormLayerXMLImport_Impl
      72        1233 : OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl(SvXMLImport& _rImporter)
      73             :     :m_rImporter(_rImporter)
      74        1233 :     ,m_pAutoStyles(NULL)
      75             : {
      76             :     // build the attribute2property map
      77             :     // string properties which are exported as attributes
      78             :     m_aAttributeMetaData.addStringProperty(
      79        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_NAME), PROPERTY_NAME);
      80             :     m_aAttributeMetaData.addStringProperty(
      81        1233 :             OAttributeMetaData::getSpecialAttributeName(SCA_GROUP_NAME), PROPERTY_GROUP_NAME);
      82             :         m_aAttributeMetaData.addStringProperty(
      83        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_IMAGE_DATA), PROPERTY_IMAGEURL);
      84             :     m_aAttributeMetaData.addStringProperty(
      85        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_LABEL), PROPERTY_LABEL);
      86             :     m_aAttributeMetaData.addStringProperty(
      87        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION), PROPERTY_TARGETURL);
      88             :     m_aAttributeMetaData.addStringProperty(
      89        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_TITLE), PROPERTY_TITLE);
      90             :     m_aAttributeMetaData.addStringProperty(
      91        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_FRAME), PROPERTY_TARGETFRAME, "_blank");
      92             :     m_aAttributeMetaData.addStringProperty(
      93        1233 :         OAttributeMetaData::getDatabaseAttributeName(DA_DATA_FIELD), PROPERTY_DATAFIELD);
      94             :     m_aAttributeMetaData.addStringProperty(
      95        1233 :         OAttributeMetaData::getFormAttributeName(faCommand), PROPERTY_COMMAND);
      96             :     m_aAttributeMetaData.addStringProperty(
      97        1233 :         OAttributeMetaData::getFormAttributeName(faDatasource), PROPERTY_DATASOURCENAME);
      98             :     m_aAttributeMetaData.addStringProperty(
      99        1233 :         OAttributeMetaData::getFormAttributeName(faFilter), PROPERTY_FILTER);
     100             :     m_aAttributeMetaData.addStringProperty(
     101        1233 :         OAttributeMetaData::getFormAttributeName(faOrder), PROPERTY_ORDER);
     102             : 
     103             :     // properties not added because they're already present in another form
     104             :     OSL_ENSURE(
     105             :         OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_TARGET_LOCATION)).equalsAscii(
     106             :             OAttributeMetaData::getFormAttributeName(faAction)),
     107             :         "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (1)!");
     108             :         // if this fails, we would have to add a translation from faAction->PROPERTY_TARGETURL
     109             :         // We did not because we already have one CCA_TARGET_LOCATION->PROPERTY_TARGETURL,
     110             :         // and CCA_TARGET_LOCATION and faAction should be represented by the same attribute
     111             : 
     112             :     OSL_ENSURE(
     113             :         OUString::createFromAscii(OAttributeMetaData::getCommonControlAttributeName(CCA_NAME)).equalsAscii(
     114             :             OAttributeMetaData::getFormAttributeName(faName)),
     115             :         "OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (2)!");
     116             :         // the same for faName, CCA_NAME and PROPERTY_NAME
     117             : 
     118             :     // boolean properties which are exported as attributes
     119             :     m_aAttributeMetaData.addBooleanProperty(
     120        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_CURRENT_SELECTED), PROPERTY_STATE, false);
     121             :     m_aAttributeMetaData.addBooleanProperty(
     122        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_DISABLED), PROPERTY_ENABLED, false, true);
     123             :     m_aAttributeMetaData.addBooleanProperty(
     124        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_DROPDOWN), PROPERTY_DROPDOWN, false);
     125             :     m_aAttributeMetaData.addBooleanProperty(
     126        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_PRINTABLE), PROPERTY_PRINTABLE, true);
     127             :     m_aAttributeMetaData.addBooleanProperty(
     128        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_READONLY), PROPERTY_READONLY, false);
     129             :     m_aAttributeMetaData.addBooleanProperty(
     130        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_SELECTED), PROPERTY_DEFAULT_STATE, false);
     131             :     m_aAttributeMetaData.addBooleanProperty(
     132        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_STOP), PROPERTY_TABSTOP, true);
     133             :     m_aAttributeMetaData.addBooleanProperty(
     134        1233 :         OAttributeMetaData::getDatabaseAttributeName(DA_CONVERT_EMPTY), PROPERTY_EMPTY_IS_NULL, false);
     135             :     m_aAttributeMetaData.addBooleanProperty(
     136        1233 :         OAttributeMetaData::getSpecialAttributeName(SCA_VALIDATION), PROPERTY_STRICTFORMAT, false);
     137             :     m_aAttributeMetaData.addBooleanProperty(
     138        1233 :         OAttributeMetaData::getSpecialAttributeName(SCA_MULTI_LINE), PROPERTY_MULTILINE, false);
     139             :     m_aAttributeMetaData.addBooleanProperty(
     140        1233 :         OAttributeMetaData::getSpecialAttributeName(SCA_AUTOMATIC_COMPLETION), PROPERTY_AUTOCOMPLETE, false);
     141             :     m_aAttributeMetaData.addBooleanProperty(
     142        1233 :         OAttributeMetaData::getSpecialAttributeName(SCA_MULTIPLE), PROPERTY_MULTISELECTION, false);
     143             :     m_aAttributeMetaData.addBooleanProperty(
     144        1233 :         OAttributeMetaData::getSpecialAttributeName(SCA_DEFAULT_BUTTON), PROPERTY_DEFAULTBUTTON, false);
     145             :     m_aAttributeMetaData.addBooleanProperty(
     146        1233 :         OAttributeMetaData::getSpecialAttributeName(SCA_IS_TRISTATE), PROPERTY_TRISTATE, false);
     147             :     m_aAttributeMetaData.addBooleanProperty(
     148        1233 :         OAttributeMetaData::getFormAttributeName(faAllowDeletes), PROPERTY_ALLOWDELETES, true);
     149             :     m_aAttributeMetaData.addBooleanProperty(
     150        1233 :         OAttributeMetaData::getFormAttributeName(faAllowInserts), PROPERTY_ALLOWINSERTS, true);
     151             :     m_aAttributeMetaData.addBooleanProperty(
     152        1233 :         OAttributeMetaData::getFormAttributeName(faAllowUpdates), PROPERTY_ALLOWUPDATES, true);
     153             :     m_aAttributeMetaData.addBooleanProperty(
     154        1233 :         OAttributeMetaData::getFormAttributeName(faApplyFilter), PROPERTY_APPLYFILTER, false);
     155             :     m_aAttributeMetaData.addBooleanProperty(
     156        1233 :         OAttributeMetaData::getFormAttributeName(faEscapeProcessing), PROPERTY_ESCAPEPROCESSING, true);
     157             :     m_aAttributeMetaData.addBooleanProperty(
     158        1233 :         OAttributeMetaData::getFormAttributeName(faIgnoreResult), PROPERTY_IGNORERESULT, false);
     159             :     m_aAttributeMetaData.addBooleanProperty(
     160        1233 :         OAttributeMetaData::getSpecialAttributeName( SCA_TOGGLE ), PROPERTY_TOGGLE, false );
     161             :     m_aAttributeMetaData.addBooleanProperty(
     162        1233 :         OAttributeMetaData::getSpecialAttributeName( SCA_FOCUS_ON_CLICK ), PROPERTY_FOCUS_ON_CLICK, true );
     163             :     m_aAttributeMetaData.addBooleanProperty(
     164        1233 :         OAttributeMetaData::getDatabaseAttributeName( DA_INPUT_REQUIRED ), PROPERTY_INPUT_REQUIRED, false );
     165             : 
     166             :     // the int16 attributes
     167             :     m_aAttributeMetaData.addInt16Property(
     168        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_MAX_LENGTH), PROPERTY_MAXTEXTLENGTH, 0);
     169             :     m_aAttributeMetaData.addInt16Property(
     170        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_SIZE), PROPERTY_LINECOUNT, 5);
     171             :     m_aAttributeMetaData.addInt16Property(
     172        1233 :         OAttributeMetaData::getCommonControlAttributeName(CCA_TAB_INDEX), PROPERTY_TABINDEX, 0);
     173             :     m_aAttributeMetaData.addInt16Property(
     174        1233 :         OAttributeMetaData::getDatabaseAttributeName(DA_BOUND_COLUMN), PROPERTY_BOUNDCOLUMN, 0);
     175             : 
     176             :     // the int32 attributes
     177             :     m_aAttributeMetaData.addInt32Property(
     178        1233 :         OAttributeMetaData::getSpecialAttributeName( SCA_PAGE_STEP_SIZE ), PROPERTY_BLOCK_INCREMENT, 10 );
     179             : 
     180             :     // the enum attributes
     181             :     m_aAttributeMetaData.addEnumProperty(
     182             :         OAttributeMetaData::getCommonControlAttributeName( CCA_VISUAL_EFFECT ), PROPERTY_VISUAL_EFFECT,
     183             :         VisualEffect::LOOK3D, OEnumMapper::getEnumMap( OEnumMapper::epVisualEffect ),
     184        1233 :         &::cppu::UnoType<sal_Int16>::get() );
     185             :     m_aAttributeMetaData.addEnumProperty(
     186             :         OAttributeMetaData::getCommonControlAttributeName( CCA_ORIENTATION ), PROPERTY_ORIENTATION,
     187             :         ScrollBarOrientation::HORIZONTAL, OEnumMapper::getEnumMap( OEnumMapper::epOrientation ),
     188        1233 :         &::cppu::UnoType<sal_Int32>::get() );
     189             :     m_aAttributeMetaData.addEnumProperty(
     190             :         OAttributeMetaData::getCommonControlAttributeName(CCA_BUTTON_TYPE), PROPERTY_BUTTONTYPE,
     191             :         FormButtonType_PUSH, OEnumMapper::getEnumMap(OEnumMapper::epButtonType),
     192        1233 :         &::cppu::UnoType<FormButtonType>::get());
     193             :     m_aAttributeMetaData.addEnumProperty(
     194             :         OAttributeMetaData::getDatabaseAttributeName(DA_LIST_SOURCE_TYPE), PROPERTY_LISTSOURCETYPE,
     195             :         ListSourceType_VALUELIST, OEnumMapper::getEnumMap(OEnumMapper::epListSourceType),
     196        1233 :         &::cppu::UnoType<ListSourceType>::get());
     197             :     m_aAttributeMetaData.addEnumProperty(
     198             :         OAttributeMetaData::getSpecialAttributeName(SCA_STATE), PROPERTY_DEFAULT_STATE, TRISTATE_FALSE,
     199             :         OEnumMapper::getEnumMap(OEnumMapper::epCheckState),
     200        1233 :         &::cppu::UnoType<sal_Int16>::get());
     201             :     m_aAttributeMetaData.addEnumProperty(
     202             :         OAttributeMetaData::getSpecialAttributeName(SCA_CURRENT_STATE), PROPERTY_STATE, TRISTATE_FALSE,
     203             :         OEnumMapper::getEnumMap(OEnumMapper::epCheckState),
     204        1233 :         &::cppu::UnoType<sal_Int16>::get());
     205             :     m_aAttributeMetaData.addEnumProperty(
     206             :         OAttributeMetaData::getFormAttributeName(faEnctype), PROPERTY_SUBMIT_ENCODING,
     207             :         FormSubmitEncoding_URL, OEnumMapper::getEnumMap(OEnumMapper::epSubmitEncoding),
     208        1233 :         &::cppu::UnoType<FormSubmitEncoding>::get());
     209             :     m_aAttributeMetaData.addEnumProperty(
     210             :         OAttributeMetaData::getFormAttributeName(faMethod), PROPERTY_SUBMIT_METHOD,
     211             :         FormSubmitMethod_GET, OEnumMapper::getEnumMap(OEnumMapper::epSubmitMethod),
     212        1233 :         &::cppu::UnoType<FormSubmitMethod>::get());
     213             :     m_aAttributeMetaData.addEnumProperty(
     214             :         OAttributeMetaData::getFormAttributeName(faCommandType), PROPERTY_COMMAND_TYPE,
     215        1233 :         CommandType::COMMAND, OEnumMapper::getEnumMap(OEnumMapper::epCommandType));
     216             :     m_aAttributeMetaData.addEnumProperty(
     217             :         OAttributeMetaData::getFormAttributeName(faNavigationMode), PROPERTY_NAVIGATION,
     218             :         NavigationBarMode_NONE, OEnumMapper::getEnumMap(OEnumMapper::epNavigationType),
     219        1233 :         &::cppu::UnoType<NavigationBarMode>::get());
     220             :     m_aAttributeMetaData.addEnumProperty(
     221             :         OAttributeMetaData::getFormAttributeName(faTabbingCycle), PROPERTY_CYCLE,
     222             :         TabulatorCycle_RECORDS, OEnumMapper::getEnumMap(OEnumMapper::epTabCyle),
     223        1233 :         &::cppu::UnoType<TabulatorCycle>::get());
     224             : 
     225             :     // 'initialize'
     226        1233 :     m_aCurrentPageIds = m_aControlIds.end();
     227        1233 : }
     228             : 
     229        3699 : OFormLayerXMLImport_Impl::~OFormLayerXMLImport_Impl()
     230             : {
     231             :     // outlined to allow forward declaration of OAttribute2Property in the header
     232             : 
     233        1233 :     if (m_pAutoStyles)
     234        1231 :         m_pAutoStyles->ReleaseRef();
     235        2466 : }
     236             : 
     237        1231 : void OFormLayerXMLImport_Impl::setAutoStyleContext(SvXMLStylesContext* _pNewContext)
     238             : {
     239             :     OSL_ENSURE(!m_pAutoStyles, "OFormLayerXMLImport_Impl::setAutoStyleContext: not to be called twice!");
     240        1231 :     m_pAutoStyles = _pNewContext;
     241        1231 :     if (m_pAutoStyles)
     242        1231 :         m_pAutoStyles->AddFirstRef();
     243        1231 : }
     244             : 
     245           0 : void OFormLayerXMLImport_Impl::applyControlNumberStyle(const Reference< XPropertySet >& _rxControlModel, const OUString& _rControlNumerStyleName)
     246             : {
     247             :     OSL_ENSURE(_rxControlModel.is() && (!_rControlNumerStyleName.isEmpty()),
     248             :         "OFormLayerXMLImport_Impl::applyControlNumberStyle: invalid arguments (this will crash)!");
     249             : 
     250             :     OSL_ENSURE(m_pAutoStyles, "OFormLayerXMLImport_Impl::applyControlNumberStyle: have no auto style context!");
     251           0 :     if (!m_pAutoStyles)
     252             :     {
     253           0 :         m_pAutoStyles = m_rImporter.GetShapeImport()->GetAutoStylesContext();
     254           0 :         if (m_pAutoStyles)
     255           0 :             m_pAutoStyles->AddFirstRef();
     256             :     }
     257             : 
     258           0 :     if (m_pAutoStyles)
     259             :     {
     260           0 :         const SvXMLStyleContext* pStyle = m_pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, _rControlNumerStyleName);
     261           0 :         if (pStyle)
     262             :         {
     263           0 :             const SvXMLNumFormatContext* pDataStyle = static_cast<const SvXMLNumFormatContext*>(pStyle);
     264             : 
     265             :             // set this format at the control model
     266             :             try
     267             :             {
     268             :                 // the models number format supplier and formats
     269           0 :                 Reference< XNumberFormatsSupplier > xFormatsSupplier;
     270           0 :                 _rxControlModel->getPropertyValue(PROPERTY_FORMATSSUPPLIER) >>= xFormatsSupplier;
     271           0 :                 Reference< XNumberFormats > xFormats;
     272           0 :                 if (xFormatsSupplier.is())
     273           0 :                     xFormats = xFormatsSupplier->getNumberFormats();
     274             :                 OSL_ENSURE(xFormats.is(), "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain the controls number formats!");
     275             : 
     276             :                 // obtain a key
     277           0 :                 if (xFormats.is())
     278             :                 {
     279           0 :                     sal_Int32 nFormatKey = const_cast<SvXMLNumFormatContext*>(pDataStyle)->CreateAndInsert( xFormatsSupplier );
     280             :                     OSL_ENSURE(-1 != nFormatKey, "OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain a format key!");
     281             : 
     282             :                     // set the format on the control model
     283           0 :                     _rxControlModel->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
     284           0 :                 }
     285             :             }
     286           0 :             catch(const Exception&)
     287             :             {
     288             :                 OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: couldn't set the format!");
     289             :             }
     290             :         }
     291             :         else
     292             :             OSL_FAIL("OFormLayerXMLImport_Impl::applyControlNumberStyle: did not find the style with the given name!");
     293             :     }
     294           0 : }
     295             : 
     296           0 : void OFormLayerXMLImport_Impl::registerCellValueBinding( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellAddress )
     297             : {
     298             :     OSL_ENSURE( _rxControlModel.is() && !_rCellAddress.isEmpty(),
     299             :         "OFormLayerXMLImport_Impl::registerCellValueBinding: invalid arguments!" );
     300           0 :     m_aCellValueBindings.push_back( ModelStringPair( _rxControlModel, _rCellAddress ) );
     301           0 : }
     302             : 
     303           0 : void OFormLayerXMLImport_Impl::registerXFormsValueBinding(
     304             :     const Reference< XPropertySet >& _rxControlModel,
     305             :     const OUString& _rBindingID )
     306             : {
     307             :     // TODO: is an empty binding name allowed?
     308             :     OSL_ENSURE( _rxControlModel.is(), "need  model" );
     309             : 
     310             :     m_aXFormsValueBindings.push_back(
     311           0 :         ModelStringPair( _rxControlModel, _rBindingID ) );
     312           0 : }
     313             : 
     314           0 : void OFormLayerXMLImport_Impl::registerXFormsListBinding(
     315             :     const Reference< XPropertySet >& _rxControlModel,
     316             :     const OUString& _rBindingID )
     317             : {
     318             :     // TODO: is an empty binding name allowed?
     319             :     OSL_ENSURE( _rxControlModel.is(), "need  model" );
     320             : 
     321             :     m_aXFormsListBindings.push_back(
     322           0 :         ModelStringPair( _rxControlModel, _rBindingID ) );
     323           0 : }
     324             : 
     325           0 : void OFormLayerXMLImport_Impl::registerXFormsSubmission(
     326             :     const Reference< XPropertySet >& _rxControlModel,
     327             :     const OUString& _rSubmissionID )
     328             : {
     329             :     // TODO: is an empty binding name allowed?
     330             :     OSL_ENSURE( _rxControlModel.is(), "need  model" );
     331             : 
     332             :     m_aXFormsSubmissions.push_back(
     333           0 :         ModelStringPair( _rxControlModel, _rSubmissionID ) );
     334           0 : }
     335             : 
     336           0 : void OFormLayerXMLImport_Impl::registerCellRangeListSource( const Reference< XPropertySet >& _rxControlModel, const OUString& _rCellRangeAddress )
     337             : {
     338             :     OSL_ENSURE( _rxControlModel.is() && !_rCellRangeAddress.isEmpty(),
     339             :         "OFormLayerXMLImport_Impl::registerCellRangeListSource: invalid arguments!" );
     340           0 :     m_aCellRangeListSources.push_back( ModelStringPair( _rxControlModel, _rCellRangeAddress ) );
     341           0 : }
     342           0 : const SvXMLStyleContext* OFormLayerXMLImport_Impl::getStyleElement(const OUString& _rStyleName) const
     343             : {
     344             :     OSL_ENSURE( m_pAutoStyles, "OFormLayerXMLImport_Impl::getStyleElement: have no auto style context!" );
     345             :         // did you use setAutoStyleContext?
     346             : 
     347             :     const SvXMLStyleContext* pControlStyle =
     348           0 :         m_pAutoStyles ? m_pAutoStyles->FindStyleChildContext( XML_STYLE_FAMILY_TEXT_PARAGRAPH, _rStyleName ) : NULL;
     349             :     OSL_ENSURE( pControlStyle || !m_pAutoStyles,
     350             :                 OStringBuffer("OFormLayerXMLImport_Impl::getStyleElement: did not find the style named \"").append(OUStringToOString(_rStyleName, RTL_TEXTENCODING_ASCII_US)).append("\"!").getStr() );
     351           0 :     return pControlStyle;
     352             : }
     353             : 
     354          15 : void OFormLayerXMLImport_Impl::enterEventContext()
     355             : {
     356             :     // install our own translation table. We need to disable the other tables because of name conflicts.
     357          15 :     m_rImporter.GetEventImport().PushTranslationTable();
     358          15 :     m_rImporter.GetEventImport().AddTranslationTable(g_pFormsEventTranslation);
     359          15 : }
     360             : 
     361          15 : void OFormLayerXMLImport_Impl::leaveEventContext()
     362             : {
     363             :     // install the original event tables.
     364          15 :     m_rImporter.GetEventImport().PopTranslationTable();
     365          15 : }
     366             : 
     367          39 : void OFormLayerXMLImport_Impl::registerControlId(const Reference< XPropertySet >& _rxControl, const OUString& _rId)
     368             : {
     369             :     OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::registerControlId: no current page!");
     370             :     OSL_ENSURE(!_rId.isEmpty(), "OFormLayerXMLImport_Impl::registerControlId: invalid (empty) control id!");
     371             : 
     372             :     OSL_ENSURE(m_aCurrentPageIds->second.end() == m_aCurrentPageIds->second.find(_rId), "OFormLayerXMLImport_Impl::registerControlId: control id already used!");
     373          39 :     m_aCurrentPageIds->second[_rId] = _rxControl;
     374          39 : }
     375             : 
     376           0 : void OFormLayerXMLImport_Impl::registerControlReferences(const Reference< XPropertySet >& _rxControl, const OUString& _rReferringControls)
     377             : {
     378             :     OSL_ENSURE(!_rReferringControls.isEmpty(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (empty) control id list!");
     379             :     OSL_ENSURE(_rxControl.is(), "OFormLayerXMLImport_Impl::registerControlReferences: invalid (NULL) control!");
     380           0 :     m_aControlReferences.push_back( ModelStringPair( _rxControl, _rReferringControls ) );
     381           0 : }
     382             : 
     383        1039 : void OFormLayerXMLImport_Impl::startPage(const Reference< XDrawPage >& _rxDrawPage)
     384             : {
     385        1039 :     m_xCurrentPageFormsSupp.clear();
     386             : 
     387             :     OSL_ENSURE(_rxDrawPage.is(), "OFormLayerXMLImport_Impl::startPage: NULL page!");
     388        1039 :     m_xCurrentPageFormsSupp.set(_rxDrawPage, css::uno::UNO_QUERY);
     389             :     OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::startPage: invalid draw page (no XFormsSupplier)!" );
     390        1039 :     if ( !m_xCurrentPageFormsSupp.is() )
     391        1039 :         return;
     392             : 
     393             :     // add a new entry to our page map
     394        1039 :     ::std::pair< MapDrawPage2Map::iterator, bool > aPagePosition;
     395        2078 :     aPagePosition =
     396        3117 :         m_aControlIds.insert(MapDrawPage2Map::value_type(_rxDrawPage, MapString2PropertySet()));
     397             :     OSL_ENSURE(aPagePosition.second, "OFormLayerXMLImport_Impl::startPage: already imported this page!");
     398        1039 :     m_aCurrentPageIds = aPagePosition.first;
     399             : }
     400             : 
     401        1039 : void OFormLayerXMLImport_Impl::endPage()
     402             : {
     403             :     OSL_ENSURE( m_xCurrentPageFormsSupp.is(), "OFormLayerXMLImport_Impl::endPage: sure you called startPage before?" );
     404             : 
     405             :     // do some knittings for the controls which are referring to each other
     406             :     try
     407             :     {
     408             :         static const sal_Unicode s_nSeparator = ',';
     409        1039 :         OUString sReferring;
     410        2078 :         OUString sCurrentReferring;
     411        2078 :         OUString sSeparator(&s_nSeparator, 1);
     412        2078 :         Reference< XPropertySet > xCurrentReferring;
     413             :         sal_Int32 nSeparator, nPrevSep;
     414        1039 :         ::std::vector< ModelStringPair >::const_iterator aEnd = m_aControlReferences.end();
     415        1039 :         for (   ::std::vector< ModelStringPair >::const_iterator aReferences = m_aControlReferences.begin();
     416             :                 aReferences != aEnd;
     417             :                 ++aReferences
     418             :             )
     419             :         {
     420             :             // the list of control ids is comma separated
     421             : 
     422             :             // in a list of n ids there are only n-1 separators ... have to catch this last id
     423             :             // -> normalize the list
     424           0 :             sReferring = aReferences->second;
     425           0 :             sReferring += sSeparator;
     426             : 
     427           0 :             nPrevSep = -1;
     428           0 :             while (-1 != (nSeparator = sReferring.indexOf(s_nSeparator, nPrevSep + 1)))
     429             :             {
     430           0 :                 sCurrentReferring = sReferring.copy(nPrevSep + 1, nSeparator - nPrevSep - 1);
     431           0 :                 xCurrentReferring = lookupControlId(sCurrentReferring);
     432           0 :                 if (xCurrentReferring.is())
     433             :                     // if this condition fails, this is an error, but lookupControlId should have asserted this ...
     434           0 :                     xCurrentReferring->setPropertyValue( PROPERTY_CONTROLLABEL, makeAny( aReferences->first ) );
     435             : 
     436           0 :                 nPrevSep = nSeparator;
     437             :             }
     438        1039 :         }
     439             :     }
     440           0 :     catch(Exception&)
     441             :     {
     442             :         OSL_FAIL("OFormLayerXMLImport_Impl::endPage: unable to knit the control references (caught an exception)!");
     443             :     }
     444             : 
     445             :     // now that we have all children of the forms collection, attach the events
     446        1039 :     Reference< XIndexAccess > xIndexContainer;
     447        1039 :     if ( m_xCurrentPageFormsSupp.is() && m_xCurrentPageFormsSupp->hasForms() )
     448          15 :         xIndexContainer.set(m_xCurrentPageFormsSupp->getForms(), css::uno::UNO_QUERY);
     449        1039 :     if ( xIndexContainer.is() )
     450          15 :         ODefaultEventAttacherManager::setEvents( xIndexContainer );
     451             : 
     452             :     // clear the structures for the control references.
     453        1039 :     m_aControlReferences.clear();
     454             : 
     455             :     // and no we have no current page anymore
     456        1039 :     m_aCurrentPageIds = m_aControlIds.end();
     457        1039 : }
     458             : 
     459          39 : Reference< XPropertySet > OFormLayerXMLImport_Impl::lookupControlId(const OUString& _rControlId)
     460             : {
     461             :     OSL_ENSURE(m_aCurrentPageIds != m_aControlIds.end(), "OFormLayerXMLImport_Impl::lookupControlId: no current page!");
     462          39 :     Reference< XPropertySet > xReturn;
     463          39 :     if (m_aCurrentPageIds != m_aControlIds.end())
     464             :     {
     465          39 :         MapString2PropertySet::const_iterator aPos = m_aCurrentPageIds->second.find(_rControlId);
     466          39 :         if (m_aCurrentPageIds->second.end() != aPos)
     467          39 :             xReturn = aPos->second;
     468             :         else
     469             :             OSL_FAIL("OFormLayerXMLImport_Impl::lookupControlId: invalid control id (did not find it)!");
     470             :     }
     471          39 :     return xReturn;
     472             : }
     473             : 
     474          66 : SvXMLImportContext* OFormLayerXMLImport_Impl::createOfficeFormsContext(
     475             :     SvXMLImport& _rImport,
     476             :     sal_uInt16 _nPrefix,
     477             :     const OUString& _rLocalName)
     478             : {
     479          66 :     return new OFormsRootImport( _rImport, _nPrefix, _rLocalName );
     480             : }
     481             : 
     482          15 : SvXMLImportContext* OFormLayerXMLImport_Impl::createContext(const sal_uInt16 _nPrefix, const OUString& _rLocalName,
     483             :     const Reference< xml::sax::XAttributeList >&)
     484             : {
     485          15 :     SvXMLImportContext* pContext = NULL;
     486          15 :     if ( _rLocalName == "form" )
     487             :     {
     488          15 :         if ( m_xCurrentPageFormsSupp.is() )
     489          15 :             pContext = new OFormImport(*this, *this, _nPrefix, _rLocalName, m_xCurrentPageFormsSupp->getForms() );
     490             :     }
     491           0 :     else if (  ( _nPrefix == XML_NAMESPACE_XFORMS
     492           0 :             && ( xmloff::token::IsXMLToken( _rLocalName, xmloff::token::XML_MODEL ) ) )
     493             :             )
     494             :     {
     495           0 :         pContext = createXFormsModelContext( m_rImporter, _nPrefix, _rLocalName );
     496             :     }
     497             : 
     498          15 :     if ( !pContext )
     499             :     {
     500             :         OSL_FAIL( "unknown element" );
     501             :         pContext =
     502           0 :             new SvXMLImportContext(m_rImporter, _nPrefix, _rLocalName);
     503             :     }
     504             : 
     505          15 :     return pContext;
     506             : }
     507             : 
     508        1233 : void OFormLayerXMLImport_Impl::documentDone( )
     509             : {
     510        1233 :     SvXMLImport& rImport = getGlobalContext();
     511        1233 :     if ( !( rImport.getImportFlags() & SvXMLImportFlags::CONTENT ) )
     512        1733 :         return;
     513             : 
     514             :     // create (and bind) the spreadsheet cell bindings
     515        1466 :     if  (   !m_aCellValueBindings.empty()
     516         733 :         &&  FormCellBindingHelper::isCellBindingAllowed( rImport.GetModel() )
     517             :         )
     518             :     {
     519             :         static const char s_sIndex[] = ":index";
     520           0 :         ::std::vector< ModelStringPair >::const_iterator aEnd = m_aCellValueBindings.end();
     521           0 :         for (   ::std::vector< ModelStringPair >::const_iterator aCellBindings = m_aCellValueBindings.begin();
     522             :                 aCellBindings != aEnd;
     523             :                 ++aCellBindings
     524             :             )
     525             :         {
     526             :             try
     527             :             {
     528           0 :                 FormCellBindingHelper aHelper( aCellBindings->first, rImport.GetModel() );
     529             :                 OSL_ENSURE( aHelper.isCellBindingAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
     530           0 :                 if ( aHelper.isCellBindingAllowed() )
     531             :                 {
     532             :                     // There are special bindings for listboxes. See
     533             :                     // OListAndComboImport::doRegisterCellValueBinding for a comment on this HACK.
     534           0 :                     OUString sBoundCellAddress( aCellBindings->second );
     535           0 :                     sal_Int32 nIndicator = sBoundCellAddress.lastIndexOf( s_sIndex );
     536             : 
     537           0 :                     bool bUseIndexBinding = false;
     538           0 :                     if ( nIndicator != -1 )
     539             :                     {
     540           0 :                         sBoundCellAddress = sBoundCellAddress.copy( 0, nIndicator );
     541           0 :                         bUseIndexBinding = true;
     542             :                     }
     543             : 
     544           0 :                     aHelper.setBinding( aHelper.createCellBindingFromStringAddress( sBoundCellAddress, bUseIndexBinding ) );
     545           0 :                 }
     546             :             }
     547           0 :             catch( const Exception& )
     548             :             {
     549             :                 OSL_FAIL( "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell!" );
     550             :             }
     551             :         }
     552           0 :         m_aCellValueBindings.clear();
     553             :     }
     554             : 
     555             :     // the same for the spreadsheet cell range list sources
     556        1466 :     if  (   !m_aCellRangeListSources.empty()
     557         733 :         &&  FormCellBindingHelper::isListCellRangeAllowed( rImport.GetModel() )
     558             :         )
     559             :     {
     560           0 :         for (   ::std::vector< ModelStringPair >::const_iterator aRangeBindings = m_aCellRangeListSources.begin();
     561           0 :                 aRangeBindings != m_aCellRangeListSources.end();
     562             :                 ++aRangeBindings
     563             :             )
     564             :         {
     565             :             try
     566             :             {
     567           0 :                 FormCellBindingHelper aHelper( aRangeBindings->first, rImport.GetModel() );
     568             :                 OSL_ENSURE( aHelper.isListCellRangeAllowed(), "OFormLayerXMLImport_Impl::documentDone: can't bind this control model!" );
     569           0 :                 if ( aHelper.isListCellRangeAllowed() )
     570             :                 {
     571           0 :                     aHelper.setListSource( aHelper.createCellListSourceFromStringAddress( aRangeBindings->second ) );
     572           0 :                 }
     573             :             }
     574           0 :             catch( const Exception& )
     575             :             {
     576             :                 OSL_FAIL( "OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell range!" );
     577             :             }
     578             :         }
     579           0 :         m_aCellRangeListSources.clear();
     580             :     }
     581             : 
     582             :     // process XForms-bindings; call registerXFormsValueBinding for each
     583             :     std::for_each( m_aXFormsValueBindings.begin(),
     584             :                    m_aXFormsValueBindings.end(),
     585         733 :                    std::bind( bindXFormsValueBinding, rImport.GetModel(), std::placeholders::_1 ) );
     586             :     // same for list bindings
     587             :     std::for_each( m_aXFormsListBindings.begin(),
     588             :                    m_aXFormsListBindings.end(),
     589         733 :                    std::bind( bindXFormsListBinding, rImport.GetModel(), std::placeholders::_1 ) );
     590             :     // same for submissions
     591             :     std::for_each( m_aXFormsSubmissions.begin(),
     592             :                    m_aXFormsSubmissions.end(),
     593         733 :                    std::bind( bindXFormsSubmission, rImport.GetModel(), std::placeholders::_1 ) );
     594             : }
     595             : 
     596             : }   // namespace xmloff
     597             : 
     598             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11