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