xref: /AOO41X/main/sw/source/core/access/accnotexthyperlink.cxx (revision d3553c6b68aef63d45d1605bdabbc6fea7b9e42f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sw.hxx"
24 
25 #include <comphelper/accessiblekeybindinghelper.hxx>
26 #include <swurl.hxx>
27 #include <vos/mutex.hxx>
28 #include <vcl/svapp.hxx>
29 #include <ndtxt.hxx>
30 #include <txtinet.hxx>
31 #include <frmfmt.hxx>
32 
33 #include <accnotexthyperlink.hxx>
34 
35 #include <fmturl.hxx>
36 
37 #include <svtools/imap.hxx>
38 #include <svtools/imapobj.hxx>
39 
40 #include <accmap.hxx>
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::accessibility;
44 //using namespace ::rtl;
45 
SwAccessibleNoTextHyperlink(SwAccessibleNoTextFrame * p,const SwFrm * aFrm,sal_uInt16 nIndex)46 SwAccessibleNoTextHyperlink::SwAccessibleNoTextHyperlink( SwAccessibleNoTextFrame *p, const SwFrm *aFrm, sal_uInt16 nIndex) :
47     xFrame( p ),
48     mpFrm( aFrm ),
49     mnIndex(nIndex)
50 {
51 }
52 
53 // XAccessibleAction
getAccessibleActionCount()54 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionCount()
55         throw (RuntimeException)
56 {
57     SwFmtURL aURL( GetFmt()->GetURL() );
58     ImageMap* pMap = aURL.GetMap();
59     if( pMap != NULL )
60     {
61         return  pMap->GetIMapObjectCount();
62     }else if( aURL.GetURL().Len() )
63     {
64         return 1;
65     }
66 
67     return 0;
68 }
69 
doAccessibleAction(sal_Int32 nIndex)70 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::doAccessibleAction( sal_Int32 nIndex )
71         throw (IndexOutOfBoundsException, RuntimeException)
72 {
73     vos::OGuard aGuard(Application::GetSolarMutex());
74 
75     if(nIndex < 0 || nIndex >= getAccessibleActionCount())
76         throw new IndexOutOfBoundsException;
77 
78     sal_Bool bRet = sal_False;
79     SwFmtURL aURL( GetFmt()->GetURL() );
80     ImageMap* pMap = aURL.GetMap();
81     if( pMap != NULL )
82     {
83         IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
84         if(pMapObj->GetURL().Len())
85         {
86             ViewShell *pVSh = xFrame->GetShell();
87             if( pVSh )
88             {
89                 LoadURL( pMapObj->GetURL(), pVSh, URLLOAD_NOFILTER,
90                          &pMapObj->GetTarget() );
91                 bRet = sal_True;
92             }
93         }
94     }
95     else if( aURL.GetURL().Len() )
96     {
97         ViewShell *pVSh = xFrame->GetShell();
98         if( pVSh )
99         {
100             LoadURL( aURL.GetURL(), pVSh, URLLOAD_NOFILTER,
101                      &aURL.GetTargetFrameName() );
102             bRet = sal_True;
103         }
104     }
105 
106     return bRet;
107 }
108 
getAccessibleActionDescription(sal_Int32 nIndex)109 rtl::OUString SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionDescription(
110         sal_Int32 nIndex )
111         throw (IndexOutOfBoundsException, RuntimeException)
112 {
113     rtl::OUString sDesc;
114 
115     if(nIndex < 0 || nIndex >= getAccessibleActionCount())
116         throw new IndexOutOfBoundsException;
117 
118     SwFmtURL aURL( GetFmt()->GetURL() );
119     ImageMap* pMap = aURL.GetMap();
120     if( pMap != NULL )
121     {
122         IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
123         if(pMapObj->GetDesc().Len())
124             sDesc = rtl::OUString( pMapObj->GetDesc() );
125         else if(pMapObj->GetURL().Len())
126             sDesc = rtl::OUString( pMapObj->GetURL() );
127     }
128     else if( aURL.GetURL().Len() )
129         sDesc = rtl::OUString( aURL.GetName() );
130         //sDesc = rtl::OUString( aURL.GetName() );
131 
132     return sDesc;
133 }
134 
135 Reference< XAccessibleKeyBinding > SAL_CALL
getAccessibleActionKeyBinding(sal_Int32 nIndex)136     SwAccessibleNoTextHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex )
137     throw (IndexOutOfBoundsException, RuntimeException)
138 {
139     Reference< XAccessibleKeyBinding > xKeyBinding;
140 
141     if(nIndex < 0 || nIndex >= getAccessibleActionCount())
142         throw new IndexOutOfBoundsException;
143 
144     bool bIsValid = sal_False;
145     SwFmtURL aURL( GetFmt()->GetURL() );
146     ImageMap* pMap = aURL.GetMap();
147     if( pMap != NULL )
148     {
149         IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
150         if(pMapObj->GetURL().Len())
151             bIsValid = sal_True;
152     }else if( aURL.GetURL().Len() )
153         bIsValid = sal_True;
154 
155     if(bIsValid)
156     {
157         ::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper =
158             new ::comphelper::OAccessibleKeyBindingHelper();
159         xKeyBinding = pKeyBindingHelper;
160 
161         ::com::sun::star::awt::KeyStroke aKeyStroke;
162         aKeyStroke.Modifiers = 0;
163         aKeyStroke.KeyCode = KEY_RETURN;
164         aKeyStroke.KeyChar = 0;
165         aKeyStroke.KeyFunc = 0;
166         pKeyBindingHelper->AddKeyBinding( aKeyStroke );
167     }
168 
169     return xKeyBinding;
170 }
171 
172 // XAccessibleHyperlink
getAccessibleActionAnchor(sal_Int32 nIndex)173 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionAnchor(
174         sal_Int32 nIndex )
175         throw (IndexOutOfBoundsException, RuntimeException)
176 {
177     if(nIndex < 0 || nIndex >= getAccessibleActionCount())
178         throw new IndexOutOfBoundsException;
179 
180     Any aRet;
181     //SwFrm* pAnchor = ((SwFlyFrm*)mpFrm)->GetAnchor();
182     Reference< XAccessible > xAnchor = xFrame->GetAccessibleMap()->GetContext(mpFrm, sal_True);
183     //SwAccessibleNoTextFrame* pFrame = xFrame.get();
184     //Reference< XAccessible > xAnchor = (XAccessible*)pFrame;
185     aRet <<= xAnchor;
186     return aRet;
187 }
188 
getAccessibleActionObject(sal_Int32 nIndex)189 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionObject(
190             sal_Int32 nIndex )
191     throw (IndexOutOfBoundsException, RuntimeException)
192 {
193     if(nIndex < 0 || nIndex >= getAccessibleActionCount())
194         throw new IndexOutOfBoundsException;
195 
196     SwFmtURL aURL( GetFmt()->GetURL() );
197     ::rtl::OUString retText;
198     ImageMap* pMap = aURL.GetMap();
199     if( pMap != NULL )
200     {
201         IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
202         if(pMapObj->GetURL().Len())
203             retText = rtl::OUString( pMapObj->GetURL() );
204     }else if( aURL.GetURL().Len() )
205         retText = rtl::OUString( aURL.GetURL() );
206 
207     Any aRet;
208     aRet <<= retText;
209     return aRet;
210 }
211 
getStartIndex()212 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getStartIndex()
213         throw (RuntimeException)
214 {
215     return 0;
216 }
217 
getEndIndex()218 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getEndIndex()
219         throw (RuntimeException)
220 {
221     return 0;
222 }
223 
isValid()224 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::isValid(  )
225         throw (::com::sun::star::uno::RuntimeException)
226 {
227     SwFmtURL aURL( GetFmt()->GetURL() );
228 
229     if( aURL.GetMap() || aURL.GetURL().Len() )
230         return sal_True;
231     return sal_False;
232 }
233