LibreOffice Module framework (master) 1
framelistanalyzer.cxx
Go to the documentation of this file.
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
21
22#include <targets.h>
23#include <properties.h>
24
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
27#include <com/sun/star/frame/ModuleManager.hpp>
28#include <com/sun/star/frame/UnknownModuleException.hpp>
29#include <com/sun/star/frame/XFrame.hpp>
30
33#include <sal/log.hxx>
34
35namespace framework{
36
37FrameListAnalyzer::FrameListAnalyzer( const css::uno::Reference< css::frame::XFramesSupplier >& xSupplier ,
38 const css::uno::Reference< css::frame::XFrame >& xReferenceFrame ,
39 FrameAnalyzerFlags eDetectMode )
40 : m_xSupplier (xSupplier )
41 , m_xReferenceFrame(xReferenceFrame)
42 , m_eDetectMode (eDetectMode )
43{
44 impl_analyze();
45}
46
47FrameListAnalyzer::~FrameListAnalyzer()
48{
49}
50
65void FrameListAnalyzer::impl_analyze()
66{
67 // reset all members to get a consistent state
68 m_bReferenceIsHidden = false;
69 m_bReferenceIsHelp = false;
70 m_bReferenceIsBacking = false;
71 m_xHelp.clear();
72 m_xBackingComponent.clear();
73
74 // try to get the task container by using the given supplier
75 css::uno::Reference< css::container::XIndexAccess > xFrameContainer = m_xSupplier->getFrames();
76
77 // All return list get an initial size to include all possible frames.
78 // They will be packed at the end of this method ... using the actual step positions then.
79 sal_Int32 nVisibleStep = 0;
80 sal_Int32 nHiddenStep = 0;
81 sal_Int32 nModelStep = 0;
82 sal_Int32 nCount = xFrameContainer->getCount();
83
84 m_lOtherVisibleFrames.resize(nCount);
85 m_lOtherHiddenFrames.resize(nCount);
86 m_lModelFrames.resize(nCount);
87
88 // ask for the model of the given reference frame.
89 // It must be compared with the model of every frame of the container
90 // to sort it into the list of frames with the same model.
91 // Suppress this step, if right detect mode isn't set.
92 css::uno::Reference< css::frame::XModel > xReferenceModel;
93 if (m_eDetectMode & FrameAnalyzerFlags::Model)
94 {
95 css::uno::Reference< css::frame::XController > xReferenceController;
96 if (m_xReferenceFrame.is())
97 xReferenceController = m_xReferenceFrame->getController();
98 if (xReferenceController.is())
99 xReferenceModel = xReferenceController->getModel();
100 }
101
102 // check, if the reference frame is in hidden mode.
103 // But look, if this analyze step is really needed.
104 css::uno::Reference< css::beans::XPropertySet > xSet(m_xReferenceFrame, css::uno::UNO_QUERY);
105 if ( (m_eDetectMode & FrameAnalyzerFlags::Hidden) && xSet.is() )
106 {
107 xSet->getPropertyValue(FRAME_PROPNAME_ASCII_ISHIDDEN) >>= m_bReferenceIsHidden;
108 }
109
110 // check, if the reference frame includes the backing component.
111 // But look, if this analyze step is really needed.
112 if ((m_eDetectMode & FrameAnalyzerFlags::BackingComponent) && m_xReferenceFrame.is() )
113 {
114 try
115 {
116 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
117 css::uno::Reference< css::frame::XModuleManager2 > xModuleMgr = css::frame::ModuleManager::create(xContext);
118 OUString sModule = xModuleMgr->identify(m_xReferenceFrame);
119 m_bReferenceIsBacking = sModule == "com.sun.star.frame.StartModule";
120 }
121 catch(const css::frame::UnknownModuleException&)
122 {
123 }
124 catch(const css::uno::Exception&)
125 {
127 }
128 }
129
130 // check, if the reference frame includes the help module.
131 // But look, if this analyze step is really needed.
132 if (
133 (m_eDetectMode & FrameAnalyzerFlags::Help) &&
134 (m_xReferenceFrame.is() ) &&
135 (m_xReferenceFrame->getName() == SPECIALTARGET_HELPTASK)
136 )
137 {
138 m_bReferenceIsHelp = true;
139 }
140
141 try
142 {
143 // Step over all frames of the desktop frame container and analyze it.
144 for (sal_Int32 i=0; i<nCount; ++i)
145 {
146 // Ignore invalid items ... and of course the reference frame.
147 // It will be a member of the given frame list too - but it was already
148 // analyzed before!
149 css::uno::Reference< css::frame::XFrame > xFrame;
150 if (
151 !(xFrameContainer->getByIndex(i) >>= xFrame) ||
152 !(xFrame.is() ) ||
153 (xFrame==m_xReferenceFrame )
154 )
155 continue;
156
157 if (
158 (m_eDetectMode & FrameAnalyzerFlags::Zombie) &&
159 (
160 (!xFrame->getContainerWindow().is()) ||
161 (!xFrame->getComponentWindow().is())
162 )
163 )
164 {
165 SAL_INFO("fwk", "FrameListAnalyzer::impl_analyze(): ZOMBIE!");
166 }
167
168 // a) Is it the special help task?
169 // Return it separated from any return list.
170 if (
171 (m_eDetectMode & FrameAnalyzerFlags::Help) &&
172 (xFrame->getName()==SPECIALTARGET_HELPTASK)
173 )
174 {
175 m_xHelp = xFrame;
176 continue;
177 }
178
179 // b) Or is includes this task the special backing component?
180 // Return it separated from any return list.
181 // But check if the reference task itself is the backing frame.
182 // Our user must know it to decide right.
183 if (m_eDetectMode & FrameAnalyzerFlags::BackingComponent)
184 {
185 try
186 {
187 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
188 css::uno::Reference< css::frame::XModuleManager2 > xModuleMgr = css::frame::ModuleManager::create(xContext);
189 OUString sModule = xModuleMgr->identify(xFrame);
190 if (sModule == "com.sun.star.frame.StartModule")
191 {
192 m_xBackingComponent = xFrame;
193 continue;
194 }
195 }
196 catch (const css::uno::Exception&)
197 {
198 }
199 }
200
201 // c) Or is it the a task, which uses the specified model?
202 // Add it to the list of "model frames".
203 if (m_eDetectMode & FrameAnalyzerFlags::Model)
204 {
205 css::uno::Reference< css::frame::XController > xController = xFrame->getController();
206 css::uno::Reference< css::frame::XModel > xModel;
207 if (xController.is())
208 xModel = xController->getModel();
209 if (xModel==xReferenceModel)
210 {
211 m_lModelFrames[nModelStep] = xFrame;
212 ++nModelStep;
213 continue;
214 }
215 }
216
217 // d) Or is it the a task, which use another or no model at all?
218 // Add it to the list of "other frames". But look for its
219 // visible state ... if it's allowed to do so.
220
221 bool bHidden = false;
222 if (m_eDetectMode & FrameAnalyzerFlags::Hidden)
223 {
224 xSet.set(xFrame, css::uno::UNO_QUERY);
225 if (xSet.is())
226 {
227 xSet->getPropertyValue(FRAME_PROPNAME_ASCII_ISHIDDEN) >>= bHidden;
228 }
229 }
230
231 if (bHidden)
232 {
233 m_lOtherHiddenFrames[nHiddenStep] = xFrame;
234 ++nHiddenStep;
235 }
236 else
237 {
238 m_lOtherVisibleFrames[nVisibleStep] = xFrame;
239 ++nVisibleStep;
240 }
241 }
242 }
243 catch (const css::lang::IndexOutOfBoundsException&)
244 {
245 // stop copying if index seems to be wrong.
246 // This interface can't really guarantee its count for multithreaded
247 // environments. So it can occur!
248 }
249
250 // Pack both lists by using the actual step positions.
251 // All empty or ignorable items should exist at the end of these lists
252 // behind the position pointers. So they will be removed by a reallocation.
253 m_lOtherVisibleFrames.resize(nVisibleStep);
254 m_lOtherHiddenFrames.resize(nHiddenStep);
255 m_lModelFrames.resize(nModelStep);
256}
257
258} // namespace framework
259
260/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
int nCount
#define DBG_UNHANDLED_EXCEPTION(...)
FrameAnalyzerFlags
These enums can be combined as flags to enable/disable special search algorithm during analyze phase.
#define SAL_INFO(area, stream)
constexpr OUStringLiteral FRAME_PROPNAME_ASCII_ISHIDDEN
Definition: properties.h:29
constexpr OUStringLiteral SPECIALTARGET_HELPTASK
Definition: targets.h:34
int i
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel