LibreOffice Module sw (master) 1
formatcontentcontrol.hxx
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#pragma once
21
22#include <com/sun/star/text/XTextContent.hpp>
23#include <com/sun/star/beans/PropertyValue.hpp>
24
26#include <sal/types.h>
27#include <svl/poolitem.hxx>
28#include <unotools/weakref.hxx>
29
30#include "calbck.hxx"
31#include "swdllapi.h"
32
33namespace vcl
34{
35class KeyCode;
36}
39class SwTextNode;
41
43{
47 PICTURE,
48 DATE,
51};
52
55{
56 std::shared_ptr<SwContentControl> m_pContentControl;
58
59public:
60 SwTextContentControl* GetTextAttr() { return m_pTextAttr; }
61 void SetTextAttr(SwTextContentControl* pTextAttr);
62
64 void DoCopy(SwTextNode& rTargetTextNode);
65
66 explicit SwFormatContentControl(sal_uInt16 nWhich);
67
68 explicit SwFormatContentControl(const std::shared_ptr<SwContentControl>& pContentControl,
69 sal_uInt16 nWhich);
70 ~SwFormatContentControl() override;
71
73 bool operator==(const SfxPoolItem&) const override;
74 SwFormatContentControl* Clone(SfxItemPool* pPool = nullptr) const override;
75
80 void NotifyChangeTextNode(SwTextNode* pTextNode);
81 SwTextNode* GetTextNode() const;
82 static SwFormatContentControl* CreatePoolDefault(sal_uInt16 nWhich);
83 const std::shared_ptr<SwContentControl>& GetContentControl() const { return m_pContentControl; }
84
85 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
86};
87
90{
91public:
95 OUString m_aValue;
96
97 void dumpAsXml(xmlTextWriterPtr pWriter) const;
98
99 const OUString& ToString() const;
100
101 bool operator==(const SwContentControlListItem& rOther) const;
102
103 static void ItemsToAny(const std::vector<SwContentControlListItem>& rItems,
104 css::uno::Any& rVal);
105
106 static std::vector<SwContentControlListItem> ItemsFromAny(const css::uno::Any& rVal);
107};
108
110class SW_DLLPUBLIC SwContentControl final : public sw::BroadcastingModify
111{
113
115
118
120 bool m_bShowingPlaceHolder = false;
121
123 bool m_bCheckbox = false;
124
126 bool m_bChecked = false;
127
130
133
134 std::vector<SwContentControlListItem> m_aListItems;
135
136 bool m_bPicture = false;
137
138 bool m_bDate = false;
139
142
145
148
150 bool m_bPlainText = false;
151
153 bool m_bComboBox = false;
154
156 bool m_bDropDown = false;
157
160
163
166
169
171 OUString m_aColor;
172
175
177 OUString m_aAlias;
178
180 OUString m_aTag;
181
183 sal_Int32 m_nId = 0;
184
186 sal_uInt32 m_nTabIndex = 0;
187
189 OUString m_aLock;
190
192 // i.e. temporarily store the selected item until the text is inserted by GotoContentControl.
193 std::optional<size_t> m_oSelectedListItem;
194
196 // i.e. temporarily store the date until the text is inserted by GotoContentControl.
197 std::optional<double> m_oSelectedDate;
198
203 bool m_bReadWrite = false;
204
205public:
206 SwTextContentControl* GetTextAttr() const;
207
208 SwTextNode* GetTextNode() const { return m_pTextNode; }
209
210 SwFormatContentControl* GetFormatContentControl() const { return m_pFormat; }
211
212 void SetFormatContentControl(SwFormatContentControl* pFormat) { m_pFormat = pFormat; };
213
214 void NotifyChangeTextNode(SwTextNode* pTextNode);
215
217 {
218 return m_wXContentControl;
219 }
220
221 void SetXContentControl(const rtl::Reference<SwXContentControl>& xContentControl);
222
223 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
224
225 explicit SwContentControl(SwFormatContentControl* pFormat);
226
227 virtual ~SwContentControl() override;
228
229 void SetShowingPlaceHolder(bool bShowingPlaceHolder)
230 {
231 m_bShowingPlaceHolder = bShowingPlaceHolder;
232 }
233
234 bool GetShowingPlaceHolder() const { return m_bShowingPlaceHolder; }
235
236 void SetCheckbox(bool bCheckbox) { m_bCheckbox = bCheckbox; }
237
238 bool GetCheckbox() const { return m_bCheckbox; }
239
240 void SetChecked(bool bChecked) { m_bChecked = bChecked; }
241
242 bool GetChecked() const { return m_bChecked; }
243
244 void SetCheckedState(const OUString& rCheckedState) { m_aCheckedState = rCheckedState; }
245
246 const OUString& GetCheckedState() const { return m_aCheckedState; }
247
248 void SetUncheckedState(const OUString& rUncheckedState) { m_aUncheckedState = rUncheckedState; }
249
250 const OUString& GetUncheckedState() const { return m_aUncheckedState; }
251
252 const std::vector<SwContentControlListItem>& GetListItems() const { return m_aListItems; }
253
254 void SetListItems(const std::vector<SwContentControlListItem>& rListItems)
255 {
256 m_aListItems = rListItems;
257 }
258
259 bool AddListItem(size_t nZIndex, const OUString& rDisplayText, const OUString& rValue);
260 void DeleteListItem(size_t nZIndex);
261 void ClearListItems();
262
263 void SetPicture(bool bPicture) { m_bPicture = bPicture; }
264
265 bool GetPicture() const { return m_bPicture; }
266
267 void SetDate(bool bDate) { m_bDate = bDate; }
268
269 bool GetDate() const { return m_bDate; }
270
271 void SetDateFormat(const OUString& rDateFormat) { m_aDateFormat = rDateFormat; }
272
273 const OUString& GetDateFormat() const { return m_aDateFormat; }
274
275 void SetDateLanguage(const OUString& rDateLanguage) { m_aDateLanguage = rDateLanguage; }
276
277 const OUString& GetDateLanguage() const { return m_aDateLanguage; }
278
279 void SetCurrentDate(const OUString& rCurrentDate) { m_aCurrentDate = rCurrentDate; }
280
281 const OUString& GetCurrentDate() const { return m_aCurrentDate; }
282
284 void SetCurrentDateValue(double fCurrentDate);
285
287 double GetCurrentDateValue() const;
288
290 OUString GetDateString() const;
291
292 void SetPlainText(bool bPlainText) { m_bPlainText = bPlainText; }
293
294 bool GetPlainText() const { return m_bPlainText; }
295
296 void SetComboBox(bool bComboBox) { m_bComboBox = bComboBox; }
297
298 bool GetComboBox() const { return m_bComboBox; }
299
300 void SetDropDown(bool bDropDown) { m_bDropDown = bDropDown; }
301
302 bool GetDropDown() const { return m_bDropDown; }
303
304 void SetPlaceholderDocPart(const OUString& rPlaceholderDocPart)
305 {
306 m_aPlaceholderDocPart = rPlaceholderDocPart;
307 }
308
309 const OUString& GetPlaceholderDocPart() const { return m_aPlaceholderDocPart; }
310
311 void SetSelectedListItem(std::optional<size_t> oSelectedListItem)
312 {
313 m_oSelectedListItem = oSelectedListItem;
314 }
315
316 const std::optional<size_t>& GetSelectedListItem() const { return m_oSelectedListItem; }
317
320 std::optional<size_t> GetSelectedListItem(bool bCheckDocModel) const;
321
322 void SetSelectedDate(std::optional<double> oSelectedDate) { m_oSelectedDate = oSelectedDate; }
323
324 const std::optional<double>& GetSelectedDate() const { return m_oSelectedDate; }
325
327 bool IsInteractingCharacter(sal_Unicode cCh);
328
330 bool ShouldOpenPopup(const vcl::KeyCode& rKeyCode);
331
332 void dumpAsXml(xmlTextWriterPtr pWriter) const;
333
334 void SetDataBindingPrefixMappings(const OUString& rDataBindingPrefixMappings)
335 {
336 m_aDataBindingPrefixMappings = rDataBindingPrefixMappings;
337 }
338
339 const OUString& GetDataBindingPrefixMappings() const { return m_aDataBindingPrefixMappings; }
340
341 void SetDataBindingXpath(const OUString& rDataBindingXpath)
342 {
343 m_aDataBindingXpath = rDataBindingXpath;
344 }
345
346 const OUString& GetDataBindingXpath() const { return m_aDataBindingXpath; }
347
348 void SetDataBindingStoreItemID(const OUString& rDataBindingStoreItemID)
349 {
350 m_aDataBindingStoreItemID = rDataBindingStoreItemID;
351 }
352
353 const OUString& GetDataBindingStoreItemID() const { return m_aDataBindingStoreItemID; }
354
355 void SetColor(const OUString& rColor) { m_aColor = rColor; }
356
357 const OUString& GetColor() const { return m_aColor; }
358
359 void SetAppearance(const OUString& rAppearance) { m_aAppearance = rAppearance; }
360
361 const OUString& GetAppearance() const { return m_aAppearance; }
362
363 void SetAlias(const OUString& rAlias) { m_aAlias = rAlias; }
364
365 const OUString& GetAlias() const { return m_aAlias; }
366
367 void SetTag(const OUString& rTag) { m_aTag = rTag; }
368
369 const OUString& GetTag() const { return m_aTag; }
370
371 void SetId(sal_Int32 nId) { m_nId = nId; }
372
373 sal_Int32 GetId() const { return m_nId; }
374
375 void SetTabIndex(sal_uInt32 nTabIndex) { m_nTabIndex = nTabIndex; }
376
377 sal_uInt32 GetTabIndex() const { return m_nTabIndex; }
378
379 // At the design level, define how the control should be locked. No effect at implementation lvl
380 void SetLock(bool bLockContent, bool bLockControl);
381 void SetLock(const OUString& rLock) { m_aLock = rLock; }
382
383 // At the design level, get how the control is locked. Does not reflect actual implementation.
384 std::optional<bool> GetLock(bool bControl) const;
385 const OUString& GetLock() const { return m_aLock; }
386
387 void SetReadWrite(bool bReadWrite) { m_bReadWrite = bReadWrite; }
388
389 // At the implementation level, define whether the user can directly modify the contents.
390 bool GetReadWrite() const { return m_bReadWrite; }
391
392 SwContentControlType GetType() const;
393};
394
395/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
virtual bool operator==(const SfxPoolItem &) const=0
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
Represents one list item in a content control dropdown list.
OUString m_aValue
This must not be empty.
OUString m_aDisplayText
This may be empty, ToString() falls back to m_aValue.
Stores the properties of a content control.
void SetSelectedDate(std::optional< double > oSelectedDate)
OUString m_aCheckedState
If m_bCheckbox is true, the value of a checked checkbox.
void SetShowingPlaceHolder(bool bShowingPlaceHolder)
OUString m_aDataBindingXpath
The data bindings's XPath: just remembered.
const OUString & GetCurrentDate() const
void SetPicture(bool bPicture)
void SetPlaceholderDocPart(const OUString &rPlaceholderDocPart)
void SetDataBindingXpath(const OUString &rDataBindingXpath)
const OUString & GetDateFormat() const
const OUString & GetDateLanguage() const
const OUString & GetLock() const
SwFormatContentControl * m_pFormat
SwFormatContentControl * GetFormatContentControl() const
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)
const OUString & GetAppearance() const
void SetReadWrite(bool bReadWrite)
void SetDateFormat(const OUString &rDateFormat)
const OUString & GetDataBindingStoreItemID() const
void SetDataBindingPrefixMappings(const OUString &rDataBindingPrefixMappings)
void SetAlias(const OUString &rAlias)
const OUString & GetDataBindingXpath() const
sal_uInt32 GetTabIndex() const
void SetCheckedState(const OUString &rCheckedState)
void SetListItems(const std::vector< SwContentControlListItem > &rListItems)
const OUString & GetCheckedState() const
std::optional< size_t > m_oSelectedListItem
Stores a list item index, in case the doc model is not yet updated.
void SetPlainText(bool bPlainText)
sal_Int32 GetId() const
void SetFormatContentControl(SwFormatContentControl *pFormat)
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 SetDateLanguage(const OUString &rDateLanguage)
OUString m_aLock
The control and content locks: mostly just remembered.
const std::optional< double > & GetSelectedDate() 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().
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)
OUString m_aAlias
The alias: just remembered.
SwTextNode * m_pTextNode
Can be nullptr if not in a document for undo purposes.
const unotools::WeakReference< SwXContentControl > & GetXContentControl() const
const OUString & GetDataBindingPrefixMappings() const
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.
const OUString & GetAlias() const
const OUString & GetUncheckedState() const
void SetId(sal_Int32 nId)
void SetCheckbox(bool bCheckbox)
void SetDate(bool bDate)
OUString m_aPlaceholderDocPart
The placeholder's doc part: just remembered.
OUString m_aColor
The color: just remembered.
void SetSelectedListItem(std::optional< size_t > oSelectedListItem)
OUString m_aDataBindingStoreItemID
The data bindings's store item ID: just remembered.
const OUString & GetPlaceholderDocPart() const
const OUString & GetColor() const
bool GetShowingPlaceHolder() const
const OUString & GetTag() const
void SetLock(const OUString &rLock)
SwTextNode * GetTextNode() const
void SetTabIndex(sal_uInt32 nTabIndex)
SfxPoolItem subclass that wraps an SwContentControl.
std::shared_ptr< SwContentControl > m_pContentControl
const std::shared_ptr< SwContentControl > & GetContentControl() const
SwTextContentControl * m_pTextAttr
SwTextContentControl * GetTextAttr()
SwTextAttr subclass that tracks the location of the wrapped SwFormatContentControl.
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
UNO API wrapper around an SwContentControl, exposed as the com.sun.star.text.ContentControl service.
Color m_aColor
struct _xmlTextWriter * xmlTextWriterPtr
SwContentControlType
DATE
OUString GetDateString(const css::util::DateTime &_rDT)
sal_Int16 nId
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
sal_uInt16 sal_Unicode