Update ooo320-m1
[ooovba.git] / sw / source / core / draw / drawdoc.cxx
blobaf52b77336645359c60f35a87c677f7793d9f52d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drawdoc.cxx,v $
10 * $Revision: 1.24 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifndef _SVX_SVXIDS_HRC
35 #include <svx/svxids.hrc>
36 #endif
37 #include <tools/stream.hxx>
38 #include <svtools/pathoptions.hxx>
39 #include <sot/storage.hxx>
40 #include <svtools/intitem.hxx>
41 #include <svx/forbiddencharacterstable.hxx>
43 #include <unotools/ucbstreamhelper.hxx>
44 #include <svx/xtable.hxx>
45 #include <svx/drawitem.hxx>
46 #include <viewsh.hxx>
47 #include <doc.hxx>
48 #include <rootfrm.hxx>
49 #include <drawdoc.hxx>
50 #include <dpage.hxx>
51 #ifndef _DOCSH_HXX
52 #include <docsh.hxx>
53 #endif
54 #include <shellio.hxx>
55 #include <hintids.hxx>
56 #include <com/sun/star/embed/ElementModes.hpp>
58 using namespace com::sun::star;
60 /*************************************************************************
62 |* Konstruktor
64 \************************************************************************/
66 const String GetPalettePath()
68 SvtPathOptions aPathOpt;
69 return aPathOpt.GetPalettePath();
72 SwDrawDocument::SwDrawDocument( SwDoc* pD ) :
73 FmFormModel( ::GetPalettePath(), &pD->GetAttrPool(),
74 pD->GetDocShell(), TRUE ),
75 pDoc( pD )
77 SetScaleUnit( MAP_TWIP );
78 SetSwapGraphics( TRUE );
80 SwDocShell* pDocSh = pDoc->GetDocShell();
81 if ( pDocSh )
83 SetObjectShell( pDocSh );
84 SvxColorTableItem* pColItem = ( SvxColorTableItem* )
85 ( pDocSh->GetItem( SID_COLOR_TABLE ) );
86 XColorTable *pXCol = pColItem ? pColItem->GetColorTable() :
87 XColorTable::GetStdColorTable();
88 SetColorTable( pXCol );
90 if ( !pColItem )
91 pDocSh->PutItem( SvxColorTableItem( pXCol, SID_COLOR_TABLE ) );
93 pDocSh->PutItem( SvxGradientListItem( GetGradientList(), SID_GRADIENT_LIST ));
94 pDocSh->PutItem( SvxHatchListItem( GetHatchList(), SID_HATCH_LIST ) );
95 pDocSh->PutItem( SvxBitmapListItem( GetBitmapList(), SID_BITMAP_LIST ) );
96 pDocSh->PutItem( SvxDashListItem( GetDashList(), SID_DASH_LIST ) );
97 pDocSh->PutItem( SvxLineEndListItem( GetLineEndList(), SID_LINEEND_LIST ) );
98 pDocSh->PutItem( SfxUInt16Item(SID_ATTR_LINEEND_WIDTH_DEFAULT, 111) );
99 SetObjectShell( pDocSh );
101 else
102 SetColorTable( XColorTable::GetStdColorTable() );
104 // copy all the default values to the SdrModel
105 SfxItemPool* pSdrPool = pD->GetAttrPool().GetSecondaryPool();
106 if( pSdrPool )
108 const USHORT aWhichRanges[] =
110 RES_CHRATR_BEGIN, RES_CHRATR_END,
111 RES_PARATR_BEGIN, RES_PARATR_END,
115 SfxItemPool& rDocPool = pD->GetAttrPool();
116 USHORT nEdtWhich, nSlotId;
117 const SfxPoolItem* pItem;
118 for( const USHORT* pRangeArr = aWhichRanges;
119 *pRangeArr; pRangeArr += 2 )
120 for( USHORT nW = *pRangeArr, nEnd = *(pRangeArr+1);
121 nW < nEnd; ++nW )
122 if( 0 != (pItem = rDocPool.GetPoolDefaultItem( nW )) &&
123 0 != (nSlotId = rDocPool.GetSlotId( nW ) ) &&
124 nSlotId != nW &&
125 0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
126 nSlotId != nEdtWhich )
128 SfxPoolItem* pCpy = pItem->Clone();
129 pCpy->SetWhich( nEdtWhich );
130 pSdrPool->SetPoolDefaultItem( *pCpy );
131 delete pCpy;
135 SetForbiddenCharsTable( pD->getForbiddenCharacterTable() );
136 // #87795# Implementation for asian compression
137 SetCharCompressType( static_cast<UINT16>(pD->getCharacterCompressionType() ));
140 /*************************************************************************
142 |* Destruktor
144 \************************************************************************/
147 SwDrawDocument::~SwDrawDocument()
149 Broadcast(SdrHint(HINT_MODELCLEARED));
151 // #116168#
152 ClearModel(sal_True);
153 //Clear();
156 /*************************************************************************
158 |* Diese Methode erzeugt eine neue Seite (SdPage) und gibt einen Zeiger
159 |* darauf zurueck. Die Drawing Engine benutzt diese Methode beim Laden
160 |* zur Erzeugung von Seiten (deren Typ sie ja nicht kennt, da es ABLEITUNGEN
161 |* der SdrPage sind).
163 \************************************************************************/
166 SdrPage* SwDrawDocument::AllocPage(FASTBOOL bMasterPage)
168 SwDPage* pPage = new SwDPage(*this, 0 != bMasterPage);
169 pPage->SetName( String::CreateFromAscii(
170 RTL_CONSTASCII_STRINGPARAM( "Controls" )) );
171 return pPage;
175 SvStream* SwDrawDocument::GetDocumentStream( SdrDocumentStreamInfo& rInfo ) const
177 SvStream* pRet = NULL;
178 uno::Reference < embed::XStorage > xRoot( pDoc->GetDocStorage() );
179 if( xRoot.is() )
181 if( rInfo.maUserData.Len() &&
182 ( rInfo.maUserData.GetToken( 0, ':' ) ==
183 String( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package" ) ) ) )
185 const String aPicturePath( rInfo.maUserData.GetToken( 1, ':' ) );
187 // graphic from picture stream in picture storage in XML package
188 if( aPicturePath.GetTokenCount( '/' ) == 2 )
190 const String aPictureStorageName( aPicturePath.GetToken( 0, '/' ) );
191 const String aPictureStreamName( aPicturePath.GetToken( 1, '/' ) );
195 uno::Reference < embed::XStorage > xPictureStorage = xRoot->openStorageElement(
196 aPictureStorageName, embed::ElementModes::READ );
197 uno::Reference < io::XStream > xStream = xPictureStorage->openStreamElement(
198 aPictureStreamName, embed::ElementModes::READ );
199 pRet = utl::UcbStreamHelper::CreateStream( xStream );
200 if( pRet )
202 rInfo.mbDeleteAfterUse = TRUE;
203 rInfo.mxStorageRef = xPictureStorage;
206 catch ( uno::Exception& )
212 return pRet;
215 SdrLayerID SwDrawDocument::GetControlExportLayerId( const SdrObject & ) const
217 //fuer Versionen < 5.0, es gab nur Hell und Heaven
218 return (SdrLayerID)pDoc->GetHeavenId();
221 // --> OD 2006-03-01 #b6382898#
222 uno::Reference< uno::XInterface > SwDrawDocument::createUnoModel()
225 uno::Reference< uno::XInterface > xModel;
229 if ( GetDoc().GetDocShell() )
231 xModel = GetDoc().GetDocShell()->GetModel();
234 catch( uno::RuntimeException& )
236 ASSERT( false,
237 "<SwDrawDocument::createUnoModel()> - could *not* retrieve model at <SwDocShell>" );
240 return xModel;
243 // <--