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