1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: accframebase.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 #include <unotools/accessiblestatesethelper.hxx>
38 #include <vos/mutex.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/window.hxx>
42 #include <ndnotxt.hxx>
45 #include <fmtcntnt.hxx>
46 #include <ndindex.hxx>
50 #include "accframebase.hxx"
52 using namespace ::com::sun::star
;
53 using namespace ::com::sun::star::accessibility
;
54 using ::rtl::OUString
;
56 sal_Bool
SwAccessibleFrameBase::IsSelected()
58 sal_Bool bRet
= sal_False
;
60 DBG_ASSERT( GetMap(), "no map?" );
61 const ViewShell
*pVSh
= GetMap()->GetShell();
62 DBG_ASSERT( pVSh
, "no shell?" );
63 if( pVSh
->ISA( SwFEShell
) )
65 const SwFEShell
*pFESh
= static_cast< const SwFEShell
* >( pVSh
);
66 const SwFrm
*pFlyFrm
= pFESh
->GetCurrFlyFrm();
67 if( pFlyFrm
== GetFrm() )
74 void SwAccessibleFrameBase::GetStates(
75 ::utl::AccessibleStateSetHelper
& rStateSet
)
77 SwAccessibleContext::GetStates( rStateSet
);
79 const ViewShell
*pVSh
= GetMap()->GetShell();
80 DBG_ASSERT( pVSh
, "no shell?" );
81 sal_Bool bSelectable
= pVSh
->ISA( SwFEShell
);
85 rStateSet
.AddState( AccessibleStateType::SELECTABLE
);
89 rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
91 // SELECTED and FOCUSED
94 rStateSet
.AddState( AccessibleStateType::SELECTED
);
95 ASSERT( bIsSelected
, "bSelected out of sync" );
96 ::vos::ORef
< SwAccessibleContext
> xThis( this );
97 GetMap()->SetCursorContext( xThis
);
99 Window
*pWin
= GetWindow();
100 if( pWin
&& pWin
->HasFocus() )
101 rStateSet
.AddState( AccessibleStateType::FOCUSED
);
106 sal_uInt8
SwAccessibleFrameBase::GetNodeType( const SwFlyFrm
*pFlyFrm
)
108 sal_uInt8 nType
= ND_TEXTNODE
;
109 if( pFlyFrm
->Lower() )
111 if( pFlyFrm
->Lower()->IsNoTxtFrm() )
113 const SwCntntFrm
*pCntFrm
=
114 static_cast<const SwCntntFrm
*>( pFlyFrm
->Lower() );
115 nType
= pCntFrm
->GetNode()->GetNodeType();
120 const SwFrmFmt
*pFrmFmt
= pFlyFrm
->GetFmt();
121 const SwFmtCntnt
& rCntnt
= pFrmFmt
->GetCntnt();
122 const SwNodeIndex
*pNdIdx
= rCntnt
.GetCntntIdx();
125 const SwCntntNode
*pCNd
=
126 (pNdIdx
->GetNodes())[pNdIdx
->GetIndex()+1]->GetCntntNode();
128 nType
= pCNd
->GetNodeType();
135 SwAccessibleFrameBase::SwAccessibleFrameBase(
136 SwAccessibleMap
* pInitMap
,
138 const SwFlyFrm
* pFlyFrm
) :
139 SwAccessibleContext( pInitMap
, nInitRole
, pFlyFrm
),
140 bIsSelected( sal_False
)
142 vos::OGuard
aGuard(Application::GetSolarMutex());
144 const SwFrmFmt
*pFrmFmt
= pFlyFrm
->GetFmt();
145 const_cast< SwFrmFmt
* >( pFrmFmt
)->Add( this );
147 SetName( pFrmFmt
->GetName() );
149 bIsSelected
= IsSelected();
152 void SwAccessibleFrameBase::_InvalidateCursorPos()
154 sal_Bool bNewSelected
= IsSelected();
155 sal_Bool bOldSelected
;
158 vos::OGuard
aGuard( aMutex
);
159 bOldSelected
= bIsSelected
;
160 bIsSelected
= bNewSelected
;
165 // remember that object as the one that has the caret. This is
166 // neccessary to notify that object if the cursor leaves it.
167 ::vos::ORef
< SwAccessibleContext
> xThis( this );
168 GetMap()->SetCursorContext( xThis
);
171 if( bOldSelected
!= bNewSelected
)
173 Window
*pWin
= GetWindow();
174 if( pWin
&& pWin
->HasFocus() && bNewSelected
)
175 FireStateChangedEvent( AccessibleStateType::FOCUSED
, bNewSelected
);
176 FireStateChangedEvent( AccessibleStateType::SELECTED
, bNewSelected
);
177 if( pWin
&& pWin
->HasFocus() && !bNewSelected
)
178 FireStateChangedEvent( AccessibleStateType::FOCUSED
, bNewSelected
);
180 uno::Reference
< XAccessible
> xParent( GetWeakParent() );
183 SwAccessibleContext
*pAcc
=
184 static_cast <SwAccessibleContext
*>( xParent
.get() );
186 AccessibleEventObject aEvent
;
187 aEvent
.EventId
= AccessibleEventId::SELECTION_CHANGED
;
188 pAcc
->FireAccessibleEvent( aEvent
);
193 void SwAccessibleFrameBase::_InvalidateFocus()
195 Window
*pWin
= GetWindow();
201 vos::OGuard
aGuard( aMutex
);
202 bSelected
= bIsSelected
;
204 ASSERT( bSelected
, "focus object should be selected" );
206 FireStateChangedEvent( AccessibleStateType::FOCUSED
,
207 pWin
->HasFocus() && bSelected
);
211 sal_Bool
SwAccessibleFrameBase::HasCursor()
213 vos::OGuard
aGuard( aMutex
);
218 SwAccessibleFrameBase::~SwAccessibleFrameBase()
222 void SwAccessibleFrameBase::Modify( SfxPoolItem
*pOld
, SfxPoolItem
*pNew
)
224 sal_uInt16 nWhich
= pOld
? pOld
->Which() : pNew
? pNew
->Which() : 0 ;
225 const SwFlyFrm
*pFlyFrm
= static_cast< const SwFlyFrm
* >( GetFrm() );
228 case RES_NAME_CHANGED
:
231 const SwFrmFmt
*pFrmFmt
= pFlyFrm
->GetFmt();
232 ASSERT( pFrmFmt
== GetRegisteredIn(), "invalid frame" );
234 OUString
sOldName( GetName() );
236 static_cast < SwStringMsgPoolItem
* >( pOld
)->GetString() == String( sOldName
),
237 "invalid old name" );
239 const String
& rNewName
= pFrmFmt
->GetName();
242 static_cast < SwStringMsgPoolItem
* >( pNew
)->GetString() == rNewName
,
243 "invalid new name" );
245 if( sOldName
!= GetName() )
247 AccessibleEventObject aEvent
;
248 aEvent
.EventId
= AccessibleEventId::NAME_CHANGED
;
249 aEvent
.OldValue
<<= sOldName
;
250 aEvent
.NewValue
<<= GetName();
251 FireAccessibleEvent( aEvent
);
255 case RES_OBJECTDYING
:
256 if( GetRegisteredIn() ==
257 static_cast< SwModify
*>( static_cast< SwPtrMsgPoolItem
* >( pOld
)->pObject
) )
258 pRegisteredIn
->Remove( this );
262 if( static_cast< SwFmtChg
* >(pNew
)->pChangedFmt
== GetRegisteredIn() &&
263 static_cast< SwFmtChg
* >(pOld
)->pChangedFmt
->IsFmtInDTOR() )
264 pRegisteredIn
->Remove( this );
267 SwClient::Modify( pOld
, pNew
);
272 void SwAccessibleFrameBase::Dispose( sal_Bool bRecursive
)
274 vos::OGuard
aGuard(Application::GetSolarMutex());
276 if( GetRegisteredIn() )
277 pRegisteredIn
->Remove( this );
279 SwAccessibleContext::Dispose( bRecursive
);