Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
30 : : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31 : : #include <unotools/accessiblestatesethelper.hxx>
32 : : #include <osl/mutex.hxx>
33 : : #include <vcl/svapp.hxx>
34 : : #include <vcl/window.hxx>
35 : : #include <frmfmt.hxx>
36 : : #include <ndnotxt.hxx>
37 : : #include <flyfrm.hxx>
38 : : #include <cntfrm.hxx>
39 : : #include <fmtcntnt.hxx>
40 : : #include <ndindex.hxx>
41 : : #include "fesh.hxx"
42 : : #include <hints.hxx>
43 : : #include "accmap.hxx"
44 : : #include "accframebase.hxx"
45 : :
46 : : using namespace ::com::sun::star;
47 : : using namespace ::com::sun::star::accessibility;
48 : : using ::rtl::OUString;
49 : :
50 : 6 : sal_Bool SwAccessibleFrameBase::IsSelected()
51 : : {
52 : 6 : sal_Bool bRet = sal_False;
53 : :
54 : : OSL_ENSURE( GetMap(), "no map?" );
55 : 6 : const ViewShell *pVSh = GetMap()->GetShell();
56 : : OSL_ENSURE( pVSh, "no shell?" );
57 [ + - ]: 6 : if( pVSh->ISA( SwFEShell ) )
58 : : {
59 : 6 : const SwFEShell *pFESh = static_cast< const SwFEShell * >( pVSh );
60 : 6 : const SwFrm *pFlyFrm = pFESh->GetCurrFlyFrm();
61 [ - + ]: 6 : if( pFlyFrm == GetFrm() )
62 : 0 : bRet = sal_True;
63 : : }
64 : :
65 : 6 : return bRet;
66 : : }
67 : :
68 : 4 : void SwAccessibleFrameBase::GetStates(
69 : : ::utl::AccessibleStateSetHelper& rStateSet )
70 : : {
71 : 4 : SwAccessibleContext::GetStates( rStateSet );
72 : :
73 : 4 : const ViewShell *pVSh = GetMap()->GetShell();
74 : : OSL_ENSURE( pVSh, "no shell?" );
75 : 4 : sal_Bool bSelectable = pVSh->ISA( SwFEShell );
76 : :
77 : : // SELECTABLE
78 [ + - ]: 4 : if( bSelectable )
79 : 4 : rStateSet.AddState( AccessibleStateType::SELECTABLE );
80 : :
81 : : // FOCUSABLE
82 [ + - ]: 4 : if( bSelectable )
83 : 4 : rStateSet.AddState( AccessibleStateType::FOCUSABLE );
84 : :
85 : : // SELECTED and FOCUSED
86 [ - + ]: 4 : if( IsSelected() )
87 : : {
88 [ # # ]: 0 : rStateSet.AddState( AccessibleStateType::SELECTED );
89 : : OSL_ENSURE( bIsSelected, "bSelected out of sync" );
90 : 0 : ::rtl::Reference < SwAccessibleContext > xThis( this );
91 [ # # ]: 0 : GetMap()->SetCursorContext( xThis );
92 : :
93 [ # # ]: 0 : Window *pWin = GetWindow();
94 [ # # ][ # # ]: 0 : if( pWin && pWin->HasFocus() )
[ # # ][ # # ]
95 [ # # ]: 0 : rStateSet.AddState( AccessibleStateType::FOCUSED );
96 : : }
97 : 4 : }
98 : :
99 : :
100 : 2 : sal_uInt8 SwAccessibleFrameBase::GetNodeType( const SwFlyFrm *pFlyFrm )
101 : : {
102 : 2 : sal_uInt8 nType = ND_TEXTNODE;
103 [ + - ]: 2 : if( pFlyFrm->Lower() )
104 : : {
105 [ + - ]: 2 : if( pFlyFrm->Lower()->IsNoTxtFrm() )
106 : : {
107 : : const SwCntntFrm *pCntFrm =
108 : 2 : static_cast<const SwCntntFrm *>( pFlyFrm->Lower() );
109 : 2 : nType = pCntFrm->GetNode()->GetNodeType();
110 : : }
111 : : }
112 : : else
113 : : {
114 : 0 : const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
115 : 0 : const SwFmtCntnt& rCntnt = pFrmFmt->GetCntnt();
116 : 0 : const SwNodeIndex *pNdIdx = rCntnt.GetCntntIdx();
117 [ # # ]: 0 : if( pNdIdx )
118 : : {
119 : : const SwCntntNode *pCNd =
120 : 0 : (pNdIdx->GetNodes())[pNdIdx->GetIndex()+1]->GetCntntNode();
121 [ # # ]: 0 : if( pCNd )
122 : 0 : nType = pCNd->GetNodeType();
123 : : }
124 : : }
125 : :
126 : 2 : return nType;
127 : : }
128 : :
129 : 2 : SwAccessibleFrameBase::SwAccessibleFrameBase(
130 : : SwAccessibleMap* pInitMap,
131 : : sal_Int16 nInitRole,
132 : : const SwFlyFrm* pFlyFrm ) :
133 : : SwAccessibleContext( pInitMap, nInitRole, pFlyFrm ),
134 : 2 : bIsSelected( sal_False )
135 : : {
136 [ + - ]: 2 : SolarMutexGuard aGuard;
137 : :
138 [ + - ]: 2 : const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
139 [ + - ]: 2 : const_cast< SwFrmFmt * >( pFrmFmt )->Add( this );
140 : :
141 [ + - ]: 2 : SetName( pFrmFmt->GetName() );
142 : :
143 [ + - ][ + - ]: 2 : bIsSelected = IsSelected();
144 : 2 : }
145 : :
146 : 0 : void SwAccessibleFrameBase::_InvalidateCursorPos()
147 : : {
148 : 0 : sal_Bool bNewSelected = IsSelected();
149 : : sal_Bool bOldSelected;
150 : :
151 : : {
152 [ # # ]: 0 : osl::MutexGuard aGuard( aMutex );
153 : 0 : bOldSelected = bIsSelected;
154 [ # # ]: 0 : bIsSelected = bNewSelected;
155 : : }
156 : :
157 [ # # ]: 0 : if( bNewSelected )
158 : : {
159 : : // remember that object as the one that has the caret. This is
160 : : // neccessary to notify that object if the cursor leaves it.
161 : 0 : ::rtl::Reference < SwAccessibleContext > xThis( this );
162 [ # # ]: 0 : GetMap()->SetCursorContext( xThis );
163 : : }
164 : :
165 [ # # ]: 0 : if( bOldSelected != bNewSelected )
166 : : {
167 [ # # ]: 0 : Window *pWin = GetWindow();
168 [ # # ][ # # ]: 0 : if( pWin && pWin->HasFocus() && bNewSelected )
[ # # ][ # # ]
[ # # ]
169 [ # # ]: 0 : FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
170 [ # # ]: 0 : FireStateChangedEvent( AccessibleStateType::SELECTED, bNewSelected );
171 [ # # ][ # # ]: 0 : if( pWin && pWin->HasFocus() && !bNewSelected )
[ # # ][ # # ]
[ # # ]
172 [ # # ]: 0 : FireStateChangedEvent( AccessibleStateType::FOCUSED, bNewSelected );
173 : :
174 [ # # ]: 0 : uno::Reference< XAccessible > xParent( GetWeakParent() );
175 [ # # ]: 0 : if( xParent.is() )
176 : : {
177 : : SwAccessibleContext *pAcc =
178 [ # # ][ # # ]: 0 : static_cast <SwAccessibleContext *>( xParent.get() );
179 : :
180 [ # # ]: 0 : AccessibleEventObject aEvent;
181 : 0 : aEvent.EventId = AccessibleEventId::SELECTION_CHANGED;
182 [ # # ][ # # ]: 0 : pAcc->FireAccessibleEvent( aEvent );
183 : 0 : }
184 : : }
185 : 0 : }
186 : :
187 : 0 : void SwAccessibleFrameBase::_InvalidateFocus()
188 : : {
189 : 0 : Window *pWin = GetWindow();
190 [ # # ]: 0 : if( pWin )
191 : : {
192 : : sal_Bool bSelected;
193 : :
194 : : {
195 [ # # ]: 0 : osl::MutexGuard aGuard( aMutex );
196 [ # # ]: 0 : bSelected = bIsSelected;
197 : : }
198 : : OSL_ENSURE( bSelected, "focus object should be selected" );
199 : :
200 : : FireStateChangedEvent( AccessibleStateType::FOCUSED,
201 [ # # ][ # # ]: 0 : pWin->HasFocus() && bSelected );
202 : : }
203 : 0 : }
204 : :
205 : 2 : sal_Bool SwAccessibleFrameBase::HasCursor()
206 : : {
207 [ + - ]: 2 : osl::MutexGuard aGuard( aMutex );
208 [ + - ]: 2 : return bIsSelected;
209 : : }
210 : :
211 : :
212 [ + - ]: 2 : SwAccessibleFrameBase::~SwAccessibleFrameBase()
213 : : {
214 [ - + ]: 2 : }
215 : :
216 : 0 : void SwAccessibleFrameBase::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew)
217 : : {
218 [ # # ][ # # ]: 0 : sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ;
219 : 0 : const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() );
220 [ # # # # ]: 0 : switch( nWhich )
221 : : {
222 : : case RES_NAME_CHANGED:
223 [ # # ]: 0 : if( pFlyFrm )
224 : : {
225 [ # # ]: 0 : const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
226 : : OSL_ENSURE( pFrmFmt == GetRegisteredIn(), "invalid frame" );
227 : :
228 : 0 : OUString sOldName( GetName() );
229 : : OSL_ENSURE( !pOld ||
230 : : static_cast < const SwStringMsgPoolItem * >( pOld )->GetString() == String( sOldName ),
231 : : "invalid old name" );
232 : :
233 : 0 : const String& rNewName = pFrmFmt->GetName();
234 [ # # ]: 0 : SetName( rNewName );
235 : : OSL_ENSURE( !pNew ||
236 : : static_cast < const SwStringMsgPoolItem * >( pNew )->GetString() == rNewName,
237 : : "invalid new name" );
238 : :
239 [ # # ]: 0 : if( sOldName != GetName() )
240 : : {
241 [ # # ]: 0 : AccessibleEventObject aEvent;
242 : 0 : aEvent.EventId = AccessibleEventId::NAME_CHANGED;
243 [ # # ]: 0 : aEvent.OldValue <<= sOldName;
244 [ # # ]: 0 : aEvent.NewValue <<= GetName();
245 [ # # ][ # # ]: 0 : FireAccessibleEvent( aEvent );
246 : 0 : }
247 : : }
248 : 0 : break;
249 : : case RES_OBJECTDYING:
250 : : // mba: it seems that this class intentionally does not call code in base class SwClient
251 [ # # ]: 0 : if( GetRegisteredIn() ==
252 : : static_cast< SwModify *>( static_cast< const SwPtrMsgPoolItem * >( pOld )->pObject ) )
253 : 0 : GetRegisteredInNonConst()->Remove( this );
254 : 0 : break;
255 : :
256 : : case RES_FMT_CHG:
257 [ # # # # ]: 0 : if( static_cast< const SwFmtChg * >(pNew)->pChangedFmt == GetRegisteredIn() &&
[ # # ]
258 : 0 : static_cast< const SwFmtChg * >(pOld)->pChangedFmt->IsFmtInDTOR() )
259 : 0 : GetRegisteredInNonConst()->Remove( this );
260 : 0 : break;
261 : :
262 : : default:
263 : : // mba: former call to base class method removed as it is meant to handle only RES_OBJECTDYING
264 : 0 : break;
265 : : }
266 : 0 : }
267 : :
268 : 2 : void SwAccessibleFrameBase::Dispose( sal_Bool bRecursive )
269 : : {
270 [ + - ]: 2 : SolarMutexGuard aGuard;
271 : :
272 [ + - ]: 2 : if( GetRegisteredIn() )
273 [ + - ]: 2 : GetRegisteredInNonConst()->Remove( this );
274 : :
275 [ + - ][ + - ]: 2 : SwAccessibleContext::Dispose( bRecursive );
276 : 2 : }
277 : :
278 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|