xref: /trunk/main/sw/source/core/access/accfootnote.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1  /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <vos/mutex.hxx>
33 #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
35 #include <unotools/accessiblestatesethelper.hxx>
36 #include <rtl/uuid.h>
37 #include <vcl/svapp.hxx>
38 #include <ftnfrm.hxx>
39 #include <fmtftn.hxx>
40 #include <txtftn.hxx>
41 #include <viewsh.hxx>
42 #include <accmap.hxx>
43 #include "accfootnote.hxx"
44 #ifndef _ACCESS_HRC
45 #include "access.hrc"
46 #endif
47 
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::lang;
51 using namespace ::com::sun::star::accessibility;
52 using ::rtl::OUString;
53 
54 const sal_Char sServiceNameFootnote[] = "com.sun.star.text.AccessibleFootnoteView";
55 const sal_Char sServiceNameEndnote[] = "com.sun.star.text.AccessibleEndnoteView";
56 const sal_Char sImplementationNameFootnote[] = "com.sun.star.comp.Writer.SwAccessibleFootnoteView";
57 const sal_Char sImplementationNameEndnote[] = "com.sun.star.comp.Writer.SwAccessibleEndnoteView";
58 
59 SwAccessibleFootnote::SwAccessibleFootnote(
60         SwAccessibleMap* pInitMap,
61         sal_Bool bIsEndnote,
62         sal_Int32 nFootEndNote,
63         const SwFtnFrm *pFtnFrm ) :
64     SwAccessibleContext( pInitMap,
65         bIsEndnote ? AccessibleRole::END_NOTE : AccessibleRole::FOOTNOTE,
66         pFtnFrm )
67 {
68     vos::OGuard aGuard(Application::GetSolarMutex());
69 
70     sal_uInt16 nResId = bIsEndnote ? STR_ACCESS_ENDNOTE_NAME
71                                    : STR_ACCESS_FOOTNOTE_NAME;
72     OUString sArg( OUString::valueOf( nFootEndNote ) );
73     SetName( GetResource( nResId, &sArg ) );
74 }
75 
76 SwAccessibleFootnote::~SwAccessibleFootnote()
77 {
78 }
79 
80 OUString SAL_CALL SwAccessibleFootnote::getAccessibleDescription (void)
81         throw (uno::RuntimeException)
82 {
83     vos::OGuard aGuard(Application::GetSolarMutex());
84 
85     CHECK_FOR_DEFUNC( XAccessibleContext )
86 
87     sal_uInt16 nResId = AccessibleRole::END_NOTE == GetRole()
88         ? STR_ACCESS_ENDNOTE_DESC
89         : STR_ACCESS_FOOTNOTE_DESC ;
90 
91     OUString sArg;
92     const SwTxtFtn *pTxtFtn =
93         static_cast< const SwFtnFrm *>( GetFrm() )->GetAttr();
94     if( pTxtFtn )
95     {
96         const SwDoc *pDoc = GetMap()->GetShell()->GetDoc();
97         sArg = pTxtFtn->GetFtn().GetViewNumStr( *pDoc );
98     }
99 
100     return GetResource( nResId, &sArg );
101 }
102 
103 OUString SAL_CALL SwAccessibleFootnote::getImplementationName()
104         throw( RuntimeException )
105 {
106     if( AccessibleRole::END_NOTE == GetRole() )
107         return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameEndnote));
108     else
109         return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationNameFootnote));
110 }
111 
112 sal_Bool SAL_CALL SwAccessibleFootnote::supportsService(
113         const ::rtl::OUString& sTestServiceName)
114     throw (uno::RuntimeException)
115 {
116     if( sTestServiceName.equalsAsciiL( sAccessibleServiceName,
117                                        sizeof(sAccessibleServiceName)-1 ) )
118         return sal_True;
119     else if( AccessibleRole::END_NOTE == GetRole() )
120         return sTestServiceName.equalsAsciiL( sServiceNameEndnote, sizeof(sServiceNameEndnote)-1 );
121     else
122         return sTestServiceName.equalsAsciiL( sServiceNameFootnote, sizeof(sServiceNameFootnote)-1 );
123 
124 }
125 
126 Sequence< OUString > SAL_CALL SwAccessibleFootnote::getSupportedServiceNames()
127         throw( uno::RuntimeException )
128 {
129     Sequence< OUString > aRet(2);
130     OUString* pArray = aRet.getArray();
131     if( AccessibleRole::END_NOTE == GetRole() )
132         pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameEndnote) );
133     else
134         pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceNameFootnote) );
135     pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) );
136     return aRet;
137 }
138 
139 Sequence< sal_Int8 > SAL_CALL SwAccessibleFootnote::getImplementationId()
140         throw(RuntimeException)
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 
153 sal_Bool SwAccessibleFootnote::IsEndnote( const SwFtnFrm *pFtnFrm )
154 {
155     const SwTxtFtn *pTxtFtn = pFtnFrm ->GetAttr();
156     return pTxtFtn && pTxtFtn->GetFtn().IsEndNote() ;
157 }
158