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:
431 SvxStatusItem aItem( SID_TABLE_CELL, aPos, StatusCategory::RowColumn );
435 case SID_SEARCH_OPTIONS:
441 nOpt &=
~SearchOptionFlags(SearchOptionFlags::REPLACE|SearchOptionFlags::REPLACE_ALL);
446 case SID_SEARCH_ITEM:
474 if(nWhich == SID_UNDO)
498 case SID_MAIL_SENDDOCASPDF:
499 case SID_MAIL_SENDDOC :
500 case SID_EXPORTDOCASPDF:
501 case SID_DIRECTEXPORTDOCASPDF:
504 case SID_BROWSER_MODE:
563 case SvxSearchCmd::FIND:
564 case SvxSearchCmd::FIND_ALL:
565 nFound = pTextView->
Search( aSearchOpt, bForward ) ? 1 : 0;
568 case SvxSearchCmd::REPLACE_ALL: bAll =
true;
570 case SvxSearchCmd::REPLACE:
571 nFound = pTextView->
Replace( aSearchOpt, bAll, bForward );
581 bool bNotFoundMessage =
false;
584 bNotFoundMessage = bAtStart;
588 bNotFoundMessage =
true;
597 std::unique_ptr<weld::MessageDialog> xInfoBox(xBuilder->weld_message_dialog(
"InfoNotFoundDialog"));
607 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog(
"QueryContinueEndDialog"));
608 nRet = xQueryBox->run();
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();
629 if ( (SfxPrinterChangeFlags::JOBSETUP | SfxPrinterChangeFlags::PRINTER) & nDiffFlags )
632 if ( nDiffFlags & SfxPrinterChangeFlags::PRINTER )
635 if ( nDiffFlags & SfxPrinterChangeFlags::OPTIONS )
638 const bool bChgOri = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_ORIENTATION);
639 const bool bChgSize = bool(nDiffFlags & SfxPrinterChangeFlags::CHG_SIZE);
640 if ( bChgOri || bChgSize )
657 bool bCalcNumPagesOnly )
659 if (!pOutDev || nPage <= 0)
673 aSize =
m_aEditWin->GetOutWin()->PixelToLogic(aSize,
MapMode(MapUnit::Map100thMM));
688 const tools::Long nLinespPage = nLineHeight ? aPaperSz.
Height() / nLineHeight : 1;
690 const sal_Int32 nCharspLine = nCharWidth ?
static_cast<sal_Int32
>(aPaperSz.
Width() / nCharWidth) : 1;
693 const sal_Int32 nPages =
static_cast<sal_Int32
>(nParas / nLinespPage + 1 );
694 sal_Int32 nCurPage = 1;
697 if (!bCalcNumPagesOnly && nPage == nCurPage)
700 Point aPos( aStartPos );
701 for ( sal_uInt32 nPara = 0; nPara < nParas; ++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 )
712 if (!bCalcNumPagesOnly && nPage == nCurPage)
716 if (!bCalcNumPagesOnly && nPage == nCurPage)
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) );
728 OSL_ENSURE( bCalcNumPagesOnly || nPage <= nCurPage,
"page number out of range" );
734 if (rHint.
GetId() == SfxHintId::ModeChanged || rHint.
GetId() == SfxHintId::TitleChanged)
738 if (!(rHint.
GetId() == SfxHintId::TitleChanged
751 rtl_TextEncoding eDestEnc = RTL_TEXTENCODING_UTF8;
757 std::shared_ptr<const SfxFilter> pFilter = pMedium->
GetFilter();
758 bool bHtml = pFilter && pFilter->GetUserData() ==
"HTML";
760 if(bHtml && !bDocModified && pDocShell->
HasName())
765 rtl_TextEncoding eHeaderEnc =
766 SfxHTMLParser::GetEncodingByHttpHeader(
768 if( RTL_TEXTENCODING_DONTKNOW == eHeaderEnc )
770 const char *pTmpCharSet =
771 rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_ISO_8859_1 );
772 eHeaderEnc = rtl_getTextEncodingFromMimeCharset( pTmpCharSet );
774 if( RTL_TEXTENCODING_DONTKNOW != eHeaderEnc &&
775 eDestEnc != eHeaderEnc )
777 eDestEnc = eHeaderEnc;
790 VclMessageType::Info, VclButtonsType::Ok,
799 const OUString sFileURL( aTempFile.
GetURL() );
802 SfxMedium aMedium( sFileURL,StreamMode::READWRITE );
806 const OUString sWriteName = pDocShell->
HasName()
831 assert(
dynamic_cast<SwWebDocShell*
>( pDocShell) &&
"Why no WebDocShell?" );
832 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
constexpr tools::Long Y() const
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
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)
bool Search(const i18nutil::SearchOptions2 &rSearchOptions, bool bForward)
OUString GetSelected() const
const TextSelection & GetSelection() const
sal_uInt16 Replace(const i18nutil::SearchOptions2 &rSearchOptions, bool bAll, bool bForward)
TextEngine * GetTextEngine() const
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)