tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / unoidl / unowcntr.cxx
blob7cc43c906c9d5eff612523ed3ec9b730e699feea
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 <com/sun/star/lang/XComponent.hpp>
22 #include "unowcntr.hxx"
23 #include "unolayer.hxx"
25 using namespace ::com::sun::star;
27 SvUnoWeakContainer::SvUnoWeakContainer() noexcept
31 SvUnoWeakContainer::~SvUnoWeakContainer() noexcept
35 /** inserts the given ref into this container */
36 void SvUnoWeakContainer::insert( const rtl::Reference< SdLayer >& xRef ) noexcept
38 for ( auto it = maVector.begin(); it != maVector.end(); )
40 unotools::WeakReference< SdLayer > & rWeakRef = *it;
41 rtl::Reference< SdLayer > xTestRef( rWeakRef );
42 if ( !xTestRef.is() )
44 it = maVector.erase( it );
46 else
48 if ( xTestRef == xRef )
49 return;
50 ++it;
53 maVector.emplace_back( xRef );
56 /** searches the container for a ref that returns true on the given
57 search function
59 bool SvUnoWeakContainer::findRef(
60 rtl::Reference< SdLayer >& rRef,
61 SdrLayer const * pSearchData
64 for ( auto it = maVector.begin(); it != maVector.end(); )
66 unotools::WeakReference< SdLayer > & itRef = *it;
67 rtl::Reference< SdLayer > xSdLayer( itRef );
68 if ( !xSdLayer.is() )
70 it = maVector.erase( it );
72 else
74 SdrLayer* pSdrLayer = xSdLayer->GetSdrLayer ();
75 if (pSdrLayer == pSearchData)
77 rRef = std::move(xSdLayer);
78 return true;
80 ++it;
83 return false;
86 void SvUnoWeakContainer::dispose()
88 for (auto const& elem : maVector)
90 uno::Reference< uno::XInterface > xTestRef( elem );
91 if ( xTestRef.is() )
93 uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY );
94 if( xComp.is() )
95 xComp->dispose();
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */