Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / vbahelper / source / msforms / vbaradiobutton.cxx
blob10dabf8c8abe4cfcbe71f25b35fc09ce5e9f6f28
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 "vbaradiobutton.hxx"
21 #include "vbanewfont.hxx"
23 using namespace com::sun::star;
24 using namespace ooo::vba;
27 const static OUString LABEL( "Label" );
28 const static OUString STATE( "State" );
29 ScVbaRadioButton::ScVbaRadioButton( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : RadioButtonImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper )
33 // Attributes
34 OUString SAL_CALL
35 ScVbaRadioButton::getCaption() throw (css::uno::RuntimeException)
37 OUString Label;
38 m_xProps->getPropertyValue( LABEL ) >>= Label;
39 return Label;
42 void SAL_CALL
43 ScVbaRadioButton::setCaption( const OUString& _caption ) throw (::com::sun::star::uno::RuntimeException)
45 m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) );
48 uno::Any SAL_CALL
49 ScVbaRadioButton::getValue() throw (css::uno::RuntimeException)
51 sal_Int16 nValue = -1;
52 m_xProps->getPropertyValue( STATE ) >>= nValue;
53 if( nValue != 0 )
54 nValue = -1;
55 // return uno::makeAny( nValue );
56 // I must be missing something MSO says value should be -1 if selected, 0 if not
57 // selected
58 return uno::makeAny( ( nValue == -1 ) ? sal_True : sal_False );
62 void SAL_CALL
63 ScVbaRadioButton::setValue( const uno::Any& _value ) throw (uno::RuntimeException)
65 sal_Int16 nValue = 0;
66 sal_Int16 nOldValue = 0;
67 m_xProps->getPropertyValue( STATE ) >>= nOldValue;
69 sal_Bool bValue = sal_False;
70 if( _value >>= nValue )
72 if( nValue == -1)
73 nValue = 1;
75 else if ( _value >>= bValue )
77 if ( bValue )
78 nValue = 1;
80 m_xProps->setPropertyValue( STATE, uno::makeAny( nValue ) );
81 if ( nValue != nOldValue )
83 fireChangeEvent();
84 // In Excel, only when the radio button is checked, the click event is fired.
85 if ( nValue != 0 )
87 fireClickEvent();
92 uno::Reference< msforms::XNewFont > SAL_CALL ScVbaRadioButton::getFont() throw (uno::RuntimeException)
94 return new VbaNewFont( this, mxContext, m_xProps );
97 OUString
98 ScVbaRadioButton::getServiceImplName()
100 return OUString( "ScVbaRadioButton" );
103 uno::Sequence< OUString >
104 ScVbaRadioButton::getServiceNames()
106 static uno::Sequence< OUString > aServiceNames;
107 if ( aServiceNames.getLength() == 0 )
109 aServiceNames.realloc( 1 );
110 aServiceNames[ 0 ] = "ooo.vba.msforms.RadioButton";
112 return aServiceNames;
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */