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_sw.hxx"
26 
27 
28 #include <vos/mutex.hxx>
29 #include <com/sun/star/accessibility/AccessibleRole.hpp>
30 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 #include <unotools/accessiblestatesethelper.hxx>
32 #include <rtl/uuid.h>
33 #include <vcl/svapp.hxx>
34 #include <ftnfrm.hxx>
35 #include <fmtftn.hxx>
36 #include <txtftn.hxx>
37 #include <viewsh.hxx>
38 #include <accmap.hxx>
39 #include "accfootnote.hxx"
40 #ifndef _ACCESS_HRC
41 #include "access.hrc"
42 #endif
43 
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::accessibility;
48 using ::rtl::OUString;
49 
50 const sal_Char sServiceNameFootnote[] = "com.sun.star.text.AccessibleFootnoteView";
51 const sal_Char sServiceNameEndnote[] = "com.sun.star.text.AccessibleEndnoteView";
52 const sal_Char sImplementationNameFootnote[] = "com.sun.star.comp.Writer.SwAccessibleFootnoteView";
53 const sal_Char sImplementationNameEndnote[] = "com.sun.star.comp.Writer.SwAccessibleEndnoteView";
54 
55 SwAccessibleFootnote::SwAccessibleFootnote(
56         SwAccessibleMap* pInitMap,
57 		sal_Bool bIsEndnote,
58 		sal_Int32 nFootEndNote,
59 		const SwFtnFrm *pFtnFrm	) :
60     SwAccessibleContext( pInitMap,
61 		bIsEndnote ? AccessibleRole::END_NOTE : AccessibleRole::FOOTNOTE,
62 		pFtnFrm )
63 {
64 	vos::OGuard aGuard(Application::GetSolarMutex());
65 
66 	sal_uInt16 nResId = bIsEndnote ? STR_ACCESS_ENDNOTE_NAME
67 								   : STR_ACCESS_FOOTNOTE_NAME;
68 	OUString sArg( OUString::valueOf( nFootEndNote ) );
69 	SetName( GetResource( nResId, &sArg ) );
70 }
71 
72 SwAccessibleFootnote::~SwAccessibleFootnote()
73 {
74 }
75 
76 OUString SAL_CALL SwAccessibleFootnote::getAccessibleDescription (void)
77         throw (uno::RuntimeException)
78 {
79 	vos::OGuard aGuard(Application::GetSolarMutex());
80 
81 	CHECK_FOR_DEFUNC( XAccessibleContext )
82 
83 	sal_uInt16 nResId = AccessibleRole::END_NOTE == GetRole()
84 		? STR_ACCESS_ENDNOTE_DESC
85 		: STR_ACCESS_FOOTNOTE_DESC ;
86 
87 	OUString sArg;
88 	const SwTxtFtn *pTxtFtn =
89 		static_cast< const SwFtnFrm *>( GetFrm() )->GetAttr();
90 	if( pTxtFtn )
91 	{
92 		const SwDoc *pDoc = GetMap()->GetShell()->GetDoc();
93 		sArg = pTxtFtn->GetFtn().GetViewNumStr( *pDoc );
94 	}
95 
96 	return GetResource( nResId, &sArg );
97 }
98 
99 OUString SAL_CALL SwAccessibleFootnote::getImplementationName()
100         throw( RuntimeException )
101 {
102 	if( AccessibleRole::END_NOTE == GetRole() )
103 		return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameEndnote));
104 	else
105 		return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameFootnote));
106 }
107 
108 sal_Bool SAL_CALL SwAccessibleFootnote::supportsService(
109 		const ::rtl::OUString& sTestServiceName)
110     throw (uno::RuntimeException)
111 {
112 	if( sTestServiceName.equalsAsciiL( sAccessibleServiceName,
113 									   sizeof(sAccessibleServiceName)-1 ) )
114 		return sal_True;
115 	else if( AccessibleRole::END_NOTE == GetRole() )
116 		return sTestServiceName.equalsAsciiL( sServiceNameEndnote, sizeof(sServiceNameEndnote)-1 );
117 	else
118 		return sTestServiceName.equalsAsciiL( sServiceNameFootnote, sizeof(sServiceNameFootnote)-1 );
119 
120 }
121 
122 Sequence< OUString > SAL_CALL SwAccessibleFootnote::getSupportedServiceNames()
123         throw( uno::RuntimeException )
124 {
125 	Sequence< OUString > aRet(2);
126 	OUString* pArray = aRet.getArray();
127 	if( AccessibleRole::END_NOTE == GetRole() )
128 		pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameEndnote) );
129 	else
130 		pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameFootnote) );
131 	pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
132 	return aRet;
133 }
134 
135 Sequence< sal_Int8 > SAL_CALL SwAccessibleFootnote::getImplementationId()
136 		throw(RuntimeException)
137 {
138     vos::OGuard aGuard(Application::GetSolarMutex());
139     static Sequence< sal_Int8 > aId( 16 );
140     static sal_Bool bInit = sal_False;
141     if(!bInit)
142     {
143         rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
144         bInit = sal_True;
145     }
146     return aId;
147 }
148 
149 sal_Bool SwAccessibleFootnote::IsEndnote( const SwFtnFrm *pFtnFrm )
150 {
151 	const SwTxtFtn *pTxtFtn = pFtnFrm ->GetAttr();
152 	return pTxtFtn && pTxtFtn->GetFtn().IsEndNote() ;
153 }
154