android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / access / accnotexthyperlink.cxx
blob36ded739007efcb432e481b575d80fb59041bae4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
22 #include <comphelper/accessiblekeybindinghelper.hxx>
23 #include <swurl.hxx>
24 #include <vcl/svapp.hxx>
25 #include <frmfmt.hxx>
27 #include "accnotexthyperlink.hxx"
29 #include <fmturl.hxx>
31 #include <vcl/imap.hxx>
32 #include <vcl/imapobj.hxx>
33 #include <vcl/keycodes.hxx>
35 #include <accmap.hxx>
37 using namespace css;
38 using namespace css::lang;
39 using namespace css::uno;
40 using namespace css::accessibility;
42 SwAccessibleNoTextHyperlink::SwAccessibleNoTextHyperlink( SwAccessibleNoTextFrame *p, const SwFrame *aFrame ) :
43 mxFrame( p ),
44 mpFrame( aFrame )
48 // XAccessibleAction
49 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionCount()
51 SolarMutexGuard g;
53 SwFormatURL aURL( GetFormat()->GetURL() );
54 ImageMap* pMap = aURL.GetMap();
55 if( pMap != nullptr )
57 return pMap->GetIMapObjectCount();
59 else if( !aURL.GetURL().isEmpty() )
61 return 1;
64 return 0;
67 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::doAccessibleAction( sal_Int32 nIndex )
69 SolarMutexGuard aGuard;
71 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
72 throw lang::IndexOutOfBoundsException();
74 bool bRet = false;
75 SwFormatURL aURL( GetFormat()->GetURL() );
76 ImageMap* pMap = aURL.GetMap();
77 if( pMap != nullptr )
79 IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
80 if (!pMapObj->GetURL().isEmpty())
82 SwViewShell *pVSh = mxFrame->GetShell();
83 if( pVSh )
85 LoadURL( *pVSh, pMapObj->GetURL(), LoadUrlFlags::NONE,
86 pMapObj->GetTarget() );
87 bRet = true;
91 else if (!aURL.GetURL().isEmpty())
93 SwViewShell *pVSh = mxFrame->GetShell();
94 if( pVSh )
96 LoadURL( *pVSh, aURL.GetURL(), LoadUrlFlags::NONE,
97 aURL.GetTargetFrameName() );
98 bRet = true;
102 return bRet;
105 OUString SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionDescription(
106 sal_Int32 nIndex )
108 SolarMutexGuard g;
110 OUString sDesc;
112 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
113 throw lang::IndexOutOfBoundsException();
115 SwFormatURL aURL( GetFormat()->GetURL() );
116 ImageMap* pMap = aURL.GetMap();
117 if( pMap != nullptr )
119 IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
120 if (!pMapObj->GetDesc().isEmpty())
121 sDesc = pMapObj->GetDesc();
122 else if (!pMapObj->GetURL().isEmpty())
123 sDesc = pMapObj->GetURL();
125 else if( !aURL.GetURL().isEmpty() )
126 sDesc = aURL.GetName();
128 return sDesc;
131 Reference< XAccessibleKeyBinding > SAL_CALL
132 SwAccessibleNoTextHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex )
134 SolarMutexGuard g;
136 Reference< XAccessibleKeyBinding > xKeyBinding;
138 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
139 throw lang::IndexOutOfBoundsException();
141 bool bIsValid = false;
142 SwFormatURL aURL( GetFormat()->GetURL() );
143 ImageMap* pMap = aURL.GetMap();
144 if( pMap != nullptr )
146 IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
147 if (!pMapObj->GetURL().isEmpty())
148 bIsValid = true;
150 else if (!aURL.GetURL().isEmpty())
151 bIsValid = true;
153 if(bIsValid)
155 rtl::Reference<::comphelper::OAccessibleKeyBindingHelper> pKeyBindingHelper =
156 new ::comphelper::OAccessibleKeyBindingHelper();
157 xKeyBinding = pKeyBindingHelper;
159 css::awt::KeyStroke aKeyStroke;
160 aKeyStroke.Modifiers = 0;
161 aKeyStroke.KeyCode = KEY_RETURN;
162 aKeyStroke.KeyChar = 0;
163 aKeyStroke.KeyFunc = 0;
164 pKeyBindingHelper->AddKeyBinding( aKeyStroke );
167 return xKeyBinding;
170 // XAccessibleHyperlink
171 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionAnchor(
172 sal_Int32 nIndex )
174 SolarMutexGuard g;
176 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
177 throw lang::IndexOutOfBoundsException();
179 Any aRet;
180 //SwFrame* pAnchor = static_cast<SwFlyFrame*>(mpFrame)->GetAnchor();
181 Reference< XAccessible > xAnchor = mxFrame->GetAccessibleMap()->GetContext(mpFrame);
182 //SwAccessibleNoTextFrame* pFrame = xFrame.get();
183 //Reference< XAccessible > xAnchor = (XAccessible*)pFrame;
184 aRet <<= xAnchor;
185 return aRet;
188 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionObject(
189 sal_Int32 nIndex )
191 SolarMutexGuard g;
193 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
194 throw lang::IndexOutOfBoundsException();
196 SwFormatURL aURL( GetFormat()->GetURL() );
197 OUString retText;
198 ImageMap* pMap = aURL.GetMap();
199 if( pMap != nullptr )
201 IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
202 if (!pMapObj->GetURL().isEmpty())
203 retText = pMapObj->GetURL();
205 else if ( !aURL.GetURL().isEmpty() )
206 retText = aURL.GetURL();
208 Any aRet;
209 aRet <<= retText;
210 return aRet;
213 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getStartIndex()
215 return 0;
218 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getEndIndex()
220 return 0;
223 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::isValid( )
225 SolarMutexGuard g;
227 SwFormatURL aURL( GetFormat()->GetURL() );
229 if( aURL.GetMap() || !aURL.GetURL().isEmpty() )
230 return true;
231 return false;
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */