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