1  /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 #include <comphelper/accessiblekeybindinghelper.hxx>
31 #include <swurl.hxx>
32 #include <vos/mutex.hxx>
33 #include <vcl/svapp.hxx>
34 #include <ndtxt.hxx>
35 #include <txtinet.hxx>
36 #include <accpara.hxx>
37 #include <acchyperlink.hxx>
38 
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::accessibility;
41 using ::rtl::OUString;
42 
43 SwAccessibleHyperlink::SwAccessibleHyperlink( sal_uInt16 nHPos,
44 	SwAccessibleParagraph *p, sal_Int32 nStt, sal_Int32 nEnd ) :
45 	nHintPos( nHPos ),
46 	xPara( p ),
47 	nStartIdx( nStt ),
48 	nEndIdx( nEnd )
49 {
50 }
51 
52 const SwTxtAttr *SwAccessibleHyperlink::GetTxtAttr() const
53 {
54 	const SwTxtAttr *pTxtAttr = 0;
55 	if( xPara.isValid() && xPara->GetMap() )
56 	{
57 		const SwTxtNode *pTxtNd = xPara->GetTxtNode();
58 		const SwpHints *pHints = pTxtNd->GetpSwpHints();
59 		if( pHints && nHintPos < pHints->Count() )
60 		{
61 			const SwTxtAttr *pHt = (*pHints)[nHintPos];
62 			if( RES_TXTATR_INETFMT == pHt->Which() )
63 				pTxtAttr = pHt;
64 		}
65 	}
66 
67 	return pTxtAttr;
68 }
69 
70 
71 // XAccessibleAction
72 sal_Int32 SAL_CALL SwAccessibleHyperlink::getAccessibleActionCount()
73 		throw (uno::RuntimeException)
74 {
75 	 return isValid() ? 1 : 0;
76 }
77 
78 sal_Bool SAL_CALL SwAccessibleHyperlink::doAccessibleAction( sal_Int32 nIndex )
79 		throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
80 {
81 	vos::OGuard aGuard(Application::GetSolarMutex());
82 
83 	sal_Bool bRet = sal_False;
84 
85 	const SwTxtAttr *pTxtAttr = GetTxtAttr();
86 	if( pTxtAttr && 0 == nIndex )
87 	{
88 		const SwFmtINetFmt& rINetFmt = pTxtAttr->GetINetFmt();
89 		if( rINetFmt.GetValue().Len() )
90 		{
91 			ViewShell *pVSh = xPara->GetShell();
92 			if( pVSh )
93 			{
94 				LoadURL( rINetFmt.GetValue(), pVSh, URLLOAD_NOFILTER,
95 						 &rINetFmt.GetTargetFrame() );
96 				ASSERT( pTxtAttr == rINetFmt.GetTxtINetFmt(),
97 					 	"lost my txt attr" );
98 				const SwTxtINetFmt* pTxtAttr2 = rINetFmt.GetTxtINetFmt();
99 				if( pTxtAttr2 )
100 				{
101                     const_cast<SwTxtINetFmt*>(pTxtAttr2)->SetVisited(true);
102                     const_cast<SwTxtINetFmt*>(pTxtAttr2)->SetVisitedValid(true);
103 				}
104 				bRet = sal_True;
105 			}
106 		}
107 	}
108 
109 	return bRet;
110 }
111 
112 OUString SAL_CALL SwAccessibleHyperlink::getAccessibleActionDescription(
113 		sal_Int32 nIndex )
114 		throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
115 {
116 	OUString sDesc;
117 
118 	const SwTxtAttr *pTxtAttr = GetTxtAttr();
119 	if( pTxtAttr && 0 == nIndex )
120 	{
121 		const SwFmtINetFmt& rINetFmt = pTxtAttr->GetINetFmt();
122 		sDesc = OUString( rINetFmt.GetValue() );
123 	}
124 
125 	return sDesc;
126 }
127 
128 uno::Reference< XAccessibleKeyBinding > SAL_CALL
129 	SwAccessibleHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex )
130 	throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
131 {
132 	uno::Reference< XAccessibleKeyBinding > xKeyBinding;
133 
134 	if( isValid() && 0==nIndex )
135 	{
136 		::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper =
137 		   	new ::comphelper::OAccessibleKeyBindingHelper();
138 		xKeyBinding = pKeyBindingHelper;
139 
140         awt::KeyStroke aKeyStroke;
141 		aKeyStroke.Modifiers = 0;
142 		aKeyStroke.KeyCode = KEY_RETURN;
143 		aKeyStroke.KeyChar = 0;
144 		aKeyStroke.KeyFunc = 0;
145 		pKeyBindingHelper->AddKeyBinding( aKeyStroke );
146 	}
147 
148 	return xKeyBinding;
149 }
150 
151 // XAccessibleHyperlink
152 uno::Any SAL_CALL SwAccessibleHyperlink::getAccessibleActionAnchor(
153         sal_Int32 /*nIndex*/ )
154 		throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
155 {
156 	return uno::Any();
157 }
158 
159 uno::Any SAL_CALL SwAccessibleHyperlink::getAccessibleActionObject(
160             sal_Int32 /*nIndex*/ )
161 	throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
162 {
163 	return uno::Any();
164 }
165 
166 sal_Int32 SAL_CALL SwAccessibleHyperlink::getStartIndex()
167 		throw (uno::RuntimeException)
168 {
169 	return nStartIdx;
170 }
171 
172 sal_Int32 SAL_CALL SwAccessibleHyperlink::getEndIndex()
173 		throw (uno::RuntimeException)
174 {
175 	return nEndIdx;
176 }
177 
178 sal_Bool SAL_CALL SwAccessibleHyperlink::isValid(  )
179 		throw (uno::RuntimeException)
180 {
181 	vos::OGuard aGuard(Application::GetSolarMutex());
182 	return xPara.isValid();
183 }
184 
185 void SwAccessibleHyperlink::Invalidate()
186 {
187 	vos::OGuard aGuard(Application::GetSolarMutex());
188 	xPara = 0;
189 }
190 
191