Update ooo320-m1
[ooovba.git] / sd / source / ui / app / sdmod1.cxx
blobb837633a09a8b047108d2cf4d1c5dcc71821939e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdmod1.cxx,v $
10 * $Revision: 1.52 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include <svtools/lckbitem.hxx>
35 #include <sfx2/frame.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <svtools/moduleoptions.hxx>
38 #include "framework/FrameworkHelper.hxx"
40 #include <svx/dialogs.hrc>
42 #include <svx/langitem.hxx>
43 #include <svx/editdata.hxx>
44 #include <vcl/msgbox.hxx>
45 #include <svx/svxenum.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <sfx2/request.hxx>
48 #include <sfx2/printer.hxx>
49 #include <sfx2/docfile.hxx>
50 #include <svx/paperinf.hxx>
51 #include <svx/eeitem.hxx>
52 #include <svtools/useroptions.hxx>
54 #include "app.hrc"
55 #include "glob.hrc"
56 #include "strings.hrc"
57 #include "res_bmp.hrc"
59 #define _SD_DLL // fuer SD_MOD()
60 #include "sdmod.hxx"
61 #include "sddll.hxx"
62 #include "pres.hxx"
63 #include "optsitem.hxx"
64 #include "ViewShell.hxx"
65 #include "sdattr.hxx"
66 #include "sdpage.hxx"
67 #include "DrawDocShell.hxx"
68 #include "drawdoc.hxx"
69 #include "assclass.hxx"
70 #include "sdenumdef.hxx"
71 #include "sdresid.hxx"
72 #include "OutlineViewShell.hxx"
73 #include "ViewShellBase.hxx"
74 #include "TaskPaneViewShell.hxx"
75 #ifndef SD_FRAMW_VIEW_HXX
76 #include "FrameView.hxx"
77 #endif
78 #include "FactoryIds.hxx"
79 #include "sdabstdlg.hxx"
80 #include <memory>
81 #include <boost/shared_ptr.hpp>
82 #include <boost/scoped_array.hpp>
83 #include "slideshow.hxx"
85 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
86 #include <com/sun/star/document/XDocumentProperties.hpp>
89 using ::sd::framework::FrameworkHelper;
91 namespace {
93 class OutlineToImpressFinalizer
95 public:
96 OutlineToImpressFinalizer (
97 ::sd::ViewShellBase& rBase,
98 SdDrawDocument& rDocument,
99 SvLockBytes& rBytes);
100 virtual ~OutlineToImpressFinalizer (void) {};
101 void operator() (bool bEventSeen);
102 private:
103 ::sd::ViewShellBase& mrBase;
104 SdDrawDocument& mrDocument;
105 ::boost::shared_ptr<SvMemoryStream> mpStream;
109 } //end of anonymous namespace
112 /*************************************************************************
114 |* Execute
116 \************************************************************************/
118 void SdModule::Execute(SfxRequest& rReq)
120 const SfxItemSet* pSet = rReq.GetArgs();
121 ULONG nSlotId = rReq.GetSlot();
123 switch ( nSlotId )
125 case SID_NEWDOC:
127 SFX_APP()->ExecuteSlot(rReq, SFX_APP()->GetInterface());
129 break;
131 case SID_AUTOSPELL_CHECK:
133 // automatische Rechtschreibpruefung
134 const SfxPoolItem* pItem;
135 if( pSet && SFX_ITEM_SET == pSet->GetItemState(
136 SID_AUTOSPELL_CHECK, FALSE, &pItem ) )
138 BOOL bOnlineSpelling = ( (const SfxBoolItem*) pItem )->GetValue();
139 // am Dokument sichern:
140 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
141 if( pDocSh )
143 SdDrawDocument* pDoc = pDocSh->GetDoc();
144 pDoc->SetOnlineSpell( bOnlineSpelling );
148 break;
150 case SID_ATTR_METRIC:
152 const SfxPoolItem* pItem;
153 if ( pSet && SFX_ITEM_SET == pSet->GetItemState( SID_ATTR_METRIC, TRUE, &pItem ) )
155 FieldUnit eUnit = (FieldUnit)((const SfxUInt16Item*)pItem)->GetValue();
156 switch( eUnit )
158 case FUNIT_MM: // nur die Einheiten, die auch im Dialog stehen
159 case FUNIT_CM:
160 case FUNIT_INCH:
161 case FUNIT_PICA:
162 case FUNIT_POINT:
164 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
165 if(pDocSh)
167 DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType();
169 PutItem( *pItem );
170 SdOptions* pOptions = GetSdOptions( eDocType );
171 if(pOptions)
172 pOptions->SetMetric( (UINT16)eUnit );
173 rReq.Done();
176 break;
177 default:
178 break;
183 break;
185 case SID_ATTR_LANGUAGE:
186 case SID_ATTR_CHAR_CJK_LANGUAGE:
187 case SID_ATTR_CHAR_CTL_LANGUAGE:
189 const SfxPoolItem* pItem;
190 if( pSet &&
192 SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_LANGUAGE, FALSE, &pItem ) ||
193 SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_CHAR_CJK_LANGUAGE, FALSE, &pItem ) ||
194 SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_CHAR_CTL_LANGUAGE, FALSE, &pItem )
198 // am Dokument sichern:
199 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
200 if ( pDocSh )
202 LanguageType eLanguage = ( (SvxLanguageItem*)pItem )->GetValue();
203 SdDrawDocument* pDoc = pDocSh->GetDoc();
205 if( nSlotId == SID_ATTR_CHAR_CJK_LANGUAGE )
206 pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE_CJK );
207 else if( nSlotId == SID_ATTR_CHAR_CTL_LANGUAGE )
208 pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE_CTL );
209 else
210 pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE );
212 if( pDoc->GetOnlineSpell() )
214 pDoc->StopOnlineSpelling();
215 pDoc->StartOnlineSpelling();
220 break;
222 case SID_SD_AUTOPILOT:
223 case SID_NEWSD:
225 SfxFrame* pFrame = ExecuteNewDocument( rReq );
226 // #94442# if a frame was created, set it as return value
227 if(pFrame)
228 rReq.SetReturnValue(SfxFrameItem(0, pFrame));
231 break;
233 case SID_OPENHYPERLINK:
234 case SID_OPENDOC:
236 BOOL bIntercept = FALSE;
237 ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
238 if (pDocShell)
240 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
241 if (pViewShell)
243 if( sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() ) )
245 // Prevent documents from opening while the slide
246 // show is running, except when this request comes
247 // from a shape interaction.
248 if (rReq.GetArgs() == NULL)
250 bIntercept = TRUE;
256 if (!bIntercept)
258 SFX_APP()->ExecuteSlot(rReq, SFX_APP()->GetInterface());
260 else
262 ErrorBox(NULL, WB_OK, String(SdResId(STR_CANT_PERFORM_IN_LIVEMODE))).Execute();
264 SFX_REQUEST_ARG( rReq, pLinkItem, SfxLinkItem, SID_DONELINK, FALSE );
265 if( pLinkItem )
266 pLinkItem->GetValue().Call( 0 );
269 break;
271 case SID_OUTLINE_TO_IMPRESS:
272 OutlineToImpress (rReq);
273 break;
275 default:
276 break;
283 void SdModule::OutlineToImpress (SfxRequest& rRequest)
285 const SfxItemSet* pSet = rRequest.GetArgs();
287 if (pSet)
289 SvLockBytes* pBytes = ((SfxLockBytesItem&) pSet->Get(SID_OUTLINE_TO_IMPRESS)).GetValue();
291 if (pBytes)
293 SfxObjectShellLock xDocShell;
294 ::sd::DrawDocShell* pDocSh;
295 xDocShell = pDocSh = new ::sd::DrawDocShell(
296 SFX_CREATE_MODE_STANDARD, FALSE);
297 if(pDocSh)
299 pDocSh->DoInitNew(NULL);
300 SdDrawDocument* pDoc = pDocSh->GetDoc();
301 if(pDoc)
303 pDoc->CreateFirstPages();
304 pDoc->StopWorkStartupDelay();
307 SFX_REQUEST_ARG( rRequest, pFrmItem, SfxFrameItem, SID_DOCFRAME, FALSE);
308 if ( pFrmItem )
310 SfxFrame* pFrame = pFrmItem->GetFrame();
311 pFrame->InsertDocument( pDocSh );
313 else
314 SfxViewFrame::CreateViewFrame(*pDocSh, ::sd::OUTLINE_FACTORY_ID);
316 ::sd::ViewShell* pViewSh = pDocSh->GetViewShell();
318 if (pViewSh)
320 // AutoLayouts muessen fertig sein
321 pDoc->StopWorkStartupDelay();
323 SfxViewFrame* pViewFrame = pViewSh->GetViewFrame();
325 // When the view frame has not been just created we have
326 // to switch synchronously to the outline view.
327 // (Otherwise the request will be ignored anyway.)
328 ::sd::ViewShellBase* pBase
329 = dynamic_cast< ::sd::ViewShellBase*>(pViewFrame->GetViewShell());
330 if (pBase != NULL)
332 ::boost::shared_ptr<FrameworkHelper> pHelper (
333 FrameworkHelper::Instance(*pBase));
334 pHelper->RequestView(
335 FrameworkHelper::msOutlineViewURL,
336 FrameworkHelper::msCenterPaneURL);
338 pHelper->RunOnResourceActivation(
339 FrameworkHelper::CreateResourceId(
340 FrameworkHelper::msOutlineViewURL,
341 FrameworkHelper::msCenterPaneURL),
342 OutlineToImpressFinalizer(*pBase, *pDoc, *pBytes));
349 rRequest.IsDone();
355 /*************************************************************************
357 |* GetState
359 \************************************************************************/
361 static bool bOnce = false;
363 void SdModule::GetState(SfxItemSet& rItemSet)
365 // Autopilot waehrend der Praesentation disablen
366 if (rItemSet.GetItemState(SID_SD_AUTOPILOT) != SFX_ITEM_UNKNOWN)
368 if (!SvtModuleOptions().IsImpress())
370 rItemSet.DisableItem(SID_SD_AUTOPILOT);
372 else
374 ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
375 if (pDocShell)
377 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
378 if (pViewShell)
380 if( sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() ) )
382 rItemSet.DisableItem(SID_SD_AUTOPILOT);
389 if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_ATTR_METRIC ) )
391 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
392 if(pDocSh)
394 DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType();
396 SdOptions* pOptions = GetSdOptions(eDocType);
397 rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, pOptions->GetMetric() ) );
401 // der Status von SID_OPENDOC wird von der Basisklasse bestimmt
402 if (rItemSet.GetItemState(SID_OPENDOC) != SFX_ITEM_UNKNOWN)
404 const SfxPoolItem* pItem = SFX_APP()->GetSlotState(SID_OPENDOC, SFX_APP()->GetInterface());
405 if (pItem)
406 rItemSet.Put(*pItem);
409 // der Status von SID_OPENHYPERLINK wird von der Basisklasse bestimmt
410 if (rItemSet.GetItemState(SID_OPENHYPERLINK) != SFX_ITEM_UNKNOWN)
412 const SfxPoolItem* pItem = SFX_APP()->GetSlotState(SID_OPENHYPERLINK, SFX_APP()->GetInterface());
413 if (pItem)
414 rItemSet.Put(*pItem);
417 if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_AUTOSPELL_CHECK ) )
419 ::sd::DrawDocShell* pDocSh =
420 PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
421 if( pDocSh )
423 SdDrawDocument* pDoc = pDocSh->GetDoc();
424 rItemSet.Put( SfxBoolItem( SID_AUTOSPELL_CHECK, pDoc->GetOnlineSpell() ) );
428 if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_ATTR_LANGUAGE ) )
430 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
431 if( pDocSh )
432 rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE ) );
435 if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE ) )
437 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
438 if( pDocSh )
439 rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CJK ), SID_ATTR_CHAR_CJK_LANGUAGE ) );
442 if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE ) )
444 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
445 if( pDocSh )
446 rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CTL ), SID_ATTR_CHAR_CTL_LANGUAGE ) );
449 if ( !bOnce )
451 ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
452 if( pDocShell ) // Impress or Draw ?
454 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
456 if( pViewShell && (pDocShell->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) )
458 // add our event listener as soon as possible
459 Application::AddEventListener( LINK( this, SdModule, EventListenerHdl ) );
460 bOnce = true;
466 IMPL_LINK( SdModule, EventListenerHdl, VclSimpleEvent*, pEvent )
468 if( pEvent && (pEvent->GetId() == VCLEVENT_WINDOW_COMMAND) && static_cast<VclWindowEvent*>(pEvent)->GetData() )
470 const CommandEvent& rEvent = *(const CommandEvent*)static_cast<VclWindowEvent*>(pEvent)->GetData();
472 if( rEvent.GetCommand() == COMMAND_MEDIA )
474 switch( rEvent.GetMediaCommand() )
476 case MEDIA_COMMAND_PLAY:
478 ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
479 if( pDocShell ) // Impress or Draw ?
481 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
483 // #i97925# start the presentation if and only if an Impress document is focused
484 if( pViewShell && (pDocShell->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) )
485 pViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_PRESENTATION );
488 break;
490 default:
491 break;
495 return 0;
499 void SdModule::AddSummaryPage (SfxViewFrame* pViewFrame, SdDrawDocument* pDocument)
501 if( !pViewFrame || !pViewFrame->GetDispatcher() || !pDocument )
502 return;
504 pViewFrame->GetDispatcher()->Execute(SID_SUMMARY_PAGE,
505 SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
507 OSL_ASSERT (pDocument!=NULL);
509 sal_Int32 nPageCount = pDocument->GetSdPageCount (PK_STANDARD);
511 // We need at least two pages: the summary page and one to use as
512 // template to take the transition parameters from.
513 if (nPageCount >= 2)
515 // Get a page from which to retrieve the transition parameters.
516 SdPage* pTemplatePage = pDocument->GetSdPage (0, PK_STANDARD);
517 OSL_ASSERT (pTemplatePage!=NULL);
519 // The summary page, if it exists, is the last page.
520 SdPage* pSummaryPage = pDocument->GetSdPage (
521 (USHORT)nPageCount-1, PK_STANDARD);
522 OSL_ASSERT (pSummaryPage!=NULL);
524 // Take the change mode of the template page as indication of the
525 // document's kiosk mode.
526 pSummaryPage->setTransitionDuration(pTemplatePage->getTransitionDuration());
527 pSummaryPage->SetPresChange(pTemplatePage->GetPresChange());
528 pSummaryPage->SetTime(pTemplatePage->GetTime());
529 pSummaryPage->SetSound(pTemplatePage->IsSoundOn());
530 pSummaryPage->SetSoundFile(pTemplatePage->GetSoundFile());
531 pSummaryPage->setTransitionType(pTemplatePage->getTransitionType());
532 pSummaryPage->setTransitionSubtype(pTemplatePage->getTransitionSubtype());
533 pSummaryPage->setTransitionDirection(pTemplatePage->getTransitionDirection());
534 pSummaryPage->setTransitionFadeColor(pTemplatePage->getTransitionFadeColor());
535 pSummaryPage->setTransitionDuration(pTemplatePage->getTransitionDuration());
539 SfxFrame* SdModule::CreateFromTemplate( const String& rTemplatePath, SfxFrame* pTargetFrame )
541 SfxFrame* pFrame = 0;
543 SfxObjectShellLock xDocShell;
545 SfxItemSet* pSet = new SfxAllItemSet( SFX_APP()->GetPool() );
546 pSet->Put( SfxBoolItem( SID_TEMPLATE, TRUE ) );
548 ULONG lErr = SFX_APP()->LoadTemplate( xDocShell, rTemplatePath, TRUE, pSet );
550 SfxObjectShell* pDocShell = xDocShell;
552 if( lErr )
554 ErrorHandler::HandleError(lErr);
556 else if( pDocShell )
558 if ( pTargetFrame )
560 pFrame = pTargetFrame;
561 pFrame->InsertDocument( pDocShell );
563 else
565 SfxViewFrame* pViewFrame = SfxViewFrame::CreateViewFrame( *pDocShell );
566 if( pViewFrame )
567 pFrame = pViewFrame->GetFrame();
571 return pFrame;
575 SfxFrame* SdModule::ExecuteNewDocument( SfxRequest& rReq )
577 SfxFrame* pFrame = 0;
578 if ( SvtModuleOptions().IsImpress() )
580 SfxFrame* pTargetFrame = 0;
581 SFX_REQUEST_ARG( rReq, pFrmItem, SfxFrameItem, SID_DOCFRAME, FALSE);
582 if ( pFrmItem )
583 pTargetFrame = pFrmItem->GetFrame();
585 bool bMakeLayoutVisible = false;
586 SfxViewFrame* pViewFrame = NULL;
588 SdOptions* pOpt = GetSdOptions(DOCUMENT_TYPE_IMPRESS);
589 bool bStartWithTemplate = pOpt->IsStartWithTemplate();
591 bool bNewDocDirect = rReq.GetSlot() == SID_NEWSD;
592 if( bNewDocDirect && !bStartWithTemplate )
594 //we start without wizard
596 //check wether we should load a template document
597 const ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) );
598 String aStandardTemplate( SfxObjectFactory::GetStandardTemplate( aServiceName ) );
600 if( aStandardTemplate.Len() > 0 )
602 //load a template document
603 pFrame = CreateFromTemplate( aStandardTemplate, pTargetFrame );
605 else
607 //create an empty document
608 pFrame = CreateEmptyDocument( DOCUMENT_TYPE_IMPRESS, pTargetFrame );
609 bMakeLayoutVisible = true;
612 else
614 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
615 std::auto_ptr< AbstractAssistentDlg > pPilotDlg( pFact ? pFact->CreateAssistentDlg( NULL, !bNewDocDirect ) : 0 );
617 // Open the Pilot
618 if( pPilotDlg.get() && pPilotDlg->Execute()==RET_OK )
620 const String aDocPath( pPilotDlg->GetDocPath());
621 const sal_Bool bIsDocEmpty = pPilotDlg->IsDocEmpty();
623 // So that you can open the document without AutoLayout-Dialog
624 pOpt->SetStartWithTemplate(FALSE);
625 if(bNewDocDirect && !pPilotDlg->GetStartWithFlag())
626 bStartWithTemplate = FALSE;
628 if( pPilotDlg->GetStartType() == ST_OPEN )
630 String aFileToOpen = aDocPath;
632 DBG_ASSERT( aFileToOpen.Len()!=0, "The autopilot should have asked for a file itself already!" );
633 if(aFileToOpen.Len() != 0)
635 const String aPasswrd( pPilotDlg->GetPassword() );
637 SfxStringItem aFile( SID_FILE_NAME, aFileToOpen );
638 SfxStringItem aReferer( SID_REFERER, UniString() );
639 SfxStringItem aPassword( SID_PASSWORD, aPasswrd );
641 if ( pTargetFrame )
643 SfxAllItemSet aSet( *rReq.GetArgs()->GetPool() );
644 aSet.Put( aFile );
645 aSet.Put( aReferer );
646 // Put the password into the request
647 // only if it is not empty.
648 if (aPasswrd.Len() > 0)
649 aSet.Put( aPassword );
651 const SfxPoolItem* pRet = pTargetFrame->LoadDocumentSynchron( aSet );
652 const SfxViewFrameItem* pFrameItem = PTR_CAST( SfxViewFrameItem, pRet );
653 if ( pFrameItem && pFrameItem->GetFrame() )
654 pFrame = pFrameItem->GetFrame()->GetFrame();
656 else
658 SfxRequest aRequest (SID_OPENDOC, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool());
659 aRequest.AppendItem (aFile);
660 aRequest.AppendItem (aReferer);
661 // Put the password into the request
662 // only if it is not empty.
663 if (aPasswrd.Len() > 0)
664 aRequest.AppendItem (aPassword);
665 aRequest.AppendItem (SfxStringItem (
666 SID_TARGETNAME,
667 String (RTL_CONSTASCII_USTRINGPARAM ("_default"))));
670 const SfxPoolItem* pRet = SFX_APP()->ExecuteSlot (aRequest);
671 const SfxViewFrameItem* pFrameItem = PTR_CAST( SfxViewFrameItem, pRet );
672 if ( pFrameItem )
673 pFrame = pFrameItem->GetFrame()->GetFrame();
675 catch (::com::sun::star::uno::Exception e)
677 DBG_ASSERT (FALSE, "caught IllegalArgumentException while loading document from Impress autopilot");
682 pOpt->SetStartWithTemplate(bStartWithTemplate);
683 if(bNewDocDirect && !bStartWithTemplate)
685 std::auto_ptr< SfxItemSet > pRet( CreateItemSet( SID_SD_EDITOPTIONS ) );
686 if(pRet.get())
687 ApplyItemSet( SID_SD_EDITOPTIONS, *pRet.get() );
691 else
693 SfxObjectShellLock xShell( pPilotDlg->GetDocument() );
694 SfxObjectShell* pShell = xShell;
695 if( pShell )
697 if ( pTargetFrame )
699 pFrame = pTargetFrame;
700 pFrame->InsertDocument( pShell );
701 pViewFrame = pFrame->GetCurrentViewFrame();
703 else
705 pViewFrame = SfxViewFrame::CreateViewFrame( *pShell );
706 if( pViewFrame )
707 pFrame = pViewFrame->GetFrame();
710 DBG_ASSERT( pViewFrame, "no ViewFrame!!" );
712 if(bNewDocDirect && !bStartWithTemplate)
714 std::auto_ptr< SfxItemSet > pRet( CreateItemSet( SID_SD_EDITOPTIONS ) );
715 if(pRet.get())
716 ApplyItemSet( SID_SD_EDITOPTIONS, *pRet.get() );
719 if( pShell && pViewFrame )
721 ::sd::DrawDocShell* pDocShell =
722 PTR_CAST(::sd::DrawDocShell,pShell);
723 SdDrawDocument* pDoc = pDocShell->GetDoc();
725 ::sd::ViewShellBase* pBase =
726 ::sd::ViewShellBase::GetViewShellBase (
727 pViewFrame);
728 OSL_ASSERT (pBase!=NULL);
729 ::boost::shared_ptr<sd::ViewShell> pViewSh = pBase->GetMainViewShell();
730 SdOptions* pOptions = GetSdOptions(pDoc->GetDocumentType());
732 if (pOptions && pViewSh.get())
734 // The AutoPilot-document shall be open without its own options
735 ::sd::FrameView* pFrameView = pViewSh->GetFrameView();
736 pFrameView->Update(pOptions);
737 pViewSh->ReadFrameViewData(pFrameView);
740 ChangeMedium( pDocShell, pViewFrame, pPilotDlg->GetOutputMedium() );
742 if(pPilotDlg->IsSummary())
743 AddSummaryPage(pViewFrame, pDoc);
745 // empty document
746 if((aDocPath.Len() == 0) && pViewFrame && pViewFrame->GetDispatcher())
748 SfxBoolItem aIsChangedItem(SID_MODIFYPAGE, !bIsDocEmpty);
749 SfxUInt32Item eAutoLayout( ID_VAL_WHATLAYOUT, (UINT32) AUTOLAYOUT_TITLE );
750 pViewFrame->GetDispatcher()->Execute(SID_MODIFYPAGE,
751 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aIsChangedItem, &eAutoLayout, 0L);
754 // clear document info
755 using namespace ::com::sun::star;
756 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
757 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
758 uno::Reference<document::XDocumentProperties>
759 xDocProps(xDPS->getDocumentProperties());
760 DBG_ASSERT(xDocProps.is(), "no DocumentProperties");
761 xDocProps->resetUserData(
762 SvtUserOptions().GetFullName() );
763 xDocProps->setTemplateName(xDocProps->getTitle());
764 xDocProps->setTemplateURL(pPilotDlg->GetDocPath());
766 pDoc->SetChanged(!bIsDocEmpty);
768 pDocShell->SetUseUserData(TRUE);
770 // #94652# clear UNDO stack after autopilot
771 pDocShell->ClearUndoBuffer();
773 bMakeLayoutVisible = true;
776 pOpt->SetStartWithTemplate(bStartWithTemplate);
781 if (bMakeLayoutVisible && pViewFrame!=NULL)
783 // Make the layout menu visible in the tool pane.
784 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase(pViewFrame);
785 if (pBase != NULL)
787 FrameworkHelper::Instance(*pBase)->RequestTaskPanel(
788 FrameworkHelper::msLayoutTaskPanelURL);
793 return pFrame;
796 SfxFrame* SdModule::CreateEmptyDocument( DocumentType eDocType, SfxFrame* pTargetFrame )
798 SfxFrame* pFrame = 0;
800 SfxObjectShellLock xDocShell;
801 ::sd::DrawDocShell* pNewDocSh;
802 xDocShell = pNewDocSh = new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD,FALSE,eDocType);
803 if(pNewDocSh)
805 pNewDocSh->DoInitNew(NULL);
806 SdDrawDocument* pDoc = pNewDocSh->GetDoc();
807 if(pDoc)
809 pDoc->CreateFirstPages();
810 pDoc->StopWorkStartupDelay();
813 if ( pTargetFrame )
815 pFrame = pTargetFrame;
816 pFrame->InsertDocument( pNewDocSh );
818 else
820 SfxViewFrame* pViewFrame = SfxViewFrame::CreateViewFrame( *pNewDocSh );
821 if( pViewFrame )
822 pFrame = pViewFrame->GetFrame();
826 return pFrame;
829 void SdModule::ChangeMedium( ::sd::DrawDocShell* pDocShell, SfxViewFrame* pViewFrame, const sal_Int32 eMedium )
831 if( !pDocShell )
832 return;
834 SdDrawDocument* pDoc = pDocShell->GetDoc();
835 if( !pDoc )
836 return;
838 // settings for the Outputmedium
839 Size aNewSize;
840 UINT32 nLeft = 0;
841 UINT32 nRight = 0;
842 UINT32 nLower = 0;
843 UINT32 nUpper = 0;
844 switch(eMedium)
846 case OUTPUT_PAGE:
847 case OUTPUT_OVERHEAD:
849 SfxPrinter* pPrinter = pDocShell->GetPrinter(TRUE);
851 if( pPrinter && pPrinter->IsValid())
853 // Der Printer gibt leider kein exaktes
854 // Format (z.B. A4) zurueck
855 Size aSize(pPrinter->GetPaperSize());
856 Paper ePaper = SvxPaperInfo::GetSvxPaper( aSize, MAP_100TH_MM, TRUE);
858 if (ePaper != PAPER_USER)
860 // Korrekte Size holen
861 aSize = SvxPaperInfo::GetPaperSize(ePaper, MAP_100TH_MM);
864 if (aSize.Height() > aSize.Width())
866 // Stets Querformat
867 aNewSize.Width() = aSize.Height();
868 aNewSize.Height() = aSize.Width();
870 else
872 aNewSize = aSize;
875 else
877 aNewSize=Size(29700, 21000);
880 if (eMedium == OUTPUT_PAGE)
882 nLeft =1000;
883 nRight=1000;
884 nUpper=1000;
885 nLower=1000;
887 else
889 nLeft =0;
890 nRight=0;
891 nUpper=0;
892 nLower=0;
895 break;
897 case OUTPUT_SLIDE:
899 aNewSize = Size(27000, 18000);
900 nLeft =0;
901 nRight=0;
902 nUpper=0;
903 nLower=0;
905 break;
907 case OUTPUT_PRESENTATION:
909 aNewSize = Size(28000, 21000);
910 nLeft =0;
911 nRight=0;
912 nUpper=0;
913 nLower=0;
915 break;
918 BOOL bScaleAll = TRUE;
919 USHORT nPageCnt = pDoc->GetMasterSdPageCount(PK_STANDARD);
920 USHORT i;
921 SdPage* pPage;
923 // master pages first
924 for (i = 0; i < nPageCnt; i++)
926 pPage = pDoc->GetMasterSdPage(i, PK_STANDARD);
928 if (pPage)
930 if(eMedium != OUTPUT_ORIGINAL)
932 Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
933 pPage->ScaleObjects(aNewSize, aBorderRect, bScaleAll);
934 pPage->SetSize(aNewSize);
935 pPage->SetBorder(nLeft, nUpper, nRight, nLower);
937 SdPage* pNotesPage = pDoc->GetMasterSdPage(i, PK_NOTES);
938 DBG_ASSERT( pNotesPage, "Wrong page ordering!" );
939 if( pNotesPage ) pNotesPage->CreateTitleAndLayout();
940 pPage->CreateTitleAndLayout();
944 nPageCnt = pDoc->GetSdPageCount(PK_STANDARD);
946 // then slides
947 for (i = 0; i < nPageCnt; i++)
949 pPage = pDoc->GetSdPage(i, PK_STANDARD);
951 if (pPage)
953 if(eMedium != OUTPUT_ORIGINAL)
955 Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
956 pPage->ScaleObjects(aNewSize, aBorderRect, bScaleAll);
957 pPage->SetSize(aNewSize);
958 pPage->SetBorder(nLeft, nUpper, nRight, nLower);
960 SdPage* pNotesPage = pDoc->GetSdPage(i, PK_NOTES);
961 DBG_ASSERT( pNotesPage, "Wrong page ordering!" );
962 if( pNotesPage ) pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() );
963 pPage->SetAutoLayout( pPage->GetAutoLayout() );
967 SdPage* pHandoutPage = pDoc->GetSdPage(0, PK_HANDOUT);
968 pHandoutPage->CreateTitleAndLayout(TRUE);
970 if( (eMedium != OUTPUT_ORIGINAL) && pViewFrame && pViewFrame->GetDispatcher())
972 pViewFrame->GetDispatcher()->Execute(SID_SIZE_PAGE, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
979 //===== OutlineToImpressFinalize ==============================================
981 namespace {
983 OutlineToImpressFinalizer::OutlineToImpressFinalizer (
984 ::sd::ViewShellBase& rBase,
985 SdDrawDocument& rDocument,
986 SvLockBytes& rBytes)
987 : mrBase(rBase),
988 mrDocument(rDocument),
989 mpStream()
991 // The given stream has a lifetime shorter than this new
992 // OutlineToImpressFinalizer object. Therefore a local copy of the
993 // stream is created.
994 const SvStream* pStream (rBytes.GetStream());
995 if (pStream != NULL)
997 // Create a memory stream and prepare to fill it with the content of
998 // the original stream.
999 mpStream.reset(new SvMemoryStream());
1000 static const sal_Size nBufferSize = 4096;
1001 ::boost::scoped_array<sal_Int8> pBuffer (new sal_Int8[nBufferSize]);
1003 sal_Size nReadPosition (0);
1004 bool bLoop (true);
1005 while (bLoop)
1007 // Read the next part of the original stream.
1008 sal_Size nReadByteCount (0);
1009 const ErrCode nErrorCode (
1010 rBytes.ReadAt(
1011 nReadPosition,
1012 reinterpret_cast<void*>(pBuffer.get()),
1013 nBufferSize,
1014 &nReadByteCount));
1016 // Check the error code and stop copying the stream data when an
1017 // error has occured.
1018 switch (nErrorCode)
1020 case ERRCODE_NONE:
1021 if (nReadByteCount == 0)
1022 bLoop = false;
1023 break;
1024 case ERRCODE_IO_PENDING:
1025 break;
1027 default:
1028 bLoop = false;
1029 nReadByteCount = 0;
1030 break;
1033 // Append the read bytes to the end of the memory stream.
1034 if (nReadByteCount > 0)
1036 mpStream->Write(reinterpret_cast<void*>(pBuffer.get()), nReadByteCount);
1037 nReadPosition += nReadByteCount;
1041 // Rewind the memory stream so that in the operator() method its
1042 // content is properly read.
1043 mpStream->Seek(STREAM_SEEK_TO_BEGIN);
1050 void OutlineToImpressFinalizer::operator() (bool)
1052 // Fetch the new outline view shell.
1053 ::sd::OutlineViewShell* pOutlineShell
1054 = dynamic_cast<sd::OutlineViewShell*>(FrameworkHelper::Instance(mrBase)->GetViewShell(FrameworkHelper::msCenterPaneURL).get());
1056 if (pOutlineShell != NULL && mpStream.get() != NULL)
1058 sd::OutlineView* pView = static_cast<sd::OutlineView*>(pOutlineShell->GetView());
1059 // mba: the stream can't contain any relative URLs, because we don't
1060 // have any information about a BaseURL!
1061 if ( pOutlineShell->Read(*mpStream, String(), EE_FORMAT_RTF) == 0 )
1064 sd::OutlineViewPageChangesGuard aGuard( pView );
1066 // Remove the first empty pages
1067 USHORT nPageCount = mrDocument.GetPageCount();
1068 mrDocument.RemovePage( --nPageCount ); // notes page
1069 mrDocument.RemovePage( --nPageCount ); // standard page
1073 // Call UpdatePreview once for every slide to resync the
1074 // document with the outliner of the OutlineViewShell.
1075 USHORT nPageCount (mrDocument.GetSdPageCount(PK_STANDARD));
1076 for (USHORT nIndex=0; nIndex<nPageCount; nIndex++)
1078 SdPage* pPage = mrDocument.GetSdPage(nIndex, PK_STANDARD);
1079 // Make the page the actual page so that the
1080 // following UpdatePreview() call accesses the
1081 // correct paragraphs.
1082 pView->SetActualPage(pPage);
1083 pOutlineShell->UpdatePreview(pPage, true);
1085 // Select the first slide.
1086 SdPage* pPage = mrDocument.GetSdPage(0, PK_STANDARD);
1087 pView->SetActualPage(pPage);
1088 pOutlineShell->UpdatePreview(pPage, true);
1092 // #97231# Undo-Stack needs to be cleared, else the user may remove the
1093 // only drawpage and this is a state we cannot handle ATM.
1094 ::sd::DrawDocShell* pDocShell = mrDocument.GetDocSh();
1095 if( pDocShell )
1096 pDocShell->ClearUndoBuffer();
1100 } // end of anonymous namespace