1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include "oox/ole/axcontrolfragment.hxx"
22 #include "oox/core/xmlfilterbase.hxx"
23 #include "oox/helper/binaryinputstream.hxx"
24 #include "oox/helper/binaryoutputstream.hxx"
25 #include "oox/ole/axcontrol.hxx"
26 #include "oox/ole/olehelper.hxx"
27 #include "oox/ole/olestorage.hxx"
32 // ============================================================================
34 using namespace ::com::sun::star::io
;
35 using namespace ::com::sun::star::uno
;
37 using ::oox::core::ContextHandler2
;
38 using ::oox::core::ContextHandlerRef
;
39 using ::oox::core::FragmentHandler2
;
40 using ::oox::core::XmlFilterBase
;
42 // ============================================================================
44 AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2
& rFragment
, ControlModelBase
& rModel
) :
45 ContextHandler2( rFragment
),
47 mnPropId( XML_TOKEN_INVALID
)
51 ContextHandlerRef
AxControlPropertyContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
53 switch( getCurrentElement() )
56 if( nElement
== AX_TOKEN( ocxPr
) )
58 mnPropId
= rAttribs
.getToken( AX_TOKEN( name
), XML_TOKEN_INVALID
);
61 case XML_TOKEN_INVALID
:
65 return this; // import picture path from ax:picture child element
67 mrModel
.importProperty( mnPropId
, rAttribs
.getString( AX_TOKEN( value
), OUString() ) );
72 case AX_TOKEN( ocxPr
):
73 if( nElement
== AX_TOKEN( picture
) )
75 OUString aPicturePath
= getFragmentPathFromRelId( rAttribs
.getString( R_TOKEN( id
), OUString() ) );
76 if( !aPicturePath
.isEmpty() )
78 BinaryXInputStream
aInStrm( getFilter().openInputStream( aPicturePath
), true );
79 mrModel
.importPictureData( mnPropId
, aInStrm
);
87 // ============================================================================
89 AxControlFragment::AxControlFragment( XmlFilterBase
& rFilter
, const OUString
& rFragmentPath
, EmbeddedControl
& rControl
) :
90 FragmentHandler2( rFilter
, rFragmentPath
, true ),
95 ContextHandlerRef
AxControlFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
97 if( isRootElement() && (nElement
== AX_TOKEN( ocx
)) )
99 OUString aClassId
= rAttribs
.getString( AX_TOKEN( classid
), OUString() );
100 switch( rAttribs
.getToken( AX_TOKEN( persistence
), XML_TOKEN_INVALID
) )
102 case XML_persistPropertyBag
:
103 if( ControlModelBase
* pModel
= mrControl
.createModelFromGuid( aClassId
) )
104 return new AxControlPropertyContext( *this, *pModel
);
107 case XML_persistStreamInit
:
109 OUString aFragmentPath
= getFragmentPathFromRelId( rAttribs
.getString( R_TOKEN( id
), OUString() ) );
110 if( !aFragmentPath
.isEmpty() )
112 BinaryXInputStream
aInStrm( getFilter().openInputStream( aFragmentPath
), true );
113 if( !aInStrm
.isEof() )
115 // binary stream contains a copy of the class ID, must be equal to attribute value
116 OUString aStrmClassId
= OleHelper::importGuid( aInStrm
);
117 OSL_ENSURE( aClassId
.equalsIgnoreAsciiCase( aStrmClassId
),
118 "AxControlFragment::importBinaryControl - form control class ID mismatch" );
119 if( ControlModelBase
* pModel
= mrControl
.createModelFromGuid( aStrmClassId
) )
120 pModel
->importBinaryModel( aInStrm
);
126 case XML_persistStorage
:
128 OUString aFragmentPath
= getFragmentPathFromRelId( rAttribs
.getString( R_TOKEN( id
), OUString() ) );
129 if( !aFragmentPath
.isEmpty() )
131 Reference
< XInputStream
> xStrgStrm
= getFilter().openInputStream( aFragmentPath
);
134 OleStorage
aStorage( getFilter().getComponentContext(), xStrgStrm
, false );
135 BinaryXInputStream
aInStrm( aStorage
.openInputStream( "f" ), true );
136 if( !aInStrm
.isEof() )
137 if( AxContainerModelBase
* pModel
= dynamic_cast< AxContainerModelBase
* >( mrControl
.createModelFromGuid( aClassId
) ) )
138 pModel
->importBinaryModel( aInStrm
);
148 // ============================================================================
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */