update dev300-m58
[ooovba.git] / vbahelper / source / msforms / vbatogglebutton.cxx
blob0d7cfaf2dbf9d383e4a48f745ee9bc7faefa2ba6
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile$
7 * $Revision$
9 * last change: $Author$ $Date$
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
35 #include "vbatogglebutton.hxx"
36 #include <vector>
38 using namespace com::sun::star;
39 using namespace ooo::vba;
42 const static rtl::OUString LABEL( RTL_CONSTASCII_USTRINGPARAM("Label") );
43 const static rtl::OUString TOGGLE( RTL_CONSTASCII_USTRINGPARAM("Toggle") );
44 const static rtl::OUString STATE( RTL_CONSTASCII_USTRINGPARAM("State") );
45 ScVbaToggleButton::ScVbaToggleButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ) : ToggleButtonImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper )
47 OSL_TRACE("ScVbaToggleButton(ctor)");
48 m_xProps->setPropertyValue( TOGGLE, uno::makeAny( sal_True ) );
51 ScVbaToggleButton::~ScVbaToggleButton()
53 OSL_TRACE("~ScVbaToggleButton(dtor)");
56 // Attributes
57 rtl::OUString SAL_CALL
58 ScVbaToggleButton::getCaption() throw (css::uno::RuntimeException)
60 rtl::OUString Label;
61 m_xProps->getPropertyValue( LABEL ) >>= Label;
62 return Label;
65 void SAL_CALL
66 ScVbaToggleButton::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException)
68 m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) );
71 uno::Any SAL_CALL
72 ScVbaToggleButton::getValue() throw (uno::RuntimeException)
74 sal_Int16 nState = 0;
75 m_xProps->getPropertyValue( STATE ) >>= nState;
76 return uno::makeAny( nState ? sal_Int16( -1 ) : sal_Int16( 0 ) );
79 //liuchen 2009-7-23, resolve the defect that ToggleButton.Value cannot be set correctly
80 void SAL_CALL
81 ScVbaToggleButton::setValue( const uno::Any& _value ) throw (uno::RuntimeException)
83 sal_Int16 nState = 0;
84 if (_value.getValueTypeClass() == typelib_TypeClass_BOOLEAN)
86 sal_Bool bValue;
87 _value >>= bValue;
88 nState = static_cast< sal_Int16 >(bValue);
90 else if (_value.getValueTypeClass() == typelib_TypeClass_BYTE)
92 sal_Int8 nValue;
93 _value >>= nValue;
94 nState = ( nValue == 1) ? 1 : 0;
96 else
98 _value >>= nState;
99 OSL_TRACE( "nState - %d", nState );
100 nState = ( nState == -1 ) ? 1 : 0;
101 OSL_TRACE( "nState - %d", nState );
103 m_xProps->setPropertyValue( STATE, uno::makeAny( nState ) );
105 //liuchen 2009-7-23
107 rtl::OUString&
108 ScVbaToggleButton::getServiceImplName()
110 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaToggleButton") );
111 return sImplName;
114 uno::Sequence< rtl::OUString >
115 ScVbaToggleButton::getServiceNames()
117 static uno::Sequence< rtl::OUString > aServiceNames;
118 if ( aServiceNames.getLength() == 0 )
120 aServiceNames.realloc( 1 );
121 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ToggleButton" ) );
123 return aServiceNames;