bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / docshell / docshel4.cxx
blob9c998a33a4d78e982e242aad5396df5cf2960e5a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "DrawDocShell.hxx"
22 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
23 #include <tools/urlobj.hxx>
24 #include <sfx2/progress.hxx>
25 #include <vcl/waitobj.hxx>
26 #include <svx/svxids.hrc>
27 #include <editeng/flstitem.hxx>
28 #include <editeng/eeitem.hxx>
29 #include <svl/aeitem.hxx>
30 #include <svl/flagitem.hxx>
31 #include <sot/storage.hxx>
32 #include <sfx2/dinfdlg.hxx>
33 #include <sfx2/docfile.hxx>
34 #include <sfx2/docfilt.hxx>
35 #include <sfx2/dispatch.hxx>
36 #include <svx/svdotext.hxx>
37 #include <svl/style.hxx>
38 #include <sfx2/printer.hxx>
39 #include <svtools/ctrltool.hxx>
40 #include <svtools/sfxecode.hxx>
41 #include <comphelper/classids.hxx>
42 #include <sot/formats.hxx>
43 #include <sfx2/request.hxx>
44 #include <unotools/fltrcfg.hxx>
45 #include <sfx2/frame.hxx>
46 #include <sfx2/viewfrm.hxx>
47 #include <unotools/saveopt.hxx>
48 #include <com/sun/star/drawing/XDrawPage.hpp>
49 #include <com/sun/star/drawing/XDrawView.hpp>
50 #include <comphelper/processfactory.hxx>
52 #include "app.hrc"
53 #include "glob.hrc"
54 #include "strings.hrc"
55 #include "strmname.h"
56 #include "FrameView.hxx"
57 #include "optsitem.hxx"
58 #include "Outliner.hxx"
59 #include "sdattr.hxx"
60 #include "drawdoc.hxx"
61 #include "ViewShell.hxx"
62 #include "sdmod.hxx"
63 #include "View.hxx"
64 #include "sdpage.hxx"
65 #include "sdresid.hxx"
66 #include "DrawViewShell.hxx"
67 #include "ViewShellBase.hxx"
68 #include "Window.hxx"
69 #include "sdmod.hxx"
70 #include "OutlineViewShell.hxx"
71 #include "sdxmlwrp.hxx"
72 #include "sdpptwrp.hxx"
73 #include "sdcgmfilter.hxx"
74 #include "sdgrffilter.hxx"
75 #include "sdhtmlfilter.hxx"
76 #include "framework/FrameworkHelper.hxx"
78 using namespace ::com::sun::star;
79 using namespace ::com::sun::star::uno;
80 using ::sd::framework::FrameworkHelper;
83 namespace sd {
85 /**
86 * Creates (if necessary) and returns a SfxPrinter
88 SfxPrinter* DrawDocShell::GetPrinter(sal_Bool bCreate)
90 if (bCreate && !mpPrinter)
92 // create ItemSet with special pool area
93 SfxItemSet* pSet = new SfxItemSet( GetPool(),
94 SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
95 SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
96 ATTR_OPTIONS_PRINT, ATTR_OPTIONS_PRINT,
97 0 );
98 // set PrintOptionsSet
99 SdOptionsPrintItem aPrintItem( ATTR_OPTIONS_PRINT,
100 SD_MOD()->GetSdOptions(mpDoc->GetDocumentType()));
101 SfxFlagItem aFlagItem( SID_PRINTER_CHANGESTODOC );
102 sal_uInt16 nFlags = 0;
104 nFlags = (aPrintItem.GetOptionsPrint().IsWarningSize() ? SFX_PRINTER_CHG_SIZE : 0) |
105 (aPrintItem.GetOptionsPrint().IsWarningOrientation() ? SFX_PRINTER_CHG_ORIENTATION : 0);
106 aFlagItem.SetValue( nFlags );
108 pSet->Put( aPrintItem );
109 pSet->Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, aPrintItem.GetOptionsPrint().IsWarningPrinter() ) );
110 pSet->Put( aFlagItem );
112 mpPrinter = new SfxPrinter(pSet);
113 mbOwnPrinter = sal_True;
115 // set output quality
116 sal_uInt16 nQuality = aPrintItem.GetOptionsPrint().GetOutputQuality();
118 sal_uLong nMode = DRAWMODE_DEFAULT;
120 if( nQuality == 1 )
121 nMode = DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT;
122 else if( nQuality == 2 )
123 nMode = DRAWMODE_BLACKLINE | DRAWMODE_WHITEFILL | DRAWMODE_BLACKTEXT | DRAWMODE_WHITEBITMAP | DRAWMODE_WHITEGRADIENT;
125 mpPrinter->SetDrawMode( nMode );
127 MapMode aMM (mpPrinter->GetMapMode());
128 aMM.SetMapUnit(MAP_100TH_MM);
129 mpPrinter->SetMapMode(aMM);
130 UpdateRefDevice();
132 return mpPrinter;
136 * Set new SfxPrinter (transfer of ownership)
138 void DrawDocShell::SetPrinter(SfxPrinter *pNewPrinter)
140 if ( mpViewShell )
142 ::sd::View* pView = mpViewShell->GetView();
143 if ( pView->IsTextEdit() )
144 pView->SdrEndTextEdit();
147 if ( mpPrinter && mbOwnPrinter && (mpPrinter != pNewPrinter) )
149 delete mpPrinter;
152 mpPrinter = pNewPrinter;
153 mbOwnPrinter = sal_True;
154 if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
155 UpdateFontList();
156 UpdateRefDevice();
159 void DrawDocShell::UpdateFontList()
161 delete mpFontList;
162 OutputDevice* pRefDevice = NULL;
163 if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
164 pRefDevice = GetPrinter(sal_True);
165 else
166 pRefDevice = SD_MOD()->GetVirtualRefDevice();
167 mpFontList = new FontList( pRefDevice, NULL, sal_False );
168 SvxFontListItem aFontListItem( mpFontList, SID_ATTR_CHAR_FONTLIST );
169 PutItem( aFontListItem );
172 Printer* DrawDocShell::GetDocumentPrinter()
174 return GetPrinter(sal_False);
177 void DrawDocShell::OnDocumentPrinterChanged(Printer* pNewPrinter)
179 // if we already have a printer, see if its the same
180 if( mpPrinter )
182 // easy case
183 if( mpPrinter == pNewPrinter )
184 return;
186 // compare if its the same printer with the same job setup
187 if( (mpPrinter->GetName() == pNewPrinter->GetName()) &&
188 (mpPrinter->GetJobSetup() == pNewPrinter->GetJobSetup()))
189 return;
192 // if (mpPrinter->IsA(SfxPrinter))
194 // Since we do not have RTTI we use a hard cast (...)
195 SetPrinter((SfxPrinter*) pNewPrinter);
197 // container owns printer
198 mbOwnPrinter = sal_False;
202 void DrawDocShell::UpdateRefDevice()
204 if( mpDoc )
206 // Determine the device for which the output will be formatted.
207 OutputDevice* pRefDevice = NULL;
208 switch (mpDoc->GetPrinterIndependentLayout())
210 case ::com::sun::star::document::PrinterIndependentLayout::DISABLED:
211 pRefDevice = mpPrinter;
212 break;
214 case ::com::sun::star::document::PrinterIndependentLayout::ENABLED:
215 pRefDevice = SD_MOD()->GetVirtualRefDevice();
216 break;
218 default:
219 // We are confronted with an invalid or un-implemented
220 // layout mode. Use the printer as formatting device
221 // as a fall-back.
222 DBG_ASSERT(false, "DrawDocShell::UpdateRefDevice(): Unexpected printer layout mode");
224 pRefDevice = mpPrinter;
225 break;
227 mpDoc->SetRefDevice( pRefDevice );
229 ::sd::Outliner* pOutl = mpDoc->GetOutliner( sal_False );
231 if( pOutl )
232 pOutl->SetRefDevice( pRefDevice );
234 ::sd::Outliner* pInternalOutl = mpDoc->GetInternalOutliner( sal_False );
236 if( pInternalOutl )
237 pInternalOutl->SetRefDevice( pRefDevice );
242 * Creates new document, opens streams
244 sal_Bool DrawDocShell::InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
246 sal_Bool bRet = sal_False;
248 bRet = SfxObjectShell::InitNew( xStorage );
250 Rectangle aVisArea( Point(0, 0), Size(14100, 10000) );
251 SetVisArea(aVisArea);
253 if (bRet)
255 mpDoc->SetDrawingLayerPoolDefaults();
256 if( !mbSdDataObj )
257 mpDoc->NewOrLoadCompleted(NEW_DOC); // otherwise calling
258 // NewOrLoadCompleted(NEW_LOADED) in
259 // SdDrawDocument::AllocModel()
261 return bRet;
265 * loads pools and document
267 sal_Bool DrawDocShell::Load( SfxMedium& rMedium )
269 mbNewDocument = sal_False;
271 sal_Bool bRet = sal_False;
272 bool bStartPresentation = false;
273 ErrCode nError = ERRCODE_NONE;
275 SfxItemSet* pSet = rMedium.GetItemSet();
278 if( pSet )
280 if( ( SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
282 mpDoc->SetStarDrawPreviewMode( sal_True );
285 if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
286 ( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
288 bStartPresentation = true;
289 mpDoc->SetStartWithPresentation( true );
293 bRet = SfxObjectShell::Load( rMedium );
294 if( bRet )
296 bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
299 if( bRet )
301 UpdateTablePointers();
303 // If we're an embedded OLE object, use tight bounds
304 // for our visArea. No point in showing the user lots of empty
305 // space. Had to remove the check for empty VisArea below,
306 // since XML load always sets a VisArea before.
307 //TODO/LATER: looks a little bit strange!
308 if( ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) && SfxObjectShell::GetVisArea( ASPECT_CONTENT ).IsEmpty() )
310 SdPage* pPage = mpDoc->GetSdPage( 0, PK_STANDARD );
312 if( pPage )
313 SetVisArea( Rectangle( pPage->GetAllObjBoundRect() ) );
316 FinishedLoading( SFX_LOADED_ALL );
318 const INetURLObject aUrl;
319 SfxObjectShell::SetAutoLoad( aUrl, 0, sal_False );
321 else
323 if( nError == ERRCODE_IO_BROKENPACKAGE )
324 SetError( ERRCODE_IO_BROKENPACKAGE, OSL_LOG_PREFIX );
326 // TODO/LATER: correct error handling?!
327 //pStore->SetError( SVSTREAM_WRONGVERSION, OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
328 else
329 SetError( ERRCODE_ABORT, OSL_LOG_PREFIX );
332 // tell SFX to change viewshell when in preview mode
333 if( IsPreview() || bStartPresentation )
335 SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
336 if( pMediumSet )
337 pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
340 return bRet;
344 * loads content for organizer
346 sal_Bool DrawDocShell::LoadFrom( SfxMedium& rMedium )
348 mbNewDocument = sal_False;
350 WaitObject* pWait = NULL;
351 if( mpViewShell )
352 pWait = new WaitObject( (Window*) mpViewShell->GetActiveWindow() );
354 sal_Bool bRet = sal_False;
356 mpDoc->NewOrLoadCompleted( NEW_DOC );
357 mpDoc->CreateFirstPages();
358 mpDoc->StopWorkStartupDelay();
360 // TODO/LATER: nobody is interested in the error code?!
361 ErrCode nError = ERRCODE_NONE;
362 bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Organizer, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
365 // tell SFX to change viewshell when in preview mode
366 if( IsPreview() )
368 SfxItemSet *pSet = GetMedium()->GetItemSet();
370 if( pSet )
371 pSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
374 delete pWait;
376 return bRet;
380 * load from 3rd party format
382 sal_Bool DrawDocShell::ImportFrom( SfxMedium &rMedium, bool bInsert )
384 const sal_Bool bRet=SfxObjectShell::ImportFrom(rMedium, bInsert);
386 SfxItemSet* pSet = rMedium.GetItemSet();
387 if( pSet )
389 if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
390 ( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
392 mpDoc->SetStartWithPresentation( true );
394 // tell SFX to change viewshell when in preview mode
395 if( IsPreview() )
397 SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
398 if( pMediumSet )
399 pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, 1 ) );
404 return bRet;
408 * load from a foreign format
410 sal_Bool DrawDocShell::ConvertFrom( SfxMedium& rMedium )
412 mbNewDocument = sal_False;
414 const OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
415 sal_Bool bRet = sal_False;
416 bool bStartPresentation = false;
418 SetWaitCursor( sal_True );
420 SfxItemSet* pSet = rMedium.GetItemSet();
421 if( pSet )
423 if( ( SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
425 mpDoc->SetStarDrawPreviewMode( sal_True );
428 if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
429 ( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
431 bStartPresentation = true;
432 mpDoc->SetStartWithPresentation( true );
436 if( aFilterName == pFilterPowerPoint97
437 || aFilterName == pFilterPowerPoint97Template
438 || aFilterName == pFilterPowerPoint97AutoPlay)
440 mpDoc->StopWorkStartupDelay();
441 bRet = SdPPTFilter( rMedium, *this, sal_True ).Import();
443 else if (aFilterName.indexOf("impress8") >= 0 ||
444 aFilterName.indexOf("draw8") >= 0)
446 // TODO/LATER: nobody is interested in the error code?!
447 mpDoc->CreateFirstPages();
448 mpDoc->StopWorkStartupDelay();
449 ErrCode nError = ERRCODE_NONE;
450 bRet = SdXMLFilter( rMedium, *this, sal_True ).Import( nError );
453 else if (aFilterName.indexOf("StarOffice XML (Draw)") >= 0 ||
454 aFilterName.indexOf("StarOffice XML (Impress)") >= 0)
456 // TODO/LATER: nobody is interested in the error code?!
457 mpDoc->CreateFirstPages();
458 mpDoc->StopWorkStartupDelay();
459 ErrCode nError = ERRCODE_NONE;
460 bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 ).Import( nError );
462 else if( aFilterName.equals( "CGM - Computer Graphics Metafile" ) )
464 mpDoc->CreateFirstPages();
465 mpDoc->StopWorkStartupDelay();
466 bRet = SdCGMFilter( rMedium, *this, sal_True ).Import();
468 else
470 mpDoc->CreateFirstPages();
471 mpDoc->StopWorkStartupDelay();
472 bRet = SdGRFFilter( rMedium, *this ).Import();
475 FinishedLoading( SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES );
477 // tell SFX to change viewshell when in preview mode
478 if( IsPreview() )
480 SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
482 if( pMediumSet )
483 pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
485 SetWaitCursor( sal_False );
487 // tell SFX to change viewshell when in preview mode
488 if( IsPreview() || bStartPresentation )
490 SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
491 if( pMediumSet )
492 pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
495 return bRet;
499 * Writes pools and document to the open streams
501 sal_Bool DrawDocShell::Save()
503 mpDoc->StopWorkStartupDelay();
505 //TODO/LATER: why this?!
506 if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
507 SfxObjectShell::SetVisArea( Rectangle() );
509 sal_Bool bRet = SfxObjectShell::Save();
511 if( bRet )
513 // Call UpdateDocInfoForSave() before export
514 UpdateDocInfoForSave();
516 bRet = SdXMLFilter( *GetMedium(), *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( GetMedium()->GetStorage() ) ).Export();
519 return bRet;
523 * Writes pools and document to the provided storage
525 sal_Bool DrawDocShell::SaveAs( SfxMedium& rMedium )
527 mpDoc->StopWorkStartupDelay();
529 //TODO/LATER: why this?!
530 if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
531 SfxObjectShell::SetVisArea( Rectangle() );
533 sal_uInt32 nVBWarning = ERRCODE_NONE;
534 sal_Bool bRet = SfxObjectShell::SaveAs( rMedium );
536 if( bRet )
538 // Call UpdateDocInfoForSave() before export
539 UpdateDocInfoForSave();
540 bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Export();
543 if( GetError() == ERRCODE_NONE )
544 SetError( nVBWarning, OSL_LOG_PREFIX );
546 return bRet;
550 * save to foreign format
552 sal_Bool DrawDocShell::ConvertTo( SfxMedium& rMedium )
554 sal_Bool bRet = sal_False;
556 if( mpDoc->GetPageCount() )
558 const SfxFilter* pMediumFilter = rMedium.GetFilter();
559 const OUString aTypeName( pMediumFilter->GetTypeName() );
560 SdFilter* pFilter = NULL;
562 if( aTypeName.indexOf( "graphic_HTML" ) >= 0 )
564 pFilter = new SdHTMLFilter( rMedium, *this, sal_True );
566 else if( aTypeName.indexOf( "MS_PowerPoint_97" ) >= 0 )
568 pFilter = new SdPPTFilter( rMedium, *this, sal_True );
569 ((SdPPTFilter*)pFilter)->PreSaveBasic();
571 else if ( aTypeName.indexOf( "CGM_Computer_Graphics_Metafile" ) >= 0 )
573 pFilter = new SdCGMFilter( rMedium, *this, sal_True );
575 else if( aTypeName.indexOf( "draw8" ) >= 0 ||
576 aTypeName.indexOf( "impress8" ) >= 0 )
578 pFilter = new SdXMLFilter( rMedium, *this, sal_True );
579 UpdateDocInfoForSave();
581 else if( aTypeName.indexOf( "StarOffice_XML_Impress" ) >= 0 ||
582 aTypeName.indexOf( "StarOffice_XML_Draw" ) >= 0 )
584 pFilter = new SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 );
585 UpdateDocInfoForSave();
587 else
589 pFilter = new SdGRFFilter( rMedium, *this );
592 if( pFilter )
594 const sal_uLong nOldSwapMode = mpDoc->GetSwapGraphicsMode();
596 mpDoc->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
598 bRet = pFilter->Export();
599 if( !bRet )
600 mpDoc->SetSwapGraphicsMode( nOldSwapMode );
602 delete pFilter;
606 return bRet;
610 * Reopen own streams to ensure that nobody else can prevent use from opening
611 * them.
613 sal_Bool DrawDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
615 sal_Bool bRet = sal_False;
617 if( SfxObjectShell::SaveCompleted(xStorage) )
619 mpDoc->NbcSetChanged( sal_False );
621 if( mpViewShell )
623 if( mpViewShell->ISA( OutlineViewShell ) )
624 static_cast<OutlineView*>(mpViewShell->GetView())
625 ->GetOutliner()->ClearModifyFlag();
627 SdrOutliner* pOutl = mpViewShell->GetView()->GetTextEditOutliner();
628 if( pOutl )
630 SdrObject* pObj = mpViewShell->GetView()->GetTextEditObject();
631 if( pObj )
632 pObj->NbcSetOutlinerParaObject( pOutl->CreateParaObject() );
634 pOutl->ClearModifyFlag();
638 bRet = sal_True;
640 SfxViewFrame* pFrame = ( mpViewShell && mpViewShell->GetViewFrame() ) ?
641 mpViewShell->GetViewFrame() :
642 SfxViewFrame::Current();
644 if( pFrame )
645 pFrame->GetBindings().Invalidate( SID_NAVIGATOR_STATE, sal_True, sal_False );
647 return bRet;
650 SdDrawDocument* DrawDocShell::GetDoc()
652 return mpDoc;
655 SfxStyleSheetBasePool* DrawDocShell::GetStyleSheetPool()
657 return( (SfxStyleSheetBasePool*) mpDoc->GetStyleSheetPool() );
660 sal_Bool DrawDocShell::GotoBookmark(const String& rBookmark)
662 sal_Bool bFound = sal_False;
664 if (mpViewShell && mpViewShell->ISA(DrawViewShell))
666 DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(mpViewShell);
667 ViewShellBase& rBase (mpViewShell->GetViewShellBase());
669 sal_Bool bIsMasterPage = sal_False;
670 sal_uInt16 nPageNumber = SDRPAGE_NOTFOUND;
671 SdrObject* pObj = NULL;
673 OUString sBookmark( rBookmark );
674 const OUString sInteraction( "action?" );
675 if ( sBookmark.match( sInteraction ) )
677 const OUString sJump( "jump=" );
678 if ( sBookmark.match( sJump, sInteraction.getLength() ) )
680 OUString aDestination( sBookmark.copy( sInteraction.getLength() + sJump.getLength() ) );
681 if ( aDestination.match( "firstslide" ) )
683 nPageNumber = 1;
685 else if ( aDestination.match( "lastslide" ) )
687 nPageNumber = mpDoc->GetPageCount() - 2;
689 else if ( aDestination.match( "previousslide" ) )
691 SdPage* pPage = pDrawViewShell->GetActualPage();
692 nPageNumber = pPage->GetPageNum();
693 nPageNumber = nPageNumber > 2 ? nPageNumber - 2 : SDRPAGE_NOTFOUND;
695 else if ( aDestination.match( "nextslide" ) )
697 SdPage* pPage = pDrawViewShell->GetActualPage();
698 nPageNumber = pPage->GetPageNum() + 2;
699 if ( nPageNumber >= mpDoc->GetPageCount() )
700 nPageNumber = SDRPAGE_NOTFOUND;
704 else
706 String aBookmark( rBookmark );
708 // Is the bookmark a page?
709 nPageNumber = mpDoc->GetPageByName( aBookmark, bIsMasterPage );
711 if (nPageNumber == SDRPAGE_NOTFOUND)
713 // Is the bookmark a object?
714 pObj = mpDoc->GetObj(aBookmark);
716 if (pObj)
718 nPageNumber = pObj->GetPage()->GetPageNum();
722 if (nPageNumber != SDRPAGE_NOTFOUND)
724 // Jump to the bookmarked page. This is done in three steps.
726 bFound = sal_True;
727 SdPage* pPage;
728 if (bIsMasterPage)
729 pPage = (SdPage*) mpDoc->GetMasterPage(nPageNumber);
730 else
731 pPage = (SdPage*) mpDoc->GetPage(nPageNumber);
733 // 1.) Change the view shell to the edit view, the notes view,
734 // or the handout view.
735 PageKind eNewPageKind = pPage->GetPageKind();
737 if( (eNewPageKind != PK_STANDARD) && (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
738 return sal_False;
740 if (eNewPageKind != pDrawViewShell->GetPageKind())
742 // change work area
743 GetFrameView()->SetPageKind(eNewPageKind);
744 OUString sViewURL;
745 switch (eNewPageKind)
747 case PK_STANDARD:
748 sViewURL = FrameworkHelper::msImpressViewURL;
749 break;
750 case PK_NOTES:
751 sViewURL = FrameworkHelper::msNotesViewURL;
752 break;
753 case PK_HANDOUT:
754 sViewURL = FrameworkHelper::msHandoutViewURL;
755 break;
756 default:
757 break;
759 if (!sViewURL.isEmpty())
761 ::boost::shared_ptr<FrameworkHelper> pHelper (
762 FrameworkHelper::Instance(rBase));
763 pHelper->RequestView(
764 sViewURL,
765 FrameworkHelper::msCenterPaneURL);
766 pHelper->WaitForUpdate();
768 // Get the new DrawViewShell.
769 mpViewShell = pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
770 pDrawViewShell = dynamic_cast<sd::DrawViewShell*>(mpViewShell);
772 else
774 pDrawViewShell = NULL;
778 if (pDrawViewShell != NULL)
780 // Set the edit mode to either the normal edit mode or the
781 // master page mode.
782 EditMode eNewEditMode = EM_PAGE;
783 if (bIsMasterPage)
785 eNewEditMode = EM_MASTERPAGE;
788 if (eNewEditMode != pDrawViewShell->GetEditMode())
790 // EditMode setzen
791 pDrawViewShell->ChangeEditMode(eNewEditMode, sal_False);
794 // Make the bookmarked page the current page. This is done
795 // by using the API because this takes care of all the
796 // little things to be done. Especially writing the view
797 // data to the frame view.
798 sal_uInt16 nSdPgNum = (nPageNumber - 1) / 2;
799 Reference<drawing::XDrawView> xController (rBase.GetController(), UNO_QUERY);
800 if (xController.is())
802 Reference<drawing::XDrawPage> xDrawPage (pPage->getUnoPage(), UNO_QUERY);
803 xController->setCurrentPage (xDrawPage);
805 else
807 // As a fall back switch to the page via the core.
808 DBG_ASSERT (xController.is(),
809 "DrawDocShell::GotoBookmark: can't switch page via API");
810 pDrawViewShell->SwitchPage(nSdPgNum);
813 if (pObj != NULL)
815 // show and select object
816 pDrawViewShell->MakeVisible(pObj->GetLogicRect(),
817 *pDrawViewShell->GetActiveWindow());
818 pDrawViewShell->GetView()->UnmarkAll();
819 pDrawViewShell->GetView()->MarkObj(
820 pObj,
821 pDrawViewShell->GetView()->GetSdrPageView(), sal_False);
826 SfxBindings& rBindings = (pDrawViewShell->GetViewFrame()!=NULL
827 ? pDrawViewShell->GetViewFrame()
828 : SfxViewFrame::Current() )->GetBindings();
830 rBindings.Invalidate(SID_NAVIGATOR_STATE, sal_True, sal_False);
831 rBindings.Invalidate(SID_NAVIGATOR_PAGENAME);
834 return (bFound);
838 * If it should become a document template.
840 sal_Bool DrawDocShell::SaveAsOwnFormat( SfxMedium& rMedium )
843 const SfxFilter* pFilter = rMedium.GetFilter();
845 if (pFilter->IsOwnTemplateFormat())
847 /* now the StarDraw specialty:
848 we assign known layout names to the layout template of the first
849 page, we set the layout names of the affected masterpages and pages.
850 We inform all text objects of the affected standard, note and
851 masterpages about the name change.
854 String aLayoutName;
856 SfxStringItem* pLayoutItem;
857 if( rMedium.GetItemSet()->GetItemState(SID_TEMPLATE_NAME, sal_False, (const SfxPoolItem**) & pLayoutItem ) == SFX_ITEM_SET )
859 aLayoutName = pLayoutItem->GetValue();
861 else
863 INetURLObject aURL( rMedium.GetName() );
864 aURL.removeExtension();
865 aLayoutName = aURL.getName();
868 if( aLayoutName.Len() )
870 sal_uInt32 nCount = mpDoc->GetMasterSdPageCount(PK_STANDARD);
871 for (sal_uInt32 i = 0; i < nCount; ++i)
873 OUString aOldPageLayoutName = mpDoc->GetMasterSdPage(i, PK_STANDARD)->GetLayoutName();
874 OUString aNewLayoutName = aLayoutName;
875 // Don't add suffix for the first master page
876 if( i > 0 )
877 aNewLayoutName += OUString::number(i);
879 mpDoc->RenameLayoutTemplate(aOldPageLayoutName, aNewLayoutName);
884 return SfxObjectShell::SaveAsOwnFormat(rMedium);
888 void DrawDocShell::FillClass(SvGlobalName* pClassName,
889 sal_uInt32* pFormat,
890 OUString* ,
891 OUString* pFullTypeName,
892 OUString* pShortTypeName,
893 sal_Int32 nFileFormat,
894 sal_Bool bTemplate /* = sal_False */) const
896 if (nFileFormat == SOFFICE_FILEFORMAT_60)
898 if ( meDocType == DOCUMENT_TYPE_DRAW )
900 *pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
901 *pFormat = SOT_FORMATSTR_ID_STARDRAW_60;
902 *pFullTypeName = OUString(SdResId(STR_GRAPHIC_DOCUMENT_FULLTYPE_60));
904 else
906 *pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
907 *pFormat = SOT_FORMATSTR_ID_STARIMPRESS_60;
908 *pFullTypeName = OUString(SdResId(STR_IMPRESS_DOCUMENT_FULLTYPE_60));
911 else if (nFileFormat == SOFFICE_FILEFORMAT_8)
913 if ( meDocType == DOCUMENT_TYPE_DRAW )
915 *pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
916 *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARDRAW_8_TEMPLATE : SOT_FORMATSTR_ID_STARDRAW_8;
917 *pFullTypeName = "Draw 8"; // HACK: method will be removed with new storage API
919 else
921 *pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
922 *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARIMPRESS_8_TEMPLATE : SOT_FORMATSTR_ID_STARIMPRESS_8;
923 *pFullTypeName = "Impress 8"; // HACK: method will be removed with new storage API
927 *pShortTypeName = OUString(SdResId( (meDocType == DOCUMENT_TYPE_DRAW) ?
928 STR_GRAPHIC_DOCUMENT : STR_IMPRESS_DOCUMENT ));
931 OutputDevice* DrawDocShell::GetDocumentRefDev (void)
933 OutputDevice* pReferenceDevice = SfxObjectShell::GetDocumentRefDev ();
934 // Only when our parent does not have a reference device then we return
935 // our own.
936 if (pReferenceDevice == NULL && mpDoc != NULL)
937 pReferenceDevice = mpDoc->GetRefDevice ();
938 return pReferenceDevice;
941 /** executes the SID_OPENDOC slot to let the framework open a document
942 with the given URL and this document as a referer */
943 void DrawDocShell::OpenBookmark( const String& rBookmarkURL )
945 SfxStringItem aStrItem( SID_FILE_NAME, rBookmarkURL );
946 SfxStringItem aReferer( SID_REFERER, GetMedium()->GetName() );
947 const SfxPoolItem* ppArgs[] = { &aStrItem, &aReferer, 0 };
948 ( mpViewShell ? mpViewShell->GetViewFrame() : SfxViewFrame::Current() )->GetBindings().Execute( SID_OPENHYPERLINK, ppArgs );
951 SfxDocumentInfoDialog* DrawDocShell::CreateDocumentInfoDialog( ::Window *pParent, const SfxItemSet &rSet )
953 SfxDocumentInfoDialog* pDlg = new SfxDocumentInfoDialog( pParent, rSet );
954 DrawDocShell* pDocSh = PTR_CAST(DrawDocShell,SfxObjectShell::Current());
956 if( pDocSh == this )
958 pDlg->AddFontTabPage();
960 return pDlg;
963 } // end of namespace sd
965 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */