2010-10-12 15:53:47 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-11-12 17:21:24 +00:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2000-12-06 16:32:01 +00:00
# include "layerimport.hxx"
# include "formenums.hxx"
# include "elementimport.hxx"
2001-03-20 12:39:58 +00:00
# include "officeforms.hxx"
2000-12-06 16:32:01 +00:00
# include "strings.hxx"
2007-06-27 14:17:04 +00:00
# include <xmloff/xmlictxt.hxx>
# include <xmloff/xmlstyle.hxx>
# include <xmloff/families.hxx>
# include <xmloff/xmlprmap.hxx>
# include <xmloff/prstylei.hxx>
# include <xmloff/xmlimp.hxx>
2001-01-02 14:58:22 +00:00
# include "XMLEventImportHelper.hxx"
2007-06-27 14:17:04 +00:00
# include <xmloff/xmlimppr.hxx>
# include <xmloff/xmlnumfi.hxx>
2001-05-28 13:59:18 +00:00
# include <com/sun/star/util/XNumberFormatsSupplier.hpp>
2000-12-06 16:32:01 +00:00
# include <com/sun/star/form/FormSubmitEncoding.hpp>
# include <com/sun/star/form/FormSubmitMethod.hpp>
# include <com/sun/star/sdb/CommandType.hpp>
# include <com/sun/star/form/NavigationBarMode.hpp>
# include <com/sun/star/form/TabulatorCycle.hpp>
# include <com/sun/star/form/FormButtonType.hpp>
2003-12-11 11:09:57 +00:00
# include <com/sun/star/awt/ScrollBarOrientation.hpp>
2004-07-05 15:09:35 +00:00
# include <com/sun/star/awt/VisualEffect.hpp>
2000-12-06 16:32:01 +00:00
# include <com/sun/star/form/ListSourceType.hpp>
2014-02-24 12:25:02 +01:00
# include <tools/gen.hxx>
2001-05-28 13:59:18 +00:00
# include <com/sun/star/lang/Locale.hpp>
2007-06-27 14:17:04 +00:00
# include <xmloff/controlpropertyhdl.hxx>
2000-12-18 14:14:35 +00:00
# include "controlpropertymap.hxx"
2001-01-02 14:58:22 +00:00
# include "formevents.hxx"
2003-10-21 07:40:08 +00:00
# include "formcellbinding.hxx"
2013-11-11 22:30:35 -06:00
# include <xmloff/xformsimport.hxx>
2007-06-27 14:17:04 +00:00
# include <xmloff/xmltoken.hxx>
2013-11-11 22:30:35 -06:00
# include <xmloff/xmlnmspe.hxx>
2011-10-05 09:27:07 +01:00
# include <rtl/strbuf.hxx>
2004-11-16 09:10:27 +00:00
# include <algorithm>
2015-05-08 17:29:01 +09:00
# include <functional>
2000-12-18 14:14:35 +00:00
2000-12-06 16:32:01 +00:00
namespace xmloff
{
2009-04-23 10:42:05 +00:00
using namespace : : com : : sun : : star : : uno ;
using namespace : : com : : sun : : star : : awt ;
using namespace : : com : : sun : : star : : lang ;
using namespace : : com : : sun : : star : : beans ;
using namespace : : com : : sun : : star : : container ;
using namespace : : com : : sun : : star : : drawing ;
2012-07-02 13:58:52 +02:00
using namespace : : com : : sun : : star ;
2009-04-23 10:42:05 +00:00
using namespace : : com : : sun : : star : : util ;
using namespace : : com : : sun : : star : : form ;
using namespace : : com : : sun : : star : : sdb ;
//= OFormLayerXMLImport_Impl
OFormLayerXMLImport_Impl : : OFormLayerXMLImport_Impl ( SvXMLImport & _rImporter )
: m_rImporter ( _rImporter )
2015-11-10 10:29:15 +01:00
, m_pAutoStyles ( nullptr )
2009-04-23 10:42:05 +00:00
{
// build the attribute2property map
// string properties which are exported as attributes
m_aAttributeMetaData . addStringProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Name ) , PROPERTY_NAME ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addStringProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : GroupName ) , PROPERTY_GROUP_NAME ) ;
2015-02-05 21:43:33 +01:00
m_aAttributeMetaData . addStringProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : ImageData ) , PROPERTY_IMAGEURL ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addStringProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Label ) , PROPERTY_LABEL ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addStringProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : TargetLocation ) , PROPERTY_TARGETURL ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addStringProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Title ) , PROPERTY_TITLE ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addStringProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : TargetFrame ) , PROPERTY_TARGETFRAME , " _blank " ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addStringProperty (
2016-05-12 14:12:29 +02:00
OAttributeMetaData : : getDatabaseAttributeName ( DAFlags : : DataField ) , PROPERTY_DATAFIELD ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addStringProperty (
OAttributeMetaData : : getFormAttributeName ( faCommand ) , PROPERTY_COMMAND ) ;
m_aAttributeMetaData . addStringProperty (
OAttributeMetaData : : getFormAttributeName ( faDatasource ) , PROPERTY_DATASOURCENAME ) ;
m_aAttributeMetaData . addStringProperty (
OAttributeMetaData : : getFormAttributeName ( faFilter ) , PROPERTY_FILTER ) ;
m_aAttributeMetaData . addStringProperty (
OAttributeMetaData : : getFormAttributeName ( faOrder ) , PROPERTY_ORDER ) ;
// properties not added because they're already present in another form
OSL_ENSURE (
2016-05-12 14:05:29 +02:00
OUString : : createFromAscii ( OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : TargetLocation ) ) . equalsAscii (
2009-04-23 10:42:05 +00:00
OAttributeMetaData : : getFormAttributeName ( faAction ) ) ,
" OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (1)! " ) ;
// if this fails, we would have to add a translation from faAction->PROPERTY_TARGETURL
2016-05-12 14:05:29 +02:00
// We did not because we already have one CCAFlags::TargetLocation->PROPERTY_TARGETURL,
// and CCAFlags::TargetLocation and faAction should be represented by the same attribute
2009-04-23 10:42:05 +00:00
OSL_ENSURE (
2016-05-12 14:05:29 +02:00
OUString : : createFromAscii ( OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Name ) ) . equalsAscii (
2009-04-23 10:42:05 +00:00
OAttributeMetaData : : getFormAttributeName ( faName ) ) ,
" OFormLayerXMLImport_Impl::OFormLayerXMLImport_Impl: invalid attribute names (2)! " ) ;
2016-05-12 14:05:29 +02:00
// the same for faName, CCAFlags::Name and PROPERTY_NAME
2009-04-23 10:42:05 +00:00
// boolean properties which are exported as attributes
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : CurrentSelected ) , PROPERTY_STATE , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Disabled ) , PROPERTY_ENABLED , false , true ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Dropdown ) , PROPERTY_DROPDOWN , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Printable ) , PROPERTY_PRINTABLE , true ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : ReadOnly ) , PROPERTY_READONLY , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Selected ) , PROPERTY_DEFAULT_STATE , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : TabStop ) , PROPERTY_TABSTOP , true ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:12:29 +02:00
OAttributeMetaData : : getDatabaseAttributeName ( DAFlags : : ConvertEmpty ) , PROPERTY_EMPTY_IS_NULL , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : Validation ) , PROPERTY_STRICTFORMAT , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : MultiLine ) , PROPERTY_MULTILINE , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : AutoCompletion ) , PROPERTY_AUTOCOMPLETE , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : Multiple ) , PROPERTY_MULTISELECTION , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : DefaultButton ) , PROPERTY_DEFAULTBUTTON , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : IsTristate ) , PROPERTY_TRISTATE , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2014-04-07 16:42:18 +02:00
OAttributeMetaData : : getFormAttributeName ( faAllowDeletes ) , PROPERTY_ALLOWDELETES , true ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2014-04-07 16:42:18 +02:00
OAttributeMetaData : : getFormAttributeName ( faAllowInserts ) , PROPERTY_ALLOWINSERTS , true ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2014-04-07 16:42:18 +02:00
OAttributeMetaData : : getFormAttributeName ( faAllowUpdates ) , PROPERTY_ALLOWUPDATES , true ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2014-04-07 16:42:18 +02:00
OAttributeMetaData : : getFormAttributeName ( faApplyFilter ) , PROPERTY_APPLYFILTER , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2014-04-07 16:42:18 +02:00
OAttributeMetaData : : getFormAttributeName ( faEscapeProcessing ) , PROPERTY_ESCAPEPROCESSING , true ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2014-04-07 16:42:18 +02:00
OAttributeMetaData : : getFormAttributeName ( faIgnoreResult ) , PROPERTY_IGNORERESULT , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : Toggle ) , PROPERTY_TOGGLE , false ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : FocusOnClick ) , PROPERTY_FOCUS_ON_CLICK , true ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addBooleanProperty (
2016-05-12 14:12:29 +02:00
OAttributeMetaData : : getDatabaseAttributeName ( DAFlags : : InputRequired ) , PROPERTY_INPUT_REQUIRED , false ) ;
2009-04-23 10:42:05 +00:00
// the int16 attributes
m_aAttributeMetaData . addInt16Property (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : MaxLength ) , PROPERTY_MAXTEXTLENGTH , 0 ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addInt16Property (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Size ) , PROPERTY_LINECOUNT , 5 ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addInt16Property (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : TabIndex ) , PROPERTY_TABINDEX , 0 ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addInt16Property (
2016-05-12 14:12:29 +02:00
OAttributeMetaData : : getDatabaseAttributeName ( DAFlags : : BoundColumn ) , PROPERTY_BOUNDCOLUMN , 0 ) ;
2009-04-23 10:42:05 +00:00
// the int32 attributes
m_aAttributeMetaData . addInt32Property (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : PageStepSize ) , PROPERTY_BLOCK_INCREMENT , 10 ) ;
2009-04-23 10:42:05 +00:00
// the enum attributes
m_aAttributeMetaData . addEnumProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : VisualEffect ) , PROPERTY_VISUAL_EFFECT ,
2009-04-23 10:42:05 +00:00
VisualEffect : : LOOK3D , OEnumMapper : : getEnumMap ( OEnumMapper : : epVisualEffect ) ,
2014-05-10 23:51:21 +02:00
& : : cppu : : UnoType < sal_Int16 > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addEnumProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : Orientation ) , PROPERTY_ORIENTATION ,
2009-04-23 10:42:05 +00:00
ScrollBarOrientation : : HORIZONTAL , OEnumMapper : : getEnumMap ( OEnumMapper : : epOrientation ) ,
2014-05-10 23:51:21 +02:00
& : : cppu : : UnoType < sal_Int32 > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addEnumProperty (
2016-05-12 14:05:29 +02:00
OAttributeMetaData : : getCommonControlAttributeName ( CCAFlags : : ButtonType ) , PROPERTY_BUTTONTYPE ,
2009-04-23 10:42:05 +00:00
FormButtonType_PUSH , OEnumMapper : : getEnumMap ( OEnumMapper : : epButtonType ) ,
2014-05-10 23:51:21 +02:00
& : : cppu : : UnoType < FormButtonType > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addEnumProperty (
2016-05-12 14:12:29 +02:00
OAttributeMetaData : : getDatabaseAttributeName ( DAFlags : : ListSource_TYPE ) , PROPERTY_LISTSOURCETYPE ,
2009-04-23 10:42:05 +00:00
ListSourceType_VALUELIST , OEnumMapper : : getEnumMap ( OEnumMapper : : epListSourceType ) ,
2014-05-11 10:09:04 +02:00
& : : cppu : : UnoType < ListSourceType > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addEnumProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : State ) , PROPERTY_DEFAULT_STATE , TRISTATE_FALSE ,
2009-04-23 10:42:05 +00:00
OEnumMapper : : getEnumMap ( OEnumMapper : : epCheckState ) ,
2014-05-10 23:51:21 +02:00
& : : cppu : : UnoType < sal_Int16 > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addEnumProperty (
2016-05-12 14:32:30 +02:00
OAttributeMetaData : : getSpecialAttributeName ( SCAFlags : : CurrentState ) , PROPERTY_STATE , TRISTATE_FALSE ,
2009-04-23 10:42:05 +00:00
OEnumMapper : : getEnumMap ( OEnumMapper : : epCheckState ) ,
2014-05-10 23:51:21 +02:00
& : : cppu : : UnoType < sal_Int16 > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addEnumProperty (
OAttributeMetaData : : getFormAttributeName ( faEnctype ) , PROPERTY_SUBMIT_ENCODING ,
FormSubmitEncoding_URL , OEnumMapper : : getEnumMap ( OEnumMapper : : epSubmitEncoding ) ,
2014-05-10 23:51:21 +02:00
& : : cppu : : UnoType < FormSubmitEncoding > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addEnumProperty (
OAttributeMetaData : : getFormAttributeName ( faMethod ) , PROPERTY_SUBMIT_METHOD ,
FormSubmitMethod_GET , OEnumMapper : : getEnumMap ( OEnumMapper : : epSubmitMethod ) ,
2014-05-10 23:51:21 +02:00
& : : cppu : : UnoType < FormSubmitMethod > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addEnumProperty (
OAttributeMetaData : : getFormAttributeName ( faCommandType ) , PROPERTY_COMMAND_TYPE ,
CommandType : : COMMAND , OEnumMapper : : getEnumMap ( OEnumMapper : : epCommandType ) ) ;
m_aAttributeMetaData . addEnumProperty (
OAttributeMetaData : : getFormAttributeName ( faNavigationMode ) , PROPERTY_NAVIGATION ,
NavigationBarMode_NONE , OEnumMapper : : getEnumMap ( OEnumMapper : : epNavigationType ) ,
2014-05-11 10:09:04 +02:00
& : : cppu : : UnoType < NavigationBarMode > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
m_aAttributeMetaData . addEnumProperty (
OAttributeMetaData : : getFormAttributeName ( faTabbingCycle ) , PROPERTY_CYCLE ,
TabulatorCycle_RECORDS , OEnumMapper : : getEnumMap ( OEnumMapper : : epTabCyle ) ,
2014-05-11 10:09:04 +02:00
& : : cppu : : UnoType < TabulatorCycle > : : get ( ) ) ;
2009-04-23 10:42:05 +00:00
// 'initialize'
m_aCurrentPageIds = m_aControlIds . end ( ) ;
}
OFormLayerXMLImport_Impl : : ~ OFormLayerXMLImport_Impl ( )
{
// outlined to allow forward declaration of OAttribute2Property in the header
2000-12-06 16:32:01 +00:00
2009-04-23 10:42:05 +00:00
if ( m_pAutoStyles )
m_pAutoStyles - > ReleaseRef ( ) ;
}
2001-05-28 13:59:18 +00:00
2009-04-23 10:42:05 +00:00
void OFormLayerXMLImport_Impl : : setAutoStyleContext ( SvXMLStylesContext * _pNewContext )
{
OSL_ENSURE ( ! m_pAutoStyles , " OFormLayerXMLImport_Impl::setAutoStyleContext: not to be called twice! " ) ;
m_pAutoStyles = _pNewContext ;
if ( m_pAutoStyles )
2014-10-02 14:37:06 +02:00
m_pAutoStyles - > AddFirstRef ( ) ;
2009-04-23 10:42:05 +00:00
}
2013-04-07 12:06:47 +02:00
void OFormLayerXMLImport_Impl : : applyControlNumberStyle ( const Reference < XPropertySet > & _rxControlModel , const OUString & _rControlNumerStyleName )
2009-04-23 10:42:05 +00:00
{
2012-01-25 21:59:48 -02:00
OSL_ENSURE ( _rxControlModel . is ( ) & & ( ! _rControlNumerStyleName . isEmpty ( ) ) ,
2009-04-23 10:42:05 +00:00
" OFormLayerXMLImport_Impl::applyControlNumberStyle: invalid arguments (this will crash)! " ) ;
2001-05-28 13:59:18 +00:00
2009-04-23 10:42:05 +00:00
OSL_ENSURE ( m_pAutoStyles , " OFormLayerXMLImport_Impl::applyControlNumberStyle: have no auto style context! " ) ;
if ( ! m_pAutoStyles )
2001-05-28 13:59:18 +00:00
{
2009-04-23 10:42:05 +00:00
m_pAutoStyles = m_rImporter . GetShapeImport ( ) - > GetAutoStylesContext ( ) ;
2001-05-28 13:59:18 +00:00
if ( m_pAutoStyles )
2014-10-02 14:37:06 +02:00
m_pAutoStyles - > AddFirstRef ( ) ;
2001-05-28 13:59:18 +00:00
}
2009-04-23 10:42:05 +00:00
if ( m_pAutoStyles )
2001-05-28 13:59:18 +00:00
{
2009-04-23 10:42:05 +00:00
const SvXMLStyleContext * pStyle = m_pAutoStyles - > FindStyleChildContext ( XML_STYLE_FAMILY_DATA_STYLE , _rControlNumerStyleName ) ;
if ( pStyle )
2001-05-28 13:59:18 +00:00
{
2009-04-23 10:42:05 +00:00
const SvXMLNumFormatContext * pDataStyle = static_cast < const SvXMLNumFormatContext * > ( pStyle ) ;
2001-05-28 13:59:18 +00:00
2009-04-23 10:42:05 +00:00
// set this format at the control model
try
2001-05-28 13:59:18 +00:00
{
2009-04-23 10:42:05 +00:00
// the models number format supplier and formats
Reference < XNumberFormatsSupplier > xFormatsSupplier ;
_rxControlModel - > getPropertyValue ( PROPERTY_FORMATSSUPPLIER ) > > = xFormatsSupplier ;
Reference < XNumberFormats > xFormats ;
if ( xFormatsSupplier . is ( ) )
xFormats = xFormatsSupplier - > getNumberFormats ( ) ;
OSL_ENSURE ( xFormats . is ( ) , " OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain the controls number formats! " ) ;
// obtain a key
if ( xFormats . is ( ) )
2001-05-28 13:59:18 +00:00
{
2009-04-23 10:42:05 +00:00
sal_Int32 nFormatKey = const_cast < SvXMLNumFormatContext * > ( pDataStyle ) - > CreateAndInsert ( xFormatsSupplier ) ;
OSL_ENSURE ( - 1 ! = nFormatKey , " OFormLayerXMLImport_Impl::applyControlNumberStyle: could not obtain a format key! " ) ;
2005-03-08 14:37:10 +00:00
2009-04-23 10:42:05 +00:00
// set the format on the control model
_rxControlModel - > setPropertyValue ( PROPERTY_FORMATKEY , makeAny ( nFormatKey ) ) ;
2001-05-28 13:59:18 +00:00
}
}
2009-04-23 10:42:05 +00:00
catch ( const Exception & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OFormLayerXMLImport_Impl::applyControlNumberStyle: couldn't set the format! " ) ;
2009-04-23 10:42:05 +00:00
}
2001-05-28 13:59:18 +00:00
}
2009-04-23 10:42:05 +00:00
else
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OFormLayerXMLImport_Impl::applyControlNumberStyle: did not find the style with the given name! " ) ;
2000-12-06 16:32:01 +00:00
}
2009-04-23 10:42:05 +00:00
}
2000-12-06 16:32:01 +00:00
2013-04-07 12:06:47 +02:00
void OFormLayerXMLImport_Impl : : registerCellValueBinding ( const Reference < XPropertySet > & _rxControlModel , const OUString & _rCellAddress )
2009-04-23 10:42:05 +00:00
{
2012-01-25 21:59:48 -02:00
OSL_ENSURE ( _rxControlModel . is ( ) & & ! _rCellAddress . isEmpty ( ) ,
2009-04-23 10:42:05 +00:00
" OFormLayerXMLImport_Impl::registerCellValueBinding: invalid arguments! " ) ;
m_aCellValueBindings . push_back ( ModelStringPair ( _rxControlModel , _rCellAddress ) ) ;
}
void OFormLayerXMLImport_Impl : : registerXFormsValueBinding (
const Reference < XPropertySet > & _rxControlModel ,
2013-04-07 12:06:47 +02:00
const OUString & _rBindingID )
2009-04-23 10:42:05 +00:00
{
// TODO: is an empty binding name allowed?
OSL_ENSURE ( _rxControlModel . is ( ) , " need model " ) ;
2003-10-21 07:40:08 +00:00
2009-04-23 10:42:05 +00:00
m_aXFormsValueBindings . push_back (
ModelStringPair ( _rxControlModel , _rBindingID ) ) ;
}
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
void OFormLayerXMLImport_Impl : : registerXFormsListBinding (
const Reference < XPropertySet > & _rxControlModel ,
2013-04-07 12:06:47 +02:00
const OUString & _rBindingID )
2009-04-23 10:42:05 +00:00
{
// TODO: is an empty binding name allowed?
OSL_ENSURE ( _rxControlModel . is ( ) , " need model " ) ;
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
m_aXFormsListBindings . push_back (
ModelStringPair ( _rxControlModel , _rBindingID ) ) ;
}
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
void OFormLayerXMLImport_Impl : : registerXFormsSubmission (
const Reference < XPropertySet > & _rxControlModel ,
2013-04-07 12:06:47 +02:00
const OUString & _rSubmissionID )
2009-04-23 10:42:05 +00:00
{
// TODO: is an empty binding name allowed?
OSL_ENSURE ( _rxControlModel . is ( ) , " need model " ) ;
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
m_aXFormsSubmissions . push_back (
ModelStringPair ( _rxControlModel , _rSubmissionID ) ) ;
}
2002-10-25 12:19:34 +00:00
2013-04-07 12:06:47 +02:00
void OFormLayerXMLImport_Impl : : registerCellRangeListSource ( const Reference < XPropertySet > & _rxControlModel , const OUString & _rCellRangeAddress )
2009-04-23 10:42:05 +00:00
{
2012-01-25 21:59:48 -02:00
OSL_ENSURE ( _rxControlModel . is ( ) & & ! _rCellRangeAddress . isEmpty ( ) ,
2009-04-23 10:42:05 +00:00
" OFormLayerXMLImport_Impl::registerCellRangeListSource: invalid arguments! " ) ;
m_aCellRangeListSources . push_back ( ModelStringPair ( _rxControlModel , _rCellRangeAddress ) ) ;
}
2013-04-07 12:06:47 +02:00
const SvXMLStyleContext * OFormLayerXMLImport_Impl : : getStyleElement ( const OUString & _rStyleName ) const
2009-04-23 10:42:05 +00:00
{
OSL_ENSURE ( m_pAutoStyles , " OFormLayerXMLImport_Impl::getStyleElement: have no auto style context! " ) ;
// did you use setAutoStyleContext?
const SvXMLStyleContext * pControlStyle =
2015-11-10 10:29:15 +01:00
m_pAutoStyles ? m_pAutoStyles - > FindStyleChildContext ( XML_STYLE_FAMILY_TEXT_PARAGRAPH , _rStyleName ) : nullptr ;
2009-04-23 10:42:05 +00:00
OSL_ENSURE ( pControlStyle | | ! m_pAutoStyles ,
2013-04-07 12:06:47 +02:00
OStringBuffer ( " OFormLayerXMLImport_Impl::getStyleElement: did not find the style named \" " ) . append ( OUStringToOString ( _rStyleName , RTL_TEXTENCODING_ASCII_US ) ) . append ( " \" ! " ) . getStr ( ) ) ;
2009-04-23 10:42:05 +00:00
return pControlStyle ;
}
void OFormLayerXMLImport_Impl : : enterEventContext ( )
{
// install our own translation table. We need to disable the other tables because of name conflicts.
m_rImporter . GetEventImport ( ) . PushTranslationTable ( ) ;
m_rImporter . GetEventImport ( ) . AddTranslationTable ( g_pFormsEventTranslation ) ;
}
2001-01-24 08:34:40 +00:00
2009-04-23 10:42:05 +00:00
void OFormLayerXMLImport_Impl : : leaveEventContext ( )
{
// install the original event tables.
m_rImporter . GetEventImport ( ) . PopTranslationTable ( ) ;
}
2001-01-24 08:34:40 +00:00
2013-04-07 12:06:47 +02:00
void OFormLayerXMLImport_Impl : : registerControlId ( const Reference < XPropertySet > & _rxControl , const OUString & _rId )
2009-04-23 10:42:05 +00:00
{
OSL_ENSURE ( m_aCurrentPageIds ! = m_aControlIds . end ( ) , " OFormLayerXMLImport_Impl::registerControlId: no current page! " ) ;
2012-01-25 21:59:48 -02:00
OSL_ENSURE ( ! _rId . isEmpty ( ) , " OFormLayerXMLImport_Impl::registerControlId: invalid (empty) control id! " ) ;
2000-12-13 09:40:15 +00:00
2009-04-23 10:42:05 +00:00
OSL_ENSURE ( m_aCurrentPageIds - > second . end ( ) = = m_aCurrentPageIds - > second . find ( _rId ) , " OFormLayerXMLImport_Impl::registerControlId: control id already used! " ) ;
m_aCurrentPageIds - > second [ _rId ] = _rxControl ;
}
2000-12-12 11:01:05 +00:00
2013-04-07 12:06:47 +02:00
void OFormLayerXMLImport_Impl : : registerControlReferences ( const Reference < XPropertySet > & _rxControl , const OUString & _rReferringControls )
2009-04-23 10:42:05 +00:00
{
2012-01-25 21:59:48 -02:00
OSL_ENSURE ( ! _rReferringControls . isEmpty ( ) , " OFormLayerXMLImport_Impl::registerControlReferences: invalid (empty) control id list! " ) ;
2009-04-23 10:42:05 +00:00
OSL_ENSURE ( _rxControl . is ( ) , " OFormLayerXMLImport_Impl::registerControlReferences: invalid (NULL) control! " ) ;
m_aControlReferences . push_back ( ModelStringPair ( _rxControl , _rReferringControls ) ) ;
}
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
void OFormLayerXMLImport_Impl : : startPage ( const Reference < XDrawPage > & _rxDrawPage )
{
m_xCurrentPageFormsSupp . clear ( ) ;
OSL_ENSURE ( _rxDrawPage . is ( ) , " OFormLayerXMLImport_Impl::startPage: NULL page! " ) ;
2014-06-13 17:53:15 +02:00
m_xCurrentPageFormsSupp . set ( _rxDrawPage , css : : uno : : UNO_QUERY ) ;
2009-04-23 10:42:05 +00:00
OSL_ENSURE ( m_xCurrentPageFormsSupp . is ( ) , " OFormLayerXMLImport_Impl::startPage: invalid draw page (no XFormsSupplier)! " ) ;
if ( ! m_xCurrentPageFormsSupp . is ( ) )
return ;
// add a new entry to our page map
2013-12-06 10:17:37 +01:00
: : std : : pair < MapDrawPage2Map : : iterator , bool > aPagePosition ;
2009-04-23 10:42:05 +00:00
aPagePosition =
m_aControlIds . insert ( MapDrawPage2Map : : value_type ( _rxDrawPage , MapString2PropertySet ( ) ) ) ;
OSL_ENSURE ( aPagePosition . second , " OFormLayerXMLImport_Impl::startPage: already imported this page! " ) ;
m_aCurrentPageIds = aPagePosition . first ;
}
void OFormLayerXMLImport_Impl : : endPage ( )
{
OSL_ENSURE ( m_xCurrentPageFormsSupp . is ( ) , " OFormLayerXMLImport_Impl::endPage: sure you called startPage before? " ) ;
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
// do some knittings for the controls which are referring to each other
try
2000-12-12 11:01:05 +00:00
{
2009-04-23 10:42:05 +00:00
static const sal_Unicode s_nSeparator = ' , ' ;
2013-04-07 12:06:47 +02:00
OUString sReferring ;
OUString sCurrentReferring ;
OUString sSeparator ( & s_nSeparator , 1 ) ;
2009-04-23 10:42:05 +00:00
Reference < XPropertySet > xCurrentReferring ;
sal_Int32 nSeparator , nPrevSep ;
: : std : : vector < ModelStringPair > : : const_iterator aEnd = m_aControlReferences . end ( ) ;
for ( : : std : : vector < ModelStringPair > : : const_iterator aReferences = m_aControlReferences . begin ( ) ;
aReferences ! = aEnd ;
+ + aReferences
)
2000-12-12 11:01:05 +00:00
{
2009-04-23 10:42:05 +00:00
// the list of control ids is comma separated
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
// in a list of n ids there are only n-1 separators ... have to catch this last id
// -> normalize the list
sReferring = aReferences - > second ;
sReferring + = sSeparator ;
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
nPrevSep = - 1 ;
while ( - 1 ! = ( nSeparator = sReferring . indexOf ( s_nSeparator , nPrevSep + 1 ) ) )
{
sCurrentReferring = sReferring . copy ( nPrevSep + 1 , nSeparator - nPrevSep - 1 ) ;
xCurrentReferring = lookupControlId ( sCurrentReferring ) ;
if ( xCurrentReferring . is ( ) )
// if this condition fails, this is an error, but lookupControlId should have asserted this ...
xCurrentReferring - > setPropertyValue ( PROPERTY_CONTROLLABEL , makeAny ( aReferences - > first ) ) ;
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
nPrevSep = nSeparator ;
2000-12-12 11:01:05 +00:00
}
}
2009-04-23 10:42:05 +00:00
}
catch ( Exception & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OFormLayerXMLImport_Impl::endPage: unable to knit the control references (caught an exception)! " ) ;
2009-04-23 10:42:05 +00:00
}
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
// now that we have all children of the forms collection, attach the events
Reference < XIndexAccess > xIndexContainer ;
if ( m_xCurrentPageFormsSupp . is ( ) & & m_xCurrentPageFormsSupp - > hasForms ( ) )
2014-06-13 17:53:15 +02:00
xIndexContainer . set ( m_xCurrentPageFormsSupp - > getForms ( ) , css : : uno : : UNO_QUERY ) ;
2009-04-23 10:42:05 +00:00
if ( xIndexContainer . is ( ) )
ODefaultEventAttacherManager : : setEvents ( xIndexContainer ) ;
2001-01-02 14:58:22 +00:00
2009-04-23 10:42:05 +00:00
// clear the structures for the control references.
m_aControlReferences . clear ( ) ;
2000-12-12 11:01:05 +00:00
2009-04-23 10:42:05 +00:00
// and no we have no current page anymore
m_aCurrentPageIds = m_aControlIds . end ( ) ;
}
2000-12-12 11:01:05 +00:00
2013-04-07 12:06:47 +02:00
Reference < XPropertySet > OFormLayerXMLImport_Impl : : lookupControlId ( const OUString & _rControlId )
2009-04-23 10:42:05 +00:00
{
OSL_ENSURE ( m_aCurrentPageIds ! = m_aControlIds . end ( ) , " OFormLayerXMLImport_Impl::lookupControlId: no current page! " ) ;
Reference < XPropertySet > xReturn ;
if ( m_aCurrentPageIds ! = m_aControlIds . end ( ) )
2000-12-12 11:01:05 +00:00
{
2013-12-05 22:41:15 +01:00
MapString2PropertySet : : const_iterator aPos = m_aCurrentPageIds - > second . find ( _rControlId ) ;
2009-04-23 10:42:05 +00:00
if ( m_aCurrentPageIds - > second . end ( ) ! = aPos )
xReturn = aPos - > second ;
else
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OFormLayerXMLImport_Impl::lookupControlId: invalid control id (did not find it)! " ) ;
2000-12-06 16:32:01 +00:00
}
2009-04-23 10:42:05 +00:00
return xReturn ;
}
SvXMLImportContext * OFormLayerXMLImport_Impl : : createOfficeFormsContext (
SvXMLImport & _rImport ,
sal_uInt16 _nPrefix ,
2013-04-07 12:06:47 +02:00
const OUString & _rLocalName )
2009-04-23 10:42:05 +00:00
{
return new OFormsRootImport ( _rImport , _nPrefix , _rLocalName ) ;
}
2000-12-06 16:32:01 +00:00
2013-04-07 12:06:47 +02:00
SvXMLImportContext * OFormLayerXMLImport_Impl : : createContext ( const sal_uInt16 _nPrefix , const OUString & _rLocalName ,
2012-07-02 13:58:52 +02:00
const Reference < xml : : sax : : XAttributeList > & )
2009-04-23 10:42:05 +00:00
{
2015-11-10 10:29:15 +01:00
SvXMLImportContext * pContext = nullptr ;
2014-12-12 12:25:35 +01:00
if ( _rLocalName = = " form " )
2001-03-20 12:39:58 +00:00
{
2009-04-23 10:42:05 +00:00
if ( m_xCurrentPageFormsSupp . is ( ) )
pContext = new OFormImport ( * this , * this , _nPrefix , _rLocalName , m_xCurrentPageFormsSupp - > getForms ( ) ) ;
2001-03-20 12:39:58 +00:00
}
2009-04-23 10:42:05 +00:00
else if ( ( _nPrefix = = XML_NAMESPACE_XFORMS
& & ( xmloff : : token : : IsXMLToken ( _rLocalName , xmloff : : token : : XML_MODEL ) ) )
)
2000-12-06 16:32:01 +00:00
{
2009-04-23 10:42:05 +00:00
pContext = createXFormsModelContext ( m_rImporter , _nPrefix , _rLocalName ) ;
2000-12-06 16:32:01 +00:00
}
2009-04-23 10:42:05 +00:00
if ( ! pContext )
2000-12-13 09:40:15 +00:00
{
2011-03-12 14:27:45 +01:00
OSL_FAIL ( " unknown element " ) ;
2009-04-23 10:42:05 +00:00
pContext =
new SvXMLImportContext ( m_rImporter , _nPrefix , _rLocalName ) ;
2000-12-13 09:40:15 +00:00
}
2009-04-23 10:42:05 +00:00
return pContext ;
}
void OFormLayerXMLImport_Impl : : documentDone ( )
{
SvXMLImport & rImport = getGlobalContext ( ) ;
2014-12-25 15:17:55 +02:00
if ( ! ( rImport . getImportFlags ( ) & SvXMLImportFlags : : CONTENT ) )
2009-04-23 10:42:05 +00:00
return ;
// create (and bind) the spreadsheet cell bindings
if ( ! m_aCellValueBindings . empty ( )
& & FormCellBindingHelper : : isCellBindingAllowed ( rImport . GetModel ( ) )
)
{
2014-11-03 14:03:54 +02:00
static const char s_sIndex [ ] = " :index " ;
2009-04-23 10:42:05 +00:00
: : std : : vector < ModelStringPair > : : const_iterator aEnd = m_aCellValueBindings . end ( ) ;
for ( : : std : : vector < ModelStringPair > : : const_iterator aCellBindings = m_aCellValueBindings . begin ( ) ;
aCellBindings ! = aEnd ;
+ + aCellBindings
2003-10-21 07:40:08 +00:00
)
{
2009-04-23 10:42:05 +00:00
try
2003-10-21 07:40:08 +00:00
{
2009-04-23 10:42:05 +00:00
FormCellBindingHelper aHelper ( aCellBindings - > first , rImport . GetModel ( ) ) ;
OSL_ENSURE ( aHelper . isCellBindingAllowed ( ) , " OFormLayerXMLImport_Impl::documentDone: can't bind this control model! " ) ;
if ( aHelper . isCellBindingAllowed ( ) )
2003-10-21 07:40:08 +00:00
{
2009-04-23 10:42:05 +00:00
// There are special bindings for listboxes. See
// OListAndComboImport::doRegisterCellValueBinding for a comment on this HACK.
2013-04-07 12:06:47 +02:00
OUString sBoundCellAddress ( aCellBindings - > second ) ;
2009-04-23 10:42:05 +00:00
sal_Int32 nIndicator = sBoundCellAddress . lastIndexOf ( s_sIndex ) ;
bool bUseIndexBinding = false ;
if ( nIndicator ! = - 1 )
2003-10-21 07:40:08 +00:00
{
2009-04-23 10:42:05 +00:00
sBoundCellAddress = sBoundCellAddress . copy ( 0 , nIndicator ) ;
bUseIndexBinding = true ;
2003-10-21 07:40:08 +00:00
}
2009-04-23 10:42:05 +00:00
aHelper . setBinding ( aHelper . createCellBindingFromStringAddress ( sBoundCellAddress , bUseIndexBinding ) ) ;
2003-10-21 07:40:08 +00:00
}
}
2009-04-23 10:42:05 +00:00
catch ( const Exception & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell! " ) ;
2009-04-23 10:42:05 +00:00
}
2003-10-21 07:40:08 +00:00
}
2009-04-23 10:42:05 +00:00
m_aCellValueBindings . clear ( ) ;
}
2003-10-21 07:40:08 +00:00
2009-04-23 10:42:05 +00:00
// the same for the spreadsheet cell range list sources
if ( ! m_aCellRangeListSources . empty ( )
& & FormCellBindingHelper : : isListCellRangeAllowed ( rImport . GetModel ( ) )
)
{
for ( : : std : : vector < ModelStringPair > : : const_iterator aRangeBindings = m_aCellRangeListSources . begin ( ) ;
aRangeBindings ! = m_aCellRangeListSources . end ( ) ;
+ + aRangeBindings
2003-10-21 07:40:08 +00:00
)
{
2009-04-23 10:42:05 +00:00
try
2003-10-21 07:40:08 +00:00
{
2009-04-23 10:42:05 +00:00
FormCellBindingHelper aHelper ( aRangeBindings - > first , rImport . GetModel ( ) ) ;
OSL_ENSURE ( aHelper . isListCellRangeAllowed ( ) , " OFormLayerXMLImport_Impl::documentDone: can't bind this control model! " ) ;
if ( aHelper . isListCellRangeAllowed ( ) )
2003-10-21 07:40:08 +00:00
{
2009-04-23 10:42:05 +00:00
aHelper . setListSource ( aHelper . createCellListSourceFromStringAddress ( aRangeBindings - > second ) ) ;
2003-10-21 07:40:08 +00:00
}
}
2009-04-23 10:42:05 +00:00
catch ( const Exception & )
{
2011-03-19 14:09:49 +01:00
OSL_FAIL ( " OFormLayerXMLImport_Impl::documentDone: caught an exception while binding to a cell range! " ) ;
2009-04-23 10:42:05 +00:00
}
2003-10-21 07:40:08 +00:00
}
2009-04-23 10:42:05 +00:00
m_aCellRangeListSources . clear ( ) ;
2003-10-21 07:40:08 +00:00
}
2009-04-23 10:42:05 +00:00
// process XForms-bindings; call registerXFormsValueBinding for each
2015-10-30 00:26:23 -03:00
for ( auto & aXFormsValueBinding : m_aXFormsValueBindings )
bindXFormsValueBinding ( rImport . GetModel ( ) , aXFormsValueBinding ) ;
2009-04-23 10:42:05 +00:00
// same for list bindings
2015-10-30 00:26:23 -03:00
for ( auto & aXFormsListBindings : m_aXFormsListBindings )
bindXFormsListBinding ( rImport . GetModel ( ) , aXFormsListBindings ) ;
2009-04-23 10:42:05 +00:00
// same for submissions
2015-10-30 00:26:23 -03:00
for ( auto & aXFormsSubmission : m_aXFormsSubmissions )
bindXFormsSubmission ( rImport . GetModel ( ) , aXFormsSubmission ) ;
2009-04-23 10:42:05 +00:00
}
2000-12-06 16:32:01 +00:00
} // namespace xmloff
2010-10-12 15:53:47 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */