Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sw / source / core / draw / drawdoc.cxx
blob1c1229d9e456a10adf6ad1e51e027301add2f041
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 <svx/svxids.hrc>
21 #include <tools/stream.hxx>
22 #include <unotools/configmgr.hxx>
23 #include <unotools/pathoptions.hxx>
24 #include <sot/storage.hxx>
25 #include <svl/intitem.hxx>
26 #include <editeng/forbiddencharacterstable.hxx>
28 #include <svx/xtable.hxx>
29 #include <svx/drawitem.hxx>
30 #include <viewsh.hxx>
31 #include <doc.hxx>
32 #include <rootfrm.hxx>
33 #include <drawdoc.hxx>
34 #include <dpage.hxx>
35 #include <docsh.hxx>
36 #include <shellio.hxx>
37 #include <hintids.hxx>
38 #include <DocumentSettingManager.hxx>
39 #include <IDocumentDrawModelAccess.hxx>
41 using namespace com::sun::star;
43 // Constructor
45 const OUString GetPalettePath()
47 if (utl::ConfigManager::IsFuzzing())
48 return OUString();
49 SvtPathOptions aPathOpt;
50 return aPathOpt.GetPalettePath();
53 SwDrawModel::SwDrawModel(SwDoc *const pDoc)
54 : FmFormModel( ::GetPalettePath(), &pDoc->GetAttrPool(),
55 pDoc->GetDocShell(), true )
56 , m_pDoc( pDoc )
58 SetScaleUnit( MapUnit::MapTwip );
59 SetSwapGraphics();
61 // use common InitDrawModelAndDocShell which will set the associations as needed,
62 // including SvxColorTableItem with WhichID SID_COLOR_TABLE
63 InitDrawModelAndDocShell(m_pDoc->GetDocShell(), this);
65 // copy all the default values to the SdrModel
66 SfxItemPool* pSdrPool = m_pDoc->GetAttrPool().GetSecondaryPool();
67 if( pSdrPool )
69 const sal_uInt16 aWhichRanges[] =
71 RES_CHRATR_BEGIN, RES_CHRATR_END,
72 RES_PARATR_BEGIN, RES_PARATR_END,
76 SfxItemPool& rDocPool = m_pDoc->GetAttrPool();
77 sal_uInt16 nEdtWhich, nSlotId;
78 const SfxPoolItem* pItem;
79 for( const sal_uInt16* pRangeArr = aWhichRanges;
80 *pRangeArr; pRangeArr += 2 )
81 for( sal_uInt16 nW = *pRangeArr, nEnd = *(pRangeArr+1);
82 nW < nEnd; ++nW )
83 if( nullptr != (pItem = rDocPool.GetPoolDefaultItem( nW )) &&
84 0 != (nSlotId = rDocPool.GetSlotId( nW ) ) &&
85 nSlotId != nW &&
86 0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
87 nSlotId != nEdtWhich )
89 SfxPoolItem* pCpy = pItem->Clone();
90 pCpy->SetWhich( nEdtWhich );
91 pSdrPool->SetPoolDefaultItem( *pCpy );
92 delete pCpy;
96 SetForbiddenCharsTable(m_pDoc->GetDocumentSettingManager().getForbiddenCharacterTable());
97 // Implementation for asian compression
98 SetCharCompressType( m_pDoc->GetDocumentSettingManager().getCharacterCompressionType() );
101 // Destructor
103 SwDrawModel::~SwDrawModel()
105 Broadcast(SdrHint(SdrHintKind::ModelCleared));
107 ClearModel(true);
110 /** Create a new page (SdPage) and return a pointer to it back.
112 * The drawing engine is using this method while loading for the creating of
113 * pages (whose type it not even know, because they are inherited from SdrPage).
115 * @return Pointer to the new page.
117 SdrPage* SwDrawModel::AllocPage(bool bMasterPage)
119 SwDPage* pPage = new SwDPage(*this, bMasterPage);
120 pPage->SetName("Controls");
121 return pPage;
124 uno::Reference<embed::XStorage> SwDrawModel::GetDocumentStorage() const
126 return m_pDoc->GetDocStorage();
129 uno::Reference< uno::XInterface > SwDrawModel::createUnoModel()
131 uno::Reference< uno::XInterface > xModel;
135 if ( GetDoc().GetDocShell() )
137 xModel = GetDoc().GetDocShell()->GetModel();
140 catch( uno::RuntimeException& )
142 OSL_FAIL( "<SwDrawModel::createUnoModel()> - could *not* retrieve model at <SwDocShell>" );
145 return xModel;
148 void SwDrawModel::PutAreaListItems(SfxItemSet& rSet) const
150 rSet.Put(SvxColorListItem(GetColorList(), SID_COLOR_TABLE));
151 rSet.Put(SvxGradientListItem(GetGradientList(), SID_GRADIENT_LIST));
152 rSet.Put(SvxHatchListItem(GetHatchList(), SID_HATCH_LIST));
153 rSet.Put(SvxBitmapListItem(GetBitmapList(), SID_BITMAP_LIST));
154 rSet.Put(SvxPatternListItem(GetPatternList(), SID_PATTERN_LIST));
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */