21#include <bookmark.hxx>
35#include <libxml/xmlwriter.h>
48#include <LibreOfficeKit/LibreOfficeKitEnums.h>
49#include <rtl/strbuf.hxx>
62 SwPosition const& rStartPos(rMark.GetMarkStart());
68 std::optional<SwPosition> ret;
75 sal_Int32
const nStart(
n == nStartNode
78 sal_Int32
const nEnd(
n == nEndNode
82 for (sal_Int32
i = nEnd; nStart <
i; --
i)
100 ret.emplace(rTextNode,
i - 1);
111 assert(nStartNode <= pNode->StartOfSectionIndex());
137 <<
" without proper TextNode");
145 <<
" is beyond " << pTextNode->
Len());
150 void lcl_AssertFieldMarksSet(
const Fieldmark& rField,
156 SwPosition const& rStart(rField.GetMarkStart());
157 assert(rStart.GetNode().GetTextNode()->GetText()[rStart.GetContentIndex()] == aStartMark); (void) rStart; (void) aStartMark;
159 assert(sepPos.GetNode().GetTextNode()->GetText()[sepPos.GetContentIndex()] ==
CH_TXT_ATR_FIELDSEP); (void) sepPos;
163 assert(rField.GetMarkPos().GetContentIndex() + 1 == rField.GetOtherMarkPos().GetContentIndex());
166 assert(rEnd.GetNode().GetTextNode()->GetText()[rEnd.GetContentIndex() - 1] == aEndMark); (void) rEnd;
169 void lcl_SetFieldMarks(Fieldmark& rField,
176 OUString startChar(aStartMark);
178 && rField.GetMarkStart() == rField.GetMarkEnd())
188 SwPaM aStartPaM(start);
190 start.AdjustContent( -startChar.getLength() );
193 rField.SetMarkStartPos( start );
196 assert(pSepPos ==
nullptr || (start < *pSepPos && *pSepPos <= rEnd));
197 if (startChar.getLength() == 1)
199 *aStartPaM.GetPoint() = pSepPos ? *pSepPos : rEnd;
201 if (!pSepPos || rEnd < *pSepPos)
206 assert(pSepPos ==
nullptr || (start < *pSepPos && *pSepPos <= rEnd));
210 assert(pSepPos ==
nullptr);
214 if (aEndMark && startChar.getLength() == 1)
224 assert(rField.GetMarkPos().GetContentIndex() + 1 == rField.GetOtherMarkPos().GetContentIndex());
227 lcl_AssertFieldMarksSet(rField, aStartMark, aEndMark);
232 void lcl_RemoveFieldMarks(
const Fieldmark& rField,
239 const SwPosition& rStart = rField.GetMarkStart();
241 assert(pStartTextNode);
244 (void) pStartTextNode;
253 assert(pEndTextNode);
254 const sal_Int32 nEndPos = (rEnd == rStart)
257 assert(pEndTextNode->
GetText()[nEndPos] == aEndMark);
258 SwPosition const aEnd(*pEndTextNode, nEndPos);
264 auto InvalidatePosition(
SwPosition const& rPos) ->
void
275 : m_oPos1(*aPaM.GetPoint())
312 return "Mark: ( Name, [ Node1, Index1 ] ): ( " +
m_aName +
", [ "
313 + OUString::number( sal_Int32(
GetMarkPos().GetNodeIndex()) ) +
", "
314 + OUString::number(
GetMarkPos().GetContentIndex( ) ) +
" ] )";
319 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"MarkBase"));
320 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"name"), BAD_CAST(
m_aName.toUtf8().getStr()));
321 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"markPos"));
323 (void)xmlTextWriterEndElement(pWriter);
326 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"otherMarkPos"));
328 (void)xmlTextWriterEndElement(pWriter);
330 (void)xmlTextWriterEndElement(pWriter);
338 static bool bHack = (getenv(
"LIBO_ONEWAY_STABLE_ODF_EXPORT") !=
nullptr);
342 static sal_Int64 nIdCounter = SAL_CONST_INT64(6000000000);
343 return rPrefix + OUString::number(nIdCounter++);
347 static OUString sUniquePostfix;
352 std::numeric_limits<unsigned int>::max()));
353 sUniquePostfix =
"_" + OUString::number(
n);
357 return rPrefix + OUString::number(
nCount++) + sUniquePostfix;
363 CallSwClientNotify(rHint);
364 if (rHint.
GetId() != SfxHintId::SwLegacyModify)
407 p->SendDataChanged();
415 const OUString& rName)
432 OUString fieldCommand =
GetName();
434 aJson.
put(
"commandName",
".uno:DeleteBookmark");
435 aJson.
put(
"success",
true);
438 aJson.
put(
"DeleteBookmark", fieldCommand);
450 std::make_unique<SwUndoInsBookmark>(*
this));
463 std::make_unique<SwUndoDeleteBookmark>(*
this));
472 InvalidatePosition(GetMarkPos());
475 InvalidatePosition(GetOtherMarkPos());
524 const uno::Reference< rdf::XMetadatable> xMeta(
546 return "Fieldmark: ( Name, Type, [ Nd1, Id1 ], [ Nd2, Id2 ] ): ( " +
m_aName +
", "
548 +
", " + OUString::number(
GetMarkPos( ).GetContentIndex( ) ) +
" ], ["
549 + OUString::number( sal_Int32(
GetOtherMarkPos().GetNodeIndex( )) ) +
", "
563 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"Fieldmark"));
564 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"fieldname"), BAD_CAST(
m_aFieldname.toUtf8().getStr()));
565 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"fieldHelptext"), BAD_CAST(
m_aFieldHelptext.toUtf8().getStr()));
567 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"parameters"));
570 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"parameter"));
571 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"name"), BAD_CAST(rParam.first.toUtf8().getStr()));
572 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"value"), BAD_CAST(
comphelper::anyToString(rParam.second).toUtf8().getStr()));
573 (void)xmlTextWriterEndElement(pWriter);
575 (void)xmlTextWriterEndElement(pWriter);
576 (void)xmlTextWriterEndElement(pWriter);
581 , m_pDocumentContentOperationsManager(nullptr)
583 if ( !rName.isEmpty() )
596 OUString fieldCommand;
599 aJson.
put(
"commandName",
".uno:DeleteTextFormField");
600 aJson.
put(
"success",
true);
603 aJson.
put(
"DeleteTextFormField", fieldCommand);
626 if (rIDUR.DoesUndo())
628 rIDUR.AppendUndo(std::make_unique<SwUndoDelTextFieldmark>(*
this));
642 const sal_Int32 nEnd(
GetMarkEnd().GetContentIndex());
645 const sal_Int32 nLen = rTextNode.
GetText().getLength();
646 if (nStart + 1 < nLen && nEnd <= nLen && nEnd > nStart + 2)
647 sContent = rTextNode.
GetText().copy(nStart + 1, nEnd - nStart - 2);
659 const sal_Int32 nEnd(
GetMarkEnd().GetContentIndex());
662 if (nStart + 1 < nLen && nEnd <= nLen && nEnd > nStart + 2)
683 assert(pSepPos ==
nullptr);
697 if (rIDUR.DoesUndo())
699 rIDUR.AppendUndo(std::make_unique<SwUndoDelNoTextFieldmark>(*
this));
702 lcl_RemoveFieldMarks(*
this, rDoc,
710 if (!rName.isEmpty())
727 bool bResult =
false;
730 pResult->second >>= bResult;
774 if (!rName.isEmpty())
806 sal_Int32
nIndex = pIndex ? *pIndex : -1;
811 uno::Sequence<OUString>
aSeq;
842 uno::Sequence<OUString>
aSeq;
843 sw::mark::IFieldmark::parameter_map_t* pParameters =
GetParameters();
848 if (nCurrentTextPos != -1)
851 *pIndex = nCurrentTextPos;
855 const sal_Int32 nLen =
aSeq.getLength();
856 const sal_Int32 nNewPos = pIndex && *pIndex > -1 ?
std::min(*pIndex, nLen) : nLen;
859 sal_Int32 nResultIndex = -1;
861 if (nNewPos <= nResultIndex)
864 auto aList = comphelper::sequenceToContainer<std::vector<OUString>>(
aSeq);
866 aList.insert(aList.begin() + nNewPos, rText);
871 aList.push_back(rText);
895 if (!pIndex && !pText)
898 uno::Sequence<OUString>
aSeq;
899 sw::mark::IFieldmark::parameter_map_t* pParameters =
GetParameters();
901 const sal_Int32 nLen =
aSeq.getLength();
905 if (*pIndex < 0 || *pIndex >= nLen)
925 if (*pIndex > -1 && *pIndex < nLen)
927 auto aList = comphelper::sequenceToContainer<std::vector<OUString>>(
aSeq);
928 aList[*pIndex] = *pText;
945 sw::mark::IFieldmark::parameter_map_t* pParameters =
GetParameters();
946 uno::Sequence<OUString>
aSeq;
956 if (nDelIndex >=
aSeq.getLength())
961 sal_Int32 nResultIndex = -1;
963 if (nDelIndex == nResultIndex)
965 else if (nDelIndex < nResultIndex)
969 if (nResultIndex != -1)
996 OStringBuffer sPayload;
997 sPayload = OString::Concat(
"{\"action\": \"show\","
998 " \"type\": \"drop-down\", \"textArea\": \"") +
1001 sPayload.append(
" \"params\": { \"items\": [");
1006 css::uno::Sequence<OUString> vListEntries;
1007 if (pListEntriesIter != pParameters->end())
1009 pListEntriesIter->second >>= vListEntries;
1010 for (
const OUString& sItem : std::as_const(vListEntries))
1011 sPayload.append(
"\"" +
OUStringToOString(sItem, RTL_TEXTENCODING_UTF8) +
"\", ");
1012 sPayload.setLength(sPayload.getLength() - 2);
1014 sPayload.append(
"], ");
1018 sal_Int32 nSelection = -1;
1019 if (pSelectedItemIter != pParameters->end())
1021 pSelectedItemIter->second >>= nSelection;
1023 sPayload.append(
"\"selected\": \"" + OString::number(nSelection) +
"\", ");
1026 sPayload.append(
"\"placeholderText\": \"" +
OUStringToOString(
SwResId(STR_DROP_DOWN_EMPTY_LIST), RTL_TEXTENCODING_UTF8) +
"\"}}");
1033 "{\"action\": \"hide\", \"type\": \"drop-down\"}");
1038 , m_pNumberFormatter(nullptr)
1039 , m_pDocumentContentOperationsManager(nullptr)
1065 if (rIDUR.DoesUndo())
1068 rIDUR.AppendUndo(std::make_unique<SwUndoDelTextFieldmark>(*
this));
1091 if (rPortionPaintArea.
IsEmpty())
1100 if (rPortionPaintArea.
IsEmpty())
1123 const sal_Int32 nEnd (
GetMarkEnd().GetContentIndex());
1126 if(nStart + 1 < pTextNode->
GetText().getLength() && nEnd <= pTextNode->GetText().
getLength() &&
1128 sContent = pTextNode->
GetText().copy(nStart + 1, nEnd - nStart - 2);
1140 const sal_Int32 nEnd (
GetMarkEnd().GetContentIndex());
1142 if(nStart + 1 < pTextNode->
GetText().getLength() && nEnd <= pTextNode->GetText().
getLength() &&
1164 const sw::mark::IFieldmark::parameter_map_t* pParameters =
GetParameters();
1165 bool bFoundValidDate =
false;
1166 double dCurrentDate = 0;
1167 OUString sDateFormat;
1169 if (pResult != pParameters->end())
1171 pResult->second >>= sDateFormat;
1176 if (pResult != pParameters->end())
1178 pResult->second >>= sLang;
1187 sal_Int32 nCheckPos = 0;
1200 return std::pair<bool, double>(bFoundValidDate, dCurrentDate);
1209 sw::mark::IFieldmark::parameter_map_t* pParameters =
GetParameters();
1215 OUString sCurrentDate;
1219 sal_Int32 nCheckPos = 0;
1231 const Color* pCol =
nullptr;
1234 return sCurrentDate;
1239 bool bFoundValidDate =
false;
1240 double dCurrentDate = 0;
1242 const sw::mark::IFieldmark::parameter_map_t* pParameters =
GetParameters();
1244 OUString sCurrentDate;
1245 if (pResult != pParameters->end())
1247 pResult->second >>= sCurrentDate;
1249 if(!sCurrentDate.isEmpty())
1254 sal_Int32 nCheckPos = 0;
1269 return std::pair<bool, double>(bFoundValidDate, dCurrentDate);
1276 OUString sDateFormat;
1277 const sw::mark::IFieldmark::parameter_map_t* pParameters =
GetParameters();
1279 if (pResult != pParameters->end())
1281 pResult->second >>= sDateFormat;
1286 if (pResult != pParameters->end())
1288 pResult->second >>= sLang;
1292 OUString sCurrentContent;
1296 sal_Int32 nCheckPos = 0;
1298 OUString sFormat = sDateFormat;
1308 const Color* pCol =
nullptr;
1311 return sCurrentContent;
1323 sw::mark::IFieldmark::parameter_map_t* pParameters =
GetParameters();
virtual bool InsertString(const SwPaM &rRg, const OUString &, const SwInsertFlags nInsertMode=SwInsertFlags::EMPTYEXPAND)=0
Insert string into existing text node at position rRg.Point().
virtual sfx2::LinkManager & GetLinkManager()=0
virtual void SetModified()=0
Must be called manually at changes of format.
bool isLOKMobilePhone() const
virtual void libreOfficeKitViewCallback(int nType, const OString &pPayload) const override
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
SwContentIndex & Assign(const SwContentNode *, sal_Int32)
IDocumentState const & getIDocumentState() const
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
IDocumentContentOperations const & getIDocumentContentOperations() const
IDocumentUndoRedo & GetIDocumentUndoRedo()
::sfx2::IXmlIdRegistry & GetXmlIdRegistry()
::sw::DocumentContentOperationsManager const & GetDocumentContentOperationsManager() const
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
bool IsInHeaderFooter(const SwNode &) const
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Base class of the Writer document model elements.
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
bool IsNoTextNode() const
SwNodeOffset StartOfSectionIndex() const
bool IsSectionNode() const
const SwStartNode * StartOfSectionNode() const
PaM is Point and Mark: a selection of the document model.
const SwPosition * GetMark() const
const SwPosition * GetPoint() const
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Of course Writer needs its own rectangles.
Point BottomRight() const
tools::Rectangle SVRect() const
SwTextNode is a paragraph in the document model.
virtual sal_Int32 Len() const override
const OUString & GetText() const
static rtl::Reference< SwXBookmark > CreateXBookmark(SwDoc &rDoc, ::sw::mark::IMark *pBookmark)
static VclPtr< reference_type > Create(Arg &&... arg)
void RemoveServer(SvLinkSource *rObj)
bool ReplaceRange(SwPaM &rPam, const OUString &rNewStr, const bool bRegExReplace) override
Replace selected range in a TextNode with string.
bool InsertString(const SwPaM &rRg, const OUString &, const SwInsertFlags nInsertMode=SwInsertFlags::EMPTYEXPAND) override
Insert string into existing text node at position rRg.Point().
void DeleteDummyChar(SwPosition const &rPos, sal_Unicode cDummy)
void SetHideCondition(const OUString &rHideCondition) override
css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
auto InvalidateFrames() -> void override
bool IsInClipboard() const override
void DeregisterFromDoc(SwDoc &io_rDoc) override
bool IsInUndo() const override
void Hide(bool rHide) override
OUString m_sHideCondition
void sendLOKDeleteCallback()
::sfx2::IXmlIdRegistry & GetRegistry() override
Bookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
bool IsInContent() const override
void InitDoc(SwDoc &io_Doc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
bool IsChecked() const override
void SetChecked(bool checked) override
void ReplaceContent(const OUString &sNewContent) override
OUString GetContent() const override
CheckboxFieldmark(const SwPaM &rPaM, const OUString &rName)
void SetPortionPaintAreaStart(const SwRect &rPortionPaintArea)
void InvalidateCurrentDateParam()
std::pair< bool, double > ParseCurrentDateParam() const
std::pair< bool, double > GetCurrentDate() const override
void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
~DateFieldmark() override
void SetCurrentDate(double fDate) override
DateFieldmark(const SwPaM &rPaM)
SvNumberFormatter * m_pNumberFormatter
void ReleaseDoc(SwDoc &rDoc) override
OUString GetDateInStandardDateFormat(double fDate) const override
OUString GetContent() const override
void ReplaceContent(const OUString &sNewContent) override
void ShowButton(SwEditWin *pEditWin) override
void SetPortionPaintAreaEnd(const SwRect &rPortionPaintArea)
OUString GetDateInCurrentDateFormat(double fDate) const
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
void SetRefObject(SwServerObject *pObj)
DdeBookmark(const SwPaM &rPaM)
tools::SvRef< SwServerObject > m_aRefObj
virtual void DeregisterFromDoc(SwDoc &rDoc)
void SendLOKShowMessage(const SfxViewShell *pViewShell)
SwRect m_aPortionPaintArea
void DelContent(sal_Int32 nDelIndex=-1) override
Remove everything if the given index is negative, else remove the given index (if valid).
void ShowButton(SwEditWin *pEditWin) override
void AddContent(const OUString &rText, sal_Int32 *pIndex=nullptr) override
AddContent : INSERTS a new choice.
void RemoveButton() override
~DropDownFieldmark() override
DropDownFieldmark(const SwPaM &rPaM, const OUString &rName)
void SetPortionPaintArea(const SwRect &rPortionPaintArea)
OUString GetContent() const override
void ReplaceContent(const OUString *pText, sal_Int32 *pIndex) override
ReplaceContent : changes the list result index or renames the existing choices.
static void SendLOKHideMessage(const SfxViewShell *pViewShell)
void dumpAsXml(xmlTextWriterPtr pWriter) const override
OUString m_aFieldHelptext
void Invalidate() override
IFieldmark::parameter_map_t m_vParams
void SetMarkStartPos(const SwPosition &rNewStartPos)
Fieldmark(const SwPaM &rPaM)
OUString ToString() const override
IFieldmark::parameter_map_t * GetParameters() override
void SwClientNotify(const SwModify &, const SfxHint &) override
virtual void SetOtherMarkPos(const SwPosition &rNewPos)
const OUString & GetName() const override
std::optional< SwPosition > m_oPos1
OUString ToString() const override
void SetXBookmark(rtl::Reference< SwXBookmark > const &xBkmk)
void dumpAsXml(xmlTextWriterPtr pWriter) const override
std::optional< SwPosition > m_oPos2
SwPosition & GetMarkEnd() const override
unotools::WeakReference< SwXBookmark > m_wXBookmark
virtual auto InvalidateFrames() -> void
bool IsCoveringPosition(const SwPosition &rPos) const override
bool IsExpanded() const override
virtual void SetMarkPos(const SwPosition &rNewPos)
MarkBase(const SwPaM &rPaM, OUString aName)
SwPosition & GetMarkPos() const override
SwPosition & GetMarkStart() const override
SwPosition & GetOtherMarkPos() const override
static OUString GenerateNewName(std::u16string_view rPrefix)
NavigatorReminder(const SwPaM &rPaM)
NonTextFieldmark(const SwPaM &rPaM)
void ReleaseDoc(SwDoc &rDoc) override
void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
void ReplaceContent(const OUString &sNewContent) override
TextFieldmark(const SwPaM &rPaM, const OUString &rName)
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
void ReleaseDoc(SwDoc &rDoc) override
OUString GetContent() const override
UnoMark(const SwPaM &rPaM)
struct _xmlTextWriter * xmlTextWriterPtr
#define CH_TXT_ATR_FIELDSEP
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(181)
#define CH_TXT_ATR_FORMELEMENT
#define CH_TXT_ATR_FIELDEND
#define CH_TXT_ATR_FIELDSTART
Sequence< sal_Int8 > aSeq
#define SAL_INFO(area, stream)
double getLength(const B2DPolygon &rCandidate)
unsigned int uniform_uint_distribution(unsigned int a, unsigned int b)
OUString anyToString(uno::Any const &value)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
void removeElementAt(css::uno::Sequence< T > &_rSeq, sal_Int32 _nPos)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
void UpdateFramesForRemoveDeleteRedline(SwDoc &rDoc, SwPaM const &rPam)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
constexpr OUStringLiteral ODF_FORMCHECKBOX_RESULT
constexpr OUStringLiteral ODF_FORMDROPDOWN_RESULT
constexpr OUStringLiteral ODF_FORMDATE_CURRENTDATE
constexpr OUStringLiteral ODF_FORMDATE_DATEFORMAT
constexpr OUStringLiteral ODF_FORMDATE_CURRENTDATE_FORMAT
#define ODF_FORMDATE_CURRENTDATE_LANGUAGE
constexpr OUStringLiteral ODF_FORMDROPDOWN_LISTENTRY
constexpr OUStringLiteral ODF_CODE_PARAM
constexpr OUStringLiteral ODF_FORMDATE_DATEFORMAT_LANGUAGE
SwContentNode * GetNode(SwPaM &rPam, bool &rbFirst, SwMoveFnCollection const &fnMove, bool const bInReadOnly, SwRootFrame const *const i_pLayout)
This function returns the next node in direction of search.
Marks a position in the document model.
void dumpAsXml(xmlTextWriterPtr pWriter) const
SwNodeOffset GetNodeIndex() const
const SwNodes & GetNodes() const
sal_Int32 GetContentIndex() const
void AdjustContent(sal_Int32 nDelta)
Adjust content index, only valid to call this if the position points to a SwContentNode subclass.
OUString SwResId(TranslateId aId)
constexpr sal_uInt32 NUMBERFORMAT_ENTRY_NOT_FOUND