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());
61 aResult = aResult.replaceAll(
"<p",
"<span");
62 aResult = aResult.replaceAll(
"</p>",
"</span>");
65 aResult = aResult.replaceAll(
"<ul>",
"");
66 aResult = aResult.replaceAll(
"</ul>",
"");
67 aResult = aResult.replaceAll(
"<ol>",
"");
68 aResult = aResult.replaceAll(
"</ol>",
"");
69 aResult = aResult.replaceAll(
"\n",
"").trim();
80 if (pHtmlTransferable.is())
93#if !ENABLE_WASM_STRIP_EXTRA
101 bool& rCancelTranslation)
109 if (m_pCurrentPam->GetPoint()->nNode > m_pCurrentPam->GetMark()->nNode)
110 m_pCurrentPam->Exchange();
113 auto const& pNodes = rWrtSh.
GetNodes();
114 SwPosition aPoint = *m_pCurrentPam->GetPoint();
117 auto endNode = bHasSelection ? aMark.
nNode.
GetIndex() : pNodes.Count() - 1;
120 sal_Int32 nProgress(0);
124 if (pNodes[
n] && pNodes[
n]->IsTextNode())
126 if (pNodes[
n]->GetTextNode()->GetText().isEmpty())
134 uno::Reference<task::XStatusIndicatorFactory> xProgressFactory(
xFrame, uno::UNO_QUERY);
135 uno::Reference<task::XStatusIndicator> xStatusIndicator;
137 if (xProgressFactory.is())
139 xStatusIndicator = xProgressFactory->createStatusIndicator();
142 if (xStatusIndicator.is())
143 xStatusIndicator->start(
SwResId(STR_STATSTR_SWTRANSLATE),
nCount);
147 if (rCancelTranslation)
168 if (startNode == endNode)
171 cursor->GetPoint()->nContent = aPoint.
nContent;
174 else if (
n == startNode)
179 else if (
n == endNode)
182 cursor->GetMark()->nContent = aMark.
nContent;
183 cursor->GetPoint()->nContent = 0;
192 if (xStatusIndicator.is())
193 xStatusIndicator->setValue((100 * ++nProgress) /
nCount);
195 Idle aIdle(
"ProgressBar::SetValue aIdle");
208 if (xStatusIndicator.is())
209 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 OString ExportPaMToHTML(SwPaM *pCursor)
SW_DLLPUBLIC void TranslateDocumentCancellable(SwWrtShell &rWrtSh, const TranslateAPIConfig &rConfig, bool &rCancelTranslation)
SW_DLLPUBLIC void PasteHTMLToPaM(SwWrtShell &rWrtSh, SwPaM *pCursor, const OString &rData)
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)