update dev300-m58
[ooovba.git] / sw / source / ui / uiview / srcview.cxx
blob24eca08fac3bc66510b70aa7fdd58dee3169cd61
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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/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>
74 #include <docsh.hxx>
75 #include <wdocsh.hxx>
76 #include <srcview.hxx>
77 #include <viewfunc.hxx>
78 #include <doc.hxx>
79 #include <sfx2/msg.hxx>
80 #include <shellio.hxx>
82 #include <cmdid.h> // FN_ ...
83 #include <helpid.h>
84 #include <globals.hrc>
85 #include <shells.hrc>
86 #include <popup.hrc>
87 #include <web.hrc>
88 #include <view.hrc>
89 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
90 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
91 #include <sfx2/filedlghelper.hxx>
92 #define SwSrcView
93 #define SearchSettings
94 #define _ExecSearch Execute
95 #define _StateSearch GetState
96 #include <svx/svxslots.hxx>
97 #include "swslots.hxx"
99 #include <unomid.h>
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| \
118 SFX_VIEW_CAN_PRINT|\
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
125 #define RMARGPRN 900
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 );
186 if ( nPages != 1 )
188 aFont.SetWeight( WEIGHT_NORMAL );
189 pPrinter->SetFont( aFont );
190 String aPageStr( C2S(" [") );
191 aPageStr += String( SW_RES( STR_PAGE ) );
192 aPageStr += ' ';
193 aPageStr += String::CreateFromInt32( nCurPage );
194 aPageStr += ']';
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 );
220 return eRet;
222 /*-----------------18.11.96 08.21-------------------
224 --------------------------------------------------*/
226 void lcl_ConvertTabsToSpaces( String& rLine )
228 if ( rLine.Len() )
230 USHORT nPos = 0;
231 USHORT nMax = rLine.Len();
232 while ( nPos < nMax )
234 if ( rLine.GetChar(nPos) == '\t' )
236 // Nicht 4 Blanks, sondern an 4er TabPos:
237 String aBlanker;
238 aBlanker.Fill( ( 4 - ( nPos % 4 ) ), ' ' );
239 rLine.Erase( nPos, 1 );
240 rLine.Insert( aBlanker, nPos );
241 nMax = rLine.Len();
243 nPos++; // Nicht optimal, falls Tab, aber auch nicht verkehrt...
248 /*--------------------------------------------------------------------
249 Beschreibung:
250 --------------------------------------------------------------------*/
253 SwSrcView::SwSrcView(SfxViewFrame* pViewFrame, SfxViewShell*) :
254 SfxViewShell( pViewFrame, SWSRCVIEWFLAGS ),
255 aEditWin( &pViewFrame->GetWindow(), this ),
256 pSearchItem(0),
257 bSourceSaved(FALSE),
258 eLoadEncoding(RTL_TEXTENCODING_DONTKNOW)
260 Init();
263 /*--------------------------------------------------------------------
264 Beschreibung:
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);
285 delete pSearchItem;
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 /*--------------------------------------------------------------------
299 Beschreibung:
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())
312 Load(pDocShell);
313 else
315 aEditWin.SetReadonly(TRUE);
318 // StartListening(*GetViewFrame());
319 StartListening(*pDocShell,TRUE);
322 /*--------------------------------------------------------------------
323 Beschreibung:
324 --------------------------------------------------------------------*/
326 SwDocShell* SwSrcView::GetDocShell()
328 SfxObjectShell* pObjShell = GetViewFrame()->GetObjectShell();
329 return PTR_CAST(SwDocShell, pObjShell);
332 /*--------------------------------------------------------------------
333 Beschreibung:
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);
343 aMedium.Commit();
346 /*--------------------------------------------------------------------
347 Beschreibung:
348 --------------------------------------------------------------------*/
351 void SwSrcView::Execute(SfxRequest& rReq)
353 USHORT nSlot = rReq.GetSlot();
354 TextView* pTextView = aEditWin.GetTextView();
355 switch( nSlot )
357 case SID_SAVEASDOC:
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 );
372 if ( pFilter )
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 ) ;
380 else
382 // filter not found
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,
393 FALSE );
394 SvStream* pOutStream = aMedium.GetOutStream();
395 pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
396 aEditWin.Write( *pOutStream );
397 aMedium.Commit();
400 break;
401 case SID_SAVEDOC:
403 SwDocShell* pDocShell = GetDocShell();
404 SfxMedium* pMed = 0;
405 if(pDocShell->HasName())
406 pMed = pDocShell->GetMedium();
407 else
409 SfxBoolItem* pItem = (SfxBoolItem*)pDocShell->ExecuteSlot(rReq, pDocShell->GetInterface());
410 if(pItem && pItem->GetValue())
411 pMed = pDocShell->GetMedium();
413 if(pMed)
415 SvStream* pOutStream = pMed->GetOutStream();
416 pOutStream->Seek(0);
417 pOutStream->SetStreamSize(0);
418 pOutStream->SetStreamCharSet(lcl_GetStreamCharSet(eLoadEncoding));
419 aEditWin.Write( *pOutStream );
420 pMed->CloseOutStream();
421 pMed->Commit();
422 pDocShell->GetDoc()->ResetModified();
423 SourceSaved();
424 aEditWin.ClearModifyFlag();
427 break;
428 case FID_SEARCH_NOW:
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();
440 break;
441 case FN_REPEAT_SEARCH:
443 SvxSearchItem* pSrchItem = GetSearchItem();
444 if(pSrchItem)
446 StartSearchAndReplace( *pSrchItem, FALSE, rReq.IsAPI() );
447 if(aEditWin.IsModified())
448 GetDocShell()->GetDoc()->SetModified();
451 break;
452 case SID_PRINTDOC:
453 case SID_PRINTDOCDIRECT:
455 SfxViewShell::ExecuteSlot( rReq, SfxViewShell::GetInterface() );
457 break;
458 case SID_UNDO:
459 pTextView->Undo();
460 break;
461 case SID_REDO:
462 pTextView->Redo();
463 break;
464 case SID_REPEAT:
465 break;
466 case SID_CUT:
467 pTextView->Cut();
468 break;
469 case SID_COPY:
470 pTextView->Copy();
471 break;
472 case SID_PASTE:
473 pTextView->Paste();
474 break;
475 case SID_SELECTALL:
476 pTextView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
477 break;
479 aEditWin.Invalidate();
482 /*--------------------------------------------------------------------
483 Beschreibung:
484 --------------------------------------------------------------------*/
487 void SwSrcView::GetState(SfxItemSet& rSet)
489 SfxWhichIter aIter(rSet);
490 USHORT nWhich = aIter.FirstWhich();
491 TextView* pTextView = aEditWin.GetTextView();
493 while(nWhich)
495 switch(nWhich)
497 case SID_SAVEASDOC:
498 rSet.Put(SfxStringItem(nWhich, String(SW_RES(STR_SAVEAS_SRC))));
499 break;
500 case SID_SAVEDOC:
502 SwDocShell* pDocShell = GetDocShell();
503 if(!pDocShell->IsModified())
504 rSet.DisableItem(nWhich);
506 break;
507 case SID_PRINTDOC:
508 case SID_PRINTDOCDIRECT:
509 break;
510 case SID_TABLE_CELL:
512 String aPos( SW_RES(STR_SRCVIEW_ROW) );
513 TextSelection aSel = pTextView->GetSelection();
514 aPos += String::CreateFromInt32( aSel.GetEnd().GetPara()+1 );
515 aPos +=C2S(" : ");
516 aPos += String(SW_RES(STR_SRCVIEW_COL));
517 aPos += String::CreateFromInt32( aSel.GetEnd().GetIndex()+1 );
518 SfxStringItem aItem( nWhich, aPos );
519 rSet.Put( aItem );
521 break;
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) );
530 break;
531 case SID_SEARCH_ITEM:
533 String sSelected;
534 if ( !pTextView->HasSelection() )
536 const TextSelection& rSel = pTextView->GetSelection();
537 sSelected = aEditWin.GetTextEngine()->GetWord( rSel.GetStart());
539 else
541 sSelected = pTextView->GetSelected();
543 SvxSearchItem * pSrchItem = GetSearchItem();
544 pSrchItem->SetSearchString( sSelected );
545 rSet.Put( *pSrchItem );
547 break;
548 case FN_REPEAT_SEARCH:
550 if(!GetSearchItem())
551 rSet.DisableItem(nWhich);
553 break;
554 case SID_UNDO:
555 case SID_REDO:
557 SfxUndoManager& rMgr = pTextView->GetTextEngine()->GetUndoManager();
558 USHORT nCount = 0;
559 if(nWhich == SID_UNDO)
561 nCount = rMgr.GetUndoActionCount();
562 if(nCount)
564 String aStr(ResId( STR_UNDO, *SFX_APP()->GetSfxResManager() ));;
565 aStr += rMgr.GetUndoActionComment(--nCount);
566 rSet.Put(SfxStringItem(nWhich, aStr));
568 else
569 rSet.DisableItem(nWhich);
571 else
573 nCount = rMgr.GetRedoActionCount();
574 if(nCount)
576 String aStr(ResId( STR_REDO, *SFX_APP()->GetSfxResManager() ));;
577 aStr += rMgr.GetRedoActionComment(--nCount);
578 rSet.Put(SfxStringItem(nWhich,aStr));
580 else
581 rSet.DisableItem(nWhich);
584 break;
585 case SID_MAIL_SENDDOCASPDF:
586 case SID_MAIL_SENDDOC :
587 case SID_EXPORTDOCASPDF:
588 case SID_DIRECTEXPORTDOCASPDF:
589 case SID_EXPORTDOC:
590 case SID_REPEAT:
591 rSet.DisableItem(nWhich);
592 break;
593 case SID_CUT:
594 case SID_COPY:
595 if(!pTextView->HasSelection())
596 rSet.DisableItem(nWhich);
597 break;
598 case SID_PASTE:
600 BOOL bDisable = 0 == SW_MOD()->pClipboard;
601 if( bDisable )
603 TransferableDataHelper aDataHelper(
604 TransferableDataHelper::CreateFromSystemClipboard(
605 &aEditWin) );
606 bDisable = !aDataHelper.GetXTransferable().is() ||
607 0 == aDataHelper.GetFormatCount();
609 if( bDisable )
610 rSet.DisableItem(nWhich);
612 break;
614 nWhich = aIter.NextWhich();
618 /*--------------------------------------------------------------------
619 Beschreibung:
620 --------------------------------------------------------------------*/
623 SvxSearchItem* SwSrcView::GetSearchItem()
625 if(!pSearchItem)
627 pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
629 return pSearchItem;
632 /*--------------------------------------------------------------------
633 Beschreibung:
634 --------------------------------------------------------------------*/
637 void SwSrcView::SetSearchItem( const SvxSearchItem& rItem )
639 delete pSearchItem;
640 pSearchItem = (SvxSearchItem*)rItem.Clone();
643 /*--------------------------------------------------------------------
644 Beschreibung:
645 --------------------------------------------------------------------*/
648 USHORT SwSrcView::StartSearchAndReplace(const SvxSearchItem& rSearchItem,
649 BOOL bFromStart,
650 BOOL bApi,
651 BOOL bRecursive)
653 ExtTextView* pTextView = aEditWin.GetTextView();
654 TextSelection aSel;
655 TextPaM aPaM;
657 BOOL bForward = !rSearchItem.GetBackward();
658 BOOL bAtStart = pTextView->GetSelection() == TextSelection( aPaM, aPaM );
660 if( !bForward )
661 aPaM = TextPaM( (ULONG)-1, (USHORT)-1 );
663 if( bFromStart )
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() ) );
673 USHORT nFound;
674 BOOL bAll = FALSE;
675 switch( rSearchItem.GetCommand() )
677 case SVX_SEARCHCMD_FIND:
678 case SVX_SEARCHCMD_FIND_ALL:
679 nFound = pTextView->Search( aSearchOpt, bForward );
680 break;
682 case SVX_SEARCHCMD_REPLACE_ALL: bAll = TRUE;
683 case SVX_SEARCHCMD_REPLACE:
684 nFound = pTextView->Replace( aSearchOpt, bAll, bForward );
685 break;
687 default:
688 nFound = 0;
691 if( !nFound )
693 BOOL bNotFoundMessage = FALSE;
694 if(!bRecursive)
696 if(!bFromStart)
698 bNotFoundMessage = bAtStart;
700 else
702 bNotFoundMessage = TRUE;
703 pTextView->SetSelection( aSel );
706 else if(bAtStart)
708 bNotFoundMessage = TRUE;
712 if(!bApi)
713 if(bNotFoundMessage)
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 );
725 return nFound;
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();
749 return 0;
752 /*--------------------------------------------------------------------
753 Beschreibung:
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);
760 if ( !pPrinter )
761 pPrinter = pDocPrinter;
762 else if ( pDocPrinter != pPrinter )
764 pProgress->RestoreOnEndPrint( pDocPrinter->Clone() );
765 SetPrinter( pPrinter, SFX_PRINTER_PRINTER );
767 pProgress->SetWaitMode(FALSE);
769 // Drucker starten
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 );
801 USHORT nCurPage = 1;
803 BOOL bStartJob = pPrinter->StartJob( aTitle );
804 if( bStartJob )
806 pPrinter->StartPage();
807 // Header drucken...
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 ) )
821 nCurPage++;
822 pPrinter->EndPage();
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;
831 pPrinter->EndPage();
834 pPrinter->SetFont( aOldFont );
835 pPrinter->SetMapMode( eOldMapMode );
837 if ( !bStartJob )
839 // Printer konnte nicht gestartet werden
840 delete pProgress;
841 return ERRCODE_IO_ABORT;
844 pProgress->Stop();
845 pProgress->DeleteOnEndPrint();
846 pPrinter->EndJob();
847 return pPrinter->GetError();
850 /*--------------------------------------------------------------------
851 Beschreibung:
852 --------------------------------------------------------------------*/
855 SfxPrinter* SwSrcView::GetPrinter( BOOL bCreate )
857 return GetDocShell()->GetDoc()->getPrinter( bCreate );
860 /*--------------------------------------------------------------------
861 Beschreibung:
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 );
923 pStream->Seek(0);
924 TextEngine* pTextEngine = aEditWin.GetTextEngine();
925 pTextEngine->EnableUndo(FALSE);
926 aEditWin.Read(*pStream);//, EE_FORMAT_TEXT);
927 pTextEngine->EnableUndo(TRUE);
929 else
931 Window *pTmpWindow = &GetViewFrame()->GetWindow();
932 InfoBox(pTmpWindow, SW_RES(MSG_ERR_SRCSTREAM)).Execute();
935 else
937 utl::TempFile aTempFile;
938 aTempFile.EnableKillingFile();
939 String sFileURL( aTempFile.GetURL() );
940 SvtSaveOptions aOpt;
943 SfxMedium aMedium( sFileURL,STREAM_READWRITE, TRUE );
944 SwWriter aWriter( aMedium, *pDocShell->GetDoc() );
945 WriterRef xWriter;
946 ::GetHTMLWriter(aEmptyStr, aMedium.GetBaseURL( true ), xWriter);
947 String sWriteName = pDocShell->HasName() ?
948 pMedium->GetName() :
949 (const String&) sFileURL;
950 ULONG nRes = aWriter.Write(xWriter, &sWriteName);
951 if(nRes)
953 ErrorHandler::HandleError(ErrCode(nRes));
954 aEditWin.SetReadonly(TRUE);
956 aMedium.Commit();
957 SvStream* pInStream = aMedium.GetInStream();
958 pInStream->Seek(0);
959 pInStream->SetStreamCharSet( eDestEnc );
962 aEditWin.Read(*pInStream);//, EE_FORMAT_TEXT);
965 aEditWin.ClearModifyFlag();
967 eLoadEncoding = eDestEnc;
969 if(bDocModified)
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();