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