1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <hintids.hxx>
22 #include <com/sun/star/util/SearchOptions.hpp>
23 #include <com/sun/star/util/SearchFlags.hpp>
24 #include <com/sun/star/i18n/TransliterationModules.hpp>
25 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
26 #include <comphelper/string.hxx>
27 #include <unotools/tempfile.hxx>
28 #include <tools/urlobj.hxx>
29 #include <vcl/print.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <vcl/wrkwin.hxx>
32 #include <vcl/metric.hxx>
33 #include <svtools/ctrltool.hxx>
34 #include <svl/intitem.hxx>
35 #include <svl/stritem.hxx>
36 #include <unotools/pathoptions.hxx>
37 #include <svl/undo.hxx>
38 #include <unotools/textsearch.hxx>
39 #include <svl/eitem.hxx>
40 #include <svl/whiter.hxx>
41 #include <unotools/saveopt.hxx>
42 #include <svtools/transfer.hxx>
43 #include <svtools/svtools.hrc>
44 #include <svtools/svtresid.hxx>
45 #include <svx/svxids.hrc>
46 #include <svtools/htmlcfg.hxx>
47 #include <sfx2/app.hxx>
48 #include <sfx2/objface.hxx>
49 #include <sfx2/viewfrm.hxx>
50 #include <sfx2/bindings.hxx>
51 #include <sfx2/docfilt.hxx>
52 #include <sfx2/fcontnr.hxx>
53 #include <sfx2/request.hxx>
54 #include <sfx2/prnmon.hxx>
55 #include <sfx2/docfile.hxx>
56 #include <editeng/fhgtitem.hxx>
57 #include <svx/srchdlg.hxx>
58 #include <svl/srchitem.hxx>
59 #include <editeng/fontitem.hxx>
60 #include <editeng/flstitem.hxx>
61 #include "editeng/unolingu.hxx"
62 #include <sfx2/sfxhtml.hxx>
63 #include <swtypes.hxx>
64 #include <swmodule.hxx>
67 #include <srcview.hxx>
68 #include <viewfunc.hxx>
70 #include <sfx2/msg.hxx>
71 #include <shellio.hxx>
73 #include <cmdid.h> // FN_ ...
75 #include <globals.hrc>
80 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
81 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
82 #include <sfx2/filedlghelper.hxx>
84 #include "swslots.hxx"
88 #include <com/sun/star/document/XDocumentProperties.hpp>
89 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
91 using namespace ::com::sun::star
;
92 using namespace ::com::sun::star::i18n
;
93 using namespace ::com::sun::star::lang
;
94 using namespace ::com::sun::star::uno
;
95 using namespace ::com::sun::star::ui::dialogs
;
96 using namespace ::sfx2
;
97 using ::com::sun::star::util::SearchOptions
;
100 #define SWSRCVIEWFLAGS ( SFX_VIEW_CAN_PRINT|\
101 SFX_VIEW_NO_NEWWINDOW )
103 #define SRC_SEARCHOPTIONS (0xFFFF & ~(SEARCH_OPTIONS_FORMAT|SEARCH_OPTIONS_FAMILIES|SEARCH_OPTIONS_SEARCH_ALL))
105 // Druckraender -> wie Basic - Ide
106 #define LMARGPRN 1700
108 #define TMARGPRN 2000
109 #define BMARGPRN 1000
110 #define BORDERPRN 300
112 SFX_IMPL_NAMED_VIEWFACTORY(SwSrcView
, "SourceView")
114 SFX_VIEW_REGISTRATION(SwWebDocShell
);
117 SFX_IMPL_INTERFACE( SwSrcView
, SfxViewShell
, SW_RES(0) )
119 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_SRCVIEW_POPUPMENU
));
120 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS
|
121 SFX_VISIBILITY_STANDARD
|SFX_VISIBILITY_SERVER
,
122 SW_RES(RID_WEBTOOLS_TOOLBOX
) );
123 SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
126 TYPEINIT1(SwSrcView
, SfxViewShell
)
128 static void lcl_PrintHeader( OutputDevice
&rOutDev
, sal_uInt16 nPages
, sal_uInt16 nCurPage
, const String
& rTitle
)
130 short nLeftMargin
= LMARGPRN
;
131 Size aSz
= rOutDev
.GetOutputSize();
132 short nBorder
= BORDERPRN
;
134 Color
aOldFillColor( rOutDev
.GetFillColor() );
135 Font
aOldFont( rOutDev
.GetFont() );
137 rOutDev
.SetFillColor( Color(COL_TRANSPARENT
) );
139 Font
aFont( aOldFont
);
140 aFont
.SetWeight( WEIGHT_BOLD
);
141 aFont
.SetAlign( ALIGN_BOTTOM
);
142 rOutDev
.SetFont( aFont
);
144 long nFontHeight
= rOutDev
.GetTextHeight();
146 // 1.Border => Strich, 2+3 Border = Freiraum.
147 long nYTop
= TMARGPRN
-3*nBorder
-nFontHeight
;
149 long nXLeft
= nLeftMargin
-nBorder
;
150 long nXRight
= aSz
.Width()-RMARGPRN
+nBorder
;
152 rOutDev
.DrawRect( Rectangle(
153 Point( nXLeft
, nYTop
),
154 Size( nXRight
-nXLeft
, aSz
.Height() - nYTop
- BMARGPRN
+ nBorder
) ) );
157 long nY
= TMARGPRN
-2*nBorder
;
158 Point
aPos( nLeftMargin
, nY
);
159 rOutDev
.DrawText( aPos
, rTitle
);
162 aFont
.SetWeight( WEIGHT_NORMAL
);
163 rOutDev
.SetFont( aFont
);
164 String
aPageStr( OUString(" [") );
165 aPageStr
+= String( SW_RES( STR_PAGE
) );
167 aPageStr
+= OUString::number( nCurPage
);
169 aPos
.X() += rOutDev
.GetTextWidth( rTitle
);
170 rOutDev
.DrawText( aPos
, aPageStr
);
174 nY
= TMARGPRN
-nBorder
;
176 rOutDev
.DrawLine( Point( nXLeft
, nY
), Point( nXRight
, nY
) );
178 rOutDev
.SetFont( aOldFont
);
179 rOutDev
.SetFillColor( aOldFillColor
);
182 static rtl_TextEncoding
lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding
)
184 rtl_TextEncoding eRet
= eLoadEncoding
;
185 if(RTL_TEXTENCODING_DONTKNOW
== eRet
)
187 SvxHtmlOptions
& rHtmlOptions
= SvxHtmlOptions::Get();
188 const sal_Char
*pCharSet
=
189 rtl_getBestMimeCharsetFromTextEncoding( rHtmlOptions
.GetTextEncoding() );
190 eRet
= rtl_getTextEncodingFromMimeCharset( pCharSet
);
195 static void lcl_ConvertTabsToSpaces( String
& rLine
)
200 sal_uInt16 nMax
= rLine
.Len();
201 while ( nPos
< nMax
)
203 if ( rLine
.GetChar(nPos
) == '\t' )
205 // Nicht 4 Blanks, sondern an 4er TabPos:
206 OUStringBuffer aBlanker
;
207 comphelper::string::padToLength(aBlanker
, ( 4 - ( nPos
% 4 ) ), ' ');
208 rLine
.Erase( nPos
, 1 );
209 rLine
.Insert(aBlanker
.makeStringAndClear(), nPos
);
212 nPos
++; // Nicht optimal, falls Tab, aber auch nicht verkehrt...
217 SwSrcView::SwSrcView(SfxViewFrame
* pViewFrame
, SfxViewShell
*) :
218 SfxViewShell( pViewFrame
, SWSRCVIEWFLAGS
),
219 aEditWin( &pViewFrame
->GetWindow(), this ),
221 bSourceSaved(sal_False
),
222 eLoadEncoding(RTL_TEXTENCODING_DONTKNOW
)
227 SwSrcView::~SwSrcView()
229 SwDocShell
* pDocShell
= GetDocShell();
230 OSL_ENSURE(PTR_CAST(SwWebDocShell
, pDocShell
), "Wieso keine WebDocShell?");
231 const TextSelection
& rSel
= aEditWin
.GetTextView()->GetSelection();
232 ((SwWebDocShell
*)pDocShell
)->SetSourcePara( static_cast< sal_uInt16
>( rSel
.GetStart().GetPara() ) );
234 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
235 pDocShell
->GetModel(), uno::UNO_QUERY_THROW
);
236 uno::Reference
<document::XDocumentProperties
> xDocProps
237 = xDPS
->getDocumentProperties();
238 OUString url
= xDocProps
->getAutoloadURL();
239 sal_Int32 delay
= xDocProps
->getAutoloadSecs();
240 pDocShell
->SetAutoLoad(INetURLObject(url
), delay
,
241 (delay
!= 0) || !url
.isEmpty());
242 EndListening(*pDocShell
);
246 void SwSrcView::SaveContentTo(SfxMedium
& rMed
)
248 SvStream
* pOutStream
= rMed
.GetOutStream();
249 pOutStream
->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding
));
250 aEditWin
.Write( *pOutStream
);
253 void SwSrcView::Init()
255 SetHelpId(SW_SRC_VIEWSHELL
);
256 SetName(OUString("Source"));
257 SetWindow( &aEditWin
);
258 SwDocShell
* pDocShell
= GetDocShell();
259 // wird das Doc noch geladen, dann muss die DocShell das Load
260 // anwerfen, wenn das Laden abgeschlossen ist
261 if(!pDocShell
->IsLoading())
265 aEditWin
.SetReadonly(sal_True
);
268 SetNewWindowAllowed( sal_False
);
269 StartListening(*pDocShell
,sal_True
);
272 SwDocShell
* SwSrcView::GetDocShell()
274 SfxObjectShell
* pObjShell
= GetViewFrame()->GetObjectShell();
275 return PTR_CAST(SwDocShell
, pObjShell
);
278 void SwSrcView::SaveContent(const String
& rTmpFile
)
280 SfxMedium
aMedium( rTmpFile
, STREAM_WRITE
);
281 SvStream
* pOutStream
= aMedium
.GetOutStream();
282 pOutStream
->SetStreamCharSet( lcl_GetStreamCharSet(eLoadEncoding
) );
283 aEditWin
.Write(*pOutStream
);
287 void SwSrcView::Execute(SfxRequest
& rReq
)
289 sal_uInt16 nSlot
= rReq
.GetSlot();
290 TextView
* pTextView
= aEditWin
.GetTextView();
296 SvtPathOptions aPathOpt
;
297 // filesave dialog with autoextension
298 FileDialogHelper
aDlgHelper(
299 TemplateDescription::FILESAVE_AUTOEXTENSION
, 0 );
300 uno::Reference
< XFilePicker
> xFP
= aDlgHelper
.GetFilePicker();
301 uno::Reference
<XFilterManager
> xFltMgr(xFP
, UNO_QUERY
);
303 // search for an html filter for export
304 SfxFilterContainer
* pFilterCont
= GetObjectShell()->GetFactory().GetFilterContainer();
305 const SfxFilter
* pFilter
=
306 pFilterCont
->GetFilter4Extension( OUString("html"), SFX_FILTER_EXPORT
);
309 // filter found -> use its uiname and wildcard
310 const String
& rUIName
= pFilter
->GetUIName();
311 const WildCard
& rCard
= pFilter
->GetWildcard();
312 xFltMgr
->appendFilter( rUIName
, rCard
.getGlob() );
313 xFltMgr
->setCurrentFilter( rUIName
) ;
318 OUString
sHtml("HTML");
319 xFltMgr
->appendFilter( sHtml
, OUString("*.html;*.htm") );
320 xFltMgr
->setCurrentFilter( sHtml
) ;
323 xFP
->setDisplayDirectory( aPathOpt
.GetWorkPath() );
324 if( aDlgHelper
.Execute() == ERRCODE_NONE
)
326 SfxMedium
aMedium( xFP
->getFiles().getConstArray()[0],
327 STREAM_WRITE
| STREAM_SHARE_DENYNONE
);
328 SvStream
* pOutStream
= aMedium
.GetOutStream();
329 pOutStream
->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding
));
330 aEditWin
.Write( *pOutStream
);
337 SwDocShell
* pDocShell
= GetDocShell();
339 if(pDocShell
->HasName())
340 pMed
= pDocShell
->GetMedium();
343 SfxBoolItem
* pItem
= (SfxBoolItem
*)pDocShell
->ExecuteSlot(rReq
, pDocShell
->GetInterface());
344 if(pItem
&& pItem
->GetValue())
345 pMed
= pDocShell
->GetMedium();
349 SvStream
* pOutStream
= pMed
->GetOutStream();
351 pOutStream
->SetStreamSize(0);
352 pOutStream
->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding
));
353 aEditWin
.Write( *pOutStream
);
354 pMed
->CloseOutStream();
356 pDocShell
->GetDoc()->ResetModified();
358 aEditWin
.ClearModifyFlag();
364 const SfxItemSet
* pTmpArgs
= rReq
.GetArgs();
366 sal_uInt16 nWhich
= pTmpArgs
->GetWhichByPos( 0 );
367 OSL_ENSURE( nWhich
, "Wich fuer SearchItem ?" );
368 const SfxPoolItem
& rItem
= pTmpArgs
->Get( nWhich
);
369 SetSearchItem( (const SvxSearchItem
&)rItem
);
370 StartSearchAndReplace( (const SvxSearchItem
&)rItem
, sal_False
, rReq
.IsAPI() );
371 if(aEditWin
.IsModified())
372 GetDocShell()->GetDoc()->SetModified();
375 case FN_REPEAT_SEARCH
:
377 SvxSearchItem
* pSrchItem
= GetSearchItem();
380 StartSearchAndReplace( *pSrchItem
, sal_False
, rReq
.IsAPI() );
381 if(aEditWin
.IsModified())
382 GetDocShell()->GetDoc()->SetModified();
387 case SID_PRINTDOCDIRECT
:
389 SfxViewShell::ExecuteSlot( rReq
, SfxViewShell::GetInterface() );
394 GetViewFrame()->GetBindings().InvalidateAll(sal_False
);
398 GetViewFrame()->GetBindings().InvalidateAll(sal_False
);
403 if(pTextView
->HasSelection())
407 if(pTextView
->HasSelection())
414 pTextView
->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
417 aEditWin
.Invalidate();
420 void SwSrcView::GetState(SfxItemSet
& rSet
)
422 SfxWhichIter
aIter(rSet
);
423 sal_uInt16 nWhich
= aIter
.FirstWhich();
424 TextView
* pTextView
= aEditWin
.GetTextView();
431 rSet
.Put(SfxStringItem(nWhich
, String(SW_RES(STR_SAVEAS_SRC
))));
434 rSet
.Put(SfxStringItem(nWhich
, String(SW_RES(STR_SAVEACOPY_SRC
))));
438 SwDocShell
* pDocShell
= GetDocShell();
439 if(!pDocShell
->IsModified())
440 rSet
.DisableItem(nWhich
);
444 case SID_PRINTDOCDIRECT
:
448 String
aPos( SW_RES(STR_SRCVIEW_ROW
) );
449 TextSelection aSel
= pTextView
->GetSelection();
450 aPos
+= OUString::number( aSel
.GetEnd().GetPara()+1 );
451 aPos
+= OUString(" : ");
452 aPos
+= String(SW_RES(STR_SRCVIEW_COL
));
453 aPos
+= OUString::number( aSel
.GetEnd().GetIndex()+1 );
454 SfxStringItem
aItem( nWhich
, aPos
);
458 case SID_SEARCH_OPTIONS
:
460 sal_uInt16 nOpt
= SRC_SEARCHOPTIONS
;
461 if(GetDocShell()->IsReadOnly())
462 nOpt
&= ~(SEARCH_OPTIONS_REPLACE
|SEARCH_OPTIONS_REPLACE_ALL
);
464 rSet
.Put( SfxUInt16Item( SID_SEARCH_OPTIONS
, nOpt
) );
467 case SID_SEARCH_ITEM
:
470 if ( !pTextView
->HasSelection() )
472 const TextSelection
& rSel
= pTextView
->GetSelection();
473 sSelected
= aEditWin
.GetTextEngine()->GetWord( rSel
.GetStart());
477 sSelected
= pTextView
->GetSelected();
479 SvxSearchItem
* pSrchItem
= GetSearchItem();
480 pSrchItem
->SetSearchString( sSelected
);
481 rSet
.Put( *pSrchItem
);
484 case FN_REPEAT_SEARCH
:
487 rSet
.DisableItem(nWhich
);
493 ::svl::IUndoManager
& rMgr
= pTextView
->GetTextEngine()->GetUndoManager();
494 sal_uInt16 nCount
= 0;
495 if(nWhich
== SID_UNDO
)
497 nCount
= rMgr
.GetUndoActionCount();
500 String
aStr(SvtResId( STR_UNDO
));
501 aStr
+= rMgr
.GetUndoActionComment(--nCount
);
502 rSet
.Put(SfxStringItem(nWhich
, aStr
));
505 rSet
.DisableItem(nWhich
);
509 nCount
= rMgr
.GetRedoActionCount();
512 String
aStr(SvtResId( STR_REDO
));
513 aStr
+= rMgr
.GetRedoActionComment(--nCount
);
514 rSet
.Put(SfxStringItem(nWhich
,aStr
));
517 rSet
.DisableItem(nWhich
);
521 case SID_MAIL_SENDDOCASPDF
:
522 case SID_MAIL_SENDDOC
:
523 case SID_EXPORTDOCASPDF
:
524 case SID_DIRECTEXPORTDOCASPDF
:
527 case SID_BROWSER_MODE
:
528 case FN_PRINT_LAYOUT
:
529 rSet
.DisableItem(nWhich
);
533 if(!pTextView
->HasSelection())
534 rSet
.DisableItem(nWhich
);
538 TransferableDataHelper
aDataHelper(
539 TransferableDataHelper::CreateFromSystemClipboard(
541 bool bDisable
= !aDataHelper
.GetXTransferable().is() ||
542 0 == aDataHelper
.GetFormatCount();
544 rSet
.DisableItem(nWhich
);
548 nWhich
= aIter
.NextWhich();
552 SvxSearchItem
* SwSrcView::GetSearchItem()
556 pSearchItem
= new SvxSearchItem(SID_SEARCH_ITEM
);
561 void SwSrcView::SetSearchItem( const SvxSearchItem
& rItem
)
564 pSearchItem
= (SvxSearchItem
*)rItem
.Clone();
567 sal_uInt16
SwSrcView::StartSearchAndReplace(const SvxSearchItem
& rSearchItem
,
572 ExtTextView
* pTextView
= aEditWin
.GetTextView();
576 sal_Bool bForward
= !rSearchItem
.GetBackward();
577 bool bAtStart
= pTextView
->GetSelection() == TextSelection( aPaM
, aPaM
);
580 aPaM
= TextPaM( (sal_uLong
)-1, (sal_uInt16
)-1 );
584 aSel
= pTextView
->GetSelection();
585 pTextView
->SetSelection( TextSelection( aPaM
, aPaM
));
588 util::SearchOptions
aSearchOpt( rSearchItem
.GetSearchOptions() );
589 aSearchOpt
.Locale
= GetAppLanguageTag().getLocale();
592 sal_Bool bAll
= sal_False
;
593 switch( rSearchItem
.GetCommand() )
595 case SVX_SEARCHCMD_FIND
:
596 case SVX_SEARCHCMD_FIND_ALL
:
597 nFound
= pTextView
->Search( aSearchOpt
, bForward
);
600 case SVX_SEARCHCMD_REPLACE_ALL
: bAll
= sal_True
;
601 case SVX_SEARCHCMD_REPLACE
:
602 nFound
= pTextView
->Replace( aSearchOpt
, bAll
, bForward
);
611 bool bNotFoundMessage
= false;
616 bNotFoundMessage
= bAtStart
;
620 bNotFoundMessage
= true;
621 pTextView
->SetSelection( aSel
);
626 bNotFoundMessage
= true;
634 InfoBox( 0, SW_RES(MSG_NOT_FOUND
)).Execute();
636 else if(!bRecursive
&& RET_YES
==
637 QueryBox(0, SW_RES( bForward
? MSG_SEARCH_END
638 : MSG_SEARCH_START
)).Execute())
640 pTextView
->SetSelection( TextSelection( aPaM
, aPaM
) );
641 StartSearchAndReplace( rSearchItem
, sal_False
, sal_False
, sal_True
);
648 sal_uInt16
SwSrcView::SetPrinter(SfxPrinter
* pNew
, sal_uInt16 nDiffFlags
, bool )
650 SwDocShell
* pDocSh
= GetDocShell();
651 if ( (SFX_PRINTER_JOBSETUP
| SFX_PRINTER_PRINTER
) & nDiffFlags
)
653 pDocSh
->GetDoc()->setPrinter( pNew
, true, true );
654 if ( nDiffFlags
& SFX_PRINTER_PRINTER
)
655 pDocSh
->SetModified();
657 if ( nDiffFlags
& SFX_PRINTER_OPTIONS
)
658 ::SetPrinter( pDocSh
->getIDocumentDeviceAccess(), pNew
, sal_True
);
660 const bool bChgOri
= nDiffFlags
& SFX_PRINTER_CHG_ORIENTATION
;
661 const bool bChgSize
= nDiffFlags
& SFX_PRINTER_CHG_SIZE
;
662 if ( bChgOri
|| bChgSize
)
664 pDocSh
->SetModified();
669 SfxPrinter
* SwSrcView::GetPrinter( sal_Bool bCreate
)
671 return GetDocShell()->GetDoc()->getPrinter( bCreate
);
674 sal_Int32
SwSrcView::PrintSource(
675 OutputDevice
*pOutDev
,
677 bool bCalcNumPagesOnly
)
679 if (!pOutDev
|| nPage
<= 0)
682 //! this a lgorithm for printing the n-th page is very poor since it
683 //! needs to go over the text of all previous pages to get to the correct one.
684 //! But since HTML source code is expected to be just a small number of pages
685 //! even this poor algorithm should be enough...
689 TextEngine
* pTextEngine
= aEditWin
.GetTextEngine();
690 pOutDev
->SetMapMode( MAP_100TH_MM
);
691 Font
aFont( aEditWin
.GetOutWin()->GetFont() );
692 Size
aSize( aFont
.GetSize() );
693 aSize
= aEditWin
.GetOutWin()->PixelToLogic( aSize
, MAP_100TH_MM
);
694 aFont
.SetSize( aSize
);
695 aFont
.SetColor( COL_BLACK
);
696 pOutDev
->SetFont( aFont
);
698 String
aTitle( GetViewFrame()->GetWindow().GetText() );
700 sal_uInt16 nLineHeight
= (sal_uInt16
) pOutDev
->GetTextHeight(); // etwas mehr.
701 sal_uInt16 nParaSpace
= 10;
703 Size aPaperSz
= pOutDev
->GetOutputSize();
704 aPaperSz
.Width() -= (LMARGPRN
+ RMARGPRN
);
705 aPaperSz
.Height() -= (TMARGPRN
+ BMARGPRN
);
707 // nLinepPage stimmt nicht, wenn Zeilen umgebrochen werden muessen...
708 sal_uInt16 nLinespPage
= (sal_uInt16
) (aPaperSz
.Height() / nLineHeight
);
709 sal_uInt16 nCharspLine
= (sal_uInt16
) (aPaperSz
.Width() / pOutDev
->GetTextWidth(OUString('X')));
710 sal_uInt16 nParas
= static_cast< sal_uInt16
>( pTextEngine
->GetParagraphCount() );
712 sal_uInt16 nPages
= (sal_uInt16
) (nParas
/ nLinespPage
+ 1 );
713 sal_uInt16 nCurPage
= 1;
716 if (!bCalcNumPagesOnly
&& nPage
== nCurPage
)
717 lcl_PrintHeader( *pOutDev
, nPages
, nCurPage
, aTitle
);
718 const Point
aStartPos( LMARGPRN
, TMARGPRN
);
719 Point
aPos( aStartPos
);
720 for ( sal_uInt16 nPara
= 0; nPara
< nParas
; ++nPara
)
722 String
aLine( pTextEngine
->GetText( nPara
) );
723 lcl_ConvertTabsToSpaces( aLine
);
724 sal_uInt16 nLines
= aLine
.Len() / nCharspLine
+ 1;
725 for ( sal_uInt16 nLine
= 0; nLine
< nLines
; ++nLine
)
727 String
aTmpLine( aLine
, nLine
* nCharspLine
, nCharspLine
);
728 aPos
.Y() += nLineHeight
;
729 if ( aPos
.Y() > ( aPaperSz
.Height() + TMARGPRN
- nLineHeight
/2 ) )
732 if (!bCalcNumPagesOnly
&& nPage
== nCurPage
)
733 lcl_PrintHeader( *pOutDev
, nPages
, nCurPage
, aTitle
);
736 if (!bCalcNumPagesOnly
&& nPage
== nCurPage
)
737 pOutDev
->DrawText( aPos
, aTmpLine
);
739 aPos
.Y() += nParaSpace
;
744 OSL_ENSURE( bCalcNumPagesOnly
|| nPage
<= nCurPage
, "page number out of range" );
748 void SwSrcView::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
750 if ( rHint
.ISA(SfxSimpleHint
) &&
752 ((SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_MODECHANGED
||
754 ((SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_TITLECHANGED
&&
755 !GetDocShell()->IsReadOnly() && aEditWin
.IsReadonly()
760 // Broadcast kommt nur einmal!
761 const SwDocShell
* pDocSh
= GetDocShell();
762 const sal_Bool bReadonly
= pDocSh
->IsReadOnly();
763 aEditWin
.SetReadonly(bReadonly
);
765 SfxViewShell::Notify(rBC
, rHint
);
768 void SwSrcView::Load(SwDocShell
* pDocShell
)
770 SvxHtmlOptions
& rHtmlOptions
= SvxHtmlOptions::Get();
771 const sal_Char
*pCharSet
=
772 rtl_getBestMimeCharsetFromTextEncoding( rHtmlOptions
.GetTextEncoding() );
773 rtl_TextEncoding eDestEnc
= rtl_getTextEncodingFromMimeCharset( pCharSet
);
775 aEditWin
.SetReadonly(pDocShell
->IsReadOnly());
776 aEditWin
.SetTextEncoding(eDestEnc
);
777 SfxMedium
* pMedium
= pDocShell
->GetMedium();
779 const SfxFilter
* pFilter
= pMedium
->GetFilter();
780 bool bHtml
= pFilter
&& pFilter
->GetUserData() == "HTML";
781 sal_Bool bDocModified
= pDocShell
->IsModified();
782 if(bHtml
&& !bDocModified
&& pDocShell
->HasName())
784 SvStream
* pStream
= pMedium
->GetInStream();
785 if(pStream
&& 0 == pStream
->GetError() )
787 rtl_TextEncoding eHeaderEnc
=
788 SfxHTMLParser::GetEncodingByHttpHeader(
789 pDocShell
->GetHeaderAttributes() );
790 if( RTL_TEXTENCODING_DONTKNOW
== eHeaderEnc
)
792 const sal_Char
*pTmpCharSet
=
793 rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1
);
794 eHeaderEnc
= rtl_getTextEncodingFromMimeCharset( pTmpCharSet
);
796 if( RTL_TEXTENCODING_DONTKNOW
!= eHeaderEnc
&&
797 eDestEnc
!= eHeaderEnc
)
799 eDestEnc
= eHeaderEnc
;
800 aEditWin
.SetTextEncoding(eDestEnc
);
802 pStream
->SetStreamCharSet( eDestEnc
);
804 TextEngine
* pTextEngine
= aEditWin
.GetTextEngine();
805 pTextEngine
->EnableUndo(sal_False
);
806 aEditWin
.Read(*pStream
);
807 pTextEngine
->EnableUndo(sal_True
);
811 Window
*pTmpWindow
= &GetViewFrame()->GetWindow();
812 InfoBox(pTmpWindow
, SW_RES(MSG_ERR_SRCSTREAM
)).Execute();
817 utl::TempFile aTempFile
;
818 aTempFile
.EnableKillingFile();
819 String
sFileURL( aTempFile
.GetURL() );
823 SfxMedium
aMedium( sFileURL
,STREAM_READWRITE
);
824 SwWriter
aWriter( aMedium
, *pDocShell
->GetDoc() );
826 ::GetHTMLWriter(aEmptyStr
, aMedium
.GetBaseURL( true ), xWriter
);
828 if (pDocShell
->HasName())
829 sWriteName
= pMedium
->GetName();
831 sWriteName
= sFileURL
;
832 sal_uLong nRes
= aWriter
.Write(xWriter
, &sWriteName
);
835 ErrorHandler::HandleError(ErrCode(nRes
));
836 aEditWin
.SetReadonly(sal_True
);
839 SvStream
* pInStream
= aMedium
.GetInStream();
841 pInStream
->SetStreamCharSet( eDestEnc
);
844 aEditWin
.Read(*pInStream
);
847 aEditWin
.ClearModifyFlag();
849 eLoadEncoding
= eDestEnc
;
852 pDocShell
->SetModified();// das Flag wird zwischendurch zurueckgesetzt
853 // AutoLoad abschalten
854 pDocShell
->SetAutoLoad(INetURLObject(), 0, sal_False
);
855 OSL_ENSURE(PTR_CAST(SwWebDocShell
, pDocShell
), "Wieso keine WebDocShell?");
856 sal_uInt16 nLine
= ((SwWebDocShell
*)pDocShell
)->GetSourcePara();
857 aEditWin
.SetStartLine(nLine
);
858 aEditWin
.GetTextEngine()->ResetUndo();
859 aEditWin
.GetOutWin()->GrabFocus();
863 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */