Line data Source code
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 <comphelper/accessiblekeybindinghelper.hxx>
21 : #include <swurl.hxx>
22 : #include <osl/mutex.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <ndtxt.hxx>
25 : #include <txtinet.hxx>
26 : #include <accpara.hxx>
27 : #include <acchyperlink.hxx>
28 :
29 : using namespace ::com::sun::star;
30 : using namespace ::com::sun::star::accessibility;
31 :
32 0 : SwAccessibleHyperlink::SwAccessibleHyperlink( sal_uInt16 nHPos,
33 : SwAccessibleParagraph *p, sal_Int32 nStt, sal_Int32 nEnd ) :
34 : nHintPos( nHPos ),
35 : xPara( p ),
36 : nStartIdx( nStt ),
37 0 : nEndIdx( nEnd )
38 : {
39 0 : }
40 :
41 0 : const SwTxtAttr *SwAccessibleHyperlink::GetTxtAttr() const
42 : {
43 0 : const SwTxtAttr *pTxtAttr = 0;
44 0 : if( xPara.is() && xPara->GetMap() )
45 : {
46 0 : const SwTxtNode *pTxtNd = xPara->GetTxtNode();
47 0 : const SwpHints *pHints = pTxtNd->GetpSwpHints();
48 0 : if( pHints && nHintPos < pHints->Count() )
49 : {
50 0 : const SwTxtAttr *pHt = (*pHints)[nHintPos];
51 0 : if( RES_TXTATR_INETFMT == pHt->Which() )
52 0 : pTxtAttr = pHt;
53 : }
54 : }
55 :
56 0 : return pTxtAttr;
57 : }
58 :
59 :
60 : // XAccessibleAction
61 0 : sal_Int32 SAL_CALL SwAccessibleHyperlink::getAccessibleActionCount()
62 : throw (uno::RuntimeException)
63 : {
64 0 : return isValid() ? 1 : 0;
65 : }
66 :
67 0 : sal_Bool SAL_CALL SwAccessibleHyperlink::doAccessibleAction( sal_Int32 nIndex )
68 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
69 : {
70 0 : SolarMutexGuard aGuard;
71 :
72 0 : sal_Bool bRet = sal_False;
73 :
74 0 : const SwTxtAttr *pTxtAttr = GetTxtAttr();
75 0 : if( pTxtAttr && 0 == nIndex )
76 : {
77 0 : const SwFmtINetFmt& rINetFmt = pTxtAttr->GetINetFmt();
78 0 : if( rINetFmt.GetValue().Len() )
79 : {
80 0 : ViewShell *pVSh = xPara->GetShell();
81 0 : if( pVSh )
82 : {
83 0 : LoadURL(*pVSh, rINetFmt.GetValue(), URLLOAD_NOFILTER,
84 0 : rINetFmt.GetTargetFrame());
85 : OSL_ENSURE( pTxtAttr == rINetFmt.GetTxtINetFmt(),
86 : "lost my txt attr" );
87 0 : const SwTxtINetFmt* pTxtAttr2 = rINetFmt.GetTxtINetFmt();
88 0 : if( pTxtAttr2 )
89 : {
90 0 : const_cast<SwTxtINetFmt*>(pTxtAttr2)->SetVisited(true);
91 0 : const_cast<SwTxtINetFmt*>(pTxtAttr2)->SetVisitedValid(true);
92 : }
93 0 : bRet = sal_True;
94 : }
95 : }
96 : }
97 :
98 0 : return bRet;
99 : }
100 :
101 0 : OUString SAL_CALL SwAccessibleHyperlink::getAccessibleActionDescription(
102 : sal_Int32 nIndex )
103 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
104 : {
105 0 : OUString sDesc;
106 :
107 0 : const SwTxtAttr *pTxtAttr = GetTxtAttr();
108 0 : if( pTxtAttr && 0 == nIndex )
109 : {
110 0 : const SwFmtINetFmt& rINetFmt = pTxtAttr->GetINetFmt();
111 0 : sDesc = OUString( rINetFmt.GetValue() );
112 : }
113 :
114 0 : return sDesc;
115 : }
116 :
117 : uno::Reference< XAccessibleKeyBinding > SAL_CALL
118 0 : SwAccessibleHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex )
119 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
120 : {
121 0 : uno::Reference< XAccessibleKeyBinding > xKeyBinding;
122 :
123 0 : if( isValid() && 0==nIndex )
124 : {
125 : ::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper =
126 0 : new ::comphelper::OAccessibleKeyBindingHelper();
127 0 : xKeyBinding = pKeyBindingHelper;
128 :
129 0 : awt::KeyStroke aKeyStroke;
130 0 : aKeyStroke.Modifiers = 0;
131 0 : aKeyStroke.KeyCode = KEY_RETURN;
132 0 : aKeyStroke.KeyChar = 0;
133 0 : aKeyStroke.KeyFunc = 0;
134 0 : pKeyBindingHelper->AddKeyBinding( aKeyStroke );
135 : }
136 :
137 0 : return xKeyBinding;
138 : }
139 :
140 : // XAccessibleHyperlink
141 0 : uno::Any SAL_CALL SwAccessibleHyperlink::getAccessibleActionAnchor(
142 : sal_Int32 /*nIndex*/ )
143 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
144 : {
145 0 : return uno::Any();
146 : }
147 :
148 0 : uno::Any SAL_CALL SwAccessibleHyperlink::getAccessibleActionObject(
149 : sal_Int32 /*nIndex*/ )
150 : throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
151 : {
152 0 : return uno::Any();
153 : }
154 :
155 0 : sal_Int32 SAL_CALL SwAccessibleHyperlink::getStartIndex()
156 : throw (uno::RuntimeException)
157 : {
158 0 : return nStartIdx;
159 : }
160 :
161 0 : sal_Int32 SAL_CALL SwAccessibleHyperlink::getEndIndex()
162 : throw (uno::RuntimeException)
163 : {
164 0 : return nEndIdx;
165 : }
166 :
167 0 : sal_Bool SAL_CALL SwAccessibleHyperlink::isValid( )
168 : throw (uno::RuntimeException)
169 : {
170 0 : SolarMutexGuard aGuard;
171 0 : return xPara.is();
172 : }
173 :
174 0 : void SwAccessibleHyperlink::Invalidate()
175 : {
176 0 : SolarMutexGuard aGuard;
177 0 : xPara = 0;
178 99 : }
179 :
180 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|