bump product version to 5.0.4.1
[LibreOffice.git] / vbahelper / source / msforms / vbamultipage.cxx
blob2fb7016ac02e81bab69a37961b023c40cdf7d57a
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 .
19 #include "vbamultipage.hxx"
20 #include <ooo/vba/XCollection.hpp>
21 #include "vbapages.hxx"
22 #include <com/sun/star/container/XNameContainer.hpp>
24 using namespace com::sun::star;
25 using namespace ooo::vba;
27 const OUString SVALUE( "MultiPageValue" );
29 typedef cppu::WeakImplHelper1< container::XIndexAccess > PagesImpl_Base;
30 class PagesImpl : public PagesImpl_Base
32 sal_Int32 mnPages;
33 public:
34 PagesImpl( sal_Int32 nPages ) : mnPages( nPages ) {}
35 virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return mnPages; }
36 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException, std::exception) SAL_OVERRIDE
38 if ( Index < 0 || Index > mnPages )
39 throw lang::IndexOutOfBoundsException();
40 return uno::makeAny( uno::Reference< uno::XInterface >() );
42 // XElementAccess
43 virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
45 // no Pages object yet #FIXME
46 //return cppu::UnoType<msforms::XPage>::get();
47 return cppu::UnoType<uno::XInterface>::get();
49 virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
51 return ( mnPages > 0 );
54 uno::Reference< container::XIndexAccess >
55 ScVbaMultiPage::getPages( sal_Int32 nPages )
57 return new PagesImpl( nPages );
60 ScVbaMultiPage::ScVbaMultiPage(
61 const uno::Reference< ov::XHelperInterface >& xParent,
62 const uno::Reference< uno::XComponentContext >& xContext,
63 const uno::Reference< uno::XInterface >& xControl,
64 const uno::Reference< frame::XModel >& xModel,
65 AbstractGeometryAttributes* pGeomHelper) :
66 MultiPageImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper )
70 // Attributes
71 sal_Int32 SAL_CALL
72 ScVbaMultiPage::getValue() throw (css::uno::RuntimeException, std::exception)
74 sal_Int32 nValue = 0;
75 m_xProps->getPropertyValue( SVALUE ) >>= nValue;
76 // VBA 0 based tab index
77 return nValue - 1;
80 void SAL_CALL
81 ScVbaMultiPage::setValue( const sal_Int32 _value ) throw (::com::sun::star::uno::RuntimeException, std::exception)
83 // Openoffice 1 based tab index
84 sal_Int32 nVal = _value + 1;
85 sal_Int32 nOldVal = getValue();
86 m_xProps->setPropertyValue( SVALUE, uno::makeAny( nVal ) );
87 if ( nVal != nOldVal )
88 fireChangeEvent();
91 OUString
92 ScVbaMultiPage::getServiceImplName()
94 return OUString( "ScVbaMultiPage" );
97 uno::Any SAL_CALL
98 ScVbaMultiPage::Pages( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
100 // get the container model
101 uno::Reference< container::XNameContainer > xContainer( m_xProps, uno::UNO_QUERY_THROW );
102 uno::Reference< XCollection > xColl( new ScVbaPages( this, mxContext, getPages( xContainer->getElementNames().getLength() ) ) );
103 if ( !index.hasValue() )
104 return uno::makeAny( xColl );
105 return xColl->Item( index, uno::Any() );
108 uno::Sequence< OUString >
109 ScVbaMultiPage::getServiceNames()
111 static uno::Sequence< OUString > aServiceNames;
112 if ( aServiceNames.getLength() == 0 )
114 aServiceNames.realloc( 1 );
115 aServiceNames[ 0 ] = "ooo.vba.msforms.MultiPage";
117 return aServiceNames;
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */