xref: /trunk/main/sd/source/ui/app/sdmod1.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include <svl/lckbitem.hxx>
32 #include <sfx2/frame.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <unotools/moduleoptions.hxx>
35 #include "framework/FrameworkHelper.hxx"
36 
37 #include <svx/dialogs.hrc>
38 
39 #include <editeng/langitem.hxx>
40 #include <editeng/editdata.hxx>
41 #include <vcl/msgbox.hxx>
42 #include <editeng/svxenum.hxx>
43 #include <sfx2/dispatch.hxx>
44 #include <sfx2/request.hxx>
45 #include <sfx2/printer.hxx>
46 #include <sfx2/docfile.hxx>
47 #include <editeng/paperinf.hxx>
48 #include <editeng/eeitem.hxx>
49 #include <unotools/useroptions.hxx>
50 
51 #include "app.hrc"
52 #include "glob.hrc"
53 #include "strings.hrc"
54 #include "res_bmp.hrc"
55 
56 #define _SD_DLL                 // fuer SD_MOD()
57 #include "sdmod.hxx"
58 #include "sddll.hxx"
59 #include "pres.hxx"
60 #include "optsitem.hxx"
61 #include "ViewShell.hxx"
62 #include "sdattr.hxx"
63 #include "sdpage.hxx"
64 #include "DrawDocShell.hxx"
65 #include "drawdoc.hxx"
66 #include "assclass.hxx"
67 #include "sdenumdef.hxx"
68 #include "sdresid.hxx"
69 #include "OutlineViewShell.hxx"
70 #include "ViewShellBase.hxx"
71 #ifndef SD_FRAMW_VIEW_HXX
72 #include "FrameView.hxx"
73 #endif
74 #include "FactoryIds.hxx"
75 #include "sdabstdlg.hxx"
76 #include <memory>
77 #include <boost/shared_ptr.hpp>
78 #include <boost/scoped_array.hpp>
79 #include "slideshow.hxx"
80 
81 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
82 #include <com/sun/star/document/XDocumentProperties.hpp>
83 
84 
85 using ::sd::framework::FrameworkHelper;
86 using ::com::sun::star::uno::Reference;
87 using ::com::sun::star::frame::XFrame;
88 
89 namespace {
90 
91 class OutlineToImpressFinalizer
92 {
93 public:
94     OutlineToImpressFinalizer (
95         ::sd::ViewShellBase& rBase,
96         SdDrawDocument& rDocument,
97         SvLockBytes& rBytes);
98     virtual ~OutlineToImpressFinalizer (void) {};
99     void operator() (bool bEventSeen);
100 private:
101     ::sd::ViewShellBase& mrBase;
102     SdDrawDocument& mrDocument;
103     ::boost::shared_ptr<SvMemoryStream> mpStream;
104 };
105 
106 
107 } //end of anonymous namespace
108 
109 
110 /*************************************************************************
111 |*
112 |* Execute
113 |*
114 \************************************************************************/
115 
116 void SdModule::Execute(SfxRequest& rReq)
117 {
118     const SfxItemSet* pSet = rReq.GetArgs();
119     sal_uLong nSlotId = rReq.GetSlot();
120 
121     switch ( nSlotId )
122     {
123         case SID_NEWDOC:
124         {
125             SFX_APP()->ExecuteSlot(rReq, SFX_APP()->GetInterface());
126         }
127         break;
128 
129         case SID_AUTOSPELL_CHECK:
130         {
131             // automatische Rechtschreibpruefung
132             const SfxPoolItem* pItem;
133             if( pSet && SFX_ITEM_SET == pSet->GetItemState(
134                         SID_AUTOSPELL_CHECK, sal_False, &pItem ) )
135             {
136                 sal_Bool bOnlineSpelling = ( (const SfxBoolItem*) pItem )->GetValue();
137                 // am Dokument sichern:
138                 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
139                 if( pDocSh )
140                 {
141                     SdDrawDocument* pDoc = pDocSh->GetDoc();
142                     pDoc->SetOnlineSpell( bOnlineSpelling );
143                 }
144             }
145         }
146         break;
147 
148         case SID_ATTR_METRIC:
149         {
150             const SfxPoolItem* pItem;
151             if ( pSet && SFX_ITEM_SET == pSet->GetItemState( SID_ATTR_METRIC, sal_True, &pItem ) )
152             {
153                 FieldUnit eUnit = (FieldUnit)((const SfxUInt16Item*)pItem)->GetValue();
154                 switch( eUnit )
155                 {
156                     case FUNIT_MM:      // nur die Einheiten, die auch im Dialog stehen
157                     case FUNIT_CM:
158                     case FUNIT_INCH:
159                     case FUNIT_PICA:
160                     case FUNIT_POINT:
161                         {
162                             ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
163                             if(pDocSh)
164                             {
165                                 DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType();
166 
167                                 PutItem( *pItem );
168                                 SdOptions* pOptions = GetSdOptions( eDocType );
169                                 if(pOptions)
170                                     pOptions->SetMetric( (sal_uInt16)eUnit );
171                                 rReq.Done();
172                             }
173                         }
174                         break;
175                     default:
176                         break;
177                     }
178                 }
179 
180         }
181         break;
182 
183         case SID_ATTR_LANGUAGE:
184         case SID_ATTR_CHAR_CJK_LANGUAGE:
185         case SID_ATTR_CHAR_CTL_LANGUAGE:
186         {
187             const SfxPoolItem* pItem;
188             if( pSet &&
189                 (
190                 SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_LANGUAGE, sal_False, &pItem ) ||
191                 SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_CHAR_CJK_LANGUAGE, sal_False, &pItem ) ||
192                 SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_CHAR_CTL_LANGUAGE, sal_False, &pItem )
193                 )
194               )
195             {
196                 // am Dokument sichern:
197                 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
198                 if ( pDocSh )
199                 {
200                     LanguageType eLanguage = ( (SvxLanguageItem*)pItem )->GetValue();
201                     SdDrawDocument* pDoc = pDocSh->GetDoc();
202 
203                     if( nSlotId == SID_ATTR_CHAR_CJK_LANGUAGE )
204                         pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE_CJK );
205                     else if( nSlotId == SID_ATTR_CHAR_CTL_LANGUAGE )
206                         pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE_CTL );
207                     else
208                         pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE );
209 
210                     if( pDoc->GetOnlineSpell() )
211                     {
212                         pDoc->StopOnlineSpelling();
213                         pDoc->StartOnlineSpelling();
214                     }
215                 }
216             }
217         }
218         break;
219 
220         case SID_SD_AUTOPILOT:
221         case SID_NEWSD:
222             {
223                 SfxFrame* pFrame = ExecuteNewDocument( rReq );
224                 // #94442# if a frame was created, set it as return value
225                 if(pFrame)
226                     rReq.SetReturnValue(SfxFrameItem(0, pFrame));
227             }
228 
229             break;
230 
231         case SID_OPENHYPERLINK:
232         case SID_OPENDOC:
233         {
234             sal_Bool bIntercept = sal_False;
235             ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
236             if (pDocShell)
237             {
238                 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
239                 if (pViewShell)
240                 {
241                     if( sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() ) )
242                     {
243                         // Prevent documents from opening while the slide
244                         // show is running, except when this request comes
245                         // from a shape interaction.
246                         if (rReq.GetArgs() == NULL)
247                         {
248                             bIntercept = sal_True;
249                         }
250                     }
251                 }
252             }
253 
254             if (!bIntercept)
255             {
256                 SFX_APP()->ExecuteSlot(rReq, SFX_APP()->GetInterface());
257             }
258             else
259             {
260                 ErrorBox(NULL, WB_OK, String(SdResId(STR_CANT_PERFORM_IN_LIVEMODE))).Execute();
261 
262                 SFX_REQUEST_ARG( rReq, pLinkItem, SfxLinkItem, SID_DONELINK, sal_False );
263                 if( pLinkItem )
264                     pLinkItem->GetValue().Call( 0 );
265             }
266         }
267         break;
268 
269         case SID_OUTLINE_TO_IMPRESS:
270             OutlineToImpress (rReq);
271             break;
272 
273         default:
274         break;
275     }
276 }
277 
278 
279 
280 
281 void SdModule::OutlineToImpress (SfxRequest& rRequest)
282 {
283     const SfxItemSet* pSet = rRequest.GetArgs();
284 
285     if (pSet)
286     {
287         SvLockBytes* pBytes = ((SfxLockBytesItem&) pSet->Get(SID_OUTLINE_TO_IMPRESS)).GetValue();
288 
289         if (pBytes)
290         {
291             SfxObjectShellLock xDocShell;
292             ::sd::DrawDocShell* pDocSh;
293             xDocShell = pDocSh = new ::sd::DrawDocShell(
294                 SFX_CREATE_MODE_STANDARD, sal_False);
295             if(pDocSh)
296             {
297                 pDocSh->DoInitNew(NULL);
298                 SdDrawDocument* pDoc = pDocSh->GetDoc();
299                 if(pDoc)
300                 {
301                     pDoc->CreateFirstPages();
302                     pDoc->StopWorkStartupDelay();
303                 }
304 
305                 SFX_REQUEST_ARG( rRequest, pFrmItem, SfxFrameItem, SID_DOCFRAME, sal_False);
306                 SfxViewFrame::LoadDocumentIntoFrame( *pDocSh, pFrmItem, ::sd::OUTLINE_FACTORY_ID );
307 
308                 ::sd::ViewShell* pViewSh = pDocSh->GetViewShell();
309 
310                 if (pViewSh)
311                 {
312                     // AutoLayouts muessen fertig sein
313                     pDoc->StopWorkStartupDelay();
314 
315                     SfxViewFrame* pViewFrame = pViewSh->GetViewFrame();
316 
317                     // When the view frame has not been just created we have
318                     // to switch synchronously to the outline view.
319                     // (Otherwise the request will be ignored anyway.)
320                     ::sd::ViewShellBase* pBase
321                         = dynamic_cast< ::sd::ViewShellBase*>(pViewFrame->GetViewShell());
322                     if (pBase != NULL)
323                     {
324                         ::boost::shared_ptr<FrameworkHelper> pHelper (
325                             FrameworkHelper::Instance(*pBase));
326                         pHelper->RequestView(
327                             FrameworkHelper::msOutlineViewURL,
328                             FrameworkHelper::msCenterPaneURL);
329 
330                         pHelper->RunOnResourceActivation(
331                             FrameworkHelper::CreateResourceId(
332                             FrameworkHelper::msOutlineViewURL,
333                             FrameworkHelper::msCenterPaneURL),
334                             OutlineToImpressFinalizer(*pBase, *pDoc, *pBytes));
335                     }
336                 }
337             }
338         }
339     }
340 
341     rRequest.IsDone();
342 }
343 
344 
345 
346 
347 /*************************************************************************
348 |*
349 |* GetState
350 |*
351 \************************************************************************/
352 
353 static bool bOnce = false;
354 
355 void SdModule::GetState(SfxItemSet& rItemSet)
356 {
357     // Autopilot waehrend der Praesentation disablen
358     if (rItemSet.GetItemState(SID_SD_AUTOPILOT) != SFX_ITEM_UNKNOWN)
359     {
360         if (!SvtModuleOptions().IsImpress())
361         {
362             rItemSet.DisableItem(SID_SD_AUTOPILOT);
363         }
364         else
365         {
366             ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
367             if (pDocShell)
368             {
369                 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
370                 if (pViewShell)
371                 {
372                     if( sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() ) )
373                     {
374                         rItemSet.DisableItem(SID_SD_AUTOPILOT);
375                     }
376                 }
377             }
378         }
379     }
380 
381     if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_ATTR_METRIC ) )
382     {
383         ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
384         if(pDocSh)
385         {
386             DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType();
387 
388             SdOptions* pOptions = GetSdOptions(eDocType);
389             rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, pOptions->GetMetric() ) );
390         }
391     }
392 
393     // der Status von SID_OPENDOC wird von der Basisklasse bestimmt
394     if (rItemSet.GetItemState(SID_OPENDOC) != SFX_ITEM_UNKNOWN)
395     {
396         const SfxPoolItem* pItem = SFX_APP()->GetSlotState(SID_OPENDOC, SFX_APP()->GetInterface());
397         if (pItem)
398             rItemSet.Put(*pItem);
399     }
400 
401     // der Status von SID_OPENHYPERLINK wird von der Basisklasse bestimmt
402     if (rItemSet.GetItemState(SID_OPENHYPERLINK) != SFX_ITEM_UNKNOWN)
403     {
404         const SfxPoolItem* pItem = SFX_APP()->GetSlotState(SID_OPENHYPERLINK, SFX_APP()->GetInterface());
405         if (pItem)
406             rItemSet.Put(*pItem);
407     }
408 
409     if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_AUTOSPELL_CHECK ) )
410     {
411         ::sd::DrawDocShell* pDocSh =
412               PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
413         if( pDocSh )
414         {
415             SdDrawDocument* pDoc = pDocSh->GetDoc();
416             rItemSet.Put( SfxBoolItem( SID_AUTOSPELL_CHECK, pDoc->GetOnlineSpell() ) );
417         }
418     }
419 
420     if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_ATTR_LANGUAGE ) )
421     {
422         ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
423         if( pDocSh )
424             rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE ) );
425     }
426 
427     if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE ) )
428     {
429         ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
430         if( pDocSh )
431             rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CJK ), SID_ATTR_CHAR_CJK_LANGUAGE ) );
432     }
433 
434     if( SFX_ITEM_AVAILABLE == rItemSet.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE ) )
435     {
436         ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
437         if( pDocSh )
438             rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CTL ), SID_ATTR_CHAR_CTL_LANGUAGE ) );
439     }
440 
441     if ( !bOnce )
442     {
443         ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
444         if( pDocShell ) // Impress or Draw ?
445         {
446             ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
447 
448             if( pViewShell && (pDocShell->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) )
449             {
450                 // add our event listener as soon as possible
451                 Application::AddEventListener( LINK( this, SdModule, EventListenerHdl ) );
452                 bOnce = true;
453             }
454         }
455     }
456 }
457 
458 IMPL_LINK( SdModule, EventListenerHdl, VclSimpleEvent*, pEvent )
459 {
460     if( pEvent && (pEvent->GetId() == VCLEVENT_WINDOW_COMMAND) && static_cast<VclWindowEvent*>(pEvent)->GetData() )
461     {
462         const CommandEvent& rEvent = *(const CommandEvent*)static_cast<VclWindowEvent*>(pEvent)->GetData();
463 
464         if( rEvent.GetCommand() == COMMAND_MEDIA )
465         {
466             switch( rEvent.GetMediaCommand() )
467             {
468                 case MEDIA_COMMAND_PLAY:
469                 {
470                     ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
471                     if( pDocShell )  // Impress or Draw ?
472                     {
473                         ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
474 
475                         // #i97925# start the presentation if and only if an Impress document is focused
476                         if( pViewShell && (pDocShell->GetDocumentType() == DOCUMENT_TYPE_IMPRESS) )
477                             pViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_PRESENTATION );
478                     }
479                 }
480                     break;
481 
482                 default:
483                     break;
484             }
485         }
486     }
487     return 0;
488 }
489 
490 
491 void SdModule::AddSummaryPage (SfxViewFrame* pViewFrame, SdDrawDocument* pDocument)
492 {
493     if( !pViewFrame || !pViewFrame->GetDispatcher() || !pDocument )
494         return;
495 
496     pViewFrame->GetDispatcher()->Execute(SID_SUMMARY_PAGE,
497         SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
498 
499     OSL_ASSERT (pDocument!=NULL);
500 
501     sal_Int32 nPageCount = pDocument->GetSdPageCount (PK_STANDARD);
502 
503     // We need at least two pages: the summary page and one to use as
504     // template to take the transition parameters from.
505     if (nPageCount >= 2)
506     {
507         // Get a page from which to retrieve the transition parameters.
508         SdPage* pTemplatePage = pDocument->GetSdPage (0, PK_STANDARD);
509         OSL_ASSERT (pTemplatePage!=NULL);
510 
511         // The summary page, if it exists, is the last page.
512         SdPage* pSummaryPage = pDocument->GetSdPage (
513             (sal_uInt16)nPageCount-1, PK_STANDARD);
514         OSL_ASSERT (pSummaryPage!=NULL);
515 
516         // Take the change mode of the template page as indication of the
517         // document's kiosk mode.
518         pSummaryPage->setTransitionDuration(pTemplatePage->getTransitionDuration());
519         pSummaryPage->SetPresChange(pTemplatePage->GetPresChange());
520         pSummaryPage->SetTime(pTemplatePage->GetTime());
521         pSummaryPage->SetSound(pTemplatePage->IsSoundOn());
522         pSummaryPage->SetSoundFile(pTemplatePage->GetSoundFile());
523         pSummaryPage->setTransitionType(pTemplatePage->getTransitionType());
524         pSummaryPage->setTransitionSubtype(pTemplatePage->getTransitionSubtype());
525         pSummaryPage->setTransitionDirection(pTemplatePage->getTransitionDirection());
526         pSummaryPage->setTransitionFadeColor(pTemplatePage->getTransitionFadeColor());
527         pSummaryPage->setTransitionDuration(pTemplatePage->getTransitionDuration());
528     }
529 }
530 
531 SfxFrame* SdModule::CreateFromTemplate( const String& rTemplatePath, const Reference< XFrame >& i_rFrame )
532 {
533     SfxFrame* pFrame = 0;
534 
535     SfxObjectShellLock xDocShell;
536 
537     SfxItemSet* pSet = new SfxAllItemSet( SFX_APP()->GetPool() );
538     pSet->Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
539 
540     sal_uLong lErr = SFX_APP()->LoadTemplate( xDocShell, rTemplatePath, sal_True, pSet );
541 
542     SfxObjectShell* pDocShell = xDocShell;
543 
544     if( lErr )
545     {
546         ErrorHandler::HandleError(lErr);
547     }
548     else if( pDocShell )
549     {
550         SfxViewFrame* pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pDocShell, i_rFrame );
551         OSL_ENSURE( pViewFrame, "SdModule::CreateFromTemplate: no view frame - was the document really loaded?" );
552         pFrame = pViewFrame ? &pViewFrame->GetFrame() : NULL;
553     }
554 
555     return pFrame;
556 
557 }
558 
559 SfxFrame* SdModule::ExecuteNewDocument( SfxRequest& rReq )
560 {
561     SfxFrame* pFrame = 0;
562     if ( SvtModuleOptions().IsImpress() )
563     {
564         Reference< XFrame > xTargetFrame;
565         SFX_REQUEST_ARG( rReq, pFrmItem, SfxUnoFrameItem, SID_FILLFRAME, sal_False);
566         if ( pFrmItem )
567             xTargetFrame = pFrmItem->GetFrame();
568 
569         bool bMakeLayoutVisible = false;
570         SfxViewFrame* pViewFrame = NULL;
571 
572         SdOptions* pOpt = GetSdOptions(DOCUMENT_TYPE_IMPRESS);
573         bool bStartWithTemplate = pOpt->IsStartWithTemplate();
574 
575         bool bNewDocDirect = rReq.GetSlot() == SID_NEWSD;
576         if( bNewDocDirect && !bStartWithTemplate )
577         {
578             //we start without wizard
579 
580             //check wether we should load a template document
581             const ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) );
582             String aStandardTemplate( SfxObjectFactory::GetStandardTemplate( aServiceName ) );
583 
584             if( aStandardTemplate.Len() > 0 )
585             {
586                 //load a template document
587                 pFrame = CreateFromTemplate( aStandardTemplate, xTargetFrame );
588             }
589             else
590             {
591                 //create an empty document
592                 pFrame = CreateEmptyDocument( DOCUMENT_TYPE_IMPRESS, xTargetFrame );
593                 bMakeLayoutVisible = true;
594             }
595         }
596         else
597         {
598             SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
599             std::auto_ptr< AbstractAssistentDlg > pPilotDlg( pFact ? pFact->CreateAssistentDlg( NULL, !bNewDocDirect ) : 0 );
600 
601             // Open the Pilot
602             if( pPilotDlg.get() && pPilotDlg->Execute()==RET_OK )
603             {
604                 const String aDocPath( pPilotDlg->GetDocPath());
605                 const sal_Bool bIsDocEmpty = pPilotDlg->IsDocEmpty();
606 
607                 // So that you can open the document without AutoLayout-Dialog
608                 pOpt->SetStartWithTemplate(sal_False);
609                 if(bNewDocDirect && !pPilotDlg->GetStartWithFlag())
610                     bStartWithTemplate = sal_False;
611 
612                 if( pPilotDlg->GetStartType() == ST_OPEN )
613                 {
614                     String aFileToOpen = aDocPath;
615 
616                     DBG_ASSERT( aFileToOpen.Len()!=0, "The autopilot should have asked for a file itself already!" );
617                     if(aFileToOpen.Len() != 0)
618                     {
619                         const String aPasswrd( pPilotDlg->GetPassword() );
620 
621                         SfxStringItem aFile( SID_FILE_NAME, aFileToOpen );
622                         SfxStringItem aReferer( SID_REFERER, UniString() );
623                         SfxStringItem aPassword( SID_PASSWORD, aPasswrd );
624 
625                         if ( xTargetFrame.is() )
626                         {
627                             SfxAllItemSet aSet( *rReq.GetArgs()->GetPool() );
628                             aSet.Put( aFile );
629                             aSet.Put( aReferer );
630                             // Put the password into the request
631                             // only if it is not empty.
632                             if (aPasswrd.Len() > 0)
633                                 aSet.Put( aPassword );
634 
635                             const SfxPoolItem* pRet = SfxFrame::OpenDocumentSynchron( aSet, xTargetFrame );
636                             const SfxViewFrameItem* pFrameItem = PTR_CAST( SfxViewFrameItem, pRet );
637                             if ( pFrameItem && pFrameItem->GetFrame() )
638                                 pFrame = &pFrameItem->GetFrame()->GetFrame();
639                         }
640                         else
641                         {
642                             SfxRequest aRequest (SID_OPENDOC, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool());
643                             aRequest.AppendItem (aFile);
644                             aRequest.AppendItem (aReferer);
645                             // Put the password into the request
646                             // only if it is not empty.
647                             if (aPasswrd.Len() > 0)
648                                 aRequest.AppendItem (aPassword);
649                             aRequest.AppendItem (SfxStringItem (
650                                 SID_TARGETNAME,
651                                 String (RTL_CONSTASCII_USTRINGPARAM ("_default"))));
652                             try
653                             {
654                                 const SfxPoolItem* pRet = SFX_APP()->ExecuteSlot (aRequest);
655                                 const SfxViewFrameItem* pFrameItem = PTR_CAST( SfxViewFrameItem, pRet );
656                                 if ( pFrameItem )
657                                     pFrame = &pFrameItem->GetFrame()->GetFrame();
658                             }
659                             catch (::com::sun::star::uno::Exception e)
660                             {
661                                 DBG_ASSERT (sal_False, "caught IllegalArgumentException while loading document from Impress autopilot");
662                             }
663                         }
664                     }
665 
666                     pOpt->SetStartWithTemplate(bStartWithTemplate);
667                     if(bNewDocDirect && !bStartWithTemplate)
668                     {
669                         std::auto_ptr< SfxItemSet > pRet( CreateItemSet( SID_SD_EDITOPTIONS ) );
670                         if(pRet.get())
671                             ApplyItemSet( SID_SD_EDITOPTIONS, *pRet.get() );
672 
673                     }
674                 }
675                 else
676                 {
677                     SfxObjectShellLock xShell( pPilotDlg->GetDocument() );
678                     SfxObjectShell* pShell = xShell;
679                     if( pShell )
680                     {
681                         pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pShell, xTargetFrame );
682                         DBG_ASSERT( pViewFrame, "no ViewFrame!!" );
683                         pFrame = pViewFrame ? &pViewFrame->GetFrame() : NULL;
684 
685                         if(bNewDocDirect && !bStartWithTemplate)
686                         {
687                             std::auto_ptr< SfxItemSet > pRet( CreateItemSet( SID_SD_EDITOPTIONS ) );
688                             if(pRet.get())
689                                 ApplyItemSet( SID_SD_EDITOPTIONS, *pRet.get() );
690                         }
691 
692                         if( pShell && pViewFrame )
693                         {
694                             ::sd::DrawDocShell* pDocShell =
695                                   PTR_CAST(::sd::DrawDocShell,pShell);
696                             SdDrawDocument* pDoc = pDocShell->GetDoc();
697 
698                             ::sd::ViewShellBase* pBase =
699                                   ::sd::ViewShellBase::GetViewShellBase (
700                                       pViewFrame);
701                             OSL_ASSERT (pBase!=NULL);
702                             ::boost::shared_ptr<sd::ViewShell> pViewSh = pBase->GetMainViewShell();
703                             SdOptions* pOptions = GetSdOptions(pDoc->GetDocumentType());
704 
705                             if (pOptions && pViewSh.get())
706                             {
707                                 // The AutoPilot-document shall be open without its own options
708                                 ::sd::FrameView* pFrameView = pViewSh->GetFrameView();
709                                 pFrameView->Update(pOptions);
710                                 pViewSh->ReadFrameViewData(pFrameView);
711                             }
712 
713                             ChangeMedium( pDocShell, pViewFrame, pPilotDlg->GetOutputMedium() );
714 
715                             if(pPilotDlg->IsSummary())
716                                 AddSummaryPage(pViewFrame, pDoc);
717 
718                             // empty document
719                             if((aDocPath.Len() == 0) && pViewFrame && pViewFrame->GetDispatcher())
720                             {
721                                 SfxBoolItem aIsChangedItem(SID_MODIFYPAGE, !bIsDocEmpty);
722                                 SfxUInt32Item eAutoLayout( ID_VAL_WHATLAYOUT, (sal_uInt32) AUTOLAYOUT_TITLE );
723                                 pViewFrame->GetDispatcher()->Execute(SID_MODIFYPAGE,
724                                    SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aIsChangedItem, &eAutoLayout, 0L);
725                             }
726 
727                             // clear document info
728                             using namespace ::com::sun::star;
729                             uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
730                                 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
731                             uno::Reference<document::XDocumentProperties>
732                                 xDocProps(xDPS->getDocumentProperties());
733                             DBG_ASSERT(xDocProps.is(), "no DocumentProperties");
734                             xDocProps->resetUserData(
735                                 SvtUserOptions().GetFullName() );
736                             xDocProps->setTemplateName(xDocProps->getTitle());
737                             xDocProps->setTemplateURL(pPilotDlg->GetDocPath());
738 
739                             pDoc->SetChanged(!bIsDocEmpty);
740 
741                             pDocShell->SetUseUserData(sal_True);
742 
743                             // #94652# clear UNDO stack after autopilot
744                             pDocShell->ClearUndoBuffer();
745 
746                             bMakeLayoutVisible = true;
747                         }
748                     }
749                     pOpt->SetStartWithTemplate(bStartWithTemplate);
750                 }
751             }
752         }
753 
754         if (bMakeLayoutVisible && pViewFrame!=NULL)
755         {
756             // Make the layout menu visible in the tool pane.
757             ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase(pViewFrame);
758             if (pBase != NULL)
759             {
760                 FrameworkHelper::Instance(*pBase)->RequestTaskPanel(
761                     FrameworkHelper::msLayoutTaskPanelURL);
762             }
763         }
764     }
765 
766     return pFrame;
767 }
768 
769 SfxFrame* SdModule::CreateEmptyDocument( DocumentType eDocType, const Reference< XFrame >& i_rFrame )
770 {
771     SfxFrame* pFrame = 0;
772 
773     SfxObjectShellLock xDocShell;
774     ::sd::DrawDocShell* pNewDocSh;
775     xDocShell = pNewDocSh = new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD,sal_False,eDocType);
776     if(pNewDocSh)
777     {
778         pNewDocSh->DoInitNew(NULL);
779         SdDrawDocument* pDoc = pNewDocSh->GetDoc();
780         if(pDoc)
781         {
782             pDoc->CreateFirstPages();
783             pDoc->StopWorkStartupDelay();
784         }
785 
786         SfxViewFrame* pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pNewDocSh, i_rFrame );
787         OSL_ENSURE( pViewFrame, "SdModule::CreateEmptyDocument: no view frame - was the document really loaded?" );
788         pFrame = pViewFrame ? &pViewFrame->GetFrame() : NULL;
789     }
790 
791     return pFrame;
792 }
793 
794 void SdModule::ChangeMedium( ::sd::DrawDocShell* pDocShell, SfxViewFrame* pViewFrame, const sal_Int32 eMedium )
795 {
796     if( !pDocShell )
797         return;
798 
799     SdDrawDocument* pDoc = pDocShell->GetDoc();
800     if( !pDoc )
801         return;
802 
803     // settings for the Outputmedium
804     Size aNewSize;
805     sal_uInt32 nLeft = 0;
806     sal_uInt32 nRight = 0;
807     sal_uInt32 nLower = 0;
808     sal_uInt32 nUpper = 0;
809     switch(eMedium)
810     {
811         case OUTPUT_PAGE:
812         case OUTPUT_OVERHEAD:
813         {
814             SfxPrinter* pPrinter = pDocShell->GetPrinter(sal_True);
815 
816             if( pPrinter && pPrinter->IsValid())
817             {
818                 // Der Printer gibt leider kein exaktes
819                 // Format (z.B. A4) zurueck
820                 Size aSize(pPrinter->GetPaperSize());
821                 Paper ePaper = SvxPaperInfo::GetSvxPaper( aSize, MAP_100TH_MM, sal_True);
822 
823                 if (ePaper != PAPER_USER)
824                 {
825                     // Korrekte Size holen
826                     aSize = SvxPaperInfo::GetPaperSize(ePaper, MAP_100TH_MM);
827                 }
828 
829                 if (aSize.Height() > aSize.Width())
830                 {
831                      // Stets Querformat
832                      aNewSize.Width()  = aSize.Height();
833                      aNewSize.Height() = aSize.Width();
834                 }
835                 else
836                 {
837                      aNewSize = aSize;
838                 }
839             }
840             else
841             {
842                 aNewSize=Size(29700, 21000);
843             }
844 
845             if (eMedium == OUTPUT_PAGE)
846             {
847                 nLeft =1000;
848                 nRight=1000;
849                 nUpper=1000;
850                 nLower=1000;
851             }
852             else
853             {
854                 nLeft =0;
855                 nRight=0;
856                 nUpper=0;
857                 nLower=0;
858             }
859         }
860         break;
861 
862         case OUTPUT_SLIDE:
863         {
864             aNewSize = Size(27000, 18000);
865             nLeft =0;
866             nRight=0;
867             nUpper=0;
868             nLower=0;
869         }
870         break;
871 
872         case OUTPUT_PRESENTATION:
873         {
874             aNewSize = Size(28000, 21000);
875             nLeft =0;
876             nRight=0;
877             nUpper=0;
878             nLower=0;
879         }
880         break;
881     }
882 
883     sal_Bool bScaleAll = sal_True;
884     sal_uInt16 nPageCnt = pDoc->GetMasterSdPageCount(PK_STANDARD);
885     sal_uInt16 i;
886     SdPage* pPage;
887 
888     // master pages first
889     for (i = 0; i < nPageCnt; i++)
890     {
891         pPage = pDoc->GetMasterSdPage(i, PK_STANDARD);
892 
893         if (pPage)
894         {
895             if(eMedium != OUTPUT_ORIGINAL)
896             {
897                 Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
898                 pPage->ScaleObjects(aNewSize, aBorderRect, bScaleAll);
899                 pPage->SetSize(aNewSize);
900                 pPage->SetBorder(nLeft, nUpper, nRight, nLower);
901             }
902             SdPage* pNotesPage = pDoc->GetMasterSdPage(i, PK_NOTES);
903             DBG_ASSERT( pNotesPage, "Wrong page ordering!" );
904             if( pNotesPage ) pNotesPage->CreateTitleAndLayout();
905             pPage->CreateTitleAndLayout();
906         }
907     }
908 
909     nPageCnt = pDoc->GetSdPageCount(PK_STANDARD);
910 
911     // then slides
912     for (i = 0; i < nPageCnt; i++)
913     {
914         pPage = pDoc->GetSdPage(i, PK_STANDARD);
915 
916         if (pPage)
917         {
918             if(eMedium != OUTPUT_ORIGINAL)
919             {
920                 Rectangle aBorderRect(nLeft, nUpper, nRight, nLower);
921                 pPage->ScaleObjects(aNewSize, aBorderRect, bScaleAll);
922                 pPage->SetSize(aNewSize);
923                 pPage->SetBorder(nLeft, nUpper, nRight, nLower);
924             }
925             SdPage* pNotesPage = pDoc->GetSdPage(i, PK_NOTES);
926             DBG_ASSERT( pNotesPage, "Wrong page ordering!" );
927             if( pNotesPage ) pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() );
928             pPage->SetAutoLayout( pPage->GetAutoLayout() );
929         }
930     }
931 
932     SdPage* pHandoutPage = pDoc->GetSdPage(0, PK_HANDOUT);
933     pHandoutPage->CreateTitleAndLayout(sal_True);
934 
935     if( (eMedium != OUTPUT_ORIGINAL) && pViewFrame && pViewFrame->GetDispatcher())
936     {
937         pViewFrame->GetDispatcher()->Execute(SID_SIZE_PAGE, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
938     }
939 }
940 
941 
942 
943 
944 //===== OutlineToImpressFinalize ==============================================
945 
946 namespace {
947 
948 OutlineToImpressFinalizer::OutlineToImpressFinalizer (
949     ::sd::ViewShellBase& rBase,
950     SdDrawDocument& rDocument,
951     SvLockBytes& rBytes)
952     : mrBase(rBase),
953       mrDocument(rDocument),
954       mpStream()
955 {
956     // The given stream has a lifetime shorter than this new
957     // OutlineToImpressFinalizer object.  Therefore a local copy of the
958     // stream is created.
959     const SvStream* pStream (rBytes.GetStream());
960     if (pStream != NULL)
961     {
962         // Create a memory stream and prepare to fill it with the content of
963         // the original stream.
964         mpStream.reset(new SvMemoryStream());
965         static const sal_Size nBufferSize = 4096;
966         ::boost::scoped_array<sal_Int8> pBuffer (new sal_Int8[nBufferSize]);
967 
968         sal_Size nReadPosition (0);
969         bool bLoop (true);
970         while (bLoop)
971         {
972             // Read the next part of the original stream.
973             sal_Size nReadByteCount (0);
974             const ErrCode nErrorCode (
975                 rBytes.ReadAt(
976                     nReadPosition,
977                     reinterpret_cast<void*>(pBuffer.get()),
978                     nBufferSize,
979                     &nReadByteCount));
980 
981             // Check the error code and stop copying the stream data when an
982             // error has occured.
983             switch (nErrorCode)
984             {
985                 case ERRCODE_NONE:
986                     if (nReadByteCount == 0)
987                         bLoop = false;
988                     break;
989                 case ERRCODE_IO_PENDING:
990                     break;
991 
992                 default:
993                     bLoop = false;
994                     nReadByteCount = 0;
995                     break;
996             }
997 
998             // Append the read bytes to the end of the memory stream.
999             if (nReadByteCount > 0)
1000             {
1001                 mpStream->Write(reinterpret_cast<void*>(pBuffer.get()), nReadByteCount);
1002                 nReadPosition += nReadByteCount;
1003             }
1004         }
1005 
1006         // Rewind the memory stream so that in the operator() method its
1007         // content is properly read.
1008         mpStream->Seek(STREAM_SEEK_TO_BEGIN);
1009     }
1010 }
1011 
1012 
1013 
1014 
1015 void OutlineToImpressFinalizer::operator() (bool)
1016 {
1017     // Fetch the new outline view shell.
1018     ::sd::OutlineViewShell* pOutlineShell
1019         = dynamic_cast<sd::OutlineViewShell*>(FrameworkHelper::Instance(mrBase)->GetViewShell(FrameworkHelper::msCenterPaneURL).get());
1020 
1021     if (pOutlineShell != NULL && mpStream.get() != NULL)
1022     {
1023         sd::OutlineView* pView = static_cast<sd::OutlineView*>(pOutlineShell->GetView());
1024         // mba: the stream can't contain any relative URLs, because we don't
1025         // have any information about a BaseURL!
1026         if ( pOutlineShell->Read(*mpStream, String(), EE_FORMAT_RTF) == 0 )
1027         {
1028 /*
1029             sd::OutlineViewPageChangesGuard aGuard( pView );
1030 
1031             // Remove the first empty pages
1032             sal_uInt16 nPageCount = mrDocument.GetPageCount();
1033             mrDocument.RemovePage( --nPageCount );  // notes page
1034             mrDocument.RemovePage( --nPageCount );  // standard page
1035 */
1036         }
1037 
1038         // Call UpdatePreview once for every slide to resync the
1039         // document with the outliner of the OutlineViewShell.
1040         sal_uInt16 nPageCount (mrDocument.GetSdPageCount(PK_STANDARD));
1041         for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++)
1042         {
1043             SdPage* pPage = mrDocument.GetSdPage(nIndex, PK_STANDARD);
1044             // Make the page the actual page so that the
1045             // following UpdatePreview() call accesses the
1046             // correct paragraphs.
1047             pView->SetActualPage(pPage);
1048             pOutlineShell->UpdatePreview(pPage, true);
1049         }
1050         // Select the first slide.
1051         SdPage* pPage = mrDocument.GetSdPage(0, PK_STANDARD);
1052         pView->SetActualPage(pPage);
1053         pOutlineShell->UpdatePreview(pPage, true);
1054     }
1055 
1056 
1057     // #97231# Undo-Stack needs to be cleared, else the user may remove the
1058     // only drawpage and this is a state we cannot handle ATM.
1059     ::sd::DrawDocShell* pDocShell = mrDocument.GetDocSh();
1060     if( pDocShell )
1061         pDocShell->ClearUndoBuffer();
1062 }
1063 
1064 
1065 } // end of anonymous namespace
1066