xref: /aoo41x/main/sc/source/core/data/poolhelp.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 // INCLUDE ---------------------------------------------------------------
34 
35 #include <svl/zforlist.hxx>
36 #include <editeng/editeng.hxx>
37 
38 #include "poolhelp.hxx"
39 #include "document.hxx"
40 #include "docpool.hxx"
41 #include "stlpool.hxx"
42 
43 // -----------------------------------------------------------------------
44 
45 ScPoolHelper::ScPoolHelper( ScDocument* pSourceDoc )
46 :pFormTable(NULL)
47 ,pEditPool(NULL)
48 ,pEnginePool(NULL)
49 ,m_pSourceDoc(pSourceDoc)
50 {
51 	DBG_ASSERT( pSourceDoc, "ScPoolHelper: no document" );
52 	pDocPool = new ScDocumentPool;
53 	pDocPool->FreezeIdRanges();
54 
55 	mxStylePool = new ScStyleSheetPool( *pDocPool, pSourceDoc );
56 }
57 
58 ScPoolHelper::~ScPoolHelper()
59 {
60 	SfxItemPool::Free(pEnginePool);
61 	SfxItemPool::Free(pEditPool);
62 	delete pFormTable;
63 	mxStylePool.clear();
64 	SfxItemPool::Free(pDocPool);
65 }
66 SfxItemPool*		ScPoolHelper::GetEditPool() const
67 {
68     if ( !pEditPool )
69     {
70         pEditPool = EditEngine::CreatePool();
71 	    pEditPool->SetDefaultMetric( SFX_MAPUNIT_100TH_MM );
72 	    pEditPool->FreezeIdRanges();
73 	    pEditPool->SetFileFormatVersion( SOFFICE_FILEFORMAT_50 );	// used in ScGlobal::EETextObjEqual
74     }
75     return pEditPool;
76 }
77 SfxItemPool*		ScPoolHelper::GetEnginePool() const
78 {
79     if ( !pEnginePool )
80     {
81         pEnginePool = EditEngine::CreatePool();
82 	    pEnginePool->SetDefaultMetric( SFX_MAPUNIT_100TH_MM );
83 	    pEnginePool->FreezeIdRanges();
84     } // ifg ( pEnginePool )
85     return pEnginePool;
86 }
87 SvNumberFormatter*	ScPoolHelper::GetFormTable() const
88 {
89     if ( !pFormTable )
90     {
91         pFormTable = new SvNumberFormatter( m_pSourceDoc->GetServiceManager(), ScGlobal::eLnge );
92         pFormTable->SetColorLink( LINK( m_pSourceDoc, ScDocument, GetUserDefinedColor ) );
93 	    pFormTable->SetEvalDateFormat( NF_EVALDATEFORMAT_INTL_FORMAT );
94 
95         UseDocOptions();        // null date, year2000, std precision
96     }
97     return pFormTable;
98 }
99 
100 void ScPoolHelper::UseDocOptions() const
101 {
102     if (pFormTable)
103     {
104         sal_uInt16 d,m,y;
105         aOpt.GetDate( d,m,y );
106         pFormTable->ChangeNullDate( d,m,y );
107 	    pFormTable->ChangeStandardPrec( (sal_uInt16)aOpt.GetStdPrecision() );
108 	    pFormTable->SetYear2000( aOpt.GetYear2000() );
109     }
110 }
111 
112 void ScPoolHelper::SetFormTableOpt(const ScDocOptions& rOpt)
113 {
114     aOpt = rOpt;
115     UseDocOptions();        // #i105512# if the number formatter exists, update its settings
116 }
117 
118 void ScPoolHelper::SourceDocumentGone()
119 {
120 	//	reset all pointers to the source document
121 	mxStylePool->SetDocument( NULL );
122     if ( pFormTable )
123         pFormTable->SetColorLink( Link() );
124 }
125 
126 // -----------------------------------------------------------------------
127 
128 
129