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 <vcl/window.hxx>
21 #include <vcl/menu.hxx>
22 #include <vcl/lazydelete.hxx>
27 LazyDeletorBase::LazyDeletorBase()
31 LazyDeletorBase::~LazyDeletorBase()
35 // instantiate instance pointer for LazyDeletor<Window>
36 LazyDeletor
* LazyDeletor::s_pOneInstance
= nullptr;
38 // a list for all LazyeDeletor<T> singletons
39 static std::vector
< LazyDeletorBase
* > lcl_aDeletors
;
41 void LazyDelete::addDeletor( LazyDeletorBase
* i_pDel
)
43 lcl_aDeletors
.push_back( i_pDel
);
46 void LazyDelete::flush()
48 DBG_TESTSOLARMUTEX(); // must be locked
50 unsigned int nCount
= lcl_aDeletors
.size();
51 for( unsigned int i
= 0; i
< nCount
; i
++ )
52 delete lcl_aDeletors
[i
];
53 lcl_aDeletors
.clear();
56 // specialized is_less function for Window
57 bool LazyDeletor::is_less( vcl::Window
* left
, vcl::Window
* right
)
59 return left
!= right
&& right
->IsChild( left
, true );
62 DeleteOnDeinitBase::~DeleteOnDeinitBase()
64 ImplSVData
* pSVData
= ImplGetSVData();
65 if( pSVData
&& pSVData
->mpDeinitDeleteList
!= nullptr )
66 pSVData
->mpDeinitDeleteList
->remove( this );
69 void DeleteOnDeinitBase::addDeinitContainer( DeleteOnDeinitBase
* i_pContainer
)
71 ImplSVData
* pSVData
= ImplGetSVData();
73 SAL_WARN_IF( pSVData
->mbDeInit
, "vcl", "DeleteOnDeinit added after DeiInitVCL !" );
74 if( pSVData
->mbDeInit
)
77 if( pSVData
->mpDeinitDeleteList
== nullptr )
78 pSVData
->mpDeinitDeleteList
= new std::list
< DeleteOnDeinitBase
* >();
79 pSVData
->mpDeinitDeleteList
->push_back( i_pContainer
);
82 void DeleteOnDeinitBase::ImplDeleteOnDeInit()
84 ImplSVData
* pSVData
= ImplGetSVData();
85 if( pSVData
->mpDeinitDeleteList
)
87 for( std::list
< vcl::DeleteOnDeinitBase
* >::iterator it
= pSVData
->mpDeinitDeleteList
->begin();
88 it
!= pSVData
->mpDeinitDeleteList
->end(); ++it
)
92 delete pSVData
->mpDeinitDeleteList
;
93 pSVData
->mpDeinitDeleteList
= nullptr;
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */