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