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