xref: /trunk/main/sd/source/ui/docshell/docshel4.cxx (revision 1396af09)
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_sd.hxx"
26 
27 #include "DrawDocShell.hxx"
28 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
29 #include <tools/urlobj.hxx>
30 #include <sfx2/progress.hxx>
31 #include <vcl/waitobj.hxx>
32 #ifndef _SVXIDS_HRC
33 #include <svx/svxids.hrc>
34 #endif
35 #include <editeng/flstitem.hxx>
36 #include <editeng/eeitem.hxx>
37 #include <svl/aeitem.hxx>
38 #include <svl/flagitem.hxx>
39 #include <sot/storage.hxx>
40 #include <sfx2/docfile.hxx>
41 #include <sfx2/docfilt.hxx>
42 #ifndef _DISPATCH_HXX //autogen
43 #include <sfx2/dispatch.hxx>
44 #endif
45 #include <svx/svdotext.hxx>
46 #include <svl/style.hxx>
47 #include <sfx2/printer.hxx>
48 #include <svtools/ctrltool.hxx>
49 #ifndef _SFX_ECODE_HXX //autogen
50 #include <svtools/sfxecode.hxx>
51 #endif
52 #include <sot/clsids.hxx>
53 #include <sot/formats.hxx>
54 #include <sfx2/request.hxx>
55 #ifdef TF_STARONE
56 #include "unomodel.hxx"
57 #endif
58 
59 #include <unotools/fltrcfg.hxx>
60 #include <sfx2/frame.hxx>
61 #include <sfx2/viewfrm.hxx>
62 //#include <svx/svxmsbas.hxx>
63 #include <unotools/saveopt.hxx>
64 #include <com/sun/star/drawing/XDrawPage.hpp>
65 #include <com/sun/star/drawing/XDrawView.hpp>
66 #include <comphelper/processfactory.hxx>
67 
68 #include "app.hrc"
69 #include "glob.hrc"
70 #include "strings.hrc"
71 #include "strmname.h"
72 #ifndef SD_FRAMW_VIEW_HXX
73 #include "FrameView.hxx"
74 #endif
75 #include "optsitem.hxx"
76 #include "Outliner.hxx"
77 #include "sdattr.hxx"
78 #include "drawdoc.hxx"
79 #include "ViewShell.hxx"
80 #include "app.hxx"
81 #include "View.hxx"
82 #include "sdpage.hxx"
83 #include "sdresid.hxx"
84 #include "DrawViewShell.hxx"
85 #include "ViewShellBase.hxx"
86 #include "Window.hxx"
87 #include "sdmod.hxx"
88 #include "OutlineViewShell.hxx"
89 #include "sdxmlwrp.hxx"
90 #include "sdpptwrp.hxx"
91 #include "sdcgmfilter.hxx"
92 #include "sdgrffilter.hxx"
93 #include "sdhtmlfilter.hxx"
94 #include "framework/FrameworkHelper.hxx"
95 
96 using namespace ::com::sun::star;
97 using namespace ::com::sun::star::uno;
98 using ::sd::framework::FrameworkHelper;
99 
100 
101 namespace sd {
102 
103 /*************************************************************************
104 |*
105 |* SfxPrinter ggf. erzeugen und zurueckgeben
106 |*
107 \************************************************************************/
108 
109 SfxPrinter* DrawDocShell::GetPrinter(sal_Bool bCreate)
110 {
111 	if (bCreate && !mpPrinter)
112 	{
113 		// ItemSet mit speziellem Poolbereich anlegen
114 		SfxItemSet* pSet = new SfxItemSet( GetPool(),
115 							SID_PRINTER_NOTFOUND_WARN,	SID_PRINTER_NOTFOUND_WARN,
116 							SID_PRINTER_CHANGESTODOC,	SID_PRINTER_CHANGESTODOC,
117 							ATTR_OPTIONS_PRINT, 		ATTR_OPTIONS_PRINT,
118 							0 );
119 		// PrintOptionsSet setzen
120 		SdOptionsPrintItem aPrintItem( ATTR_OPTIONS_PRINT,
121 							SD_MOD()->GetSdOptions(mpDoc->GetDocumentType()));
122 		SfxFlagItem aFlagItem( SID_PRINTER_CHANGESTODOC );
123 		sal_uInt16		nFlags = 0;
124 
125 		nFlags =  (aPrintItem.GetOptionsPrint().IsWarningSize() ? SFX_PRINTER_CHG_SIZE : 0) |
126 				(aPrintItem.GetOptionsPrint().IsWarningOrientation() ? SFX_PRINTER_CHG_ORIENTATION : 0);
127 		aFlagItem.SetValue( nFlags );
128 
129 		pSet->Put( aPrintItem );
130 		pSet->Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, aPrintItem.GetOptionsPrint().IsWarningPrinter() ) );
131 		pSet->Put( aFlagItem );
132 
133 		mpPrinter = new SfxPrinter(pSet);
134 		mbOwnPrinter = sal_True;
135 
136 		// Ausgabequalitaet setzen
137 		sal_uInt16 nQuality = aPrintItem.GetOptionsPrint().GetOutputQuality();
138 
139 		sal_uLong nMode = DRAWMODE_DEFAULT;
140 
141         if( nQuality == 1 )
142 			nMode = DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_BLACKTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT;
143 		else if( nQuality == 2 )
144 			nMode = DRAWMODE_BLACKLINE | DRAWMODE_BLACKTEXT | DRAWMODE_WHITEFILL | DRAWMODE_GRAYBITMAP | DRAWMODE_WHITEGRADIENT;
145 
146 		mpPrinter->SetDrawMode( nMode );
147 
148 		MapMode aMM (mpPrinter->GetMapMode());
149 		aMM.SetMapUnit(MAP_100TH_MM);
150 		mpPrinter->SetMapMode(aMM);
151         UpdateRefDevice();
152 	}
153 	return mpPrinter;
154 }
155 
156 /*************************************************************************
157 |*
158 |* neuen SfxPrinter setzen (Eigentuemeruebergang)
159 |*
160 \************************************************************************/
161 
162 void DrawDocShell::SetPrinter(SfxPrinter *pNewPrinter)
163 {
164 	if ( mpViewShell )
165 	{
166 		::sd::View* pView = mpViewShell->GetView();
167 		if ( pView->IsTextEdit() )
168 			pView->SdrEndTextEdit();
169 	}
170 
171 	if ( mpPrinter && mbOwnPrinter && (mpPrinter != pNewPrinter) )
172 	{
173 		delete mpPrinter;
174 	}
175 
176 	mpPrinter = pNewPrinter;
177 	mbOwnPrinter = sal_True;
178     if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
179 		UpdateFontList();
180     UpdateRefDevice();
181 }
182 
183 void DrawDocShell::UpdateFontList()
184 {
185 	delete mpFontList;
186     OutputDevice* pRefDevice = NULL;
187     if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
188 		pRefDevice = GetPrinter(sal_True);
189 	else
190 		pRefDevice = SD_MOD()->GetVirtualRefDevice();
191 	mpFontList = new FontList( pRefDevice, NULL, sal_False );
192     SvxFontListItem aFontListItem( mpFontList, SID_ATTR_CHAR_FONTLIST );
193 	PutItem( aFontListItem );
194 }
195 
196 /*************************************************************************
197 |*
198 |*
199 |*
200 \************************************************************************/
201 Printer* DrawDocShell::GetDocumentPrinter()
202 {
203 	return GetPrinter(sal_False);
204 }
205 
206 /*************************************************************************
207 |*
208 |*
209 |*
210 \************************************************************************/
211 void DrawDocShell::OnDocumentPrinterChanged(Printer* pNewPrinter)
212 {
213 	// if we already have a printer, see if its the same
214 	if( mpPrinter )
215 	{
216 		// easy case
217 		if( mpPrinter == pNewPrinter )
218 			return;
219 
220 		// compare if its the same printer with the same job setup
221 		if( (mpPrinter->GetName() == pNewPrinter->GetName()) &&
222 			(mpPrinter->GetJobSetup() == pNewPrinter->GetJobSetup()))
223 			return;
224 	}
225 
226 	//	if (mpPrinter->IsA(SfxPrinter))
227 	{
228 		// Da kein RTTI verfuegbar, wird hart gecasted (...)
229 		SetPrinter((SfxPrinter*) pNewPrinter);
230 
231 		// Printer gehoert dem Container
232 		mbOwnPrinter = sal_False;
233 	}
234 }
235 
236 /*************************************************************************
237 |*
238 |*
239 |*
240 \************************************************************************/
241 void DrawDocShell::UpdateRefDevice()
242 {
243 	if( mpDoc )
244 	{
245         // Determine the device for which the output will be formatted.
246         OutputDevice* pRefDevice = NULL;
247         switch (mpDoc->GetPrinterIndependentLayout())
248         {
249             case ::com::sun::star::document::PrinterIndependentLayout::DISABLED:
250                 pRefDevice = mpPrinter;
251                 break;
252 
253             case ::com::sun::star::document::PrinterIndependentLayout::ENABLED:
254                 pRefDevice = SD_MOD()->GetVirtualRefDevice();
255                 break;
256 
257             default:
258                 // We are confronted with an invalid or un-implemented
259                 // layout mode.  Use the printer as formatting device
260                 // as a fall-back.
261                 DBG_ASSERT(false, "DrawDocShell::UpdateRefDevice(): Unexpected printer layout mode");
262 
263                 pRefDevice = mpPrinter;
264                 break;
265         }
266 		mpDoc->SetRefDevice( pRefDevice );
267 
268 		::sd::Outliner* pOutl = mpDoc->GetOutliner( sal_False );
269 
270 		if( pOutl )
271 			pOutl->SetRefDevice( pRefDevice );
272 
273 		::sd::Outliner* pInternalOutl = mpDoc->GetInternalOutliner( sal_False );
274 
275 		if( pInternalOutl )
276 			pInternalOutl->SetRefDevice( pRefDevice );
277 	}
278 }
279 
280 /*************************************************************************
281 |*
282 |* InitNew, (Dokument wird neu erzeugt): Streams oeffnen
283 |*
284 \************************************************************************/
285 
286 sal_Bool DrawDocShell::InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
287 {
288 	sal_Bool bRet = sal_False;
289 
290     bRet = SfxObjectShell::InitNew( xStorage );
291 
292 	Rectangle aVisArea( Point(0, 0), Size(14100, 10000) );
293 	SetVisArea(aVisArea);
294 
295 	if (bRet)
296 	{
297 		if( !mbSdDataObj )
298 			mpDoc->NewOrLoadCompleted(NEW_DOC);  // otherwise calling
299 			                                    // NewOrLoadCompleted(NEW_LOADED) in
300 												// SdDrawDocument::AllocModel()
301 	}
302 	return bRet;
303 }
304 
305 /*************************************************************************
306 |*
307 |* Load: Pools und Dokument laden
308 |*
309 \************************************************************************/
310 
311 sal_Bool DrawDocShell::Load( SfxMedium& rMedium )
312 {
313     mbNewDocument = sal_False;
314 
315 	sal_Bool	bRet = sal_False;
316 	bool	bStartPresentation = false;
317     ErrCode nError = ERRCODE_NONE;
318 
319     SfxItemSet* pSet = rMedium.GetItemSet();
320 
321 
322 	if( pSet )
323 	{
324 		if( (  SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
325 		{
326 			mpDoc->SetStarDrawPreviewMode( sal_True );
327 		}
328 
329 		if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
330 			( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
331 		{
332 			bStartPresentation = true;
333 			mpDoc->SetStartWithPresentation( true );
334 		}
335 	}
336 
337     bRet = SfxObjectShell::Load( rMedium );
338 	if( bRet )
339 	{
340         bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
341 	}
342 
343 	if( bRet )
344 	{
345 		UpdateTablePointers();
346 
347         // #108451# If we're an embedded OLE object, use tight bounds
348         // for our visArea. No point in showing the user lots of empty
349         // space. Had to remove the check for empty VisArea below,
350         // since XML load always sets a VisArea before.
351         //TODO/LATER: looks a little bit strange!
352         if( ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) && SfxObjectShell::GetVisArea( ASPECT_CONTENT ).IsEmpty() )
353 		{
354 			SdPage* pPage = mpDoc->GetSdPage( 0, PK_STANDARD );
355 
356 			if( pPage )
357 				SetVisArea( Rectangle( pPage->GetAllObjBoundRect() ) );
358 		}
359 
360 		FinishedLoading( SFX_LOADED_ALL );
361 
362         const INetURLObject aUrl;
363         SfxObjectShell::SetAutoLoad( aUrl, 0, sal_False );
364 	}
365 	else
366 	{
367         if( nError == ERRCODE_IO_BROKENPACKAGE )
368             SetError( ERRCODE_IO_BROKENPACKAGE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
369 
370         // TODO/LATER: correct error handling?!
371         //pStore->SetError( SVSTREAM_WRONGVERSION, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
372         else
373             SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
374 	}
375 
376 	// tell SFX to change viewshell when in preview mode
377 	if( IsPreview() || bStartPresentation )
378 	{
379 		SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
380 		if( pMediumSet )
381 			pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
382 	}
383 
384 	return bRet;
385 }
386 
387 /*************************************************************************
388 |*
389 |* LoadFrom: Inhalte fuer Organizer laden
390 |*
391 \************************************************************************/
392 
393 sal_Bool DrawDocShell::LoadFrom( SfxMedium& rMedium )
394 {
395     mbNewDocument = sal_False;
396 
397 	WaitObject* pWait = NULL;
398 	if( mpViewShell )
399 		pWait = new WaitObject( (Window*) mpViewShell->GetActiveWindow() );
400 
401 	sal_Bool bRet = sal_False;
402 
403         /*
404         // #90691# return to old behaviour (before #80365#): construct own medium
405         SfxMedium aMedium(xStorage);
406 
407 		// #90691# for having a progress bar nonetheless for XML copy it
408 		// from the local DocShell medium (GetMedium()) to the constructed one
409 		SfxMedium* pLocalMedium = GetMedium();
410 		if(pLocalMedium)
411 		{
412 			SfxItemSet* pLocalItemSet = pLocalMedium->GetItemSet();
413 			SfxItemSet* pDestItemSet = aMedium.GetItemSet();
414 
415 			if(pLocalItemSet && pDestItemSet)
416 			{
417 				const SfxUnoAnyItem* pItem = static_cast<
418                     const SfxUnoAnyItem*>(
419                         pLocalItemSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL));
420 
421 				if(pItem)
422 				{
423 					pDestItemSet->Put(*pItem);
424 				}
425 			}
426         }                           */
427 
428 		mpDoc->NewOrLoadCompleted( NEW_DOC );
429 		mpDoc->CreateFirstPages();
430 		mpDoc->StopWorkStartupDelay();
431 
432         // TODO/LATER: nobody is interested in the error code?!
433         ErrCode nError = ERRCODE_NONE;
434         bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Organizer, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
435 
436 
437 	// tell SFX to change viewshell when in preview mode
438 	if( IsPreview() )
439 	{
440 		SfxItemSet *pSet = GetMedium()->GetItemSet();
441 
442 		if( pSet )
443 			pSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
444 	}
445 
446 	delete pWait;
447 
448 	return bRet;
449 }
450 
451 /*************************************************************************
452 |*
453 |* ConvertFrom: aus Fremdformat laden
454 |*
455 \************************************************************************/
456 
457 sal_Bool DrawDocShell::ConvertFrom( SfxMedium& rMedium )
458 {
459     mbNewDocument = sal_False;
460 
461 	const String	aFilterName( rMedium.GetFilter()->GetFilterName() );
462 	sal_Bool			bRet = sal_False;
463 	bool	bStartPresentation = false;
464 
465 	SetWaitCursor( sal_True );
466 
467     SfxItemSet* pSet = rMedium.GetItemSet();
468 	if( pSet )
469 	{
470 		if( (  SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
471 		{
472 			mpDoc->SetStarDrawPreviewMode( sal_True );
473 		}
474 
475 		if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
476 			( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
477 		{
478 			bStartPresentation = true;
479 			mpDoc->SetStartWithPresentation( true );
480 		}
481 	}
482 
483 	if( aFilterName == pFilterPowerPoint97 || aFilterName == pFilterPowerPoint97Template)
484 	{
485 		mpDoc->StopWorkStartupDelay();
486         bRet = SdPPTFilter( rMedium, *this, sal_True ).Import();
487 	}
488 	else if (aFilterName.SearchAscii("impress8" )  != STRING_NOTFOUND ||
489 		     aFilterName.SearchAscii("draw8")  != STRING_NOTFOUND )
490 	{
491         // TODO/LATER: nobody is interested in the error code?!
492 		mpDoc->CreateFirstPages();
493 		mpDoc->StopWorkStartupDelay();
494         ErrCode nError = ERRCODE_NONE;
495         bRet = SdXMLFilter( rMedium, *this, sal_True ).Import( nError );
496 
497 	}
498 	else if (aFilterName.SearchAscii("StarOffice XML (Draw)" )  != STRING_NOTFOUND || aFilterName.SearchAscii("StarOffice XML (Impress)")  != STRING_NOTFOUND )
499 	{
500         // TODO/LATER: nobody is interested in the error code?!
501 		mpDoc->CreateFirstPages();
502 		mpDoc->StopWorkStartupDelay();
503         ErrCode nError = ERRCODE_NONE;
504         bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 ).Import( nError );
505 	}
506 	else if( aFilterName.EqualsAscii( "CGM - Computer Graphics Metafile" ) )
507 	{
508 		mpDoc->CreateFirstPages();
509 		mpDoc->StopWorkStartupDelay();
510         bRet = SdCGMFilter( rMedium, *this, sal_True ).Import();
511 	}
512 	else
513 	{
514 		mpDoc->CreateFirstPages();
515 		mpDoc->StopWorkStartupDelay();
516         bRet = SdGRFFilter( rMedium, *this ).Import();
517 	}
518 
519 	FinishedLoading( SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES );
520 
521 	// tell SFX to change viewshell when in preview mode
522 	if( IsPreview() )
523 	{
524 		SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
525 
526 		if( pMediumSet )
527 			pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
528 	}
529 	SetWaitCursor( sal_False );
530 
531 	// tell SFX to change viewshell when in preview mode
532 	if( IsPreview() || bStartPresentation )
533 	{
534 		SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
535 		if( pMediumSet )
536 			pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
537 	}
538 
539 	return bRet;
540 }
541 
542 /*************************************************************************
543 |*
544 |* Save: Pools und Dokument in die offenen Streams schreiben
545 |*
546 \************************************************************************/
547 
548 sal_Bool DrawDocShell::Save()
549 {
550 	mpDoc->StopWorkStartupDelay();
551 
552     //TODO/LATER: why this?!
553 	if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
554         SfxObjectShell::SetVisArea( Rectangle() );
555 
556     sal_Bool bRet = SfxObjectShell::Save();
557 
558 	if( bRet )
559 	{
560 		// #86834# Call UpdateDocInfoForSave() before export
561 		UpdateDocInfoForSave();
562 
563         bRet = SdXMLFilter( *GetMedium(), *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( GetMedium()->GetStorage() ) ).Export();
564 	}
565 
566 	return bRet;
567 }
568 
569 /*************************************************************************
570 |*
571 |* SaveAs: Pools und Dokument in den angegebenen Storage sichern
572 |*
573 \************************************************************************/
574 
575 sal_Bool DrawDocShell::SaveAs( SfxMedium& rMedium )
576 {
577 	mpDoc->StopWorkStartupDelay();
578 
579     //TODO/LATER: why this?!
580 	if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
581         SfxObjectShell::SetVisArea( Rectangle() );
582 
583 	sal_uInt32	nVBWarning = ERRCODE_NONE;
584     sal_Bool    bRet = SfxObjectShell::SaveAs( rMedium );
585 
586 	if( bRet )
587 	{
588         // #86834# Call UpdateDocInfoForSave() before export
589         UpdateDocInfoForSave();
590         bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Export();
591     }
592 
593 	if( GetError() == ERRCODE_NONE )
594 		SetError( nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
595 
596 	return bRet;
597 }
598 
599 /*************************************************************************
600 |*
601 |* ConvertTo: im Fremdformat speichern
602 |*
603 \************************************************************************/
604 
605 sal_Bool DrawDocShell::ConvertTo( SfxMedium& rMedium )
606 {
607 	sal_Bool bRet = sal_False;
608 
609 	if( mpDoc->GetPageCount() )
610 	{
611 		const SfxFilter*	pMediumFilter = rMedium.GetFilter();
612 		const String		aTypeName( pMediumFilter->GetTypeName() );
613 		SdFilter*			pFilter = NULL;
614 
615 		if( aTypeName.SearchAscii( "graphic_HTML" ) != STRING_NOTFOUND )
616 		{
617 			pFilter = new SdHTMLFilter( rMedium, *this, sal_True );
618 		}
619 		else if( aTypeName.SearchAscii( "MS_PowerPoint_97" ) != STRING_NOTFOUND )
620 		{
621 			pFilter = new SdPPTFilter( rMedium, *this, sal_True );
622 			((SdPPTFilter*)pFilter)->PreSaveBasic();
623 		}
624 		else if ( aTypeName.SearchAscii( "CGM_Computer_Graphics_Metafile" ) != STRING_NOTFOUND )
625 		{
626 			pFilter = new SdCGMFilter( rMedium, *this, sal_True );
627 		}
628 		else if( ( aTypeName.SearchAscii( "draw8" ) != STRING_NOTFOUND ) ||
629 				 ( aTypeName.SearchAscii( "impress8" ) != STRING_NOTFOUND ) )
630 		{
631 			pFilter = new SdXMLFilter( rMedium, *this, sal_True );
632 			UpdateDocInfoForSave();
633 		}
634 		else if( ( aTypeName.SearchAscii( "StarOffice_XML_Impress" ) != STRING_NOTFOUND ) ||
635 				 ( aTypeName.SearchAscii( "StarOffice_XML_Draw" ) != STRING_NOTFOUND ) )
636 		{
637 			pFilter = new SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 );
638 			UpdateDocInfoForSave();
639 		}
640 		else
641 		{
642 			pFilter = new SdGRFFilter( rMedium, *this );
643 		}
644 
645 		if( pFilter )
646 		{
647 			const sal_uLong	nOldSwapMode = mpDoc->GetSwapGraphicsMode();
648 
649 			mpDoc->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
650 
651 			bRet = pFilter->Export();
652 			if( !bRet )
653 				mpDoc->SetSwapGraphicsMode( nOldSwapMode );
654 
655 			delete pFilter;
656 		}
657 	}
658 
659 	return  bRet;
660 }
661 
662 /*************************************************************************
663 |*
664 |* SaveCompleted: die eigenen Streams wieder oeffnen, damit kein anderer
665 |*								  sie "besetzt"
666 |*
667 \************************************************************************/
668 
669 sal_Bool DrawDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
670 {
671 	sal_Bool bRet = sal_False;
672 
673     if( SfxObjectShell::SaveCompleted(xStorage) )
674 	{
675 		mpDoc->NbcSetChanged( sal_False );
676 
677 		if( mpViewShell )
678 		{
679 			if( mpViewShell->ISA( OutlineViewShell ) )
680 				static_cast<OutlineView*>(mpViewShell->GetView())
681                     ->GetOutliner()->ClearModifyFlag();
682 
683 			SdrOutliner* pOutl = mpViewShell->GetView()->GetTextEditOutliner();
684 			if( pOutl )
685 			{
686 				SdrObject* pObj = mpViewShell->GetView()->GetTextEditObject();
687 				if( pObj )
688 					pObj->NbcSetOutlinerParaObject( pOutl->CreateParaObject() );
689 
690 				pOutl->ClearModifyFlag();
691 			}
692 		}
693 
694 		bRet = sal_True;
695 
696 		SfxViewFrame* pFrame = ( mpViewShell && mpViewShell->GetViewFrame() ) ?
697 							   mpViewShell->GetViewFrame() :
698 							   SfxViewFrame::Current();
699 
700 		if( pFrame )
701 			pFrame->GetBindings().Invalidate( SID_NAVIGATOR_STATE, sal_True, sal_False );
702 	}
703 	return bRet;
704 }
705 
706 /*************************************************************************
707 |*
708 |* Referenz auf Dokument
709 |*
710 \************************************************************************/
711 
712 SdDrawDocument* DrawDocShell::GetDoc()
713 {
714 	return mpDoc;
715 }
716 
717 /*************************************************************************
718 |*
719 |* Referenz auf Dokument
720 |*
721 \************************************************************************/
722 
723 SfxStyleSheetBasePool* DrawDocShell::GetStyleSheetPool()
724 {
725 	return( (SfxStyleSheetBasePool*) mpDoc->GetStyleSheetPool() );
726 }
727 
728 /*************************************************************************
729 |*
730 |* Sprung zu Bookmark
731 |*
732 \************************************************************************/
733 
734 sal_Bool DrawDocShell::GotoBookmark(const String& rBookmark)
735 {
736 	sal_Bool bFound = sal_False;
737 
738 	if (mpViewShell && mpViewShell->ISA(DrawViewShell))
739 	{
740 		DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(mpViewShell);
741         ViewShellBase& rBase (mpViewShell->GetViewShellBase());
742 
743 		sal_Bool bIsMasterPage = sal_False;
744 		sal_uInt16 nPageNumber = SDRPAGE_NOTFOUND;
745 		SdrObject* pObj = NULL;
746 
747 		rtl::OUString sBookmark( rBookmark );
748 		const rtl::OUString sInteraction( RTL_CONSTASCII_USTRINGPARAM( "action?" ) );
749 		if ( sBookmark.match( sInteraction ) )
750 		{
751 			const rtl::OUString sJump( RTL_CONSTASCII_USTRINGPARAM( "jump=" ) );
752 			if ( sBookmark.match( sJump, sInteraction.getLength() ) )
753 			{
754 				rtl::OUString aDestination( sBookmark.copy( sInteraction.getLength() + sJump.getLength() ) );
755 				if ( aDestination.match( String( RTL_CONSTASCII_USTRINGPARAM( "firstslide" ) ) ) )
756 				{
757 					nPageNumber = 1;
758 				}
759 				else if ( aDestination.match( String( RTL_CONSTASCII_USTRINGPARAM( "lastslide" ) ) ) )
760 				{
761 					nPageNumber = mpDoc->GetPageCount() - 2;
762 				}
763 				else if ( aDestination.match( String( RTL_CONSTASCII_USTRINGPARAM( "previousslide" ) ) ) )
764 				{
765                     SdPage* pPage = pDrawViewShell->GetActualPage();
766                     nPageNumber = pPage->GetPageNum();
767 					nPageNumber = nPageNumber > 2 ? nPageNumber - 2 : SDRPAGE_NOTFOUND;
768 				}
769 				else if ( aDestination.match( String( RTL_CONSTASCII_USTRINGPARAM( "nextslide" ) ) ) )
770 				{
771                     SdPage* pPage = pDrawViewShell->GetActualPage();
772                     nPageNumber = pPage->GetPageNum() + 2;
773 					if ( nPageNumber >= mpDoc->GetPageCount() )
774 						nPageNumber = SDRPAGE_NOTFOUND;
775 				}
776 			}
777 		}
778 		else
779 		{
780 			String aBookmark( rBookmark );
781 
782 			// Ist das Bookmark eine Seite?
783 			nPageNumber = mpDoc->GetPageByName( aBookmark, bIsMasterPage );
784 
785 			if (nPageNumber == SDRPAGE_NOTFOUND)
786 			{
787 				// Ist das Bookmark ein Objekt?
788 				pObj = mpDoc->GetObj(aBookmark);
789 
790 				if (pObj)
791 				{
792 					nPageNumber = pObj->GetPage()->GetPageNum();
793 				}
794 			}
795 		}
796 		if (nPageNumber != SDRPAGE_NOTFOUND)
797 		{
798 			// Jump to the bookmarked page.  This is done in three steps.
799 
800 			bFound = sal_True;
801 			SdPage* pPage;
802             if (bIsMasterPage)
803                 pPage = (SdPage*) mpDoc->GetMasterPage(nPageNumber);
804             else
805                 pPage = (SdPage*) mpDoc->GetPage(nPageNumber);
806 
807             // 1.) Change the view shell to the edit view, the notes view,
808             // or the handout view.
809 			PageKind eNewPageKind = pPage->GetPageKind();
810 
811 			if( (eNewPageKind != PK_STANDARD) && (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
812 				return sal_False;
813 
814 			if (eNewPageKind != pDrawViewShell->GetPageKind())
815 			{
816 				// Arbeitsbereich wechseln
817 				GetFrameView()->SetPageKind(eNewPageKind);
818                 ::rtl::OUString sViewURL;
819                 switch (eNewPageKind)
820                 {
821                     case PK_STANDARD:
822                         sViewURL = FrameworkHelper::msImpressViewURL;
823                         break;
824                     case PK_NOTES:
825                         sViewURL = FrameworkHelper::msNotesViewURL;
826                         break;
827                     case PK_HANDOUT:
828                         sViewURL = FrameworkHelper::msHandoutViewURL;
829                         break;
830                     default:
831                         break;
832                 }
833                 if (sViewURL.getLength() > 0)
834                 {
835                     ::boost::shared_ptr<FrameworkHelper> pHelper (
836                         FrameworkHelper::Instance(rBase));
837                     pHelper->RequestView(
838                         sViewURL,
839                         FrameworkHelper::msCenterPaneURL);
840                     pHelper->WaitForUpdate();
841 
842                     // Get the new DrawViewShell.
843                     mpViewShell = pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
844                     pDrawViewShell = dynamic_cast<sd::DrawViewShell*>(mpViewShell);
845                 }
846                 else
847                 {
848                     pDrawViewShell = NULL;
849                 }
850             }
851 
852             if (pDrawViewShell != NULL)
853             {
854                 // Set the edit mode to either the normal edit mode or the
855                 // master page mode.
856                 EditMode eNewEditMode = EM_PAGE;
857                 if (bIsMasterPage)
858                 {
859                     eNewEditMode = EM_MASTERPAGE;
860                 }
861 
862                 if (eNewEditMode != pDrawViewShell->GetEditMode())
863                 {
864                     // EditMode setzen
865                     pDrawViewShell->ChangeEditMode(eNewEditMode, sal_False);
866                 }
867 
868                 // Make the bookmarked page the current page.  This is done
869                 // by using the API because this takes care of all the
870                 // little things to be done.  Especially writing the view
871                 // data to the frame view (see bug #107803#).
872                 sal_uInt16 nSdPgNum = (nPageNumber - 1) / 2;
873                 Reference<drawing::XDrawView> xController (rBase.GetController(), UNO_QUERY);
874                 if (xController.is())
875                 {
876                     Reference<drawing::XDrawPage> xDrawPage (pPage->getUnoPage(), UNO_QUERY);
877                     xController->setCurrentPage (xDrawPage);
878                 }
879                 else
880                 {
881                     // As a fall back switch to the page via the core.
882                     DBG_ASSERT (xController.is(),
883                         "DrawDocShell::GotoBookmark: can't switch page via API");
884                     pDrawViewShell->SwitchPage(nSdPgNum);
885                 }
886 
887                 if (pObj != NULL)
888                 {
889                     // Objekt einblenden und selektieren
890                     pDrawViewShell->MakeVisible(pObj->GetLogicRect(),
891                         *pDrawViewShell->GetActiveWindow());
892                     pDrawViewShell->GetView()->UnmarkAll();
893                     pDrawViewShell->GetView()->MarkObj(
894                         pObj,
895                         pDrawViewShell->GetView()->GetSdrPageView(), sal_False);
896                 }
897             }
898         }
899 
900         SfxBindings& rBindings = (pDrawViewShell->GetViewFrame()!=NULL
901             ? pDrawViewShell->GetViewFrame()
902             : SfxViewFrame::Current() )->GetBindings();
903 
904         rBindings.Invalidate(SID_NAVIGATOR_STATE, sal_True, sal_False);
905         rBindings.Invalidate(SID_NAVIGATOR_PAGENAME);
906     }
907 
908 	return (bFound);
909 }
910 
911 /*************************************************************************
912 |*
913 |* SaveAsOwnFormat: wenn es eine Dokumentvorlage werden soll,
914 |*
915 \************************************************************************/
916 #include <tools/urlobj.hxx>
917 
918 sal_Bool DrawDocShell::SaveAsOwnFormat( SfxMedium& rMedium )
919 {
920 
921 	const SfxFilter* pFilter = rMedium.GetFilter();
922 
923 	if (pFilter->IsOwnTemplateFormat())
924 	{
925 		// jetzt die StarDraw-Spezialitaeten:
926 		// die Layoutvorlagen der ersten Seite werden mit dem jetzt
927 		// bekannten Layoutnamen versehen, die Layoutnamen der betroffenen
928 		// Masterpages und Seiten werden gesetzt;
929 		// alle Textobjekte der betroffenen Standard-, Notiz- und
930 		// Masterpages werden ueber die Namensaenderung informiert
931 
932 		String aLayoutName;
933 
934 		SfxStringItem* pLayoutItem;
935 		if( rMedium.GetItemSet()->GetItemState(SID_TEMPLATE_NAME, sal_False, (const SfxPoolItem**) & pLayoutItem ) == SFX_ITEM_SET )
936 		{
937 			aLayoutName = pLayoutItem->GetValue();
938 		}
939 		else
940 		{
941 			INetURLObject aURL( rMedium.GetName() );
942 			aURL.removeExtension();
943 			aLayoutName = aURL.getName();
944 		}
945 
946 		if( aLayoutName.Len() )
947 		{
948 			sal_uInt32 nCount = mpDoc->GetMasterSdPageCount(PK_STANDARD);
949 			for(sal_uInt32 i = 0; i < nCount; i++)
950 			{
951 				String aOldPageLayoutName = mpDoc->GetMasterSdPage(i, PK_STANDARD)->GetLayoutName();
952 				String aNewLayoutName = aLayoutName;
953 				// Don't add suffix for the first master page
954 				if( i > 0 )
955 					aNewLayoutName += String::CreateFromInt32(i);
956 
957 				mpDoc->RenameLayoutTemplate(aOldPageLayoutName, aNewLayoutName);
958 			}
959 		}
960 	}
961 
962 	return SfxObjectShell::SaveAsOwnFormat(rMedium);
963 }
964 
965 /*************************************************************************
966 |*
967 |* FillClass
968 |*
969 \************************************************************************/
970 
971 void DrawDocShell::FillClass(SvGlobalName* pClassName,
972 										sal_uInt32*  pFormat,
973 										String* ,
974 										String* pFullTypeName,
975                                         String* pShortTypeName,
976 										sal_Int32 nFileFormat,
977 										sal_Bool bTemplate /* = sal_False */) const
978 {
979 	if (nFileFormat == SOFFICE_FILEFORMAT_60)
980 	{
981         if ( meDocType == DOCUMENT_TYPE_DRAW )
982         {
983                 *pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
984                 *pFormat = SOT_FORMATSTR_ID_STARDRAW_60;
985                 *pFullTypeName = String(SdResId(STR_GRAPHIC_DOCUMENT_FULLTYPE_60));
986         }
987         else
988         {
989                 *pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
990                 *pFormat = SOT_FORMATSTR_ID_STARIMPRESS_60;
991                 *pFullTypeName = String(SdResId(STR_IMPRESS_DOCUMENT_FULLTYPE_60));
992         }
993 	}
994 	else if (nFileFormat == SOFFICE_FILEFORMAT_8)
995 	{
996         if ( meDocType == DOCUMENT_TYPE_DRAW )
997         {
998                 *pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
999                 *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARDRAW_8_TEMPLATE : SOT_FORMATSTR_ID_STARDRAW_8;
1000                 *pFullTypeName = String(RTL_CONSTASCII_USTRINGPARAM("Draw 8"));	// HACK: method will be removed with new storage API
1001         }
1002         else
1003         {
1004                 *pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
1005                 *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARIMPRESS_8_TEMPLATE : SOT_FORMATSTR_ID_STARIMPRESS_8;
1006                 *pFullTypeName = String(RTL_CONSTASCII_USTRINGPARAM("Impress 8")); // HACK: method will be removed with new storage API
1007         }
1008 	}
1009 
1010 	*pShortTypeName = String(SdResId( (meDocType == DOCUMENT_TYPE_DRAW) ?
1011 									  STR_GRAPHIC_DOCUMENT : STR_IMPRESS_DOCUMENT ));
1012 }
1013 
1014 OutputDevice* DrawDocShell::GetDocumentRefDev (void)
1015 {
1016     OutputDevice* pReferenceDevice = SfxObjectShell::GetDocumentRefDev ();
1017     // Only when our parent does not have a reference device then we return
1018     // our own.
1019     if (pReferenceDevice == NULL && mpDoc != NULL)
1020         pReferenceDevice = mpDoc->GetRefDevice ();
1021     return pReferenceDevice;
1022 }
1023 
1024 /** executes the SID_OPENDOC slot to let the framework open a document
1025 	with the given URL and this document as a referer */
1026 void DrawDocShell::OpenBookmark( const String& rBookmarkURL )
1027 {
1028     SfxStringItem   aStrItem( SID_FILE_NAME, rBookmarkURL );
1029     SfxStringItem   aReferer( SID_REFERER, GetMedium()->GetName() );
1030 	const SfxPoolItem* ppArgs[] = { &aStrItem, &aReferer, 0 };
1031 	( mpViewShell ? mpViewShell->GetViewFrame() : SfxViewFrame::Current() )->GetBindings().Execute( SID_OPENHYPERLINK, ppArgs );
1032 }
1033 
1034 } // end of namespace sd
1035