merge the formfield patch from ooo-build
[ooovba.git] / framework / source / classes / framelistanalyzer.cxx
blob84b9e97969f98f1b5f20a9764ce9f7d755505bbb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: framelistanalyzer.cxx,v $
10 * $Revision: 1.10 $
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_framework.hxx"
34 #include "classes/framelistanalyzer.hxx"
36 //_______________________________________________
37 // my own includes
38 #include <threadhelp/writeguard.hxx>
39 #include <threadhelp/readguard.hxx>
40 #include <targets.h>
41 #include <properties.h>
42 #include <services.h>
44 //_______________________________________________
45 // interface includes
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #include <com/sun/star/frame/XModuleManager.hpp>
50 //_______________________________________________
51 // includes of other projects
52 #include <unotools/processfactory.hxx>
53 #include <vcl/svapp.hxx>
55 //_______________________________________________
56 // namespace
58 namespace framework{
60 //_______________________________________________
61 // non exported const
63 //_______________________________________________
64 // non exported definitions
66 //_______________________________________________
67 // declarations
69 //_______________________________________________
71 /**
74 FrameListAnalyzer::FrameListAnalyzer( const css::uno::Reference< css::frame::XFramesSupplier >& xSupplier ,
75 const css::uno::Reference< css::frame::XFrame >& xReferenceFrame ,
76 sal_uInt32 eDetectMode )
77 : m_xSupplier (xSupplier )
78 , m_xReferenceFrame(xReferenceFrame)
79 , m_eDetectMode (eDetectMode )
81 impl_analyze();
84 //_______________________________________________
86 /**
89 FrameListAnalyzer::~FrameListAnalyzer()
93 //_______________________________________________
95 /** returns an analyzed list of all currently opened (top!) frames inside the desktop tree.
97 We try to get a snapshot of all opened frames, which are part of the desktop frame container.
98 Of course we can't access frames, which stands outside of this tree.
99 But it's neccessary to collect top frames here only. Otherwhise we interpret closing of last
100 frame wrong. Further we analyze this list and split into different parts.
101 E.g. for "CloseDoc" we must know, which frames of the given list referr to the same model.
102 These frames must be closed then. But all other frames must be untouched.
103 In case the request was "CloseWin" these splitted lists can be used too, to decide if the last window
104 or document was closed. Then we have to initialize the backing window ...
105 Last but not least we must know something about our special help frame. It must be handled
106 seperatly. And last but not least - the backing component frame must be detected too.
109 void FrameListAnalyzer::impl_analyze()
111 // reset all members to get a consistent state
112 m_bReferenceIsHidden = sal_False;
113 m_bReferenceIsHelp = sal_False;
114 m_bReferenceIsBacking = sal_False;
115 m_xHelp = css::uno::Reference< css::frame::XFrame >();
116 m_xBackingComponent = css::uno::Reference< css::frame::XFrame >();
118 // try to get the task container by using the given supplier
119 css::uno::Reference< css::container::XIndexAccess > xFrameContainer(m_xSupplier->getFrames(), css::uno::UNO_QUERY);
121 // All return list get an initial size to include all possible frames.
122 // They will be packed at the end of this method ... using the actual step positions then.
123 sal_Int32 nVisibleStep = 0;
124 sal_Int32 nHiddenStep = 0;
125 sal_Int32 nModelStep = 0;
126 sal_Int32 nCount = xFrameContainer->getCount();
128 m_lOtherVisibleFrames.realloc(nCount);
129 m_lOtherHiddenFrames.realloc(nCount);
130 m_lModelFrames.realloc(nCount);
132 // ask for the model of the given reference frame.
133 // It must be compared with the model of every frame of the container
134 // to sort it into the list of frames with the same model.
135 // Supress this step, if right detect mode isn't set.
136 css::uno::Reference< css::frame::XModel > xReferenceModel;
137 if ((m_eDetectMode & E_MODEL) == E_MODEL )
139 css::uno::Reference< css::frame::XController > xReferenceController;
140 if (m_xReferenceFrame.is())
141 xReferenceController = m_xReferenceFrame->getController();
142 if (xReferenceController.is())
143 xReferenceModel = xReferenceController->getModel();
146 // check, if the reference frame is in hidden mode.
147 // But look, if this analyze step is realy needed.
148 css::uno::Reference< css::beans::XPropertySet > xSet(m_xReferenceFrame, css::uno::UNO_QUERY);
149 if (
150 ((m_eDetectMode & E_HIDDEN) == E_HIDDEN) &&
151 (xSet.is() )
154 xSet->getPropertyValue(FRAME_PROPNAME_ISHIDDEN) >>= m_bReferenceIsHidden;
157 // check, if the reference frame includes the backing component.
158 // But look, if this analyze step is realy needed.
159 if ((m_eDetectMode & E_BACKINGCOMPONENT) == E_BACKINGCOMPONENT)
163 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::utl::getProcessServiceFactory();
164 css::uno::Reference< css::frame::XModuleManager > xModuleMgr(xSMGR->createInstance(SERVICENAME_MODULEMANAGER), css::uno::UNO_QUERY_THROW);
165 ::rtl::OUString sModule = xModuleMgr->identify(m_xReferenceFrame);
166 m_bReferenceIsBacking = (sModule.equals(SERVICENAME_STARTMODULE));
168 catch(const css::uno::Exception&)
172 // check, if the reference frame includes the help module.
173 // But look, if this analyze step is realy needed.
174 if (
175 ((m_eDetectMode & E_HELP) == E_HELP ) &&
176 (m_xReferenceFrame.is() ) &&
177 (m_xReferenceFrame->getName() == SPECIALTARGET_HELPTASK)
180 m_bReferenceIsHelp = sal_True;
185 // Step over all frames of the desktop frame container and analyze it.
186 for (sal_Int32 i=0; i<nCount; ++i)
188 // Ignore invalid items ... and of course the reference frame.
189 // It will be a member of the given frame list too - but it was already
190 // analyzed before!
191 css::uno::Reference< css::frame::XFrame > xFrame;
192 if (
193 !(xFrameContainer->getByIndex(i) >>= xFrame) ||
194 !(xFrame.is() ) ||
195 (xFrame==m_xReferenceFrame )
197 continue;
199 #ifdef ENABLE_WARNINGS
200 if (
201 ((m_eDetectMode & E_ZOMBIE) == E_ZOMBIE) &&
203 (!xFrame->getContainerWindow().is()) ||
204 (!xFrame->getComponentWindow().is())
208 LOG_WARNING("FrameListAnalyzer::impl_analyze()", "ZOMBIE!")
210 #endif
212 // -------------------------------------------------
213 // a) Is it the special help task?
214 // Return it seperated from any return list.
215 if (
216 ((m_eDetectMode & E_HELP) == E_HELP ) &&
217 (xFrame->getName()==SPECIALTARGET_HELPTASK)
220 m_xHelp = xFrame;
221 continue;
224 // -------------------------------------------------
225 // b) Or is includes this task the special backing component?
226 // Return it seperated from any return list.
227 // But check if the reference task itself is the backing frame.
228 // Our user mst know it to decide right.
229 if ((m_eDetectMode & E_BACKINGCOMPONENT) == E_BACKINGCOMPONENT)
233 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::utl::getProcessServiceFactory();
234 css::uno::Reference< css::frame::XModuleManager > xModuleMgr(xSMGR->createInstance(SERVICENAME_MODULEMANAGER), css::uno::UNO_QUERY);
235 ::rtl::OUString sModule = xModuleMgr->identify(xFrame);
236 if (sModule.equals(SERVICENAME_STARTMODULE))
238 m_xBackingComponent = xFrame;
239 continue;
242 catch(const css::uno::Exception&)
246 // -------------------------------------------------
247 // c) Or is it the a task, which uses the specified model?
248 // Add it to the list of "model frames".
249 if ((m_eDetectMode & E_MODEL) == E_MODEL)
251 css::uno::Reference< css::frame::XController > xController = xFrame->getController();
252 css::uno::Reference< css::frame::XModel > xModel ;
253 if (xController.is())
254 xModel = xController->getModel();
255 if (xModel==xReferenceModel)
257 m_lModelFrames[nModelStep] = xFrame;
258 ++nModelStep;
259 continue;
263 // -------------------------------------------------
264 // d) Or is it the a task, which use another or no model at all?
265 // Add it to the list of "other frames". But look for it's
266 // visible state ... if it's allowed to do so.
267 // -------------------------------------------------
268 sal_Bool bHidden = sal_False;
269 if ((m_eDetectMode & E_HIDDEN) == E_HIDDEN )
271 xSet = css::uno::Reference< css::beans::XPropertySet >(xFrame, css::uno::UNO_QUERY);
272 if (xSet.is())
274 xSet->getPropertyValue(FRAME_PROPNAME_ISHIDDEN) >>= bHidden;
278 if (bHidden)
280 m_lOtherHiddenFrames[nHiddenStep] = xFrame;
281 ++nHiddenStep;
283 else
285 m_lOtherVisibleFrames[nVisibleStep] = xFrame;
286 ++nVisibleStep;
290 catch(css::lang::IndexOutOfBoundsException)
292 // stop copying if index seams to be wrong.
293 // This interface can't realy guarantee its count for multithreaded
294 // environments. So it can occure!
297 // Pack both lists by using the actual step positions.
298 // All empty or ignorable items should exist at the end of these lists
299 // behind the position pointers. So they will be removed by a reallocation.
300 m_lOtherVisibleFrames.realloc(nVisibleStep);
301 m_lOtherHiddenFrames.realloc(nHiddenStep);
302 m_lModelFrames.realloc(nModelStep);
305 } // namespace framework