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/bindings.hxx>
61 #include <sfx2/docfilt.hxx>
62 #include <sfx2/fcontnr.hxx>
63 #include <sfx2/request.hxx>
64 #include <sfx2/prnmon.hxx>
65 #include <sfx2/docfile.hxx>
66 #include <svx/fhgtitem.hxx>
67 #include <svx/srchdlg.hxx>
68 #include <svx/srchitem.hxx>
69 #include <svx/fontitem.hxx>
70 #include <svx/flstitem.hxx>
71 #include "svx/unolingu.hxx"
72 #include <sfx2/sfxhtml.hxx>
73 #include <swtypes.hxx>
74 #include <swmodule.hxx>
77 #include <srcview.hxx>
78 #include <viewfunc.hxx>
80 #include <sfx2/msg.hxx>
81 #include <shellio.hxx>
83 #include <cmdid.h> // FN_ ...
85 #include <globals.hrc>
90 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
91 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
92 #include <sfx2/filedlghelper.hxx>
94 #define SearchSettings
95 #define _ExecSearch Execute
96 #define _StateSearch GetState
97 #include <svx/svxslots.hxx>
98 #include "swslots.hxx"
102 #include <com/sun/star/document/XDocumentProperties.hpp>
103 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
105 using namespace ::com::sun::star
;
106 using namespace ::com::sun::star::i18n
;
107 using namespace ::com::sun::star::lang
;
108 using namespace ::com::sun::star::uno
;
109 using namespace ::com::sun::star::ui::dialogs
;
110 using namespace ::com::sun::star::i18n
;
111 using namespace ::com::sun::star::lang
;
112 using namespace ::sfx2
;
113 using ::rtl::OUString
;
114 using ::com::sun::star::util::SearchOptions
;
117 #define SWSRCVIEWFLAGS ( SFX_VIEW_MAXIMIZE_FIRST| \
118 SFX_VIEW_OBJECTSIZE_EMBEDDED| \
120 SFX_VIEW_NO_NEWWINDOW )
122 #define SRC_SEARCHOPTIONS (0xFFFF & ~(SEARCH_OPTIONS_FORMAT|SEARCH_OPTIONS_FAMILIES|SEARCH_OPTIONS_SEARCH_ALL))
124 // Druckraender -> wie Basic - Ide
125 #define LMARGPRN 1700
127 #define TMARGPRN 2000
128 #define BMARGPRN 1000
129 #define BORDERPRN 300
133 SFX_IMPL_VIEWFACTORY(SwSrcView
, SW_RES(STR_NONAME
))
135 SFX_VIEW_REGISTRATION(SwWebDocShell
);
139 SFX_IMPL_INTERFACE( SwSrcView
, SfxViewShell
, SW_RES(0) )
141 SFX_POPUPMENU_REGISTRATION(SW_RES(MN_SRCVIEW_POPUPMENU
));
142 SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS
|
143 SFX_VISIBILITY_STANDARD
|SFX_VISIBILITY_SERVER
,
144 SW_RES(RID_WEBTOOLS_TOOLBOX
) );
145 SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
148 TYPEINIT1(SwSrcView
, SfxViewShell
)
150 /*-----------------18.11.96 08.05-------------------
152 --------------------------------------------------*/
155 void lcl_PrintHeader( Printer
* pPrinter
, USHORT nPages
, USHORT nCurPage
, const String
& rTitle
)
157 short nLeftMargin
= LMARGPRN
;
158 Size aSz
= pPrinter
->GetOutputSize();
159 short nBorder
= BORDERPRN
;
161 Color
aOldFillColor( pPrinter
->GetFillColor() );
162 Font
aOldFont( pPrinter
->GetFont() );
164 pPrinter
->SetFillColor( Color(COL_TRANSPARENT
) );
166 Font
aFont( aOldFont
);
167 aFont
.SetWeight( WEIGHT_BOLD
);
168 aFont
.SetAlign( ALIGN_BOTTOM
);
169 pPrinter
->SetFont( aFont
);
171 long nFontHeight
= pPrinter
->GetTextHeight();
173 // 1.Border => Strich, 2+3 Border = Freiraum.
174 long nYTop
= TMARGPRN
-3*nBorder
-nFontHeight
;
176 long nXLeft
= nLeftMargin
-nBorder
;
177 long nXRight
= aSz
.Width()-RMARGPRN
+nBorder
;
179 pPrinter
->DrawRect( Rectangle(
180 Point( nXLeft
, nYTop
),
181 Size( nXRight
-nXLeft
, aSz
.Height() - nYTop
- BMARGPRN
+ nBorder
) ) );
184 long nY
= TMARGPRN
-2*nBorder
;
185 Point
aPos( nLeftMargin
, nY
);
186 pPrinter
->DrawText( aPos
, rTitle
);
189 aFont
.SetWeight( WEIGHT_NORMAL
);
190 pPrinter
->SetFont( aFont
);
191 String
aPageStr( C2S(" [") );
192 aPageStr
+= String( SW_RES( STR_PAGE
) );
194 aPageStr
+= String::CreateFromInt32( nCurPage
);
196 aPos
.X() += pPrinter
->GetTextWidth( rTitle
);
197 pPrinter
->DrawText( aPos
, aPageStr
);
201 nY
= TMARGPRN
-nBorder
;
203 pPrinter
->DrawLine( Point( nXLeft
, nY
), Point( nXRight
, nY
) );
205 pPrinter
->SetFont( aOldFont
);
206 pPrinter
->SetFillColor( aOldFillColor
);
208 /* -----------------13.11.2003 16:24-----------------
210 --------------------------------------------------*/
211 rtl_TextEncoding
lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding
)
213 rtl_TextEncoding eRet
= eLoadEncoding
;
214 if(RTL_TEXTENCODING_DONTKNOW
== eRet
)
216 SvxHtmlOptions
* pHtmlOptions
= SvxHtmlOptions::Get();
217 const sal_Char
*pCharSet
=
218 rtl_getBestMimeCharsetFromTextEncoding( pHtmlOptions
->GetTextEncoding() );
219 eRet
= rtl_getTextEncodingFromMimeCharset( pCharSet
);
223 /*-----------------18.11.96 08.21-------------------
225 --------------------------------------------------*/
227 void lcl_ConvertTabsToSpaces( String
& rLine
)
232 USHORT nMax
= rLine
.Len();
233 while ( nPos
< nMax
)
235 if ( rLine
.GetChar(nPos
) == '\t' )
237 // Nicht 4 Blanks, sondern an 4er TabPos:
239 aBlanker
.Fill( ( 4 - ( nPos
% 4 ) ), ' ' );
240 rLine
.Erase( nPos
, 1 );
241 rLine
.Insert( aBlanker
, nPos
);
244 nPos
++; // Nicht optimal, falls Tab, aber auch nicht verkehrt...
249 /*--------------------------------------------------------------------
251 --------------------------------------------------------------------*/
254 SwSrcView::SwSrcView(SfxViewFrame
* pViewFrame
, SfxViewShell
*) :
255 SfxViewShell( pViewFrame
, SWSRCVIEWFLAGS
),
256 aEditWin( &pViewFrame
->GetWindow(), this ),
259 eLoadEncoding(RTL_TEXTENCODING_DONTKNOW
)
264 /*--------------------------------------------------------------------
266 --------------------------------------------------------------------*/
269 SwSrcView::~SwSrcView()
271 SwDocShell
* pDocShell
= GetDocShell();
272 DBG_ASSERT(PTR_CAST(SwWebDocShell
, pDocShell
), "Wieso keine WebDocShell?");
273 const TextSelection
& rSel
= aEditWin
.GetTextView()->GetSelection();
274 ((SwWebDocShell
*)pDocShell
)->SetSourcePara( static_cast< USHORT
>( rSel
.GetStart().GetPara() ) );
276 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
277 pDocShell
->GetModel(), uno::UNO_QUERY_THROW
);
278 uno::Reference
<document::XDocumentProperties
> xDocProps
279 = xDPS
->getDocumentProperties();
280 ::rtl::OUString url
= xDocProps
->getAutoloadURL();
281 sal_Int32 delay
= xDocProps
->getAutoloadSecs();
282 pDocShell
->SetAutoLoad(INetURLObject(url
), delay
,
283 (delay
!= 0) || !url
.equalsAscii(""));
284 // EndListening(*GetViewFrame());
285 EndListening(*pDocShell
);
289 /*-----------------24.04.97 10:37-------------------
291 --------------------------------------------------*/
292 void SwSrcView::SaveContentTo(SfxMedium
& rMed
)
294 SvStream
* pOutStream
= rMed
.GetOutStream();
295 pOutStream
->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding
));
296 aEditWin
.Write( *pOutStream
);//, EE_FORMAT_TEXT);
299 /*--------------------------------------------------------------------
301 --------------------------------------------------------------------*/
304 void SwSrcView::Init()
306 SetHelpId(SW_SRC_VIEWSHELL
);
307 SetName(C2S("Source"));
308 SetWindow( &aEditWin
);
309 SwDocShell
* pDocShell
= GetDocShell();
310 // wird das Doc noch geladen, dann muss die DocShell das Load
311 // anwerfen, wenn das Laden abgeschlossen ist
312 if(!pDocShell
->IsLoading())
316 aEditWin
.SetReadonly(TRUE
);
319 // StartListening(*GetViewFrame());
320 StartListening(*pDocShell
,TRUE
);
323 /*--------------------------------------------------------------------
325 --------------------------------------------------------------------*/
327 SwDocShell
* SwSrcView::GetDocShell()
329 SfxObjectShell
* pObjShell
= GetViewFrame()->GetObjectShell();
330 return PTR_CAST(SwDocShell
, pObjShell
);
333 /*--------------------------------------------------------------------
335 --------------------------------------------------------------------*/
338 void SwSrcView::SaveContent(const String
& rTmpFile
)
340 SfxMedium
aMedium( rTmpFile
, STREAM_WRITE
, TRUE
);
341 SvStream
* pOutStream
= aMedium
.GetOutStream();
342 pOutStream
->SetStreamCharSet( lcl_GetStreamCharSet(eLoadEncoding
) );
343 aEditWin
.Write(*pOutStream
);//, EE_FORMAT_TEXT);
347 /*--------------------------------------------------------------------
349 --------------------------------------------------------------------*/
352 void SwSrcView::Execute(SfxRequest
& rReq
)
354 USHORT nSlot
= rReq
.GetSlot();
355 TextView
* pTextView
= aEditWin
.GetTextView();
360 SvtPathOptions aPathOpt
;
361 // filesave dialog with autoextension
362 FileDialogHelper
aDlgHelper(
363 TemplateDescription::FILESAVE_AUTOEXTENSION
,
364 TemplateDescription::FILESAVE_SIMPLE
);
365 uno::Reference
< XFilePicker
> xFP
= aDlgHelper
.GetFilePicker();
366 // pFileDlg->SetHelpId(HID_FILEDLG_SRCVIEW);
367 uno::Reference
<XFilterManager
> xFltMgr(xFP
, UNO_QUERY
);
369 // search for an html filter for export
370 SfxFilterContainer
* pFilterCont
= GetObjectShell()->GetFactory().GetFilterContainer();
371 const SfxFilter
* pFilter
=
372 pFilterCont
->GetFilter4Extension( C2S("html"), SFX_FILTER_EXPORT
);
375 // filter found -> use its uiname and wildcard
376 const String
& rUIName
= pFilter
->GetUIName();
377 const WildCard
& rCard
= pFilter
->GetWildcard();
378 xFltMgr
->appendFilter( rUIName
, rCard() );
379 xFltMgr
->setCurrentFilter( rUIName
) ;
384 String
sHtml(C2S("HTML"));
385 xFltMgr
->appendFilter( sHtml
, C2S("*.html;*.htm") );
386 xFltMgr
->setCurrentFilter( sHtml
) ;
389 xFP
->setDisplayDirectory( aPathOpt
.GetWorkPath() );
390 if( aDlgHelper
.Execute() == ERRCODE_NONE
)
392 SfxMedium
aMedium( xFP
->getFiles().getConstArray()[0],
393 STREAM_WRITE
| STREAM_SHARE_DENYNONE
,
395 SvStream
* pOutStream
= aMedium
.GetOutStream();
396 pOutStream
->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding
));
397 aEditWin
.Write( *pOutStream
);
404 SwDocShell
* pDocShell
= GetDocShell();
406 if(pDocShell
->HasName())
407 pMed
= pDocShell
->GetMedium();
410 SfxBoolItem
* pItem
= (SfxBoolItem
*)pDocShell
->ExecuteSlot(rReq
, pDocShell
->GetInterface());
411 if(pItem
&& pItem
->GetValue())
412 pMed
= pDocShell
->GetMedium();
416 SvStream
* pOutStream
= pMed
->GetOutStream();
418 pOutStream
->SetStreamSize(0);
419 pOutStream
->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding
));
420 aEditWin
.Write( *pOutStream
);
421 pMed
->CloseOutStream();
423 pDocShell
->GetDoc()->ResetModified();
425 aEditWin
.ClearModifyFlag();
431 const SfxItemSet
* pTmpArgs
= rReq
.GetArgs();
433 USHORT nWhich
= pTmpArgs
->GetWhichByPos( 0 );
434 DBG_ASSERT( nWhich
, "Wich fuer SearchItem ?" );
435 const SfxPoolItem
& rItem
= pTmpArgs
->Get( nWhich
);
436 SetSearchItem( (const SvxSearchItem
&)rItem
);
437 StartSearchAndReplace( (const SvxSearchItem
&)rItem
, FALSE
, rReq
.IsAPI() );
438 if(aEditWin
.IsModified())
439 GetDocShell()->GetDoc()->SetModified();
442 case FN_REPEAT_SEARCH
:
444 SvxSearchItem
* pSrchItem
= GetSearchItem();
447 StartSearchAndReplace( *pSrchItem
, FALSE
, rReq
.IsAPI() );
448 if(aEditWin
.IsModified())
449 GetDocShell()->GetDoc()->SetModified();
454 case SID_PRINTDOCDIRECT
:
456 SfxViewShell::ExecuteSlot( rReq
, SfxViewShell::GetInterface() );
461 GetViewFrame()->GetBindings().InvalidateAll(FALSE
);
465 GetViewFrame()->GetBindings().InvalidateAll(FALSE
);
470 if(pTextView
->HasSelection())
474 if(pTextView
->HasSelection())
481 pTextView
->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
484 aEditWin
.Invalidate();
487 /*--------------------------------------------------------------------
489 --------------------------------------------------------------------*/
492 void SwSrcView::GetState(SfxItemSet
& rSet
)
494 SfxWhichIter
aIter(rSet
);
495 USHORT nWhich
= aIter
.FirstWhich();
496 TextView
* pTextView
= aEditWin
.GetTextView();
503 rSet
.Put(SfxStringItem(nWhich
, String(SW_RES(STR_SAVEAS_SRC
))));
507 SwDocShell
* pDocShell
= GetDocShell();
508 if(!pDocShell
->IsModified())
509 rSet
.DisableItem(nWhich
);
513 case SID_PRINTDOCDIRECT
:
517 String
aPos( SW_RES(STR_SRCVIEW_ROW
) );
518 TextSelection aSel
= pTextView
->GetSelection();
519 aPos
+= String::CreateFromInt32( aSel
.GetEnd().GetPara()+1 );
521 aPos
+= String(SW_RES(STR_SRCVIEW_COL
));
522 aPos
+= String::CreateFromInt32( aSel
.GetEnd().GetIndex()+1 );
523 SfxStringItem
aItem( nWhich
, aPos
);
527 case SID_SEARCH_OPTIONS
:
529 USHORT nOpt
= SRC_SEARCHOPTIONS
;
530 if(GetDocShell()->IsReadOnly())
531 nOpt
&= ~(SEARCH_OPTIONS_REPLACE
|SEARCH_OPTIONS_REPLACE_ALL
);
533 rSet
.Put( SfxUInt16Item( SID_SEARCH_OPTIONS
, nOpt
) );
536 case SID_SEARCH_ITEM
:
539 if ( !pTextView
->HasSelection() )
541 const TextSelection
& rSel
= pTextView
->GetSelection();
542 sSelected
= aEditWin
.GetTextEngine()->GetWord( rSel
.GetStart());
546 sSelected
= pTextView
->GetSelected();
548 SvxSearchItem
* pSrchItem
= GetSearchItem();
549 pSrchItem
->SetSearchString( sSelected
);
550 rSet
.Put( *pSrchItem
);
553 case FN_REPEAT_SEARCH
:
556 rSet
.DisableItem(nWhich
);
562 SfxUndoManager
& rMgr
= pTextView
->GetTextEngine()->GetUndoManager();
564 if(nWhich
== SID_UNDO
)
566 nCount
= rMgr
.GetUndoActionCount();
569 String
aStr(ResId( STR_UNDO
, *SFX_APP()->GetSfxResManager() ));;
570 aStr
+= rMgr
.GetUndoActionComment(--nCount
);
571 rSet
.Put(SfxStringItem(nWhich
, aStr
));
574 rSet
.DisableItem(nWhich
);
578 nCount
= rMgr
.GetRedoActionCount();
581 String
aStr(ResId( STR_REDO
, *SFX_APP()->GetSfxResManager() ));;
582 aStr
+= rMgr
.GetRedoActionComment(--nCount
);
583 rSet
.Put(SfxStringItem(nWhich
,aStr
));
586 rSet
.DisableItem(nWhich
);
590 case SID_MAIL_SENDDOCASPDF
:
591 case SID_MAIL_SENDDOC
:
592 case SID_EXPORTDOCASPDF
:
593 case SID_DIRECTEXPORTDOCASPDF
:
596 case SID_BROWSER_MODE
:
597 case FN_PRINT_LAYOUT
:
598 rSet
.DisableItem(nWhich
);
602 if(!pTextView
->HasSelection())
603 rSet
.DisableItem(nWhich
);
607 BOOL bDisable
= 0 == SW_MOD()->pClipboard
;
610 TransferableDataHelper
aDataHelper(
611 TransferableDataHelper::CreateFromSystemClipboard(
613 bDisable
= !aDataHelper
.GetXTransferable().is() ||
614 0 == aDataHelper
.GetFormatCount();
617 rSet
.DisableItem(nWhich
);
621 nWhich
= aIter
.NextWhich();
625 /*--------------------------------------------------------------------
627 --------------------------------------------------------------------*/
630 SvxSearchItem
* SwSrcView::GetSearchItem()
634 pSearchItem
= new SvxSearchItem(SID_SEARCH_ITEM
);
639 /*--------------------------------------------------------------------
641 --------------------------------------------------------------------*/
644 void SwSrcView::SetSearchItem( const SvxSearchItem
& rItem
)
647 pSearchItem
= (SvxSearchItem
*)rItem
.Clone();
650 /*--------------------------------------------------------------------
652 --------------------------------------------------------------------*/
655 USHORT
SwSrcView::StartSearchAndReplace(const SvxSearchItem
& rSearchItem
,
660 ExtTextView
* pTextView
= aEditWin
.GetTextView();
664 BOOL bForward
= !rSearchItem
.GetBackward();
665 BOOL bAtStart
= pTextView
->GetSelection() == TextSelection( aPaM
, aPaM
);
668 aPaM
= TextPaM( (ULONG
)-1, (USHORT
)-1 );
672 aSel
= pTextView
->GetSelection();
673 pTextView
->SetSelection( TextSelection( aPaM
, aPaM
));
676 util::SearchOptions
aSearchOpt( rSearchItem
.GetSearchOptions() );
677 aSearchOpt
.Locale
= SvxCreateLocale(
678 static_cast< LanguageType
>( GetAppLanguage() ) );
682 switch( rSearchItem
.GetCommand() )
684 case SVX_SEARCHCMD_FIND
:
685 case SVX_SEARCHCMD_FIND_ALL
:
686 nFound
= pTextView
->Search( aSearchOpt
, bForward
);
689 case SVX_SEARCHCMD_REPLACE_ALL
: bAll
= TRUE
;
690 case SVX_SEARCHCMD_REPLACE
:
691 nFound
= pTextView
->Replace( aSearchOpt
, bAll
, bForward
);
700 BOOL bNotFoundMessage
= FALSE
;
705 bNotFoundMessage
= bAtStart
;
709 bNotFoundMessage
= TRUE
;
710 pTextView
->SetSelection( aSel
);
715 bNotFoundMessage
= TRUE
;
722 InfoBox( 0, SW_RES(MSG_NOT_FOUND
)).Execute();
724 else if(!bRecursive
&& RET_YES
==
725 QueryBox(0, SW_RES( bForward
? MSG_SEARCH_END
726 : MSG_SEARCH_START
)).Execute())
728 pTextView
->SetSelection( TextSelection( aPaM
, aPaM
) );
729 StartSearchAndReplace( rSearchItem
, FALSE
, FALSE
, TRUE
);
735 /*-----------------02.07.97 09:29-------------------
737 --------------------------------------------------*/
738 USHORT
SwSrcView::SetPrinter(SfxPrinter
* pNew
, USHORT nDiffFlags
, bool )
740 SwDocShell
* pDocSh
= GetDocShell();
741 SfxPrinter
* pOld
= pDocSh
->GetDoc()->getPrinter( false );
742 if ( pOld
&& pOld
->IsPrinting() )
743 return SFX_PRINTERROR_BUSY
;
745 if ( (SFX_PRINTER_JOBSETUP
| SFX_PRINTER_PRINTER
) & nDiffFlags
)
747 pDocSh
->GetDoc()->setPrinter( pNew
, true, true );
748 if ( nDiffFlags
& SFX_PRINTER_PRINTER
)
749 pDocSh
->SetModified();
751 if ( nDiffFlags
& SFX_PRINTER_OPTIONS
)
752 ::SetPrinter( pDocSh
->getIDocumentDeviceAccess(), pNew
, TRUE
);
754 const BOOL bChgOri
= nDiffFlags
& SFX_PRINTER_CHG_ORIENTATION
? TRUE
: FALSE
;
755 const BOOL bChgSize
= nDiffFlags
& SFX_PRINTER_CHG_SIZE
? TRUE
: FALSE
;
756 if ( bChgOri
|| bChgSize
)
758 pDocSh
->SetModified();
763 /*--------------------------------------------------------------------
765 --------------------------------------------------------------------*/
767 ErrCode
SwSrcView::DoPrint( SfxPrinter
*pPrinter
, PrintDialog
*pDlg
, BOOL bSilent
, BOOL bIsAPI
)
769 SfxPrintProgress
*pProgress
= new SfxPrintProgress( this, !bSilent
);
770 SfxPrinter
*pDocPrinter
= GetPrinter(TRUE
);
772 pPrinter
= pDocPrinter
;
773 else if ( pDocPrinter
!= pPrinter
)
775 pProgress
->RestoreOnEndPrint( pDocPrinter
->Clone() );
776 SetPrinter( pPrinter
, SFX_PRINTER_PRINTER
);
778 pProgress
->SetWaitMode(FALSE
);
781 PreparePrint( pDlg
);
783 SfxViewShell::Print(*pProgress
, bIsAPI
, pDlg
); //???
785 MapMode
eOldMapMode( pPrinter
->GetMapMode() );
786 Font
aOldFont( pPrinter
->Printer::GetFont() );
788 TextEngine
* pTextEngine
= aEditWin
.GetTextEngine();
789 pPrinter
->SetMapMode(MAP_100TH_MM
);
790 Font
aFont(aEditWin
.GetOutWin()->GetFont());
791 Size
aSize(aFont
.GetSize());
792 aSize
= aEditWin
.GetOutWin()->PixelToLogic(aSize
, MAP_100TH_MM
);
793 aFont
.SetSize(aSize
);
794 aFont
.SetColor(COL_BLACK
);
795 pPrinter
->SetFont( aFont
);
797 String
aTitle( GetViewFrame()->GetWindow().GetText() );
799 USHORT nLineHeight
= (USHORT
) pPrinter
->GetTextHeight(); // etwas mehr.
800 USHORT nParaSpace
= 10;
802 Size aPaperSz
= pPrinter
->GetOutputSize();
803 aPaperSz
.Width() -= (LMARGPRN
+RMARGPRN
);
804 aPaperSz
.Height() -= (TMARGPRN
+BMARGPRN
);
806 // nLinepPage stimmt nicht, wenn Zeilen umgebrochen werden muessen...
807 USHORT nLinespPage
= (USHORT
) (aPaperSz
.Height()/nLineHeight
);
808 USHORT nCharspLine
= (USHORT
) (aPaperSz
.Width() / pPrinter
->GetTextWidth( 'X' ));
809 USHORT nParas
= static_cast< USHORT
>( pTextEngine
->GetParagraphCount() );
811 USHORT nPages
= (USHORT
) (nParas
/nLinespPage
+1 );
814 BOOL bStartJob
= pPrinter
->StartJob( aTitle
);
817 pPrinter
->StartPage();
819 lcl_PrintHeader( pPrinter
, nPages
, nCurPage
, aTitle
);
820 Point
aPos( LMARGPRN
, TMARGPRN
);
821 for ( USHORT nPara
= 0; nPara
< nParas
; nPara
++ )
823 String
aLine( pTextEngine
->GetText( nPara
) );
824 lcl_ConvertTabsToSpaces( aLine
);
825 USHORT nLines
= aLine
.Len()/nCharspLine
+1;
826 for ( USHORT nLine
= 0; nLine
< nLines
; nLine
++ )
828 String
aTmpLine( aLine
, nLine
*nCharspLine
, nCharspLine
);
829 aPos
.Y() += nLineHeight
;
830 if ( aPos
.Y() > ( aPaperSz
.Height()+TMARGPRN
) )
834 pPrinter
->StartPage();
835 lcl_PrintHeader( pPrinter
, nPages
, nCurPage
, aTitle
);
836 aPos
= Point( LMARGPRN
, TMARGPRN
+nLineHeight
);
838 pPrinter
->DrawText( aPos
, aTmpLine
);
840 aPos
.Y() += nParaSpace
;
845 pPrinter
->SetFont( aOldFont
);
846 pPrinter
->SetMapMode( eOldMapMode
);
850 // Printer konnte nicht gestartet werden
852 return ERRCODE_IO_ABORT
;
856 pProgress
->DeleteOnEndPrint();
858 return pPrinter
->GetError();
861 /*--------------------------------------------------------------------
863 --------------------------------------------------------------------*/
866 SfxPrinter
* SwSrcView::GetPrinter( BOOL bCreate
)
868 return GetDocShell()->GetDoc()->getPrinter( bCreate
);
871 /*--------------------------------------------------------------------
873 --------------------------------------------------------------------*/
876 void SwSrcView::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
878 if ( rHint
.ISA(SfxSimpleHint
) &&
880 ((SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_MODECHANGED
||
882 ((SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_TITLECHANGED
&&
883 !GetDocShell()->IsReadOnly() && aEditWin
.IsReadonly()
888 // Broadcast kommt nur einmal!
889 const SwDocShell
* pDocSh
= GetDocShell();
890 const BOOL bReadonly
= pDocSh
->IsReadOnly();
891 aEditWin
.SetReadonly(bReadonly
);
893 SfxViewShell::Notify(rBC
, rHint
);
896 /*-----------------19.04.97 10:19-------------------
898 --------------------------------------------------*/
899 void SwSrcView::Load(SwDocShell
* pDocShell
)
901 SvxHtmlOptions
* pHtmlOptions
= SvxHtmlOptions::Get();
902 const sal_Char
*pCharSet
=
903 rtl_getBestMimeCharsetFromTextEncoding( pHtmlOptions
->GetTextEncoding() );
904 rtl_TextEncoding eDestEnc
= rtl_getTextEncodingFromMimeCharset( pCharSet
);
906 aEditWin
.SetReadonly(pDocShell
->IsReadOnly());
907 aEditWin
.SetTextEncoding(eDestEnc
);
908 SfxMedium
* pMedium
= pDocShell
->GetMedium();
910 const SfxFilter
* pFilter
= pMedium
->GetFilter();
911 BOOL bHtml
= pFilter
&& pFilter
->GetUserData().EqualsAscii("HTML");
912 BOOL bDocModified
= pDocShell
->IsModified();
913 if(bHtml
&& !bDocModified
&& pDocShell
->HasName())
915 SvStream
* pStream
= pMedium
->GetInStream();
916 if(pStream
&& 0 == pStream
->GetError() )
918 rtl_TextEncoding eHeaderEnc
=
919 SfxHTMLParser::GetEncodingByHttpHeader(
920 pDocShell
->GetHeaderAttributes() );
921 if( RTL_TEXTENCODING_DONTKNOW
== eHeaderEnc
)
923 const sal_Char
*pTmpCharSet
=
924 rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1
);
925 eHeaderEnc
= rtl_getTextEncodingFromMimeCharset( pTmpCharSet
);
927 if( RTL_TEXTENCODING_DONTKNOW
!= eHeaderEnc
&&
928 eDestEnc
!= eHeaderEnc
)
930 eDestEnc
= eHeaderEnc
;
931 aEditWin
.SetTextEncoding(eDestEnc
);
933 pStream
->SetStreamCharSet( eDestEnc
);
935 TextEngine
* pTextEngine
= aEditWin
.GetTextEngine();
936 pTextEngine
->EnableUndo(FALSE
);
937 aEditWin
.Read(*pStream
);//, EE_FORMAT_TEXT);
938 pTextEngine
->EnableUndo(TRUE
);
942 Window
*pTmpWindow
= &GetViewFrame()->GetWindow();
943 InfoBox(pTmpWindow
, SW_RES(MSG_ERR_SRCSTREAM
)).Execute();
948 utl::TempFile aTempFile
;
949 aTempFile
.EnableKillingFile();
950 String
sFileURL( aTempFile
.GetURL() );
954 SfxMedium
aMedium( sFileURL
,STREAM_READWRITE
, TRUE
);
955 SwWriter
aWriter( aMedium
, *pDocShell
->GetDoc() );
957 ::GetHTMLWriter(aEmptyStr
, aMedium
.GetBaseURL( true ), xWriter
);
958 String sWriteName
= pDocShell
->HasName() ?
960 (const String
&) sFileURL
;
961 ULONG nRes
= aWriter
.Write(xWriter
, &sWriteName
);
964 ErrorHandler::HandleError(ErrCode(nRes
));
965 aEditWin
.SetReadonly(TRUE
);
968 SvStream
* pInStream
= aMedium
.GetInStream();
970 pInStream
->SetStreamCharSet( eDestEnc
);
973 aEditWin
.Read(*pInStream
);//, EE_FORMAT_TEXT);
976 aEditWin
.ClearModifyFlag();
978 eLoadEncoding
= eDestEnc
;
981 pDocShell
->SetModified();// das Flag wird zwischendurch zurueckgesetzt
982 // AutoLoad abschalten
983 pDocShell
->SetAutoLoad(INetURLObject(), 0, FALSE
);
984 DBG_ASSERT(PTR_CAST(SwWebDocShell
, pDocShell
), "Wieso keine WebDocShell?");
985 USHORT nLine
= ((SwWebDocShell
*)pDocShell
)->GetSourcePara();
986 aEditWin
.SetStartLine(nLine
);
987 aEditWin
.GetTextEngine()->ResetUndo();
988 aEditWin
.GetOutWin()->GrabFocus();