1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: srcview.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <hintids.hxx>
35 #include <com/sun/star/util/SearchOptions.hpp>
36 #include <com/sun/star/util/SearchFlags.hpp>
37 #include <com/sun/star/i18n/TransliterationModules.hpp>
38 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
39 #include <unotools/tempfile.hxx>
40 #include <tools/urlobj.hxx>
41 #include <vcl/print.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <vcl/wrkwin.hxx>
44 #include <vcl/metric.hxx>
45 #include <svtools/ctrltool.hxx>
46 #include <svtools/intitem.hxx>
47 #include <svtools/stritem.hxx>
48 #include <svtools/pathoptions.hxx>
49 #include <svtools/undo.hxx>
50 #include <svtools/txtcmp.hxx>
51 #include <svtools/eitem.hxx>
52 #include <svtools/whiter.hxx>
53 #include <svtools/saveopt.hxx>
54 #include <svtools/transfer.hxx>
56 #include <svx/htmlcfg.hxx>
57 #include <sfx2/app.hxx>
58 #include <sfx2/objface.hxx>
59 #include <sfx2/viewfrm.hxx>
60 #include <sfx2/docfilt.hxx>
61 #include <sfx2/fcontnr.hxx>
62 #include <sfx2/request.hxx>
63 #include <sfx2/prnmon.hxx>
64 #include <sfx2/docfile.hxx>
65 #include <svx/fhgtitem.hxx>
66 #include <svx/srchdlg.hxx>
67 #include <svx/srchitem.hxx>
68 #include <svx/fontitem.hxx>
69 #include <svx/flstitem.hxx>
70 #include "svx/unolingu.hxx"
71 #include <sfx2/sfxhtml.hxx>
72 #include <swtypes.hxx>
73 #include <swmodule.hxx>
76 #include <srcview.hxx>
77 #include <viewfunc.hxx>
79 #include <sfx2/msg.hxx>
80 #include <shellio.hxx>
82 #include <cmdid.h> // FN_ ...
84 #include <globals.hrc>
89 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
90 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
91 #include <sfx2/filedlghelper.hxx>
93 #define SearchSettings
94 #define _ExecSearch Execute
95 #define _StateSearch GetState
96 #include <svx/svxslots.hxx>
97 #include "swslots.hxx"
101 #include <com/sun/star/document/XDocumentProperties.hpp>
102 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
104 using namespace ::com::sun::star
;
105 using namespace ::com::sun::star::i18n
;
106 using namespace ::com::sun::star::lang
;
107 using namespace ::com::sun::star::uno
;
108 using namespace ::com::sun::star::ui::dialogs
;
109 using namespace ::com::sun::star::i18n
;
110 using namespace ::com::sun::star::lang
;
111 using namespace ::sfx2
;
112 using ::rtl::OUString
;
113 using ::com::sun::star::util::SearchOptions
;
116 #define SWSRCVIEWFLAGS ( SFX_VIEW_MAXIMIZE_FIRST| \
117 SFX_VIEW_OBJECTSIZE_EMBEDDED| \
119 SFX_VIEW_NO_NEWWINDOW )
121 #define SRC_SEARCHOPTIONS (0xFFFF & ~(SEARCH_OPTIONS_FORMAT|SEARCH_OPTIONS_FAMILIES|SEARCH_OPTIONS_SEARCH_ALL))
123 // Druckraender -> wie Basic - Ide
124 #define LMARGPRN 1700
126 #define TMARGPRN 2000
127 #define BMARGPRN 1000
128 #define BORDERPRN 300
132 SFX_IMPL_VIEWFACTORY(SwSrcView
, SW_RES(STR_NONAME
))
134 SFX_VIEW_REGISTRATION(SwWebDocShell
);
138 SFX_IMPL_INTERFACE( SwSrcView
, SfxViewShell
, SW_RES(0) )
140 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_SRCVIEW_POPUPMENU
));
141 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS
|
142 SFX_VISIBILITY_STANDARD
|SFX_VISIBILITY_SERVER
,
143 SW_RES(RID_WEBTOOLS_TOOLBOX
) );
144 SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
147 TYPEINIT1(SwSrcView
, SfxViewShell
)
149 /*-----------------18.11.96 08.05-------------------
151 --------------------------------------------------*/
154 void lcl_PrintHeader( Printer
* pPrinter
, USHORT nPages
, USHORT nCurPage
, const String
& rTitle
)
156 short nLeftMargin
= LMARGPRN
;
157 Size aSz
= pPrinter
->GetOutputSize();
158 short nBorder
= BORDERPRN
;
160 Color
aOldFillColor( pPrinter
->GetFillColor() );
161 Font
aOldFont( pPrinter
->GetFont() );
163 pPrinter
->SetFillColor( Color(COL_TRANSPARENT
) );
165 Font
aFont( aOldFont
);
166 aFont
.SetWeight( WEIGHT_BOLD
);
167 aFont
.SetAlign( ALIGN_BOTTOM
);
168 pPrinter
->SetFont( aFont
);
170 long nFontHeight
= pPrinter
->GetTextHeight();
172 // 1.Border => Strich, 2+3 Border = Freiraum.
173 long nYTop
= TMARGPRN
-3*nBorder
-nFontHeight
;
175 long nXLeft
= nLeftMargin
-nBorder
;
176 long nXRight
= aSz
.Width()-RMARGPRN
+nBorder
;
178 pPrinter
->DrawRect( Rectangle(
179 Point( nXLeft
, nYTop
),
180 Size( nXRight
-nXLeft
, aSz
.Height() - nYTop
- BMARGPRN
+ nBorder
) ) );
183 long nY
= TMARGPRN
-2*nBorder
;
184 Point
aPos( nLeftMargin
, nY
);
185 pPrinter
->DrawText( aPos
, rTitle
);
188 aFont
.SetWeight( WEIGHT_NORMAL
);
189 pPrinter
->SetFont( aFont
);
190 String
aPageStr( C2S(" [") );
191 aPageStr
+= String( SW_RES( STR_PAGE
) );
193 aPageStr
+= String::CreateFromInt32( nCurPage
);
195 aPos
.X() += pPrinter
->GetTextWidth( rTitle
);
196 pPrinter
->DrawText( aPos
, aPageStr
);
200 nY
= TMARGPRN
-nBorder
;
202 pPrinter
->DrawLine( Point( nXLeft
, nY
), Point( nXRight
, nY
) );
204 pPrinter
->SetFont( aOldFont
);
205 pPrinter
->SetFillColor( aOldFillColor
);
207 /* -----------------13.11.2003 16:24-----------------
209 --------------------------------------------------*/
210 rtl_TextEncoding
lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding
)
212 rtl_TextEncoding eRet
= eLoadEncoding
;
213 if(RTL_TEXTENCODING_DONTKNOW
== eRet
)
215 SvxHtmlOptions
* pHtmlOptions
= SvxHtmlOptions::Get();
216 const sal_Char
*pCharSet
=
217 rtl_getBestMimeCharsetFromTextEncoding( pHtmlOptions
->GetTextEncoding() );
218 eRet
= rtl_getTextEncodingFromMimeCharset( pCharSet
);
222 /*-----------------18.11.96 08.21-------------------
224 --------------------------------------------------*/
226 void lcl_ConvertTabsToSpaces( String
& rLine
)
231 USHORT nMax
= rLine
.Len();
232 while ( nPos
< nMax
)
234 if ( rLine
.GetChar(nPos
) == '\t' )
236 // Nicht 4 Blanks, sondern an 4er TabPos:
238 aBlanker
.Fill( ( 4 - ( nPos
% 4 ) ), ' ' );
239 rLine
.Erase( nPos
, 1 );
240 rLine
.Insert( aBlanker
, nPos
);
243 nPos
++; // Nicht optimal, falls Tab, aber auch nicht verkehrt...
248 /*--------------------------------------------------------------------
250 --------------------------------------------------------------------*/
253 SwSrcView::SwSrcView(SfxViewFrame
* pViewFrame
, SfxViewShell
*) :
254 SfxViewShell( pViewFrame
, SWSRCVIEWFLAGS
),
255 aEditWin( &pViewFrame
->GetWindow(), this ),
258 eLoadEncoding(RTL_TEXTENCODING_DONTKNOW
)
263 /*--------------------------------------------------------------------
265 --------------------------------------------------------------------*/
268 SwSrcView::~SwSrcView()
270 SwDocShell
* pDocShell
= GetDocShell();
271 DBG_ASSERT(PTR_CAST(SwWebDocShell
, pDocShell
), "Wieso keine WebDocShell?");
272 const TextSelection
& rSel
= aEditWin
.GetTextView()->GetSelection();
273 ((SwWebDocShell
*)pDocShell
)->SetSourcePara( static_cast< USHORT
>( rSel
.GetStart().GetPara() ) );
275 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
276 pDocShell
->GetModel(), uno::UNO_QUERY_THROW
);
277 uno::Reference
<document::XDocumentProperties
> xDocProps
278 = xDPS
->getDocumentProperties();
279 ::rtl::OUString url
= xDocProps
->getAutoloadURL();
280 sal_Int32 delay
= xDocProps
->getAutoloadSecs();
281 pDocShell
->SetAutoLoad(INetURLObject(url
), delay
,
282 (delay
!= 0) || !url
.equalsAscii(""));
283 // EndListening(*GetViewFrame());
284 EndListening(*pDocShell
);
288 /*-----------------24.04.97 10:37-------------------
290 --------------------------------------------------*/
291 void SwSrcView::SaveContentTo(SfxMedium
& rMed
)
293 SvStream
* pOutStream
= rMed
.GetOutStream();
294 pOutStream
->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding
));
295 aEditWin
.Write( *pOutStream
);//, EE_FORMAT_TEXT);
298 /*--------------------------------------------------------------------
300 --------------------------------------------------------------------*/
303 void SwSrcView::Init()
305 SetHelpId(SW_SRC_VIEWSHELL
);
306 SetName(C2S("Source"));
307 SetWindow( &aEditWin
);
308 SwDocShell
* pDocShell
= GetDocShell();
309 // wird das Doc noch geladen, dann muss die DocShell das Load
310 // anwerfen, wenn das Laden abgeschlossen ist
311 if(!pDocShell
->IsLoading())
315 aEditWin
.SetReadonly(TRUE
);
318 // StartListening(*GetViewFrame());
319 StartListening(*pDocShell
,TRUE
);
322 /*--------------------------------------------------------------------
324 --------------------------------------------------------------------*/
326 SwDocShell
* SwSrcView::GetDocShell()
328 SfxObjectShell
* pObjShell
= GetViewFrame()->GetObjectShell();
329 return PTR_CAST(SwDocShell
, pObjShell
);
332 /*--------------------------------------------------------------------
334 --------------------------------------------------------------------*/
337 void SwSrcView::SaveContent(const String
& rTmpFile
)
339 SfxMedium
aMedium( rTmpFile
, STREAM_WRITE
, TRUE
);
340 SvStream
* pOutStream
= aMedium
.GetOutStream();
341 pOutStream
->SetStreamCharSet( lcl_GetStreamCharSet(eLoadEncoding
) );
342 aEditWin
.Write(*pOutStream
);//, EE_FORMAT_TEXT);
346 /*--------------------------------------------------------------------
348 --------------------------------------------------------------------*/
351 void SwSrcView::Execute(SfxRequest
& rReq
)
353 USHORT nSlot
= rReq
.GetSlot();
354 TextView
* pTextView
= aEditWin
.GetTextView();
359 SvtPathOptions aPathOpt
;
360 // filesave dialog with autoextension
361 FileDialogHelper
aDlgHelper(
362 TemplateDescription::FILESAVE_AUTOEXTENSION
,
363 TemplateDescription::FILESAVE_SIMPLE
);
364 uno::Reference
< XFilePicker
> xFP
= aDlgHelper
.GetFilePicker();
365 // pFileDlg->SetHelpId(HID_FILEDLG_SRCVIEW);
366 uno::Reference
<XFilterManager
> xFltMgr(xFP
, UNO_QUERY
);
368 // search for an html filter for export
369 SfxFilterContainer
* pFilterCont
= GetObjectShell()->GetFactory().GetFilterContainer();
370 const SfxFilter
* pFilter
=
371 pFilterCont
->GetFilter4Extension( C2S("html"), SFX_FILTER_EXPORT
);
374 // filter found -> use its uiname and wildcard
375 const String
& rUIName
= pFilter
->GetUIName();
376 const WildCard
& rCard
= pFilter
->GetWildcard();
377 xFltMgr
->appendFilter( rUIName
, rCard() );
378 xFltMgr
->setCurrentFilter( rUIName
) ;
383 String
sHtml(C2S("HTML"));
384 xFltMgr
->appendFilter( sHtml
, C2S("*.html;*.htm") );
385 xFltMgr
->setCurrentFilter( sHtml
) ;
388 xFP
->setDisplayDirectory( aPathOpt
.GetWorkPath() );
389 if( aDlgHelper
.Execute() == ERRCODE_NONE
)
391 SfxMedium
aMedium( xFP
->getFiles().getConstArray()[0],
392 STREAM_WRITE
| STREAM_SHARE_DENYNONE
,
394 SvStream
* pOutStream
= aMedium
.GetOutStream();
395 pOutStream
->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding
));
396 aEditWin
.Write( *pOutStream
);
403 SwDocShell
* pDocShell
= GetDocShell();
405 if(pDocShell
->HasName())
406 pMed
= pDocShell
->GetMedium();
409 SfxBoolItem
* pItem
= (SfxBoolItem
*)pDocShell
->ExecuteSlot(rReq
, pDocShell
->GetInterface());
410 if(pItem
&& pItem
->GetValue())
411 pMed
= pDocShell
->GetMedium();
415 SvStream
* pOutStream
= pMed
->GetOutStream();
417 pOutStream
->SetStreamSize(0);
418 pOutStream
->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding
));
419 aEditWin
.Write( *pOutStream
);
420 pMed
->CloseOutStream();
422 pDocShell
->GetDoc()->ResetModified();
424 aEditWin
.ClearModifyFlag();
430 const SfxItemSet
* pTmpArgs
= rReq
.GetArgs();
432 USHORT nWhich
= pTmpArgs
->GetWhichByPos( 0 );
433 DBG_ASSERT( nWhich
, "Wich fuer SearchItem ?" );
434 const SfxPoolItem
& rItem
= pTmpArgs
->Get( nWhich
);
435 SetSearchItem( (const SvxSearchItem
&)rItem
);
436 StartSearchAndReplace( (const SvxSearchItem
&)rItem
, FALSE
, rReq
.IsAPI() );
437 if(aEditWin
.IsModified())
438 GetDocShell()->GetDoc()->SetModified();
441 case FN_REPEAT_SEARCH
:
443 SvxSearchItem
* pSrchItem
= GetSearchItem();
446 StartSearchAndReplace( *pSrchItem
, FALSE
, rReq
.IsAPI() );
447 if(aEditWin
.IsModified())
448 GetDocShell()->GetDoc()->SetModified();
453 case SID_PRINTDOCDIRECT
:
455 SfxViewShell::ExecuteSlot( rReq
, SfxViewShell::GetInterface() );
476 pTextView
->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
479 aEditWin
.Invalidate();
482 /*--------------------------------------------------------------------
484 --------------------------------------------------------------------*/
487 void SwSrcView::GetState(SfxItemSet
& rSet
)
489 SfxWhichIter
aIter(rSet
);
490 USHORT nWhich
= aIter
.FirstWhich();
491 TextView
* pTextView
= aEditWin
.GetTextView();
498 rSet
.Put(SfxStringItem(nWhich
, String(SW_RES(STR_SAVEAS_SRC
))));
502 SwDocShell
* pDocShell
= GetDocShell();
503 if(!pDocShell
->IsModified())
504 rSet
.DisableItem(nWhich
);
508 case SID_PRINTDOCDIRECT
:
512 String
aPos( SW_RES(STR_SRCVIEW_ROW
) );
513 TextSelection aSel
= pTextView
->GetSelection();
514 aPos
+= String::CreateFromInt32( aSel
.GetEnd().GetPara()+1 );
516 aPos
+= String(SW_RES(STR_SRCVIEW_COL
));
517 aPos
+= String::CreateFromInt32( aSel
.GetEnd().GetIndex()+1 );
518 SfxStringItem
aItem( nWhich
, aPos
);
522 case SID_SEARCH_OPTIONS
:
524 USHORT nOpt
= SRC_SEARCHOPTIONS
;
525 if(GetDocShell()->IsReadOnly())
526 nOpt
&= ~(SEARCH_OPTIONS_REPLACE
|SEARCH_OPTIONS_REPLACE_ALL
);
528 rSet
.Put( SfxUInt16Item( SID_SEARCH_OPTIONS
, nOpt
) );
531 case SID_SEARCH_ITEM
:
534 if ( !pTextView
->HasSelection() )
536 const TextSelection
& rSel
= pTextView
->GetSelection();
537 sSelected
= aEditWin
.GetTextEngine()->GetWord( rSel
.GetStart());
541 sSelected
= pTextView
->GetSelected();
543 SvxSearchItem
* pSrchItem
= GetSearchItem();
544 pSrchItem
->SetSearchString( sSelected
);
545 rSet
.Put( *pSrchItem
);
548 case FN_REPEAT_SEARCH
:
551 rSet
.DisableItem(nWhich
);
557 SfxUndoManager
& rMgr
= pTextView
->GetTextEngine()->GetUndoManager();
559 if(nWhich
== SID_UNDO
)
561 nCount
= rMgr
.GetUndoActionCount();
564 String
aStr(ResId( STR_UNDO
, *SFX_APP()->GetSfxResManager() ));;
565 aStr
+= rMgr
.GetUndoActionComment(--nCount
);
566 rSet
.Put(SfxStringItem(nWhich
, aStr
));
569 rSet
.DisableItem(nWhich
);
573 nCount
= rMgr
.GetRedoActionCount();
576 String
aStr(ResId( STR_REDO
, *SFX_APP()->GetSfxResManager() ));;
577 aStr
+= rMgr
.GetRedoActionComment(--nCount
);
578 rSet
.Put(SfxStringItem(nWhich
,aStr
));
581 rSet
.DisableItem(nWhich
);
585 case SID_MAIL_SENDDOCASPDF
:
586 case SID_MAIL_SENDDOC
:
587 case SID_EXPORTDOCASPDF
:
588 case SID_DIRECTEXPORTDOCASPDF
:
591 rSet
.DisableItem(nWhich
);
595 if(!pTextView
->HasSelection())
596 rSet
.DisableItem(nWhich
);
600 BOOL bDisable
= 0 == SW_MOD()->pClipboard
;
603 TransferableDataHelper
aDataHelper(
604 TransferableDataHelper::CreateFromSystemClipboard(
606 bDisable
= !aDataHelper
.GetXTransferable().is() ||
607 0 == aDataHelper
.GetFormatCount();
610 rSet
.DisableItem(nWhich
);
614 nWhich
= aIter
.NextWhich();
618 /*--------------------------------------------------------------------
620 --------------------------------------------------------------------*/
623 SvxSearchItem
* SwSrcView::GetSearchItem()
627 pSearchItem
= new SvxSearchItem(SID_SEARCH_ITEM
);
632 /*--------------------------------------------------------------------
634 --------------------------------------------------------------------*/
637 void SwSrcView::SetSearchItem( const SvxSearchItem
& rItem
)
640 pSearchItem
= (SvxSearchItem
*)rItem
.Clone();
643 /*--------------------------------------------------------------------
645 --------------------------------------------------------------------*/
648 USHORT
SwSrcView::StartSearchAndReplace(const SvxSearchItem
& rSearchItem
,
653 ExtTextView
* pTextView
= aEditWin
.GetTextView();
657 BOOL bForward
= !rSearchItem
.GetBackward();
658 BOOL bAtStart
= pTextView
->GetSelection() == TextSelection( aPaM
, aPaM
);
661 aPaM
= TextPaM( (ULONG
)-1, (USHORT
)-1 );
665 aSel
= pTextView
->GetSelection();
666 pTextView
->SetSelection( TextSelection( aPaM
, aPaM
));
669 util::SearchOptions
aSearchOpt( rSearchItem
.GetSearchOptions() );
670 aSearchOpt
.Locale
= SvxCreateLocale(
671 static_cast< LanguageType
>( GetAppLanguage() ) );
675 switch( rSearchItem
.GetCommand() )
677 case SVX_SEARCHCMD_FIND
:
678 case SVX_SEARCHCMD_FIND_ALL
:
679 nFound
= pTextView
->Search( aSearchOpt
, bForward
);
682 case SVX_SEARCHCMD_REPLACE_ALL
: bAll
= TRUE
;
683 case SVX_SEARCHCMD_REPLACE
:
684 nFound
= pTextView
->Replace( aSearchOpt
, bAll
, bForward
);
693 BOOL bNotFoundMessage
= FALSE
;
698 bNotFoundMessage
= bAtStart
;
702 bNotFoundMessage
= TRUE
;
703 pTextView
->SetSelection( aSel
);
708 bNotFoundMessage
= TRUE
;
715 InfoBox( 0, SW_RES(MSG_NOT_FOUND
)).Execute();
717 else if(!bRecursive
&& RET_YES
==
718 QueryBox(0, SW_RES( bForward
? MSG_SEARCH_END
719 : MSG_SEARCH_START
)).Execute())
721 pTextView
->SetSelection( TextSelection( aPaM
, aPaM
) );
722 StartSearchAndReplace( rSearchItem
, FALSE
, FALSE
, TRUE
);
728 /*-----------------02.07.97 09:29-------------------
730 --------------------------------------------------*/
731 USHORT
SwSrcView::SetPrinter(SfxPrinter
* pNew
, USHORT nDiffFlags
, bool )
733 SwDocShell
* pDocSh
= GetDocShell();
734 if ( (SFX_PRINTER_JOBSETUP
| SFX_PRINTER_PRINTER
) & nDiffFlags
)
736 pDocSh
->GetDoc()->setPrinter( pNew
, true, true );
737 if ( nDiffFlags
& SFX_PRINTER_PRINTER
)
738 pDocSh
->SetModified();
740 if ( nDiffFlags
& SFX_PRINTER_OPTIONS
)
741 ::SetPrinter( pDocSh
->getIDocumentDeviceAccess(), pNew
, TRUE
);
743 const BOOL bChgOri
= nDiffFlags
& SFX_PRINTER_CHG_ORIENTATION
? TRUE
: FALSE
;
744 const BOOL bChgSize
= nDiffFlags
& SFX_PRINTER_CHG_SIZE
? TRUE
: FALSE
;
745 if ( bChgOri
|| bChgSize
)
747 pDocSh
->SetModified();
752 /*--------------------------------------------------------------------
754 --------------------------------------------------------------------*/
756 ErrCode
SwSrcView::DoPrint( SfxPrinter
*pPrinter
, PrintDialog
*pDlg
, BOOL bSilent
, BOOL bIsAPI
)
758 SfxPrintProgress
*pProgress
= new SfxPrintProgress( this, !bSilent
);
759 SfxPrinter
*pDocPrinter
= GetPrinter(TRUE
);
761 pPrinter
= pDocPrinter
;
762 else if ( pDocPrinter
!= pPrinter
)
764 pProgress
->RestoreOnEndPrint( pDocPrinter
->Clone() );
765 SetPrinter( pPrinter
, SFX_PRINTER_PRINTER
);
767 pProgress
->SetWaitMode(FALSE
);
770 PreparePrint( pDlg
);
772 SfxViewShell::Print(*pProgress
, bIsAPI
, pDlg
); //???
774 MapMode
eOldMapMode( pPrinter
->GetMapMode() );
775 Font
aOldFont( pPrinter
->Printer::GetFont() );
777 TextEngine
* pTextEngine
= aEditWin
.GetTextEngine();
778 pPrinter
->SetMapMode(MAP_100TH_MM
);
779 Font
aFont(aEditWin
.GetOutWin()->GetFont());
780 Size
aSize(aFont
.GetSize());
781 aSize
= aEditWin
.GetOutWin()->PixelToLogic(aSize
, MAP_100TH_MM
);
782 aFont
.SetSize(aSize
);
783 aFont
.SetColor(COL_BLACK
);
784 pPrinter
->SetFont( aFont
);
786 String
aTitle( GetViewFrame()->GetWindow().GetText() );
788 USHORT nLineHeight
= (USHORT
) pPrinter
->GetTextHeight(); // etwas mehr.
789 USHORT nParaSpace
= 10;
791 Size aPaperSz
= pPrinter
->GetOutputSize();
792 aPaperSz
.Width() -= (LMARGPRN
+RMARGPRN
);
793 aPaperSz
.Height() -= (TMARGPRN
+BMARGPRN
);
795 // nLinepPage stimmt nicht, wenn Zeilen umgebrochen werden muessen...
796 USHORT nLinespPage
= (USHORT
) (aPaperSz
.Height()/nLineHeight
);
797 USHORT nCharspLine
= (USHORT
) (aPaperSz
.Width() / pPrinter
->GetTextWidth( 'X' ));
798 USHORT nParas
= static_cast< USHORT
>( pTextEngine
->GetParagraphCount() );
800 USHORT nPages
= (USHORT
) (nParas
/nLinespPage
+1 );
803 BOOL bStartJob
= pPrinter
->StartJob( aTitle
);
806 pPrinter
->StartPage();
808 lcl_PrintHeader( pPrinter
, nPages
, nCurPage
, aTitle
);
809 Point
aPos( LMARGPRN
, TMARGPRN
);
810 for ( USHORT nPara
= 0; nPara
< nParas
; nPara
++ )
812 String
aLine( pTextEngine
->GetText( nPara
) );
813 lcl_ConvertTabsToSpaces( aLine
);
814 USHORT nLines
= aLine
.Len()/nCharspLine
+1;
815 for ( USHORT nLine
= 0; nLine
< nLines
; nLine
++ )
817 String
aTmpLine( aLine
, nLine
*nCharspLine
, nCharspLine
);
818 aPos
.Y() += nLineHeight
;
819 if ( aPos
.Y() > ( aPaperSz
.Height()+TMARGPRN
) )
823 pPrinter
->StartPage();
824 lcl_PrintHeader( pPrinter
, nPages
, nCurPage
, aTitle
);
825 aPos
= Point( LMARGPRN
, TMARGPRN
+nLineHeight
);
827 pPrinter
->DrawText( aPos
, aTmpLine
);
829 aPos
.Y() += nParaSpace
;
834 pPrinter
->SetFont( aOldFont
);
835 pPrinter
->SetMapMode( eOldMapMode
);
839 // Printer konnte nicht gestartet werden
841 return ERRCODE_IO_ABORT
;
845 pProgress
->DeleteOnEndPrint();
847 return pPrinter
->GetError();
850 /*--------------------------------------------------------------------
852 --------------------------------------------------------------------*/
855 SfxPrinter
* SwSrcView::GetPrinter( BOOL bCreate
)
857 return GetDocShell()->GetDoc()->getPrinter( bCreate
);
860 /*--------------------------------------------------------------------
862 --------------------------------------------------------------------*/
865 void SwSrcView::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
867 if ( rHint
.ISA(SfxSimpleHint
) &&
869 ((SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_MODECHANGED
||
871 ((SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_TITLECHANGED
&&
872 !GetDocShell()->IsReadOnly() && aEditWin
.IsReadonly()
877 // Broadcast kommt nur einmal!
878 const SwDocShell
* pDocSh
= GetDocShell();
879 const BOOL bReadonly
= pDocSh
->IsReadOnly();
880 aEditWin
.SetReadonly(bReadonly
);
882 SfxViewShell::Notify(rBC
, rHint
);
885 /*-----------------19.04.97 10:19-------------------
887 --------------------------------------------------*/
888 void SwSrcView::Load(SwDocShell
* pDocShell
)
890 SvxHtmlOptions
* pHtmlOptions
= SvxHtmlOptions::Get();
891 const sal_Char
*pCharSet
=
892 rtl_getBestMimeCharsetFromTextEncoding( pHtmlOptions
->GetTextEncoding() );
893 rtl_TextEncoding eDestEnc
= rtl_getTextEncodingFromMimeCharset( pCharSet
);
895 aEditWin
.SetReadonly(pDocShell
->IsReadOnly());
896 aEditWin
.SetTextEncoding(eDestEnc
);
897 SfxMedium
* pMedium
= pDocShell
->GetMedium();
899 const SfxFilter
* pFilter
= pMedium
->GetFilter();
900 BOOL bHtml
= pFilter
&& pFilter
->GetUserData().EqualsAscii("HTML");
901 BOOL bDocModified
= pDocShell
->IsModified();
902 if(bHtml
&& !bDocModified
&& pDocShell
->HasName())
904 SvStream
* pStream
= pMedium
->GetInStream();
905 if(pStream
&& 0 == pStream
->GetError() )
907 rtl_TextEncoding eHeaderEnc
=
908 SfxHTMLParser::GetEncodingByHttpHeader(
909 pDocShell
->GetHeaderAttributes() );
910 if( RTL_TEXTENCODING_DONTKNOW
== eHeaderEnc
)
912 const sal_Char
*pTmpCharSet
=
913 rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1
);
914 eHeaderEnc
= rtl_getTextEncodingFromMimeCharset( pTmpCharSet
);
916 if( RTL_TEXTENCODING_DONTKNOW
!= eHeaderEnc
&&
917 eDestEnc
!= eHeaderEnc
)
919 eDestEnc
= eHeaderEnc
;
920 aEditWin
.SetTextEncoding(eDestEnc
);
922 pStream
->SetStreamCharSet( eDestEnc
);
924 TextEngine
* pTextEngine
= aEditWin
.GetTextEngine();
925 pTextEngine
->EnableUndo(FALSE
);
926 aEditWin
.Read(*pStream
);//, EE_FORMAT_TEXT);
927 pTextEngine
->EnableUndo(TRUE
);
931 Window
*pTmpWindow
= &GetViewFrame()->GetWindow();
932 InfoBox(pTmpWindow
, SW_RES(MSG_ERR_SRCSTREAM
)).Execute();
937 utl::TempFile aTempFile
;
938 aTempFile
.EnableKillingFile();
939 String
sFileURL( aTempFile
.GetURL() );
943 SfxMedium
aMedium( sFileURL
,STREAM_READWRITE
, TRUE
);
944 SwWriter
aWriter( aMedium
, *pDocShell
->GetDoc() );
946 ::GetHTMLWriter(aEmptyStr
, aMedium
.GetBaseURL( true ), xWriter
);
947 String sWriteName
= pDocShell
->HasName() ?
949 (const String
&) sFileURL
;
950 ULONG nRes
= aWriter
.Write(xWriter
, &sWriteName
);
953 ErrorHandler::HandleError(ErrCode(nRes
));
954 aEditWin
.SetReadonly(TRUE
);
957 SvStream
* pInStream
= aMedium
.GetInStream();
959 pInStream
->SetStreamCharSet( eDestEnc
);
962 aEditWin
.Read(*pInStream
);//, EE_FORMAT_TEXT);
965 aEditWin
.ClearModifyFlag();
967 eLoadEncoding
= eDestEnc
;
970 pDocShell
->SetModified();// das Flag wird zwischendurch zurueckgesetzt
971 // AutoLoad abschalten
972 pDocShell
->SetAutoLoad(INetURLObject(), 0, FALSE
);
973 DBG_ASSERT(PTR_CAST(SwWebDocShell
, pDocShell
), "Wieso keine WebDocShell?");
974 USHORT nLine
= ((SwWebDocShell
*)pDocShell
)->GetSourcePara();
975 aEditWin
.SetStartLine(nLine
);
976 aEditWin
.GetTextEngine()->ResetUndo();
977 aEditWin
.GetOutWin()->GrabFocus();