LibreOffice Module sc (master)  1
docsh2.cxx
Go to the documentation of this file.
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>
25 #include <orcusfilters.hxx>
26 #include <config_folders.h>
27 #include <unotools/configmgr.hxx>
29 
30 #include <drwlayer.hxx>
31 #include <stlpool.hxx>
32 #include <docsh.hxx>
33 #include <docfunc.hxx>
34 #include <svx/svxids.hrc>
35 #include <filter.hxx>
36 #include <functional>
37 
38 using namespace com::sun::star;
39 
40 bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
41 {
42  bool bRet = SfxObjectShell::InitNew( xStor );
43 
44  m_aDocument.MakeTable(0);
45 
46  // Additional tables are created by the first View, if bIsEmpty is still sal_True
47  if( bRet )
48  {
50  static_cast<long>( ScGlobal::nStdRowHeight * HMM_PER_TWIPS * OLE_STD_CELLS_Y ) );
51  // Also adjust start here
52  SetVisAreaOrSize( tools::Rectangle( Point(), aSize ) );
53  }
54 
55  // InitOptions sets the document languages, must be called before CreateStandardStyles
56  InitOptions(false);
57 
58  m_aDocument.GetStyleSheetPool()->CreateStandardStyles();
59  m_aDocument.UpdStlShtPtrsFrmNms();
60 
61  if (!m_bUcalcTest)
62  {
63  /* Create styles that are imported through Orcus */
64 
65  OUString aURL("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/calc/styles.xml");
66  rtl::Bootstrap::expandMacros(aURL);
67 
68  OUString aPath;
69  osl::FileBase::getSystemPathFromFileURL(aURL, aPath);
70 
72  if (pOrcus)
73  {
74  pOrcus->importODS_Styles(m_aDocument, aPath);
75  m_aDocument.GetStyleSheetPool()->setAllParaStandard();
76  }
77  }
78 
79  // SetDocumentModified is not allowed anymore in Load/InitNew!
80  InitItems();
81  CalcOutputFactor();
82 
83  return bRet;
84 }
85 
86 void ScDocShell::SetEmpty(bool bSet)
87 {
88  m_bIsEmpty = bSet;
89 }
90 
92 {
93  // Fill AllItemSet for Controller with needed Items:
94  // Printer Options are set in GetPrinter when printing
95  UpdateFontList();
96 
97  ScDrawLayer* pDrawLayer = m_aDocument.GetDrawLayer();
98  if (pDrawLayer)
99  {
100  PutItem( SvxColorListItem ( pDrawLayer->GetColorList(), SID_COLOR_TABLE ) );
101  PutItem( SvxGradientListItem( pDrawLayer->GetGradientList(), SID_GRADIENT_LIST ) );
102  PutItem( SvxHatchListItem ( pDrawLayer->GetHatchList(), SID_HATCH_LIST ) );
103  PutItem( SvxBitmapListItem ( pDrawLayer->GetBitmapList(), SID_BITMAP_LIST ) );
104  PutItem( SvxPatternListItem ( pDrawLayer->GetPatternList(), SID_PATTERN_LIST ) );
105  PutItem( SvxDashListItem ( pDrawLayer->GetDashList(), SID_DASH_LIST ) );
106  PutItem( SvxLineEndListItem ( pDrawLayer->GetLineEndList(), SID_LINEEND_LIST ) );
107 
108  // Other modifications after creation of the DrawLayer
109  pDrawLayer->SetNotifyUndoActionHdl( std::bind( &ScDocFunc::NotifyDrawUndo, m_pDocFunc.get(), std::placeholders::_1 ) );
110  }
111  else if (!utl::ConfigManager::IsFuzzing())
112  {
113  // always use global color table instead of local copy
114  PutItem( SvxColorListItem( XColorList::GetStdColorList(), SID_COLOR_TABLE ) );
115  }
116 
118  (!m_aDocument.GetForbiddenCharacters() || !m_aDocument.IsValidAsianCompression() || !m_aDocument.IsValidAsianKerning())))
119  return;
120 
121  // get settings from SvxAsianConfig
122  SvxAsianConfig aAsian;
123 
124  if (!m_aDocument.GetForbiddenCharacters())
125  {
126  // set forbidden characters if necessary
127  const uno::Sequence<lang::Locale> aLocales = aAsian.GetStartEndCharLocales();
128  if (aLocales.hasElements())
129  {
130  std::shared_ptr<SvxForbiddenCharactersTable> xForbiddenTable(
132 
133  for (const lang::Locale& rLocale : aLocales)
134  {
135  i18n::ForbiddenCharacters aForbidden;
136  aAsian.GetStartEndChars( rLocale, aForbidden.beginLine, aForbidden.endLine );
138 
139  xForbiddenTable->SetForbiddenCharacters( eLang, aForbidden );
140  }
141 
142  m_aDocument.SetForbiddenCharacters( xForbiddenTable );
143  }
144  }
145 
146  if ( !m_aDocument.IsValidAsianCompression() )
147  {
148  // set compression mode from configuration if not already set (e.g. XML import)
149  m_aDocument.SetAsianCompression( aAsian.GetCharDistanceCompression() );
150  }
151 
152  if ( !m_aDocument.IsValidAsianKerning() )
153  {
154  // set asian punctuation kerning from configuration if not already set (e.g. XML import)
155  m_aDocument.SetAsianKerning( !aAsian.IsKerningWesternTextOnly() ); // reversed
156  }
157 }
158 
160 {
161  ScDrawLayer* pDrawLayer = m_aDocument.GetDrawLayer();
162  if (pDrawLayer)
163  pDrawLayer->SetObjectShell( nullptr );
164 }
165 
167 {
168  ScDrawLayer* pDrawLayer = m_aDocument.GetDrawLayer();
169  if (!pDrawLayer)
170  {
171  m_aDocument.InitDrawLayer(this);
172  pDrawLayer = m_aDocument.GetDrawLayer();
173  InitItems(); // including Undo and Basic
174  Broadcast( SfxHint( SfxHintId::ScDrawLayerNew ) );
175  if (m_nDocumentLock)
176  pDrawLayer->setLock(true);
177  }
178  return pDrawLayer;
179 }
180 
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define OLE_STD_CELLS_Y
Definition: global.hxx:115
URL aURL
bool IsKerningWesternTextOnly() const
Collection of orcus filter wrappers.
void NotifyDrawUndo(std::unique_ptr< SdrUndoAction >)
Definition: docfunc.cxx:105
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
#define OLE_STD_CELLS_X
Definition: global.hxx:114
void SetNotifyUndoActionHdl(const std::function< void(std::unique_ptr< SdrUndoAction >)> &rLink)
XDashListRef GetDashList() const
static SC_DLLPUBLIC ScFormatFilterPlugin & Get()
Definition: impex.cxx:2347
SAL_DLLPRIVATE void InitItems()
Definition: docsh2.cxx:91
virtual bool importODS_Styles(ScDocument &rDoc, OUString &aFileName) const =0
Used to import just the styles from an xml file.
XPatternListRef GetPatternList() const
virtual ScOrcusFilters * GetOrcusFilters()=0
#define STD_COL_WIDTH
Definition: global.hxx:93
static bool IsFuzzing()
void SetEmpty(bool bSet)
Definition: docsh2.cxx:86
#define HMM_PER_TWIPS
Definition: global.hxx:91
XLineEndListRef GetLineEndList() const
static std::shared_ptr< SvxForbiddenCharactersTable > makeForbiddenCharactersTable(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
ScDrawLayer * MakeDrawLayer()
Definition: docsh2.cxx:166
static XColorListRef GetStdColorList()
static SC_DLLPUBLIC sal_uInt16 nStdRowHeight
Definition: global.hxx:587
bool GetStartEndChars(css::lang::Locale const &locale, OUString &startChars, OUString &endChars) const
CharCompressType GetCharDistanceCompression() const
SAL_DLLPRIVATE void ResetDrawObjectShell()
Definition: docsh2.cxx:159
XGradientListRef GetGradientList() const
virtual bool InitNew(const css::uno::Reference< css::embed::XStorage > &xStorage)
void setLock(bool bLock)
css::uno::Sequence< css::lang::Locale > GetStartEndCharLocales() const
XHatchListRef GetHatchList() const
void SetObjectShell(SfxObjectShell *pShell)
Reference< XComponentContext > getProcessComponentContext()
XBitmapListRef GetBitmapList() const
XColorListRef GetColorList() const
virtual bool InitNew(const css::uno::Reference< css::embed::XStorage > &) override
Definition: docsh2.cxx:40