Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include "vbamultipage.hxx"
20 : #include <ooo/vba/XCollection.hpp>
21 : #include "vbapages.hxx"
22 : #include <com/sun/star/container/XNameContainer.hpp>
23 :
24 : using namespace com::sun::star;
25 : using namespace ooo::vba;
26 :
27 2 : const OUString SVALUE( "MultiPageValue" );
28 :
29 : typedef cppu::WeakImplHelper1< container::XIndexAccess > PagesImpl_Base;
30 0 : class PagesImpl : public PagesImpl_Base
31 : {
32 : sal_Int32 mnPages;
33 : public:
34 0 : explicit PagesImpl( sal_Int32 nPages ) : mnPages( nPages ) {}
35 0 : virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return mnPages; }
36 0 : virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException, std::exception) SAL_OVERRIDE
37 : {
38 0 : if ( Index < 0 || Index > mnPages )
39 0 : throw lang::IndexOutOfBoundsException();
40 0 : return uno::makeAny( uno::Reference< uno::XInterface >() );
41 : }
42 : // XElementAccess
43 0 : virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
44 : {
45 : // no Pages object yet #FIXME
46 : //return cppu::UnoType<msforms::XPage>::get();
47 0 : return cppu::UnoType<uno::XInterface>::get();
48 : }
49 0 : virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
50 : {
51 0 : return ( mnPages > 0 );
52 : }
53 : };
54 : uno::Reference< container::XIndexAccess >
55 0 : ScVbaMultiPage::getPages( sal_Int32 nPages )
56 : {
57 0 : return new PagesImpl( nPages );
58 : }
59 :
60 0 : 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 0 : MultiPageImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper )
67 : {
68 0 : }
69 :
70 : // Attributes
71 : sal_Int32 SAL_CALL
72 0 : ScVbaMultiPage::getValue() throw (css::uno::RuntimeException, std::exception)
73 : {
74 0 : sal_Int32 nValue = 0;
75 0 : m_xProps->getPropertyValue( SVALUE ) >>= nValue;
76 : // VBA 0 based tab index
77 0 : return nValue - 1;
78 : }
79 :
80 : void SAL_CALL
81 0 : ScVbaMultiPage::setValue( const sal_Int32 _value ) throw (::com::sun::star::uno::RuntimeException, std::exception)
82 : {
83 : // Openoffice 1 based tab index
84 0 : sal_Int32 nVal = _value + 1;
85 0 : sal_Int32 nOldVal = getValue();
86 0 : m_xProps->setPropertyValue( SVALUE, uno::makeAny( nVal ) );
87 0 : if ( nVal != nOldVal )
88 0 : fireChangeEvent();
89 0 : }
90 :
91 : OUString
92 0 : ScVbaMultiPage::getServiceImplName()
93 : {
94 0 : return OUString( "ScVbaMultiPage" );
95 : }
96 :
97 : uno::Any SAL_CALL
98 0 : ScVbaMultiPage::Pages( const uno::Any& index ) throw (uno::RuntimeException, std::exception)
99 : {
100 : // get the container model
101 0 : uno::Reference< container::XNameContainer > xContainer( m_xProps, uno::UNO_QUERY_THROW );
102 0 : uno::Reference< XCollection > xColl( new ScVbaPages( this, mxContext, getPages( xContainer->getElementNames().getLength() ) ) );
103 0 : if ( !index.hasValue() )
104 0 : return uno::makeAny( xColl );
105 0 : return xColl->Item( index, uno::Any() );
106 : }
107 :
108 : uno::Sequence< OUString >
109 0 : ScVbaMultiPage::getServiceNames()
110 : {
111 0 : static uno::Sequence< OUString > aServiceNames;
112 0 : if ( aServiceNames.getLength() == 0 )
113 : {
114 0 : aServiceNames.realloc( 1 );
115 0 : aServiceNames[ 0 ] = "ooo.vba.msforms.MultiPage";
116 : }
117 0 : return aServiceNames;
118 6 : }
119 :
120 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|