xref: /trunk/main/sw/source/core/access/accfootnote.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
87     vos::OGuard aGuard(Application::GetSolarMutex());
88 
89     CHECK_FOR_DEFUNC( XAccessibleContext )
90 
91     sal_uInt16 nResId = AccessibleRole::END_NOTE == GetRole()
92         ? STR_ACCESS_ENDNOTE_DESC
93         : STR_ACCESS_FOOTNOTE_DESC ;
94 
95     OUString sArg;
96     const SwTxtFtn *pTxtFtn =
97         static_cast< const SwFtnFrm *>( GetFrm() )->GetAttr();
98     if( pTxtFtn )
99     {
100         const SwDoc *pDoc = GetMap()->GetShell()->GetDoc();
101         sArg = pTxtFtn->GetFtn().GetViewNumStr( *pDoc );
102     }
103 
104     return GetResource( nResId, &sArg );
105 }
106 
getImplementationName()107 OUString SAL_CALL SwAccessibleFootnote::getImplementationName()
108 {
109     if( AccessibleRole::END_NOTE == GetRole() )
110         return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameEndnote));
111     else
112         return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameFootnote));
113 }
114 
supportsService(const::rtl::OUString & sTestServiceName)115 sal_Bool SAL_CALL SwAccessibleFootnote::supportsService(
116         const ::rtl::OUString& sTestServiceName)
117 {
118     if( sTestServiceName.equalsAsciiL( sAccessibleServiceName,
119                                        sizeof(sAccessibleServiceName)-1 ) )
120         return sal_True;
121     else if( AccessibleRole::END_NOTE == GetRole() )
122         return sTestServiceName.equalsAsciiL( sServiceNameEndnote, sizeof(sServiceNameEndnote)-1 );
123     else
124         return sTestServiceName.equalsAsciiL( sServiceNameFootnote, sizeof(sServiceNameFootnote)-1 );
125 
126 }
127 
getSupportedServiceNames()128 Sequence< OUString > SAL_CALL SwAccessibleFootnote::getSupportedServiceNames()
129 {
130     Sequence< OUString > aRet(2);
131     OUString* pArray = aRet.getArray();
132     if( AccessibleRole::END_NOTE == GetRole() )
133         pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameEndnote) );
134     else
135         pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameFootnote) );
136     pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
137     return aRet;
138 }
139 
getImplementationId()140 Sequence< sal_Int8 > SAL_CALL SwAccessibleFootnote::getImplementationId()
141 {
142     vos::OGuard aGuard(Application::GetSolarMutex());
143     static Sequence< sal_Int8 > aId( 16 );
144     static sal_Bool bInit = sal_False;
145     if(!bInit)
146     {
147         rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True );
148         bInit = sal_True;
149     }
150     return aId;
151 }
152 
IsEndnote(const SwFtnFrm * pFtnFrm)153 sal_Bool SwAccessibleFootnote::IsEndnote( const SwFtnFrm *pFtnFrm )
154 {
155     const SwTxtFtn *pTxtFtn = pFtnFrm ->GetAttr();
156     return pTxtFtn && pTxtFtn->GetFtn().IsEndNote() ;
157 }
158