1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*ca5ec200SAndrew Rist * distributed with this work for additional information
6*ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at
10*ca5ec200SAndrew Rist *
11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist *
13*ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the
17*ca5ec200SAndrew Rist * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist * under the License.
19*ca5ec200SAndrew Rist *
20*ca5ec200SAndrew Rist *************************************************************/
21*ca5ec200SAndrew Rist
22*ca5ec200SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "oox/ole/axcontrolfragment.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx"
27cdf0e10cSrcweir #include "oox/helper/binaryinputstream.hxx"
28cdf0e10cSrcweir #include "oox/helper/binaryoutputstream.hxx"
29cdf0e10cSrcweir #include "oox/ole/axcontrol.hxx"
30cdf0e10cSrcweir #include "oox/ole/olehelper.hxx"
31cdf0e10cSrcweir #include "oox/ole/olestorage.hxx"
32cdf0e10cSrcweir
33cdf0e10cSrcweir namespace oox {
34cdf0e10cSrcweir namespace ole {
35cdf0e10cSrcweir
36cdf0e10cSrcweir // ============================================================================
37cdf0e10cSrcweir
38cdf0e10cSrcweir using namespace ::com::sun::star::io;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir
41cdf0e10cSrcweir using ::oox::core::ContextHandler2;
42cdf0e10cSrcweir using ::oox::core::ContextHandlerRef;
43cdf0e10cSrcweir using ::oox::core::FragmentHandler2;
44cdf0e10cSrcweir using ::oox::core::XmlFilterBase;
45cdf0e10cSrcweir using ::rtl::OUString;
46cdf0e10cSrcweir
47cdf0e10cSrcweir // ============================================================================
48cdf0e10cSrcweir
AxControlPropertyContext(FragmentHandler2 & rFragment,ControlModelBase & rModel)49cdf0e10cSrcweir AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2& rFragment, ControlModelBase& rModel ) :
50cdf0e10cSrcweir ContextHandler2( rFragment ),
51cdf0e10cSrcweir mrModel( rModel ),
52cdf0e10cSrcweir mnPropId( XML_TOKEN_INVALID )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)56cdf0e10cSrcweir ContextHandlerRef AxControlPropertyContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir switch( getCurrentElement() )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir case AX_TOKEN( ocx ):
61cdf0e10cSrcweir if( nElement == AX_TOKEN( ocxPr ) )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir mnPropId = rAttribs.getToken( AX_TOKEN( name ), XML_TOKEN_INVALID );
64cdf0e10cSrcweir switch( mnPropId )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir case XML_TOKEN_INVALID:
67cdf0e10cSrcweir return 0;
68cdf0e10cSrcweir case XML_Picture:
69cdf0e10cSrcweir case XML_MouseIcon:
70cdf0e10cSrcweir return this; // import picture path from ax:picture child element
71cdf0e10cSrcweir default:
72cdf0e10cSrcweir mrModel.importProperty( mnPropId, rAttribs.getString( AX_TOKEN( value ), OUString() ) );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir }
75cdf0e10cSrcweir break;
76cdf0e10cSrcweir
77cdf0e10cSrcweir case AX_TOKEN( ocxPr ):
78cdf0e10cSrcweir if( nElement == AX_TOKEN( picture ) )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir OUString aPicturePath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
81cdf0e10cSrcweir if( aPicturePath.getLength() > 0 )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir BinaryXInputStream aInStrm( getFilter().openInputStream( aPicturePath ), true );
84cdf0e10cSrcweir mrModel.importPictureData( mnPropId, aInStrm );
85cdf0e10cSrcweir }
86cdf0e10cSrcweir }
87cdf0e10cSrcweir break;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir return 0;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir // ============================================================================
93cdf0e10cSrcweir
AxControlFragment(XmlFilterBase & rFilter,const OUString & rFragmentPath,EmbeddedControl & rControl)94cdf0e10cSrcweir AxControlFragment::AxControlFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, EmbeddedControl& rControl ) :
95cdf0e10cSrcweir FragmentHandler2( rFilter, rFragmentPath, true ),
96cdf0e10cSrcweir mrControl( rControl )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
onCreateContext(sal_Int32 nElement,const AttributeList & rAttribs)100cdf0e10cSrcweir ContextHandlerRef AxControlFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir if( isRootElement() && (nElement == AX_TOKEN( ocx )) )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir OUString aClassId = rAttribs.getString( AX_TOKEN( classid ), OUString() );
105cdf0e10cSrcweir switch( rAttribs.getToken( AX_TOKEN( persistence ), XML_TOKEN_INVALID ) )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir case XML_persistPropertyBag:
108cdf0e10cSrcweir if( ControlModelBase* pModel = mrControl.createModelFromGuid( aClassId ) )
109cdf0e10cSrcweir return new AxControlPropertyContext( *this, *pModel );
110cdf0e10cSrcweir break;
111cdf0e10cSrcweir
112cdf0e10cSrcweir case XML_persistStreamInit:
113cdf0e10cSrcweir {
114cdf0e10cSrcweir OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
115cdf0e10cSrcweir if( aFragmentPath.getLength() > 0 )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir BinaryXInputStream aInStrm( getFilter().openInputStream( aFragmentPath ), true );
118cdf0e10cSrcweir if( !aInStrm.isEof() )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir // binary stream contains a copy of the class ID, must be equal to attribute value
121cdf0e10cSrcweir OUString aStrmClassId = OleHelper::importGuid( aInStrm );
122cdf0e10cSrcweir OSL_ENSURE( aClassId.equalsIgnoreAsciiCase( aStrmClassId ),
123cdf0e10cSrcweir "AxControlFragment::importBinaryControl - form control class ID mismatch" );
124cdf0e10cSrcweir if( ControlModelBase* pModel = mrControl.createModelFromGuid( aStrmClassId ) )
125cdf0e10cSrcweir pModel->importBinaryModel( aInStrm );
126cdf0e10cSrcweir }
127cdf0e10cSrcweir }
128cdf0e10cSrcweir }
129cdf0e10cSrcweir break;
130cdf0e10cSrcweir
131cdf0e10cSrcweir case XML_persistStorage:
132cdf0e10cSrcweir {
133cdf0e10cSrcweir OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
134cdf0e10cSrcweir if( aFragmentPath.getLength() > 0 )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir Reference< XInputStream > xStrgStrm = getFilter().openInputStream( aFragmentPath );
137cdf0e10cSrcweir if( xStrgStrm.is() )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir OleStorage aStorage( getFilter().getComponentContext(), xStrgStrm, false );
140cdf0e10cSrcweir BinaryXInputStream aInStrm( aStorage.openInputStream( CREATE_OUSTRING( "f" ) ), true );
141cdf0e10cSrcweir if( !aInStrm.isEof() )
142cdf0e10cSrcweir if( AxContainerModelBase* pModel = dynamic_cast< AxContainerModelBase* >( mrControl.createModelFromGuid( aClassId ) ) )
143cdf0e10cSrcweir pModel->importBinaryModel( aInStrm );
144cdf0e10cSrcweir }
145cdf0e10cSrcweir }
146cdf0e10cSrcweir }
147cdf0e10cSrcweir break;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir }
150cdf0e10cSrcweir return 0;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir // ============================================================================
154cdf0e10cSrcweir
155cdf0e10cSrcweir } // namespace ole
156cdf0e10cSrcweir } // namespace oox
157