/src/libreoffice/sc/source/ui/docshell/docsh2.cxx
Line | Count | Source |
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 <rtl/bootstrap.hxx> |
21 | | #include <osl/file.hxx> |
22 | | #include <svx/drawitem.hxx> |
23 | | #include <svl/asiancfg.hxx> |
24 | | #include <editeng/forbiddencharacterstable.hxx> |
25 | | #include <orcusfilters.hxx> |
26 | | #include <config_folders.h> |
27 | | #include <comphelper/configuration.hxx> |
28 | | #include <comphelper/processfactory.hxx> |
29 | | #include <o3tl/unit_conversion.hxx> |
30 | | |
31 | | #include <drwlayer.hxx> |
32 | | #include <stlpool.hxx> |
33 | | #include <docsh.hxx> |
34 | | #include <docfunc.hxx> |
35 | | #include <svx/svxids.hrc> |
36 | | #include <filter.hxx> |
37 | | #include <functional> |
38 | | |
39 | | using namespace com::sun::star; |
40 | | |
41 | | bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor ) |
42 | 31.7k | { |
43 | 31.7k | bool bRet = SfxObjectShell::InitNew( xStor ); |
44 | | |
45 | 31.7k | m_pDocument->MakeTable(0); |
46 | | |
47 | | // Additional tables are created by the first View, if bIsEmpty is still sal_True |
48 | 31.7k | if( bRet ) |
49 | 31.7k | { |
50 | 31.7k | Size aSize( |
51 | 31.7k | o3tl::convert(STD_COL_WIDTH * OLE_STD_CELLS_X, o3tl::Length::twip, o3tl::Length::mm100), |
52 | 31.7k | o3tl::convert(ScGlobal::nStdRowHeight * OLE_STD_CELLS_Y, o3tl::Length::twip, |
53 | 31.7k | o3tl::Length::mm100)); |
54 | | // Also adjust start here |
55 | 31.7k | SetVisAreaOrSize( tools::Rectangle( Point(), aSize ) ); |
56 | 31.7k | } |
57 | | |
58 | | // InitOptions sets the document languages, must be called before CreateStandardStyles |
59 | 31.7k | InitOptions(false); |
60 | | |
61 | 31.7k | if (ScStyleSheetPool* pStyleSheetPool = m_pDocument->GetStyleSheetPool()) |
62 | 31.7k | { |
63 | 31.7k | pStyleSheetPool->CreateStandardStyles(); |
64 | 31.7k | m_pDocument->getCellAttributeHelper().UpdateAllStyleSheets(*m_pDocument); |
65 | | |
66 | | /* Create styles that are imported through Orcus */ |
67 | | |
68 | 31.7k | OUString aURL(u"$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/calc/styles.xml"_ustr); |
69 | 31.7k | rtl::Bootstrap::expandMacros(aURL); |
70 | | |
71 | 31.7k | OUString aPath; |
72 | 31.7k | osl::FileBase::getSystemPathFromFileURL(aURL, aPath); |
73 | | |
74 | 31.7k | ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters(); |
75 | 31.7k | if (pOrcus) |
76 | 31.7k | { |
77 | 31.7k | pOrcus->importODS_Styles(*m_pDocument, aPath); |
78 | 31.7k | pStyleSheetPool->setAllParaStandard(); |
79 | 31.7k | } |
80 | 31.7k | } |
81 | | |
82 | | // SetDocumentModified is not allowed anymore in Load/InitNew! |
83 | 31.7k | InitItems(); |
84 | 31.7k | CalcOutputFactor(); |
85 | | |
86 | 31.7k | return bRet; |
87 | 31.7k | } |
88 | | |
89 | | void ScDocShell::SetEmpty(bool bSet) |
90 | 4.04k | { |
91 | 4.04k | m_bIsEmpty = bSet; |
92 | 4.04k | } |
93 | | |
94 | | void ScDocShell::InitItems() |
95 | 35.6k | { |
96 | | // Fill AllItemSet for Controller with needed Items: |
97 | | // Printer Options are set in GetPrinter when printing |
98 | 35.6k | UpdateFontList(); |
99 | | |
100 | 35.6k | ScDrawLayer* pDrawLayer = m_pDocument->GetDrawLayer(); |
101 | 35.6k | if (pDrawLayer) |
102 | 3.85k | { |
103 | 3.85k | PutItem( SvxColorListItem ( pDrawLayer->GetColorList(), SID_COLOR_TABLE ) ); |
104 | 3.85k | PutItem( SvxGradientListItem( pDrawLayer->GetGradientList(), SID_GRADIENT_LIST ) ); |
105 | 3.85k | PutItem( SvxHatchListItem ( pDrawLayer->GetHatchList(), SID_HATCH_LIST ) ); |
106 | 3.85k | PutItem( SvxBitmapListItem ( pDrawLayer->GetBitmapList(), SID_BITMAP_LIST ) ); |
107 | 3.85k | PutItem( SvxPatternListItem ( pDrawLayer->GetPatternList(), SID_PATTERN_LIST ) ); |
108 | 3.85k | PutItem( SvxDashListItem ( pDrawLayer->GetDashList(), SID_DASH_LIST ) ); |
109 | 3.85k | PutItem( SvxLineEndListItem ( pDrawLayer->GetLineEndList(), SID_LINEEND_LIST ) ); |
110 | | |
111 | | // Other modifications after creation of the DrawLayer |
112 | 3.85k | pDrawLayer->SetNotifyUndoActionHdl( [this](auto pUndo) { m_pDocFunc->NotifyDrawUndo(std::move(pUndo)); } ); |
113 | 3.85k | } |
114 | 31.7k | else if (!comphelper::IsFuzzing()) |
115 | 0 | { |
116 | | // always use global color table instead of local copy |
117 | 0 | PutItem( SvxColorListItem( XColorList::GetStdColorList(), SID_COLOR_TABLE ) ); |
118 | 0 | } |
119 | | |
120 | 35.6k | if (comphelper::IsFuzzing() || |
121 | 0 | (m_pDocument->GetForbiddenCharacters() && m_pDocument->IsValidAsianCompression() && m_pDocument->IsValidAsianKerning())) |
122 | 35.6k | return; |
123 | | |
124 | | // get settings from SvxAsianConfig |
125 | 0 | SvxAsianConfig aAsian; |
126 | |
|
127 | 0 | if (!m_pDocument->GetForbiddenCharacters()) |
128 | 0 | { |
129 | | // set forbidden characters if necessary |
130 | 0 | const uno::Sequence<lang::Locale> aLocales = SvxAsianConfig::GetStartEndCharLocales(); |
131 | 0 | if (aLocales.hasElements()) |
132 | 0 | { |
133 | 0 | std::shared_ptr<SvxForbiddenCharactersTable> xForbiddenTable( |
134 | 0 | SvxForbiddenCharactersTable::makeForbiddenCharactersTable(comphelper::getProcessComponentContext())); |
135 | |
|
136 | 0 | for (const lang::Locale& rLocale : aLocales) |
137 | 0 | { |
138 | 0 | i18n::ForbiddenCharacters aForbidden; |
139 | 0 | SvxAsianConfig::GetStartEndChars( rLocale, aForbidden.beginLine, aForbidden.endLine ); |
140 | 0 | LanguageType eLang = LanguageTag::convertToLanguageType(rLocale); |
141 | |
|
142 | 0 | xForbiddenTable->SetForbiddenCharacters( eLang, aForbidden ); |
143 | 0 | } |
144 | |
|
145 | 0 | m_pDocument->SetForbiddenCharacters( xForbiddenTable ); |
146 | 0 | } |
147 | 0 | } |
148 | |
|
149 | 0 | if ( !m_pDocument->IsValidAsianCompression() ) |
150 | 0 | { |
151 | | // set compression mode from configuration if not already set (e.g. XML import) |
152 | 0 | m_pDocument->SetAsianCompression( SvxAsianConfig::GetCharDistanceCompression() ); |
153 | 0 | } |
154 | |
|
155 | 0 | if ( !m_pDocument->IsValidAsianKerning() ) |
156 | 0 | { |
157 | | // set asian punctuation kerning from configuration if not already set (e.g. XML import) |
158 | 0 | m_pDocument->SetAsianKerning( !SvxAsianConfig::IsKerningWesternTextOnly() ); // reversed |
159 | 0 | } |
160 | 0 | } |
161 | | |
162 | | void ScDocShell::ResetDrawObjectShell() |
163 | 31.6k | { |
164 | 31.6k | ScDrawLayer* pDrawLayer = m_pDocument->GetDrawLayer(); |
165 | 31.6k | if (pDrawLayer) |
166 | 17.8k | pDrawLayer->SetObjectShell( nullptr ); |
167 | 31.6k | } |
168 | | |
169 | | ScDrawLayer* ScDocShell::MakeDrawLayer() |
170 | 23.3k | { |
171 | 23.3k | ScDrawLayer* pDrawLayer = m_pDocument->GetDrawLayer(); |
172 | 23.3k | if (!pDrawLayer) |
173 | 3.85k | { |
174 | 3.85k | m_pDocument->InitDrawLayer(this); |
175 | 3.85k | pDrawLayer = m_pDocument->GetDrawLayer(); |
176 | 3.85k | InitItems(); // including Undo and Basic |
177 | 3.85k | Broadcast( SfxHint( SfxHintId::ScDrawLayerNew ) ); |
178 | 3.85k | if (m_nDocumentLock) |
179 | 0 | pDrawLayer->setLock(true); |
180 | 3.85k | } |
181 | 23.3k | return pDrawLayer; |
182 | 23.3k | } |
183 | | |
184 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |