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"
29 #include <osl/diagnose.h>
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 AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2
& rFragment
, ControlModelBase
& rModel
) :
43 ContextHandler2( rFragment
),
45 mnPropId( XML_TOKEN_INVALID
)
49 ContextHandlerRef
AxControlPropertyContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
51 switch( getCurrentElement() )
54 if( nElement
== AX_TOKEN( ocxPr
) )
56 mnPropId
= rAttribs
.getToken( AX_TOKEN( name
), XML_TOKEN_INVALID
);
59 case XML_TOKEN_INVALID
:
63 return this; // import picture path from ax:picture child element
65 mrModel
.importProperty( mnPropId
, rAttribs
.getString( AX_TOKEN( value
), OUString() ) );
70 case AX_TOKEN( ocxPr
):
71 if( nElement
== AX_TOKEN( picture
) )
73 OUString aPicturePath
= getFragmentPathFromRelId( rAttribs
.getString( R_TOKEN( id
), OUString() ) );
74 if( !aPicturePath
.isEmpty() )
76 BinaryXInputStream
aInStrm( getFilter().openInputStream( aPicturePath
), true );
77 mrModel
.importPictureData( mnPropId
, aInStrm
);
85 AxControlFragment::AxControlFragment( XmlFilterBase
& rFilter
, const OUString
& rFragmentPath
, EmbeddedControl
& rControl
) :
86 FragmentHandler2( rFilter
, rFragmentPath
, true ),
91 ContextHandlerRef
AxControlFragment::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
93 if( isRootElement() && (nElement
== AX_TOKEN( ocx
)) )
95 OUString aClassId
= rAttribs
.getString( AX_TOKEN( classid
), OUString() );
96 switch( rAttribs
.getToken( AX_TOKEN( persistence
), XML_TOKEN_INVALID
) )
98 case XML_persistPropertyBag
:
99 if( ControlModelBase
* pModel
= mrControl
.createModelFromGuid( aClassId
) )
100 return new AxControlPropertyContext( *this, *pModel
);
103 case XML_persistStreamInit
:
105 OUString aFragmentPath
= getFragmentPathFromRelId( rAttribs
.getString( R_TOKEN( id
), OUString() ) );
106 if( !aFragmentPath
.isEmpty() )
108 BinaryXInputStream
aInStrm( getFilter().openInputStream( aFragmentPath
), true );
109 if( !aInStrm
.isEof() )
111 // binary stream contains a copy of the class ID, must be equal to attribute value
112 OUString aStrmClassId
= OleHelper::importGuid( aInStrm
);
113 OSL_ENSURE( aClassId
.equalsIgnoreAsciiCase( aStrmClassId
),
114 "AxControlFragment::importBinaryControl - form control class ID mismatch" );
115 if( ControlModelBase
* pModel
= mrControl
.createModelFromGuid( aStrmClassId
) )
116 pModel
->importBinaryModel( aInStrm
);
122 case XML_persistStorage
:
124 OUString aFragmentPath
= getFragmentPathFromRelId( rAttribs
.getString( R_TOKEN( id
), OUString() ) );
125 if( !aFragmentPath
.isEmpty() )
127 Reference
< XInputStream
> xStrgStrm
= getFilter().openInputStream( aFragmentPath
);
130 OleStorage
aStorage( getFilter().getComponentContext(), xStrgStrm
, false );
131 BinaryXInputStream
aInStrm( aStorage
.openInputStream( "f" ), true );
132 if( !aInStrm
.isEof() )
133 if( AxContainerModelBase
* pModel
= dynamic_cast< AxContainerModelBase
* >( mrControl
.createModelFromGuid( aClassId
) ) )
134 pModel
->importBinaryModel( aInStrm
);
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */