merge the formfield patch from ooo-build
[ooovba.git] / oox / source / ole / axcontrolfragment.cxx
blobff1b1e1c8117b408073fc4affa3f307d1187a22a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: axcontrolfragment.cxx,v $
10 * $Revision: 1.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/ole/axcontrolfragment.hxx"
32 #include "oox/helper/binaryinputstream.hxx"
33 #include "oox/helper/binaryoutputstream.hxx"
34 #include "oox/core/xmlfilterbase.hxx"
35 #include "oox/ole/axcontrol.hxx"
37 using ::rtl::OUString;
38 using ::oox::core::ContextHandler2;
39 using ::oox::core::ContextHandlerRef;
40 using ::oox::core::FragmentHandler2;
41 using ::oox::core::XmlFilterBase;
43 namespace oox {
44 namespace ole {
46 // ============================================================================
48 AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2& rFragment, AxControlModelBase& rModel ) :
49 ContextHandler2( rFragment ),
50 mrModel( rModel ),
51 mnPropId( XML_TOKEN_INVALID )
55 ContextHandlerRef AxControlPropertyContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
57 switch( getCurrentElement() )
59 case AX_TOKEN( ocx ):
60 if( nElement == AX_TOKEN( ocxPr ) )
62 mnPropId = rAttribs.getToken( AX_TOKEN( name ), XML_TOKEN_INVALID );
63 switch( mnPropId )
65 case XML_TOKEN_INVALID:
66 return 0;
67 case XML_Picture:
68 case XML_MouseIcon:
69 return this; // import picture path from ax:picture child element
70 default:
71 mrModel.importProperty( mnPropId, rAttribs.getString( AX_TOKEN( value ), OUString() ) );
74 break;
76 case AX_TOKEN( ocxPr ):
77 if( nElement == AX_TOKEN( picture ) )
79 OUString aPicturePath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
80 if( aPicturePath.getLength() > 0 )
82 StreamDataSequence aPictureData;
83 if( getFilter().importBinaryData( aPictureData, aPicturePath ) )
84 mrModel.importPictureData( mnPropId, aPictureData );
87 break;
89 return 0;
92 // ============================================================================
94 AxControlFragment::AxControlFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, AxControl& rControl ) :
95 FragmentHandler2( rFilter, rFragmentPath, true ),
96 mrControl( rControl )
100 ContextHandlerRef AxControlFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
102 if( isRootElement() && (nElement == AX_TOKEN( ocx )) )
104 if( rAttribs.getToken( AX_TOKEN( persistence ), XML_TOKEN_INVALID ) == XML_persistPropertyBag )
106 OUString aClassId = rAttribs.getString( AX_TOKEN( classid ), OUString() );
107 if( AxControlModelBase* pModel = mrControl.createModel( aClassId ) )
108 return new AxControlPropertyContext( *this, *pModel );
111 return 0;
114 // ============================================================================
116 } // namespace ole
117 } // namespace oox