LCOV - code coverage report
Current view: top level - sw/source/core/uibase/uiview - srcview.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 439 0.0 %
Date: 2014-04-14 Functions: 0 34 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10