Bump version to 4.1-6
[LibreOffice.git] / vbahelper / source / msforms / vbamultipage.cxx
blob7cfbe97019e57134a00225a5dfc9a6842b368859
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 <vector>
23 #include <com/sun/star/container/XNameContainer.hpp>
25 using namespace com::sun::star;
26 using namespace ooo::vba;
28 const OUString SVALUE( "MultiPageValue" );
30 typedef cppu::WeakImplHelper1< container::XIndexAccess > PagesImpl_Base;
31 class PagesImpl : public PagesImpl_Base
33 sal_Int32 mnPages;
34 public:
35 PagesImpl( sal_Int32 nPages ) : mnPages( nPages ) {}
36 virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) { return mnPages; }
37 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException)
39 if ( Index < 0 || Index > mnPages )
40 throw lang::IndexOutOfBoundsException();
41 return uno::makeAny( uno::Reference< uno::XInterface >() );
43 // XElementAccess
44 virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException)
46 // no Pages object yet #FIXME
47 //return msforms::XPage::static_type(0);
48 return uno::XInterface::static_type(0);
50 virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
52 return ( mnPages > 0 );
55 uno::Reference< container::XIndexAccess >
56 ScVbaMultiPage::getPages( sal_Int32 nPages )
58 return new PagesImpl( nPages );
61 ScVbaMultiPage::ScVbaMultiPage(
62 const uno::Reference< ov::XHelperInterface >& xParent,
63 const uno::Reference< uno::XComponentContext >& xContext,
64 const uno::Reference< uno::XInterface >& xControl,
65 const uno::Reference< frame::XModel >& xModel,
66 AbstractGeometryAttributes* pGeomHelper) :
67 MultiPageImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper )
71 // Attributes
72 sal_Int32 SAL_CALL
73 ScVbaMultiPage::getValue() throw (css::uno::RuntimeException)
75 sal_Int32 nValue = 0;
76 m_xProps->getPropertyValue( SVALUE ) >>= nValue;
77 // VBA 0 based tab index
78 return nValue - 1;
81 void SAL_CALL
82 ScVbaMultiPage::setValue( const sal_Int32 _value ) throw (::com::sun::star::uno::RuntimeException)
84 // Openoffice 1 based tab index
85 sal_Int32 nVal = _value + 1;
86 sal_Int32 nOldVal = getValue();
87 m_xProps->setPropertyValue( SVALUE, uno::makeAny( nVal ) );
88 if ( nVal != nOldVal )
89 fireChangeEvent();
92 OUString
93 ScVbaMultiPage::getServiceImplName()
95 return OUString( "ScVbaMultiPage" );
98 uno::Any SAL_CALL
99 ScVbaMultiPage::Pages( const uno::Any& index ) throw (uno::RuntimeException)
101 // get the container model
102 uno::Reference< container::XNameContainer > xContainer( m_xProps, uno::UNO_QUERY_THROW );
103 uno::Reference< XCollection > xColl( new ScVbaPages( this, mxContext, getPages( xContainer->getElementNames().getLength() ) ) );
104 if ( !index.hasValue() )
105 return uno::makeAny( xColl );
106 return xColl->Item( uno::makeAny( index ), uno::Any() );
109 uno::Sequence< OUString >
110 ScVbaMultiPage::getServiceNames()
112 static uno::Sequence< OUString > aServiceNames;
113 if ( aServiceNames.getLength() == 0 )
115 aServiceNames.realloc( 1 );
116 aServiceNames[ 0 ] = "ooo.vba.msforms.MultiPage";
118 return aServiceNames;
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */