Files
libreoffice/starmath/source/accessibility.cxx

1737 lines
50 KiB
C++
Raw Normal View History

2002-05-15 12:49:22 +00:00
/*************************************************************************
*
* $RCSfile: accessibility.cxx,v $
*
* $Revision: 1.8 $
2002-05-15 12:49:22 +00:00
*
* last change: $Author: tl $ $Date: 2002-06-13 14:41:41 $
2002-05-15 12:49:22 +00:00
*
* 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): _______________________________________
*
*
************************************************************************/
#ifndef _DRAFTS_COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
#include <drafts/com/sun/star/accessibility/AccessibleRole.hpp>
#endif
#ifndef _DRAFTS_COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
#include <drafts/com/sun/star/accessibility/AccessibleStateType.hpp>
#endif
2002-05-24 06:48:49 +00:00
#ifndef _DRAFTS_COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLETEXTTYPE_HPP_
#include <drafts/com/sun/star/accessibility/AccessibleTextType.hpp>
#endif
2002-05-31 13:23:22 +00:00
#ifndef _DRAFTS_COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLEEVENTLISTENER_HPP_
#include <drafts/com/sun/star/accessibility/XAccessibleEventListener.hpp>
#endif
#ifndef _DRAFTS_COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTOBJECT_HPP_
#include <drafts/com/sun/star/accessibility/AccessibleEventObject.hpp>
#endif
2002-05-15 12:49:22 +00:00
#ifndef _COM_SUN_STAR_AWT_FOCUSEVENT_HPP_
#include <com/sun/star/awt/FocusEvent.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XFOCUSLISTENER_HPP_
#include <com/sun/star/awt/XFocusListener.hpp>
#endif
2002-05-24 06:48:49 +00:00
#ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XCLIPBOARD_HPP_
#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
#endif
#ifndef _COM_SUN_STAR_DATATRANSFER_CLIPBOARD_XFLUSHABLECLIPBOARD_HPP_
#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
#endif
#ifndef _COM_SUN_STAR_I18N_WORDTYPE_HPP_
#include <com/sun/star/i18n/WordType.hpp>
2002-05-24 07:53:34 +00:00
#endif
2002-05-15 12:49:22 +00:00
#ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX_
#include <unotools/accessiblestatesethelper.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef _SV_SVAPP_HXX
#include <vcl/svapp.hxx>
#endif
#ifndef _SV_WINDOW_HXX
#include <vcl/window.hxx>
#endif
#ifndef _VCL_UNOHELP2_HXX
#include <vcl/unohelp2.hxx>
#endif
2002-05-15 12:49:22 +00:00
#ifndef _VOS_MUTEX_HXX_
#include <vos/mutex.hxx>
#endif
#ifndef _SFXITEMSET_HXX
#include <svtools/itemset.hxx>
#endif
#include <svx/editdata.hxx>
#ifndef _MyEDITVIEW_HXX
#include <svx/editview.hxx>
#endif
#ifndef _EEITEM_HXX
#include <svx/eeitem.hxx>
#endif
#ifndef _OUTLINER_HXX
#include <svx/outliner.hxx>
#endif
#ifndef _SVX_UNOEDHLP_HXX
#include <svx/unoedhlp.hxx>
#endif
2002-05-15 12:49:22 +00:00
#ifndef _ACCESSIBILITY_HXX_
#include "accessibility.hxx"
#endif
#ifndef APPLICAT_HXX
#include <applicat.hxx>
#endif
#ifndef DOCUMENT_HXX
#include <document.hxx>
#endif
#ifndef VIEW_HXX
#include <view.hxx>
#endif
using namespace rtl;
using namespace com::sun::star;
using namespace com::sun::star::lang;
using namespace com::sun::star::uno;
using namespace drafts::com::sun::star::accessibility;
//////////////////////////////////////////////////////////////////////
SmGraphicAccessible::SmGraphicAccessible( SmGraphicWindow *pGraphicWin ) :
2002-05-24 06:48:49 +00:00
pWin (pGraphicWin),
2002-05-15 12:49:22 +00:00
aAccEventListeners (aListenerMutex)
{
DBG_ASSERT( pWin, "SmGraphicAccessible: window missing" );
2002-05-15 12:49:22 +00:00
//++aRefCount;
}
SmGraphicAccessible::SmGraphicAccessible( const SmGraphicAccessible &rSmAcc ) :
2002-05-15 12:49:22 +00:00
aAccEventListeners (aListenerMutex)
{
//vos::OGuard aGuard(Application::GetSolarMutex());
pWin = rSmAcc.pWin;
DBG_ASSERT( pWin, "SmGraphicAccessible: window missing" );
2002-05-15 12:49:22 +00:00
//++aRefCount;
}
SmGraphicAccessible::~SmGraphicAccessible()
2002-05-15 12:49:22 +00:00
{
/*
vos::OGuard aGuard(Application::GetSolarMutex());
if (--aRefCount == 0)
{
}
*/
}
SmDocShell * SmGraphicAccessible::GetDoc_Impl()
2002-05-15 12:49:22 +00:00
{
SmViewShell *pView = pWin ? pWin->GetView() : 0;
return pView ? pView->GetDoc() : 0;
}
String SmGraphicAccessible::GetAccessibleText_Impl()
2002-05-24 06:48:49 +00:00
{
String aTxt;
SmDocShell *pDoc = GetDoc_Impl();
if (pDoc)
aTxt = pDoc->GetAccessibleText();
return aTxt;
}
void SmGraphicAccessible::ClearWin()
2002-05-15 12:49:22 +00:00
{
pWin = 0; // implicitly results in AccessibleStateType::DEFUNC set
EventObject aEvtObj;
aEvtObj.Source = (XAccessible *) this;
aAccEventListeners.disposeAndClear( aEvtObj );
}
void SmGraphicAccessible::LaunchEvent(
2002-05-31 13:23:22 +00:00
const sal_Int16 nAccesibleEventId,
const uno::Any &rOldVal,
const uno::Any &rNewVal)
2002-05-15 12:49:22 +00:00
{
2002-05-31 13:23:22 +00:00
AccessibleEventObject aEvt;
aEvt.Source = (XAccessible *) this;
aEvt.EventId = nAccesibleEventId;
aEvt.OldValue = rOldVal;
aEvt.NewValue = rNewVal ;
2002-05-15 12:49:22 +00:00
2002-05-31 13:23:22 +00:00
// pass event on to event-listener's
cppu::OInterfaceIteratorHelper aIt( aAccEventListeners );
while (aIt.hasMoreElements())
{
Reference< XAccessibleEventListener > xRef( aIt.next(), UNO_QUERY );
if (xRef.is())
xRef->notifyEvent( aEvt );
2002-05-15 12:49:22 +00:00
}
}
uno::Reference< XAccessibleContext > SAL_CALL SmGraphicAccessible::getAccessibleContext()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return this;
}
sal_Bool SAL_CALL SmGraphicAccessible::contains( const awt::Point& aPoint )
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Size aSz( pWin->GetSizePixel() );
return aPoint.X >= 0 && aPoint.Y >= 0 &&
aPoint.X < aSz.Width() && aPoint.Y < aSz.Height();
}
uno::Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleAt(
2002-05-15 12:49:22 +00:00
const awt::Point& aPoint )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
XAccessible *pRes = 0;
if (contains( aPoint ))
pRes = this;
return pRes;
}
awt::Rectangle SAL_CALL SmGraphicAccessible::getBounds()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Point aPt( pWin->GetPosPixel() );
Size aSz( pWin->GetSizePixel() );
return awt::Rectangle( aPt.X(), aPt.Y(), aSz.Width(), aSz.Height() );
}
awt::Point SAL_CALL SmGraphicAccessible::getLocation()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Point aPt( pWin->GetPosPixel() );
return awt::Point( aPt.X(), aPt.Y() );
}
awt::Point SAL_CALL SmGraphicAccessible::getLocationOnScreen()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Point aPt( pWin->OutputToAbsoluteScreenPixel( Point() ) );
return awt::Point( aPt.X(), aPt.Y() );
}
awt::Size SAL_CALL SmGraphicAccessible::getSize()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Size aSz( pWin->GetSizePixel() );
return awt::Size( aSz.Width(), aSz.Height() );
}
sal_Bool SAL_CALL SmGraphicAccessible::isShowing()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
return pWin->IsVisible();
}
sal_Bool SAL_CALL SmGraphicAccessible::isVisible()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
return pWin->IsReallyVisible();
}
sal_Bool SAL_CALL SmGraphicAccessible::isFocusTraversable()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return TRUE;
}
void SAL_CALL SmGraphicAccessible::grabFocus()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
pWin->GrabFocus();
}
uno::Any SAL_CALL SmGraphicAccessible::getAccessibleKeyBinding()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return uno::Any();
}
sal_Int32 SAL_CALL SmGraphicAccessible::getAccessibleChildCount()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return 0;
}
Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleChild(
2002-05-15 12:49:22 +00:00
sal_Int32 i )
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
throw IndexOutOfBoundsException(); // there is no child...
return 0;
}
Reference< XAccessible > SAL_CALL SmGraphicAccessible::getAccessibleParent()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Window *pAccParent = pWin->GetAccessibleParentWindow();
DBG_ASSERT( pAccParent, "accessible parent missing" );
return pAccParent ? pAccParent->GetAccessible() : Reference< XAccessible >();
2002-05-15 12:49:22 +00:00
}
sal_Int32 SAL_CALL SmGraphicAccessible::getAccessibleIndexInParent()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
sal_Int32 nIdx = -1;
Window *pAccParent = pWin ? pWin->GetAccessibleParentWindow() : 0;
if (pAccParent)
{
USHORT nCnt = pAccParent->GetAccessibleChildWindowCount();
for (USHORT i = 0; i < nCnt && nIdx == -1; ++i)
if (pAccParent->GetAccessibleChildWindow( i ) == pWin)
nIdx = i;
}
return nIdx;
}
sal_Int16 SAL_CALL SmGraphicAccessible::getAccessibleRole()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return AccessibleRole::DOCUMENT;
}
OUString SAL_CALL SmGraphicAccessible::getAccessibleDescription()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
SmDocShell *pDoc = GetDoc_Impl();
return pDoc ? OUString(pDoc->GetText()) : OUString();
2002-05-15 12:49:22 +00:00
}
OUString SAL_CALL SmGraphicAccessible::getAccessibleName()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return String( SmResId(RID_DOCUMENTSTR) );
}
Reference< XAccessibleRelationSet > SAL_CALL SmGraphicAccessible::getAccessibleRelationSet()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return 0; // no relation set
}
Reference< XAccessibleStateSet > SAL_CALL SmGraphicAccessible::getAccessibleStateSet()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
::utl::AccessibleStateSetHelper *pStateSet =
new ::utl::AccessibleStateSetHelper;
Reference<XAccessibleStateSet> xStateSet( pStateSet );
if (!pWin)
pStateSet->AddState( AccessibleStateType::DEFUNC );
else
{
//pStateSet->AddState( AccessibleStateType::EDITABLE );
//pStateSet->AddState( AccessibleStateType::HORIZONTAL );
//pStateSet->AddState( AccessibleStateType::TRANSIENT );
pStateSet->AddState( AccessibleStateType::ENABLED );
pStateSet->AddState( AccessibleStateType::FOCUSABLE );
if (pWin->HasFocus())
pStateSet->AddState( AccessibleStateType::FOCUSED );
if (pWin->IsActive())
pStateSet->AddState( AccessibleStateType::ACTIVE );
if (pWin->IsVisible())
pStateSet->AddState( AccessibleStateType::SHOWING );
if (pWin->IsReallyVisible())
pStateSet->AddState( AccessibleStateType::VISIBLE );
if (COL_TRANSPARENT != pWin->GetBackground().GetColor().GetColor())
pStateSet->AddState( AccessibleStateType::OPAQUE );
}
return xStateSet;
}
Locale SAL_CALL SmGraphicAccessible::getLocale()
2002-05-15 12:49:22 +00:00
throw (IllegalAccessibleComponentStateException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
// should be the document language...
// We use the language of the localized symbol names here.
return Application::GetSettings().GetUILocale();
}
void SAL_CALL SmGraphicAccessible::addEventListener(
2002-05-24 06:48:49 +00:00
const Reference< XAccessibleEventListener >& xListener )
throw (RuntimeException)
{
//vos::OGuard aGuard(Application::GetSolarMutex());
if (pWin) // not disposing (about to destroy view shell)
aAccEventListeners.addInterface( xListener );
}
void SAL_CALL SmGraphicAccessible::removeEventListener(
2002-05-24 06:48:49 +00:00
const Reference< XAccessibleEventListener >& xListener )
throw (RuntimeException)
{
//vos::OGuard aGuard(Application::GetSolarMutex());
aAccEventListeners.removeInterface( xListener );
}
sal_Int32 SAL_CALL SmGraphicAccessible::getCaretPosition()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return 0;
2002-05-15 12:49:22 +00:00
}
sal_Unicode SAL_CALL SmGraphicAccessible::getCharacter( sal_Int32 nIndex )
2002-05-15 12:49:22 +00:00
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
xub_StrLen nIdx = (xub_StrLen) nIndex;
String aTxt( GetAccessibleText_Impl() );
if (!(0 <= nIdx && nIdx < aTxt.Len()))
throw IndexOutOfBoundsException();
return aTxt.GetChar( nIdx );
2002-05-15 12:49:22 +00:00
}
Sequence< beans::PropertyValue > SAL_CALL SmGraphicAccessible::getCharacterAttributes(
2002-05-15 12:49:22 +00:00
sal_Int32 nIndex )
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return Sequence< beans::PropertyValue >();
}
awt::Rectangle SAL_CALL SmGraphicAccessible::getCharacterBounds( sal_Int32 nIndex )
2002-05-15 12:49:22 +00:00
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-31 13:23:22 +00:00
awt::Rectangle aRes;
if (!pWin)
throw RuntimeException();
else
{
// get accessible text
SmViewShell *pView = pWin->GetView();
SmDocShell *pDoc = pView ? pView->GetDoc() : 0;
if (!pDoc)
throw RuntimeException();
String aTxt( GetAccessibleText_Impl() );
if (!(0 <= nIndex && nIndex <= aTxt.Len()))
throw IndexOutOfBoundsException();
const SmNode *pTree = pDoc->GetFormulaTree();
const SmNode *pNode = pTree->FindNodeWithAccessibleIndex( (xub_StrLen) nIndex );
//! pNode may be 0 if the index belongs to a char that was inserted
//! only for the accessible text!
if (pNode)
{
sal_Int32 nAccIndex = pNode->GetAccessibleIndex();
DBG_ASSERT( nAccIndex >= 0, "invalid accessible index" );
DBG_ASSERT( nIndex >= nAccIndex, "index out of range" );
String aNodeText;
pNode->GetAccessibleText( aNodeText );
sal_Int32 nNodeIndex = nIndex - nAccIndex;
if (0 <= nNodeIndex && nNodeIndex < aNodeText.Len())
{
// get appropriate rectangle
Point aOffset(pNode->GetTopLeft() - pTree->GetTopLeft());
Point aTLPos (pWin->GetFormulaDrawPos() + aOffset);
// aTLPos.X() -= pNode->GetItalicLeftSpace();
// Size aSize (pNode->GetItalicSize());
aTLPos.X() -= 0;
Size aSize (pNode->GetSize());
2002-05-31 13:23:22 +00:00
long *pXAry = new long[ aNodeText.Len() ];
pWin->SetFont( pNode->GetFont() );
pWin->GetTextArray( aNodeText, pXAry, 0, aNodeText.Len() );
aTLPos.X() += nNodeIndex > 0 ? pXAry[nNodeIndex - 1] : 0;
aSize.Width() = nNodeIndex > 0 ? pXAry[nNodeIndex] - pXAry[nNodeIndex - 1] : pXAry[nNodeIndex];
delete[] pXAry;
#ifdef DEBUG
Point aLP00( pWin->LogicToPixel( Point(0,0)) );
Point aPL00( pWin->PixelToLogic( Point(0,0)) );
#endif
2002-05-31 13:23:22 +00:00
aTLPos = pWin->LogicToPixel( aTLPos );
aSize = pWin->LogicToPixel( aSize );
aRes.X = aTLPos.X();
aRes.Y = aTLPos.Y();
aRes.Width = aSize.Width();
aRes.Height = aSize.Height();
}
}
}
return aRes;
2002-05-15 12:49:22 +00:00
}
sal_Int32 SAL_CALL SmGraphicAccessible::getCharacterCount()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
return GetAccessibleText_Impl().Len();
2002-05-15 12:49:22 +00:00
}
sal_Int32 SAL_CALL SmGraphicAccessible::getIndexAtPoint( const awt::Point& aPoint )
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-31 13:23:22 +00:00
sal_Int32 nRes = -1;
if (pWin)
{
const SmNode *pTree = pWin->GetView()->GetDoc()->GetFormulaTree();
//! kann NULL sein! ZB wenn bereits beim laden des Dokuments (bevor der
//! Parser angeworfen wurde) ins Fenster geklickt wird.
if (!pTree)
return nRes;
// get position relativ to formula draw position
Point aPos( aPoint.X, aPoint.Y );
aPos = pWin->PixelToLogic( aPos );
aPos -= pWin->GetFormulaDrawPos();
// if it was inside the formula then get the appropriate node
const SmNode *pNode = 0;
if (pTree->OrientedDist(aPos) <= 0)
pNode = pTree->FindRectClosestTo(aPos);
if (pNode)
{
// get appropriate rectangle
Point aOffset( pNode->GetTopLeft() - pTree->GetTopLeft() );
Point aTLPos ( /*pWin->GetFormulaDrawPos() +*/ aOffset );
// aTLPos.X() -= pNode->GetItalicLeftSpace();
// Size aSize( pNode->GetItalicSize() );
aTLPos.X() -= 0;
Size aSize( pNode->GetSize() );
#ifdef DEBUG
Point aLP00( pWin->LogicToPixel( Point(0,0)) );
Point aPL00( pWin->PixelToLogic( Point(0,0)) );
#endif
2002-05-31 13:23:22 +00:00
Rectangle aRect( aTLPos, aSize );
if (aRect.IsInside( aPos ))
{
DBG_ASSERT( pNode->IsVisible(), "node is not a leaf" );
String aTxt;
pNode->GetAccessibleText( aTxt );
2002-05-31 13:23:22 +00:00
DBG_ASSERT( aTxt.Len(), "no accessible text available" );
long nNodeX = pNode->GetLeft();
2002-05-31 13:23:22 +00:00
long *pXAry = new long[ aTxt.Len() ];
pWin->SetFont( pNode->GetFont() );
pWin->GetTextArray( aTxt, pXAry, 0, aTxt.Len() );
for (sal_Int32 i = 0; i < aTxt.Len() && nRes == -1; ++i)
2002-05-31 13:23:22 +00:00
{
if (pXAry[i] + nNodeX > aPos.X())
2002-05-31 13:23:22 +00:00
nRes = i;
}
delete[] pXAry;
DBG_ASSERT( nRes >= 0 && nRes < aTxt.Len(), "index out of range" );
DBG_ASSERT( pNode->GetAccessibleIndex() >= 0,
"invalid accessible index" );
nRes = pNode->GetAccessibleIndex() + nRes;
}
}
}
return nRes;
2002-05-15 12:49:22 +00:00
}
OUString SAL_CALL SmGraphicAccessible::getSelectedText()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return OUString();
}
sal_Int32 SAL_CALL SmGraphicAccessible::getSelectionStart()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
return -1;
2002-05-15 12:49:22 +00:00
}
sal_Int32 SAL_CALL SmGraphicAccessible::getSelectionEnd()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
return -1;
2002-05-15 12:49:22 +00:00
}
sal_Bool SAL_CALL SmGraphicAccessible::setSelection(
2002-05-15 12:49:22 +00:00
sal_Int32 nStartIndex,
sal_Int32 nEndIndex )
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return FALSE;
}
OUString SAL_CALL SmGraphicAccessible::getText()
2002-05-15 12:49:22 +00:00
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
return GetAccessibleText_Impl();
2002-05-15 12:49:22 +00:00
}
OUString SAL_CALL SmGraphicAccessible::getTextRange(
2002-05-15 12:49:22 +00:00
sal_Int32 nStartIndex,
sal_Int32 nEndIndex )
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
String aTxt( GetAccessibleText_Impl() );
xub_StrLen nStart = (xub_StrLen) nStartIndex;
xub_StrLen nEnd = (xub_StrLen) nEndIndex;
if (!(0 <= nStart && nStart < aTxt.Len()) ||
!(0 <= nEnd && nEnd < aTxt.Len()))
throw IndexOutOfBoundsException();
if (nStartIndex > nEndIndex)
return OUString();
return aTxt.Copy( nStart, nEnd );
2002-05-15 12:49:22 +00:00
}
OUString SAL_CALL SmGraphicAccessible::getTextAtIndex(
2002-05-15 12:49:22 +00:00
sal_Int32 nIndex,
sal_Int16 aTextType )
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
if (AccessibleTextType::CHARACTER != aTextType)
return OUString();
String aTxt( GetAccessibleText_Impl() );
2002-05-24 07:53:34 +00:00
xub_StrLen nIdx = (xub_StrLen) nIndex;
if (!(0 <= nIdx && nIdx < aTxt.Len()))
throw IndexOutOfBoundsException();
return aTxt.Copy(nIdx, 1);
2002-05-15 12:49:22 +00:00
}
OUString SAL_CALL SmGraphicAccessible::getTextBeforeIndex(
2002-05-15 12:49:22 +00:00
sal_Int32 nIndex,
sal_Int16 aTextType )
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
if (AccessibleTextType::CHARACTER != aTextType)
return OUString();
String aTxt( GetAccessibleText_Impl() );
2002-05-24 07:53:34 +00:00
xub_StrLen nIdx = (xub_StrLen) nIndex;
if (!(0 <= nIdx && nIdx < aTxt.Len()))
throw IndexOutOfBoundsException();
return aTxt.Copy(0, nIdx);
2002-05-15 12:49:22 +00:00
}
OUString SAL_CALL SmGraphicAccessible::getTextBehindIndex(
2002-05-15 12:49:22 +00:00
sal_Int32 nIndex,
sal_Int16 aTextType )
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
if (AccessibleTextType::CHARACTER != aTextType)
return OUString();
String aTxt( GetAccessibleText_Impl() );
2002-05-24 07:53:34 +00:00
xub_StrLen nIdx = (xub_StrLen) nIndex;
if (!(0 <= nIdx && nIdx < aTxt.Len()))
throw IndexOutOfBoundsException();
return aTxt.Copy(nIdx, aTxt.Len()-1);
2002-05-15 12:49:22 +00:00
}
sal_Bool SAL_CALL SmGraphicAccessible::copyText(
2002-05-15 12:49:22 +00:00
sal_Int32 nStartIndex,
sal_Int32 nEndIndex )
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
2002-05-24 06:48:49 +00:00
sal_Bool bReturn = sal_False;
2002-05-24 07:53:34 +00:00
2002-05-24 06:48:49 +00:00
if ( pWin )
{
2002-05-24 07:53:34 +00:00
String aTxt( GetAccessibleText_Impl() );
xub_StrLen nStart = (xub_StrLen) nStartIndex;
xub_StrLen nEnd = (xub_StrLen) nEndIndex;
if (!(0 <= nStart && nStart < aTxt.Len()) ||
!(0 <= nEnd && nEnd < aTxt.Len()))
throw IndexOutOfBoundsException();
String aCopy;
if (nStart <= nEnd)
aCopy = aTxt.Copy(nStart, nEnd - nStart + 1);
2002-05-24 06:48:49 +00:00
Reference< datatransfer::clipboard::XClipboard > xClipboard = pWin->GetClipboard();
if ( xClipboard.is() )
{
2002-05-24 07:53:34 +00:00
::rtl::OUString sText( aCopy );
2002-05-15 12:49:22 +00:00
2002-05-24 06:48:49 +00:00
::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
const sal_uInt32 nRef = Application::ReleaseSolarMutex();
xClipboard->setContents( pDataObj, NULL );
2002-05-15 12:49:22 +00:00
2002-05-24 06:48:49 +00:00
Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
if( xFlushableClipboard.is() )
xFlushableClipboard->flushClipboard();
Application::AcquireSolarMutex( nRef );
bReturn = sal_True;
}
}
2002-05-24 07:53:34 +00:00
2002-05-24 06:48:49 +00:00
return bReturn;
2002-05-15 12:49:22 +00:00
}
//////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------
SmEditSource::SmEditSource( SmEditWindow *pWin, EditEngine &rEEngine, EditView &rEView ) :
aViewFwd (rEView),
aTextFwd (rEEngine, *this),
aEditViewFwd(rEView),
rEditEngine (rEEngine),
rEditView (rEView)
{
}
SmEditSource::SmEditSource( const SmEditSource &rSrc ) :
aViewFwd (rSrc.rEditView),
aTextFwd (rSrc.rEditEngine, *this),
aEditViewFwd(rSrc.rEditView),
rEditEngine (rSrc.rEditEngine),
rEditView (rSrc.rEditView)
{
//aBroadCaster; can be completely new
}
SmEditSource::~SmEditSource()
{
}
SvxEditSource* SmEditSource::Clone() const
{
return new SmEditSource( *this );
}
SvxTextForwarder* SmEditSource::GetTextForwarder()
{
return &aTextFwd;
}
SvxViewForwarder* SmEditSource::GetViewForwarder()
{
return &aViewFwd;
}
SvxEditViewForwarder* SmEditSource::GetEditViewForwarder( sal_Bool bCreate )
{
return &aEditViewFwd;
}
void SmEditSource::UpdateData()
{
// would possibly only by needed if the XText inteface is implemented
// and its text needs to be updated.
}
SfxBroadcaster & SmEditSource::GetBroadcaster() const
{
return ((SmEditSource *) this)->aBroadCaster;
}
//------------------------------------------------------------------------
SmViewForwarder::SmViewForwarder( EditView &rView ) :
rEditView(rView)
{
}
SmViewForwarder::~SmViewForwarder()
{
}
BOOL SmViewForwarder::IsValid() const
{
return sal_True;
}
Rectangle SmViewForwarder::GetVisArea() const
{
OutputDevice* pOutDev = rEditView.GetWindow();
if( pOutDev )
{
Rectangle aVisArea = rEditView.GetVisArea();
// figure out map mode from edit engine
EditEngine* pEditEngine = rEditView.GetEditEngine();
if( pEditEngine )
{
MapMode aMapMode(pOutDev->GetMapMode());
aVisArea = OutputDevice::LogicToLogic( aVisArea,
pEditEngine->GetRefMapMode(),
aMapMode.GetMapUnit() );
aMapMode.SetOrigin(Point());
return pOutDev->LogicToPixel( aVisArea, aMapMode );
}
}
return Rectangle();
}
Point SmViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
{
OutputDevice* pOutDev = rEditView.GetWindow();
if( pOutDev )
{
MapMode aMapMode(pOutDev->GetMapMode());
Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
aMapMode.GetMapUnit() ) );
aMapMode.SetOrigin(Point());
return pOutDev->LogicToPixel( aPoint, aMapMode );
}
return Point();
}
Point SmViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
{
OutputDevice* pOutDev = rEditView.GetWindow();
if( pOutDev )
{
MapMode aMapMode(pOutDev->GetMapMode());
aMapMode.SetOrigin(Point());
Point aPoint( pOutDev->PixelToLogic( rPoint, aMapMode ) );
return OutputDevice::LogicToLogic( aPoint,
aMapMode.GetMapUnit(),
rMapMode );
}
return Point();
}
//------------------------------------------------------------------------
SmTextForwarder::SmTextForwarder( EditEngine& rEngine, SmEditSource & rSource) :
rEditEngine ( rEngine ),
rEditSource (rSource)
{
rEditEngine.SetNotifyHdl( LINK(this, SmTextForwarder, NotifyHdl) );
}
SmTextForwarder::~SmTextForwarder()
{
// die EditEngine muss ggf. von aussen geloescht werden
rEditEngine.SetNotifyHdl( Link() );
}
IMPL_LINK(SmTextForwarder, NotifyHdl, EENotify*, aNotify)
{
if (aNotify)
{
::std::auto_ptr< SfxHint > aHint = SvxEditSourceHintTranslator::EENotification2Hint( aNotify );
if (aHint.get())
rEditSource.GetBroadcaster().Broadcast( *aHint.get() );
}
return 0;
}
USHORT SmTextForwarder::GetParagraphCount() const
{
return rEditEngine.GetParagraphCount();
}
USHORT SmTextForwarder::GetTextLen( USHORT nParagraph ) const
{
return rEditEngine.GetTextLen( nParagraph );
}
String SmTextForwarder::GetText( const ESelection& rSel ) const
{
String aRet = rEditEngine.GetText( rSel, LINEEND_LF );
aRet.ConvertLineEnd();
return aRet;
}
SfxItemSet SmTextForwarder::GetAttribs( const ESelection& rSel, BOOL bOnlyHardAttrib ) const
{
if( rSel.nStartPara == rSel.nEndPara )
{
sal_uInt8 nFlags = 0;
switch( bOnlyHardAttrib )
{
case EditEngineAttribs_All:
nFlags = GETATTRIBS_ALL;
break;
case EditEngineAttribs_HardAndPara:
nFlags = GETATTRIBS_PARAATTRIBS|GETATTRIBS_CHARATTRIBS;
break;
case EditEngineAttribs_OnlyHard:
nFlags = GETATTRIBS_CHARATTRIBS;
break;
default:
DBG_ERROR("unknown flags for SvxOutlinerForwarder::GetAttribs");
}
return rEditEngine.GetAttribs( rSel.nStartPara, rSel.nStartPos, rSel.nEndPos, nFlags );
}
else
{
return rEditEngine.GetAttribs( rSel, bOnlyHardAttrib );
}
}
SfxItemSet SmTextForwarder::GetParaAttribs( USHORT nPara ) const
{
SfxItemSet aSet( rEditEngine.GetParaAttribs( nPara ) );
USHORT nWhich = EE_PARA_START;
while( nWhich <= EE_PARA_END )
{
if( aSet.GetItemState( nWhich, TRUE ) != SFX_ITEM_ON )
{
if( rEditEngine.HasParaAttrib( nPara, nWhich ) )
aSet.Put( rEditEngine.GetParaAttrib( nPara, nWhich ) );
}
nWhich++;
}
return aSet;
}
void SmTextForwarder::SetParaAttribs( USHORT nPara, const SfxItemSet& rSet )
{
rEditEngine.SetParaAttribs( nPara, rSet );
}
SfxItemPool* SmTextForwarder::GetPool() const
{
return rEditEngine.GetEmptyItemSet().GetPool();
}
void SmTextForwarder::GetPortions( USHORT nPara, SvUShorts& rList ) const
{
rEditEngine.GetPortions( nPara, rList );
}
void SmTextForwarder::QuickInsertText( const String& rText, const ESelection& rSel )
{
rEditEngine.QuickInsertText( rText, rSel );
}
void SmTextForwarder::QuickInsertLineBreak( const ESelection& rSel )
{
rEditEngine.QuickInsertLineBreak( rSel );
}
void SmTextForwarder::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel )
{
rEditEngine.QuickInsertField( rFld, rSel );
}
void SmTextForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel )
{
rEditEngine.QuickSetAttribs( rSet, rSel );
}
BOOL SmTextForwarder::IsValid() const
{
// cannot reliably query EditEngine state
// while in the middle of an update
return rEditEngine.GetUpdateMode();
}
XubString SmTextForwarder::CalcFieldValue( const SvxFieldItem& rField, USHORT nPara, USHORT nPos, Color*& rpTxtColor, Color*& rpFldColor )
{
return rEditEngine.CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
}
USHORT GetSvxEditEngineItemState( EditEngine& rEditEngine, const ESelection& rSel, USHORT nWhich )
{
EECharAttribArray aAttribs;
const SfxPoolItem* pLastItem = NULL;
SfxItemState eState = SFX_ITEM_DEFAULT;
// check all paragraphs inside the selection
for( USHORT nPara = rSel.nStartPara; nPara <= rSel.nEndPara; nPara++ )
{
SfxItemState eParaState = SFX_ITEM_DEFAULT;
// calculate start and endpos for this paragraph
USHORT nPos = 0;
if( rSel.nStartPara == nPara )
nPos = rSel.nStartPos;
USHORT nEndPos = rSel.nEndPos;
if( rSel.nEndPara != nPara )
nEndPos = rEditEngine.GetTextLen( nPara );
// get list of char attribs
rEditEngine.GetCharAttribs( nPara, aAttribs );
BOOL bEmpty = TRUE; // we found no item inside the selektion of this paragraph
BOOL bGaps = FALSE; // we found items but theire gaps between them
USHORT nLastEnd = nPos;
const SfxPoolItem* pParaItem = NULL;
for( USHORT nAttrib = 0; nAttrib < aAttribs.Count(); nAttrib++ )
{
struct EECharAttrib aAttrib = aAttribs.GetObject( nAttrib );
DBG_ASSERT( aAttrib.pAttr, "GetCharAttribs gives corrupt data" );
const sal_Bool bEmptyPortion = aAttrib.nStart == aAttrib.nEnd;
if( (!bEmptyPortion && (aAttrib.nStart >= nEndPos)) || (bEmptyPortion && (aAttrib.nStart > nEndPos)) )
break; // break if we are already behind our selektion
if( (!bEmptyPortion && (aAttrib.nEnd <= nPos)) || (bEmptyPortion && (aAttrib.nEnd < nPos)) )
continue; // or if the attribute ends before our selektion
if( aAttrib.pAttr->Which() != nWhich )
continue; // skip if is not the searched item
// if we already found an item
if( pParaItem )
{
// ... and its different to this one than the state is dont care
if( *pParaItem != *aAttrib.pAttr )
return SFX_ITEM_DONTCARE;
}
else
{
pParaItem = aAttrib.pAttr;
}
if( bEmpty )
bEmpty = FALSE;
if( !bGaps && aAttrib.nStart > nLastEnd )
bGaps = TRUE;
nLastEnd = aAttrib.nEnd;
}
if( !bEmpty && !bGaps && nLastEnd < ( nEndPos - 1 ) )
bGaps = TRUE;
/*
// since we have no portion with our item or if there were gaps
if( bEmpty || bGaps )
{
// we need to check the paragraph item
const SfxItemSet& rParaSet = rEditEngine.GetParaAttribs( nPara );
if( rParaSet.GetItemState( nWhich ) == SFX_ITEM_SET )
{
eState = SFX_ITEM_SET;
// get item from the paragraph
const SfxPoolItem* pTempItem = rParaSet.GetItem( nWhich );
if( pParaItem )
{
if( *pParaItem != *pTempItem )
return SFX_ITEM_DONTCARE;
}
else
{
pParaItem = pTempItem;
}
// set if theres no last item or if its the same
eParaState = SFX_ITEM_SET;
}
else if( bEmpty )
{
eParaState = SFX_ITEM_DEFAULT;
}
else if( bGaps )
{
// gaps and item not set in paragraph, thats a dont care
return SFX_ITEM_DONTCARE;
}
}
else
{
eParaState = SFX_ITEM_SET;
}
*/
if( bEmpty )
eParaState = SFX_ITEM_DEFAULT;
else if( bGaps )
eParaState = SFX_ITEM_DONTCARE;
else
eParaState = SFX_ITEM_SET;
// if we already found an item check if we found the same
if( pLastItem )
{
if( (pParaItem == NULL) || (*pLastItem != *pParaItem) )
return SFX_ITEM_DONTCARE;
}
else
{
pLastItem = pParaItem;
eState = eParaState;
}
}
return eState;
}
USHORT SmTextForwarder::GetItemState( const ESelection& rSel, USHORT nWhich ) const
{
return GetSvxEditEngineItemState( rEditEngine, rSel, nWhich );
}
USHORT SmTextForwarder::GetItemState( USHORT nPara, USHORT nWhich ) const
{
const SfxItemSet& rSet = rEditEngine.GetParaAttribs( nPara );
return rSet.GetItemState( nWhich );
}
LanguageType SmTextForwarder::GetLanguage( USHORT nPara, USHORT nIndex ) const
{
return rEditEngine.GetLanguage(nPara, nIndex);
}
USHORT SmTextForwarder::GetFieldCount( USHORT nPara ) const
{
return rEditEngine.GetFieldCount(nPara);
}
EFieldInfo SmTextForwarder::GetFieldInfo( USHORT nPara, USHORT nField ) const
{
return rEditEngine.GetFieldInfo( nPara, nField );
}
EBulletInfo SmTextForwarder::GetBulletInfo( USHORT nPara ) const
{
return EBulletInfo();
}
Rectangle SmTextForwarder::GetCharBounds( USHORT nPara, USHORT nIndex ) const
{
return rEditEngine.GetCharacterBounds( EPosition(nPara, nIndex) );
}
Rectangle SmTextForwarder::GetParaBounds( USHORT nPara ) const
{
const Point aPnt = rEditEngine.GetDocPosTopLeft( nPara );
const ULONG nWidth = rEditEngine.CalcTextWidth();
const ULONG nHeight = rEditEngine.GetTextHeight( nPara );
return Rectangle( aPnt.X(), aPnt.Y(), aPnt.X() + nWidth, aPnt.Y() + nHeight );
}
MapMode SmTextForwarder::GetMapMode() const
{
return rEditEngine.GetRefMapMode();
}
OutputDevice* SmTextForwarder::GetRefDevice() const
{
return rEditEngine.GetRefDevice();
}
sal_Bool SmTextForwarder::GetIndexAtPoint( const Point& rPos, USHORT& nPara, USHORT& nIndex ) const
{
EPosition aDocPos = rEditEngine.FindDocPosition( rPos );
nPara = aDocPos.nPara;
nIndex = aDocPos.nIndex;
return sal_True;
}
sal_Bool SmTextForwarder::GetWordIndices( USHORT nPara, USHORT nIndex, USHORT& nStart, USHORT& nEnd ) const
{
ESelection aRes = rEditEngine.GetWord( ESelection(nPara, nIndex, nPara, nIndex), com::sun::star::i18n::WordType::DICTIONARY_WORD );
if( aRes.nStartPara == nPara &&
aRes.nStartPara == aRes.nEndPara )
{
nStart = aRes.nStartPos;
nEnd = aRes.nEndPos;
return sal_True;
}
return sal_False;
}
USHORT SmTextForwarder::GetLineCount( USHORT nPara ) const
{
return rEditEngine.GetLineCount(nPara);
}
USHORT SmTextForwarder::GetLineLen( USHORT nPara, USHORT nLine ) const
{
return rEditEngine.GetLineLen(nPara, nLine);
}
sal_Bool SmTextForwarder::QuickFormatDoc( BOOL bFull )
{
rEditEngine.QuickFormatDoc();
return sal_True;
}
sal_Bool SmTextForwarder::Delete( const ESelection& rSelection )
{
rEditEngine.QuickDelete( rSelection );
rEditEngine.QuickFormatDoc();
return sal_True;
}
sal_Bool SmTextForwarder::InsertText( const String& rStr, const ESelection& rSelection )
{
rEditEngine.QuickInsertText( rStr, rSelection );
rEditEngine.QuickFormatDoc();
return sal_True;
}
//------------------------------------------------------------------------
SmEditViewForwarder::SmEditViewForwarder( EditView& rView ) :
rEditView( rView )
{
}
SmEditViewForwarder::~SmEditViewForwarder()
{
}
BOOL SmEditViewForwarder::IsValid() const
{
return sal_True;
}
Rectangle SmEditViewForwarder::GetVisArea() const
{
OutputDevice* pOutDev = rEditView.GetWindow();
if( pOutDev )
{
Rectangle aVisArea = rEditView.GetVisArea();
// figure out map mode from edit engine
EditEngine* pEditEngine = rEditView.GetEditEngine();
if( pEditEngine )
{
MapMode aMapMode(pOutDev->GetMapMode());
aVisArea = OutputDevice::LogicToLogic( aVisArea,
pEditEngine->GetRefMapMode(),
aMapMode.GetMapUnit() );
aMapMode.SetOrigin(Point());
return pOutDev->LogicToPixel( aVisArea, aMapMode );
}
}
return Rectangle();
}
Point SmEditViewForwarder::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const
{
OutputDevice* pOutDev = rEditView.GetWindow();
if( pOutDev )
{
MapMode aMapMode(pOutDev->GetMapMode());
Point aPoint( OutputDevice::LogicToLogic( rPoint, rMapMode,
aMapMode.GetMapUnit() ) );
aMapMode.SetOrigin(Point());
return pOutDev->LogicToPixel( aPoint, aMapMode );
}
return Point();
}
Point SmEditViewForwarder::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const
{
OutputDevice* pOutDev = rEditView.GetWindow();
if( pOutDev )
{
MapMode aMapMode(pOutDev->GetMapMode());
aMapMode.SetOrigin(Point());
Point aPoint( pOutDev->PixelToLogic( rPoint, aMapMode ) );
return OutputDevice::LogicToLogic( aPoint,
aMapMode.GetMapUnit(),
rMapMode );
}
return Point();
}
sal_Bool SmEditViewForwarder::GetSelection( ESelection& rSelection ) const
{
rSelection = rEditView.GetSelection();
return sal_True;
}
sal_Bool SmEditViewForwarder::SetSelection( const ESelection& rSelection )
{
rEditView.SetSelection( rSelection );
return sal_True;
}
sal_Bool SmEditViewForwarder::Copy()
{
rEditView.Copy();
return sal_True;
}
sal_Bool SmEditViewForwarder::Cut()
{
rEditView.Cut();
return sal_True;
}
sal_Bool SmEditViewForwarder::Paste()
{
rEditView.Paste();
return sal_True;
}
//------------------------------------------------------------------------
SmEditAccessible::SmEditAccessible( SmEditWindow *pEditWin ) :
pWin (pEditWin),
aAccEventListeners (aListenerMutex),
pTextHelper (0)
{
DBG_ASSERT( pWin, "SmEditAccessible: window missing" );
//++aRefCount;
}
SmEditAccessible::SmEditAccessible( const SmEditAccessible &rSmAcc ) :
aAccEventListeners (aListenerMutex)
{
//vos::OGuard aGuard(Application::GetSolarMutex());
pWin = rSmAcc.pWin;
DBG_ASSERT( pWin, "SmEditAccessible: window missing" );
//++aRefCount;
}
SmEditAccessible::~SmEditAccessible()
{
delete pTextHelper;
/*
vos::OGuard aGuard(Application::GetSolarMutex());
if (--aRefCount == 0)
{
}
*/
}
void SmEditAccessible::Init()
{
DBG_ASSERT( pWin, "SmEditAccessible: window missing" );
if (pWin)
{
EditEngine *pEditEngine = pWin->GetEditEngine();
EditView *pEditView = pWin->GetEditView();
if (pEditEngine && pEditView)
{
::std::auto_ptr< SvxEditSource > pEditSource(
new SmEditSource( pWin, *pEditEngine, *pEditView ) );
pTextHelper = new accessibility::AccessibleTextHelper( this, pEditSource );
}
}
}
SmDocShell * SmEditAccessible::GetDoc_Impl()
{
SmViewShell *pView = pWin ? pWin->GetView() : 0;
return pView ? pView->GetDoc() : 0;
}
void SmEditAccessible::ClearWin()
{
pWin = 0; // implicitly results in AccessibleStateType::DEFUNC set
delete pTextHelper; pTextHelper = 0;
EventObject aEvtObj;
aEvtObj.Source = (XAccessible *) this;
aAccEventListeners.disposeAndClear( aEvtObj );
}
// XAccessible
uno::Reference< XAccessibleContext > SAL_CALL SmEditAccessible::getAccessibleContext( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return this;
}
// XAccessibleComponent
sal_Bool SAL_CALL SmEditAccessible::contains( const awt::Point& aPoint )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Size aSz( pWin->GetSizePixel() );
return aPoint.X >= 0 && aPoint.Y >= 0 &&
aPoint.X < aSz.Width() && aPoint.Y < aSz.Height();
}
uno::Reference< XAccessible > SAL_CALL SmEditAccessible::getAccessibleAt( const awt::Point& aPoint )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pTextHelper)
throw RuntimeException();
return pTextHelper->GetAt( aPoint );
}
awt::Rectangle SAL_CALL SmEditAccessible::getBounds( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Point aPt( pWin->GetPosPixel() );
Size aSz( pWin->GetSizePixel() );
return awt::Rectangle( aPt.X(), aPt.Y(), aSz.Width(), aSz.Height() );
}
awt::Point SAL_CALL SmEditAccessible::getLocation( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Point aPt( pWin->GetPosPixel() );
return awt::Point( aPt.X(), aPt.Y() );
}
awt::Point SAL_CALL SmEditAccessible::getLocationOnScreen( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Point aPt( pWin->OutputToAbsoluteScreenPixel( Point() ) );
return awt::Point( aPt.X(), aPt.Y() );
}
awt::Size SAL_CALL SmEditAccessible::getSize( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Size aSz( pWin->GetSizePixel() );
return awt::Size( aSz.Width(), aSz.Height() );
}
sal_Bool SAL_CALL SmEditAccessible::isShowing( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
return pWin->IsVisible();
}
sal_Bool SAL_CALL SmEditAccessible::isVisible( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
return pWin->IsReallyVisible();
}
sal_Bool SAL_CALL SmEditAccessible::isFocusTraversable( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return TRUE;
}
void SAL_CALL SmEditAccessible::grabFocus( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
pWin->GrabFocus();
}
uno::Any SAL_CALL SmEditAccessible::getAccessibleKeyBinding( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return uno::Any();
}
// XAccessibleContext
sal_Int32 SAL_CALL SmEditAccessible::getAccessibleChildCount( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pTextHelper)
throw RuntimeException();
return pTextHelper->GetChildCount();
}
uno::Reference< XAccessible > SAL_CALL SmEditAccessible::getAccessibleChild( sal_Int32 i )
throw (IndexOutOfBoundsException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pTextHelper)
throw RuntimeException();
return pTextHelper->GetChild( i );
}
uno::Reference< XAccessible > SAL_CALL SmEditAccessible::getAccessibleParent( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
if (!pWin)
throw RuntimeException();
Window *pAccParent = pWin->GetAccessibleParentWindow();
DBG_ASSERT( pAccParent, "accessible parent missing" );
return pAccParent ? pAccParent->GetAccessible() : Reference< XAccessible >();
}
sal_Int32 SAL_CALL SmEditAccessible::getAccessibleIndexInParent( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
sal_Int32 nIdx = -1;
Window *pAccParent = pWin ? pWin->GetAccessibleParentWindow() : 0;
if (pAccParent)
{
USHORT nCnt = pAccParent->GetAccessibleChildWindowCount();
for (USHORT i = 0; i < nCnt && nIdx == -1; ++i)
if (pAccParent->GetAccessibleChildWindow( i ) == pWin)
nIdx = i;
}
return nIdx;
}
sal_Int16 SAL_CALL SmEditAccessible::getAccessibleRole( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return AccessibleRole::PANEL /*TEXT ?*/;
}
rtl::OUString SAL_CALL SmEditAccessible::getAccessibleDescription( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
SmDocShell *pDoc = GetDoc_Impl();
return pDoc ? OUString(pDoc->GetText()) : OUString();
}
rtl::OUString SAL_CALL SmEditAccessible::getAccessibleName( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return String( SmResId(RID_DOCUMENTSTR) );
}
uno::Reference< XAccessibleRelationSet > SAL_CALL SmEditAccessible::getAccessibleRelationSet( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
return 0; // no relation set
}
uno::Reference< XAccessibleStateSet > SAL_CALL SmEditAccessible::getAccessibleStateSet( )
throw (RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
::utl::AccessibleStateSetHelper *pStateSet =
new ::utl::AccessibleStateSetHelper;
Reference<XAccessibleStateSet> xStateSet( pStateSet );
if (!pWin || !pTextHelper)
pStateSet->AddState( AccessibleStateType::DEFUNC );
else
{
//pStateSet->AddState( AccessibleStateType::EDITABLE );
pStateSet->AddState( AccessibleStateType::MULTILINE );
//pStateSet->AddState( AccessibleStateType::HORIZONTAL );
//pStateSet->AddState( AccessibleStateType::TRANSIENT );
pStateSet->AddState( AccessibleStateType::ENABLED );
pStateSet->AddState( AccessibleStateType::FOCUSABLE );
if (pWin->HasFocus())
pStateSet->AddState( AccessibleStateType::FOCUSED );
if (pWin->IsActive())
pStateSet->AddState( AccessibleStateType::ACTIVE );
if (pWin->IsVisible())
pStateSet->AddState( AccessibleStateType::SHOWING );
if (pWin->IsReallyVisible())
pStateSet->AddState( AccessibleStateType::VISIBLE );
if (COL_TRANSPARENT != pWin->GetBackground().GetColor().GetColor())
pStateSet->AddState( AccessibleStateType::OPAQUE );
}
return xStateSet;
}
Locale SAL_CALL SmEditAccessible::getLocale( )
throw (IllegalAccessibleComponentStateException, RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
// should be the document language...
// We use the language of the localized symbol names here.
return Application::GetSettings().GetUILocale();
}
// XAccessibleEventBroadcaster
void SAL_CALL SmEditAccessible::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
throw (RuntimeException)
{
//vos::OGuard aGuard(Application::GetSolarMutex());
if (pTextHelper) // not disposing (about to destroy view shell)
pTextHelper->AddEventListener( xListener );
}
void SAL_CALL SmEditAccessible::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
throw (RuntimeException)
{
//vos::OGuard aGuard(Application::GetSolarMutex());
if (pTextHelper) // not disposing (about to destroy view shell)
pTextHelper->RemoveEventListener( xListener );
}
//////////////////////////////////////////////////////////////////////
2002-05-24 06:48:49 +00:00