xref: /AOO41X/main/editeng/source/accessibility/AccessibleHyperlink.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <comphelper/accessiblekeybindinghelper.hxx>
30 
31 #include "AccessibleHyperlink.hxx"
32 #include "editeng/unoedprx.hxx"
33 #include <editeng/flditem.hxx>
34 #include <vcl/keycodes.hxx>
35 
36 using namespace ::com::sun::star;
37 
38 
39 //------------------------------------------------------------------------
40 //
41 // AccessibleHyperlink implementation
42 //
43 //------------------------------------------------------------------------
44 
45 namespace accessibility
46 {
47 
48     AccessibleHyperlink::AccessibleHyperlink( SvxAccessibleTextAdapter& r, SvxFieldItem* p, sal_uInt16 nP, sal_uInt16 nR, sal_Int32 nStt, sal_Int32 nEnd, const ::rtl::OUString& rD )
49     : rTA( r )
50     {
51         pFld = p;
52         nPara = nP;
53         nRealIdx = nR;
54         nStartIdx = nStt;
55         nEndIdx = nEnd;
56         aDescription = rD;
57     }
58 
59     AccessibleHyperlink::~AccessibleHyperlink()
60     {
61         delete pFld;
62     }
63 
64     // XAccessibleAction
65     sal_Int32 SAL_CALL AccessibleHyperlink::getAccessibleActionCount() throw (uno::RuntimeException)
66     {
67          return isValid() ? 1 : 0;
68     }
69 
70     sal_Bool SAL_CALL AccessibleHyperlink::doAccessibleAction( sal_Int32 nIndex  ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
71     {
72         sal_Bool bRet = sal_False;
73         if ( isValid() && ( nIndex == 0 ) )
74         {
75             rTA.FieldClicked( *pFld, nPara, nRealIdx );
76             bRet = sal_True;
77         }
78         return bRet;
79     }
80 
81     ::rtl::OUString  SAL_CALL AccessibleHyperlink::getAccessibleActionDescription( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
82     {
83         ::rtl::OUString aDesc;
84 
85         if ( isValid() && ( nIndex == 0 ) )
86             aDesc = aDescription;
87 
88         return aDesc;
89     }
90 
91     uno::Reference< ::com::sun::star::accessibility::XAccessibleKeyBinding > SAL_CALL AccessibleHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
92     {
93         uno::Reference< ::com::sun::star::accessibility::XAccessibleKeyBinding > xKeyBinding;
94 
95         if( isValid() && ( nIndex == 0 ) )
96         {
97             ::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper = new ::comphelper::OAccessibleKeyBindingHelper();
98             xKeyBinding = pKeyBindingHelper;
99 
100             awt::KeyStroke aKeyStroke;
101             aKeyStroke.Modifiers = 0;
102             aKeyStroke.KeyCode = KEY_RETURN;
103             aKeyStroke.KeyChar = 0;
104             aKeyStroke.KeyFunc = 0;
105             pKeyBindingHelper->AddKeyBinding( aKeyStroke );
106         }
107 
108         return xKeyBinding;
109     }
110 
111     // XAccessibleHyperlink
112     uno::Any SAL_CALL AccessibleHyperlink::getAccessibleActionAnchor( sal_Int32 /*nIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
113     {
114         return uno::Any();
115     }
116 
117     uno::Any SAL_CALL AccessibleHyperlink::getAccessibleActionObject( sal_Int32 /*nIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
118     {
119         return uno::Any();
120     }
121 
122     sal_Int32 SAL_CALL AccessibleHyperlink::getStartIndex() throw (uno::RuntimeException)
123     {
124         return nStartIdx;
125     }
126 
127     sal_Int32 SAL_CALL AccessibleHyperlink::getEndIndex() throw (uno::RuntimeException)
128     {
129         return nEndIdx;
130     }
131 
132     sal_Bool SAL_CALL AccessibleHyperlink::isValid(  ) throw (uno::RuntimeException)
133     {
134         return rTA.IsValid();
135     }
136 
137 }  // end of namespace accessibility
138 
139 //------------------------------------------------------------------------
140