LibreOffice Module oox (master) 1
axcontrolfragment.cxx
Go to the documentation of this file.
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
21
22#include <com/sun/star/io/XInputStream.hpp>
26#include <oox/ole/axcontrol.hxx>
27#include <oox/ole/olehelper.hxx>
29#include <oox/token/namespaces.hxx>
30#include <oox/token/tokens.hxx>
31
32#include <osl/diagnose.h>
33
34namespace oox::ole {
35
36using namespace ::com::sun::star::io;
37using namespace ::com::sun::star::uno;
38
39using ::oox::core::ContextHandler2;
41using ::oox::core::FragmentHandler2;
42using ::oox::core::XmlFilterBase;
43
44AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2 const & rFragment, ControlModelBase& rModel ) :
45 ContextHandler2( rFragment ),
46 mrModel( rModel ),
47 mnPropId( XML_TOKEN_INVALID )
48{
49}
50
52{
53 switch( getCurrentElement() )
54 {
55 case AX_TOKEN( ocx ):
56 if( nElement == AX_TOKEN( ocxPr ) )
57 {
58 mnPropId = rAttribs.getToken( AX_TOKEN( name ), XML_TOKEN_INVALID );
59 switch( mnPropId )
60 {
62 return nullptr;
63 case XML_Picture:
64 case XML_MouseIcon:
65 return this; // import picture path from ax:picture child element
66 default:
67 mrModel.importProperty( mnPropId, rAttribs.getStringDefaulted( AX_TOKEN( value )) );
68 }
69 }
70 break;
71
72 case AX_TOKEN( ocxPr ):
73 if( nElement == AX_TOKEN( picture ) )
74 {
75 OUString aPicturePath = getFragmentPathFromRelId( rAttribs.getStringDefaulted( R_TOKEN( id )) );
76 if( !aPicturePath.isEmpty() )
77 {
78 BinaryXInputStream aInStrm( getFilter().openInputStream( aPicturePath ), true );
80 }
81 }
82 break;
83 }
84 return nullptr;
85}
86
87AxControlFragment::AxControlFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, EmbeddedControl& rControl ) :
88 FragmentHandler2( rFilter, rFragmentPath, true ),
89 mrControl( rControl )
90{
91}
92
94{
95 if( isRootElement() && (nElement == AX_TOKEN( ocx )) )
96 {
97 OUString aClassId = rAttribs.getStringDefaulted( AX_TOKEN( classid ));
98 switch( rAttribs.getToken( AX_TOKEN( persistence ), XML_TOKEN_INVALID ) )
99 {
100 case XML_persistPropertyBag:
101 if( ControlModelBase* pModel = mrControl.createModelFromGuid( aClassId ) )
102 return new AxControlPropertyContext( *this, *pModel );
103 break;
104
105 case XML_persistStreamInit:
106 {
107 OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getStringDefaulted( R_TOKEN( id )) );
108 if( !aFragmentPath.isEmpty() )
109 {
110 BinaryXInputStream aInStrm( getFilter().openInputStream( aFragmentPath ), true );
111 if( !aInStrm.isEof() )
112 {
113 // binary stream contains a copy of the class ID, must be equal to attribute value
114 OUString aStrmClassId = OleHelper::importGuid( aInStrm );
115 OSL_ENSURE( aClassId.equalsIgnoreAsciiCase( aStrmClassId ),
116 "AxControlFragment::importBinaryControl - form control class ID mismatch" );
117 if( ControlModelBase* pModel = mrControl.createModelFromGuid( aStrmClassId ) )
118 pModel->importBinaryModel( aInStrm );
119 }
120 }
121 }
122 break;
123
124 case XML_persistStorage:
125 {
126 OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getStringDefaulted( R_TOKEN( id )) );
127 if( !aFragmentPath.isEmpty() )
128 {
129 Reference< XInputStream > xStrgStrm = getFilter().openInputStream( aFragmentPath );
130 if( xStrgStrm.is() )
131 {
132 // Try to import as a parent control
133 bool bImportedAsParent = false;
134 OleStorage aStorage( getFilter().getComponentContext(), xStrgStrm, false );
135 BinaryXInputStream aInStrm( aStorage.openInputStream( "f" ), true );
136 if( !aInStrm.isEof() )
137 {
138 if( AxContainerModelBase* pModel = dynamic_cast< AxContainerModelBase* >( mrControl.createModelFromGuid( aClassId ) ) )
139 {
140 pModel->importBinaryModel( aInStrm );
141 bImportedAsParent = true;
142 }
143 }
144 // Import it as a non-parent control
145 if(!bImportedAsParent)
146 {
147 BinaryXInputStream aInStrm2(aStorage.openInputStream("contents"), true);
148 if (!aInStrm2.isEof())
149 {
150 if (ControlModelBase* pModel = mrControl.createModelFromGuid(aClassId))
151 {
152 pModel->importBinaryModel(aInStrm2);
153 }
154 }
155 }
156 }
157 }
158 }
159 break;
160 }
161 }
162 return nullptr;
163}
164
165} // namespace oox::ole
166
167/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ChartModel & mrModel
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
Returns the token identifier of the value of the specified attribute.
bool isEof() const
Returns true, if the stream position is invalid (EOF).
Wraps a UNO input stream and provides convenient access functions.
css::uno::Reference< css::io::XInputStream > openInputStream(const OUString &rStreamName)
Opens and returns the specified input stream from the storage.
XmlFilterBase & getFilter() const
Returns the filter instance.
OUString getFragmentPathFromRelId(const OUString &rRelId) const
Returns the full fragment path for the passed relation identifier.
Base class for ActiveX container controls.
Definition: axcontrol.hxx:798
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
AxControlFragment(::oox::core::XmlFilterBase &rFilter, const OUString &rFragmentPath, EmbeddedControl &rControl)
Context handler for ActiveX form control model properties.
AxControlPropertyContext(::oox::core::FragmentHandler2 const &rFragment, ControlModelBase &rModel)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
sal_Int32 mnPropId
Identifier of currently processed property.
Base class for all models of form controls.
Definition: axcontrol.hxx:347
virtual void importProperty(sal_Int32 nPropId, const OUString &rValue)
Derived classes set specific OOXML properties at the model structure.
Definition: axcontrol.cxx:634
virtual void importPictureData(sal_Int32 nPropId, BinaryInputStream &rInStrm)
Derived classes set binary data (picture, mouse icon) at the model structure.
Definition: axcontrol.cxx:638
A form control embedded in a document draw page.
Definition: axcontrol.hxx:898
ControlModelBase * createModelFromGuid(std::u16string_view rClassId)
Creates and returns the internal control model according to the passed MS class identifier.
Definition: axcontrol.cxx:2663
Implements stream access for binary OLE storages.
Definition: olestorage.hxx:44
Any value
const char * name
@ picture
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
::rtl::Reference< ContextHandler > ContextHandlerRef
OOX_DLLPUBLIC OUString importGuid(BinaryInputStream &rInStrm)
Imports a GUID from the passed binary stream and returns its string representation (in uppercase char...
Definition: olehelper.cxx:261
XML_TOKEN_INVALID