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