update dev300-m58
[ooovba.git] / oox / source / ole / axcontrolhelper.cxx
bloba1bd9bfd9ac75fddda8495192964c27e6dc494f1
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: axcontrolhelper.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/axcontrolhelper.hxx"
32 #include <com/sun/star/container/XNameContainer.hpp>
33 #include <com/sun/star/form/XForm.hpp>
34 #include <com/sun/star/form/XFormsSupplier.hpp>
35 #include "tokens.hxx"
36 #include "oox/helper/containerhelper.hxx"
37 #include "oox/core/filterbase.hxx"
38 #include "oox/drawingml/color.hxx"
40 using ::rtl::OUString;
41 using ::com::sun::star::uno::Any;
42 using ::com::sun::star::uno::Exception;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::UNO_QUERY_THROW;
45 using ::com::sun::star::uno::UNO_SET_THROW;
46 using ::com::sun::star::container::XNameContainer;
47 using ::com::sun::star::graphic::XGraphic;
48 using ::com::sun::star::drawing::XDrawPage;
49 using ::com::sun::star::form::XForm;
50 using ::com::sun::star::form::XFormsSupplier;
51 using ::oox::core::FilterBase;
53 namespace oox {
54 namespace ole {
56 // ============================================================================
58 namespace {
60 const sal_uInt32 AX_COLORTYPE_MASK = 0xFF000000;
61 const sal_uInt32 AX_COLORTYPE_CLIENT = 0x00000000;
62 const sal_uInt32 AX_COLORTYPE_PALETTE = 0x01000000;
63 const sal_uInt32 AX_COLORTYPE_BGR = 0x02000000;
64 const sal_uInt32 AX_COLORTYPE_SYSCOLOR = 0x80000000;
66 const sal_uInt32 AX_PALETTECOLOR_MASK = 0x0000FFFF;
67 const sal_uInt32 AX_BGRCOLOR_MASK = 0x00FFFFFF;
68 const sal_uInt32 AX_SYSTEMCOLOR_MASK = 0x0000FFFF;
70 // ----------------------------------------------------------------------------
72 /** Returns the UNO RGB color from the passed encoded OLE BGR color. */
73 inline sal_Int32 lclDecodeBgrColor( sal_uInt32 nAxColor )
75 return static_cast< sal_Int32 >( ((nAxColor & 0x0000FF) << 16) | (nAxColor & 0x00FF00) | ((nAxColor & 0xFF0000) >> 16) );
78 } // namespace
80 // ============================================================================
82 AxControlHelper::AxControlHelper( const FilterBase& rFilter, AxDefaultColorMode eColorMode ) :
83 mrFilter( rFilter ),
84 meColorMode( eColorMode ),
85 mbHasFormQuerried( false )
89 AxControlHelper::~AxControlHelper()
93 Reference< XForm > AxControlHelper::getControlForm() const
95 if( !mbHasFormQuerried )
96 mxForm = createControlForm(); // virtual call
97 mbHasFormQuerried = true;
98 return mxForm;
101 sal_Int32 AxControlHelper::convertColor( sal_uInt32 nAxColor ) const
103 static const sal_Int32 spnSystemColors[] =
105 XML_scrollBar, XML_background, XML_activeCaption, XML_inactiveCaption,
106 XML_menu, XML_window, XML_windowFrame, XML_menuText,
107 XML_windowText, XML_captionText, XML_activeBorder, XML_inactiveBorder,
108 XML_appWorkspace, XML_highlight, XML_highlightText, XML_btnFace,
109 XML_btnShadow, XML_grayText, XML_btnText, XML_inactiveCaptionText,
110 XML_btnHighlight, XML_3dDkShadow, XML_3dLight, XML_infoText,
111 XML_infoBk
114 switch( nAxColor & AX_COLORTYPE_MASK )
116 case AX_COLORTYPE_CLIENT:
117 switch( meColorMode )
119 case AX_DEFAULTCOLORMODE_BGR: return lclDecodeBgrColor( nAxColor );
120 case AX_DEFAULTCOLORMODE_PALETTE: return getPaletteColor( static_cast< sal_uInt16 >( nAxColor & AX_PALETTECOLOR_MASK ) );
122 break;
124 case AX_COLORTYPE_PALETTE:
125 return getPaletteColor( static_cast< sal_uInt16 >( nAxColor & AX_PALETTECOLOR_MASK ) );
127 case AX_COLORTYPE_BGR:
128 return lclDecodeBgrColor( nAxColor );
130 case AX_COLORTYPE_SYSCOLOR:
131 return mrFilter.getSystemColor( STATIC_ARRAY_SELECT( spnSystemColors, nAxColor & AX_SYSTEMCOLOR_MASK, XML_TOKEN_INVALID ), API_RGB_WHITE );
133 OSL_ENSURE( false, "AxControlHelper::convertColor - unknown color type" );
134 return 0;
137 sal_Int32 AxControlHelper::getPaletteColor( sal_uInt16 /*nPaletteIdx*/ ) const
139 OSL_ENSURE( false, "AxControlHelper::getPaletteColor - palette colors not implemented" );
140 return 0;
143 // ============================================================================
145 AxEmbeddedControlHelper::AxEmbeddedControlHelper( const FilterBase& rFilter,
146 const Reference< XDrawPage >& rxDrawPage, AxDefaultColorMode eColorMode ) :
147 AxControlHelper( rFilter, eColorMode ),
148 mxDrawPage( rxDrawPage )
152 Reference< XForm > AxEmbeddedControlHelper::createControlForm() const
154 Reference< XForm > xForm;
157 Reference< XFormsSupplier > xFormsSupplier( mxDrawPage, UNO_QUERY_THROW );
158 Reference< XNameContainer > xFormsNC( xFormsSupplier->getForms(), UNO_SET_THROW );
159 OUString aFormName = CREATE_OUSTRING( "Standard" );
160 if( xFormsNC->hasByName( aFormName ) )
162 xFormsNC->getByName( aFormName ) >>= xForm;
164 else
166 Reference< XForm > xNewForm( getFilter().getModelFactory()->createInstance( CREATE_OUSTRING( "com.sun.star.form.component.Form" ) ), UNO_QUERY_THROW );
167 xFormsNC->insertByName( aFormName, Any( xNewForm ) );
168 // return the form if insertion did not fail
169 xForm = xNewForm;
172 catch( Exception& )
175 return xForm;
178 // ============================================================================
180 } // namespace ole
181 } // namespace oox