23#include <com/sun/star/beans/XPropertySet.hpp>
24#include <com/sun/star/container/XIndexAccess.hpp>
25#include <com/sun/star/frame/XModel.hpp>
26#include <com/sun/star/lang/XMultiServiceFactory.hpp>
27#include <com/sun/star/table/XCellRange.hpp>
28#include <com/sun/star/text/XText.hpp>
29#include <com/sun/star/text/XTextFieldsSupplier.hpp>
30#include <ooo/vba/office/MsoHyperlinkType.hpp>
31#include <ooo/vba/msforms/XShape.hpp>
38 const uno::Reference< uno::XComponentContext >& rxContext ) :
41 mnType( office::MsoHyperlinkType::msoHyperlinkRange )
43 uno::Reference< text::XTextFieldsSupplier > xTextFields( mxCell, uno::UNO_QUERY_THROW );
44 uno::Reference< container::XIndexAccess > xIndex( xTextFields->getTextFields(), uno::UNO_QUERY_THROW );
45 mxTextField.set( xIndex->getByIndex(0), uno::UNO_QUERY_THROW );
49 const uno::Reference< uno::XComponentContext >& rxContext,
55 UrlComponents aUrlComp;
56 OUString aTextToDisplay;
57 if( !(rAddress >>= aUrlComp.first) || aUrlComp.first.isEmpty() )
58 throw uno::RuntimeException(
"Cannot get address" );
59 rSubAddress >>= aUrlComp.second;
60 rScreenTip >>= maScreenTip;
61 rTextToDisplay >>= aTextToDisplay;
64 uno::Reference< excel::XRange > xAnchorRange( rxAnchor, uno::UNO_QUERY );
65 if( xAnchorRange.is() )
67 mnType = office::MsoHyperlinkType::msoHyperlinkRange;
71 mxCell.set( xUnoRange->getCellByPosition( 0, 0 ), uno::UNO_SET_THROW );
72 uno::Reference< text::XText > xText( mxCell, uno::UNO_QUERY_THROW );
74 if( aTextToDisplay.isEmpty() )
76 aTextToDisplay = xText->getString();
77 if( aTextToDisplay.isEmpty() )
79 OUStringBuffer
aBuffer( aUrlComp.first );
80 if( !aUrlComp.second.isEmpty() )
81 aBuffer.append(
" - " + aUrlComp.second );
82 aTextToDisplay =
aBuffer.makeStringAndClear();
87 uno::Reference< text::XTextContent > xUrlField(
xFactory->createInstance(
"com.sun.star.text.TextField.URL"), uno::UNO_QUERY_THROW );
88 mxTextField.set( xUrlField, uno::UNO_QUERY_THROW );
89 setUrlComponents( aUrlComp );
90 setTextToDisplay( aTextToDisplay );
92 xText->setString( OUString() );
93 uno::Reference< text::XTextRange > xRange( xText->createTextCursor(), uno::UNO_QUERY_THROW );
94 xText->insertTextContent( xRange, xUrlField,
false );
98 uno::Reference< msforms::XShape > xAnchorShape( rxAnchor, uno::UNO_QUERY_THROW );
99 mnType = office::MsoHyperlinkType::msoHyperlinkShape;
101 throw uno::RuntimeException();
128 aUrlComp.first = rAddress;
140 aUrlComp.second = rSubAddress;
157 OUString aTextToDisplay;
158 mxTextField->getPropertyValue(
"Representation") >>= aTextToDisplay;
159 return aTextToDisplay;
175 if(
mnType == office::MsoHyperlinkType::msoHyperlinkRange )
178 uno::Reference< excel::XRange > xAnchorRange(
getParent(), uno::UNO_QUERY );
179 if( !xAnchorRange.is() )
182 uno::Reference< table::XCellRange > xRange(
mxCell, uno::UNO_QUERY_THROW );
184 xAnchorRange.set(
new ScVbaRange( uno::Reference< XHelperInterface >(),
mxContext, xRange ) );
189 throw uno::RuntimeException();
195 return uno::Reference< msforms::XShape >(
getParent(), uno::UNO_QUERY_THROW );
204 if( !mxTextField.is() )
205 throw uno::RuntimeException();
213 sal_Int32 nHashPos = aUrl.indexOf(
'#' );
216 return UrlComponents( aUrl.copy( 0, nHashPos ), aUrl.copy( nHashPos + 1 ) );
222 OUStringBuffer aUrl( rUrlComp.first );
223 if( !rUrlComp.second.isEmpty() )
224 aUrl.append(
"#" + rUrlComp.second );
228extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
230 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& args)
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
virtual css::uno::Reference< ov::msforms::XShape > SAL_CALL getShape() override
void setUrlComponents(const UrlComponents &rUrlComp)
::std::pair< OUString, OUString > UrlComponents
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getRange() override
virtual ~ScVbaHyperlink() override
virtual OUString SAL_CALL getSubAddress() override
virtual OUString SAL_CALL getAddress() override
virtual OUString SAL_CALL getScreenTip() override
virtual void SAL_CALL setTextToDisplay(const OUString &rTextToDisplay) override
css::uno::Reference< css::beans::XPropertySet > mxTextField
virtual void SAL_CALL setName(const OUString &rName) override
virtual void SAL_CALL setAddress(const OUString &rAddress) override
virtual void SAL_CALL setScreenTip(const OUString &rScreenTip) override
virtual OUString SAL_CALL getName() override
ScVbaHyperlink(const css::uno::Sequence< css::uno::Any > &rArgs, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual void SAL_CALL setSubAddress(const OUString &rSubAddress) override
UrlComponents getUrlComponents()
virtual OUString SAL_CALL getTextToDisplay() override
virtual sal_Int32 SAL_CALL getType() override
css::uno::Reference< css::table::XCell > mxCell
virtual css::uno::Any SAL_CALL getCellRange() override
css::uno::Reference< css::frame::XModel > getUnoModel()
Reference< XSingleServiceFactory > xFactory
css::uno::Reference< T > getXSomethingFromArgs(css::uno::Sequence< css::uno::Any > const &args, sal_Int32 nPos, bool bCanBeNull=true)
#define VBAHELPER_IMPL_XHELPERINTERFACE(classname, servicename)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Calc_ScVbaHyperlink_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
std::unique_ptr< char[]> aBuffer