1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include "DrawDocShell.hxx"
21 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
22 #include <tools/urlobj.hxx>
23 #include <sfx2/progress.hxx>
24 #include <vcl/waitobj.hxx>
25 #include <svx/svxids.hrc>
26 #include <editeng/editeng.hxx>
27 #include <editeng/editstat.hxx>
28 #include <editeng/flstitem.hxx>
29 #include <editeng/eeitem.hxx>
30 #include <svl/aeitem.hxx>
31 #include <svl/flagitem.hxx>
32 #include <sot/storage.hxx>
33 #include <sfx2/dinfdlg.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <sfx2/docfilt.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <svx/svdotext.hxx>
38 #include <svl/style.hxx>
39 #include <sfx2/printer.hxx>
40 #include <svtools/ctrltool.hxx>
41 #include <svtools/sfxecode.hxx>
42 #include <comphelper/classids.hxx>
43 #include <sot/formats.hxx>
44 #include <sfx2/request.hxx>
45 #include <unotools/fltrcfg.hxx>
46 #include <sfx2/frame.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <unotools/saveopt.hxx>
49 #include <com/sun/star/drawing/XDrawPage.hpp>
50 #include <com/sun/star/drawing/XDrawView.hpp>
51 #include <comphelper/processfactory.hxx>
55 #include "strings.hrc"
57 #include "FrameView.hxx"
58 #include "optsitem.hxx"
59 #include "Outliner.hxx"
61 #include "drawdoc.hxx"
62 #include "ViewShell.hxx"
66 #include "sdresid.hxx"
67 #include "DrawViewShell.hxx"
68 #include "ViewShellBase.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 #include "SdUnoDrawView.hxx"
80 using namespace ::com::sun::star
;
81 using namespace ::com::sun::star::uno
;
82 using ::sd::framework::FrameworkHelper
;
87 * Creates (if necessary) and returns a SfxPrinter
89 SfxPrinter
* DrawDocShell::GetPrinter(bool bCreate
)
91 if (bCreate
&& !mpPrinter
)
93 // create ItemSet with special pool area
94 SfxItemSet
* pSet
= new SfxItemSet( GetPool(),
95 SID_PRINTER_NOTFOUND_WARN
, SID_PRINTER_NOTFOUND_WARN
,
96 SID_PRINTER_CHANGESTODOC
, SID_PRINTER_CHANGESTODOC
,
97 ATTR_OPTIONS_PRINT
, ATTR_OPTIONS_PRINT
,
99 // set PrintOptionsSet
100 SdOptionsPrintItem
aPrintItem( ATTR_OPTIONS_PRINT
,
101 SD_MOD()->GetSdOptions(mpDoc
->GetDocumentType()));
102 SfxFlagItem
aFlagItem( SID_PRINTER_CHANGESTODOC
);
103 SfxPrinterChangeFlags nFlags
=
104 (aPrintItem
.GetOptionsPrint().IsWarningSize() ? SfxPrinterChangeFlags::CHG_SIZE
: SfxPrinterChangeFlags::NONE
) |
105 (aPrintItem
.GetOptionsPrint().IsWarningOrientation() ? SfxPrinterChangeFlags::CHG_ORIENTATION
: SfxPrinterChangeFlags::NONE
);
106 aFlagItem
.SetValue( static_cast<int>(nFlags
) );
108 pSet
->Put( aPrintItem
);
109 pSet
->Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN
, aPrintItem
.GetOptionsPrint().IsWarningPrinter() ) );
110 pSet
->Put( aFlagItem
);
112 mpPrinter
= VclPtr
<SfxPrinter
>::Create(pSet
);
115 // set output quality
116 sal_uInt16 nQuality
= aPrintItem
.GetOptionsPrint().GetOutputQuality();
118 DrawModeFlags nMode
= DrawModeFlags::Default
;
119 // 1 == Grayscale, 2 == Black & White (with grayscale images)
121 nMode
= DrawModeFlags::GrayLine
| DrawModeFlags::GrayFill
| DrawModeFlags::GrayText
| DrawModeFlags::GrayBitmap
| DrawModeFlags::GrayGradient
;
122 else if( nQuality
== 2 )
123 nMode
= DrawModeFlags::BlackLine
| DrawModeFlags::WhiteFill
| DrawModeFlags::BlackText
| DrawModeFlags::GrayBitmap
| DrawModeFlags::WhiteGradient
;
125 mpPrinter
->SetDrawMode( nMode
);
127 MapMode
aMM (mpPrinter
->GetMapMode());
128 aMM
.SetMapUnit(MAP_100TH_MM
);
129 mpPrinter
->SetMapMode(aMM
);
136 * Set new SfxPrinter (transfer of ownership)
138 void DrawDocShell::SetPrinter(SfxPrinter
*pNewPrinter
)
142 ::sd::View
* pView
= mpViewShell
->GetView();
143 if ( pView
->IsTextEdit() )
144 pView
->SdrEndTextEdit();
147 if ( mpPrinter
&& mbOwnPrinter
&& (mpPrinter
.get() != pNewPrinter
) )
148 mpPrinter
.disposeAndClear();
150 mpPrinter
= pNewPrinter
;
152 if ( mpDoc
->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED
)
157 void DrawDocShell::UpdateFontList()
160 OutputDevice
* pRefDevice
= NULL
;
161 if ( mpDoc
->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED
)
162 pRefDevice
= GetPrinter(true);
164 pRefDevice
= SD_MOD()->GetVirtualRefDevice();
165 mpFontList
= new FontList( pRefDevice
, NULL
, false );
166 SvxFontListItem
aFontListItem( mpFontList
, SID_ATTR_CHAR_FONTLIST
);
167 PutItem( aFontListItem
);
170 Printer
* DrawDocShell::GetDocumentPrinter()
172 return GetPrinter(false);
175 void DrawDocShell::OnDocumentPrinterChanged(Printer
* pNewPrinter
)
177 // if we already have a printer, see if its the same
181 if( mpPrinter
== pNewPrinter
)
184 // compare if its the same printer with the same job setup
185 if( (mpPrinter
->GetName() == pNewPrinter
->GetName()) &&
186 (mpPrinter
->GetJobSetup() == pNewPrinter
->GetJobSetup()))
190 // if (mpPrinter->IsA(SfxPrinter))
192 // Since we do not have RTTI we use a hard cast (...)
193 SetPrinter(static_cast<SfxPrinter
*>(pNewPrinter
));
195 // container owns printer
196 mbOwnPrinter
= false;
200 void DrawDocShell::UpdateRefDevice()
204 // Determine the device for which the output will be formatted.
205 VclPtr
< OutputDevice
> pRefDevice
;
206 switch (mpDoc
->GetPrinterIndependentLayout())
208 case ::com::sun::star::document::PrinterIndependentLayout::DISABLED
:
209 pRefDevice
= mpPrinter
.get();
212 case ::com::sun::star::document::PrinterIndependentLayout::ENABLED
:
213 pRefDevice
= SD_MOD()->GetVirtualRefDevice();
217 // We are confronted with an invalid or un-implemented
218 // layout mode. Use the printer as formatting device
220 DBG_ASSERT(false, "DrawDocShell::UpdateRefDevice(): Unexpected printer layout mode");
222 pRefDevice
= mpPrinter
.get();
225 mpDoc
->SetRefDevice( pRefDevice
.get() );
227 ::sd::Outliner
* pOutl
= mpDoc
->GetOutliner( false );
230 pOutl
->SetRefDevice( pRefDevice
);
232 ::sd::Outliner
* pInternalOutl
= mpDoc
->GetInternalOutliner( false );
235 pInternalOutl
->SetRefDevice( pRefDevice
);
240 * Creates new document, opens streams
242 bool DrawDocShell::InitNew( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& xStorage
)
244 bool bRet
= SfxObjectShell::InitNew( xStorage
);
246 Rectangle
aVisArea( Point(0, 0), Size(14100, 10000) );
247 SetVisArea(aVisArea
);
252 mpDoc
->NewOrLoadCompleted(NEW_DOC
); // otherwise calling
253 // NewOrLoadCompleted(NEW_LOADED) in
254 // SdDrawDocument::AllocModel()
260 * loads pools and document
262 bool DrawDocShell::Load( SfxMedium
& rMedium
)
264 mbNewDocument
= false;
267 bool bStartPresentation
= false;
268 ErrCode nError
= ERRCODE_NONE
;
270 SfxItemSet
* pSet
= rMedium
.GetItemSet();
274 if( ( SfxItemState::SET
== pSet
->GetItemState(SID_PREVIEW
) ) && static_cast<const SfxBoolItem
&>( pSet
->Get( SID_PREVIEW
) ).GetValue() )
276 mpDoc
->SetStarDrawPreviewMode( true );
279 if( SfxItemState::SET
== pSet
->GetItemState(SID_DOC_STARTPRESENTATION
)&&
280 static_cast<const SfxBoolItem
&>( pSet
->Get( SID_DOC_STARTPRESENTATION
) ).GetValue() )
282 bStartPresentation
= true;
283 mpDoc
->SetStartWithPresentation( true );
287 bRet
= SfxObjectShell::Load( rMedium
);
290 bRet
= SdXMLFilter( rMedium
, *this, true, SDXMLMODE_Normal
, SotStorage::GetVersion( rMedium
.GetStorage() ) ).Import( nError
);
295 UpdateTablePointers();
297 // If we're an embedded OLE object, use tight bounds
298 // for our visArea. No point in showing the user lots of empty
299 // space. Had to remove the check for empty VisArea below,
300 // since XML load always sets a VisArea before.
301 //TODO/LATER: looks a little bit strange!
302 if( ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED
) && SfxObjectShell::GetVisArea( ASPECT_CONTENT
).IsEmpty() )
304 SdPage
* pPage
= mpDoc
->GetSdPage( 0, PK_STANDARD
);
307 SetVisArea( Rectangle( pPage
->GetAllObjBoundRect() ) );
310 FinishedLoading( SfxLoadedFlags::ALL
);
312 const INetURLObject aUrl
;
313 SfxObjectShell::SetAutoLoad( aUrl
, 0, false );
317 if( nError
== ERRCODE_IO_BROKENPACKAGE
)
318 SetError( ERRCODE_IO_BROKENPACKAGE
, OSL_LOG_PREFIX
);
320 // TODO/LATER: correct error handling?!
321 //pStore->SetError( SVSTREAM_WRONGVERSION, OUString( OSL_LOG_PREFIX ) );
323 SetError( ERRCODE_ABORT
, OSL_LOG_PREFIX
);
326 // tell SFX to change viewshell when in preview mode
327 if( IsPreview() || bStartPresentation
)
329 SfxItemSet
*pMediumSet
= GetMedium()->GetItemSet();
331 pMediumSet
->Put( SfxUInt16Item( SID_VIEW_ID
, bStartPresentation
? 1 : 5 ) );
338 * loads content for organizer
340 bool DrawDocShell::LoadFrom( SfxMedium
& rMedium
)
342 mbNewDocument
= false;
344 WaitObject
* pWait
= NULL
;
346 pWait
= new WaitObject( (vcl::Window
*) mpViewShell
->GetActiveWindow() );
348 mpDoc
->NewOrLoadCompleted( NEW_DOC
);
349 mpDoc
->CreateFirstPages();
350 mpDoc
->StopWorkStartupDelay();
352 // TODO/LATER: nobody is interested in the error code?!
353 ErrCode nError
= ERRCODE_NONE
;
354 bool bRet
= SdXMLFilter( rMedium
, *this, true, SDXMLMODE_Organizer
, SotStorage::GetVersion( rMedium
.GetStorage() ) ).Import( nError
);
356 // tell SFX to change viewshell when in preview mode
359 SfxItemSet
*pSet
= GetMedium()->GetItemSet();
362 pSet
->Put( SfxUInt16Item( SID_VIEW_ID
, 5 ) );
371 * load from 3rd party format
373 bool DrawDocShell::ImportFrom(SfxMedium
&rMedium
,
374 uno::Reference
<text::XTextRange
> const& xInsertPosition
)
376 const OUString
aFilterName( rMedium
.GetFilter()->GetFilterName() );
377 if( aFilterName
== "Impress MS PowerPoint 2007 XML" ||
378 aFilterName
== "Impress MS PowerPoint 2007 XML AutoPlay" )
380 // As this is a MSFT format, we should use the "MS Compat"
381 // mode for spacing before and after paragraphs.
383 // This is copied from what is done for .ppt import in
384 // ImplSdPPTImport::Import() in sd/source/filter/ppt/pptin.cxx
385 // in. We need to tell both the edit engine of the draw outliner,
386 // and the document, to do "summation of paragraphs".
387 SdrOutliner
& rOutl
= mpDoc
->GetDrawOutliner();
388 EEControlBits nControlWord
= rOutl
.GetEditEngine().GetControlWord();
389 nControlWord
|= EEControlBits::ULSPACESUMMATION
;
390 nControlWord
&=~ EEControlBits::ULSPACEFIRSTPARA
;
391 ((EditEngine
&)rOutl
.GetEditEngine()).SetControlWord( nControlWord
);
393 mpDoc
->SetSummationOfParagraphs( true );
396 const bool bRet
= SfxObjectShell::ImportFrom(rMedium
, xInsertPosition
);
398 SfxItemSet
* pSet
= rMedium
.GetItemSet();
401 if( SfxItemState::SET
== pSet
->GetItemState(SID_DOC_STARTPRESENTATION
)&&
402 static_cast<const SfxBoolItem
&>( pSet
->Get( SID_DOC_STARTPRESENTATION
) ).GetValue() )
404 mpDoc
->SetStartWithPresentation( true );
406 // tell SFX to change viewshell when in preview mode
409 SfxItemSet
*pMediumSet
= GetMedium()->GetItemSet();
411 pMediumSet
->Put( SfxUInt16Item( SID_VIEW_ID
, 1 ) );
420 * load from a foreign format
422 bool DrawDocShell::ConvertFrom( SfxMedium
& rMedium
)
424 mbNewDocument
= false;
426 const OUString
aFilterName( rMedium
.GetFilter()->GetFilterName() );
428 bool bStartPresentation
= false;
430 SetWaitCursor( true );
432 SfxItemSet
* pSet
= rMedium
.GetItemSet();
435 if( ( SfxItemState::SET
== pSet
->GetItemState(SID_PREVIEW
) ) && static_cast<const SfxBoolItem
&>( pSet
->Get( SID_PREVIEW
) ).GetValue() )
437 mpDoc
->SetStarDrawPreviewMode( true );
440 if( SfxItemState::SET
== pSet
->GetItemState(SID_DOC_STARTPRESENTATION
)&&
441 static_cast<const SfxBoolItem
&>( pSet
->Get( SID_DOC_STARTPRESENTATION
) ).GetValue() )
443 bStartPresentation
= true;
444 mpDoc
->SetStartWithPresentation( true );
448 if( aFilterName
== pFilterPowerPoint97
449 || aFilterName
== pFilterPowerPoint97Template
450 || aFilterName
== pFilterPowerPoint97AutoPlay
)
452 mpDoc
->StopWorkStartupDelay();
453 bRet
= SdPPTFilter( rMedium
, *this, true ).Import();
455 else if (aFilterName
.indexOf("impress8") >= 0 ||
456 aFilterName
.indexOf("draw8") >= 0)
458 // TODO/LATER: nobody is interested in the error code?!
459 mpDoc
->CreateFirstPages();
460 mpDoc
->StopWorkStartupDelay();
461 ErrCode nError
= ERRCODE_NONE
;
462 bRet
= SdXMLFilter( rMedium
, *this, true ).Import( nError
);
465 else if (aFilterName
.indexOf("StarOffice XML (Draw)") >= 0 ||
466 aFilterName
.indexOf("StarOffice XML (Impress)") >= 0)
468 // TODO/LATER: nobody is interested in the error code?!
469 mpDoc
->CreateFirstPages();
470 mpDoc
->StopWorkStartupDelay();
471 ErrCode nError
= ERRCODE_NONE
;
472 bRet
= SdXMLFilter( rMedium
, *this, true, SDXMLMODE_Normal
, SOFFICE_FILEFORMAT_60
).Import( nError
);
474 else if( aFilterName
== "CGM - Computer Graphics Metafile" )
476 mpDoc
->CreateFirstPages();
477 mpDoc
->StopWorkStartupDelay();
478 bRet
= SdCGMFilter( rMedium
, *this, true ).Import();
482 mpDoc
->CreateFirstPages();
483 mpDoc
->StopWorkStartupDelay();
484 bRet
= SdGRFFilter( rMedium
, *this ).Import();
487 FinishedLoading( SfxLoadedFlags::ALL
);
489 // tell SFX to change viewshell when in preview mode
492 SfxItemSet
*pMediumSet
= GetMedium()->GetItemSet();
495 pMediumSet
->Put( SfxUInt16Item( SID_VIEW_ID
, 5 ) );
497 SetWaitCursor( false );
499 // tell SFX to change viewshell when in preview mode
500 if( IsPreview() || bStartPresentation
)
502 SfxItemSet
*pMediumSet
= GetMedium()->GetItemSet();
504 pMediumSet
->Put( SfxUInt16Item( SID_VIEW_ID
, bStartPresentation
? 1 : 5 ) );
511 * Writes pools and document to the open streams
513 bool DrawDocShell::Save()
515 mpDoc
->StopWorkStartupDelay();
517 //TODO/LATER: why this?!
518 if( GetCreateMode() == SfxObjectCreateMode::STANDARD
)
519 SfxObjectShell::SetVisArea( Rectangle() );
521 bool bRet
= SfxObjectShell::Save();
524 bRet
= SdXMLFilter( *GetMedium(), *this, true, SDXMLMODE_Normal
, SotStorage::GetVersion( GetMedium()->GetStorage() ) ).Export();
530 * Writes pools and document to the provided storage
532 bool DrawDocShell::SaveAs( SfxMedium
& rMedium
)
534 mpDoc
->setDocAccTitle(OUString());
535 SfxViewFrame
* pFrame1
= SfxViewFrame::GetFirst( this );
538 vcl::Window
* pWindow
= &pFrame1
->GetWindow();
541 vcl::Window
* pSysWin
= pWindow
->GetSystemWindow();
544 pSysWin
->SetAccessibleName(OUString());
548 mpDoc
->StopWorkStartupDelay();
550 //TODO/LATER: why this?!
551 if( GetCreateMode() == SfxObjectCreateMode::STANDARD
)
552 SfxObjectShell::SetVisArea( Rectangle() );
554 sal_uInt32 nVBWarning
= ERRCODE_NONE
;
555 bool bRet
= SfxObjectShell::SaveAs( rMedium
);
558 bRet
= SdXMLFilter( rMedium
, *this, true, SDXMLMODE_Normal
, SotStorage::GetVersion( rMedium
.GetStorage() ) ).Export();
560 if( GetError() == ERRCODE_NONE
)
561 SetError( nVBWarning
, OSL_LOG_PREFIX
);
567 * save to foreign format
569 bool DrawDocShell::ConvertTo( SfxMedium
& rMedium
)
573 if( mpDoc
->GetPageCount() )
575 const SfxFilter
* pMediumFilter
= rMedium
.GetFilter();
576 const OUString
aTypeName( pMediumFilter
->GetTypeName() );
577 SdFilter
* pFilter
= NULL
;
579 if( aTypeName
.indexOf( "graphic_HTML" ) >= 0 )
581 pFilter
= new SdHTMLFilter( rMedium
, *this, true );
583 else if( aTypeName
.indexOf( "MS_PowerPoint_97" ) >= 0 )
585 pFilter
= new SdPPTFilter( rMedium
, *this, true );
586 static_cast<SdPPTFilter
*>(pFilter
)->PreSaveBasic();
588 else if ( aTypeName
.indexOf( "CGM_Computer_Graphics_Metafile" ) >= 0 )
590 pFilter
= new SdCGMFilter( rMedium
, *this, true );
592 else if( aTypeName
.indexOf( "draw8" ) >= 0 ||
593 aTypeName
.indexOf( "impress8" ) >= 0 )
595 pFilter
= new SdXMLFilter( rMedium
, *this, true );
597 else if( aTypeName
.indexOf( "StarOffice_XML_Impress" ) >= 0 ||
598 aTypeName
.indexOf( "StarOffice_XML_Draw" ) >= 0 )
600 pFilter
= new SdXMLFilter( rMedium
, *this, true, SDXMLMODE_Normal
, SOFFICE_FILEFORMAT_60
);
604 pFilter
= new SdGRFFilter( rMedium
, *this );
609 const SdrSwapGraphicsMode nOldSwapMode
= mpDoc
->GetSwapGraphicsMode();
611 mpDoc
->SetSwapGraphicsMode( SdrSwapGraphicsMode::TEMP
);
613 bRet
= pFilter
->Export();
615 mpDoc
->SetSwapGraphicsMode( nOldSwapMode
);
625 * Reopen own streams to ensure that nobody else can prevent use from opening
628 bool DrawDocShell::SaveCompleted( const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& xStorage
)
632 if( SfxObjectShell::SaveCompleted(xStorage
) )
634 mpDoc
->NbcSetChanged( false );
638 if( mpViewShell
->ISA( OutlineViewShell
) )
639 static_cast<OutlineView
*>(mpViewShell
->GetView())
640 ->GetOutliner().ClearModifyFlag();
642 SdrOutliner
* pOutl
= mpViewShell
->GetView()->GetTextEditOutliner();
645 SdrObject
* pObj
= mpViewShell
->GetView()->GetTextEditObject();
647 pObj
->NbcSetOutlinerParaObject( pOutl
->CreateParaObject() );
649 pOutl
->ClearModifyFlag();
655 SfxViewFrame
* pFrame
= ( mpViewShell
&& mpViewShell
->GetViewFrame() ) ?
656 mpViewShell
->GetViewFrame() :
657 SfxViewFrame::Current();
660 pFrame
->GetBindings().Invalidate( SID_NAVIGATOR_STATE
, true, false );
665 SfxStyleSheetBasePool
* DrawDocShell::GetStyleSheetPool()
667 return mpDoc
->GetStyleSheetPool();
670 bool DrawDocShell::GotoBookmark(const OUString
& rBookmark
)
674 if (mpViewShell
&& mpViewShell
->ISA(DrawViewShell
))
676 DrawViewShell
* pDrawViewShell
= static_cast<DrawViewShell
*>(mpViewShell
);
677 ViewShellBase
& rBase (mpViewShell
->GetViewShellBase());
679 bool bIsMasterPage
= false;
680 sal_uInt16 nPageNumber
= SDRPAGE_NOTFOUND
;
681 SdrObject
* pObj
= NULL
;
683 OUString
sBookmark( rBookmark
);
684 const OUString
sInteraction( "action?" );
685 if ( sBookmark
.match( sInteraction
) )
687 const OUString
sJump( "jump=" );
688 if ( sBookmark
.match( sJump
, sInteraction
.getLength() ) )
690 OUString
aDestination( sBookmark
.copy( sInteraction
.getLength() + sJump
.getLength() ) );
691 if ( aDestination
.match( "firstslide" ) )
695 else if ( aDestination
.match( "lastslide" ) )
697 nPageNumber
= mpDoc
->GetPageCount() - 2;
699 else if ( aDestination
.match( "previousslide" ) )
701 SdPage
* pPage
= pDrawViewShell
->GetActualPage();
702 nPageNumber
= pPage
->GetPageNum();
703 nPageNumber
= nPageNumber
> 2 ? nPageNumber
- 2 : SDRPAGE_NOTFOUND
;
705 else if ( aDestination
.match( "nextslide" ) )
707 SdPage
* pPage
= pDrawViewShell
->GetActualPage();
708 nPageNumber
= pPage
->GetPageNum() + 2;
709 if ( nPageNumber
>= mpDoc
->GetPageCount() )
710 nPageNumber
= SDRPAGE_NOTFOUND
;
716 OUString
aBookmark( rBookmark
);
718 // Is the bookmark a page?
719 nPageNumber
= mpDoc
->GetPageByName( aBookmark
, bIsMasterPage
);
721 if (nPageNumber
== SDRPAGE_NOTFOUND
)
723 // Is the bookmark a object?
724 pObj
= mpDoc
->GetObj(aBookmark
);
728 nPageNumber
= pObj
->GetPage()->GetPageNum();
732 if (nPageNumber
!= SDRPAGE_NOTFOUND
)
734 // Jump to the bookmarked page. This is done in three steps.
739 pPage
= static_cast<SdPage
*>( mpDoc
->GetMasterPage(nPageNumber
) );
741 pPage
= static_cast<SdPage
*>( mpDoc
->GetPage(nPageNumber
) );
743 // 1.) Change the view shell to the edit view, the notes view,
744 // or the handout view.
745 PageKind eNewPageKind
= pPage
->GetPageKind();
747 if( (eNewPageKind
!= PK_STANDARD
) && (mpDoc
->GetDocumentType() == DOCUMENT_TYPE_DRAW
) )
750 if (eNewPageKind
!= pDrawViewShell
->GetPageKind())
753 GetFrameView()->SetPageKind(eNewPageKind
);
755 switch (eNewPageKind
)
758 sViewURL
= FrameworkHelper::msImpressViewURL
;
761 sViewURL
= FrameworkHelper::msNotesViewURL
;
764 sViewURL
= FrameworkHelper::msHandoutViewURL
;
769 if (!sViewURL
.isEmpty())
771 ::boost::shared_ptr
<FrameworkHelper
> pHelper (
772 FrameworkHelper::Instance(rBase
));
773 pHelper
->RequestView(
775 FrameworkHelper::msCenterPaneURL
);
776 pHelper
->WaitForUpdate();
778 // Get the new DrawViewShell.
779 mpViewShell
= pHelper
->GetViewShell(FrameworkHelper::msCenterPaneURL
).get();
780 pDrawViewShell
= dynamic_cast<sd::DrawViewShell
*>(mpViewShell
);
784 pDrawViewShell
= NULL
;
788 if (pDrawViewShell
!= NULL
)
790 setEditMode(pDrawViewShell
, bIsMasterPage
);
792 // Make the bookmarked page the current page. This is done
793 // by using the API because this takes care of all the
794 // little things to be done. Especially writing the view
795 // data to the frame view.
796 sal_uInt16 nSdPgNum
= (nPageNumber
- 1) / 2;
797 Reference
<drawing::XDrawView
> xController (rBase
.GetController(), UNO_QUERY
);
798 if (xController
.is())
800 Reference
<drawing::XDrawPage
> xDrawPage (pPage
->getUnoPage(), UNO_QUERY
);
801 xController
->setCurrentPage (xDrawPage
);
805 // As a fall back switch to the page via the core.
806 DBG_ASSERT (xController
.is(),
807 "DrawDocShell::GotoBookmark: can't switch page via API");
808 pDrawViewShell
->SwitchPage(nSdPgNum
);
813 // show and select object
814 pDrawViewShell
->MakeVisible(pObj
->GetLogicRect(),
815 *pDrawViewShell
->GetActiveWindow());
816 pDrawViewShell
->GetView()->UnmarkAll();
817 pDrawViewShell
->GetView()->MarkObj(
819 pDrawViewShell
->GetView()->GetSdrPageView(), false);
824 SfxBindings
& rBindings
= ((pDrawViewShell
&& pDrawViewShell
->GetViewFrame()!=NULL
)
825 ? pDrawViewShell
->GetViewFrame()
826 : SfxViewFrame::Current() )->GetBindings();
828 rBindings
.Invalidate(SID_NAVIGATOR_STATE
, true, false);
829 rBindings
.Invalidate(SID_NAVIGATOR_PAGENAME
);
835 // If object is marked return true else return false.
836 bool DrawDocShell::IsMarked( SdrObject
* pObject
)
838 bool bisMarked
=false;
840 if (mpViewShell
&& mpViewShell
->ISA(DrawViewShell
))
842 DrawViewShell
* pDrViewSh
= static_cast<DrawViewShell
*>( mpViewShell
);
845 bisMarked
= pDrViewSh
->GetView()->IsObjMarked(pObject
);
851 // If object is marked return true else return false.
852 bool DrawDocShell::GetObjectIsmarked(const OUString
& rBookmark
)
854 OSL_TRACE("GotoBookmark %s",
855 OUStringToOString(rBookmark
, RTL_TEXTENCODING_UTF8
).getStr());
856 bool bUnMark
= false;
858 if (mpViewShell
&& mpViewShell
->ISA(DrawViewShell
))
860 DrawViewShell
* pDrViewSh
= static_cast<DrawViewShell
*>( mpViewShell
);
862 OUString
aBookmark( rBookmark
);
864 if( rBookmark
.startsWith("#") )
865 aBookmark
= rBookmark
.copy( 1 );
867 // Is the bookmark a page ?
869 sal_uInt16 nPgNum
= mpDoc
->GetPageByName( aBookmark
, bIsMasterPage
);
870 SdrObject
* pObj
= NULL
;
872 if (nPgNum
== SDRPAGE_NOTFOUND
)
874 // Is the bookmark an object ?
875 pObj
= mpDoc
->GetObj(aBookmark
);
879 nPgNum
= pObj
->GetPage()->GetPageNum();
883 if (nPgNum
!= SDRPAGE_NOTFOUND
)
885 /********************
887 ********************/
888 SdPage
* pPage
= static_cast<SdPage
*>( mpDoc
->GetPage(nPgNum
) );
890 PageKind eNewPageKind
= pPage
->GetPageKind();
892 if (eNewPageKind
!= pDrViewSh
->GetPageKind())
895 GetFrameView()->SetPageKind(eNewPageKind
);
896 ( ( mpViewShell
&& mpViewShell
->GetViewFrame() ) ?
897 mpViewShell
->GetViewFrame() : SfxViewFrame::Current() )->
898 GetDispatcher()->Execute( SID_VIEWSHELL0
, SfxCallMode::SYNCHRON
| SfxCallMode::RECORD
);
900 // The current ViewShell changed
901 pDrViewSh
= static_cast<DrawViewShell
*>( mpViewShell
);
904 setEditMode(pDrViewSh
, bIsMasterPage
);
906 // Jump to the page. This is done by using the API because this
907 // takes care of all the little things to be done. Especially
908 // writing the view data to the frame view (see bug #107803#).
909 SdUnoDrawView
* pUnoDrawView
= new SdUnoDrawView (
911 *pDrViewSh
->GetView());
912 ::com::sun::star::uno::Reference
<
913 ::com::sun::star::drawing::XDrawPage
> xDrawPage (
914 pPage
->getUnoPage(), ::com::sun::star::uno::UNO_QUERY
);
915 pUnoDrawView
->setCurrentPage (xDrawPage
);
920 // Show and select object
921 pDrViewSh
->MakeVisible(pObj
->GetLogicRect(),
922 *pDrViewSh
->GetActiveWindow());
924 bUnMark
= pDrViewSh
->GetView()->IsObjMarked(pObj
);
932 // realize multi-selection of objects
933 bool DrawDocShell::GotoTreeBookmark(const OUString
& rBookmark
)
935 OSL_TRACE("GotoBookmark %s",
936 OUStringToOString(rBookmark
, RTL_TEXTENCODING_UTF8
).getStr());
939 if (mpViewShell
&& mpViewShell
->ISA(DrawViewShell
))
941 DrawViewShell
* pDrViewSh
= static_cast<DrawViewShell
*>( mpViewShell
);
943 OUString
aBookmark( rBookmark
);
945 if( rBookmark
.startsWith("#") )
946 aBookmark
= rBookmark
.copy( 1 );
948 // is the bookmark a page ?
950 sal_uInt16 nPgNum
= mpDoc
->GetPageByName( aBookmark
, bIsMasterPage
);
951 SdrObject
* pObj
= NULL
;
953 if (nPgNum
== SDRPAGE_NOTFOUND
)
955 // is the bookmark an object ?
956 pObj
= mpDoc
->GetObj(aBookmark
);
960 nPgNum
= pObj
->GetPage()->GetPageNum();
964 if (nPgNum
!= SDRPAGE_NOTFOUND
)
966 /********************
968 ********************/
970 SdPage
* pPage
= static_cast<SdPage
*>( mpDoc
->GetPage(nPgNum
) );
972 PageKind eNewPageKind
= pPage
->GetPageKind();
974 if (eNewPageKind
!= pDrViewSh
->GetPageKind())
977 GetFrameView()->SetPageKind(eNewPageKind
);
978 ( ( mpViewShell
&& mpViewShell
->GetViewFrame() ) ?
979 mpViewShell
->GetViewFrame() : SfxViewFrame::Current() )->
980 GetDispatcher()->Execute( SID_VIEWSHELL0
, SfxCallMode::SYNCHRON
| SfxCallMode::RECORD
);
982 // The current ViewShell changed
983 pDrViewSh
= static_cast<DrawViewShell
*>( mpViewShell
);
986 setEditMode(pDrViewSh
, bIsMasterPage
);
988 // Jump to the page. This is done by using the API because this
989 // takes care of all the little things to be done. Especially
990 // writing the view data to the frame view (see bug #107803#).
991 SdUnoDrawView
* pUnoDrawView
= new SdUnoDrawView (
993 *pDrViewSh
->GetView());
994 ::com::sun::star::uno::Reference
<
995 ::com::sun::star::drawing::XDrawPage
> xDrawPage (
996 pPage
->getUnoPage(), ::com::sun::star::uno::UNO_QUERY
);
997 pUnoDrawView
->setCurrentPage (xDrawPage
);
1002 // Show and select object
1003 pDrViewSh
->MakeVisible(pObj
->GetLogicRect(),
1004 *pDrViewSh
->GetActiveWindow());
1005 bool bUnMark
= pDrViewSh
->GetView()->IsObjMarked(pObj
);
1006 pDrViewSh
->GetView()->MarkObj(pObj
, pDrViewSh
->GetView()->GetSdrPageView(), bUnMark
);
1010 SfxBindings
& rBindings
= ( ( mpViewShell
&& mpViewShell
->GetViewFrame() ) ?
1011 mpViewShell
->GetViewFrame() : SfxViewFrame::Current() )->GetBindings();
1013 rBindings
.Invalidate(SID_NAVIGATOR_STATE
, true, false);
1014 rBindings
.Invalidate(SID_NAVIGATOR_PAGENAME
);
1021 * If it should become a document template.
1023 bool DrawDocShell::SaveAsOwnFormat( SfxMedium
& rMedium
)
1026 const SfxFilter
* pFilter
= rMedium
.GetFilter();
1028 if (pFilter
->IsOwnTemplateFormat())
1030 /* now the StarDraw specialty:
1031 we assign known layout names to the layout template of the first
1032 page, we set the layout names of the affected masterpages and pages.
1033 We inform all text objects of the affected standard, note and
1034 masterpages about the name change.
1037 OUString aLayoutName
;
1039 SfxStringItem
const * pLayoutItem
;
1040 if( rMedium
.GetItemSet()->GetItemState(SID_TEMPLATE_NAME
, false, reinterpret_cast<const SfxPoolItem
**>(& pLayoutItem
) ) == SfxItemState::SET
)
1042 aLayoutName
= pLayoutItem
->GetValue();
1046 INetURLObject
aURL( rMedium
.GetName() );
1047 aURL
.removeExtension();
1048 aLayoutName
= aURL
.getName();
1051 if (!aLayoutName
.isEmpty())
1053 sal_uInt32 nCount
= mpDoc
->GetMasterSdPageCount(PK_STANDARD
);
1054 for (sal_uInt32 i
= 0; i
< nCount
; ++i
)
1056 OUString aOldPageLayoutName
= mpDoc
->GetMasterSdPage(i
, PK_STANDARD
)->GetLayoutName();
1057 OUString aNewLayoutName
= aLayoutName
;
1058 // Don't add suffix for the first master page
1060 aNewLayoutName
+= OUString::number(i
);
1062 mpDoc
->RenameLayoutTemplate(aOldPageLayoutName
, aNewLayoutName
);
1067 return SfxObjectShell::SaveAsOwnFormat(rMedium
);
1070 void DrawDocShell::FillClass(SvGlobalName
* pClassName
,
1071 SotClipboardFormatId
* pFormat
,
1073 OUString
* pFullTypeName
,
1074 OUString
* pShortTypeName
,
1075 sal_Int32 nFileFormat
,
1076 bool bTemplate
/* = false */) const
1078 if (nFileFormat
== SOFFICE_FILEFORMAT_60
)
1080 if ( meDocType
== DOCUMENT_TYPE_DRAW
)
1082 *pClassName
= SvGlobalName(SO3_SDRAW_CLASSID_60
);
1083 *pFormat
= SotClipboardFormatId::STARDRAW_60
;
1084 *pFullTypeName
= OUString(SdResId(STR_GRAPHIC_DOCUMENT_FULLTYPE_60
));
1088 *pClassName
= SvGlobalName(SO3_SIMPRESS_CLASSID_60
);
1089 *pFormat
= SotClipboardFormatId::STARIMPRESS_60
;
1090 *pFullTypeName
= OUString(SdResId(STR_IMPRESS_DOCUMENT_FULLTYPE_60
));
1093 else if (nFileFormat
== SOFFICE_FILEFORMAT_8
)
1095 if ( meDocType
== DOCUMENT_TYPE_DRAW
)
1097 *pClassName
= SvGlobalName(SO3_SDRAW_CLASSID_60
);
1098 *pFormat
= bTemplate
? SotClipboardFormatId::STARDRAW_8_TEMPLATE
: SotClipboardFormatId::STARDRAW_8
;
1099 *pFullTypeName
= "Draw 8"; // HACK: method will be removed with new storage API
1103 *pClassName
= SvGlobalName(SO3_SIMPRESS_CLASSID_60
);
1104 *pFormat
= bTemplate
? SotClipboardFormatId::STARIMPRESS_8_TEMPLATE
: SotClipboardFormatId::STARIMPRESS_8
;
1105 *pFullTypeName
= "Impress 8"; // HACK: method will be removed with new storage API
1109 *pShortTypeName
= OUString(SdResId( (meDocType
== DOCUMENT_TYPE_DRAW
) ?
1110 STR_GRAPHIC_DOCUMENT
: STR_IMPRESS_DOCUMENT
));
1113 OutputDevice
* DrawDocShell::GetDocumentRefDev()
1115 OutputDevice
* pReferenceDevice
= SfxObjectShell::GetDocumentRefDev ();
1116 // Only when our parent does not have a reference device then we return
1118 if (pReferenceDevice
== NULL
&& mpDoc
!= NULL
)
1119 pReferenceDevice
= mpDoc
->GetRefDevice ();
1120 return pReferenceDevice
;
1123 /** executes the SID_OPENDOC slot to let the framework open a document
1124 with the given URL and this document as a referer */
1125 void DrawDocShell::OpenBookmark( const OUString
& rBookmarkURL
)
1127 SfxStringItem
aStrItem( SID_FILE_NAME
, rBookmarkURL
);
1128 SfxStringItem
aReferer( SID_REFERER
, GetMedium()->GetName() );
1129 const SfxPoolItem
* ppArgs
[] = { &aStrItem
, &aReferer
, 0 };
1130 ( mpViewShell
? mpViewShell
->GetViewFrame() : SfxViewFrame::Current() )->GetBindings().Execute( SID_OPENHYPERLINK
, ppArgs
);
1133 VclPtr
<SfxDocumentInfoDialog
> DrawDocShell::CreateDocumentInfoDialog( vcl::Window
*pParent
, const SfxItemSet
&rSet
)
1135 VclPtr
<SfxDocumentInfoDialog
> pDlg
= VclPtr
<SfxDocumentInfoDialog
>::Create( pParent
, rSet
);
1136 DrawDocShell
* pDocSh
= PTR_CAST(DrawDocShell
,SfxObjectShell::Current());
1138 if( pDocSh
== this )
1140 pDlg
->AddFontTabPage();
1145 void DrawDocShell::setEditMode(DrawViewShell
* pDrawViewShell
, bool isMasterPage
)
1147 // Set the edit mode to either the normal edit mode or the
1148 // master page mode.
1149 EditMode eNewEditMode
= EM_PAGE
;
1152 eNewEditMode
= EM_MASTERPAGE
;
1155 if (eNewEditMode
!= pDrawViewShell
->GetEditMode())
1158 pDrawViewShell
->ChangeEditMode(eNewEditMode
, false);
1161 } // end of namespace sd
1163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */