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 <hintids.hxx> 32 #include <com/sun/star/util/SearchOptions.hpp> 33 #include <com/sun/star/util/SearchFlags.hpp> 34 #include <com/sun/star/i18n/TransliterationModules.hpp> 35 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 36 #include <unotools/tempfile.hxx> 37 #include <tools/urlobj.hxx> 38 #include <vcl/print.hxx> 39 #include <vcl/msgbox.hxx> 40 #include <vcl/wrkwin.hxx> 41 #include <vcl/metric.hxx> 42 #include <svtools/ctrltool.hxx> 43 #include <svl/intitem.hxx> 44 #include <svl/stritem.hxx> 45 #include <unotools/pathoptions.hxx> 46 #include <svl/undo.hxx> 47 #include <svtools/txtcmp.hxx> 48 #include <svl/eitem.hxx> 49 #include <svl/whiter.hxx> 50 #include <unotools/saveopt.hxx> 51 #include <svtools/transfer.hxx> 52 #include <svtools/svtools.hrc> 53 #include <svtools/svtdata.hxx> 54 #include <svx/svxids.hrc> 55 #include <svtools/htmlcfg.hxx> 56 #include <sfx2/app.hxx> 57 #include <sfx2/objface.hxx> 58 #include <sfx2/viewfrm.hxx> 59 #include <sfx2/bindings.hxx> 60 #include <sfx2/docfilt.hxx> 61 #include <sfx2/fcontnr.hxx> 62 #include <sfx2/request.hxx> 63 #include <sfx2/prnmon.hxx> 64 #include <sfx2/docfile.hxx> 65 #include <editeng/fhgtitem.hxx> 66 #include <svx/srchdlg.hxx> 67 #include <svl/srchitem.hxx> 68 #include <editeng/fontitem.hxx> 69 #include <editeng/flstitem.hxx> 70 #include "editeng/unolingu.hxx" 71 #include <sfx2/sfxhtml.hxx> 72 #include <swtypes.hxx> 73 #include <swmodule.hxx> 74 #include <docsh.hxx> 75 #include <wdocsh.hxx> 76 #include <srcview.hxx> 77 #include <viewfunc.hxx> 78 #include <doc.hxx> 79 #include <sfx2/msg.hxx> 80 #include <shellio.hxx> 81 82 #include <cmdid.h> // FN_ ... 83 #include <helpid.h> 84 #include <globals.hrc> 85 #include <shells.hrc> 86 #include <popup.hrc> 87 #include <web.hrc> 88 #include <view.hrc> 89 #include <com/sun/star/ui/dialogs/XFilePicker.hpp> 90 #include <com/sun/star/ui/dialogs/XFilterManager.hpp> 91 #include <sfx2/filedlghelper.hxx> 92 #define SwSrcView 93 #include "swslots.hxx" 94 95 #include <unomid.h> 96 97 #include <com/sun/star/document/XDocumentProperties.hpp> 98 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 99 100 using namespace ::com::sun::star; 101 using namespace ::com::sun::star::i18n; 102 using namespace ::com::sun::star::lang; 103 using namespace ::com::sun::star::uno; 104 using namespace ::com::sun::star::ui::dialogs; 105 using namespace ::com::sun::star::i18n; 106 using namespace ::com::sun::star::lang; 107 using namespace ::sfx2; 108 using ::rtl::OUString; 109 using ::com::sun::star::util::SearchOptions; 110 111 112 #define SWSRCVIEWFLAGS ( SFX_VIEW_CAN_PRINT|\ 113 SFX_VIEW_NO_NEWWINDOW ) 114 115 #define SRC_SEARCHOPTIONS (0xFFFF & ~(SEARCH_OPTIONS_FORMAT|SEARCH_OPTIONS_FAMILIES|SEARCH_OPTIONS_SEARCH_ALL)) 116 117 // Druckraender -> wie Basic - Ide 118 #define LMARGPRN 1700 119 #define RMARGPRN 900 120 #define TMARGPRN 2000 121 #define BMARGPRN 1000 122 #define BORDERPRN 300 123 124 SFX_IMPL_NAMED_VIEWFACTORY(SwSrcView, "SourceView") 125 { 126 SFX_VIEW_REGISTRATION(SwWebDocShell); 127 } 128 129 SFX_IMPL_INTERFACE( SwSrcView, SfxViewShell, SW_RES(0) ) 130 { 131 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_SRCVIEW_POPUPMENU)); 132 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS| 133 SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER, 134 SW_RES(RID_WEBTOOLS_TOOLBOX) ); 135 SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId()); 136 } 137 138 TYPEINIT1(SwSrcView, SfxViewShell) 139 140 /*-----------------18.11.96 08.05------------------- 141 142 --------------------------------------------------*/ 143 144 145 void lcl_PrintHeader( OutputDevice &rOutDev, sal_uInt16 nPages, sal_uInt16 nCurPage, const String& rTitle ) 146 { 147 short nLeftMargin = LMARGPRN; 148 Size aSz = rOutDev.GetOutputSize(); 149 short nBorder = BORDERPRN; 150 151 Color aOldFillColor( rOutDev.GetFillColor() ); 152 Font aOldFont( rOutDev.GetFont() ); 153 154 rOutDev.SetFillColor( Color(COL_TRANSPARENT) ); 155 156 Font aFont( aOldFont ); 157 aFont.SetWeight( WEIGHT_BOLD ); 158 aFont.SetAlign( ALIGN_BOTTOM ); 159 rOutDev.SetFont( aFont ); 160 161 long nFontHeight = rOutDev.GetTextHeight(); 162 163 // 1.Border => Strich, 2+3 Border = Freiraum. 164 long nYTop = TMARGPRN-3*nBorder-nFontHeight; 165 166 long nXLeft = nLeftMargin-nBorder; 167 long nXRight = aSz.Width()-RMARGPRN+nBorder; 168 169 rOutDev.DrawRect( Rectangle( 170 Point( nXLeft, nYTop ), 171 Size( nXRight-nXLeft, aSz.Height() - nYTop - BMARGPRN + nBorder ) ) ); 172 173 174 long nY = TMARGPRN-2*nBorder; 175 Point aPos( nLeftMargin, nY ); 176 rOutDev.DrawText( aPos, rTitle ); 177 if ( nPages != 1 ) 178 { 179 aFont.SetWeight( WEIGHT_NORMAL ); 180 rOutDev.SetFont( aFont ); 181 String aPageStr( C2S(" [") ); 182 aPageStr += String( SW_RES( STR_PAGE ) ); 183 aPageStr += ' '; 184 aPageStr += String::CreateFromInt32( nCurPage ); 185 aPageStr += ']'; 186 aPos.X() += rOutDev.GetTextWidth( rTitle ); 187 rOutDev.DrawText( aPos, aPageStr ); 188 } 189 190 191 nY = TMARGPRN-nBorder; 192 193 rOutDev.DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) ); 194 195 rOutDev.SetFont( aOldFont ); 196 rOutDev.SetFillColor( aOldFillColor ); 197 } 198 /* -----------------13.11.2003 16:24----------------- 199 200 --------------------------------------------------*/ 201 rtl_TextEncoding lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding) 202 { 203 rtl_TextEncoding eRet = eLoadEncoding; 204 if(RTL_TEXTENCODING_DONTKNOW == eRet) 205 { 206 SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get(); 207 const sal_Char *pCharSet = 208 rtl_getBestMimeCharsetFromTextEncoding( pHtmlOptions->GetTextEncoding() ); 209 eRet = rtl_getTextEncodingFromMimeCharset( pCharSet ); 210 } 211 return eRet; 212 } 213 /*-----------------18.11.96 08.21------------------- 214 215 --------------------------------------------------*/ 216 217 void lcl_ConvertTabsToSpaces( String& rLine ) 218 { 219 if ( rLine.Len() ) 220 { 221 sal_uInt16 nPos = 0; 222 sal_uInt16 nMax = rLine.Len(); 223 while ( nPos < nMax ) 224 { 225 if ( rLine.GetChar(nPos) == '\t' ) 226 { 227 // Nicht 4 Blanks, sondern an 4er TabPos: 228 String aBlanker; 229 aBlanker.Fill( ( 4 - ( nPos % 4 ) ), ' ' ); 230 rLine.Erase( nPos, 1 ); 231 rLine.Insert( aBlanker, nPos ); 232 nMax = rLine.Len(); 233 } 234 nPos++; // Nicht optimal, falls Tab, aber auch nicht verkehrt... 235 } 236 } 237 } 238 239 /*-------------------------------------------------------------------- 240 Beschreibung: 241 --------------------------------------------------------------------*/ 242 243 244 SwSrcView::SwSrcView(SfxViewFrame* pViewFrame, SfxViewShell*) : 245 SfxViewShell( pViewFrame, SWSRCVIEWFLAGS ), 246 aEditWin( &pViewFrame->GetWindow(), this ), 247 pSearchItem(0), 248 bSourceSaved(sal_False), 249 eLoadEncoding(RTL_TEXTENCODING_DONTKNOW) 250 { 251 Init(); 252 } 253 254 /*-------------------------------------------------------------------- 255 Beschreibung: 256 --------------------------------------------------------------------*/ 257 258 259 SwSrcView::~SwSrcView() 260 { 261 SwDocShell* pDocShell = GetDocShell(); 262 DBG_ASSERT(PTR_CAST(SwWebDocShell, pDocShell), "Wieso keine WebDocShell?"); 263 const TextSelection& rSel = aEditWin.GetTextView()->GetSelection(); 264 ((SwWebDocShell*)pDocShell)->SetSourcePara( static_cast< sal_uInt16 >( rSel.GetStart().GetPara() ) ); 265 266 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 267 pDocShell->GetModel(), uno::UNO_QUERY_THROW); 268 uno::Reference<document::XDocumentProperties> xDocProps 269 = xDPS->getDocumentProperties(); 270 ::rtl::OUString url = xDocProps->getAutoloadURL(); 271 sal_Int32 delay = xDocProps->getAutoloadSecs(); 272 pDocShell->SetAutoLoad(INetURLObject(url), delay, 273 (delay != 0) || !url.equalsAscii("")); 274 // EndListening(*GetViewFrame()); 275 EndListening(*pDocShell); 276 delete pSearchItem; 277 } 278 279 /*-----------------24.04.97 10:37------------------- 280 281 --------------------------------------------------*/ 282 void SwSrcView::SaveContentTo(SfxMedium& rMed) 283 { 284 SvStream* pOutStream = rMed.GetOutStream(); 285 pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding)); 286 aEditWin.Write( *pOutStream );//, EE_FORMAT_TEXT); 287 } 288 289 /*-------------------------------------------------------------------- 290 Beschreibung: 291 --------------------------------------------------------------------*/ 292 293 294 void SwSrcView::Init() 295 { 296 SetHelpId(SW_SRC_VIEWSHELL); 297 SetName(C2S("Source")); 298 SetWindow( &aEditWin ); 299 SwDocShell* pDocShell = GetDocShell(); 300 // wird das Doc noch geladen, dann muss die DocShell das Load 301 // anwerfen, wenn das Laden abgeschlossen ist 302 if(!pDocShell->IsLoading()) 303 Load(pDocShell); 304 else 305 { 306 aEditWin.SetReadonly(sal_True); 307 } 308 309 SetNewWindowAllowed( sal_False ); 310 StartListening(*pDocShell,sal_True); 311 } 312 313 /*-------------------------------------------------------------------- 314 Beschreibung: 315 --------------------------------------------------------------------*/ 316 317 SwDocShell* SwSrcView::GetDocShell() 318 { 319 SfxObjectShell* pObjShell = GetViewFrame()->GetObjectShell(); 320 return PTR_CAST(SwDocShell, pObjShell); 321 } 322 323 /*-------------------------------------------------------------------- 324 Beschreibung: 325 --------------------------------------------------------------------*/ 326 327 328 void SwSrcView::SaveContent(const String& rTmpFile) 329 { 330 SfxMedium aMedium( rTmpFile, STREAM_WRITE, sal_True); 331 SvStream* pOutStream = aMedium.GetOutStream(); 332 pOutStream->SetStreamCharSet( lcl_GetStreamCharSet(eLoadEncoding) ); 333 aEditWin.Write(*pOutStream);//, EE_FORMAT_TEXT); 334 aMedium.Commit(); 335 } 336 337 /*-------------------------------------------------------------------- 338 Beschreibung: 339 --------------------------------------------------------------------*/ 340 341 342 void SwSrcView::Execute(SfxRequest& rReq) 343 { 344 sal_uInt16 nSlot = rReq.GetSlot(); 345 TextView* pTextView = aEditWin.GetTextView(); 346 switch( nSlot ) 347 { 348 case SID_SAVEASDOC: 349 { 350 SvtPathOptions aPathOpt; 351 // filesave dialog with autoextension 352 FileDialogHelper aDlgHelper( 353 TemplateDescription::FILESAVE_AUTOEXTENSION, 354 TemplateDescription::FILESAVE_SIMPLE ); 355 uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); 356 // pFileDlg->SetHelpId(HID_FILEDLG_SRCVIEW); 357 uno::Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY); 358 359 // search for an html filter for export 360 SfxFilterContainer* pFilterCont = GetObjectShell()->GetFactory().GetFilterContainer(); 361 const SfxFilter* pFilter = 362 pFilterCont->GetFilter4Extension( C2S("html"), SFX_FILTER_EXPORT ); 363 if ( pFilter ) 364 { 365 // filter found -> use its uiname and wildcard 366 const String& rUIName = pFilter->GetUIName(); 367 const WildCard& rCard = pFilter->GetWildcard(); 368 xFltMgr->appendFilter( rUIName, rCard() ); 369 xFltMgr->setCurrentFilter( rUIName ) ; 370 } 371 else 372 { 373 // filter not found 374 String sHtml(C2S("HTML")); 375 xFltMgr->appendFilter( sHtml, C2S("*.html;*.htm") ); 376 xFltMgr->setCurrentFilter( sHtml ) ; 377 } 378 379 xFP->setDisplayDirectory( aPathOpt.GetWorkPath() ); 380 if( aDlgHelper.Execute() == ERRCODE_NONE) 381 { 382 SfxMedium aMedium( xFP->getFiles().getConstArray()[0], 383 STREAM_WRITE | STREAM_SHARE_DENYNONE, 384 sal_False ); 385 SvStream* pOutStream = aMedium.GetOutStream(); 386 pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding)); 387 aEditWin.Write( *pOutStream ); 388 aMedium.Commit(); 389 } 390 } 391 break; 392 case SID_SAVEDOC: 393 { 394 SwDocShell* pDocShell = GetDocShell(); 395 SfxMedium* pMed = 0; 396 if(pDocShell->HasName()) 397 pMed = pDocShell->GetMedium(); 398 else 399 { 400 SfxBoolItem* pItem = (SfxBoolItem*)pDocShell->ExecuteSlot(rReq, pDocShell->GetInterface()); 401 if(pItem && pItem->GetValue()) 402 pMed = pDocShell->GetMedium(); 403 } 404 if(pMed) 405 { 406 SvStream* pOutStream = pMed->GetOutStream(); 407 pOutStream->Seek(0); 408 pOutStream->SetStreamSize(0); 409 pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding)); 410 aEditWin.Write( *pOutStream ); 411 pMed->CloseOutStream(); 412 pMed->Commit(); 413 pDocShell->GetDoc()->ResetModified(); 414 SourceSaved(); 415 aEditWin.ClearModifyFlag(); 416 } 417 } 418 break; 419 case FID_SEARCH_NOW: 420 { 421 const SfxItemSet* pTmpArgs = rReq.GetArgs(); 422 423 sal_uInt16 nWhich = pTmpArgs->GetWhichByPos( 0 ); 424 DBG_ASSERT( nWhich, "Wich fuer SearchItem ?" ); 425 const SfxPoolItem& rItem = pTmpArgs->Get( nWhich ); 426 SetSearchItem( (const SvxSearchItem&)rItem); 427 StartSearchAndReplace( (const SvxSearchItem&)rItem, sal_False, rReq.IsAPI() ); 428 if(aEditWin.IsModified()) 429 GetDocShell()->GetDoc()->SetModified(); 430 } 431 break; 432 case FN_REPEAT_SEARCH: 433 { 434 SvxSearchItem* pSrchItem = GetSearchItem(); 435 if(pSrchItem) 436 { 437 StartSearchAndReplace( *pSrchItem, sal_False, rReq.IsAPI() ); 438 if(aEditWin.IsModified()) 439 GetDocShell()->GetDoc()->SetModified(); 440 } 441 } 442 break; 443 case SID_PRINTDOC: 444 case SID_PRINTDOCDIRECT: 445 { 446 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() ); 447 } 448 break; 449 case SID_UNDO: 450 pTextView->Undo(); 451 GetViewFrame()->GetBindings().InvalidateAll(sal_False); 452 break; 453 case SID_REDO: 454 pTextView->Redo(); 455 GetViewFrame()->GetBindings().InvalidateAll(sal_False); 456 break; 457 case SID_REPEAT: 458 break; 459 case SID_CUT: 460 if(pTextView->HasSelection()) 461 pTextView->Cut(); 462 break; 463 case SID_COPY: 464 if(pTextView->HasSelection()) 465 pTextView->Copy(); 466 break; 467 case SID_PASTE: 468 pTextView->Paste(); 469 break; 470 case SID_SELECTALL: 471 pTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) ); 472 break; 473 } 474 aEditWin.Invalidate(); 475 } 476 477 /*-------------------------------------------------------------------- 478 Beschreibung: 479 --------------------------------------------------------------------*/ 480 481 482 void SwSrcView::GetState(SfxItemSet& rSet) 483 { 484 SfxWhichIter aIter(rSet); 485 sal_uInt16 nWhich = aIter.FirstWhich(); 486 TextView* pTextView = aEditWin.GetTextView(); 487 488 while(nWhich) 489 { 490 switch(nWhich) 491 { 492 case SID_SAVEASDOC: 493 rSet.Put(SfxStringItem(nWhich, String(SW_RES(STR_SAVEAS_SRC)))); 494 break; 495 case SID_SAVEDOC: 496 { 497 SwDocShell* pDocShell = GetDocShell(); 498 if(!pDocShell->IsModified()) 499 rSet.DisableItem(nWhich); 500 } 501 break; 502 case SID_PRINTDOC: 503 case SID_PRINTDOCDIRECT: 504 break; 505 case SID_TABLE_CELL: 506 { 507 String aPos( SW_RES(STR_SRCVIEW_ROW) ); 508 TextSelection aSel = pTextView->GetSelection(); 509 aPos += String::CreateFromInt32( aSel.GetEnd().GetPara()+1 ); 510 aPos +=C2S(" : "); 511 aPos += String(SW_RES(STR_SRCVIEW_COL)); 512 aPos += String::CreateFromInt32( aSel.GetEnd().GetIndex()+1 ); 513 SfxStringItem aItem( nWhich, aPos ); 514 rSet.Put( aItem ); 515 } 516 break; 517 case SID_SEARCH_OPTIONS: 518 { 519 sal_uInt16 nOpt = SRC_SEARCHOPTIONS; 520 if(GetDocShell()->IsReadOnly()) 521 nOpt &= ~(SEARCH_OPTIONS_REPLACE|SEARCH_OPTIONS_REPLACE_ALL); 522 523 rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOpt) ); 524 } 525 break; 526 case SID_SEARCH_ITEM: 527 { 528 String sSelected; 529 if ( !pTextView->HasSelection() ) 530 { 531 const TextSelection& rSel = pTextView->GetSelection(); 532 sSelected = aEditWin.GetTextEngine()->GetWord( rSel.GetStart()); 533 } 534 else 535 { 536 sSelected = pTextView->GetSelected(); 537 } 538 SvxSearchItem * pSrchItem = GetSearchItem(); 539 pSrchItem->SetSearchString( sSelected ); 540 rSet.Put( *pSrchItem ); 541 } 542 break; 543 case FN_REPEAT_SEARCH: 544 { 545 if(!GetSearchItem()) 546 rSet.DisableItem(nWhich); 547 }; 548 break; 549 case SID_UNDO: 550 case SID_REDO: 551 { 552 ::svl::IUndoManager& rMgr = pTextView->GetTextEngine()->GetUndoManager(); 553 sal_uInt16 nCount = 0; 554 if(nWhich == SID_UNDO) 555 { 556 nCount = rMgr.GetUndoActionCount(); 557 if(nCount) 558 { 559 String aStr(SvtResId( STR_UNDO));; 560 aStr += rMgr.GetUndoActionComment(--nCount); 561 rSet.Put(SfxStringItem(nWhich, aStr)); 562 } 563 else 564 rSet.DisableItem(nWhich); 565 } 566 else 567 { 568 nCount = rMgr.GetRedoActionCount(); 569 if(nCount) 570 { 571 String aStr(SvtResId( STR_REDO));; 572 aStr += rMgr.GetRedoActionComment(--nCount); 573 rSet.Put(SfxStringItem(nWhich,aStr)); 574 } 575 else 576 rSet.DisableItem(nWhich); 577 } 578 } 579 break; 580 case SID_MAIL_SENDDOCASPDF: 581 case SID_MAIL_SENDDOC : 582 case SID_EXPORTDOCASPDF: 583 case SID_DIRECTEXPORTDOCASPDF: 584 case SID_EXPORTDOC: 585 case SID_REPEAT: 586 case SID_BROWSER_MODE: 587 case FN_PRINT_LAYOUT: 588 rSet.DisableItem(nWhich); 589 break; 590 case SID_CUT: 591 case SID_COPY: 592 if(!pTextView->HasSelection()) 593 rSet.DisableItem(nWhich); 594 break; 595 case SID_PASTE: 596 { 597 TransferableDataHelper aDataHelper( 598 TransferableDataHelper::CreateFromSystemClipboard( 599 &aEditWin) ); 600 sal_Bool bDisable = !aDataHelper.GetXTransferable().is() || 601 0 == aDataHelper.GetFormatCount(); 602 if( bDisable ) 603 rSet.DisableItem(nWhich); 604 } 605 break; 606 } 607 nWhich = aIter.NextWhich(); 608 } 609 } 610 611 /*-------------------------------------------------------------------- 612 Beschreibung: 613 --------------------------------------------------------------------*/ 614 615 616 SvxSearchItem* SwSrcView::GetSearchItem() 617 { 618 if(!pSearchItem) 619 { 620 pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM); 621 } 622 return pSearchItem; 623 } 624 625 /*-------------------------------------------------------------------- 626 Beschreibung: 627 --------------------------------------------------------------------*/ 628 629 630 void SwSrcView::SetSearchItem( const SvxSearchItem& rItem ) 631 { 632 delete pSearchItem; 633 pSearchItem = (SvxSearchItem*)rItem.Clone(); 634 } 635 636 /*-------------------------------------------------------------------- 637 Beschreibung: 638 --------------------------------------------------------------------*/ 639 640 641 sal_uInt16 SwSrcView::StartSearchAndReplace(const SvxSearchItem& rSearchItem, 642 sal_Bool bFromStart, 643 sal_Bool bApi, 644 sal_Bool bRecursive) 645 { 646 ExtTextView* pTextView = aEditWin.GetTextView(); 647 TextSelection aSel; 648 TextPaM aPaM; 649 650 sal_Bool bForward = !rSearchItem.GetBackward(); 651 sal_Bool bAtStart = pTextView->GetSelection() == TextSelection( aPaM, aPaM ); 652 653 if( !bForward ) 654 aPaM = TextPaM( (sal_uLong)-1, (sal_uInt16)-1 ); 655 656 if( bFromStart ) 657 { 658 aSel = pTextView->GetSelection(); 659 pTextView->SetSelection( TextSelection( aPaM, aPaM )); 660 } 661 662 util::SearchOptions aSearchOpt( rSearchItem.GetSearchOptions() ); 663 aSearchOpt.Locale = SvxCreateLocale( 664 static_cast< LanguageType >( GetAppLanguage() ) ); 665 666 sal_uInt16 nFound; 667 sal_Bool bAll = sal_False; 668 switch( rSearchItem.GetCommand() ) 669 { 670 case SVX_SEARCHCMD_FIND: 671 case SVX_SEARCHCMD_FIND_ALL: 672 nFound = pTextView->Search( aSearchOpt, bForward ); 673 break; 674 675 case SVX_SEARCHCMD_REPLACE_ALL: bAll = sal_True; 676 case SVX_SEARCHCMD_REPLACE: 677 nFound = pTextView->Replace( aSearchOpt, bAll, bForward ); 678 break; 679 680 default: 681 nFound = 0; 682 } 683 684 if( !nFound ) 685 { 686 sal_Bool bNotFoundMessage = sal_False; 687 if(!bRecursive) 688 { 689 if(!bFromStart) 690 { 691 bNotFoundMessage = bAtStart; 692 } 693 else 694 { 695 bNotFoundMessage = sal_True; 696 pTextView->SetSelection( aSel ); 697 } 698 } 699 else if(bAtStart) 700 { 701 bNotFoundMessage = sal_True; 702 } 703 704 705 if(!bApi) 706 { 707 if(bNotFoundMessage) 708 { 709 InfoBox( 0, SW_RES(MSG_NOT_FOUND)).Execute(); 710 } 711 else if(!bRecursive && RET_YES == 712 QueryBox(0, SW_RES( bForward ? MSG_SEARCH_END 713 : MSG_SEARCH_START)).Execute()) 714 { 715 pTextView->SetSelection( TextSelection( aPaM, aPaM ) ); 716 StartSearchAndReplace( rSearchItem, sal_False, sal_False, sal_True ); 717 } 718 } 719 } 720 return nFound; 721 } 722 723 /*-------------------------------------------------------------------- 724 Beschreibung: 725 --------------------------------------------------------------------*/ 726 727 sal_uInt16 SwSrcView::SetPrinter(SfxPrinter* pNew, sal_uInt16 nDiffFlags, bool ) 728 { 729 SwDocShell* pDocSh = GetDocShell(); 730 if ( (SFX_PRINTER_JOBSETUP | SFX_PRINTER_PRINTER) & nDiffFlags ) 731 { 732 pDocSh->GetDoc()->setPrinter( pNew, true, true ); 733 if ( nDiffFlags & SFX_PRINTER_PRINTER ) 734 pDocSh->SetModified(); 735 } 736 if ( nDiffFlags & SFX_PRINTER_OPTIONS ) 737 ::SetPrinter( pDocSh->getIDocumentDeviceAccess(), pNew, sal_True ); 738 739 const sal_Bool bChgOri = nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ? sal_True : sal_False; 740 const sal_Bool bChgSize= nDiffFlags & SFX_PRINTER_CHG_SIZE ? sal_True : sal_False; 741 if ( bChgOri || bChgSize ) 742 { 743 pDocSh->SetModified(); 744 } 745 return 0; 746 } 747 748 /*-------------------------------------------------------------------- 749 Beschreibung: 750 --------------------------------------------------------------------*/ 751 752 SfxPrinter* SwSrcView::GetPrinter( sal_Bool bCreate ) 753 { 754 return GetDocShell()->GetDoc()->getPrinter( bCreate ); 755 } 756 757 /*-------------------------------------------------------------------- 758 Beschreibung: 759 --------------------------------------------------------------------*/ 760 sal_Int32 SwSrcView::PrintSource( 761 OutputDevice *pOutDev, 762 sal_Int32 nPage, 763 bool bCalcNumPagesOnly ) 764 { 765 if (!pOutDev || nPage <= 0) 766 return 0; 767 768 //! this a lgorithm for printing the n-th page is very poor since it 769 //! needs to go over the text of all previous pages to get to the correct one. 770 //! But since HTML source code is expected to be just a small number of pages 771 //! even this poor algorithm should be enough... 772 773 pOutDev->Push(); 774 775 TextEngine* pTextEngine = aEditWin.GetTextEngine(); 776 pOutDev->SetMapMode( MAP_100TH_MM ); 777 Font aFont( aEditWin.GetOutWin()->GetFont() ); 778 Size aSize( aFont.GetSize() ); 779 aSize = aEditWin.GetOutWin()->PixelToLogic( aSize, MAP_100TH_MM ); 780 aFont.SetSize( aSize ); 781 aFont.SetColor( COL_BLACK ); 782 pOutDev->SetFont( aFont ); 783 784 String aTitle( GetViewFrame()->GetWindow().GetText() ); 785 786 sal_uInt16 nLineHeight = (sal_uInt16) pOutDev->GetTextHeight(); // etwas mehr. 787 sal_uInt16 nParaSpace = 10; 788 789 Size aPaperSz = pOutDev->GetOutputSize(); 790 aPaperSz.Width() -= (LMARGPRN + RMARGPRN); 791 aPaperSz.Height() -= (TMARGPRN + BMARGPRN); 792 793 // nLinepPage stimmt nicht, wenn Zeilen umgebrochen werden muessen... 794 sal_uInt16 nLinespPage = (sal_uInt16) (aPaperSz.Height() / nLineHeight); 795 sal_uInt16 nCharspLine = (sal_uInt16) (aPaperSz.Width() / pOutDev->GetTextWidth( 'X' )); 796 sal_uInt16 nParas = static_cast< sal_uInt16 >( pTextEngine->GetParagraphCount() ); 797 798 sal_uInt16 nPages = (sal_uInt16) (nParas / nLinespPage + 1 ); 799 sal_uInt16 nCurPage = 1; 800 801 // Header drucken... 802 if (!bCalcNumPagesOnly && nPage == nCurPage) 803 lcl_PrintHeader( *pOutDev, nPages, nCurPage, aTitle ); 804 const Point aStartPos( LMARGPRN, TMARGPRN ); 805 Point aPos( aStartPos ); 806 for ( sal_uInt16 nPara = 0; nPara < nParas; ++nPara ) 807 { 808 String aLine( pTextEngine->GetText( nPara ) ); 809 lcl_ConvertTabsToSpaces( aLine ); 810 sal_uInt16 nLines = aLine.Len() / nCharspLine + 1; 811 for ( sal_uInt16 nLine = 0; nLine < nLines; ++nLine ) 812 { 813 String aTmpLine( aLine, nLine * nCharspLine, nCharspLine ); 814 aPos.Y() += nLineHeight; 815 if ( aPos.Y() > ( aPaperSz.Height() + TMARGPRN - nLineHeight/2 ) ) 816 { 817 ++nCurPage; 818 if (!bCalcNumPagesOnly && nPage == nCurPage) 819 lcl_PrintHeader( *pOutDev, nPages, nCurPage, aTitle ); 820 aPos = aStartPos; 821 } 822 if (!bCalcNumPagesOnly && nPage == nCurPage) 823 pOutDev->DrawText( aPos, aTmpLine ); 824 } 825 aPos.Y() += nParaSpace; 826 } 827 828 pOutDev->Pop(); 829 830 DBG_ASSERT( bCalcNumPagesOnly || nPage <= nCurPage, "page number out of range" ); 831 return nCurPage; 832 } 833 834 835 /*-------------------------------------------------------------------- 836 Beschreibung: 837 --------------------------------------------------------------------*/ 838 839 840 void SwSrcView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) 841 { 842 if ( rHint.ISA(SfxSimpleHint) && 843 ( 844 ((SfxSimpleHint&) rHint).GetId() == SFX_HINT_MODECHANGED || 845 ( 846 ((SfxSimpleHint&) rHint).GetId() == SFX_HINT_TITLECHANGED && 847 !GetDocShell()->IsReadOnly() && aEditWin.IsReadonly() 848 ) 849 ) 850 ) 851 { 852 // Broadcast kommt nur einmal! 853 const SwDocShell* pDocSh = GetDocShell(); 854 const sal_Bool bReadonly = pDocSh->IsReadOnly(); 855 aEditWin.SetReadonly(bReadonly); 856 } 857 SfxViewShell::Notify(rBC, rHint); 858 } 859 860 /*-----------------19.04.97 10:19------------------- 861 862 --------------------------------------------------*/ 863 void SwSrcView::Load(SwDocShell* pDocShell) 864 { 865 SvxHtmlOptions* pHtmlOptions = SvxHtmlOptions::Get(); 866 const sal_Char *pCharSet = 867 rtl_getBestMimeCharsetFromTextEncoding( pHtmlOptions->GetTextEncoding() ); 868 rtl_TextEncoding eDestEnc = rtl_getTextEncodingFromMimeCharset( pCharSet ); 869 870 aEditWin.SetReadonly(pDocShell->IsReadOnly()); 871 aEditWin.SetTextEncoding(eDestEnc); 872 SfxMedium* pMedium = pDocShell->GetMedium(); 873 874 const SfxFilter* pFilter = pMedium->GetFilter(); 875 sal_Bool bHtml = pFilter && pFilter->GetUserData().EqualsAscii("HTML"); 876 sal_Bool bDocModified = pDocShell->IsModified(); 877 if(bHtml && !bDocModified && pDocShell->HasName()) 878 { 879 SvStream* pStream = pMedium->GetInStream(); 880 if(pStream && 0 == pStream->GetError() ) 881 { 882 rtl_TextEncoding eHeaderEnc = 883 SfxHTMLParser::GetEncodingByHttpHeader( 884 pDocShell->GetHeaderAttributes() ); 885 if( RTL_TEXTENCODING_DONTKNOW == eHeaderEnc ) 886 { 887 const sal_Char *pTmpCharSet = 888 rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1 ); 889 eHeaderEnc = rtl_getTextEncodingFromMimeCharset( pTmpCharSet ); 890 } 891 if( RTL_TEXTENCODING_DONTKNOW != eHeaderEnc && 892 eDestEnc != eHeaderEnc ) 893 { 894 eDestEnc = eHeaderEnc; 895 aEditWin.SetTextEncoding(eDestEnc); 896 } 897 pStream->SetStreamCharSet( eDestEnc ); 898 pStream->Seek(0); 899 TextEngine* pTextEngine = aEditWin.GetTextEngine(); 900 pTextEngine->EnableUndo(sal_False); 901 aEditWin.Read(*pStream);//, EE_FORMAT_TEXT); 902 pTextEngine->EnableUndo(sal_True); 903 } 904 else 905 { 906 Window *pTmpWindow = &GetViewFrame()->GetWindow(); 907 InfoBox(pTmpWindow, SW_RES(MSG_ERR_SRCSTREAM)).Execute(); 908 } 909 } 910 else 911 { 912 utl::TempFile aTempFile; 913 aTempFile.EnableKillingFile(); 914 String sFileURL( aTempFile.GetURL() ); 915 SvtSaveOptions aOpt; 916 917 { 918 SfxMedium aMedium( sFileURL,STREAM_READWRITE, sal_True ); 919 SwWriter aWriter( aMedium, *pDocShell->GetDoc() ); 920 WriterRef xWriter; 921 ::GetHTMLWriter(aEmptyStr, aMedium.GetBaseURL( true ), xWriter); 922 String sWriteName = pDocShell->HasName() ? 923 pMedium->GetName() : 924 (const String&) sFileURL; 925 sal_uLong nRes = aWriter.Write(xWriter, &sWriteName); 926 if(nRes) 927 { 928 ErrorHandler::HandleError(ErrCode(nRes)); 929 aEditWin.SetReadonly(sal_True); 930 } 931 aMedium.Commit(); 932 SvStream* pInStream = aMedium.GetInStream(); 933 pInStream->Seek(0); 934 pInStream->SetStreamCharSet( eDestEnc ); 935 936 937 aEditWin.Read(*pInStream);//, EE_FORMAT_TEXT); 938 } 939 } 940 aEditWin.ClearModifyFlag(); 941 942 eLoadEncoding = eDestEnc; 943 944 if(bDocModified) 945 pDocShell->SetModified();// das Flag wird zwischendurch zurueckgesetzt 946 // AutoLoad abschalten 947 pDocShell->SetAutoLoad(INetURLObject(), 0, sal_False); 948 DBG_ASSERT(PTR_CAST(SwWebDocShell, pDocShell), "Wieso keine WebDocShell?"); 949 sal_uInt16 nLine = ((SwWebDocShell*)pDocShell)->GetSourcePara(); 950 aEditWin.SetStartLine(nLine); 951 aEditWin.GetTextEngine()->ResetUndo(); 952 aEditWin.GetOutWin()->GrabFocus(); 953 } 954 955 956