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 : 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
174 OUString m_aAlias;
175
177 OUString m_aTag;
178
180 sal_Int32 m_nId = 0;
181
183 // i.e. temporarily store the selected item until the text is inserted by GotoContentControl.
184 std::optional<size_t> m_oSelectedListItem;
185
187 // i.e. temporarily store the date until the text is inserted by GotoContentControl.
188 std::optional<double> m_oSelectedDate;
189
194 bool m_bReadWrite = false;
195
196public:
197 SwTextContentControl* GetTextAttr() const;
198
199 SwTextNode* GetTextNode() const { return m_pTextNode; }
200
201 SwFormatContentControl* GetFormatContentControl() const { return m_pFormat; }
202
203 void SetFormatContentControl(SwFormatContentControl* pFormat) { m_pFormat = pFormat; };
204
205 void NotifyChangeTextNode(SwTextNode* pTextNode);
206
208 {
209 return m_wXContentControl;
210 }
211
212 void SetXContentControl(const rtl::Reference<SwXContentControl>& xContentCnotrol);
213
214 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
215
216 explicit SwContentControl(SwFormatContentControl* pFormat);
217
218 virtual ~SwContentControl() override;
219
220 void SetShowingPlaceHolder(bool bShowingPlaceHolder)
221 {
222 m_bShowingPlaceHolder = bShowingPlaceHolder;
223 }
224
225 bool GetShowingPlaceHolder() const { return m_bShowingPlaceHolder; }
226
227 void SetCheckbox(bool bCheckbox) { m_bCheckbox = bCheckbox; }
228
229 bool GetCheckbox() const { return m_bCheckbox; }
230
231 void SetChecked(bool bChecked) { m_bChecked = bChecked; }
232
233 bool GetChecked() const { return m_bChecked; }
234
235 void SetCheckedState(const OUString& rCheckedState) { m_aCheckedState = rCheckedState; }
236
237 const OUString& GetCheckedState() const { return m_aCheckedState; }
238
239 void SetUncheckedState(const OUString& rUncheckedState) { m_aUncheckedState = rUncheckedState; }
240
241 const OUString& GetUncheckedState() const { return m_aUncheckedState; }
242
243 const std::vector<SwContentControlListItem>& GetListItems() const { return m_aListItems; }
244
245 void SetListItems(const std::vector<SwContentControlListItem>& rListItems)
246 {
247 m_aListItems = rListItems;
248 }
249
250 bool AddListItem(size_t nZIndex, const OUString& rDisplayText, const OUString& rValue);
251 void DeleteListItem(size_t nZIndex);
252 void ClearListItems();
253
254 void SetPicture(bool bPicture) { m_bPicture = bPicture; }
255
256 bool GetPicture() const { return m_bPicture; }
257
258 void SetDate(bool bDate) { m_bDate = bDate; }
259
260 bool GetDate() const { return m_bDate; }
261
262 void SetDateFormat(const OUString& rDateFormat) { m_aDateFormat = rDateFormat; }
263
264 const OUString& GetDateFormat() const { return m_aDateFormat; }
265
266 void SetDateLanguage(const OUString& rDateLanguage) { m_aDateLanguage = rDateLanguage; }
267
268 const OUString& GetDateLanguage() const { return m_aDateLanguage; }
269
270 void SetCurrentDate(const OUString& rCurrentDate) { m_aCurrentDate = rCurrentDate; }
271
272 const OUString& GetCurrentDate() const { return m_aCurrentDate; }
273
275 void SetCurrentDateValue(double fCurrentDate);
276
278 double GetCurrentDateValue() const;
279
281 OUString GetDateString() const;
282
283 void SetPlainText(bool bPlainText) { m_bPlainText = bPlainText; }
284
285 bool GetPlainText() const { return m_bPlainText; }
286
287 void SetComboBox(bool bComboBox) { m_bComboBox = bComboBox; }
288
289 bool GetComboBox() const { return m_bComboBox; }
290
291 void SetDropDown(bool bDropDown) { m_bDropDown = bDropDown; }
292
293 bool GetDropDown() const { return m_bDropDown; }
294
295 void SetPlaceholderDocPart(const OUString& rPlaceholderDocPart)
296 {
297 m_aPlaceholderDocPart = rPlaceholderDocPart;
298 }
299
300 const OUString& GetPlaceholderDocPart() const { return m_aPlaceholderDocPart; }
301
302 void SetSelectedListItem(std::optional<size_t> oSelectedListItem)
303 {
304 m_oSelectedListItem = oSelectedListItem;
305 }
306
307 const std::optional<size_t>& GetSelectedListItem() const { return m_oSelectedListItem; }
308
309 void SetSelectedDate(std::optional<double> oSelectedDate) { m_oSelectedDate = oSelectedDate; }
310
311 const std::optional<double>& GetSelectedDate() const { return m_oSelectedDate; }
312
314 bool IsInteractingCharacter(sal_Unicode cCh);
315
317 bool ShouldOpenPopup(const vcl::KeyCode& rKeyCode);
318
319 void dumpAsXml(xmlTextWriterPtr pWriter) const;
320
321 void SetDataBindingPrefixMappings(const OUString& rDataBindingPrefixMappings)
322 {
323 m_aDataBindingPrefixMappings = rDataBindingPrefixMappings;
324 }
325
326 const OUString& GetDataBindingPrefixMappings() const { return m_aDataBindingPrefixMappings; }
327
328 void SetDataBindingXpath(const OUString& rDataBindingXpath)
329 {
330 m_aDataBindingXpath = rDataBindingXpath;
331 }
332
333 const OUString& GetDataBindingXpath() const { return m_aDataBindingXpath; }
334
335 void SetDataBindingStoreItemID(const OUString& rDataBindingStoreItemID)
336 {
337 m_aDataBindingStoreItemID = rDataBindingStoreItemID;
338 }
339
340 const OUString& GetDataBindingStoreItemID() const { return m_aDataBindingStoreItemID; }
341
342 void SetColor(const OUString& rColor) { m_aColor = rColor; }
343
344 const OUString& GetColor() const { return m_aColor; }
345
346 void SetAlias(const OUString& rAlias) { m_aAlias = rAlias; }
347
348 const OUString& GetAlias() const { return m_aAlias; }
349
350 void SetTag(const OUString& rTag) { m_aTag = rTag; }
351
352 const OUString& GetTag() const { return m_aTag; }
353
354 void SetId(sal_Int32 nId) { m_nId = nId; }
355
356 sal_Int32 GetId() const { return m_nId; }
357
358 void SetReadWrite(bool bReadWrite) { m_bReadWrite = bReadWrite; }
359
360 bool GetReadWrite() const { return m_bReadWrite; }
361
362 SwContentControlType GetType() const;
363};
364
365/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
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
SwFormatContentControl * m_pFormat
SwFormatContentControl * GetFormatContentControl() const
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)
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
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)
const std::optional< size_t > & GetSelectedListItem() const
void SetDateLanguage(const OUString &rDateLanguage)
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
SwTextNode * GetTextNode() const
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:111
UNO API wrapper around an SwContentControl, exposed as the com.sun.star.text.ContentControl service.
Color m_aColor
SwContentControlType
DATE
OUString GetDateString(const css::util::DateTime &_rDT)
sal_Int16 nId
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
sal_uInt16 sal_Unicode