xref: /AOO41X/main/sw/source/core/access/accnotexthyperlink.cxx (revision 0deba7fbda3d9908785c25a443701a293b6f4e71)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright IBM Corporation 2010.
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org.  If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <comphelper/accessiblekeybindinghelper.hxx>
32 #include <swurl.hxx>
33 #include <vos/mutex.hxx>
34 #include <vcl/svapp.hxx>
35 #include <ndtxt.hxx>
36 #include <txtinet.hxx>
37 #include <frmfmt.hxx>
38 
39 #include <accnotexthyperlink.hxx>
40 
41 #include <fmturl.hxx>
42 
43 #include <svtools/imap.hxx>
44 #include <svtools/imapobj.hxx>
45 
46 #include <accmap.hxx>
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::accessibility;
50 //using namespace ::rtl;
51 
52 SwAccessibleNoTextHyperlink::SwAccessibleNoTextHyperlink( SwAccessibleNoTextFrame *p, const SwFrm *aFrm, sal_uInt16 nIndex) :
53 	xFrame( p ),
54 	mpFrm( aFrm ),
55 	mnIndex(nIndex)
56 {
57 }
58 
59 // XAccessibleAction
60 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionCount()
61 		throw (RuntimeException)
62 {
63 	SwFmtURL aURL( GetFmt()->GetURL() );
64 	ImageMap* pMap = aURL.GetMap();
65 	if( pMap != NULL )
66 	{
67 		return	pMap->GetIMapObjectCount();
68 	}else if( aURL.GetURL().Len() )
69 	{
70 		return 1;
71 	}
72 
73 	return 0;
74 }
75 
76 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::doAccessibleAction( sal_Int32 nIndex )
77 		throw (IndexOutOfBoundsException, RuntimeException)
78 {
79 	vos::OGuard aGuard(Application::GetSolarMutex());
80 
81 	if(nIndex < 0 || nIndex >= getAccessibleActionCount())
82 		throw new IndexOutOfBoundsException;
83 
84 	sal_Bool bRet = sal_False;
85 	SwFmtURL aURL( GetFmt()->GetURL() );
86 	ImageMap* pMap = aURL.GetMap();
87 	if( pMap != NULL )
88 	{
89 		IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
90 		if(pMapObj->GetURL().Len())
91 		{
92 			ViewShell *pVSh = xFrame->GetShell();
93 			if( pVSh )
94 			{
95 				LoadURL( pMapObj->GetURL(), pVSh, URLLOAD_NOFILTER,
96 						 &pMapObj->GetTarget() );
97 				bRet = sal_True;
98 			}
99 		}
100 	}
101 	else if( aURL.GetURL().Len() )
102 	{
103 		ViewShell *pVSh = xFrame->GetShell();
104 		if( pVSh )
105 		{
106 			LoadURL( aURL.GetURL(), pVSh, URLLOAD_NOFILTER,
107 					 &aURL.GetTargetFrameName() );
108 			bRet = sal_True;
109 		}
110 	}
111 
112 	return bRet;
113 }
114 
115 rtl::OUString SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionDescription(
116 		sal_Int32 nIndex )
117 		throw (IndexOutOfBoundsException, RuntimeException)
118 {
119 	rtl::OUString sDesc;
120 
121 	if(nIndex < 0 || nIndex >= getAccessibleActionCount())
122 		throw new IndexOutOfBoundsException;
123 
124 	SwFmtURL aURL( GetFmt()->GetURL() );
125 	ImageMap* pMap = aURL.GetMap();
126 	if( pMap != NULL )
127 	{
128 		IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
129 		if(pMapObj->GetDesc().Len())
130 			sDesc = rtl::OUString( pMapObj->GetDesc() );
131 		else if(pMapObj->GetURL().Len())
132 			sDesc = rtl::OUString( pMapObj->GetURL() );
133 	}
134 	else if( aURL.GetURL().Len() )
135 		sDesc = rtl::OUString( aURL.GetName() );
136 		//sDesc = rtl::OUString( aURL.GetName() );
137 
138 	return sDesc;
139 }
140 
141 Reference< XAccessibleKeyBinding > SAL_CALL
142 	SwAccessibleNoTextHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex )
143 	throw (IndexOutOfBoundsException, RuntimeException)
144 {
145 	Reference< XAccessibleKeyBinding > xKeyBinding;
146 
147 	if(nIndex < 0 || nIndex >= getAccessibleActionCount())
148 		throw new IndexOutOfBoundsException;
149 
150 	bool bIsValid = sal_False;
151 	SwFmtURL aURL( GetFmt()->GetURL() );
152 	ImageMap* pMap = aURL.GetMap();
153 	if( pMap != NULL )
154 	{
155 		IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
156 		if(pMapObj->GetURL().Len())
157 			bIsValid = sal_True;
158 	}else if( aURL.GetURL().Len() )
159 		bIsValid = sal_True;
160 
161 	if(bIsValid)
162 	{
163 		::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper =
164 		   	new ::comphelper::OAccessibleKeyBindingHelper();
165 		xKeyBinding = pKeyBindingHelper;
166 
167 		::com::sun::star::awt::KeyStroke aKeyStroke;
168 		aKeyStroke.Modifiers = 0;
169 		aKeyStroke.KeyCode = KEY_RETURN;
170 		aKeyStroke.KeyChar = 0;
171 		aKeyStroke.KeyFunc = 0;
172 		pKeyBindingHelper->AddKeyBinding( aKeyStroke );
173 	}
174 
175 	return xKeyBinding;
176 }
177 
178 // XAccessibleHyperlink
179 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionAnchor(
180 		sal_Int32 nIndex )
181 		throw (IndexOutOfBoundsException, RuntimeException)
182 {
183 	if(nIndex < 0 || nIndex >= getAccessibleActionCount())
184 		throw new IndexOutOfBoundsException;
185 
186 	Any aRet;
187 	//SwFrm* pAnchor = ((SwFlyFrm*)mpFrm)->GetAnchor();
188 	Reference< XAccessible > xAnchor = xFrame->GetAccessibleMap()->GetContext(mpFrm, sal_True);
189 	//SwAccessibleNoTextFrame* pFrame = xFrame.get();
190 	//Reference< XAccessible > xAnchor = (XAccessible*)pFrame;
191 	aRet <<= xAnchor;
192 	return aRet;
193 }
194 
195 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionObject(
196 			sal_Int32 nIndex )
197 	throw (IndexOutOfBoundsException, RuntimeException)
198 {
199 	if(nIndex < 0 || nIndex >= getAccessibleActionCount())
200 		throw new IndexOutOfBoundsException;
201 
202 	SwFmtURL aURL( GetFmt()->GetURL() );
203 	::rtl::OUString retText;
204 	ImageMap* pMap = aURL.GetMap();
205 	if( pMap != NULL )
206 	{
207 		IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
208 		if(pMapObj->GetURL().Len())
209 			retText = rtl::OUString( pMapObj->GetURL() );
210 	}else if( aURL.GetURL().Len() )
211 		retText = rtl::OUString( aURL.GetURL() );
212 
213 	Any aRet;
214 	aRet <<= retText;
215 	return aRet;
216 }
217 
218 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getStartIndex()
219 		throw (RuntimeException)
220 {
221 	return 0;
222 }
223 
224 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getEndIndex()
225 		throw (RuntimeException)
226 {
227 	return 0;
228 }
229 
230 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::isValid(  )
231 		throw (::com::sun::star::uno::RuntimeException)
232 {
233 	SwFmtURL aURL( GetFmt()->GetURL() );
234 
235 	if( aURL.GetMap() || aURL.GetURL().Len() )
236 		return sal_True;
237 	return sal_False;
238 }
239