1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <svx/drawitem.hxx>
24 #include <osl/diagnose.h>
26 #include <drawdoc.hxx>
29 #include <hintids.hxx>
30 #include <dcontact.hxx>
31 #include <DocumentSettingManager.hxx>
33 using namespace com::sun::star
;
36 SwDrawModel::SwDrawModel(SwDoc
& rDoc
)
37 : FmFormModel(&rDoc
.GetAttrPool(), rDoc
.GetDocShell())
40 m_bThemedControls
= false;
41 SetScaleUnit( MapUnit::MapTwip
);
44 // use common InitDrawModelAndDocShell which will set the associations as needed,
45 // including SvxColorTableItem with WhichID SID_COLOR_TABLE
46 InitDrawModelAndDocShell(m_rDoc
.GetDocShell(), this);
48 // copy all the default values to the SdrModel
49 SfxItemPool
* pSdrPool
= m_rDoc
.GetAttrPool().GetSecondaryPool();
52 const sal_uInt16 aWhichRanges
[] =
54 RES_CHRATR_BEGIN
, RES_CHRATR_END
,
55 RES_PARATR_BEGIN
, RES_PARATR_END
,
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);
66 if( nullptr != (pItem
= rDocPool
.GetPoolDefaultItem( nW
)) &&
67 0 != (nSlotId
= rDocPool
.GetSlotId( nW
) ) &&
69 0 != (nEdtWhich
= pSdrPool
->GetWhich( nSlotId
)) &&
70 nSlotId
!= nEdtWhich
)
72 std::unique_ptr
<SfxPoolItem
> pCpy(pItem
->Clone());
73 pCpy
->SetWhich( nEdtWhich
);
74 pSdrPool
->SetPoolDefaultItem( *pCpy
);
78 SetForbiddenCharsTable(m_rDoc
.GetDocumentSettingManager().getForbiddenCharacterTable());
79 // Implementation for asian compression
80 SetCharCompressType( m_rDoc
.GetDocumentSettingManager().getCharacterCompressionType() );
85 SwDrawModel::~SwDrawModel()
87 Broadcast(SdrHint(SdrHintKind::ModelCleared
));
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
)
99 SdrPage
* pPage
= GetPage(i
);
100 const size_t nObjCount
= pPage
->GetObjCount();
101 for (size_t j
=0; j
< nObjCount
; ++j
)
103 SdrObject
* pSdrObj
= pPage
->GetObj(j
);
104 SwDrawContact
* pContact
= dynamic_cast<SwDrawContact
*>(pSdrObj
->GetUserCall());
106 pContact
->RemoveAllVirtObjs();
113 /** Create a new page (SdPage) and return a pointer to it back.
115 * The drawing engine is using this method while loading for the creating of
116 * pages (whose type it not even know, because they are inherited from SdrPage).
118 * @return Pointer to the new page.
120 rtl::Reference
<SdrPage
> SwDrawModel::AllocPage(bool bMasterPage
)
122 rtl::Reference
<SwDPage
> pPage
= new SwDPage(*this, bMasterPage
);
123 pPage
->SetName("Controls");
127 uno::Reference
<embed::XStorage
> SwDrawModel::GetDocumentStorage() const
129 return m_rDoc
.GetDocStorage();
132 uno::Reference
< uno::XInterface
> SwDrawModel::createUnoModel()
134 uno::Reference
< uno::XInterface
> xModel
;
138 if ( GetDoc().GetDocShell() )
140 xModel
= GetDoc().GetDocShell()->GetModel();
143 catch( uno::RuntimeException
& )
145 OSL_FAIL( "<SwDrawModel::createUnoModel()> - could *not* retrieve model at <SwDocShell>" );
151 void SwDrawModel::PutAreaListItems(SfxItemSet
& rSet
) const
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
));
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */