GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / ole / axcontrolfragment.cxx
blob7cd0cadb515b071e53daedf12686954d38e2e711
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/ole/axcontrolfragment.hxx"
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"
29 namespace oox {
30 namespace ole {
32 // ============================================================================
34 using namespace ::com::sun::star::io;
35 using namespace ::com::sun::star::uno;
37 using ::oox::core::ContextHandler2;
38 using ::oox::core::ContextHandlerRef;
39 using ::oox::core::FragmentHandler2;
40 using ::oox::core::XmlFilterBase;
42 // ============================================================================
44 AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2& rFragment, ControlModelBase& rModel ) :
45 ContextHandler2( rFragment ),
46 mrModel( rModel ),
47 mnPropId( XML_TOKEN_INVALID )
51 ContextHandlerRef AxControlPropertyContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
53 switch( getCurrentElement() )
55 case AX_TOKEN( ocx ):
56 if( nElement == AX_TOKEN( ocxPr ) )
58 mnPropId = rAttribs.getToken( AX_TOKEN( name ), XML_TOKEN_INVALID );
59 switch( mnPropId )
61 case XML_TOKEN_INVALID:
62 return 0;
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.getString( AX_TOKEN( value ), OUString() ) );
70 break;
72 case AX_TOKEN( ocxPr ):
73 if( nElement == AX_TOKEN( picture ) )
75 OUString aPicturePath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
76 if( !aPicturePath.isEmpty() )
78 BinaryXInputStream aInStrm( getFilter().openInputStream( aPicturePath ), true );
79 mrModel.importPictureData( mnPropId, aInStrm );
82 break;
84 return 0;
87 // ============================================================================
89 AxControlFragment::AxControlFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, EmbeddedControl& rControl ) :
90 FragmentHandler2( rFilter, rFragmentPath, true ),
91 mrControl( rControl )
95 ContextHandlerRef AxControlFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
97 if( isRootElement() && (nElement == AX_TOKEN( ocx )) )
99 OUString aClassId = rAttribs.getString( AX_TOKEN( classid ), OUString() );
100 switch( rAttribs.getToken( AX_TOKEN( persistence ), XML_TOKEN_INVALID ) )
102 case XML_persistPropertyBag:
103 if( ControlModelBase* pModel = mrControl.createModelFromGuid( aClassId ) )
104 return new AxControlPropertyContext( *this, *pModel );
105 break;
107 case XML_persistStreamInit:
109 OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
110 if( !aFragmentPath.isEmpty() )
112 BinaryXInputStream aInStrm( getFilter().openInputStream( aFragmentPath ), true );
113 if( !aInStrm.isEof() )
115 // binary stream contains a copy of the class ID, must be equal to attribute value
116 OUString aStrmClassId = OleHelper::importGuid( aInStrm );
117 OSL_ENSURE( aClassId.equalsIgnoreAsciiCase( aStrmClassId ),
118 "AxControlFragment::importBinaryControl - form control class ID mismatch" );
119 if( ControlModelBase* pModel = mrControl.createModelFromGuid( aStrmClassId ) )
120 pModel->importBinaryModel( aInStrm );
124 break;
126 case XML_persistStorage:
128 OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
129 if( !aFragmentPath.isEmpty() )
131 Reference< XInputStream > xStrgStrm = getFilter().openInputStream( aFragmentPath );
132 if( xStrgStrm.is() )
134 OleStorage aStorage( getFilter().getComponentContext(), xStrgStrm, false );
135 BinaryXInputStream aInStrm( aStorage.openInputStream( "f" ), true );
136 if( !aInStrm.isEof() )
137 if( AxContainerModelBase* pModel = dynamic_cast< AxContainerModelBase* >( mrControl.createModelFromGuid( aClassId ) ) )
138 pModel->importBinaryModel( aInStrm );
142 break;
145 return 0;
148 // ============================================================================
150 } // namespace ole
151 } // namespace oox
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */