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 <comphelper/processfactory.hxx>
21 #include <svl/zforlist.hxx>
22 #include <editeng/editeng.hxx>
23
24 #include <poolhelp.hxx>
25 #include <document.hxx>
26 #include <docpool.hxx>
27 #include <stlpool.hxx>
28
ScPoolHelper(ScDocument & rSourceDoc)29 ScPoolHelper::ScPoolHelper( ScDocument& rSourceDoc )
30 : pDocPool(new ScDocumentPool)
31 , m_rSourceDoc(rSourceDoc)
32 {
33 pDocPool->FreezeIdRanges();
34
35 mxStylePool = new ScStyleSheetPool( *pDocPool, &rSourceDoc );
36 }
37
~ScPoolHelper()38 ScPoolHelper::~ScPoolHelper()
39 {
40 pEnginePool.clear();
41 pEditPool.clear();
42 pFormTable.reset();
43 mxStylePool.clear();
44 pDocPool.clear();
45 }
46
GetEditPool() const47 SfxItemPool* ScPoolHelper::GetEditPool() const
48 {
49 if ( !pEditPool )
50 {
51 pEditPool = EditEngine::CreatePool();
52 pEditPool->SetDefaultMetric( MapUnit::Map100thMM );
53 pEditPool->FreezeIdRanges();
54 }
55 return pEditPool.get();
56 }
57
GetEnginePool() const58 SfxItemPool* ScPoolHelper::GetEnginePool() const
59 {
60 if ( !pEnginePool )
61 {
62 pEnginePool = EditEngine::CreatePool();
63 pEnginePool->SetDefaultMetric( MapUnit::Map100thMM );
64 pEnginePool->FreezeIdRanges();
65 } // ifg ( pEnginePool )
66 return pEnginePool.get();
67 }
GetFormTable() const68 SvNumberFormatter* ScPoolHelper::GetFormTable() const
69 {
70 if (!pFormTable)
71 pFormTable = CreateNumberFormatter();
72 return pFormTable.get();
73 }
74
SetFormTableOpt(const ScDocOptions & rOpt)75 void ScPoolHelper::SetFormTableOpt(const ScDocOptions& rOpt)
76 {
77 aOpt = rOpt;
78 // #i105512# if the number formatter exists, update its settings
79 if (pFormTable)
80 {
81 sal_uInt16 d,m;
82 sal_Int16 y;
83 aOpt.GetDate( d,m,y );
84 pFormTable->ChangeNullDate( d,m,y );
85 pFormTable->ChangeStandardPrec( aOpt.GetStdPrecision() );
86 pFormTable->SetYear2000( aOpt.GetYear2000() );
87 }
88 }
89
CreateNumberFormatter() const90 std::unique_ptr<SvNumberFormatter> ScPoolHelper::CreateNumberFormatter() const
91 {
92 std::unique_ptr<SvNumberFormatter> p;
93 {
94 osl::MutexGuard aGuard(&maMtxCreateNumFormatter);
95 p.reset(new SvNumberFormatter(comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM));
96 }
97 p->SetColorLink( LINK(&m_rSourceDoc, ScDocument, GetUserDefinedColor) );
98 p->SetEvalDateFormat(NF_EVALDATEFORMAT_INTL_FORMAT);
99
100 sal_uInt16 d,m;
101 sal_Int16 y;
102 aOpt.GetDate(d, m, y);
103 p->ChangeNullDate(d, m, y);
104 p->ChangeStandardPrec(aOpt.GetStdPrecision());
105 p->SetYear2000(aOpt.GetYear2000());
106 return p;
107 }
108
SourceDocumentGone()109 void ScPoolHelper::SourceDocumentGone()
110 {
111 // reset all pointers to the source document
112 mxStylePool->SetDocument( nullptr );
113 if ( pFormTable )
114 pFormTable->SetColorLink( Link<sal_uInt16,Color*>() );
115 }
116
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
118