merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / vba / vbahyperlink.cxx
blob1de663804fe942bf1a344b22679e22250d3b6eba
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile$
7 * $Revision$
9 * last change: $Author$ $Date$
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
35 #include <vbahelper/helperdecl.hxx>
36 #include "vbahyperlink.hxx"
37 #include <com/sun/star/container/XIndexAccess.hpp>
38 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
39 #include <com/sun/star/container/XEnumerationAccess.hpp>
40 #include "vbarange.hxx"
42 using namespace ::ooo::vba;
43 using namespace ::com::sun::star;
45 ScVbaHyperlink::ScVbaHyperlink( uno::Sequence< uno::Any> const & args,
46 uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : HyperlinkImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxCell( getXSomethingFromArgs< table::XCell >( args, 1, false ) )
48 mxCell = getXSomethingFromArgs< table::XCell >( args, 1, false );
49 uno::Reference< text::XTextFieldsSupplier > xTextFields( mxCell, uno::UNO_QUERY_THROW );
50 uno::Reference< container::XIndexAccess > xIndex( xTextFields->getTextFields(), uno::UNO_QUERY_THROW );
51 mxTextField.set( xIndex->getByIndex(0), uno::UNO_QUERY_THROW );
54 ScVbaHyperlink::~ScVbaHyperlink()
58 ::rtl::OUString
59 ScVbaHyperlink::getAddress() throw (css::uno::RuntimeException)
61 rtl::OUString aAddress;
62 uno::Any aValue = mxTextField->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
63 aValue >>= aAddress;
64 return aAddress;
67 void
68 ScVbaHyperlink::setAddress( const ::rtl::OUString & rAddress ) throw (css::uno::RuntimeException)
70 uno::Any aValue;
71 aValue <<= rAddress;
72 mxTextField->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ), aValue );
75 ::rtl::OUString
76 ScVbaHyperlink::getName() throw (css::uno::RuntimeException)
78 // it seems this attribute is same as TextToDisplay
79 return getTextToDisplay();
82 void
83 ScVbaHyperlink::setName( const ::rtl::OUString & rName ) throw (css::uno::RuntimeException)
85 setTextToDisplay( rName );
88 ::rtl::OUString
89 ScVbaHyperlink::getTextToDisplay() throw (css::uno::RuntimeException)
91 rtl::OUString aTextToDisplay;
92 uno::Any aValue = mxTextField->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Representation" ) ) );
93 aValue >>= aTextToDisplay;
94 return aTextToDisplay;
97 void
98 ScVbaHyperlink::setTextToDisplay( const ::rtl::OUString & rTextToDisplay ) throw (css::uno::RuntimeException)
100 uno::Any aValue;
101 aValue <<= rTextToDisplay;
102 mxTextField->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Representation" ) ), aValue );
105 css::uno::Reference< ov::excel::XRange > SAL_CALL ScVbaHyperlink::Range() throw (css::uno::RuntimeException)
107 uno::Reference< table::XCellRange > xRange( mxCell,uno::UNO_QUERY_THROW );
108 // FIXME: need to pass current worksheet as the parent of XRange.
109 return uno::Reference< excel::XRange >( new ScVbaRange( uno::Reference< XHelperInterface > (), mxContext, xRange ) );
112 rtl::OUString&
113 ScVbaHyperlink::getServiceImplName()
115 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaHyperlink") );
116 return sImplName;
119 uno::Sequence< rtl::OUString >
120 ScVbaHyperlink::getServiceNames()
122 static uno::Sequence< rtl::OUString > aServiceNames;
123 if ( aServiceNames.getLength() == 0 )
125 aServiceNames.realloc( 1 );
126 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Hyperlink" ) );
128 return aServiceNames;
131 namespace hyperlink
133 namespace sdecl = comphelper::service_decl;
134 sdecl::vba_service_class_<ScVbaHyperlink, sdecl::with_args<true> > serviceImpl;
135 extern sdecl::ServiceDecl const serviceDecl(
136 serviceImpl,
137 "ScVbaHyperlink",
138 "ooo.vba.excel.Hyperlink" );