Files
libreoffice/sw/source/core/access/accselectionhelper.cxx

370 lines
13 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/accessibility/XAccessibleSelection.hpp>
#include "accselectionhelper.hxx"
#include "acccontext.hxx"
#include <accmap.hxx>
2002-05-15 12:22:47 +00:00
#include <svx/AccessibleShape.hxx>
#include <viewsh.hxx>
#include <fesh.hxx>
#include <vcl/svapp.hxx>
#include <flyfrm.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
#include <fmtanchr.hxx>
using namespace ::com::sun::star::accessibility;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using ::com::sun::star::accessibility::XAccessible;
using ::com::sun::star::accessibility::XAccessibleContext;
using ::com::sun::star::accessibility::XAccessibleSelection;
using namespace ::sw::access;
SwAccessibleSelectionHelper::SwAccessibleSelectionHelper(
SwAccessibleContext& rContext ) :
m_rContext( rContext )
{
}
SwAccessibleSelectionHelper::~SwAccessibleSelectionHelper()
{
}
SwFEShell* SwAccessibleSelectionHelper::GetFEShell()
{
OSL_ENSURE( m_rContext.GetMap() != nullptr, "no map?" );
SwViewShell* pViewShell = m_rContext.GetMap()->GetShell();
OSL_ENSURE( pViewShell != nullptr,
"No view shell? Then what are you looking at?" );
SwFEShell* pFEShell = dynamic_cast<SwFEShell*>( pViewShell );
return pFEShell;
}
void SwAccessibleSelectionHelper::throwIndexOutOfBoundsException()
{
Reference < XAccessibleContext > xThis( &m_rContext );
Reference < XAccessibleSelection >xSelThis( xThis, UNO_QUERY );
lang::IndexOutOfBoundsException aExcept(
"index out of bounds",
xSelThis );
throw aExcept;
}
// XAccessibleSelection
void SwAccessibleSelectionHelper::selectAccessibleChild(
sal_Int32 nChildIndex )
{
SolarMutexGuard aGuard;
// Get the respective child as SwFrame (also do index checking), ...
const SwAccessibleChild aChild = m_rContext.GetChild( *(m_rContext.GetMap()),
nChildIndex );
if( !aChild.IsValid() )
throwIndexOutOfBoundsException();
// we can only select fly frames, so we ignore (should: return
// false) all other attempts at child selection
SwFEShell* pFEShell = GetFEShell();
if( pFEShell != nullptr )
{
const SdrObject *pObj = aChild.GetDrawObject();
2002-05-15 12:22:47 +00:00
if( pObj )
m_rContext.Select( const_cast< SdrObject *>( pObj ), nullptr==aChild.GetSwFrame());
}
// no frame shell, or no frame, or no fly frame -> can't select
}
//When the selected state of the SwFrameOrObj is set, return true.
static bool lcl_getSelectedState(const SwAccessibleChild& aChild,
SwAccessibleContext* pContext,
SwAccessibleMap* pMap)
{
Reference< XAccessible > xAcc;
if ( aChild.GetSwFrame() )
{
xAcc = pMap->GetContext( aChild.GetSwFrame(), false );
}
else if ( aChild.GetDrawObject() )
{
xAcc = pMap->GetContext( aChild.GetDrawObject(), pContext, false );
}
if( xAcc.is() )
{
Reference< XAccessibleContext > pRContext = xAcc->getAccessibleContext();
if(!pRContext.is())
return false;
Reference<XAccessibleStateSet> pRStateSet = pRContext->getAccessibleStateSet();
if( pRStateSet.is() )
{
Sequence<short> aStates = pRStateSet->getStates();
sal_Int32 count = aStates.getLength();
for( sal_Int32 i = 0; i < count; i++ )
{
if( aStates[i] == AccessibleStateType::SELECTED)
return true;
}
}
}
return false;
}
bool SwAccessibleSelectionHelper::isAccessibleChildSelected(
sal_Int32 nChildIndex )
{
SolarMutexGuard aGuard;
// Get the respective child as SwFrame (also do index checking), ...
const SwAccessibleChild aChild = m_rContext.GetChild( *(m_rContext.GetMap()),
nChildIndex );
if( !aChild.IsValid() )
throwIndexOutOfBoundsException();
// ... and compare to the currently selected frame
bool bRet = false;
const SwFEShell* pFEShell = GetFEShell();
2002-05-15 12:22:47 +00:00
if( pFEShell )
{
if ( aChild.GetSwFrame() != nullptr )
2002-05-15 12:22:47 +00:00
{
bRet = (pFEShell->GetSelectedFlyFrame() == aChild.GetSwFrame());
2002-05-15 12:22:47 +00:00
}
else if ( aChild.GetDrawObject() )
2002-05-15 12:22:47 +00:00
{
bRet = pFEShell->IsObjSelected( *aChild.GetDrawObject() );
2002-05-15 12:22:47 +00:00
}
//If the SwFrameOrObj is not selected directly in the UI, we should check whether it is selected in the selection cursor.
if( !bRet )
{
if( lcl_getSelectedState( aChild, &m_rContext, m_rContext.GetMap() ) )
bRet = true;
}
2002-05-15 12:22:47 +00:00
}
return bRet;
}
void SwAccessibleSelectionHelper::selectAllAccessibleChildren( )
{
SolarMutexGuard aGuard;
// We can select only one. So iterate over the children to find
// the first we can select, and select it.
2002-05-15 12:22:47 +00:00
SwFEShell* pFEShell = GetFEShell();
if( pFEShell )
{
std::list< SwAccessibleChild > aChildren;
m_rContext.GetChildren( *(m_rContext.GetMap()), aChildren );
2002-05-15 12:22:47 +00:00
std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
2002-05-15 12:22:47 +00:00
while( aIter != aEndIter )
{
const SwAccessibleChild& rChild = *aIter;
const SdrObject* pObj = rChild.GetDrawObject();
const SwFrame* pFrame = rChild.GetSwFrame();
if( pObj && !(pFrame != nullptr && pFEShell->IsObjSelected()) )
{
m_rContext.Select( const_cast< SdrObject *>( pObj ), nullptr==pFrame );
if( pFrame )
2002-05-15 12:22:47 +00:00
break;
}
2002-05-15 12:22:47 +00:00
++aIter;
}
}
}
sal_Int32 SwAccessibleSelectionHelper::getSelectedAccessibleChildCount( )
{
SolarMutexGuard aGuard;
2002-05-15 12:22:47 +00:00
sal_Int32 nCount = 0;
// Only one frame can be selected at a time, and we only frames
// for selectable children.
const SwFEShell* pFEShell = GetFEShell();
if( pFEShell != nullptr )
2002-05-15 12:22:47 +00:00
{
const SwFlyFrame* pFlyFrame = pFEShell->GetSelectedFlyFrame();
if( pFlyFrame )
2002-05-15 12:22:47 +00:00
{
nCount = 1;
2002-05-15 12:22:47 +00:00
}
else
{
const size_t nSelObjs = pFEShell->IsObjSelected();
2002-05-15 12:22:47 +00:00
if( nSelObjs > 0 )
{
std::list< SwAccessibleChild > aChildren;
m_rContext.GetChildren( *(m_rContext.GetMap()), aChildren );
2002-05-15 12:22:47 +00:00
std::list< SwAccessibleChild >::const_iterator aIter =
2002-05-15 12:22:47 +00:00
aChildren.begin();
std::list< SwAccessibleChild >::const_iterator aEndIter =
2002-05-15 12:22:47 +00:00
aChildren.end();
while( aIter != aEndIter && static_cast<size_t>(nCount) < nSelObjs )
2002-05-15 12:22:47 +00:00
{
const SwAccessibleChild& rChild = *aIter;
if( rChild.GetDrawObject() && !rChild.GetSwFrame() &&
SwAccessibleFrame::GetParent(rChild, m_rContext.IsInPagePreview())
== m_rContext.GetFrame() &&
pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
2002-05-15 12:22:47 +00:00
{
nCount++;
}
++aIter;
}
}
}
//If the SwFrameOrObj is not selected directly in the UI,
//we should check whether it is selected in the selection cursor.
if( nCount == 0 )
{
std::list< SwAccessibleChild > aChildren;
m_rContext.GetChildren( *(m_rContext.GetMap()), aChildren );
std::list< SwAccessibleChild >::const_iterator aIter =
aChildren.begin();
std::list< SwAccessibleChild >::const_iterator aEndIter =
aChildren.end();
while( aIter != aEndIter )
{
const SwAccessibleChild& aChild = *aIter;
if( lcl_getSelectedState( aChild, &m_rContext, m_rContext.GetMap() ) )
nCount++;
++aIter;
}
}
2002-05-15 12:22:47 +00:00
}
return nCount;
}
Reference<XAccessible> SwAccessibleSelectionHelper::getSelectedAccessibleChild(
sal_Int32 nSelectedChildIndex )
{
SolarMutexGuard aGuard;
// Since the index is relative to the selected children, and since
// there can be at most one selected frame child, the index must
// be 0, and a selection must exist, otherwise we have to throw an
// lang::IndexOutOfBoundsException
2002-05-15 12:22:47 +00:00
SwFEShell* pFEShell = GetFEShell();
if( nullptr == pFEShell )
throwIndexOutOfBoundsException();
SwAccessibleChild aChild;
const SwFlyFrame *pFlyFrame = pFEShell->GetSelectedFlyFrame();
if( pFlyFrame )
2002-05-15 12:22:47 +00:00
{
if( 0 == nSelectedChildIndex )
2002-05-22 10:48:43 +00:00
{
if(SwAccessibleFrame::GetParent( SwAccessibleChild(pFlyFrame), m_rContext.IsInPagePreview()) == m_rContext.GetFrame() )
{
aChild = pFlyFrame;
}
else
{
const SwFrameFormat *pFrameFormat = pFlyFrame->GetFormat();
if (pFrameFormat)
{
const SwFormatAnchor& rAnchor = pFrameFormat->GetAnchor();
if( rAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR )
{
const SwFrame *pParaFrame = SwAccessibleFrame::GetParent( SwAccessibleChild(pFlyFrame), m_rContext.IsInPagePreview() );
aChild = pParaFrame;
}
}
}
2002-05-22 10:48:43 +00:00
}
2002-05-15 12:22:47 +00:00
}
else
{
const size_t nSelObjs = pFEShell->IsObjSelected();
if( 0 == nSelObjs || static_cast<size_t>(nSelectedChildIndex) >= nSelObjs )
throwIndexOutOfBoundsException();
2002-05-15 12:22:47 +00:00
std::list< SwAccessibleChild > aChildren;
m_rContext.GetChildren( *(m_rContext.GetMap()), aChildren );
2002-05-15 12:22:47 +00:00
std::list< SwAccessibleChild >::const_iterator aIter = aChildren.begin();
std::list< SwAccessibleChild >::const_iterator aEndIter = aChildren.end();
2002-05-15 12:22:47 +00:00
while( aIter != aEndIter && !aChild.IsValid() )
{
const SwAccessibleChild& rChild = *aIter;
if( rChild.GetDrawObject() && !rChild.GetSwFrame() &&
SwAccessibleFrame::GetParent(rChild, m_rContext.IsInPagePreview()) ==
m_rContext.GetFrame() &&
pFEShell->IsObjSelected( *rChild.GetDrawObject() ) )
2002-05-15 12:22:47 +00:00
{
if( 0 == nSelectedChildIndex )
aChild = rChild;
else
--nSelectedChildIndex;
}
++aIter;
}
}
if( !aChild.IsValid() )
throwIndexOutOfBoundsException();
2002-05-15 12:22:47 +00:00
OSL_ENSURE( m_rContext.GetMap() != nullptr, "We need the map." );
2002-05-15 12:22:47 +00:00
Reference< XAccessible > xChild;
if( aChild.GetSwFrame() )
2002-05-15 12:22:47 +00:00
{
2010-10-15 11:44:38 -05:00
::rtl::Reference < SwAccessibleContext > xChildImpl(
m_rContext.GetMap()->GetContextImpl( aChild.GetSwFrame() ) );
2010-10-15 11:44:38 -05:00
if( xChildImpl.is() )
2002-05-15 12:22:47 +00:00
{
xChildImpl->SetParent( &m_rContext );
2010-10-15 11:44:38 -05:00
xChild = xChildImpl.get();
2002-05-15 12:22:47 +00:00
}
}
else if ( aChild.GetDrawObject() )
2002-05-15 12:22:47 +00:00
{
2010-10-15 11:44:38 -05:00
::rtl::Reference < ::accessibility::AccessibleShape > xChildImpl(
m_rContext.GetMap()->GetContextImpl( aChild.GetDrawObject(),
&m_rContext ) );
2010-10-15 11:44:38 -05:00
if( xChildImpl.is() )
xChild = xChildImpl.get();
2002-05-15 12:22:47 +00:00
}
return xChild;
}
2011-01-30 04:19:53 +09:00
// index has to be treated as global child index.
void SwAccessibleSelectionHelper::deselectAccessibleChild(
sal_Int32 nChildIndex )
{
SolarMutexGuard g;
if( nChildIndex < 0 ||
nChildIndex >= m_rContext.GetChildCount( *(m_rContext.GetMap()) ) )
throwIndexOutOfBoundsException();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */