1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 32 #include <com/sun/star/frame/XDispatchHelper.hpp> 33 34 #include <comphelper/processfactory.hxx> 35 36 #include <hintids.hxx> 37 #include <tools/urlobj.hxx> 38 #include <unotools/tempfile.hxx> 39 #include <vcl/wrkwin.hxx> 40 #include <vcl/msgbox.hxx> 41 #include <svl/lckbitem.hxx> 42 #include <svl/eitem.hxx> 43 #include <svl/zforlist.hxx> 44 #include <svl/zformat.hxx> 45 #include <unotools/pathoptions.hxx> 46 #include <svtools/transfer.hxx> 47 #include <sfx2/dialogs.hrc> 48 #include <sfx2/dinfdlg.hxx> 49 #include <sfx2/request.hxx> 50 #include <sfx2/dispatch.hxx> 51 #include <sfx2/new.hxx> 52 #include <sfx2/filedlghelper.hxx> 53 #include <sfx2/printer.hxx> 54 #include <sfx2/evntconf.hxx> 55 #include <svtools/sfxecode.hxx> 56 #include <sfx2/docfile.hxx> 57 #include <sfx2/docfilt.hxx> 58 #include <svx/svxids.hrc> 59 #include <svx/drawitem.hxx> 60 #include <editeng/svxacorr.hxx> 61 #include <editeng/langitem.hxx> 62 #include <svx/fmshell.hxx> 63 64 #include <svtools/htmlcfg.hxx> 65 #include <svx/ofaitem.hxx> 66 #include <SwSmartTagMgr.hxx> 67 #include <sfx2/app.hxx> 68 #include <basic/sbstar.hxx> 69 #include <basic/basmgr.hxx> 70 #include <sot/storage.hxx> 71 #include <sot/clsids.hxx> 72 #include <swunodef.hxx> 73 #include <fmtcol.hxx> 74 #include <swevent.hxx> 75 #include <view.hxx> // fuer die aktuelle Sicht 76 #include <docsh.hxx> // Dokumenterzeugung 77 #include <wrtsh.hxx> 78 #include <fldbas.hxx> 79 #include <viewopt.hxx> 80 #include <globdoc.hxx> 81 #include <fldwrap.hxx> 82 #include <redlndlg.hxx> 83 #include <docstyle.hxx> 84 #include <doc.hxx> 85 #include <IDocumentUndoRedo.hxx> 86 #include <pagedesc.hxx> 87 #include <shellio.hxx> 88 #include <pview.hxx> 89 #include <srcview.hxx> 90 #include <poolfmt.hxx> 91 #include <usrpref.hxx> 92 #include <wdocsh.hxx> 93 #include <unotxdoc.hxx> 94 #include <acmplwrd.hxx> 95 #include <swmodule.hxx> 96 #include <unobaseclass.hxx> 97 #include <swwait.hxx> 98 #include <swcli.hxx> 99 100 #include <cmdid.h> 101 #include <globals.h> 102 #include <helpid.h> 103 #include <app.hrc> 104 #include <poolfmt.hrc> 105 #include <globals.hrc> 106 #include <com/sun/star/ui/dialogs/XFilePicker.hpp> 107 #include <com/sun/star/ui/dialogs/XFilterManager.hpp> 108 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> 109 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 110 #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp> 111 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 112 #include "com/sun/star/ui/dialogs/TemplateDescription.hpp" 113 #ifdef FUTURE_VBA 114 #include <com/sun/star/script/vba/XVBAEventProcessor.hpp> 115 #include <com/sun/star/script/vba/VBAEventId.hpp> 116 #endif 117 #include <editeng/acorrcfg.hxx> 118 #include <SwStyleNameMapper.hxx> 119 120 #include <sfx2/fcontnr.hxx> 121 122 #include "swabstdlg.hxx" 123 #include "dialog.hrc" 124 #include "swabstdlg.hxx" 125 126 #include <ndtxt.hxx> //#outline level,add by zhaojianwei 127 128 using namespace ::com::sun::star::ui::dialogs; 129 using namespace ::com::sun::star::lang; 130 using namespace ::com::sun::star::uno; 131 using namespace ::com::sun::star; 132 using ::rtl::OUString; 133 using namespace ::sfx2; 134 extern sal_Bool FindPhyStyle( SwDoc& , const String& , SfxStyleFamily ); 135 136 /*-------------------------------------------------------------------- 137 Beschreibung: DocInfo kreieren (virtuell) 138 --------------------------------------------------------------------*/ 139 140 SfxDocumentInfoDialog* SwDocShell::CreateDocumentInfoDialog( 141 Window *pParent, const SfxItemSet &rSet) 142 { 143 SfxDocumentInfoDialog* pDlg = new SfxDocumentInfoDialog(pParent, rSet); 144 //nur mit Statistik, wenn dieses Doc auch angezeigt wird, nicht 145 //aus dem Doc-Manager 146 SwDocShell* pDocSh = (SwDocShell*) SfxObjectShell::Current(); 147 if( pDocSh == this ) 148 { 149 //Nicht fuer SourceView. 150 SfxViewShell *pVSh = SfxViewShell::Current(); 151 if ( pVSh && !pVSh->ISA(SwSrcView) ) 152 { 153 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); 154 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!"); 155 pDlg->AddTabPage(TP_DOC_STAT, SW_RESSTR(STR_DOC_STAT),pFact->GetTabPageCreatorFunc( TP_DOC_STAT ),0); 156 } 157 } 158 return pDlg; 159 } 160 161 // Disable "multiple layout" 162 163 void SwDocShell::ToggleBrowserMode(sal_Bool bSet, SwView* _pView ) 164 { 165 GetDoc()->set(IDocumentSettingAccess::BROWSE_MODE, bSet ); 166 UpdateFontList(); 167 SwView* pTempView = _pView ? _pView : (SwView*)GetView(); 168 if( pTempView ) 169 { 170 pTempView->GetViewFrame()->GetBindings().Invalidate(FN_SHADOWCURSOR); 171 if( !GetDoc()->getPrinter( false ) ) 172 pTempView->SetPrinter( GetDoc()->getPrinter( false ), SFX_PRINTER_PRINTER | SFX_PRINTER_JOBSETUP ); 173 GetDoc()->CheckDefaultPageFmt(); 174 SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this, sal_False); 175 do { 176 if( pTmpFrm != pTempView->GetViewFrame() ) 177 { 178 pTmpFrm->DoClose(); 179 pTmpFrm = SfxViewFrame::GetFirst(this, sal_False); 180 } 181 else 182 pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this, sal_False); 183 184 } while ( pTmpFrm ); 185 const SwViewOption& rViewOptions = *pTempView->GetWrtShell().GetViewOptions(); 186 pTempView->GetWrtShell().CheckBrowseView( sal_True ); 187 pTempView->CheckVisArea(); 188 if( bSet ) 189 { 190 const SvxZoomType eType = (SvxZoomType)rViewOptions.GetZoomType(); 191 if ( SVX_ZOOM_PERCENT != eType) 192 ((SwView*)GetView())->SetZoom( eType ); 193 } 194 pTempView->InvalidateBorder(); 195 pTempView->SetNewWindowAllowed(!bSet); 196 } 197 } 198 // End of disabled "multiple layout" 199 200 /// update text fields on document properties changes 201 void SwDocShell::DoFlushDocInfo() 202 { 203 if ( !pDoc ) return; 204 205 bool bUnlockView(true); 206 if ( pWrtShell ) { 207 bUnlockView = !pWrtShell->IsViewLocked(); 208 pWrtShell->LockView( sal_True ); // lock visible section 209 pWrtShell->StartAllAction(); 210 } 211 212 pDoc->DocInfoChgd(); 213 214 if ( pWrtShell ) { 215 pWrtShell->EndAllAction(); 216 if ( bUnlockView ) { 217 pWrtShell->LockView( sal_False ); 218 } 219 } 220 } 221 222 #ifdef FUTURE_VBA 223 void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XVBAEventProcessor >& xVbaEvents, const SfxHint& rHint ) 224 { 225 using namespace com::sun::star::script::vba::VBAEventId; 226 if ( rHint.ISA( SfxEventHint ) ) 227 { 228 uno::Sequence< uno::Any > aArgs; 229 sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId(); 230 switch( nEventId ) 231 { 232 case SFX_EVENT_CREATEDOC: 233 xVbaEvents->processVbaEvent( DOCUMENT_NEW, aArgs ); 234 break; 235 case SFX_EVENT_OPENDOC: 236 xVbaEvents->processVbaEvent( DOCUMENT_OPEN, aArgs ); 237 break; 238 } 239 } 240 } 241 #endif 242 243 /*-------------------------------------------------------------------- 244 Beschreibung: Benachrichtigung bei geaenderter DocInfo 245 --------------------------------------------------------------------*/ 246 247 void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) 248 { 249 if( !pDoc ) 250 { 251 //MA: Kommt bei der OLE-Registration vor! 252 // ASSERT( !this, "DocShell ist nicht richtig initialisiert!" ); 253 return ; 254 } 255 256 #ifdef FUTURE_VBA 257 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor(); 258 if( xVbaEvents.is() ) 259 lcl_processCompatibleSfxHint( xVbaEvents, rHint ); 260 #endif 261 262 sal_uInt16 nAction = 0; 263 if( rHint.ISA(SfxSimpleHint) ) 264 { 265 // swithc for more actions 266 switch( ((SfxSimpleHint&) rHint).GetId() ) 267 { 268 case SFX_HINT_TITLECHANGED: 269 if( GetMedium() ) 270 nAction = 2; 271 break; 272 } 273 } 274 else if( rHint.ISA(SfxEventHint) && 275 ((SfxEventHint&) rHint).GetEventId() == SFX_EVENT_LOADFINISHED ) 276 { 277 // --> OD 2004-12-03 #i38126# - own action id 278 nAction = 3; 279 // <-- 280 } 281 282 if( nAction ) 283 { 284 sal_Bool bUnlockView = sal_True; //initializing prevents warning 285 if( pWrtShell ) 286 { 287 bUnlockView = !pWrtShell->IsViewLocked(); 288 pWrtShell->LockView( sal_True ); //lock visible section 289 pWrtShell->StartAllAction(); 290 } 291 switch( nAction ) 292 { 293 case 2: 294 pDoc->GetSysFldType( RES_FILENAMEFLD )->UpdateFlds(); 295 break; 296 // --> OD 2004-12-03 #i38126# - own action for event LOADFINISHED 297 // in order to avoid a modified document. 298 // --> OD 2005-02-01 #i41679# - Also for the instance of <SwDoc> 299 // it has to be assured, that it's not modified. 300 // Perform the same as for action id 1, but disable <SetModified>. 301 case 3: 302 { 303 const bool bResetModified = IsEnableSetModified(); 304 if ( bResetModified ) 305 EnableSetModified( sal_False ); 306 // --> OD 2005-02-01 #i41679# 307 const bool bIsDocModified = pDoc->IsModified(); 308 // <-- 309 310 pDoc->DocInfoChgd( ); 311 312 // --> OD 2005-02-01 #i41679# 313 if ( !bIsDocModified ) 314 pDoc->ResetModified(); 315 // <-- 316 if ( bResetModified ) 317 EnableSetModified( sal_True ); 318 } 319 break; 320 // <-- 321 } 322 323 if( pWrtShell ) 324 { 325 pWrtShell->EndAllAction(); 326 if( bUnlockView ) 327 pWrtShell->LockView( sal_False ); 328 } 329 } 330 } 331 332 /*-------------------------------------------------------------------- 333 Beschreibung: Benachrichtigung Doc schliessen 334 --------------------------------------------------------------------*/ 335 336 sal_uInt16 SwDocShell::PrepareClose( sal_Bool bUI, sal_Bool bForBrowsing ) 337 { 338 sal_uInt16 nRet = SfxObjectShell::PrepareClose( bUI, bForBrowsing ); 339 340 if( sal_True == nRet ) //Unbedingt auf sal_True abfragen! (RET_NEWTASK) 341 EndListening( *this ); 342 343 #ifdef FUTURE_VBA 344 if( pDoc && IsInPrepareClose() ) 345 { 346 uno::Reference< script::vba::XVBAEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor(); 347 if( xVbaEvents.is() ) 348 { 349 using namespace com::sun::star::script::vba::VBAEventId; 350 uno::Sequence< uno::Any > aArgs; 351 xVbaEvents->processVbaEvent( DOCUMENT_CLOSE, aArgs ); 352 } 353 } 354 #endif 355 return nRet; 356 } 357 358 /*-------------------------------------------------------------------- 359 Beschreibung: Organizer 360 --------------------------------------------------------------------*/ 361 362 sal_Bool SwDocShell::Insert( SfxObjectShell &rSource, 363 sal_uInt16 nSourceIdx1, // SourcePool: oberste Inhaltsebene (Vorlagen/Makros) 364 sal_uInt16 nSourceIdx2, // Index in den Inhalt 365 sal_uInt16 nSourceIdx3, // Index in die Inhaltsebene 366 sal_uInt16 &rIdx1, // und das gleiche fuer den DestinationPool 367 sal_uInt16 &rIdx2, // "" 368 sal_uInt16 &rIdx3, // "" 369 sal_uInt16 &rRemovedIdx ) // falls doppelte geloescht werden, Pos zurueck 370 { 371 // --> OD 2005-05-10 #i48949# - actions aren't undoable. Thus, allow no undo 372 // actions 373 // Note: The undo action stack is cleared at the end of this method. 374 ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo()); 375 // <-- 376 377 sal_Bool bRet = sal_False; 378 379 if (INDEX_IGNORE == rIdx1 && CONTENT_STYLE == nSourceIdx1) 380 rIdx1 = CONTENT_STYLE; 381 382 if (CONTENT_STYLE == nSourceIdx1 && CONTENT_STYLE == rIdx1) 383 { 384 SfxStyleSheetBasePool* pHisPool = rSource.GetStyleSheetPool(); 385 SwDocStyleSheetPool* pMyPool = 386 (SwDocStyleSheetPool*)GetStyleSheetPool(); 387 388 // wir koennen nicht in uns selbst hin und her moven 389 if( pHisPool == pMyPool ) 390 return sal_False; 391 392 if( INDEX_IGNORE == rIdx2 ) 393 rIdx2 = pMyPool->Count(); 394 395 // erstmal auf die Such-Maske "positionieren" 396 pHisPool->First(); 397 SfxStyleSheetBase* pHisSheet = (*pHisPool)[nSourceIdx2]; 398 399 // wenn so eine Vorlage schon existiert: loeschen! 400 const String& rOldName = pHisSheet->GetName(); 401 SfxStyleFamily eOldFamily( pHisSheet->GetFamily() ); 402 403 // dflt. PageDesc und StandardZeichenvorlage nie loeschen !!! 404 if( ( SFX_STYLE_FAMILY_PAGE == eOldFamily && 405 const_cast<const SwDoc *>(pDoc)->GetPageDesc(0).GetName() == 406 rOldName ) || 407 ( SFX_STYLE_FAMILY_CHAR == eOldFamily && 408 rOldName == *SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD - 409 RES_POOLCOLL_TEXT_BEGIN ] )) 410 return sal_False; 411 412 SfxStyleFamily eMyOldFamily( pMyPool->GetSearchFamily() ); 413 sal_uInt16 nMySrchMask = pMyPool->GetSearchMask(); 414 415 SfxStyleSheetBase* pExist; 416 if( ::FindPhyStyle( *pDoc, rOldName, eOldFamily ) ) 417 { 418 // Bug 20365: nur uebernehmen, wenn das gewuenscht ist! 419 if( ERRCODE_BUTTON_OK != ErrorHandler::HandleError( 420 *new MessageInfo( ERRCODE_SFXMSG_STYLEREPLACE, rOldName )) ) 421 { 422 return sal_False; 423 } 424 425 // Da Replace den aStyleSheet-Member selbst benoetigt, muss 426 // das Ergebnis vom Find kopiert werden (s.u.)) 427 rtl::Reference< SwDocStyleSheet > xExist( new SwDocStyleSheet( 428 *(SwDocStyleSheet*)pMyPool->Find( rOldName, eOldFamily ) ) ); 429 pMyPool->Replace( *pHisSheet, *xExist.get() ); 430 431 // An der Reihenfolge der Vorlagen im Pool aendert sich nichts. 432 rIdx2 = rIdx1 = INDEX_IGNORE; 433 434 GetDoc()->SetModified(); 435 436 return sal_True; 437 } 438 439 pMyPool->SetSearchMask( eOldFamily, nMySrchMask ); 440 441 // MIB 18.12.98: SwDocStyleSheetPool::Make liefert einen 442 // Pointer auf SwDocStyleSheetPool::aStyleSheet zurueck. 443 // Der gleiche Member von SwDocStyleSheetPool::Find benutzt. 444 // Deshalb muss hier mit einer Kopie gearbeitet werden. 445 // Vorsicht: SfxStyleSheetBase::SetFollow ruft seinerseits 446 // ein SwDocStyleSheetPool::Find auf, do dass es nicht genuegt 447 // die Find-Aufrufe in dieser Methode zu eleminieren. 448 449 rtl::Reference< SwDocStyleSheet > xNewSheet( new SwDocStyleSheet( (SwDocStyleSheet&)pMyPool 450 ->Make(rOldName, eOldFamily, pHisSheet->GetMask() ) ) ); 451 if( SFX_STYLE_FAMILY_PAGE == eOldFamily && rSource.ISA(SwDocShell) ) 452 { 453 // gesondert behandeln!! 454 SwPageDesc* pDestDsc = (SwPageDesc*)xNewSheet->GetPageDesc(); 455 SwPageDesc* pCpyDsc = (SwPageDesc*)((SwDocStyleSheet*)pHisSheet)->GetPageDesc(); 456 pDoc->CopyPageDesc( *pCpyDsc, *pDestDsc ); 457 } 458 else 459 // die neue Vorlage mit den Attributen fuellen 460 xNewSheet->SetItemSet( pHisSheet->GetItemSet() ); 461 462 pMyPool->SetSearchMask( SFX_STYLE_FAMILY_ALL, nMySrchMask ); 463 464 if( xNewSheet->IsUserDefined() || xNewSheet->IsUsed() ) 465 { 466 // Benutzte und Benutzer-definierte Vorlagen werden angezeigt. 467 // Dshalb muss hier der Index der neuen Vorlage im Pool 468 // ermittelt werden. 469 pExist = pMyPool->First(); 470 sal_uInt16 nIdx = 0; 471 while( pExist ) 472 { 473 if( pExist->GetName() == rOldName && 474 eOldFamily == pExist->GetFamily() ) 475 { 476 rIdx2 = nIdx; 477 break; 478 } 479 pExist = pMyPool->Next(); 480 nIdx++; 481 } 482 } 483 else 484 { 485 // Andere Vorlagen werden nicht angezeigt. 486 rIdx1 = rIdx2 = INDEX_IGNORE; 487 } 488 489 /* pMyPool->Count(); //interne Liste neu fuellen lassen!!!!! 490 491 // suchen, um die richige Insert-Position returnen zu koennen 492 pMyPool->Find( rOldName, SFX_STYLE_FAMILY_ALL, nMySrchMask ); 493 rIdx2 = pMyPool->GetFindPos();*/ 494 495 // wer bekommt den Neuen als Parent? wer benutzt den Neuen als Follow? 496 // (immer nur ueber die Instanziierten!!!) 497 pMyPool->SetSearchMask( eOldFamily, nMySrchMask ); 498 pMyPool->SetOrganizerMode( sal_True ); 499 SfxStyleSheetBase* pTestSheet = pMyPool->First(); 500 while (pTestSheet) 501 { 502 if (pTestSheet->GetFamily() == eOldFamily && 503 pTestSheet->HasParentSupport() && 504 pTestSheet->GetParent() == rOldName) 505 { 506 pTestSheet->SetParent(rOldName); // Verknuepfung neu aufbauen 507 } 508 509 if (pTestSheet->GetFamily() == eOldFamily && 510 pTestSheet->HasFollowSupport() && 511 pTestSheet->GetFollow() == rOldName) 512 { 513 pTestSheet->SetFollow(rOldName); // Verknuepfung neu aufbauen 514 } 515 516 pTestSheet = pMyPool->Next(); 517 } 518 pMyPool->SetOrganizerMode( SFX_CREATE_MODE_ORGANIZER == GetCreateMode() ); 519 520 // hat der Neue einen Parent? wenn ja, mit gleichem Namen bei uns suchen 521 if (pHisSheet->HasParentSupport()) 522 { 523 const String& rParentName = pHisSheet->GetParent(); 524 if (0 != rParentName.Len()) 525 { 526 SfxStyleSheetBase* pParentOfNew = pMyPool->Find(rParentName, 527 eOldFamily); 528 if (pParentOfNew) 529 { 530 xNewSheet->SetParent(rParentName); 531 } 532 pMyPool->SetSearchMask( eOldFamily, nMySrchMask ); 533 } 534 } 535 536 // hat der Neue einen Follow? wenn ja, mit gleichem Namen bei uns suchen 537 if (pHisSheet->HasFollowSupport()) 538 { 539 const String& rFollowName = pHisSheet->GetFollow(); 540 if (0 != rFollowName.Len()) 541 { 542 SfxStyleSheetBase* pFollowOfNew = pMyPool->Find(rFollowName, 543 eOldFamily); 544 if (pFollowOfNew) 545 { 546 xNewSheet->SetFollow(rFollowName); 547 } 548 pMyPool->SetSearchMask( eOldFamily, nMySrchMask ); 549 } 550 } 551 552 // Bug 27347: alte Einstellung wieder setzen 553 pMyPool->SetSearchMask( eMyOldFamily, nMySrchMask ); 554 555 // Model geaendert 556 ASSERT(pDoc, "Doc fehlt"); 557 GetDoc()->SetModified(); 558 559 bRet = sal_True; 560 } 561 else 562 bRet = SfxObjectShell::Insert( rSource, 563 nSourceIdx1, 564 nSourceIdx2, 565 nSourceIdx3, 566 rIdx1, 567 rIdx2, 568 rIdx3, 569 rRemovedIdx); 570 571 // --> OD 2005-05-10 #i48949# - actions aren't undoable and could have change 572 // the document node array. Thus, clear the undo action stack. 573 if (undoGuard.UndoWasEnabled()) 574 { 575 GetDoc()->GetIDocumentUndoRedo().DelAllUndoObj(); 576 } 577 // <-- 578 579 return bRet; 580 } 581 582 /*-------------------------------------------------------------------- 583 Beschreibung: Vorlagen Remove 584 --------------------------------------------------------------------*/ 585 586 sal_Bool SwDocShell::Remove(sal_uInt16 nIdx1, // siehe Insert 587 sal_uInt16 nIdx2, 588 sal_uInt16 nIdx3) 589 { 590 sal_Bool bRet = sal_False; 591 592 if (CONTENT_STYLE == nIdx1) 593 { 594 SwDocStyleSheetPool* pMyPool = (SwDocStyleSheetPool*)GetStyleSheetPool(); 595 596 pMyPool->First(); // vorm Zugriff Pool aktualisieren!! 597 SfxStyleSheetBase* pMySheet = (*pMyPool)[nIdx2]; 598 599 String aName( pMySheet->GetName() ); 600 SfxStyleFamily eFamily( pMySheet->GetFamily() ); 601 602 // dflt. PageDesc und StandardZeichenvorlage nie loeschen !!! 603 if( ( SFX_STYLE_FAMILY_PAGE == eFamily && 604 const_cast<const SwDoc *>(pDoc)->GetPageDesc(0).GetName() 605 == aName ) || 606 ( SFX_STYLE_FAMILY_CHAR == eFamily && 607 aName == *SwStyleNameMapper::GetTextUINameArray()[ RES_POOLCOLL_STANDARD - 608 RES_POOLCOLL_TEXT_BEGIN ] )) 609 return sal_False; 610 611 // also loeschen 612 pMyPool->Remove( pMySheet ); 613 614 // jetzt noch die Parents/Follows aller Instanziierten korrigieren 615 pMyPool->SetOrganizerMode( sal_True ); 616 SfxStyleSheetBase* pTestSheet = pMyPool->First(); 617 while (pTestSheet) 618 { 619 if (pTestSheet->GetFamily() == eFamily && 620 pTestSheet->HasParentSupport() && 621 pTestSheet->GetParent() == aName) 622 { 623 pTestSheet->SetParent( aEmptyStr ); // Verknuepfung aufloesen 624 } 625 626 if (pTestSheet->GetFamily() == eFamily && 627 pTestSheet->HasFollowSupport() && 628 pTestSheet->GetFollow() == aName) 629 { 630 pTestSheet->SetFollow( aEmptyStr ); // Verknuepfung aufloesen 631 } 632 633 pTestSheet = pMyPool->Next(); 634 } 635 pMyPool->SetOrganizerMode( SFX_CREATE_MODE_ORGANIZER == GetCreateMode() ); 636 637 bRet = sal_True; 638 } 639 else 640 bRet = SfxObjectShell::Remove( nIdx1, 641 nIdx2, 642 nIdx3 ); 643 644 645 // Model geaendert 646 ASSERT(pDoc, "Doc fehlt"); 647 GetDoc()->SetModified(); 648 649 return bRet; 650 } 651 652 /*-------------------------------------------------------------------- 653 Beschreibung: 654 --------------------------------------------------------------------*/ 655 656 void SwDocShell::Execute(SfxRequest& rReq) 657 { 658 const SfxItemSet* pArgs = rReq.GetArgs(); 659 const SfxPoolItem* pItem; 660 sal_uInt16 nWhich = rReq.GetSlot(); 661 sal_Bool bDone = sal_False; 662 switch ( nWhich ) 663 { 664 case SID_AUTO_CORRECT_DLG: 665 { 666 SvxSwAutoFmtFlags* pAFlags = &SvxAutoCorrCfg::Get()->GetAutoCorrect()->GetSwFlags(); 667 SwAutoCompleteWord& rACW = SwDoc::GetAutoCompleteWords(); 668 669 sal_Bool bOldLocked = rACW.IsLockWordLstLocked(), 670 bOldAutoCmpltCollectWords = pAFlags->bAutoCmpltCollectWords; 671 672 rACW.SetLockWordLstLocked( sal_True ); 673 674 SvStringsISortDtor aTmpLst; 675 aTmpLst.Insert( &rACW.GetWordList() ); 676 pAFlags->pAutoCmpltList = &aTmpLst; 677 678 SfxApplication* pApp = SFX_APP(); 679 SfxRequest aAppReq(SID_AUTO_CORRECT_DLG, SFX_CALLMODE_SYNCHRON, pApp->GetPool()); 680 SfxBoolItem aSwOptions( SID_AUTO_CORRECT_DLG, sal_True ); 681 aAppReq.AppendItem(aSwOptions); 682 683 // SMARTTAGS 684 pAFlags->pSmartTagMgr = &SwSmartTagMgr::Get(); 685 686 //pApp->ExecuteSlot(aAppReq); 687 688 SfxItemSet aSet( pApp->GetPool(), SID_AUTO_CORRECT_DLG, SID_AUTO_CORRECT_DLG, SID_OPEN_SMARTTAGOPTIONS, SID_OPEN_SMARTTAGOPTIONS, 0 ); 689 aSet.Put( aSwOptions ); 690 691 const SfxPoolItem* pOpenSmartTagOptionsItem = 0; 692 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( SID_OPEN_SMARTTAGOPTIONS, sal_False, &pOpenSmartTagOptionsItem ) ) 693 aSet.Put( *static_cast<const SfxBoolItem*>(pOpenSmartTagOptionsItem) ); 694 695 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); 696 SfxAbstractTabDialog* pDlg = pFact->CreateTabDialog( RID_OFA_AUTOCORR_DLG, NULL, &aSet, NULL ); 697 pDlg->Execute(); 698 delete pDlg; 699 700 rACW.SetLockWordLstLocked( bOldLocked ); 701 702 SwEditShell::SetAutoFmtFlags( pAFlags ); 703 rACW.SetMinWordLen( pAFlags->nAutoCmpltWordLen ); 704 rACW.SetMaxCount( pAFlags->nAutoCmpltListLen ); 705 if( pAFlags->pAutoCmpltList ) // any changes? 706 { 707 rACW.CheckChangedList( aTmpLst ); 708 // clear the temp WordList pointer 709 pAFlags->pAutoCmpltList = 0; 710 } 711 // remove all pointer we never delete the strings 712 aTmpLst.Remove( (sal_uInt16)0, aTmpLst.Count() ); 713 714 if( !bOldAutoCmpltCollectWords && bOldAutoCmpltCollectWords != 715 pAFlags->bAutoCmpltCollectWords ) 716 { 717 // call on all Docs the idle formatter to start 718 // the collection of Words 719 TypeId aType = TYPE(SwDocShell); 720 for( SwDocShell *pDocSh = (SwDocShell*)SfxObjectShell::GetFirst(&aType); 721 pDocSh; 722 pDocSh = (SwDocShell*)SfxObjectShell::GetNext( *pDocSh, &aType ) ) 723 { 724 SwDoc* pTmp = pDocSh->GetDoc(); 725 if ( pTmp->GetCurrentViewShell() ) //swmod 071108//swmod 071225 726 pTmp->InvalidateAutoCompleteFlag(); 727 } 728 } 729 } 730 break; 731 732 case SID_PRINTPREVIEW: 733 { 734 sal_Bool bSet = sal_False, bFound = sal_False, bOnly = sal_True; 735 SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(this); 736 SfxViewShell* pViewShell = SfxViewShell::Current(); 737 SwView* pCurrView = dynamic_cast< SwView *> ( pViewShell ); 738 sal_Bool bCurrent = IS_TYPE( SwPagePreView, pViewShell ); 739 740 while( pTmpFrm ) // search PreView 741 { 742 if( IS_TYPE( SwView, pTmpFrm->GetViewShell()) ) 743 bOnly = sal_False; 744 else if( IS_TYPE( SwPagePreView, pTmpFrm->GetViewShell())) 745 { 746 pTmpFrm->GetFrame().Appear(); 747 bFound = sal_True; 748 } 749 if( bFound && !bOnly ) 750 break; 751 pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, this); 752 } 753 754 if( pArgs && SFX_ITEM_SET == 755 pArgs->GetItemState( SID_PRINTPREVIEW, sal_False, &pItem )) 756 bSet = ((SfxBoolItem*)pItem)->GetValue(); 757 else 758 bSet = !bCurrent; 759 760 sal_uInt16 nSlotId = 0; 761 if( bSet && !bFound ) // Keine gefunden, daher neue Preview anlegen 762 nSlotId = SID_VIEWSHELL1; 763 else if( bFound && !bSet ) 764 nSlotId = bOnly ? SID_VIEWSHELL0 : SID_VIEWSHELL1; 765 766 if( nSlotId ) 767 { 768 //JP 23.8.2001: Bug 91360 - PagePreView in the WebDocShell 769 // is found under Id ViewShell2. 770 if( ISA(SwWebDocShell) && SID_VIEWSHELL1 == nSlotId ) 771 nSlotId = SID_VIEWSHELL2; 772 773 if( pCurrView && pCurrView->GetDocShell() == this ) 774 pTmpFrm = pCurrView->GetViewFrame(); 775 else 776 pTmpFrm = SfxViewFrame::GetFirst( this ); 777 778 pTmpFrm->GetDispatcher()->Execute( nSlotId, 0, 0, SFX_CALLMODE_ASYNCHRON ); 779 } 780 781 rReq.SetReturnValue(SfxBoolItem(SID_PRINTPREVIEW, bSet )); 782 } 783 break; 784 case SID_TEMPLATE_LOAD: 785 { 786 String aFileName; 787 static sal_Bool bText = sal_True; 788 static sal_Bool bFrame = sal_False; 789 static sal_Bool bPage = sal_False; 790 static sal_Bool bNum = sal_False; 791 static sal_Bool bMerge = sal_False; 792 sal_uInt16 nRet = USHRT_MAX; 793 794 sal_uInt16 nFlags = bFrame ? SFX_LOAD_FRAME_STYLES : 0; 795 if(bPage) 796 nFlags|= SFX_LOAD_PAGE_STYLES; 797 if(bNum) 798 nFlags|= SFX_LOAD_NUM_STYLES; 799 if(!nFlags || bText) 800 nFlags|= SFX_LOAD_TEXT_STYLES; 801 if(bMerge) 802 nFlags|= SFX_MERGE_STYLES; 803 804 if ( pArgs ) 805 { 806 SFX_REQUEST_ARG( rReq, pTemplateItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False ); 807 if ( pTemplateItem ) 808 { 809 aFileName = pTemplateItem->GetValue(); 810 SFX_REQUEST_ARG( rReq, pFlagsItem, SfxInt32Item, SID_TEMPLATE_LOAD, sal_False ); 811 if ( pFlagsItem ) 812 nFlags = (sal_uInt16) pFlagsItem->GetValue(); 813 } 814 } 815 816 if ( !aFileName.Len() ) 817 { 818 SvtPathOptions aPathOpt; 819 SfxNewFileDialog* pNewFileDlg = 820 new SfxNewFileDialog(&GetView()->GetViewFrame()->GetWindow(), SFXWB_LOAD_TEMPLATE); 821 pNewFileDlg->SetTemplateFlags(nFlags); 822 823 nRet = pNewFileDlg->Execute(); 824 if(RET_TEMPLATE_LOAD == nRet) 825 { 826 FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 ); 827 uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); 828 829 xFP->setDisplayDirectory( aPathOpt.GetWorkPath() ); 830 831 SfxObjectFactory &rFact = GetFactory(); 832 SfxFilterMatcher aMatcher( String::CreateFromAscii(rFact.GetShortName()) ); 833 SfxFilterMatcherIter aIter( &aMatcher ); 834 uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY); 835 const SfxFilter* pFlt = aIter.First(); 836 while( pFlt ) 837 { 838 // --> OD #i117339# 839 // if( pFlt && pFlt->IsAllowedAsTemplate() ) 840 if( pFlt && pFlt->IsAllowedAsTemplate() && 841 ( pFlt->GetUserData().EqualsAscii("CXML") || 842 pFlt->GetUserData().EqualsAscii("CXMLV") ) ) 843 { 844 const String sWild = ((WildCard&)pFlt->GetWildcard()).GetWildCard(); 845 xFltMgr->appendFilter( pFlt->GetUIName(), sWild ); 846 } 847 pFlt = aIter.Next(); 848 } 849 sal_Bool bWeb = 0 != dynamic_cast< SwWebDocShell *>( this ); 850 const SfxFilter *pOwnFlt = 851 SwDocShell::Factory().GetFilterContainer()-> 852 GetFilter4FilterName(String::CreateFromAscii("writer8")); 853 854 //#b6439685# make sure the default file format is also available 855 if(bWeb) 856 { 857 const String sWild = ((WildCard&)pOwnFlt->GetWildcard()).GetWildCard(); 858 xFltMgr->appendFilter( pOwnFlt->GetUIName(), sWild ); 859 } 860 861 bool bError = false; 862 //#b6439685# catch expception if wrong filter is selected - should not happen anymore 863 try 864 { 865 xFltMgr->setCurrentFilter( pOwnFlt->GetUIName() ); 866 } 867 catch( const uno::Exception& ) 868 { 869 bError = true; 870 } 871 872 if( !bError && ERRCODE_NONE == aDlgHelper.Execute() ) 873 { 874 aFileName = xFP->getFiles().getConstArray()[0]; 875 } 876 } 877 else if( RET_OK == nRet) 878 { 879 aFileName = pNewFileDlg->GetTemplateFileName(); 880 } 881 882 nFlags = pNewFileDlg->GetTemplateFlags(); 883 rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aFileName ) ); 884 rReq.AppendItem( SfxInt32Item( SID_TEMPLATE_LOAD, (long) nFlags ) ); 885 delete pNewFileDlg; 886 } 887 888 if( aFileName.Len() ) 889 { 890 SwgReaderOption aOpt; 891 aOpt.SetTxtFmts( bText = (0 != (nFlags&SFX_LOAD_TEXT_STYLES) )); 892 aOpt.SetFrmFmts( bFrame = (0 != (nFlags&SFX_LOAD_FRAME_STYLES))); 893 aOpt.SetPageDescs( bPage = (0 != (nFlags&SFX_LOAD_PAGE_STYLES ))); 894 aOpt.SetNumRules( bNum = (0 != (nFlags&SFX_LOAD_NUM_STYLES ))); 895 //different meaning between SFX_MERGE_STYLES and aOpt.SetMerge! 896 bMerge = 0 != (nFlags&SFX_MERGE_STYLES); 897 aOpt.SetMerge( !bMerge ); 898 899 SetError( LoadStylesFromFile( aFileName, aOpt, sal_False ), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) )); 900 if ( !GetError() ) 901 rReq.Done(); 902 } 903 } 904 break; 905 case SID_SOURCEVIEW: 906 { 907 SfxViewShell* pViewShell = GetView() 908 ? (SfxViewShell*)GetView() 909 : SfxViewShell::Current(); 910 SfxViewFrame* pViewFrm = pViewShell->GetViewFrame(); 911 SwSrcView* pSrcView = dynamic_cast< SwSrcView *>( pViewShell ); 912 if(!pSrcView) 913 { 914 // 3 possible state: 915 // 1 - file unsaved -> save as HTML 916 // 2 - file modified and HTML filter active -> save 917 // 3 - file saved in non-HTML -> QueryBox to save as HTML 918 const SfxFilter* pHtmlFlt = 919 SwIoSystem::GetFilterOfFormat( 920 String::CreateFromAscii("HTML"), 921 SwWebDocShell::Factory().GetFilterContainer() ); 922 sal_Bool bLocalHasName = HasName(); 923 if(bLocalHasName) 924 { 925 //check for filter type 926 const SfxFilter* pFlt = GetMedium()->GetFilter(); 927 if(!pFlt || pFlt->GetUserData() != pHtmlFlt->GetUserData()) 928 { 929 QueryBox aQuery(&pViewFrm->GetWindow(), SW_RES(MSG_SAVEAS_HTML_QUERY)); 930 if(RET_YES == aQuery.Execute()) 931 bLocalHasName = sal_False; 932 else 933 break; 934 } 935 } 936 if(!bLocalHasName) 937 { 938 FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 ); 939 aDlgHelper.AddFilter( pHtmlFlt->GetFilterName(), pHtmlFlt->GetDefaultExtension() ); 940 aDlgHelper.SetCurrentFilter( pHtmlFlt->GetFilterName() ); 941 if( ERRCODE_NONE != aDlgHelper.Execute()) 942 { 943 break; 944 } 945 String sPath = aDlgHelper.GetPath(); 946 SfxStringItem aName(SID_FILE_NAME, sPath); 947 SfxStringItem aFilter(SID_FILTER_NAME, pHtmlFlt->GetName()); 948 const SfxBoolItem* pBool = (const SfxBoolItem*) 949 pViewFrm->GetDispatcher()->Execute( 950 SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON, &aName, &aFilter, 0L ); 951 if(!pBool || !pBool->GetValue()) 952 break; 953 } 954 } 955 #ifdef DBG_UTIL 956 { 957 sal_Bool bWeb = 0 != dynamic_cast<SwWebDocShell*>(this); 958 DBG_ASSERT(bWeb == sal_True, "SourceView nur in der WebDocShell"); 959 } 960 #endif 961 // die SourceView ist fuer die SwWebDocShell die 1 962 sal_uInt16 nSlot = SID_VIEWSHELL1; 963 sal_Bool bSetModified = sal_False; 964 SfxPrinter* pSavePrinter = 0; 965 if( 0 != pSrcView) 966 { 967 SfxPrinter* pTemp = GetDoc()->getPrinter( false ); 968 if(pTemp) 969 pSavePrinter = new SfxPrinter(*pTemp); 970 bSetModified = IsModified() || pSrcView->IsModified(); 971 if(pSrcView->IsModified()||pSrcView->HasSourceSaved()) 972 { 973 utl::TempFile aTempFile; 974 aTempFile.EnableKillingFile(); 975 pSrcView->SaveContent(aTempFile.GetURL()); 976 bDone = sal_True; 977 SvxMacro aMac(aEmptyStr, aEmptyStr, STARBASIC); 978 SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_OPENDOC ), aMac, this); 979 SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEDOC ), aMac, this); 980 SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_ACTIVATEDOC ), aMac, this); 981 SfxEventConfiguration::ConfigureEvent(GlobalEventConfig::GetEventName( STR_EVENT_DEACTIVATEDOC ), aMac, this); 982 ReloadFromHtml(aTempFile.GetURL(), pSrcView); 983 nSlot = 0; 984 } 985 else 986 { 987 nSlot = SID_VIEWSHELL0; 988 } 989 } 990 /* OS 10.04.97 14.20: Im Web-Writer gibt es keinen Unterschied zwischen 991 Export in den SourceMode und dem Speichern des Docs 992 else if(IsModified()) 993 { 994 sal_uInt16 nRet = QueryBox( SFX_APPWINDOW ,SW_RES(MSG_SAVE_HTML_QUERY)).Execute(); 995 if(RET_YES == nRet) 996 { 997 S F X _DISPATCHER().Execute(SID_SAVEDOC, 998 SFX_CALLMODE_SYNCHRON); 999 // der ReturnValue von SID_SAVEDOC ist etwas schwer verstaendlich 1000 if(IsModified()) 1001 nSlot = 0; 1002 } 1003 else if( RET_CANCEL == nRet ) 1004 { 1005 nSlot = 0; 1006 } 1007 }*/ 1008 if(nSlot) 1009 pViewFrm->GetDispatcher()->Execute(nSlot, SFX_CALLMODE_SYNCHRON); 1010 if(bSetModified) 1011 GetDoc()->SetModified(); 1012 if(pSavePrinter) 1013 { 1014 GetDoc()->setPrinter( pSavePrinter, true, true); 1015 //pSavePrinter darf nicht wieder geloescht werden 1016 } 1017 pViewFrm->GetBindings().SetState(SfxBoolItem(SID_SOURCEVIEW, nSlot == SID_VIEWSHELL2)); 1018 pViewFrm->GetBindings().Invalidate( SID_NEWWINDOW ); 1019 pViewFrm->GetBindings().Invalidate( SID_BROWSER_MODE ); 1020 pViewFrm->GetBindings().Invalidate( FN_PRINT_LAYOUT ); 1021 } 1022 break; 1023 case SID_GET_COLORTABLE: 1024 { 1025 SvxColorTableItem* pColItem = (SvxColorTableItem*)GetItem(SID_COLOR_TABLE); 1026 XColorTable* pTable = pColItem->GetColorTable(); 1027 rReq.SetReturnValue(OfaPtrItem(SID_GET_COLORTABLE, pTable)); 1028 } 1029 break; 1030 case FN_ABSTRACT_STARIMPRESS: 1031 case FN_ABSTRACT_NEWDOC: 1032 { 1033 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); 1034 DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!"); 1035 1036 AbstractSwInsertAbstractDlg* pDlg = pFact->CreateSwInsertAbstractDlg(0, DLG_INSERT_ABSTRACT ); 1037 DBG_ASSERT(pDlg, "Dialogdiet fail!"); 1038 if(RET_OK == pDlg->Execute()) 1039 { 1040 sal_uInt8 nLevel = pDlg->GetLevel(); 1041 sal_uInt8 nPara = pDlg->GetPara(); 1042 SwDoc* pSmryDoc = new SwDoc(); 1043 SfxObjectShellLock xDocSh( new SwDocShell( pSmryDoc, SFX_CREATE_MODE_STANDARD)); 1044 xDocSh->DoInitNew( 0 ); 1045 1046 sal_Bool bImpress = FN_ABSTRACT_STARIMPRESS == nWhich; 1047 pDoc->Summary( pSmryDoc, nLevel, nPara, bImpress ); 1048 if( bImpress ) 1049 { 1050 WriterRef xWrt; 1051 // mba: looks as if relative URLs don't make sense here 1052 ::GetRTFWriter( aEmptyStr, String(), xWrt ); 1053 SvMemoryStream *pStrm = new SvMemoryStream(); 1054 pStrm->SetBufferSize( 16348 ); 1055 SwWriter aWrt( *pStrm, *pSmryDoc ); 1056 ErrCode eErr = aWrt.Write( xWrt ); 1057 if( !ERRCODE_TOERROR( eErr ) ) 1058 { 1059 uno::Reference< lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory(); 1060 uno::Reference< frame::XDispatchProvider > xProv( 1061 xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY ); 1062 if ( xProv.is() ) 1063 { 1064 ::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( "SendOutlineToImpress" ); 1065 uno::Reference< frame::XDispatchHelper > xHelper( 1066 xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY ); 1067 if ( xHelper.is() ) 1068 { 1069 pStrm->Seek( STREAM_SEEK_TO_END ); 1070 *pStrm << '\0'; 1071 pStrm->Seek( STREAM_SEEK_TO_BEGIN ); 1072 1073 // Transfer ownership of stream to a lockbytes object 1074 SvLockBytes aLockBytes( pStrm, sal_True ); 1075 SvLockBytesStat aStat; 1076 if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE ) 1077 { 1078 sal_uInt32 nLen = aStat.nSize; 1079 sal_uLong nRead = 0; 1080 uno::Sequence< sal_Int8 > aSeq( nLen ); 1081 aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead ); 1082 1083 uno::Sequence< beans::PropertyValue > aArgs(1); 1084 aArgs[0].Name = ::rtl::OUString::createFromAscii("RtfOutline"); 1085 aArgs[0].Value <<= aSeq; 1086 xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aArgs ); 1087 } 1088 } 1089 } 1090 } 1091 else 1092 ErrorHandler::HandleError(ErrCode( eErr )); 1093 } 1094 else 1095 { 1096 // Neues Dokument erzeugen. 1097 SfxViewFrame *pFrame = SfxViewFrame::LoadDocument( *xDocSh, 0 ); 1098 SwView *pCurrView = (SwView*) pFrame->GetViewShell(); 1099 1100 // Dokumenttitel setzen 1101 String aTmp( SW_RES(STR_ABSTRACT_TITLE) ); 1102 aTmp += GetTitle(); 1103 xDocSh->SetTitle( aTmp ); 1104 pCurrView->GetWrtShell().SetNewDoc(); 1105 pFrame->Show(); 1106 pSmryDoc->SetModified(); 1107 } 1108 1109 } 1110 delete pDlg; 1111 } 1112 break; 1113 case FN_OUTLINE_TO_CLIPBOARD: 1114 case FN_OUTLINE_TO_IMPRESS: 1115 { 1116 sal_Bool bEnable = IsEnableSetModified(); 1117 EnableSetModified( sal_False ); 1118 WriterRef xWrt; 1119 // mba: looks as if relative URLs don't make sense here 1120 ::GetRTFWriter( 'O', String(), xWrt ); 1121 SvMemoryStream *pStrm = new SvMemoryStream(); 1122 pStrm->SetBufferSize( 16348 ); 1123 SwWriter aWrt( *pStrm, *GetDoc() ); 1124 ErrCode eErr = aWrt.Write( xWrt ); 1125 EnableSetModified( bEnable ); 1126 if( !ERRCODE_TOERROR( eErr ) ) 1127 { 1128 pStrm->Seek( STREAM_SEEK_TO_END ); 1129 *pStrm << '\0'; 1130 pStrm->Seek( STREAM_SEEK_TO_BEGIN ); 1131 if ( nWhich == FN_OUTLINE_TO_IMPRESS ) 1132 { 1133 uno::Reference< lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory(); 1134 uno::Reference< frame::XDispatchProvider > xProv( 1135 xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.drawing.ModuleDispatcher")), UNO_QUERY ); 1136 if ( xProv.is() ) 1137 { 1138 ::rtl::OUString aCmd = ::rtl::OUString::createFromAscii( "SendOutlineToImpress" ); 1139 uno::Reference< frame::XDispatchHelper > xHelper( 1140 xORB->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.frame.DispatchHelper")), UNO_QUERY ); 1141 if ( xHelper.is() ) 1142 { 1143 pStrm->Seek( STREAM_SEEK_TO_END ); 1144 *pStrm << '\0'; 1145 pStrm->Seek( STREAM_SEEK_TO_BEGIN ); 1146 1147 // Transfer ownership of stream to a lockbytes object 1148 SvLockBytes aLockBytes( pStrm, sal_True ); 1149 SvLockBytesStat aStat; 1150 if ( aLockBytes.Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE ) 1151 { 1152 sal_uInt32 nLen = aStat.nSize; 1153 sal_uLong nRead = 0; 1154 uno::Sequence< sal_Int8 > aSeq( nLen ); 1155 aLockBytes.ReadAt( 0, aSeq.getArray(), nLen, &nRead ); 1156 1157 uno::Sequence< beans::PropertyValue > aArgs(1); 1158 aArgs[0].Name = ::rtl::OUString::createFromAscii("RtfOutline"); 1159 aArgs[0].Value <<= aSeq; 1160 xHelper->executeDispatch( xProv, aCmd, ::rtl::OUString(), 0, aArgs ); 1161 } 1162 } 1163 } 1164 } 1165 else 1166 { 1167 TransferDataContainer* pClipCntnr = 1168 new TransferDataContainer; 1169 STAR_REFERENCE( datatransfer::XTransferable ) 1170 xRef( pClipCntnr ); 1171 1172 pClipCntnr->CopyAnyData( FORMAT_RTF, (sal_Char*) 1173 pStrm->GetData(), pStrm->GetEndOfData() ); 1174 pClipCntnr->CopyToClipboard( 1175 GetView()? (Window*)&GetView()->GetEditWin() : 0 ); 1176 delete pStrm; 1177 } 1178 } 1179 else 1180 ErrorHandler::HandleError(ErrCode( eErr )); 1181 } 1182 break; 1183 case SID_SPELLCHECKER_CHANGED: 1184 //! sal_False, sal_True, sal_True is on the save side but a probably overdone 1185 SW_MOD()->CheckSpellChanges(sal_False, sal_True, sal_True, sal_False ); 1186 break; 1187 1188 case SID_MAIL_PREPAREEXPORT: 1189 { 1190 //pWrtShell is not set in page preview 1191 if(pWrtShell) 1192 pWrtShell->StartAllAction(); 1193 pDoc->UpdateFlds( NULL, false ); 1194 pDoc->EmbedAllLinks(); 1195 pDoc->RemoveInvisibleContent(); 1196 if(pWrtShell) 1197 pWrtShell->EndAllAction(); 1198 } 1199 break; 1200 1201 case SID_MAIL_EXPORT_FINISHED: 1202 { 1203 if(pWrtShell) 1204 pWrtShell->StartAllAction(); 1205 //try to undo the removal of invisible content 1206 pDoc->RestoreInvisibleContent(); 1207 if(pWrtShell) 1208 pWrtShell->EndAllAction(); 1209 } 1210 break; 1211 case FN_NEW_HTML_DOC: 1212 case FN_NEW_GLOBAL_DOC: 1213 { 1214 bDone = sal_False; 1215 sal_Bool bCreateHtml = FN_NEW_HTML_DOC == nWhich; 1216 1217 sal_Bool bCreateByOutlineLevel = false; //#outline level,add by zhaojianwei 1218 sal_Int32 nTemplateOutlineLevel = 0 ; //#outline level,add by zhaojianwei 1219 1220 String aFileName, aTemplateName; 1221 if( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nWhich, sal_False, &pItem ) ) 1222 { 1223 aFileName = ((const SfxStringItem*)pItem)->GetValue(); 1224 SFX_ITEMSET_ARG( pArgs, pTemplItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False ); 1225 if ( pTemplItem ) 1226 aTemplateName = pTemplItem->GetValue(); 1227 } 1228 bool bError = false; 1229 if ( !aFileName.Len() ) 1230 { 1231 FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE, 0 ); 1232 1233 const sal_Int16 nControlIds[] = { 1234 CommonFilePickerElementIds::PUSHBUTTON_OK, 1235 CommonFilePickerElementIds::PUSHBUTTON_CANCEL, 1236 CommonFilePickerElementIds::LISTBOX_FILTER, 1237 CommonFilePickerElementIds::CONTROL_FILEVIEW, 1238 CommonFilePickerElementIds::EDIT_FILEURL, 1239 ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 1240 ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, 1241 0 1242 }; 1243 1244 const char* aHTMLHelpIds[] = 1245 { 1246 HID_SEND_HTML_CTRL_PUSHBUTTON_OK, 1247 HID_SEND_HTML_CTRL_PUSHBUTTON_CANCEL, 1248 HID_SEND_HTML_CTRL_LISTBOX_FILTER, 1249 HID_SEND_HTML_CTRL_CONTROL_FILEVIEW, 1250 HID_SEND_HTML_CTRL_EDIT_FILEURL, 1251 HID_SEND_HTML_CTRL_CHECKBOX_AUTOEXTENSION, 1252 HID_SEND_HTML_CTRL_LISTBOX_TEMPLATE, 1253 "" 1254 }; 1255 1256 const char* aMasterHelpIds[] = 1257 { 1258 HID_SEND_MASTER_CTRL_PUSHBUTTON_OK, 1259 HID_SEND_MASTER_CTRL_PUSHBUTTON_CANCEL, 1260 HID_SEND_MASTER_CTRL_LISTBOX_FILTER, 1261 HID_SEND_MASTER_CTRL_CONTROL_FILEVIEW, 1262 HID_SEND_MASTER_CTRL_EDIT_FILEURL, 1263 HID_SEND_MASTER_CTRL_CHECKBOX_AUTOEXTENSION, 1264 HID_SEND_MASTER_CTRL_LISTBOX_TEMPLATE, 1265 "" 1266 }; 1267 1268 const char** pHelpIds = bCreateHtml ? aHTMLHelpIds : aMasterHelpIds; 1269 aDlgHelper.SetControlHelpIds( nControlIds, pHelpIds ); 1270 uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); 1271 1272 const SfxFilter* pFlt; 1273 sal_uInt16 nStrId; 1274 1275 if( bCreateHtml ) 1276 { 1277 // fuer HTML gibts es nur einen Filter!! 1278 pFlt = SwIoSystem::GetFilterOfFormat( 1279 String::CreateFromAscii("HTML"), 1280 SwWebDocShell::Factory().GetFilterContainer() ); 1281 nStrId = STR_LOAD_HTML_DOC; 1282 } 1283 else 1284 { 1285 // Fuer Global-Dokumente bieten wir jetzt auch nur 1286 // noch den aktuellen an. 1287 pFlt = SwGlobalDocShell::Factory().GetFilterContainer()-> 1288 GetFilter4Extension( String::CreateFromAscii("odm") ); 1289 nStrId = STR_LOAD_GLOBAL_DOC; 1290 } 1291 1292 if( pFlt ) 1293 { 1294 uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY); 1295 const String sWild = ((WildCard&)pFlt->GetWildcard()).GetWildCard(); 1296 xFltMgr->appendFilter( pFlt->GetUIName(), sWild ); 1297 try 1298 { 1299 xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ; 1300 } 1301 catch( const uno::Exception& ) 1302 { 1303 bError = true; 1304 } 1305 } 1306 if(!bError) 1307 { 1308 uno::Reference<XFilePickerControlAccess> xCtrlAcc(xFP, UNO_QUERY); 1309 1310 //#removed by zhaojianwei 1311 1312 // const sal_uInt16 nCount = pDoc->GetTxtFmtColls()->Count(); 1313 // Sequence<OUString> aListBoxEntries(nCount); 1314 // OUString* pEntries = aListBoxEntries.getArray(); 1315 // sal_Int32 nIdx = 0; 1316 // sal_Int16 nSelect = 0; 1317 // OUString sStartTemplate; 1318 // SwTxtFmtColl *pFnd = 0, *pAny = 0; 1319 // for(sal_uInt16 i = 0; i < nCount; ++i) 1320 // { 1321 // SwTxtFmtColl &rTxtColl = 1322 // *pDoc->GetTxtFmtColls()->GetObject( i ); 1323 // if( !rTxtColl.IsDefault() && rTxtColl.IsAtDocNodeSet() ) 1324 // { 1325 // //if( MAXLEVEL >= rTxtColl.GetOutlineLevel() && ( !pFnd || //#outline level,zhaojianwei 1326 //if( rTxtColl.IsAssignedToListLevelOfOutlineStyle() && ( !pFnd || //<-end,zhaojianwei 1327 // pFnd->GetAssignedOutlineStyleLevel() > rTxtColl.GetAssignedOutlineStyleLevel() )) 1328 // { 1329 // nSelect = (sal_Int16)nIdx; 1330 // pFnd = &rTxtColl; 1331 // sStartTemplate = rTxtColl.GetName(); 1332 // } 1333 // else if( !pAny ) 1334 // pAny = &rTxtColl; 1335 // //pEntries[nIdx++] = rTxtColl.GetName(); //#outline level,remove by zhaojianwei 1336 // pEntries[nIdx++] = sStyles + rTxtColl.GetName(); //#outline level,add by zhaojianwei 1337 // } 1338 // } 1339 // if(!sStartTemplate.getLength() && pAny) 1340 // sStartTemplate = pAny->GetName(); 1341 // aListBoxEntries.realloc(nIdx); 1342 //<-end,zhaojianwei 1343 1344 1345 //#outline level,add by zhaojianwei 1346 ///////////////////////////////////////////////////////////////////// 1347 1348 bool bOutline[MAXLEVEL] = {false}; 1349 const SwOutlineNodes& rOutlNds = pDoc->GetNodes().GetOutLineNds(); 1350 if( rOutlNds.Count() ) 1351 { 1352 int nLevel; 1353 for(sal_uInt16 n = 0; n < rOutlNds.Count(); ++n ) 1354 if( ( nLevel = rOutlNds[n]->GetTxtNode()->GetAttrOutlineLevel()) > 0 && 1355 ! bOutline[nLevel-1] ) 1356 { 1357 bOutline[nLevel-1] = true; 1358 } 1359 } 1360 1361 const sal_uInt16 nStyleCount = pDoc->GetTxtFmtColls()->Count(); 1362 Sequence<OUString> aListBoxEntries( MAXLEVEL + nStyleCount); 1363 OUString* pEntries = aListBoxEntries.getArray(); 1364 sal_Int32 nIdx = 0 ; 1365 1366 OUString sOutline( SW_RESSTR(STR_FDLG_OUTLINE_LEVEL) ); 1367 for( sal_uInt16 i = 0; i < MAXLEVEL; ++i ) 1368 { 1369 if( bOutline[i] ) 1370 pEntries[nIdx++] = sOutline + String::CreateFromInt32( i+1 ); 1371 } 1372 1373 OUString sStyle( SW_RESSTR(STR_FDLG_STYLE) ); 1374 for(sal_uInt16 i = 0; i < nStyleCount; ++i) 1375 { 1376 SwTxtFmtColl &rTxtColl = 1377 *pDoc->GetTxtFmtColls()->GetObject( i ); 1378 if( !rTxtColl.IsDefault() && rTxtColl.IsAtDocNodeSet() ) 1379 { 1380 pEntries[nIdx++] = sStyle + rTxtColl.GetName(); 1381 } 1382 } 1383 1384 aListBoxEntries.realloc(nIdx); 1385 sal_Int16 nSelect = 0; 1386 ///////////////////////////////////////////////////////////////////// 1387 //<-end,zhaojianwei 1388 1389 try 1390 { 1391 Any aTemplates(&aListBoxEntries, ::getCppuType(&aListBoxEntries)); 1392 1393 xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, 1394 ListboxControlActions::ADD_ITEMS , aTemplates ); 1395 Any aSelectPos(&nSelect, ::getCppuType(&nSelect)); 1396 xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, 1397 ListboxControlActions::SET_SELECT_ITEM, aSelectPos ); 1398 xCtrlAcc->setLabel( ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, 1399 String(SW_RES( STR_FDLG_TEMPLATE_NAME ))); 1400 } 1401 catch(Exception& ) 1402 { 1403 DBG_ERROR("control acces failed"); 1404 } 1405 1406 xFP->setTitle( SW_RESSTR( nStrId )); 1407 SvtPathOptions aPathOpt; 1408 xFP->setDisplayDirectory( aPathOpt.GetWorkPath() ); 1409 if( ERRCODE_NONE == aDlgHelper.Execute()) 1410 { 1411 aFileName = xFP->getFiles().getConstArray()[0]; 1412 Any aTemplateValue = xCtrlAcc->getValue( 1413 ExtendedFilePickerElementIds::LISTBOX_TEMPLATE, 1414 ListboxControlActions::GET_SELECTED_ITEM ); 1415 OUString sTmpl; 1416 aTemplateValue >>= sTmpl; 1417 //aTemplateName = sTmpl; //#outline level,removed by zhaojianwei 1418 //#outline level,add by zhaojianwei 1419 1420 sal_Int32 nColonPos = sTmpl.indexOf( sal_Unicode(':') ); 1421 OUString sPrefix = sTmpl.copy( 0L, nColonPos ); 1422 if( sPrefix.equalsAscii("Style")) 1423 { 1424 aTemplateName = sTmpl.copy( 7L ); //get string behind "Style: " 1425 } 1426 else if( sPrefix.equalsAscii("Outline")) 1427 { 1428 nTemplateOutlineLevel = ( sTmpl.copy( 15L )).toInt32(); //get string behind "Outline: Leve "; 1429 bCreateByOutlineLevel = true; 1430 } 1431 //<-end,zhaojianwei 1432 1433 if ( aFileName.Len() ) 1434 { 1435 rReq.AppendItem( SfxStringItem( nWhich, aFileName ) ); 1436 if( aTemplateName.Len() ) 1437 rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aTemplateName ) ); 1438 } 1439 } 1440 } 1441 } 1442 1443 //const SwTxtFmtColl* pSplitColl = 0; //#outline level,removed by zhaojianwei 1444 // if ( aTemplateName.Len() ) 1445 // pSplitColl = pDoc->FindTxtFmtCollByName(aTemplateName); 1446 //<-end,zhaojianwei 1447 if( aFileName.Len() ) 1448 { 1449 if( PrepareClose( sal_False ) ) 1450 { 1451 SwWait aWait( *this, sal_True ); 1452 1453 //bDone = bCreateHtml //#outline level,removed by zhaojianwei 1454 // ? pDoc->GenerateHTMLDoc( aFileName, pSplitColl ) 1455 // : pDoc->GenerateGlobalDoc( aFileName, pSplitColl ); 1456 if ( bCreateByOutlineLevel ) //add by zhaojianwei 1457 { 1458 bDone = bCreateHtml //#outline level,removed by zhaojianwei 1459 ? pDoc->GenerateHTMLDoc( aFileName, nTemplateOutlineLevel ) 1460 : pDoc->GenerateGlobalDoc( aFileName, nTemplateOutlineLevel ); 1461 } 1462 else 1463 { 1464 const SwTxtFmtColl* pSplitColl = 0; 1465 if ( aTemplateName.Len() ) 1466 pSplitColl = pDoc->FindTxtFmtCollByName(aTemplateName); 1467 bDone = bCreateHtml //#outline level,removed by zhaojianwei 1468 ? pDoc->GenerateHTMLDoc( aFileName, pSplitColl ) 1469 : pDoc->GenerateGlobalDoc( aFileName, pSplitColl ); 1470 } 1471 //<-end,zhaojianwei 1472 if( bDone ) 1473 { 1474 SfxStringItem aName( SID_FILE_NAME, aFileName ); 1475 SfxStringItem aReferer( SID_REFERER, aEmptyStr ); 1476 SfxViewShell* pViewShell = SfxViewShell::GetFirst(); 1477 while(pViewShell) 1478 { 1479 //search for the view that created the call 1480 if(pViewShell->GetObjectShell() == this && pViewShell->GetDispatcher()) 1481 { 1482 SfxFrameItem* pFrameItem = new SfxFrameItem( SID_DOCFRAME, 1483 pViewShell->GetViewFrame() ); 1484 SfxDispatcher* pDispatch = pViewShell->GetDispatcher(); 1485 pDispatch->Execute( 1486 SID_OPENDOC, 1487 SFX_CALLMODE_ASYNCHRON, 1488 &aName, 1489 &aReferer, 1490 pFrameItem, 0L ); 1491 1492 delete pFrameItem; 1493 break; 1494 } 1495 pViewShell = SfxViewShell::GetNext(*pViewShell); 1496 } 1497 } 1498 } 1499 if( !bDone && !rReq.IsAPI() ) 1500 { 1501 InfoBox( 0, SW_RESSTR( STR_CANTCREATE )).Execute(); 1502 } 1503 } 1504 } 1505 rReq.SetReturnValue(SfxBoolItem( nWhich, bDone )); 1506 if (bDone) 1507 rReq.Done(); 1508 else 1509 rReq.Ignore(); 1510 break; 1511 1512 case SID_ATTR_YEAR2000: 1513 if ( pArgs && SFX_ITEM_SET == pArgs->GetItemState( nWhich , sal_False, &pItem )) 1514 { 1515 DBG_ASSERT(pItem->ISA(SfxUInt16Item), "falsches Item"); 1516 sal_uInt16 nYear2K = ((SfxUInt16Item*)pItem)->GetValue(); 1517 //ueber Views iterieren und den State an den FormShells setzen 1518 1519 SfxViewFrame* pVFrame = SfxViewFrame::GetFirst( this ); 1520 SfxViewShell* pViewShell = pVFrame ? pVFrame->GetViewShell() : 0; 1521 SwView* pCurrView = dynamic_cast< SwView* >( pViewShell ); 1522 while(pCurrView) 1523 { 1524 FmFormShell* pFormShell = pCurrView->GetFormShell(); 1525 if(pFormShell) 1526 pFormShell->SetY2KState(nYear2K); 1527 pVFrame = SfxViewFrame::GetNext( *pVFrame, this ); 1528 pViewShell = pVFrame ? pVFrame->GetViewShell() : 0; 1529 pCurrView = dynamic_cast<SwView*>( pViewShell ); 1530 } 1531 pDoc->GetNumberFormatter(sal_True)->SetYear2000(nYear2K); 1532 } 1533 break; 1534 1535 default: DBG_ERROR("falscher Dispatcher"); 1536 } 1537 } 1538 1539 1540 /*-------------------------------------------------------------------- 1541 Beschreibung: 1542 --------------------------------------------------------------------*/ 1543 1544 long SwDocShell::DdeGetData( const String& rItem, const String& rMimeType, 1545 uno::Any & rValue ) 1546 { 1547 return pDoc->GetData( rItem, rMimeType, rValue ); 1548 } 1549 1550 1551 /*-------------------------------------------------------------------- 1552 Beschreibung: 1553 --------------------------------------------------------------------*/ 1554 1555 long SwDocShell::DdeSetData( const String& rItem, const String& rMimeType, 1556 const uno::Any & rValue ) 1557 { 1558 return pDoc->SetData( rItem, rMimeType, rValue ); 1559 } 1560 1561 1562 /*-------------------------------------------------------------------- 1563 Beschreibung: 1564 --------------------------------------------------------------------*/ 1565 1566 ::sfx2::SvLinkSource* SwDocShell::DdeCreateLinkSource( const String& rItem ) 1567 { 1568 return pDoc->CreateLinkSource( rItem ); 1569 } 1570 1571 /*-------------------------------------------------------------------- 1572 Beschreibung: 1573 --------------------------------------------------------------------*/ 1574 1575 void SwDocShell::FillClass( SvGlobalName * pClassName, 1576 sal_uInt32 * pClipFormat, 1577 String * /*pAppName*/, 1578 String * pLongUserName, 1579 String * pUserName, 1580 sal_Int32 nVersion, 1581 sal_Bool bTemplate /* = sal_False */) const 1582 { 1583 if (nVersion == SOFFICE_FILEFORMAT_60) 1584 { 1585 *pClassName = SvGlobalName( SO3_SW_CLASSID_60 ); 1586 *pClipFormat = SOT_FORMATSTR_ID_STARWRITER_60; 1587 *pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE); 1588 } 1589 else if (nVersion == SOFFICE_FILEFORMAT_8) 1590 { 1591 *pClassName = SvGlobalName( SO3_SW_CLASSID_60 ); 1592 *pClipFormat = bTemplate ? SOT_FORMATSTR_ID_STARWRITER_8_TEMPLATE : SOT_FORMATSTR_ID_STARWRITER_8; 1593 *pLongUserName = SW_RESSTR(STR_WRITER_DOCUMENT_FULLTYPE); 1594 } 1595 1596 *pUserName = SW_RESSTR(STR_HUMAN_SWDOC_NAME); 1597 } 1598 1599 1600 /*-------------------------------------------------------------------- 1601 Beschreibung: 1602 --------------------------------------------------------------------*/ 1603 1604 void SwDocShell::SetModified( sal_Bool bSet ) 1605 { 1606 SfxObjectShell::SetModified( bSet ); 1607 if( IsEnableSetModified()) 1608 { 1609 if (!pDoc->IsInCallModified() ) 1610 { 1611 EnableSetModified( sal_False ); 1612 if( bSet ) 1613 { 1614 sal_Bool bOld = pDoc->IsModified(); 1615 pDoc->SetModified(); 1616 if( !bOld ) 1617 { 1618 pDoc->GetIDocumentUndoRedo().SetUndoNoResetModified(); 1619 } 1620 } 1621 else 1622 pDoc->ResetModified(); 1623 1624 EnableSetModified( sal_True ); 1625 } 1626 1627 UpdateChildWindows(); 1628 Broadcast(SfxSimpleHint(SFX_HINT_DOCCHANGED)); 1629 } 1630 } 1631 1632 /*-------------------------------------------------------------------- 1633 Beschreibung: 1634 --------------------------------------------------------------------*/ 1635 1636 void SwDocShell::UpdateChildWindows() 1637 { 1638 // Flddlg ggf neu initialisieren (z.B. fuer TYP_SETVAR) 1639 if(!GetView()) 1640 return; 1641 SfxViewFrame* pVFrame = GetView()->GetViewFrame(); 1642 SwFldDlgWrapper *pWrp = (SwFldDlgWrapper*)pVFrame-> 1643 GetChildWindow( SwFldDlgWrapper::GetChildWindowId() ); 1644 if( pWrp ) 1645 pWrp->ReInitDlg( this ); 1646 1647 // RedlineDlg ggf neu initialisieren 1648 SwRedlineAcceptChild *pRed = (SwRedlineAcceptChild*)pVFrame-> 1649 GetChildWindow( SwRedlineAcceptChild::GetChildWindowId() ); 1650 if( pRed ) 1651 pRed->ReInitDlg( this ); 1652 } 1653 1654 /*-------------------------------------------------------------------- 1655 Beschreibung: 1656 --------------------------------------------------------------------*/ 1657 // --> OD 2005-08-02 #i48748# 1658 class SwReloadFromHtmlReader : public SwReader 1659 { 1660 public: 1661 SwReloadFromHtmlReader( SfxMedium& _rTmpMedium, 1662 const String& _rFilename, 1663 SwDoc* _pDoc ) 1664 : SwReader( _rTmpMedium, _rFilename, _pDoc ) 1665 { 1666 SetBaseURL( _rFilename ); 1667 } 1668 }; 1669 // <-- 1670 void SwDocShell::ReloadFromHtml( const String& rStreamName, SwSrcView* pSrcView ) 1671 { 1672 sal_Bool bModified = IsModified(); 1673 1674 // MIB 23.6.97: Die HTTP-Header-Felder muessen geloescht werden, 1675 // sonst gibt es welche aus Meta-Tags hinter doppelt und dreifach. 1676 ClearHeaderAttributesForSourceViewHack(); 1677 1678 // MIB 24.07.97: Das Dokument-Basic muss auch noch d'ran glauben ... 1679 SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get(); 1680 //#59620# HasBasic() zeigt an, dass es schon einen BasicManager an der DocShell 1681 // gibt. Der wurde im HTML-Import immer angelegt, wenn Macros im Quelltext 1682 // vorhanden sind. 1683 if( pHtmlOptions && pHtmlOptions->IsStarBasic() && HasBasic()) 1684 { 1685 BasicManager *pBasicMan = GetBasicManager(); 1686 if( pBasicMan && (pBasicMan != SFX_APP()->GetBasicManager()) ) 1687 { 1688 sal_uInt16 nLibCount = pBasicMan->GetLibCount(); 1689 while( nLibCount ) 1690 { 1691 StarBASIC *pBasic = pBasicMan->GetLib( --nLibCount ); 1692 if( pBasic ) 1693 { 1694 // Die IDE benachrichtigen 1695 SfxUsrAnyItem aShellItem( SID_BASICIDE_ARG_DOCUMENT_MODEL, makeAny( GetModel() ) ); 1696 String aLibName( pBasic->GetName() ); 1697 SfxStringItem aLibNameItem( SID_BASICIDE_ARG_LIBNAME, aLibName ); 1698 pSrcView->GetViewFrame()->GetDispatcher()->Execute( 1699 SID_BASICIDE_LIBREMOVED, 1700 SFX_CALLMODE_SYNCHRON, 1701 &aShellItem, &aLibNameItem, 0L ); 1702 1703 // Aus der Standard-Lib werden nur die Module geloescht 1704 if( nLibCount ) 1705 pBasicMan->RemoveLib( nLibCount, sal_True ); 1706 else 1707 pBasic->Clear(); 1708 } 1709 } 1710 1711 ASSERT( pBasicMan->GetLibCount() <= 1, 1712 "Loschen des Basics hat nicht geklappt" ); 1713 } 1714 } 1715 sal_Bool bWasBrowseMode = pDoc->get(IDocumentSettingAccess::BROWSE_MODE); 1716 RemoveLink(); 1717 1718 //jetzt muss auch das UNO-Model ueber das neue Doc informiert werden #51535# 1719 uno::Reference<text::XTextDocument> xDoc(GetBaseModel(), uno::UNO_QUERY); 1720 text::XTextDocument* pxDoc = xDoc.get(); 1721 ((SwXTextDocument*)pxDoc)->InitNewDoc(); 1722 1723 AddLink(); 1724 //#116402# update font list when new document is created 1725 UpdateFontList(); 1726 pDoc->set(IDocumentSettingAccess::BROWSE_MODE, bWasBrowseMode); 1727 pSrcView->SetPool(&GetPool()); 1728 1729 1730 const String& rMedname = GetMedium()->GetName(); 1731 1732 // fix #51032#: Die HTML-Vorlage muss noch gesetzt werden 1733 SetHTMLTemplate( *GetDoc() ); //Styles aus HTML.vor 1734 1735 SfxViewShell* pViewShell = GetView() ? (SfxViewShell*)GetView() 1736 : SfxViewShell::Current(); 1737 SfxViewFrame* pViewFrm = pViewShell->GetViewFrame(); 1738 pViewFrm->GetDispatcher()->Execute( SID_VIEWSHELL0, SFX_CALLMODE_SYNCHRON ); 1739 1740 SubInitNew(); 1741 1742 SfxMedium aMed( rStreamName, STREAM_READ, sal_False ); 1743 // --> OD 2005-08-01 #i48748# - use class <SwReloadFromHtmlReader>, because 1744 // the base URL has to be set to the filename of the document <rMedname> 1745 // and not to the base URL of the temporary file <aMed> in order to get 1746 // the URLs of the linked graphics correctly resolved. 1747 SwReloadFromHtmlReader aReader( aMed, rMedname, pDoc ); 1748 // <-- 1749 aReader.Read( *ReadHTML ); 1750 1751 const SwView* pCurrView = GetView(); 1752 //in print layout the first page(s) may have been formatted as a mix of browse 1753 //and print layout 1754 if(!bWasBrowseMode && pCurrView) 1755 { 1756 SwWrtShell& rWrtSh = pCurrView->GetWrtShell(); 1757 if( rWrtSh.GetLayout()) 1758 rWrtSh.CheckBrowseView( sal_True ); 1759 } 1760 1761 1762 // MIB 23.6.97: Die HTTP-Header-Attribute wieder in die DokInfo 1763 // uebernehmen. Die Base-URL ist hier egal, da TLX zum absolutieren die 1764 // vom Dokument nimmt. 1765 SetHeaderAttributesForSourceViewHack(); 1766 1767 if(bModified && !IsReadOnly()) 1768 SetModified(); 1769 else 1770 pDoc->ResetModified(); 1771 } 1772 1773 sal_uLong SwDocShell::LoadStylesFromFile( const String& rURL, 1774 SwgReaderOption& rOpt, sal_Bool bUnoCall ) 1775 { 1776 sal_uLong nErr = 0; 1777 1778 // Create a URL from filename 1779 INetURLObject aURLObj( rURL ); 1780 String sURL( aURLObj.GetMainURL( INetURLObject::NO_DECODE ) ); 1781 1782 // Filter bestimmen: 1783 // const SfxFilter* pFlt = SwIoSystem::GetFileFilter( rURL, aEmptyStr ); 1784 String sFactory(String::CreateFromAscii(SwDocShell::Factory().GetShortName())); 1785 SfxFilterMatcher aMatcher( sFactory ); 1786 1787 //#b6445961# search for filter in WebDocShell, too 1788 SfxMedium aMed( rURL, STREAM_STD_READ, sal_False ); 1789 const SfxFilter* pFlt = 0; 1790 aMatcher.DetectFilter( aMed, &pFlt, sal_False, sal_False ); 1791 if(!pFlt) 1792 { 1793 String sWebFactory(String::CreateFromAscii(SwWebDocShell::Factory().GetShortName())); 1794 SfxFilterMatcher aWebMatcher( sWebFactory ); 1795 aWebMatcher.DetectFilter( aMed, &pFlt, sal_False, sal_False ); 1796 } 1797 // --> OD #i117339# - trigger import only for own formats 1798 // if( aMed.IsStorage() ) 1799 bool bImport( false ); 1800 { 1801 if ( aMed.IsStorage() ) 1802 { 1803 // As <SfxMedium.GetFilter().IsOwnFormat() resp. IsOwnTemplateFormat() 1804 // does not work correct (e.g., MS Word 2007 XML Template), 1805 // use workaround provided by MAV. 1806 uno::Reference< embed::XStorage > xStorage = aMed.GetStorage(); 1807 if ( xStorage.is() ) 1808 { 1809 // use <try-catch> on retrieving <MediaType> in order to check, 1810 // if the storage is one of our own ones. 1811 try 1812 { 1813 uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY_THROW ); 1814 const ::rtl::OUString aMediaTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); 1815 xProps->getPropertyValue( aMediaTypePropName ); 1816 bImport = true; 1817 } 1818 catch( const uno::Exception& ) 1819 { 1820 bImport = false; 1821 } 1822 } 1823 } 1824 } 1825 if ( bImport ) 1826 // <-- 1827 { 1828 DBG_ASSERT((pFlt ? pFlt->GetVersion() : 0) >= SOFFICE_FILEFORMAT_60, "which file version?"); 1829 SwRead pRead = ReadXML; 1830 SwReader* pReader = 0; 1831 SwPaM* pPam = 0; 1832 // the SW3IO - Reader need the pam/wrtshell, because only then he 1833 // insert the styles! 1834 if( bUnoCall ) 1835 { 1836 SwNodeIndex aIdx( pDoc->GetNodes().GetEndOfContent(), -1 ); 1837 pPam = new SwPaM( aIdx ); 1838 pReader = new SwReader( aMed, rURL, *pPam ); 1839 } 1840 else 1841 { 1842 pReader = new SwReader( aMed, rURL, *pWrtShell->GetCrsr() ); 1843 } 1844 1845 pRead->GetReaderOpt().SetTxtFmts( rOpt.IsTxtFmts() ); 1846 pRead->GetReaderOpt().SetFrmFmts( rOpt.IsFrmFmts() ); 1847 pRead->GetReaderOpt().SetPageDescs( rOpt.IsPageDescs() ); 1848 pRead->GetReaderOpt().SetNumRules( rOpt.IsNumRules() ); 1849 pRead->GetReaderOpt().SetMerge( rOpt.IsMerge() ); 1850 1851 if( bUnoCall ) 1852 { 1853 UnoActionContext aAction( pDoc ); 1854 nErr = pReader->Read( *pRead ); 1855 } 1856 else 1857 { 1858 pWrtShell->StartAllAction(); 1859 nErr = pReader->Read( *pRead ); 1860 pWrtShell->EndAllAction(); 1861 } 1862 delete pPam; 1863 delete pReader; 1864 } 1865 1866 return nErr; 1867 } 1868 1869 /*-------------------------------------------------------------------- 1870 Get a client for an embedded object if possible. 1871 --------------------------------------------------------------------*/ 1872 SfxInPlaceClient* SwDocShell::GetIPClient( const ::svt::EmbeddedObjectRef& xObjRef ) 1873 { 1874 SfxInPlaceClient* pResult = NULL; 1875 1876 SwWrtShell* pShell = GetWrtShell(); 1877 if ( pShell ) 1878 { 1879 pResult = pShell->GetView().FindIPClient( xObjRef.GetObject(), (Window*)&pShell->GetView().GetEditWin() ); 1880 if ( !pResult ) 1881 pResult = new SwOleClient( &pShell->GetView(), &pShell->GetView().GetEditWin(), xObjRef ); 1882 } 1883 1884 return pResult; 1885 } 1886 1887