LibreOffice Module sw (master) 1
srcview.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <rtl/tencinfo.h>
21#include <osl/diagnose.h>
22#include <com/sun/star/frame/XModel.hpp>
23#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
24#include <unotools/tempfile.hxx>
25#include <tools/urlobj.hxx>
26#include <vcl/errinf.hxx>
27#include <vcl/weld.hxx>
28#include <vcl/textview.hxx>
29#include <vcl/svapp.hxx>
30#include <svl/intitem.hxx>
31#include <svl/stritem.hxx>
32#include <svl/undo.hxx>
33#include <svl/eitem.hxx>
34#include <svl/whiter.hxx>
35#include <vcl/transfer.hxx>
36#include <svtools/strings.hrc>
37#include <svtools/svtresid.hxx>
38#include <svtools/htmlcfg.hxx>
39#include <sfx2/app.hxx>
40#include <sfx2/objface.hxx>
41#include <sfx2/viewfrm.hxx>
42#include <sfx2/bindings.hxx>
43#include <sfx2/docfilt.hxx>
44#include <sfx2/fcontnr.hxx>
45#include <sfx2/request.hxx>
46#include <sfx2/docfile.hxx>
47#include <svx/srchdlg.hxx>
48#include <svl/srchitem.hxx>
49#include <sfx2/sfxhtml.hxx>
50#include <swtypes.hxx>
51#include <docsh.hxx>
52#include <wdocsh.hxx>
53#include <srcview.hxx>
54#include "viewfunc.hxx"
55#include <doc.hxx>
57#include <IDocumentState.hxx>
58#include <sfx2/msg.hxx>
59#include <shellio.hxx>
60
61#include <cmdid.h>
62#include <strings.hrc>
63#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
65#define ShellClass_SwSrcView
66#include <swslots.hxx>
67
68#include <com/sun/star/document/XDocumentProperties.hpp>
69#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
70
71using namespace ::com::sun::star;
72using namespace ::com::sun::star::i18n;
73using namespace ::com::sun::star::lang;
74using namespace ::com::sun::star::uno;
75using namespace ::com::sun::star::ui::dialogs;
76using namespace ::sfx2;
77
78#define SWSRCVIEWFLAGS SfxViewShellFlags::NO_NEWWINDOW
79
80#define SRC_SEARCHOPTIONS (SearchOptionFlags::ALL & ~SearchOptionFlags(SearchOptionFlags::FORMAT|SearchOptionFlags::FAMILIES|SearchOptionFlags::SEARCHALL))
81
82// Printing margins -> like Basic - Ide
83#define LMARGPRN 1700
84#define RMARGPRN 900
85#define TMARGPRN 2000
86#define BMARGPRN 1000
87#define BORDERPRN 300
88
90{
92}
93
95
96void SwSrcView::InitInterface_Impl()
97{
98 GetStaticInterface()->RegisterPopupMenu("source");
99
100 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_TOOLS,
101 SfxVisibilityFlags::Standard|SfxVisibilityFlags::Server,
102 ToolbarId::Webtools_Toolbox);
103
104 GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
105}
106
107
108static void lcl_PrintHeader( vcl::RenderContext &rOutDev, sal_Int32 nPages, sal_Int32 nCurPage, const OUString& rTitle )
109{
110 short nLeftMargin = LMARGPRN;
111 Size aSz = rOutDev.GetOutputSize();
112 short nBorder = BORDERPRN;
113
114 Color aOldFillColor( rOutDev.GetFillColor() );
115 vcl::Font aOldFont( rOutDev.GetFont() );
116
117 rOutDev.SetFillColor( COL_TRANSPARENT );
118
119 vcl::Font aFont( aOldFont );
120 aFont.SetWeight( WEIGHT_BOLD );
121 aFont.SetAlignment( ALIGN_BOTTOM );
122 rOutDev.SetFont( aFont );
123
124 tools::Long nFontHeight = rOutDev.GetTextHeight();
125
126 // 1.Border => Line, 2+3 Border = Space.
127 tools::Long nYTop = TMARGPRN-3*nBorder-nFontHeight;
128
130 tools::Long nXRight = aSz.Width()-RMARGPRN+nBorder;
131
132 rOutDev.DrawRect( tools::Rectangle(
133 Point( nXLeft, nYTop ),
134 Size( nXRight-nXLeft, aSz.Height() - nYTop - BMARGPRN + nBorder ) ) );
135
137 Point aPos( nLeftMargin, nY );
138 rOutDev.DrawText( aPos, rTitle );
139 if ( nPages != 1 )
140 {
141 aFont.SetWeight( WEIGHT_NORMAL );
142 rOutDev.SetFont( aFont );
143 OUString aPageStr = " [" + SwResId( STR_PAGE ) + " " + OUString::number( nCurPage ) + "]";
144 aPos.AdjustX(rOutDev.GetTextWidth( rTitle ) );
145 rOutDev.DrawText( aPos, aPageStr );
146 }
147
148 nY = TMARGPRN-nBorder;
149
150 rOutDev.DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
151
152 rOutDev.SetFont( aOldFont );
153 rOutDev.SetFillColor( aOldFillColor );
154}
155
156static rtl_TextEncoding lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding)
157{
158 rtl_TextEncoding eRet = eLoadEncoding;
159 if(RTL_TEXTENCODING_DONTKNOW == eRet)
160 {
161 eRet = RTL_TEXTENCODING_UTF8;
162 }
163 return eRet;
164}
165
166static OUString lcl_ConvertTabsToSpaces( const OUString& sLine )
167{
168 if (sLine.isEmpty())
169 return sLine;
170
171 OUString aRet = sLine;
172 const sal_Unicode aPadSpaces[4] = {' ', ' ', ' ', ' '};
173 sal_Int32 nPos = 0;
174 for (;;)
175 {
176 nPos = aRet.indexOf('\t', nPos);
177 if (nPos<0)
178 {
179 break;
180 }
181 // Not 4 blanks, but on 4th TabPos:
182 const sal_Int32 nPadLen = 4 - (nPos % 4);
183 aRet = aRet.replaceAt(nPos, 1, std::u16string_view{aPadSpaces, static_cast<size_t>(nPadLen)});
184 nPos += nPadLen;
185 }
186 return aRet;
187}
188
190 SfxViewShell( pViewFrame, SWSRCVIEWFLAGS ),
191 m_aEditWin( VclPtr<SwSrcEditWindow>::Create( &pViewFrame->GetWindow(), this ) ),
192 m_bSourceSaved(false),
193 m_eLoadEncoding(RTL_TEXTENCODING_DONTKNOW)
194{
195 Init();
196}
197
199{
200 SwDocShell* pDocShell = GetDocShell();
201 assert(dynamic_cast<SwWebDocShell*>( pDocShell) && "Why no WebDocShell?" );
202 const TextSelection& rSel = m_aEditWin->GetTextView()->GetSelection();
203 static_cast<SwWebDocShell*>(pDocShell)->SetSourcePara( static_cast< sal_uInt16 >( rSel.GetStart().GetPara() ) );
204
205 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
206 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
207 uno::Reference<document::XDocumentProperties> xDocProps
208 = xDPS->getDocumentProperties();
209 OUString url = xDocProps->getAutoloadURL();
210 sal_Int32 delay = xDocProps->getAutoloadSecs();
211 pDocShell->SetAutoLoad(INetURLObject(url), delay,
212 (delay != 0) || !url.isEmpty());
213 EndListening(*pDocShell);
214 m_pSearchItem.reset();
215
217}
218
220{
221 SvStream* pOutStream = rMed.GetOutStream();
223 m_aEditWin->Write( *pOutStream );
224}
225
227{
228 SetName("Source");
230 SwDocShell* pDocShell = GetDocShell();
231 // If the doc is still loading, then the DocShell must fire up
232 // the Load if the loading is completed.
233 if(!pDocShell->IsLoading())
234 Load(pDocShell);
235 else
236 {
237 m_aEditWin->SetReadonly(true);
238 }
239
240 SetNewWindowAllowed( false );
241 StartListening(*pDocShell, DuplicateHandling::Prevent);
242}
243
245{
247 return dynamic_cast<SwDocShell*>( pObjShell );
248}
249
250void SwSrcView::SaveContent(const OUString& rTmpFile)
251{
252 SfxMedium aMedium( rTmpFile, StreamMode::WRITE);
253 SvStream* pOutStream = aMedium.GetOutStream();
255 m_aEditWin->Write(*pOutStream);
256 aMedium.Commit();
257}
258
260{
261 TextView* pTextView = m_aEditWin->GetTextView();
262 switch( rReq.GetSlot() )
263 {
264 case SID_SAVEACOPY:
265 case SID_SAVEASDOC:
266 {
267 // filesave dialog with autoextension
268 FileDialogHelper aDlgHelper(
269 TemplateDescription::FILESAVE_AUTOEXTENSION,
270 FileDialogFlags::NONE, m_aEditWin->GetFrameWeld());
271 uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
272
273 // search for an html filter for export
275 std::shared_ptr<const SfxFilter> pFilter =
276 pFilterCont->GetFilter4Extension( "html", SfxFilterFlags::EXPORT );
277 if ( pFilter )
278 {
279 // filter found -> use its uiname and wildcard
280 const OUString& rUIName = pFilter->GetUIName();
281 const WildCard& rCard = pFilter->GetWildcard();
282 xFP->appendFilter( rUIName, rCard.getGlob() );
283 xFP->setCurrentFilter( rUIName ) ;
284 }
285 else
286 {
287 // filter not found
288 OUString sHtml("HTML");
289 xFP->appendFilter( sHtml, "*.html;*.htm" );
290 xFP->setCurrentFilter( sHtml ) ;
291 }
292
293 if( aDlgHelper.Execute() == ERRCODE_NONE)
294 {
295 SfxMedium aMedium( xFP->getSelectedFiles().getConstArray()[0],
296 StreamMode::WRITE | StreamMode::SHARE_DENYNONE );
297 SvStream* pOutStream = aMedium.GetOutStream();
299 m_aEditWin->Write( *pOutStream );
300 aMedium.Commit();
301 }
302 }
303 break;
304 case SID_SAVEDOC:
305 {
306 SwDocShell* pDocShell = GetDocShell();
307 assert(pDocShell);
308 SfxMedium* pMed = nullptr;
309 if(pDocShell->HasName())
310 pMed = pDocShell->GetMedium();
311 else
312 {
313 const SfxBoolItem* pItem = static_cast<const SfxBoolItem*>(pDocShell->ExecuteSlot(rReq, pDocShell->GetInterface()));
314 if(pItem && pItem->GetValue())
315 pMed = pDocShell->GetMedium();
316 }
317 if(pMed)
318 {
319 SvStream* pOutStream = pMed->GetOutStream();
320 pOutStream->Seek(0);
321 pOutStream->SetStreamSize(0);
323 m_aEditWin->Write( *pOutStream );
324 pMed->CloseOutStream();
325 pMed->Commit();
326 pDocShell->GetDoc()->getIDocumentState().ResetModified();
327 m_bSourceSaved = true;
328 m_aEditWin->ClearModifyFlag();
329 }
330 }
331 break;
332 case FID_SEARCH_NOW:
333 {
334 const SfxItemSet* pTmpArgs = rReq.GetArgs();
335
336 const sal_uInt16 nWhich = pTmpArgs->GetWhichByPos( 0 );
337 OSL_ENSURE( nWhich, "Which for SearchItem ?" );
338 const SfxPoolItem& rItem = pTmpArgs->Get( nWhich );
339 SetSearchItem( static_cast<const SvxSearchItem&>(rItem));
340 StartSearchAndReplace( static_cast<const SvxSearchItem&>(rItem), rReq.IsAPI() );
341 if(m_aEditWin->IsModified())
342 {
343 SwDocShell* pDocShell = GetDocShell();
344 assert(pDocShell);
345 pDocShell->GetDoc()->getIDocumentState().SetModified();
346 }
347 }
348 break;
349 case FN_REPEAT_SEARCH:
350 {
351 SvxSearchItem* pSrchItem = GetSearchItem();
352 if(pSrchItem)
353 {
354 StartSearchAndReplace( *pSrchItem, rReq.IsAPI() );
355 if(m_aEditWin->IsModified())
357 }
358 }
359 break;
360 case SID_PRINTDOC:
361 case SID_PRINTDOCDIRECT:
362 {
364 }
365 break;
366 case SID_UNDO:
367 pTextView->Undo();
369 break;
370 case SID_REDO:
371 pTextView->Redo();
373 break;
374 case SID_REPEAT:
375 break;
376 case SID_CUT:
377 if(pTextView->HasSelection())
378 pTextView->Cut();
379 break;
380 case SID_COPY:
381 if(pTextView->HasSelection())
382 pTextView->Copy();
383 break;
384 case SID_PASTE:
385 pTextView->Paste();
386 break;
387 case SID_SELECTALL:
389 break;
390 }
391 m_aEditWin->Invalidate();
392}
393
395{
396 SfxWhichIter aIter(rSet);
397 sal_uInt16 nWhich = aIter.FirstWhich();
398 TextView* pTextView = m_aEditWin->GetTextView();
399
400 while(nWhich)
401 {
402 switch(nWhich)
403 {
404 case SID_SAVEASDOC:
405 rSet.Put(SfxStringItem(nWhich, SwResId(STR_SAVEAS_SRC)));
406 break;
407 case SID_SAVEACOPY:
408 rSet.Put(SfxStringItem(nWhich, SwResId(STR_SAVEACOPY_SRC)));
409 break;
410 case SID_SAVEDOC:
411 {
412 SwDocShell* pDocShell = GetDocShell();
413 assert(pDocShell);
414 if(!pDocShell->IsModified())
415 rSet.DisableItem(nWhich);
416 }
417 break;
418 case SID_PRINTDOC:
419 case SID_PRINTDOCDIRECT:
420 break;
421 case SID_TABLE_CELL:
422 {
423 OUString aPos( SwResId(STR_SRCVIEW_ROW) );
424 TextSelection aSel = pTextView->GetSelection();
425 aPos += OUString::number( aSel.GetEnd().GetPara()+1 );
426 aPos += " : " +
427 SwResId(STR_SRCVIEW_COL);
428 aPos += OUString::number( aSel.GetEnd().GetIndex()+1 );
429 SfxStringItem aItem( nWhich, aPos );
430 rSet.Put( aItem );
431 }
432 break;
433 case SID_SEARCH_OPTIONS:
434 {
436 SwDocShell* pDocShell = GetDocShell();
437 assert(pDocShell);
438 if (pDocShell->IsReadOnly())
439 nOpt &= ~SearchOptionFlags(SearchOptionFlags::REPLACE|SearchOptionFlags::REPLACE_ALL);
440
441 rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, static_cast<sal_uInt16>(nOpt) ) );
442 }
443 break;
444 case SID_SEARCH_ITEM:
445 {
446 OUString sSelected;
447 if ( !pTextView->HasSelection() )
448 {
449 const TextSelection& rSel = pTextView->GetSelection();
450 sSelected = m_aEditWin->GetTextEngine()->GetWord( rSel.GetStart());
451 }
452 else
453 {
454 sSelected = pTextView->GetSelected();
455 }
456 SvxSearchItem * pSrchItem = GetSearchItem();
457 pSrchItem->SetSearchString( sSelected );
458 rSet.Put( *pSrchItem );
459 }
460 break;
461 case FN_REPEAT_SEARCH:
462 {
463 if(!GetSearchItem())
464 rSet.DisableItem(nWhich);
465 }
466 break;
467 case SID_UNDO:
468 case SID_REDO:
469 {
470 SfxUndoManager& rMgr = pTextView->GetTextEngine()->GetUndoManager();
471 sal_uInt16 nCount = 0;
472 if(nWhich == SID_UNDO)
473 {
474 nCount = rMgr.GetUndoActionCount();
475 if(nCount)
476 {
477 OUString aStr(SvtResId( STR_UNDO));
479 rSet.Put(SfxStringItem(nWhich, aStr));
480 }
481 else
482 rSet.DisableItem(nWhich);
483 }
484 else
485 {
486 nCount = rMgr.GetRedoActionCount();
487 if(nCount)
488 {
489 OUString aStr(SvtResId( STR_REDO));
491 rSet.Put(SfxStringItem(nWhich,aStr));
492 }
493 else
494 rSet.DisableItem(nWhich);
495 }
496 }
497 break;
498 case SID_MAIL_SENDDOCASPDF:
499 case SID_MAIL_SENDDOC :
500 case SID_EXPORTDOCASPDF:
501 case SID_DIRECTEXPORTDOCASPDF:
502 case SID_EXPORTDOC:
503 case SID_REPEAT:
504 case SID_BROWSER_MODE:
505 case FN_PRINT_LAYOUT:
506 rSet.DisableItem(nWhich);
507 break;
508 case SID_CUT:
509 case SID_COPY:
510 if(!pTextView->HasSelection())
511 rSet.DisableItem(nWhich);
512 break;
513 case SID_PASTE:
514 {
515 TransferableDataHelper aDataHelper(
517 m_aEditWin.get()) );
518 bool bDisable = !aDataHelper.GetXTransferable().is() ||
519 0 == aDataHelper.GetFormatCount();
520 if( bDisable )
521 rSet.DisableItem(nWhich);
522 }
523 break;
524 }
525 nWhich = aIter.NextWhich();
526 }
527}
528
530{
531 if(!m_pSearchItem)
532 {
533 m_pSearchItem.reset(new SvxSearchItem(SID_SEARCH_ITEM));
534 }
535 return m_pSearchItem.get();
536}
537
539{
540 m_pSearchItem.reset(rItem.Clone());
541}
542
544 bool bApi,
545 bool bRecursive)
546{
547 TextView* pTextView = m_aEditWin->GetTextView();
548 TextPaM aPaM;
549
550 bool bForward = !rSearchItem.GetBackward();
551 bool bAtStart = pTextView->GetSelection() == TextSelection( aPaM, aPaM );
552
553 if( !bForward )
555
556 i18nutil::SearchOptions2 aSearchOpt( rSearchItem.GetSearchOptions() );
557 aSearchOpt.Locale = GetAppLanguageTag().getLocale();
558
559 sal_uInt16 nFound;
560 bool bAll = false;
561 switch( rSearchItem.GetCommand() )
562 {
563 case SvxSearchCmd::FIND:
564 case SvxSearchCmd::FIND_ALL:
565 nFound = pTextView->Search( aSearchOpt, bForward ) ? 1 : 0;
566 break;
567
568 case SvxSearchCmd::REPLACE_ALL: bAll = true;
569 [[fallthrough]];
570 case SvxSearchCmd::REPLACE:
571 nFound = pTextView->Replace( aSearchOpt, bAll, bForward );
572 break;
573
574 default:
575 nFound = 0;
576 }
577
578 if( nFound )
579 return;
580
581 bool bNotFoundMessage = false;
582 if(!bRecursive)
583 {
584 bNotFoundMessage = bAtStart;
585 }
586 else if(bAtStart)
587 {
588 bNotFoundMessage = true;
589 }
590
591 if(bApi)
592 return;
593
594 if(bNotFoundMessage)
595 {
596 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "modules/swriter/ui/infonotfounddialog.ui"));
597 std::unique_ptr<weld::MessageDialog> xInfoBox(xBuilder->weld_message_dialog("InfoNotFoundDialog"));
598 xInfoBox->run();
599 }
600 else if(!bRecursive)
601 {
602 int nRet;
603
604 if (!bForward)
605 {
606 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "modules/swriter/ui/querycontinueenddialog.ui"));
607 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("QueryContinueEndDialog"));
608 nRet = xQueryBox->run();
609 }
610 else
611 {
612 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "modules/swriter/ui/querycontinuebegindialog.ui"));
613 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("QueryContinueBeginDialog"));
614 nRet = xQueryBox->run();
615 }
616
617 if (nRet == RET_YES)
618 {
619 pTextView->SetSelection( TextSelection( aPaM, aPaM ) );
620 StartSearchAndReplace( rSearchItem, false, true );
621 }
622 }
623}
624
626{
627 SwDocShell* pDocSh = GetDocShell();
628 assert(pDocSh);
629 if ( (SfxPrinterChangeFlags::JOBSETUP | SfxPrinterChangeFlags::PRINTER) & nDiffFlags )
630 {
631 pDocSh->GetDoc()->getIDocumentDeviceAccess().setPrinter( pNew, true, true );
632 if ( nDiffFlags & SfxPrinterChangeFlags::PRINTER )
633 pDocSh->SetModified();
634 }
635 if ( nDiffFlags & SfxPrinterChangeFlags::OPTIONS )
636 ::SetPrinter( &pDocSh->getIDocumentDeviceAccess(), pNew, true );
637
638 const bool bChgOri = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION);
639 const bool bChgSize = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE);
640 if ( bChgOri || bChgSize )
641 {
642 pDocSh->SetModified();
643 }
644 return 0;
645}
646
648{
649 SwDocShell* pDocSh = GetDocShell();
650 assert(pDocSh);
651 return pDocSh->GetDoc()->getIDocumentDeviceAccess().getPrinter(bCreate);
652}
653
655 OutputDevice *pOutDev,
656 sal_Int32 nPage,
657 bool bCalcNumPagesOnly )
658{
659 if (!pOutDev || nPage <= 0)
660 return 0;
661
666
667 pOutDev->Push();
668
669 TextEngine* pTextEngine = m_aEditWin->GetTextEngine();
670 pOutDev->SetMapMode(MapMode(MapUnit::Map100thMM));
671 vcl::Font aFont( m_aEditWin->GetOutWin()->GetFont() );
672 Size aSize( aFont.GetFontSize() );
673 aSize = m_aEditWin->GetOutWin()->PixelToLogic(aSize, MapMode(MapUnit::Map100thMM));
674 aFont.SetFontSize( aSize );
675 aFont.SetColor( COL_BLACK );
676 pOutDev->SetFont( aFont );
677
678 OUString aTitle( GetViewFrame()->GetWindow().GetText() );
679
680 const tools::Long nLineHeight = pOutDev->GetTextHeight(); // slightly more
681 const tools::Long nParaSpace = 10;
682
683 Size aPaperSz = pOutDev->GetOutputSize();
684 aPaperSz.AdjustWidth( -(LMARGPRN + RMARGPRN) );
685 aPaperSz.AdjustHeight( -(TMARGPRN + BMARGPRN) );
686
687 // nLinepPage is not true, if lines have to be wrapped...
688 const tools::Long nLinespPage = nLineHeight ? aPaperSz.Height() / nLineHeight : 1;
689 const tools::Long nCharWidth = pOutDev->GetTextWidth("X");
690 const sal_Int32 nCharspLine = nCharWidth ? static_cast<sal_Int32>(aPaperSz.Width() / nCharWidth) : 1;
691 const sal_uInt32 nParas = pTextEngine->GetParagraphCount();
692
693 const sal_Int32 nPages = static_cast<sal_Int32>(nParas / nLinespPage + 1 );
694 sal_Int32 nCurPage = 1;
695
696 // Print header...
697 if (!bCalcNumPagesOnly && nPage == nCurPage)
698 lcl_PrintHeader( *pOutDev, nPages, nCurPage, aTitle );
699 const Point aStartPos( LMARGPRN, TMARGPRN );
700 Point aPos( aStartPos );
701 for ( sal_uInt32 nPara = 0; nPara < nParas; ++nPara )
702 {
703 const OUString aLine( lcl_ConvertTabsToSpaces(pTextEngine->GetText( nPara )) );
704 const sal_Int32 nLineLen = aLine.getLength();
705 const sal_Int32 nLines = (nLineLen+nCharspLine-1) / nCharspLine;
706 for ( sal_Int32 nLine = 0; nLine < nLines; ++nLine )
707 {
708 aPos.AdjustY(nLineHeight );
709 if ( aPos.Y() > ( aPaperSz.Height() + TMARGPRN - nLineHeight/2 ) )
710 {
711 ++nCurPage;
712 if (!bCalcNumPagesOnly && nPage == nCurPage)
713 lcl_PrintHeader( *pOutDev, nPages, nCurPage, aTitle );
714 aPos = aStartPos;
715 }
716 if (!bCalcNumPagesOnly && nPage == nCurPage)
717 {
718 const sal_Int32 nStart = nLine * nCharspLine;
719 const sal_Int32 nLen = std::min(nLineLen-nStart, nCharspLine);
720 pOutDev->DrawText( aPos, aLine.copy(nStart, nLen) );
721 }
722 }
723 aPos.AdjustY(nParaSpace );
724 }
725
726 pOutDev->Pop();
727
728 OSL_ENSURE( bCalcNumPagesOnly || nPage <= nCurPage, "page number out of range" );
729 return nCurPage;
730}
731
732void SwSrcView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
733{
734 if (rHint.GetId() == SfxHintId::ModeChanged || rHint.GetId() == SfxHintId::TitleChanged)
735 {
736 const SwDocShell* pDocSh = GetDocShell();
737 assert(pDocSh);
738 if (!(rHint.GetId() == SfxHintId::TitleChanged
739 && (pDocSh->IsReadOnly() || !m_aEditWin->IsReadonly())))
740 {
741 // Broadcast only comes once!
742 const bool bReadonly = pDocSh->IsReadOnly();
743 m_aEditWin->SetReadonly(bReadonly);
744 }
745 }
746 SfxViewShell::Notify(rBC, rHint);
747}
748
750{
751 rtl_TextEncoding eDestEnc = RTL_TEXTENCODING_UTF8;
752
753 m_aEditWin->SetReadonly(pDocShell->IsReadOnly());
754 m_aEditWin->SetTextEncoding(eDestEnc);
755 SfxMedium* pMedium = pDocShell->GetMedium();
756
757 std::shared_ptr<const SfxFilter> pFilter = pMedium->GetFilter();
758 bool bHtml = pFilter && pFilter->GetUserData() == "HTML";
759 bool bDocModified = pDocShell->IsModified();
760 if(bHtml && !bDocModified && pDocShell->HasName())
761 {
762 SvStream* pStream = pMedium->GetInStream();
763 if(pStream && ERRCODE_NONE == pStream->GetError() )
764 {
765 rtl_TextEncoding eHeaderEnc =
766 SfxHTMLParser::GetEncodingByHttpHeader(
767 pDocShell->GetHeaderAttributes() );
768 if( RTL_TEXTENCODING_DONTKNOW == eHeaderEnc )
769 {
770 const char *pTmpCharSet =
771 rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1 );
772 eHeaderEnc = rtl_getTextEncodingFromMimeCharset( pTmpCharSet );
773 }
774 if( RTL_TEXTENCODING_DONTKNOW != eHeaderEnc &&
775 eDestEnc != eHeaderEnc )
776 {
777 eDestEnc = eHeaderEnc;
778 m_aEditWin->SetTextEncoding(eDestEnc);
779 }
780 pStream->SetStreamCharSet( eDestEnc );
781 pStream->Seek(0);
782 TextEngine* pTextEngine = m_aEditWin->GetTextEngine();
783 pTextEngine->EnableUndo(false);
784 m_aEditWin->Read(*pStream);
785 pTextEngine->EnableUndo(true);
786 }
787 else
788 {
789 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetViewFrame()->GetFrameWeld(),
790 VclMessageType::Info, VclButtonsType::Ok,
791 SwResId(STR_ERR_SRCSTREAM)));
792 xBox->run();
793 }
794 }
795 else
796 {
797 utl::TempFileNamed aTempFile;
798 aTempFile.EnableKillingFile();
799 const OUString sFileURL( aTempFile.GetURL() );
800
801 {
802 SfxMedium aMedium( sFileURL,StreamMode::READWRITE );
803 SwWriter aWriter( aMedium, *pDocShell->GetDoc() );
804 WriterRef xWriter;
805 ::GetHTMLWriter(std::u16string_view(), aMedium.GetBaseURL( true ), xWriter);
806 const OUString sWriteName = pDocShell->HasName()
807 ? pMedium->GetName()
808 : sFileURL;
809 ErrCode nRes = aWriter.Write(xWriter, &sWriteName);
810 if(nRes)
811 {
813 m_aEditWin->SetReadonly(true);
814 }
815 aMedium.Commit();
816 SvStream* pInStream = aMedium.GetInStream();
817 pInStream->Seek(0);
818 pInStream->SetStreamCharSet( eDestEnc );
819
820 m_aEditWin->Read(*pInStream);
821 }
822 }
823 m_aEditWin->ClearModifyFlag();
824
825 m_eLoadEncoding = eDestEnc;
826
827 if(bDocModified)
828 pDocShell->SetModified();// The flag will be reset in between times.
829 // Disable AutoLoad
830 pDocShell->SetAutoLoad(INetURLObject(), 0, false);
831 assert(dynamic_cast<SwWebDocShell*>( pDocShell) && "Why no WebDocShell?" );
832 sal_uInt16 nLine = static_cast<SwWebDocShell*>(pDocShell)->GetSourcePara();
833 m_aEditWin->SetStartLine(nLine);
834 m_aEditWin->GetTextEngine()->ResetUndo();
835 m_aEditWin->GetOutWin()->GrabFocus();
836}
837
838/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
virtual SfxPrinter * getPrinter(bool bCreate) const =0
Return the printer set at the document.
virtual void setPrinter(SfxPrinter *pP, bool bDeleteOld, bool bCallPrtDataChanged)=0
Set the printer at the document.
virtual void ResetModified()=0
virtual void SetModified()=0
Must be called manually at changes of format.
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
Size GetOutputSize() const
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
void SetMapMode()
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
void SetFillColor()
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
tools::Long GetTextHeight() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const Color & GetFillColor() const
void InvalidateAll(bool bWithMsg)
bool GetValue() const
std::shared_ptr< const SfxFilter > GetFilter4Extension(const OUString &rExt, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
SfxHintId GetId() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void DisableItem(sal_uInt16 nWhich)
sal_uInt16 GetWhichByPos(sal_uInt16 nPos) const
const std::shared_ptr< const SfxFilter > & GetFilter() const
OUString GetBaseURL(bool bForSaving=false)
void CloseOutStream()
const OUString & GetName() const
SvStream * GetOutStream()
SvStream * GetInStream()
bool Commit()
SfxFilterContainer * GetFilterContainer() const
void SetAutoLoad(const INetURLObject &, sal_uInt32 nTime, bool bReload)
bool HasName() const
virtual SfxObjectFactory & GetFactory() const=0
bool IsReadOnly() const
bool IsLoading() const
bool IsModified() const
SvKeyValueIterator * GetHeaderAttributes()
SfxMedium * GetMedium() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
bool IsAPI() const
virtual SfxInterface * GetInterface() const
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
void SetName(const OUString &rName)
OUString GetRedoActionComment(size_t nNo=0, bool const i_currentLevel=CurrentLevel) const
OUString GetUndoActionComment(size_t nNo=0, bool const i_currentLevel=CurrentLevel) const
virtual size_t GetRedoActionCount(bool const i_currentLevel=CurrentLevel) const
virtual size_t GetUndoActionCount(bool const i_currentLevel=CurrentLevel) const
SfxBindings & GetBindings()
virtual SfxObjectShell * GetObjectShell() override
weld::Window * GetFrameWeld() const
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
SfxViewFrame * GetViewFrame() const
virtual SfxObjectShell * GetObjectShell() override
void SetNewWindowAllowed(bool bSet)
void SetWindow(vcl::Window *pViewPort)
vcl::Window * GetWindow() const
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
tools::Long AdjustWidth(tools::Long n)
constexpr tools::Long Width() const
bool SetStreamSize(sal_uInt64 nSize)
sal_uInt64 Seek(sal_uInt64 nPos)
void SetStreamCharSet(rtl_TextEncoding eCharSet)
ErrCode GetError() const
SvxSearchCmd GetCommand() const
const i18nutil::SearchOptions2 & GetSearchOptions() const
virtual SvxSearchItem * Clone(SfxItemPool *pPool=nullptr) const override
void SetSearchString(const OUString &rNewString)
bool GetBackward() const
IDocumentDeviceAccess & getIDocumentDeviceAccess()
Definition: docshini.cxx:695
virtual void SetModified(bool=true) override
Definition: docsh2.cxx:1429
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:400
IDocumentDeviceAccess const & getIDocumentDeviceAccess() const
Definition: doc.cxx:244
void GetState(SfxItemSet &)
Definition: srcview.cxx:394
SvxSearchItem * GetSearchItem()
Definition: srcview.cxx:529
void SetSearchItem(const SvxSearchItem &rItem)
Definition: srcview.cxx:538
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: srcview.cxx:732
rtl_TextEncoding m_eLoadEncoding
Definition: srcview.hxx:40
std::unique_ptr< SvxSearchItem > m_pSearchItem
Definition: srcview.hxx:37
sal_Int32 PrintSource(OutputDevice *pOutDev, sal_Int32 nPage, bool bCalcNumPagesOnly)
Definition: srcview.cxx:654
SwDocShell * GetDocShell()
Definition: srcview.cxx:244
void Init()
Definition: srcview.cxx:226
void SaveContent(const OUString &rTmpFile)
Definition: srcview.cxx:250
void Load(SwDocShell *pDocShell)
Definition: srcview.cxx:749
bool m_bSourceSaved
Definition: srcview.hxx:39
virtual sal_uInt16 SetPrinter(SfxPrinter *pNew, SfxPrinterChangeFlags nDiff=SFX_PRINTER_ALL) override
Definition: srcview.cxx:625
void StartSearchAndReplace(const SvxSearchItem &rItem, bool bApi, bool bRecursive=false)
Definition: srcview.cxx:543
void Execute(SfxRequest &)
Definition: srcview.cxx:259
void SaveContentTo(SfxMedium &rMed)
Definition: srcview.cxx:219
VclPtr< SwSrcEditWindow > m_aEditWin
Definition: srcview.hxx:35
virtual SfxPrinter * GetPrinter(bool bCreate=false) override
Definition: srcview.cxx:647
SwSrcView(SfxViewFrame *pFrame, SfxViewShell *)
Definition: srcview.cxx:189
virtual ~SwSrcView() override
Definition: srcview.cxx:198
ErrCode Write(WriterRef const &rxWriter, const OUString *=nullptr)
Definition: shellio.cxx:739
SfxUndoManager & GetUndoManager()
OUString GetText(LineEnd aSeparator=LINEEND_LF) const
sal_uInt32 GetParagraphCount() const
void EnableUndo(bool bEnable)
sal_uInt32 GetPara() const
sal_Int32 GetIndex() const
const TextPaM & GetStart() const
const TextPaM & GetEnd() const
void SetSelection(const TextSelection &rNewSel)
void Paste()
OUString GetSelected() const
void Cut()
void Redo()
void Copy()
const TextSelection & GetSelection() const
bool Search(const i18nutil::SearchOptions &rSearchOptions, bool bForward)
void Undo()
TextEngine * GetTextEngine() const
sal_uInt16 Replace(const i18nutil::SearchOptions &rSearchOptions, bool bAll, bool bForward)
bool HasSelection() const
sal_uInt32 GetFormatCount() const
static TransferableDataHelper CreateFromSystemClipboard(vcl::Window *pWindow)
css::uno::Reference< css::datatransfer::XTransferable > GetXTransferable() const
void disposeAndClear()
reference_type * get() const
const OUString & getGlob() const
void EnableKillingFile(bool bEnable=true)
OUString const & GetURL() const
void SetFontSize(const Size &)
void SetColor(const Color &)
void SetWeight(FontWeight)
const Size & GetFontSize() const
void SetAlignment(TextAlign)
#define FN_PRINT_LAYOUT
Definition: cmdid.h:170
#define FN_REPEAT_SEARCH
Definition: cmdid.h:110
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
int nCount
SFX_IMPL_SUPERCLASS_INTERFACE(DrawDocShell, SfxObjectShell)
#define ERRCODE_NONE
ALIGN_BOTTOM
WEIGHT_BOLD
WEIGHT_NORMAL
const LanguageTag & GetAppLanguageTag()
Definition: init.cxx:732
sal_uInt16 nPos
aStr
tools::Long const nBorder
tools::Long const nLeftMargin
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
Definition: legacyitem.cxx:32
long Long
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
#define SFX_OBJECTBAR_TOOLS
static SfxItemSet & rSet
SearchOptionFlags
#define TMARGPRN
Definition: srcview.cxx:85
static OUString lcl_ConvertTabsToSpaces(const OUString &sLine)
Definition: srcview.cxx:166
static rtl_TextEncoding lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding)
Definition: srcview.cxx:156
#define SRC_SEARCHOPTIONS
Definition: srcview.cxx:80
#define SWSRCVIEWFLAGS
Definition: srcview.cxx:78
#define LMARGPRN
Definition: srcview.cxx:83
#define RMARGPRN
Definition: srcview.cxx:84
SFX_IMPL_NAMED_VIEWFACTORY(SwSrcView, "SourceView")
Definition: srcview.cxx:89
static void lcl_PrintHeader(vcl::RenderContext &rOutDev, sal_Int32 nPages, sal_Int32 nCurPage, const OUString &rTitle)
Definition: srcview.cxx:108
#define BORDERPRN
Definition: srcview.cxx:87
#define BMARGPRN
Definition: srcview.cxx:86
css::lang::Locale Locale
SVT_DLLPUBLIC OUString SvtResId(TranslateId aId)
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165
#define TEXT_INDEX_ALL
#define TEXT_PARA_ALL
sal_uInt16 sal_Unicode
RET_YES
SfxPrinterChangeFlags
#define SFX_VIEW_REGISTRATION(DocClass)
void GetHTMLWriter(std::u16string_view rFilterOptions, const OUString &rBaseURL, WriterRef &xRet)
Definition: wrthtml.cxx:1659