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 :
21 : #include <accfrmobj.hxx>
22 :
23 : #include <accmap.hxx>
24 : #include <acccontext.hxx>
25 :
26 : #include <viewsh.hxx>
27 : #include <rootfrm.hxx>
28 : #include <flyfrm.hxx>
29 : #include <pagefrm.hxx>
30 : #include <cellfrm.hxx>
31 : #include <swtable.hxx>
32 : #include <dflyobj.hxx>
33 : #include <frmfmt.hxx>
34 : #include <fmtanchr.hxx>
35 : #include <dcontact.hxx>
36 :
37 : #include <vcl/window.hxx>
38 :
39 : namespace sw { namespace access {
40 :
41 1383 : SwAccessibleChild::SwAccessibleChild()
42 : : mpFrm( 0 )
43 : , mpDrawObj( 0 )
44 1383 : , mpWindow( 0 )
45 1383 : {}
46 :
47 0 : SwAccessibleChild::SwAccessibleChild( const SdrObject* pDrawObj )
48 : : mpFrm( 0 )
49 : , mpDrawObj( 0 )
50 0 : , mpWindow( 0 )
51 : {
52 0 : Init( pDrawObj );
53 0 : }
54 :
55 9541 : SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm )
56 : : mpFrm( 0 )
57 : , mpDrawObj( 0 )
58 9541 : , mpWindow( 0 )
59 : {
60 9541 : Init( pFrm );
61 9541 : }
62 :
63 67 : SwAccessibleChild::SwAccessibleChild( Window* pWindow )
64 : : mpFrm( 0 )
65 : , mpDrawObj( 0 )
66 67 : , mpWindow( 0 )
67 : {
68 67 : Init( pWindow );
69 67 : }
70 :
71 :
72 59 : SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm,
73 : const SdrObject* pDrawObj,
74 : Window* pWindow )
75 : {
76 59 : if ( pFrm )
77 : {
78 59 : Init( pFrm );
79 : }
80 0 : else if ( pDrawObj )
81 : {
82 0 : Init( pDrawObj );
83 : }
84 0 : else if ( pWindow )
85 : {
86 0 : Init( pWindow );
87 : }
88 : OSL_ENSURE( (!pFrm || pFrm == mpFrm) &&
89 : (!pDrawObj || pDrawObj == mpDrawObj) &&
90 : (!pWindow || pWindow == mpWindow),
91 : "invalid frame/object/window combination" );
92 :
93 59 : }
94 :
95 149 : void SwAccessibleChild::Init( const SdrObject* pDrawObj )
96 : {
97 149 : mpDrawObj = pDrawObj;
98 28 : mpFrm = mpDrawObj && mpDrawObj->ISA(SwVirtFlyDrawObj)
99 28 : ? static_cast < const SwVirtFlyDrawObj * >( mpDrawObj )->GetFlyFrm()
100 177 : : 0;
101 149 : mpWindow = 0;
102 149 : }
103 :
104 14526 : void SwAccessibleChild::Init( const SwFrm* pFrm )
105 : {
106 14526 : mpFrm = pFrm;
107 13940 : mpDrawObj = mpFrm && mpFrm->IsFlyFrm()
108 25 : ? static_cast < const SwFlyFrm * >( mpFrm )->GetVirtDrawObj()
109 14551 : : 0;
110 14526 : mpWindow = 0;
111 14526 : }
112 :
113 67 : void SwAccessibleChild::Init( Window* pWindow )
114 : {
115 67 : mpWindow = pWindow;
116 67 : mpFrm = 0;
117 67 : mpDrawObj = 0;
118 67 : }
119 :
120 7477 : bool SwAccessibleChild::IsAccessible( sal_Bool bPagePreview ) const
121 : {
122 7477 : bool bRet( false );
123 :
124 7477 : if ( mpFrm )
125 : {
126 12250 : bRet = mpFrm->IsAccessibleFrm() &&
127 4920 : ( !mpFrm->IsCellFrm() ||
128 4920 : static_cast<const SwCellFrm *>( mpFrm )->GetTabBox()->GetSttNd() != 0 ) &&
129 19915 : !mpFrm->IsInCoveredCell() &&
130 4773 : ( bPagePreview ||
131 12250 : !mpFrm->IsPageFrm() );
132 : }
133 0 : else if ( mpDrawObj )
134 : {
135 0 : bRet = true;
136 : }
137 0 : else if ( mpWindow )
138 : {
139 0 : bRet = true;
140 : }
141 :
142 7477 : return bRet;
143 : }
144 :
145 388 : bool SwAccessibleChild::IsBoundAsChar() const
146 : {
147 388 : bool bRet( false );
148 :
149 388 : if ( mpFrm )
150 : {
151 412 : bRet = mpFrm->IsFlyFrm() &&
152 412 : static_cast< const SwFlyFrm *>(mpFrm)->IsFlyInCntFrm();
153 : }
154 0 : else if ( mpDrawObj )
155 : {
156 0 : const SwFrmFmt* mpFrmFmt = ::FindFrmFmt( mpDrawObj );
157 : bRet = mpFrmFmt
158 0 : ? (FLY_AS_CHAR == mpFrmFmt->GetAnchor().GetAnchorId())
159 0 : : false;
160 : }
161 0 : else if ( mpWindow )
162 : {
163 0 : bRet = false;
164 : }
165 :
166 388 : return bRet;
167 : }
168 :
169 156 : SwAccessibleChild::SwAccessibleChild( const SwAccessibleChild& r )
170 : : mpFrm( r.mpFrm )
171 : , mpDrawObj( r.mpDrawObj )
172 156 : , mpWindow( r.mpWindow )
173 156 : {}
174 :
175 172 : SwAccessibleChild& SwAccessibleChild::operator=( const SwAccessibleChild& r )
176 : {
177 172 : mpDrawObj = r.mpDrawObj;
178 172 : mpFrm = r.mpFrm;
179 172 : mpWindow = r.mpWindow;
180 :
181 172 : return *this;
182 : }
183 :
184 149 : SwAccessibleChild& SwAccessibleChild::operator=( const SdrObject* pDrawObj )
185 : {
186 149 : Init( pDrawObj );
187 149 : return *this;
188 : }
189 :
190 4926 : SwAccessibleChild& SwAccessibleChild::operator=( const SwFrm* pFrm )
191 : {
192 4926 : Init( pFrm );
193 4926 : return *this;
194 : }
195 :
196 0 : SwAccessibleChild& SwAccessibleChild::operator=( Window* pWindow )
197 : {
198 0 : Init( pWindow );
199 0 : return *this;
200 : }
201 :
202 1278 : bool SwAccessibleChild::operator==( const SwAccessibleChild& r ) const
203 : {
204 1869 : return mpFrm == r.mpFrm &&
205 1869 : mpDrawObj == r.mpDrawObj &&
206 1869 : mpWindow == r.mpWindow;
207 : }
208 :
209 931 : bool SwAccessibleChild::IsValid() const
210 : {
211 1481 : return mpFrm != 0 ||
212 1481 : mpDrawObj != 0 ||
213 1481 : mpWindow != 0;
214 : }
215 :
216 667 : const SdrObject* SwAccessibleChild::GetDrawObject() const
217 : {
218 667 : return mpDrawObj;
219 : }
220 :
221 17754 : const SwFrm *SwAccessibleChild::GetSwFrm() const
222 : {
223 17754 : return mpFrm;
224 : }
225 :
226 652 : Window* SwAccessibleChild::GetWindow() const
227 : {
228 652 : return mpWindow;
229 : }
230 :
231 618 : bool SwAccessibleChild::IsVisibleChildrenOnly() const
232 : {
233 618 : bool bRet( false );
234 :
235 618 : if ( !mpFrm )
236 : {
237 0 : bRet = true;
238 : }
239 : else
240 : {
241 1611 : bRet = mpFrm->IsRootFrm() ||
242 1016 : !( mpFrm->IsTabFrm() ||
243 488 : mpFrm->IsInTab() ||
244 375 : ( IsBoundAsChar() &&
245 993 : static_cast<const SwFlyFrm*>(mpFrm)->GetAnchorFrm()->IsInTab() ) );
246 : }
247 :
248 618 : return bRet;
249 : }
250 :
251 544 : SwRect SwAccessibleChild::GetBox( const SwAccessibleMap& rAccMap ) const
252 : {
253 544 : SwRect aBox;
254 :
255 544 : if ( mpFrm )
256 : {
257 655 : if ( mpFrm->IsPageFrm() &&
258 111 : static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() )
259 : {
260 0 : aBox = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 1, 1 );
261 : }
262 544 : else if ( mpFrm->IsTabFrm() )
263 : {
264 17 : aBox = SwRect( mpFrm->Frm() );
265 17 : aBox.Intersection( mpFrm->GetUpper()->Frm() );
266 : }
267 : else
268 : {
269 527 : aBox = mpFrm->Frm();
270 : }
271 : }
272 0 : else if( mpDrawObj )
273 : {
274 0 : aBox = SwRect( mpDrawObj->GetCurrentBoundRect() );
275 : }
276 0 : else if ( mpWindow )
277 : {
278 0 : aBox = SwRect( rAccMap.GetShell()->GetWin()->PixelToLogic(
279 0 : Rectangle( mpWindow->GetPosPixel(),
280 0 : mpWindow->GetSizePixel() ) ) );
281 : }
282 :
283 544 : return aBox;
284 : }
285 :
286 3143 : SwRect SwAccessibleChild::GetBounds( const SwAccessibleMap& rAccMap ) const
287 : {
288 3143 : SwRect aBound;
289 :
290 3143 : if( mpFrm )
291 : {
292 3143 : if( mpFrm->IsPageFrm() &&
293 0 : static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() )
294 : {
295 0 : aBound = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 0, 0 );
296 : }
297 : else
298 3143 : aBound = mpFrm->PaintArea();
299 : }
300 0 : else if( mpDrawObj )
301 : {
302 0 : aBound = GetBox( rAccMap );
303 : }
304 0 : else if ( mpWindow )
305 : {
306 0 : aBound = GetBox( rAccMap );
307 : }
308 :
309 3143 : return aBound;
310 : }
311 :
312 327 : bool SwAccessibleChild::AlwaysIncludeAsChild() const
313 : {
314 327 : bool bAlwaysIncludedAsChild( false );
315 :
316 327 : if ( mpWindow )
317 : {
318 0 : bAlwaysIncludedAsChild = true;
319 : }
320 :
321 327 : return bAlwaysIncludedAsChild;
322 : }
323 :
324 2486 : const SwFrm* SwAccessibleChild::GetParent( const sal_Bool bInPagePreview ) const
325 : {
326 2486 : const SwFrm* pParent( 0 );
327 :
328 2486 : if ( mpFrm )
329 : {
330 2486 : if( mpFrm->IsFlyFrm() )
331 : {
332 0 : const SwFlyFrm* pFly = static_cast< const SwFlyFrm *>( mpFrm );
333 0 : if( pFly->IsFlyInCntFrm() )
334 : {
335 : // For FLY_AS_CHAR the parent is the anchor
336 0 : pParent = pFly->GetAnchorFrm();
337 : OSL_ENSURE( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
338 : "parent is not accessible" );
339 : }
340 : else
341 : {
342 : // In any other case the parent is the root frm
343 : // (in page preview, the page frame)
344 0 : if( bInPagePreview )
345 0 : pParent = pFly->FindPageFrm();
346 : else
347 0 : pParent = pFly->getRootFrm();
348 : }
349 : }
350 : else
351 : {
352 2486 : SwAccessibleChild aUpper( mpFrm->GetUpper() );
353 9167 : while( aUpper.GetSwFrm() && !aUpper.IsAccessible(bInPagePreview) )
354 : {
355 4195 : aUpper = aUpper.GetSwFrm()->GetUpper();
356 : }
357 2486 : pParent = aUpper.GetSwFrm();
358 : }
359 : }
360 0 : else if( mpDrawObj )
361 : {
362 : const SwDrawContact *pContact =
363 0 : static_cast< const SwDrawContact* >( GetUserCall( mpDrawObj ) );
364 : OSL_ENSURE( pContact, "sdr contact is missing" );
365 0 : if( pContact )
366 : {
367 0 : const SwFrmFmt *pFrmFmt = pContact->GetFmt();
368 : OSL_ENSURE( pFrmFmt, "frame format is missing" );
369 0 : if( pFrmFmt && FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId() )
370 : {
371 : // For FLY_AS_CHAR the parent is the anchor
372 0 : pParent = pContact->GetAnchorFrm();
373 : OSL_ENSURE( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
374 : "parent is not accessible" );
375 :
376 : }
377 : else
378 : {
379 : // In any other case the parent is the root frm
380 0 : if( bInPagePreview )
381 0 : pParent = pContact->GetAnchorFrm()->FindPageFrm();
382 : else
383 0 : pParent = pContact->GetAnchorFrm()->getRootFrm();
384 : }
385 : }
386 : }
387 0 : else if ( mpWindow )
388 : {
389 : css::uno::Reference < css::accessibility::XAccessible > xAcc =
390 0 : mpWindow->GetAccessible();
391 0 : if ( xAcc.is() )
392 : {
393 : css::uno::Reference < css::accessibility::XAccessibleContext > xAccContext =
394 0 : xAcc->getAccessibleContext();
395 0 : if ( xAccContext.is() )
396 : {
397 : css::uno::Reference < css::accessibility::XAccessible > xAccParent =
398 0 : xAccContext->getAccessibleParent();
399 0 : if ( xAccParent.is() )
400 : {
401 : SwAccessibleContext* pAccParentImpl =
402 0 : dynamic_cast< SwAccessibleContext *>( xAccParent.get() );
403 0 : if ( pAccParentImpl )
404 : {
405 0 : pParent = pAccParentImpl->GetFrm();
406 : }
407 0 : }
408 0 : }
409 0 : }
410 : }
411 :
412 2486 : return pParent;
413 : }
414 :
415 99 : } } // eof of namespace sw::access
416 :
417 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|