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