1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2008 by Sun Microsystems, Inc.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * $RCSfile: AccessibleEditableTextPara.cxx,v $
10  * $Revision: 1.53 $
11  *
12  * This file is part of OpenOffice.org.
13  *
14  * OpenOffice.org is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU Lesser General Public License version 3
16  * only, as published by the Free Software Foundation.
17  *
18  * OpenOffice.org is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU Lesser General Public License version 3 for more details
22  * (a copy is included in the LICENSE file that accompanied this code).
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * version 3 along with OpenOffice.org.  If not, see
26  * <http://www.openoffice.org/license.html>
27  * for a copy of the LGPLv3 License.
28  *
29  ************************************************************************/
30 
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_editeng.hxx"
33 
34 #include <com/sun/star/uno/Any.hxx>
35 #include <com/sun/star/uno/Reference.hxx>
36 #include <comphelper/accessiblekeybindinghelper.hxx>
37 
38 #include "AccessibleHyperlink.hxx"
39 #include "editeng/unoedprx.hxx"
40 #include <editeng/flditem.hxx>
41 #include <vcl/keycodes.hxx>
42 
43 using namespace ::com::sun::star;
44 
45 
46 //------------------------------------------------------------------------
47 //
48 // AccessibleHyperlink implementation
49 //
50 //------------------------------------------------------------------------
51 
52 namespace accessibility
53 {
54 
55     AccessibleHyperlink::AccessibleHyperlink( SvxAccessibleTextAdapter& r, SvxFieldItem* p, sal_uInt16 nP, sal_uInt16 nR, sal_Int32 nStt, sal_Int32 nEnd, const ::rtl::OUString& rD )
56     : rTA( r )
57     {
58         pFld = p;
59         nPara = nP;
60         nRealIdx = nR;
61         nStartIdx = nStt;
62         nEndIdx = nEnd;
63         aDescription = rD;
64     }
65 
66     AccessibleHyperlink::~AccessibleHyperlink()
67     {
68         delete pFld;
69     }
70 
71     // XAccessibleAction
72     sal_Int32 SAL_CALL AccessibleHyperlink::getAccessibleActionCount() throw (uno::RuntimeException)
73     {
74     	 return isValid() ? 1 : 0;
75     }
76 
77     sal_Bool SAL_CALL AccessibleHyperlink::doAccessibleAction( sal_Int32 nIndex  ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
78     {
79     	sal_Bool bRet = sal_False;
80     	if ( isValid() && ( nIndex == 0 ) )
81     	{
82     	    rTA.FieldClicked( *pFld, nPara, nRealIdx );
83     	    bRet = sal_True;
84     	}
85     	return bRet;
86     }
87 
88     ::rtl::OUString  SAL_CALL AccessibleHyperlink::getAccessibleActionDescription( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
89     {
90     	::rtl::OUString aDesc;
91 
92     	if ( isValid() && ( nIndex == 0 ) )
93     	    aDesc = aDescription;
94 
95     	return aDesc;
96     }
97 
98     uno::Reference< ::com::sun::star::accessibility::XAccessibleKeyBinding > SAL_CALL AccessibleHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
99     {
100     	uno::Reference< ::com::sun::star::accessibility::XAccessibleKeyBinding > xKeyBinding;
101 
102     	if( isValid() && ( nIndex == 0 ) )
103     	{
104     		::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper = new ::comphelper::OAccessibleKeyBindingHelper();
105     		xKeyBinding = pKeyBindingHelper;
106 
107             awt::KeyStroke aKeyStroke;
108     		aKeyStroke.Modifiers = 0;
109     		aKeyStroke.KeyCode = KEY_RETURN;
110     		aKeyStroke.KeyChar = 0;
111     		aKeyStroke.KeyFunc = 0;
112     		pKeyBindingHelper->AddKeyBinding( aKeyStroke );
113     	}
114 
115     	return xKeyBinding;
116     }
117 
118     // XAccessibleHyperlink
119     uno::Any SAL_CALL AccessibleHyperlink::getAccessibleActionAnchor( sal_Int32 /*nIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
120     {
121     	return uno::Any();
122     }
123 
124     uno::Any SAL_CALL AccessibleHyperlink::getAccessibleActionObject( sal_Int32 /*nIndex*/ ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
125     {
126     	return uno::Any();
127     }
128 
129     sal_Int32 SAL_CALL AccessibleHyperlink::getStartIndex() throw (uno::RuntimeException)
130     {
131     	return nStartIdx;
132     }
133 
134     sal_Int32 SAL_CALL AccessibleHyperlink::getEndIndex() throw (uno::RuntimeException)
135     {
136     	return nEndIdx;
137     }
138 
139     sal_Bool SAL_CALL AccessibleHyperlink::isValid(  ) throw (uno::RuntimeException)
140     {
141     	return rTA.IsValid();
142     }
143 
144 }  // end of namespace accessibility
145 
146 //------------------------------------------------------------------------
147