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 pointers for LazyDeletor<Window,Menu>
36 template<> LazyDeletor
<Window
>* LazyDeletor
<Window
>::s_pOneInstance
= NULL
;
37 template<> LazyDeletor
<Menu
>* LazyDeletor
<Menu
>::s_pOneInstance
= NULL
;
39 // a list for all LazyeDeletor<T> singletons
40 static std::vector
< LazyDeletorBase
* > lcl_aDeletors
;
42 void LazyDelete::addDeletor( LazyDeletorBase
* i_pDel
)
44 lcl_aDeletors
.push_back( i_pDel
);
47 void LazyDelete::flush()
49 unsigned int nCount
= lcl_aDeletors
.size();
50 for( unsigned int i
= 0; i
< nCount
; i
++ )
51 delete lcl_aDeletors
[i
];
52 lcl_aDeletors
.clear();
55 // specialized is_less function for Window
56 template<> bool LazyDeletor
<Window
>::is_less( Window
* left
, Window
* right
)
58 return (left
!= right
&& right
->IsChild( left
, sal_True
)) ? true : false;
62 // specialized is_less function for Menu
63 template<> bool LazyDeletor
<Menu
>::is_less( Menu
* left
, Menu
* right
)
65 while( left
&& left
!= right
)
66 left
= left
->ImplGetStartedFrom();
71 DeleteOnDeinitBase::~DeleteOnDeinitBase()
73 ImplSVData
* pSVData
= ImplGetSVData();
74 if( pSVData
&& pSVData
->mpDeinitDeleteList
!= NULL
)
75 pSVData
->mpDeinitDeleteList
->remove( this );
78 void DeleteOnDeinitBase::addDeinitContainer( DeleteOnDeinitBase
* i_pContainer
)
80 ImplSVData
* pSVData
= ImplGetSVData();
84 pSVData
= ImplGetSVData();
87 DBG_ASSERT( ! pSVData
->mbDeInit
, "DeleteOnDeinit added after DeiInitVCL !" );
88 if( pSVData
->mbDeInit
)
91 if( pSVData
->mpDeinitDeleteList
== NULL
)
92 pSVData
->mpDeinitDeleteList
= new std::list
< DeleteOnDeinitBase
* >();
93 pSVData
->mpDeinitDeleteList
->push_back( i_pContainer
);
96 void DeleteOnDeinitBase::ImplDeleteOnDeInit()
98 ImplSVData
* pSVData
= ImplGetSVData();
99 if( pSVData
->mpDeinitDeleteList
)
101 for( std::list
< vcl::DeleteOnDeinitBase
* >::iterator it
= pSVData
->mpDeinitDeleteList
->begin();
102 it
!= pSVData
->mpDeinitDeleteList
->end(); ++it
)
106 delete pSVData
->mpDeinitDeleteList
;
107 pSVData
->mpDeinitDeleteList
= NULL
;
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */