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