summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2024-10-03 20:18:22 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-10-07 14:07:45 +0200
commit75a030d577fb7dbe0233b54168a6cfb1ac289eb3 (patch)
treead9d60a5ce4511473807e1aec83525ee71ed5811 /sw
parent01479df14c14a4736dfbadf23c342b7ee835eba2 (diff)
allow creating rich content comments via .uno:InsertAnnotation args
Change-Id: I186f5955cad88c1d0d6cae66a7eb0a7845bb73a0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174591 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/AnnotationWin.hxx2
-rw-r--r--sw/inc/postithelper.hxx3
-rw-r--r--sw/source/uibase/docvw/AnnotationWin.cxx25
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx13
4 files changed, 35 insertions, 8 deletions
diff --git a/sw/inc/AnnotationWin.hxx b/sw/inc/AnnotationWin.hxx
index 0a91496bea86..890b84dc4e0b 100644
--- a/sw/inc/AnnotationWin.hxx
+++ b/sw/inc/AnnotationWin.hxx
@@ -75,6 +75,8 @@ class SAL_DLLPUBLIC_RTTI SwAnnotationWin final : public InterimItemWindow
void UpdateText(const OUString& rText);
void UpdateHTML(const OUString& rHtml);
+ static void ImportHtml(Outliner& rOutliner, const OUString& rHtml);
+
OUString GetAuthor() const;
Date GetDate() const;
tools::Time GetTime() const;
diff --git a/sw/inc/postithelper.hxx b/sw/inc/postithelper.hxx
index e9d30a3d854d..174e103231bd 100644
--- a/sw/inc/postithelper.hxx
+++ b/sw/inc/postithelper.hxx
@@ -26,6 +26,7 @@
#include "SidebarWindowsTypes.hxx"
#include "nodeoffset.hxx"
+class Outliner;
class SfxBroadcaster;
class SwRootFrame;
class SwPostItMgr;
@@ -89,6 +90,8 @@ namespace SwPostItHelper
tools::Long getLayoutHeight( const SwRootFrame* pRoot );
void setSidebarChanged( SwRootFrame* pRoot, bool bBrowseMode );
tools::ULong getPageInfo( SwRect& rPageFrame, const SwRootFrame* , const Point& );
+
+ void ImportHTML(Outliner& rOutliner, const OUString& rHtml);
}
class SAL_DLLPUBLIC_RTTI SwSidebarItem
diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx b/sw/source/uibase/docvw/AnnotationWin.cxx
index 24b4ee846252..c69f7ff6826b 100644
--- a/sw/source/uibase/docvw/AnnotationWin.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin.cxx
@@ -86,6 +86,22 @@ void collectUIInformation( const OUString& aevent , const OUString& aID )
}
+namespace SwPostItHelper {
+
+void ImportHTML(Outliner& rOutliner, const OUString& rHtml)
+{
+ OString sHtmlContent(rHtml.toUtf8());
+ SvMemoryStream aHTMLStream(const_cast<char*>(sHtmlContent.getStr()),
+ sHtmlContent.getLength(), StreamMode::READ);
+ SvKeyValueIteratorRef xValues(new SvKeyValueIterator);
+ // Insert newlines for divs, not normally done, so to keep things simple
+ // only enable that for this case.
+ xValues->Append(SvKeyValue("newline-on-div", "true"));
+ rOutliner.Read(aHTMLStream, "", EETextFormat::Html, xValues.get());
+}
+
+}
+
namespace sw::annotation {
// see AnnotationContents in sd for something similar
@@ -488,14 +504,7 @@ void SwAnnotationWin::UpdateText(const OUString& aText)
void SwAnnotationWin::UpdateHTML(const OUString& rHtml)
{
mpOutliner->Clear();
- OString sHtmlContent(rHtml.toUtf8());
- SvMemoryStream aHTMLStream(const_cast<char*>(sHtmlContent.getStr()),
- sHtmlContent.getLength(), StreamMode::READ);
- SvKeyValueIteratorRef xValues(new SvKeyValueIterator);
- // Insert newlines for divs, not normally done, so to keep things simple
- // only enable that for this case.
- xValues->Append(SvKeyValue("newline-on-div", "true"));
- GetOutlinerView()->Read(aHTMLStream, EETextFormat::Html, xValues.get());
+ SwPostItHelper::ImportHTML(*mpOutliner, rHtml);
UpdateData();
}
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 9dddd5fe4d15..50d054b86ba8 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -62,6 +62,7 @@
#include <swundo.hxx>
#include <swcli.hxx>
#include <poolfmt.hxx>
+#include <postithelper.hxx>
#include <edtwin.hxx>
#include <fmtcol.hxx>
#include <swtable.hxx>
@@ -2271,11 +2272,14 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq)
if ( pTextItem )
sText = pTextItem->GetValue();
+ const SvxPostItTextItem* pHtmlItem = rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_HTML);
+
// If we have a text already registered for answer, use that
if (GetView().GetPostItMgr()->IsAnswer() && !GetView().GetPostItMgr()->GetAnswerText().isEmpty())
{
sText = GetView().GetPostItMgr()->GetAnswerText();
GetView().GetPostItMgr()->RegisterAnswerText(OUString());
+ pHtmlItem = nullptr;
}
if ( HasSelection() && !IsTableMode() )
@@ -2336,6 +2340,15 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq)
Push();
SwCursorShell::Left(1, SwCursorSkipMode::Chars);
pPostIt = static_cast<SwPostItField*>(rFieldMgr.GetCurField());
+
+ if (pPostIt && pHtmlItem)
+ {
+ SwDocShell* pDocSh = GetView().GetDocShell();
+ Outliner aOutliner(&pDocSh->GetPool(), OutlinerMode::TextObject);
+ SwPostItHelper::ImportHTML(aOutliner, pHtmlItem->GetValue());
+ pPostIt->SetTextObject(aOutliner.CreateParaObject());
+ }
+
Pop(SwCursorShell::PopMode::DeleteCurrent); // Restore cursor position
}