1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acchyperlink.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <comphelper/accessiblekeybindinghelper.hxx>
35 #include <vos/mutex.hxx>
36 #include <vcl/svapp.hxx>
38 #include <txtinet.hxx>
39 #include <accpara.hxx>
40 #include <acchyperlink.hxx>
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::accessibility
;
44 using ::rtl::OUString
;
46 SwAccessibleHyperlink::SwAccessibleHyperlink( sal_uInt16 nHPos
,
47 SwAccessibleParagraph
*p
, sal_Int32 nStt
, sal_Int32 nEnd
) :
55 const SwTxtAttr
*SwAccessibleHyperlink::GetTxtAttr() const
57 const SwTxtAttr
*pTxtAttr
= 0;
58 if( xPara
.isValid() && xPara
->GetMap() )
60 const SwTxtNode
*pTxtNd
= xPara
->GetTxtNode();
61 const SwpHints
*pHints
= pTxtNd
->GetpSwpHints();
62 if( pHints
&& nHintPos
< pHints
->Count() )
64 const SwTxtAttr
*pHt
= (*pHints
)[nHintPos
];
65 if( RES_TXTATR_INETFMT
== pHt
->Which() )
75 sal_Int32 SAL_CALL
SwAccessibleHyperlink::getAccessibleActionCount()
76 throw (uno::RuntimeException
)
78 return isValid() ? 1 : 0;
81 sal_Bool SAL_CALL
SwAccessibleHyperlink::doAccessibleAction( sal_Int32 nIndex
)
82 throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
84 vos::OGuard
aGuard(Application::GetSolarMutex());
86 sal_Bool bRet
= sal_False
;
88 const SwTxtAttr
*pTxtAttr
= GetTxtAttr();
89 if( pTxtAttr
&& 0 == nIndex
)
91 const SwFmtINetFmt
& rINetFmt
= pTxtAttr
->GetINetFmt();
92 if( rINetFmt
.GetValue().Len() )
94 ViewShell
*pVSh
= xPara
->GetShell();
97 LoadURL( rINetFmt
.GetValue(), pVSh
, URLLOAD_NOFILTER
,
98 &rINetFmt
.GetTargetFrame() );
99 ASSERT( pTxtAttr
== rINetFmt
.GetTxtINetFmt(),
100 "lost my txt attr" );
101 const SwTxtINetFmt
* pTxtAttr2
= rINetFmt
.GetTxtINetFmt();
104 const_cast<SwTxtINetFmt
*>(pTxtAttr2
)->SetVisited(true);
105 const_cast<SwTxtINetFmt
*>(pTxtAttr2
)->SetVisitedValid(true);
115 OUString SAL_CALL
SwAccessibleHyperlink::getAccessibleActionDescription(
117 throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
121 const SwTxtAttr
*pTxtAttr
= GetTxtAttr();
122 if( pTxtAttr
&& 0 == nIndex
)
124 const SwFmtINetFmt
& rINetFmt
= pTxtAttr
->GetINetFmt();
125 sDesc
= OUString( rINetFmt
.GetValue() );
131 uno::Reference
< XAccessibleKeyBinding
> SAL_CALL
132 SwAccessibleHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
133 throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
135 uno::Reference
< XAccessibleKeyBinding
> xKeyBinding
;
137 if( isValid() && 0==nIndex
)
139 ::comphelper::OAccessibleKeyBindingHelper
* pKeyBindingHelper
=
140 new ::comphelper::OAccessibleKeyBindingHelper();
141 xKeyBinding
= pKeyBindingHelper
;
143 awt::KeyStroke aKeyStroke
;
144 aKeyStroke
.Modifiers
= 0;
145 aKeyStroke
.KeyCode
= KEY_RETURN
;
146 aKeyStroke
.KeyChar
= 0;
147 aKeyStroke
.KeyFunc
= 0;
148 pKeyBindingHelper
->AddKeyBinding( aKeyStroke
);
154 // XAccessibleHyperlink
155 uno::Any SAL_CALL
SwAccessibleHyperlink::getAccessibleActionAnchor(
156 sal_Int32
/*nIndex*/ )
157 throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
162 uno::Any SAL_CALL
SwAccessibleHyperlink::getAccessibleActionObject(
163 sal_Int32
/*nIndex*/ )
164 throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
169 sal_Int32 SAL_CALL
SwAccessibleHyperlink::getStartIndex()
170 throw (uno::RuntimeException
)
175 sal_Int32 SAL_CALL
SwAccessibleHyperlink::getEndIndex()
176 throw (uno::RuntimeException
)
181 sal_Bool SAL_CALL
SwAccessibleHyperlink::isValid( )
182 throw (uno::RuntimeException
)
184 vos::OGuard
aGuard(Application::GetSolarMutex());
185 return xPara
.isValid();
188 void SwAccessibleHyperlink::Invalidate()
190 vos::OGuard
aGuard(Application::GetSolarMutex());