1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #include "vbamultipage.hxx" 28 #include <ooo/vba/XCollection.hpp> 29 #include "vbapages.hxx" 30 #include <vector> 31 32 using namespace com::sun::star; 33 using namespace ooo::vba; 34 35 // uno servicename com.sun.star.awt.UnoControlProgressBarMode 36 const rtl::OUString SVALUE( RTL_CONSTASCII_USTRINGPARAM("ProgressValue") ); 37 const rtl::OUString SVALUEMAX( RTL_CONSTASCII_USTRINGPARAM("ProgressValueMax") ); 38 const rtl::OUString SSTEP( RTL_CONSTASCII_USTRINGPARAM("Step") ); 39 40 typedef cppu::WeakImplHelper1< container::XIndexAccess > PagesImpl_Base; 41 class PagesImpl : public PagesImpl_Base 42 { 43 sal_Int32 mnPages; 44 public: 45 PagesImpl( sal_Int32 nPages ) : mnPages( nPages ) {} 46 virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) { return mnPages; } 47 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException) 48 { 49 if ( Index < 0 || Index > mnPages ) 50 throw lang::IndexOutOfBoundsException(); 51 return uno::makeAny( uno::Reference< uno::XInterface >() ); 52 } 53 // XElementAccess 54 virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException) 55 { 56 // no Pages object yet #FIXME 57 //return msforms::XPage::static_type(0); 58 return uno::XInterface::static_type(0); 59 } 60 virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) 61 { 62 return ( mnPages > 0 ); 63 } 64 }; 65 uno::Reference< container::XIndexAccess > 66 ScVbaMultiPage::getPages( sal_Int32 nPages ) 67 { 68 return new PagesImpl( nPages ); 69 } 70 71 ScVbaMultiPage::ScVbaMultiPage( 72 const uno::Reference< ov::XHelperInterface >& xParent, 73 const uno::Reference< uno::XComponentContext >& xContext, 74 const uno::Reference< uno::XInterface >& xControl, 75 const uno::Reference< frame::XModel >& xModel, 76 AbstractGeometryAttributes* pGeomHelper, 77 const uno::Reference< awt::XControl >& xDialog ) : 78 MultiPageImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) 79 { 80 mxDialogProps.set( xDialog->getModel(), uno::UNO_QUERY_THROW ); 81 // set dialog step to value of multipage pseudo model 82 setValue(getValue()); 83 } 84 85 // Attributes 86 sal_Int32 SAL_CALL 87 ScVbaMultiPage::getValue() throw (css::uno::RuntimeException) 88 { 89 sal_Int32 nValue = 0; 90 m_xProps->getPropertyValue( SVALUE ) >>= nValue; 91 return nValue; 92 } 93 94 void SAL_CALL 95 ScVbaMultiPage::setValue( const sal_Int32 _value ) throw (::com::sun::star::uno::RuntimeException) 96 { 97 // track change in dialog ( dialog value is 1 based, 0 is a special value ) 98 m_xProps->setPropertyValue( SVALUE, uno::makeAny( _value ) ); 99 mxDialogProps->setPropertyValue( SSTEP, uno::makeAny( _value + 1) ); 100 } 101 102 103 rtl::OUString& 104 ScVbaMultiPage::getServiceImplName() 105 { 106 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMultiPage") ); 107 return sImplName; 108 } 109 110 uno::Any SAL_CALL 111 ScVbaMultiPage::Pages( const uno::Any& index ) throw (uno::RuntimeException) 112 { 113 sal_Int32 nValue = 0; 114 m_xProps->getPropertyValue( SVALUEMAX ) >>= nValue; 115 uno::Reference< XCollection > xColl( new ScVbaPages( this, mxContext, getPages( nValue ) ) ); 116 if ( !index.hasValue() ) 117 return uno::makeAny( xColl ); 118 return xColl->Item( uno::makeAny( index ), uno::Any() ); 119 } 120 121 uno::Sequence< rtl::OUString > 122 ScVbaMultiPage::getServiceNames() 123 { 124 static uno::Sequence< rtl::OUString > aServiceNames; 125 if ( aServiceNames.getLength() == 0 ) 126 { 127 aServiceNames.realloc( 1 ); 128 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.MultiPage" ) ); 129 } 130 return aServiceNames; 131 } 132