22#include <libxml/xmlwriter.h>
40inline constexpr OUStringLiteral CURRENT_DATE_FORMAT =
u"YYYY-MM-DD";
50 , m_pTextAttr(nullptr)
55 const std::shared_ptr<SwContentControl>& pContentControl, sal_uInt16 nWhich)
57 , m_pContentControl(pContentControl)
58 , m_pTextAttr(nullptr)
62 SAL_WARN(
"sw.core",
"SwFormatContentControl ctor: no pContentControl?");
100 SAL_WARN(
"sw.core",
"SwFormatContentControl::SetTextAttr: already has a text attribute");
104 SAL_WARN(
"sw.core",
"SwFormatContentControl::SetTextAttr: no attribute to remove");
109 SAL_WARN(
"sw.core",
"inserted SwFormatContentControl has no SwContentControl");
132 SAL_WARN(
"sw.core",
"SwFormatContentControl::NotifyChangeTextNode: no content control?");
157 SAL_WARN(
"sw.core",
"SwFormatContentControl::DoCopy: called for SwFormatContentControl "
158 "with no SwContentControl.");
168 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwFormatContentControl"));
169 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
170 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"m_pTextAttr"),
"%p",
m_pTextAttr);
178 (void)xmlTextWriterEndElement(pWriter);
182 :
sw::BroadcastingModify()
184 , m_pTextNode(nullptr)
219 SetId(pOther->m_nId);
250 GetNotifier().Broadcast(
SfxHint(SfxHintId::Deinitializing));
256 if (rHint.
GetId() != SfxHintId::SwLegacyModify)
260 CallSwClientNotify(rHint);
261 GetNotifier().Broadcast(
SfxHint(SfxHintId::DataChanged));
267 GetNotifier().Broadcast(
SfxHint(SfxHintId::Deinitializing));
281 for (
size_t i = 0;
i < nLen; ++
i)
286 assert(!
GetDropDown() &&
"DropDowns must always have an associated list item");
291 const OUString& rValue)
294 if (rValue.isEmpty())
296 if (rDisplayText.isEmpty())
309 if (rListItem == aListItem)
316 if (oSelected && *oSelected >= nZIndex)
318 if (*oSelected < nLen)
321 std::vector<SwContentControlListItem> vListItems =
GetListItems();
322 vListItems.insert(vListItems.begin() + nZIndex, aListItem);
335 if (*oSelected == nZIndex)
341 else if (*oSelected < nZIndex)
345 std::vector<SwContentControlListItem> vListItems =
GetListItems();
346 vListItems.erase(vListItems.begin() + nZIndex);
363 sal_uInt32 nFormat = pNumberFormatter->
GetEntryKey(
369 sal_Int32 nCheckPos = 0;
372 pNumberFormatter->
PutEntry(aFormat, nCheckPos,
nType, nFormat,
376 const Color* pColor =
nullptr;
378 double fSelectedDate = 0;
393 pNumberFormatter->
GetOutputString(fSelectedDate, nFormat, aFormatted, &pColor,
false);
406 sal_Int32 nCheckPos = 0;
408 OUString sFormat = CURRENT_DATE_FORMAT;
417 const Color* pColor =
nullptr;
418 pNumberFormatter->
GetOutputString(fCurrentDate, nFormat, aFormatted, &pColor,
false);
434 sal_Int32 nCheckPos = 0;
436 OUString sFormat = CURRENT_DATE_FORMAT;
445 double dCurrentDate = 0;
446 OUString aCurrentDate =
m_aCurrentDate.replaceAll(
"T00:00:00Z",
"");
447 (void)pNumberFormatter->
IsNumberFormat(aCurrentDate, nFormat, dCurrentDate);
492 std::optional<bool> oLock;
495 else if (
m_aLock.equalsIgnoreAsciiCase(
"sdtContentLocked"))
497 else if (
m_aLock.equalsIgnoreAsciiCase(
"unlocked"))
499 else if (
m_aLock.equalsIgnoreAsciiCase(
"sdtLocked"))
501 else if (
m_aLock.equalsIgnoreAsciiCase(
"contentLocked"))
504 assert(oLock &&
"invalid or unknown lock state");
510 if (!bLockContent && !bLockControl)
512 else if (bLockContent && bLockControl)
514 else if (bLockContent)
557 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwContentControl"));
558 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
559 (void)xmlTextWriterWriteFormatAttribute(
560 pWriter, BAD_CAST(
"showing-place-holder"),
"%s",
562 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"checkbox"),
"%s",
564 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"checked"),
"%s",
565 BAD_CAST(OString::boolean(
m_bChecked).getStr()));
566 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"checked-state"),
"%s",
568 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"unchecked-state"),
"%s",
570 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"picture"),
571 BAD_CAST(OString::boolean(
m_bPicture).getStr()));
572 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"date"),
573 BAD_CAST(OString::boolean(
m_bDate).getStr()));
574 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"date-format"),
576 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"date-language"),
578 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"current-date"),
580 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"plain-text"),
582 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"combo-box"),
584 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"drop-down"),
586 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"placeholder-doc-part"),
588 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"data-binding-prefix-mappings"),
590 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"data-binding-xpath"),
592 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"data-binding-store-item-id"),
594 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"color"),
595 BAD_CAST(
m_aColor.toUtf8().getStr()));
596 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"appearance"),
598 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"alias"),
599 BAD_CAST(
m_aAlias.toUtf8().getStr()));
600 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"tag"), BAD_CAST(
m_aTag.toUtf8().getStr()));
601 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"id"),
602 BAD_CAST(OString::number(
m_nId).getStr()));
603 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"tab-index"),
605 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"lock"),
606 BAD_CAST(
m_aLock.toUtf8().getStr()));
612 rListItem.dumpAsXml(pWriter);
616 (void)xmlTextWriterEndElement(pWriter);
621 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwContentControlListItem"));
622 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
623 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"display-text"),
625 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"value"),
626 BAD_CAST(
m_aValue.toUtf8().getStr()));
628 (void)xmlTextWriterEndElement(pWriter);
649 uno::Sequence<uno::Sequence<beans::PropertyValue>> aRet(rItems.size());
651 uno::Sequence<beans::PropertyValue>* pRet = aRet.getArray();
652 for (
size_t i = 0;
i < rItems.size(); ++
i)
655 uno::Sequence<beans::PropertyValue> aItem = {
665std::vector<SwContentControlListItem>
668 std::vector<SwContentControlListItem> aRet;
670 uno::Sequence<uno::Sequence<beans::PropertyValue>> aSequence;
672 for (
const auto& rItem : aSequence)
676 auto it =
aMap.find(
"DisplayText");
677 if (it !=
aMap.end())
681 it =
aMap.find(
"Value");
682 if (it !=
aMap.end())
686 aRet.push_back(aItem);
696 sal_Int32 nEnd,
bool bIsCopy)
701 if (!pTargetTextNode)
704 "SwTextContentControl ctor: cannot copy content control without target node");
706 rAttr.
DoCopy(*pTargetTextNode);
710 return pTextContentControl;
728 if (rFormatContentControl.GetTextAttr() ==
this)
737 if (rFormatContentControl.GetTextAttr() ==
this)
782 sal_Int32 nEnd = *
End() - 1;
808 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwTextContentControl"));
809 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
812 (void)xmlTextWriterEndElement(pWriter);
835 SwNodeOffset nIdxLHS = pLhs->GetTextNode()->GetIndex();
836 SwNodeOffset nIdxRHS = pRhs->GetTextNode()->GetIndex();
837 if (nIdxLHS == nIdxRHS)
839 return pLhs->GetStart() < pRhs->GetStart();
842 return nIdxLHS < nIdxRHS;
845 return m_aContentControls[
nIndex];
856 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwContentControlManager"));
857 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
860 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwTextContentControl"));
861 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p", pContentControl);
862 (void)xmlTextWriterEndElement(pWriter);
865 (void)xmlTextWriterEndElement(pWriter);
virtual bool DeleteAndJoin(SwPaM &, SwDeleteFlags flags=SwDeleteFlags::Default)=0
complete delete of a given PaM
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
virtual bool operator==(const SfxPoolItem &) const=0
Represents one list item in a content control dropdown list.
void dumpAsXml(xmlTextWriterPtr pWriter) const
bool operator==(const SwContentControlListItem &rOther) const
OUString m_aValue
This must not be empty.
const OUString & ToString() const
static std::vector< SwContentControlListItem > ItemsFromAny(const css::uno::Any &rVal)
static void ItemsToAny(const std::vector< SwContentControlListItem > &rItems, css::uno::Any &rVal)
OUString m_aDisplayText
This may be empty, ToString() falls back to m_aValue.
Knows all the text content controls in the document.
std::vector< SwTextContentControl * > m_aContentControls
Non-owning reference to text content controls.
SwTextContentControl * Get(size_t nIndex)
void Insert(SwTextContentControl *pTextContentControl)
void Erase(SwTextContentControl *pTextContentControl)
void dumpAsXml(xmlTextWriterPtr pWriter) const
SwContentControlManager()
SwTextContentControl * UnsortedGet(size_t nIndex)
OUString m_aCheckedState
If m_bCheckbox is true, the value of a checked checkbox.
virtual ~SwContentControl() override
void SetShowingPlaceHolder(bool bShowingPlaceHolder)
OUString m_aDataBindingXpath
The data bindings's XPath: just remembered.
void NotifyChangeTextNode(SwTextNode *pTextNode)
void SetPicture(bool bPicture)
void SetPlaceholderDocPart(const OUString &rPlaceholderDocPart)
void SetXContentControl(const rtl::Reference< SwXContentControl > &xContentControl)
void SetDataBindingXpath(const OUString &rDataBindingXpath)
bool m_bDropDown
Same as combo box, but free-form input is not accepted.
const OUString & GetLock() const
SwFormatContentControl * m_pFormat
OUString m_aAppearance
The appearance: just remembered.
unotools::WeakReference< SwXContentControl > m_wXContentControl
OUString m_aDateLanguage
If m_bDate is true, the date's BCP 47 language tag.
void SetCurrentDate(const OUString &rCurrentDate)
SwContentControl(SwFormatContentControl *pFormat)
OUString GetDateString() const
Formats m_oSelectedDate, taking m_aDateFormat and m_aDateLanguage into account.
void SetDateFormat(const OUString &rDateFormat)
void SetDataBindingPrefixMappings(const OUString &rDataBindingPrefixMappings)
bool ShouldOpenPopup(const vcl::KeyCode &rKeyCode)
Given rKeyCode as a keyboard event, should a popup be opened for this content control?
void SetAlias(const OUString &rAlias)
bool m_bShowingPlaceHolder
Current content is placeholder text.
void SetCheckedState(const OUString &rCheckedState)
sal_uInt32 m_nTabIndex
The tabIndex: just remembered.
void SetListItems(const std::vector< SwContentControlListItem > &rListItems)
std::optional< size_t > m_oSelectedListItem
Stores a list item index, in case the doc model is not yet updated.
sal_Int32 m_nId
The id: just remembered.
SwTextContentControl * GetTextAttr() const
void SetPlainText(bool bPlainText)
void dumpAsXml(xmlTextWriterPtr pWriter) const
bool AddListItem(size_t nZIndex, const OUString &rDisplayText, const OUString &rValue)
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
double GetCurrentDateValue() const
Parses m_aCurrentDate and returns it.
OUString m_aDataBindingPrefixMappings
The data bindings's prefix mappings: just remembered.
const std::vector< SwContentControlListItem > & GetListItems() const
void SetTag(const OUString &rTag)
void SetAppearance(const OUString &rAppearance)
const std::optional< size_t > & GetSelectedListItem() const
void SetLock(bool bLockContent, bool bLockControl)
bool m_bComboBox
Same as drop-down, but free-form input is also accepted.
void SetDateLanguage(const OUString &rDateLanguage)
OUString m_aLock
The control and content locks: mostly just remembered.
SwContentControlType GetType() const
void SetComboBox(bool bComboBox)
void SetChecked(bool bChecked)
void SetColor(const OUString &rColor)
OUString m_aDateFormat
If m_bDate is true, the date format in a syntax accepted by SvNumberFormatter::PutEntry().
void SetCurrentDateValue(double fCurrentDate)
Formats fCurrentDate and sets it.
bool m_bChecked
If m_bCheckbox is true, is the checkbox checked?
OUString m_aTag
The tag: just remembered.
std::optional< double > m_oSelectedDate
Stores a date timestamp, in case the doc model is not yet updated.
void SetUncheckedState(const OUString &rUncheckedState)
void SetDataBindingStoreItemID(const OUString &rDataBindingStoreItemID)
void SetDropDown(bool bDropDown)
bool m_bCheckbox
Display the content control as a checkbox.
OUString m_aAlias
The alias: just remembered.
SwTextNode * m_pTextNode
Can be nullptr if not in a document for undo purposes.
bool m_bPlainText
Plain text, i.e. not rich text.
std::vector< SwContentControlListItem > m_aListItems
OUString m_aUncheckedState
If m_bCheckbox is true, the value of an unchecked checkbox.
OUString m_aCurrentDate
Date in YYYY-MM-DDT00:00:00Z format.
void SetId(sal_Int32 nId)
void SetCheckbox(bool bCheckbox)
OUString m_aPlaceholderDocPart
The placeholder's doc part: just remembered.
OUString m_aColor
The color: just remembered.
void SetSelectedListItem(std::optional< size_t > oSelectedListItem)
void DeleteListItem(size_t nZIndex)
OUString m_aDataBindingStoreItemID
The data bindings's store item ID: just remembered.
bool GetShowingPlaceHolder() const
bool IsInteractingCharacter(sal_Unicode cCh)
Should this character (during key input) interact with the content control?
void SetTabIndex(sal_uInt32 nTabIndex)
void Push()
store a copy of the current cursor on the cursor stack
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
IDocumentContentOperations const & getIDocumentContentOperations() const
void ResetAttrs(const SwPaM &rRg, bool bTextAttr=true, const o3tl::sorted_vector< sal_uInt16 > &rAttrs=o3tl::sorted_vector< sal_uInt16 >(), const bool bSendDataChangedEvents=true, SwRootFrame const *pLayout=nullptr)
Reset attributes.
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
SwDocShell * GetDocShell()
::SwContentControlManager & GetContentControlManager()
SfxPoolItem subclass that wraps an SwContentControl.
void NotifyChangeTextNode(SwTextNode *pTextNode)
Notify clients registered at m_pContentControl that this content control is being (re-)moved.
std::shared_ptr< SwContentControl > m_pContentControl
const std::shared_ptr< SwContentControl > & GetContentControl() const
SwFormatContentControl(sal_uInt16 nWhich)
SwTextContentControl * m_pTextAttr
SwTextContentControl * GetTextAttr()
bool operator==(const SfxPoolItem &) const override
SfxPoolItem.
~SwFormatContentControl() override
void dumpAsXml(xmlTextWriterPtr pWriter) const override
SwTextNode * GetTextNode() const
void DoCopy(SwTextNode &rTargetTextNode)
This method must be called when the hint is actually copied.
static SwFormatContentControl * CreatePoolDefault(sal_uInt16 nWhich)
void SetTextAttr(SwTextContentControl *pTextAttr)
SwFormatContentControl * Clone(SfxItemPool *pPool=nullptr) const override
PaM is Point and Mark: a selection of the document model.
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
const SfxPoolItem & GetAttr() const
const sal_Int32 * End() const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
sal_Int32 GetStart() const
void SetHasDummyChar(const bool bFlag)
SwTextAttr subclass that tracks the location of the wrapped SwFormatContentControl.
SwTextContentControl(SwContentControlManager *pManager, SwFormatContentControl &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
static SwTextContentControl * CreateTextContentControl(SwDoc &rDoc, SwTextNode *pTargetTextNode, SwFormatContentControl &rAttr, sal_Int32 nStart, sal_Int32 nEnd, bool bIsCopy)
void Delete(bool bSaveContents)
void ChgTextNode(SwTextNode *pNode)
OUString ToString() const
Get the current (potentially invalid) string from the doc.
SwTextNode * GetTextNode() const
SwContentControlManager * m_pManager
~SwTextContentControl() override
void dumpAsXml(xmlTextWriterPtr pWriter) const override
SwTextNode is a paragraph in the document model.
bool GotoContentControl(const SwFormatContentControl &rContentControl, bool bOnlyRefresh=false)
bool Pop(SwCursorShell::PopMode, ::std::optional< SwCallLink > &roLink)
sal_uInt16 GetCode() const
struct _xmlTextWriter * xmlTextWriterPtr
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(181)
constexpr TypedWhichId< SwFormatContentControl > RES_TXTATR_CONTENTCONTROL(56)
constexpr sal_uInt16 KEY_DOWN
#define LANGUAGE_ENGLISH_US
#define SAL_WARN(area, stream)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
Dialog to specify the properties of date form field.
HashMap_OWString_Interface aMap
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
constexpr sal_uInt32 NUMBERFORMAT_ENTRY_NOT_FOUND