xref: /trunk/main/svx/source/svdraw/svdviter.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include "svx/svdviter.hxx"
32 #include <svx/svdobj.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/svdmodel.hxx>
35 #include <svx/svdview.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <svx/svdsob.hxx>
38 #include <svl/brdcst.hxx>
39 #include <svx/sdrpaintwindow.hxx>
40 
41 ////////////////////////////////////////////////////////////////////////////////////////////////////
42 
43 void SdrViewIter::ImpInitVars()
44 {
45     mnListenerNum = 0L;
46     mnPageViewNum = 0L;
47     mnOutDevNum = 0L;
48     mpAktView = 0L;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
52 
53 SdrViewIter::SdrViewIter(const SdrModel* pModel)
54 {
55     mpModel = pModel;
56     mpPage = 0L;
57     mpObject = 0L;
58     ImpInitVars();
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////////////////////////
62 
63 SdrViewIter::SdrViewIter(const SdrPage* pPage, sal_Bool bNoMasterPage)
64 {
65     mpPage = pPage;
66     mpModel = (pPage) ? pPage->GetModel() : 0L;
67     mpObject = 0L;
68     mbNoMasterPage = bNoMasterPage;
69     ImpInitVars();
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////////////////////////
73 
74 SdrViewIter::SdrViewIter(const SdrObject* pObject, sal_Bool bNoMasterPage)
75 {
76     mpObject = pObject;
77     mpModel = (pObject) ? pObject->GetModel() : 0L;
78     mpPage = (pObject) ? pObject->GetPage() : 0L;
79     mbNoMasterPage = bNoMasterPage;
80 
81     if(!mpModel || !mpPage)
82     {
83         mpModel = 0L;
84         mpPage = 0L;
85     }
86 
87     ImpInitVars();
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////////////////////////
91 
92 sal_Bool SdrViewIter::ImpCheckPageView(SdrPageView* pPV) const
93 {
94     if(mpPage)
95     {
96         sal_Bool bMaster(mpPage->IsMasterPage());
97         SdrPage* pPg = pPV->GetPage();
98 
99         if(pPg == mpPage)
100         {
101             if(mpObject)
102             {
103                 // Objekt gewuenscht? Na dann erstmal sehen, ob
104                 // das Obj in dieser PageView auch sichtbar ist.
105                 SetOfByte aObjLay;
106                 mpObject->getMergedHierarchyLayerSet(aObjLay);
107                 aObjLay &= pPV->GetVisibleLayers();
108                 return !aObjLay.IsEmpty();
109             }
110             else
111             {
112                 return sal_True;
113             }
114         }
115         else
116         {
117             if(!mbNoMasterPage && bMaster && (!mpObject || !mpObject->IsNotVisibleAsMaster()))
118             {
119                 if(pPg->TRG_HasMasterPage())
120                 {
121                     SdrPage& rMasterPage = pPg->TRG_GetMasterPage();
122 
123                     if(&rMasterPage == mpPage)
124                     {
125                         // Aha, die gewuenschte Page ist also MasterPage in dieser PageView
126                         if(mpObject)
127                         {
128                             // Objekt gewuenscht? Na dann erstmal sehen, ob
129                             // das Obj in dieser PageView auch sichtbar ist.
130                             SetOfByte aObjLay;
131                             mpObject->getMergedHierarchyLayerSet(aObjLay);
132                             aObjLay &= pPV->GetVisibleLayers();
133                             aObjLay &= pPg->TRG_GetMasterPageVisibleLayers();
134 
135                             if(!aObjLay.IsEmpty())
136                             {
137                                 return sal_True;
138                             } // ansonsten die naechste MasterPage der Page ansehen...
139                         }
140                         else
141                         {
142                             return sal_True;
143                         }
144                     }
145                 }
146             }
147 
148             // MasterPage nicht erlaubt oder keine passende gefunden
149             return sal_False;
150         }
151     }
152     else
153     {
154         return sal_True;
155     }
156 }
157 
158 ////////////////////////////////////////////////////////////////////////////////////////////////////
159 
160 SdrView* SdrViewIter::ImpFindView()
161 {
162     if(mpModel)
163     {
164         sal_uInt32 nLsAnz(mpModel->GetListenerCount());
165 
166         while(mnListenerNum < nLsAnz)
167         {
168             SfxListener* pLs = mpModel->GetListener((sal_uInt16)mnListenerNum);
169             mpAktView = PTR_CAST(SdrView, pLs);
170 
171             if(mpAktView)
172             {
173                 if(mpPage)
174                 {
175                     SdrPageView* pPV = mpAktView->GetSdrPageView();
176 
177                     if(pPV)
178                     {
179                         if(ImpCheckPageView(pPV))
180                         {
181                             return mpAktView;
182                         }
183                     }
184                 }
185                 else
186                 {
187                     return mpAktView;
188                 }
189             }
190 
191             mnListenerNum++;
192         }
193     }
194 
195     mpAktView = 0L;
196     return mpAktView;
197 }
198 
199 ////////////////////////////////////////////////////////////////////////////////////////////////////
200 
201 SdrPageView* SdrViewIter::ImpFindPageView()
202 {
203     if(mpModel)
204     {
205         while(mpAktView)
206         {
207             SdrPageView* pPV = mpAktView->GetSdrPageView();
208 
209             if(pPV)
210             {
211                 if(mpPage)
212                 {
213                     if(ImpCheckPageView(pPV))
214                     {
215                         return pPV;
216                     }
217                 }
218                 else
219                 {
220                     return pPV;
221                 }
222 
223                 mnPageViewNum++;
224             }
225 
226             mnListenerNum++;
227             ImpFindView();
228         }
229     }
230 
231     return 0L;
232 }
233 
234 ////////////////////////////////////////////////////////////////////////////////////////////////////
235 
236 OutputDevice* SdrViewIter::ImpFindOutDev()
237 {
238     while(mpAktView)
239     {
240         const sal_uInt32 nOutDevAnz(mpAktView->PaintWindowCount());
241 
242         if(mnOutDevNum < nOutDevAnz)
243         {
244             SdrPaintWindow* pPaintWindow = mpAktView->GetPaintWindow(mnOutDevNum);
245             return &pPaintWindow->GetOutputDevice();
246         }
247 
248         mnListenerNum++;
249         ImpFindView();
250     }
251 
252     return 0L;
253 }
254 
255 ////////////////////////////////////////////////////////////////////////////////////////////////////
256 
257 Window* SdrViewIter::ImpFindWindow()
258 {
259     while(mpAktView)
260     {
261         const sal_uInt32 nOutDevAnz(mpAktView->PaintWindowCount());
262 
263         while(mnOutDevNum < nOutDevAnz)
264         {
265             SdrPaintWindow* pPaintWindow = mpAktView->GetPaintWindow(mnOutDevNum);
266             OutputDevice& rOutDev = pPaintWindow->GetOutputDevice();
267 
268             if(OUTDEV_WINDOW == rOutDev.GetOutDevType())
269             {
270                 return (Window*)(&rOutDev);
271             }
272 
273             mnOutDevNum++;
274         }
275 
276         mnListenerNum++;
277         ImpFindView();
278     }
279 
280     return 0L;
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////////////////////////
284 
285 SdrView* SdrViewIter::FirstView()
286 {
287     ImpInitVars();
288     return ImpFindView();
289 }
290 
291 ////////////////////////////////////////////////////////////////////////////////////////////////////
292 
293 SdrView* SdrViewIter::NextView()
294 {
295     mnListenerNum++;
296     return ImpFindView();
297 }
298 
299 ////////////////////////////////////////////////////////////////////////////////////////////////////
300 
301 SdrPageView* SdrViewIter::FirstPageView()
302 {
303     ImpInitVars();
304     ImpFindView();
305     return ImpFindPageView();
306 }
307 
308 ////////////////////////////////////////////////////////////////////////////////////////////////////
309 
310 SdrPageView* SdrViewIter::NextPageView()
311 {
312     mnPageViewNum++;
313     return ImpFindPageView();
314 }
315 
316 ////////////////////////////////////////////////////////////////////////////////////////////////////
317 
318 OutputDevice* SdrViewIter::FirstOutDev()
319 {
320     ImpInitVars();
321     ImpFindView();
322     return ImpFindOutDev();
323 }
324 
325 ////////////////////////////////////////////////////////////////////////////////////////////////////
326 
327 OutputDevice* SdrViewIter::NextOutDev()
328 {
329     mnOutDevNum++;
330     return ImpFindOutDev();
331 }
332 
333 ////////////////////////////////////////////////////////////////////////////////////////////////////
334 
335 Window* SdrViewIter::FirstWindow()
336 {
337     ImpInitVars();
338     ImpFindView();
339     return ImpFindWindow();
340 }
341 
342 ////////////////////////////////////////////////////////////////////////////////////////////////////
343 
344 Window* SdrViewIter::NextWindow()
345 {
346     mnOutDevNum++;
347     return ImpFindWindow();
348 }
349 
350 ////////////////////////////////////////////////////////////////////////////////////////////////////
351 
352