LibreOffice Module sw (master) 1
drawdoc.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 <svx/svxids.hrc>
21
22#include <com/sun/star/frame/XModel.hpp>
23#include <svx/drawitem.hxx>
24#include <osl/diagnose.h>
25#include <doc.hxx>
26#include <drawdoc.hxx>
27#include <dpage.hxx>
28#include <docsh.hxx>
29#include <hintids.hxx>
30#include <dcontact.hxx>
32
33using namespace com::sun::star;
34
35// Constructor
37 : FmFormModel(&rDoc.GetAttrPool(), rDoc.GetDocShell())
38 , m_rDoc(rDoc)
39{
40 SetScaleUnit( MapUnit::MapTwip );
42
43 // use common InitDrawModelAndDocShell which will set the associations as needed,
44 // including SvxColorTableItem with WhichID SID_COLOR_TABLE
46
47 // copy all the default values to the SdrModel
49 if( pSdrPool )
50 {
51 const sal_uInt16 aWhichRanges[] =
52 {
55 0
56 };
57
58 SfxItemPool& rDocPool = m_rDoc.GetAttrPool();
59 sal_uInt16 nEdtWhich, nSlotId;
60 const SfxPoolItem* pItem;
61 for( const sal_uInt16* pRangeArr = aWhichRanges;
62 *pRangeArr; pRangeArr += 2 )
63 for( sal_uInt16 nW = *pRangeArr, nEnd = *(pRangeArr+1);
64 nW < nEnd; ++nW )
65 if( nullptr != (pItem = rDocPool.GetPoolDefaultItem( nW )) &&
66 0 != (nSlotId = rDocPool.GetSlotId( nW ) ) &&
67 nSlotId != nW &&
68 0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
69 nSlotId != nEdtWhich )
70 {
71 std::unique_ptr<SfxPoolItem> pCpy(pItem->Clone());
72 pCpy->SetWhich( nEdtWhich );
73 pSdrPool->SetPoolDefaultItem( *pCpy );
74 }
75 }
76
78 // Implementation for asian compression
80}
81
82// Destructor
83
85{
86 Broadcast(SdrHint(SdrHintKind::ModelCleared));
87
88 // We have a nasty situation, where SwDrawVirtObj has a SwAnchoredObject field,
89 // which points back to the SwDrawVirtObj via the rtl::Reference<SdrObject> mpDrawObj field.
90 // Which creates a reference loop.
91 // But other code also uses SwAnchoredObject, and does
92 // so in a way which expects the mpDrawObj to keep things alive.
93 // So we cannot change that.
94 // So to prevent leaks on shutdown, we have to remove all of the SwDrawVirtObj objects.
95 sal_uInt16 nPageCount=GetPageCount();
96 for (sal_uInt16 i=0; i < nPageCount; ++i)
97 {
98 SdrPage* pPage = GetPage(i);
99 const size_t nObjCount = pPage->GetObjCount();
100 for (size_t j=0; j < nObjCount; ++j)
101 {
102 SdrObject* pSdrObj = pPage->GetObj(j);
103 SwDrawContact* pContact = dynamic_cast<SwDrawContact*>(pSdrObj->GetUserCall());
104 if (pContact)
105 pContact->RemoveAllVirtObjs();
106 }
107 }
108
109 ClearModel(true);
110}
111
120{
121 rtl::Reference<SwDPage> pPage = new SwDPage(*this, bMasterPage);
122 pPage->SetName("Controls");
123 return pPage;
124}
125
126uno::Reference<embed::XStorage> SwDrawModel::GetDocumentStorage() const
127{
128 return m_rDoc.GetDocStorage();
129}
130
131uno::Reference< uno::XInterface > SwDrawModel::createUnoModel()
132{
133 uno::Reference< uno::XInterface > xModel;
134
135 try
136 {
137 if ( GetDoc().GetDocShell() )
138 {
140 }
141 }
142 catch( uno::RuntimeException& )
143 {
144 OSL_FAIL( "<SwDrawModel::createUnoModel()> - could *not* retrieve model at <SwDocShell>" );
145 }
146
147 return xModel;
148}
149
151{
152 rSet.Put(SvxColorListItem(GetColorList(), SID_COLOR_TABLE));
153 rSet.Put(SvxGradientListItem(GetGradientList(), SID_GRADIENT_LIST));
154 rSet.Put(SvxHatchListItem(GetHatchList(), SID_HATCH_LIST));
155 rSet.Put(SvxBitmapListItem(GetBitmapList(), SID_BITMAP_LIST));
156 rSet.Put(SvxPatternListItem(GetPatternList(), SID_PATTERN_LIST));
157}
158
159/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XBitmapListRef GetBitmapList() const
void SetCharCompressType(CharCompressType nType)
void SetForbiddenCharsTable(const std::shared_ptr< SvxForbiddenCharactersTable > &xForbiddenChars)
XGradientListRef GetGradientList() const
XPatternListRef GetPatternList() const
void ClearModel(bool bCalledFromDestructor)
void SetScaleUnit(MapUnit eMap)
XColorListRef GetColorList() const
void SetSwapGraphics()
XHatchListRef GetHatchList() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
SdrObjUserCall * GetUserCall() const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
SfxItemPool * GetSecondaryPool() const
const SfxPoolItem * GetPoolDefaultItem(sal_uInt16 nWhich) const
sal_uInt16 GetSlotId(sal_uInt16 nWhich) const
void SetPoolDefaultItem(const SfxPoolItem &)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
css::uno::Reference< css::frame::XModel3 > GetModel() const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
Definition: doc.hxx:192
css::uno::Reference< css::embed::XStorage > GetDocStorage()
Definition: docnew.cxx:636
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1322
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:187
SwDocShell * GetDocShell()
Definition: doc.hxx:1355
ContactObject for connection of formats as representatives of draw objects in SwClient and the object...
Definition: dcontact.hxx:304
void RemoveAllVirtObjs()
remove 'virtual' drawing objects and destroy them.
Definition: dcontact.cxx:842
void PutAreaListItems(SfxItemSet &rSet) const
Put needed items for XPropertyList entries from the DrawModel.
Definition: drawdoc.cxx:150
virtual css::uno::Reference< css::uno::XInterface > createUnoModel() override
override of <SdrModel::createUnoModel()> is needed to provide corresponding uno model.
Definition: drawdoc.cxx:131
virtual ~SwDrawModel() override
Definition: drawdoc.cxx:84
SwDrawModel(SwDoc &rDoc)
Definition: drawdoc.cxx:36
virtual rtl::Reference< SdrPage > AllocPage(bool bMasterPage) override
Create a new page (SdPage) and return a pointer to it back.
Definition: drawdoc.cxx:119
const SwDoc & GetDoc() const
Definition: drawdoc.hxx:35
virtual css::uno::Reference< css::embed::XStorage > GetDocumentStorage() const override
Definition: drawdoc.cxx:126
SwDoc & m_rDoc
Definition: drawdoc.hxx:29
virtual CharCompressType getCharacterCompressionType() const override
Get the character compression type for Asian characters.
virtual std::shared_ptr< SvxForbiddenCharactersTable > & getForbiddenCharacterTable() override
Get the forbidden character table and creates one if necessary.
SwDoc & m_rDoc
Definition: docbm.cxx:1201
void InitDrawModelAndDocShell(SwDocShell *pSwDocShell, SwDrawModel *pSwDrawDocument)
Definition: docshdrw.cxx:32
constexpr sal_uInt16 RES_CHRATR_END(46)
constexpr sal_uInt16 RES_PARATR_BEGIN(RES_TXTATR_END)
constexpr sal_uInt16 RES_PARATR_END(82)
constexpr sal_uInt16 RES_CHRATR_BEGIN(HINT_BEGIN)
int i
static SfxItemSet & rSet
Reference< XModel > xModel