19#include <config_wasm_strip.h>
26#include <rtl/string.h>
30#include <boost/property_tree/ptree.hpp>
31#include <boost/property_tree/json_parser.hpp>
36#include <com/sun/star/task/XStatusIndicator.hpp>
38#include <com/sun/star/task/XStatusIndicatorFactory.hpp>
48 GetHTMLWriter(
u"NoLineLimit,SkipHeaderFooter,NoPrettyPrint", OUString(), xWrt);
49 if (pCursor !=
nullptr)
52 SwWriter aWriter(aMemoryStream, *pCursor);
56 SAL_WARN(
"sw.ui",
"ExportPaMToHTML: failed to export selection to HTML");
60 = OString(
static_cast<const char*
>(aMemoryStream.
GetData()), aMemoryStream.
GetSize());
63 aResult = aResult.replaceAll(
"<p",
"<span");
64 aResult = aResult.replaceAll(
"</p>",
"</span>");
68 aResult = aResult.replaceAll(
"<ul>",
"");
69 aResult = aResult.replaceAll(
"</ul>",
"");
70 aResult = aResult.replaceAll(
"<ol>",
"");
71 aResult = aResult.replaceAll(
"</ol>",
"");
72 aResult = aResult.replaceAll(
"\n",
"").trim();
83 if (pHtmlTransferable.is())
99#if !ENABLE_WASM_STRIP_EXTRA
102 bool bCancel =
false;
107 bool& rCancelTranslation)
115 if (m_pCurrentPam->GetPoint()->nNode > m_pCurrentPam->GetMark()->nNode)
116 m_pCurrentPam->Exchange();
119 auto const& pNodes = rWrtSh.
GetNodes();
120 SwPosition aPoint = *m_pCurrentPam->GetPoint();
123 auto endNode = bHasSelection ? aMark.
nNode.
GetIndex() : pNodes.Count() - 1;
126 sal_Int32 nProgress(0);
130 if (pNodes[
n] && pNodes[
n]->IsTextNode())
132 if (pNodes[
n]->GetTextNode()->GetText().isEmpty())
140 uno::Reference<task::XStatusIndicatorFactory> xProgressFactory(
xFrame, uno::UNO_QUERY);
141 uno::Reference<task::XStatusIndicator> xStatusIndicator;
143 if (xProgressFactory.is())
145 xStatusIndicator = xProgressFactory->createStatusIndicator();
148 if (xStatusIndicator.is())
149 xStatusIndicator->start(
SwResId(STR_STATSTR_SWTRANSLATE),
nCount);
153 if (rCancelTranslation)
174 if (startNode == endNode)
177 cursor->GetPoint()->nContent = aPoint.
nContent;
180 else if (
n == startNode)
185 else if (
n == endNode)
188 cursor->GetMark()->nContent = aMark.
nContent;
189 cursor->GetPoint()->nContent = 0;
198 if (xStatusIndicator.is())
199 xStatusIndicator->setValue((100 * ++nProgress) /
nCount);
201 Idle aIdle(
"ProgressBar::SetValue aIdle");
214 if (xStatusIndicator.is())
215 xStatusIndicator->end();
virtual void Start(bool bStartTimer=true) override
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxFrame & GetFrame() const
void SetMark(const sw::mark::IMark *pMark)
const sw::mark::IMark * GetMark() const
void SetSelection(const SwPaM &rCursor)
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
SwNodeOffset GetIndex() const
Base class of the Writer document model elements.
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
SwNodeOffset GetIndex() const
SwNodeOffset Count() const
PaM is Point and Mark: a selection of the document model.
const OUString & GetText() const
static bool Paste(SwWrtShell &, TransferableDataHelper &, RndStdIds nAnchorType=RndStdIds::FLY_AT_PARA, bool bIgnoreComments=false, PasteTableType ePasteTable=PasteTableType::PASTE_DEFAULT)
static bool IsPasteSpecial(const SwWrtShell &rWrtShell, const TransferableDataHelper &)
const SwNodes & GetNodes() const
ErrCode Write(WriterRef const &rxWriter, const OUString *=nullptr)
Used by the UI to modify the document model.
tools::Long KillSelection(const Point *pPt, bool bProp)
bool HasSelection() const
void SetPriority(TaskPriority ePriority)
css::uno::Reference< css::datatransfer::XTransferable > GetXTransferable() const
static std::shared_ptr< SwUnoCursor > NewUnoCursor(SwDoc &rDoc, SwNodeOffset const nStartIdx, SwNodeOffset const nEndIdx)
#define SAL_WARN(area, stream)
SW_DLLPUBLIC void TranslateDocumentCancellable(SwWrtShell &rWrtSh, const TranslateAPIConfig &rConfig, bool &rCancelTranslation)
SW_DLLPUBLIC OString ExportPaMToHTML(SwPaM *pCursor, bool bReplacePTag)
SW_DLLPUBLIC void PasteHTMLToPaM(SwWrtShell &rWrtSh, SwPaM *pCursor, const OString &rData, bool bSetSelection)
SW_DLLPUBLIC void TranslateDocument(SwWrtShell &rWrtSh, const TranslateAPIConfig &rConfig)
OString Translate(const OString &rTargetLang, const OString &rAPIUrl, const OString &rAuthKey, const OString &rData)
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Marks a position in the document model.
const OString m_xTargetLanguage
Reference< XFrame > xFrame
OUString SwResId(TranslateId aId)
void GetHTMLWriter(std::u16string_view rFilterOptions, const OUString &rBaseURL, WriterRef &xRet)