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