LibreOffice Module sw (master)  1
accnotexthyperlink.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
21 
23 #include <swurl.hxx>
24 #include <vcl/svapp.hxx>
25 #include <ndtxt.hxx>
26 #include <txtinet.hxx>
27 #include <frmfmt.hxx>
28 
29 #include "accnotexthyperlink.hxx"
30 
31 #include <fmturl.hxx>
32 
33 #include <vcl/imap.hxx>
34 #include <vcl/imapobj.hxx>
35 #include <vcl/keycodes.hxx>
36 
37 #include <accmap.hxx>
38 
39 using namespace css;
40 using namespace css::lang;
41 using namespace css::uno;
42 using namespace css::accessibility;
43 
45  mxFrame( p ),
46  mpFrame( aFrame )
47 {
48 }
49 
50 // XAccessibleAction
52 {
54 
55  SwFormatURL aURL( GetFormat()->GetURL() );
56  ImageMap* pMap = aURL.GetMap();
57  if( pMap != nullptr )
58  {
59  return pMap->GetIMapObjectCount();
60  }
61  else if( !aURL.GetURL().isEmpty() )
62  {
63  return 1;
64  }
65 
66  return 0;
67 }
68 
70 {
71  SolarMutexGuard aGuard;
72 
73  if(nIndex < 0 || nIndex >= getAccessibleActionCount())
74  throw lang::IndexOutOfBoundsException();
75 
76  bool bRet = false;
77  SwFormatURL aURL( GetFormat()->GetURL() );
78  ImageMap* pMap = aURL.GetMap();
79  if( pMap != nullptr )
80  {
81  IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
82  if (!pMapObj->GetURL().isEmpty())
83  {
84  SwViewShell *pVSh = mxFrame->GetShell();
85  if( pVSh )
86  {
87  LoadURL( *pVSh, pMapObj->GetURL(), LoadUrlFlags::NONE,
88  pMapObj->GetTarget() );
89  bRet = true;
90  }
91  }
92  }
93  else if (!aURL.GetURL().isEmpty())
94  {
95  SwViewShell *pVSh = mxFrame->GetShell();
96  if( pVSh )
97  {
98  LoadURL( *pVSh, aURL.GetURL(), LoadUrlFlags::NONE,
99  aURL.GetTargetFrameName() );
100  bRet = true;
101  }
102  }
103 
104  return bRet;
105 }
106 
108  sal_Int32 nIndex )
109 {
110  SolarMutexGuard g;
111 
112  OUString sDesc;
113 
114  if(nIndex < 0 || nIndex >= getAccessibleActionCount())
115  throw lang::IndexOutOfBoundsException();
116 
117  SwFormatURL aURL( GetFormat()->GetURL() );
118  ImageMap* pMap = aURL.GetMap();
119  if( pMap != nullptr )
120  {
121  IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
122  if (!pMapObj->GetDesc().isEmpty())
123  sDesc = pMapObj->GetDesc();
124  else if (!pMapObj->GetURL().isEmpty())
125  sDesc = pMapObj->GetURL();
126  }
127  else if( !aURL.GetURL().isEmpty() )
128  sDesc = aURL.GetName();
129 
130  return sDesc;
131 }
132 
133 Reference< XAccessibleKeyBinding > SAL_CALL
135 {
136  SolarMutexGuard g;
137 
138  Reference< XAccessibleKeyBinding > xKeyBinding;
139 
140  if(nIndex < 0 || nIndex >= getAccessibleActionCount())
141  throw lang::IndexOutOfBoundsException();
142 
143  bool bIsValid = false;
144  SwFormatURL aURL( GetFormat()->GetURL() );
145  ImageMap* pMap = aURL.GetMap();
146  if( pMap != nullptr )
147  {
148  IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
149  if (!pMapObj->GetURL().isEmpty())
150  bIsValid = true;
151  }
152  else if (!aURL.GetURL().isEmpty())
153  bIsValid = true;
154 
155  if(bIsValid)
156  {
157  ::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper =
158  new ::comphelper::OAccessibleKeyBindingHelper();
159  xKeyBinding = pKeyBindingHelper;
160 
161  css::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
174  sal_Int32 nIndex )
175 {
176  SolarMutexGuard g;
177 
178  if(nIndex < 0 || nIndex >= getAccessibleActionCount())
179  throw lang::IndexOutOfBoundsException();
180 
181  Any aRet;
182  //SwFrame* pAnchor = static_cast<SwFlyFrame*>(mpFrame)->GetAnchor();
183  Reference< XAccessible > xAnchor = mxFrame->GetAccessibleMap()->GetContext(mpFrame);
184  //SwAccessibleNoTextFrame* pFrame = xFrame.get();
185  //Reference< XAccessible > xAnchor = (XAccessible*)pFrame;
186  aRet <<= xAnchor;
187  return aRet;
188 }
189 
191  sal_Int32 nIndex )
192 {
193  SolarMutexGuard g;
194 
195  if(nIndex < 0 || nIndex >= getAccessibleActionCount())
196  throw lang::IndexOutOfBoundsException();
197 
198  SwFormatURL aURL( GetFormat()->GetURL() );
199  OUString retText;
200  ImageMap* pMap = aURL.GetMap();
201  if( pMap != nullptr )
202  {
203  IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
204  if (!pMapObj->GetURL().isEmpty())
205  retText = pMapObj->GetURL();
206  }
207  else if ( !aURL.GetURL().isEmpty() )
208  retText = aURL.GetURL();
209 
210  Any aRet;
211  aRet <<= retText;
212  return aRet;
213 }
214 
216 {
217  return 0;
218 }
219 
221 {
222  return 0;
223 }
224 
226 {
227  SolarMutexGuard g;
228 
229  SwFormatURL aURL( GetFormat()->GetURL() );
230 
231  if( aURL.GetMap() || !aURL.GetURL().isEmpty() )
232  return true;
233  return false;
234 }
235 
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetTarget() const
Base class of the Writer layout elements.
Definition: frame.hxx:295
size_t GetIMapObjectCount() const
void AddKeyBinding(const css::uno::Sequence< css::awt::KeyStroke > &rKeyBinding)
void LoadURL(SwViewShell &rVSh, const OUString &rURL, LoadUrlFlags nFilter, const OUString &rTargetFrameName)
Definition: wrtsh2.cxx:491
const OUString & GetName() const
Definition: fmturl.hxx:71
unsigned char sal_Bool
const ImageMap * GetMap() const
Definition: fmturl.hxx:68
#define KEY_RETURN
const OUString & GetTargetFrameName() const
Definition: fmturl.hxx:65
IMapObject * GetIMapObject(size_t nPos) const
const OUString & GetDesc() const
const OUString & GetURL() const
const OUString & GetURL() const
Definition: fmturl.hxx:66