tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / docshell / docsh2.cxx
blob6823327284db78f9d9ee1d379c42b617f0073eee
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 <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>
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>
39 using namespace com::sun::star;
41 bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
43 bool bRet = SfxObjectShell::InitNew( xStor );
45 m_pDocument->MakeTable(0);
47 // Additional tables are created by the first View, if bIsEmpty is still sal_True
48 if( bRet )
50 Size aSize(
51 o3tl::convert(STD_COL_WIDTH * OLE_STD_CELLS_X, o3tl::Length::twip, o3tl::Length::mm100),
52 o3tl::convert(ScGlobal::nStdRowHeight * OLE_STD_CELLS_Y, o3tl::Length::twip,
53 o3tl::Length::mm100));
54 // Also adjust start here
55 SetVisAreaOrSize( tools::Rectangle( Point(), aSize ) );
58 // InitOptions sets the document languages, must be called before CreateStandardStyles
59 InitOptions(false);
61 if (ScStyleSheetPool* pStyleSheetPool = m_pDocument->GetStyleSheetPool())
63 pStyleSheetPool->CreateStandardStyles();
64 m_pDocument->getCellAttributeHelper().UpdateAllStyleSheets(*m_pDocument);
66 /* Create styles that are imported through Orcus */
68 OUString aURL(u"$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/calc/styles.xml"_ustr);
69 rtl::Bootstrap::expandMacros(aURL);
71 OUString aPath;
72 osl::FileBase::getSystemPathFromFileURL(aURL, aPath);
74 ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
75 if (pOrcus)
77 pOrcus->importODS_Styles(*m_pDocument, aPath);
78 pStyleSheetPool->setAllParaStandard();
82 // SetDocumentModified is not allowed anymore in Load/InitNew!
83 InitItems();
84 CalcOutputFactor();
86 return bRet;
89 void ScDocShell::SetEmpty(bool bSet)
91 m_bIsEmpty = bSet;
94 void ScDocShell::InitItems()
96 // Fill AllItemSet for Controller with needed Items:
97 // Printer Options are set in GetPrinter when printing
98 UpdateFontList();
100 ScDrawLayer* pDrawLayer = m_pDocument->GetDrawLayer();
101 if (pDrawLayer)
103 PutItem( SvxColorListItem ( pDrawLayer->GetColorList(), SID_COLOR_TABLE ) );
104 PutItem( SvxGradientListItem( pDrawLayer->GetGradientList(), SID_GRADIENT_LIST ) );
105 PutItem( SvxHatchListItem ( pDrawLayer->GetHatchList(), SID_HATCH_LIST ) );
106 PutItem( SvxBitmapListItem ( pDrawLayer->GetBitmapList(), SID_BITMAP_LIST ) );
107 PutItem( SvxPatternListItem ( pDrawLayer->GetPatternList(), SID_PATTERN_LIST ) );
108 PutItem( SvxDashListItem ( pDrawLayer->GetDashList(), SID_DASH_LIST ) );
109 PutItem( SvxLineEndListItem ( pDrawLayer->GetLineEndList(), SID_LINEEND_LIST ) );
111 // Other modifications after creation of the DrawLayer
112 pDrawLayer->SetNotifyUndoActionHdl( std::bind( &ScDocFunc::NotifyDrawUndo, m_pDocFunc.get(), std::placeholders::_1 ) );
114 else if (!comphelper::IsFuzzing())
116 // always use global color table instead of local copy
117 PutItem( SvxColorListItem( XColorList::GetStdColorList(), SID_COLOR_TABLE ) );
120 if (comphelper::IsFuzzing() ||
121 (m_pDocument->GetForbiddenCharacters() && m_pDocument->IsValidAsianCompression() && m_pDocument->IsValidAsianKerning()))
122 return;
124 // get settings from SvxAsianConfig
125 SvxAsianConfig aAsian;
127 if (!m_pDocument->GetForbiddenCharacters())
129 // set forbidden characters if necessary
130 const uno::Sequence<lang::Locale> aLocales = SvxAsianConfig::GetStartEndCharLocales();
131 if (aLocales.hasElements())
133 std::shared_ptr<SvxForbiddenCharactersTable> xForbiddenTable(
134 SvxForbiddenCharactersTable::makeForbiddenCharactersTable(comphelper::getProcessComponentContext()));
136 for (const lang::Locale& rLocale : aLocales)
138 i18n::ForbiddenCharacters aForbidden;
139 SvxAsianConfig::GetStartEndChars( rLocale, aForbidden.beginLine, aForbidden.endLine );
140 LanguageType eLang = LanguageTag::convertToLanguageType(rLocale);
142 xForbiddenTable->SetForbiddenCharacters( eLang, aForbidden );
145 m_pDocument->SetForbiddenCharacters( xForbiddenTable );
149 if ( !m_pDocument->IsValidAsianCompression() )
151 // set compression mode from configuration if not already set (e.g. XML import)
152 m_pDocument->SetAsianCompression( SvxAsianConfig::GetCharDistanceCompression() );
155 if ( !m_pDocument->IsValidAsianKerning() )
157 // set asian punctuation kerning from configuration if not already set (e.g. XML import)
158 m_pDocument->SetAsianKerning( !SvxAsianConfig::IsKerningWesternTextOnly() ); // reversed
162 void ScDocShell::ResetDrawObjectShell()
164 ScDrawLayer* pDrawLayer = m_pDocument->GetDrawLayer();
165 if (pDrawLayer)
166 pDrawLayer->SetObjectShell( nullptr );
169 ScDrawLayer* ScDocShell::MakeDrawLayer()
171 ScDrawLayer* pDrawLayer = m_pDocument->GetDrawLayer();
172 if (!pDrawLayer)
174 m_pDocument->InitDrawLayer(this);
175 pDrawLayer = m_pDocument->GetDrawLayer();
176 InitItems(); // including Undo and Basic
177 Broadcast( SfxHint( SfxHintId::ScDrawLayerNew ) );
178 if (m_nDocumentLock)
179 pDrawLayer->setLock(true);
181 return pDrawLayer;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */