Files
libreoffice/sw/source/core/access/acctable.hxx

278 lines
10 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 .
*/
#ifndef INCLUDED_SW_SOURCE_CORE_ACCESS_ACCTABLE_HXX
#define INCLUDED_SW_SOURCE_CORE_ACCESS_ACCTABLE_HXX
#include <com/sun/star/accessibility/XAccessibleTable.hpp>
#include <com/sun/star/accessibility/XAccessibleTableSelection.hpp>
#include <vector>
#include <com/sun/star/accessibility/XAccessibleSelection.hpp>
#include "acccontext.hxx"
2002-04-11 12:42:31 +00:00
class SwTabFrame;
2002-04-17 13:07:39 +00:00
class SwAccessibleTableData_Impl;
class SwTableBox;
class SwSelBoxes;
namespace sw { namespace access {
class SwAccessibleChild;
} }
2002-04-11 12:42:31 +00:00
2002-04-17 13:07:39 +00:00
class SwAccessibleTable :
public SwAccessibleContext,
public css::accessibility::XAccessibleTable,
public css::accessibility::XAccessibleSelection,
public css::accessibility::XAccessibleTableSelection,
public SwClient
2002-04-11 12:42:31 +00:00
{
2002-04-17 13:07:39 +00:00
SwAccessibleTableData_Impl *mpTableData; // the table's data, prot by Sol-Mutex
OUString m_sDesc;
2002-04-17 13:07:39 +00:00
const SwSelBoxes *GetSelBoxes() const;
2002-05-03 11:34:00 +00:00
void FireTableChangeEvent( const SwAccessibleTableData_Impl& rTableData );
2002-04-11 12:42:31 +00:00
/** get the SwTableBox* for the given child */
const SwTableBox* GetTableBox( sal_Int32 ) const;
bool IsChildSelected( sal_Int32 nChildIndex ) const;
2002-08-15 08:30:33 +00:00
sal_Int32 GetIndexOfSelectedChild( sal_Int32 nSelectedChildIndex ) const;
2002-04-11 12:42:31 +00:00
protected:
// Set states for getAccessibleStateSet.
2014-04-11 08:32:05 +02:00
// This derived class additionally sets MULTISELECTABLE(+)
virtual void GetStates( ::utl::AccessibleStateSetHelper& rStateSet ) override;
2002-04-11 12:42:31 +00:00
virtual ~SwAccessibleTable() override;
2002-04-11 12:42:31 +00:00
2011-01-30 04:19:53 +09:00
// #i77106#
void SetDesc( const OUString& sNewDesc )
{
m_sDesc = sNewDesc;
}
2011-01-30 04:19:53 +09:00
virtual SwAccessibleTableData_Impl* CreateNewTableData(); // #i77106#
2002-04-17 13:07:39 +00:00
// force update of table data
void UpdateTableData();
// remove the current table data
void ClearTableData();
// get table data, update if necessary
inline SwAccessibleTableData_Impl& GetTableData();
// Is table data evailable?
bool HasTableData() const { return (mpTableData != nullptr); }
2002-04-17 13:07:39 +00:00
virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
2002-04-11 12:42:31 +00:00
public:
tdf#58624 sw: fix ~SwAccessibleContext() use-after-free race As seen in JunitTest_toolkit_unoapi_1: Method doAccessibleAction() finished with state OK LOG> doAccessibleAction(): COMPLETED.OK debug:27272:12: -SwAccessibleParagraph mutexwait 0x3fd9f50 debug:27272:9: SwAccessibleContext::Dispose 0x3872620 11SwRootFrame debug:27272:9: SwAccessibleContext::DisposeChildren 0x4047c80 0x386d600 11SwPageFrame debug:27272:9: SwAccessibleContext::DisposeChildren xAcc 0 debug:27272:9: SwAccessibleContext::DisposeChildren 0x4047c80 0x386cef0 11SwBodyFrame debug:27272:9: SwAccessibleContext::DisposeChildren xAcc 0 debug:27272:9: SwAccessibleContext::DisposeChildren 0x4047c80 0x3878fe0 11SwTextFrame debug:27272:9: SwAccessibleContext::DisposeChildren xAcc 0 debug:27272:9: SwAccessibleMap::RemoveContext erase 0x3872620 debug:27272:9: ~SwAccessibleMap: frame entry 0x3878fe0 debug:27272:9: ~SwAccessibleMap: mpFrameMap 0x3eb64a0 debug:27272:9: ~SwAccessibleMap: mpShapeMap 0 soffice.bin: sw/source/core/access/accmap.cxx:1726: virtual SwAccessibleMap::~SwAccessibleMap(): Assertion `(!mpFrameMap || mpFrameMap->empty()) && "Frame map should be empty after disposing the root frame"' The problem here is that thread 12 is blocked on SolarMutex in ~SwAccessibleParagraph(), while thread 9 is in ~SwAccessibleMap(). This means that in SwAccessibleContext::DisposeChildren(), the WeakReference to the SwAccessibleParagraph cannot create a uno::Reference because its reference count is 0, so SwAccessibleContext::Dispose() is not called on it and it remains in the SwAccessibleMap::mpFrameMap. This triggers the assert and later on ~SwAccessibleContext() would access the deleted SwAccessibleMap and crash. To fix this, introduce a weak reference from SwAccessibleContext to SwAccessibleMap; use a std::weak_ptr because that is not derived from OWeakObject. The weak_ptr is only used in the dtor ~SwAccessibleContext(); as long as the ref-count of SwAccessibleContext is > 0 it is guaranteed that the SwAccessibleContext::m_pMap is either null or valid as the recursive Dispose() will work fine. It is possible that additional temporary owning references could delay the destruction of SwAccessibleMap, and the order of destruction of Writer documents is very fragile, so rely on the SolarMutex lock to prevent that; the only shared_ptr that owns SwAccessibleMap while SolarMutex is not locked is the one in SwViewShellImp. (An alternative fix would be to represent the 3 lifecycle stages of SwAccessibleContext by adding a C++-pointer to the SwAccessibleMap::mpFrameMap, so that DisposeChildren() can, if the WeakReference is no longer valid due to ref-count 0, use the pointer and clear SwAccessibleContext::m_pMap - this and the corresponding call to SwAccessibleMap::RemoveContext() from ~SwAccessibleContext() under a mutex that is shared_ptr-owned by SwAccessibleMap and all SwAccessibleContext.) Change-Id: If2b44c79189e3b3d276491a5c57d5404bb2be71a
2017-03-24 13:04:32 +01:00
SwAccessibleTable(std::shared_ptr<SwAccessibleMap> const& pInitMap,
const SwTabFrame* pTableFrame);
2002-04-11 12:42:31 +00:00
// XInterface
2002-04-17 13:07:39 +00:00
// (XInterface methods need to be implemented to disambigouate
// between those inherited through SwAccessibleContext and
2002-04-17 13:07:39 +00:00
// XAccessibleTable).
virtual css::uno::Any SAL_CALL queryInterface(
const css::uno::Type& aType ) override;
2002-04-17 13:07:39 +00:00
virtual void SAL_CALL acquire( ) throw () override
2002-04-17 13:07:39 +00:00
{ SwAccessibleContext::acquire(); };
virtual void SAL_CALL release( ) throw () override
2002-04-17 13:07:39 +00:00
{ SwAccessibleContext::release(); };
// XTypeProvider
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
// XAccessibleContext
2002-04-11 12:42:31 +00:00
/// Return this object's description.
virtual OUString SAL_CALL
getAccessibleDescription() override;
2002-04-11 12:42:31 +00:00
// XAccessibleTable
2002-04-17 13:07:39 +00:00
virtual sal_Int32 SAL_CALL getAccessibleRowCount() override;
virtual sal_Int32 SAL_CALL getAccessibleColumnCount( ) override;
virtual OUString SAL_CALL getAccessibleRowDescription(
sal_Int32 nRow ) override;
virtual OUString SAL_CALL getAccessibleColumnDescription(
sal_Int32 nColumn ) override;
2002-04-17 13:07:39 +00:00
virtual sal_Int32 SAL_CALL getAccessibleRowExtentAt(
sal_Int32 nRow, sal_Int32 nColumn ) override;
2002-04-17 13:07:39 +00:00
virtual sal_Int32 SAL_CALL getAccessibleColumnExtentAt(
sal_Int32 nRow, sal_Int32 nColumn ) override;
virtual css::uno::Reference<
css::accessibility::XAccessibleTable >
SAL_CALL getAccessibleRowHeaders( ) override;
virtual css::uno::Reference<
css::accessibility::XAccessibleTable >
SAL_CALL getAccessibleColumnHeaders( ) override;
virtual css::uno::Sequence< sal_Int32 > SAL_CALL
getSelectedAccessibleRows( ) override;
virtual css::uno::Sequence< sal_Int32 > SAL_CALL
getSelectedAccessibleColumns( ) override;
virtual sal_Bool SAL_CALL isAccessibleRowSelected( sal_Int32 nRow ) override;
virtual sal_Bool SAL_CALL isAccessibleColumnSelected( sal_Int32 nColumn ) override;
virtual css::uno::Reference<
css::accessibility::XAccessible > SAL_CALL
getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn ) override;
virtual css::uno::Reference<
css::accessibility::XAccessible > SAL_CALL
getAccessibleCaption( ) override;
virtual css::uno::Reference<
css::accessibility::XAccessible > SAL_CALL
getAccessibleSummary( ) override;
2002-04-17 13:07:39 +00:00
virtual sal_Bool SAL_CALL isAccessibleSelected(
sal_Int32 nRow, sal_Int32 nColumn ) override;
2002-04-17 13:07:39 +00:00
virtual sal_Int32 SAL_CALL getAccessibleIndex(
sal_Int32 nRow, sal_Int32 nColumn ) override;
virtual sal_Int32 SAL_CALL getAccessibleRow( sal_Int32 nChildIndex ) override;
virtual sal_Int32 SAL_CALL getAccessibleColumn( sal_Int32 nChildIndex ) override;
// XAccessibleTableSelection
virtual sal_Bool SAL_CALL selectRow( sal_Int32 row ) override ;
virtual sal_Bool SAL_CALL selectColumn( sal_Int32 column ) override ;
virtual sal_Bool SAL_CALL unselectRow( sal_Int32 row ) override;
virtual sal_Bool SAL_CALL unselectColumn( sal_Int32 column ) override;
// XServiceInfo
2002-04-11 12:42:31 +00:00
/** Returns an identifier for the implementation of this object.
*/
virtual OUString SAL_CALL
getImplementationName() override;
2002-04-11 12:42:31 +00:00
/** Return whether the specified service is supported by this class.
*/
virtual sal_Bool SAL_CALL
supportsService (const OUString& sServiceName) override;
2002-04-11 12:42:31 +00:00
/** Returns a list of all supported services. In this case that is just
the AccessibleContext service.
*/
virtual css::uno::Sequence< OUString> SAL_CALL
getSupportedServiceNames() override;
2002-04-17 13:07:39 +00:00
// C++ interface
2002-04-17 13:07:39 +00:00
// The object has been moved by the layout
virtual void InvalidatePosOrSize( const SwRect& rOldBox ) override;
2002-04-17 13:07:39 +00:00
// The object is not visible an longer and should be destroyed
virtual void Dispose(bool bRecursive, bool bCanSkipInvisible = true) override;
virtual void DisposeChild( const sw::access::SwAccessibleChild& rFrameOrObj,
bool bRecursive, bool bCanSkipInvisible ) override;
virtual void InvalidateChildPosOrSize( const sw::access::SwAccessibleChild& rFrameOrObj,
const SwRect& rFrame ) override;
// XAccessibleSelection
virtual void SAL_CALL selectAccessibleChild(
sal_Int32 nChildIndex ) override;
virtual sal_Bool SAL_CALL isAccessibleChildSelected(
sal_Int32 nChildIndex ) override;
virtual void SAL_CALL clearAccessibleSelection( ) override;
virtual void SAL_CALL selectAllAccessibleChildren( ) override;
virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) override;
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(
sal_Int32 nSelectedChildIndex ) override;
2011-01-30 04:19:53 +09:00
// index has to be treated as global child index.
virtual void SAL_CALL deselectAccessibleChild(
sal_Int32 nChildIndex ) override;
// XAccessibleComponent
sal_Int32 SAL_CALL getBackground() override;
typedef std::vector< std::pair<SwAccessibleContext*,
css::uno::WeakReference<css::accessibility::XAccessible> > > Cells_t;
Cells_t m_vecCellAdd;
Cells_t m_vecCellRemove;
void FireSelectionEvent( );
void AddSelectionCell(SwAccessibleContext*, bool bAddOrRemove);
2002-04-11 12:42:31 +00:00
};
2002-04-17 13:07:39 +00:00
inline SwAccessibleTableData_Impl& SwAccessibleTable::GetTableData()
{
if( !mpTableData )
UpdateTableData();
return *mpTableData;
}
2011-01-30 04:19:53 +09:00
// #i77106# - subclass to represent table column headers
class SwAccessibleTableColHeaders : public SwAccessibleTable
{
protected:
virtual ~SwAccessibleTableColHeaders() override
{}
virtual SwAccessibleTableData_Impl* CreateNewTableData() override;
virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override;
public:
tdf#58624 sw: fix ~SwAccessibleContext() use-after-free race As seen in JunitTest_toolkit_unoapi_1: Method doAccessibleAction() finished with state OK LOG> doAccessibleAction(): COMPLETED.OK debug:27272:12: -SwAccessibleParagraph mutexwait 0x3fd9f50 debug:27272:9: SwAccessibleContext::Dispose 0x3872620 11SwRootFrame debug:27272:9: SwAccessibleContext::DisposeChildren 0x4047c80 0x386d600 11SwPageFrame debug:27272:9: SwAccessibleContext::DisposeChildren xAcc 0 debug:27272:9: SwAccessibleContext::DisposeChildren 0x4047c80 0x386cef0 11SwBodyFrame debug:27272:9: SwAccessibleContext::DisposeChildren xAcc 0 debug:27272:9: SwAccessibleContext::DisposeChildren 0x4047c80 0x3878fe0 11SwTextFrame debug:27272:9: SwAccessibleContext::DisposeChildren xAcc 0 debug:27272:9: SwAccessibleMap::RemoveContext erase 0x3872620 debug:27272:9: ~SwAccessibleMap: frame entry 0x3878fe0 debug:27272:9: ~SwAccessibleMap: mpFrameMap 0x3eb64a0 debug:27272:9: ~SwAccessibleMap: mpShapeMap 0 soffice.bin: sw/source/core/access/accmap.cxx:1726: virtual SwAccessibleMap::~SwAccessibleMap(): Assertion `(!mpFrameMap || mpFrameMap->empty()) && "Frame map should be empty after disposing the root frame"' The problem here is that thread 12 is blocked on SolarMutex in ~SwAccessibleParagraph(), while thread 9 is in ~SwAccessibleMap(). This means that in SwAccessibleContext::DisposeChildren(), the WeakReference to the SwAccessibleParagraph cannot create a uno::Reference because its reference count is 0, so SwAccessibleContext::Dispose() is not called on it and it remains in the SwAccessibleMap::mpFrameMap. This triggers the assert and later on ~SwAccessibleContext() would access the deleted SwAccessibleMap and crash. To fix this, introduce a weak reference from SwAccessibleContext to SwAccessibleMap; use a std::weak_ptr because that is not derived from OWeakObject. The weak_ptr is only used in the dtor ~SwAccessibleContext(); as long as the ref-count of SwAccessibleContext is > 0 it is guaranteed that the SwAccessibleContext::m_pMap is either null or valid as the recursive Dispose() will work fine. It is possible that additional temporary owning references could delay the destruction of SwAccessibleMap, and the order of destruction of Writer documents is very fragile, so rely on the SolarMutex lock to prevent that; the only shared_ptr that owns SwAccessibleMap while SolarMutex is not locked is the one in SwViewShellImp. (An alternative fix would be to represent the 3 lifecycle stages of SwAccessibleContext by adding a C++-pointer to the SwAccessibleMap::mpFrameMap, so that DisposeChildren() can, if the WeakReference is no longer valid due to ref-count 0, use the pointer and clear SwAccessibleContext::m_pMap - this and the corresponding call to SwAccessibleMap::RemoveContext() from ~SwAccessibleContext() under a mutex that is shared_ptr-owned by SwAccessibleMap and all SwAccessibleContext.) Change-Id: If2b44c79189e3b3d276491a5c57d5404bb2be71a
2017-03-24 13:04:32 +01:00
SwAccessibleTableColHeaders(std::shared_ptr<SwAccessibleMap> const& pMap,
const SwTabFrame *pTabFrame);
// XInterface
virtual css::uno::Any SAL_CALL queryInterface(
const css::uno::Type& aType ) override;
// XAccessibleContext
/// Return the number of currently visible children.
virtual sal_Int32 SAL_CALL getAccessibleChildCount() override;
/// Return the specified child or NULL if index is invalid.
virtual css::uno::Reference< css::accessibility::XAccessible> SAL_CALL
getAccessibleChild (sal_Int32 nIndex) override;
2002-04-11 12:42:31 +00:00
// XAccessibleTable
virtual css::uno::Reference<
css::accessibility::XAccessibleTable >
SAL_CALL getAccessibleRowHeaders( ) override;
virtual css::uno::Reference<
css::accessibility::XAccessibleTable >
SAL_CALL getAccessibleColumnHeaders( ) override;
// XServiceInfo
/** Returns an identifier for the implementation of this object.
*/
virtual OUString SAL_CALL
getImplementationName() override;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */