1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10efeef26fSAndrew Rist *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19efeef26fSAndrew Rist *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #include <comphelper/accessiblekeybindinghelper.hxx>
27cdf0e10cSrcweir #include <swurl.hxx>
28cdf0e10cSrcweir #include <vos/mutex.hxx>
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir #include <ndtxt.hxx>
31cdf0e10cSrcweir #include <txtinet.hxx>
32cdf0e10cSrcweir #include <accpara.hxx>
33cdf0e10cSrcweir #include <acchyperlink.hxx>
34cdf0e10cSrcweir
35*ca62e2c2SSteve Yin #include <comphelper/processfactory.hxx>
36*ca62e2c2SSteve Yin #ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_
37*ca62e2c2SSteve Yin #include <com/sun/star/frame/XDesktop.hpp>
38*ca62e2c2SSteve Yin #endif
39*ca62e2c2SSteve Yin #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
40*ca62e2c2SSteve Yin #include <com/sun/star/frame/XComponentLoader.hpp>
41*ca62e2c2SSteve Yin #endif
42*ca62e2c2SSteve Yin #ifndef _COM_SUN_STAR_DOCUMENT_XLINKTARGETSUPPLIER_HPP_
43*ca62e2c2SSteve Yin #include <com/sun/star/document/XLinkTargetSupplier.hpp>
44*ca62e2c2SSteve Yin #endif
45*ca62e2c2SSteve Yin
46cdf0e10cSrcweir using namespace ::com::sun::star;
47cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
48cdf0e10cSrcweir using ::rtl::OUString;
49*ca62e2c2SSteve Yin using ::com::sun::star::lang::IndexOutOfBoundsException;
50cdf0e10cSrcweir
SwAccessibleHyperlink(sal_uInt16 nHPos,SwAccessibleParagraph * p,sal_Int32 nStt,sal_Int32 nEnd)51cdf0e10cSrcweir SwAccessibleHyperlink::SwAccessibleHyperlink( sal_uInt16 nHPos,
52cdf0e10cSrcweir SwAccessibleParagraph *p, sal_Int32 nStt, sal_Int32 nEnd ) :
53cdf0e10cSrcweir nHintPos( nHPos ),
54cdf0e10cSrcweir xPara( p ),
55cdf0e10cSrcweir nStartIdx( nStt ),
56cdf0e10cSrcweir nEndIdx( nEnd )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir
GetTxtAttr() const60cdf0e10cSrcweir const SwTxtAttr *SwAccessibleHyperlink::GetTxtAttr() const
61cdf0e10cSrcweir {
62cdf0e10cSrcweir const SwTxtAttr *pTxtAttr = 0;
63cdf0e10cSrcweir if( xPara.isValid() && xPara->GetMap() )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir const SwTxtNode *pTxtNd = xPara->GetTxtNode();
66cdf0e10cSrcweir const SwpHints *pHints = pTxtNd->GetpSwpHints();
67cdf0e10cSrcweir if( pHints && nHintPos < pHints->Count() )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir const SwTxtAttr *pHt = (*pHints)[nHintPos];
70cdf0e10cSrcweir if( RES_TXTATR_INETFMT == pHt->Which() )
71cdf0e10cSrcweir pTxtAttr = pHt;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir return pTxtAttr;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
78cdf0e10cSrcweir
79cdf0e10cSrcweir // XAccessibleAction
getAccessibleActionCount()80cdf0e10cSrcweir sal_Int32 SAL_CALL SwAccessibleHyperlink::getAccessibleActionCount()
81cdf0e10cSrcweir throw (uno::RuntimeException)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir return isValid() ? 1 : 0;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
doAccessibleAction(sal_Int32 nIndex)86cdf0e10cSrcweir sal_Bool SAL_CALL SwAccessibleHyperlink::doAccessibleAction( sal_Int32 nIndex )
87cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir vos::OGuard aGuard(Application::GetSolarMutex());
90cdf0e10cSrcweir
91cdf0e10cSrcweir sal_Bool bRet = sal_False;
92cdf0e10cSrcweir
93*ca62e2c2SSteve Yin if(nIndex != 0)
94*ca62e2c2SSteve Yin throw new IndexOutOfBoundsException;
95cdf0e10cSrcweir const SwTxtAttr *pTxtAttr = GetTxtAttr();
96*ca62e2c2SSteve Yin if( pTxtAttr /*&& 0 == nIndex*/ )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir const SwFmtINetFmt& rINetFmt = pTxtAttr->GetINetFmt();
99cdf0e10cSrcweir if( rINetFmt.GetValue().Len() )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir ViewShell *pVSh = xPara->GetShell();
102cdf0e10cSrcweir if( pVSh )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir LoadURL( rINetFmt.GetValue(), pVSh, URLLOAD_NOFILTER,
105cdf0e10cSrcweir &rINetFmt.GetTargetFrame() );
106cdf0e10cSrcweir ASSERT( pTxtAttr == rINetFmt.GetTxtINetFmt(),
107cdf0e10cSrcweir "lost my txt attr" );
108cdf0e10cSrcweir const SwTxtINetFmt* pTxtAttr2 = rINetFmt.GetTxtINetFmt();
109cdf0e10cSrcweir if( pTxtAttr2 )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir const_cast<SwTxtINetFmt*>(pTxtAttr2)->SetVisited(true);
112cdf0e10cSrcweir const_cast<SwTxtINetFmt*>(pTxtAttr2)->SetVisitedValid(true);
113cdf0e10cSrcweir }
114cdf0e10cSrcweir bRet = sal_True;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir return bRet;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
getAccessibleActionDescription(sal_Int32 nIndex)122cdf0e10cSrcweir OUString SAL_CALL SwAccessibleHyperlink::getAccessibleActionDescription(
123cdf0e10cSrcweir sal_Int32 nIndex )
124cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir OUString sDesc;
127cdf0e10cSrcweir
128*ca62e2c2SSteve Yin if(nIndex != 0)
129*ca62e2c2SSteve Yin throw new IndexOutOfBoundsException;
130cdf0e10cSrcweir const SwTxtAttr *pTxtAttr = GetTxtAttr();
131*ca62e2c2SSteve Yin if( pTxtAttr /*&& 0 == nIndex*/ )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir const SwFmtINetFmt& rINetFmt = pTxtAttr->GetINetFmt();
134cdf0e10cSrcweir sDesc = OUString( rINetFmt.GetValue() );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir return sDesc;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir uno::Reference< XAccessibleKeyBinding > SAL_CALL
getAccessibleActionKeyBinding(sal_Int32)140*ca62e2c2SSteve Yin SwAccessibleHyperlink::getAccessibleActionKeyBinding( sal_Int32 )
141cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
142cdf0e10cSrcweir {
143cdf0e10cSrcweir uno::Reference< XAccessibleKeyBinding > xKeyBinding;
144cdf0e10cSrcweir
145*ca62e2c2SSteve Yin if( isValid() /*&& 0 == nIndex*/ )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir ::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper =
148cdf0e10cSrcweir new ::comphelper::OAccessibleKeyBindingHelper();
149cdf0e10cSrcweir xKeyBinding = pKeyBindingHelper;
150cdf0e10cSrcweir
151cdf0e10cSrcweir awt::KeyStroke aKeyStroke;
152cdf0e10cSrcweir aKeyStroke.Modifiers = 0;
153cdf0e10cSrcweir aKeyStroke.KeyCode = KEY_RETURN;
154cdf0e10cSrcweir aKeyStroke.KeyChar = 0;
155cdf0e10cSrcweir aKeyStroke.KeyFunc = 0;
156cdf0e10cSrcweir pKeyBindingHelper->AddKeyBinding( aKeyStroke );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir return xKeyBinding;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
162cdf0e10cSrcweir // XAccessibleHyperlink
getAccessibleActionAnchor(sal_Int32 nIndex)163cdf0e10cSrcweir uno::Any SAL_CALL SwAccessibleHyperlink::getAccessibleActionAnchor(
164*ca62e2c2SSteve Yin sal_Int32 nIndex)
165cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
166cdf0e10cSrcweir {
167*ca62e2c2SSteve Yin uno::Any aRet;
168*ca62e2c2SSteve Yin if(nIndex != 0)
169*ca62e2c2SSteve Yin throw new IndexOutOfBoundsException;
170*ca62e2c2SSteve Yin //End Added.
171*ca62e2c2SSteve Yin ::rtl::OUString text = OUString( xPara->GetString() );
172*ca62e2c2SSteve Yin ::rtl::OUString retText = text.copy(nStartIdx, nEndIdx - nStartIdx);
173*ca62e2c2SSteve Yin aRet <<= retText;
174*ca62e2c2SSteve Yin return aRet;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
getAccessibleActionObject(sal_Int32 nIndex)177cdf0e10cSrcweir uno::Any SAL_CALL SwAccessibleHyperlink::getAccessibleActionObject(
178*ca62e2c2SSteve Yin sal_Int32 nIndex )
179cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
180cdf0e10cSrcweir {
181*ca62e2c2SSteve Yin if(nIndex != 0)
182*ca62e2c2SSteve Yin throw new IndexOutOfBoundsException;
183*ca62e2c2SSteve Yin //End Added.
184*ca62e2c2SSteve Yin const SwTxtAttr *pTxtAttr = GetTxtAttr();
185*ca62e2c2SSteve Yin ::rtl::OUString retText;
186*ca62e2c2SSteve Yin if( pTxtAttr /*&& 0 == nIndex*/ )
187*ca62e2c2SSteve Yin {
188*ca62e2c2SSteve Yin const SwFmtINetFmt& rINetFmt = pTxtAttr->GetINetFmt();
189*ca62e2c2SSteve Yin retText = OUString( rINetFmt.GetValue() );
190*ca62e2c2SSteve Yin }
191*ca62e2c2SSteve Yin uno::Any aRet;
192*ca62e2c2SSteve Yin aRet <<= retText;
193*ca62e2c2SSteve Yin return aRet;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
getStartIndex()196cdf0e10cSrcweir sal_Int32 SAL_CALL SwAccessibleHyperlink::getStartIndex()
197cdf0e10cSrcweir throw (uno::RuntimeException)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir return nStartIdx;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
getEndIndex()202cdf0e10cSrcweir sal_Int32 SAL_CALL SwAccessibleHyperlink::getEndIndex()
203cdf0e10cSrcweir throw (uno::RuntimeException)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir return nEndIdx;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir
isValid()208cdf0e10cSrcweir sal_Bool SAL_CALL SwAccessibleHyperlink::isValid( )
209cdf0e10cSrcweir throw (uno::RuntimeException)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir vos::OGuard aGuard(Application::GetSolarMutex());
212*ca62e2c2SSteve Yin // return xPara.isValid();
213*ca62e2c2SSteve Yin if (xPara.isValid())
214*ca62e2c2SSteve Yin {
215*ca62e2c2SSteve Yin const SwTxtAttr *pTxtAttr = GetTxtAttr();
216*ca62e2c2SSteve Yin ::rtl::OUString sText;
217*ca62e2c2SSteve Yin if( pTxtAttr )
218*ca62e2c2SSteve Yin {
219*ca62e2c2SSteve Yin const SwFmtINetFmt& rINetFmt = pTxtAttr->GetINetFmt();
220*ca62e2c2SSteve Yin sText = OUString( rINetFmt.GetValue() );
221*ca62e2c2SSteve Yin ::rtl::OUString sToken = ::rtl::OUString::createFromAscii("#");
222*ca62e2c2SSteve Yin sal_Int32 nPos = sText.indexOf(sToken);
223*ca62e2c2SSteve Yin if (nPos==0)//document link
224*ca62e2c2SSteve Yin {
225*ca62e2c2SSteve Yin uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
226*ca62e2c2SSteve Yin if( ! xFactory.is() )
227*ca62e2c2SSteve Yin return sal_False;
228*ca62e2c2SSteve Yin uno::Reference< com::sun::star::frame::XDesktop > xDesktop( xFactory->createInstance( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ),
229*ca62e2c2SSteve Yin uno::UNO_QUERY );
230*ca62e2c2SSteve Yin if( !xDesktop.is() )
231*ca62e2c2SSteve Yin return sal_False;
232*ca62e2c2SSteve Yin uno::Reference< lang::XComponent > xComp;
233*ca62e2c2SSteve Yin xComp = xDesktop->getCurrentComponent();
234*ca62e2c2SSteve Yin if( !xComp.is() )
235*ca62e2c2SSteve Yin return sal_False;
236*ca62e2c2SSteve Yin uno::Reference< com::sun::star::document::XLinkTargetSupplier > xLTS(xComp, uno::UNO_QUERY);
237*ca62e2c2SSteve Yin if ( !xLTS.is())
238*ca62e2c2SSteve Yin return sal_False;
239*ca62e2c2SSteve Yin
240*ca62e2c2SSteve Yin uno::Reference< ::com::sun::star::container::XNameAccess > xLinks = xLTS->getLinks();
241*ca62e2c2SSteve Yin uno::Reference< ::com::sun::star::container::XNameAccess > xSubLinks;
242*ca62e2c2SSteve Yin const uno::Sequence< OUString > aNames( xLinks->getElementNames() );
243*ca62e2c2SSteve Yin const sal_uLong nLinks = aNames.getLength();
244*ca62e2c2SSteve Yin const OUString* pNames = aNames.getConstArray();
245*ca62e2c2SSteve Yin
246*ca62e2c2SSteve Yin for( sal_uLong i = 0; i < nLinks; i++ )
247*ca62e2c2SSteve Yin {
248*ca62e2c2SSteve Yin uno::Any aAny;
249*ca62e2c2SSteve Yin OUString aLink( *pNames++ );
250*ca62e2c2SSteve Yin aAny = xLinks->getByName( aLink );
251*ca62e2c2SSteve Yin aAny >>= xSubLinks;
252*ca62e2c2SSteve Yin if (xSubLinks->hasByName(sText.copy(1)) )
253*ca62e2c2SSteve Yin return sal_True;
254*ca62e2c2SSteve Yin }
255*ca62e2c2SSteve Yin }
256*ca62e2c2SSteve Yin else//internet
257*ca62e2c2SSteve Yin return sal_True;
258*ca62e2c2SSteve Yin }
259*ca62e2c2SSteve Yin }//xpara valid
260*ca62e2c2SSteve Yin return sal_False;
261cdf0e10cSrcweir }
262cdf0e10cSrcweir
Invalidate()263cdf0e10cSrcweir void SwAccessibleHyperlink::Invalidate()
264cdf0e10cSrcweir {
265cdf0e10cSrcweir vos::OGuard aGuard(Application::GetSolarMutex());
266cdf0e10cSrcweir xPara = 0;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir
269