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 m_bThemedControls = false;
41 SetScaleUnit( MapUnit::MapTwip );
43
44 // use common InitDrawModelAndDocShell which will set the associations as needed,
45 // including SvxColorTableItem with WhichID SID_COLOR_TABLE
47
48 // copy all the default values to the SdrModel
50 if( pSdrPool )
51 {
52 const sal_uInt16 aWhichRanges[] =
53 {
56 0
57 };
58
59 SfxItemPool& rDocPool = m_rDoc.GetAttrPool();
60 sal_uInt16 nEdtWhich, nSlotId;
61 const SfxPoolItem* pItem;
62 for( const sal_uInt16* pRangeArr = aWhichRanges;
63 *pRangeArr; pRangeArr += 2 )
64 for( sal_uInt16 nW = *pRangeArr, nEnd = *(pRangeArr+1);
65 nW < nEnd; ++nW )
66 if( nullptr != (pItem = rDocPool.GetPoolDefaultItem( nW )) &&
67 0 != (nSlotId = rDocPool.GetSlotId( nW ) ) &&
68 nSlotId != nW &&
69 0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
70 nSlotId != nEdtWhich )
71 {
72 std::unique_ptr<SfxPoolItem> pCpy(pItem->Clone());
73 pCpy->SetWhich( nEdtWhich );
74 pSdrPool->SetPoolDefaultItem( *pCpy );
75 }
76 }
77
79 // Implementation for asian compression
81}
82
83// Destructor
84
86{
87 Broadcast(SdrHint(SdrHintKind::ModelCleared));
88
89 // We have a nasty situation, where SwDrawVirtObj has a SwAnchoredObject field,
90 // which points back to the SwDrawVirtObj via the rtl::Reference<SdrObject> mpDrawObj field.
91 // Which creates a reference loop.
92 // But other code also uses SwAnchoredObject, and does
93 // so in a way which expects the mpDrawObj to keep things alive.
94 // So we cannot change that.
95 // So to prevent leaks on shutdown, we have to remove all of the SwDrawVirtObj objects.
96 sal_uInt16 nPageCount=GetPageCount();
97 for (sal_uInt16 i=0; i < nPageCount; ++i)
98 {
99 SdrPage* pPage = GetPage(i);
100 const size_t nObjCount = pPage->GetObjCount();
101 for (size_t j=0; j < nObjCount; ++j)
102 {
103 SdrObject* pSdrObj = pPage->GetObj(j);
104 SwDrawContact* pContact = dynamic_cast<SwDrawContact*>(pSdrObj->GetUserCall());
105 if (pContact)
106 pContact->RemoveAllVirtObjs();
107 }
108 }
109
110 ClearModel(true);
111}
112
121{
122 rtl::Reference<SwDPage> pPage = new SwDPage(*this, bMasterPage);
123 pPage->SetName("Controls");
124 return pPage;
125}
126
127uno::Reference<embed::XStorage> SwDrawModel::GetDocumentStorage() const
128{
129 return m_rDoc.GetDocStorage();
130}
131
132uno::Reference< uno::XInterface > SwDrawModel::createUnoModel()
133{
134 uno::Reference< uno::XInterface > xModel;
135
136 try
137 {
138 if ( GetDoc().GetDocShell() )
139 {
141 }
142 }
143 catch( uno::RuntimeException& )
144 {
145 OSL_FAIL( "<SwDrawModel::createUnoModel()> - could *not* retrieve model at <SwDocShell>" );
146 }
147
148 return xModel;
149}
150
152{
153 rSet.Put(SvxColorListItem(GetColorList(), SID_COLOR_TABLE));
154 rSet.Put(SvxGradientListItem(GetGradientList(), SID_GRADIENT_LIST));
155 rSet.Put(SvxHatchListItem(GetHatchList(), SID_HATCH_LIST));
156 rSet.Put(SvxBitmapListItem(GetBitmapList(), SID_BITMAP_LIST));
157 rSet.Put(SvxPatternListItem(GetPatternList(), SID_PATTERN_LIST));
158}
159
160/* 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
bool m_bThemedControls
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
SwDPage is Writer's draw page: derives from SdrPage, but has a reference to the Writer document via S...
Definition: dpage.hxx:34
Definition: doc.hxx:197
css::uno::Reference< css::embed::XStorage > GetDocStorage()
Definition: docnew.cxx:644
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1337
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:200
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
ContactObject for connection of formats as representatives of draw objects in SwClient and the object...
Definition: dcontact.hxx:305
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:151
virtual css::uno::Reference< css::uno::XInterface > createUnoModel() override
override of <SdrModel::createUnoModel()> is needed to provide corresponding uno model.
Definition: drawdoc.cxx:132
virtual ~SwDrawModel() override
Definition: drawdoc.cxx:85
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:120
const SwDoc & GetDoc() const
Definition: drawdoc.hxx:35
virtual css::uno::Reference< css::embed::XStorage > GetDocumentStorage() const override
Definition: drawdoc.cxx:127
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:1228
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