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 <svl/lckbitem.hxx>
21 #include <sfx2/frame.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <unotools/moduleoptions.hxx>
24 #include "framework/FrameworkHelper.hxx"
26 #include <svx/dialogs.hrc>
28 #include <editeng/langitem.hxx>
29 #include <editeng/editdata.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <editeng/svxenum.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include <sfx2/request.hxx>
34 #include <sfx2/printer.hxx>
35 #include <sfx2/docfile.hxx>
36 #include <editeng/paperinf.hxx>
37 #include <editeng/eeitem.hxx>
38 #include <unotools/useroptions.hxx>
39 #include <com/sun/star/uno/Sequence.h>
43 #include "strings.hrc"
44 #include "res_bmp.hrc"
48 #include "optsitem.hxx"
49 #include "ViewShell.hxx"
52 #include "DrawDocShell.hxx"
53 #include "drawdoc.hxx"
54 #include "assclass.hxx"
55 #include "sdenumdef.hxx"
56 #include "sdresid.hxx"
57 #include "OutlineViewShell.hxx"
58 #include "ViewShellBase.hxx"
59 #include "FrameView.hxx"
60 #include "FactoryIds.hxx"
61 #include "sdabstdlg.hxx"
62 #include <boost/shared_ptr.hpp>
63 #include <boost/scoped_array.hpp>
64 #include "slideshow.hxx"
66 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
67 #include <com/sun/star/document/XDocumentProperties.hpp>
69 using ::sd::framework::FrameworkHelper
;
70 using ::com::sun::star::uno::Reference
;
71 using ::com::sun::star::frame::XFrame
;
72 using ::com::sun::star::uno::Sequence
;
76 class OutlineToImpressFinalizer
79 OutlineToImpressFinalizer (
80 ::sd::ViewShellBase
& rBase
,
81 SdDrawDocument
& rDocument
,
83 virtual ~OutlineToImpressFinalizer() {};
84 void operator() (bool bEventSeen
);
86 ::sd::ViewShellBase
& mrBase
;
87 SdDrawDocument
& mrDocument
;
88 ::boost::shared_ptr
<SvMemoryStream
> mpStream
;
91 } //end of anonymous namespace
93 void SdModule::Execute(SfxRequest
& rReq
)
95 const SfxItemSet
* pSet
= rReq
.GetArgs();
96 sal_uLong nSlotId
= rReq
.GetSlot();
102 SfxGetpApp()->ExecuteSlot(rReq
, SfxGetpApp()->GetInterface());
106 case SID_AUTOSPELL_CHECK
:
108 // automatic spell checker
109 const SfxPoolItem
* pItem
;
110 if( pSet
&& SfxItemState::SET
== pSet
->GetItemState(
111 SID_AUTOSPELL_CHECK
, false, &pItem
) )
113 bool bOnlineSpelling
= static_cast<const SfxBoolItem
*>( pItem
)->GetValue();
115 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
118 SdDrawDocument
* pDoc
= pDocSh
->GetDoc();
119 pDoc
->SetOnlineSpell( bOnlineSpelling
);
125 case SID_ATTR_METRIC
:
127 const SfxPoolItem
* pItem
;
128 if ( pSet
&& SfxItemState::SET
== pSet
->GetItemState( SID_ATTR_METRIC
, true, &pItem
) )
130 FieldUnit eUnit
= (FieldUnit
)static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
133 case FUNIT_MM
: // only the units which are also in the dialog
139 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current() );
142 DocumentType eDocType
= pDocSh
->GetDoc()->GetDocumentType();
145 SdOptions
* pOptions
= GetSdOptions( eDocType
);
147 pOptions
->SetMetric( (sal_uInt16
)eUnit
);
160 case SID_ATTR_LANGUAGE
:
161 case SID_ATTR_CHAR_CJK_LANGUAGE
:
162 case SID_ATTR_CHAR_CTL_LANGUAGE
:
164 const SfxPoolItem
* pItem
;
167 SfxItemState::SET
== pSet
->GetItemState(SID_ATTR_LANGUAGE
, false, &pItem
) ||
168 SfxItemState::SET
== pSet
->GetItemState(SID_ATTR_CHAR_CJK_LANGUAGE
, false, &pItem
) ||
169 SfxItemState::SET
== pSet
->GetItemState(SID_ATTR_CHAR_CTL_LANGUAGE
, false, &pItem
)
173 // save at the document:
174 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
177 LanguageType eLanguage
= static_cast<const SvxLanguageItem
*>(pItem
)->GetValue();
178 SdDrawDocument
* pDoc
= pDocSh
->GetDoc();
180 if( nSlotId
== SID_ATTR_CHAR_CJK_LANGUAGE
)
181 pDoc
->SetLanguage( eLanguage
, EE_CHAR_LANGUAGE_CJK
);
182 else if( nSlotId
== SID_ATTR_CHAR_CTL_LANGUAGE
)
183 pDoc
->SetLanguage( eLanguage
, EE_CHAR_LANGUAGE_CTL
);
185 pDoc
->SetLanguage( eLanguage
, EE_CHAR_LANGUAGE
);
187 if( pDoc
->GetOnlineSpell() )
189 pDoc
->StopOnlineSpelling();
190 pDoc
->StartOnlineSpelling();
197 case SID_SD_AUTOPILOT
:
200 SfxFrame
* pFrame
= ExecuteNewDocument( rReq
);
201 // if a frame was created, set it as return value
203 rReq
.SetReturnValue(SfxFrameItem(0, pFrame
));
208 case SID_OPENHYPERLINK
:
211 bool bIntercept
= false;
212 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
215 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
218 if( sd::SlideShow::IsRunning( pViewShell
->GetViewShellBase() ) )
220 // Prevent documents from opening while the slide
221 // show is running, except when this request comes
222 // from a shape interaction.
223 if (rReq
.GetArgs() == NULL
)
233 SfxGetpApp()->ExecuteSlot(rReq
, SfxGetpApp()->GetInterface());
237 ScopedVclPtrInstance
<MessageDialog
>::Create(nullptr, SD_RESSTR(STR_CANT_PERFORM_IN_LIVEMODE
))->Execute();
239 SFX_REQUEST_ARG( rReq
, pLinkItem
, SfxLinkItem
, SID_DONELINK
, false );
241 pLinkItem
->GetValue().Call( 0 );
246 case SID_OUTLINE_TO_IMPRESS
:
247 OutlineToImpress (rReq
);
255 bool SdModule::OutlineToImpress(SfxRequest
& rRequest
)
257 const SfxItemSet
* pSet
= rRequest
.GetArgs();
261 SvLockBytes
* pBytes
= static_cast<const SfxLockBytesItem
&>(pSet
->Get(SID_OUTLINE_TO_IMPRESS
)).GetValue();
265 SfxObjectShellLock xDocShell
;
266 ::sd::DrawDocShell
* pDocSh
;
267 xDocShell
= pDocSh
= new ::sd::DrawDocShell(
268 SfxObjectCreateMode::STANDARD
, false);
270 pDocSh
->DoInitNew(NULL
);
271 SdDrawDocument
* pDoc
= pDocSh
->GetDoc();
274 pDoc
->CreateFirstPages();
275 pDoc
->StopWorkStartupDelay();
278 SFX_REQUEST_ARG( rRequest
, pFrmItem
, SfxFrameItem
, SID_DOCFRAME
, false);
279 SfxViewFrame::LoadDocumentIntoFrame( *pDocSh
, pFrmItem
, ::sd::OUTLINE_FACTORY_ID
);
281 ::sd::ViewShell
* pViewSh
= pDocSh
->GetViewShell();
285 // AutoLayouts have to be finished
286 pDoc
->StopWorkStartupDelay();
288 SfxViewFrame
* pViewFrame
= pViewSh
->GetViewFrame();
290 // When the view frame has not been just created we have
291 // to switch synchronously to the outline view.
292 // (Otherwise the request will be ignored anyway.)
293 ::sd::ViewShellBase
* pBase
294 = dynamic_cast< ::sd::ViewShellBase
*>(pViewFrame
->GetViewShell());
297 ::boost::shared_ptr
<FrameworkHelper
> pHelper (
298 FrameworkHelper::Instance(*pBase
));
299 pHelper
->RequestView(
300 FrameworkHelper::msOutlineViewURL
,
301 FrameworkHelper::msCenterPaneURL
);
303 pHelper
->RunOnResourceActivation(
304 FrameworkHelper::CreateResourceId(
305 FrameworkHelper::msOutlineViewURL
,
306 FrameworkHelper::msCenterPaneURL
),
307 OutlineToImpressFinalizer(*pBase
, *pDoc
, *pBytes
));
313 return rRequest
.IsDone();
316 void SdModule::GetState(SfxItemSet
& rItemSet
)
318 // disable Autopilot during presentation
319 if (rItemSet
.GetItemState(SID_SD_AUTOPILOT
) != SfxItemState::UNKNOWN
)
321 if (!SvtModuleOptions().IsImpress())
323 rItemSet
.DisableItem(SID_SD_AUTOPILOT
);
327 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
330 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
333 if( sd::SlideShow::IsRunning( pViewShell
->GetViewShellBase() ) )
335 rItemSet
.DisableItem(SID_SD_AUTOPILOT
);
342 if( SfxItemState::DEFAULT
== rItemSet
.GetItemState( SID_ATTR_METRIC
) )
344 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current() );
347 DocumentType eDocType
= pDocSh
->GetDoc()->GetDocumentType();
349 SdOptions
* pOptions
= GetSdOptions(eDocType
);
350 rItemSet
.Put( SfxUInt16Item( SID_ATTR_METRIC
, pOptions
->GetMetric() ) );
354 // state of SID_OPENDOC is determined by the base class
355 if (rItemSet
.GetItemState(SID_OPENDOC
) != SfxItemState::UNKNOWN
)
357 const SfxPoolItem
* pItem
= SfxGetpApp()->GetSlotState(SID_OPENDOC
, SfxGetpApp()->GetInterface());
359 rItemSet
.Put(*pItem
);
362 // state of SID_OPENHYPERLINK is determined by the base class
363 if (rItemSet
.GetItemState(SID_OPENHYPERLINK
) != SfxItemState::UNKNOWN
)
365 const SfxPoolItem
* pItem
= SfxGetpApp()->GetSlotState(SID_OPENHYPERLINK
, SfxGetpApp()->GetInterface());
367 rItemSet
.Put(*pItem
);
370 if( SfxItemState::DEFAULT
== rItemSet
.GetItemState( SID_AUTOSPELL_CHECK
) )
372 ::sd::DrawDocShell
* pDocSh
=
373 PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
376 SdDrawDocument
* pDoc
= pDocSh
->GetDoc();
377 rItemSet
.Put( SfxBoolItem( SID_AUTOSPELL_CHECK
, pDoc
->GetOnlineSpell() ) );
381 if( SfxItemState::DEFAULT
== rItemSet
.GetItemState( SID_ATTR_LANGUAGE
) )
383 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
385 rItemSet
.Put( SvxLanguageItem( pDocSh
->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE
), SID_ATTR_LANGUAGE
) );
388 if( SfxItemState::DEFAULT
== rItemSet
.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE
) )
390 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
392 rItemSet
.Put( SvxLanguageItem( pDocSh
->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CJK
), SID_ATTR_CHAR_CJK_LANGUAGE
) );
395 if( SfxItemState::DEFAULT
== rItemSet
.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE
) )
397 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
399 rItemSet
.Put( SvxLanguageItem( pDocSh
->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CTL
), SID_ATTR_CHAR_CTL_LANGUAGE
) );
402 if ( !mbEventListenerAdded
)
404 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
405 if( pDocShell
) // Impress or Draw ?
407 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
409 if( pViewShell
&& (pDocShell
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
) )
411 // add our event listener as soon as possible
412 Application::AddEventListener( LINK( this, SdModule
, EventListenerHdl
) );
413 mbEventListenerAdded
= true;
419 IMPL_STATIC_LINK( SdModule
, EventListenerHdl
, VclSimpleEvent
*, pEvent
)
421 if( pEvent
&& (pEvent
->GetId() == VCLEVENT_WINDOW_COMMAND
) && static_cast<VclWindowEvent
*>(pEvent
)->GetData() )
423 const CommandEvent
& rEvent
= *static_cast<const CommandEvent
*>(static_cast<VclWindowEvent
*>(pEvent
)->GetData());
425 if( rEvent
.GetCommand() == CommandEventId::Media
)
427 CommandMediaData
* pMediaData
= rEvent
.GetMediaData();
428 pMediaData
->SetPassThroughToOS(false);
429 switch (pMediaData
->GetMediaId())
431 case MediaCommand::Play
:
433 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
434 if( pDocShell
) // Impress or Draw ?
436 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
438 // #i97925# start the presentation if and only if an Impress document is focused
439 if( pViewShell
&& (pDocShell
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
) )
440 pViewShell
->GetViewFrame()->GetDispatcher()->Execute( SID_PRESENTATION
);
445 pMediaData
->SetPassThroughToOS(true);
453 void SdModule::AddSummaryPage (SfxViewFrame
* pViewFrame
, SdDrawDocument
* pDocument
)
455 if( !pViewFrame
|| !pViewFrame
->GetDispatcher() || !pDocument
)
458 pViewFrame
->GetDispatcher()->Execute(SID_SUMMARY_PAGE
,
459 SfxCallMode::SYNCHRON
| SfxCallMode::RECORD
);
461 OSL_ASSERT (pDocument
!=NULL
);
463 sal_Int32 nPageCount
= pDocument
->GetSdPageCount (PK_STANDARD
);
465 // We need at least two pages: the summary page and one to use as
466 // template to take the transition parameters from.
469 // Get a page from which to retrieve the transition parameters.
470 SdPage
* pTemplatePage
= pDocument
->GetSdPage (0, PK_STANDARD
);
471 OSL_ASSERT (pTemplatePage
!=NULL
);
473 // The summary page, if it exists, is the last page.
474 SdPage
* pSummaryPage
= pDocument
->GetSdPage (
475 (sal_uInt16
)nPageCount
-1, PK_STANDARD
);
476 OSL_ASSERT (pSummaryPage
!=NULL
);
478 // Take the change mode of the template page as indication of the
479 // document's kiosk mode.
480 pSummaryPage
->setTransitionDuration(pTemplatePage
->getTransitionDuration());
481 pSummaryPage
->SetPresChange(pTemplatePage
->GetPresChange());
482 pSummaryPage
->SetTime(pTemplatePage
->GetTime());
483 pSummaryPage
->SetSound(pTemplatePage
->IsSoundOn());
484 pSummaryPage
->SetSoundFile(pTemplatePage
->GetSoundFile());
485 pSummaryPage
->setTransitionType(pTemplatePage
->getTransitionType());
486 pSummaryPage
->setTransitionSubtype(pTemplatePage
->getTransitionSubtype());
487 pSummaryPage
->setTransitionDirection(pTemplatePage
->getTransitionDirection());
488 pSummaryPage
->setTransitionFadeColor(pTemplatePage
->getTransitionFadeColor());
489 pSummaryPage
->setTransitionDuration(pTemplatePage
->getTransitionDuration());
493 SfxFrame
* SdModule::CreateFromTemplate( const OUString
& rTemplatePath
, const Reference
< XFrame
>& i_rFrame
)
495 SfxFrame
* pFrame
= 0;
497 SfxObjectShellLock xDocShell
;
499 SfxItemSet
* pSet
= new SfxAllItemSet( SfxGetpApp()->GetPool() );
500 pSet
->Put( SfxBoolItem( SID_TEMPLATE
, true ) );
502 sal_uLong lErr
= SfxGetpApp()->LoadTemplate( xDocShell
, rTemplatePath
, true, pSet
);
504 SfxObjectShell
* pDocShell
= xDocShell
;
508 ErrorHandler::HandleError(lErr
);
512 SfxViewFrame
* pViewFrame
= SfxViewFrame::LoadDocumentIntoFrame( *pDocShell
, i_rFrame
);
513 OSL_ENSURE( pViewFrame
, "SdModule::CreateFromTemplate: no view frame - was the document really loaded?" );
514 pFrame
= pViewFrame
? &pViewFrame
->GetFrame() : NULL
;
521 SfxFrame
* SdModule::ExecuteNewDocument( SfxRequest
& rReq
)
523 SfxFrame
* pFrame
= 0;
524 if ( SvtModuleOptions().IsImpress() )
526 Reference
< XFrame
> xTargetFrame
;
527 SFX_REQUEST_ARG( rReq
, pFrmItem
, SfxUnoFrameItem
, SID_FILLFRAME
, false);
529 xTargetFrame
= pFrmItem
->GetFrame();
531 SfxViewFrame
* pViewFrame
= NULL
;
533 SdOptions
* pOpt
= GetSdOptions(DOCUMENT_TYPE_IMPRESS
);
534 bool bStartWithTemplate
= pOpt
->IsStartWithTemplate();
536 bool bNewDocDirect
= rReq
.GetSlot() == SID_NEWSD
;
537 if( bNewDocDirect
&& !bStartWithTemplate
)
539 //we start without wizard
541 //check whether we should load a template document
542 const OUString
aServiceName( "com.sun.star.presentation.PresentationDocument" );
543 OUString
aStandardTemplate( SfxObjectFactory::GetStandardTemplate( aServiceName
) );
545 if( !aStandardTemplate
.isEmpty() )
547 //load a template document
548 pFrame
= CreateFromTemplate( aStandardTemplate
, xTargetFrame
);
552 //create an empty document
553 pFrame
= CreateEmptyDocument( DOCUMENT_TYPE_IMPRESS
, xTargetFrame
);
558 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
559 boost::scoped_ptr
< AbstractAssistentDlg
> pPilotDlg( pFact
? pFact
->CreateAssistentDlg( NULL
, !bNewDocDirect
) : 0 );
562 if( pPilotDlg
.get() && pPilotDlg
->Execute()==RET_OK
)
564 const OUString
aDocPath( pPilotDlg
->GetDocPath());
565 const bool bIsDocEmpty
= pPilotDlg
->IsDocEmpty();
567 // So that you can open the document without AutoLayout-Dialog
568 pOpt
->SetStartWithTemplate(false);
569 if(bNewDocDirect
&& !pPilotDlg
->GetStartWithFlag())
570 bStartWithTemplate
= false;
572 if( pPilotDlg
->GetStartType() == ST_OPEN
)
574 OUString aFileToOpen
= aDocPath
;
576 DBG_ASSERT( !aFileToOpen
.isEmpty(), "The autopilot should have asked for a file itself already!" );
577 if (!aFileToOpen
.isEmpty())
579 com::sun::star::uno::Sequence
< com::sun::star::beans::NamedValue
> aPasswrd( pPilotDlg
->GetPassword() );
581 SfxStringItem
aFile( SID_FILE_NAME
, aFileToOpen
);
582 SfxStringItem
aReferer( SID_REFERER
, OUString());
583 SfxUnoAnyItem
aPassword( SID_ENCRYPTIONDATA
, com::sun::star::uno::makeAny(aPasswrd
) );
585 if ( xTargetFrame
.is() )
587 SfxAllItemSet
aSet( *rReq
.GetArgs()->GetPool() );
589 aSet
.Put( aReferer
);
590 // Put the password into the request
591 // only if it is not empty.
592 if (aPasswrd
.getLength() > 0)
593 aSet
.Put( aPassword
);
595 const SfxPoolItem
* pRet
= SfxFrame::OpenDocumentSynchron( aSet
, xTargetFrame
);
596 const SfxViewFrameItem
* pFrameItem
= PTR_CAST( SfxViewFrameItem
, pRet
);
597 if ( pFrameItem
&& pFrameItem
->GetFrame() )
598 pFrame
= &pFrameItem
->GetFrame()->GetFrame();
602 SfxRequest
aRequest (SID_OPENDOC
, SfxCallMode::SYNCHRON
, SfxGetpApp()->GetPool());
603 aRequest
.AppendItem (aFile
);
604 aRequest
.AppendItem (aReferer
);
605 // Put the password into the request
606 // only if it is not empty.
607 if (aPasswrd
.getLength() > 0)
608 aRequest
.AppendItem (aPassword
);
609 aRequest
.AppendItem (SfxStringItem (
611 OUString("_default")));
614 const SfxPoolItem
* pRet
= SfxGetpApp()->ExecuteSlot (aRequest
);
615 const SfxViewFrameItem
* pFrameItem
= PTR_CAST( SfxViewFrameItem
, pRet
);
617 pFrame
= &pFrameItem
->GetFrame()->GetFrame();
619 catch (const ::com::sun::star::uno::Exception
&)
621 DBG_ASSERT (false, "caught IllegalArgumentException while loading document from Impress autopilot");
626 pOpt
->SetStartWithTemplate(bStartWithTemplate
);
627 if(bNewDocDirect
&& !bStartWithTemplate
)
629 boost::scoped_ptr
< SfxItemSet
> pRet( CreateItemSet( SID_SD_EDITOPTIONS
) );
631 ApplyItemSet( SID_SD_EDITOPTIONS
, *pRet
.get() );
637 SfxObjectShellLock
xShell( pPilotDlg
->GetDocument() );
638 SfxObjectShell
* pShell
= xShell
;
641 pViewFrame
= SfxViewFrame::LoadDocumentIntoFrame( *pShell
, xTargetFrame
);
642 DBG_ASSERT( pViewFrame
, "no ViewFrame!!" );
643 pFrame
= pViewFrame
? &pViewFrame
->GetFrame() : NULL
;
645 if(bNewDocDirect
&& !bStartWithTemplate
)
647 boost::scoped_ptr
< SfxItemSet
> pRet( CreateItemSet( SID_SD_EDITOPTIONS
) );
649 ApplyItemSet( SID_SD_EDITOPTIONS
, *pRet
.get() );
652 ::sd::DrawDocShell
* pDocShell(NULL
);
653 ::sd::ViewShellBase
* pBase(NULL
);
654 SdDrawDocument
* pDoc(NULL
);
655 if (pShell
&& pViewFrame
)
657 pDocShell
= PTR_CAST(::sd::DrawDocShell
, pShell
);
658 pDoc
= pDocShell
? pDocShell
->GetDoc() : NULL
;
659 pBase
= ::sd::ViewShellBase::GetViewShellBase(pViewFrame
);
664 ::boost::shared_ptr
<sd::ViewShell
> pViewSh
= pBase
->GetMainViewShell();
665 SdOptions
* pOptions
= GetSdOptions(pDoc
->GetDocumentType());
667 if (pOptions
&& pViewSh
.get())
669 // The AutoPilot-document shall be open without its own options
670 ::sd::FrameView
* pFrameView
= pViewSh
->GetFrameView();
671 pFrameView
->Update(pOptions
);
672 pViewSh
->ReadFrameViewData(pFrameView
);
675 ChangeMedium( pDocShell
, pViewFrame
, pPilotDlg
->GetOutputMedium() );
677 if(pPilotDlg
->IsSummary())
678 AddSummaryPage(pViewFrame
, pDoc
);
681 if (aDocPath
.isEmpty() && pViewFrame
&& pViewFrame
->GetDispatcher())
683 SfxBoolItem
aIsChangedItem(SID_MODIFYPAGE
, !bIsDocEmpty
);
684 SfxUInt32Item
eAutoLayout( ID_VAL_WHATLAYOUT
, (sal_uInt32
) AUTOLAYOUT_TITLE
);
685 pViewFrame
->GetDispatcher()->Execute(SID_MODIFYPAGE
,
686 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
, &aIsChangedItem
, &eAutoLayout
, 0L);
689 // clear document info
690 using namespace ::com::sun::star
;
691 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
692 pDocShell
->GetModel(), uno::UNO_QUERY_THROW
);
693 uno::Reference
<document::XDocumentProperties
>
694 xDocProps(xDPS
->getDocumentProperties());
695 DBG_ASSERT(xDocProps
.is(), "no DocumentProperties");
696 xDocProps
->resetUserData(
697 SvtUserOptions().GetFullName() );
698 xDocProps
->setTemplateName(xDocProps
->getTitle());
699 xDocProps
->setTemplateURL(pPilotDlg
->GetDocPath());
701 pDoc
->SetChanged(!bIsDocEmpty
);
703 pDocShell
->SetUseUserData(true);
705 // clear UNDO stack after autopilot
706 pDocShell
->ClearUndoBuffer();
709 pOpt
->SetStartWithTemplate(bStartWithTemplate
);
718 SfxFrame
* SdModule::CreateEmptyDocument( DocumentType eDocType
, const Reference
< XFrame
>& i_rFrame
)
720 SfxFrame
* pFrame
= 0;
722 SfxObjectShellLock xDocShell
;
723 ::sd::DrawDocShell
* pNewDocSh
;
724 xDocShell
= pNewDocSh
= new ::sd::DrawDocShell(SfxObjectCreateMode::STANDARD
,false,eDocType
);
725 pNewDocSh
->DoInitNew(NULL
);
726 SdDrawDocument
* pDoc
= pNewDocSh
->GetDoc();
729 pDoc
->CreateFirstPages();
730 pDoc
->StopWorkStartupDelay();
733 SfxViewFrame
* pViewFrame
= SfxViewFrame::LoadDocumentIntoFrame( *pNewDocSh
, i_rFrame
);
734 OSL_ENSURE( pViewFrame
, "SdModule::CreateEmptyDocument: no view frame - was the document really loaded?" );
735 pFrame
= pViewFrame
? &pViewFrame
->GetFrame() : NULL
;
740 void SdModule::ChangeMedium( ::sd::DrawDocShell
* pDocShell
, SfxViewFrame
* pViewFrame
, const sal_Int32 eMedium
)
745 SdDrawDocument
* pDoc
= pDocShell
->GetDoc();
749 // settings for the Outputmedium
751 sal_uInt32 nLeft
= 0;
752 sal_uInt32 nRight
= 0;
753 sal_uInt32 nLower
= 0;
754 sal_uInt32 nUpper
= 0;
758 case OUTPUT_OVERHEAD
:
760 SfxPrinter
* pPrinter
= pDocShell
->GetPrinter(true);
762 if( pPrinter
&& pPrinter
->IsValid())
764 // Unfortunately, the printer does not provide an exact format
766 Size
aSize(pPrinter
->GetPaperSize());
767 Paper ePaper
= SvxPaperInfo::GetSvxPaper( aSize
, MAP_100TH_MM
, true);
769 if (ePaper
!= PAPER_USER
)
772 aSize
= SvxPaperInfo::GetPaperSize(ePaper
, MAP_100TH_MM
);
775 if (aSize
.Height() > aSize
.Width())
778 aNewSize
.Width() = aSize
.Height();
779 aNewSize
.Height() = aSize
.Width();
788 aNewSize
=Size(29700, 21000);
791 if (eMedium
== OUTPUT_PAGE
)
810 aNewSize
= Size(27000, 18000);
818 case OUTPUT_WIDESCREEN
:
820 aNewSize
= Size(28000, 15750);
828 case OUTPUT_PRESENTATION
:
830 aNewSize
= Size(28000, 21000);
839 bool bScaleAll
= true;
840 sal_uInt16 nPageCnt
= pDoc
->GetMasterSdPageCount(PK_STANDARD
);
844 // master pages first
845 for (i
= 0; i
< nPageCnt
; i
++)
847 pPage
= pDoc
->GetMasterSdPage(i
, PK_STANDARD
);
851 if(eMedium
!= OUTPUT_ORIGINAL
)
853 Rectangle
aBorderRect(nLeft
, nUpper
, nRight
, nLower
);
854 pPage
->ScaleObjects(aNewSize
, aBorderRect
, bScaleAll
);
855 pPage
->SetSize(aNewSize
);
856 pPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
858 SdPage
* pNotesPage
= pDoc
->GetMasterSdPage(i
, PK_NOTES
);
859 DBG_ASSERT( pNotesPage
, "Wrong page ordering!" );
860 if( pNotesPage
) pNotesPage
->CreateTitleAndLayout();
861 pPage
->CreateTitleAndLayout();
865 nPageCnt
= pDoc
->GetSdPageCount(PK_STANDARD
);
868 for (i
= 0; i
< nPageCnt
; i
++)
870 pPage
= pDoc
->GetSdPage(i
, PK_STANDARD
);
874 if(eMedium
!= OUTPUT_ORIGINAL
)
876 Rectangle
aBorderRect(nLeft
, nUpper
, nRight
, nLower
);
877 pPage
->ScaleObjects(aNewSize
, aBorderRect
, bScaleAll
);
878 pPage
->SetSize(aNewSize
);
879 pPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
881 SdPage
* pNotesPage
= pDoc
->GetSdPage(i
, PK_NOTES
);
882 DBG_ASSERT( pNotesPage
, "Wrong page ordering!" );
883 if( pNotesPage
) pNotesPage
->SetAutoLayout( pNotesPage
->GetAutoLayout() );
884 pPage
->SetAutoLayout( pPage
->GetAutoLayout() );
888 SdPage
* pHandoutPage
= pDoc
->GetSdPage(0, PK_HANDOUT
);
889 pHandoutPage
->CreateTitleAndLayout(true);
891 if( (eMedium
!= OUTPUT_ORIGINAL
) && pViewFrame
&& pViewFrame
->GetDispatcher())
893 pViewFrame
->GetDispatcher()->Execute(SID_SIZE_PAGE
, SfxCallMode::SYNCHRON
| SfxCallMode::RECORD
);
897 //===== OutlineToImpressFinalize ==============================================
901 OutlineToImpressFinalizer::OutlineToImpressFinalizer (
902 ::sd::ViewShellBase
& rBase
,
903 SdDrawDocument
& rDocument
,
906 mrDocument(rDocument
),
909 // The given stream has a lifetime shorter than this new
910 // OutlineToImpressFinalizer object. Therefore a local copy of the
911 // stream is created.
912 const SvStream
* pStream (rBytes
.GetStream());
915 // Create a memory stream and prepare to fill it with the content of
916 // the original stream.
917 mpStream
.reset(new SvMemoryStream());
918 static const sal_Size nBufferSize
= 4096;
919 ::boost::scoped_array
<sal_Int8
> pBuffer (new sal_Int8
[nBufferSize
]);
921 sal_uInt64
nReadPosition(0);
925 // Read the next part of the original stream.
926 sal_Size
nReadByteCount (0);
927 const ErrCode
nErrorCode (
934 // Check the error code and stop copying the stream data when an
935 // error has occurred.
939 if (nReadByteCount
== 0)
942 case ERRCODE_IO_PENDING
:
951 // Append the read bytes to the end of the memory stream.
952 if (nReadByteCount
> 0)
954 mpStream
->Write(pBuffer
.get(), nReadByteCount
);
955 nReadPosition
+= nReadByteCount
;
959 // Rewind the memory stream so that in the operator() method its
960 // content is properly read.
961 mpStream
->Seek(STREAM_SEEK_TO_BEGIN
);
965 void OutlineToImpressFinalizer::operator() (bool)
967 // Fetch the new outline view shell.
968 ::sd::OutlineViewShell
* pOutlineShell
969 = dynamic_cast<sd::OutlineViewShell
*>(FrameworkHelper::Instance(mrBase
)->GetViewShell(FrameworkHelper::msCenterPaneURL
).get());
971 if (pOutlineShell
!= NULL
&& mpStream
.get() != NULL
)
973 sd::OutlineView
* pView
= static_cast<sd::OutlineView
*>(pOutlineShell
->GetView());
974 // mba: the stream can't contain any relative URLs, because we don't
975 // have any information about a BaseURL!
976 if ( pOutlineShell
->Read(*mpStream
, OUString(), EE_FORMAT_RTF
) == 0 )
980 // Call UpdatePreview once for every slide to resync the
981 // document with the outliner of the OutlineViewShell.
982 sal_uInt16
nPageCount (mrDocument
.GetSdPageCount(PK_STANDARD
));
983 for (sal_uInt16 nIndex
=0; nIndex
<nPageCount
; nIndex
++)
985 SdPage
* pPage
= mrDocument
.GetSdPage(nIndex
, PK_STANDARD
);
986 // Make the page the actual page so that the
987 // following UpdatePreview() call accesses the
988 // correct paragraphs.
989 pView
->SetActualPage(pPage
);
990 pOutlineShell
->UpdatePreview(pPage
, true);
992 // Select the first slide.
993 SdPage
* pPage
= mrDocument
.GetSdPage(0, PK_STANDARD
);
994 pView
->SetActualPage(pPage
);
995 pOutlineShell
->UpdatePreview(pPage
, true);
998 // Undo-Stack needs to be cleared, else the user may remove the
999 // only drawpage and this is a state we cannot handle ATM.
1000 ::sd::DrawDocShell
* pDocShell
= mrDocument
.GetDocSh();
1002 pDocShell
->ClearUndoBuffer();
1005 } // end of anonymous namespace
1007 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */