LibreOffice Module framework (master) 1
framecontainer.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 <com/sun/star/frame/FrameSearchFlag.hpp>
23
24#include <vcl/svapp.hxx>
26#include <sal/log.hxx>
27
28namespace framework
29{
37/*DEPRECATEME
38 , m_bAsyncQuit ( sal_False ) // default must be "disabled"!
39 , m_aAsyncCall ( LINK( this, FrameContainer, implts_asyncQuit ) )
40*/
41{
42}
43
51{
52 // Don't forget to free memory!
53 m_aContainer.clear();
54 m_xActiveFrame.clear();
55}
56
67void FrameContainer::append(const css::uno::Reference<css::frame::XFrame>& xFrame)
68{
69 if (xFrame.is() && !exist(xFrame))
70 {
72 m_aContainer.push_back(xFrame);
73 }
74}
75
87void FrameContainer::remove(const css::uno::Reference<css::frame::XFrame>& xFrame)
88{
90
91 TFrameContainer::iterator aSearchedItem
92 = ::std::find(m_aContainer.begin(), m_aContainer.end(), xFrame);
93 if (aSearchedItem != m_aContainer.end())
94 {
95 m_aContainer.erase(aSearchedItem);
96
97 // If removed frame was the current active frame - reset state variable.
99 m_xActiveFrame.clear();
100 }
101}
102
113bool FrameContainer::exist(const css::uno::Reference<css::frame::XFrame>& xFrame) const
114{
116 return (::std::find(m_aContainer.begin(), m_aContainer.end(), xFrame) != m_aContainer.end());
117}
118
124{
126 // Clear the container ...
127 m_aContainer.clear();
128 // ... and don't forget to reset the active frame.
129 // It's a reference to a valid container-item.
130 // But no container item => no active frame!
131 m_xActiveFrame.clear();
132}
133
143sal_uInt32 FrameContainer::getCount() const
144{
146 return static_cast<sal_uInt32>(m_aContainer.size());
147}
148
161css::uno::Reference<css::frame::XFrame> FrameContainer::operator[](sal_uInt32 nIndex) const
162{
163 css::uno::Reference<css::frame::XFrame> xFrame;
164 try
165 {
166 // Get element form container WITH automatic test of ranges!
167 // If index not valid, an out_of_range exception is thrown.
170 }
171 catch (const std::out_of_range&)
172 {
173 // The index is not valid for current container-content - we must handle this case!
174 // We can return the default value ...
175 SAL_INFO("fwk", "FrameContainer::operator[]: Exception caught: std::out_of_range");
176 }
177 return xFrame;
178}
179
188css::uno::Sequence<css::uno::Reference<css::frame::XFrame>> FrameContainer::getAllElements() const
189{
192}
193
204void FrameContainer::setActive(const css::uno::Reference<css::frame::XFrame>& xFrame)
205{
206 if (!xFrame.is() || exist(xFrame))
207 {
210 }
211}
212
223css::uno::Reference<css::frame::XFrame> FrameContainer::getActive() const
224{
226 return m_xActiveFrame;
227}
228
240css::uno::Reference<css::frame::XFrame>
241FrameContainer::searchOnAllChildrens(const OUString& sName) const
242{
244 // Step over all child frames. But if direct child isn't the right one search on his children first - before
245 // you go to next direct child of this container!
246 css::uno::Reference<css::frame::XFrame> xSearchedFrame;
247 for (auto const& container : m_aContainer)
248 {
249 if (container->getName() == sName)
250 {
251 xSearchedFrame = container;
252 break;
253 }
254 else
255 {
256 xSearchedFrame = container->findFrame(sName, css::frame::FrameSearchFlag::CHILDREN);
257 if (xSearchedFrame.is())
258 break;
259 }
260 }
261 return xSearchedFrame;
262}
263
275css::uno::Reference<css::frame::XFrame>
276FrameContainer::searchOnDirectChildrens(std::u16string_view sName) const
277{
279 css::uno::Reference<css::frame::XFrame> xSearchedFrame;
280 for (auto const& container : m_aContainer)
281 {
282 if (container->getName() == sName)
283 {
284 xSearchedFrame = container;
285 break;
286 }
287 }
288 return xSearchedFrame;
289}
290
291} // namespace framework
292
293/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void clear()
-****************************************************************************************************...
css::uno::Reference< css::frame::XFrame > operator[](sal_uInt32 nIndex) const
-****************************************************************************************************...
void append(const css::uno::Reference< css::frame::XFrame > &xFrame)
add/remove/mark container items
void setActive(const css::uno::Reference< css::frame::XFrame > &xFrame)
-****************************************************************************************************...
bool exist(const css::uno::Reference< css::frame::XFrame > &xFrame) const
checks and free memory
sal_uInt32 getCount() const
deprecated IndexAccess!
TFrameContainer m_aContainer
list to hold all frames
css::uno::Reference< css::frame::XFrame > searchOnAllChildrens(const OUString &sName) const
special helper for Frame::findFrame()
css::uno::Reference< css::frame::XFrame > getActive() const
-****************************************************************************************************...
FrameContainer()
constructor / destructor
void remove(const css::uno::Reference< css::frame::XFrame > &xFrame)
-****************************************************************************************************...
~FrameContainer()
-****************************************************************************************************...
css::uno::Sequence< css::uno::Reference< css::frame::XFrame > > getAllElements() const
replacement for deprecated index access
css::uno::Reference< css::frame::XFrame > m_xActiveFrame
one container item can be the current active frame. It's necessary for Desktop or Frame implementatio...
css::uno::Reference< css::frame::XFrame > searchOnDirectChildrens(std::u16string_view sName) const
-****************************************************************************************************...
OUString sName
sal_Int32 nIndex
#define SAL_INFO(area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Reference< XFrame > xFrame