Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
22 : #include <comphelper/servicehelper.hxx>
23 : #include <osl/mutex.hxx>
24 : #include <vcl/svapp.hxx>
25 : #include <com/sun/star/accessibility/AccessibleRole.hpp>
26 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
27 : #include <com/sun/star/accessibility/AccessibleRelation.hpp>
28 : #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
29 : #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp>
30 : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31 : #include <unotools/accessiblestatesethelper.hxx>
32 : #include <frmfmt.hxx>
33 : #include <flyfrm.hxx>
34 : #include <accmap.hxx>
35 : #include <unotools/accessiblerelationsethelper.hxx>
36 : #include <hints.hxx> // #i73249#
37 : #include "acctextframe.hxx"
38 :
39 : using namespace ::com::sun::star;
40 : using namespace ::com::sun::star::accessibility;
41 :
42 : using utl::AccessibleRelationSetHelper;
43 : using ::com::sun::star::accessibility::XAccessibleContext;
44 :
45 : const sal_Char sServiceName[] = "com.sun.star.text.AccessibleTextFrameView";
46 : const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleTextFrameView";
47 :
48 0 : SwAccessibleTextFrame::SwAccessibleTextFrame(
49 : SwAccessibleMap* pInitMap,
50 : const SwFlyFrm* pFlyFrm ) :
51 : SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, pFlyFrm ),
52 : msTitle(),
53 0 : msDesc()
54 : {
55 0 : if ( pFlyFrm )
56 : {
57 : const SwFlyFrmFmt* pFlyFrmFmt =
58 0 : dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
59 0 : msTitle = pFlyFrmFmt->GetObjTitle();
60 :
61 0 : msDesc = pFlyFrmFmt->GetObjDescription();
62 0 : if ( msDesc.isEmpty() &&
63 0 : msTitle != GetName() )
64 : {
65 0 : msDesc = msTitle;
66 : }
67 : }
68 0 : }
69 :
70 0 : SwAccessibleTextFrame::~SwAccessibleTextFrame()
71 : {
72 0 : }
73 :
74 0 : void SwAccessibleTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
75 : {
76 0 : const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
77 : // #i73249# - suppress handling of RES_NAME_CHANGED
78 : // in case that attribute Title is used as the accessible name.
79 0 : if ( nWhich != RES_NAME_CHANGED ||
80 0 : msTitle.isEmpty() )
81 : {
82 0 : SwAccessibleFrameBase::Modify( pOld, pNew );
83 : }
84 :
85 0 : const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() );
86 0 : switch( nWhich )
87 : {
88 : // #i73249#
89 : case RES_TITLE_CHANGED:
90 : {
91 : const String& sOldTitle(
92 0 : dynamic_cast<const SwStringMsgPoolItem*>(pOld)->GetString() );
93 : const String& sNewTitle(
94 0 : dynamic_cast<const SwStringMsgPoolItem*>(pNew)->GetString() );
95 0 : if ( sOldTitle == sNewTitle )
96 : {
97 0 : break;
98 : }
99 0 : msTitle = sNewTitle;
100 0 : AccessibleEventObject aEvent;
101 0 : aEvent.EventId = AccessibleEventId::NAME_CHANGED;
102 0 : aEvent.OldValue <<= OUString( sOldTitle );
103 0 : aEvent.NewValue <<= msTitle;
104 0 : FireAccessibleEvent( aEvent );
105 :
106 : const SwFlyFrmFmt* pFlyFrmFmt =
107 0 : dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
108 0 : if ( pFlyFrmFmt->GetObjDescription().Len() != 0 )
109 : {
110 0 : break;
111 0 : }
112 : }
113 : // intentionally no break here
114 : case RES_DESCRIPTION_CHANGED:
115 : {
116 0 : if ( pFlyFrm )
117 : {
118 0 : const OUString sOldDesc( msDesc );
119 :
120 : const SwFlyFrmFmt* pFlyFrmFmt =
121 0 : dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() );
122 0 : const String& rDesc = pFlyFrmFmt->GetObjDescription();
123 0 : msDesc = rDesc;
124 0 : if ( msDesc.isEmpty() &&
125 0 : msTitle != GetName() )
126 : {
127 0 : msDesc = msTitle;
128 : }
129 :
130 0 : if ( msDesc != sOldDesc )
131 : {
132 0 : AccessibleEventObject aEvent;
133 0 : aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED;
134 0 : aEvent.OldValue <<= sOldDesc;
135 0 : aEvent.NewValue <<= msDesc;
136 0 : FireAccessibleEvent( aEvent );
137 0 : }
138 : }
139 : }
140 0 : break;
141 : }
142 0 : }
143 :
144 : // #i73249#
145 0 : OUString SAL_CALL SwAccessibleTextFrame::getAccessibleName (void)
146 : throw (uno::RuntimeException)
147 : {
148 0 : SolarMutexGuard aGuard;
149 :
150 0 : CHECK_FOR_DEFUNC( XAccessibleContext )
151 :
152 0 : if ( !msTitle.isEmpty() )
153 : {
154 0 : return msTitle;
155 : }
156 :
157 0 : return SwAccessibleFrameBase::getAccessibleName();
158 : }
159 0 : OUString SAL_CALL SwAccessibleTextFrame::getAccessibleDescription (void)
160 : throw (uno::RuntimeException)
161 : {
162 0 : SolarMutexGuard aGuard;
163 :
164 0 : CHECK_FOR_DEFUNC( XAccessibleContext )
165 :
166 0 : return msDesc;
167 :
168 : }
169 :
170 0 : OUString SAL_CALL SwAccessibleTextFrame::getImplementationName()
171 : throw( uno::RuntimeException )
172 : {
173 0 : return OUString(sImplementationName);
174 : }
175 :
176 0 : sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService(
177 : const OUString& sTestServiceName)
178 : throw (uno::RuntimeException)
179 : {
180 : return sTestServiceName.equalsAsciiL( sServiceName,
181 0 : sizeof(sServiceName)-1 ) ||
182 : sTestServiceName.equalsAsciiL( sAccessibleServiceName,
183 0 : sizeof(sAccessibleServiceName)-1 );
184 : }
185 :
186 0 : uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames()
187 : throw( uno::RuntimeException )
188 : {
189 0 : uno::Sequence< OUString > aRet(2);
190 0 : OUString* pArray = aRet.getArray();
191 0 : pArray[0] = OUString( sServiceName );
192 0 : pArray[1] = OUString( sAccessibleServiceName );
193 0 : return aRet;
194 : }
195 :
196 : namespace
197 : {
198 : class theSwAccessibleTextFrameImplementationId : public rtl::Static< UnoTunnelIdInit, theSwAccessibleTextFrameImplementationId > {};
199 : }
200 :
201 0 : uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId()
202 : throw(uno::RuntimeException)
203 : {
204 0 : return theSwAccessibleTextFrameImplementationId::get().getSeq();
205 : }
206 :
207 :
208 : // XAccessibleRelationSet
209 0 : SwFlyFrm* SwAccessibleTextFrame::getFlyFrm() const
210 : {
211 0 : SwFlyFrm* pFlyFrm = NULL;
212 :
213 0 : const SwFrm* pFrm = GetFrm();
214 : OSL_ENSURE( pFrm != NULL, "frame expected" );
215 0 : if( pFrm->IsFlyFrm() )
216 : {
217 0 : pFlyFrm = static_cast<SwFlyFrm*>( const_cast<SwFrm*>( pFrm ) );
218 : }
219 :
220 0 : return pFlyFrm;
221 : }
222 :
223 0 : AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrm* pFrm )
224 : {
225 0 : uno::Sequence<uno::Reference<XInterface> > aSequence(1);
226 0 : aSequence[0] = GetMap()->GetContext( pFrm );
227 0 : return AccessibleRelation( nType, aSequence );
228 : }
229 :
230 :
231 0 : uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( )
232 : throw ( uno::RuntimeException )
233 : {
234 0 : SolarMutexGuard aGuard;
235 0 : CHECK_FOR_DEFUNC( XAccessibleContext );
236 :
237 : // get the frame, and insert prev/next relations into helper
238 :
239 0 : AccessibleRelationSetHelper* pHelper = new AccessibleRelationSetHelper();
240 :
241 0 : SwFlyFrm* pFlyFrm = getFlyFrm();
242 : OSL_ENSURE( pFlyFrm != NULL, "fly frame expected" );
243 :
244 0 : const SwFlyFrm* pPrevFrm = pFlyFrm->GetPrevLink();
245 0 : if( pPrevFrm != NULL )
246 : pHelper->AddRelation( makeRelation(
247 0 : AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrm ) );
248 :
249 0 : const SwFlyFrm* pNextFrm = pFlyFrm->GetNextLink();
250 0 : if( pNextFrm != NULL )
251 : pHelper->AddRelation( makeRelation(
252 0 : AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrm ) );
253 :
254 0 : return pHelper;
255 99 : }
256 :
257 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|