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
SwAccessibleFootnote(SwAccessibleMap * pInitMap,sal_Bool bIsEndnote,const SwFtnFrm * pFtnFrm)55 SwAccessibleFootnote::SwAccessibleFootnote(
56 SwAccessibleMap* pInitMap,
57 sal_Bool bIsEndnote,
58 const SwFtnFrm *pFtnFrm ) :
59 SwAccessibleContext( pInitMap,
60 bIsEndnote ? AccessibleRole::END_NOTE : AccessibleRole::FOOTNOTE,
61 pFtnFrm )
62 {
63 vos::OGuard aGuard(Application::GetSolarMutex());
64
65 sal_uInt16 nResId = bIsEndnote ? STR_ACCESS_ENDNOTE_NAME
66 : STR_ACCESS_FOOTNOTE_NAME;
67 //OUString sArg( OUString::valueOf( nFootEndNote ) );
68 //old codes end
69 OUString sArg;
70 const SwTxtFtn *pTxtFtn =
71 static_cast< const SwFtnFrm *>( GetFrm() )->GetAttr();
72 if( pTxtFtn )
73 {
74 const SwDoc *pDoc = GetShell()->GetDoc();
75 sArg = pTxtFtn->GetFtn().GetViewNumStr( *pDoc );
76 }
77
78 SetName( GetResource( nResId, &sArg ) );
79 }
80
~SwAccessibleFootnote()81 SwAccessibleFootnote::~SwAccessibleFootnote()
82 {
83 }
84
getAccessibleDescription(void)85 OUString SAL_CALL SwAccessibleFootnote::getAccessibleDescription (void)
86 throw (uno::RuntimeException)
87 {
88 vos::OGuard aGuard(Application::GetSolarMutex());
89
90 CHECK_FOR_DEFUNC( XAccessibleContext )
91
92 sal_uInt16 nResId = AccessibleRole::END_NOTE == GetRole()
93 ? STR_ACCESS_ENDNOTE_DESC
94 : STR_ACCESS_FOOTNOTE_DESC ;
95
96 OUString sArg;
97 const SwTxtFtn *pTxtFtn =
98 static_cast< const SwFtnFrm *>( GetFrm() )->GetAttr();
99 if( pTxtFtn )
100 {
101 const SwDoc *pDoc = GetMap()->GetShell()->GetDoc();
102 sArg = pTxtFtn->GetFtn().GetViewNumStr( *pDoc );
103 }
104
105 return GetResource( nResId, &sArg );
106 }
107
getImplementationName()108 OUString SAL_CALL SwAccessibleFootnote::getImplementationName()
109 throw( RuntimeException )
110 {
111 if( AccessibleRole::END_NOTE == GetRole() )
112 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameEndnote));
113 else
114 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameFootnote));
115 }
116
supportsService(const::rtl::OUString & sTestServiceName)117 sal_Bool SAL_CALL SwAccessibleFootnote::supportsService(
118 const ::rtl::OUString& sTestServiceName)
119 throw (uno::RuntimeException)
120 {
121 if( sTestServiceName.equalsAsciiL( sAccessibleServiceName,
122 sizeof(sAccessibleServiceName)-1 ) )
123 return sal_True;
124 else if( AccessibleRole::END_NOTE == GetRole() )
125 return sTestServiceName.equalsAsciiL( sServiceNameEndnote, sizeof(sServiceNameEndnote)-1 );
126 else
127 return sTestServiceName.equalsAsciiL( sServiceNameFootnote, sizeof(sServiceNameFootnote)-1 );
128
129 }
130
getSupportedServiceNames()131 Sequence< OUString > SAL_CALL SwAccessibleFootnote::getSupportedServiceNames()
132 throw( uno::RuntimeException )
133 {
134 Sequence< OUString > aRet(2);
135 OUString* pArray = aRet.getArray();
136 if( AccessibleRole::END_NOTE == GetRole() )
137 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameEndnote) );
138 else
139 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameFootnote) );
140 pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
141 return aRet;
142 }
143
getImplementationId()144 Sequence< sal_Int8 > SAL_CALL SwAccessibleFootnote::getImplementationId()
145 throw(RuntimeException)
146 {
147 vos::OGuard aGuard(Application::GetSolarMutex());
148 static Sequence< sal_Int8 > aId( 16 );
149 static sal_Bool bInit = sal_False;
150 if(!bInit)
151 {
152 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
153 bInit = sal_True;
154 }
155 return aId;
156 }
157
IsEndnote(const SwFtnFrm * pFtnFrm)158 sal_Bool SwAccessibleFootnote::IsEndnote( const SwFtnFrm *pFtnFrm )
159 {
160 const SwTxtFtn *pTxtFtn = pFtnFrm ->GetAttr();
161 return pTxtFtn && pTxtFtn->GetFtn().IsEndNote() ;
162 }
163