Line data Source code
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 : #include <tools/stream.hxx>
22 : #include <unotools/pathoptions.hxx>
23 : #include <sot/storage.hxx>
24 : #include <svl/intitem.hxx>
25 : #include <editeng/forbiddencharacterstable.hxx>
26 :
27 : #include <unotools/ucbstreamhelper.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 <com/sun/star/embed/ElementModes.hpp>
39 : #include <DocumentSettingManager.hxx>
40 : #include <IDocumentDrawModelAccess.hxx>
41 :
42 : using namespace com::sun::star;
43 :
44 : // Constructor
45 :
46 5052 : const OUString GetPalettePath()
47 : {
48 5052 : SvtPathOptions aPathOpt;
49 5052 : return aPathOpt.GetPalettePath();
50 : }
51 :
52 5052 : SwDrawModel::SwDrawModel( SwDoc* pD ) :
53 5052 : FmFormModel( ::GetPalettePath(), &pD->GetAttrPool(),
54 5052 : pD->GetDocShell(), true ),
55 5052 : pDoc( pD )
56 : {
57 5052 : SetScaleUnit( MAP_TWIP );
58 5052 : SetSwapGraphics( true );
59 :
60 : // use common InitDrawModelAndDocShell which will set the associations as needed,
61 : // including SvxColorTableItem with WhichID SID_COLOR_TABLE
62 5052 : InitDrawModelAndDocShell(pDoc ? pDoc->GetDocShell() : 0, this);
63 :
64 : // copy all the default values to the SdrModel
65 5052 : SfxItemPool* pSdrPool = pD->GetAttrPool().GetSecondaryPool();
66 5052 : if( pSdrPool )
67 : {
68 : const sal_uInt16 aWhichRanges[] =
69 : {
70 : RES_CHRATR_BEGIN, RES_CHRATR_END,
71 : RES_PARATR_BEGIN, RES_PARATR_END,
72 : 0
73 5052 : };
74 :
75 5052 : SfxItemPool& rDocPool = pD->GetAttrPool();
76 : sal_uInt16 nEdtWhich, nSlotId;
77 : const SfxPoolItem* pItem;
78 15156 : for( const sal_uInt16* pRangeArr = aWhichRanges;
79 : *pRangeArr; pRangeArr += 2 )
80 333432 : for( sal_uInt16 nW = *pRangeArr, nEnd = *(pRangeArr+1);
81 : nW < nEnd; ++nW )
82 646656 : if( 0 != (pItem = rDocPool.GetPoolDefaultItem( nW )) &&
83 0 : 0 != (nSlotId = rDocPool.GetSlotId( nW ) ) &&
84 0 : nSlotId != nW &&
85 323328 : 0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
86 : nSlotId != nEdtWhich )
87 : {
88 0 : SfxPoolItem* pCpy = pItem->Clone();
89 0 : pCpy->SetWhich( nEdtWhich );
90 0 : pSdrPool->SetPoolDefaultItem( *pCpy );
91 0 : delete pCpy;
92 : }
93 : }
94 :
95 5052 : SetForbiddenCharsTable( pD->GetDocumentSettingManager().getForbiddenCharacterTable() );
96 : // Implementation for asian compression
97 5052 : SetCharCompressType( static_cast<sal_uInt16>(pD->GetDocumentSettingManager().getCharacterCompressionType() ));
98 5052 : }
99 :
100 : // Destructor
101 :
102 15135 : SwDrawModel::~SwDrawModel()
103 : {
104 5045 : Broadcast(SdrHint(HINT_MODELCLEARED));
105 :
106 5045 : ClearModel(true);
107 10090 : }
108 :
109 : /** Create a new page (SdPage) and return a pointer to it back.
110 : *
111 : * The drawing engine is using this method while loading for the creating of
112 : * pages (whose type it not even know, because they are inherited from SdrPage).
113 : *
114 : * @return Pointer to the new page.
115 : */
116 5052 : SdrPage* SwDrawModel::AllocPage(bool bMasterPage)
117 : {
118 5052 : SwDPage* pPage = new SwDPage(*this, bMasterPage);
119 5052 : pPage->SetName(OUString("Controls"));
120 5052 : return pPage;
121 : }
122 :
123 0 : uno::Reference<embed::XStorage> SwDrawModel::GetDocumentStorage() const
124 : {
125 0 : return pDoc->GetDocStorage();
126 : }
127 :
128 0 : SdrLayerID SwDrawModel::GetControlExportLayerId( const SdrObject & ) const
129 : {
130 : //for versions < 5.0, there was only Hell and Heaven
131 0 : return (SdrLayerID)pDoc->getIDocumentDrawModelAccess().GetHeavenId();
132 : }
133 :
134 148 : uno::Reference< uno::XInterface > SwDrawModel::createUnoModel()
135 : {
136 148 : uno::Reference< uno::XInterface > xModel;
137 :
138 : try
139 : {
140 148 : if ( GetDoc().GetDocShell() )
141 : {
142 148 : xModel = GetDoc().GetDocShell()->GetModel();
143 : }
144 : }
145 0 : catch( uno::RuntimeException& )
146 : {
147 : OSL_FAIL( "<SwDrawModel::createUnoModel()> - could *not* retrieve model at <SwDocShell>" );
148 : }
149 :
150 148 : return xModel;
151 270 : }
152 :
153 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|