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 wether 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 if (bMakeLayoutVisible && pViewFrame!=NULL) 751 { 752 // Make the layout menu visible in the tool pane. 753 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase(pViewFrame); 754 if (pBase != NULL) 755 { 756 FrameworkHelper::Instance(*pBase)->RequestTaskPanel( 757 FrameworkHelper::msLayoutTaskPanelURL); 758 } 759 } 760 } 761 762 return pFrame; 763 } 764 765 SfxFrame* SdModule::CreateEmptyDocument( DocumentType eDocType, const Reference< XFrame >& i_rFrame ) 766 { 767 SfxFrame* pFrame = 0; 768 769 SfxObjectShellLock xDocShell; 770 ::sd::DrawDocShell* pNewDocSh; 771 xDocShell = pNewDocSh = new ::sd::DrawDocShell(SFX_CREATE_MODE_STANDARD,sal_False,eDocType); 772 if(pNewDocSh) 773 { 774 pNewDocSh->DoInitNew(NULL); 775 SdDrawDocument* pDoc = pNewDocSh->GetDoc(); 776 if(pDoc) 777 { 778 pDoc->CreateFirstPages(); 779 pDoc->StopWorkStartupDelay(); 780 } 781 782 SfxViewFrame* pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pNewDocSh, i_rFrame ); 783 OSL_ENSURE( pViewFrame, "SdModule::CreateEmptyDocument: no view frame - was the document really loaded?" ); 784 pFrame = pViewFrame ? &pViewFrame->GetFrame() : NULL; 785 } 786 787 return pFrame; 788 } 789 790 void SdModule::ChangeMedium( ::sd::DrawDocShell* pDocShell, SfxViewFrame* pViewFrame, const sal_Int32 eMedium ) 791 { 792 if( !pDocShell ) 793 return; 794 795 SdDrawDocument* pDoc = pDocShell->GetDoc(); 796 if( !pDoc ) 797 return; 798 799 // settings for the Outputmedium 800 Size aNewSize; 801 sal_uInt32 nLeft = 0; 802 sal_uInt32 nRight = 0; 803 sal_uInt32 nLower = 0; 804 sal_uInt32 nUpper = 0; 805 switch(eMedium) 806 { 807 case OUTPUT_PAGE: 808 case OUTPUT_OVERHEAD: 809 { 810 SfxPrinter* pPrinter = pDocShell->GetPrinter(sal_True); 811 812 if( pPrinter && pPrinter->IsValid()) 813 { 814 // Der Printer gibt leider kein exaktes 815 // Format (z.B. A4) zurueck 816 Size aSize(pPrinter->GetPaperSize()); 817 Paper ePaper = SvxPaperInfo::GetSvxPaper( aSize, MAP_100TH_MM, sal_True); 818 819 if (ePaper != PAPER_USER) 820 { 821 // Korrekte Size holen 822 aSize = SvxPaperInfo::GetPaperSize(ePaper, MAP_100TH_MM); 823 } 824 825 if (aSize.Height() > aSize.Width()) 826 { 827 // Stets Querformat 828 aNewSize.Width() = aSize.Height(); 829 aNewSize.Height() = aSize.Width(); 830 } 831 else 832 { 833 aNewSize = aSize; 834 } 835 } 836 else 837 { 838 aNewSize=Size(29700, 21000); 839 } 840 841 if (eMedium == OUTPUT_PAGE) 842 { 843 nLeft =1000; 844 nRight=1000; 845 nUpper=1000; 846 nLower=1000; 847 } 848 else 849 { 850 nLeft =0; 851 nRight=0; 852 nUpper=0; 853 nLower=0; 854 } 855 } 856 break; 857 858 case OUTPUT_SLIDE: 859 { 860 aNewSize = Size(27000, 18000); 861 nLeft =0; 862 nRight=0; 863 nUpper=0; 864 nLower=0; 865 } 866 break; 867 868 case OUTPUT_PRESENTATION: 869 { 870 aNewSize = Size(28000, 21000); 871 nLeft =0; 872 nRight=0; 873 nUpper=0; 874 nLower=0; 875 } 876 break; 877 } 878 879 sal_Bool bScaleAll = sal_True; 880 sal_uInt16 nPageCnt = pDoc->GetMasterSdPageCount(PK_STANDARD); 881 sal_uInt16 i; 882 SdPage* pPage; 883 884 // master pages first 885 for (i = 0; i < nPageCnt; i++) 886 { 887 pPage = pDoc->GetMasterSdPage(i, PK_STANDARD); 888 889 if (pPage) 890 { 891 if(eMedium != OUTPUT_ORIGINAL) 892 { 893 Rectangle aBorderRect(nLeft, nUpper, nRight, nLower); 894 pPage->ScaleObjects(aNewSize, aBorderRect, bScaleAll); 895 pPage->SetSize(aNewSize); 896 pPage->SetBorder(nLeft, nUpper, nRight, nLower); 897 } 898 SdPage* pNotesPage = pDoc->GetMasterSdPage(i, PK_NOTES); 899 DBG_ASSERT( pNotesPage, "Wrong page ordering!" ); 900 if( pNotesPage ) pNotesPage->CreateTitleAndLayout(); 901 pPage->CreateTitleAndLayout(); 902 } 903 } 904 905 nPageCnt = pDoc->GetSdPageCount(PK_STANDARD); 906 907 // then slides 908 for (i = 0; i < nPageCnt; i++) 909 { 910 pPage = pDoc->GetSdPage(i, PK_STANDARD); 911 912 if (pPage) 913 { 914 if(eMedium != OUTPUT_ORIGINAL) 915 { 916 Rectangle aBorderRect(nLeft, nUpper, nRight, nLower); 917 pPage->ScaleObjects(aNewSize, aBorderRect, bScaleAll); 918 pPage->SetSize(aNewSize); 919 pPage->SetBorder(nLeft, nUpper, nRight, nLower); 920 } 921 SdPage* pNotesPage = pDoc->GetSdPage(i, PK_NOTES); 922 DBG_ASSERT( pNotesPage, "Wrong page ordering!" ); 923 if( pNotesPage ) pNotesPage->SetAutoLayout( pNotesPage->GetAutoLayout() ); 924 pPage->SetAutoLayout( pPage->GetAutoLayout() ); 925 } 926 } 927 928 SdPage* pHandoutPage = pDoc->GetSdPage(0, PK_HANDOUT); 929 pHandoutPage->CreateTitleAndLayout(sal_True); 930 931 if( (eMedium != OUTPUT_ORIGINAL) && pViewFrame && pViewFrame->GetDispatcher()) 932 { 933 pViewFrame->GetDispatcher()->Execute(SID_SIZE_PAGE, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD); 934 } 935 } 936 937 938 939 940 //===== OutlineToImpressFinalize ============================================== 941 942 namespace { 943 944 OutlineToImpressFinalizer::OutlineToImpressFinalizer ( 945 ::sd::ViewShellBase& rBase, 946 SdDrawDocument& rDocument, 947 SvLockBytes& rBytes) 948 : mrBase(rBase), 949 mrDocument(rDocument), 950 mpStream() 951 { 952 // The given stream has a lifetime shorter than this new 953 // OutlineToImpressFinalizer object. Therefore a local copy of the 954 // stream is created. 955 const SvStream* pStream (rBytes.GetStream()); 956 if (pStream != NULL) 957 { 958 // Create a memory stream and prepare to fill it with the content of 959 // the original stream. 960 mpStream.reset(new SvMemoryStream()); 961 static const sal_Size nBufferSize = 4096; 962 ::boost::scoped_array<sal_Int8> pBuffer (new sal_Int8[nBufferSize]); 963 964 sal_Size nReadPosition (0); 965 bool bLoop (true); 966 while (bLoop) 967 { 968 // Read the next part of the original stream. 969 sal_Size nReadByteCount (0); 970 const ErrCode nErrorCode ( 971 rBytes.ReadAt( 972 nReadPosition, 973 reinterpret_cast<void*>(pBuffer.get()), 974 nBufferSize, 975 &nReadByteCount)); 976 977 // Check the error code and stop copying the stream data when an 978 // error has occured. 979 switch (nErrorCode) 980 { 981 case ERRCODE_NONE: 982 if (nReadByteCount == 0) 983 bLoop = false; 984 break; 985 case ERRCODE_IO_PENDING: 986 break; 987 988 default: 989 bLoop = false; 990 nReadByteCount = 0; 991 break; 992 } 993 994 // Append the read bytes to the end of the memory stream. 995 if (nReadByteCount > 0) 996 { 997 mpStream->Write(reinterpret_cast<void*>(pBuffer.get()), nReadByteCount); 998 nReadPosition += nReadByteCount; 999 } 1000 } 1001 1002 // Rewind the memory stream so that in the operator() method its 1003 // content is properly read. 1004 mpStream->Seek(STREAM_SEEK_TO_BEGIN); 1005 } 1006 } 1007 1008 1009 1010 1011 void OutlineToImpressFinalizer::operator() (bool) 1012 { 1013 // Fetch the new outline view shell. 1014 ::sd::OutlineViewShell* pOutlineShell 1015 = dynamic_cast<sd::OutlineViewShell*>(FrameworkHelper::Instance(mrBase)->GetViewShell(FrameworkHelper::msCenterPaneURL).get()); 1016 1017 if (pOutlineShell != NULL && mpStream.get() != NULL) 1018 { 1019 sd::OutlineView* pView = static_cast<sd::OutlineView*>(pOutlineShell->GetView()); 1020 // mba: the stream can't contain any relative URLs, because we don't 1021 // have any information about a BaseURL! 1022 if ( pOutlineShell->Read(*mpStream, String(), EE_FORMAT_RTF) == 0 ) 1023 { 1024 /* 1025 sd::OutlineViewPageChangesGuard aGuard( pView ); 1026 1027 // Remove the first empty pages 1028 sal_uInt16 nPageCount = mrDocument.GetPageCount(); 1029 mrDocument.RemovePage( --nPageCount ); // notes page 1030 mrDocument.RemovePage( --nPageCount ); // standard page 1031 */ 1032 } 1033 1034 // Call UpdatePreview once for every slide to resync the 1035 // document with the outliner of the OutlineViewShell. 1036 sal_uInt16 nPageCount (mrDocument.GetSdPageCount(PK_STANDARD)); 1037 for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++) 1038 { 1039 SdPage* pPage = mrDocument.GetSdPage(nIndex, PK_STANDARD); 1040 // Make the page the actual page so that the 1041 // following UpdatePreview() call accesses the 1042 // correct paragraphs. 1043 pView->SetActualPage(pPage); 1044 pOutlineShell->UpdatePreview(pPage, true); 1045 } 1046 // Select the first slide. 1047 SdPage* pPage = mrDocument.GetSdPage(0, PK_STANDARD); 1048 pView->SetActualPage(pPage); 1049 pOutlineShell->UpdatePreview(pPage, true); 1050 } 1051 1052 1053 // #97231# Undo-Stack needs to be cleared, else the user may remove the 1054 // only drawpage and this is a state we cannot handle ATM. 1055 ::sd::DrawDocShell* pDocShell = mrDocument.GetDocSh(); 1056 if( pDocShell ) 1057 pDocShell->ClearUndoBuffer(); 1058 } 1059 1060 1061 } // end of anonymous namespace 1062