Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "scitems.hxx"
21 : #include <editeng/eeitem.hxx>
22 : #include <tools/gen.hxx>
23 : #include "AccessibleText.hxx"
24 : #include "editsrc.hxx"
25 : #include "AccessiblePreviewCell.hxx"
26 : #include "AccessibilityHints.hxx"
27 : #include "prevwsh.hxx"
28 : #include "prevloc.hxx"
29 : #include "document.hxx"
30 : #include <svx/AccessibleTextHelper.hxx>
31 : #include <unotools/accessiblestatesethelper.hxx>
32 : #include <editeng/brushitem.hxx>
33 : #include <vcl/window.hxx>
34 : #include <vcl/svapp.hxx>
35 : #include <toolkit/helper/convert.hxx>
36 : #include <comphelper/servicehelper.hxx>
37 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38 :
39 : using namespace ::com::sun::star;
40 : using namespace ::com::sun::star::accessibility;
41 :
42 : //===== internal ============================================================
43 :
44 12 : ScAccessiblePreviewCell::ScAccessiblePreviewCell( const ::com::sun::star::uno::Reference<
45 : ::com::sun::star::accessibility::XAccessible>& rxParent,
46 : ScPreviewShell* pViewShell, /* const */ ScAddress& rCellAddress,
47 : sal_Int32 nIndex ) :
48 : ScAccessibleCellBase( rxParent, ( pViewShell ? pViewShell->GetDocument() : NULL ), rCellAddress, nIndex ),
49 : mpViewShell( pViewShell ),
50 12 : mpTextHelper(NULL)
51 : {
52 12 : if (mpViewShell)
53 12 : mpViewShell->AddAccessibilityObject(*this);
54 12 : }
55 :
56 36 : ScAccessiblePreviewCell::~ScAccessiblePreviewCell()
57 : {
58 12 : if (!ScAccessibleContextBase::IsDefunc() && !rBHelper.bInDispose)
59 : {
60 : // increment refcount to prevent double call off dtor
61 0 : osl_atomic_increment( &m_refCount );
62 : // call dispose to inform object which have a weak reference to this object
63 0 : dispose();
64 : }
65 24 : }
66 :
67 12 : void SAL_CALL ScAccessiblePreviewCell::disposing()
68 : {
69 12 : SolarMutexGuard aGuard;
70 12 : if (mpViewShell)
71 : {
72 12 : mpViewShell->RemoveAccessibilityObject(*this);
73 12 : mpViewShell = NULL;
74 : }
75 :
76 12 : if (mpTextHelper)
77 7 : DELETEZ(mpTextHelper);
78 :
79 12 : ScAccessibleCellBase::disposing();
80 12 : }
81 :
82 21 : void ScAccessiblePreviewCell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
83 : {
84 21 : if (rHint.ISA( SfxSimpleHint ))
85 : {
86 10 : const SfxSimpleHint& rRef = (const SfxSimpleHint&)rHint;
87 10 : if (rRef.GetId() == SC_HINT_ACC_VISAREACHANGED)
88 : {
89 10 : if (mpTextHelper)
90 5 : mpTextHelper->UpdateChildren();
91 : }
92 : }
93 :
94 21 : ScAccessibleContextBase::Notify(rBC, rHint);
95 21 : }
96 :
97 : //===== XAccessibleComponent ============================================
98 :
99 0 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleAtPoint( const awt::Point& rPoint )
100 : throw (uno::RuntimeException)
101 : {
102 0 : uno::Reference<XAccessible> xRet;
103 0 : if (containsPoint(rPoint))
104 : {
105 0 : SolarMutexGuard aGuard;
106 0 : IsObjectValid();
107 :
108 0 : if(!mpTextHelper)
109 0 : CreateTextHelper();
110 :
111 0 : xRet = mpTextHelper->GetAt(rPoint);
112 : }
113 :
114 0 : return xRet;
115 : }
116 :
117 0 : void SAL_CALL ScAccessiblePreviewCell::grabFocus() throw (uno::RuntimeException)
118 : {
119 0 : SolarMutexGuard aGuard;
120 0 : IsObjectValid();
121 0 : if (getAccessibleParent().is())
122 : {
123 0 : uno::Reference<XAccessibleComponent> xAccessibleComponent(getAccessibleParent()->getAccessibleContext(), uno::UNO_QUERY);
124 0 : if (xAccessibleComponent.is())
125 0 : xAccessibleComponent->grabFocus();
126 0 : }
127 0 : }
128 :
129 : //===== XAccessibleContext ==============================================
130 :
131 17 : sal_Int32 SAL_CALL ScAccessiblePreviewCell::getAccessibleChildCount() throw(uno::RuntimeException)
132 : {
133 17 : SolarMutexGuard aGuard;
134 17 : IsObjectValid();
135 17 : if (!mpTextHelper)
136 7 : CreateTextHelper();
137 17 : return mpTextHelper->GetChildCount();
138 : }
139 :
140 8 : uno::Reference< XAccessible > SAL_CALL ScAccessiblePreviewCell::getAccessibleChild(sal_Int32 nIndex)
141 : throw (uno::RuntimeException, lang::IndexOutOfBoundsException)
142 : {
143 8 : SolarMutexGuard aGuard;
144 8 : IsObjectValid();
145 8 : if (!mpTextHelper)
146 0 : CreateTextHelper();
147 8 : return mpTextHelper->GetChild(nIndex);
148 : }
149 :
150 9 : uno::Reference<XAccessibleStateSet> SAL_CALL ScAccessiblePreviewCell::getAccessibleStateSet()
151 : throw(uno::RuntimeException)
152 : {
153 9 : SolarMutexGuard aGuard;
154 :
155 18 : uno::Reference<XAccessibleStateSet> xParentStates;
156 9 : if (getAccessibleParent().is())
157 : {
158 9 : uno::Reference<XAccessibleContext> xParentContext = getAccessibleParent()->getAccessibleContext();
159 9 : xParentStates = xParentContext->getAccessibleStateSet();
160 : }
161 9 : utl::AccessibleStateSetHelper* pStateSet = new utl::AccessibleStateSetHelper();
162 9 : if (IsDefunc(xParentStates))
163 0 : pStateSet->AddState(AccessibleStateType::DEFUNC);
164 : else
165 : {
166 9 : pStateSet->AddState(AccessibleStateType::ENABLED);
167 9 : pStateSet->AddState(AccessibleStateType::MULTI_LINE);
168 9 : if (IsOpaque(xParentStates))
169 0 : pStateSet->AddState(AccessibleStateType::OPAQUE);
170 9 : if (isShowing())
171 0 : pStateSet->AddState(AccessibleStateType::SHOWING);
172 9 : pStateSet->AddState(AccessibleStateType::TRANSIENT);
173 9 : if (isVisible())
174 9 : pStateSet->AddState(AccessibleStateType::VISIBLE);
175 : // MANAGES_DESCENDANTS (for paragraphs)
176 9 : pStateSet->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
177 : }
178 18 : return pStateSet;
179 : }
180 :
181 : //===== XServiceInfo ====================================================
182 :
183 6 : OUString SAL_CALL ScAccessiblePreviewCell::getImplementationName() throw(uno::RuntimeException)
184 : {
185 6 : return OUString("ScAccessiblePreviewCell");
186 : }
187 :
188 0 : uno::Sequence<OUString> SAL_CALL ScAccessiblePreviewCell::getSupportedServiceNames()
189 : throw(uno::RuntimeException)
190 : {
191 0 : uno::Sequence< OUString > aSequence = ScAccessibleContextBase::getSupportedServiceNames();
192 0 : sal_Int32 nOldSize(aSequence.getLength());
193 0 : aSequence.realloc(nOldSize + 1);
194 0 : OUString* pNames = aSequence.getArray();
195 :
196 0 : pNames[nOldSize] = OUString("com.sun.star.table.AccessibleCellView");
197 :
198 0 : return aSequence;
199 : }
200 :
201 : //===== XTypeProvider =======================================================
202 :
203 : namespace
204 : {
205 : class theScAccessiblePreviewCellImplementationId : public rtl::Static< UnoTunnelIdInit, theScAccessiblePreviewCellImplementationId > {};
206 : }
207 :
208 : uno::Sequence<sal_Int8> SAL_CALL
209 0 : ScAccessiblePreviewCell::getImplementationId(void)
210 : throw (uno::RuntimeException)
211 : {
212 0 : return theScAccessiblePreviewCellImplementationId::get().getSeq();
213 : }
214 :
215 : //==== internal =========================================================
216 :
217 0 : Rectangle ScAccessiblePreviewCell::GetBoundingBoxOnScreen() const throw (uno::RuntimeException)
218 : {
219 0 : Rectangle aCellRect;
220 0 : if (mpViewShell)
221 : {
222 0 : mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
223 0 : Window* pWindow = mpViewShell->GetWindow();
224 0 : if (pWindow)
225 : {
226 0 : Rectangle aRect = pWindow->GetWindowExtentsRelative(NULL);
227 0 : aCellRect.setX(aCellRect.getX() + aRect.getX());
228 0 : aCellRect.setY(aCellRect.getY() + aRect.getY());
229 : }
230 : }
231 0 : return aCellRect;
232 : }
233 :
234 10 : Rectangle ScAccessiblePreviewCell::GetBoundingBox() const throw (uno::RuntimeException)
235 : {
236 10 : Rectangle aCellRect;
237 10 : if (mpViewShell)
238 : {
239 10 : mpViewShell->GetLocationData().GetCellPosition( maCellAddress, aCellRect );
240 10 : uno::Reference<XAccessible> xAccParent = const_cast<ScAccessiblePreviewCell*>(this)->getAccessibleParent();
241 10 : if (xAccParent.is())
242 : {
243 10 : uno::Reference<XAccessibleContext> xAccParentContext = xAccParent->getAccessibleContext();
244 20 : uno::Reference<XAccessibleComponent> xAccParentComp (xAccParentContext, uno::UNO_QUERY);
245 10 : if (xAccParentComp.is())
246 : {
247 10 : Rectangle aParentRect (VCLRectangle(xAccParentComp->getBounds()));
248 10 : aCellRect.setX(aCellRect.getX() - aParentRect.getX());
249 10 : aCellRect.setY(aCellRect.getY() - aParentRect.getY());
250 10 : }
251 10 : }
252 : }
253 10 : return aCellRect;
254 : }
255 :
256 9 : sal_Bool ScAccessiblePreviewCell::IsDefunc(
257 : const uno::Reference<XAccessibleStateSet>& rxParentStates)
258 : {
259 36 : return ScAccessibleContextBase::IsDefunc() || (mpDoc == NULL) || (mpViewShell == NULL) || !getAccessibleParent().is() ||
260 36 : (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
261 : }
262 :
263 1 : sal_Bool ScAccessiblePreviewCell::IsEditable(
264 : const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
265 : {
266 1 : return false;
267 : }
268 :
269 9 : sal_Bool ScAccessiblePreviewCell::IsOpaque(
270 : const uno::Reference<XAccessibleStateSet>& /* rxParentStates */)
271 : {
272 : // test whether there is a background color
273 : //! could be moved to ScAccessibleCellBase
274 :
275 9 : sal_Bool bOpaque(sal_True);
276 9 : if (mpDoc)
277 : {
278 : const SvxBrushItem* pItem = (const SvxBrushItem*)mpDoc->GetAttr(
279 9 : maCellAddress.Col(), maCellAddress.Row(), maCellAddress.Tab(), ATTR_BACKGROUND);
280 9 : if (pItem)
281 9 : bOpaque = pItem->GetColor() != COL_TRANSPARENT;
282 : }
283 9 : return bOpaque;
284 : }
285 :
286 7 : void ScAccessiblePreviewCell::CreateTextHelper()
287 : {
288 7 : if (!mpTextHelper)
289 : {
290 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
291 : ::std::auto_ptr < ScAccessibleTextData > pAccessiblePreviewCellTextData
292 7 : (new ScAccessiblePreviewCellTextData(mpViewShell, maCellAddress));
293 14 : ::std::auto_ptr< SvxEditSource > pEditSource (new ScAccessibilityEditSource(pAccessiblePreviewCellTextData));
294 : SAL_WNODEPRECATED_DECLARATIONS_POP
295 :
296 7 : mpTextHelper = new ::accessibility::AccessibleTextHelper( pEditSource );
297 7 : mpTextHelper->SetEventSource( this );
298 :
299 : // paragraphs in preview are transient
300 14 : ::accessibility::AccessibleTextHelper::VectorOfStates aChildStates;
301 7 : aChildStates.push_back( AccessibleStateType::TRANSIENT );
302 14 : mpTextHelper->SetAdditionalChildStates( aChildStates );
303 : }
304 100 : }
305 :
306 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|