1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <classes/framecontainer.hxx>
22 #include <com/sun/star/frame/FrameSearchFlag.hpp>
24 #include <vcl/svapp.hxx>
28 /**-***************************************************************************************************************
29 @short initialize an empty container
30 @descr The container will be empty then - special features (e.g. the async quit mechanism) are disabled.
32 @threadsafe not necessary - its not a singleton
33 *****************************************************************************************************************/
34 FrameContainer::FrameContainer()
36 , m_bAsyncQuit ( sal_False ) // default must be "disabled"!
37 , m_aAsyncCall ( LINK( this, FrameContainer, implts_asyncQuit ) )
42 /**-***************************************************************************************************************
43 @short deinitialize may a filled container
44 @descr Special features (if the currently are running) will be dsiabled and we free all used other resources.
46 @threadsafe not necessary - its not a singleton
47 *****************************************************************************************************************/
48 FrameContainer::~FrameContainer()
50 // Don't forget to free memory!
52 m_xActiveFrame
.clear();
55 /**-***************************************************************************************************************
56 @short append a new frame to the container
57 @descr We accept the incoming frame only, if it is a valid reference and dosnt exist already.
60 frame, which should be added to this container
61 Must be a valid reference.
64 *****************************************************************************************************************/
65 void FrameContainer::append( const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
67 if (xFrame
.is() && ! exist(xFrame
))
70 m_aContainer
.push_back( xFrame
);
74 /**-***************************************************************************************************************
75 @short remove a frame from the container
76 @descr In case we remove the last frame and our internal special feature (the async quit mechanism)
77 was enabled by the desktop instance, we start it.
80 frame, which should be deleted from this container
81 Must be a valid reference.
84 *****************************************************************************************************************/
85 void FrameContainer::remove( const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
89 TFrameIterator aSearchedItem
= ::std::find( m_aContainer
.begin(), m_aContainer
.end(), xFrame
);
90 if (aSearchedItem
!=m_aContainer
.end())
92 m_aContainer
.erase( aSearchedItem
);
94 // If removed frame was the current active frame - reset state variable.
95 if (m_xActiveFrame
==xFrame
)
96 m_xActiveFrame
= css::uno::Reference
< css::frame::XFrame
>();
100 /**-***************************************************************************************************************
101 @short check if the given frame currently exist inside the container
103 reference to the queried frame
105 @return <TRUE/> if frame is oart of this container
109 *****************************************************************************************************************/
110 bool FrameContainer::exist( const css::uno::Reference
< css::frame::XFrame
>& xFrame
) const
113 return( ::std::find( m_aContainer
.begin(), m_aContainer
.end(), xFrame
) != m_aContainer
.end() );
116 /**-***************************************************************************************************************
117 @short delete all existing items of the container
119 *****************************************************************************************************************/
120 void FrameContainer::clear()
123 // Clear the container ...
124 m_aContainer
.clear();
125 // ... and don't forget to reset the active frame.
126 // Its an reference to a valid container-item.
127 // But no container item => no active frame!
128 m_xActiveFrame
= css::uno::Reference
< css::frame::XFrame
>();
131 /**-***************************************************************************************************************
132 @short returns count of all current existing frames
133 @deprecated This value can't be guaranteed for multithreading environments.
134 So it will be marked as deprecated and should be replaced by "getAllElements()".
136 @return the count of existing container items
139 *****************************************************************************************************************/
140 sal_uInt32
FrameContainer::getCount() const
143 return( (sal_uInt32
)m_aContainer
.size() );
146 /**-***************************************************************************************************************
147 @short returns one item of this container
148 @deprecated This value can't be guaranteed for multithreading environments.
149 So it will be marked as deprecatedf and should be replaced by "getAllElements()".
152 a valud between 0 and (getCount()-1) to address one container item
154 @return a reference to a frame inside the container, which match with given index
157 *****************************************************************************************************************/
158 css::uno::Reference
< css::frame::XFrame
> FrameContainer::operator[]( sal_uInt32 nIndex
) const
161 css::uno::Reference
< css::frame::XFrame
> xFrame
;
164 // Get element form container WITH automatic test of ranges!
165 // If index not valid, a out_of_range exception is thrown.
167 xFrame
= m_aContainer
.at( nIndex
);
169 catch( const std::out_of_range
& )
171 // The index is not valid for current container-content - we must handle this case!
172 // We can return the default value ...
173 SAL_INFO( "fwk", "FrameContainer::operator[]: Exception caught: std::out_of_range" );
178 /**-***************************************************************************************************************
179 @short returns a snapshot of all currently existing frames inside this container
180 @descr Should be used to replace the deprecated functions getCount()/operator[]!
182 @return a list of all frame references inside this container
185 *****************************************************************************************************************/
186 css::uno::Sequence
< css::uno::Reference
< css::frame::XFrame
> > FrameContainer::getAllElements() const
189 sal_Int32 nPosition
= 0;
190 css::uno::Sequence
< css::uno::Reference
< css::frame::XFrame
> > lElements ( (sal_uInt32
)m_aContainer
.size() );
191 for (TConstFrameIterator pItem
=m_aContainer
.begin(); pItem
!=m_aContainer
.end(); ++pItem
)
192 lElements
[nPosition
++] = *pItem
;
196 /**-***************************************************************************************************************
197 @short set the given frame as the new active one inside this container
198 @descr We accept this frame only, if it's already a part of this container.
201 reference to the new active frame
202 Must be a valid reference and already part of this container.
205 *****************************************************************************************************************/
206 void FrameContainer::setActive( const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
208 if ( !xFrame
.is() || exist(xFrame
) )
211 m_xActiveFrame
= xFrame
;
215 /**-***************************************************************************************************************
216 @short return sthe current active frame of this container
217 @descr Value can be null in case the frame was removed from the container and nobody
218 from outside decide which of all others should be the new one ...
220 @return a reference to the current active frame
224 *****************************************************************************************************************/
225 css::uno::Reference
< css::frame::XFrame
> FrameContainer::getActive() const
228 return m_xActiveFrame
;
231 /**-***************************************************************************************************************
232 @short implements a simple search based on current container items
233 @descr It can be used for findFrame() and implements a deep down search.
236 target name, which is searched
238 @return reference to the found frame or NULL if not.
241 *****************************************************************************************************************/
242 css::uno::Reference
< css::frame::XFrame
> FrameContainer::searchOnAllChildrens( const OUString
& sName
) const
245 // Step over all child frames. But if direct child isn't the right one search on his children first - before
246 // you go to next direct child of this container!
247 css::uno::Reference
< css::frame::XFrame
> xSearchedFrame
;
248 for( TConstFrameIterator pIterator
=m_aContainer
.begin(); pIterator
!=m_aContainer
.end(); ++pIterator
)
250 if ((*pIterator
)->getName()==sName
)
252 xSearchedFrame
= *pIterator
;
257 xSearchedFrame
= (*pIterator
)->findFrame( sName
, css::frame::FrameSearchFlag::CHILDREN
);
258 if (xSearchedFrame
.is())
262 return xSearchedFrame
;
265 /**-***************************************************************************************************************
266 @short implements a simple search based on current container items
267 @descr It can be used for findFrame() and search on members of this container only!
270 target name, which is searched
272 @return reference to the found frame or NULL if not.
275 *****************************************************************************************************************/
276 css::uno::Reference
< css::frame::XFrame
> FrameContainer::searchOnDirectChildrens( const OUString
& sName
) const
279 css::uno::Reference
< css::frame::XFrame
> xSearchedFrame
;
280 for( TConstFrameIterator pIterator
=m_aContainer
.begin(); pIterator
!=m_aContainer
.end(); ++pIterator
)
282 if ((*pIterator
)->getName()==sName
)
284 xSearchedFrame
= *pIterator
;
288 return xSearchedFrame
;
291 } // namespace framework
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */