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>
36#include <svtools/strings.hrc>
64#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
66#define ShellClass_SwSrcView
69#include <com/sun/star/document/XDocumentProperties.hpp>
70#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
77using namespace ::
sfx2;
79#define SWSRCVIEWFLAGS SfxViewShellFlags::NO_NEWWINDOW
81#define SRC_SEARCHOPTIONS (SearchOptionFlags::ALL & ~SearchOptionFlags(SearchOptionFlags::FORMAT|SearchOptionFlags::FAMILIES|SearchOptionFlags::SEARCHALL))
99 GetStaticInterface()->RegisterPopupMenu(
"source");
102 SfxVisibilityFlags::Standard|SfxVisibilityFlags::Server,
103 ToolbarId::Webtools_Toolbox);
105 GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
134 Point( nXLeft, nYTop ),
144 OUString aPageStr =
" [" +
SwResId( STR_PAGE ) +
" " + OUString::number( nCurPage ) +
"]";
159 rtl_TextEncoding eRet = eLoadEncoding;
160 if(RTL_TEXTENCODING_DONTKNOW == eRet)
162 eRet = RTL_TEXTENCODING_UTF8;
172 OUString aRet = sLine;
173 const sal_Unicode aPadSpaces[4] = {
' ',
' ',
' ',
' '};
183 const sal_Int32 nPadLen = 4 - (
nPos % 4);
184 aRet = aRet.replaceAt(
nPos, 1, std::u16string_view{aPadSpaces,
static_cast<size_t>(nPadLen)});
193 m_bSourceSaved(false),
194 m_eLoadEncoding(RTL_TEXTENCODING_DONTKNOW)
202 assert(
dynamic_cast<SwWebDocShell*
>( pDocShell) &&
"Why no WebDocShell?" );
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();
213 (delay != 0) || !url.isEmpty());
214 EndListening(*pDocShell);
248 return dynamic_cast<SwDocShell*
>( pObjShell );
253 SfxMedium aMedium( rTmpFile, StreamMode::WRITE);
269 FileDialogHelper aDlgHelper(
270 TemplateDescription::FILESAVE_AUTOEXTENSION,
271 FileDialogFlags::NONE,
m_aEditWin->GetFrameWeld());
272 uno::Reference < XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
276 std::shared_ptr<const SfxFilter> pFilter =
281 const OUString& rUIName = pFilter->GetUIName();
282 const WildCard& rCard = pFilter->GetWildcard();
283 xFP->appendFilter( rUIName, rCard.
getGlob() );
284 xFP->setCurrentFilter( rUIName ) ;
289 OUString sHtml(
"HTML");
290 xFP->appendFilter( sHtml,
"*.html;*.htm" );
291 xFP->setCurrentFilter( sHtml ) ;
296 SfxMedium aMedium( xFP->getSelectedFiles().getConstArray()[0],
297 StreamMode::WRITE | StreamMode::SHARE_DENYNONE );
338 OSL_ENSURE( nWhich,
"Which for SearchItem ?" );
362 case SID_PRINTDOCDIRECT:
420 case SID_PRINTDOCDIRECT:
424 OUString aPos(
SwResId(STR_SRCVIEW_ROW) );
430 SvxStatusItem aItem( SID_TABLE_CELL, aPos, StatusCategory::RowColumn );
434 case SID_SEARCH_OPTIONS:
440 nOpt &=
~SearchOptionFlags(SearchOptionFlags::REPLACE|SearchOptionFlags::REPLACE_ALL);
445 case SID_SEARCH_ITEM:
473 if(nWhich == SID_UNDO)
499 case SID_MAIL_SENDDOCASPDF:
500 case SID_MAIL_SENDDOC :
501 case SID_EXPORTDOCASPDF:
502 case SID_DIRECTEXPORTDOCASPDF:
505 case SID_BROWSER_MODE:
564 case SvxSearchCmd::FIND:
565 case SvxSearchCmd::FIND_ALL:
566 nFound = pTextView->
Search( aSearchOpt, bForward ) ? 1 : 0;
569 case SvxSearchCmd::REPLACE_ALL: bAll =
true;
571 case SvxSearchCmd::REPLACE:
572 nFound = pTextView->
Replace( aSearchOpt, bAll, bForward );
582 bool bNotFoundMessage =
false;
585 bNotFoundMessage = bAtStart;
589 bNotFoundMessage =
true;
598 std::unique_ptr<weld::MessageDialog> xInfoBox(xBuilder->weld_message_dialog(
"InfoNotFoundDialog"));
608 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog(
"QueryContinueEndDialog"));
609 nRet = xQueryBox->run();
613 std::unique_ptr<weld::Builder> xBuilder(
Application::CreateBuilder(
nullptr,
"modules/swriter/ui/querycontinuebegindialog.ui"));
614 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog(
"QueryContinueBeginDialog"));
615 nRet = xQueryBox->run();
630 if ( (SfxPrinterChangeFlags::JOBSETUP | SfxPrinterChangeFlags::PRINTER) & nDiffFlags )
633 if ( nDiffFlags & SfxPrinterChangeFlags::PRINTER )
636 if ( nDiffFlags & SfxPrinterChangeFlags::OPTIONS )
639 const bool bChgOri = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION);
640 const bool bChgSize = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE);
641 if ( bChgOri || bChgSize )
658 bool bCalcNumPagesOnly )
660 if (!pOutDev || nPage <= 0)
674 aSize =
m_aEditWin->GetOutWin()->PixelToLogic(aSize,
MapMode(MapUnit::Map100thMM));
689 const tools::Long nLinespPage = nLineHeight ? aPaperSz.
Height() / nLineHeight : 1;
691 const sal_Int32 nCharspLine = nCharWidth ?
static_cast<sal_Int32
>(aPaperSz.
Width() / nCharWidth) : 1;
694 const sal_Int32 nPages =
static_cast<sal_Int32
>(nParas / nLinespPage + 1 );
695 sal_Int32 nCurPage = 1;
698 if (!bCalcNumPagesOnly && nPage == nCurPage)
701 Point aPos( aStartPos );
702 for ( sal_uInt32 nPara = 0; nPara < nParas; ++nPara )
705 const sal_Int32 nLineLen = aLine.getLength();
706 const sal_Int32 nLines = (nLineLen+nCharspLine-1) / nCharspLine;
707 for ( sal_Int32 nLine = 0; nLine < nLines; ++nLine )
709 aPos.AdjustY(nLineHeight );
710 if ( aPos.Y() > ( aPaperSz.
Height() +
TMARGPRN - nLineHeight/2 ) )
713 if (!bCalcNumPagesOnly && nPage == nCurPage)
717 if (!bCalcNumPagesOnly && nPage == nCurPage)
719 const sal_Int32 nStart = nLine * nCharspLine;
720 const sal_Int32 nLen =
std::min(nLineLen-nStart, nCharspLine);
721 pOutDev->
DrawText( aPos, aLine.copy(nStart, nLen) );
724 aPos.AdjustY(nParaSpace );
729 OSL_ENSURE( bCalcNumPagesOnly || nPage <= nCurPage,
"page number out of range" );
735 if (rHint.
GetId() == SfxHintId::ModeChanged || rHint.
GetId() == SfxHintId::TitleChanged)
739 if (!(rHint.
GetId() == SfxHintId::TitleChanged
752 rtl_TextEncoding eDestEnc = RTL_TEXTENCODING_UTF8;
758 std::shared_ptr<const SfxFilter> pFilter = pMedium->
GetFilter();
759 bool bHtml = pFilter && pFilter->GetUserData() ==
"HTML";
761 if(bHtml && !bDocModified && pDocShell->
HasName())
766 rtl_TextEncoding eHeaderEnc =
767 SfxHTMLParser::GetEncodingByHttpHeader(
769 if( RTL_TEXTENCODING_DONTKNOW == eHeaderEnc )
771 const char *pTmpCharSet =
772 rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1 );
773 eHeaderEnc = rtl_getTextEncodingFromMimeCharset( pTmpCharSet );
775 if( RTL_TEXTENCODING_DONTKNOW != eHeaderEnc &&
776 eDestEnc != eHeaderEnc )
778 eDestEnc = eHeaderEnc;
791 VclMessageType::Info, VclButtonsType::Ok,
800 const OUString sFileURL( aTempFile.
GetURL() );
803 SfxMedium aMedium( sFileURL,StreamMode::READWRITE );
807 const OUString sWriteName = pDocShell->
HasName()
832 assert(
dynamic_cast<SwWebDocShell*
>( pDocShell) &&
"Why no WebDocShell?" );
833 sal_uInt16 nLine =
static_cast<SwWebDocShell*
>(pDocShell)->GetSourcePara();
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)
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 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)
std::shared_ptr< const SfxFilter > GetFilter4Extension(const OUString &rExt, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) 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)
const OUString & GetName() const
SvStream * GetOutStream()
SfxFilterContainer * GetFilterContainer() const
void SetAutoLoad(const INetURLObject &, sal_uInt32 nTime, bool bReload)
virtual SfxObjectFactory & GetFactory() const=0
SvKeyValueIterator * GetHeaderAttributes()
SfxMedium * GetMedium() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() 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
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)
SvxSearchCmd GetCommand() const
const i18nutil::SearchOptions2 & GetSearchOptions() const
virtual SvxSearchItem * Clone(SfxItemPool *pPool=nullptr) const override
void SetSearchString(const OUString &rNewString)
IDocumentDeviceAccess & getIDocumentDeviceAccess()
virtual void SetModified(bool=true) override
SwDoc * GetDoc()
returns Doc. But be careful!
IDocumentState const & getIDocumentState() const
IDocumentDeviceAccess const & getIDocumentDeviceAccess() const
void GetState(SfxItemSet &)
SvxSearchItem * GetSearchItem()
void SetSearchItem(const SvxSearchItem &rItem)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
rtl_TextEncoding m_eLoadEncoding
std::unique_ptr< SvxSearchItem > m_pSearchItem
sal_Int32 PrintSource(OutputDevice *pOutDev, sal_Int32 nPage, bool bCalcNumPagesOnly)
SwDocShell * GetDocShell()
void SaveContent(const OUString &rTmpFile)
void Load(SwDocShell *pDocShell)
virtual sal_uInt16 SetPrinter(SfxPrinter *pNew, SfxPrinterChangeFlags nDiff=SFX_PRINTER_ALL) override
void StartSearchAndReplace(const SvxSearchItem &rItem, bool bApi, bool bRecursive=false)
void Execute(SfxRequest &)
void SaveContentTo(SfxMedium &rMed)
VclPtr< SwSrcEditWindow > m_aEditWin
SwSrcView(SfxViewFrame &rFrame, SfxViewShell *)
virtual SfxPrinter * GetPrinter(bool bCreate=false) override
virtual ~SwSrcView() override
ErrCode Write(WriterRef const &rxWriter, const OUString *=nullptr)
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)
OUString GetSelected() const
const TextSelection & GetSelection() const
bool Search(const i18nutil::SearchOptions &rSearchOptions, bool bForward)
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
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)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
SFX_IMPL_SUPERCLASS_INTERFACE(DrawDocShell, SfxObjectShell)
const LanguageTag & GetAppLanguageTag()
tools::Long const nBorder
tools::Long const nLeftMargin
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
#define SFX_OBJECTBAR_TOOLS
static OUString lcl_ConvertTabsToSpaces(const OUString &sLine)
static rtl_TextEncoding lcl_GetStreamCharSet(rtl_TextEncoding eLoadEncoding)
#define SRC_SEARCHOPTIONS
SFX_IMPL_NAMED_VIEWFACTORY(SwSrcView, "SourceView")
static void lcl_PrintHeader(vcl::RenderContext &rOutDev, sal_Int32 nPages, sal_Int32 nCurPage, const OUString &rTitle)
SVT_DLLPUBLIC OUString SvtResId(TranslateId aId)
OUString SwResId(TranslateId aId)
#define SFX_VIEW_REGISTRATION(DocClass)
void GetHTMLWriter(std::u16string_view rFilterOptions, const OUString &rBaseURL, WriterRef &xRet)