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 <svl/zforlist.hxx>
21 : #include <editeng/editeng.hxx>
22 :
23 : #include "poolhelp.hxx"
24 : #include "document.hxx"
25 : #include "docpool.hxx"
26 : #include "stlpool.hxx"
27 :
28 : // -----------------------------------------------------------------------
29 :
30 189 : ScPoolHelper::ScPoolHelper( ScDocument* pSourceDoc )
31 : :pFormTable(NULL)
32 : ,pEditPool(NULL)
33 : ,pEnginePool(NULL)
34 189 : ,m_pSourceDoc(pSourceDoc)
35 : {
36 : OSL_ENSURE( pSourceDoc, "ScPoolHelper: no document" );
37 189 : pDocPool = new ScDocumentPool;
38 189 : pDocPool->FreezeIdRanges();
39 :
40 189 : mxStylePool = new ScStyleSheetPool( *pDocPool, pSourceDoc );
41 189 : }
42 :
43 324 : ScPoolHelper::~ScPoolHelper()
44 : {
45 108 : SfxItemPool::Free(pEnginePool);
46 108 : SfxItemPool::Free(pEditPool);
47 108 : delete pFormTable;
48 108 : mxStylePool.clear();
49 108 : SfxItemPool::Free(pDocPool);
50 216 : }
51 93 : SfxItemPool* ScPoolHelper::GetEditPool() const
52 : {
53 93 : if ( !pEditPool )
54 : {
55 12 : pEditPool = EditEngine::CreatePool();
56 12 : pEditPool->SetDefaultMetric( SFX_MAPUNIT_100TH_MM );
57 12 : pEditPool->FreezeIdRanges();
58 12 : pEditPool->SetFileFormatVersion( SOFFICE_FILEFORMAT_50 ); // used in ScGlobal::EETextObjEqual
59 : }
60 93 : return pEditPool;
61 : }
62 25 : SfxItemPool* ScPoolHelper::GetEnginePool() const
63 : {
64 25 : if ( !pEnginePool )
65 : {
66 9 : pEnginePool = EditEngine::CreatePool();
67 9 : pEnginePool->SetDefaultMetric( SFX_MAPUNIT_100TH_MM );
68 9 : pEnginePool->FreezeIdRanges();
69 : } // ifg ( pEnginePool )
70 25 : return pEnginePool;
71 : }
72 28177 : SvNumberFormatter* ScPoolHelper::GetFormTable() const
73 : {
74 28177 : if ( !pFormTable )
75 : {
76 104 : pFormTable = new SvNumberFormatter( m_pSourceDoc->GetServiceManager(), ScGlobal::eLnge );
77 104 : pFormTable->SetColorLink( LINK( m_pSourceDoc, ScDocument, GetUserDefinedColor ) );
78 104 : pFormTable->SetEvalDateFormat( NF_EVALDATEFORMAT_INTL_FORMAT );
79 :
80 104 : UseDocOptions(); // null date, year2000, std precision
81 : }
82 28177 : return pFormTable;
83 : }
84 :
85 532 : void ScPoolHelper::UseDocOptions() const
86 : {
87 532 : if (pFormTable)
88 : {
89 : sal_uInt16 d,m,y;
90 461 : aOpt.GetDate( d,m,y );
91 461 : pFormTable->ChangeNullDate( d,m,y );
92 461 : pFormTable->ChangeStandardPrec( (sal_uInt16)aOpt.GetStdPrecision() );
93 461 : pFormTable->SetYear2000( aOpt.GetYear2000() );
94 : }
95 532 : }
96 :
97 428 : void ScPoolHelper::SetFormTableOpt(const ScDocOptions& rOpt)
98 : {
99 428 : aOpt = rOpt;
100 428 : UseDocOptions(); // #i105512# if the number formatter exists, update its settings
101 428 : }
102 :
103 109 : void ScPoolHelper::SourceDocumentGone()
104 : {
105 : // reset all pointers to the source document
106 109 : mxStylePool->SetDocument( NULL );
107 109 : if ( pFormTable )
108 60 : pFormTable->SetColorLink( Link() );
109 109 : }
110 :
111 : // -----------------------------------------------------------------------
112 :
113 :
114 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|