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 <svx/statusitem.hxx>
49#include <svl/srchitem.hxx>
50#include <sfx2/sfxhtml.hxx>
51#include <swtypes.hxx>
52#include <docsh.hxx>
53#include <wdocsh.hxx>
54#include <srcview.hxx>
55#include "viewfunc.hxx"
56#include <doc.hxx>
58#include <IDocumentState.hxx>
59#include <sfx2/msg.hxx>
60#include <shellio.hxx>
61
62#include <cmdid.h>
63#include <strings.hrc>
64#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
66#define ShellClass_SwSrcView
67#include <swslots.hxx>
68
69#include <com/sun/star/document/XDocumentProperties.hpp>
70#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
71
72using namespace ::com::sun::star;
73using namespace ::com::sun::star::i18n;
74using namespace ::com::sun::star::lang;
75using namespace ::com::sun::star::uno;
76using namespace ::com::sun::star::ui::dialogs;
77using namespace ::sfx2;
78
79#define SWSRCVIEWFLAGS SfxViewShellFlags::NO_NEWWINDOW
80
81#define SRC_SEARCHOPTIONS (SearchOptionFlags::ALL & ~SearchOptionFlags(SearchOptionFlags::FORMAT|SearchOptionFlags::FAMILIES|SearchOptionFlags::SEARCHALL))
82
83// Printing margins -> like Basic - Ide
84#define LMARGPRN 1700
85#define RMARGPRN 900
86#define TMARGPRN 2000
87#define BMARGPRN 1000
88#define BORDERPRN 300
89
91{
93}
94
96
97void SwSrcView::InitInterface_Impl()
98{
99 GetStaticInterface()->RegisterPopupMenu("source");
100
101 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_TOOLS,
102 SfxVisibilityFlags::Standard|SfxVisibilityFlags::Server,
103 ToolbarId::Webtools_Toolbox);
104
105 GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
106}
107
108
109static void lcl_PrintHeader( vcl::RenderContext &rOutDev, sal_Int32 nPages, sal_Int32 nCurPage, const OUString& rTitle )
110{
111 short nLeftMargin = LMARGPRN;
112 Size aSz = rOutDev.GetOutputSize();
113 short nBorder = BORDERPRN;
114
115 Color aOldFillColor( rOutDev.GetFillColor() );
116 vcl::Font aOldFont( rOutDev.GetFont() );
117
118 rOutDev.SetFillColor( COL_TRANSPARENT );
119
120 vcl::Font aFont( aOldFont );
121 aFont.SetWeight( WEIGHT_BOLD );
122 aFont.SetAlignment( ALIGN_BOTTOM );
123 rOutDev.SetFont( aFont );
124
125 tools::Long nFontHeight = rOutDev.GetTextHeight();
126
127 // 1.Border => Line, 2+3 Border = Space.
128 tools::Long nYTop = TMARGPRN-3*nBorder-nFontHeight;
129
131 tools::Long nXRight = aSz.Width()-RMARGPRN+nBorder;
132
133 rOutDev.DrawRect( tools::Rectangle(
134 Point( nXLeft, nYTop ),
135 Size( nXRight-nXLeft, aSz.Height() - nYTop - BMARGPRN + nBorder ) ) );
136
138 Point aPos( nLeftMargin, nY );
139 rOutDev.DrawText( aPos, rTitle );
140 if ( nPages != 1 )
141 {
142 aFont.SetWeight( WEIGHT_NORMAL );
143 rOutDev.SetFont( aFont );
144 OUString aPageStr = " [" + SwResId( STR_PAGE ) + " " + OUString::number( nCurPage ) + "]";
145 aPos.AdjustX(rOutDev.GetTextWidth( rTitle ) );
146 rOutDev.DrawText( aPos, aPageStr );
147 }
148
149 nY = TMARGPRN-nBorder;
150
151 rOutDev.DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
152
153 rOutDev.SetFont( aOldFont );
154 rOutDev.SetFillColor( aOldFillColor );
155}
156
157static rtl_TextEncoding lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding)
158{
159 rtl_TextEncoding eRet = eLoadEncoding;
160 if(RTL_TEXTENCODING_DONTKNOW == eRet)
161 {
162 eRet = RTL_TEXTENCODING_UTF8;
163 }
164 return eRet;
165}
166
167static OUString lcl_ConvertTabsToSpaces( const OUString& sLine )
168{
169 if (sLine.isEmpty())
170 return sLine;
171
172 OUString aRet = sLine;
173 const sal_Unicode aPadSpaces[4] = {' ', ' ', ' ', ' '};
174 sal_Int32 nPos = 0;
175 for (;;)
176 {
177 nPos = aRet.indexOf('\t', nPos);
178 if (nPos<0)
179 {
180 break;
181 }
182 // Not 4 blanks, but on 4th TabPos:
183 const sal_Int32 nPadLen = 4 - (nPos % 4);
184 aRet = aRet.replaceAt(nPos, 1, std::u16string_view{aPadSpaces, static_cast<size_t>(nPadLen)});
185 nPos += nPadLen;
186 }
187 return aRet;
188}
189
191 SfxViewShell( rViewFrame, SWSRCVIEWFLAGS ),
192 m_aEditWin( VclPtr<SwSrcEditWindow>::Create( &rViewFrame.GetWindow(), this ) ),
193 m_bSourceSaved(false),
194 m_eLoadEncoding(RTL_TEXTENCODING_DONTKNOW)
195{
196 Init();
197}
198
200{
201 SwDocShell* pDocShell = GetDocShell();
202 assert(dynamic_cast<SwWebDocShell*>( pDocShell) && "Why no WebDocShell?" );
203 const TextSelection& rSel = m_aEditWin->GetTextView()->GetSelection();
204 static_cast<SwWebDocShell*>(pDocShell)->SetSourcePara( static_cast< sal_uInt16 >( rSel.GetStart().GetPara() ) );
205
206 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
207 pDocShell->GetModel(), uno::UNO_QUERY_THROW);
208 uno::Reference<document::XDocumentProperties> xDocProps
209 = xDPS->getDocumentProperties();
210 OUString url = xDocProps->getAutoloadURL();
211 sal_Int32 delay = xDocProps->getAutoloadSecs();
212 pDocShell->SetAutoLoad(INetURLObject(url), delay,
213 (delay != 0) || !url.isEmpty());
214 EndListening(*pDocShell);
215 m_pSearchItem.reset();
216
218}
219
221{
222 SvStream* pOutStream = rMed.GetOutStream();
224 m_aEditWin->Write( *pOutStream );
225}
226
228{
229 SetName("Source");
231 SwDocShell* pDocShell = GetDocShell();
232 // If the doc is still loading, then the DocShell must fire up
233 // the Load if the loading is completed.
234 if(!pDocShell->IsLoading())
235 Load(pDocShell);
236 else
237 {
238 m_aEditWin->SetReadonly(true);
239 }
240
241 SetNewWindowAllowed( false );
242 StartListening(*pDocShell, DuplicateHandling::Prevent);
243}
244
246{
248 return dynamic_cast<SwDocShell*>( pObjShell );
249}
250
251void SwSrcView::SaveContent(const OUString& rTmpFile)
252{
253 SfxMedium aMedium( rTmpFile, StreamMode::WRITE);
254 SvStream* pOutStream = aMedium.GetOutStream();
256 m_aEditWin->Write(*pOutStream);
257 aMedium.Commit();
258}
259
261{
262 TextView* pTextView = m_aEditWin->GetTextView();
263 switch( rReq.GetSlot() )
264 {
265 case SID_SAVEACOPY:
266 case SID_SAVEASDOC:
267 {
268 // filesave dialog with autoextension
269 FileDialogHelper aDlgHelper(
270 TemplateDescription::FILESAVE_AUTOEXTENSION,
271 FileDialogFlags::NONE, m_aEditWin->GetFrameWeld());
272 uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
273
274 // search for an html filter for export
276 std::shared_ptr<const SfxFilter> pFilter =
277 pFilterCont->GetFilter4Extension( "html", SfxFilterFlags::EXPORT );
278 if ( pFilter )
279 {
280 // filter found -> use its uiname and wildcard
281 const OUString& rUIName = pFilter->GetUIName();
282 const WildCard& rCard = pFilter->GetWildcard();
283 xFP->appendFilter( rUIName, rCard.getGlob() );
284 xFP->setCurrentFilter( rUIName ) ;
285 }
286 else
287 {
288 // filter not found
289 OUString sHtml("HTML");
290 xFP->appendFilter( sHtml, "*.html;*.htm" );
291 xFP->setCurrentFilter( sHtml ) ;
292 }
293
294 if( aDlgHelper.Execute() == ERRCODE_NONE)
295 {
296 SfxMedium aMedium( xFP->getSelectedFiles().getConstArray()[0],
297 StreamMode::WRITE | StreamMode::SHARE_DENYNONE );
298 SvStream* pOutStream = aMedium.GetOutStream();
300 m_aEditWin->Write( *pOutStream );
301 aMedium.Commit();
302 }
303 }
304 break;
305 case SID_SAVEDOC:
306 {
307 SwDocShell* pDocShell = GetDocShell();
308 assert(pDocShell);
309 SfxMedium* pMed = nullptr;
310 if(pDocShell->HasName())
311 pMed = pDocShell->GetMedium();
312 else
313 {
314 const SfxBoolItem* pItem = static_cast<const SfxBoolItem*>(pDocShell->ExecuteSlot(rReq, pDocShell->GetInterface()));
315 if(pItem && pItem->GetValue())
316 pMed = pDocShell->GetMedium();
317 }
318 if(pMed)
319 {
320 SvStream* pOutStream = pMed->GetOutStream();
321 pOutStream->Seek(0);
322 pOutStream->SetStreamSize(0);
324 m_aEditWin->Write( *pOutStream );
325 pMed->CloseOutStream();
326 pMed->Commit();
327 pDocShell->GetDoc()->getIDocumentState().ResetModified();
328 m_bSourceSaved = true;
329 m_aEditWin->ClearModifyFlag();
330 }
331 }
332 break;
333 case FID_SEARCH_NOW:
334 {
335 const SfxItemSet* pTmpArgs = rReq.GetArgs();
336
337 const sal_uInt16 nWhich = pTmpArgs->GetWhichByPos( 0 );
338 OSL_ENSURE( nWhich, "Which for SearchItem ?" );
339 const SfxPoolItem& rItem = pTmpArgs->Get( nWhich );
340 SetSearchItem( static_cast<const SvxSearchItem&>(rItem));
341 StartSearchAndReplace( static_cast<const SvxSearchItem&>(rItem), rReq.IsAPI() );
342 if(m_aEditWin->IsModified())
343 {
344 SwDocShell* pDocShell = GetDocShell();
345 assert(pDocShell);
346 pDocShell->GetDoc()->getIDocumentState().SetModified();
347 }
348 }
349 break;
350 case FN_REPEAT_SEARCH:
351 {
352 SvxSearchItem* pSrchItem = GetSearchItem();
353 if(pSrchItem)
354 {
355 StartSearchAndReplace( *pSrchItem, rReq.IsAPI() );
356 if(m_aEditWin->IsModified())
358 }
359 }
360 break;
361 case SID_PRINTDOC:
362 case SID_PRINTDOCDIRECT:
363 {
365 }
366 break;
367 case SID_UNDO:
368 pTextView->Undo();
370 break;
371 case SID_REDO:
372 pTextView->Redo();
374 break;
375 case SID_REPEAT:
376 break;
377 case SID_CUT:
378 if(pTextView->HasSelection())
379 pTextView->Cut();
380 break;
381 case SID_COPY:
382 if(pTextView->HasSelection())
383 pTextView->Copy();
384 break;
385 case SID_PASTE:
386 pTextView->Paste();
387 break;
388 case SID_SELECTALL:
390 break;
391 }
392 m_aEditWin->Invalidate();
393}
394
396{
397 SfxWhichIter aIter(rSet);
398 sal_uInt16 nWhich = aIter.FirstWhich();
399 TextView* pTextView = m_aEditWin->GetTextView();
400
401 while(nWhich)
402 {
403 switch(nWhich)
404 {
405 case SID_SAVEASDOC:
406 rSet.Put(SfxStringItem(nWhich, SwResId(STR_SAVEAS_SRC)));
407 break;
408 case SID_SAVEACOPY:
409 rSet.Put(SfxStringItem(nWhich, SwResId(STR_SAVEACOPY_SRC)));
410 break;
411 case SID_SAVEDOC:
412 {
413 SwDocShell* pDocShell = GetDocShell();
414 assert(pDocShell);
415 if(!pDocShell->IsModified())
416 rSet.DisableItem(nWhich);
417 }
418 break;
419 case SID_PRINTDOC:
420 case SID_PRINTDOCDIRECT:
421 break;
422 case SID_TABLE_CELL:
423 {
424 TextSelection aSel = pTextView->GetSelection();
425 OUString aPos =
426 SwResId(STR_SRCVIEW_ROW)
427 + OUString::number( aSel.GetEnd().GetPara()+1 )
428 + " : "
429 + SwResId(STR_SRCVIEW_COL)
430 + OUString::number( aSel.GetEnd().GetIndex()+1 );
431 SvxStatusItem aItem( SID_TABLE_CELL, aPos, StatusCategory::RowColumn );
432 rSet.Put( aItem );
433 }
434 break;
435 case SID_SEARCH_OPTIONS:
436 {
438 SwDocShell* pDocShell = GetDocShell();
439 assert(pDocShell);
440 if (pDocShell->IsReadOnly())
441 nOpt &= ~SearchOptionFlags(SearchOptionFlags::REPLACE|SearchOptionFlags::REPLACE_ALL);
442
443 rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, static_cast<sal_uInt16>(nOpt) ) );
444 }
445 break;
446 case SID_SEARCH_ITEM:
447 {
448 OUString sSelected;
449 if ( !pTextView->HasSelection() )
450 {
451 const TextSelection& rSel = pTextView->GetSelection();
452 sSelected = m_aEditWin->GetTextEngine()->GetWord( rSel.GetStart());
453 }
454 else
455 {
456 sSelected = pTextView->GetSelected();
457 }
458 SvxSearchItem * pSrchItem = GetSearchItem();
459 pSrchItem->SetSearchString( sSelected );
460 rSet.Put( *pSrchItem );
461 }
462 break;
463 case FN_REPEAT_SEARCH:
464 {
465 if(!GetSearchItem())
466 rSet.DisableItem(nWhich);
467 }
468 break;
469 case SID_UNDO:
470 case SID_REDO:
471 {
472 SfxUndoManager& rMgr = pTextView->GetTextEngine()->GetUndoManager();
473 sal_uInt16 nCount = 0;
474 if(nWhich == SID_UNDO)
475 {
476 nCount = rMgr.GetUndoActionCount();
477 if(nCount)
478 {
479 OUString aStr = SvtResId( STR_UNDO) + rMgr.GetUndoActionComment(--nCount);
480 rSet.Put(SfxStringItem(nWhich, aStr));
481 }
482 else
483 rSet.DisableItem(nWhich);
484 }
485 else
486 {
487 nCount = rMgr.GetRedoActionCount();
488 if(nCount)
489 {
490 OUString aStr = SvtResId( STR_REDO) + rMgr.GetRedoActionComment(--nCount);
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, const ILibreOfficeKitNotifier *pNotifier=nullptr)
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
constexpr tools::Long Y() const
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
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
SfxViewFrame & GetViewFrame() const
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
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:701
virtual void SetModified(bool=true) override
Definition: docsh2.cxx:1437
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:408
IDocumentDeviceAccess const & getIDocumentDeviceAccess() const
Definition: doc.cxx:252
void GetState(SfxItemSet &)
Definition: srcview.cxx:395
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:245
void Init()
Definition: srcview.cxx:227
void SaveContent(const OUString &rTmpFile)
Definition: srcview.cxx:251
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:260
void SaveContentTo(SfxMedium &rMed)
Definition: srcview.cxx:220
VclPtr< SwSrcEditWindow > m_aEditWin
Definition: srcview.hxx:35
SwSrcView(SfxViewFrame &rFrame, SfxViewShell *)
Definition: srcview.cxx:190
virtual SfxPrinter * GetPrinter(bool bCreate=false) override
Definition: srcview.cxx:647
virtual ~SwSrcView() override
Definition: srcview.cxx:199
ErrCode Write(WriterRef const &rxWriter, const OUString *=nullptr)
Definition: shellio.cxx:745
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)
bool Search(const i18nutil::SearchOptions2 &rSearchOptions, bool bForward)
void Paste()
OUString GetSelected() const
void Cut()
void Redo()
void Copy()
const TextSelection & GetSelection() const
sal_uInt16 Replace(const i18nutil::SearchOptions2 &rSearchOptions, bool bAll, bool bForward)
void Undo()
TextEngine * GetTextEngine() const
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:175
#define FN_REPEAT_SEARCH
Definition: cmdid.h:112
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:748
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:86
static OUString lcl_ConvertTabsToSpaces(const OUString &sLine)
Definition: srcview.cxx:167
static rtl_TextEncoding lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding)
Definition: srcview.cxx:157
#define SRC_SEARCHOPTIONS
Definition: srcview.cxx:81
#define SWSRCVIEWFLAGS
Definition: srcview.cxx:79
#define LMARGPRN
Definition: srcview.cxx:84
#define RMARGPRN
Definition: srcview.cxx:85
SFX_IMPL_NAMED_VIEWFACTORY(SwSrcView, "SourceView")
Definition: srcview.cxx:90
static void lcl_PrintHeader(vcl::RenderContext &rOutDev, sal_Int32 nPages, sal_Int32 nCurPage, const OUString &rTitle)
Definition: srcview.cxx:109
#define BORDERPRN
Definition: srcview.cxx:88
#define BMARGPRN
Definition: srcview.cxx:87
css::lang::Locale Locale
SVT_DLLPUBLIC OUString SvtResId(TranslateId aId)
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
#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:1675