merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / docshell / docshel4.cxx
blobd5cadc19ce8091db0e31fd6e16b60ffb1b6c8d6b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docshel4.cxx,v $
10 * $Revision: 1.80.86.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "DrawDocShell.hxx"
35 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
36 #include <tools/urlobj.hxx>
37 #include <sfx2/progress.hxx>
38 #include <vcl/waitobj.hxx>
39 #ifndef _SVXIDS_HRC
40 #include <svx/svxids.hrc>
41 #endif
42 #include <svx/flstitem.hxx>
43 #include <svx/eeitem.hxx>
44 #include <svtools/aeitem.hxx>
45 #include <svtools/flagitem.hxx>
46 #include <sot/storage.hxx>
47 #include <sfx2/docfile.hxx>
48 #include <sfx2/docfilt.hxx>
49 #ifndef _DISPATCH_HXX //autogen
50 #include <sfx2/dispatch.hxx>
51 #endif
52 #include <svx/svdotext.hxx>
53 #include <svtools/style.hxx>
54 #include <sfx2/printer.hxx>
55 #include <svtools/ctrltool.hxx>
56 #ifndef _SFX_ECODE_HXX //autogen
57 #include <svtools/sfxecode.hxx>
58 #endif
59 #include <sot/clsids.hxx>
60 #include <sot/formats.hxx>
61 #include <sfx2/request.hxx>
62 #ifdef TF_STARONE
63 #include "unomodel.hxx"
64 #endif
66 #include <svtools/fltrcfg.hxx>
67 #include <sfx2/frame.hxx>
68 #include <sfx2/viewfrm.hxx>
69 #include <svx/svxmsbas.hxx>
70 #include <svtools/saveopt.hxx>
71 #include <com/sun/star/drawing/XDrawPage.hpp>
72 #include <com/sun/star/drawing/XDrawView.hpp>
73 #include <comphelper/processfactory.hxx>
75 #include "app.hrc"
76 #include "glob.hrc"
77 #include "strings.hrc"
78 #include "strmname.h"
79 #ifndef SD_FRAMW_VIEW_HXX
80 #include "FrameView.hxx"
81 #endif
82 #include "optsitem.hxx"
83 #include "Outliner.hxx"
84 #include "sdattr.hxx"
85 #include "drawdoc.hxx"
86 #include "ViewShell.hxx"
87 #include "app.hxx"
88 #include "View.hxx"
89 #include "sdpage.hxx"
90 #include "sdresid.hxx"
91 #include "DrawViewShell.hxx"
92 #include "ViewShellBase.hxx"
93 #include "Window.hxx"
94 #include "sdmod.hxx"
95 #include "OutlineViewShell.hxx"
96 #include "sdxmlwrp.hxx"
97 #include "sdpptwrp.hxx"
98 #include "sdcgmfilter.hxx"
99 #include "sdgrffilter.hxx"
100 #include "sdhtmlfilter.hxx"
101 #include "framework/FrameworkHelper.hxx"
103 using namespace ::com::sun::star;
104 using namespace ::com::sun::star::uno;
105 using ::sd::framework::FrameworkHelper;
108 namespace sd {
110 /*************************************************************************
112 |* SfxPrinter ggf. erzeugen und zurueckgeben
114 \************************************************************************/
116 SfxPrinter* DrawDocShell::GetPrinter(BOOL bCreate)
118 if (bCreate && !mpPrinter)
120 // ItemSet mit speziellem Poolbereich anlegen
121 SfxItemSet* pSet = new SfxItemSet( GetPool(),
122 SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
123 SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
124 ATTR_OPTIONS_PRINT, ATTR_OPTIONS_PRINT,
125 0 );
126 // PrintOptionsSet setzen
127 SdOptionsPrintItem aPrintItem( ATTR_OPTIONS_PRINT,
128 SD_MOD()->GetSdOptions(mpDoc->GetDocumentType()));
129 SfxFlagItem aFlagItem( SID_PRINTER_CHANGESTODOC );
130 USHORT nFlags = 0;
132 nFlags = (aPrintItem.GetOptionsPrint().IsWarningSize() ? SFX_PRINTER_CHG_SIZE : 0) |
133 (aPrintItem.GetOptionsPrint().IsWarningOrientation() ? SFX_PRINTER_CHG_ORIENTATION : 0);
134 aFlagItem.SetValue( nFlags );
136 pSet->Put( aPrintItem );
137 pSet->Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, aPrintItem.GetOptionsPrint().IsWarningPrinter() ) );
138 pSet->Put( aFlagItem );
140 mpPrinter = new SfxPrinter(pSet);
141 mbOwnPrinter = TRUE;
143 // Ausgabequalitaet setzen
144 UINT16 nQuality = aPrintItem.GetOptionsPrint().GetOutputQuality();
146 ULONG nMode = DRAWMODE_DEFAULT;
148 if( nQuality == 1 )
149 nMode = DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_BLACKTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT;
150 else if( nQuality == 2 )
151 nMode = DRAWMODE_BLACKLINE | DRAWMODE_BLACKTEXT | DRAWMODE_WHITEFILL | DRAWMODE_GRAYBITMAP | DRAWMODE_WHITEGRADIENT;
153 mpPrinter->SetDrawMode( nMode );
155 MapMode aMM (mpPrinter->GetMapMode());
156 aMM.SetMapUnit(MAP_100TH_MM);
157 mpPrinter->SetMapMode(aMM);
158 UpdateRefDevice();
160 return mpPrinter;
163 /*************************************************************************
165 |* neuen SfxPrinter setzen (Eigentuemeruebergang)
167 \************************************************************************/
169 void DrawDocShell::SetPrinter(SfxPrinter *pNewPrinter)
171 if ( mpViewShell )
173 ::sd::View* pView = mpViewShell->GetView();
174 if ( pView->IsTextEdit() )
175 pView->SdrEndTextEdit();
178 if ( mpPrinter && mbOwnPrinter && (mpPrinter != pNewPrinter) )
180 delete mpPrinter;
183 mpPrinter = pNewPrinter;
184 mbOwnPrinter = TRUE;
185 if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
186 UpdateFontList();
187 UpdateRefDevice();
190 void DrawDocShell::UpdateFontList()
192 delete mpFontList;
193 OutputDevice* pRefDevice = NULL;
194 if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
195 pRefDevice = GetPrinter(TRUE);
196 else
197 pRefDevice = SD_MOD()->GetVirtualRefDevice();
198 mpFontList = new FontList( pRefDevice, NULL, FALSE );
199 SvxFontListItem aFontListItem( mpFontList, SID_ATTR_CHAR_FONTLIST );
200 PutItem( aFontListItem );
203 /*************************************************************************
207 \************************************************************************/
208 Printer* DrawDocShell::GetDocumentPrinter()
210 return GetPrinter(FALSE);
213 /*************************************************************************
217 \************************************************************************/
218 void DrawDocShell::OnDocumentPrinterChanged(Printer* pNewPrinter)
220 // if we already have a printer, see if its the same
221 if( mpPrinter )
223 // easy case
224 if( mpPrinter == pNewPrinter )
225 return;
227 // compare if its the same printer with the same job setup
228 if( (mpPrinter->GetName() == pNewPrinter->GetName()) &&
229 (mpPrinter->GetJobSetup() == pNewPrinter->GetJobSetup()))
230 return;
233 // if (mpPrinter->IsA(SfxPrinter))
235 // Da kein RTTI verfuegbar, wird hart gecasted (...)
236 SetPrinter((SfxPrinter*) pNewPrinter);
238 // Printer gehoert dem Container
239 mbOwnPrinter = FALSE;
243 /*************************************************************************
247 \************************************************************************/
248 void DrawDocShell::UpdateRefDevice()
250 if( mpDoc )
252 // Determine the device for which the output will be formatted.
253 OutputDevice* pRefDevice = NULL;
254 switch (mpDoc->GetPrinterIndependentLayout())
256 case ::com::sun::star::document::PrinterIndependentLayout::DISABLED:
257 pRefDevice = mpPrinter;
258 break;
260 case ::com::sun::star::document::PrinterIndependentLayout::ENABLED:
261 pRefDevice = SD_MOD()->GetVirtualRefDevice();
262 break;
264 default:
265 // We are confronted with an invalid or un-implemented
266 // layout mode. Use the printer as formatting device
267 // as a fall-back.
268 DBG_ASSERT(false, "DrawDocShell::UpdateRefDevice(): Unexpected printer layout mode");
270 pRefDevice = mpPrinter;
271 break;
273 mpDoc->SetRefDevice( pRefDevice );
275 ::sd::Outliner* pOutl = mpDoc->GetOutliner( FALSE );
277 if( pOutl )
278 pOutl->SetRefDevice( pRefDevice );
280 ::sd::Outliner* pInternalOutl = mpDoc->GetInternalOutliner( FALSE );
282 if( pInternalOutl )
283 pInternalOutl->SetRefDevice( pRefDevice );
287 /*************************************************************************
289 |* InitNew, (Dokument wird neu erzeugt): Streams oeffnen
291 \************************************************************************/
293 BOOL DrawDocShell::InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
295 BOOL bRet = FALSE;
297 bRet = SfxObjectShell::InitNew( xStorage );
299 Rectangle aVisArea( Point(0, 0), Size(14100, 10000) );
300 SetVisArea(aVisArea);
302 if (bRet)
304 if( !mbSdDataObj )
305 mpDoc->NewOrLoadCompleted(NEW_DOC); // otherwise calling
306 // NewOrLoadCompleted(NEW_LOADED) in
307 // SdDrawDocument::AllocModel()
309 return bRet;
312 /*************************************************************************
314 |* Load: Pools und Dokument laden
316 \************************************************************************/
318 sal_Bool DrawDocShell::IsNewDocument() const
320 return( mbNewDocument &&
321 ( !GetMedium() || GetMedium()->GetURLObject().GetProtocol() == INET_PROT_NOT_VALID ) );
324 /*************************************************************************
326 |* Load: Pools und Dokument laden
328 \************************************************************************/
330 BOOL DrawDocShell::Load( SfxMedium& rMedium )
332 mbNewDocument = sal_False;
334 BOOL bRet = FALSE;
335 bool bStartPresentation = false;
336 ErrCode nError = ERRCODE_NONE;
338 SfxItemSet* pSet = rMedium.GetItemSet();
341 if( pSet )
343 if( ( SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
345 mpDoc->SetStarDrawPreviewMode( TRUE );
348 if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
349 ( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
351 bStartPresentation = true;
352 mpDoc->SetStartWithPresentation( true );
356 bRet = SfxObjectShell::Load( rMedium );
357 if( bRet )
359 bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
362 if( bRet )
364 UpdateTablePointers();
366 // #108451# If we're an embedded OLE object, use tight bounds
367 // for our visArea. No point in showing the user lots of empty
368 // space. Had to remove the check for empty VisArea below,
369 // since XML load always sets a VisArea before.
370 //TODO/LATER: looks a little bit strange!
371 if( ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) && SfxObjectShell::GetVisArea( ASPECT_CONTENT ).IsEmpty() )
373 SdPage* pPage = mpDoc->GetSdPage( 0, PK_STANDARD );
375 if( pPage )
376 SetVisArea( Rectangle( pPage->GetAllObjBoundRect() ) );
379 FinishedLoading( SFX_LOADED_ALL );
381 const INetURLObject aUrl;
382 SfxObjectShell::SetAutoLoad( aUrl, 0, sal_False );
384 else
386 if( nError == ERRCODE_IO_BROKENPACKAGE )
387 SetError( ERRCODE_IO_BROKENPACKAGE, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
389 // TODO/LATER: correct error handling?!
390 //pStore->SetError( SVSTREAM_WRONGVERSION, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
391 else
392 SetError( ERRCODE_ABORT, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
395 // tell SFX to change viewshell when in preview mode
396 if( IsPreview() || bStartPresentation )
398 SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
399 if( pMediumSet )
400 pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
403 return bRet;
406 /*************************************************************************
408 |* LoadFrom: Inhalte fuer Organizer laden
410 \************************************************************************/
412 BOOL DrawDocShell::LoadFrom( SfxMedium& rMedium )
414 mbNewDocument = sal_False;
416 WaitObject* pWait = NULL;
417 if( mpViewShell )
418 pWait = new WaitObject( (Window*) mpViewShell->GetActiveWindow() );
420 BOOL bRet = FALSE;
423 // #90691# return to old behaviour (before #80365#): construct own medium
424 SfxMedium aMedium(xStorage);
426 // #90691# for having a progress bar nonetheless for XML copy it
427 // from the local DocShell medium (GetMedium()) to the constructed one
428 SfxMedium* pLocalMedium = GetMedium();
429 if(pLocalMedium)
431 SfxItemSet* pLocalItemSet = pLocalMedium->GetItemSet();
432 SfxItemSet* pDestItemSet = aMedium.GetItemSet();
434 if(pLocalItemSet && pDestItemSet)
436 const SfxUnoAnyItem* pItem = static_cast<
437 const SfxUnoAnyItem*>(
438 pLocalItemSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL));
440 if(pItem)
442 pDestItemSet->Put(*pItem);
445 } */
447 mpDoc->NewOrLoadCompleted( NEW_DOC );
448 mpDoc->CreateFirstPages();
449 mpDoc->StopWorkStartupDelay();
451 // TODO/LATER: nobody is interested in the error code?!
452 ErrCode nError = ERRCODE_NONE;
453 bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Organizer, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
456 // tell SFX to change viewshell when in preview mode
457 if( IsPreview() )
459 SfxItemSet *pSet = GetMedium()->GetItemSet();
461 if( pSet )
462 pSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
465 delete pWait;
467 return bRet;
470 /*************************************************************************
472 |* ImportFrom: load from 3rd party format
474 \************************************************************************/
476 sal_Bool DrawDocShell::ImportFrom( SfxMedium &rMedium )
478 const sal_Bool bRet=SfxObjectShell::ImportFrom(rMedium);
480 SfxItemSet* pSet = rMedium.GetItemSet();
481 if( pSet )
483 if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
484 ( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
486 mpDoc->SetStartWithPresentation( true );
488 // tell SFX to change viewshell when in preview mode
489 if( IsPreview() )
491 SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
492 if( pMediumSet )
493 pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, 1 ) );
498 return bRet;
501 /*************************************************************************
503 |* ConvertFrom: aus Fremdformat laden
505 \************************************************************************/
507 BOOL DrawDocShell::ConvertFrom( SfxMedium& rMedium )
509 mbNewDocument = sal_False;
511 const String aFilterName( rMedium.GetFilter()->GetFilterName() );
512 BOOL bRet = FALSE;
513 bool bStartPresentation = false;
515 SetWaitCursor( TRUE );
517 SfxItemSet* pSet = rMedium.GetItemSet();
518 if( pSet )
520 if( ( SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
522 mpDoc->SetStarDrawPreviewMode( TRUE );
525 if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
526 ( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
528 bStartPresentation = true;
529 mpDoc->SetStartWithPresentation( true );
533 if( aFilterName == pFilterPowerPoint97
534 || aFilterName == pFilterPowerPoint97Template
535 || aFilterName == pFilterPowerPoint97AutoPlay)
537 mpDoc->StopWorkStartupDelay();
538 bRet = SdPPTFilter( rMedium, *this, sal_True ).Import();
540 else if (aFilterName.SearchAscii("impress8" ) != STRING_NOTFOUND ||
541 aFilterName.SearchAscii("draw8") != STRING_NOTFOUND )
543 // TODO/LATER: nobody is interested in the error code?!
544 mpDoc->CreateFirstPages();
545 mpDoc->StopWorkStartupDelay();
546 ErrCode nError = ERRCODE_NONE;
547 bRet = SdXMLFilter( rMedium, *this, sal_True ).Import( nError );
550 else if (aFilterName.SearchAscii("StarOffice XML (Draw)" ) != STRING_NOTFOUND || aFilterName.SearchAscii("StarOffice XML (Impress)") != STRING_NOTFOUND )
552 // TODO/LATER: nobody is interested in the error code?!
553 mpDoc->CreateFirstPages();
554 mpDoc->StopWorkStartupDelay();
555 ErrCode nError = ERRCODE_NONE;
556 bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 ).Import( nError );
558 else if( aFilterName.EqualsAscii( "CGM - Computer Graphics Metafile" ) )
560 mpDoc->CreateFirstPages();
561 mpDoc->StopWorkStartupDelay();
562 bRet = SdCGMFilter( rMedium, *this, sal_True ).Import();
564 else
566 mpDoc->CreateFirstPages();
567 mpDoc->StopWorkStartupDelay();
568 bRet = SdGRFFilter( rMedium, *this ).Import();
571 FinishedLoading( SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES );
573 // tell SFX to change viewshell when in preview mode
574 if( IsPreview() )
576 SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
578 if( pMediumSet )
579 pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
581 SetWaitCursor( FALSE );
583 // tell SFX to change viewshell when in preview mode
584 if( IsPreview() || bStartPresentation )
586 SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
587 if( pMediumSet )
588 pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
591 return bRet;
594 /*************************************************************************
596 |* Save: Pools und Dokument in die offenen Streams schreiben
598 \************************************************************************/
600 BOOL DrawDocShell::Save()
602 mpDoc->StopWorkStartupDelay();
604 //TODO/LATER: why this?!
605 if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
606 SfxObjectShell::SetVisArea( Rectangle() );
608 BOOL bRet = SfxObjectShell::Save();
610 if( bRet )
612 // #86834# Call UpdateDocInfoForSave() before export
613 UpdateDocInfoForSave();
615 bRet = SdXMLFilter( *GetMedium(), *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( GetMedium()->GetStorage() ) ).Export();
618 return bRet;
621 /*************************************************************************
623 |* SaveAs: Pools und Dokument in den angegebenen Storage sichern
625 \************************************************************************/
627 BOOL DrawDocShell::SaveAs( SfxMedium& rMedium )
629 mpDoc->StopWorkStartupDelay();
631 //TODO/LATER: why this?!
632 if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
633 SfxObjectShell::SetVisArea( Rectangle() );
635 UINT32 nVBWarning = ERRCODE_NONE;
636 BOOL bRet = SfxObjectShell::SaveAs( rMedium );
638 if( bRet )
640 // #86834# Call UpdateDocInfoForSave() before export
641 UpdateDocInfoForSave();
642 bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Export();
645 if( GetError() == ERRCODE_NONE )
646 SetError( nVBWarning, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
648 return bRet;
651 /*************************************************************************
653 |* ConvertTo: im Fremdformat speichern
655 \************************************************************************/
657 BOOL DrawDocShell::ConvertTo( SfxMedium& rMedium )
659 BOOL bRet = FALSE;
661 if( mpDoc->GetPageCount() )
663 const SfxFilter* pMediumFilter = rMedium.GetFilter();
664 const String aTypeName( pMediumFilter->GetTypeName() );
665 SdFilter* pFilter = NULL;
667 if( aTypeName.SearchAscii( "graphic_HTML" ) != STRING_NOTFOUND )
669 pFilter = new SdHTMLFilter( rMedium, *this, sal_True );
671 else if( aTypeName.SearchAscii( "MS_PowerPoint_97" ) != STRING_NOTFOUND )
673 pFilter = new SdPPTFilter( rMedium, *this, sal_True );
674 ((SdPPTFilter*)pFilter)->PreSaveBasic();
676 else if ( aTypeName.SearchAscii( "CGM_Computer_Graphics_Metafile" ) != STRING_NOTFOUND )
678 pFilter = new SdCGMFilter( rMedium, *this, sal_True );
680 else if( ( aTypeName.SearchAscii( "draw8" ) != STRING_NOTFOUND ) ||
681 ( aTypeName.SearchAscii( "impress8" ) != STRING_NOTFOUND ) )
683 pFilter = new SdXMLFilter( rMedium, *this, sal_True );
684 UpdateDocInfoForSave();
686 else if( ( aTypeName.SearchAscii( "StarOffice_XML_Impress" ) != STRING_NOTFOUND ) ||
687 ( aTypeName.SearchAscii( "StarOffice_XML_Draw" ) != STRING_NOTFOUND ) )
689 pFilter = new SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 );
690 UpdateDocInfoForSave();
692 else
694 pFilter = new SdGRFFilter( rMedium, *this );
697 if( pFilter )
699 const ULONG nOldSwapMode = mpDoc->GetSwapGraphicsMode();
701 mpDoc->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
703 bRet = pFilter->Export();
704 if( !bRet )
705 mpDoc->SetSwapGraphicsMode( nOldSwapMode );
707 delete pFilter;
711 return bRet;
714 /*************************************************************************
716 |* SaveCompleted: die eigenen Streams wieder oeffnen, damit kein anderer
717 |* sie "besetzt"
719 \************************************************************************/
721 BOOL DrawDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
723 BOOL bRet = FALSE;
725 if( SfxObjectShell::SaveCompleted(xStorage) )
727 mpDoc->NbcSetChanged( FALSE );
729 if( mpViewShell )
731 if( mpViewShell->ISA( OutlineViewShell ) )
732 static_cast<OutlineView*>(mpViewShell->GetView())
733 ->GetOutliner()->ClearModifyFlag();
735 SdrOutliner* pOutl = mpViewShell->GetView()->GetTextEditOutliner();
736 if( pOutl )
738 SdrObject* pObj = mpViewShell->GetView()->GetTextEditObject();
739 if( pObj )
740 pObj->NbcSetOutlinerParaObject( pOutl->CreateParaObject() );
742 pOutl->ClearModifyFlag();
746 bRet = TRUE;
748 SfxViewFrame* pFrame = ( mpViewShell && mpViewShell->GetViewFrame() ) ?
749 mpViewShell->GetViewFrame() :
750 SfxViewFrame::Current();
752 if( pFrame )
753 pFrame->GetBindings().Invalidate( SID_NAVIGATOR_STATE, TRUE, FALSE );
755 return bRet;
758 /*************************************************************************
760 |* Referenz auf Dokument
762 \************************************************************************/
764 SdDrawDocument* DrawDocShell::GetDoc()
766 return mpDoc;
769 /*************************************************************************
771 |* Referenz auf Dokument
773 \************************************************************************/
775 SfxStyleSheetBasePool* DrawDocShell::GetStyleSheetPool()
777 return( (SfxStyleSheetBasePool*) mpDoc->GetStyleSheetPool() );
780 /*************************************************************************
782 |* Sprung zu Bookmark
784 \************************************************************************/
786 BOOL DrawDocShell::GotoBookmark(const String& rBookmark)
788 BOOL bFound = FALSE;
790 if (mpViewShell && mpViewShell->ISA(DrawViewShell))
792 DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(mpViewShell);
793 ViewShellBase& rBase (mpViewShell->GetViewShellBase());
795 BOOL bIsMasterPage = sal_False;
796 USHORT nPageNumber = SDRPAGE_NOTFOUND;
797 SdrObject* pObj = NULL;
799 rtl::OUString sBookmark( rBookmark );
800 const rtl::OUString sInteraction( RTL_CONSTASCII_USTRINGPARAM( "action?" ) );
801 if ( sBookmark.match( sInteraction ) )
803 const rtl::OUString sJump( RTL_CONSTASCII_USTRINGPARAM( "jump=" ) );
804 if ( sBookmark.match( sJump, sInteraction.getLength() ) )
806 rtl::OUString aDestination( sBookmark.copy( sInteraction.getLength() + sJump.getLength() ) );
807 if ( aDestination.match( String( RTL_CONSTASCII_USTRINGPARAM( "firstslide" ) ) ) )
809 nPageNumber = 1;
811 else if ( aDestination.match( String( RTL_CONSTASCII_USTRINGPARAM( "lastslide" ) ) ) )
813 nPageNumber = mpDoc->GetPageCount() - 2;
815 else if ( aDestination.match( String( RTL_CONSTASCII_USTRINGPARAM( "previousslide" ) ) ) )
817 SdPage* pPage = pDrawViewShell->GetActualPage();
818 nPageNumber = pPage->GetPageNum();
819 nPageNumber = nPageNumber > 2 ? nPageNumber - 2 : SDRPAGE_NOTFOUND;
821 else if ( aDestination.match( String( RTL_CONSTASCII_USTRINGPARAM( "nextslide" ) ) ) )
823 SdPage* pPage = pDrawViewShell->GetActualPage();
824 nPageNumber = pPage->GetPageNum() + 2;
825 if ( nPageNumber >= mpDoc->GetPageCount() )
826 nPageNumber = SDRPAGE_NOTFOUND;
830 else
832 String aBookmark( rBookmark );
834 // Ist das Bookmark eine Seite?
835 nPageNumber = mpDoc->GetPageByName( aBookmark, bIsMasterPage );
837 if (nPageNumber == SDRPAGE_NOTFOUND)
839 // Ist das Bookmark ein Objekt?
840 pObj = mpDoc->GetObj(aBookmark);
842 if (pObj)
844 nPageNumber = pObj->GetPage()->GetPageNum();
848 if (nPageNumber != SDRPAGE_NOTFOUND)
850 // Jump to the bookmarked page. This is done in three steps.
852 bFound = TRUE;
853 SdPage* pPage;
854 if (bIsMasterPage)
855 pPage = (SdPage*) mpDoc->GetMasterPage(nPageNumber);
856 else
857 pPage = (SdPage*) mpDoc->GetPage(nPageNumber);
859 // 1.) Change the view shell to the edit view, the notes view,
860 // or the handout view.
861 PageKind eNewPageKind = pPage->GetPageKind();
863 if( (eNewPageKind != PK_STANDARD) && (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
864 return FALSE;
866 if (eNewPageKind != pDrawViewShell->GetPageKind())
868 // Arbeitsbereich wechseln
869 GetFrameView()->SetPageKind(eNewPageKind);
870 ::rtl::OUString sViewURL;
871 switch (eNewPageKind)
873 case PK_STANDARD:
874 sViewURL = FrameworkHelper::msImpressViewURL;
875 break;
876 case PK_NOTES:
877 sViewURL = FrameworkHelper::msNotesViewURL;
878 break;
879 case PK_HANDOUT:
880 sViewURL = FrameworkHelper::msHandoutViewURL;
881 break;
882 default:
883 break;
885 if (sViewURL.getLength() > 0)
887 ::boost::shared_ptr<FrameworkHelper> pHelper (
888 FrameworkHelper::Instance(rBase));
889 pHelper->RequestView(
890 sViewURL,
891 FrameworkHelper::msCenterPaneURL);
892 pHelper->WaitForUpdate();
894 // Get the new DrawViewShell.
895 mpViewShell = pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
896 pDrawViewShell = dynamic_cast<sd::DrawViewShell*>(mpViewShell);
898 else
900 pDrawViewShell = NULL;
904 if (pDrawViewShell != NULL)
906 // Set the edit mode to either the normal edit mode or the
907 // master page mode.
908 EditMode eNewEditMode = EM_PAGE;
909 if (bIsMasterPage)
911 eNewEditMode = EM_MASTERPAGE;
914 if (eNewEditMode != pDrawViewShell->GetEditMode())
916 // EditMode setzen
917 pDrawViewShell->ChangeEditMode(eNewEditMode, FALSE);
920 // Make the bookmarked page the current page. This is done
921 // by using the API because this takes care of all the
922 // little things to be done. Especially writing the view
923 // data to the frame view (see bug #107803#).
924 USHORT nSdPgNum = (nPageNumber - 1) / 2;
925 Reference<drawing::XDrawView> xController (rBase.GetController(), UNO_QUERY);
926 if (xController.is())
928 Reference<drawing::XDrawPage> xDrawPage (pPage->getUnoPage(), UNO_QUERY);
929 xController->setCurrentPage (xDrawPage);
931 else
933 // As a fall back switch to the page via the core.
934 DBG_ASSERT (xController.is(),
935 "DrawDocShell::GotoBookmark: can't switch page via API");
936 pDrawViewShell->SwitchPage(nSdPgNum);
939 if (pObj != NULL)
941 // Objekt einblenden und selektieren
942 pDrawViewShell->MakeVisible(pObj->GetLogicRect(),
943 *pDrawViewShell->GetActiveWindow());
944 pDrawViewShell->GetView()->UnmarkAll();
945 pDrawViewShell->GetView()->MarkObj(
946 pObj,
947 pDrawViewShell->GetView()->GetSdrPageView(), FALSE);
952 SfxBindings& rBindings = (pDrawViewShell->GetViewFrame()!=NULL
953 ? pDrawViewShell->GetViewFrame()
954 : SfxViewFrame::Current() )->GetBindings();
956 rBindings.Invalidate(SID_NAVIGATOR_STATE, TRUE, FALSE);
957 rBindings.Invalidate(SID_NAVIGATOR_PAGENAME);
960 return (bFound);
963 /*************************************************************************
965 |* SaveAsOwnFormat: wenn es eine Dokumentvorlage werden soll,
967 \************************************************************************/
968 #include <tools/urlobj.hxx>
970 BOOL DrawDocShell::SaveAsOwnFormat( SfxMedium& rMedium )
973 const SfxFilter* pFilter = rMedium.GetFilter();
975 if (pFilter->IsOwnTemplateFormat())
977 // jetzt die StarDraw-Spezialitaeten:
978 // die Layoutvorlagen der ersten Seite werden mit dem jetzt
979 // bekannten Layoutnamen versehen, die Layoutnamen der betroffenen
980 // Masterpages und Seiten werden gesetzt;
981 // alle Textobjekte der betroffenen Standard-, Notiz- und
982 // Masterpages werden ueber die Namensaenderung informiert
984 String aLayoutName;
986 SfxStringItem* pLayoutItem;
987 if( rMedium.GetItemSet()->GetItemState(SID_TEMPLATE_NAME, FALSE, (const SfxPoolItem**) & pLayoutItem ) == SFX_ITEM_SET )
989 aLayoutName = pLayoutItem->GetValue();
991 else
993 INetURLObject aURL( rMedium.GetName() );
994 aURL.removeExtension();
995 aLayoutName = aURL.getName();
998 if( aLayoutName.Len() )
1000 String aOldPageLayoutName = mpDoc->GetSdPage(0, PK_STANDARD)->GetLayoutName();
1001 mpDoc->RenameLayoutTemplate(aOldPageLayoutName, aLayoutName);
1005 return SfxObjectShell::SaveAsOwnFormat(rMedium);
1008 /*************************************************************************
1010 |* FillClass
1012 \************************************************************************/
1014 void DrawDocShell::FillClass(SvGlobalName* pClassName,
1015 sal_uInt32* pFormat,
1016 String* ,
1017 String* pFullTypeName,
1018 String* pShortTypeName,
1019 sal_Int32 nFileFormat,
1020 sal_Bool bTemplate /* = sal_False */) const
1022 if (nFileFormat == SOFFICE_FILEFORMAT_60)
1024 if ( meDocType == DOCUMENT_TYPE_DRAW )
1026 *pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
1027 *pFormat = SOT_FORMATSTR_ID_STARDRAW_60;
1028 *pFullTypeName = String(SdResId(STR_GRAPHIC_DOCUMENT_FULLTYPE_60));
1030 else
1032 *pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
1033 *pFormat = SOT_FORMATSTR_ID_STARIMPRESS_60;
1034 *pFullTypeName = String(SdResId(STR_IMPRESS_DOCUMENT_FULLTYPE_60));
1037 else if (nFileFormat == SOFFICE_FILEFORMAT_8)
1039 if ( meDocType == DOCUMENT_TYPE_DRAW )
1041 *pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
1042 *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARDRAW_8_TEMPLATE : SOT_FORMATSTR_ID_STARDRAW_8;
1043 *pFullTypeName = String(RTL_CONSTASCII_USTRINGPARAM("Draw 8")); // HACK: method will be removed with new storage API
1045 else
1047 *pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
1048 *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARIMPRESS_8_TEMPLATE : SOT_FORMATSTR_ID_STARIMPRESS_8;
1049 *pFullTypeName = String(RTL_CONSTASCII_USTRINGPARAM("Impress 8")); // HACK: method will be removed with new storage API
1053 *pShortTypeName = String(SdResId( (meDocType == DOCUMENT_TYPE_DRAW) ?
1054 STR_GRAPHIC_DOCUMENT : STR_IMPRESS_DOCUMENT ));
1057 OutputDevice* DrawDocShell::GetDocumentRefDev (void)
1059 OutputDevice* pReferenceDevice = SfxObjectShell::GetDocumentRefDev ();
1060 // Only when our parent does not have a reference device then we return
1061 // our own.
1062 if (pReferenceDevice == NULL && mpDoc != NULL)
1063 pReferenceDevice = mpDoc->GetRefDevice ();
1064 return pReferenceDevice;
1067 /** executes the SID_OPENDOC slot to let the framework open a document
1068 with the given URL and this document as a referer */
1069 void DrawDocShell::OpenBookmark( const String& rBookmarkURL )
1071 SfxStringItem aStrItem( SID_FILE_NAME, rBookmarkURL );
1072 SfxStringItem aReferer( SID_REFERER, GetMedium()->GetName() );
1073 const SfxPoolItem* ppArgs[] = { &aStrItem, &aReferer, 0 };
1074 ( mpViewShell ? mpViewShell->GetViewFrame() : SfxViewFrame::Current() )->GetBindings().Execute( SID_OPENHYPERLINK, ppArgs );
1077 } // end of namespace sd