Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / unoobj / forbiuno.cxx
blob242816de80fc58665534526b70529f8811e1045a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <editeng/forbiddencharacterstable.hxx>
22 #include "forbiuno.hxx"
23 #include "docsh.hxx"
25 using namespace ::com::sun::star;
27 //------------------------------------------------------------------------
29 static rtl::Reference<SvxForbiddenCharactersTable> lcl_GetForbidden( ScDocShell* pDocSh )
31 rtl::Reference<SvxForbiddenCharactersTable> xRet;
32 if ( pDocSh )
34 ScDocument* pDoc = pDocSh->GetDocument();
35 xRet = pDoc->GetForbiddenCharacters();
36 if ( !xRet.is() )
38 // create an empty SvxForbiddenCharactersTable for SvxUnoForbiddenCharsTable,
39 // so changes can be stored.
41 xRet = new SvxForbiddenCharactersTable( comphelper::getProcessComponentContext() );
42 pDoc->SetForbiddenCharacters( xRet );
45 return xRet;
48 ScForbiddenCharsObj::ScForbiddenCharsObj( ScDocShell* pDocSh ) :
49 SvxUnoForbiddenCharsTable( lcl_GetForbidden( pDocSh ) ),
50 pDocShell( pDocSh )
52 if (pDocShell)
53 pDocShell->GetDocument()->AddUnoObject(*this);
56 ScForbiddenCharsObj::~ScForbiddenCharsObj()
58 if (pDocShell)
59 pDocShell->GetDocument()->RemoveUnoObject(*this);
62 void ScForbiddenCharsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
64 if ( rHint.ISA( SfxSimpleHint ) &&
65 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
67 pDocShell = NULL; // document gone
71 void ScForbiddenCharsObj::onChange()
73 if (pDocShell)
75 pDocShell->GetDocument()->SetForbiddenCharacters( mxForbiddenChars );
76 pDocShell->PostPaintGridAll();
77 pDocShell->SetDocumentModified();
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */