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