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