xref: /trunk/main/sw/source/core/draw/drawdoc.cxx (revision 26ea3662)
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 
SwDrawModel(SwDoc * pD)65 SwDrawModel::SwDrawModel( SwDoc* pD )
66 :   FmFormModel( ::GetPalettePath(), &pD->GetAttrPool(), pD->GetDocShell() ),
67     pDoc( pD )
68 {
69 	SetScaleUnit( MAP_TWIP );
70 	SetSwapGraphics( sal_True );
71 
72     // use common InitDrawModelAndDocShell which will set the associations as needed,
73     // including SvxColorTableItem  with WhichID SID_COLOR_TABLE
74     InitDrawModelAndDocShell(pDoc ? pDoc->GetDocShell() : 0, this);
75 
76 	// copy all the default values to the SdrModel
77 	SfxItemPool* pSdrPool = pD->GetAttrPool().GetSecondaryPool();
78 	if( pSdrPool )
79 	{
80 		const sal_uInt16 aWhichRanges[] =
81 			{
82 				RES_CHRATR_BEGIN, RES_CHRATR_END,
83 				RES_PARATR_BEGIN, RES_PARATR_END,
84 				0
85 			};
86 
87 		SfxItemPool& rDocPool = pD->GetAttrPool();
88 		sal_uInt16 nEdtWhich, nSlotId;
89 		const SfxPoolItem* pItem;
90 		for( const sal_uInt16* pRangeArr = aWhichRanges;
91 			*pRangeArr; pRangeArr += 2 )
92 			for( sal_uInt16 nW = *pRangeArr, nEnd = *(pRangeArr+1);
93 					nW < nEnd; ++nW )
94 				if( 0 != (pItem = rDocPool.GetPoolDefaultItem( nW )) &&
95 					0 != (nSlotId = rDocPool.GetSlotId( nW ) ) &&
96 					nSlotId != nW &&
97 					0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
98 					nSlotId != nEdtWhich )
99 				{
100 					SfxPoolItem* pCpy = pItem->Clone();
101 					pCpy->SetWhich( nEdtWhich );
102 					pSdrPool->SetPoolDefaultItem( *pCpy );
103 					delete pCpy;
104 				}
105 	}
106 
107     SetForbiddenCharsTable( pD->getForbiddenCharacterTable() );
108 	// #87795# Implementation for asian compression
109     SetCharCompressType( static_cast<sal_uInt16>(pD->getCharacterCompressionType() ));
110 }
111 
112 /*************************************************************************
113 |*
114 |* Destruktor
115 |*
116 \************************************************************************/
117 
118 
~SwDrawModel()119 SwDrawModel::~SwDrawModel()
120 {
121 	Broadcast(SdrHint(HINT_MODELCLEARED));
122 
123 	// #116168#
124 	ClearModel(sal_True);
125 	//Clear();
126 }
127 
128 /*************************************************************************
129 |*
130 |* Diese Methode erzeugt eine neue Seite (SdPage) und gibt einen Zeiger
131 |* darauf zurueck. Die Drawing Engine benutzt diese Methode beim Laden
132 |* zur Erzeugung von Seiten (deren Typ sie ja nicht kennt, da es ABLEITUNGEN
133 |* der SdrPage sind).
134 |*
135 \************************************************************************/
136 
137 
AllocPage(FASTBOOL bMasterPage)138 SdrPage* SwDrawModel::AllocPage(FASTBOOL bMasterPage)
139 {
140 	SwDPage* pPage = new SwDPage(*this, 0 != bMasterPage);
141 	pPage->SetName( String::CreateFromAscii(
142 									RTL_CONSTASCII_STRINGPARAM( "Controls" )) );
143 	return pPage;
144 }
145 
146 
GetDocumentStream(SdrDocumentStreamInfo & rInfo) const147 SvStream* SwDrawModel::GetDocumentStream( SdrDocumentStreamInfo& rInfo ) const
148 {
149 	SvStream* pRet = NULL;
150     uno::Reference < embed::XStorage > xRoot( pDoc->GetDocStorage() );
151     if( xRoot.is() )
152     {
153 	    if( rInfo.maUserData.Len() &&
154 		    ( rInfo.maUserData.GetToken( 0, ':' ) ==
155 		      String( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package" ) ) ) )
156 	    {
157 		    const String aPicturePath( rInfo.maUserData.GetToken( 1, ':' ) );
158 
159 		    // graphic from picture stream in picture storage in XML package
160 		    if( aPicturePath.GetTokenCount( '/' ) == 2 )
161 		    {
162 			    const String    aPictureStorageName( aPicturePath.GetToken( 0, '/' ) );
163                 const String    aPictureStreamName( aPicturePath.GetToken( 1, '/' ) );
164 
165                 try
166                 {
167                     uno::Reference < embed::XStorage > xPictureStorage = xRoot->openStorageElement(
168                             aPictureStorageName, embed::ElementModes::READ );
169                     uno::Reference < io::XStream > xStream = xPictureStorage->openStreamElement(
170                             aPictureStreamName, embed::ElementModes::READ );
171                     pRet = utl::UcbStreamHelper::CreateStream( xStream );
172 				    if( pRet )
173 				    {
174                         rInfo.mbDeleteAfterUse = sal_True;
175                         rInfo.mxStorageRef = xPictureStorage;
176 				    }
177 			    }
178                 catch ( uno::Exception& )
179                 {
180                 }
181 		    }
182 	    }
183     }
184 	return pRet;
185 }
186 
GetControlExportLayerId(const SdrObject &) const187 SdrLayerID SwDrawModel::GetControlExportLayerId( const SdrObject & ) const
188 {
189 	//fuer Versionen < 5.0, es gab nur Hell und Heaven
190 	return (SdrLayerID)pDoc->GetHeavenId();
191 }
192 
193 // --> OD 2006-03-01 #b6382898#
createUnoModel()194 uno::Reference< uno::XInterface > SwDrawModel::createUnoModel()
195 {
196 
197     uno::Reference< uno::XInterface > xModel;
198 
199     try
200     {
201         if ( GetDoc().GetDocShell() )
202         {
203             xModel = GetDoc().GetDocShell()->GetModel();
204         }
205     }
206     catch( uno::RuntimeException& )
207     {
208         ASSERT( false, "<SwDrawModel::createUnoModel()> - could *not* retrieve model at <SwDocShell>" );
209     }
210 
211     return xModel;
212 }
213 
214 // <--
215