fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / helper / ocomponentenumeration.cxx
blob260c96330bb6029dcc2a132e2c840bf46cbbdbb8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <helper/ocomponentenumeration.hxx>
22 #include <vcl/svapp.hxx>
24 namespace framework{
26 using namespace ::com::sun::star::container;
27 using namespace ::com::sun::star::lang;
28 using namespace ::com::sun::star::uno;
29 using namespace ::cppu;
30 using namespace ::osl;
32 // constructor
34 OComponentEnumeration::OComponentEnumeration( const Sequence< css::uno::Reference< XComponent > >& seqComponents )
35 : m_nPosition ( 0 ) // 0 is the first position for a valid list and the right value for an invalid list to!
36 , m_seqComponents ( seqComponents )
39 // destructor
41 OComponentEnumeration::~OComponentEnumeration()
43 // Reset instance, free memory ....
44 impl_resetObject();
47 // XEventListener
48 void SAL_CALL OComponentEnumeration::disposing( const EventObject& aEvent ) throw( RuntimeException, std::exception )
50 SolarMutexGuard g;
52 // Safe impossible cases
53 // This method is not specified for all incoming parameters.
54 (void) aEvent;
55 SAL_WARN_IF( !aEvent.Source.is(), "fwk", "OComponentEnumeration::disposing(): Invalid parameter detected!" );
57 // Reset instance to defaults, release references and free memory.
58 impl_resetObject();
61 // XEnumeration
62 sal_Bool SAL_CALL OComponentEnumeration::hasMoreElements() throw( RuntimeException, std::exception )
64 SolarMutexGuard g;
66 // First position in a valid list is 0.
67 // => The last one is getLength() - 1!
68 // m_nPosition's current value is the position for the next element, which will be return, if user call "nextElement()"
69 // => We have more elements if current position less then the length of the list!
70 return ( m_nPosition < (sal_uInt32)(m_seqComponents.getLength()) );
73 // XEnumeration
75 Any SAL_CALL OComponentEnumeration::nextElement() throw( NoSuchElementException ,
76 WrappedTargetException ,
77 RuntimeException, std::exception )
79 SolarMutexGuard g;
81 // If we have no elements or end of enumeration is arrived ...
82 if ( hasMoreElements() == sal_False )
84 // .. throw an exception!
85 throw NoSuchElementException();
88 // Else; Get next element from list ...
89 Any aComponent;
90 aComponent <<= m_seqComponents[m_nPosition];
91 // ... and step to next element!
92 ++m_nPosition;
94 // Return listitem.
95 return aComponent;
98 // proteced method
100 void OComponentEnumeration::impl_resetObject()
102 // Attention:
103 // Write this for multiple calls - NOT AT THE SAME TIME - but for more than one call again)!
104 // It exist two ways to call this method. From destructor and from disposing().
105 // I can't say, which one is the first. Normally the disposing-call - but other way ....
107 // Delete list of components.
108 m_seqComponents.realloc( 0 );
109 // Reset position in list.
110 // The list has no elements anymore. m_nPosition is normally the current position in list for nextElement!
111 // But a position of 0 in a list of 0 items is an invalid state. This constellation can't work in future.
112 // End of enumeration is arrived!
113 // (see hasMoreElements() for more details...)
114 m_nPosition = 0;
117 } // namespace framework
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */