Files
libreoffice/sw/source/core/access/accframebase.cxx
2002-04-05 11:08:57 +00:00

244 lines
6.8 KiB
C++

/*************************************************************************
*
* $RCSfile: accframebase.cxx,v $
*
* $Revision: 1.1 $
*
* last change: $Author: mib $ $Date: 2002-04-05 12:04:26 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifdef PRECOMPILED
#include "core_pch.hxx"
#endif
#pragma hdrstop
#ifndef _DRAFTS_COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
#include <drafts/com/sun/star/accessibility/AccessibleStateType.hpp>
#endif
#ifndef _DRAFTS_COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTID_HPP_
#include <drafts/com/sun/star/accessibility/AccessibleEventId.hpp>
#endif
#ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX_
#include <unotools/accessiblestatesethelper.hxx>
#endif
#ifndef _VOS_MUTEX_HXX_ //autogen
#include <vos/mutex.hxx>
#endif
#ifndef _SV_SVAPP_HXX //autogen
#include <vcl/svapp.hxx>
#endif
#ifndef _FRMFMT_HXX
#include <frmfmt.hxx>
#endif
#ifndef _NDNOTXT_HXX
#include <ndnotxt.hxx>
#endif
#ifndef _FLYFRM_HXX
#include <flyfrm.hxx>
#endif
#ifndef _CNTFRM_HXX
#include <cntfrm.hxx>
#endif
#ifndef _FMTCNTNT_HXX
#include <fmtcntnt.hxx>
#endif
#ifndef _NDINDEX_HXX
#include <ndindex.hxx>
#endif
#ifndef _FESH_HXX
#include "fesh.hxx"
#endif
#ifndef _ACCMAP_HXX
#include "accmap.hxx"
#endif
#ifndef _ACCFRAMEBASE_HXX
#include "accframebase.hxx"
#endif
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
using namespace ::drafts::com::sun::star::accessibility;
using namespace ::rtl;
sal_Bool SwAccessibleFrameBase::IsSelected()
{
sal_Bool bRet = sal_False;
DBG_ASSERT( GetMap(), "no map?" );
ViewShell *pVSh = GetMap()->GetShell();
DBG_ASSERT( pVSh, "no shell?" );
if( pVSh->ISA( SwFEShell ) )
{
SwFEShell *pFESh = static_cast< SwFEShell * >( pVSh );
const SwFrm *pFlyFrm = pFESh->GetCurrFlyFrm();
if( pFlyFrm == GetFrm() )
bRet = sal_True;
}
return bRet;
}
void SwAccessibleFrameBase::GetStates(
::utl::AccessibleStateSetHelper& rStateSet )
{
SwAccessibleContext::GetStates( rStateSet );
// SELECTABLE
rStateSet.AddState( AccessibleStateType::SELECTABLE );
// TODO: SELECTED
if( IsSelected() )
{
rStateSet.AddState( AccessibleStateType::SELECTED );
ASSERT( bIsSelected, "bSelected out of sync" );
::vos::ORef < SwAccessibleContext > xThis( this );
GetMap()->SetCursorContext( xThis );
}
}
sal_uInt8 SwAccessibleFrameBase::GetNodeType( const SwFlyFrm *pFlyFrm )
{
sal_uInt8 nType = ND_TEXTNODE;
if( pFlyFrm->Lower() )
{
if( pFlyFrm->Lower()->IsNoTxtFrm() )
{
const SwCntntFrm *pCntFrm =
static_cast<const SwCntntFrm *>( pFlyFrm->Lower() );
nType = pCntFrm->GetNode()->GetNodeType();
}
}
else
{
const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
const SwFmtCntnt& rCntnt = pFrmFmt->GetCntnt();
const SwNodeIndex *pNdIdx = rCntnt.GetCntntIdx();
if( pNdIdx )
{
const SwCntntNode *pCNd =
(pNdIdx->GetNodes())[pNdIdx->GetIndex()+1]->GetCntntNode();
if( pCNd )
nType = pCNd->GetNodeType();
}
}
return nType;
}
SwAccessibleFrameBase::SwAccessibleFrameBase(
SwAccessibleMap *pMap, sal_Int16 nRole,
const SwFlyFrm *pFlyFrm ) :
SwAccessibleContext( pMap, nRole, pFlyFrm ),
bIsSelected( sal_False )
{
vos::OGuard aGuard(Application::GetSolarMutex());
const SwFrmFmt *pFrmFmt = pFlyFrm->GetFmt();
SetName( pFrmFmt->GetName() );
bIsSelected = IsSelected();
}
void SwAccessibleFrameBase::_InvalidateCursorPos()
{
sal_Bool bNew = IsSelected();
sal_Bool bOld;
{
vos::OGuard aGuard( aMutex );
bOld = bIsSelected;
bIsSelected = bNew;
}
if( bNew )
{
// remember that object as the one that has the caret. This is
// neccessary to notify that object if the cursor leaves it.
::vos::ORef < SwAccessibleContext > xThis( this );
GetMap()->SetCursorContext( xThis );
}
if( bOld != bNew )
{
FireStateChangedEvent( AccessibleStateType::SELECTED, bNew );
Reference< XAccessible > xParent( GetWeakParent() );
if( xParent.is() )
{
SwAccessibleContext *pAcc = (SwAccessibleContext *)xParent.get();
AccessibleEventObject aEvent;
aEvent.EventId = AccessibleEventId::ACCESSIBLE_SELECTION_EVENT;
pAcc->FireAccessibleEvent( aEvent );
}
}
}
sal_Bool SwAccessibleFrameBase::HasCursor()
{
vos::OGuard aGuard( aMutex );
return bIsSelected;
}
SwAccessibleFrameBase::~SwAccessibleFrameBase()
{
}