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 $
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
;
46 // ============================================================================
48 AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2
& rFragment
, AxControlModelBase
& rModel
) :
49 ContextHandler2( rFragment
),
51 mnPropId( XML_TOKEN_INVALID
)
55 ContextHandlerRef
AxControlPropertyContext::onCreateContext( sal_Int32 nElement
, const AttributeList
& rAttribs
)
57 switch( getCurrentElement() )
60 if( nElement
== AX_TOKEN( ocxPr
) )
62 mnPropId
= rAttribs
.getToken( AX_TOKEN( name
), XML_TOKEN_INVALID
);
65 case XML_TOKEN_INVALID
:
69 return this; // import picture path from ax:picture child element
71 mrModel
.importProperty( mnPropId
, rAttribs
.getString( AX_TOKEN( value
), OUString() ) );
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
);
92 // ============================================================================
94 AxControlFragment::AxControlFragment( XmlFilterBase
& rFilter
, const OUString
& rFragmentPath
, AxControl
& rControl
) :
95 FragmentHandler2( rFilter
, rFragmentPath
, true ),
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
);
114 // ============================================================================