merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / unoidl / unowcntr.cxx
blobcd7c3ae10eab502398c69ecc39e577b98038a3ac
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: unowcntr.cxx,v $
10 * $Revision: 1.6 $
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_sd.hxx"
33 #include <com/sun/star/lang/XComponent.hpp>
34 #include <tools/list.hxx>
36 #include <unowcntr.hxx>
38 using namespace ::rtl;
39 using namespace ::com::sun::star;
41 DECLARE_LIST( WeakRefList, uno::WeakReference< uno::XInterface >* )
43 SvUnoWeakContainer::SvUnoWeakContainer() throw()
45 mpList = new WeakRefList;
48 SvUnoWeakContainer::~SvUnoWeakContainer() throw()
50 uno::WeakReference< uno::XInterface >* pRef = mpList->First();
51 while( pRef )
53 delete mpList->Remove();
54 pRef = mpList->GetCurObject();
56 delete mpList;
59 /** inserts the given ref into this container */
60 void SvUnoWeakContainer::insert( uno::WeakReference< uno::XInterface > xRef ) throw()
62 uno::WeakReference< uno::XInterface >* pRef = mpList->First();
63 while( pRef )
65 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xTestRef( *pRef );
66 if(! xTestRef.is() )
68 delete mpList->Remove();
69 pRef = mpList->GetCurObject();
71 else
73 if( *pRef == xRef )
74 return;
76 pRef = mpList->Next();
80 mpList->Insert( new uno::WeakReference< uno::XInterface >( xRef ) );
83 /** removes the given ref from this container */
84 void SvUnoWeakContainer::remove( uno::WeakReference< uno::XInterface > xRef ) throw()
86 uno::WeakReference< uno::XInterface >* pRef = mpList->First();
87 while( pRef )
89 uno::Reference< uno::XInterface > xTestRef( *pRef );
90 if(!xTestRef.is())
92 delete mpList->Remove();
93 pRef = mpList->GetCurObject();
95 else
97 if( *pRef == xRef )
99 delete mpList->Remove();
100 break;
103 pRef = mpList->Next();
108 /** searches the container for a ref that returns true on the given
109 search function
111 sal_Bool SvUnoWeakContainer::findRef( uno::WeakReference< uno::XInterface >& rRef, void* pSearchData, weakref_searchfunc pSearchFunc )
113 uno::WeakReference< uno::XInterface >* pRef = mpList->First();
114 while( pRef )
116 uno::Reference< ::com::sun::star::uno::XInterface > xTestRef( *pRef );
117 if(!xTestRef.is())
119 delete mpList->Remove();
120 pRef = mpList->GetCurObject();
122 else
124 if( (*pSearchFunc)( *pRef, pSearchData ) )
126 rRef = *pRef;
127 return sal_True;
130 pRef = mpList->Next();
134 return sal_False;
137 void SvUnoWeakContainer::dispose()
139 uno::WeakReference< uno::XInterface >* pRef = mpList->First();
140 while( pRef )
142 uno::Reference< uno::XInterface > xTestRef( *pRef );
143 if(xTestRef.is())
145 uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY );
146 if( xComp.is() )
147 xComp->dispose();
150 pRef = mpList->Next();