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 "oox/ole/axcontrolfragment.hxx"
21 :
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"
28 :
29 : namespace oox {
30 : namespace ole {
31 :
32 : using namespace ::com::sun::star::io;
33 : using namespace ::com::sun::star::uno;
34 :
35 : using ::oox::core::ContextHandler2;
36 : using ::oox::core::ContextHandlerRef;
37 : using ::oox::core::FragmentHandler2;
38 : using ::oox::core::XmlFilterBase;
39 :
40 0 : AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2& rFragment, ControlModelBase& rModel ) :
41 : ContextHandler2( rFragment ),
42 : mrModel( rModel ),
43 0 : mnPropId( XML_TOKEN_INVALID )
44 : {
45 0 : }
46 :
47 0 : ContextHandlerRef AxControlPropertyContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
48 : {
49 0 : switch( getCurrentElement() )
50 : {
51 : case AX_TOKEN( ocx ):
52 0 : if( nElement == AX_TOKEN( ocxPr ) )
53 : {
54 0 : mnPropId = rAttribs.getToken( AX_TOKEN( name ), XML_TOKEN_INVALID );
55 0 : switch( mnPropId )
56 : {
57 : case XML_TOKEN_INVALID:
58 0 : return 0;
59 : case XML_Picture:
60 : case XML_MouseIcon:
61 0 : return this; // import picture path from ax:picture child element
62 : default:
63 0 : mrModel.importProperty( mnPropId, rAttribs.getString( AX_TOKEN( value ), OUString() ) );
64 : }
65 : }
66 0 : break;
67 :
68 : case AX_TOKEN( ocxPr ):
69 0 : if( nElement == AX_TOKEN( picture ) )
70 : {
71 0 : OUString aPicturePath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
72 0 : if( !aPicturePath.isEmpty() )
73 : {
74 0 : BinaryXInputStream aInStrm( getFilter().openInputStream( aPicturePath ), true );
75 0 : mrModel.importPictureData( mnPropId, aInStrm );
76 0 : }
77 : }
78 0 : break;
79 : }
80 0 : return 0;
81 : }
82 :
83 0 : AxControlFragment::AxControlFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, EmbeddedControl& rControl ) :
84 : FragmentHandler2( rFilter, rFragmentPath, true ),
85 0 : mrControl( rControl )
86 : {
87 0 : }
88 :
89 0 : ContextHandlerRef AxControlFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
90 : {
91 0 : if( isRootElement() && (nElement == AX_TOKEN( ocx )) )
92 : {
93 0 : OUString aClassId = rAttribs.getString( AX_TOKEN( classid ), OUString() );
94 0 : switch( rAttribs.getToken( AX_TOKEN( persistence ), XML_TOKEN_INVALID ) )
95 : {
96 : case XML_persistPropertyBag:
97 0 : if( ControlModelBase* pModel = mrControl.createModelFromGuid( aClassId ) )
98 0 : return new AxControlPropertyContext( *this, *pModel );
99 0 : break;
100 :
101 : case XML_persistStreamInit:
102 : {
103 0 : OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
104 0 : if( !aFragmentPath.isEmpty() )
105 : {
106 0 : BinaryXInputStream aInStrm( getFilter().openInputStream( aFragmentPath ), true );
107 0 : if( !aInStrm.isEof() )
108 : {
109 : // binary stream contains a copy of the class ID, must be equal to attribute value
110 0 : OUString aStrmClassId = OleHelper::importGuid( aInStrm );
111 : OSL_ENSURE( aClassId.equalsIgnoreAsciiCase( aStrmClassId ),
112 : "AxControlFragment::importBinaryControl - form control class ID mismatch" );
113 0 : if( ControlModelBase* pModel = mrControl.createModelFromGuid( aStrmClassId ) )
114 0 : pModel->importBinaryModel( aInStrm );
115 0 : }
116 0 : }
117 : }
118 0 : break;
119 :
120 : case XML_persistStorage:
121 : {
122 0 : OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
123 0 : if( !aFragmentPath.isEmpty() )
124 : {
125 0 : Reference< XInputStream > xStrgStrm = getFilter().openInputStream( aFragmentPath );
126 0 : if( xStrgStrm.is() )
127 : {
128 0 : OleStorage aStorage( getFilter().getComponentContext(), xStrgStrm, false );
129 0 : BinaryXInputStream aInStrm( aStorage.openInputStream( "f" ), true );
130 0 : if( !aInStrm.isEof() )
131 0 : if( AxContainerModelBase* pModel = dynamic_cast< AxContainerModelBase* >( mrControl.createModelFromGuid( aClassId ) ) )
132 0 : pModel->importBinaryModel( aInStrm );
133 0 : }
134 0 : }
135 : }
136 0 : break;
137 0 : }
138 : }
139 0 : return 0;
140 : }
141 :
142 : } // namespace ole
143 408 : } // namespace oox
144 :
145 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|