1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5efeef26fSAndrew Rist * distributed with this work for additional information
6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist * software distributed under the License is distributed on an
15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17efeef26fSAndrew Rist * specific language governing permissions and limitations
18efeef26fSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20efeef26fSAndrew Rist *************************************************************/
21efeef26fSAndrew Rist
22efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifndef _SVX_SVXIDS_HRC
28cdf0e10cSrcweir #include <svx/svxids.hrc>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <tools/stream.hxx>
31cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
32cdf0e10cSrcweir #include <sot/storage.hxx>
33cdf0e10cSrcweir #include <svl/intitem.hxx>
34cdf0e10cSrcweir #include <editeng/forbiddencharacterstable.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
37cdf0e10cSrcweir #include <svx/xtable.hxx>
38cdf0e10cSrcweir #include <svx/drawitem.hxx>
39cdf0e10cSrcweir #include <viewsh.hxx>
40cdf0e10cSrcweir #include <doc.hxx>
41cdf0e10cSrcweir #include <rootfrm.hxx>
42cdf0e10cSrcweir #include <drawdoc.hxx>
43cdf0e10cSrcweir #include <dpage.hxx>
44cdf0e10cSrcweir #ifndef _DOCSH_HXX
45cdf0e10cSrcweir #include <docsh.hxx>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #include <shellio.hxx>
48cdf0e10cSrcweir #include <hintids.hxx>
49cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
50cdf0e10cSrcweir
51cdf0e10cSrcweir using namespace com::sun::star;
52cdf0e10cSrcweir
53cdf0e10cSrcweir /*************************************************************************
54cdf0e10cSrcweir |*
55cdf0e10cSrcweir |* Konstruktor
56cdf0e10cSrcweir |*
57cdf0e10cSrcweir \************************************************************************/
58cdf0e10cSrcweir
GetPalettePath()59cdf0e10cSrcweir const String GetPalettePath()
60cdf0e10cSrcweir {
61cdf0e10cSrcweir SvtPathOptions aPathOpt;
62cdf0e10cSrcweir return aPathOpt.GetPalettePath();
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
SwDrawDocument(SwDoc * pD)65cdf0e10cSrcweir SwDrawDocument::SwDrawDocument( SwDoc* pD ) :
66*c7be74b1SArmin Le Grand FmFormModel( ::GetPalettePath(), &pD->GetAttrPool(), pD->GetDocShell() ),
67cdf0e10cSrcweir pDoc( pD )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir SetScaleUnit( MAP_TWIP );
70cdf0e10cSrcweir SetSwapGraphics( sal_True );
71cdf0e10cSrcweir
72cdf0e10cSrcweir SwDocShell* pDocSh = pDoc->GetDocShell();
73cdf0e10cSrcweir if ( pDocSh )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir SetObjectShell( pDocSh );
76cdf0e10cSrcweir SvxColorTableItem* pColItem = ( SvxColorTableItem* )
77cdf0e10cSrcweir ( pDocSh->GetItem( SID_COLOR_TABLE ) );
78*c7be74b1SArmin Le Grand XColorListSharedPtr aXCol = pColItem ?
79*c7be74b1SArmin Le Grand pColItem->GetColorTable() :
8097e8a929SArmin Le Grand XColorList::GetStdColorList();
81*c7be74b1SArmin Le Grand SetColorTableAtSdrModel( aXCol );
82cdf0e10cSrcweir
83cdf0e10cSrcweir if ( !pColItem )
84*c7be74b1SArmin Le Grand pDocSh->PutItem( SvxColorTableItem( aXCol, SID_COLOR_TABLE ) );
85cdf0e10cSrcweir
86*c7be74b1SArmin Le Grand pDocSh->PutItem( SvxGradientListItem( GetGradientListFromSdrModel(), SID_GRADIENT_LIST ));
87*c7be74b1SArmin Le Grand pDocSh->PutItem( SvxHatchListItem( GetHatchListFromSdrModel(), SID_HATCH_LIST ) );
88*c7be74b1SArmin Le Grand pDocSh->PutItem( SvxBitmapListItem( GetBitmapListFromSdrModel(), SID_BITMAP_LIST ) );
89*c7be74b1SArmin Le Grand pDocSh->PutItem( SvxDashListItem( GetDashListFromSdrModel(), SID_DASH_LIST ) );
90*c7be74b1SArmin Le Grand pDocSh->PutItem( SvxLineEndListItem( GetLineEndListFromSdrModel(), SID_LINEEND_LIST ) );
91cdf0e10cSrcweir pDocSh->PutItem( SfxUInt16Item(SID_ATTR_LINEEND_WIDTH_DEFAULT, 111) );
92cdf0e10cSrcweir SetObjectShell( pDocSh );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir else
95*c7be74b1SArmin Le Grand SetColorTableAtSdrModel( XColorList::GetStdColorList() );
96cdf0e10cSrcweir
97cdf0e10cSrcweir // copy all the default values to the SdrModel
98cdf0e10cSrcweir SfxItemPool* pSdrPool = pD->GetAttrPool().GetSecondaryPool();
99cdf0e10cSrcweir if( pSdrPool )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir const sal_uInt16 aWhichRanges[] =
102cdf0e10cSrcweir {
103cdf0e10cSrcweir RES_CHRATR_BEGIN, RES_CHRATR_END,
104cdf0e10cSrcweir RES_PARATR_BEGIN, RES_PARATR_END,
105cdf0e10cSrcweir 0
106cdf0e10cSrcweir };
107cdf0e10cSrcweir
108cdf0e10cSrcweir SfxItemPool& rDocPool = pD->GetAttrPool();
109cdf0e10cSrcweir sal_uInt16 nEdtWhich, nSlotId;
110cdf0e10cSrcweir const SfxPoolItem* pItem;
111cdf0e10cSrcweir for( const sal_uInt16* pRangeArr = aWhichRanges;
112cdf0e10cSrcweir *pRangeArr; pRangeArr += 2 )
113cdf0e10cSrcweir for( sal_uInt16 nW = *pRangeArr, nEnd = *(pRangeArr+1);
114cdf0e10cSrcweir nW < nEnd; ++nW )
115cdf0e10cSrcweir if( 0 != (pItem = rDocPool.GetPoolDefaultItem( nW )) &&
116cdf0e10cSrcweir 0 != (nSlotId = rDocPool.GetSlotId( nW ) ) &&
117cdf0e10cSrcweir nSlotId != nW &&
118cdf0e10cSrcweir 0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
119cdf0e10cSrcweir nSlotId != nEdtWhich )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir SfxPoolItem* pCpy = pItem->Clone();
122cdf0e10cSrcweir pCpy->SetWhich( nEdtWhich );
123cdf0e10cSrcweir pSdrPool->SetPoolDefaultItem( *pCpy );
124cdf0e10cSrcweir delete pCpy;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
128cdf0e10cSrcweir SetForbiddenCharsTable( pD->getForbiddenCharacterTable() );
129cdf0e10cSrcweir // #87795# Implementation for asian compression
130cdf0e10cSrcweir SetCharCompressType( static_cast<sal_uInt16>(pD->getCharacterCompressionType() ));
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir /*************************************************************************
134cdf0e10cSrcweir |*
135cdf0e10cSrcweir |* Destruktor
136cdf0e10cSrcweir |*
137cdf0e10cSrcweir \************************************************************************/
138cdf0e10cSrcweir
139cdf0e10cSrcweir
~SwDrawDocument()140cdf0e10cSrcweir SwDrawDocument::~SwDrawDocument()
141cdf0e10cSrcweir {
142cdf0e10cSrcweir Broadcast(SdrHint(HINT_MODELCLEARED));
143cdf0e10cSrcweir
144cdf0e10cSrcweir // #116168#
145cdf0e10cSrcweir ClearModel(sal_True);
146cdf0e10cSrcweir //Clear();
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir /*************************************************************************
150cdf0e10cSrcweir |*
151cdf0e10cSrcweir |* Diese Methode erzeugt eine neue Seite (SdPage) und gibt einen Zeiger
152cdf0e10cSrcweir |* darauf zurueck. Die Drawing Engine benutzt diese Methode beim Laden
153cdf0e10cSrcweir |* zur Erzeugung von Seiten (deren Typ sie ja nicht kennt, da es ABLEITUNGEN
154cdf0e10cSrcweir |* der SdrPage sind).
155cdf0e10cSrcweir |*
156cdf0e10cSrcweir \************************************************************************/
157cdf0e10cSrcweir
158cdf0e10cSrcweir
AllocPage(FASTBOOL bMasterPage)159cdf0e10cSrcweir SdrPage* SwDrawDocument::AllocPage(FASTBOOL bMasterPage)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir SwDPage* pPage = new SwDPage(*this, 0 != bMasterPage);
162cdf0e10cSrcweir pPage->SetName( String::CreateFromAscii(
163cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( "Controls" )) );
164cdf0e10cSrcweir return pPage;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir
GetDocumentStream(SdrDocumentStreamInfo & rInfo) const168cdf0e10cSrcweir SvStream* SwDrawDocument::GetDocumentStream( SdrDocumentStreamInfo& rInfo ) const
169cdf0e10cSrcweir {
170cdf0e10cSrcweir SvStream* pRet = NULL;
171cdf0e10cSrcweir uno::Reference < embed::XStorage > xRoot( pDoc->GetDocStorage() );
172cdf0e10cSrcweir if( xRoot.is() )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir if( rInfo.maUserData.Len() &&
175cdf0e10cSrcweir ( rInfo.maUserData.GetToken( 0, ':' ) ==
176cdf0e10cSrcweir String( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package" ) ) ) )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir const String aPicturePath( rInfo.maUserData.GetToken( 1, ':' ) );
179cdf0e10cSrcweir
180cdf0e10cSrcweir // graphic from picture stream in picture storage in XML package
181cdf0e10cSrcweir if( aPicturePath.GetTokenCount( '/' ) == 2 )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir const String aPictureStorageName( aPicturePath.GetToken( 0, '/' ) );
184cdf0e10cSrcweir const String aPictureStreamName( aPicturePath.GetToken( 1, '/' ) );
185cdf0e10cSrcweir
186cdf0e10cSrcweir try
187cdf0e10cSrcweir {
188cdf0e10cSrcweir uno::Reference < embed::XStorage > xPictureStorage = xRoot->openStorageElement(
189cdf0e10cSrcweir aPictureStorageName, embed::ElementModes::READ );
190cdf0e10cSrcweir uno::Reference < io::XStream > xStream = xPictureStorage->openStreamElement(
191cdf0e10cSrcweir aPictureStreamName, embed::ElementModes::READ );
192cdf0e10cSrcweir pRet = utl::UcbStreamHelper::CreateStream( xStream );
193cdf0e10cSrcweir if( pRet )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir rInfo.mbDeleteAfterUse = sal_True;
196cdf0e10cSrcweir rInfo.mxStorageRef = xPictureStorage;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir }
199cdf0e10cSrcweir catch ( uno::Exception& )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir }
202cdf0e10cSrcweir }
203cdf0e10cSrcweir }
204cdf0e10cSrcweir }
205cdf0e10cSrcweir return pRet;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir
GetControlExportLayerId(const SdrObject &) const208cdf0e10cSrcweir SdrLayerID SwDrawDocument::GetControlExportLayerId( const SdrObject & ) const
209cdf0e10cSrcweir {
210cdf0e10cSrcweir //fuer Versionen < 5.0, es gab nur Hell und Heaven
211cdf0e10cSrcweir return (SdrLayerID)pDoc->GetHeavenId();
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214cdf0e10cSrcweir // --> OD 2006-03-01 #b6382898#
createUnoModel()215cdf0e10cSrcweir uno::Reference< uno::XInterface > SwDrawDocument::createUnoModel()
216cdf0e10cSrcweir {
217cdf0e10cSrcweir
218cdf0e10cSrcweir uno::Reference< uno::XInterface > xModel;
219cdf0e10cSrcweir
220cdf0e10cSrcweir try
221cdf0e10cSrcweir {
222cdf0e10cSrcweir if ( GetDoc().GetDocShell() )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir xModel = GetDoc().GetDocShell()->GetModel();
225cdf0e10cSrcweir }
226cdf0e10cSrcweir }
227cdf0e10cSrcweir catch( uno::RuntimeException& )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir ASSERT( false,
230cdf0e10cSrcweir "<SwDrawDocument::createUnoModel()> - could *not* retrieve model at <SwDocShell>" );
231cdf0e10cSrcweir }
232cdf0e10cSrcweir
233cdf0e10cSrcweir return xModel;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
236cdf0e10cSrcweir // <--
237