LibreOffice Module sw (master) 1
atrref.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <fmtrfmrk.hxx>
21
22#include <libxml/xmlwriter.h>
23
24#include <hintids.hxx>
25#include <hints.hxx>
26#include <txtrfmrk.hxx>
27#include <unorefmark.hxx>
28#include <utility>
29#include <sfx2/viewsh.hxx>
30#include <tools/json_writer.hxx>
31#include <LibreOfficeKit/LibreOfficeKitEnums.h>
32#include <comphelper/lok.hxx>
33#include <doc.hxx>
34#include <ndtxt.hxx>
35
37{
38}
39
42 , sw::BroadcastingModify()
43 , m_pTextAttr(nullptr)
44 , m_aRefName(std::move(aName))
45{
46}
47
50 , sw::BroadcastingModify()
51 , m_pTextAttr(nullptr)
52 , m_aRefName(rAttr.m_aRefName)
53{
54}
55
57{ m_wXReferenceMark = xMark.get(); }
58
59bool SwFormatRefMark::operator==( const SfxPoolItem& rAttr ) const
60{
61 assert(SfxPoolItem::operator==(rAttr));
62 return m_aRefName == static_cast<const SwFormatRefMark&>(rAttr).m_aRefName;
63}
64
66{
67 return new SwFormatRefMark( *this );
68}
69
71{
72 if (rHint.GetId() != SfxHintId::SwLegacyModify)
73 return;
74 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
75 CallSwClientNotify(rHint);
76 if(RES_REMOVE_UNO_OBJECT == pLegacy->GetWhich())
77 SetXRefMark(nullptr);
78}
79
81{
83 &static_cast<sw::BroadcastingModify&>(*this)); // cast to base class (void*)
84 CallSwClientNotify(sw::LegacyModifyHint(&item, &item));
85}
86
88{
89 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatRefMark"));
90 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
91 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("m_pTextAttr"), "%p", m_pTextAttr);
92 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("ref-name"),
93 BAD_CAST(m_aRefName.toUtf8().getStr()));
95
96
97 (void)xmlTextWriterEndElement(pWriter);
98}
99
100// attribute for content references in the text
101
103 sal_Int32 const nStartPos, sal_Int32 const*const pEnd)
104 : SwTextAttr(rAttr, nStartPos)
105 , SwTextAttrEnd( rAttr, nStartPos, nStartPos )
106 , m_pTextNode( nullptr )
107 , m_pEnd( nullptr )
108{
109 rAttr.m_pTextAttr = this;
110 if ( pEnd )
111 {
112 m_nEnd = *pEnd;
113 m_pEnd = & m_nEnd;
114 }
115 else
116 {
117 SetHasDummyChar(true);
118 }
119 SetDontMoveAttr( true );
120 SetOverlapAllowedAttr( true );
121}
122
124{
125 if (!comphelper::LibreOfficeKit::isActive() || GetTextNode().GetDoc().IsClipBoard())
126 return;
127
128 SfxViewShell* pViewShell = SfxViewShell::Current();
129 if (!pViewShell)
130 return;
131
132 OUString fieldCommand = GetRefMark().GetRefName();
133 tools::JsonWriter aJson;
134 aJson.put("commandName", ".uno:DeleteField");
135 aJson.put("success", true);
136 {
137 auto result = aJson.startNode("result");
138 aJson.put("DeleteField", fieldCommand);
139 }
140
141 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_UNO_COMMAND_RESULT, aJson.extractData());
142}
143
144const sal_Int32* SwTextRefMark::GetEnd() const
145{
146 return m_pEnd;
147}
148
149void SwTextRefMark::SetEnd(sal_Int32 n)
150{
151 *m_pEnd = n;
152 if (m_pHints)
154}
155
157{
158 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwTextRefMark"));
159 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
160 SwTextAttr::dumpAsXml(pWriter);
161
162 (void)xmlTextWriterEndElement(pWriter);
163}
164
165/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxHintId GetId() const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
virtual void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
OUString m_aRefName
Definition: fmtrfmrk.hxx:43
void SetXRefMark(rtl::Reference< SwXReferenceMark > const &xMark)
Definition: atrref.cxx:56
SwFormatRefMark(OUString aText)
Definition: atrref.cxx:40
virtual ~SwFormatRefMark() override
Definition: atrref.cxx:36
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: atrref.cxx:70
unotools::WeakReference< SwXReferenceMark > m_wXReferenceMark
Definition: fmtrfmrk.hxx:45
virtual SwFormatRefMark * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrref.cxx:65
SwTextRefMark * m_pTextAttr
Definition: fmtrfmrk.hxx:40
virtual bool operator==(const SfxPoolItem &) const override
"Pure virtual methods" of SfxPoolItem.
Definition: atrref.cxx:59
void InvalidateRefMark()
Definition: atrref.cxx:80
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrref.cxx:87
OUString & GetRefName()
Definition: fmtrfmrk.hxx:63
sal_Int32 m_nEnd
Definition: txatbase.hxx:138
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
void SetDontMoveAttr(bool bFlag)
Definition: txatbase.hxx:73
const SwFormatRefMark & GetRefMark() const
Definition: txatbase.hxx:238
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: txatbase.cxx:89
void SetOverlapAllowedAttr(bool bFlag)
Definition: txatbase.hxx:75
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:78
SwpHints * m_pHints
Definition: txatbase.hxx:67
const SwTextNode & GetTextNode() const
Definition: txtrfmrk.hxx:47
virtual void SetEnd(sal_Int32) override
Definition: atrref.cxx:149
sal_Int32 * m_pEnd
Definition: txtrfmrk.hxx:30
SwTextRefMark(SwFormatRefMark &rAttr, sal_Int32 const nStart, sal_Int32 const *const pEnd=nullptr)
Definition: atrref.cxx:102
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: atrref.cxx:156
virtual const sal_Int32 * GetEnd() const override
end position
Definition: atrref.cxx:144
void EndPosChanged() const
Definition: ndhints.hxx:213
void put(const char *pPropName, const OUString &rPropValue)
char * extractData()
ScopedJsonWriterNode startNode(const char *)
struct _xmlTextWriter * xmlTextWriterPtr
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(181)
constexpr TypedWhichId< SwFormatRefMark > RES_TXTATR_REFMARK(RES_TXTATR_WITHEND_BEGIN)
OUString aName
sal_Int64 n
Dialog to specify the properties of date form field.
Any result