xref: /aoo42x/main/sw/source/core/access/accfrmobj.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include <accfrmobj.hxx>
28 
29 #include <accmap.hxx>
30 #include <acccontext.hxx>
31 
32 #include <viewsh.hxx>
33 #include <rootfrm.hxx>
34 #include <flyfrm.hxx>
35 #include <pagefrm.hxx>
36 #include <cellfrm.hxx>
37 #include <swtable.hxx>
38 #include <dflyobj.hxx>
39 #include <frmfmt.hxx>
40 #include <fmtanchr.hxx>
41 #include <dcontact.hxx>
42 
43 #include <vcl/window.hxx>
44 
45 namespace css = ::com::sun::star;
46 
47 namespace sw { namespace access {
48 
49 SwAccessibleChild::SwAccessibleChild()
50     : mpFrm( 0 )
51     , mpDrawObj( 0 )
52     , mpWindow( 0 )
53 {}
54 
55 SwAccessibleChild::SwAccessibleChild( const SdrObject* pDrawObj )
56     : mpFrm( 0 )
57     , mpDrawObj( 0 )
58     , mpWindow( 0 )
59 {
60     Init( pDrawObj );
61 }
62 
63 SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm )
64     : mpFrm( 0 )
65     , mpDrawObj( 0 )
66     , mpWindow( 0 )
67 {
68     Init( pFrm );
69 }
70 
71 SwAccessibleChild::SwAccessibleChild( Window* pWindow )
72     : mpFrm( 0 )
73     , mpDrawObj( 0 )
74     , mpWindow( 0 )
75 {
76     Init( pWindow );
77 }
78 
79 
80 SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm,
81                                       const SdrObject* pDrawObj,
82                                       Window* pWindow )
83 {
84     if ( pFrm )
85     {
86         Init( pFrm );
87     }
88     else if ( pDrawObj )
89     {
90         Init( pDrawObj );
91     }
92     else if ( pWindow )
93     {
94         Init( pWindow );
95     }
96     ASSERT( (!pFrm || pFrm == mpFrm) &&
97             (!pDrawObj || pDrawObj == mpDrawObj) &&
98             (!pWindow || pWindow == mpWindow),
99             "invalid frame/object/window combination" );
100 
101 }
102 
103 void SwAccessibleChild::Init( const SdrObject* pDrawObj )
104 {
105     mpDrawObj = pDrawObj;
106     mpFrm = mpDrawObj && mpDrawObj->ISA(SwVirtFlyDrawObj)
107             ? static_cast < const SwVirtFlyDrawObj * >( mpDrawObj )->GetFlyFrm()
108             : 0;
109     mpWindow = 0;
110 }
111 
112 void SwAccessibleChild::Init( const SwFrm* pFrm )
113 {
114     mpFrm = pFrm;
115     mpDrawObj = mpFrm && mpFrm->IsFlyFrm()
116                 ? static_cast < const SwFlyFrm * >( mpFrm )->GetVirtDrawObj()
117                 : 0;
118     mpWindow = 0;
119 }
120 
121 void SwAccessibleChild::Init( Window* pWindow )
122 {
123     mpWindow = pWindow;
124     mpFrm = 0;
125     mpDrawObj = 0;
126 }
127 
128 bool SwAccessibleChild::IsAccessible( sal_Bool bPagePreview ) const
129 {
130     bool bRet( false );
131 
132     if ( mpFrm )
133     {
134         bRet = mpFrm->IsAccessibleFrm() &&
135                ( !mpFrm->IsCellFrm() ||
136                  static_cast<const SwCellFrm *>( mpFrm )->GetTabBox()->GetSttNd() != 0 ) &&
137                !mpFrm->IsInCoveredCell() &&
138                ( bPagePreview ||
139                  !mpFrm->IsPageFrm() );
140     }
141     else if ( mpDrawObj )
142     {
143         bRet = true;
144     }
145     else if ( mpWindow )
146     {
147         bRet = true;
148     }
149 
150     return bRet;
151 }
152 
153 bool SwAccessibleChild::IsBoundAsChar() const
154 {
155     bool bRet( false );
156 
157     if ( mpFrm )
158 	{
159         bRet = mpFrm->IsFlyFrm() &&
160                static_cast< const SwFlyFrm *>(mpFrm)->IsFlyInCntFrm();
161 	}
162     else if ( mpDrawObj )
163 	{
164         const SwFrmFmt* mpFrmFmt = ::FindFrmFmt( mpDrawObj );
165         bRet = mpFrmFmt
166                ? (FLY_AS_CHAR == mpFrmFmt->GetAnchor().GetAnchorId())
167                : false;
168 	}
169     else if ( mpWindow )
170     {
171         bRet = false;
172     }
173 
174     return bRet;
175 }
176 
177 SwAccessibleChild::SwAccessibleChild( const SwAccessibleChild& r )
178     : mpFrm( r.mpFrm )
179     , mpDrawObj( r.mpDrawObj )
180     , mpWindow( r.mpWindow )
181 {}
182 
183 SwAccessibleChild& SwAccessibleChild::operator=( const SwAccessibleChild& r )
184 {
185     mpDrawObj = r.mpDrawObj;
186     mpFrm = r.mpFrm;
187     mpWindow = r.mpWindow;
188 
189     return *this;
190 }
191 
192 SwAccessibleChild& SwAccessibleChild::operator=( const SdrObject* pDrawObj )
193 {
194     Init( pDrawObj );
195     return *this;
196 }
197 
198 SwAccessibleChild& SwAccessibleChild::operator=( const SwFrm* pFrm )
199 {
200     Init( pFrm );
201     return *this;
202 }
203 
204 SwAccessibleChild& SwAccessibleChild::operator=( Window* pWindow )
205 {
206     Init( pWindow );
207     return *this;
208 }
209 
210 bool SwAccessibleChild::operator==( const SwAccessibleChild& r ) const
211 {
212     return mpFrm == r.mpFrm &&
213            mpDrawObj == r.mpDrawObj &&
214            mpWindow == r.mpWindow;
215 }
216 
217 bool SwAccessibleChild::IsValid() const
218 {
219     return mpFrm != 0 ||
220            mpDrawObj != 0 ||
221            mpWindow != 0;
222 }
223 
224 const SdrObject* SwAccessibleChild::GetDrawObject() const
225 {
226     return mpDrawObj;
227 }
228 
229 const SwFrm *SwAccessibleChild::GetSwFrm() const
230 {
231     return mpFrm;
232 }
233 
234 Window* SwAccessibleChild::GetWindow() const
235 {
236     return mpWindow;
237 }
238 
239 bool SwAccessibleChild::IsVisibleChildrenOnly() const
240 {
241     bool bRet( false );
242 
243     if ( !mpFrm )
244     {
245         bRet = true;
246     }
247     else
248     {
249         bRet = mpFrm->IsRootFrm() ||
250                !( mpFrm->IsTabFrm() ||
251                   mpFrm->IsInTab() ||
252                   ( IsBoundAsChar() &&
253                     static_cast<const SwFlyFrm*>(mpFrm)->GetAnchorFrm()->IsInTab() ) );
254     }
255 
256     return bRet;
257 }
258 
259 SwRect SwAccessibleChild::GetBox( const SwAccessibleMap& rAccMap ) const
260 {
261     SwRect aBox;
262 
263     if ( mpFrm )
264     {
265         if ( mpFrm->IsPageFrm() &&
266              static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() )
267         {
268             aBox = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 1, 1 );
269         }
270         else if ( mpFrm->IsTabFrm() )
271         {
272             aBox = SwRect( mpFrm->Frm() );
273             aBox.Intersection( mpFrm->GetUpper()->Frm() );
274         }
275         else
276         {
277             aBox = mpFrm->Frm();
278         }
279     }
280     else if( mpDrawObj )
281     {
282         aBox = SwRect( mpDrawObj->GetCurrentBoundRect() );
283     }
284     else if ( mpWindow )
285     {
286         aBox = SwRect( rAccMap.GetShell()->GetWin()->PixelToLogic(
287                                         Rectangle( mpWindow->GetPosPixel(),
288                                                    mpWindow->GetSizePixel() ) ) );
289 }
290 
291     return aBox;
292 }
293 
294 SwRect SwAccessibleChild::GetBounds( const SwAccessibleMap& rAccMap ) const
295 {
296     SwRect aBound;
297 
298     if( mpFrm )
299     {
300         if( mpFrm->IsPageFrm() &&
301             static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() )
302         {
303             aBound = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 0, 0 );
304         }
305         else
306             aBound = mpFrm->PaintArea();
307     }
308     else if( mpDrawObj )
309     {
310         aBound = GetBox( rAccMap );
311     }
312     else if ( mpWindow )
313     {
314         aBound = GetBox( rAccMap );
315     }
316 
317     return aBound;
318 }
319 
320 bool SwAccessibleChild::AlwaysIncludeAsChild() const
321 {
322     bool bAlwaysIncludedAsChild( false );
323 
324     if ( mpWindow )
325     {
326         bAlwaysIncludedAsChild = true;
327     }
328 
329     return bAlwaysIncludedAsChild;
330 }
331 
332 const SwFrm* SwAccessibleChild::GetParent( const sal_Bool bInPagePreview ) const
333 {
334     const SwFrm* pParent( 0 );
335 
336     if ( mpFrm )
337     {
338         if( mpFrm->IsFlyFrm() )
339         {
340             const SwFlyFrm* pFly = static_cast< const SwFlyFrm *>( mpFrm );
341             if( pFly->IsFlyInCntFrm() )
342             {
343                 // For FLY_AS_CHAR the parent is the anchor
344                 pParent = pFly->GetAnchorFrm();
345                 ASSERT( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
346                         "parent is not accessible" );
347             }
348             else
349             {
350                 // In any other case the parent is the root frm
351                 // (in page preview, the page frame)
352                 if( bInPagePreview )
353                     pParent = pFly->FindPageFrm();
354                 else
355                     pParent = pFly->getRootFrm();
356             }
357         }
358         else
359         {
360             SwAccessibleChild aUpper( mpFrm->GetUpper() );
361             while( aUpper.GetSwFrm() && !aUpper.IsAccessible(bInPagePreview) )
362             {
363                 aUpper = aUpper.GetSwFrm()->GetUpper();
364             }
365             pParent = aUpper.GetSwFrm();
366         }
367     }
368     else if( mpDrawObj )
369     {
370         const SwDrawContact *pContact =
371             static_cast< const SwDrawContact* >( GetUserCall( mpDrawObj ) );
372         ASSERT( pContact, "sdr contact is missing" );
373         if( pContact )
374         {
375             const SwFrmFmt *pFrmFmt = pContact->GetFmt();
376             ASSERT( pFrmFmt, "frame format is missing" );
377             if( pFrmFmt && FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId() )
378             {
379                 // For FLY_AS_CHAR the parent is the anchor
380                 pParent = pContact->GetAnchorFrm();
381                 ASSERT( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ),
382                         "parent is not accessible" );
383 
384             }
385             else
386             {
387                 // In any other case the parent is the root frm
388                 if( bInPagePreview )
389                     pParent = pContact->GetAnchorFrm()->FindPageFrm();
390                 else
391                     pParent = pContact->GetAnchorFrm()->getRootFrm();
392             }
393         }
394     }
395     else if ( mpWindow )
396     {
397         css::uno::Reference < css::accessibility::XAccessible > xAcc =
398                                                     mpWindow->GetAccessible();
399         if ( xAcc.is() )
400         {
401             css::uno::Reference < css::accessibility::XAccessibleContext > xAccContext =
402                                                 xAcc->getAccessibleContext();
403             if ( xAccContext.is() )
404             {
405                 css::uno::Reference < css::accessibility::XAccessible > xAccParent =
406                                                 xAccContext->getAccessibleParent();
407                 if ( xAccParent.is() )
408                 {
409                     SwAccessibleContext* pAccParentImpl =
410                                 dynamic_cast< SwAccessibleContext *>( xAccParent.get() );
411                     if ( pAccParentImpl )
412                     {
413                         pParent = pAccParentImpl->GetFrm();
414                     }
415                 }
416             }
417         }
418     }
419 
420     return pParent;
421 }
422 
423 } } // eof of namespace sw::access
424 
425