LibreOffice Module sw (master) 1
acchyperlink.cxx
Go to the documentation of this file.
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
22#include <com/sun/star/frame/XDesktop.hpp>
23#include <com/sun/star/document/XLinkTargetSupplier.hpp>
24#include <com/sun/star/lang/XMultiServiceFactory.hpp>
25#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26#include <swurl.hxx>
27#include <vcl/keycodes.hxx>
28#include <vcl/svapp.hxx>
29#include <txtinet.hxx>
30#include "accpara.hxx"
31#include "acchyperlink.hxx"
32
33using namespace ::com::sun::star;
34using namespace ::com::sun::star::accessibility;
35using ::com::sun::star::lang::IndexOutOfBoundsException;
36
38 SwAccessibleParagraph & rAccPara,
39 sal_Int32 const nStt, sal_Int32 const nEnd)
40 : m_pHyperlink(const_cast<SwFormatINetFormat*>(&rTextAttr.GetINetFormat()))
41 , m_xParagraph(&rAccPara)
42 , m_nStartIndex( nStt )
43 , m_nEndIndex( nEnd )
44{
46}
47
49{
50 Invalidate(); // with SolarMutex!
51}
52
53// when the pool item dies, invalidate! this is the only reason for Listener...
55{
56 if (rHint.GetId() == SfxHintId::Dying)
57 {
58 Invalidate();
59 }
60}
61
62// both the parent SwAccessibleParagraph and the pool-item must be valid
64{
65 return (m_xParagraph.is() && m_xParagraph->GetMap())
67 : nullptr;
68}
69
70// XAccessibleAction
72{
73 return isValid() ? 1 : 0;
74}
75
77{
78 SolarMutexGuard aGuard;
79
80 bool bRet = false;
81
82 if(nIndex != 0)
83 throw lang::IndexOutOfBoundsException();
84 SwFormatINetFormat const*const pINetFormat = GetTextAttr();
85 if (pINetFormat && !pINetFormat->GetValue().isEmpty())
86 {
87 SwViewShell *pVSh = m_xParagraph->GetShell();
88 if (pVSh)
89 {
90 LoadURL(*pVSh, pINetFormat->GetValue(), LoadUrlFlags::NONE,
91 pINetFormat->GetTargetFrame());
92 const SwTextINetFormat *const pTextAttr = pINetFormat->GetTextINetFormat();
93 if (pTextAttr)
94 {
95 const_cast<SwTextINetFormat*>(pTextAttr)->SetVisited(true);
96 const_cast<SwTextINetFormat*>(pTextAttr)->SetVisitedValid(true);
97 }
98 bRet = true;
99 }
100 }
101
102 return bRet;
103}
104
106 sal_Int32 nIndex )
107{
108 if(nIndex != 0)
109 throw lang::IndexOutOfBoundsException();
110
112 if (SwFormatINetFormat const*const pINetFormat = GetTextAttr())
113 {
114 return pINetFormat->GetValue();
115 }
116
117 return OUString();
118}
119
120uno::Reference< XAccessibleKeyBinding > SAL_CALL
122{
123 uno::Reference< XAccessibleKeyBinding > xKeyBinding;
124
125 if( isValid() )
126 {
128 new ::comphelper::OAccessibleKeyBindingHelper();
129 xKeyBinding = pKeyBindingHelper;
130
131 awt::KeyStroke aKeyStroke;
132 aKeyStroke.Modifiers = 0;
133 aKeyStroke.KeyCode = KEY_RETURN;
134 aKeyStroke.KeyChar = 0;
135 aKeyStroke.KeyFunc = 0;
136 pKeyBindingHelper->AddKeyBinding( aKeyStroke );
137 }
138
139 return xKeyBinding;
140}
141
142// XAccessibleHyperlink
144 sal_Int32 nIndex)
145{
147
148 uno::Any aRet;
149 if(nIndex != 0)
150 throw lang::IndexOutOfBoundsException();
151 OUString text( m_xParagraph->GetString() );
152 OUString retText = text.copy(m_nStartIndex, m_nEndIndex - m_nStartIndex);
153 aRet <<= retText;
154 return aRet;
155}
156
158 sal_Int32 nIndex )
159{
161
162 if(nIndex != 0)
163 throw lang::IndexOutOfBoundsException();
164 OUString retText;
165 if (SwFormatINetFormat const*const pINetFormat = GetTextAttr())
166 {
167 retText = pINetFormat->GetValue();
168 }
169 uno::Any aRet;
170 aRet <<= retText;
171 return aRet;
172}
173
175{
176 return m_nStartIndex;
177}
178
180{
181 return m_nEndIndex;
182}
183
185{
186 SolarMutexGuard aGuard;
187 if (m_xParagraph.is())
188 {
189 if (SwFormatINetFormat const*const pINetFormat = GetTextAttr())
190 {
191 OUString const sText(pINetFormat->GetValue());
192 sal_Int32 nPos = sText.indexOf("#");
193 if (nPos==0)//document link
194 {
195 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
196 if( ! xFactory.is() )
197 return false;
198 uno::Reference< css::frame::XDesktop > xDesktop( xFactory->createInstance( "com.sun.star.frame.Desktop" ),
199 uno::UNO_QUERY );
200 if( !xDesktop.is() )
201 return false;
202 uno::Reference< lang::XComponent > xComp = xDesktop->getCurrentComponent();
203 if( !xComp.is() )
204 return false;
205 uno::Reference< css::document::XLinkTargetSupplier > xLTS(xComp, uno::UNO_QUERY);
206 if ( !xLTS.is())
207 return false;
208
209 uno::Reference< css::container::XNameAccess > xLinks = xLTS->getLinks();
210 uno::Reference< css::container::XNameAccess > xSubLinks;
211 const uno::Sequence< OUString > aNames( xLinks->getElementNames() );
212
213 for( const OUString& aLink : aNames )
214 {
215 uno::Any aAny = xLinks->getByName( aLink );
216 aAny >>= xSubLinks;
217 if (xSubLinks->hasByName(sText.copy(1)) )
218 return true;
219 }
220 }
221 else//internet
222 return true;
223 }
224 }//xpara valid
225 return false;
226}
227
229{
230 SolarMutexGuard aGuard;
231 m_xParagraph = nullptr;
232 m_pHyperlink = nullptr;
234}
235
236/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxHintId GetId() const
void EndListeningAll()
bool StartListening(SvtBroadcaster &rBroadcaster)
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
const SwTextINetFormat * GetTextINetFormat() const
Definition: fmtinfmt.hxx:70
const OUString & GetTargetFrame() const
Definition: fmtinfmt.hxx:89
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
SwTextAttr subclass that tracks the location of the wrapped SwFormatURL.
Definition: txtinet.hxx:30
SvtBroadcaster & GetNotifier()
Definition: calbck.hxx:102
Reference< XSingleServiceFactory > xFactory
sal_Int32 nIndex
constexpr sal_uInt16 KEY_RETURN
sal_uInt16 nPos
def text(shape, orig_st)
unsigned char sal_Bool
void LoadURL(SwViewShell &rVSh, const OUString &rURL, LoadUrlFlags nFilter, const OUString &rTargetFrameName)
Definition: wrtsh2.cxx:555