Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef LAZYDELETE_CXX
21 : #define LAZYDELETE_CXX
22 :
23 : #include "vcl/window.hxx"
24 : #include "vcl/menu.hxx"
25 : #include "vcl/lazydelete.hxx"
26 : #include "svdata.hxx"
27 :
28 : namespace vcl {
29 :
30 42 : LazyDeletorBase::LazyDeletorBase()
31 : {
32 42 : }
33 :
34 34 : LazyDeletorBase::~LazyDeletorBase()
35 : {
36 34 : }
37 :
38 : // instantiate instance pointers for LazyDeletor<Window,Menu>
39 : template<> LazyDeletor<Window>* LazyDeletor<Window>::s_pOneInstance = NULL;
40 : template<> LazyDeletor<Menu>* LazyDeletor<Menu>::s_pOneInstance = NULL;
41 :
42 : // a list for all LazyeDeletor<T> singletons
43 36 : static std::vector< LazyDeletorBase* > lcl_aDeletors;
44 :
45 42 : void LazyDelete::addDeletor( LazyDeletorBase* i_pDel )
46 : {
47 42 : lcl_aDeletors.push_back( i_pDel );
48 42 : }
49 :
50 846 : void LazyDelete::flush()
51 : {
52 846 : unsigned int nCount = lcl_aDeletors.size();
53 880 : for( unsigned int i = 0; i < nCount; i++ )
54 34 : delete lcl_aDeletors[i];
55 846 : lcl_aDeletors.clear();
56 846 : }
57 :
58 : // specialized is_less function for Window
59 0 : template<> bool LazyDeletor<Window>::is_less( Window* left, Window* right )
60 : {
61 0 : return (left != right && right->IsChild( left, sal_True )) ? true : false;
62 : }
63 :
64 : #ifndef LINUX
65 : // specialized is_less function for Menu
66 : template<> bool LazyDeletor<Menu>::is_less( Menu* left, Menu* right )
67 : {
68 : while( left && left != right )
69 : left = left->ImplGetStartedFrom();
70 : return left != NULL;
71 : }
72 : #endif
73 :
74 66 : DeleteOnDeinitBase::~DeleteOnDeinitBase()
75 : {
76 66 : ImplSVData* pSVData = ImplGetSVData();
77 66 : if( pSVData && pSVData->mpDeinitDeleteList != NULL )
78 66 : pSVData->mpDeinitDeleteList->remove( this );
79 66 : }
80 :
81 66 : void DeleteOnDeinitBase::addDeinitContainer( DeleteOnDeinitBase* i_pContainer )
82 : {
83 66 : ImplSVData* pSVData = ImplGetSVData();
84 66 : if( ! pSVData )
85 : {
86 0 : ImplInitSVData();
87 0 : pSVData = ImplGetSVData();
88 : }
89 :
90 : DBG_ASSERT( ! pSVData->mbDeInit, "DeleteOnDeinit added after DeiInitVCL !" );
91 66 : if( pSVData->mbDeInit )
92 66 : return;
93 :
94 66 : if( pSVData->mpDeinitDeleteList == NULL )
95 7 : pSVData->mpDeinitDeleteList = new std::list< DeleteOnDeinitBase* >();
96 66 : pSVData->mpDeinitDeleteList->push_back( i_pContainer );
97 : }
98 :
99 0 : void DeleteOnDeinitBase::ImplDeleteOnDeInit()
100 : {
101 0 : ImplSVData* pSVData = ImplGetSVData();
102 0 : if( pSVData->mpDeinitDeleteList )
103 : {
104 0 : for( std::list< vcl::DeleteOnDeinitBase* >::iterator it = pSVData->mpDeinitDeleteList->begin();
105 0 : it != pSVData->mpDeinitDeleteList->end(); ++it )
106 : {
107 0 : (*it)->doCleanup();
108 : }
109 0 : delete pSVData->mpDeinitDeleteList;
110 0 : pSVData->mpDeinitDeleteList = NULL;
111 : }
112 0 : }
113 :
114 108 : } // namespace vcl
115 :
116 : #endif
117 :
118 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|