1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <vcl/svapp.hxx>
27 #include "accnotexthyperlink.hxx"
31 #include <vcl/imap.hxx>
32 #include <vcl/imapobj.hxx>
33 #include <vcl/keycodes.hxx>
38 using namespace css::lang
;
39 using namespace css::uno
;
40 using namespace css::accessibility
;
42 SwAccessibleNoTextHyperlink::SwAccessibleNoTextHyperlink( SwAccessibleNoTextFrame
*p
, const SwFrame
*aFrame
) :
49 sal_Int32 SAL_CALL
SwAccessibleNoTextHyperlink::getAccessibleActionCount()
53 SwFormatURL
aURL( GetFormat()->GetURL() );
54 ImageMap
* pMap
= aURL
.GetMap();
57 return pMap
->GetIMapObjectCount();
59 else if( !aURL
.GetURL().isEmpty() )
67 sal_Bool SAL_CALL
SwAccessibleNoTextHyperlink::doAccessibleAction( sal_Int32 nIndex
)
69 SolarMutexGuard aGuard
;
71 if(nIndex
< 0 || nIndex
>= getAccessibleActionCount())
72 throw lang::IndexOutOfBoundsException();
75 SwFormatURL
aURL( GetFormat()->GetURL() );
76 ImageMap
* pMap
= aURL
.GetMap();
79 IMapObject
* pMapObj
= pMap
->GetIMapObject(nIndex
);
80 if (!pMapObj
->GetURL().isEmpty())
82 SwViewShell
*pVSh
= mxFrame
->GetShell();
85 LoadURL( *pVSh
, pMapObj
->GetURL(), LoadUrlFlags::NONE
,
86 pMapObj
->GetTarget() );
91 else if (!aURL
.GetURL().isEmpty())
93 SwViewShell
*pVSh
= mxFrame
->GetShell();
96 LoadURL( *pVSh
, aURL
.GetURL(), LoadUrlFlags::NONE
,
97 aURL
.GetTargetFrameName() );
105 OUString SAL_CALL
SwAccessibleNoTextHyperlink::getAccessibleActionDescription(
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();
131 Reference
< XAccessibleKeyBinding
> SAL_CALL
132 SwAccessibleNoTextHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex
)
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())
150 else if (!aURL
.GetURL().isEmpty())
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
);
170 // XAccessibleHyperlink
171 Any SAL_CALL
SwAccessibleNoTextHyperlink::getAccessibleActionAnchor(
176 if(nIndex
< 0 || nIndex
>= getAccessibleActionCount())
177 throw lang::IndexOutOfBoundsException();
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;
188 Any SAL_CALL
SwAccessibleNoTextHyperlink::getAccessibleActionObject(
193 if(nIndex
< 0 || nIndex
>= getAccessibleActionCount())
194 throw lang::IndexOutOfBoundsException();
196 SwFormatURL
aURL( GetFormat()->GetURL() );
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();
213 sal_Int32 SAL_CALL
SwAccessibleNoTextHyperlink::getStartIndex()
218 sal_Int32 SAL_CALL
SwAccessibleNoTextHyperlink::getEndIndex()
223 sal_Bool SAL_CALL
SwAccessibleNoTextHyperlink::isValid( )
227 SwFormatURL
aURL( GetFormat()->GetURL() );
229 if( aURL
.GetMap() || !aURL
.GetURL().isEmpty() )
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */