/src/libreoffice/oox/source/ole/axcontrolfragment.cxx
Line | Count | Source |
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 <com/sun/star/io/XInputStream.hpp> |
23 | | #include <oox/core/xmlfilterbase.hxx> |
24 | | #include <oox/helper/attributelist.hxx> |
25 | | #include <oox/helper/binaryinputstream.hxx> |
26 | | #include <oox/ole/axcontrol.hxx> |
27 | | #include <oox/ole/olehelper.hxx> |
28 | | #include <oox/ole/olestorage.hxx> |
29 | | #include <oox/token/namespaces.hxx> |
30 | | #include <oox/token/tokens.hxx> |
31 | | |
32 | | #include <osl/diagnose.h> |
33 | | |
34 | | namespace oox::ole { |
35 | | |
36 | | using namespace ::com::sun::star::io; |
37 | | using namespace ::com::sun::star::uno; |
38 | | |
39 | | using ::oox::core::ContextHandler2; |
40 | | using ::oox::core::ContextHandlerRef; |
41 | | using ::oox::core::FragmentHandler2; |
42 | | using ::oox::core::XmlFilterBase; |
43 | | |
44 | | AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2 const & rFragment, ControlModelBase& rModel ) : |
45 | 0 | ContextHandler2( rFragment ), |
46 | 0 | mrModel( rModel ), |
47 | 0 | mnPropId( XML_TOKEN_INVALID ) |
48 | 0 | { |
49 | 0 | } |
50 | | |
51 | | ContextHandlerRef AxControlPropertyContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) |
52 | 0 | { |
53 | 0 | switch( getCurrentElement() ) |
54 | 0 | { |
55 | 0 | case AX_TOKEN( ocx ): |
56 | 0 | if( nElement == AX_TOKEN( ocxPr ) ) |
57 | 0 | { |
58 | 0 | mnPropId = rAttribs.getToken( AX_TOKEN( name ), XML_TOKEN_INVALID ); |
59 | 0 | switch( mnPropId ) |
60 | 0 | { |
61 | 0 | case XML_TOKEN_INVALID: |
62 | 0 | return nullptr; |
63 | 0 | case XML_Picture: |
64 | 0 | case XML_MouseIcon: |
65 | 0 | return this; // import picture path from ax:picture child element |
66 | 0 | default: |
67 | 0 | mrModel.importProperty( mnPropId, rAttribs.getStringDefaulted( AX_TOKEN( value )) ); |
68 | 0 | } |
69 | 0 | } |
70 | 0 | break; |
71 | | |
72 | 0 | case AX_TOKEN( ocxPr ): |
73 | 0 | if( nElement == AX_TOKEN( picture ) ) |
74 | 0 | { |
75 | 0 | OUString aPicturePath = getFragmentPathFromRelId( rAttribs.getStringDefaulted( R_TOKEN( id )) ); |
76 | 0 | if( !aPicturePath.isEmpty() ) |
77 | 0 | { |
78 | 0 | BinaryXInputStream aInStrm( getFilter().openInputStream( aPicturePath ), true ); |
79 | 0 | mrModel.importPictureData( mnPropId, aInStrm ); |
80 | 0 | } |
81 | 0 | } |
82 | 0 | break; |
83 | 0 | } |
84 | 0 | return nullptr; |
85 | 0 | } |
86 | | |
87 | | AxControlFragment::AxControlFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, EmbeddedControl& rControl ) : |
88 | 20 | FragmentHandler2( rFilter, rFragmentPath, true ), |
89 | 20 | mrControl( rControl ) |
90 | 20 | { |
91 | 20 | } |
92 | | |
93 | | ContextHandlerRef AxControlFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) |
94 | 20 | { |
95 | 20 | if( isRootElement() && (nElement == AX_TOKEN( ocx )) ) |
96 | 20 | { |
97 | 20 | OUString aClassId = rAttribs.getStringDefaulted( AX_TOKEN( classid )); |
98 | 20 | switch( rAttribs.getToken( AX_TOKEN( persistence ), XML_TOKEN_INVALID ) ) |
99 | 20 | { |
100 | 0 | case XML_persistPropertyBag: |
101 | 0 | if( ControlModelBase* pModel = mrControl.createModelFromGuid( aClassId ) ) |
102 | 0 | return new AxControlPropertyContext( *this, *pModel ); |
103 | 0 | break; |
104 | | |
105 | 20 | case XML_persistStreamInit: |
106 | 20 | { |
107 | 20 | OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getStringDefaulted( R_TOKEN( id )) ); |
108 | 20 | if( !aFragmentPath.isEmpty() ) |
109 | 17 | { |
110 | 17 | BinaryXInputStream aInStrm( getFilter().openInputStream( aFragmentPath ), true ); |
111 | 17 | if( !aInStrm.isEof() ) |
112 | 16 | { |
113 | | // binary stream contains a copy of the class ID, must be equal to attribute value |
114 | 16 | OUString aStrmClassId = OleHelper::importGuid( aInStrm ); |
115 | 16 | OSL_ENSURE( aClassId.equalsIgnoreAsciiCase( aStrmClassId ), |
116 | 16 | "AxControlFragment::importBinaryControl - form control class ID mismatch" ); |
117 | 16 | if( ControlModelBase* pModel = mrControl.createModelFromGuid( aStrmClassId ) ) |
118 | 16 | pModel->importBinaryModel( aInStrm ); |
119 | 16 | } |
120 | 17 | } |
121 | 20 | } |
122 | 20 | break; |
123 | | |
124 | 0 | case XML_persistStorage: |
125 | 0 | { |
126 | 0 | OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getStringDefaulted( R_TOKEN( id )) ); |
127 | 0 | if( !aFragmentPath.isEmpty() ) |
128 | 0 | { |
129 | 0 | Reference< XInputStream > xStrgStrm = getFilter().openInputStream( aFragmentPath ); |
130 | 0 | if( xStrgStrm.is() ) |
131 | 0 | { |
132 | | // Try to import as a parent control |
133 | 0 | bool bImportedAsParent = false; |
134 | 0 | OleStorage aStorage( getFilter().getComponentContext(), xStrgStrm, false ); |
135 | 0 | BinaryXInputStream aInStrm( aStorage.openInputStream( u"f"_ustr ), true ); |
136 | 0 | if( !aInStrm.isEof() ) |
137 | 0 | { |
138 | 0 | if( AxContainerModelBase* pModel = dynamic_cast< AxContainerModelBase* >( mrControl.createModelFromGuid( aClassId ) ) ) |
139 | 0 | { |
140 | 0 | pModel->importBinaryModel( aInStrm ); |
141 | 0 | bImportedAsParent = true; |
142 | 0 | } |
143 | 0 | } |
144 | | // Import it as a non-parent control |
145 | 0 | if(!bImportedAsParent) |
146 | 0 | { |
147 | 0 | BinaryXInputStream aInStrm2(aStorage.openInputStream(u"contents"_ustr), true); |
148 | 0 | if (!aInStrm2.isEof()) |
149 | 0 | { |
150 | 0 | if (ControlModelBase* pModel = mrControl.createModelFromGuid(aClassId)) |
151 | 0 | { |
152 | 0 | pModel->importBinaryModel(aInStrm2); |
153 | 0 | } |
154 | 0 | } |
155 | 0 | } |
156 | 0 | } |
157 | 0 | } |
158 | 0 | } |
159 | 0 | break; |
160 | 20 | } |
161 | 20 | } |
162 | 20 | return nullptr; |
163 | 20 | } |
164 | | |
165 | | } // namespace oox::ole |
166 | | |
167 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |