merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / uiview / srcview.cxx
blob5653071d84f263ea8eaa301a9816d8d08740f2ab
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 $
10 * $Revision: 1.59 $
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>
75 #include <docsh.hxx>
76 #include <wdocsh.hxx>
77 #include <srcview.hxx>
78 #include <viewfunc.hxx>
79 #include <doc.hxx>
80 #include <sfx2/msg.hxx>
81 #include <shellio.hxx>
83 #include <cmdid.h> // FN_ ...
84 #include <helpid.h>
85 #include <globals.hrc>
86 #include <shells.hrc>
87 #include <popup.hrc>
88 #include <web.hrc>
89 #include <view.hrc>
90 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
91 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
92 #include <sfx2/filedlghelper.hxx>
93 #define SwSrcView
94 #define SearchSettings
95 #define _ExecSearch Execute
96 #define _StateSearch GetState
97 #include <svx/svxslots.hxx>
98 #include "swslots.hxx"
100 #include <unomid.h>
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| \
119 SFX_VIEW_CAN_PRINT|\
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
126 #define RMARGPRN 900
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 );
187 if ( nPages != 1 )
189 aFont.SetWeight( WEIGHT_NORMAL );
190 pPrinter->SetFont( aFont );
191 String aPageStr( C2S(" [") );
192 aPageStr += String( SW_RES( STR_PAGE ) );
193 aPageStr += ' ';
194 aPageStr += String::CreateFromInt32( nCurPage );
195 aPageStr += ']';
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 );
221 return eRet;
223 /*-----------------18.11.96 08.21-------------------
225 --------------------------------------------------*/
227 void lcl_ConvertTabsToSpaces( String& rLine )
229 if ( rLine.Len() )
231 USHORT nPos = 0;
232 USHORT nMax = rLine.Len();
233 while ( nPos < nMax )
235 if ( rLine.GetChar(nPos) == '\t' )
237 // Nicht 4 Blanks, sondern an 4er TabPos:
238 String aBlanker;
239 aBlanker.Fill( ( 4 - ( nPos % 4 ) ), ' ' );
240 rLine.Erase( nPos, 1 );
241 rLine.Insert( aBlanker, nPos );
242 nMax = rLine.Len();
244 nPos++; // Nicht optimal, falls Tab, aber auch nicht verkehrt...
249 /*--------------------------------------------------------------------
250 Beschreibung:
251 --------------------------------------------------------------------*/
254 SwSrcView::SwSrcView(SfxViewFrame* pViewFrame, SfxViewShell*) :
255 SfxViewShell( pViewFrame, SWSRCVIEWFLAGS ),
256 aEditWin( &pViewFrame->GetWindow(), this ),
257 pSearchItem(0),
258 bSourceSaved(FALSE),
259 eLoadEncoding(RTL_TEXTENCODING_DONTKNOW)
261 Init();
264 /*--------------------------------------------------------------------
265 Beschreibung:
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);
286 delete pSearchItem;
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 /*--------------------------------------------------------------------
300 Beschreibung:
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())
313 Load(pDocShell);
314 else
316 aEditWin.SetReadonly(TRUE);
319 // StartListening(*GetViewFrame());
320 StartListening(*pDocShell,TRUE);
323 /*--------------------------------------------------------------------
324 Beschreibung:
325 --------------------------------------------------------------------*/
327 SwDocShell* SwSrcView::GetDocShell()
329 SfxObjectShell* pObjShell = GetViewFrame()->GetObjectShell();
330 return PTR_CAST(SwDocShell, pObjShell);
333 /*--------------------------------------------------------------------
334 Beschreibung:
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);
344 aMedium.Commit();
347 /*--------------------------------------------------------------------
348 Beschreibung:
349 --------------------------------------------------------------------*/
352 void SwSrcView::Execute(SfxRequest& rReq)
354 USHORT nSlot = rReq.GetSlot();
355 TextView* pTextView = aEditWin.GetTextView();
356 switch( nSlot )
358 case SID_SAVEASDOC:
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 );
373 if ( pFilter )
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 ) ;
381 else
383 // filter not found
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,
394 FALSE );
395 SvStream* pOutStream = aMedium.GetOutStream();
396 pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
397 aEditWin.Write( *pOutStream );
398 aMedium.Commit();
401 break;
402 case SID_SAVEDOC:
404 SwDocShell* pDocShell = GetDocShell();
405 SfxMedium* pMed = 0;
406 if(pDocShell->HasName())
407 pMed = pDocShell->GetMedium();
408 else
410 SfxBoolItem* pItem = (SfxBoolItem*)pDocShell->ExecuteSlot(rReq, pDocShell->GetInterface());
411 if(pItem && pItem->GetValue())
412 pMed = pDocShell->GetMedium();
414 if(pMed)
416 SvStream* pOutStream = pMed->GetOutStream();
417 pOutStream->Seek(0);
418 pOutStream->SetStreamSize(0);
419 pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
420 aEditWin.Write( *pOutStream );
421 pMed->CloseOutStream();
422 pMed->Commit();
423 pDocShell->GetDoc()->ResetModified();
424 SourceSaved();
425 aEditWin.ClearModifyFlag();
428 break;
429 case FID_SEARCH_NOW:
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();
441 break;
442 case FN_REPEAT_SEARCH:
444 SvxSearchItem* pSrchItem = GetSearchItem();
445 if(pSrchItem)
447 StartSearchAndReplace( *pSrchItem, FALSE, rReq.IsAPI() );
448 if(aEditWin.IsModified())
449 GetDocShell()->GetDoc()->SetModified();
452 break;
453 case SID_PRINTDOC:
454 case SID_PRINTDOCDIRECT:
456 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
458 break;
459 case SID_UNDO:
460 pTextView->Undo();
461 GetViewFrame()->GetBindings().InvalidateAll(FALSE);
462 break;
463 case SID_REDO:
464 pTextView->Redo();
465 GetViewFrame()->GetBindings().InvalidateAll(FALSE);
466 break;
467 case SID_REPEAT:
468 break;
469 case SID_CUT:
470 if(pTextView->HasSelection())
471 pTextView->Cut();
472 break;
473 case SID_COPY:
474 if(pTextView->HasSelection())
475 pTextView->Copy();
476 break;
477 case SID_PASTE:
478 pTextView->Paste();
479 break;
480 case SID_SELECTALL:
481 pTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
482 break;
484 aEditWin.Invalidate();
487 /*--------------------------------------------------------------------
488 Beschreibung:
489 --------------------------------------------------------------------*/
492 void SwSrcView::GetState(SfxItemSet& rSet)
494 SfxWhichIter aIter(rSet);
495 USHORT nWhich = aIter.FirstWhich();
496 TextView* pTextView = aEditWin.GetTextView();
498 while(nWhich)
500 switch(nWhich)
502 case SID_SAVEASDOC:
503 rSet.Put(SfxStringItem(nWhich, String(SW_RES(STR_SAVEAS_SRC))));
504 break;
505 case SID_SAVEDOC:
507 SwDocShell* pDocShell = GetDocShell();
508 if(!pDocShell->IsModified())
509 rSet.DisableItem(nWhich);
511 break;
512 case SID_PRINTDOC:
513 case SID_PRINTDOCDIRECT:
514 break;
515 case SID_TABLE_CELL:
517 String aPos( SW_RES(STR_SRCVIEW_ROW) );
518 TextSelection aSel = pTextView->GetSelection();
519 aPos += String::CreateFromInt32( aSel.GetEnd().GetPara()+1 );
520 aPos +=C2S(" : ");
521 aPos += String(SW_RES(STR_SRCVIEW_COL));
522 aPos += String::CreateFromInt32( aSel.GetEnd().GetIndex()+1 );
523 SfxStringItem aItem( nWhich, aPos );
524 rSet.Put( aItem );
526 break;
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) );
535 break;
536 case SID_SEARCH_ITEM:
538 String sSelected;
539 if ( !pTextView->HasSelection() )
541 const TextSelection& rSel = pTextView->GetSelection();
542 sSelected = aEditWin.GetTextEngine()->GetWord( rSel.GetStart());
544 else
546 sSelected = pTextView->GetSelected();
548 SvxSearchItem * pSrchItem = GetSearchItem();
549 pSrchItem->SetSearchString( sSelected );
550 rSet.Put( *pSrchItem );
552 break;
553 case FN_REPEAT_SEARCH:
555 if(!GetSearchItem())
556 rSet.DisableItem(nWhich);
558 break;
559 case SID_UNDO:
560 case SID_REDO:
562 SfxUndoManager& rMgr = pTextView->GetTextEngine()->GetUndoManager();
563 USHORT nCount = 0;
564 if(nWhich == SID_UNDO)
566 nCount = rMgr.GetUndoActionCount();
567 if(nCount)
569 String aStr(ResId( STR_UNDO, *SFX_APP()->GetSfxResManager() ));;
570 aStr += rMgr.GetUndoActionComment(--nCount);
571 rSet.Put(SfxStringItem(nWhich, aStr));
573 else
574 rSet.DisableItem(nWhich);
576 else
578 nCount = rMgr.GetRedoActionCount();
579 if(nCount)
581 String aStr(ResId( STR_REDO, *SFX_APP()->GetSfxResManager() ));;
582 aStr += rMgr.GetRedoActionComment(--nCount);
583 rSet.Put(SfxStringItem(nWhich,aStr));
585 else
586 rSet.DisableItem(nWhich);
589 break;
590 case SID_MAIL_SENDDOCASPDF:
591 case SID_MAIL_SENDDOC :
592 case SID_EXPORTDOCASPDF:
593 case SID_DIRECTEXPORTDOCASPDF:
594 case SID_EXPORTDOC:
595 case SID_REPEAT:
596 case SID_BROWSER_MODE:
597 case FN_PRINT_LAYOUT:
598 rSet.DisableItem(nWhich);
599 break;
600 case SID_CUT:
601 case SID_COPY:
602 if(!pTextView->HasSelection())
603 rSet.DisableItem(nWhich);
604 break;
605 case SID_PASTE:
607 BOOL bDisable = 0 == SW_MOD()->pClipboard;
608 if( bDisable )
610 TransferableDataHelper aDataHelper(
611 TransferableDataHelper::CreateFromSystemClipboard(
612 &aEditWin) );
613 bDisable = !aDataHelper.GetXTransferable().is() ||
614 0 == aDataHelper.GetFormatCount();
616 if( bDisable )
617 rSet.DisableItem(nWhich);
619 break;
621 nWhich = aIter.NextWhich();
625 /*--------------------------------------------------------------------
626 Beschreibung:
627 --------------------------------------------------------------------*/
630 SvxSearchItem* SwSrcView::GetSearchItem()
632 if(!pSearchItem)
634 pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
636 return pSearchItem;
639 /*--------------------------------------------------------------------
640 Beschreibung:
641 --------------------------------------------------------------------*/
644 void SwSrcView::SetSearchItem( const SvxSearchItem& rItem )
646 delete pSearchItem;
647 pSearchItem = (SvxSearchItem*)rItem.Clone();
650 /*--------------------------------------------------------------------
651 Beschreibung:
652 --------------------------------------------------------------------*/
655 USHORT SwSrcView::StartSearchAndReplace(const SvxSearchItem& rSearchItem,
656 BOOL bFromStart,
657 BOOL bApi,
658 BOOL bRecursive)
660 ExtTextView* pTextView = aEditWin.GetTextView();
661 TextSelection aSel;
662 TextPaM aPaM;
664 BOOL bForward = !rSearchItem.GetBackward();
665 BOOL bAtStart = pTextView->GetSelection() == TextSelection( aPaM, aPaM );
667 if( !bForward )
668 aPaM = TextPaM( (ULONG)-1, (USHORT)-1 );
670 if( bFromStart )
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() ) );
680 USHORT nFound;
681 BOOL bAll = FALSE;
682 switch( rSearchItem.GetCommand() )
684 case SVX_SEARCHCMD_FIND:
685 case SVX_SEARCHCMD_FIND_ALL:
686 nFound = pTextView->Search( aSearchOpt, bForward );
687 break;
689 case SVX_SEARCHCMD_REPLACE_ALL: bAll = TRUE;
690 case SVX_SEARCHCMD_REPLACE:
691 nFound = pTextView->Replace( aSearchOpt, bAll, bForward );
692 break;
694 default:
695 nFound = 0;
698 if( !nFound )
700 BOOL bNotFoundMessage = FALSE;
701 if(!bRecursive)
703 if(!bFromStart)
705 bNotFoundMessage = bAtStart;
707 else
709 bNotFoundMessage = TRUE;
710 pTextView->SetSelection( aSel );
713 else if(bAtStart)
715 bNotFoundMessage = TRUE;
719 if(!bApi)
720 if(bNotFoundMessage)
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 );
732 return nFound;
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();
760 return 0;
763 /*--------------------------------------------------------------------
764 Beschreibung:
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);
771 if ( !pPrinter )
772 pPrinter = pDocPrinter;
773 else if ( pDocPrinter != pPrinter )
775 pProgress->RestoreOnEndPrint( pDocPrinter->Clone() );
776 SetPrinter( pPrinter, SFX_PRINTER_PRINTER );
778 pProgress->SetWaitMode(FALSE);
780 // Drucker starten
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 );
812 USHORT nCurPage = 1;
814 BOOL bStartJob = pPrinter->StartJob( aTitle );
815 if( bStartJob )
817 pPrinter->StartPage();
818 // Header drucken...
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 ) )
832 nCurPage++;
833 pPrinter->EndPage();
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;
842 pPrinter->EndPage();
845 pPrinter->SetFont( aOldFont );
846 pPrinter->SetMapMode( eOldMapMode );
848 if ( !bStartJob )
850 // Printer konnte nicht gestartet werden
851 delete pProgress;
852 return ERRCODE_IO_ABORT;
855 pProgress->Stop();
856 pProgress->DeleteOnEndPrint();
857 pPrinter->EndJob();
858 return pPrinter->GetError();
861 /*--------------------------------------------------------------------
862 Beschreibung:
863 --------------------------------------------------------------------*/
866 SfxPrinter* SwSrcView::GetPrinter( BOOL bCreate )
868 return GetDocShell()->GetDoc()->getPrinter( bCreate );
871 /*--------------------------------------------------------------------
872 Beschreibung:
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 );
934 pStream->Seek(0);
935 TextEngine* pTextEngine = aEditWin.GetTextEngine();
936 pTextEngine->EnableUndo(FALSE);
937 aEditWin.Read(*pStream);//, EE_FORMAT_TEXT);
938 pTextEngine->EnableUndo(TRUE);
940 else
942 Window *pTmpWindow = &GetViewFrame()->GetWindow();
943 InfoBox(pTmpWindow, SW_RES(MSG_ERR_SRCSTREAM)).Execute();
946 else
948 utl::TempFile aTempFile;
949 aTempFile.EnableKillingFile();
950 String sFileURL( aTempFile.GetURL() );
951 SvtSaveOptions aOpt;
954 SfxMedium aMedium( sFileURL,STREAM_READWRITE, TRUE );
955 SwWriter aWriter( aMedium, *pDocShell->GetDoc() );
956 WriterRef xWriter;
957 ::GetHTMLWriter(aEmptyStr, aMedium.GetBaseURL( true ), xWriter);
958 String sWriteName = pDocShell->HasName() ?
959 pMedium->GetName() :
960 (const String&) sFileURL;
961 ULONG nRes = aWriter.Write(xWriter, &sWriteName);
962 if(nRes)
964 ErrorHandler::HandleError(ErrCode(nRes));
965 aEditWin.SetReadonly(TRUE);
967 aMedium.Commit();
968 SvStream* pInStream = aMedium.GetInStream();
969 pInStream->Seek(0);
970 pInStream->SetStreamCharSet( eDestEnc );
973 aEditWin.Read(*pInStream);//, EE_FORMAT_TEXT);
976 aEditWin.ClearModifyFlag();
978 eLoadEncoding = eDestEnc;
980 if(bDocModified)
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();