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

494 lines
15 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 .
*/
2002-02-04 13:10:18 +00:00
#include <vcl/window.hxx>
#include <rootfrm.hxx>
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
2002-02-18 15:27:35 +00:00
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
2002-02-05 14:52:06 +00:00
#include <unotools/accessiblestatesethelper.hxx>
#include <sfx2/viewsh.hxx>
#include <osl/mutex.hxx>
2002-02-04 13:10:18 +00:00
#include <vcl/svapp.hxx>
#include <comphelper/servicehelper.hxx>
#include <viewsh.hxx>
#include <doc.hxx>
#include <accmap.hxx>
2002-02-04 13:10:18 +00:00
#include <accdoc.hxx>
#include "access.hrc"
2002-05-22 10:48:43 +00:00
#include <pagefrm.hxx>
const sal_Char sServiceName[] = "com.sun.star.text.AccessibleTextDocumentView";
const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleDocumentView";
2002-02-04 13:10:18 +00:00
2002-05-22 10:48:43 +00:00
2002-02-04 13:10:18 +00:00
using namespace ::com::sun::star;
using namespace ::com::sun::star::accessibility;
2002-02-04 13:10:18 +00:00
using lang::IndexOutOfBoundsException;
2002-05-22 10:48:43 +00:00
// SwAccessibleDocumentBase: base class for SwAccessibleDocument and
// SwAccessiblePreview
2002-02-05 14:52:06 +00:00
SwAccessibleDocumentBase::SwAccessibleDocumentBase ( SwAccessibleMap *_pMap ) :
SwAccessibleContext( _pMap, AccessibleRole::DOCUMENT,
_pMap->GetShell()->GetLayout() ),//swmod 071107//swmod 071225
mxParent( _pMap->GetShell()->GetWin()->GetAccessibleParentWindow()->GetAccessible() ),
mpChildWin( 0 )
2002-02-04 13:10:18 +00:00
{
}
2002-05-22 10:48:43 +00:00
SwAccessibleDocumentBase::~SwAccessibleDocumentBase()
2002-02-04 13:10:18 +00:00
{
}
2002-05-22 10:48:43 +00:00
void SwAccessibleDocumentBase::SetVisArea()
2002-04-11 13:04:40 +00:00
{
SolarMutexGuard aGuard;
2002-04-11 13:04:40 +00:00
SwRect aOldVisArea( GetVisArea() );
const SwRect& rNewVisArea = GetMap()->GetVisArea();
if( aOldVisArea != rNewVisArea )
{
SwAccessibleFrame::SetVisArea( GetMap()->GetVisArea() );
2011-01-30 04:19:53 +09:00
// #i58139# - showing state of document view needs also be updated.
// Thus, call method <Scrolled(..)> instead of <ChildrenScrolled(..)>
// ChildrenScrolled( GetFrm(), aOldVisArea );
Scrolled( aOldVisArea );
2002-04-11 13:04:40 +00:00
}
}
void SwAccessibleDocumentBase::AddChild( Window *pWin, sal_Bool bFireEvent )
{
SolarMutexGuard aGuard;
OSL_ENSURE( !mpChildWin, "only one child window is supported" );
if( !mpChildWin )
{
mpChildWin = pWin;
if( bFireEvent )
{
AccessibleEventObject aEvent;
aEvent.EventId = AccessibleEventId::CHILD;
aEvent.NewValue <<= mpChildWin->GetAccessible();
FireAccessibleEvent( aEvent );
}
}
}
void SwAccessibleDocumentBase::RemoveChild( Window *pWin )
{
SolarMutexGuard aGuard;
OSL_ENSURE( !mpChildWin || pWin == mpChildWin, "invalid child window to remove" );
if( mpChildWin && pWin == mpChildWin )
{
AccessibleEventObject aEvent;
aEvent.EventId = AccessibleEventId::CHILD;
aEvent.OldValue <<= mpChildWin->GetAccessible();
FireAccessibleEvent( aEvent );
mpChildWin = 0;
}
}
sal_Int32 SAL_CALL SwAccessibleDocumentBase::getAccessibleChildCount( void )
throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
// CHECK_FOR_DEFUNC is called by parent
sal_Int32 nChildren = SwAccessibleContext::getAccessibleChildCount();
if( !IsDisposing() && mpChildWin )
nChildren++;
return nChildren;
}
uno::Reference< XAccessible> SAL_CALL
SwAccessibleDocumentBase::getAccessibleChild( sal_Int32 nIndex )
throw (uno::RuntimeException,
lang::IndexOutOfBoundsException)
{
SolarMutexGuard aGuard;
if( mpChildWin )
{
CHECK_FOR_DEFUNC( XAccessibleContext )
if ( nIndex == GetChildCount( *(GetMap()) ) )
{
return mpChildWin->GetAccessible();
}
}
return SwAccessibleContext::getAccessibleChild( nIndex );
}
2002-04-11 13:04:40 +00:00
uno::Reference< XAccessible> SAL_CALL SwAccessibleDocumentBase::getAccessibleParent (void)
throw (uno::RuntimeException)
2002-02-04 13:10:18 +00:00
{
return mxParent;
2002-02-04 13:10:18 +00:00
}
2002-05-22 10:48:43 +00:00
sal_Int32 SAL_CALL SwAccessibleDocumentBase::getAccessibleIndexInParent (void)
throw (uno::RuntimeException)
2002-02-04 13:10:18 +00:00
{
SolarMutexGuard aGuard;
2002-02-04 13:10:18 +00:00
uno::Reference < XAccessibleContext > xAcc( mxParent->getAccessibleContext() );
uno::Reference < XAccessible > xThis( this );
2002-02-04 13:10:18 +00:00
sal_Int32 nCount = xAcc->getAccessibleChildCount();
for( sal_Int32 i=0; i < nCount; i++ )
{
if( xAcc->getAccessibleChild( i ) == xThis )
return i;
}
return -1L;
}
OUString SAL_CALL SwAccessibleDocumentBase::getAccessibleDescription (void)
throw (uno::RuntimeException)
2002-02-04 13:10:18 +00:00
{
return GetResource( STR_ACCESS_DOC_DESC );
}
2002-05-22 10:48:43 +00:00
awt::Rectangle SAL_CALL SwAccessibleDocumentBase::getBounds()
throw (uno::RuntimeException)
2002-02-04 13:10:18 +00:00
{
SolarMutexGuard aGuard;
2002-02-04 13:10:18 +00:00
Window *pWin = GetWindow();
CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
2002-04-17 13:07:39 +00:00
Rectangle aPixBounds( pWin->GetWindowExtentsRelative( pWin->GetAccessibleParentWindow() ) );
2002-02-04 13:10:18 +00:00
awt::Rectangle aBox( aPixBounds.Left(), aPixBounds.Top(),
aPixBounds.GetWidth(), aPixBounds.GetHeight() );
return aBox;
}
2002-05-22 10:48:43 +00:00
awt::Point SAL_CALL SwAccessibleDocumentBase::getLocation()
throw (uno::RuntimeException)
2002-02-04 13:10:18 +00:00
{
SolarMutexGuard aGuard;
2002-02-04 13:10:18 +00:00
Window *pWin = GetWindow();
CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
2002-04-17 13:07:39 +00:00
Point aPixPos( pWin->GetWindowExtentsRelative( pWin->GetAccessibleParentWindow() ).TopLeft() );
awt::Point aLoc( aPixPos.getX(), aPixPos.getY() );
2002-02-04 13:10:18 +00:00
return aLoc;
}
2002-05-22 10:48:43 +00:00
::com::sun::star::awt::Point SAL_CALL SwAccessibleDocumentBase::getLocationOnScreen()
throw (uno::RuntimeException)
2002-02-04 13:10:18 +00:00
{
SolarMutexGuard aGuard;
2002-02-04 13:10:18 +00:00
Window *pWin = GetWindow();
CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
Point aPixPos( pWin->GetWindowExtentsRelative( 0 ).TopLeft() );
awt::Point aLoc( aPixPos.getX(), aPixPos.getY() );
2002-02-04 13:10:18 +00:00
return aLoc;
}
2002-05-22 10:48:43 +00:00
::com::sun::star::awt::Size SAL_CALL SwAccessibleDocumentBase::getSize()
throw (uno::RuntimeException)
2002-02-04 13:10:18 +00:00
{
SolarMutexGuard aGuard;
2002-02-04 13:10:18 +00:00
Window *pWin = GetWindow();
CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
Size aPixSize( pWin->GetWindowExtentsRelative( 0 ).GetSize() );
awt::Size aSize( aPixSize.Width(), aPixSize.Height() );
return aSize;
}
sal_Bool SAL_CALL SwAccessibleDocumentBase::containsPoint(
const awt::Point& aPoint )
throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
Window *pWin = GetWindow();
CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
2002-10-02 07:48:09 +00:00
Rectangle aPixBounds( pWin->GetWindowExtentsRelative( 0 ) );
aPixBounds.Move(-aPixBounds.Left(), -aPixBounds.Top());
Point aPixPoint( aPoint.X, aPoint.Y );
return aPixBounds.IsInside( aPixPoint );
}
uno::Reference< XAccessible > SAL_CALL SwAccessibleDocumentBase::getAccessibleAtPoint(
const awt::Point& aPoint )
throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
if( mpChildWin )
{
CHECK_FOR_DEFUNC( XAccessibleComponent )
Window *pWin = GetWindow();
CHECK_FOR_WINDOW( XAccessibleComponent, pWin )
2002-02-04 13:10:18 +00:00
Point aPixPoint( aPoint.X, aPoint.Y ); // px rel to window
if( mpChildWin->GetWindowExtentsRelative( pWin ).IsInside( aPixPoint ) )
return mpChildWin->GetAccessible();
}
return SwAccessibleContext::getAccessibleAtPoint( aPoint );
}
2002-05-22 10:48:43 +00:00
// SwAccessibeDocument
void SwAccessibleDocument::GetStates(
::utl::AccessibleStateSetHelper& rStateSet )
{
SwAccessibleContext::GetStates( rStateSet );
// MULTISELECTABLE
rStateSet.AddState( AccessibleStateType::MULTI_SELECTABLE );
2002-05-22 10:48:43 +00:00
}
SwAccessibleDocument::SwAccessibleDocument ( SwAccessibleMap* pInitMap ) :
SwAccessibleDocumentBase( pInitMap ),
maSelectionHelper( *this )
2002-05-22 10:48:43 +00:00
{
SetName( GetResource( STR_ACCESS_DOC_NAME ) );
Window *pWin = pInitMap->GetShell()->GetWin();
if( pWin )
{
pWin->AddChildEventListener( LINK( this, SwAccessibleDocument, WindowChildEventListener ));
sal_uInt16 nCount = pWin->GetChildCount();
for( sal_uInt16 i=0; i < nCount; i++ )
{
Window* pChildWin = pWin->GetChild( i );
if( pChildWin &&
AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
AddChild( pChildWin, sal_False );
}
}
2002-05-22 10:48:43 +00:00
}
SwAccessibleDocument::~SwAccessibleDocument()
{
Window *pWin = GetMap() ? GetMap()->GetShell()->GetWin() : 0;
if( pWin )
pWin->RemoveChildEventListener( LINK( this, SwAccessibleDocument, WindowChildEventListener ));
2002-05-22 10:48:43 +00:00
}
void SwAccessibleDocument::Dispose( sal_Bool bRecursive )
{
OSL_ENSURE( GetFrm() && GetMap(), "already disposed" );
Window *pWin = GetMap() ? GetMap()->GetShell()->GetWin() : 0;
if( pWin )
pWin->RemoveChildEventListener( LINK( this, SwAccessibleDocument, WindowChildEventListener ));
SwAccessibleContext::Dispose( bRecursive );
}
IMPL_LINK( SwAccessibleDocument, WindowChildEventListener, VclSimpleEvent*, pEvent )
{
OSL_ENSURE( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
if ( pEvent && pEvent->ISA( VclWindowEvent ) )
{
VclWindowEvent *pVclEvent = static_cast< VclWindowEvent * >( pEvent );
OSL_ENSURE( pVclEvent->GetWindow(), "Window???" );
switch ( pVclEvent->GetId() )
{
case VCLEVENT_WINDOW_SHOW: // send create on show for direct accessible children
{
Window* pChildWin = static_cast< Window* >( pVclEvent->GetData() );
if( pChildWin && AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
{
AddChild( pChildWin );
}
}
break;
case VCLEVENT_WINDOW_HIDE: // send destroy on hide for direct accessible children
{
Window* pChildWin = static_cast< Window* >( pVclEvent->GetData() );
if( pChildWin && AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
{
RemoveChild( pChildWin );
}
}
break;
2002-06-14 10:15:54 +00:00
case VCLEVENT_OBJECT_DYING: // send destroy on hide for direct accessible children
{
2002-06-14 10:15:54 +00:00
Window* pChildWin = pVclEvent->GetWindow();
if( pChildWin && AccessibleRole::EMBEDDED_OBJECT == pChildWin->GetAccessibleRole() )
{
RemoveChild( pChildWin );
}
}
break;
}
}
return 0;
}
2002-05-22 10:48:43 +00:00
2002-02-04 13:10:18 +00:00
OUString SAL_CALL SwAccessibleDocument::getImplementationName()
throw( uno::RuntimeException )
2002-02-04 13:10:18 +00:00
{
return OUString(sImplementationName);
2002-02-04 13:10:18 +00:00
}
sal_Bool SAL_CALL SwAccessibleDocument::supportsService(
const OUString& sTestServiceName)
throw (uno::RuntimeException)
2002-02-04 13:10:18 +00:00
{
return sTestServiceName.equalsAsciiL( sServiceName,
sizeof(sServiceName)-1 ) ||
sTestServiceName.equalsAsciiL( sAccessibleServiceName,
sizeof(sAccessibleServiceName)-1 );
2002-02-04 13:10:18 +00:00
}
uno::Sequence< OUString > SAL_CALL SwAccessibleDocument::getSupportedServiceNames()
throw( uno::RuntimeException )
2002-02-04 13:10:18 +00:00
{
uno::Sequence< OUString > aRet(2);
2002-02-04 13:10:18 +00:00
OUString* pArray = aRet.getArray();
pArray[0] = OUString( sServiceName );
pArray[1] = OUString( sAccessibleServiceName );
2002-02-04 13:10:18 +00:00
return aRet;
}
// XInterface
uno::Any SwAccessibleDocument::queryInterface(
const uno::Type& rType )
throw ( uno::RuntimeException )
{
uno::Any aRet;
if ( rType == ::getCppuType( static_cast< uno::Reference< XAccessibleSelection > * >( 0 ) ) )
{
uno::Reference<XAccessibleSelection> aSelect = this;
aRet <<= aSelect;
}
else
aRet = SwAccessibleContext::queryInterface( rType );
return aRet;
}
// XTypeProvider
uno::Sequence< uno::Type > SAL_CALL SwAccessibleDocument::getTypes()
throw(uno::RuntimeException)
{
uno::Sequence< uno::Type > aTypes( SwAccessibleDocumentBase::getTypes() );
sal_Int32 nIndex = aTypes.getLength();
aTypes.realloc( nIndex + 1 );
uno::Type* pTypes = aTypes.getArray();
pTypes[nIndex] = ::getCppuType( static_cast< uno::Reference< XAccessibleSelection > * >( 0 ) );
return aTypes;
}
namespace
{
class theSwAccessibleDocumentImplementationId : public rtl::Static< UnoTunnelIdInit, theSwAccessibleDocumentImplementationId > {};
}
uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleDocument::getImplementationId()
throw(uno::RuntimeException)
{
return theSwAccessibleDocumentImplementationId::get().getSeq();
}
// XAccessibleSelection
void SwAccessibleDocument::selectAccessibleChild(
sal_Int32 nChildIndex )
throw ( lang::IndexOutOfBoundsException,
uno::RuntimeException )
{
maSelectionHelper.selectAccessibleChild(nChildIndex);
}
sal_Bool SwAccessibleDocument::isAccessibleChildSelected(
sal_Int32 nChildIndex )
throw ( lang::IndexOutOfBoundsException,
uno::RuntimeException )
{
return maSelectionHelper.isAccessibleChildSelected(nChildIndex);
}
void SwAccessibleDocument::clearAccessibleSelection( )
throw ( uno::RuntimeException )
{
maSelectionHelper.clearAccessibleSelection();
}
void SwAccessibleDocument::selectAllAccessibleChildren( )
throw ( uno::RuntimeException )
{
maSelectionHelper.selectAllAccessibleChildren();
}
sal_Int32 SwAccessibleDocument::getSelectedAccessibleChildCount( )
throw ( uno::RuntimeException )
{
return maSelectionHelper.getSelectedAccessibleChildCount();
}
uno::Reference<XAccessible> SwAccessibleDocument::getSelectedAccessibleChild(
sal_Int32 nSelectedChildIndex )
throw ( lang::IndexOutOfBoundsException,
uno::RuntimeException)
{
return maSelectionHelper.getSelectedAccessibleChild(nSelectedChildIndex);
}
2011-01-30 04:19:53 +09:00
// index has to be treated as global child index.
void SwAccessibleDocument::deselectAccessibleChild(
sal_Int32 nChildIndex )
throw ( lang::IndexOutOfBoundsException,
uno::RuntimeException )
{
maSelectionHelper.deselectAccessibleChild( nChildIndex );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */