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 .
21 #include <svl/lckbitem.hxx>
22 #include <sfx2/frame.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <unotools/moduleoptions.hxx>
25 #include "framework/FrameworkHelper.hxx"
27 #include <svx/dialogs.hrc>
29 #include <editeng/langitem.hxx>
30 #include <editeng/editdata.hxx>
31 #include <vcl/msgbox.hxx>
32 #include <editeng/svxenum.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/request.hxx>
35 #include <sfx2/printer.hxx>
36 #include <sfx2/docfile.hxx>
37 #include <editeng/paperinf.hxx>
38 #include <editeng/eeitem.hxx>
39 #include <unotools/useroptions.hxx>
40 #include <com/sun/star/uno/Sequence.h>
44 #include "strings.hrc"
45 #include "res_bmp.hrc"
49 #include "optsitem.hxx"
50 #include "ViewShell.hxx"
53 #include "DrawDocShell.hxx"
54 #include "drawdoc.hxx"
55 #include "assclass.hxx"
56 #include "sdenumdef.hxx"
57 #include "sdresid.hxx"
58 #include "OutlineViewShell.hxx"
59 #include "ViewShellBase.hxx"
60 #include "FrameView.hxx"
61 #include "FactoryIds.hxx"
62 #include "sdabstdlg.hxx"
64 #include <boost/shared_ptr.hpp>
65 #include <boost/scoped_array.hpp>
66 #include "slideshow.hxx"
68 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
69 #include <com/sun/star/document/XDocumentProperties.hpp>
72 using ::sd::framework::FrameworkHelper
;
73 using ::com::sun::star::uno::Reference
;
74 using ::com::sun::star::frame::XFrame
;
75 using ::com::sun::star::uno::Sequence
;
79 class OutlineToImpressFinalizer
82 OutlineToImpressFinalizer (
83 ::sd::ViewShellBase
& rBase
,
84 SdDrawDocument
& rDocument
,
86 virtual ~OutlineToImpressFinalizer (void) {};
87 void operator() (bool bEventSeen
);
89 ::sd::ViewShellBase
& mrBase
;
90 SdDrawDocument
& mrDocument
;
91 ::boost::shared_ptr
<SvMemoryStream
> mpStream
;
95 } //end of anonymous namespace
98 void SdModule::Execute(SfxRequest
& rReq
)
100 const SfxItemSet
* pSet
= rReq
.GetArgs();
101 sal_uLong nSlotId
= rReq
.GetSlot();
107 SFX_APP()->ExecuteSlot(rReq
, SFX_APP()->GetInterface());
111 case SID_AUTOSPELL_CHECK
:
113 // automatic spell checker
114 const SfxPoolItem
* pItem
;
115 if( pSet
&& SFX_ITEM_SET
== pSet
->GetItemState(
116 SID_AUTOSPELL_CHECK
, sal_False
, &pItem
) )
118 sal_Bool bOnlineSpelling
= ( (const SfxBoolItem
*) pItem
)->GetValue();
120 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
123 SdDrawDocument
* pDoc
= pDocSh
->GetDoc();
124 pDoc
->SetOnlineSpell( bOnlineSpelling
);
130 case SID_ATTR_METRIC
:
132 const SfxPoolItem
* pItem
;
133 if ( pSet
&& SFX_ITEM_SET
== pSet
->GetItemState( SID_ATTR_METRIC
, sal_True
, &pItem
) )
135 FieldUnit eUnit
= (FieldUnit
)((const SfxUInt16Item
*)pItem
)->GetValue();
138 case FUNIT_MM
: // only the units which are also in the dialog
144 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current() );
147 DocumentType eDocType
= pDocSh
->GetDoc()->GetDocumentType();
150 SdOptions
* pOptions
= GetSdOptions( eDocType
);
152 pOptions
->SetMetric( (sal_uInt16
)eUnit
);
165 case SID_ATTR_LANGUAGE
:
166 case SID_ATTR_CHAR_CJK_LANGUAGE
:
167 case SID_ATTR_CHAR_CTL_LANGUAGE
:
169 const SfxPoolItem
* pItem
;
172 SFX_ITEM_SET
== pSet
->GetItemState(SID_ATTR_LANGUAGE
, sal_False
, &pItem
) ||
173 SFX_ITEM_SET
== pSet
->GetItemState(SID_ATTR_CHAR_CJK_LANGUAGE
, sal_False
, &pItem
) ||
174 SFX_ITEM_SET
== pSet
->GetItemState(SID_ATTR_CHAR_CTL_LANGUAGE
, sal_False
, &pItem
)
178 // save at the document:
179 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
182 LanguageType eLanguage
= ( (SvxLanguageItem
*)pItem
)->GetValue();
183 SdDrawDocument
* pDoc
= pDocSh
->GetDoc();
185 if( nSlotId
== SID_ATTR_CHAR_CJK_LANGUAGE
)
186 pDoc
->SetLanguage( eLanguage
, EE_CHAR_LANGUAGE_CJK
);
187 else if( nSlotId
== SID_ATTR_CHAR_CTL_LANGUAGE
)
188 pDoc
->SetLanguage( eLanguage
, EE_CHAR_LANGUAGE_CTL
);
190 pDoc
->SetLanguage( eLanguage
, EE_CHAR_LANGUAGE
);
192 if( pDoc
->GetOnlineSpell() )
194 pDoc
->StopOnlineSpelling();
195 pDoc
->StartOnlineSpelling();
202 case SID_SD_AUTOPILOT
:
205 SfxFrame
* pFrame
= ExecuteNewDocument( rReq
);
206 // if a frame was created, set it as return value
208 rReq
.SetReturnValue(SfxFrameItem(0, pFrame
));
213 case SID_OPENHYPERLINK
:
216 sal_Bool bIntercept
= sal_False
;
217 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
220 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
223 if( sd::SlideShow::IsRunning( pViewShell
->GetViewShellBase() ) )
225 // Prevent documents from opening while the slide
226 // show is running, except when this request comes
227 // from a shape interaction.
228 if (rReq
.GetArgs() == NULL
)
230 bIntercept
= sal_True
;
238 SFX_APP()->ExecuteSlot(rReq
, SFX_APP()->GetInterface());
242 ErrorBox(NULL
, WB_OK
, String(SdResId(STR_CANT_PERFORM_IN_LIVEMODE
))).Execute();
244 SFX_REQUEST_ARG( rReq
, pLinkItem
, SfxLinkItem
, SID_DONELINK
, sal_False
);
246 pLinkItem
->GetValue().Call( 0 );
251 case SID_OUTLINE_TO_IMPRESS
:
252 OutlineToImpress (rReq
);
261 void SdModule::OutlineToImpress (SfxRequest
& rRequest
)
263 const SfxItemSet
* pSet
= rRequest
.GetArgs();
267 SvLockBytes
* pBytes
= ((SfxLockBytesItem
&) pSet
->Get(SID_OUTLINE_TO_IMPRESS
)).GetValue();
271 SfxObjectShellLock xDocShell
;
272 ::sd::DrawDocShell
* pDocSh
;
273 xDocShell
= pDocSh
= new ::sd::DrawDocShell(
274 SFX_CREATE_MODE_STANDARD
, sal_False
);
277 pDocSh
->DoInitNew(NULL
);
278 SdDrawDocument
* pDoc
= pDocSh
->GetDoc();
281 pDoc
->CreateFirstPages();
282 pDoc
->StopWorkStartupDelay();
285 SFX_REQUEST_ARG( rRequest
, pFrmItem
, SfxFrameItem
, SID_DOCFRAME
, sal_False
);
286 SfxViewFrame::LoadDocumentIntoFrame( *pDocSh
, pFrmItem
, ::sd::OUTLINE_FACTORY_ID
);
288 ::sd::ViewShell
* pViewSh
= pDocSh
->GetViewShell();
292 // AutoLayouts have to be finished
293 pDoc
->StopWorkStartupDelay();
295 SfxViewFrame
* pViewFrame
= pViewSh
->GetViewFrame();
297 // When the view frame has not been just created we have
298 // to switch synchronously to the outline view.
299 // (Otherwise the request will be ignored anyway.)
300 ::sd::ViewShellBase
* pBase
301 = dynamic_cast< ::sd::ViewShellBase
*>(pViewFrame
->GetViewShell());
304 ::boost::shared_ptr
<FrameworkHelper
> pHelper (
305 FrameworkHelper::Instance(*pBase
));
306 pHelper
->RequestView(
307 FrameworkHelper::msOutlineViewURL
,
308 FrameworkHelper::msCenterPaneURL
);
310 pHelper
->RunOnResourceActivation(
311 FrameworkHelper::CreateResourceId(
312 FrameworkHelper::msOutlineViewURL
,
313 FrameworkHelper::msCenterPaneURL
),
314 OutlineToImpressFinalizer(*pBase
, *pDoc
, *pBytes
));
325 static bool bOnce
= false;
327 void SdModule::GetState(SfxItemSet
& rItemSet
)
329 // disable Autopilot during presentation
330 if (rItemSet
.GetItemState(SID_SD_AUTOPILOT
) != SFX_ITEM_UNKNOWN
)
332 if (!SvtModuleOptions().IsImpress())
334 rItemSet
.DisableItem(SID_SD_AUTOPILOT
);
338 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
341 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
344 if( sd::SlideShow::IsRunning( pViewShell
->GetViewShellBase() ) )
346 rItemSet
.DisableItem(SID_SD_AUTOPILOT
);
353 if( SFX_ITEM_AVAILABLE
== rItemSet
.GetItemState( SID_ATTR_METRIC
) )
355 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current() );
358 DocumentType eDocType
= pDocSh
->GetDoc()->GetDocumentType();
360 SdOptions
* pOptions
= GetSdOptions(eDocType
);
361 rItemSet
.Put( SfxUInt16Item( SID_ATTR_METRIC
, pOptions
->GetMetric() ) );
365 // state of SID_OPENDOC is determined by the base class
366 if (rItemSet
.GetItemState(SID_OPENDOC
) != SFX_ITEM_UNKNOWN
)
368 const SfxPoolItem
* pItem
= SFX_APP()->GetSlotState(SID_OPENDOC
, SFX_APP()->GetInterface());
370 rItemSet
.Put(*pItem
);
373 // state of SID_OPENHYPERLINK is determined by the base class
374 if (rItemSet
.GetItemState(SID_OPENHYPERLINK
) != SFX_ITEM_UNKNOWN
)
376 const SfxPoolItem
* pItem
= SFX_APP()->GetSlotState(SID_OPENHYPERLINK
, SFX_APP()->GetInterface());
378 rItemSet
.Put(*pItem
);
381 if( SFX_ITEM_AVAILABLE
== rItemSet
.GetItemState( SID_AUTOSPELL_CHECK
) )
383 ::sd::DrawDocShell
* pDocSh
=
384 PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
387 SdDrawDocument
* pDoc
= pDocSh
->GetDoc();
388 rItemSet
.Put( SfxBoolItem( SID_AUTOSPELL_CHECK
, pDoc
->GetOnlineSpell() ) );
392 if( SFX_ITEM_AVAILABLE
== rItemSet
.GetItemState( SID_ATTR_LANGUAGE
) )
394 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
396 rItemSet
.Put( SvxLanguageItem( pDocSh
->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE
), SID_ATTR_LANGUAGE
) );
399 if( SFX_ITEM_AVAILABLE
== rItemSet
.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE
) )
401 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
403 rItemSet
.Put( SvxLanguageItem( pDocSh
->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CJK
), SID_ATTR_CHAR_CJK_LANGUAGE
) );
406 if( SFX_ITEM_AVAILABLE
== rItemSet
.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE
) )
408 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
410 rItemSet
.Put( SvxLanguageItem( pDocSh
->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CTL
), SID_ATTR_CHAR_CTL_LANGUAGE
) );
415 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
416 if( pDocShell
) // Impress or Draw ?
418 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
420 if( pViewShell
&& (pDocShell
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
) )
422 // add our event listener as soon as possible
423 Application::AddEventListener( LINK( this, SdModule
, EventListenerHdl
) );
430 IMPL_LINK( SdModule
, EventListenerHdl
, VclSimpleEvent
*, pEvent
)
432 if( pEvent
&& (pEvent
->GetId() == VCLEVENT_WINDOW_COMMAND
) && static_cast<VclWindowEvent
*>(pEvent
)->GetData() )
434 const CommandEvent
& rEvent
= *(const CommandEvent
*)static_cast<VclWindowEvent
*>(pEvent
)->GetData();
436 if( rEvent
.GetCommand() == COMMAND_MEDIA
)
438 switch( rEvent
.GetMediaCommand() )
440 case MEDIA_COMMAND_PLAY
:
442 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
443 if( pDocShell
) // Impress or Draw ?
445 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
447 // #i97925# start the presentation if and only if an Impress document is focused
448 if( pViewShell
&& (pDocShell
->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
) )
449 pViewShell
->GetViewFrame()->GetDispatcher()->Execute( SID_PRESENTATION
);
463 void SdModule::AddSummaryPage (SfxViewFrame
* pViewFrame
, SdDrawDocument
* pDocument
)
465 if( !pViewFrame
|| !pViewFrame
->GetDispatcher() || !pDocument
)
468 pViewFrame
->GetDispatcher()->Execute(SID_SUMMARY_PAGE
,
469 SFX_CALLMODE_SYNCHRON
| SFX_CALLMODE_RECORD
);
471 OSL_ASSERT (pDocument
!=NULL
);
473 sal_Int32 nPageCount
= pDocument
->GetSdPageCount (PK_STANDARD
);
475 // We need at least two pages: the summary page and one to use as
476 // template to take the transition parameters from.
479 // Get a page from which to retrieve the transition parameters.
480 SdPage
* pTemplatePage
= pDocument
->GetSdPage (0, PK_STANDARD
);
481 OSL_ASSERT (pTemplatePage
!=NULL
);
483 // The summary page, if it exists, is the last page.
484 SdPage
* pSummaryPage
= pDocument
->GetSdPage (
485 (sal_uInt16
)nPageCount
-1, PK_STANDARD
);
486 OSL_ASSERT (pSummaryPage
!=NULL
);
488 // Take the change mode of the template page as indication of the
489 // document's kiosk mode.
490 pSummaryPage
->setTransitionDuration(pTemplatePage
->getTransitionDuration());
491 pSummaryPage
->SetPresChange(pTemplatePage
->GetPresChange());
492 pSummaryPage
->SetTime(pTemplatePage
->GetTime());
493 pSummaryPage
->SetSound(pTemplatePage
->IsSoundOn());
494 pSummaryPage
->SetSoundFile(pTemplatePage
->GetSoundFile());
495 pSummaryPage
->setTransitionType(pTemplatePage
->getTransitionType());
496 pSummaryPage
->setTransitionSubtype(pTemplatePage
->getTransitionSubtype());
497 pSummaryPage
->setTransitionDirection(pTemplatePage
->getTransitionDirection());
498 pSummaryPage
->setTransitionFadeColor(pTemplatePage
->getTransitionFadeColor());
499 pSummaryPage
->setTransitionDuration(pTemplatePage
->getTransitionDuration());
503 SfxFrame
* SdModule::CreateFromTemplate( const String
& rTemplatePath
, const Reference
< XFrame
>& i_rFrame
)
505 SfxFrame
* pFrame
= 0;
507 SfxObjectShellLock xDocShell
;
509 SfxItemSet
* pSet
= new SfxAllItemSet( SFX_APP()->GetPool() );
510 pSet
->Put( SfxBoolItem( SID_TEMPLATE
, sal_True
) );
512 sal_uLong lErr
= SFX_APP()->LoadTemplate( xDocShell
, rTemplatePath
, sal_True
, pSet
);
514 SfxObjectShell
* pDocShell
= xDocShell
;
518 ErrorHandler::HandleError(lErr
);
522 SfxViewFrame
* pViewFrame
= SfxViewFrame::LoadDocumentIntoFrame( *pDocShell
, i_rFrame
);
523 OSL_ENSURE( pViewFrame
, "SdModule::CreateFromTemplate: no view frame - was the document really loaded?" );
524 pFrame
= pViewFrame
? &pViewFrame
->GetFrame() : NULL
;
531 SfxFrame
* SdModule::ExecuteNewDocument( SfxRequest
& rReq
)
533 SfxFrame
* pFrame
= 0;
534 if ( SvtModuleOptions().IsImpress() )
536 Reference
< XFrame
> xTargetFrame
;
537 SFX_REQUEST_ARG( rReq
, pFrmItem
, SfxUnoFrameItem
, SID_FILLFRAME
, sal_False
);
539 xTargetFrame
= pFrmItem
->GetFrame();
541 bool bMakeLayoutVisible
= false;
542 SfxViewFrame
* pViewFrame
= NULL
;
544 SdOptions
* pOpt
= GetSdOptions(DOCUMENT_TYPE_IMPRESS
);
545 bool bStartWithTemplate
= pOpt
->IsStartWithTemplate();
547 bool bNewDocDirect
= rReq
.GetSlot() == SID_NEWSD
;
548 if( bNewDocDirect
&& !bStartWithTemplate
)
550 //we start without wizard
552 //check whether we should load a template document
553 const OUString
aServiceName( "com.sun.star.presentation.PresentationDocument" );
554 String
aStandardTemplate( SfxObjectFactory::GetStandardTemplate( aServiceName
) );
556 if( aStandardTemplate
.Len() > 0 )
558 //load a template document
559 pFrame
= CreateFromTemplate( aStandardTemplate
, xTargetFrame
);
563 //create an empty document
564 pFrame
= CreateEmptyDocument( DOCUMENT_TYPE_IMPRESS
, xTargetFrame
);
565 bMakeLayoutVisible
= true;
570 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
571 boost::scoped_ptr
< AbstractAssistentDlg
> pPilotDlg( pFact
? pFact
->CreateAssistentDlg( NULL
, !bNewDocDirect
) : 0 );
574 if( pPilotDlg
.get() && pPilotDlg
->Execute()==RET_OK
)
576 const String
aDocPath( pPilotDlg
->GetDocPath());
577 const sal_Bool bIsDocEmpty
= pPilotDlg
->IsDocEmpty();
579 // So that you can open the document without AutoLayout-Dialog
580 pOpt
->SetStartWithTemplate(sal_False
);
581 if(bNewDocDirect
&& !pPilotDlg
->GetStartWithFlag())
582 bStartWithTemplate
= sal_False
;
584 if( pPilotDlg
->GetStartType() == ST_OPEN
)
586 String aFileToOpen
= aDocPath
;
588 DBG_ASSERT( aFileToOpen
.Len()!=0, "The autopilot should have asked for a file itself already!" );
589 if(aFileToOpen
.Len() != 0)
591 com::sun::star::uno::Sequence
< com::sun::star::beans::NamedValue
> aPasswrd( pPilotDlg
->GetPassword() );
593 SfxStringItem
aFile( SID_FILE_NAME
, aFileToOpen
);
594 SfxStringItem
aReferer( SID_REFERER
, OUString());
595 SfxUnoAnyItem
aPassword( SID_ENCRYPTIONDATA
, com::sun::star::uno::makeAny(aPasswrd
) );
597 if ( xTargetFrame
.is() )
599 SfxAllItemSet
aSet( *rReq
.GetArgs()->GetPool() );
601 aSet
.Put( aReferer
);
602 // Put the password into the request
603 // only if it is not empty.
604 if (aPasswrd
.getLength() > 0)
605 aSet
.Put( aPassword
);
607 const SfxPoolItem
* pRet
= SfxFrame::OpenDocumentSynchron( aSet
, xTargetFrame
);
608 const SfxViewFrameItem
* pFrameItem
= PTR_CAST( SfxViewFrameItem
, pRet
);
609 if ( pFrameItem
&& pFrameItem
->GetFrame() )
610 pFrame
= &pFrameItem
->GetFrame()->GetFrame();
614 SfxRequest
aRequest (SID_OPENDOC
, SFX_CALLMODE_SYNCHRON
, SFX_APP()->GetPool());
615 aRequest
.AppendItem (aFile
);
616 aRequest
.AppendItem (aReferer
);
617 // Put the password into the request
618 // only if it is not empty.
619 if (aPasswrd
.getLength() > 0)
620 aRequest
.AppendItem (aPassword
);
621 aRequest
.AppendItem (SfxStringItem (
623 OUString("_default")));
626 const SfxPoolItem
* pRet
= SFX_APP()->ExecuteSlot (aRequest
);
627 const SfxViewFrameItem
* pFrameItem
= PTR_CAST( SfxViewFrameItem
, pRet
);
629 pFrame
= &pFrameItem
->GetFrame()->GetFrame();
631 catch (const ::com::sun::star::uno::Exception
&)
633 DBG_ASSERT (sal_False
, "caught IllegalArgumentException while loading document from Impress autopilot");
638 pOpt
->SetStartWithTemplate(bStartWithTemplate
);
639 if(bNewDocDirect
&& !bStartWithTemplate
)
641 boost::scoped_ptr
< SfxItemSet
> pRet( CreateItemSet( SID_SD_EDITOPTIONS
) );
643 ApplyItemSet( SID_SD_EDITOPTIONS
, *pRet
.get() );
649 SfxObjectShellLock
xShell( pPilotDlg
->GetDocument() );
650 SfxObjectShell
* pShell
= xShell
;
653 pViewFrame
= SfxViewFrame::LoadDocumentIntoFrame( *pShell
, xTargetFrame
);
654 DBG_ASSERT( pViewFrame
, "no ViewFrame!!" );
655 pFrame
= pViewFrame
? &pViewFrame
->GetFrame() : NULL
;
657 if(bNewDocDirect
&& !bStartWithTemplate
)
659 boost::scoped_ptr
< SfxItemSet
> pRet( CreateItemSet( SID_SD_EDITOPTIONS
) );
661 ApplyItemSet( SID_SD_EDITOPTIONS
, *pRet
.get() );
664 if( pShell
&& pViewFrame
)
666 ::sd::DrawDocShell
* pDocShell
=
667 PTR_CAST(::sd::DrawDocShell
,pShell
);
668 SdDrawDocument
* pDoc
= pDocShell
->GetDoc();
670 ::sd::ViewShellBase
* pBase
=
671 ::sd::ViewShellBase::GetViewShellBase (
673 OSL_ASSERT (pBase
!=NULL
);
674 ::boost::shared_ptr
<sd::ViewShell
> pViewSh
= pBase
->GetMainViewShell();
675 SdOptions
* pOptions
= GetSdOptions(pDoc
->GetDocumentType());
677 if (pOptions
&& pViewSh
.get())
679 // The AutoPilot-document shall be open without its own options
680 ::sd::FrameView
* pFrameView
= pViewSh
->GetFrameView();
681 pFrameView
->Update(pOptions
);
682 pViewSh
->ReadFrameViewData(pFrameView
);
685 ChangeMedium( pDocShell
, pViewFrame
, pPilotDlg
->GetOutputMedium() );
687 if(pPilotDlg
->IsSummary())
688 AddSummaryPage(pViewFrame
, pDoc
);
691 if((aDocPath
.Len() == 0) && pViewFrame
&& pViewFrame
->GetDispatcher())
693 SfxBoolItem
aIsChangedItem(SID_MODIFYPAGE
, !bIsDocEmpty
);
694 SfxUInt32Item
eAutoLayout( ID_VAL_WHATLAYOUT
, (sal_uInt32
) AUTOLAYOUT_TITLE
);
695 pViewFrame
->GetDispatcher()->Execute(SID_MODIFYPAGE
,
696 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
, &aIsChangedItem
, &eAutoLayout
, 0L);
699 // clear document info
700 using namespace ::com::sun::star
;
701 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
702 pDocShell
->GetModel(), uno::UNO_QUERY_THROW
);
703 uno::Reference
<document::XDocumentProperties
>
704 xDocProps(xDPS
->getDocumentProperties());
705 DBG_ASSERT(xDocProps
.is(), "no DocumentProperties");
706 xDocProps
->resetUserData(
707 SvtUserOptions().GetFullName() );
708 xDocProps
->setTemplateName(xDocProps
->getTitle());
709 xDocProps
->setTemplateURL(pPilotDlg
->GetDocPath());
711 pDoc
->SetChanged(!bIsDocEmpty
);
713 pDocShell
->SetUseUserData(sal_True
);
715 // clear UNDO stack after autopilot
716 pDocShell
->ClearUndoBuffer();
718 bMakeLayoutVisible
= true;
721 pOpt
->SetStartWithTemplate(bStartWithTemplate
);
726 if (bMakeLayoutVisible
&& pViewFrame
!=NULL
)
728 // Make the layout menu visible in the tool pane.
729 ::sd::ViewShellBase
* pBase
= ::sd::ViewShellBase::GetViewShellBase(pViewFrame
);
732 FrameworkHelper::Instance(*pBase
)->RequestSidebarPanel(
733 FrameworkHelper::msLayoutTaskPanelURL
);
741 SfxFrame
* SdModule::CreateEmptyDocument( DocumentType eDocType
, const Reference
< XFrame
>& i_rFrame
)
743 SfxFrame
* pFrame
= 0;
745 SfxObjectShellLock xDocShell
;
746 ::sd::DrawDocShell
* pNewDocSh
;
747 xDocShell
= pNewDocSh
= new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD
,sal_False
,eDocType
);
750 pNewDocSh
->DoInitNew(NULL
);
751 SdDrawDocument
* pDoc
= pNewDocSh
->GetDoc();
754 pDoc
->CreateFirstPages();
755 pDoc
->StopWorkStartupDelay();
758 SfxViewFrame
* pViewFrame
= SfxViewFrame::LoadDocumentIntoFrame( *pNewDocSh
, i_rFrame
);
759 OSL_ENSURE( pViewFrame
, "SdModule::CreateEmptyDocument: no view frame - was the document really loaded?" );
760 pFrame
= pViewFrame
? &pViewFrame
->GetFrame() : NULL
;
766 void SdModule::ChangeMedium( ::sd::DrawDocShell
* pDocShell
, SfxViewFrame
* pViewFrame
, const sal_Int32 eMedium
)
771 SdDrawDocument
* pDoc
= pDocShell
->GetDoc();
775 // settings for the Outputmedium
777 sal_uInt32 nLeft
= 0;
778 sal_uInt32 nRight
= 0;
779 sal_uInt32 nLower
= 0;
780 sal_uInt32 nUpper
= 0;
784 case OUTPUT_OVERHEAD
:
786 SfxPrinter
* pPrinter
= pDocShell
->GetPrinter(sal_True
);
788 if( pPrinter
&& pPrinter
->IsValid())
790 // Unfortunately, the printer does not provide an exact format
792 Size
aSize(pPrinter
->GetPaperSize());
793 Paper ePaper
= SvxPaperInfo::GetSvxPaper( aSize
, MAP_100TH_MM
, sal_True
);
795 if (ePaper
!= PAPER_USER
)
798 aSize
= SvxPaperInfo::GetPaperSize(ePaper
, MAP_100TH_MM
);
801 if (aSize
.Height() > aSize
.Width())
804 aNewSize
.Width() = aSize
.Height();
805 aNewSize
.Height() = aSize
.Width();
814 aNewSize
=Size(29700, 21000);
817 if (eMedium
== OUTPUT_PAGE
)
836 aNewSize
= Size(27000, 18000);
844 case OUTPUT_WIDESCREEN
:
846 aNewSize
= Size(28000, 15750);
854 case OUTPUT_PRESENTATION
:
856 aNewSize
= Size(28000, 21000);
865 sal_Bool bScaleAll
= sal_True
;
866 sal_uInt16 nPageCnt
= pDoc
->GetMasterSdPageCount(PK_STANDARD
);
870 // master pages first
871 for (i
= 0; i
< nPageCnt
; i
++)
873 pPage
= pDoc
->GetMasterSdPage(i
, PK_STANDARD
);
877 if(eMedium
!= OUTPUT_ORIGINAL
)
879 Rectangle
aBorderRect(nLeft
, nUpper
, nRight
, nLower
);
880 pPage
->ScaleObjects(aNewSize
, aBorderRect
, bScaleAll
);
881 pPage
->SetSize(aNewSize
);
882 pPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
884 SdPage
* pNotesPage
= pDoc
->GetMasterSdPage(i
, PK_NOTES
);
885 DBG_ASSERT( pNotesPage
, "Wrong page ordering!" );
886 if( pNotesPage
) pNotesPage
->CreateTitleAndLayout();
887 pPage
->CreateTitleAndLayout();
891 nPageCnt
= pDoc
->GetSdPageCount(PK_STANDARD
);
894 for (i
= 0; i
< nPageCnt
; i
++)
896 pPage
= pDoc
->GetSdPage(i
, PK_STANDARD
);
900 if(eMedium
!= OUTPUT_ORIGINAL
)
902 Rectangle
aBorderRect(nLeft
, nUpper
, nRight
, nLower
);
903 pPage
->ScaleObjects(aNewSize
, aBorderRect
, bScaleAll
);
904 pPage
->SetSize(aNewSize
);
905 pPage
->SetBorder(nLeft
, nUpper
, nRight
, nLower
);
907 SdPage
* pNotesPage
= pDoc
->GetSdPage(i
, PK_NOTES
);
908 DBG_ASSERT( pNotesPage
, "Wrong page ordering!" );
909 if( pNotesPage
) pNotesPage
->SetAutoLayout( pNotesPage
->GetAutoLayout() );
910 pPage
->SetAutoLayout( pPage
->GetAutoLayout() );
914 SdPage
* pHandoutPage
= pDoc
->GetSdPage(0, PK_HANDOUT
);
915 pHandoutPage
->CreateTitleAndLayout(sal_True
);
917 if( (eMedium
!= OUTPUT_ORIGINAL
) && pViewFrame
&& pViewFrame
->GetDispatcher())
919 pViewFrame
->GetDispatcher()->Execute(SID_SIZE_PAGE
, SFX_CALLMODE_SYNCHRON
| SFX_CALLMODE_RECORD
);
926 //===== OutlineToImpressFinalize ==============================================
930 OutlineToImpressFinalizer::OutlineToImpressFinalizer (
931 ::sd::ViewShellBase
& rBase
,
932 SdDrawDocument
& rDocument
,
935 mrDocument(rDocument
),
938 // The given stream has a lifetime shorter than this new
939 // OutlineToImpressFinalizer object. Therefore a local copy of the
940 // stream is created.
941 const SvStream
* pStream (rBytes
.GetStream());
944 // Create a memory stream and prepare to fill it with the content of
945 // the original stream.
946 mpStream
.reset(new SvMemoryStream());
947 static const sal_Size nBufferSize
= 4096;
948 ::boost::scoped_array
<sal_Int8
> pBuffer (new sal_Int8
[nBufferSize
]);
950 sal_Size
nReadPosition (0);
954 // Read the next part of the original stream.
955 sal_Size
nReadByteCount (0);
956 const ErrCode
nErrorCode (
959 reinterpret_cast<void*>(pBuffer
.get()),
963 // Check the error code and stop copying the stream data when an
964 // error has occurred.
968 if (nReadByteCount
== 0)
971 case ERRCODE_IO_PENDING
:
980 // Append the read bytes to the end of the memory stream.
981 if (nReadByteCount
> 0)
983 mpStream
->Write(reinterpret_cast<void*>(pBuffer
.get()), nReadByteCount
);
984 nReadPosition
+= nReadByteCount
;
988 // Rewind the memory stream so that in the operator() method its
989 // content is properly read.
990 mpStream
->Seek(STREAM_SEEK_TO_BEGIN
);
997 void OutlineToImpressFinalizer::operator() (bool)
999 // Fetch the new outline view shell.
1000 ::sd::OutlineViewShell
* pOutlineShell
1001 = dynamic_cast<sd::OutlineViewShell
*>(FrameworkHelper::Instance(mrBase
)->GetViewShell(FrameworkHelper::msCenterPaneURL
).get());
1003 if (pOutlineShell
!= NULL
&& mpStream
.get() != NULL
)
1005 sd::OutlineView
* pView
= static_cast<sd::OutlineView
*>(pOutlineShell
->GetView());
1006 // mba: the stream can't contain any relative URLs, because we don't
1007 // have any information about a BaseURL!
1008 if ( pOutlineShell
->Read(*mpStream
, String(), EE_FORMAT_RTF
) == 0 )
1012 // Call UpdatePreview once for every slide to resync the
1013 // document with the outliner of the OutlineViewShell.
1014 sal_uInt16
nPageCount (mrDocument
.GetSdPageCount(PK_STANDARD
));
1015 for (sal_uInt16 nIndex
=0; nIndex
<nPageCount
; nIndex
++)
1017 SdPage
* pPage
= mrDocument
.GetSdPage(nIndex
, PK_STANDARD
);
1018 // Make the page the actual page so that the
1019 // following UpdatePreview() call accesses the
1020 // correct paragraphs.
1021 pView
->SetActualPage(pPage
);
1022 pOutlineShell
->UpdatePreview(pPage
, true);
1024 // Select the first slide.
1025 SdPage
* pPage
= mrDocument
.GetSdPage(0, PK_STANDARD
);
1026 pView
->SetActualPage(pPage
);
1027 pOutlineShell
->UpdatePreview(pPage
, true);
1031 // Undo-Stack needs to be cleared, else the user may remove the
1032 // only drawpage and this is a state we cannot handle ATM.
1033 ::sd::DrawDocShell
* pDocShell
= mrDocument
.GetDocSh();
1035 pDocShell
->ClearUndoBuffer();
1039 } // end of anonymous namespace
1041 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */