1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessiblePreviewHeaderCell.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include "scitems.hxx"
34 #include <svx/eeitem.hxx>
35 #include <tools/gen.hxx>
36 #include "AccessibleText.hxx"
37 #include "editsrc.hxx"
38 #include <svx/AccessibleTextHelper.hxx>
39 #include "AccessiblePreviewHeaderCell.hxx"
40 #include "AccessibilityHints.hxx"
41 #include "prevwsh.hxx"
42 #include "unoguard.hxx"
43 #include "miscuno.hxx"
44 #include "prevloc.hxx"
45 #include "scresid.hxx"
50 #include <com/sun/star/accessibility/AccessibleRole.hpp>
51 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
53 #include <vcl/window.hxx>
54 #include <svtools/smplhint.hxx>
55 #include <unotools/accessiblestatesethelper.hxx>
56 #include <comphelper/sequence.hxx>
57 #include <toolkit/helper/convert.hxx>
59 using namespace ::com::sun::star
;
60 using namespace ::com::sun::star::accessibility
;
62 //===== internal ============================================================
64 ScAccessiblePreviewHeaderCell::ScAccessiblePreviewHeaderCell( const ::com::sun::star::uno::Reference
<
65 ::com::sun::star::accessibility::XAccessible
>& rxParent
,
66 ScPreviewShell
* pViewShell
,
67 const ScAddress
& rCellPos
, sal_Bool bIsColHdr
, sal_Bool bIsRowHdr
,
69 ScAccessibleContextBase( rxParent
, AccessibleRole::TABLE_CELL
),
70 mpViewShell( pViewShell
),
73 maCellPos( rCellPos
),
74 mbColumnHeader( bIsColHdr
),
75 mbRowHeader( bIsRowHdr
),
79 mpViewShell
->AddAccessibilityObject(*this);
82 ScAccessiblePreviewHeaderCell::~ScAccessiblePreviewHeaderCell()
85 mpViewShell
->RemoveAccessibilityObject(*this);
88 void SAL_CALL
ScAccessiblePreviewHeaderCell::disposing()
93 mpViewShell
->RemoveAccessibilityObject(*this);
98 DELETEZ (mpTableInfo
);
100 ScAccessibleContextBase::disposing();
103 //===== SfxListener =====================================================
105 void ScAccessiblePreviewHeaderCell::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
107 if (rHint
.ISA( SfxSimpleHint
))
109 const SfxSimpleHint
& rRef
= (const SfxSimpleHint
&)rHint
;
110 ULONG nId
= rRef
.GetId();
111 if (nId
== SC_HINT_ACC_VISAREACHANGED
)
114 mpTextHelper
->UpdateChildren();
116 else if ( nId
== SFX_HINT_DATACHANGED
)
118 // column / row layout may change with any document change,
119 // so it must be invalidated
120 DELETEZ( mpTableInfo
);
124 ScAccessibleContextBase::Notify(rBC
, rHint
);
127 //===== XInterface =====================================================
129 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::queryInterface( uno::Type
const & rType
)
130 throw (uno::RuntimeException
)
132 uno::Any
aAny (ScAccessiblePreviewHeaderCellImpl::queryInterface(rType
));
133 return aAny
.hasValue() ? aAny
: ScAccessibleContextBase::queryInterface(rType
);
136 void SAL_CALL
ScAccessiblePreviewHeaderCell::acquire()
139 ScAccessibleContextBase::acquire();
142 void SAL_CALL
ScAccessiblePreviewHeaderCell::release()
145 ScAccessibleContextBase::release();
148 //===== XAccessibleValue ================================================
150 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::getCurrentValue() throw (uno::RuntimeException
)
157 fValue
= maCellPos
.Col();
159 fValue
= maCellPos
.Row();
166 sal_Bool SAL_CALL
ScAccessiblePreviewHeaderCell::setCurrentValue( const uno::Any
& /* aNumber */ )
167 throw (uno::RuntimeException
)
169 // it is not possible to set a value
173 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::getMaximumValue() throw (uno::RuntimeException
)
188 uno::Any SAL_CALL
ScAccessiblePreviewHeaderCell::getMinimumValue() throw (uno::RuntimeException
)
196 //===== XAccessibleComponent ============================================
198 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleAtPoint( const awt::Point
& rPoint
)
199 throw (uno::RuntimeException
)
201 uno::Reference
<XAccessible
> xRet
;
202 if (containsPoint(rPoint
))
210 xRet
= mpTextHelper
->GetAt(rPoint
);
216 void SAL_CALL
ScAccessiblePreviewHeaderCell::grabFocus() throw (uno::RuntimeException
)
220 if (getAccessibleParent().is())
222 uno::Reference
<XAccessibleComponent
> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY
);
223 if (xAccessibleComponent
.is())
224 xAccessibleComponent
->grabFocus();
228 //===== XAccessibleContext ==============================================
230 sal_Int32 SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleChildCount() throw(uno::RuntimeException
)
236 return mpTextHelper
->GetChildCount();
239 uno::Reference
< XAccessible
> SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleChild(sal_Int32 nIndex
)
240 throw (uno::RuntimeException
, lang::IndexOutOfBoundsException
)
246 return mpTextHelper
->GetChild(nIndex
);
249 sal_Int32 SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleIndexInParent() throw (uno::RuntimeException
)
254 uno::Reference
<XAccessibleStateSet
> SAL_CALL
ScAccessiblePreviewHeaderCell::getAccessibleStateSet()
255 throw(uno::RuntimeException
)
259 uno::Reference
<XAccessibleStateSet
> xParentStates
;
260 if (getAccessibleParent().is())
262 uno::Reference
<XAccessibleContext
> xParentContext
= getAccessibleParent()->getAccessibleContext();
263 xParentStates
= xParentContext
->getAccessibleStateSet();
265 utl::AccessibleStateSetHelper
* pStateSet
= new utl::AccessibleStateSetHelper();
266 if (IsDefunc(xParentStates
))
267 pStateSet
->AddState(AccessibleStateType::DEFUNC
);
270 pStateSet
->AddState(AccessibleStateType::ENABLED
);
271 pStateSet
->AddState(AccessibleStateType::MULTI_LINE
);
273 pStateSet
->AddState(AccessibleStateType::SHOWING
);
274 pStateSet
->AddState(AccessibleStateType::TRANSIENT
);
276 pStateSet
->AddState(AccessibleStateType::VISIBLE
);
281 //===== XServiceInfo ====================================================
283 rtl::OUString SAL_CALL
ScAccessiblePreviewHeaderCell::getImplementationName() throw(uno::RuntimeException
)
285 return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScAccessiblePreviewHeaderCell"));
288 uno::Sequence
<rtl::OUString
> SAL_CALL
ScAccessiblePreviewHeaderCell::getSupportedServiceNames()
289 throw(uno::RuntimeException
)
291 uno::Sequence
< ::rtl::OUString
> aSequence
= ScAccessibleContextBase::getSupportedServiceNames();
292 sal_Int32
nOldSize(aSequence
.getLength());
293 aSequence
.realloc(nOldSize
+ 1);
294 ::rtl::OUString
* pNames
= aSequence
.getArray();
296 pNames
[nOldSize
] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.AccessibleCellView"));
301 //===== XTypeProvider =======================================================
303 uno::Sequence
< uno::Type
> SAL_CALL
ScAccessiblePreviewHeaderCell::getTypes()
304 throw (uno::RuntimeException
)
306 return comphelper::concatSequences(ScAccessiblePreviewHeaderCellImpl::getTypes(), ScAccessibleContextBase::getTypes());
309 uno::Sequence
<sal_Int8
> SAL_CALL
310 ScAccessiblePreviewHeaderCell::getImplementationId(void)
311 throw (uno::RuntimeException
)
315 static uno::Sequence
<sal_Int8
> aId
;
316 if (aId
.getLength() == 0)
319 rtl_createUuid (reinterpret_cast<sal_uInt8
*>(aId
.getArray()), 0, sal_True
);
324 //==== internal =========================================================
326 Rectangle
ScAccessiblePreviewHeaderCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException
)
334 const ScPreviewColRowInfo
& rColInfo
= mpTableInfo
->GetColInfo()[maCellPos
.Col()];
335 const ScPreviewColRowInfo
& rRowInfo
= mpTableInfo
->GetRowInfo()[maCellPos
.Row()];
337 aCellRect
= Rectangle( rColInfo
.nPixelStart
, rRowInfo
.nPixelStart
, rColInfo
.nPixelEnd
, rRowInfo
.nPixelEnd
);
342 Window
* pWindow
= mpViewShell
->GetWindow();
345 Rectangle aRect
= pWindow
->GetWindowExtentsRelative(NULL
);
346 aCellRect
.setX(aCellRect
.getX() + aRect
.getX());
347 aCellRect
.setY(aCellRect
.getY() + aRect
.getY());
353 Rectangle
ScAccessiblePreviewHeaderCell::GetBoundingBox() const throw (uno::RuntimeException
)
359 const ScPreviewColRowInfo
& rColInfo
= mpTableInfo
->GetColInfo()[maCellPos
.Col()];
360 const ScPreviewColRowInfo
& rRowInfo
= mpTableInfo
->GetRowInfo()[maCellPos
.Row()];
362 Rectangle
aCellRect( rColInfo
.nPixelStart
, rRowInfo
.nPixelStart
, rColInfo
.nPixelEnd
, rRowInfo
.nPixelEnd
);
363 uno::Reference
<XAccessible
> xAccParent
= const_cast<ScAccessiblePreviewHeaderCell
*>(this)->getAccessibleParent();
366 uno::Reference
<XAccessibleContext
> xAccParentContext
= xAccParent
->getAccessibleContext();
367 uno::Reference
<XAccessibleComponent
> xAccParentComp (xAccParentContext
, uno::UNO_QUERY
);
368 if (xAccParentComp
.is())
370 Rectangle
aParentRect (VCLRectangle(xAccParentComp
->getBounds()));
371 aCellRect
.setX(aCellRect
.getX() - aParentRect
.getX());
372 aCellRect
.setY(aCellRect
.getY() - aParentRect
.getY());
380 rtl::OUString SAL_CALL
ScAccessiblePreviewHeaderCell::createAccessibleDescription() throw(uno::RuntimeException
)
382 rtl::OUString sDescription
= String(ScResId(STR_ACC_HEADERCELL_DESCR
));
386 rtl::OUString SAL_CALL
ScAccessiblePreviewHeaderCell::createAccessibleName() throw(uno::RuntimeException
)
388 rtl::OUString sName
= String(ScResId(STR_ACC_HEADERCELL_NAME
));
390 if ( mbColumnHeader
)
394 //! name for corner cell?
396 // sName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Column/Row Header"));
400 // name of column header
401 sName
+= ScColToAlpha( maCellPos
.Col() );
406 // name of row header
407 sName
+= rtl::OUString::valueOf( (sal_Int32
) ( maCellPos
.Row() + 1 ) );
413 sal_Bool
ScAccessiblePreviewHeaderCell::IsDefunc( const uno::Reference
<XAccessibleStateSet
>& rxParentStates
)
415 return ScAccessibleContextBase::IsDefunc() || (mpViewShell
== NULL
) || !getAccessibleParent().is() ||
416 (rxParentStates
.is() && rxParentStates
->contains(AccessibleStateType::DEFUNC
));
419 void ScAccessiblePreviewHeaderCell::CreateTextHelper()
423 ::std::auto_ptr
< ScAccessibleTextData
> pAccessiblePreviewHeaderCellTextData
424 (new ScAccessiblePreviewHeaderCellTextData(mpViewShell
, String(getAccessibleName()), maCellPos
, mbColumnHeader
, mbRowHeader
));
425 ::std::auto_ptr
< SvxEditSource
> pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewHeaderCellTextData
));
427 mpTextHelper
= new ::accessibility::AccessibleTextHelper(pEditSource
);
428 mpTextHelper
->SetEventSource(this);
432 void ScAccessiblePreviewHeaderCell::FillTableInfo() const
434 if ( mpViewShell
&& !mpTableInfo
)
437 Window
* pWindow
= mpViewShell
->GetWindow();
439 aOutputSize
= pWindow
->GetOutputSizePixel();
441 Rectangle
aVisRect( aPoint
, aOutputSize
);
443 mpTableInfo
= new ScPreviewTableInfo
;
444 mpViewShell
->GetLocationData().GetTableInfo( aVisRect
, *mpTableInfo
);