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 : #include "vcl/window.hxx"
21 : #include "vcl/menu.hxx"
22 : #include "vcl/lazydelete.hxx"
23 : #include "svdata.hxx"
24 :
25 : namespace vcl {
26 :
27 943 : LazyDeletorBase::LazyDeletorBase()
28 : {
29 943 : }
30 :
31 917 : LazyDeletorBase::~LazyDeletorBase()
32 : {
33 917 : }
34 :
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;
38 :
39 : // a list for all LazyeDeletor<T> singletons
40 155 : static std::vector< LazyDeletorBase* > lcl_aDeletors;
41 :
42 943 : void LazyDelete::addDeletor( LazyDeletorBase* i_pDel )
43 : {
44 943 : lcl_aDeletors.push_back( i_pDel );
45 943 : }
46 :
47 125178 : void LazyDelete::flush()
48 : {
49 125178 : unsigned int nCount = lcl_aDeletors.size();
50 126095 : for( unsigned int i = 0; i < nCount; i++ )
51 917 : delete lcl_aDeletors[i];
52 125178 : lcl_aDeletors.clear();
53 125178 : }
54 :
55 : // specialized is_less function for Window
56 32 : template<> bool LazyDeletor<Window>::is_less( Window* left, Window* right )
57 : {
58 32 : return (left != right && right->IsChild( left, sal_True )) ? true : false;
59 : }
60 :
61 : #ifndef LINUX
62 : // specialized is_less function for Menu
63 : template<> bool LazyDeletor<Menu>::is_less( Menu* left, Menu* right )
64 : {
65 : while( left && left != right )
66 : left = left->ImplGetStartedFrom();
67 : return left != NULL;
68 : }
69 : #endif
70 :
71 330 : DeleteOnDeinitBase::~DeleteOnDeinitBase()
72 : {
73 330 : ImplSVData* pSVData = ImplGetSVData();
74 330 : if( pSVData && pSVData->mpDeinitDeleteList != NULL )
75 72 : pSVData->mpDeinitDeleteList->remove( this );
76 330 : }
77 :
78 330 : void DeleteOnDeinitBase::addDeinitContainer( DeleteOnDeinitBase* i_pContainer )
79 : {
80 330 : ImplSVData* pSVData = ImplGetSVData();
81 330 : if( ! pSVData )
82 : {
83 0 : ImplInitSVData();
84 0 : pSVData = ImplGetSVData();
85 : }
86 :
87 : DBG_ASSERT( ! pSVData->mbDeInit, "DeleteOnDeinit added after DeiInitVCL !" );
88 330 : if( pSVData->mbDeInit )
89 330 : return;
90 :
91 330 : if( pSVData->mpDeinitDeleteList == NULL )
92 43 : pSVData->mpDeinitDeleteList = new std::list< DeleteOnDeinitBase* >();
93 330 : pSVData->mpDeinitDeleteList->push_back( i_pContainer );
94 : }
95 :
96 94 : void DeleteOnDeinitBase::ImplDeleteOnDeInit()
97 : {
98 94 : ImplSVData* pSVData = ImplGetSVData();
99 94 : if( pSVData->mpDeinitDeleteList )
100 : {
101 876 : for( std::list< vcl::DeleteOnDeinitBase* >::iterator it = pSVData->mpDeinitDeleteList->begin();
102 584 : it != pSVData->mpDeinitDeleteList->end(); ++it )
103 : {
104 258 : (*it)->doCleanup();
105 : }
106 34 : delete pSVData->mpDeinitDeleteList;
107 34 : pSVData->mpDeinitDeleteList = NULL;
108 : }
109 94 : }
110 :
111 465 : } // namespace vcl
112 :
113 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|